strands-darwin 0.0.3
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/README.md +140 -0
- package/README.zh-CN.md +140 -0
- package/dist/patches/@strands-agents+sdk+1.16.0.patch +1443 -0
- package/dist/src/agent/background-delegation.d.ts +67 -0
- package/dist/src/agent/background-delegation.js +159 -0
- package/dist/src/agent/background-delegation.js.map +1 -0
- package/dist/src/agent/call-stats.d.ts +118 -0
- package/dist/src/agent/call-stats.js +128 -0
- package/dist/src/agent/call-stats.js.map +1 -0
- package/dist/src/agent/compact.d.ts +108 -0
- package/dist/src/agent/compact.js +192 -0
- package/dist/src/agent/compact.js.map +1 -0
- package/dist/src/agent/context-anchor.d.ts +64 -0
- package/dist/src/agent/context-anchor.js +43 -0
- package/dist/src/agent/context-anchor.js.map +1 -0
- package/dist/src/agent/cost.d.ts +56 -0
- package/dist/src/agent/cost.js +44 -0
- package/dist/src/agent/cost.js.map +1 -0
- package/dist/src/agent/diagnostics.d.ts +212 -0
- package/dist/src/agent/diagnostics.js +374 -0
- package/dist/src/agent/diagnostics.js.map +1 -0
- package/dist/src/agent/instructions.d.ts +54 -0
- package/dist/src/agent/instructions.js +118 -0
- package/dist/src/agent/instructions.js.map +1 -0
- package/dist/src/agent/max-tokens-recovery.d.ts +17 -0
- package/dist/src/agent/max-tokens-recovery.js +65 -0
- package/dist/src/agent/max-tokens-recovery.js.map +1 -0
- package/dist/src/agent/model-call-budget.d.ts +8 -0
- package/dist/src/agent/model-call-budget.js +24 -0
- package/dist/src/agent/model-call-budget.js.map +1 -0
- package/dist/src/agent/model-retry.d.ts +134 -0
- package/dist/src/agent/model-retry.js +256 -0
- package/dist/src/agent/model-retry.js.map +1 -0
- package/dist/src/agent/permission-rules.d.ts +47 -0
- package/dist/src/agent/permission-rules.js +260 -0
- package/dist/src/agent/permission-rules.js.map +1 -0
- package/dist/src/agent/permission.d.ts +361 -0
- package/dist/src/agent/permission.js +797 -0
- package/dist/src/agent/permission.js.map +1 -0
- package/dist/src/agent/prompt-cache.d.ts +66 -0
- package/dist/src/agent/prompt-cache.js +194 -0
- package/dist/src/agent/prompt-cache.js.map +1 -0
- package/dist/src/agent/refusal.d.ts +20 -0
- package/dist/src/agent/refusal.js +23 -0
- package/dist/src/agent/refusal.js.map +1 -0
- package/dist/src/agent/retry-guard.d.ts +26 -0
- package/dist/src/agent/retry-guard.js +193 -0
- package/dist/src/agent/retry-guard.js.map +1 -0
- package/dist/src/agent/rewind.d.ts +29 -0
- package/dist/src/agent/rewind.js +118 -0
- package/dist/src/agent/rewind.js.map +1 -0
- package/dist/src/agent/runtime.d.ts +814 -0
- package/dist/src/agent/runtime.js +1596 -0
- package/dist/src/agent/runtime.js.map +1 -0
- package/dist/src/agent/safety-classifier.d.ts +11 -0
- package/dist/src/agent/safety-classifier.js +0 -0
- package/dist/src/agent/safety-classifier.js.map +1 -0
- package/dist/src/agent/sdk-logging.d.ts +49 -0
- package/dist/src/agent/sdk-logging.js +110 -0
- package/dist/src/agent/sdk-logging.js.map +1 -0
- package/dist/src/agent/session.d.ts +102 -0
- package/dist/src/agent/session.js +244 -0
- package/dist/src/agent/session.js.map +1 -0
- package/dist/src/agent/stream-resumption.d.ts +16 -0
- package/dist/src/agent/stream-resumption.js +33 -0
- package/dist/src/agent/stream-resumption.js.map +1 -0
- package/dist/src/agent/system-prompt.d.ts +50 -0
- package/dist/src/agent/system-prompt.js +161 -0
- package/dist/src/agent/system-prompt.js.map +1 -0
- package/dist/src/agent/thinking.d.ts +99 -0
- package/dist/src/agent/thinking.js +145 -0
- package/dist/src/agent/thinking.js.map +1 -0
- package/dist/src/agent/usage.d.ts +132 -0
- package/dist/src/agent/usage.js +233 -0
- package/dist/src/agent/usage.js.map +1 -0
- package/dist/src/agent/working-context.d.ts +51 -0
- package/dist/src/agent/working-context.js +160 -0
- package/dist/src/agent/working-context.js.map +1 -0
- package/dist/src/agents/child-recipe.d.ts +33 -0
- package/dist/src/agents/child-recipe.js +98 -0
- package/dist/src/agents/child-recipe.js.map +1 -0
- package/dist/src/agents/concurrency-limit.d.ts +25 -0
- package/dist/src/agents/concurrency-limit.js +43 -0
- package/dist/src/agents/concurrency-limit.js.map +1 -0
- package/dist/src/agents/dispatch-registry.d.ts +180 -0
- package/dist/src/agents/dispatch-registry.js +289 -0
- package/dist/src/agents/dispatch-registry.js.map +1 -0
- package/dist/src/agents/failed-child-text.d.ts +44 -0
- package/dist/src/agents/failed-child-text.js +69 -0
- package/dist/src/agents/failed-child-text.js.map +1 -0
- package/dist/src/agents/loader.d.ts +26 -0
- package/dist/src/agents/loader.js +134 -0
- package/dist/src/agents/loader.js.map +1 -0
- package/dist/src/agents/report-projection.d.ts +31 -0
- package/dist/src/agents/report-projection.js +125 -0
- package/dist/src/agents/report-projection.js.map +1 -0
- package/dist/src/agents/subagent-tool.d.ts +61 -0
- package/dist/src/agents/subagent-tool.js +180 -0
- package/dist/src/agents/subagent-tool.js.map +1 -0
- package/dist/src/agents/workflow-tool.d.ts +85 -0
- package/dist/src/agents/workflow-tool.js +530 -0
- package/dist/src/agents/workflow-tool.js.map +1 -0
- package/dist/src/cli-args.d.ts +39 -0
- package/dist/src/cli-args.js +198 -0
- package/dist/src/cli-args.js.map +1 -0
- package/dist/src/cli-doctor.d.ts +26 -0
- package/dist/src/cli-doctor.js +398 -0
- package/dist/src/cli-doctor.js.map +1 -0
- package/dist/src/cli-main.d.ts +1 -0
- package/dist/src/cli-main.js +279 -0
- package/dist/src/cli-main.js.map +1 -0
- package/dist/src/cli-sessions.d.ts +17 -0
- package/dist/src/cli-sessions.js +136 -0
- package/dist/src/cli-sessions.js.map +1 -0
- package/dist/src/cli-trajectory.d.ts +37 -0
- package/dist/src/cli-trajectory.js +303 -0
- package/dist/src/cli-trajectory.js.map +1 -0
- package/dist/src/cli-usage.d.ts +18 -0
- package/dist/src/cli-usage.js +53 -0
- package/dist/src/cli-usage.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +29 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/custom-commands.d.ts +43 -0
- package/dist/src/commands/custom-commands.js +155 -0
- package/dist/src/commands/custom-commands.js.map +1 -0
- package/dist/src/commands/workflow-command.d.ts +26 -0
- package/dist/src/commands/workflow-command.js +56 -0
- package/dist/src/commands/workflow-command.js.map +1 -0
- package/dist/src/config.d.ts +463 -0
- package/dist/src/config.js +1457 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/context-overflow-error.d.ts +7 -0
- package/dist/src/context-overflow-error.js +26 -0
- package/dist/src/context-overflow-error.js.map +1 -0
- package/dist/src/dev-repl.d.ts +1 -0
- package/dist/src/dev-repl.js +365 -0
- package/dist/src/dev-repl.js.map +1 -0
- package/dist/src/headless-protocol.d.ts +147 -0
- package/dist/src/headless-protocol.js +359 -0
- package/dist/src/headless-protocol.js.map +1 -0
- package/dist/src/headless-runner.d.ts +30 -0
- package/dist/src/headless-runner.js +405 -0
- package/dist/src/headless-runner.js.map +1 -0
- package/dist/src/headless-stdin.d.ts +28 -0
- package/dist/src/headless-stdin.js +78 -0
- package/dist/src/headless-stdin.js.map +1 -0
- package/dist/src/headless.d.ts +106 -0
- package/dist/src/headless.js +229 -0
- package/dist/src/headless.js.map +1 -0
- package/dist/src/hooks/codex-hook-runner.d.ts +92 -0
- package/dist/src/hooks/codex-hook-runner.js +446 -0
- package/dist/src/hooks/codex-hook-runner.js.map +1 -0
- package/dist/src/hooks/codex-hooks.d.ts +23 -0
- package/dist/src/hooks/codex-hooks.js +152 -0
- package/dist/src/hooks/codex-hooks.js.map +1 -0
- package/dist/src/hooks/hook-process.d.ts +23 -0
- package/dist/src/hooks/hook-process.js +241 -0
- package/dist/src/hooks/hook-process.js.map +1 -0
- package/dist/src/hooks/lifecycle-hooks.d.ts +37 -0
- package/dist/src/hooks/lifecycle-hooks.js +153 -0
- package/dist/src/hooks/lifecycle-hooks.js.map +1 -0
- package/dist/src/hooks/tool-hooks.d.ts +63 -0
- package/dist/src/hooks/tool-hooks.js +350 -0
- package/dist/src/hooks/tool-hooks.js.map +1 -0
- package/dist/src/mcp/codegraph-preflight.d.ts +29 -0
- package/dist/src/mcp/codegraph-preflight.js +232 -0
- package/dist/src/mcp/codegraph-preflight.js.map +1 -0
- package/dist/src/mcp/registry.d.ts +133 -0
- package/dist/src/mcp/registry.js +209 -0
- package/dist/src/mcp/registry.js.map +1 -0
- package/dist/src/mcp/web-search-empty-results.d.ts +14 -0
- package/dist/src/mcp/web-search-empty-results.js +94 -0
- package/dist/src/mcp/web-search-empty-results.js.map +1 -0
- package/dist/src/memory/command.d.ts +11 -0
- package/dist/src/memory/command.js +253 -0
- package/dist/src/memory/command.js.map +1 -0
- package/dist/src/memory/controller.d.ts +51 -0
- package/dist/src/memory/controller.js +316 -0
- package/dist/src/memory/controller.js.map +1 -0
- package/dist/src/memory/prompt.d.ts +4 -0
- package/dist/src/memory/prompt.js +22 -0
- package/dist/src/memory/prompt.js.map +1 -0
- package/dist/src/memory/scheduler.d.ts +33 -0
- package/dist/src/memory/scheduler.js +134 -0
- package/dist/src/memory/scheduler.js.map +1 -0
- package/dist/src/memory/state.d.ts +112 -0
- package/dist/src/memory/state.js +355 -0
- package/dist/src/memory/state.js.map +1 -0
- package/dist/src/memory/store.d.ts +19 -0
- package/dist/src/memory/store.js +130 -0
- package/dist/src/memory/store.js.map +1 -0
- package/dist/src/memory/tools.d.ts +29 -0
- package/dist/src/memory/tools.js +22 -0
- package/dist/src/memory/tools.js.map +1 -0
- package/dist/src/memory/validation.d.ts +33 -0
- package/dist/src/memory/validation.js +159 -0
- package/dist/src/memory/validation.js.map +1 -0
- package/dist/src/npm-package/generate-patch.d.ts +23 -0
- package/dist/src/npm-package/generate-patch.js +88 -0
- package/dist/src/npm-package/generate-patch.js.map +1 -0
- package/dist/src/npm-package/patch-package-format.d.ts +43 -0
- package/dist/src/npm-package/patch-package-format.js +66 -0
- package/dist/src/npm-package/patch-package-format.js.map +1 -0
- package/dist/src/paths.d.ts +39 -0
- package/dist/src/paths.js +105 -0
- package/dist/src/paths.js.map +1 -0
- package/dist/src/pricing/cost.d.ts +182 -0
- package/dist/src/pricing/cost.js +215 -0
- package/dist/src/pricing/cost.js.map +1 -0
- package/dist/src/pricing/model-prices.d.ts +112 -0
- package/dist/src/pricing/model-prices.js +320 -0
- package/dist/src/pricing/model-prices.js.map +1 -0
- package/dist/src/sdk-patch-preflight.d.ts +23 -0
- package/dist/src/sdk-patch-preflight.js +71 -0
- package/dist/src/sdk-patch-preflight.js.map +1 -0
- package/dist/src/skills/builtin/commit-message/SKILL.md +45 -0
- package/dist/src/skills/builtin/commit-message/references/types.md +8 -0
- package/dist/src/skills/builtin/developer/SKILL.md +107 -0
- package/dist/src/skills/builtin/self-evolution-research/SKILL.md +150 -0
- package/dist/src/skills/builtin/self-evolution-research/scripts/roll-research-path.mjs +208 -0
- package/dist/src/skills/builtin/self-reflection/SKILL.md +172 -0
- package/dist/src/skills/builtin/self-reflection/references/reflection-template.md +90 -0
- package/dist/src/skills/builtin/self-reflection/scripts/locate-trajectory.mjs +175 -0
- package/dist/src/skills/loader.d.ts +26 -0
- package/dist/src/skills/loader.js +186 -0
- package/dist/src/skills/loader.js.map +1 -0
- package/dist/src/skills/plugin.d.ts +34 -0
- package/dist/src/skills/plugin.js +137 -0
- package/dist/src/skills/plugin.js.map +1 -0
- package/dist/src/skills/prompt.d.ts +8 -0
- package/dist/src/skills/prompt.js +214 -0
- package/dist/src/skills/prompt.js.map +1 -0
- package/dist/src/skills/resource-safety.d.ts +15 -0
- package/dist/src/skills/resource-safety.js +149 -0
- package/dist/src/skills/resource-safety.js.map +1 -0
- package/dist/src/tools/background-bash.d.ts +95 -0
- package/dist/src/tools/background-bash.js +639 -0
- package/dist/src/tools/background-bash.js.map +1 -0
- package/dist/src/tools/background-tail.d.ts +28 -0
- package/dist/src/tools/background-tail.js +75 -0
- package/dist/src/tools/background-tail.js.map +1 -0
- package/dist/src/tools/background-wait-contract.d.ts +4 -0
- package/dist/src/tools/background-wait-contract.js +7 -0
- package/dist/src/tools/background-wait-contract.js.map +1 -0
- package/dist/src/tools/file-editor-serial.d.ts +24 -0
- package/dist/src/tools/file-editor-serial.js +99 -0
- package/dist/src/tools/file-editor-serial.js.map +1 -0
- package/dist/src/tools/image-viewer.d.ts +43 -0
- package/dist/src/tools/image-viewer.js +256 -0
- package/dist/src/tools/image-viewer.js.map +1 -0
- package/dist/src/tools/update-plan.d.ts +30 -0
- package/dist/src/tools/update-plan.js +65 -0
- package/dist/src/tools/update-plan.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +70 -0
- package/dist/src/tools/web-fetch.js +667 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/trajectory/export.d.ts +31 -0
- package/dist/src/trajectory/export.js +116 -0
- package/dist/src/trajectory/export.js.map +1 -0
- package/dist/src/trajectory/fork.d.ts +19 -0
- package/dist/src/trajectory/fork.js +110 -0
- package/dist/src/trajectory/fork.js.map +1 -0
- package/dist/src/trajectory/memory-tool.d.ts +20 -0
- package/dist/src/trajectory/memory-tool.js +98 -0
- package/dist/src/trajectory/memory-tool.js.map +1 -0
- package/dist/src/trajectory/prompt-history.d.ts +62 -0
- package/dist/src/trajectory/prompt-history.js +256 -0
- package/dist/src/trajectory/prompt-history.js.map +1 -0
- package/dist/src/trajectory/reader.d.ts +21 -0
- package/dist/src/trajectory/reader.js +62 -0
- package/dist/src/trajectory/reader.js.map +1 -0
- package/dist/src/trajectory/record.d.ts +417 -0
- package/dist/src/trajectory/record.js +394 -0
- package/dist/src/trajectory/record.js.map +1 -0
- package/dist/src/trajectory/replay.d.ts +74 -0
- package/dist/src/trajectory/replay.js +285 -0
- package/dist/src/trajectory/replay.js.map +1 -0
- package/dist/src/trajectory/resume-recap.d.ts +43 -0
- package/dist/src/trajectory/resume-recap.js +68 -0
- package/dist/src/trajectory/resume-recap.js.map +1 -0
- package/dist/src/trajectory/search.d.ts +40 -0
- package/dist/src/trajectory/search.js +127 -0
- package/dist/src/trajectory/search.js.map +1 -0
- package/dist/src/trajectory/spend.d.ts +157 -0
- package/dist/src/trajectory/spend.js +264 -0
- package/dist/src/trajectory/spend.js.map +1 -0
- package/dist/src/trajectory/stream.d.ts +30 -0
- package/dist/src/trajectory/stream.js +30 -0
- package/dist/src/trajectory/stream.js.map +1 -0
- package/dist/src/trajectory/writer.d.ts +310 -0
- package/dist/src/trajectory/writer.js +636 -0
- package/dist/src/trajectory/writer.js.map +1 -0
- package/dist/src/tui/App.d.ts +109 -0
- package/dist/src/tui/App.js +2660 -0
- package/dist/src/tui/App.js.map +1 -0
- package/dist/src/tui/InputBox.d.ts +90 -0
- package/dist/src/tui/InputBox.js +129 -0
- package/dist/src/tui/InputBox.js.map +1 -0
- package/dist/src/tui/MarkdownText.d.ts +16 -0
- package/dist/src/tui/MarkdownText.js +117 -0
- package/dist/src/tui/MarkdownText.js.map +1 -0
- package/dist/src/tui/MessageList.d.ts +27 -0
- package/dist/src/tui/MessageList.js +61 -0
- package/dist/src/tui/MessageList.js.map +1 -0
- package/dist/src/tui/PermissionPrompt.d.ts +18 -0
- package/dist/src/tui/PermissionPrompt.js +114 -0
- package/dist/src/tui/PermissionPrompt.js.map +1 -0
- package/dist/src/tui/PlanChecklist.d.ts +7 -0
- package/dist/src/tui/PlanChecklist.js +12 -0
- package/dist/src/tui/PlanChecklist.js.map +1 -0
- package/dist/src/tui/QueuedMessages.d.ts +8 -0
- package/dist/src/tui/QueuedMessages.js +24 -0
- package/dist/src/tui/QueuedMessages.js.map +1 -0
- package/dist/src/tui/StartupScreen.d.ts +25 -0
- package/dist/src/tui/StartupScreen.js +51 -0
- package/dist/src/tui/StartupScreen.js.map +1 -0
- package/dist/src/tui/ToolCallPanel.d.ts +33 -0
- package/dist/src/tui/ToolCallPanel.js +112 -0
- package/dist/src/tui/ToolCallPanel.js.map +1 -0
- package/dist/src/tui/WelcomeHeader.d.ts +30 -0
- package/dist/src/tui/WelcomeHeader.js +69 -0
- package/dist/src/tui/WelcomeHeader.js.map +1 -0
- package/dist/src/tui/background-tool-presentation.d.ts +22 -0
- package/dist/src/tui/background-tool-presentation.js +209 -0
- package/dist/src/tui/background-tool-presentation.js.map +1 -0
- package/dist/src/tui/busy-suffix.d.ts +37 -0
- package/dist/src/tui/busy-suffix.js +39 -0
- package/dist/src/tui/busy-suffix.js.map +1 -0
- package/dist/src/tui/clipboard-image.d.ts +18 -0
- package/dist/src/tui/clipboard-image.js +109 -0
- package/dist/src/tui/clipboard-image.js.map +1 -0
- package/dist/src/tui/context-format.d.ts +43 -0
- package/dist/src/tui/context-format.js +71 -0
- package/dist/src/tui/context-format.js.map +1 -0
- package/dist/src/tui/copy-command.d.ts +68 -0
- package/dist/src/tui/copy-command.js +182 -0
- package/dist/src/tui/copy-command.js.map +1 -0
- package/dist/src/tui/edit-diff.d.ts +135 -0
- package/dist/src/tui/edit-diff.js +356 -0
- package/dist/src/tui/edit-diff.js.map +1 -0
- package/dist/src/tui/frame-budget.d.ts +351 -0
- package/dist/src/tui/frame-budget.js +446 -0
- package/dist/src/tui/frame-budget.js.map +1 -0
- package/dist/src/tui/help-format.d.ts +17 -0
- package/dist/src/tui/help-format.js +38 -0
- package/dist/src/tui/help-format.js.map +1 -0
- package/dist/src/tui/live-text.d.ts +51 -0
- package/dist/src/tui/live-text.js +154 -0
- package/dist/src/tui/live-text.js.map +1 -0
- package/dist/src/tui/markdown.d.ts +62 -0
- package/dist/src/tui/markdown.js +244 -0
- package/dist/src/tui/markdown.js.map +1 -0
- package/dist/src/tui/mcp-format.d.ts +28 -0
- package/dist/src/tui/mcp-format.js +67 -0
- package/dist/src/tui/mcp-format.js.map +1 -0
- package/dist/src/tui/path-completion.d.ts +119 -0
- package/dist/src/tui/path-completion.js +305 -0
- package/dist/src/tui/path-completion.js.map +1 -0
- package/dist/src/tui/permission-queue.d.ts +61 -0
- package/dist/src/tui/permission-queue.js +129 -0
- package/dist/src/tui/permission-queue.js.map +1 -0
- package/dist/src/tui/plan-format.d.ts +9 -0
- package/dist/src/tui/plan-format.js +30 -0
- package/dist/src/tui/plan-format.js.map +1 -0
- package/dist/src/tui/prompt-completion.d.ts +22 -0
- package/dist/src/tui/prompt-completion.js +46 -0
- package/dist/src/tui/prompt-completion.js.map +1 -0
- package/dist/src/tui/prompt-editor.d.ts +102 -0
- package/dist/src/tui/prompt-editor.js +379 -0
- package/dist/src/tui/prompt-editor.js.map +1 -0
- package/dist/src/tui/prompt-history-search.d.ts +53 -0
- package/dist/src/tui/prompt-history-search.js +123 -0
- package/dist/src/tui/prompt-history-search.js.map +1 -0
- package/dist/src/tui/prompt-queue.d.ts +58 -0
- package/dist/src/tui/prompt-queue.js +74 -0
- package/dist/src/tui/prompt-queue.js.map +1 -0
- package/dist/src/tui/prompt-recall.d.ts +74 -0
- package/dist/src/tui/prompt-recall.js +90 -0
- package/dist/src/tui/prompt-recall.js.map +1 -0
- package/dist/src/tui/react-environment.d.ts +11 -0
- package/dist/src/tui/react-environment.js +24 -0
- package/dist/src/tui/react-environment.js.map +1 -0
- package/dist/src/tui/rewind-search.d.ts +34 -0
- package/dist/src/tui/rewind-search.js +68 -0
- package/dist/src/tui/rewind-search.js.map +1 -0
- package/dist/src/tui/shell-command.d.ts +114 -0
- package/dist/src/tui/shell-command.js +310 -0
- package/dist/src/tui/shell-command.js.map +1 -0
- package/dist/src/tui/spend-advisory.d.ts +52 -0
- package/dist/src/tui/spend-advisory.js +64 -0
- package/dist/src/tui/spend-advisory.js.map +1 -0
- package/dist/src/tui/status-format.d.ts +120 -0
- package/dist/src/tui/status-format.js +192 -0
- package/dist/src/tui/status-format.js.map +1 -0
- package/dist/src/tui/subagent-format.d.ts +49 -0
- package/dist/src/tui/subagent-format.js +146 -0
- package/dist/src/tui/subagent-format.js.map +1 -0
- package/dist/src/tui/task-format.d.ts +29 -0
- package/dist/src/tui/task-format.js +87 -0
- package/dist/src/tui/task-format.js.map +1 -0
- package/dist/src/tui/terminal-bell.d.ts +20 -0
- package/dist/src/tui/terminal-bell.js +33 -0
- package/dist/src/tui/terminal-bell.js.map +1 -0
- package/dist/src/tui/tool-detail-presentation.d.ts +60 -0
- package/dist/src/tui/tool-detail-presentation.js +206 -0
- package/dist/src/tui/tool-detail-presentation.js.map +1 -0
- package/dist/src/tui/turn-state.d.ts +195 -0
- package/dist/src/tui/turn-state.js +548 -0
- package/dist/src/tui/turn-state.js.map +1 -0
- package/dist/src/tui/visual-language.d.ts +45 -0
- package/dist/src/tui/visual-language.js +57 -0
- package/dist/src/tui/visual-language.js.map +1 -0
- package/dist/src/version.d.ts +7 -0
- package/dist/src/version.js +38 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading spend back out of a record: one aggregation, one rendering, two callers.
|
|
3
|
+
*
|
|
4
|
+
* `list` and `replay` both report what a session cost, at the verbosity their format
|
|
5
|
+
* affords, and both go through here — the same discipline `turnOutcome` enforces for how
|
|
6
|
+
* a turn ended. Two implementations would eventually disagree about the only question
|
|
7
|
+
* this file exists to answer.
|
|
8
|
+
*
|
|
9
|
+
* Three rules are load-bearing, and each of them is a way of not lying:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Unknown is not zero.** A turn with no `spend` (recorded before the field existed,
|
|
12
|
+
* or with the meter unreadable) is counted as *unknown* and reported as such. A metric
|
|
13
|
+
* no contributing turn reported renders `-`, exactly as the headless `usage:` record
|
|
14
|
+
* does; a metric some turns reported is summed and the turns that did not are counted
|
|
15
|
+
* alongside it.
|
|
16
|
+
* 2. **A total names its models.** A single number covering two models covers two
|
|
17
|
+
* different price lists, so the model count travels with the total and `replay` breaks
|
|
18
|
+
* it down per model.
|
|
19
|
+
* 3. **Every rendered line is bounded**, because a model id comes from configuration and
|
|
20
|
+
* a session can hold any number of them.
|
|
21
|
+
*
|
|
22
|
+
* Totals cover **what the file records**. A forked session's trajectory begins with the
|
|
23
|
+
* bytes copied from its source (`fork` is defined as copying them), so those turns are
|
|
24
|
+
* genuinely in this file and are genuinely in its total; the `forkedFrom` record on the
|
|
25
|
+
* same file says where they came from. Excluding them would put a total on the same row
|
|
26
|
+
* as a record count and a byte count that describe a larger file.
|
|
27
|
+
*
|
|
28
|
+
* This module imports no `Agent`, no `Model` and nothing from `src/agent/**`: reporting
|
|
29
|
+
* spend must stay as offline as replaying history. Pricing keeps that rule — the
|
|
30
|
+
* arithmetic is `src/pricing/cost.ts` and the rates come from a **read** of the price
|
|
31
|
+
* cache (`src/pricing/model-prices.ts`, the sync reader only): no fetch, no write, no
|
|
32
|
+
* model call. Each model is priced at its own rates; a model the cache does not know is
|
|
33
|
+
* *unpriced* and named, its money unknown rather than zero.
|
|
34
|
+
*/
|
|
35
|
+
import { type ModelCallReading, type TrajectoryRecord, type TurnSpend } from './record.js';
|
|
36
|
+
import { type SessionCost } from '../pricing/cost.js';
|
|
37
|
+
import { type ModelPriceCache } from '../pricing/model-prices.js';
|
|
38
|
+
/** One metric's total, and how many recorded turns had nothing to say about it. */
|
|
39
|
+
export interface SpendMetric {
|
|
40
|
+
/** Sum over the turns that reported it; `undefined` when none did. */
|
|
41
|
+
total: number | undefined;
|
|
42
|
+
/** Turns that carried a spend but not this metric. */
|
|
43
|
+
unreportedTurns: number;
|
|
44
|
+
}
|
|
45
|
+
/** What one model was paid for, so a mixed total can always be broken apart. */
|
|
46
|
+
export interface ModelSpend {
|
|
47
|
+
/** `provider/model`, as recorded on the turn. */
|
|
48
|
+
label: string;
|
|
49
|
+
/** The recorded provider, as {@link label} carries it. */
|
|
50
|
+
provider: string;
|
|
51
|
+
/** The recorded darwin model id — the price-cache key. Never derived by splitting {@link label}. */
|
|
52
|
+
model: string;
|
|
53
|
+
turns: number;
|
|
54
|
+
input: SpendMetric;
|
|
55
|
+
output: SpendMetric;
|
|
56
|
+
cacheRead: SpendMetric;
|
|
57
|
+
cacheWrite: SpendMetric;
|
|
58
|
+
}
|
|
59
|
+
/** Everything a report can say about a file's spend without reading it twice. */
|
|
60
|
+
export interface SpendSummary {
|
|
61
|
+
/** Turns whose record carried a usable spend. */
|
|
62
|
+
turnsWithSpend: number;
|
|
63
|
+
/** Turns whose record carried none — unknown, never free. */
|
|
64
|
+
turnsUnknown: number;
|
|
65
|
+
input: SpendMetric;
|
|
66
|
+
output: SpendMetric;
|
|
67
|
+
cacheRead: SpendMetric;
|
|
68
|
+
cacheWrite: SpendMetric;
|
|
69
|
+
/** Per-model breakdown, in first-appearance order. */
|
|
70
|
+
models: ModelSpend[];
|
|
71
|
+
}
|
|
72
|
+
/** One turn's spend with the ordinal the record gave it, for per-turn reporting. */
|
|
73
|
+
export interface TurnSpendEntry {
|
|
74
|
+
turn: number;
|
|
75
|
+
/** `undefined` when that turn's record carried no usable spend. */
|
|
76
|
+
spend: TurnSpend | undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Aggregates every `turnEnded` record in the file.
|
|
80
|
+
*
|
|
81
|
+
* Counted per **record**, not per distinct `turn` ordinal: ordinals restart at 1 in each
|
|
82
|
+
* process that appends to a session (a pre-existing property of `TrajectoryRecorder`,
|
|
83
|
+
* noted when the failure record was added), so grouping by ordinal would silently merge
|
|
84
|
+
* two runs' turns and under-report the file.
|
|
85
|
+
*/
|
|
86
|
+
export declare function summarizeSpend(records: readonly TrajectoryRecord[]): SpendSummary;
|
|
87
|
+
/** Every closed turn's spend in file order, unknown ones included so they can be reported. */
|
|
88
|
+
export declare function turnSpendEntries(records: readonly TrajectoryRecord[]): TurnSpendEntry[];
|
|
89
|
+
/** `provider/model`, the same label `replay`'s run header uses for `runStarted`. */
|
|
90
|
+
export declare function modelLabel(spend: TurnSpend): string;
|
|
91
|
+
/**
|
|
92
|
+
* Cap on one rendered model label, in code points.
|
|
93
|
+
*
|
|
94
|
+
* A model id is configuration, so it is as unbounded as any other user-supplied string;
|
|
95
|
+
* this keeps a summary row a row. The full value stays in the record.
|
|
96
|
+
*/
|
|
97
|
+
export declare const MAX_MODEL_LABEL_CHARS = 60;
|
|
98
|
+
/** A label as a summary line may carry it. */
|
|
99
|
+
export declare function formatModelLabel(label: string, limit?: number): string;
|
|
100
|
+
/**
|
|
101
|
+
* The four buckets as the fixed `input=… output=… cacheRead=… cacheWrite=…` sequence
|
|
102
|
+
* the headless `usage:` record established, so one convention covers both surfaces.
|
|
103
|
+
*
|
|
104
|
+
* `-` means unreported, never zero. A metric only some turns reported carries how many
|
|
105
|
+
* did not, because a sum over a subset is not the same claim as a sum.
|
|
106
|
+
*/
|
|
107
|
+
export declare function formatSpendFields(summary: {
|
|
108
|
+
input: SpendMetric;
|
|
109
|
+
output: SpendMetric;
|
|
110
|
+
cacheRead: SpendMetric;
|
|
111
|
+
cacheWrite: SpendMetric;
|
|
112
|
+
}): string;
|
|
113
|
+
/** One metric: its sum, or `-`, with the turns that never reported it noted. */
|
|
114
|
+
export declare function formatMetric(metric: SpendMetric): string;
|
|
115
|
+
/**
|
|
116
|
+
* A whole file's spend as one bounded clause — what `list` appends to a session's row.
|
|
117
|
+
*
|
|
118
|
+
* `unknown` when nothing was measured: a session recorded before this field existed cost
|
|
119
|
+
* something, and printing zeros for it would be an invention.
|
|
120
|
+
*/
|
|
121
|
+
export declare function formatSpendSummary(summary: SpendSummary): string;
|
|
122
|
+
/** One turn's line for `replay`: the buckets it paid, or that nothing measured it. */
|
|
123
|
+
export declare function formatTurnSpend(entry: TurnSpendEntry): string;
|
|
124
|
+
/** Every `modelCall` record in file order, read defensively like the turn entries. */
|
|
125
|
+
export declare function modelCallEntries(records: readonly TrajectoryRecord[]): ModelCallReading[];
|
|
126
|
+
/**
|
|
127
|
+
* One completed model call's line for `replay` — bounded, and honest about absence
|
|
128
|
+
* on the spend rules: an estimate nobody reported and a price nobody projected are
|
|
129
|
+
* omitted or `unknown`, never rendered as 0.
|
|
130
|
+
*/
|
|
131
|
+
export declare function formatModelCall(call: ModelCallReading): string;
|
|
132
|
+
/** One model's line for `replay`, when a file holds more than one — priced when a report is given. */
|
|
133
|
+
export declare function formatModelSpend(model: ModelSpend, cost?: SpendCostReport): string;
|
|
134
|
+
/**
|
|
135
|
+
* What a file's spend cost, priced per model from the price cache, plus each model's
|
|
136
|
+
* own figure so `replay` can put it beside that model's token row.
|
|
137
|
+
*/
|
|
138
|
+
export interface SpendCostReport {
|
|
139
|
+
session: SessionCost;
|
|
140
|
+
models: readonly {
|
|
141
|
+
label: string;
|
|
142
|
+
cost: SessionCost;
|
|
143
|
+
}[];
|
|
144
|
+
/** Turns whose record carried no spend — money nobody measured, so the total is a floor. */
|
|
145
|
+
turnsUnknown: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Prices a {@link SpendSummary} — each model's buckets at that model's rates, read
|
|
149
|
+
* from the cache passed in (never fetched here). A metric only some turns reported is
|
|
150
|
+
* priced over the reported part and flagged `partly reported`; a model the cache has no
|
|
151
|
+
* rates for is unpriced and named. Pure: the same summary and cache always price the same.
|
|
152
|
+
*/
|
|
153
|
+
export declare function priceSpend(summary: SpendSummary, prices: ModelPriceCache): SpendCostReport;
|
|
154
|
+
/** The clause `list` appends after the spend clause: `cost: ≈ $0.0415 (base rates, LiteLLM)`. */
|
|
155
|
+
export declare function formatSpendCost(report: SpendCostReport): string;
|
|
156
|
+
/** The `session cost:` line `replay` prints under `session spend:`. */
|
|
157
|
+
export declare function formatSessionCost(report: SpendCostReport): string;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading spend back out of a record: one aggregation, one rendering, two callers.
|
|
3
|
+
*
|
|
4
|
+
* `list` and `replay` both report what a session cost, at the verbosity their format
|
|
5
|
+
* affords, and both go through here — the same discipline `turnOutcome` enforces for how
|
|
6
|
+
* a turn ended. Two implementations would eventually disagree about the only question
|
|
7
|
+
* this file exists to answer.
|
|
8
|
+
*
|
|
9
|
+
* Three rules are load-bearing, and each of them is a way of not lying:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Unknown is not zero.** A turn with no `spend` (recorded before the field existed,
|
|
12
|
+
* or with the meter unreadable) is counted as *unknown* and reported as such. A metric
|
|
13
|
+
* no contributing turn reported renders `-`, exactly as the headless `usage:` record
|
|
14
|
+
* does; a metric some turns reported is summed and the turns that did not are counted
|
|
15
|
+
* alongside it.
|
|
16
|
+
* 2. **A total names its models.** A single number covering two models covers two
|
|
17
|
+
* different price lists, so the model count travels with the total and `replay` breaks
|
|
18
|
+
* it down per model.
|
|
19
|
+
* 3. **Every rendered line is bounded**, because a model id comes from configuration and
|
|
20
|
+
* a session can hold any number of them.
|
|
21
|
+
*
|
|
22
|
+
* Totals cover **what the file records**. A forked session's trajectory begins with the
|
|
23
|
+
* bytes copied from its source (`fork` is defined as copying them), so those turns are
|
|
24
|
+
* genuinely in this file and are genuinely in its total; the `forkedFrom` record on the
|
|
25
|
+
* same file says where they came from. Excluding them would put a total on the same row
|
|
26
|
+
* as a record count and a byte count that describe a larger file.
|
|
27
|
+
*
|
|
28
|
+
* This module imports no `Agent`, no `Model` and nothing from `src/agent/**`: reporting
|
|
29
|
+
* spend must stay as offline as replaying history. Pricing keeps that rule — the
|
|
30
|
+
* arithmetic is `src/pricing/cost.ts` and the rates come from a **read** of the price
|
|
31
|
+
* cache (`src/pricing/model-prices.ts`, the sync reader only): no fetch, no write, no
|
|
32
|
+
* model call. Each model is priced at its own rates; a model the cache does not know is
|
|
33
|
+
* *unpriced* and named, its money unknown rather than zero.
|
|
34
|
+
*/
|
|
35
|
+
import { modelCallOf, turnSpendOf, } from './record.js';
|
|
36
|
+
import { describeSessionCost, sessionCost } from '../pricing/cost.js';
|
|
37
|
+
import { lookupFromEntry } from '../pricing/model-prices.js';
|
|
38
|
+
/**
|
|
39
|
+
* Aggregates every `turnEnded` record in the file.
|
|
40
|
+
*
|
|
41
|
+
* Counted per **record**, not per distinct `turn` ordinal: ordinals restart at 1 in each
|
|
42
|
+
* process that appends to a session (a pre-existing property of `TrajectoryRecorder`,
|
|
43
|
+
* noted when the failure record was added), so grouping by ordinal would silently merge
|
|
44
|
+
* two runs' turns and under-report the file.
|
|
45
|
+
*/
|
|
46
|
+
export function summarizeSpend(records) {
|
|
47
|
+
const entries = turnSpendEntries(records);
|
|
48
|
+
const spends = entries.flatMap((entry) => (entry.spend === undefined ? [] : [entry.spend]));
|
|
49
|
+
const models = [];
|
|
50
|
+
for (const spend of spends) {
|
|
51
|
+
const label = modelLabel(spend);
|
|
52
|
+
const existing = models.find((model) => model.label === label);
|
|
53
|
+
const group = existing ?? emptyModel(spend);
|
|
54
|
+
if (existing === undefined)
|
|
55
|
+
models.push(group);
|
|
56
|
+
group.turns += 1;
|
|
57
|
+
accumulate(group, spend);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
turnsWithSpend: spends.length,
|
|
61
|
+
turnsUnknown: entries.length - spends.length,
|
|
62
|
+
input: metric(spends, (spend) => spend.input),
|
|
63
|
+
output: metric(spends, (spend) => spend.output),
|
|
64
|
+
cacheRead: metric(spends, (spend) => spend.cacheRead),
|
|
65
|
+
cacheWrite: metric(spends, (spend) => spend.cacheWrite),
|
|
66
|
+
models,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Every closed turn's spend in file order, unknown ones included so they can be reported. */
|
|
70
|
+
export function turnSpendEntries(records) {
|
|
71
|
+
return records
|
|
72
|
+
.filter((record) => record.type === 'turnEnded')
|
|
73
|
+
.map((record) => ({ turn: record.turn, spend: turnSpendOf(record) }));
|
|
74
|
+
}
|
|
75
|
+
/** `provider/model`, the same label `replay`'s run header uses for `runStarted`. */
|
|
76
|
+
export function modelLabel(spend) {
|
|
77
|
+
return `${spend.provider}/${spend.model}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Cap on one rendered model label, in code points.
|
|
81
|
+
*
|
|
82
|
+
* A model id is configuration, so it is as unbounded as any other user-supplied string;
|
|
83
|
+
* this keeps a summary row a row. The full value stays in the record.
|
|
84
|
+
*/
|
|
85
|
+
export const MAX_MODEL_LABEL_CHARS = 60;
|
|
86
|
+
/** A label as a summary line may carry it. */
|
|
87
|
+
export function formatModelLabel(label, limit = MAX_MODEL_LABEL_CHARS) {
|
|
88
|
+
const points = [...label.replace(/\s+/gu, ' ').trim()];
|
|
89
|
+
return points.length <= limit ? points.join('') : `${points.slice(0, Math.max(0, limit - 1)).join('')}…`;
|
|
90
|
+
}
|
|
91
|
+
/** Models named in a summary before the rest are only counted. */
|
|
92
|
+
const LISTED_MODELS = 3;
|
|
93
|
+
/**
|
|
94
|
+
* The four buckets as the fixed `input=… output=… cacheRead=… cacheWrite=…` sequence
|
|
95
|
+
* the headless `usage:` record established, so one convention covers both surfaces.
|
|
96
|
+
*
|
|
97
|
+
* `-` means unreported, never zero. A metric only some turns reported carries how many
|
|
98
|
+
* did not, because a sum over a subset is not the same claim as a sum.
|
|
99
|
+
*/
|
|
100
|
+
export function formatSpendFields(summary) {
|
|
101
|
+
return (`input=${formatMetric(summary.input)} output=${formatMetric(summary.output)}` +
|
|
102
|
+
` cacheRead=${formatMetric(summary.cacheRead)} cacheWrite=${formatMetric(summary.cacheWrite)}`);
|
|
103
|
+
}
|
|
104
|
+
/** One metric: its sum, or `-`, with the turns that never reported it noted. */
|
|
105
|
+
export function formatMetric(metric) {
|
|
106
|
+
if (metric.total === undefined)
|
|
107
|
+
return '-';
|
|
108
|
+
return metric.unreportedTurns === 0
|
|
109
|
+
? String(metric.total)
|
|
110
|
+
: `${metric.total}(+${metric.unreportedTurns} unreported)`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A whole file's spend as one bounded clause — what `list` appends to a session's row.
|
|
114
|
+
*
|
|
115
|
+
* `unknown` when nothing was measured: a session recorded before this field existed cost
|
|
116
|
+
* something, and printing zeros for it would be an invention.
|
|
117
|
+
*/
|
|
118
|
+
export function formatSpendSummary(summary) {
|
|
119
|
+
if (summary.turnsWithSpend === 0) {
|
|
120
|
+
return summary.turnsUnknown === 0 ? 'spend: unknown (no turns)' : 'spend: unknown';
|
|
121
|
+
}
|
|
122
|
+
const unknown = summary.turnsUnknown === 0 ? '' : `, ${summary.turnsUnknown} turn(s) unknown`;
|
|
123
|
+
const named = summary.models
|
|
124
|
+
.slice(0, LISTED_MODELS)
|
|
125
|
+
.map((model) => formatModelLabel(model.label))
|
|
126
|
+
.join(', ');
|
|
127
|
+
const rest = summary.models.length - Math.min(summary.models.length, LISTED_MODELS);
|
|
128
|
+
const models = summary.models.length <= 1
|
|
129
|
+
? named
|
|
130
|
+
: `${summary.models.length} models: ${named}${rest > 0 ? ` +${rest} more` : ''}`;
|
|
131
|
+
return `spend: ${formatSpendFields(summary)} (${models}${unknown})`;
|
|
132
|
+
}
|
|
133
|
+
/** One turn's line for `replay`: the buckets it paid, or that nothing measured it. */
|
|
134
|
+
export function formatTurnSpend(entry) {
|
|
135
|
+
if (entry.spend === undefined)
|
|
136
|
+
return `turn ${entry.turn} spend: unknown (not recorded)`;
|
|
137
|
+
const one = asMetrics(entry.spend);
|
|
138
|
+
return `turn ${entry.turn} spend: ${formatSpendFields(one)} · ${formatModelLabel(modelLabel(entry.spend))}`;
|
|
139
|
+
}
|
|
140
|
+
/** Every `modelCall` record in file order, read defensively like the turn entries. */
|
|
141
|
+
export function modelCallEntries(records) {
|
|
142
|
+
return records
|
|
143
|
+
.filter((record) => record.type === 'modelCall')
|
|
144
|
+
.map((record) => modelCallOf(record));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Cap on one rendered stop reason, in code points. The value is provider-controlled
|
|
148
|
+
* (and capped at the field cap on disk), so a summary line bounds it again the way
|
|
149
|
+
* {@link formatModelLabel} bounds a model id.
|
|
150
|
+
*/
|
|
151
|
+
const MAX_STOP_REASON_CHARS = 40;
|
|
152
|
+
/**
|
|
153
|
+
* One completed model call's line for `replay` — bounded, and honest about absence
|
|
154
|
+
* on the spend rules: an estimate nobody reported and a price nobody projected are
|
|
155
|
+
* omitted or `unknown`, never rendered as 0.
|
|
156
|
+
*/
|
|
157
|
+
export function formatModelCall(call) {
|
|
158
|
+
const parts = [
|
|
159
|
+
`turn ${call.turn} model call (attempt ${call.attempt}, ${call.ms}ms)`,
|
|
160
|
+
...(call.stopReason === undefined ? [] : [`stop ${boundedWord(call.stopReason, MAX_STOP_REASON_CHARS)}`]),
|
|
161
|
+
...(call.contextTokens === undefined ? [] : [`context ~${call.contextTokens} tokens`]),
|
|
162
|
+
call.spend === undefined
|
|
163
|
+
? 'spend unknown'
|
|
164
|
+
: `${formatSpendFields(asMetrics(call.spend))} · ${formatModelLabel(modelLabel(call.spend))}`,
|
|
165
|
+
];
|
|
166
|
+
return parts.join(' · ');
|
|
167
|
+
}
|
|
168
|
+
/** A provider-controlled word as one bounded token: whitespace collapsed, length capped. */
|
|
169
|
+
function boundedWord(value, limit) {
|
|
170
|
+
const points = [...value.replace(/\s+/gu, ' ').trim()];
|
|
171
|
+
return points.length <= limit ? points.join('') : `${points.slice(0, Math.max(0, limit - 1)).join('')}…`;
|
|
172
|
+
}
|
|
173
|
+
/** One model's line for `replay`, when a file holds more than one — priced when a report is given. */
|
|
174
|
+
export function formatModelSpend(model, cost) {
|
|
175
|
+
const line = `${formatModelLabel(model.label)}: ${formatSpendFields(model)} over ${model.turns} turn(s)`;
|
|
176
|
+
const priced = cost?.models.find((entry) => entry.label === model.label);
|
|
177
|
+
return priced === undefined ? line : `${line} · cost ${describeSessionCost(priced.cost)}`;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Prices a {@link SpendSummary} — each model's buckets at that model's rates, read
|
|
181
|
+
* from the cache passed in (never fetched here). A metric only some turns reported is
|
|
182
|
+
* priced over the reported part and flagged `partly reported`; a model the cache has no
|
|
183
|
+
* rates for is unpriced and named. Pure: the same summary and cache always price the same.
|
|
184
|
+
*/
|
|
185
|
+
export function priceSpend(summary, prices) {
|
|
186
|
+
const shares = summary.models.map((model) => ({ label: model.label, share: costShareOf(model, prices) }));
|
|
187
|
+
return {
|
|
188
|
+
session: sessionCost(shares.map(({ share }) => share)),
|
|
189
|
+
models: shares.map(({ label, share }) => ({ label, cost: sessionCost([share]) })),
|
|
190
|
+
turnsUnknown: summary.turnsUnknown,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/** The clause `list` appends after the spend clause: `cost: ≈ $0.0415 (base rates, LiteLLM)`. */
|
|
194
|
+
export function formatSpendCost(report) {
|
|
195
|
+
return `cost: ${describeSessionCost(report.session, unknownTurnCaveats(report))}`;
|
|
196
|
+
}
|
|
197
|
+
/** The `session cost:` line `replay` prints under `session spend:`. */
|
|
198
|
+
export function formatSessionCost(report) {
|
|
199
|
+
return `session cost: ${describeSessionCost(report.session, unknownTurnCaveats(report))}`;
|
|
200
|
+
}
|
|
201
|
+
/** Turns nothing measured make any total a floor, said in the cost clause's own vocabulary. */
|
|
202
|
+
function unknownTurnCaveats(report) {
|
|
203
|
+
return report.turnsUnknown === 0 ? [] : [`${report.turnsUnknown} turn(s) unknown`];
|
|
204
|
+
}
|
|
205
|
+
const COST_BUCKETS = ['input', 'output', 'cacheRead', 'cacheWrite'];
|
|
206
|
+
/** One model's spend as the pure module's unit: totals as buckets, gaps as partly reported. */
|
|
207
|
+
function costShareOf(model, prices) {
|
|
208
|
+
const partlyReported = COST_BUCKETS.filter((bucket) => model[bucket].total !== undefined && model[bucket].unreportedTurns > 0);
|
|
209
|
+
return {
|
|
210
|
+
model: model.model,
|
|
211
|
+
lookup: lookupFromEntry(prices.models[model.model]),
|
|
212
|
+
buckets: {
|
|
213
|
+
input: model.input.total,
|
|
214
|
+
output: model.output.total,
|
|
215
|
+
cacheRead: model.cacheRead.total,
|
|
216
|
+
cacheWrite: model.cacheWrite.total,
|
|
217
|
+
},
|
|
218
|
+
...(partlyReported.length > 0 && { partlyReported }),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function emptyModel(spend) {
|
|
222
|
+
const zero = () => ({ total: undefined, unreportedTurns: 0 });
|
|
223
|
+
return {
|
|
224
|
+
label: modelLabel(spend),
|
|
225
|
+
provider: spend.provider,
|
|
226
|
+
model: spend.model,
|
|
227
|
+
turns: 0,
|
|
228
|
+
input: zero(),
|
|
229
|
+
output: zero(),
|
|
230
|
+
cacheRead: zero(),
|
|
231
|
+
cacheWrite: zero(),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function accumulate(model, spend) {
|
|
235
|
+
add(model.input, spend.input);
|
|
236
|
+
add(model.output, spend.output);
|
|
237
|
+
add(model.cacheRead, spend.cacheRead);
|
|
238
|
+
add(model.cacheWrite, spend.cacheWrite);
|
|
239
|
+
}
|
|
240
|
+
/** Sums a reported value, or counts the turn that did not report it. */
|
|
241
|
+
function add(metric, value) {
|
|
242
|
+
if (value === undefined) {
|
|
243
|
+
metric.unreportedTurns += 1;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
metric.total = (metric.total ?? 0) + value;
|
|
247
|
+
}
|
|
248
|
+
function metric(spends, pick) {
|
|
249
|
+
const out = { total: undefined, unreportedTurns: 0 };
|
|
250
|
+
for (const spend of spends)
|
|
251
|
+
add(out, pick(spend));
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/** One turn's spend in the shape {@link formatSpendFields} reads. */
|
|
255
|
+
function asMetrics(spend) {
|
|
256
|
+
const one = (value) => ({ total: value, unreportedTurns: 0 });
|
|
257
|
+
return {
|
|
258
|
+
input: one(spend.input),
|
|
259
|
+
output: one(spend.output),
|
|
260
|
+
cacheRead: one(spend.cacheRead),
|
|
261
|
+
cacheWrite: one(spend.cacheWrite),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=spend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spend.js","sourceRoot":"","sources":["../../../src/trajectory/spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EACL,WAAW,EACX,WAAW,GAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,WAA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,KAAgB;IAMjC,MAAM,GAAG,GAAG,CAAC,KAAyB,EAAe,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/F,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC;QACvB,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC;QACzB,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;QAC/B,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The observer seam itself: one generator that records a stream while passing it
|
|
3
|
+
* through unchanged.
|
|
4
|
+
*
|
|
5
|
+
* It exists as its own function for two reasons. `AgentRuntime.send` stays a
|
|
6
|
+
* two-line delegation, and — more importantly — the pass-through property becomes
|
|
7
|
+
* something a test can drive over a *real* `Agent.stream()`, rather than a claim
|
|
8
|
+
* about code only a live model can reach.
|
|
9
|
+
*
|
|
10
|
+
* The rules it has to keep:
|
|
11
|
+
*
|
|
12
|
+
* - every event is yielded, in order, unmodified;
|
|
13
|
+
* - nothing is awaited between receiving an event and yielding it;
|
|
14
|
+
* - `record()` and `failed()` cannot throw (they catch internally), so no recording
|
|
15
|
+
* failure can surface as a turn failure;
|
|
16
|
+
* - a thrown stream is observed and **rethrown as the identical object**: the caller
|
|
17
|
+
* sees the same class, the same message and the same stack it would have seen with
|
|
18
|
+
* recording switched off;
|
|
19
|
+
* - a consumer that stops early still closes the underlying stream, and the turn is
|
|
20
|
+
* still closed off, which is what makes a cancelled turn leave a valid record.
|
|
21
|
+
*
|
|
22
|
+
* `for await` + `yield` is used rather than `yield*` because a delegation cannot be
|
|
23
|
+
* observed from inside. The observable semantics darwin's consumers rely on are the
|
|
24
|
+
* same either way — order, completion, throw propagation, and iterator closing on an
|
|
25
|
+
* early `break` — and `spike/verify-trajectory.ts` measures that against the SDK's
|
|
26
|
+
* own stream instead of assuming it.
|
|
27
|
+
*/
|
|
28
|
+
import type { AgentStreamEvent } from '@strands-agents/sdk';
|
|
29
|
+
import type { TurnRecording } from './writer.js';
|
|
30
|
+
export declare function recordStream(events: AsyncIterable<AgentStreamEvent>, turn: TurnRecording | undefined): AsyncIterable<AgentStreamEvent>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export async function* recordStream(events, turn) {
|
|
2
|
+
try {
|
|
3
|
+
for await (const event of events) {
|
|
4
|
+
turn?.record(event);
|
|
5
|
+
yield event;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
// The one place the record learns that a turn *failed* rather than merely ended:
|
|
10
|
+
// a thrown turn emits no `agentResultEvent`, so without this the line closing it
|
|
11
|
+
// would be indistinguishable from a cancelled or an abandoned turn. `catch` runs
|
|
12
|
+
// before `finally`, so the `end()` below writes the failure out.
|
|
13
|
+
//
|
|
14
|
+
// Rethrowing the same object — not a copy, not a wrapper — is the observer
|
|
15
|
+
// contract: what the caller of `AgentRuntime.send` sees must not depend on whether
|
|
16
|
+
// recording is on. A consumer-side error is deliberately *not* seen here, because
|
|
17
|
+
// JavaScript delivers a for-await body's throw to this generator as a `return`
|
|
18
|
+
// completion: that runs the `finally` alone and the turn is recorded as abandoned,
|
|
19
|
+
// which is what it is — the turn did not fail, the reader left.
|
|
20
|
+
turn?.failed(error);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
// Reached on normal completion, on a throw, and when the consumer stops early
|
|
25
|
+
// (`break`, or a cancelled turn): the record must describe what happened either
|
|
26
|
+
// way. The append it schedules is never awaited here.
|
|
27
|
+
turn?.end();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/trajectory/stream.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,CACjC,MAAuC,EACvC,IAA+B;IAE/B,IAAI,CAAC;QACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACjC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iFAAiF;QACjF,iFAAiF;QACjF,iFAAiF;QACjF,iEAAiE;QACjE,EAAE;QACF,2EAA2E;QAC3E,mFAAmF;QACnF,kFAAkF;QAClF,+EAA+E;QAC/E,mFAAmF;QACnF,gEAAgE;QAChE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,8EAA8E;QAC9E,gFAAgF;QAChF,sDAAsD;QACtD,IAAI,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|