easc-cli 1.1.28
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/AGENTS.md +27 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/opencode +108 -0
- package/bunfig.toml +7 -0
- package/package.json +132 -0
- package/parsers-config.ts +253 -0
- package/script/build.ts +172 -0
- package/script/deploy.ts +64 -0
- package/script/postinstall.mjs +125 -0
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +70 -0
- package/script/schema.ts +47 -0
- package/script/seed-e2e.ts +50 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1285 -0
- package/src/acp/session.ts +105 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +332 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +12 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +43 -0
- package/src/auth/eliseart.ts +76 -0
- package/src/auth/index.ts +73 -0
- package/src/bun/index.ts +134 -0
- package/src/bus/bus-event.ts +43 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +105 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/account.ts +81 -0
- package/src/cli/cmd/acp.ts +69 -0
- package/src/cli/cmd/agent.ts +257 -0
- package/src/cli/cmd/auth.ts +427 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/agent.ts +166 -0
- package/src/cli/cmd/debug/config.ts +16 -0
- package/src/cli/cmd/debug/file.ts +97 -0
- package/src/cli/cmd/debug/index.ts +48 -0
- package/src/cli/cmd/debug/lsp.ts +52 -0
- package/src/cli/cmd/debug/ripgrep.ts +87 -0
- package/src/cli/cmd/debug/scrap.ts +16 -0
- package/src/cli/cmd/debug/skill.ts +16 -0
- package/src/cli/cmd/debug/snapshot.ts +52 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1548 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +827 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +407 -0
- package/src/cli/cmd/serve.ts +20 -0
- package/src/cli/cmd/session.ts +135 -0
- package/src/cli/cmd/stats.ts +402 -0
- package/src/cli/cmd/tui/app.tsx +774 -0
- package/src/cli/cmd/tui/attach.ts +31 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +148 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +256 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +114 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +164 -0
- package/src/cli/cmd/tui/component/dialog-supabase.tsx +102 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/logo.tsx +88 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +653 -0
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1182 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/spinner.tsx +16 -0
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
- package/src/cli/cmd/tui/component/tips.tsx +153 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/exit.tsx +23 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +101 -0
- package/src/cli/cmd/tui/context/kv.tsx +52 -0
- package/src/cli/cmd/tui/context/local.tsx +402 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +46 -0
- package/src/cli/cmd/tui/context/sdk.tsx +94 -0
- package/src/cli/cmd/tui/context/sync.tsx +445 -0
- package/src/cli/cmd/tui/context/theme/aura.json +69 -0
- package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
- package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
- package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
- package/src/cli/cmd/tui/context/theme/orng.json +249 -0
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
- package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme.tsx +1152 -0
- package/src/cli/cmd/tui/event.ts +48 -0
- package/src/cli/cmd/tui/routes/home.tsx +140 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/dialog-tool.tsx +63 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +129 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +136 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +2132 -0
- package/src/cli/cmd/tui/routes/session/permission.tsx +495 -0
- package/src/cli/cmd/tui/routes/session/question.tsx +435 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
- package/src/cli/cmd/tui/thread.ts +165 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +204 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +376 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +167 -0
- package/src/cli/cmd/tui/ui/link.tsx +28 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +160 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/signal.ts +7 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/util/transcript.ts +98 -0
- package/src/cli/cmd/tui/worker.ts +152 -0
- package/src/cli/cmd/uninstall.ts +357 -0
- package/src/cli/cmd/upgrade.ts +73 -0
- package/src/cli/cmd/web.ts +81 -0
- package/src/cli/error.ts +57 -0
- package/src/cli/network.ts +53 -0
- package/src/cli/ui.ts +84 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +131 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +99 -0
- package/src/config/config.ts +1361 -0
- package/src/config/markdown.ts +93 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +411 -0
- package/src/file/ripgrep.ts +407 -0
- package/src/file/time.ts +64 -0
- package/src/file/watcher.ts +127 -0
- package/src/flag/flag.ts +54 -0
- package/src/format/formatter.ts +342 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +55 -0
- package/src/id/id.ts +83 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +162 -0
- package/src/installation/index.ts +246 -0
- package/src/lsp/client.ts +252 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +119 -0
- package/src/lsp/server.ts +2046 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +931 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +680 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/index.ts +210 -0
- package/src/permission/next.ts +269 -0
- package/src/plugin/codex.ts +493 -0
- package/src/plugin/copilot.ts +269 -0
- package/src/plugin/index.ts +135 -0
- package/src/project/bootstrap.ts +35 -0
- package/src/project/instance.ts +91 -0
- package/src/project/project.ts +339 -0
- package/src/project/state.ts +66 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +147 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +112 -0
- package/src/provider/provider.ts +1391 -0
- package/src/provider/sdk/openai-compatible/src/README.md +5 -0
- package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1732 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +733 -0
- package/src/pty/index.ts +232 -0
- package/src/question/index.ts +171 -0
- package/src/scheduler/index.ts +61 -0
- package/src/server/error.ts +36 -0
- package/src/server/event.ts +7 -0
- package/src/server/mdns.ts +59 -0
- package/src/server/routes/config.ts +92 -0
- package/src/server/routes/experimental.ts +208 -0
- package/src/server/routes/file.ts +197 -0
- package/src/server/routes/global.ts +135 -0
- package/src/server/routes/mcp.ts +361 -0
- package/src/server/routes/permission.ts +68 -0
- package/src/server/routes/project.ts +82 -0
- package/src/server/routes/provider.ts +165 -0
- package/src/server/routes/pty.ts +169 -0
- package/src/server/routes/question.ts +98 -0
- package/src/server/routes/session.ts +935 -0
- package/src/server/routes/tui.ts +379 -0
- package/src/server/server.ts +573 -0
- package/src/session/compaction.ts +225 -0
- package/src/session/index.ts +488 -0
- package/src/session/llm.ts +279 -0
- package/src/session/message-v2.ts +702 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +406 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex_header.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/qwen.txt +109 -0
- package/src/session/prompt.ts +1820 -0
- package/src/session/retry.ts +90 -0
- package/src/session/revert.ts +108 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +150 -0
- package/src/session/system.ts +152 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +200 -0
- package/src/share/share.ts +92 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +136 -0
- package/src/snapshot/index.ts +236 -0
- package/src/storage/storage.ts +227 -0
- package/src/tool/apply_patch.ts +269 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/bash.ts +259 -0
- package/src/tool/bash.txt +115 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +132 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +645 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +32 -0
- package/src/tool/glob.ts +77 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +154 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +121 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp.ts +96 -0
- package/src/tool/lsp.txt +19 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +130 -0
- package/src/tool/question.ts +33 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +202 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +163 -0
- package/src/tool/skill.ts +75 -0
- package/src/tool/task.ts +188 -0
- package/src/tool/task.txt +60 -0
- package/src/tool/todo.ts +53 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +88 -0
- package/src/tool/truncation.ts +106 -0
- package/src/tool/webfetch.ts +182 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +150 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +80 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +16 -0
- package/src/util/color.ts +19 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +93 -0
- package/src/util/fn.ts +11 -0
- package/src/util/format.ts +20 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +103 -0
- package/src/util/lazy.ts +18 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +180 -0
- package/src/util/queue.ts +32 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +56 -0
- package/src/worktree/index.ts +424 -0
- package/sst-env.d.ts +9 -0
- package/test/acp/event-subscription.test.ts +436 -0
- package/test/agent/agent.test.ts +638 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/github-action.test.ts +129 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/cli/tui/transcript.test.ts +297 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +1414 -0
- package/test/config/fixtures/empty-frontmatter.md +4 -0
- package/test/config/fixtures/frontmatter.md +28 -0
- package/test/config/fixtures/no-frontmatter.md +1 -0
- package/test/config/markdown.test.ts +192 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/file/path-traversal.test.ts +198 -0
- package/test/fixture/fixture.ts +45 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +421 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/mcp/headers.test.ts +153 -0
- package/test/mcp/oauth-browser.test.ts +261 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/permission/arity.test.ts +33 -0
- package/test/permission/next.test.ts +652 -0
- package/test/permission-task.test.ts +319 -0
- package/test/plugin/codex.test.ts +123 -0
- package/test/preload.ts +65 -0
- package/test/project/project.test.ts +120 -0
- package/test/provider/amazon-bedrock.test.ts +268 -0
- package/test/provider/gitlab-duo.test.ts +286 -0
- package/test/provider/provider.test.ts +2149 -0
- package/test/provider/transform.test.ts +1596 -0
- package/test/question/question.test.ts +300 -0
- package/test/scheduler.test.ts +73 -0
- package/test/server/session-list.test.ts +39 -0
- package/test/server/session-select.test.ts +78 -0
- package/test/session/compaction.test.ts +293 -0
- package/test/session/llm.test.ts +90 -0
- package/test/session/message-v2.test.ts +662 -0
- package/test/session/retry.test.ts +131 -0
- package/test/session/revert-compact.test.ts +285 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +185 -0
- package/test/snapshot/snapshot.test.ts +939 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/apply_patch.test.ts +499 -0
- package/test/tool/bash.test.ts +320 -0
- package/test/tool/external-directory.test.ts +126 -0
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +33453 -0
- package/test/tool/grep.test.ts +109 -0
- package/test/tool/question.test.ts +105 -0
- package/test/tool/read.test.ts +332 -0
- package/test/tool/registry.test.ts +76 -0
- package/test/tool/truncation.test.ts +159 -0
- package/test/util/filesystem.test.ts +39 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/lock.test.ts +72 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +75 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { MessageV2 } from "../../src/session/message-v2"
|
|
3
|
+
|
|
4
|
+
const sessionID = "session"
|
|
5
|
+
|
|
6
|
+
function userInfo(id: string): MessageV2.User {
|
|
7
|
+
return {
|
|
8
|
+
id,
|
|
9
|
+
sessionID,
|
|
10
|
+
role: "user",
|
|
11
|
+
time: { created: 0 },
|
|
12
|
+
agent: "user",
|
|
13
|
+
model: { providerID: "test", modelID: "test" },
|
|
14
|
+
tools: {},
|
|
15
|
+
mode: "",
|
|
16
|
+
} as unknown as MessageV2.User
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function assistantInfo(id: string, parentID: string, error?: MessageV2.Assistant["error"]): MessageV2.Assistant {
|
|
20
|
+
return {
|
|
21
|
+
id,
|
|
22
|
+
sessionID,
|
|
23
|
+
role: "assistant",
|
|
24
|
+
time: { created: 0 },
|
|
25
|
+
error,
|
|
26
|
+
parentID,
|
|
27
|
+
modelID: "model",
|
|
28
|
+
providerID: "provider",
|
|
29
|
+
mode: "",
|
|
30
|
+
agent: "agent",
|
|
31
|
+
path: { cwd: "/", root: "/" },
|
|
32
|
+
cost: 0,
|
|
33
|
+
tokens: {
|
|
34
|
+
input: 0,
|
|
35
|
+
output: 0,
|
|
36
|
+
reasoning: 0,
|
|
37
|
+
cache: { read: 0, write: 0 },
|
|
38
|
+
},
|
|
39
|
+
} as unknown as MessageV2.Assistant
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function basePart(messageID: string, id: string) {
|
|
43
|
+
return {
|
|
44
|
+
id,
|
|
45
|
+
sessionID,
|
|
46
|
+
messageID,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe("session.message-v2.toModelMessage", () => {
|
|
51
|
+
test("filters out messages with no parts", () => {
|
|
52
|
+
const input: MessageV2.WithParts[] = [
|
|
53
|
+
{
|
|
54
|
+
info: userInfo("m-empty"),
|
|
55
|
+
parts: [],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
info: userInfo("m-user"),
|
|
59
|
+
parts: [
|
|
60
|
+
{
|
|
61
|
+
...basePart("m-user", "p1"),
|
|
62
|
+
type: "text",
|
|
63
|
+
text: "hello",
|
|
64
|
+
},
|
|
65
|
+
] as MessageV2.Part[],
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
70
|
+
{
|
|
71
|
+
role: "user",
|
|
72
|
+
content: [{ type: "text", text: "hello" }],
|
|
73
|
+
},
|
|
74
|
+
])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test("filters out messages with only ignored parts", () => {
|
|
78
|
+
const messageID = "m-user"
|
|
79
|
+
|
|
80
|
+
const input: MessageV2.WithParts[] = [
|
|
81
|
+
{
|
|
82
|
+
info: userInfo(messageID),
|
|
83
|
+
parts: [
|
|
84
|
+
{
|
|
85
|
+
...basePart(messageID, "p1"),
|
|
86
|
+
type: "text",
|
|
87
|
+
text: "ignored",
|
|
88
|
+
ignored: true,
|
|
89
|
+
},
|
|
90
|
+
] as MessageV2.Part[],
|
|
91
|
+
},
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([])
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test("includes synthetic text parts", () => {
|
|
98
|
+
const messageID = "m-user"
|
|
99
|
+
|
|
100
|
+
const input: MessageV2.WithParts[] = [
|
|
101
|
+
{
|
|
102
|
+
info: userInfo(messageID),
|
|
103
|
+
parts: [
|
|
104
|
+
{
|
|
105
|
+
...basePart(messageID, "p1"),
|
|
106
|
+
type: "text",
|
|
107
|
+
text: "hello",
|
|
108
|
+
synthetic: true,
|
|
109
|
+
},
|
|
110
|
+
] as MessageV2.Part[],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
info: assistantInfo("m-assistant", messageID),
|
|
114
|
+
parts: [
|
|
115
|
+
{
|
|
116
|
+
...basePart("m-assistant", "a1"),
|
|
117
|
+
type: "text",
|
|
118
|
+
text: "assistant",
|
|
119
|
+
synthetic: true,
|
|
120
|
+
},
|
|
121
|
+
] as MessageV2.Part[],
|
|
122
|
+
},
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
126
|
+
{
|
|
127
|
+
role: "user",
|
|
128
|
+
content: [{ type: "text", text: "hello" }],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
role: "assistant",
|
|
132
|
+
content: [{ type: "text", text: "assistant" }],
|
|
133
|
+
},
|
|
134
|
+
])
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test("converts user text/file parts and injects compaction/subtask prompts", () => {
|
|
138
|
+
const messageID = "m-user"
|
|
139
|
+
|
|
140
|
+
const input: MessageV2.WithParts[] = [
|
|
141
|
+
{
|
|
142
|
+
info: userInfo(messageID),
|
|
143
|
+
parts: [
|
|
144
|
+
{
|
|
145
|
+
...basePart(messageID, "p1"),
|
|
146
|
+
type: "text",
|
|
147
|
+
text: "hello",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
...basePart(messageID, "p2"),
|
|
151
|
+
type: "text",
|
|
152
|
+
text: "ignored",
|
|
153
|
+
ignored: true,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
...basePart(messageID, "p3"),
|
|
157
|
+
type: "file",
|
|
158
|
+
mime: "image/png",
|
|
159
|
+
filename: "img.png",
|
|
160
|
+
url: "https://example.com/img.png",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
...basePart(messageID, "p4"),
|
|
164
|
+
type: "file",
|
|
165
|
+
mime: "text/plain",
|
|
166
|
+
filename: "note.txt",
|
|
167
|
+
url: "https://example.com/note.txt",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
...basePart(messageID, "p5"),
|
|
171
|
+
type: "file",
|
|
172
|
+
mime: "application/x-directory",
|
|
173
|
+
filename: "dir",
|
|
174
|
+
url: "https://example.com/dir",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
...basePart(messageID, "p6"),
|
|
178
|
+
type: "compaction",
|
|
179
|
+
auto: true,
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
...basePart(messageID, "p7"),
|
|
183
|
+
type: "subtask",
|
|
184
|
+
prompt: "prompt",
|
|
185
|
+
description: "desc",
|
|
186
|
+
agent: "agent",
|
|
187
|
+
},
|
|
188
|
+
] as MessageV2.Part[],
|
|
189
|
+
},
|
|
190
|
+
]
|
|
191
|
+
|
|
192
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
193
|
+
{
|
|
194
|
+
role: "user",
|
|
195
|
+
content: [
|
|
196
|
+
{ type: "text", text: "hello" },
|
|
197
|
+
{
|
|
198
|
+
type: "file",
|
|
199
|
+
mediaType: "image/png",
|
|
200
|
+
filename: "img.png",
|
|
201
|
+
data: "https://example.com/img.png",
|
|
202
|
+
},
|
|
203
|
+
{ type: "text", text: "What did we do so far?" },
|
|
204
|
+
{ type: "text", text: "The following tool was executed by the user" },
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
])
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test("converts assistant tool completion into tool-call + tool-result messages and emits attachment message", () => {
|
|
211
|
+
const userID = "m-user"
|
|
212
|
+
const assistantID = "m-assistant"
|
|
213
|
+
|
|
214
|
+
const input: MessageV2.WithParts[] = [
|
|
215
|
+
{
|
|
216
|
+
info: userInfo(userID),
|
|
217
|
+
parts: [
|
|
218
|
+
{
|
|
219
|
+
...basePart(userID, "u1"),
|
|
220
|
+
type: "text",
|
|
221
|
+
text: "run tool",
|
|
222
|
+
},
|
|
223
|
+
] as MessageV2.Part[],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
info: assistantInfo(assistantID, userID),
|
|
227
|
+
parts: [
|
|
228
|
+
{
|
|
229
|
+
...basePart(assistantID, "a1"),
|
|
230
|
+
type: "text",
|
|
231
|
+
text: "done",
|
|
232
|
+
metadata: { openai: { assistant: "meta" } },
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
...basePart(assistantID, "a2"),
|
|
236
|
+
type: "tool",
|
|
237
|
+
callID: "call-1",
|
|
238
|
+
tool: "bash",
|
|
239
|
+
state: {
|
|
240
|
+
status: "completed",
|
|
241
|
+
input: { cmd: "ls" },
|
|
242
|
+
output: "ok",
|
|
243
|
+
title: "Bash",
|
|
244
|
+
metadata: {},
|
|
245
|
+
time: { start: 0, end: 1 },
|
|
246
|
+
attachments: [
|
|
247
|
+
{
|
|
248
|
+
...basePart(assistantID, "file-1"),
|
|
249
|
+
type: "file",
|
|
250
|
+
mime: "image/png",
|
|
251
|
+
filename: "attachment.png",
|
|
252
|
+
url: "https://example.com/attachment.png",
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
metadata: { openai: { tool: "meta" } },
|
|
257
|
+
},
|
|
258
|
+
] as MessageV2.Part[],
|
|
259
|
+
},
|
|
260
|
+
]
|
|
261
|
+
|
|
262
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
263
|
+
{
|
|
264
|
+
role: "user",
|
|
265
|
+
content: [{ type: "text", text: "run tool" }],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
role: "user",
|
|
269
|
+
content: [
|
|
270
|
+
{ type: "text", text: "The tool bash returned the following attachments:" },
|
|
271
|
+
{
|
|
272
|
+
type: "file",
|
|
273
|
+
mediaType: "image/png",
|
|
274
|
+
filename: "attachment.png",
|
|
275
|
+
data: "https://example.com/attachment.png",
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
role: "assistant",
|
|
281
|
+
content: [
|
|
282
|
+
{ type: "text", text: "done", providerOptions: { openai: { assistant: "meta" } } },
|
|
283
|
+
{
|
|
284
|
+
type: "tool-call",
|
|
285
|
+
toolCallId: "call-1",
|
|
286
|
+
toolName: "bash",
|
|
287
|
+
input: { cmd: "ls" },
|
|
288
|
+
providerExecuted: undefined,
|
|
289
|
+
providerOptions: { openai: { tool: "meta" } },
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
role: "tool",
|
|
295
|
+
content: [
|
|
296
|
+
{
|
|
297
|
+
type: "tool-result",
|
|
298
|
+
toolCallId: "call-1",
|
|
299
|
+
toolName: "bash",
|
|
300
|
+
output: { type: "text", value: "ok" },
|
|
301
|
+
providerOptions: { openai: { tool: "meta" } },
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
])
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
test("replaces compacted tool output with placeholder", () => {
|
|
309
|
+
const userID = "m-user"
|
|
310
|
+
const assistantID = "m-assistant"
|
|
311
|
+
|
|
312
|
+
const input: MessageV2.WithParts[] = [
|
|
313
|
+
{
|
|
314
|
+
info: userInfo(userID),
|
|
315
|
+
parts: [
|
|
316
|
+
{
|
|
317
|
+
...basePart(userID, "u1"),
|
|
318
|
+
type: "text",
|
|
319
|
+
text: "run tool",
|
|
320
|
+
},
|
|
321
|
+
] as MessageV2.Part[],
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
info: assistantInfo(assistantID, userID),
|
|
325
|
+
parts: [
|
|
326
|
+
{
|
|
327
|
+
...basePart(assistantID, "a1"),
|
|
328
|
+
type: "tool",
|
|
329
|
+
callID: "call-1",
|
|
330
|
+
tool: "bash",
|
|
331
|
+
state: {
|
|
332
|
+
status: "completed",
|
|
333
|
+
input: { cmd: "ls" },
|
|
334
|
+
output: "this should be cleared",
|
|
335
|
+
title: "Bash",
|
|
336
|
+
metadata: {},
|
|
337
|
+
time: { start: 0, end: 1, compacted: 1 },
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
] as MessageV2.Part[],
|
|
341
|
+
},
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
345
|
+
{
|
|
346
|
+
role: "user",
|
|
347
|
+
content: [{ type: "text", text: "run tool" }],
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
role: "assistant",
|
|
351
|
+
content: [
|
|
352
|
+
{
|
|
353
|
+
type: "tool-call",
|
|
354
|
+
toolCallId: "call-1",
|
|
355
|
+
toolName: "bash",
|
|
356
|
+
input: { cmd: "ls" },
|
|
357
|
+
providerExecuted: undefined,
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
role: "tool",
|
|
363
|
+
content: [
|
|
364
|
+
{
|
|
365
|
+
type: "tool-result",
|
|
366
|
+
toolCallId: "call-1",
|
|
367
|
+
toolName: "bash",
|
|
368
|
+
output: { type: "text", value: "[Old tool result content cleared]" },
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
])
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test("converts assistant tool error into error-text tool result", () => {
|
|
376
|
+
const userID = "m-user"
|
|
377
|
+
const assistantID = "m-assistant"
|
|
378
|
+
|
|
379
|
+
const input: MessageV2.WithParts[] = [
|
|
380
|
+
{
|
|
381
|
+
info: userInfo(userID),
|
|
382
|
+
parts: [
|
|
383
|
+
{
|
|
384
|
+
...basePart(userID, "u1"),
|
|
385
|
+
type: "text",
|
|
386
|
+
text: "run tool",
|
|
387
|
+
},
|
|
388
|
+
] as MessageV2.Part[],
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
info: assistantInfo(assistantID, userID),
|
|
392
|
+
parts: [
|
|
393
|
+
{
|
|
394
|
+
...basePart(assistantID, "a1"),
|
|
395
|
+
type: "tool",
|
|
396
|
+
callID: "call-1",
|
|
397
|
+
tool: "bash",
|
|
398
|
+
state: {
|
|
399
|
+
status: "error",
|
|
400
|
+
input: { cmd: "ls" },
|
|
401
|
+
error: "nope",
|
|
402
|
+
time: { start: 0, end: 1 },
|
|
403
|
+
metadata: {},
|
|
404
|
+
},
|
|
405
|
+
metadata: { openai: { tool: "meta" } },
|
|
406
|
+
},
|
|
407
|
+
] as MessageV2.Part[],
|
|
408
|
+
},
|
|
409
|
+
]
|
|
410
|
+
|
|
411
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
412
|
+
{
|
|
413
|
+
role: "user",
|
|
414
|
+
content: [{ type: "text", text: "run tool" }],
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
role: "assistant",
|
|
418
|
+
content: [
|
|
419
|
+
{
|
|
420
|
+
type: "tool-call",
|
|
421
|
+
toolCallId: "call-1",
|
|
422
|
+
toolName: "bash",
|
|
423
|
+
input: { cmd: "ls" },
|
|
424
|
+
providerExecuted: undefined,
|
|
425
|
+
providerOptions: { openai: { tool: "meta" } },
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
role: "tool",
|
|
431
|
+
content: [
|
|
432
|
+
{
|
|
433
|
+
type: "tool-result",
|
|
434
|
+
toolCallId: "call-1",
|
|
435
|
+
toolName: "bash",
|
|
436
|
+
output: { type: "error-text", value: "nope" },
|
|
437
|
+
providerOptions: { openai: { tool: "meta" } },
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
])
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
test("filters assistant messages with non-abort errors", () => {
|
|
445
|
+
const assistantID = "m-assistant"
|
|
446
|
+
|
|
447
|
+
const input: MessageV2.WithParts[] = [
|
|
448
|
+
{
|
|
449
|
+
info: assistantInfo(
|
|
450
|
+
assistantID,
|
|
451
|
+
"m-parent",
|
|
452
|
+
new MessageV2.APIError({ message: "boom", isRetryable: true }).toObject() as MessageV2.APIError,
|
|
453
|
+
),
|
|
454
|
+
parts: [
|
|
455
|
+
{
|
|
456
|
+
...basePart(assistantID, "a1"),
|
|
457
|
+
type: "text",
|
|
458
|
+
text: "should not render",
|
|
459
|
+
},
|
|
460
|
+
] as MessageV2.Part[],
|
|
461
|
+
},
|
|
462
|
+
]
|
|
463
|
+
|
|
464
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([])
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
test("includes aborted assistant messages only when they have non-step-start/reasoning content", () => {
|
|
468
|
+
const assistantID1 = "m-assistant-1"
|
|
469
|
+
const assistantID2 = "m-assistant-2"
|
|
470
|
+
|
|
471
|
+
const aborted = new MessageV2.AbortedError({ message: "aborted" }).toObject() as MessageV2.Assistant["error"]
|
|
472
|
+
|
|
473
|
+
const input: MessageV2.WithParts[] = [
|
|
474
|
+
{
|
|
475
|
+
info: assistantInfo(assistantID1, "m-parent", aborted),
|
|
476
|
+
parts: [
|
|
477
|
+
{
|
|
478
|
+
...basePart(assistantID1, "a1"),
|
|
479
|
+
type: "reasoning",
|
|
480
|
+
text: "thinking",
|
|
481
|
+
time: { start: 0 },
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
...basePart(assistantID1, "a2"),
|
|
485
|
+
type: "text",
|
|
486
|
+
text: "partial answer",
|
|
487
|
+
},
|
|
488
|
+
] as MessageV2.Part[],
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
info: assistantInfo(assistantID2, "m-parent", aborted),
|
|
492
|
+
parts: [
|
|
493
|
+
{
|
|
494
|
+
...basePart(assistantID2, "b1"),
|
|
495
|
+
type: "step-start",
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
...basePart(assistantID2, "b2"),
|
|
499
|
+
type: "reasoning",
|
|
500
|
+
text: "thinking",
|
|
501
|
+
time: { start: 0 },
|
|
502
|
+
},
|
|
503
|
+
] as MessageV2.Part[],
|
|
504
|
+
},
|
|
505
|
+
]
|
|
506
|
+
|
|
507
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
508
|
+
{
|
|
509
|
+
role: "assistant",
|
|
510
|
+
content: [
|
|
511
|
+
{ type: "reasoning", text: "thinking", providerOptions: undefined },
|
|
512
|
+
{ type: "text", text: "partial answer" },
|
|
513
|
+
],
|
|
514
|
+
},
|
|
515
|
+
])
|
|
516
|
+
})
|
|
517
|
+
|
|
518
|
+
test("splits assistant messages on step-start boundaries", () => {
|
|
519
|
+
const assistantID = "m-assistant"
|
|
520
|
+
|
|
521
|
+
const input: MessageV2.WithParts[] = [
|
|
522
|
+
{
|
|
523
|
+
info: assistantInfo(assistantID, "m-parent"),
|
|
524
|
+
parts: [
|
|
525
|
+
{
|
|
526
|
+
...basePart(assistantID, "p1"),
|
|
527
|
+
type: "text",
|
|
528
|
+
text: "first",
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
...basePart(assistantID, "p2"),
|
|
532
|
+
type: "step-start",
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
...basePart(assistantID, "p3"),
|
|
536
|
+
type: "text",
|
|
537
|
+
text: "second",
|
|
538
|
+
},
|
|
539
|
+
] as MessageV2.Part[],
|
|
540
|
+
},
|
|
541
|
+
]
|
|
542
|
+
|
|
543
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
544
|
+
{
|
|
545
|
+
role: "assistant",
|
|
546
|
+
content: [{ type: "text", text: "first" }],
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
role: "assistant",
|
|
550
|
+
content: [{ type: "text", text: "second" }],
|
|
551
|
+
},
|
|
552
|
+
])
|
|
553
|
+
})
|
|
554
|
+
|
|
555
|
+
test("drops messages that only contain step-start parts", () => {
|
|
556
|
+
const assistantID = "m-assistant"
|
|
557
|
+
|
|
558
|
+
const input: MessageV2.WithParts[] = [
|
|
559
|
+
{
|
|
560
|
+
info: assistantInfo(assistantID, "m-parent"),
|
|
561
|
+
parts: [
|
|
562
|
+
{
|
|
563
|
+
...basePart(assistantID, "p1"),
|
|
564
|
+
type: "step-start",
|
|
565
|
+
},
|
|
566
|
+
] as MessageV2.Part[],
|
|
567
|
+
},
|
|
568
|
+
]
|
|
569
|
+
|
|
570
|
+
expect(MessageV2.toModelMessage(input)).toStrictEqual([])
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
test("converts pending/running tool calls to error results to prevent dangling tool_use", () => {
|
|
574
|
+
const userID = "m-user"
|
|
575
|
+
const assistantID = "m-assistant"
|
|
576
|
+
|
|
577
|
+
const input: MessageV2.WithParts[] = [
|
|
578
|
+
{
|
|
579
|
+
info: userInfo(userID),
|
|
580
|
+
parts: [
|
|
581
|
+
{
|
|
582
|
+
...basePart(userID, "u1"),
|
|
583
|
+
type: "text",
|
|
584
|
+
text: "run tool",
|
|
585
|
+
},
|
|
586
|
+
] as MessageV2.Part[],
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
info: assistantInfo(assistantID, userID),
|
|
590
|
+
parts: [
|
|
591
|
+
{
|
|
592
|
+
...basePart(assistantID, "a1"),
|
|
593
|
+
type: "tool",
|
|
594
|
+
callID: "call-pending",
|
|
595
|
+
tool: "bash",
|
|
596
|
+
state: {
|
|
597
|
+
status: "pending",
|
|
598
|
+
input: { cmd: "ls" },
|
|
599
|
+
raw: "",
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
...basePart(assistantID, "a2"),
|
|
604
|
+
type: "tool",
|
|
605
|
+
callID: "call-running",
|
|
606
|
+
tool: "read",
|
|
607
|
+
state: {
|
|
608
|
+
status: "running",
|
|
609
|
+
input: { path: "/tmp" },
|
|
610
|
+
time: { start: 0 },
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
] as MessageV2.Part[],
|
|
614
|
+
},
|
|
615
|
+
]
|
|
616
|
+
|
|
617
|
+
const result = MessageV2.toModelMessage(input)
|
|
618
|
+
|
|
619
|
+
expect(result).toStrictEqual([
|
|
620
|
+
{
|
|
621
|
+
role: "user",
|
|
622
|
+
content: [{ type: "text", text: "run tool" }],
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
role: "assistant",
|
|
626
|
+
content: [
|
|
627
|
+
{
|
|
628
|
+
type: "tool-call",
|
|
629
|
+
toolCallId: "call-pending",
|
|
630
|
+
toolName: "bash",
|
|
631
|
+
input: { cmd: "ls" },
|
|
632
|
+
providerExecuted: undefined,
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
type: "tool-call",
|
|
636
|
+
toolCallId: "call-running",
|
|
637
|
+
toolName: "read",
|
|
638
|
+
input: { path: "/tmp" },
|
|
639
|
+
providerExecuted: undefined,
|
|
640
|
+
},
|
|
641
|
+
],
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
role: "tool",
|
|
645
|
+
content: [
|
|
646
|
+
{
|
|
647
|
+
type: "tool-result",
|
|
648
|
+
toolCallId: "call-pending",
|
|
649
|
+
toolName: "bash",
|
|
650
|
+
output: { type: "error-text", value: "[Tool execution was interrupted]" },
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
type: "tool-result",
|
|
654
|
+
toolCallId: "call-running",
|
|
655
|
+
toolName: "read",
|
|
656
|
+
output: { type: "error-text", value: "[Tool execution was interrupted]" },
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
},
|
|
660
|
+
])
|
|
661
|
+
})
|
|
662
|
+
})
|