From c6821bf5479d58db1c9d9de8eaaf6292f8c60f72 Mon Sep 17 00:00:00 2001 From: waleed Date: Fri, 27 Mar 2026 17:26:13 -0700 Subject: [PATCH] feat(generic): enable results tab wiring --- .../[workspaceId]/home/hooks/use-chat.ts | 138 +++++++++--------- 1 file changed, 67 insertions(+), 71 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts index 3b3511ab0f3..37bbd14c473 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts @@ -1213,31 +1213,30 @@ export function useChat( } flush() - // TODO: Uncomment when rich UI for Results tab is ready - // if (shouldOpenGenericResource(name)) { - // if (!genericEntryMap.has(id)) { - // const entryIdx = appendGenericEntry({ - // toolCallId: id, - // toolName: name, - // displayTitle: displayTitle ?? name, - // status: 'executing', - // params: args, - // }) - // genericEntryMap.set(id, entryIdx) - // const opened = addResource({ type: 'generic', id: 'results', title: 'Results' }) - // if (opened) onResourceEventRef.current?.() - // else setActiveResourceId('results') - // } else { - // const entryIdx = genericEntryMap.get(id) - // if (entryIdx !== undefined) { - // updateGenericEntry(entryIdx, { - // toolName: name, - // ...(displayTitle && { displayTitle }), - // ...(args && { params: args }), - // }) - // } - // } - // } + if (shouldOpenGenericResource(name)) { + if (!genericEntryMap.has(id)) { + const entryIdx = appendGenericEntry({ + toolCallId: id, + toolName: name, + displayTitle: displayTitle ?? name, + status: 'executing', + params: args, + }) + genericEntryMap.set(id, entryIdx) + const opened = addResource({ type: 'generic', id: 'results', title: 'Results' }) + if (opened) onResourceEventRef.current?.() + else setActiveResourceId('results') + } else { + const entryIdx = genericEntryMap.get(id) + if (entryIdx !== undefined) { + updateGenericEntry(entryIdx, { + toolName: name, + ...(displayTitle && { displayTitle }), + ...(args && { params: args }), + }) + } + } + } if ( parsed.type === 'tool_call' && @@ -1334,18 +1333,17 @@ export function useChat( flush() } - // TODO: Uncomment when rich UI for Results tab is ready - // if (toolName && shouldOpenGenericResource(toolName)) { - // const entryIdx = genericEntryMap.get(id) - // if (entryIdx !== undefined) { - // const entry = genericResourceDataRef.current.entries[entryIdx] - // if (entry) { - // updateGenericEntry(entryIdx, { - // streamingArgs: (entry.streamingArgs ?? '') + delta, - // }) - // } - // } - // } + if (toolName && shouldOpenGenericResource(toolName)) { + const entryIdx = genericEntryMap.get(id) + if (entryIdx !== undefined) { + const entry = genericResourceDataRef.current.entries[entryIdx] + if (entry) { + updateGenericEntry(entryIdx, { + streamingArgs: (entry.streamingArgs ?? '') + delta, + }) + } + } + } break } @@ -1454,33 +1452,32 @@ export function useChat( } } - // TODO: Uncomment when rich UI for Results tab is ready - // if ( - // shouldOpenGenericResource(tc.name) || - // (isDeferredResourceTool(tc.name) && extractedResources.length === 0) - // ) { - // const entryIdx = genericEntryMap.get(id) - // if (entryIdx !== undefined) { - // updateGenericEntry(entryIdx, { - // status: tc.status, - // result: tc.result ?? undefined, - // streamingArgs: undefined, - // }) - // } else { - // const newIdx = appendGenericEntry({ - // toolCallId: id, - // toolName: tc.name, - // displayTitle: tc.displayTitle ?? tc.name, - // status: tc.status, - // params: toolArgsMap.get(id) as Record | undefined, - // result: tc.result ?? undefined, - // }) - // genericEntryMap.set(id, newIdx) - // if (addResource({ type: 'generic', id: 'results', title: 'Results' })) { - // onResourceEventRef.current?.() - // } - // } - // } + if ( + shouldOpenGenericResource(tc.name) || + (isDeferredResourceTool(tc.name) && extractedResources.length === 0) + ) { + const entryIdx = genericEntryMap.get(id) + if (entryIdx !== undefined) { + updateGenericEntry(entryIdx, { + status: tc.status, + result: tc.result ?? undefined, + streamingArgs: undefined, + }) + } else { + const newIdx = appendGenericEntry({ + toolCallId: id, + toolName: tc.name, + displayTitle: tc.displayTitle ?? tc.name, + status: tc.status, + params: toolArgsMap.get(id) as Record | undefined, + result: tc.result ?? undefined, + }) + genericEntryMap.set(id, newIdx) + if (addResource({ type: 'generic', id: 'results', title: 'Results' })) { + onResourceEventRef.current?.() + } + } + } } break @@ -1577,13 +1574,12 @@ export function useChat( } flush() - // TODO: Uncomment when rich UI for Results tab is ready - // if (toolCallName && shouldOpenGenericResource(toolCallName)) { - // const entryIdx = genericEntryMap.get(id) - // if (entryIdx !== undefined) { - // updateGenericEntry(entryIdx, { status: 'error', streamingArgs: undefined }) - // } - // } + if (toolCallName && shouldOpenGenericResource(toolCallName)) { + const entryIdx = genericEntryMap.get(id) + if (entryIdx !== undefined) { + updateGenericEntry(entryIdx, { status: 'error', streamingArgs: undefined }) + } + } } break }