mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Expose console messages via tool call.
This commit is contained in:
1 parent
8108407478
commit
804efb4d23
5 files changed
+120
-7
No files matched your search
@@ -33,6 +33,7 @@ import { NostrReadNipsIndexTool } from '@/lib/tools/NostrReadNipsIndexTool';
|
||||
import { NostrGenerateKindTool } from '@/lib/tools/NostrGenerateKindTool';
|
||||
import { ShellTool } from '@/lib/tools/ShellTool';
|
||||
import { TypecheckTool } from '@/lib/tools/TypecheckTool';
|
||||
import { ReadConsoleMessagesTool } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { toolToOpenAI } from '@/lib/tools/openai-adapter';
|
||||
import { Tool } from '@/lib/tools/Tool';
|
||||
import OpenAI from 'openai';
|
||||
@@ -48,6 +49,7 @@ interface ChatPaneProps {
|
||||
onLoadingChange?: (isLoading: boolean) => void;
|
||||
isLoading?: boolean;
|
||||
isBuildLoading?: boolean;
|
||||
consoleMessages?: import('@/pages/ProjectView').ConsoleMessage[];
|
||||
}
|
||||
|
||||
export interface ChatPaneRef {
|
||||
@@ -62,6 +64,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
onLoadingChange,
|
||||
isLoading: externalIsLoading,
|
||||
isBuildLoading: externalIsBuildLoading,
|
||||
consoleMessages,
|
||||
}, ref) => {
|
||||
const { t } = useTranslation();
|
||||
const [input, setInput] = useState('');
|
||||
@@ -112,6 +115,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
nostr_read_nips_index: new NostrReadNipsIndexTool(),
|
||||
nostr_generate_kind: new NostrGenerateKindTool(),
|
||||
shell: new ShellTool(fs, cwd, git),
|
||||
read_console_messages: new ReadConsoleMessagesTool(consoleMessages || []),
|
||||
};
|
||||
|
||||
// Add deploy tool only if user is logged in
|
||||
@@ -123,7 +127,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
}
|
||||
|
||||
return baseTools;
|
||||
}, [fs, git, cwd, user, projectId]);
|
||||
}, [fs, git, cwd, user, projectId, consoleMessages]);
|
||||
|
||||
// Convert tools to OpenAI format
|
||||
const tools = useMemo(() => {
|
||||
|
||||
@@ -33,6 +33,8 @@ interface PreviewPaneProps {
|
||||
projectName?: string;
|
||||
onFirstInteraction?: () => void;
|
||||
isPreviewable?: boolean;
|
||||
consoleMessages?: ConsoleMessage[];
|
||||
setConsoleMessages?: React.Dispatch<React.SetStateAction<ConsoleMessage[]>>;
|
||||
}
|
||||
|
||||
interface JSONRPCRequest {
|
||||
@@ -65,13 +67,14 @@ interface JSONRPCResponse {
|
||||
id: number;
|
||||
}
|
||||
|
||||
interface ConsoleMessage {
|
||||
// Console message type (now defined in ProjectView for sharing)
|
||||
export interface ConsoleMessage {
|
||||
id: number;
|
||||
level: 'log' | 'warn' | 'error' | 'info' | 'debug';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function PreviewPane({ projectId, activeTab, onToggleView, projectName, onFirstInteraction, isPreviewable = true }: PreviewPaneProps) {
|
||||
export function PreviewPane({ projectId, activeTab, onToggleView, projectName, onFirstInteraction, isPreviewable = true, consoleMessages: externalConsoleMessages = [], setConsoleMessages: externalSetConsoleMessages }: PreviewPaneProps) {
|
||||
const { t } = useTranslation();
|
||||
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
||||
const [fileContent, setFileContent] = useState<string>('');
|
||||
@@ -82,9 +85,14 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
const [currentPath, setCurrentPath] = useState('/');
|
||||
const [navigationHistory, setNavigationHistory] = useState<string[]>(['/']);
|
||||
const [historyIndex, setHistoryIndex] = useState(0);
|
||||
const [consoleMessages, setConsoleMessages] = useState<ConsoleMessage[]>([]);
|
||||
const [copiedMessageId, setCopiedMessageId] = useState<number | null>(null);
|
||||
const [deployDialogOpen, setDeployDialogOpen] = useState(false);
|
||||
|
||||
// Use external state if provided, otherwise use internal state
|
||||
const [internalConsoleMessages, setInternalConsoleMessages] = useState<ConsoleMessage[]>([]);
|
||||
const consoleMessages = externalConsoleMessages || internalConsoleMessages;
|
||||
const setConsoleMessages = externalSetConsoleMessages || setInternalConsoleMessages;
|
||||
const handleSetConsoleMessages = setConsoleMessages;
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const { fs } = useFS();
|
||||
const projectsManager = useProjectsManager();
|
||||
@@ -242,11 +250,11 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
message: params.message,
|
||||
};
|
||||
|
||||
setConsoleMessages(prev => [...prev, newConsoleMessage]);
|
||||
handleSetConsoleMessages(prev => [...prev, newConsoleMessage]);
|
||||
|
||||
// Log to parent console for debugging with appropriate level
|
||||
console[normalizedLevel](`[IFRAME ${params.level.toUpperCase()}] ${params.message}`);
|
||||
}, []);
|
||||
}, [handleSetConsoleMessages]);
|
||||
|
||||
const handleFetch = useCallback(async (request: JSONRPCRequest) => {
|
||||
const { params, id } = request;
|
||||
@@ -447,7 +455,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
};
|
||||
|
||||
const clearConsole = () => {
|
||||
setConsoleMessages([]);
|
||||
handleSetConsoleMessages([]);
|
||||
};
|
||||
|
||||
const copyMessageToClipboard = async (msg: ConsoleMessage) => {
|
||||
|
||||
Reference in new issue
Block a user