Skip to content

Commit de6bfe5

Browse files
committed
Merge branch 'improvement/terminal-store-mem' of github.com:simstudioai/sim into improvement/terminal-store-mem
2 parents bd5321e + 8f89b77 commit de6bfe5

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ function isActiveStreamConflictError(input: unknown): boolean {
147147
return input.includes('A response is already in progress for this chat')
148148
}
149149

150+
/**
151+
* Extracts tool call IDs from snapshot events so that replayed client-executable
152+
* tool calls are not re-executed after a page refresh.
153+
*/
154+
function extractToolCallIdsFromSnapshot(snapshot?: StreamSnapshot | null): Set<string> {
155+
const ids = new Set<string>()
156+
if (!snapshot?.events) return ids
157+
for (const entry of snapshot.events) {
158+
const event = entry.event
159+
if (event.type === 'tool_call' && typeof event.toolCallId === 'string') {
160+
ids.add(event.toolCallId)
161+
}
162+
}
163+
return ids
164+
}
165+
150166
function buildReplayStream(events: StreamEventEnvelope[]): ReadableStream<Uint8Array> {
151167
const encoder = new TextEncoder()
152168
return new ReadableStream<Uint8Array>({
@@ -860,7 +876,7 @@ export function useChat(
860876
sendingRef.current = true
861877
streamingContentRef.current = ''
862878
streamingBlocksRef.current = []
863-
clientExecutionStartedRef.current.clear()
879+
clientExecutionStartedRef.current = extractToolCallIdsFromSnapshot(snapshot)
864880

865881
const assistantId = crypto.randomUUID()
866882

apps/sim/lib/copilot/client-sse/handlers.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
2121
import { captureBaselineSnapshot } from '@/stores/workflow-diff/utils'
2222
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
2323
import type { WorkflowState } from '@/stores/workflows/workflow/types'
24-
import { executeRunToolOnClient } from './run-tool-execution'
2524
import type { ClientContentBlock, ClientStreamingContext } from './types'
2625

2726
const logger = createLogger('CopilotClientSseHandlers')
@@ -988,10 +987,6 @@ export const sseHandlers: Record<string, SSEHandler> = {
988987
return
989988
}
990989

991-
if (clientExecutable && initialState === ClientToolCallState.executing) {
992-
executeRunToolOnClient(id, toolName, args || existing?.params || {})
993-
}
994-
995990
if (toolName === 'oauth_request_access' && args && typeof window !== 'undefined') {
996991
try {
997992
window.dispatchEvent(

0 commit comments

Comments
 (0)