Skip to content

Commit

Permalink
fix: address issue with private threads not getting or using scriptId
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Aug 12, 2024
1 parent 1592846 commit a80d481
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion components/script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Script: React.FC<ScriptProps> = ({ className, messagesHeight = 'h-full', e
connected,
running,
restartScript,
scriptId,
fetchThreads,
} = useContext(ScriptContext);

Expand Down Expand Up @@ -75,7 +76,7 @@ const Script: React.FC<ScriptProps> = ({ 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);
Expand Down
6 changes: 4 additions & 2 deletions components/threads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const Threads: React.FC<ThreadsProps> = ({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);
};

Expand Down Expand Up @@ -58,7 +60,7 @@ const Threads: React.FC<ThreadsProps> = ({className}) => {
<div
key={key}
className={`border-1 border-gray-300 px-4 rounded-xl transition duration-150 ease-in-out ${isSelected(thread.meta.id) ? 'bg-primary border-primary dark:border-primary-50 dark:bg-primary-50 text-white' : 'hover:bg-gray-100 dark:hover:bg-zinc-700 cursor-pointer dark:bg-zinc-800 dark:border-zinc-800'} `}
onClick={() => handleRun(thread.meta.script, thread.meta.id)}
onClick={() => handleRun(thread.meta.script, thread.meta.id, thread.meta.scriptId || '')}
>
<div className="flex justify-between items-center">
<h2 className="text-sm truncate">{thread.meta.name}</h2>
Expand Down
2 changes: 1 addition & 1 deletion components/threads/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 14 additions & 12 deletions contexts/script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ScriptContextProps{
interface ScriptContextState {
script: string;
scriptId?: string;
setScriptId: React.Dispatch<React.SetStateAction<string | undefined>>;
scriptContent: ToolDef[] | null;
workspace: string;
tools: string[];
Expand Down Expand Up @@ -106,21 +107,22 @@ const ScriptContextProvider: React.FC<ScriptContextProps> = ({children, initialS
setInitialFetch(true);
});
}
}, [script]);
}, [script, scriptId]);

useEffect(() => {
setHasParams(tool.arguments?.properties != undefined && Object.keys(tool.arguments?.properties).length > 0);
}, [tool]);

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]);

Expand All @@ -139,10 +141,10 @@ const ScriptContextProvider: React.FC<ScriptContextProps> = ({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");
Expand Down Expand Up @@ -177,14 +179,14 @@ const ScriptContextProvider: React.FC<ScriptContextProps> = ({children, initialS
}
restart();
}, 200),
[script, restart]
[script, thread, restart]
);

return (
<ScriptContext.Provider
value={{
scriptContent,
scriptId,
scriptId, setScriptId,
script, setScript,
workspace, setWorkspace,
tool, setTool,
Expand Down

0 comments on commit a80d481

Please sign in to comment.