From a80d481cce90c08ba2df063fe636a9a393bc8e5f Mon Sep 17 00:00:00 2001 From: tylerslaton Date: Sun, 11 Aug 2024 22:02:52 -0400 Subject: [PATCH] fix: address issue with private threads not getting or using scriptId Signed-off-by: tylerslaton --- components/script.tsx | 3 ++- components/threads.tsx | 6 ++++-- components/threads/new.tsx | 2 +- contexts/script.tsx | 26 ++++++++++++++------------ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/components/script.tsx b/components/script.tsx index da76f8c3..a4abf6e0 100644 --- a/components/script.tsx +++ b/components/script.tsx @@ -39,6 +39,7 @@ const Script: React.FC = ({ className, messagesHeight = 'h-full', e connected, running, restartScript, + scriptId, fetchThreads, } = useContext(ScriptContext); @@ -75,7 +76,7 @@ const Script: React.FC = ({ className, messagesHeight = 'h-full', e let threadId = ""; if (hasNoUserMessages() && enableThreads && !thread && setThreads && setSelectedThreadId) { - const newThread = await createThread(script, message) + const newThread = await createThread(script, message, scriptId); threadId = newThread?.meta?.id; setThreads(await getThreads()); setSelectedThreadId(threadId); diff --git a/components/threads.tsx b/components/threads.tsx index b7748fe9..23b50416 100644 --- a/components/threads.tsx +++ b/components/threads.tsx @@ -14,15 +14,17 @@ const Threads: React.FC = ({className}) => { setScript, setThread, threads, + setScriptId, selectedThreadId, setSelectedThreadId, } = useContext(ScriptContext); const [isCollapsed, setIsCollapsed] = useState(false); - const handleRun = async (script: string, id: string) => { + const handleRun = async (script: string, id: string, scriptId: string) => { setScript(script); setThread(id); + setScriptId(scriptId); setSelectedThreadId(id); }; @@ -58,7 +60,7 @@ const Threads: React.FC = ({className}) => {
handleRun(thread.meta.script, thread.meta.id)} + onClick={() => handleRun(thread.meta.script, thread.meta.id, thread.meta.scriptId || '')} >

{thread.meta.name}

diff --git a/components/threads/new.tsx b/components/threads/new.tsx index a9b423a0..80a99760 100644 --- a/components/threads/new.tsx +++ b/components/threads/new.tsx @@ -33,7 +33,7 @@ const NewThread = ({className}: NewThreadProps) => { useEffect(() => { fetchScripts() }, [isOpen]); const handleCreateThread = (script: string) => { - createThread(script).then((newThread) => { + createThread(script, '', scriptId).then((newThread) => { setThreads((threads: Thread[]) => [newThread, ...threads]); setScript(script); setThread(newThread.meta.id); diff --git a/contexts/script.tsx b/contexts/script.tsx index 6c6ff306..e1d4089f 100644 --- a/contexts/script.tsx +++ b/contexts/script.tsx @@ -20,6 +20,7 @@ interface ScriptContextProps{ interface ScriptContextState { script: string; scriptId?: string; + setScriptId: React.Dispatch>; scriptContent: ToolDef[] | null; workspace: string; tools: string[]; @@ -106,7 +107,7 @@ const ScriptContextProvider: React.FC = ({children, initialS setInitialFetch(true); }); } - }, [script]); + }, [script, scriptId]); useEffect(() => { setHasParams(tool.arguments?.properties != undefined && Object.keys(tool.arguments?.properties).length > 0); @@ -114,13 +115,14 @@ const ScriptContextProvider: React.FC = ({children, initialS useEffect(() => { if(thread) { - getThread(thread).then((thread) => { - if(thread) { - setWorkspace(thread.meta.workspace); - setScriptId(thread.meta.scriptId); - } - }); - restartScript(); + getThread(thread) + .then((thread) => { + if(thread) { + setInitialFetch(false); + setWorkspace(thread.meta.workspace); + } + restartScript(); + }) } }, [thread]); @@ -139,10 +141,10 @@ const ScriptContextProvider: React.FC = ({children, initialS useEffect(() => { if (forceRun && socket && connected) { - socket.emit("run", script, subTool ? subTool : tool.name, formValues, workspace, thread) + socket.emit("run", scriptContent ? scriptContent : script, subTool ? subTool : tool.name, formValues, workspace, thread) setForceRun(false); } - }, [forceRun, connected]); + }, [forceRun, script, scriptContent, subTool, formValues, workspace, thread, connected]); useEffect(() => { const smallBody = document.getElementById("small-message"); @@ -177,14 +179,14 @@ const ScriptContextProvider: React.FC = ({children, initialS } restart(); }, 200), - [script, restart] + [script, thread, restart] ); return (