Skip to content

Commit c6821bf

Browse files
committed
feat(generic): enable results tab wiring
1 parent a7c1e51 commit c6821bf

File tree

1 file changed

+67
-71
lines changed
  • apps/sim/app/workspace/[workspaceId]/home/hooks

1 file changed

+67
-71
lines changed

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

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,31 +1213,30 @@ export function useChat(
12131213
}
12141214
flush()
12151215

1216-
// TODO: Uncomment when rich UI for Results tab is ready
1217-
// if (shouldOpenGenericResource(name)) {
1218-
// if (!genericEntryMap.has(id)) {
1219-
// const entryIdx = appendGenericEntry({
1220-
// toolCallId: id,
1221-
// toolName: name,
1222-
// displayTitle: displayTitle ?? name,
1223-
// status: 'executing',
1224-
// params: args,
1225-
// })
1226-
// genericEntryMap.set(id, entryIdx)
1227-
// const opened = addResource({ type: 'generic', id: 'results', title: 'Results' })
1228-
// if (opened) onResourceEventRef.current?.()
1229-
// else setActiveResourceId('results')
1230-
// } else {
1231-
// const entryIdx = genericEntryMap.get(id)
1232-
// if (entryIdx !== undefined) {
1233-
// updateGenericEntry(entryIdx, {
1234-
// toolName: name,
1235-
// ...(displayTitle && { displayTitle }),
1236-
// ...(args && { params: args }),
1237-
// })
1238-
// }
1239-
// }
1240-
// }
1216+
if (shouldOpenGenericResource(name)) {
1217+
if (!genericEntryMap.has(id)) {
1218+
const entryIdx = appendGenericEntry({
1219+
toolCallId: id,
1220+
toolName: name,
1221+
displayTitle: displayTitle ?? name,
1222+
status: 'executing',
1223+
params: args,
1224+
})
1225+
genericEntryMap.set(id, entryIdx)
1226+
const opened = addResource({ type: 'generic', id: 'results', title: 'Results' })
1227+
if (opened) onResourceEventRef.current?.()
1228+
else setActiveResourceId('results')
1229+
} else {
1230+
const entryIdx = genericEntryMap.get(id)
1231+
if (entryIdx !== undefined) {
1232+
updateGenericEntry(entryIdx, {
1233+
toolName: name,
1234+
...(displayTitle && { displayTitle }),
1235+
...(args && { params: args }),
1236+
})
1237+
}
1238+
}
1239+
}
12411240

12421241
if (
12431242
parsed.type === 'tool_call' &&
@@ -1334,18 +1333,17 @@ export function useChat(
13341333
flush()
13351334
}
13361335

1337-
// TODO: Uncomment when rich UI for Results tab is ready
1338-
// if (toolName && shouldOpenGenericResource(toolName)) {
1339-
// const entryIdx = genericEntryMap.get(id)
1340-
// if (entryIdx !== undefined) {
1341-
// const entry = genericResourceDataRef.current.entries[entryIdx]
1342-
// if (entry) {
1343-
// updateGenericEntry(entryIdx, {
1344-
// streamingArgs: (entry.streamingArgs ?? '') + delta,
1345-
// })
1346-
// }
1347-
// }
1348-
// }
1336+
if (toolName && shouldOpenGenericResource(toolName)) {
1337+
const entryIdx = genericEntryMap.get(id)
1338+
if (entryIdx !== undefined) {
1339+
const entry = genericResourceDataRef.current.entries[entryIdx]
1340+
if (entry) {
1341+
updateGenericEntry(entryIdx, {
1342+
streamingArgs: (entry.streamingArgs ?? '') + delta,
1343+
})
1344+
}
1345+
}
1346+
}
13491347

13501348
break
13511349
}
@@ -1454,33 +1452,32 @@ export function useChat(
14541452
}
14551453
}
14561454

1457-
// TODO: Uncomment when rich UI for Results tab is ready
1458-
// if (
1459-
// shouldOpenGenericResource(tc.name) ||
1460-
// (isDeferredResourceTool(tc.name) && extractedResources.length === 0)
1461-
// ) {
1462-
// const entryIdx = genericEntryMap.get(id)
1463-
// if (entryIdx !== undefined) {
1464-
// updateGenericEntry(entryIdx, {
1465-
// status: tc.status,
1466-
// result: tc.result ?? undefined,
1467-
// streamingArgs: undefined,
1468-
// })
1469-
// } else {
1470-
// const newIdx = appendGenericEntry({
1471-
// toolCallId: id,
1472-
// toolName: tc.name,
1473-
// displayTitle: tc.displayTitle ?? tc.name,
1474-
// status: tc.status,
1475-
// params: toolArgsMap.get(id) as Record<string, unknown> | undefined,
1476-
// result: tc.result ?? undefined,
1477-
// })
1478-
// genericEntryMap.set(id, newIdx)
1479-
// if (addResource({ type: 'generic', id: 'results', title: 'Results' })) {
1480-
// onResourceEventRef.current?.()
1481-
// }
1482-
// }
1483-
// }
1455+
if (
1456+
shouldOpenGenericResource(tc.name) ||
1457+
(isDeferredResourceTool(tc.name) && extractedResources.length === 0)
1458+
) {
1459+
const entryIdx = genericEntryMap.get(id)
1460+
if (entryIdx !== undefined) {
1461+
updateGenericEntry(entryIdx, {
1462+
status: tc.status,
1463+
result: tc.result ?? undefined,
1464+
streamingArgs: undefined,
1465+
})
1466+
} else {
1467+
const newIdx = appendGenericEntry({
1468+
toolCallId: id,
1469+
toolName: tc.name,
1470+
displayTitle: tc.displayTitle ?? tc.name,
1471+
status: tc.status,
1472+
params: toolArgsMap.get(id) as Record<string, unknown> | undefined,
1473+
result: tc.result ?? undefined,
1474+
})
1475+
genericEntryMap.set(id, newIdx)
1476+
if (addResource({ type: 'generic', id: 'results', title: 'Results' })) {
1477+
onResourceEventRef.current?.()
1478+
}
1479+
}
1480+
}
14841481
}
14851482

14861483
break
@@ -1577,13 +1574,12 @@ export function useChat(
15771574
}
15781575
flush()
15791576

1580-
// TODO: Uncomment when rich UI for Results tab is ready
1581-
// if (toolCallName && shouldOpenGenericResource(toolCallName)) {
1582-
// const entryIdx = genericEntryMap.get(id)
1583-
// if (entryIdx !== undefined) {
1584-
// updateGenericEntry(entryIdx, { status: 'error', streamingArgs: undefined })
1585-
// }
1586-
// }
1577+
if (toolCallName && shouldOpenGenericResource(toolCallName)) {
1578+
const entryIdx = genericEntryMap.get(id)
1579+
if (entryIdx !== undefined) {
1580+
updateGenericEntry(entryIdx, { status: 'error', streamingArgs: undefined })
1581+
}
1582+
}
15871583
}
15881584
break
15891585
}

0 commit comments

Comments
 (0)