@sixb/app 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/connector-icons/README.md +1 -0
- package/assets/connector-icons/ctm.png +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +3 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/artifact-panel.d.ts +3 -1
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/components/composer-settings.d.ts +1 -1
- package/dist/agent/components/composer-settings.d.ts.map +1 -1
- package/dist/agent/components/composer.d.ts +22 -5
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/context-meter.d.ts +1 -1
- package/dist/agent/components/context-meter.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +5 -2
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +2 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/pending-messages.d.ts +20 -0
- package/dist/agent/components/pending-messages.d.ts.map +1 -0
- package/dist/agent/components/sandbox-recovery.d.ts +11 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/threads-button.d.ts +1 -1
- package/dist/agent/components/threads-button.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +3 -6
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +5 -0
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts +10 -4
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +68 -0
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +114 -0
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/inbox-handoff.d.ts +10 -0
- package/dist/agent/inbox-handoff.d.ts.map +1 -0
- package/dist/agent/live-run.d.ts +8 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/search/interpret.d.ts +101 -0
- package/dist/agent/search/interpret.d.ts.map +1 -0
- package/dist/agent/search/search-tool-view.d.ts +10 -0
- package/dist/agent/search/search-tool-view.d.ts.map +1 -0
- package/dist/agent/thread-state.d.ts +26 -0
- package/dist/agent/thread-state.d.ts.map +1 -0
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/tool-views/registry.d.ts +5 -6
- package/dist/agent/tool-views/registry.d.ts.map +1 -1
- package/dist/agent/types.d.ts +5 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/editor/block-handle.d.ts +20 -0
- package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
- package/dist/artifacts/editor/blocks.d.ts +34 -0
- package/dist/artifacts/editor/blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/callout-view.d.ts +7 -0
- package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
- package/dist/artifacts/editor/document-editor.d.ts +30 -0
- package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
- package/dist/artifacts/editor/figure-view.d.ts +12 -0
- package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
- package/dist/artifacts/editor/find-blocks.d.ts +6 -0
- package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/markdown-document.d.ts +12 -0
- package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
- package/dist/artifacts/editor/messages.d.ts +4 -0
- package/dist/artifacts/editor/messages.d.ts.map +1 -0
- package/dist/artifacts/editor/schema.d.ts +21 -0
- package/dist/artifacts/editor/schema.d.ts.map +1 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
- package/dist/artifacts/editor/slash-menu.d.ts +43 -0
- package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
- package/dist/artifacts/editor/upload.d.ts +12 -0
- package/dist/artifacts/editor/upload.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +5 -0
- package/dist/artifacts/file-source.d.ts.map +1 -1
- package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
- package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/commands.d.ts +93 -0
- package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/entry.d.ts +2 -0
- package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/frame.d.ts +5 -0
- package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/keys.d.ts +8 -0
- package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
- package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/schema.d.ts +34 -0
- package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/style.d.ts +2 -0
- package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +2 -2
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/live/boards.d.ts +2 -0
- package/dist/artifacts/live/boards.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +32 -0
- package/dist/artifacts/live/document.d.ts.map +1 -0
- package/dist/artifacts/live/header.d.ts +4 -4
- package/dist/artifacts/live/header.d.ts.map +1 -1
- package/dist/artifacts/live/presence.d.ts.map +1 -1
- package/dist/artifacts/live/session.d.ts +2 -0
- package/dist/artifacts/live/session.d.ts.map +1 -1
- package/dist/artifacts/live/view.d.ts +4 -3
- package/dist/artifacts/live/view.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +226 -2
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/pdf.d.ts +8 -0
- package/dist/artifacts/pdf.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +80 -0
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/references/references.d.ts +3 -3
- package/dist/artifacts/references/references.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
- package/dist/artifacts/renderers/designed-document.d.ts +28 -0
- package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
- package/dist/artifacts/renderers/document-tree.d.ts +2 -0
- package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
- package/dist/artifacts/renderers/document.d.ts +9 -1
- package/dist/artifacts/renderers/document.d.ts.map +1 -1
- package/dist/artifacts/renderers/live-frame.d.ts +145 -0
- package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
- package/dist/artifacts/renderers/page-editor.d.ts +16 -0
- package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
- package/dist/artifacts/renderers/page.d.ts +10 -1
- package/dist/artifacts/renderers/page.d.ts.map +1 -1
- package/dist/artifacts/viewer.d.ts.map +1 -1
- package/dist/{chunk-kymx9y5e.js → chunk-4fex83k2.js} +10874 -4690
- package/dist/chunk-4fex83k2.js.map +239 -0
- package/dist/{chunk-yrcm1pbg.js → chunk-4wm09prf.js} +491 -2128
- package/dist/chunk-4wm09prf.js.map +27 -0
- package/dist/{chunk-pxd07kvx.js → chunk-5sgac68y.js} +1 -1
- package/dist/{chunk-970s5nkn.js → chunk-69qgh20f.js} +1 -1
- package/dist/chunk-y51c4tsz.js +11 -0
- package/dist/chunk-y51c4tsz.js.map +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +5 -5
- package/dist/pages/console/data/messages.d.ts +6 -0
- package/dist/pages/console/data/messages.d.ts.map +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages.js +12 -5
- package/dist/pages.js.map +6 -6
- package/dist/shell/search-command.d.ts.map +1 -1
- package/package.json +22 -5
- package/src/agent/activity-label.ts +3 -0
- package/src/agent/agent-chat.tsx +56 -37
- package/src/agent/agent-execution-trace.tsx +2 -2
- package/src/agent/agent-panel.tsx +6 -4
- package/src/agent/agent.css +254 -0
- package/src/agent/artifact-panel.tsx +77 -22
- package/src/agent/components/composer-settings.tsx +20 -10
- package/src/agent/components/composer.tsx +342 -104
- package/src/agent/components/context-meter.tsx +7 -3
- package/src/agent/components/conversation-panel.tsx +69 -29
- package/src/agent/components/message-parts.tsx +367 -59
- package/src/agent/components/message-view.tsx +12 -2
- package/src/agent/components/pending-messages.tsx +338 -0
- package/src/agent/components/sandbox-recovery.tsx +36 -17
- package/src/agent/components/threads-button.tsx +3 -2
- package/src/agent/components/transcript.tsx +63 -34
- package/src/agent/conversation.ts +203 -54
- package/src/agent/delegation/interpret.ts +31 -7
- package/src/agent/hooks/use-agent-conversation.ts +348 -100
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +87 -11
- package/src/agent/i18n/fr.ts +83 -12
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +23 -2
- package/src/agent/react-router.tsx +2 -2
- package/src/agent/search/interpret.ts +367 -0
- package/src/agent/search/search-tool-view.tsx +235 -0
- package/src/agent/thread-state.ts +114 -0
- package/src/agent/tool-views/built-in.tsx +16 -0
- package/src/agent/tool-views/registry.tsx +28 -2
- package/src/agent/types.ts +7 -0
- package/src/agent/view-file/view-file-tool-view.tsx +33 -19
- package/src/artifacts/artifacts.css +398 -0
- package/src/artifacts/card-preview.tsx +6 -1
- package/src/artifacts/editor/block-handle.tsx +278 -0
- package/src/artifacts/editor/blocks.ts +216 -0
- package/src/artifacts/editor/callout-view.tsx +31 -0
- package/src/artifacts/editor/document-editor.tsx +484 -0
- package/src/artifacts/editor/figure-view.tsx +66 -0
- package/src/artifacts/editor/find-blocks.ts +19 -0
- package/src/artifacts/editor/markdown-document.tsx +72 -0
- package/src/artifacts/editor/messages.ts +4 -0
- package/src/artifacts/editor/schema.ts +159 -0
- package/src/artifacts/editor/selection-toolbar.tsx +364 -0
- package/src/artifacts/editor/slash-menu.tsx +251 -0
- package/src/artifacts/editor/upload.ts +40 -0
- package/src/artifacts/file-source.ts +11 -0
- package/src/artifacts/frame-editor/bundle.ts +8 -0
- package/src/artifacts/frame-editor/commands.ts +565 -0
- package/src/artifacts/frame-editor/entry.ts +6 -0
- package/src/artifacts/frame-editor/frame.ts +847 -0
- package/src/artifacts/frame-editor/generated/editor.txt +149 -0
- package/src/artifacts/frame-editor/generated.d.ts +5 -0
- package/src/artifacts/frame-editor/keys.ts +323 -0
- package/src/artifacts/frame-editor/protocol.ts +151 -0
- package/src/artifacts/frame-editor/schema.ts +293 -0
- package/src/artifacts/frame-editor/style.ts +58 -0
- package/src/artifacts/frame.tsx +11 -3
- package/src/artifacts/live/boards.ts +46 -3
- package/src/artifacts/live/document.ts +89 -0
- package/src/artifacts/live/header.tsx +9 -14
- package/src/artifacts/live/presence.ts +5 -1
- package/src/artifacts/live/session.ts +4 -2
- package/src/artifacts/live/view.ts +14 -8
- package/src/artifacts/messages.ts +138 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +11 -144
- package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
- package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
- package/src/artifacts/renderers/canvas/comments.ts +8 -4
- package/src/artifacts/renderers/designed-document.tsx +277 -0
- package/src/artifacts/renderers/document-tree.ts +9 -0
- package/src/artifacts/renderers/document.tsx +13 -102
- package/src/artifacts/renderers/live-frame.ts +163 -0
- package/src/artifacts/renderers/page-editor.tsx +613 -0
- package/src/artifacts/renderers/page.tsx +21 -4
- package/src/artifacts/viewer.tsx +87 -41
- package/src/index.ts +6 -0
- package/src/pages/console/data/messages.ts +6 -0
- package/src/pages/console/data/projections.tsx +4 -0
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/console/ontology/lineage/trail.tsx +3 -0
- package/src/shell/search-command.tsx +2 -0
- package/dist/chunk-kymx9y5e.js.map +0 -211
- package/dist/chunk-yrcm1pbg.js.map +0 -34
- /package/dist/{chunk-pxd07kvx.js.map → chunk-5sgac68y.js.map} +0 -0
- /package/dist/{chunk-970s5nkn.js.map → chunk-69qgh20f.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FileSource, messageFileSource } from "../artifacts/file-source"
|
|
2
2
|
import { isApprovalOutcomeMessage } from "./approvals"
|
|
3
|
-
import type { LiveRunState } from "./live-run"
|
|
3
|
+
import type { LiveInboxRead, LiveRunState } from "./live-run"
|
|
4
4
|
import { knownName, type MessageAuthor, principalKey } from "./message-authors"
|
|
5
5
|
import {
|
|
6
6
|
type NormalizedFile,
|
|
@@ -80,8 +80,9 @@ export interface AgentConversationMessage {
|
|
|
80
80
|
readonly id: string | null
|
|
81
81
|
readonly role: "user" | "assistant"
|
|
82
82
|
/**
|
|
83
|
-
* `pending`: sent, not saved yet. `streaming`:
|
|
84
|
-
*
|
|
83
|
+
* `pending`: sent, not saved yet. `streaming`: from the run's live stream until its saved copy
|
|
84
|
+
* replaces it: the reply, and a message the run read while answering, where it read it.
|
|
85
|
+
* `complete`: everything else.
|
|
85
86
|
*/
|
|
86
87
|
readonly status: "pending" | "streaming" | "complete"
|
|
87
88
|
/** The run that wrote a reply. */
|
|
@@ -153,26 +154,48 @@ export function conversationMessages(input: ConversationMessagesInput): AgentCon
|
|
|
153
154
|
for (const run of input.runs ?? []) {
|
|
154
155
|
if (run.status === "failed" || run.status === "cancelled") ended.set(run.id, run.status)
|
|
155
156
|
}
|
|
157
|
+
// A turn that read messages as it answered holds a reply on each side of them: only its last one
|
|
158
|
+
// says how the turn ended, as its live copy did.
|
|
159
|
+
const lastReplyOfRun = new Map<string, string>()
|
|
160
|
+
for (const message of input.messages) {
|
|
161
|
+
if (message.role === "assistant" && message.runId !== null) {
|
|
162
|
+
lastReplyOfRun.set(message.runId, message.id)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
156
165
|
|
|
166
|
+
let lastUserMessageId: string | null = null
|
|
157
167
|
for (const message of input.messages) {
|
|
158
168
|
if (message.role === "system") continue
|
|
159
169
|
|
|
160
170
|
savedIds.add(message.id)
|
|
161
171
|
if (message.role === "assistant" && message.runId !== null) answeredRuns.add(message.runId)
|
|
172
|
+
if (message.role === "user") lastUserMessageId = message.id
|
|
162
173
|
|
|
163
174
|
// Continue writes the model a message the reader never wrote: nothing to draw. Neither is the
|
|
164
175
|
// one a decision resumes a turn with: its calls' cards say how they ended, and the resumed
|
|
165
176
|
// answer stays right under the one it continues.
|
|
166
177
|
if (isContinuation(message) || isApprovalOutcomeMessage(message)) continue
|
|
167
178
|
|
|
168
|
-
//
|
|
179
|
+
// A run's reply after a message it read keeps the key its live copy had (see liveMessages).
|
|
169
180
|
const preferred = savedKey(message, input.sentKeys)
|
|
170
|
-
const
|
|
181
|
+
const after =
|
|
182
|
+
message.role === "assistant" && lastUserMessageId !== null
|
|
183
|
+
? `${preferred}:after:${lastUserMessageId}`
|
|
184
|
+
: null
|
|
185
|
+
const key = !keys.has(preferred)
|
|
186
|
+
? preferred
|
|
187
|
+
: after !== null && !keys.has(after)
|
|
188
|
+
? after
|
|
189
|
+
: `message:${message.id}`
|
|
171
190
|
keys.add(key)
|
|
172
191
|
|
|
173
192
|
const saved = savedMessage(message, key, authorOf(message.authorPrincipal, input), input)
|
|
174
193
|
const unfinished =
|
|
175
|
-
message.role === "assistant" &&
|
|
194
|
+
message.role === "assistant" &&
|
|
195
|
+
message.runId !== null &&
|
|
196
|
+
lastReplyOfRun.get(message.runId) === message.id
|
|
197
|
+
? ended.get(message.runId)
|
|
198
|
+
: undefined
|
|
176
199
|
result.push(unfinished ? unfinishedMessage(saved, unfinished) : saved)
|
|
177
200
|
}
|
|
178
201
|
|
|
@@ -181,8 +204,7 @@ export function conversationMessages(input: ConversationMessagesInput): AgentCon
|
|
|
181
204
|
result.push(pendingMessage(pending, input))
|
|
182
205
|
}
|
|
183
206
|
|
|
184
|
-
|
|
185
|
-
if (live) result.push(live)
|
|
207
|
+
result.push(...liveMessages(input, savedIds, answeredRuns))
|
|
186
208
|
|
|
187
209
|
return result
|
|
188
210
|
}
|
|
@@ -239,7 +261,7 @@ interface SavedEntry {
|
|
|
239
261
|
readonly message: AgentConversationMessage
|
|
240
262
|
}
|
|
241
263
|
|
|
242
|
-
const savedEntries = new WeakMap<AgentMessage, SavedEntry>()
|
|
264
|
+
const savedEntries = new WeakMap<AgentMessage, readonly SavedEntry[]>()
|
|
243
265
|
|
|
244
266
|
function savedMessage(
|
|
245
267
|
message: AgentMessage,
|
|
@@ -248,15 +270,11 @@ function savedMessage(
|
|
|
248
270
|
input: ConversationMessagesInput
|
|
249
271
|
): AgentConversationMessage {
|
|
250
272
|
const observed = Boolean(input.observed)
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
sameAuthor(cached.author, author)
|
|
257
|
-
) {
|
|
258
|
-
return cached.message
|
|
259
|
-
}
|
|
273
|
+
const existing = savedEntries.get(message)
|
|
274
|
+
const hit = existing?.find(
|
|
275
|
+
(entry) => entry.key === key && entry.observed === observed && sameAuthor(entry.author, author)
|
|
276
|
+
)
|
|
277
|
+
if (hit) return hit.message
|
|
260
278
|
|
|
261
279
|
const fileSource = (fileRef: AgentFileRef, path: string) =>
|
|
262
280
|
messageFileSource({
|
|
@@ -284,7 +302,8 @@ function savedMessage(
|
|
|
284
302
|
...(message.compaction ? { compaction: message.compaction } : {}),
|
|
285
303
|
}
|
|
286
304
|
|
|
287
|
-
|
|
305
|
+
const nextEntry: SavedEntry = { key, author, observed, message: converted }
|
|
306
|
+
savedEntries.set(message, existing ? [nextEntry, ...existing.slice(0, 1)] : [nextEntry])
|
|
288
307
|
return converted
|
|
289
308
|
}
|
|
290
309
|
|
|
@@ -418,76 +437,186 @@ function pendingMessage(
|
|
|
418
437
|
}
|
|
419
438
|
}
|
|
420
439
|
|
|
421
|
-
/**
|
|
422
|
-
|
|
440
|
+
/**
|
|
441
|
+
* The reply streaming in, until its saved copies are in the conversation. A message the run read as
|
|
442
|
+
* it answered sits where it read it, between the reply before and the reply after, as the thread
|
|
443
|
+
* holds them once the turn ends; each keeps the key its saved copy will have.
|
|
444
|
+
*/
|
|
445
|
+
function liveMessages(
|
|
423
446
|
input: ConversationMessagesInput,
|
|
424
447
|
savedIds: ReadonlySet<string>,
|
|
425
448
|
answeredRuns: ReadonlySet<string>
|
|
426
|
-
): AgentConversationMessage
|
|
449
|
+
): AgentConversationMessage[] {
|
|
427
450
|
const live = input.live
|
|
428
|
-
if (!live || live.runId === null
|
|
429
|
-
if (live.
|
|
430
|
-
if (
|
|
451
|
+
if (!live || live.runId === null) return []
|
|
452
|
+
if (live.parts.length === 0 && live.inboxReads.length === 0) return []
|
|
453
|
+
if (live.finalizedMessageId !== null && savedIds.has(live.finalizedMessageId)) return []
|
|
454
|
+
if (answeredRuns.has(live.runId)) return []
|
|
431
455
|
|
|
432
456
|
// A worker that stopped mid-turn saved none of what it streamed.
|
|
433
457
|
const presentation = input.presentation
|
|
434
|
-
if (presentation.kind === "interrupted" && !presentation.hasProgress) return
|
|
458
|
+
if (presentation.kind === "interrupted" && !presentation.hasProgress) return []
|
|
435
459
|
|
|
460
|
+
const runId = live.runId
|
|
436
461
|
const unfinished =
|
|
437
462
|
live.finishStatus === "failed" || live.finishStatus === "cancelled"
|
|
438
463
|
? live.finishStatus
|
|
439
464
|
: undefined
|
|
465
|
+
// Saved but not read back yet: the reply keeps its live shape until the copy replaces it.
|
|
466
|
+
const status = live.active || live.finalizedMessageId !== null ? "streaming" : "complete"
|
|
467
|
+
|
|
468
|
+
const result: AgentConversationMessage[] = []
|
|
469
|
+
let replied = false
|
|
470
|
+
let lastRead: string | null = null
|
|
471
|
+
const reply = (from: number, to: number, last: boolean) => {
|
|
472
|
+
const parts = liveParts(live, from, to, last)
|
|
473
|
+
if (parts.length === 0) return
|
|
474
|
+
|
|
475
|
+
result.push({
|
|
476
|
+
key: replied && lastRead !== null ? `run:${runId}:after:${lastRead}` : `run:${runId}`,
|
|
477
|
+
id: null,
|
|
478
|
+
role: "assistant",
|
|
479
|
+
status,
|
|
480
|
+
runId,
|
|
481
|
+
parts,
|
|
482
|
+
context: [],
|
|
483
|
+
diagnostics: [],
|
|
484
|
+
...(last && unfinished ? { unfinished } : {}),
|
|
485
|
+
})
|
|
486
|
+
replied = true
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
let from = 0
|
|
490
|
+
for (const read of live.inboxReads) {
|
|
491
|
+
reply(from, read.at, false)
|
|
492
|
+
from = read.at
|
|
493
|
+
|
|
494
|
+
for (const message of read.messages) {
|
|
495
|
+
if (savedIds.has(message.id)) continue
|
|
496
|
+
|
|
497
|
+
result.push(readMessage(message, input))
|
|
498
|
+
lastRead = message.id
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
reply(from, live.parts.length, true)
|
|
502
|
+
|
|
503
|
+
return result
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** A message the run read as it answered, drawn as the thread will hold it. */
|
|
507
|
+
function readMessage(
|
|
508
|
+
message: LiveInboxRead["messages"][number],
|
|
509
|
+
input: ConversationMessagesInput
|
|
510
|
+
): AgentConversationMessage {
|
|
511
|
+
const author = authorOf(message.authorPrincipal, input)
|
|
440
512
|
|
|
441
513
|
return {
|
|
442
|
-
key: `
|
|
514
|
+
key: `message:${message.id}`,
|
|
443
515
|
id: null,
|
|
444
|
-
role: "
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
parts:
|
|
449
|
-
|
|
516
|
+
role: "user",
|
|
517
|
+
status: "streaming",
|
|
518
|
+
runId: null,
|
|
519
|
+
...(author ? { author } : {}),
|
|
520
|
+
parts: message.parts.flatMap((part) =>
|
|
521
|
+
part.type === "text" ? [{ type: "text" as const, text: part.text, streaming: false }] : []
|
|
522
|
+
),
|
|
523
|
+
context: message.parts.flatMap((part) =>
|
|
524
|
+
part.type === "context"
|
|
525
|
+
? [{ context: part.context as AgentContextInput, origin: part.origin }]
|
|
526
|
+
: []
|
|
527
|
+
),
|
|
450
528
|
diagnostics: [],
|
|
451
|
-
...(unfinished ? { unfinished } : {}),
|
|
452
529
|
}
|
|
453
530
|
}
|
|
454
531
|
|
|
455
|
-
|
|
456
|
-
|
|
532
|
+
const liveNonTextParts = new WeakMap<
|
|
533
|
+
NormalizedPart,
|
|
534
|
+
{ readonly key: string | undefined; readonly part: AgentConversationPart }
|
|
535
|
+
>()
|
|
536
|
+
const liveSettledTextParts = new WeakMap<NormalizedPart, AgentConversationPart>()
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* The live parts from `from` to `to`. Text streams in spans the built-in chat joins, so they join
|
|
540
|
+
* here too; the model is still writing the text the `last` ones end on.
|
|
541
|
+
*/
|
|
542
|
+
function liveParts(
|
|
543
|
+
live: LiveRunState,
|
|
544
|
+
from: number,
|
|
545
|
+
to: number,
|
|
546
|
+
last: boolean
|
|
547
|
+
): AgentConversationPart[] {
|
|
457
548
|
const result: AgentConversationPart[] = []
|
|
458
549
|
|
|
459
|
-
live.parts.forEach((part,
|
|
550
|
+
live.parts.slice(from, to).forEach((part, offset) => {
|
|
460
551
|
switch (part.kind) {
|
|
461
552
|
case "text": {
|
|
462
553
|
const previous = result.at(-1)
|
|
463
554
|
if (previous?.type === "text") {
|
|
464
555
|
result[result.length - 1] = { ...previous, text: previous.text + part.text }
|
|
465
556
|
} else {
|
|
466
|
-
|
|
557
|
+
const cached = liveSettledTextParts.get(part)
|
|
558
|
+
if (cached) {
|
|
559
|
+
result.push(cached)
|
|
560
|
+
} else {
|
|
561
|
+
const created: AgentConversationPart = {
|
|
562
|
+
type: "text",
|
|
563
|
+
text: part.text,
|
|
564
|
+
streaming: false,
|
|
565
|
+
}
|
|
566
|
+
liveSettledTextParts.set(part, created)
|
|
567
|
+
result.push(created)
|
|
568
|
+
}
|
|
467
569
|
}
|
|
468
570
|
return
|
|
469
571
|
}
|
|
470
572
|
|
|
471
|
-
case "reasoning":
|
|
472
|
-
|
|
573
|
+
case "reasoning": {
|
|
574
|
+
const cached = liveNonTextParts.get(part)
|
|
575
|
+
if (cached) {
|
|
576
|
+
result.push(cached.part)
|
|
577
|
+
return
|
|
578
|
+
}
|
|
579
|
+
const created: AgentConversationPart = {
|
|
580
|
+
type: "reasoning",
|
|
581
|
+
text: part.text,
|
|
582
|
+
streaming: part.streaming,
|
|
583
|
+
}
|
|
584
|
+
liveNonTextParts.set(part, { key: undefined, part: created })
|
|
585
|
+
result.push(created)
|
|
473
586
|
return
|
|
587
|
+
}
|
|
474
588
|
|
|
475
589
|
case "tool": {
|
|
476
|
-
const key = live.partKeys[
|
|
590
|
+
const key = live.partKeys[from + offset]
|
|
591
|
+
const cached = liveNonTextParts.get(part)
|
|
592
|
+
if (cached && cached.key === key) {
|
|
593
|
+
result.push(cached.part)
|
|
594
|
+
return
|
|
595
|
+
}
|
|
477
596
|
const toolCallId = key?.startsWith("tool#") ? key.slice("tool#".length) : undefined
|
|
478
|
-
|
|
597
|
+
const created: AgentConversationPart = {
|
|
479
598
|
type: "tool",
|
|
480
599
|
toolName: part.tool.toolName,
|
|
481
600
|
...(toolCallId === undefined ? {} : { toolCallId }),
|
|
482
601
|
...toolViewProps(part.tool),
|
|
483
602
|
...(part.tool.files ? { files: part.tool.files.map(fileOf) } : {}),
|
|
484
|
-
}
|
|
603
|
+
}
|
|
604
|
+
liveNonTextParts.set(part, { key, part: created })
|
|
605
|
+
result.push(created)
|
|
485
606
|
return
|
|
486
607
|
}
|
|
487
608
|
|
|
488
|
-
case "file":
|
|
489
|
-
|
|
609
|
+
case "file": {
|
|
610
|
+
const cached = liveNonTextParts.get(part)
|
|
611
|
+
if (cached) {
|
|
612
|
+
result.push(cached.part)
|
|
613
|
+
return
|
|
614
|
+
}
|
|
615
|
+
const created: AgentConversationPart = { type: "file", ...fileOf(part) }
|
|
616
|
+
liveNonTextParts.set(part, { key: undefined, part: created })
|
|
617
|
+
result.push(created)
|
|
490
618
|
return
|
|
619
|
+
}
|
|
491
620
|
|
|
492
621
|
case "step-start":
|
|
493
622
|
return
|
|
@@ -497,10 +626,9 @@ function liveParts(live: LiveRunState): AgentConversationPart[] {
|
|
|
497
626
|
}
|
|
498
627
|
})
|
|
499
628
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
result[result.length - 1] = { ...last, streaming: true }
|
|
629
|
+
const end = result.at(-1)
|
|
630
|
+
if (last && live.active && end?.type === "text") {
|
|
631
|
+
result[result.length - 1] = { ...end, streaming: true }
|
|
504
632
|
}
|
|
505
633
|
|
|
506
634
|
return result
|
|
@@ -516,31 +644,49 @@ function fileOf(file: NormalizedFile): AgentConversationFile {
|
|
|
516
644
|
* The parts as the built-in chat draws them. Two text parts in a row were two steps, which the
|
|
517
645
|
* chat keeps apart with the step boundary between them.
|
|
518
646
|
*/
|
|
647
|
+
const normalizedPartEntries = new WeakMap<AgentConversationPart, NormalizedPart>()
|
|
648
|
+
const normalizedToolEntries = new WeakMap<AgentConversationToolPart, NormalizedTool>()
|
|
649
|
+
const STEP_START_PART: NormalizedPart = { kind: "step-start" }
|
|
650
|
+
|
|
519
651
|
export function normalizedParts(parts: readonly AgentConversationPart[]): NormalizedPart[] {
|
|
520
652
|
const result: NormalizedPart[] = []
|
|
521
653
|
|
|
522
654
|
for (const part of parts) {
|
|
655
|
+
if (part.type === "text" && result.at(-1)?.kind === "text") {
|
|
656
|
+
result.push(STEP_START_PART)
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const cached = normalizedPartEntries.get(part)
|
|
660
|
+
if (cached) {
|
|
661
|
+
result.push(cached)
|
|
662
|
+
continue
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
let created: NormalizedPart
|
|
523
666
|
switch (part.type) {
|
|
524
667
|
case "text":
|
|
525
|
-
|
|
526
|
-
result.push({ kind: "text", text: part.text })
|
|
668
|
+
created = { kind: "text", text: part.text }
|
|
527
669
|
break
|
|
528
670
|
|
|
529
671
|
case "reasoning":
|
|
530
|
-
|
|
672
|
+
created = { kind: "reasoning", text: part.text, streaming: part.streaming }
|
|
531
673
|
break
|
|
532
674
|
|
|
533
675
|
case "tool":
|
|
534
|
-
|
|
676
|
+
created = { kind: "tool", tool: normalizedTool(part) }
|
|
535
677
|
break
|
|
536
678
|
|
|
537
679
|
case "file":
|
|
538
|
-
|
|
680
|
+
created = { kind: "file", ...fileOf(part) }
|
|
539
681
|
break
|
|
540
682
|
|
|
541
683
|
default:
|
|
542
684
|
part satisfies never
|
|
685
|
+
continue
|
|
543
686
|
}
|
|
687
|
+
|
|
688
|
+
normalizedPartEntries.set(part, created)
|
|
689
|
+
result.push(created)
|
|
544
690
|
}
|
|
545
691
|
|
|
546
692
|
return result
|
|
@@ -548,7 +694,10 @@ export function normalizedParts(parts: readonly AgentConversationPart[]): Normal
|
|
|
548
694
|
|
|
549
695
|
/** A tool part as the built-in tool views read it. */
|
|
550
696
|
export function normalizedTool(part: AgentConversationToolPart): NormalizedTool {
|
|
697
|
+
const cached = normalizedToolEntries.get(part)
|
|
698
|
+
if (cached) return cached
|
|
551
699
|
const { type: _type, toolCallId: _toolCallId, ...tool } = part
|
|
700
|
+
normalizedToolEntries.set(part, tool)
|
|
552
701
|
return tool
|
|
553
702
|
}
|
|
554
703
|
|
|
@@ -91,17 +91,41 @@ export interface DelegationTurn {
|
|
|
91
91
|
/** Earlier threads hold `wait_agent`; a `wait` or a `stop` for commands alone is left out. */
|
|
92
92
|
const DELEGATION_TOOLS = new Set(["spawn_agent", "message_agent", "wait", "stop", "wait_agent"])
|
|
93
93
|
|
|
94
|
+
export interface DelegationTurnEntry {
|
|
95
|
+
readonly turn: DelegationTurn
|
|
96
|
+
readonly signature: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const delegationTurnEntries = new WeakMap<AgentConversationMessage, DelegationTurnEntry>()
|
|
100
|
+
|
|
101
|
+
export function delegationTurnEntry(msg: AgentConversationMessage): DelegationTurnEntry | null {
|
|
102
|
+
if (msg.role !== "assistant") return null
|
|
103
|
+
const cached = delegationTurnEntries.get(msg)
|
|
104
|
+
if (cached) return cached
|
|
105
|
+
|
|
106
|
+
const tools: NormalizedTool[] = []
|
|
107
|
+
let sig = `${msg.runId ?? ""}:`
|
|
108
|
+
for (const part of msg.parts) {
|
|
109
|
+
if (part.type === "tool" && DELEGATION_TOOLS.has(part.toolName)) {
|
|
110
|
+
tools.push(normalizedTool(part))
|
|
111
|
+
sig += `${part.toolName}@${part.state};`
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const entry = { turn: { runId: msg.runId, tools }, signature: sig }
|
|
115
|
+
delegationTurnEntries.set(msg, entry)
|
|
116
|
+
return entry
|
|
117
|
+
}
|
|
118
|
+
|
|
94
119
|
/** The delegation calls of each reply, oldest first, the one streaming last. */
|
|
95
120
|
export function delegationTurns(
|
|
96
121
|
messages: readonly AgentConversationMessage[]
|
|
97
122
|
): readonly DelegationTurn[] {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
})
|
|
123
|
+
const result: DelegationTurn[] = []
|
|
124
|
+
for (const message of messages) {
|
|
125
|
+
const entry = delegationTurnEntry(message)
|
|
126
|
+
if (entry) result.push(entry.turn)
|
|
127
|
+
}
|
|
128
|
+
return result
|
|
105
129
|
}
|
|
106
130
|
|
|
107
131
|
/**
|