@sixb/app 0.2.3 → 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/background/background-tool-row.d.ts.map +1 -1
- package/dist/agent/background/interpret.d.ts +1 -1
- package/dist/agent/background/interpret.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 +8 -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 +5 -0
- 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/agent-exchange.d.ts +16 -0
- package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
- package/dist/agent/delegation/child-card.d.ts +3 -3
- package/dist/agent/delegation/child-card.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +1 -10
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/child-work.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +9 -10
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
- package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
- package/dist/agent/file-edits/interpret.d.ts +25 -0
- package/dist/agent/file-edits/interpret.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +16 -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 +114 -5
- 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 +190 -8
- 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/message-agent/interpret.d.ts +2 -2
- package/dist/agent/message-agent/interpret.d.ts.map +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
- package/dist/agent/questions/interpret.d.ts +31 -0
- package/dist/agent/questions/interpret.d.ts.map +1 -0
- package/dist/agent/questions/question-card.d.ts +16 -0
- package/dist/agent/questions/question-card.d.ts.map +1 -0
- package/dist/agent/questions/question-composer.d.ts +15 -0
- package/dist/agent/questions/question-composer.d.ts.map +1 -0
- package/dist/agent/read/interpret.d.ts +8 -1
- package/dist/agent/read/interpret.d.ts.map +1 -1
- package/dist/agent/read/read-tool-view.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/agent/waits.d.ts +14 -0
- package/dist/agent/waits.d.ts.map +1 -0
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/edit-session.d.ts +11 -1
- package/dist/artifacts/edit-session.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 +278 -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 +11 -4
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
- package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
- package/dist/artifacts/renderers/canvas/canvas.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/canvas/controls.d.ts +15 -4
- package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
- package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
- package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
- 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-001c4gnk.js → chunk-4fex83k2.js} +19965 -13027
- package/dist/chunk-4fex83k2.js.map +239 -0
- package/dist/{chunk-5crvhjp2.js → chunk-4wm09prf.js} +1633 -1999
- package/dist/chunk-4wm09prf.js.map +27 -0
- package/dist/{chunk-fwb9mxwm.js → chunk-5sgac68y.js} +1 -1
- package/dist/{chunk-kes4ygmz.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 +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -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 +9 -1
- package/src/agent/agent-chat.tsx +57 -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/background/background-tool-row.tsx +24 -10
- package/src/agent/background/interpret.ts +60 -51
- 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 +96 -37
- package/src/agent/components/message-parts.tsx +390 -64
- 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 +92 -45
- package/src/agent/conversation.ts +203 -54
- package/src/agent/delegation/agent-exchange.tsx +53 -0
- package/src/agent/delegation/child-card.tsx +6 -40
- package/src/agent/delegation/child-parts.tsx +1 -84
- package/src/agent/delegation/child-work.tsx +19 -5
- package/src/agent/delegation/interpret.ts +64 -61
- package/src/agent/delegation/model.ts +1 -1
- package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
- package/src/agent/file-edits/interpret.ts +120 -0
- package/src/agent/hooks/use-agent-conversation.ts +360 -92
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +134 -16
- package/src/agent/i18n/fr.ts +122 -16
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +23 -2
- package/src/agent/message-agent/interpret.ts +4 -3
- package/src/agent/publish-artifact/interpret.ts +14 -5
- package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
- package/src/agent/questions/interpret.ts +90 -0
- package/src/agent/questions/question-card.tsx +57 -0
- package/src/agent/questions/question-composer.tsx +257 -0
- package/src/agent/react-router.tsx +2 -2
- package/src/agent/read/interpret.ts +34 -1
- package/src/agent/read/read-tool-view.tsx +20 -4
- 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 +33 -6
- 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/agent/waits.ts +50 -0
- package/src/artifacts/artifacts.css +434 -0
- package/src/artifacts/card-preview.tsx +6 -1
- package/src/artifacts/edit-session.tsx +15 -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 +14 -5
- 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 +192 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +44 -155
- package/src/artifacts/renderers/canvas/board.tsx +70 -8
- package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
- 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/canvas/controls.tsx +64 -30
- package/src/artifacts/renderers/canvas/focus.tsx +200 -56
- package/src/artifacts/renderers/canvas/gestures.ts +265 -0
- package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
- package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
- package/src/artifacts/renderers/canvas/page-size.ts +218 -0
- package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
- package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
- 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 +101 -41
- package/src/index.ts +8 -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-001c4gnk.js.map +0 -204
- package/dist/chunk-5crvhjp2.js.map +0 -28
- /package/dist/{chunk-fwb9mxwm.js.map → chunk-5sgac68y.js.map} +0 -0
- /package/dist/{chunk-kes4ygmz.js.map → chunk-69qgh20f.js.map} +0 -0
|
@@ -7,6 +7,7 @@ import { useAgentMessages } from "../i18n"
|
|
|
7
7
|
import type { LiveRunState } from "../live-run"
|
|
8
8
|
import { normalizeDurableParts } from "../parts"
|
|
9
9
|
import type { AgentMessage } from "../types"
|
|
10
|
+
import { AgentNote } from "./agent-exchange"
|
|
10
11
|
import type { AgentChild, WaitedChild } from "./interpret"
|
|
11
12
|
import { type ChildrenSource, useChildMessages } from "./use-children"
|
|
12
13
|
|
|
@@ -107,7 +108,11 @@ export function ChildWork({
|
|
|
107
108
|
{view.runs.map((run, index) => {
|
|
108
109
|
const atWork = run.status === "queued" || run.status === "running"
|
|
109
110
|
const own = byRun.get(run.id) ?? []
|
|
110
|
-
|
|
111
|
+
// Its work, and what the Agent sent it along the way; its task heads the panel already.
|
|
112
|
+
const work = own.filter(
|
|
113
|
+
(message) =>
|
|
114
|
+
message.role === "assistant" || message.parts.some((part) => part.type === "mail")
|
|
115
|
+
)
|
|
111
116
|
|
|
112
117
|
let body: ReactNode
|
|
113
118
|
if (work.length > 0) {
|
|
@@ -166,7 +171,7 @@ function continuedAfterAnswer(
|
|
|
166
171
|
return previous?.finishReason === "awaiting_answer"
|
|
167
172
|
}
|
|
168
173
|
|
|
169
|
-
/** One run's work, as its thread keeps it: its
|
|
174
|
+
/** One run's work, as its thread keeps it: its steps, and what the Agent sent it between them. */
|
|
170
175
|
const RunWork = memo(function RunWork({
|
|
171
176
|
messages,
|
|
172
177
|
threadId,
|
|
@@ -190,9 +195,18 @@ const RunWork = memo(function RunWork({
|
|
|
190
195
|
|
|
191
196
|
return (
|
|
192
197
|
<>
|
|
193
|
-
{bodies.map((parts, position) =>
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
{bodies.map((parts, position) => {
|
|
199
|
+
const message = messages[position]
|
|
200
|
+
// What the Agent sent it, an answer or a message, reads on the Agent's side.
|
|
201
|
+
if (message?.role === "user") {
|
|
202
|
+
return message.parts.flatMap((part, index) =>
|
|
203
|
+
part.type === "mail"
|
|
204
|
+
? [<AgentNote key={`${message.id}:${index}`} text={part.text} />]
|
|
205
|
+
: []
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
return <AssistantBody key={message?.id ?? position} parts={parts} nested />
|
|
209
|
+
})}
|
|
196
210
|
</>
|
|
197
211
|
)
|
|
198
212
|
})
|
|
@@ -2,6 +2,8 @@ import type { AgentChild } from "@sixb/client"
|
|
|
2
2
|
import { type AgentConversationMessage, normalizedTool } from "../conversation"
|
|
3
3
|
import type { AgentMessages } from "../i18n/en"
|
|
4
4
|
import { type NormalizedPart, type NormalizedTool, toolResultValue } from "../parts"
|
|
5
|
+
import { askedText, isAskTool } from "../questions/interpret"
|
|
6
|
+
import { isCommandId, isStop, namedIds, waitsForChildren } from "../waits"
|
|
5
7
|
|
|
6
8
|
// What the parent's own parts say about the sub-agents it delegated to: which it spawned, what it
|
|
7
9
|
// told or answered each, and what each asked. A reader of the thread always has them, even without
|
|
@@ -24,13 +26,7 @@ export interface SpawnedChild {
|
|
|
24
26
|
readonly pending: boolean
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
/**
|
|
28
|
-
export interface ChildExchange {
|
|
29
|
-
readonly kind: "told" | "asked" | "answered"
|
|
30
|
-
readonly text: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** What `wait_agent` last said about one of a child's runs. */
|
|
29
|
+
/** What `wait`, or a `stop`, last said about one of a child's runs. */
|
|
34
30
|
export interface WaitedChild {
|
|
35
31
|
readonly status: string
|
|
36
32
|
readonly text?: string
|
|
@@ -41,7 +37,6 @@ export interface WaitedChild {
|
|
|
41
37
|
export interface ThreadDelegation {
|
|
42
38
|
/** The turn that spawned each child. */
|
|
43
39
|
readonly spawnedBy: ReadonlyMap<string, string | null>
|
|
44
|
-
readonly exchanges: ReadonlyMap<string, readonly ChildExchange[]>
|
|
45
40
|
/** By the id of the run waited on: a child's first run, or one that continued it. */
|
|
46
41
|
readonly waited: ReadonlyMap<string, WaitedChild>
|
|
47
42
|
/**
|
|
@@ -93,44 +88,56 @@ export interface DelegationTurn {
|
|
|
93
88
|
readonly tools: readonly NormalizedTool[]
|
|
94
89
|
}
|
|
95
90
|
|
|
96
|
-
|
|
91
|
+
/** Earlier threads hold `wait_agent`; a `wait` or a `stop` for commands alone is left out. */
|
|
92
|
+
const DELEGATION_TOOLS = new Set(["spawn_agent", "message_agent", "wait", "stop", "wait_agent"])
|
|
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
|
+
}
|
|
97
118
|
|
|
98
119
|
/** The delegation calls of each reply, oldest first, the one streaming last. */
|
|
99
120
|
export function delegationTurns(
|
|
100
121
|
messages: readonly AgentConversationMessage[]
|
|
101
122
|
): readonly DelegationTurn[] {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
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
|
|
109
129
|
}
|
|
110
130
|
|
|
111
131
|
/**
|
|
112
|
-
* Read the thread's sub-agents from its turns, oldest first, the one streaming now last.
|
|
113
|
-
*
|
|
132
|
+
* Read the thread's sub-agents from its turns, oldest first, the one streaming now last. What
|
|
133
|
+
* passed between the Agent and a child reads in the child's panel, from its own thread.
|
|
114
134
|
*/
|
|
115
135
|
export function readThreadDelegation(turns: readonly DelegationTurn[]): ThreadDelegation {
|
|
116
136
|
const spawnedBy = new Map<string, string | null>()
|
|
117
|
-
const exchanges = new Map<string, ChildExchange[]>()
|
|
118
137
|
const waited = new Map<string, WaitedChild>()
|
|
119
138
|
const owners = new Map<string, string>()
|
|
120
139
|
const ownersByTurn = new Map<string, ReadonlyMap<string, string>>()
|
|
121
140
|
|
|
122
|
-
const add = (key: string, exchange: ChildExchange) => {
|
|
123
|
-
const owner = owners.get(key)
|
|
124
|
-
if (!owner) return
|
|
125
|
-
const list = exchanges.get(owner) ?? []
|
|
126
|
-
// A question is listed by every wait until it is answered: it reads once.
|
|
127
|
-
const repeated = list.some(
|
|
128
|
-
(earlier) => earlier.kind === exchange.kind && earlier.text === exchange.text
|
|
129
|
-
)
|
|
130
|
-
if (exchange.kind === "asked" && repeated) return
|
|
131
|
-
exchanges.set(owner, [...list, exchange])
|
|
132
|
-
}
|
|
133
|
-
|
|
134
141
|
const read = (runId: string | null, tool: NormalizedTool) => {
|
|
135
142
|
const child = spawnedChild(tool)
|
|
136
143
|
if (child && !child.pending) {
|
|
@@ -139,28 +146,15 @@ export function readThreadDelegation(turns: readonly DelegationTurn[]): ThreadDe
|
|
|
139
146
|
return
|
|
140
147
|
}
|
|
141
148
|
|
|
142
|
-
if (tool
|
|
143
|
-
const input = isRecord(tool.input) ? tool.input : {}
|
|
144
|
-
const output = toolResultValue(tool.output)
|
|
145
|
-
if (typeof input.key !== "string" || typeof input.text !== "string") return
|
|
146
|
-
const kind = isRecord(output) && output.delivery === "answer" ? "answered" : "told"
|
|
147
|
-
add(input.key.trim(), { kind, text: input.text.trim() })
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (tool.toolName !== "wait_agent" || tool.state !== "output-available") return
|
|
149
|
+
if (!waitsForChildren(tool) || tool.state !== "output-available") return
|
|
152
150
|
const output = toolResultValue(tool.output)
|
|
153
151
|
if (!isRecord(output)) return
|
|
154
152
|
|
|
155
|
-
for (const question of Array.isArray(output.questions) ? output.questions : []) {
|
|
156
|
-
if (!isRecord(question)) continue
|
|
157
|
-
if (typeof question.key !== "string" || typeof question.text !== "string") continue
|
|
158
|
-
add(question.key, { kind: "asked", text: question.text.trim() })
|
|
159
|
-
}
|
|
160
153
|
for (const result of Array.isArray(output.results) ? output.results : []) {
|
|
161
154
|
if (!isRecord(result) || typeof result.runId !== "string") continue
|
|
162
155
|
if (typeof result.status !== "string") continue
|
|
163
|
-
|
|
156
|
+
// Named by its key, as `wait` takes it, or by its run id, as `wait_agent` did.
|
|
157
|
+
waited.set(owners.get(result.runId) ?? result.runId, {
|
|
164
158
|
status: result.status,
|
|
165
159
|
...(typeof result.text === "string" ? { text: result.text } : {}),
|
|
166
160
|
...(isRecord(result.error) && typeof result.error.message === "string"
|
|
@@ -177,7 +171,6 @@ export function readThreadDelegation(turns: readonly DelegationTurn[]): ThreadDe
|
|
|
177
171
|
|
|
178
172
|
return {
|
|
179
173
|
spawnedBy,
|
|
180
|
-
exchanges,
|
|
181
174
|
waited,
|
|
182
175
|
ownerOf: (key, runId) =>
|
|
183
176
|
(runId ? ownersByTurn.get(runId) : undefined)?.get(key) ?? owners.get(key),
|
|
@@ -273,14 +266,13 @@ export function childTitle(key: string): string {
|
|
|
273
266
|
return words ? `${words.charAt(0).toUpperCase()}${words.slice(1)}` : key
|
|
274
267
|
}
|
|
275
268
|
|
|
276
|
-
/** The question a child at work waits on, from its live parts: its `
|
|
269
|
+
/** The question a child at work waits on, from its live parts: its `ask` call in flight. */
|
|
277
270
|
export function liveQuestion(parts: readonly NormalizedPart[]): string | null {
|
|
278
271
|
for (let index = parts.length - 1; index >= 0; index -= 1) {
|
|
279
272
|
const part = parts[index]
|
|
280
|
-
if (part?.kind !== "tool" || part.tool.toolName
|
|
273
|
+
if (part?.kind !== "tool" || !isAskTool(part.tool.toolName)) continue
|
|
281
274
|
if (part.tool.state !== "input-available") return null
|
|
282
|
-
|
|
283
|
-
return typeof input.question === "string" ? input.question.trim() : null
|
|
275
|
+
return askedText(part.tool.input) || null
|
|
284
276
|
}
|
|
285
277
|
return null
|
|
286
278
|
}
|
|
@@ -294,11 +286,14 @@ export function formatWorked(ms: number, messages: AgentMessages["delegation"]):
|
|
|
294
286
|
return messages.hours(Math.floor(minutes / 60), minutes % 60)
|
|
295
287
|
}
|
|
296
288
|
|
|
297
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* The children a `wait` or a `stop` names, by title: `wait` takes their keys, `wait_agent` took
|
|
291
|
+
* run ids, titled when the parts spawned them. Its background commands are not children.
|
|
292
|
+
*/
|
|
298
293
|
function waitedKeys(tool: NormalizedTool, keys: ReadonlyMap<string, string>): readonly string[] {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
294
|
+
return namedIds(tool)
|
|
295
|
+
.filter((id) => !isCommandId(id))
|
|
296
|
+
.map((id) => keys.get(id) ?? (tool.toolName === "wait_agent" ? "" : childTitle(id)))
|
|
302
297
|
}
|
|
303
298
|
|
|
304
299
|
/**
|
|
@@ -330,13 +325,11 @@ export function describeDelegationTool(
|
|
|
330
325
|
}
|
|
331
326
|
}
|
|
332
327
|
|
|
333
|
-
if (tool.toolName
|
|
334
|
-
|
|
335
|
-
const question = typeof input.question === "string" ? input.question.trim() : ""
|
|
336
|
-
return { title: labels.askedAgent(question), running: labels.states.asking }
|
|
328
|
+
if (isAskTool(tool.toolName)) {
|
|
329
|
+
return { title: labels.askedAgent(askedText(tool.input)), running: labels.states.asking }
|
|
337
330
|
}
|
|
338
331
|
|
|
339
|
-
if (tool
|
|
332
|
+
if (waitsForChildren(tool)) {
|
|
340
333
|
const keys = new Map<string, string>()
|
|
341
334
|
for (const part of parts) {
|
|
342
335
|
if (part.kind !== "tool") continue
|
|
@@ -345,6 +338,16 @@ export function describeDelegationTool(
|
|
|
345
338
|
}
|
|
346
339
|
const waitedFor = waitedKeys(tool, keys)
|
|
347
340
|
const named = waitedFor.every(Boolean) ? waitedFor : []
|
|
341
|
+
if (isStop(tool)) {
|
|
342
|
+
const name = named[0] ?? ""
|
|
343
|
+
if (tool.state === "output-error") {
|
|
344
|
+
const failed = labels.stopAgentFailed(name)
|
|
345
|
+
return { title: failed, running: failed }
|
|
346
|
+
}
|
|
347
|
+
return tool.state === "output-available"
|
|
348
|
+
? { title: labels.stoppedAgent(name), running: labels.stoppedAgent(name) }
|
|
349
|
+
: { title: labels.stoppingAgent(name), running: labels.stoppingAgent(name) }
|
|
350
|
+
}
|
|
348
351
|
const waiting =
|
|
349
352
|
named.length === 1
|
|
350
353
|
? labels.waitingFor(named[0] ?? "")
|
|
@@ -224,7 +224,7 @@ function shortName(name: string): string {
|
|
|
224
224
|
return `${(word > LINE_NAME_LENGTH / 2 ? cut.slice(0, word) : cut).replace(/[\s,.:;-]+$/, "")}…`
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
/** What `
|
|
227
|
+
/** What `wait`, or a `stop`, last said of any of the child's runs. */
|
|
228
228
|
function waitedFor(
|
|
229
229
|
waited: ReadonlyMap<string, WaitedChild>,
|
|
230
230
|
child: SpawnedChild,
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@sixb/ui/components"
|
|
2
|
+
import { cn } from "@sixb/ui/lib/utils"
|
|
3
|
+
import { ChevronRight, FilePen, FilePlus } from "lucide-react"
|
|
4
|
+
import { ActivityStatusText } from "../components/activity-status"
|
|
5
|
+
import { useAgentMessages } from "../i18n"
|
|
6
|
+
import type { NormalizedTool } from "../parts"
|
|
7
|
+
import { type DiffLine, describeEdit, describeWrite, type FileEditDescription } from "./interpret"
|
|
8
|
+
|
|
9
|
+
/** A change the agent made to part of a file: its name and `+3 −1`, opening to the diff. */
|
|
10
|
+
export function EditToolView({ tool }: { tool: NormalizedTool }) {
|
|
11
|
+
const messages = useAgentMessages()
|
|
12
|
+
return (
|
|
13
|
+
<FileEditRow tool={tool} description={describeEdit(tool, messages)} icon={FilePen} counts />
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A file the agent created or replaced whole: its name and lines, opening to what it wrote. */
|
|
18
|
+
export function WriteToolView({ tool }: { tool: NormalizedTool }) {
|
|
19
|
+
const messages = useAgentMessages()
|
|
20
|
+
return <FileEditRow tool={tool} description={describeWrite(tool, messages)} icon={FilePlus} />
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function FileEditRow({
|
|
24
|
+
tool,
|
|
25
|
+
description,
|
|
26
|
+
icon: Icon,
|
|
27
|
+
counts = false,
|
|
28
|
+
}: {
|
|
29
|
+
tool: NormalizedTool
|
|
30
|
+
description: FileEditDescription
|
|
31
|
+
icon: typeof FilePen
|
|
32
|
+
/** Show the lines added and removed, in the diff's colors, rather than the detail text. */
|
|
33
|
+
counts?: boolean
|
|
34
|
+
}) {
|
|
35
|
+
const running = tool.state === "input-streaming" || tool.state === "input-available"
|
|
36
|
+
const error = tool.state === "output-error"
|
|
37
|
+
const label = error
|
|
38
|
+
? description.failedTitle
|
|
39
|
+
: running
|
|
40
|
+
? description.runningTitle
|
|
41
|
+
: description.title
|
|
42
|
+
|
|
43
|
+
if (running) {
|
|
44
|
+
return (
|
|
45
|
+
<div className="flex w-fit max-w-full items-center gap-1.5 text-[13px] leading-normal text-muted-foreground">
|
|
46
|
+
<Icon className="size-3.5 shrink-0" />
|
|
47
|
+
<ActivityStatusText label={label} className="font-medium shimmer" />
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Collapsible>
|
|
54
|
+
<CollapsibleTrigger className="group flex w-fit max-w-full items-center gap-1.5 text-[13px] leading-normal text-muted-foreground transition-colors hover:text-foreground">
|
|
55
|
+
<Icon className="size-3.5 shrink-0" />
|
|
56
|
+
<span className="min-w-0 truncate font-medium">{label}</span>
|
|
57
|
+
{error || !description.detail ? null : counts ? (
|
|
58
|
+
<span className="shrink-0 font-mono text-[11px] tabular-nums">
|
|
59
|
+
<span className="text-emerald-600 dark:text-emerald-400">+{description.added}</span>{" "}
|
|
60
|
+
<span className="text-red-600 dark:text-red-400">−{description.removed}</span>
|
|
61
|
+
</span>
|
|
62
|
+
) : (
|
|
63
|
+
<span className="min-w-0 shrink truncate text-muted-foreground/60">
|
|
64
|
+
{description.detail}
|
|
65
|
+
</span>
|
|
66
|
+
)}
|
|
67
|
+
<ChevronRight className="size-3.5 shrink-0 opacity-0 transition-all group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[state=open]:rotate-90 group-data-[state=open]:opacity-100" />
|
|
68
|
+
</CollapsibleTrigger>
|
|
69
|
+
<CollapsibleContent>
|
|
70
|
+
<div className="mt-3 min-w-0 space-y-2 text-xs">
|
|
71
|
+
{description.path ? (
|
|
72
|
+
<p className="truncate font-mono text-[10px] text-muted-foreground/60">
|
|
73
|
+
{description.path}
|
|
74
|
+
</p>
|
|
75
|
+
) : null}
|
|
76
|
+
{error ? (
|
|
77
|
+
<pre className="scrollbar-thin max-h-60 overflow-auto rounded bg-muted/50 p-2 text-[11px] leading-relaxed text-foreground">
|
|
78
|
+
{tool.errorText?.trim()}
|
|
79
|
+
</pre>
|
|
80
|
+
) : (
|
|
81
|
+
<DiffBlock lines={description.lines} />
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
</CollapsibleContent>
|
|
85
|
+
</Collapsible>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const LINE_CLASS: Record<DiffLine["kind"], string> = {
|
|
90
|
+
hunk: "text-muted-foreground/60",
|
|
91
|
+
added: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
|
|
92
|
+
removed: "bg-red-500/10 text-red-700 dark:text-red-300",
|
|
93
|
+
context: "text-foreground/80",
|
|
94
|
+
note: "text-muted-foreground/60 italic",
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const LINE_MARK: Record<DiffLine["kind"], string> = {
|
|
98
|
+
hunk: "",
|
|
99
|
+
added: "+",
|
|
100
|
+
removed: "−",
|
|
101
|
+
context: " ",
|
|
102
|
+
note: "",
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function DiffBlock({ lines }: { lines: readonly DiffLine[] }) {
|
|
106
|
+
return (
|
|
107
|
+
<pre className="scrollbar-thin max-h-72 overflow-auto rounded bg-muted/50 py-1.5 text-[11px] leading-relaxed">
|
|
108
|
+
{lines.map((line, index) => (
|
|
109
|
+
<div
|
|
110
|
+
// Lines of one diff never reorder: the index is their identity.
|
|
111
|
+
key={index}
|
|
112
|
+
className={cn("flex min-w-max gap-2 px-2", LINE_CLASS[line.kind])}
|
|
113
|
+
>
|
|
114
|
+
{line.kind === "hunk" || line.kind === "note" ? (
|
|
115
|
+
<span>{line.text}</span>
|
|
116
|
+
) : (
|
|
117
|
+
<>
|
|
118
|
+
<span className="w-2 shrink-0 select-none opacity-70">{LINE_MARK[line.kind]}</span>
|
|
119
|
+
<span>{line.text || " "}</span>
|
|
120
|
+
</>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
))}
|
|
124
|
+
</pre>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type AgentMessages, en } from "../i18n/en"
|
|
2
|
+
import type { NormalizedTool } from "../parts"
|
|
3
|
+
|
|
4
|
+
/** One line of the unified diff `edit` returns. */
|
|
5
|
+
export interface DiffLine {
|
|
6
|
+
readonly kind: "hunk" | "added" | "removed" | "context" | "note"
|
|
7
|
+
readonly text: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FileEditDescription {
|
|
11
|
+
/** The path the call named, or empty until it streams in. */
|
|
12
|
+
readonly path: string
|
|
13
|
+
readonly title: string
|
|
14
|
+
readonly runningTitle: string
|
|
15
|
+
readonly failedTitle: string
|
|
16
|
+
/** `+3 −1` for an edit, the line count for a write, once it has a result. */
|
|
17
|
+
readonly detail?: string
|
|
18
|
+
readonly added: number
|
|
19
|
+
readonly removed: number
|
|
20
|
+
/** The edit's diff, or the written file's contents as added lines. */
|
|
21
|
+
readonly lines: readonly DiffLine[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function describeEdit(
|
|
25
|
+
tool: Pick<NormalizedTool, "input" | "output">,
|
|
26
|
+
messages: AgentMessages = en
|
|
27
|
+
): FileEditDescription {
|
|
28
|
+
const m = messages.edit
|
|
29
|
+
const path = stringField(tool.input, "path") ?? stringField(tool.output, "path") ?? ""
|
|
30
|
+
const name = fileName(path)
|
|
31
|
+
const diff = stringField(tool.output, "diff")
|
|
32
|
+
const lines = diff === undefined ? [] : parseDiff(diff)
|
|
33
|
+
|
|
34
|
+
// The diff is cut on a large edit, so the edit counts its lines; an output stored before it
|
|
35
|
+
// did carries only the diff.
|
|
36
|
+
const added =
|
|
37
|
+
numberField(tool.output, "added") ?? lines.filter((line) => line.kind === "added").length
|
|
38
|
+
const removed =
|
|
39
|
+
numberField(tool.output, "removed") ?? lines.filter((line) => line.kind === "removed").length
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
path,
|
|
43
|
+
title: m.title(name),
|
|
44
|
+
runningTitle: m.running(name),
|
|
45
|
+
failedTitle: m.failed(name),
|
|
46
|
+
...(diff === undefined ? {} : { detail: `+${added} −${removed}` }),
|
|
47
|
+
added,
|
|
48
|
+
removed,
|
|
49
|
+
lines,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function describeWrite(
|
|
54
|
+
tool: Pick<NormalizedTool, "input" | "output">,
|
|
55
|
+
messages: AgentMessages = en
|
|
56
|
+
): FileEditDescription {
|
|
57
|
+
const m = messages.write
|
|
58
|
+
const path = stringField(tool.input, "path") ?? stringField(tool.output, "path") ?? ""
|
|
59
|
+
const name = fileName(path)
|
|
60
|
+
const content = stringField(tool.input, "content")
|
|
61
|
+
const created = booleanField(tool.output, "created")
|
|
62
|
+
const lineCount = numberField(tool.output, "lines")
|
|
63
|
+
const lines: DiffLine[] =
|
|
64
|
+
content === undefined
|
|
65
|
+
? []
|
|
66
|
+
: contentLines(content).map((text) => ({ kind: "added" as const, text }))
|
|
67
|
+
return {
|
|
68
|
+
path,
|
|
69
|
+
title: created === false ? m.replaced(name) : m.created(name),
|
|
70
|
+
runningTitle: m.running(name),
|
|
71
|
+
failedTitle: m.failed(name),
|
|
72
|
+
...(lineCount === undefined ? {} : { detail: m.lines(lineCount) }),
|
|
73
|
+
added: lines.length,
|
|
74
|
+
removed: 0,
|
|
75
|
+
lines,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A unified diff's lines by kind; `… 3 more hunks` and anything unexpected are notes. */
|
|
80
|
+
export function parseDiff(diff: string): DiffLine[] {
|
|
81
|
+
const lines = diff.endsWith("\n") ? diff.slice(0, -1).split("\n") : diff.split("\n")
|
|
82
|
+
return lines.map((line): DiffLine => {
|
|
83
|
+
if (line.startsWith("@@")) return { kind: "hunk", text: line }
|
|
84
|
+
if (line.startsWith("+")) return { kind: "added", text: line.slice(1) }
|
|
85
|
+
if (line.startsWith("-")) return { kind: "removed", text: line.slice(1) }
|
|
86
|
+
if (line.startsWith(" ")) return { kind: "context", text: line.slice(1) }
|
|
87
|
+
return { kind: "note", text: line }
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const MAX_CONTENT_LINES = 400
|
|
92
|
+
|
|
93
|
+
function contentLines(content: string): string[] {
|
|
94
|
+
if (content === "") return []
|
|
95
|
+
const lines = (content.endsWith("\n") ? content.slice(0, -1) : content).split("\n")
|
|
96
|
+
return lines.length > MAX_CONTENT_LINES ? lines.slice(0, MAX_CONTENT_LINES) : lines
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function fileName(path: string): string {
|
|
100
|
+
return path.split("/").filter(Boolean).at(-1) ?? ""
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function stringField(value: unknown, key: string): string | undefined {
|
|
104
|
+
const field = isRecord(value) ? value[key] : undefined
|
|
105
|
+
return typeof field === "string" ? field : undefined
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function numberField(value: unknown, key: string): number | undefined {
|
|
109
|
+
const field = isRecord(value) ? value[key] : undefined
|
|
110
|
+
return typeof field === "number" && Number.isInteger(field) ? field : undefined
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function booleanField(value: unknown, key: string): boolean | undefined {
|
|
114
|
+
const field = isRecord(value) ? value[key] : undefined
|
|
115
|
+
return typeof field === "boolean" ? field : undefined
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
119
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
120
|
+
}
|