gsd-pi 2.73.0 → 2.73.1-dev.1040fb0
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/dist/cli.js +0 -47
- package/dist/help-text.js +1 -1
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +9 -3
- package/dist/resources/extensions/gsd/auto-dispatch.js +5 -3
- package/dist/resources/extensions/gsd/auto-model-selection.js +54 -11
- package/dist/resources/extensions/gsd/auto-prompts.js +9 -6
- package/dist/resources/extensions/gsd/auto-start.js +20 -6
- package/dist/resources/extensions/gsd/auto.js +5 -1
- package/dist/resources/extensions/gsd/bootstrap/crash-log.js +31 -0
- package/dist/resources/extensions/gsd/bootstrap/register-extension.js +18 -7
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +6 -1
- package/dist/resources/extensions/gsd/commands-handlers.js +8 -2
- package/dist/resources/extensions/gsd/crash-recovery.js +51 -0
- package/dist/resources/extensions/gsd/gsd-db.js +36 -2
- package/dist/resources/extensions/gsd/milestone-actions.js +19 -1
- package/dist/resources/extensions/gsd/preferences-models.js +43 -0
- package/dist/resources/extensions/gsd/preferences-types.js +1 -0
- package/dist/resources/extensions/gsd/preferences-validation.js +22 -0
- package/dist/startup-model-validation.js +8 -5
- package/dist/update-check.d.ts +1 -0
- package/dist/update-check.js +13 -5
- package/dist/update-cmd.js +4 -3
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +15 -15
- package/dist/web/standalone/.next/build-manifest.json +3 -3
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/required-server-files.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error/page.js +3 -3
- package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found/page.js +2 -2
- package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +3 -3
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/boot/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/browse-directories/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/browse-directories/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/dev-mode/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/dev-mode/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/experimental/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/experimental/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/notifications/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/notifications/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/preferences/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/preferences/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/remote-questions/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/remote-questions/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/events/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/session/events/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/shutdown/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/input/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/resize/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +4 -4
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/upload/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/upload/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/update/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +4 -4
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +3 -3
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/page.js +2 -2
- package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +15 -15
- package/dist/web/standalone/.next/server/chunks/63.js +3 -3
- package/dist/web/standalone/.next/server/chunks/6897.js +1 -1
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
- package/dist/web/standalone/.next/server/middleware.js +2 -2
- package/dist/web/standalone/.next/server/next-font-manifest.js +1 -1
- package/dist/web/standalone/.next/server/next-font-manifest.json +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/web/standalone/.next/static/chunks/app/_not-found/{page-2f24283c162b6ab3.js → page-f2a7482d42a5614b.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/app/{layout-9ecfd95f343793f0.js → layout-a16c7a7ecdf0c2cf.js} +1 -1
- package/dist/web/standalone/.next/static/chunks/app/page-f1e30ab6bb269149.js +1 -0
- package/dist/web/standalone/.next/static/chunks/main-app-fdab67f7802d7832.js +1 -0
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-459824ffb8c323dd.js +1 -0
- package/dist/web/standalone/node_modules/node-pty/build/Makefile +2 -2
- package/dist/web/standalone/node_modules/node-pty/build/Release/pty.node +0 -0
- package/dist/web/standalone/node_modules/node-pty/build/pty.target.mk +14 -14
- package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api.target.mk +14 -14
- package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api_except.target.mk +14 -14
- package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api_maybe.target.mk +14 -14
- package/dist/web/standalone/server.js +1 -1
- package/package.json +1 -1
- package/packages/pi-ai/dist/index.d.ts +1 -0
- package/packages/pi-ai/dist/index.d.ts.map +1 -1
- package/packages/pi-ai/dist/index.js +1 -0
- package/packages/pi-ai/dist/index.js.map +1 -1
- package/packages/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/overflow.js +12 -0
- package/packages/pi-ai/dist/utils/overflow.js.map +1 -1
- package/packages/pi-ai/dist/utils/tests/overflow.test.d.ts +2 -0
- package/packages/pi-ai/dist/utils/tests/overflow.test.d.ts.map +1 -0
- package/packages/pi-ai/dist/utils/tests/overflow.test.js +50 -0
- package/packages/pi-ai/dist/utils/tests/overflow.test.js.map +1 -0
- package/packages/pi-ai/src/index.ts +4 -0
- package/packages/pi-ai/src/utils/overflow.ts +14 -1
- package/packages/pi-ai/src/utils/tests/overflow.test.ts +58 -0
- package/packages/pi-coding-agent/dist/core/auth-storage.js +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js +27 -0
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +175 -8
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.js +5 -5
- package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-utils.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/compaction-utils.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-utils.test.js +45 -0
- package/packages/pi-coding-agent/dist/core/compaction-utils.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.js +25 -68
- package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts +12 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +51 -26
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +95 -21
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js +63 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map +1 -0
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/auth-storage.test.ts +38 -0
- package/packages/pi-coding-agent/src/core/auth-storage.ts +1 -1
- package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +198 -8
- package/packages/pi-coding-agent/src/core/compaction/utils.ts +5 -5
- package/packages/pi-coding-agent/src/core/compaction-utils.test.ts +50 -0
- package/packages/pi-coding-agent/src/core/model-resolver.ts +26 -70
- package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +62 -26
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.test.ts +71 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +115 -26
- package/pkg/package.json +1 -1
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +12 -4
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +23 -2
- package/src/resources/extensions/gsd/auto-dispatch.ts +5 -0
- package/src/resources/extensions/gsd/auto-model-selection.ts +85 -11
- package/src/resources/extensions/gsd/auto-prompts.ts +9 -3
- package/src/resources/extensions/gsd/auto-start.ts +27 -6
- package/src/resources/extensions/gsd/auto.ts +5 -0
- package/src/resources/extensions/gsd/bootstrap/crash-log.ts +32 -0
- package/src/resources/extensions/gsd/bootstrap/register-extension.ts +19 -7
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +8 -1
- package/src/resources/extensions/gsd/commands-handlers.ts +8 -2
- package/src/resources/extensions/gsd/crash-recovery.ts +59 -0
- package/src/resources/extensions/gsd/gsd-db.ts +52 -2
- package/src/resources/extensions/gsd/milestone-actions.ts +19 -1
- package/src/resources/extensions/gsd/preferences-models.ts +41 -0
- package/src/resources/extensions/gsd/preferences-types.ts +12 -0
- package/src/resources/extensions/gsd/preferences-validation.ts +23 -0
- package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +51 -2
- package/src/resources/extensions/gsd/tests/crash-handler-secondary.test.ts +235 -0
- package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +137 -1
- package/src/resources/extensions/gsd/tests/gsd-db.test.ts +59 -1
- package/src/resources/extensions/gsd/tests/model-isolation.test.ts +91 -2
- package/src/resources/extensions/gsd/tests/park-milestone.test.ts +64 -0
- package/src/resources/extensions/gsd/tests/preferences.test.ts +47 -0
- package/src/resources/extensions/gsd/tests/subagent-model-dispatch.test.ts +267 -0
- package/dist/web/standalone/.next/static/chunks/app/page-7115e62689b5fd84.js +0 -1
- package/dist/web/standalone/.next/static/chunks/main-app-d3d4c336195465f9.js +0 -1
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-ab5a8926e07ec673.js +0 -1
- /package/dist/web/standalone/.next/static/{KSZ2dcC3p4z6lOmUpPpzr → 5dzOW4v8Vz23I5xRsiNSk}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{KSZ2dcC3p4z6lOmUpPpzr → 5dzOW4v8Vz23I5xRsiNSk}/_ssgManifest.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-controller.js","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,kGAAkG;AAClG,IAAI,yBAAyB,GAAG,CAAC,CAAC;AAElC,SAAS,0BAA0B,CAAC,OAAgC;IACnE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAC1B,CAAC,CAAC,EAAE,EAAE,CACL,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;WAC1E,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAC7F,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAgC;IAC/D,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC;AACzF,CAAC;AAED,+DAA+D;AAC/D,IAAI,cAAc,G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E,CAAC;YACxB,MAAM;IACR,CAAC;AACF,CAAC","sourcesContent":["import { Loader, Markdown, Spacer, Text } from \"@gsd/pi-tui\";\n\nimport type { InteractiveModeEvent, InteractiveModeStateHost } from \"../interactive-mode-state.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { AssistantMessageComponent } from \"../components/assistant-message.js\";\nimport { ToolExecutionComponent } from \"../components/tool-execution.js\";\nimport { DynamicBorder } from \"../components/dynamic-border.js\";\nimport { appKey } from \"../components/keybinding-hints.js\";\n\n// Tracks the last processed content index to avoid re-scanning all blocks on every message_update\nlet lastProcessedContentIndex = 0;\n\nfunction hasVisibleAssistantContent(message: { content: Array<any> }): boolean {\n\treturn message.content.some(\n\t\t(c) =>\n\t\t\t(c.type === \"text\" && typeof c.text === \"string\" && c.text.trim().length > 0)\n\t\t\t|| (c.type === \"thinking\" && typeof c.thinking === \"string\" && c.thinking.trim().length > 0),\n\t);\n}\n\nfunction hasAssistantToolBlocks(message: { content: Array<any> }): boolean {\n\treturn message.content.some((c) => c.type === \"toolCall\" || c.type === \"serverToolUse\");\n}\n\n// Tracks the latest assistant text for the pinned message zone\nlet lastPinnedText = \"\";\n// Whether any tool execution has been added in this assistant turn (triggers pinned display)\nlet hasToolsInTurn = false;\n// Reference to the pinned border so we can toggle its label between working/idle\nlet pinnedBorder: DynamicBorder | undefined;\n// Reference to the pinned markdown component below the border\nlet pinnedTextComponent: Markdown | undefined;\n\nexport async function handleAgentEvent(host: InteractiveModeStateHost & {\n\tinit: () => Promise<void>;\n\tgetMarkdownThemeWithSettings: () => any;\n\taddMessageToChat: (message: any, options?: any) => void;\n\tformatWebSearchResult: (content: unknown) => string;\n\tgetRegisteredToolDefinition: (toolName: string) => any;\n\tcheckShutdownRequested: () => Promise<void>;\n\trebuildChatFromMessages: () => void;\n\tflushCompactionQueue: (options?: { willRetry?: boolean }) => Promise<void>;\n\tshowStatus: (message: string) => void;\n\tshowError: (message: string) => void;\n\tupdatePendingMessagesDisplay: () => void;\n\tupdateTerminalTitle: () => void;\n\tupdateEditorBorderColor: () => void;\n\tpendingMessagesContainer: { clear: () => void };\n}, event: InteractiveModeEvent): Promise<void> {\n\tif (!host.isInitialized) {\n\t\tawait host.init();\n\t}\n\n\thost.footer.invalidate();\n\n\t// Reset content index tracker and pinned state when a new assistant message starts\n\tif (event.type === \"message_start\" && event.message.role === \"assistant\") {\n\t\tlastProcessedContentIndex = 0;\n\t\tlastPinnedText = \"\";\n\t\thasToolsInTurn = false;\n\t\tif (pinnedBorder) pinnedBorder.stopSpinner();\n\t\tpinnedBorder = undefined;\n\t\tpinnedTextComponent = undefined;\n\t\thost.pinnedMessageContainer.clear();\n\t}\n\n\tswitch (event.type) {\n\t\tcase \"session_state_changed\":\n\t\t\tswitch (event.reason) {\n\t\t\t\tcase \"new_session\":\n\t\t\t\tcase \"switch_session\":\n\t\t\t\tcase \"fork\":\n\t\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t\thost.pendingMessagesContainer.clear();\n\t\t\t\t\thost.pinnedMessageContainer.clear();\n\t\t\t\t\tlastPinnedText = \"\";\n\t\t\t\t\thasToolsInTurn = false;\n\t\t\t\t\tif (pinnedBorder) pinnedBorder.stopSpinner();\n\t\t\t\t\tpinnedBorder = undefined;\n\t\t\t\t\tpinnedTextComponent = undefined;\n\t\t\t\t\thost.compactionQueuedMessages = [];\n\t\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_session_name\":\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_model\":\n\t\t\t\tcase \"set_thinking_level\":\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tdefault:\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t}\n\t\tcase \"agent_start\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t}\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t}\n\t\t\thost.statusContainer.clear();\n\t\t\thost.loadingAnimation = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\thost.defaultWorkingMessage,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.loadingAnimation);\n\t\t\tif (host.pendingWorkingMessage !== undefined) {\n\t\t\t\tif (host.pendingWorkingMessage) {\n\t\t\t\t\thost.loadingAnimation.setMessage(host.pendingWorkingMessage);\n\t\t\t\t}\n\t\t\t\thost.pendingWorkingMessage = undefined;\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"message_start\":\n\t\t\tif (event.message.role === \"custom\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"user\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\t// External-tool providers can stream multiple assistant turns through\n\t\t\t\t// one response. Delay component creation until visible assistant text\n\t\t\t\t// arrives so tool outputs keep chronological ordering.\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_update\":\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tconst innerEvent = event.assistantMessageEvent;\n\n\t\t\t\tlet externalToolResult:\n\t\t\t\t\t| { toolCallId: string; content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; details: Record<string, unknown>; isError: boolean }\n\t\t\t\t\t| undefined;\n\t\t\t\tif (innerEvent.type === \"toolcall_end\" && innerEvent.toolCall) {\n\t\t\t\t\tconst tc = innerEvent.toolCall as any;\n\t\t\t\t\tconst ext = tc.externalResult;\n\t\t\t\t\tif (ext) {\n\t\t\t\t\t\texternalToolResult = {\n\t\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\t\tcontent: ext.content ?? [{ type: \"text\", text: \"\" }],\n\t\t\t\t\t\t\tdetails: ext.details ?? {},\n\t\t\t\t\t\t\tisError: ext.isError ?? false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} else if (innerEvent.type === \"server_tool_use\") {\n\t\t\t\t\tconst idx = typeof innerEvent.contentIndex === \"number\" ? innerEvent.contentIndex : -1;\n\t\t\t\t\tconst block = idx >= 0 ? (host.streamingMessage.content[idx] as any) : undefined;\n\t\t\t\t\tconst ext = block?.externalResult;\n\t\t\t\t\tif (block?.id && ext) {\n\t\t\t\t\t\texternalToolResult = {\n\t\t\t\t\t\t\ttoolCallId: block.id,\n\t\t\t\t\t\t\tcontent: ext.content ?? [{ type: \"text\", text: \"\" }],\n\t\t\t\t\t\t\tdetails: ext.details ?? {},\n\t\t\t\t\t\t\tisError: ext.isError ?? false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst contentBlocks = host.streamingMessage.content;\n\t\t\t\t// Some adapters reuse a single assistant lifecycle while internally\n\t\t\t\t// spanning multiple provider turns. When a new turn starts, content\n\t\t\t\t// length can shrink back to 0/1; reset scan index to avoid skipping.\n\t\t\t\tif (lastProcessedContentIndex >= contentBlocks.length) {\n\t\t\t\t\tlastProcessedContentIndex = 0;\n\t\t\t\t}\n\t\t\t\tfor (let i = lastProcessedContentIndex; i < contentBlocks.length; i++) {\n\t\t\t\t\tconst content = contentBlocks[i];\n\t\t\t\t\tif (content.type === \"toolCall\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.arguments,\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\thost.getRegisteredToolDefinition(content.name),\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\thost.pendingTools.get(content.id)?.updateArgs(content.arguments);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"serverToolUse\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.input ?? {},\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"webSearchResult\") {\n\t\t\t\t\t\tconst component = host.pendingTools.get(content.toolUseId);\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\tif (process.env.PI_OFFLINE === \"1\") {\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Web search disabled (offline mode)\" }],\n\t\t\t\t\t\t\t\t\tisError: false,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst searchContent = content.content;\n\t\t\t\t\t\t\t\tconst isError = searchContent && typeof searchContent === \"object\" && \"type\" in (searchContent as any) && (searchContent as any).type === \"web_search_tool_result_error\";\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: host.formatWebSearchResult(searchContent) }],\n\t\t\t\t\t\t\t\t\tisError: !!isError,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// When the stream adapter signals a completed tool call with an\n\t\t\t\t// external result (from Claude Code SDK), update the pending\n\t\t\t\t// ToolExecutionComponent immediately so output is visible in\n\t\t\t\t// real-time instead of waiting for the session to end.\n\t\t\t\tif (externalToolResult) {\n\t\t\t\t\tconst component = host.pendingTools.get(externalToolResult.toolCallId);\n\t\t\t\t\tif (component) {\n\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\tcontent: externalToolResult.content,\n\t\t\t\t\t\t\tdetails: externalToolResult.details,\n\t\t\t\t\t\t\tisError: externalToolResult.isError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Render assistant text/thinking after tool components so mixed\n\t\t\t\t// streams keep chronological ordering in the chat container.\n\t\t\t\tconst hasToolBlocks = hasAssistantToolBlocks(host.streamingMessage);\n\t\t\t\tif (!host.streamingComponent && hasVisibleAssistantContent(host.streamingMessage)) {\n\t\t\t\t\thost.streamingComponent = new AssistantMessageComponent(\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t\t);\n\t\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\t}\n\t\t\t\tif (host.streamingComponent) {\n\t\t\t\t\tif (hasToolBlocks) {\n\t\t\t\t\t\thost.chatContainer.removeChild(host.streamingComponent);\n\t\t\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\t\t}\n\t\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\t}\n\n\t\t\t\t// Update index: fully processed blocks won't need re-scanning.\n\t\t\t\t// Keep the last block's index (it may still be accumulating data),\n\t\t\t\t// so we re-check it next time but skip all earlier ones.\n\t\t\t\tif (contentBlocks.length > 0) {\n\t\t\t\t\tlastProcessedContentIndex = Math.max(0, contentBlocks.length - 1);\n\t\t\t\t}\n\n\t\t\t\t// Pinned message: mirror the latest assistant text above the editor\n\t\t\t\t// when tool executions push it out of the viewport.\n\t\t\t\tconst hasTools = contentBlocks.some(\n\t\t\t\t\t(c: any) => c.type === \"toolCall\" || c.type === \"serverToolUse\",\n\t\t\t\t);\n\t\t\t\tif (hasTools) hasToolsInTurn = true;\n\n\t\t\t\tif (hasToolsInTurn) {\n\t\t\t\t\t// Collect the latest text block(s) from the assistant message\n\t\t\t\t\tlet latestText = \"\";\n\t\t\t\t\tfor (let i = contentBlocks.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tconst c = contentBlocks[i] as any;\n\t\t\t\t\t\tif (c.type === \"text\" && c.text?.trim()) {\n\t\t\t\t\t\t\tlatestText = c.text.trim();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (latestText && latestText !== lastPinnedText) {\n\t\t\t\t\t\tlastPinnedText = latestText;\n\n\t\t\t\t\t\tif (!pinnedBorder) {\n\t\t\t\t\t\t\t// First time: create border + text component\n\t\t\t\t\t\t\thost.pinnedMessageContainer.clear();\n\t\t\t\t\t\t\tpinnedBorder = new DynamicBorder(\n\t\t\t\t\t\t\t\t(str: string) => theme.fg(\"dim\", str),\n\t\t\t\t\t\t\t\t\"Working · Latest Output\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tpinnedBorder.startSpinner(host.ui, (str: string) => theme.fg(\"accent\", str));\n\t\t\t\t\t\t\thost.pinnedMessageContainer.addChild(pinnedBorder);\n\t\t\t\t\t\t\tpinnedTextComponent = new Markdown(latestText, 1, 0, host.getMarkdownThemeWithSettings());\n\t\t\t\t\t\t\t// Cap pinned content to ~40% of terminal height so tall output\n\t\t\t\t\t\t\t// doesn't exceed the viewport and cause render flashing.\n\t\t\t\t\t\t\tpinnedTextComponent.maxLines = Math.max(3, Math.floor(host.ui.terminal.rows * 0.4));\n\t\t\t\t\t\t\thost.pinnedMessageContainer.addChild(pinnedTextComponent);\n\t\t\t\t\t\t\t// Hide the separate status loader — the pinned zone replaces it\n\t\t\t\t\t\t\tif (host.loadingAnimation) {\n\t\t\t\t\t\t\t\thost.loadingAnimation.stop();\n\t\t\t\t\t\t\t\thost.loadingAnimation = undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thost.statusContainer.clear();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Update existing markdown component in-place\n\t\t\t\t\t\t\tpinnedTextComponent?.setText(latestText);\n\t\t\t\t\t\t\t// Refresh maxLines in case terminal was resized\n\t\t\t\t\t\t\tif (pinnedTextComponent) {\n\t\t\t\t\t\t\t\tpinnedTextComponent.maxLines = Math.max(3, Math.floor(host.ui.terminal.rows * 0.4));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_end\":\n\t\t\tif (event.message.role === \"user\") break;\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tlet errorMessage: string | undefined;\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\") {\n\t\t\t\t\tconst retryAttempt = host.session.retryAttempt;\n\t\t\t\t\terrorMessage = retryAttempt > 0\n\t\t\t\t\t\t? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? \"s\" : \"\"}`\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\t\thost.streamingMessage.errorMessage = errorMessage;\n\t\t\t\t}\n\n\t\t\t\tconst shouldRenderAssistant = hasVisibleAssistantContent(host.streamingMessage)\n\t\t\t\t\t|| (\n\t\t\t\t\t\t(host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\")\n\t\t\t\t\t\t&& !hasAssistantToolBlocks(host.streamingMessage)\n\t\t\t\t\t);\n\t\t\t\tif (!host.streamingComponent && shouldRenderAssistant) {\n\t\t\t\t\thost.streamingComponent = new AssistantMessageComponent(\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t\t);\n\t\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\t}\n\t\t\t\tif (host.streamingComponent) {\n\t\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\t}\n\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\") {\n\t\t\t\t\tif (!errorMessage) {\n\t\t\t\t\t\terrorMessage = host.streamingMessage.errorMessage || \"Error\";\n\t\t\t\t\t}\n\t\t\t\t\tconst pendingComponents = Array.from(host.pendingTools.values());\n\t\t\t\t\tif (pendingComponents.length > 0) {\n\t\t\t\t\t\tconst [first, ...rest] = pendingComponents;\n\t\t\t\t\t\tfirst.completeWithError(errorMessage);\n\t\t\t\t\t\tfor (const component of rest) {\n\t\t\t\t\t\t\tcomponent.completeWithError();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t} else {\n\t\t\t\t\tfor (const [, component] of host.pendingTools.entries()) {\n\t\t\t\t\t\tcomponent.setArgsComplete();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\t// Clear pinned output once the message is finalized in the chat\n\t\t\t\t// container — prevents duplicate display when the agent continues\n\t\t\t\t// (e.g. form elicitation) after the assistant message ends.\n\t\t\t\tif (pinnedBorder) pinnedBorder.stopSpinner();\n\t\t\t\thost.pinnedMessageContainer.clear();\n\t\t\t\tlastPinnedText = \"\";\n\t\t\t\thasToolsInTurn = false;\n\t\t\t\tpinnedBorder = undefined;\n\t\t\t\tpinnedTextComponent = undefined;\n\t\t\t\thost.footer.invalidate();\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_start\":\n\t\t\tif (!host.pendingTools.has(event.toolCallId)) {\n\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\tevent.toolName,\n\t\t\t\t\tevent.args,\n\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\thost.getRegisteredToolDefinition(event.toolName),\n\t\t\t\t\thost.ui,\n\t\t\t\t);\n\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\thost.pendingTools.set(event.toolCallId, component);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_update\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.partialResult, isError: false }, true);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"tool_execution_end\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.result, isError: event.isError });\n\t\t\t\thost.pendingTools.delete(event.toolCallId);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"agent_end\":\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t\thost.loadingAnimation = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (host.streamingComponent) {\n\t\t\t\thost.chatContainer.removeChild(host.streamingComponent);\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t}\n\t\t\thost.pendingTools.clear();\n\t\t\t// Pinned output is only useful while work is actively streaming.\n\t\t\t// Keep chat history as the single source after completion.\n\t\t\tif (pinnedBorder) {\n\t\t\t\tpinnedBorder.stopSpinner();\n\t\t\t}\n\t\t\thost.pinnedMessageContainer.clear();\n\t\t\tlastPinnedText = \"\";\n\t\t\thasToolsInTurn = false;\n\t\t\tpinnedBorder = undefined;\n\t\t\tpinnedTextComponent = undefined;\n\t\t\tawait host.checkShutdownRequested();\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_start\":\n\t\t\thost.autoCompactionEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortCompaction();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.autoCompactionLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`${event.reason === \"overflow\" ? \"Context overflow detected, \" : \"\"}Auto-compacting... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.autoCompactionLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_end\":\n\t\t\tif (host.autoCompactionEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.autoCompactionEscapeHandler;\n\t\t\t\thost.autoCompactionEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.autoCompactionLoader) {\n\t\t\t\thost.autoCompactionLoader.stop();\n\t\t\t\thost.autoCompactionLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (event.aborted) {\n\t\t\t\thost.showStatus(\"Auto-compaction cancelled\");\n\t\t\t} else if (event.result) {\n\t\t\t\thost.chatContainer.clear();\n\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\thost.addMessageToChat({\n\t\t\t\t\trole: \"compactionSummary\",\n\t\t\t\t\ttokensBefore: event.result.tokensBefore,\n\t\t\t\t\tsummary: event.result.summary,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t});\n\t\t\t\thost.footer.invalidate();\n\t\t\t} else if (event.errorMessage) {\n\t\t\t\thost.chatContainer.addChild(new Spacer(1));\n\t\t\t\thost.chatContainer.addChild(new Text(theme.fg(\"error\", event.errorMessage), 1, 0));\n\t\t\t}\n\t\t\tvoid host.flushCompactionQueue({ willRetry: event.willRetry });\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_start\":\n\t\t\thost.retryEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortRetry();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.retryLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"warning\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`Retrying (${event.attempt}/${event.maxAttempts}) in ${Math.round(event.delayMs / 1000)}s... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.retryLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_end\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (!event.success) {\n\t\t\t\thost.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError || \"Unknown error\"}`);\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_switch\":\n\t\t\thost.showStatus(`Switched from ${event.from} → ${event.to} (${event.reason})`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_restored\":\n\t\t\thost.showStatus(`Restored to ${event.provider}`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_chain_exhausted\":\n\t\t\thost.showError(event.reason);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"image_overflow_recovery\":\n\t\t\thost.showStatus(\n\t\t\t\t`Removed ${event.strippedCount} older image(s) to comply with API limits. Retrying...`,\n\t\t\t);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chat-controller.js","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,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AC,KAAK,EAAE,CAAC;YAC9B,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACpB,IAAI,CAAC,SAAS,CAAC,sBAAsB,KAAK,CAAC,OAAO,cAAc,KAAK,CAAC,UAAU,IAAI,eAAe,EAAE,CAAC,CAAC;YACxG,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,0BAA0B;YAC9B,IAAI,CAAC,UAAU,CAAC,iBAAiB,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YAC/E,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,4BAA4B;YAChC,IAAI,CAAC,UAAU,CAAC,eAAe,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,0BAA0B;YAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;QAEP,KAAK,yBAAyB;YAC7B,IAAI,CAAC,UAAU,CACd,WAAW,KAAK,CAAC,aAAa,wDAAwD,CACtF,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM;IACR,CAAC;AACF,CAAC","sourcesContent":["import { Loader, Markdown, Spacer, Text } from \"@gsd/pi-tui\";\n\nimport type { InteractiveModeEvent, InteractiveModeStateHost } from \"../interactive-mode-state.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { AssistantMessageComponent } from \"../components/assistant-message.js\";\nimport { ToolExecutionComponent } from \"../components/tool-execution.js\";\nimport { DynamicBorder } from \"../components/dynamic-border.js\";\nimport { appKey } from \"../components/keybinding-hints.js\";\n\n// Tracks the last processed content index to avoid re-scanning all blocks on every message_update\nlet lastProcessedContentIndex = 0;\n\n// --- Segment walker state (per streaming assistant turn) ---\ntype RenderedSegment =\n\t| { kind: \"text-run\"; startIndex: number; endIndex: number; component: AssistantMessageComponent }\n\t| { kind: \"tool\"; contentIndex: number; component: ToolExecutionComponent };\n\nlet renderedSegments: RenderedSegment[] = [];\n\nfunction hasVisibleAssistantContent(message: { content: Array<any> }): boolean {\n\treturn message.content.some(\n\t\t(c) =>\n\t\t\t(c.type === \"text\" && typeof c.text === \"string\" && c.text.trim().length > 0)\n\t\t\t|| (c.type === \"thinking\" && typeof c.thinking === \"string\" && c.thinking.trim().length > 0),\n\t);\n}\n\nfunction hasAssistantToolBlocks(message: { content: Array<any> }): boolean {\n\treturn message.content.some((c) => c.type === \"toolCall\" || c.type === \"serverToolUse\");\n}\n\n// Pick the latest non-empty text block that appears strictly before the most\n// recent tool call. Text blocks that come after the last tool call are still\n// streaming live into the chat container, so mirroring them into the pinned\n// \"Latest Output\" zone would render the same tokens twice.\nexport function findLatestPinnableText(contentBlocks: Array<any>): string {\n\tlet lastToolIdx = -1;\n\tfor (let i = contentBlocks.length - 1; i >= 0; i--) {\n\t\tconst c = contentBlocks[i];\n\t\tif (c?.type === \"toolCall\" || c?.type === \"serverToolUse\") {\n\t\t\tlastToolIdx = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (let i = lastToolIdx - 1; i >= 0; i--) {\n\t\tconst c = contentBlocks[i];\n\t\tif (c?.type === \"text\" && typeof c.text === \"string\" && c.text.trim()) {\n\t\t\treturn c.text.trim();\n\t\t}\n\t}\n\treturn \"\";\n}\n\n// Tracks the latest assistant text for the pinned message zone\nlet lastPinnedText = \"\";\n// Whether any tool execution has been added in this assistant turn (triggers pinned display)\nlet hasToolsInTurn = false;\n// Reference to the pinned border so we can toggle its label between working/idle\nlet pinnedBorder: DynamicBorder | undefined;\n// Reference to the pinned markdown component below the border\nlet pinnedTextComponent: Markdown | undefined;\n\nexport async function handleAgentEvent(host: InteractiveModeStateHost & {\n\tinit: () => Promise<void>;\n\tgetMarkdownThemeWithSettings: () => any;\n\taddMessageToChat: (message: any, options?: any) => void;\n\tformatWebSearchResult: (content: unknown) => string;\n\tgetRegisteredToolDefinition: (toolName: string) => any;\n\tcheckShutdownRequested: () => Promise<void>;\n\trebuildChatFromMessages: () => void;\n\tflushCompactionQueue: (options?: { willRetry?: boolean }) => Promise<void>;\n\tshowStatus: (message: string) => void;\n\tshowError: (message: string) => void;\n\tupdatePendingMessagesDisplay: () => void;\n\tupdateTerminalTitle: () => void;\n\tupdateEditorBorderColor: () => void;\n\tpendingMessagesContainer: { clear: () => void };\n}, event: InteractiveModeEvent): Promise<void> {\n\tif (!host.isInitialized) {\n\t\tawait host.init();\n\t}\n\n\thost.footer.invalidate();\n\n\t// Reset content index tracker and pinned state when a new assistant message starts\n\tif (event.type === \"message_start\" && event.message.role === \"assistant\") {\n\t\tlastProcessedContentIndex = 0;\n\t\tlastPinnedText = \"\";\n\t\thasToolsInTurn = false;\n\t\trenderedSegments = [];\n\t\tif (pinnedBorder) pinnedBorder.stopSpinner();\n\t\tpinnedBorder = undefined;\n\t\tpinnedTextComponent = undefined;\n\t\thost.pinnedMessageContainer.clear();\n\t}\n\n\tswitch (event.type) {\n\t\tcase \"session_state_changed\":\n\t\t\tswitch (event.reason) {\n\t\t\t\tcase \"new_session\":\n\t\t\t\tcase \"switch_session\":\n\t\t\t\tcase \"fork\":\n\t\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t\thost.pendingMessagesContainer.clear();\n\t\t\t\t\thost.pinnedMessageContainer.clear();\n\t\t\t\t\tlastPinnedText = \"\";\n\t\t\t\t\thasToolsInTurn = false;\n\t\t\t\t\trenderedSegments = [];\n\t\t\t\t\tif (pinnedBorder) pinnedBorder.stopSpinner();\n\t\t\t\t\tpinnedBorder = undefined;\n\t\t\t\t\tpinnedTextComponent = undefined;\n\t\t\t\t\thost.compactionQueuedMessages = [];\n\t\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_session_name\":\n\t\t\t\t\thost.updateTerminalTitle();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tcase \"set_model\":\n\t\t\t\tcase \"set_thinking_level\":\n\t\t\t\t\thost.updateEditorBorderColor();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\tdefault:\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t\treturn;\n\t\t\t}\n\t\tcase \"agent_start\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t}\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t}\n\t\t\thost.statusContainer.clear();\n\t\t\thost.loadingAnimation = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\thost.defaultWorkingMessage,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.loadingAnimation);\n\t\t\tif (host.pendingWorkingMessage !== undefined) {\n\t\t\t\tif (host.pendingWorkingMessage) {\n\t\t\t\t\thost.loadingAnimation.setMessage(host.pendingWorkingMessage);\n\t\t\t\t}\n\t\t\t\thost.pendingWorkingMessage = undefined;\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"message_start\":\n\t\t\tif (event.message.role === \"custom\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"user\") {\n\t\t\t\thost.addMessageToChat(event.message);\n\t\t\t\thost.updatePendingMessagesDisplay();\n\t\t\t\thost.ui.requestRender();\n\t\t\t} else if (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\t// External-tool providers can stream multiple assistant turns through\n\t\t\t\t// one response. Delay component creation until visible assistant text\n\t\t\t\t// arrives so tool outputs keep chronological ordering.\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_update\":\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tconst innerEvent = event.assistantMessageEvent;\n\n\t\t\t\tlet externalToolResult:\n\t\t\t\t\t| { toolCallId: string; content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; details: Record<string, unknown>; isError: boolean }\n\t\t\t\t\t| undefined;\n\t\t\t\tif (innerEvent.type === \"toolcall_end\" && innerEvent.toolCall) {\n\t\t\t\t\tconst tc = innerEvent.toolCall as any;\n\t\t\t\t\tconst ext = tc.externalResult;\n\t\t\t\t\tif (ext) {\n\t\t\t\t\t\texternalToolResult = {\n\t\t\t\t\t\t\ttoolCallId: tc.id,\n\t\t\t\t\t\t\tcontent: ext.content ?? [{ type: \"text\", text: \"\" }],\n\t\t\t\t\t\t\tdetails: ext.details ?? {},\n\t\t\t\t\t\t\tisError: ext.isError ?? false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t} else if (innerEvent.type === \"server_tool_use\") {\n\t\t\t\t\tconst idx = typeof innerEvent.contentIndex === \"number\" ? innerEvent.contentIndex : -1;\n\t\t\t\t\tconst block = idx >= 0 ? (host.streamingMessage.content[idx] as any) : undefined;\n\t\t\t\t\tconst ext = block?.externalResult;\n\t\t\t\t\tif (block?.id && ext) {\n\t\t\t\t\t\texternalToolResult = {\n\t\t\t\t\t\t\ttoolCallId: block.id,\n\t\t\t\t\t\t\tcontent: ext.content ?? [{ type: \"text\", text: \"\" }],\n\t\t\t\t\t\t\tdetails: ext.details ?? {},\n\t\t\t\t\t\t\tisError: ext.isError ?? false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst contentBlocks = host.streamingMessage.content;\n\t\t\t\t// Some adapters reuse a single assistant lifecycle while internally\n\t\t\t\t// spanning multiple provider turns. When a new turn starts, content\n\t\t\t\t// length can shrink back to 0/1; reset scan index to avoid skipping.\n\t\t\t\tif (lastProcessedContentIndex >= contentBlocks.length) {\n\t\t\t\t\tlastProcessedContentIndex = 0;\n\t\t\t\t}\n\t\t\t\tfor (let i = lastProcessedContentIndex; i < contentBlocks.length; i++) {\n\t\t\t\t\tconst content = contentBlocks[i];\n\t\t\t\t\tif (content.type === \"toolCall\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.arguments,\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\thost.getRegisteredToolDefinition(content.name),\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\thost.pendingTools.get(content.id)?.updateArgs(content.arguments);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"serverToolUse\") {\n\t\t\t\t\t\tif (!host.pendingTools.has(content.id)) {\n\t\t\t\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\t\t\t\tcontent.name,\n\t\t\t\t\t\t\t\tcontent.input ?? {},\n\t\t\t\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\thost.ui,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\t\t\t\thost.pendingTools.set(content.id, component);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (content.type === \"webSearchResult\") {\n\t\t\t\t\t\tconst component = host.pendingTools.get(content.toolUseId);\n\t\t\t\t\t\tif (component) {\n\t\t\t\t\t\t\tif (process.env.PI_OFFLINE === \"1\") {\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: \"Web search disabled (offline mode)\" }],\n\t\t\t\t\t\t\t\t\tisError: false,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst searchContent = content.content;\n\t\t\t\t\t\t\t\tconst isError = searchContent && typeof searchContent === \"object\" && \"type\" in (searchContent as any) && (searchContent as any).type === \"web_search_tool_result_error\";\n\t\t\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: host.formatWebSearchResult(searchContent) }],\n\t\t\t\t\t\t\t\t\tisError: !!isError,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// When the stream adapter signals a completed tool call with an\n\t\t\t\t// external result (from Claude Code SDK), update the pending\n\t\t\t\t// ToolExecutionComponent immediately so output is visible in\n\t\t\t\t// real-time instead of waiting for the session to end.\n\t\t\t\tif (externalToolResult) {\n\t\t\t\t\tconst component = host.pendingTools.get(externalToolResult.toolCallId);\n\t\t\t\t\tif (component) {\n\t\t\t\t\t\tcomponent.updateResult({\n\t\t\t\t\t\t\tcontent: externalToolResult.content,\n\t\t\t\t\t\t\tdetails: externalToolResult.details,\n\t\t\t\t\t\t\tisError: externalToolResult.isError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Segment walker: render content blocks in stream order, append-only.\n\t\t\t\t// Build desired segment plan from content[].\n\t\t\t\t{\n\t\t\t\t\tconst blocks = host.streamingMessage.content;\n\t\t\t\t\ttype DesiredSegment =\n\t\t\t\t\t\t| { kind: \"text-run\"; startIndex: number; endIndex: number }\n\t\t\t\t\t\t| { kind: \"tool\"; contentIndex: number; toolId: string };\n\t\t\t\t\tconst desired: DesiredSegment[] = [];\n\t\t\t\t\tlet runStart = -1;\n\t\t\t\t\tfor (let i = 0; i < blocks.length; i++) {\n\t\t\t\t\t\tconst b = blocks[i];\n\t\t\t\t\t\tconst isText = b.type === \"text\" || b.type === \"thinking\";\n\t\t\t\t\t\tconst isTool = b.type === \"toolCall\" || b.type === \"serverToolUse\";\n\t\t\t\t\t\tif (isText) {\n\t\t\t\t\t\t\tif (runStart === -1) runStart = i;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (runStart !== -1) {\n\t\t\t\t\t\t\t\tdesired.push({ kind: \"text-run\", startIndex: runStart, endIndex: i - 1 });\n\t\t\t\t\t\t\t\trunStart = -1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isTool) {\n\t\t\t\t\t\t\t\tdesired.push({ kind: \"tool\", contentIndex: i, toolId: b.id });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (runStart !== -1) {\n\t\t\t\t\t\tdesired.push({ kind: \"text-run\", startIndex: runStart, endIndex: blocks.length - 1 });\n\t\t\t\t\t}\n\n\t\t\t\t\t// Append any newly needed segments (never reorder existing ones).\n\t\t\t\t\tfor (const seg of desired) {\n\t\t\t\t\t\tif (seg.kind === \"tool\") {\n\t\t\t\t\t\t\t// Tool segments are already handled above via pendingTools; just\n\t\t\t\t\t\t\t// register them in renderedSegments if not yet tracked.\n\t\t\t\t\t\t\tconst existing = renderedSegments.find(\n\t\t\t\t\t\t\t\t(s) => s.kind === \"tool\" && s.contentIndex === seg.contentIndex,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (!existing) {\n\t\t\t\t\t\t\t\tconst comp = host.pendingTools.get(seg.toolId);\n\t\t\t\t\t\t\t\tif (comp) {\n\t\t\t\t\t\t\t\t\trenderedSegments.push({ kind: \"tool\", contentIndex: seg.contentIndex, component: comp });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// text-run segment\n\t\t\t\t\t\t\tconst existing = renderedSegments.find(\n\t\t\t\t\t\t\t\t(s) => s.kind === \"text-run\" && s.startIndex === seg.startIndex,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (!existing) {\n\t\t\t\t\t\t\t\tconst comp = new AssistantMessageComponent(\n\t\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t\t\t\t\t\t{ startIndex: seg.startIndex, endIndex: seg.endIndex },\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\thost.chatContainer.addChild(comp);\n\t\t\t\t\t\t\t\trenderedSegments.push({ kind: \"text-run\", startIndex: seg.startIndex, endIndex: seg.endIndex, component: comp });\n\t\t\t\t\t\t\t\thost.streamingComponent = comp;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Update all trailing text-run segments with the latest message so\n\t\t\t\t\t// streaming text grows in place.\n\t\t\t\t\tfor (const seg of renderedSegments) {\n\t\t\t\t\t\tif (seg.kind === \"text-run\") {\n\t\t\t\t\t\t\t// Find corresponding desired segment to get current endIndex\n\t\t\t\t\t\t\tconst d = desired.find((ds) => ds.kind === \"text-run\" && ds.startIndex === seg.startIndex);\n\t\t\t\t\t\t\tif (d && d.kind === \"text-run\" && d.endIndex !== seg.endIndex) {\n\t\t\t\t\t\t\t\tseg.endIndex = d.endIndex;\n\t\t\t\t\t\t\t\tseg.component.setRange({ startIndex: seg.startIndex, endIndex: seg.endIndex });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tseg.component.updateContent(host.streamingMessage);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Keep streamingComponent pointing at the last text-run for message_end compatibility.\n\t\t\t\t\tconst lastTextSeg = [...renderedSegments].reverse().find((s) => s.kind === \"text-run\");\n\t\t\t\t\tif (lastTextSeg && lastTextSeg.kind === \"text-run\") {\n\t\t\t\t\t\thost.streamingComponent = lastTextSeg.component;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Update index: fully processed blocks won't need re-scanning.\n\t\t\t\t// Keep the last block's index (it may still be accumulating data),\n\t\t\t\t// so we re-check it next time but skip all earlier ones.\n\t\t\t\tif (contentBlocks.length > 0) {\n\t\t\t\t\tlastProcessedContentIndex = Math.max(0, contentBlocks.length - 1);\n\t\t\t\t}\n\n\t\t\t\t// Pinned message: mirror the latest assistant text above the editor\n\t\t\t\t// when tool executions push it out of the viewport.\n\t\t\t\tconst hasTools = contentBlocks.some(\n\t\t\t\t\t(c: any) => c.type === \"toolCall\" || c.type === \"serverToolUse\",\n\t\t\t\t);\n\t\t\t\tif (hasTools) hasToolsInTurn = true;\n\n\t\t\t\tif (hasToolsInTurn) {\n\t\t\t\t\tconst latestText = findLatestPinnableText(contentBlocks);\n\n\t\t\t\t\tif (latestText && latestText !== lastPinnedText) {\n\t\t\t\t\t\tlastPinnedText = latestText;\n\n\t\t\t\t\t\tif (!pinnedBorder) {\n\t\t\t\t\t\t\t// First time: create border + text component\n\t\t\t\t\t\t\thost.pinnedMessageContainer.clear();\n\t\t\t\t\t\t\tpinnedBorder = new DynamicBorder(\n\t\t\t\t\t\t\t\t(str: string) => theme.fg(\"dim\", str),\n\t\t\t\t\t\t\t\t\"Working · Latest Output\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tpinnedBorder.startSpinner(host.ui, (str: string) => theme.fg(\"accent\", str));\n\t\t\t\t\t\t\thost.pinnedMessageContainer.addChild(pinnedBorder);\n\t\t\t\t\t\t\tpinnedTextComponent = new Markdown(latestText, 1, 0, host.getMarkdownThemeWithSettings());\n\t\t\t\t\t\t\t// Cap pinned content to ~40% of terminal height so tall output\n\t\t\t\t\t\t\t// doesn't exceed the viewport and cause render flashing.\n\t\t\t\t\t\t\tpinnedTextComponent.maxLines = Math.max(3, Math.floor(host.ui.terminal.rows * 0.4));\n\t\t\t\t\t\t\thost.pinnedMessageContainer.addChild(pinnedTextComponent);\n\t\t\t\t\t\t\t// Hide the separate status loader — the pinned zone replaces it\n\t\t\t\t\t\t\tif (host.loadingAnimation) {\n\t\t\t\t\t\t\t\thost.loadingAnimation.stop();\n\t\t\t\t\t\t\t\thost.loadingAnimation = undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thost.statusContainer.clear();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Update existing markdown component in-place\n\t\t\t\t\t\t\tpinnedTextComponent?.setText(latestText);\n\t\t\t\t\t\t\t// Refresh maxLines in case terminal was resized\n\t\t\t\t\t\t\tif (pinnedTextComponent) {\n\t\t\t\t\t\t\t\tpinnedTextComponent.maxLines = Math.max(3, Math.floor(host.ui.terminal.rows * 0.4));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"message_end\":\n\t\t\tif (event.message.role === \"user\") break;\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\thost.streamingMessage = event.message;\n\t\t\t\tlet errorMessage: string | undefined;\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\") {\n\t\t\t\t\tconst retryAttempt = host.session.retryAttempt;\n\t\t\t\t\terrorMessage = retryAttempt > 0\n\t\t\t\t\t\t? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? \"s\" : \"\"}`\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\t\thost.streamingMessage.errorMessage = errorMessage;\n\t\t\t\t}\n\n\t\t\t\tconst shouldRenderAssistant = hasVisibleAssistantContent(host.streamingMessage)\n\t\t\t\t\t|| (\n\t\t\t\t\t\t(host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\")\n\t\t\t\t\t\t&& !hasAssistantToolBlocks(host.streamingMessage)\n\t\t\t\t\t);\n\t\t\t\tif (!host.streamingComponent && shouldRenderAssistant) {\n\t\t\t\t\thost.streamingComponent = new AssistantMessageComponent(\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\thost.hideThinkingBlock,\n\t\t\t\t\t\thost.getMarkdownThemeWithSettings(),\n\t\t\t\t\t\thost.settingsManager.getTimestampFormat(),\n\t\t\t\t\t);\n\t\t\t\t\thost.chatContainer.addChild(host.streamingComponent);\n\t\t\t\t}\n\t\t\t\tif (host.streamingComponent) {\n\t\t\t\t\thost.streamingComponent.setShowMetadata(true);\n\t\t\t\t\thost.streamingComponent.updateContent(host.streamingMessage);\n\t\t\t\t}\n\n\t\t\t\tif (host.streamingMessage.stopReason === \"aborted\" || host.streamingMessage.stopReason === \"error\") {\n\t\t\t\t\tif (!errorMessage) {\n\t\t\t\t\t\terrorMessage = host.streamingMessage.errorMessage || \"Error\";\n\t\t\t\t\t}\n\t\t\t\t\tconst pendingComponents = Array.from(host.pendingTools.values());\n\t\t\t\t\tif (pendingComponents.length > 0) {\n\t\t\t\t\t\tconst [first, ...rest] = pendingComponents;\n\t\t\t\t\t\tfirst.completeWithError(errorMessage);\n\t\t\t\t\t\tfor (const component of rest) {\n\t\t\t\t\t\t\tcomponent.completeWithError();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\thost.pendingTools.clear();\n\t\t\t\t} else {\n\t\t\t\t\tfor (const [, component] of host.pendingTools.entries()) {\n\t\t\t\t\t\tcomponent.setArgsComplete();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t\trenderedSegments = [];\n\t\t\t\t// Clear pinned output once the message is finalized in the chat\n\t\t\t\t// container — prevents duplicate display when the agent continues\n\t\t\t\t// (e.g. form elicitation) after the assistant message ends.\n\t\t\t\tif (pinnedBorder) pinnedBorder.stopSpinner();\n\t\t\t\thost.pinnedMessageContainer.clear();\n\t\t\t\tlastPinnedText = \"\";\n\t\t\t\thasToolsInTurn = false;\n\t\t\t\tpinnedBorder = undefined;\n\t\t\t\tpinnedTextComponent = undefined;\n\t\t\t\thost.footer.invalidate();\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_start\":\n\t\t\tif (!host.pendingTools.has(event.toolCallId)) {\n\t\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\t\tevent.toolName,\n\t\t\t\t\tevent.args,\n\t\t\t\t\t{ showImages: host.settingsManager.getShowImages() },\n\t\t\t\t\thost.getRegisteredToolDefinition(event.toolName),\n\t\t\t\t\thost.ui,\n\t\t\t\t);\n\t\t\t\tcomponent.setExpanded(host.toolOutputExpanded);\n\t\t\t\thost.chatContainer.addChild(component);\n\t\t\t\thost.pendingTools.set(event.toolCallId, component);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase \"tool_execution_update\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.partialResult, isError: false }, true);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"tool_execution_end\": {\n\t\t\tconst component = host.pendingTools.get(event.toolCallId);\n\t\t\tif (component) {\n\t\t\t\tcomponent.updateResult({ ...event.result, isError: event.isError });\n\t\t\t\thost.pendingTools.delete(event.toolCallId);\n\t\t\t\thost.ui.requestRender();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"agent_end\":\n\t\t\tif (host.loadingAnimation) {\n\t\t\t\thost.loadingAnimation.stop();\n\t\t\t\thost.loadingAnimation = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (host.streamingComponent) {\n\t\t\t\thost.chatContainer.removeChild(host.streamingComponent);\n\t\t\t\thost.streamingComponent = undefined;\n\t\t\t\thost.streamingMessage = undefined;\n\t\t\t}\n\t\t\thost.pendingTools.clear();\n\t\t\t// Pinned output is only useful while work is actively streaming.\n\t\t\t// Keep chat history as the single source after completion.\n\t\t\tif (pinnedBorder) {\n\t\t\t\tpinnedBorder.stopSpinner();\n\t\t\t}\n\t\t\thost.pinnedMessageContainer.clear();\n\t\t\tlastPinnedText = \"\";\n\t\t\thasToolsInTurn = false;\n\t\t\tpinnedBorder = undefined;\n\t\t\tpinnedTextComponent = undefined;\n\t\t\tawait host.checkShutdownRequested();\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_start\":\n\t\t\thost.autoCompactionEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortCompaction();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.autoCompactionLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"accent\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`${event.reason === \"overflow\" ? \"Context overflow detected, \" : \"\"}Auto-compacting... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.autoCompactionLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_compaction_end\":\n\t\t\tif (host.autoCompactionEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.autoCompactionEscapeHandler;\n\t\t\t\thost.autoCompactionEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.autoCompactionLoader) {\n\t\t\t\thost.autoCompactionLoader.stop();\n\t\t\t\thost.autoCompactionLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (event.aborted) {\n\t\t\t\thost.showStatus(\"Auto-compaction cancelled\");\n\t\t\t} else if (event.result) {\n\t\t\t\thost.chatContainer.clear();\n\t\t\t\thost.rebuildChatFromMessages();\n\t\t\t\thost.addMessageToChat({\n\t\t\t\t\trole: \"compactionSummary\",\n\t\t\t\t\ttokensBefore: event.result.tokensBefore,\n\t\t\t\t\tsummary: event.result.summary,\n\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t});\n\t\t\t\thost.footer.invalidate();\n\t\t\t} else if (event.errorMessage) {\n\t\t\t\thost.chatContainer.addChild(new Spacer(1));\n\t\t\t\thost.chatContainer.addChild(new Text(theme.fg(\"error\", event.errorMessage), 1, 0));\n\t\t\t}\n\t\t\tvoid host.flushCompactionQueue({ willRetry: event.willRetry });\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_start\":\n\t\t\thost.retryEscapeHandler = host.defaultEditor.onEscape;\n\t\t\thost.defaultEditor.onEscape = () => host.session.abortRetry();\n\t\t\thost.statusContainer.clear();\n\t\t\thost.retryLoader = new Loader(\n\t\t\t\thost.ui,\n\t\t\t\t(spinner) => theme.fg(\"warning\", spinner),\n\t\t\t\t(text) => theme.fg(\"muted\", text),\n\t\t\t\t`Retrying (${event.attempt}/${event.maxAttempts}) in ${Math.round(event.delayMs / 1000)}s... (${appKey(host.keybindings, \"interrupt\")} to cancel)`,\n\t\t\t);\n\t\t\thost.statusContainer.addChild(host.retryLoader);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"auto_retry_end\":\n\t\t\tif (host.retryEscapeHandler) {\n\t\t\t\thost.defaultEditor.onEscape = host.retryEscapeHandler;\n\t\t\t\thost.retryEscapeHandler = undefined;\n\t\t\t}\n\t\t\tif (host.retryLoader) {\n\t\t\t\thost.retryLoader.stop();\n\t\t\t\thost.retryLoader = undefined;\n\t\t\t\thost.statusContainer.clear();\n\t\t\t}\n\t\t\tif (!event.success) {\n\t\t\t\thost.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError || \"Unknown error\"}`);\n\t\t\t}\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_switch\":\n\t\t\thost.showStatus(`Switched from ${event.from} → ${event.to} (${event.reason})`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_provider_restored\":\n\t\t\thost.showStatus(`Restored to ${event.provider}`);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"fallback_chain_exhausted\":\n\t\t\thost.showError(event.reason);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\n\t\tcase \"image_overflow_recovery\":\n\t\t\thost.showStatus(\n\t\t\t\t`Removed ${event.strippedCount} older image(s) to comply with API limits. Retrying...`,\n\t\t\t);\n\t\t\thost.ui.requestRender();\n\t\t\tbreak;\n\t}\n}\n"]}
|
package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-controller.test.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { findLatestPinnableText } from "./chat-controller.js";
|
|
4
|
+
test("findLatestPinnableText: empty content returns empty string", () => {
|
|
5
|
+
assert.equal(findLatestPinnableText([]), "");
|
|
6
|
+
});
|
|
7
|
+
test("findLatestPinnableText: no tool calls returns empty string", () => {
|
|
8
|
+
const blocks = [
|
|
9
|
+
{ type: "text", text: "hello" },
|
|
10
|
+
{ type: "text", text: "world" },
|
|
11
|
+
];
|
|
12
|
+
assert.equal(findLatestPinnableText(blocks), "");
|
|
13
|
+
});
|
|
14
|
+
test("findLatestPinnableText: returns text preceding a tool call", () => {
|
|
15
|
+
const blocks = [
|
|
16
|
+
{ type: "text", text: "doing the thing" },
|
|
17
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
18
|
+
];
|
|
19
|
+
assert.equal(findLatestPinnableText(blocks), "doing the thing");
|
|
20
|
+
});
|
|
21
|
+
test("findLatestPinnableText: ignores trailing streaming text after the last tool call (regression: pinned mirror duplicated chat-container tokens)", () => {
|
|
22
|
+
const blocks = [
|
|
23
|
+
{ type: "text", text: "first prose" },
|
|
24
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
25
|
+
{ type: "text", text: "second prose still streaming" },
|
|
26
|
+
];
|
|
27
|
+
assert.equal(findLatestPinnableText(blocks), "first prose");
|
|
28
|
+
});
|
|
29
|
+
test("findLatestPinnableText: with multiple tools, picks text before the most recent tool call", () => {
|
|
30
|
+
const blocks = [
|
|
31
|
+
{ type: "text", text: "first" },
|
|
32
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
33
|
+
{ type: "text", text: "second" },
|
|
34
|
+
{ type: "toolCall", id: "2", name: "Grep" },
|
|
35
|
+
{ type: "text", text: "third streaming" },
|
|
36
|
+
];
|
|
37
|
+
assert.equal(findLatestPinnableText(blocks), "second");
|
|
38
|
+
});
|
|
39
|
+
test("findLatestPinnableText: treats serverToolUse the same as toolCall", () => {
|
|
40
|
+
const blocks = [
|
|
41
|
+
{ type: "text", text: "before web search" },
|
|
42
|
+
{ type: "serverToolUse", id: "ws1", name: "web_search" },
|
|
43
|
+
{ type: "text", text: "answer streaming" },
|
|
44
|
+
];
|
|
45
|
+
assert.equal(findLatestPinnableText(blocks), "before web search");
|
|
46
|
+
});
|
|
47
|
+
test("findLatestPinnableText: skips empty/whitespace-only text blocks", () => {
|
|
48
|
+
const blocks = [
|
|
49
|
+
{ type: "text", text: "real prose" },
|
|
50
|
+
{ type: "text", text: " " },
|
|
51
|
+
{ type: "text", text: "" },
|
|
52
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
53
|
+
];
|
|
54
|
+
assert.equal(findLatestPinnableText(blocks), "real prose");
|
|
55
|
+
});
|
|
56
|
+
test("findLatestPinnableText: thinking blocks are not pinnable", () => {
|
|
57
|
+
const blocks = [
|
|
58
|
+
{ type: "thinking", thinking: "internal" },
|
|
59
|
+
{ type: "toolCall", id: "1", name: "Read" },
|
|
60
|
+
];
|
|
61
|
+
assert.equal(findLatestPinnableText(blocks), "");
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=chat-controller.test.js.map
|
package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-controller.test.js","sourceRoot":"","sources":["../../../../src/modes/interactive/controllers/chat-controller.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACvE,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACvE,MAAM,MAAM,GAAG;QACd,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;QAC/B,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;KAC/B,CAA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AAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport test from \"node:test\";\n\nimport { findLatestPinnableText } from \"./chat-controller.js\";\n\ntest(\"findLatestPinnableText: empty content returns empty string\", () => {\n\tassert.equal(findLatestPinnableText([]), \"\");\n});\n\ntest(\"findLatestPinnableText: no tool calls returns empty string\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"hello\" },\n\t\t{ type: \"text\", text: \"world\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"\");\n});\n\ntest(\"findLatestPinnableText: returns text preceding a tool call\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"doing the thing\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"doing the thing\");\n});\n\ntest(\"findLatestPinnableText: ignores trailing streaming text after the last tool call (regression: pinned mirror duplicated chat-container tokens)\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"first prose\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t\t{ type: \"text\", text: \"second prose still streaming\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"first prose\");\n});\n\ntest(\"findLatestPinnableText: with multiple tools, picks text before the most recent tool call\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"first\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t\t{ type: \"text\", text: \"second\" },\n\t\t{ type: \"toolCall\", id: \"2\", name: \"Grep\" },\n\t\t{ type: \"text\", text: \"third streaming\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"second\");\n});\n\ntest(\"findLatestPinnableText: treats serverToolUse the same as toolCall\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"before web search\" },\n\t\t{ type: \"serverToolUse\", id: \"ws1\", name: \"web_search\" },\n\t\t{ type: \"text\", text: \"answer streaming\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"before web search\");\n});\n\ntest(\"findLatestPinnableText: skips empty/whitespace-only text blocks\", () => {\n\tconst blocks = [\n\t\t{ type: \"text\", text: \"real prose\" },\n\t\t{ type: \"text\", text: \" \" },\n\t\t{ type: \"text\", text: \"\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"real prose\");\n});\n\ntest(\"findLatestPinnableText: thinking blocks are not pinnable\", () => {\n\tconst blocks = [\n\t\t{ type: \"thinking\", thinking: \"internal\" },\n\t\t{ type: \"toolCall\", id: \"1\", name: \"Read\" },\n\t];\n\tassert.equal(findLatestPinnableText(blocks), \"\");\n});\n"]}
|
|
@@ -531,3 +531,41 @@ describe("AuthStorage — getEarliestBackoffExpiry", () => {
|
|
|
531
531
|
assert.equal(expiry, nearExpiry, "should return the nearest (smallest) expiry");
|
|
532
532
|
});
|
|
533
533
|
});
|
|
534
|
+
|
|
535
|
+
// ─── localhost baseUrl shortcut ────────────────────────────────────────────────
|
|
536
|
+
|
|
537
|
+
describe("AuthStorage — localhost baseUrl shortcut", () => {
|
|
538
|
+
it("returns 'local-no-key-needed' for localhost provider with no configured key", async () => {
|
|
539
|
+
const storage = inMemory({});
|
|
540
|
+
const key = await storage.getApiKey("ollama", undefined, { baseUrl: "http://localhost:11434" });
|
|
541
|
+
assert.equal(key, "local-no-key-needed");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("returns 'local-no-key-needed' for 127.0.0.1 provider with no configured key", async () => {
|
|
545
|
+
const storage = inMemory({});
|
|
546
|
+
const key = await storage.getApiKey("custom", undefined, { baseUrl: "http://127.0.0.1:8080/v1" });
|
|
547
|
+
assert.equal(key, "local-no-key-needed");
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("returns configured key from fallback resolver for localhost custom provider (#4106)", async () => {
|
|
551
|
+
// Regression test: compaction called getApiKey(model) where model.baseUrl is localhost.
|
|
552
|
+
// The localhost shortcut must NOT override an explicitly configured apiKey from models.json.
|
|
553
|
+
const storage = inMemory({});
|
|
554
|
+
storage.setFallbackResolver((provider) =>
|
|
555
|
+
provider === "cliproxy" ? "sk-real-proxy-key" : undefined,
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
const key = await storage.getApiKey("cliproxy", undefined, { baseUrl: "http://localhost:8317/v1" });
|
|
559
|
+
assert.equal(key, "sk-real-proxy-key");
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("returns configured key from fallback resolver when baseUrl uses 127.0.0.1 (#4106)", async () => {
|
|
563
|
+
const storage = inMemory({});
|
|
564
|
+
storage.setFallbackResolver((provider) =>
|
|
565
|
+
provider === "myproxy" ? "sk-myproxy-key" : undefined,
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
const key = await storage.getApiKey("myproxy", undefined, { baseUrl: "http://127.0.0.1:9000/v1" });
|
|
569
|
+
assert.equal(key, "sk-myproxy-key");
|
|
570
|
+
});
|
|
571
|
+
});
|
|
@@ -819,7 +819,7 @@ export class AuthStorage {
|
|
|
819
819
|
*/
|
|
820
820
|
async getApiKey(providerId: string, sessionId?: string, options?: { baseUrl?: string }): Promise<string | undefined> {
|
|
821
821
|
// If the model has a local baseUrl, return a dummy key to avoid auth blocking
|
|
822
|
-
if (options?.baseUrl) {
|
|
822
|
+
if (options?.baseUrl && !this.fallbackResolver?.(providerId)) {
|
|
823
823
|
try {
|
|
824
824
|
const hostname = new URL(options.baseUrl).hostname;
|
|
825
825
|
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "0.0.0.0" || hostname === "::1") {
|
|
@@ -94,7 +94,7 @@ function createHost() {
|
|
|
94
94
|
return host;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
test("chat-controller
|
|
97
|
+
test("chat-controller renders content blocks in content[] index order (tool-first stream)", async () => {
|
|
98
98
|
// ToolExecutionComponent uses the global theme singleton.
|
|
99
99
|
// Install a minimal no-op theme implementation for this unit test.
|
|
100
100
|
(globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
|
|
@@ -116,7 +116,6 @@ test("chat-controller keeps tool output ahead of delayed assistant text for exte
|
|
|
116
116
|
|
|
117
117
|
await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
|
|
118
118
|
|
|
119
|
-
assert.equal(host.streamingComponent, undefined, "assistant component should be deferred at message_start");
|
|
120
119
|
assert.equal(host.chatContainer.children.length, 0, "nothing should render before content arrives");
|
|
121
120
|
|
|
122
121
|
await handleAgentEvent(
|
|
@@ -140,11 +139,10 @@ test("chat-controller keeps tool output ahead of delayed assistant text for exte
|
|
|
140
139
|
} as any,
|
|
141
140
|
);
|
|
142
141
|
|
|
143
|
-
|
|
142
|
+
// content[0] = toolCall → ToolExecutionComponent renders first
|
|
144
143
|
assert.equal(host.chatContainer.children.length, 1, "tool execution block should render immediately");
|
|
145
144
|
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
146
145
|
|
|
147
|
-
// Re-assert required host method before the text-bearing update path.
|
|
148
146
|
host.getMarkdownThemeWithSettings = () => ({});
|
|
149
147
|
|
|
150
148
|
await handleAgentEvent(
|
|
@@ -161,12 +159,13 @@ test("chat-controller keeps tool output ahead of delayed assistant text for exte
|
|
|
161
159
|
} as any,
|
|
162
160
|
);
|
|
163
161
|
|
|
164
|
-
|
|
162
|
+
// content[0]=toolCall, content[1]=text → order: tool, then text
|
|
163
|
+
assert.equal(host.chatContainer.children.length, 2, "text run should render after tool in content[] order");
|
|
165
164
|
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
166
165
|
assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
|
|
167
166
|
});
|
|
168
167
|
|
|
169
|
-
test("chat-controller
|
|
168
|
+
test("chat-controller renders serverToolUse before trailing text matching content[] index order", async () => {
|
|
170
169
|
(globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
|
|
171
170
|
fg: (_key: string, text: string) => text,
|
|
172
171
|
bg: (_key: string, text: string) => text,
|
|
@@ -199,7 +198,7 @@ test("chat-controller keeps serverToolUse output ahead of assistant text when ex
|
|
|
199
198
|
} as any,
|
|
200
199
|
);
|
|
201
200
|
|
|
202
|
-
|
|
201
|
+
// content[0] = serverToolUse → ToolExecutionComponent renders first
|
|
203
202
|
assert.equal(host.chatContainer.children.length, 1, "server tool block should render immediately");
|
|
204
203
|
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
205
204
|
|
|
@@ -229,7 +228,8 @@ test("chat-controller keeps serverToolUse output ahead of assistant text when ex
|
|
|
229
228
|
} as any,
|
|
230
229
|
);
|
|
231
230
|
|
|
232
|
-
|
|
231
|
+
// content[0]=serverToolUse, content[1]=text → order: tool, then text
|
|
232
|
+
assert.equal(host.chatContainer.children.length, 2, "text run should render after server tool in content[] order");
|
|
233
233
|
assert.equal(host.chatContainer.children[0]?.constructor?.name, "ToolExecutionComponent");
|
|
234
234
|
assert.equal(host.chatContainer.children[1]?.constructor?.name, "AssistantMessageComponent");
|
|
235
235
|
});
|
|
@@ -466,3 +466,193 @@ test("chat-controller does not pin when there are no tool calls", async () => {
|
|
|
466
466
|
|
|
467
467
|
assert.equal(host.pinnedMessageContainer.children.length, 0, "pinned zone should stay empty without tool calls");
|
|
468
468
|
});
|
|
469
|
+
|
|
470
|
+
// Regression test for issue #4144: interleaved text/tool content must render in content[] index order.
|
|
471
|
+
// Stream: [text "A", toolCall T1, text "B", toolCall T2, text "C"]
|
|
472
|
+
// Expected chatContainer order: textRun(A), toolExec(T1), textRun(B), toolExec(T2), textRun(C)
|
|
473
|
+
// Each AssistantMessageComponent must render ONLY its own text — no duplication after message_end.
|
|
474
|
+
test("chat-controller renders interleaved text and tool blocks in content[] index order (#4144)", async () => {
|
|
475
|
+
(globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
|
|
476
|
+
fg: (_key: string, text: string) => text,
|
|
477
|
+
bg: (_key: string, text: string) => text,
|
|
478
|
+
bold: (text: string) => text,
|
|
479
|
+
italic: (text: string) => text,
|
|
480
|
+
truncate: (text: string) => text,
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
const host = createHost();
|
|
484
|
+
host.getMarkdownThemeWithSettings = () => ({});
|
|
485
|
+
|
|
486
|
+
const t1 = { type: "toolCall", id: "t1", name: "tool_one", arguments: {} };
|
|
487
|
+
const t2 = { type: "toolCall", id: "t2", name: "tool_two", arguments: {} };
|
|
488
|
+
|
|
489
|
+
await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
|
|
490
|
+
|
|
491
|
+
// Stream text "A" at index 0
|
|
492
|
+
await handleAgentEvent(host, {
|
|
493
|
+
type: "message_update",
|
|
494
|
+
message: makeAssistant([{ type: "text", text: "A" }]),
|
|
495
|
+
assistantMessageEvent: {
|
|
496
|
+
type: "text_delta",
|
|
497
|
+
contentIndex: 0,
|
|
498
|
+
delta: "A",
|
|
499
|
+
partial: makeAssistant([{ type: "text", text: "A" }]),
|
|
500
|
+
},
|
|
501
|
+
} as any);
|
|
502
|
+
|
|
503
|
+
// Stream toolCall T1 at index 1
|
|
504
|
+
await handleAgentEvent(host, {
|
|
505
|
+
type: "message_update",
|
|
506
|
+
message: makeAssistant([{ type: "text", text: "A" }, t1]),
|
|
507
|
+
assistantMessageEvent: {
|
|
508
|
+
type: "toolcall_end",
|
|
509
|
+
contentIndex: 1,
|
|
510
|
+
toolCall: {
|
|
511
|
+
...t1,
|
|
512
|
+
externalResult: { content: [{ type: "text", text: "result1" }], details: {}, isError: false },
|
|
513
|
+
},
|
|
514
|
+
partial: makeAssistant([{ type: "text", text: "A" }, t1]),
|
|
515
|
+
},
|
|
516
|
+
} as any);
|
|
517
|
+
|
|
518
|
+
// Stream text "B" at index 2
|
|
519
|
+
await handleAgentEvent(host, {
|
|
520
|
+
type: "message_update",
|
|
521
|
+
message: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }]),
|
|
522
|
+
assistantMessageEvent: {
|
|
523
|
+
type: "text_delta",
|
|
524
|
+
contentIndex: 2,
|
|
525
|
+
delta: "B",
|
|
526
|
+
partial: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }]),
|
|
527
|
+
},
|
|
528
|
+
} as any);
|
|
529
|
+
|
|
530
|
+
// Stream toolCall T2 at index 3
|
|
531
|
+
await handleAgentEvent(host, {
|
|
532
|
+
type: "message_update",
|
|
533
|
+
message: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }, t2]),
|
|
534
|
+
assistantMessageEvent: {
|
|
535
|
+
type: "toolcall_end",
|
|
536
|
+
contentIndex: 3,
|
|
537
|
+
toolCall: {
|
|
538
|
+
...t2,
|
|
539
|
+
externalResult: { content: [{ type: "text", text: "result2" }], details: {}, isError: false },
|
|
540
|
+
},
|
|
541
|
+
partial: makeAssistant([{ type: "text", text: "A" }, t1, { type: "text", text: "B" }, t2]),
|
|
542
|
+
},
|
|
543
|
+
} as any);
|
|
544
|
+
|
|
545
|
+
// Stream text "C" at index 4
|
|
546
|
+
const finalContent = [
|
|
547
|
+
{ type: "text", text: "A" }, t1, { type: "text", text: "B" }, t2, { type: "text", text: "C" },
|
|
548
|
+
];
|
|
549
|
+
await handleAgentEvent(host, {
|
|
550
|
+
type: "message_update",
|
|
551
|
+
message: makeAssistant(finalContent),
|
|
552
|
+
assistantMessageEvent: {
|
|
553
|
+
type: "text_delta",
|
|
554
|
+
contentIndex: 4,
|
|
555
|
+
delta: "C",
|
|
556
|
+
partial: makeAssistant(finalContent),
|
|
557
|
+
},
|
|
558
|
+
} as any);
|
|
559
|
+
|
|
560
|
+
// Finalize — exercises the message_end path where a buggy setRange(undefined) would cause duplication
|
|
561
|
+
await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
|
|
562
|
+
|
|
563
|
+
// Assert interleaved order: textRun(A), toolExec(T1), textRun(B), toolExec(T2), textRun(C)
|
|
564
|
+
assert.equal(host.chatContainer.children.length, 5, "should have 5 children in interleaved order");
|
|
565
|
+
assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent", "index 0: text run A");
|
|
566
|
+
assert.equal(host.chatContainer.children[1]?.constructor?.name, "ToolExecutionComponent", "index 1: tool T1");
|
|
567
|
+
assert.equal(host.chatContainer.children[2]?.constructor?.name, "AssistantMessageComponent", "index 2: text run B");
|
|
568
|
+
assert.equal(host.chatContainer.children[3]?.constructor?.name, "ToolExecutionComponent", "index 3: tool T2");
|
|
569
|
+
assert.equal(host.chatContainer.children[4]?.constructor?.name, "AssistantMessageComponent", "index 4: text run C");
|
|
570
|
+
|
|
571
|
+
// Helper: collect the text of all Markdown children inside an AssistantMessageComponent.
|
|
572
|
+
// Structure: AssistantMessageComponent (Container) -> contentContainer (children[0]) -> Markdown nodes.
|
|
573
|
+
function getRenderedTexts(comp: any): string[] {
|
|
574
|
+
const contentContainer = comp.children?.[0];
|
|
575
|
+
if (!contentContainer) return [];
|
|
576
|
+
return (contentContainer.children ?? [])
|
|
577
|
+
.filter((c: any) => c.constructor?.name === "Markdown")
|
|
578
|
+
.map((c: any) => (c as any).text as string);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Each text-run component must contain only its own text — no cross-contamination after message_end
|
|
582
|
+
assert.deepEqual(getRenderedTexts(host.chatContainer.children[0]), ["A"], "text run A must contain only 'A'");
|
|
583
|
+
assert.deepEqual(getRenderedTexts(host.chatContainer.children[2]), ["B"], "text run B must contain only 'B'");
|
|
584
|
+
assert.deepEqual(getRenderedTexts(host.chatContainer.children[4]), ["C"], "text run C must contain only 'C'");
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
test("chat-controller does not duplicate text when content is [text, tool, text] (interleaved stream)", async () => {
|
|
588
|
+
(globalThis as any)[Symbol.for("@gsd/pi-coding-agent:theme")] = {
|
|
589
|
+
fg: (_key: string, text: string) => text,
|
|
590
|
+
bg: (_key: string, text: string) => text,
|
|
591
|
+
bold: (text: string) => text,
|
|
592
|
+
italic: (text: string) => text,
|
|
593
|
+
truncate: (text: string) => text,
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
const host = createHost();
|
|
597
|
+
host.getMarkdownThemeWithSettings = () => ({});
|
|
598
|
+
|
|
599
|
+
const t1 = { type: "toolCall", id: "t1", name: "tool_one", arguments: {} };
|
|
600
|
+
|
|
601
|
+
await handleAgentEvent(host, { type: "message_start", message: makeAssistant([]) } as any);
|
|
602
|
+
|
|
603
|
+
// Step 1: text "A" at index 0
|
|
604
|
+
await handleAgentEvent(host, {
|
|
605
|
+
type: "message_update",
|
|
606
|
+
message: makeAssistant([{ type: "text", text: "A" }]),
|
|
607
|
+
assistantMessageEvent: {
|
|
608
|
+
type: "text_delta",
|
|
609
|
+
contentIndex: 0,
|
|
610
|
+
delta: "A",
|
|
611
|
+
partial: makeAssistant([{ type: "text", text: "A" }]),
|
|
612
|
+
},
|
|
613
|
+
} as any);
|
|
614
|
+
|
|
615
|
+
// Step 2: toolCall at index 1
|
|
616
|
+
await handleAgentEvent(host, {
|
|
617
|
+
type: "message_update",
|
|
618
|
+
message: makeAssistant([{ type: "text", text: "A" }, t1]),
|
|
619
|
+
assistantMessageEvent: {
|
|
620
|
+
type: "toolcall_end",
|
|
621
|
+
contentIndex: 1,
|
|
622
|
+
toolCall: {
|
|
623
|
+
...t1,
|
|
624
|
+
externalResult: { content: [{ type: "text", text: "result1" }], details: {}, isError: false },
|
|
625
|
+
},
|
|
626
|
+
partial: makeAssistant([{ type: "text", text: "A" }, t1]),
|
|
627
|
+
},
|
|
628
|
+
} as any);
|
|
629
|
+
|
|
630
|
+
// Step 3: text "B" at index 2
|
|
631
|
+
const finalContent = [{ type: "text", text: "A" }, t1, { type: "text", text: "B" }];
|
|
632
|
+
await handleAgentEvent(host, {
|
|
633
|
+
type: "message_update",
|
|
634
|
+
message: makeAssistant(finalContent),
|
|
635
|
+
assistantMessageEvent: {
|
|
636
|
+
type: "text_delta",
|
|
637
|
+
contentIndex: 2,
|
|
638
|
+
delta: "B",
|
|
639
|
+
partial: makeAssistant(finalContent),
|
|
640
|
+
},
|
|
641
|
+
} as any);
|
|
642
|
+
|
|
643
|
+
assert.equal(host.chatContainer.children.length, 3);
|
|
644
|
+
assert.equal(host.chatContainer.children[0]?.constructor?.name, "AssistantMessageComponent");
|
|
645
|
+
assert.equal(host.chatContainer.children[1]?.constructor?.name, "ToolExecutionComponent");
|
|
646
|
+
assert.equal(host.chatContainer.children[2]?.constructor?.name, "AssistantMessageComponent");
|
|
647
|
+
|
|
648
|
+
const firstText = host.chatContainer.children[0];
|
|
649
|
+
const secondText = host.chatContainer.children[2];
|
|
650
|
+
assert.notEqual(firstText, secondText, "text-before-tool and text-after-tool must be separate component instances");
|
|
651
|
+
assert.deepEqual((firstText as any).range, { startIndex: 0, endIndex: 0 }, "first text-run covers only content[0]");
|
|
652
|
+
assert.deepEqual((secondText as any).range, { startIndex: 2, endIndex: 2 }, "second text-run covers only content[2]");
|
|
653
|
+
|
|
654
|
+
// Finalize — regression guard: range must NOT be cleared on message_end (would cause duplication)
|
|
655
|
+
await handleAgentEvent(host, { type: "message_end", message: makeAssistant(finalContent) } as any);
|
|
656
|
+
|
|
657
|
+
assert.deepEqual((secondText as any).range, { startIndex: 2, endIndex: 2 }, "range must not be cleared on message_end (would cause duplication)");
|
|
658
|
+
});
|