@tomsun28/pizza 0.1.0 → 0.1.1
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 +20 -143
- package/README.zh-CN.md +36 -0
- package/dist/bun/cli.d.ts +2 -0
- package/dist/bun/cli.js +6 -0
- package/dist/bun/register-bedrock.d.ts +1 -0
- package/dist/bun/register-bedrock.js +3 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/args.js +330 -0
- package/dist/cli/config-selector.d.ts +13 -0
- package/dist/cli/config-selector.js +30 -0
- package/dist/cli/file-processor.d.ts +14 -0
- package/dist/cli/file-processor.js +82 -0
- package/dist/cli/initial-message.d.ts +17 -0
- package/dist/cli/initial-message.js +21 -0
- package/dist/cli/list-models.d.ts +8 -0
- package/dist/cli/list-models.js +96 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +68 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +223 -0
- package/dist/core/agent/index.d.ts +6 -0
- package/dist/core/agent/index.js +6 -0
- package/dist/core/agent/types.d.ts +202 -0
- package/dist/core/agent/types.js +51 -0
- package/dist/core/auth-storage.d.ts +135 -0
- package/dist/core/auth-storage.js +417 -0
- package/dist/core/bash-executor.d.ts +31 -0
- package/dist/core/bash-executor.js +107 -0
- package/dist/core/compaction/branch-summarization.d.ts +87 -0
- package/dist/core/compaction/branch-summarization.js +242 -0
- package/dist/core/compaction/compaction-engine.d.ts +40 -0
- package/dist/core/compaction/compaction-engine.js +292 -0
- package/dist/core/compaction/compaction.d.ts +106 -0
- package/dist/core/compaction/compaction.js +295 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/utils.d.ts +37 -0
- package/dist/core/compaction/utils.js +152 -0
- package/dist/core/defaults.d.ts +2 -0
- package/dist/core/defaults.js +1 -0
- package/dist/core/diagnostics.d.ts +14 -0
- package/dist/core/diagnostics.js +1 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/event-bus.js +24 -0
- package/dist/core/event-store/events.d.ts +465 -0
- package/dist/core/event-store/events.js +6 -0
- package/dist/core/event-store/index.d.ts +10 -0
- package/dist/core/event-store/index.js +10 -0
- package/dist/core/event-store/sqlite-store.d.ts +27 -0
- package/dist/core/event-store/sqlite-store.js +275 -0
- package/dist/core/event-store/store.d.ts +91 -0
- package/dist/core/event-store/store.js +7 -0
- package/dist/core/event-store/thread-scoped-store.d.ts +29 -0
- package/dist/core/event-store/thread-scoped-store.js +50 -0
- package/dist/core/event-store/types.d.ts +70 -0
- package/dist/core/event-store/types.js +7 -0
- package/dist/core/event-store/workspace.d.ts +37 -0
- package/dist/core/event-store/workspace.js +71 -0
- package/dist/core/exec.d.ts +28 -0
- package/dist/core/exec.js +74 -0
- package/dist/core/export-html/ansi-to-html.d.ts +21 -0
- package/dist/core/export-html/ansi-to-html.js +248 -0
- package/dist/core/export-html/index.d.ts +29 -0
- package/dist/core/export-html/index.js +186 -0
- package/dist/core/export-html/template.css +1017 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1742 -0
- package/dist/core/export-html/tool-renderer.d.ts +39 -0
- package/dist/core/export-html/tool-renderer.js +94 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/loader.d.ts +24 -0
- package/dist/core/extensions/loader.js +492 -0
- package/dist/core/extensions/runner.d.ts +167 -0
- package/dist/core/extensions/runner.js +898 -0
- package/dist/core/extensions/session-context.d.ts +67 -0
- package/dist/core/extensions/session-context.js +272 -0
- package/dist/core/extensions/types.d.ts +1147 -0
- package/dist/core/extensions/types.js +44 -0
- package/dist/core/extensions/wrapper.d.ts +19 -0
- package/dist/core/extensions/wrapper.js +21 -0
- package/dist/core/footer-data-provider.d.ts +47 -0
- package/dist/core/footer-data-provider.js +321 -0
- package/dist/core/goal/index.d.ts +3 -0
- package/dist/core/goal/index.js +1 -0
- package/dist/core/goal/scheduler.d.ts +83 -0
- package/dist/core/goal/scheduler.js +154 -0
- package/dist/core/goal/types.d.ts +182 -0
- package/dist/core/goal/types.js +11 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +8 -0
- package/dist/core/intent/classifier.d.ts +53 -0
- package/dist/core/intent/classifier.js +353 -0
- package/dist/core/intent/index.d.ts +8 -0
- package/dist/core/intent/index.js +8 -0
- package/dist/core/intent/tool-adapter.d.ts +31 -0
- package/dist/core/intent/tool-adapter.js +168 -0
- package/dist/core/intent/types.d.ts +71 -0
- package/dist/core/intent/types.js +6 -0
- package/dist/core/keybindings.d.ts +297 -0
- package/dist/core/keybindings.js +250 -0
- package/dist/core/messages.d.ts +30 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/model-registry.d.ts +131 -0
- package/dist/core/model-registry.js +634 -0
- package/dist/core/model-resolver.d.ts +109 -0
- package/dist/core/model-resolver.js +486 -0
- package/dist/core/output-guard.d.ts +5 -0
- package/dist/core/output-guard.js +58 -0
- package/dist/core/package-manager.d.ts +196 -0
- package/dist/core/package-manager.js +1873 -0
- package/dist/core/projection/boundary-inferrer.d.ts +58 -0
- package/dist/core/projection/boundary-inferrer.js +122 -0
- package/dist/core/projection/event-to-message.d.ts +35 -0
- package/dist/core/projection/event-to-message.js +253 -0
- package/dist/core/projection/goal-projection.d.ts +67 -0
- package/dist/core/projection/goal-projection.js +339 -0
- package/dist/core/projection/index.d.ts +13 -0
- package/dist/core/projection/index.js +13 -0
- package/dist/core/projection/session-manager.d.ts +100 -0
- package/dist/core/projection/session-manager.js +331 -0
- package/dist/core/projection/session-projection.d.ts +58 -0
- package/dist/core/projection/session-projection.js +257 -0
- package/dist/core/projection/task-history.d.ts +13 -0
- package/dist/core/projection/task-history.js +61 -0
- package/dist/core/projection/timeline-projection.d.ts +82 -0
- package/dist/core/projection/timeline-projection.js +276 -0
- package/dist/core/projection/types.d.ts +69 -0
- package/dist/core/projection/types.js +6 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.js +249 -0
- package/dist/core/resolve-config-value.d.ts +22 -0
- package/dist/core/resolve-config-value.js +125 -0
- package/dist/core/resource-loader.d.ts +193 -0
- package/dist/core/resource-loader.js +685 -0
- package/dist/core/runtime/ai-client.d.ts +12 -0
- package/dist/core/runtime/ai-client.js +153 -0
- package/dist/core/runtime/checkpoint.d.ts +12 -0
- package/dist/core/runtime/checkpoint.js +78 -0
- package/dist/core/runtime/index.d.ts +12 -0
- package/dist/core/runtime/index.js +12 -0
- package/dist/core/runtime/llm-types.d.ts +99 -0
- package/dist/core/runtime/llm-types.js +6 -0
- package/dist/core/runtime/local-runtime.d.ts +23 -0
- package/dist/core/runtime/local-runtime.js +59 -0
- package/dist/core/runtime/policies.d.ts +72 -0
- package/dist/core/runtime/policies.js +37 -0
- package/dist/core/runtime/reactor.d.ts +213 -0
- package/dist/core/runtime/reactor.js +992 -0
- package/dist/core/runtime/runtime.d.ts +191 -0
- package/dist/core/runtime/runtime.js +449 -0
- package/dist/core/runtime/types.d.ts +42 -0
- package/dist/core/runtime/types.js +1 -0
- package/dist/core/sdk.d.ts +12 -0
- package/dist/core/sdk.js +10 -0
- package/dist/core/session-context-builder.d.ts +9 -0
- package/dist/core/session-context-builder.js +87 -0
- package/dist/core/session-cwd.d.ts +18 -0
- package/dist/core/session-cwd.js +36 -0
- package/dist/core/session-facade-factory.d.ts +79 -0
- package/dist/core/session-facade-factory.js +460 -0
- package/dist/core/session-facade.d.ts +57 -0
- package/dist/core/session-facade.js +91 -0
- package/dist/core/session-listing.d.ts +30 -0
- package/dist/core/session-listing.js +168 -0
- package/dist/core/session-reader.d.ts +19 -0
- package/dist/core/session-reader.js +101 -0
- package/dist/core/session-ref.d.ts +7 -0
- package/dist/core/session-ref.js +25 -0
- package/dist/core/session-services.d.ts +51 -0
- package/dist/core/session-services.js +90 -0
- package/dist/core/session-stats.d.ts +43 -0
- package/dist/core/session-stats.js +41 -0
- package/dist/core/settings-manager.d.ts +236 -0
- package/dist/core/settings-manager.js +706 -0
- package/dist/core/skill-block-parser.d.ts +12 -0
- package/dist/core/skill-block-parser.js +15 -0
- package/dist/core/skills.d.ts +59 -0
- package/dist/core/skills.js +408 -0
- package/dist/core/slash-commands.d.ts +13 -0
- package/dist/core/slash-commands.js +17 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/source-info.js +18 -0
- package/dist/core/system-prompt.d.ts +27 -0
- package/dist/core/system-prompt.js +179 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.js +30 -0
- package/dist/core/tools/bash.d.ts +95 -0
- package/dist/core/tools/bash.js +513 -0
- package/dist/core/tools/builtin-commands.d.ts +75 -0
- package/dist/core/tools/builtin-commands.js +503 -0
- package/dist/core/tools/compat-commands.d.ts +12 -0
- package/dist/core/tools/compat-commands.js +1280 -0
- package/dist/core/tools/edit-diff.d.ts +59 -0
- package/dist/core/tools/edit-diff.js +263 -0
- package/dist/core/tools/edit.d.ts +49 -0
- package/dist/core/tools/edit.js +340 -0
- package/dist/core/tools/file-mutation-queue.d.ts +5 -0
- package/dist/core/tools/file-mutation-queue.js +36 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +459 -0
- package/dist/core/tools/grep.d.ts +36 -0
- package/dist/core/tools/grep.js +422 -0
- package/dist/core/tools/index.d.ts +70 -0
- package/dist/core/tools/index.js +129 -0
- package/dist/core/tools/line-anchors.d.ts +33 -0
- package/dist/core/tools/line-anchors.js +151 -0
- package/dist/core/tools/ls.d.ts +36 -0
- package/dist/core/tools/ls.js +268 -0
- package/dist/core/tools/path-utils.d.ts +7 -0
- package/dist/core/tools/path-utils.js +80 -0
- package/dist/core/tools/read.d.ts +35 -0
- package/dist/core/tools/read.js +244 -0
- package/dist/core/tools/render-utils.d.ts +20 -0
- package/dist/core/tools/render-utils.js +48 -0
- package/dist/core/tools/session-split.d.ts +9 -0
- package/dist/core/tools/session-split.js +77 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
- package/dist/core/tools/tool-definition-wrapper.js +32 -0
- package/dist/core/tools/truncate.d.ts +69 -0
- package/dist/core/tools/truncate.js +204 -0
- package/dist/core/tools/write.d.ts +25 -0
- package/dist/core/tools/write.js +211 -0
- package/dist/core/types/session-types.d.ts +123 -0
- package/dist/core/types/session-types.js +8 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +38 -0
- package/dist/main.d.ts +11 -2
- package/dist/main.js +577 -149
- package/dist/modes/event-mapper.d.ts +115 -0
- package/dist/modes/event-mapper.js +200 -0
- package/dist/modes/gui/server.d.ts +14 -0
- package/dist/modes/gui/server.js +1032 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.js +9 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/armin.d.ts +33 -0
- package/dist/modes/interactive/components/armin.js +328 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
- package/dist/modes/interactive/components/assistant-message.js +115 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
- package/dist/modes/interactive/components/bash-execution.js +169 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.js +50 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/branch-summary-message.js +41 -0
- package/dist/modes/interactive/components/brand-header.d.ts +33 -0
- package/dist/modes/interactive/components/brand-header.js +235 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
- package/dist/modes/interactive/components/config-selector.d.ts +70 -0
- package/dist/modes/interactive/components/config-selector.js +469 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
- package/dist/modes/interactive/components/countdown-timer.js +27 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +27 -0
- package/dist/modes/interactive/components/custom-editor.js +94 -0
- package/dist/modes/interactive/components/custom-message.d.ts +19 -0
- package/dist/modes/interactive/components/custom-message.js +73 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
- package/dist/modes/interactive/components/daxnuts.js +137 -0
- package/dist/modes/interactive/components/diff.d.ts +11 -0
- package/dist/modes/interactive/components/diff.js +132 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
- package/dist/modes/interactive/components/dynamic-border.js +19 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
- package/dist/modes/interactive/components/earendil-announcement.js +39 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-editor.js +105 -0
- package/dist/modes/interactive/components/extension-input.d.ts +22 -0
- package/dist/modes/interactive/components/extension-input.js +54 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +23 -0
- package/dist/modes/interactive/components/extension-selector.js +70 -0
- package/dist/modes/interactive/components/footer.d.ts +55 -0
- package/dist/modes/interactive/components/footer.js +207 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.js +32 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.js +21 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +41 -0
- package/dist/modes/interactive/components/login-dialog.js +138 -0
- package/dist/modes/interactive/components/model-selector.d.ts +32 -0
- package/dist/modes/interactive/components/model-selector.js +209 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -0
- package/dist/modes/interactive/components/oauth-selector.js +91 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +57 -0
- package/dist/modes/interactive/components/settings-selector.js +299 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
- package/dist/modes/interactive/components/show-images-selector.js +37 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
- package/dist/modes/interactive/components/theme-selector.js +47 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
- package/dist/modes/interactive/components/thinking-selector.js +50 -0
- package/dist/modes/interactive/components/timeline-view.d.ts +31 -0
- package/dist/modes/interactive/components/timeline-view.js +81 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +64 -0
- package/dist/modes/interactive/components/tool-execution.js +305 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
- package/dist/modes/interactive/components/tree-selector.js +1072 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
- package/dist/modes/interactive/components/user-message-selector.js +110 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.js +27 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
- package/dist/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/modes/interactive/interactive-mode.d.ts +394 -0
- package/dist/modes/interactive/interactive-mode.js +4116 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +80 -0
- package/dist/modes/interactive/theme/theme.js +973 -0
- package/dist/modes/print-mode.d.ts +27 -0
- package/dist/modes/print-mode.js +102 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +48 -0
- package/dist/modes/rpc/rpc-client.d.ts +219 -0
- package/dist/modes/rpc/rpc-client.js +405 -0
- package/dist/modes/rpc/rpc-mode.d.ts +19 -0
- package/dist/modes/rpc/rpc-mode.js +381 -0
- package/dist/modes/rpc/rpc-types.d.ts +406 -0
- package/dist/modes/rpc/rpc-types.js +7 -0
- package/dist/package-manager-cli.d.ts +3 -0
- package/dist/package-manager-cli.js +233 -0
- package/dist/utils/changelog.d.ts +20 -0
- package/dist/utils/changelog.js +86 -0
- package/dist/utils/child-process.d.ts +10 -0
- package/dist/utils/child-process.js +77 -0
- package/dist/utils/clipboard-image.d.ts +10 -0
- package/dist/utils/clipboard-image.js +244 -0
- package/dist/utils/clipboard-native.d.ts +7 -0
- package/dist/utils/clipboard-native.js +13 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +77 -0
- package/dist/utils/exif-orientation.d.ts +4 -0
- package/dist/utils/exif-orientation.js +157 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/frontmatter.js +25 -0
- package/dist/utils/git.d.ts +25 -0
- package/dist/utils/git.js +162 -0
- package/dist/utils/image-convert.d.ts +8 -0
- package/dist/utils/image-convert.js +38 -0
- package/dist/utils/image-resize.d.ts +35 -0
- package/dist/utils/image-resize.js +136 -0
- package/dist/utils/mime.d.ts +1 -0
- package/dist/utils/mime.js +25 -0
- package/dist/utils/path-shims.d.ts +1 -0
- package/dist/utils/path-shims.js +90 -0
- package/dist/utils/paths.d.ts +6 -0
- package/dist/utils/paths.js +18 -0
- package/dist/utils/photon.d.ts +20 -0
- package/dist/utils/photon.js +120 -0
- package/dist/utils/shell.d.ts +29 -0
- package/dist/utils/shell.js +189 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/sleep.js +16 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.js +101 -0
- package/dist/vendor/bin/darwin-arm64/fd +0 -0
- package/dist/vendor/bin/darwin-arm64/rg +0 -0
- package/dist/vendor/bin/darwin-x64/fd +0 -0
- package/dist/vendor/bin/darwin-x64/rg +0 -0
- package/dist/vendor/bin/linux-arm64/fd +0 -0
- package/dist/vendor/bin/linux-arm64/rg +0 -0
- package/dist/vendor/bin/linux-x64/fd +0 -0
- package/dist/vendor/bin/linux-x64/rg +0 -0
- package/dist/vendor/bin/win32-arm64/fd.exe +0 -0
- package/dist/vendor/bin/win32-arm64/rg.exe +0 -0
- package/dist/vendor/bin/win32-x64/fd.exe +0 -0
- package/dist/vendor/bin/win32-x64/rg.exe +0 -0
- package/package.json +90 -26
- package/dist/extension/core.d.ts +0 -69
- package/dist/extension/core.js +0 -270
- package/dist/extension/core.js.map +0 -1
- package/dist/extension/index.d.ts +0 -14
- package/dist/extension/index.js +0 -374
- package/dist/extension/index.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/themes/pizza.json +0 -87
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactor — Event-Driven Agent Core
|
|
3
|
+
*
|
|
4
|
+
* Replaces the AgentLoop while-loop with a set of typed handlers that react
|
|
5
|
+
* to events appended to the EventStore. Each handler is a pure async function
|
|
6
|
+
* that may emit new events. The reactor itself is stateless — all mutable
|
|
7
|
+
* state lives in the EventStore.
|
|
8
|
+
*
|
|
9
|
+
* Event flow:
|
|
10
|
+
*
|
|
11
|
+
* USER_MESSAGE / USER_INTERRUPT / TOOL_RESULTS_AGGREGATED / RETRY_SCHEDULED
|
|
12
|
+
* ↓
|
|
13
|
+
* [onUserMessage] ──→ emit AGENT_TURN_REQUESTED
|
|
14
|
+
* ↓
|
|
15
|
+
* [onAgentTurnRequested] ──→ emit LLM_CALL_REQUESTED
|
|
16
|
+
* ↓
|
|
17
|
+
* [onLlmCallRequested] ──→ call LLM → emit AGENT_MESSAGE_START/CHUNK/END
|
|
18
|
+
* ↓
|
|
19
|
+
* [onAgentMessageEnd]
|
|
20
|
+
* ├── if no tool_calls → emit AGENT_TURN_COMPLETED
|
|
21
|
+
* └── if tool_calls → emit INTENT_TOOL_CALL (one per call)
|
|
22
|
+
* ↓
|
|
23
|
+
* [onIntentToolCall] ──→ (approval gate) → emit TOOL_EXECUTION_START/END
|
|
24
|
+
* ↓
|
|
25
|
+
* [onToolExecutionEnd] ──→ track count → if all done → emit TOOL_RESULTS_AGGREGATED
|
|
26
|
+
* ↓
|
|
27
|
+
* [onToolResultsAggregated] ──→ emit AGENT_TURN_REQUESTED ← loop back
|
|
28
|
+
*
|
|
29
|
+
* Other handlers (run in parallel, do not gate the main flow):
|
|
30
|
+
* onAgentTurnCompleted — UI notification
|
|
31
|
+
* onLlmCallFailed — retry scheduling
|
|
32
|
+
* onUserInterrupt — abort signal + turn completion
|
|
33
|
+
* onCompactionRequested — compaction orchestration
|
|
34
|
+
*/
|
|
35
|
+
import type { EventBase, EventType } from "../event-store/types.js";
|
|
36
|
+
import type { EventStore } from "../event-store/store.js";
|
|
37
|
+
import type { ApprovalHandler, ToolRegistry } from "../intent/types.js";
|
|
38
|
+
import type { IntentClassifier } from "../intent/classifier.js";
|
|
39
|
+
import type { LLMClient, ToolDefinition } from "./llm-types.js";
|
|
40
|
+
import type { RuntimeAdapter } from "./types.js";
|
|
41
|
+
import type { SessionProjection } from "../projection/session-projection.js";
|
|
42
|
+
import type { SessionManager } from "../projection/session-manager.js";
|
|
43
|
+
import type { CompactionPolicy, RetryPolicy } from "./policies.js";
|
|
44
|
+
/** Reactor configuration */
|
|
45
|
+
export interface ReactorConfig {
|
|
46
|
+
store: EventStore;
|
|
47
|
+
projection: SessionProjection;
|
|
48
|
+
llmClient: LLMClient;
|
|
49
|
+
classifier: IntentClassifier;
|
|
50
|
+
toolRegistry: ToolRegistry;
|
|
51
|
+
approvalHandler?: ApprovalHandler;
|
|
52
|
+
runtimeAdapter: RuntimeAdapter;
|
|
53
|
+
systemPrompt: string;
|
|
54
|
+
model: {
|
|
55
|
+
provider: string;
|
|
56
|
+
model_id: string;
|
|
57
|
+
thinking_level?: string;
|
|
58
|
+
};
|
|
59
|
+
contextBudget: number;
|
|
60
|
+
/** Tool definitions exposed to the LLM */
|
|
61
|
+
tools: ToolDefinition[];
|
|
62
|
+
/** Retry policy (default: DefaultRetryPolicy). */
|
|
63
|
+
retryPolicy?: RetryPolicy;
|
|
64
|
+
/** Whether assistant messages that complete with stop_reason=error should be retried by the reactor. */
|
|
65
|
+
retryAssistantErrorCompletions?: boolean;
|
|
66
|
+
/** Compaction policy (default: NoopCompactionPolicy). */
|
|
67
|
+
compactionPolicy?: CompactionPolicy;
|
|
68
|
+
/** SessionManager for refreshing projection after session splits. */
|
|
69
|
+
sessionManager?: SessionManager;
|
|
70
|
+
}
|
|
71
|
+
/** A single event handler. Returns void or void Promise. */
|
|
72
|
+
export type EventHandler = (event: EventBase) => void | Promise<void>;
|
|
73
|
+
/** Mapping from event type to handler */
|
|
74
|
+
export type EventHandlerMap = Partial<Record<EventType, EventHandler>>;
|
|
75
|
+
export declare class Reactor {
|
|
76
|
+
private config;
|
|
77
|
+
private abortController;
|
|
78
|
+
private turnTrackers;
|
|
79
|
+
private handlers;
|
|
80
|
+
private unsubscribers;
|
|
81
|
+
private _isRunning;
|
|
82
|
+
/** Context built in onAgentTurnRequested, consumed by onLlmCallRequested. */
|
|
83
|
+
private _pendingContext;
|
|
84
|
+
/** Active retry policy. */
|
|
85
|
+
private retryPolicy;
|
|
86
|
+
/** Active compaction policy. */
|
|
87
|
+
private compactionPolicy;
|
|
88
|
+
/** Pending follow-up messages (delivered after current turn completes without interrupt). */
|
|
89
|
+
private followUpQueue;
|
|
90
|
+
/** Aborter for the current compaction run (if any). */
|
|
91
|
+
private compactionAbort;
|
|
92
|
+
/** Retry timers waiting to re-enter the turn loop. */
|
|
93
|
+
private retryTimers;
|
|
94
|
+
/** Set when abort() is called with no new content — next turn completion should discard queued follow-ups. */
|
|
95
|
+
private _abortedByUser;
|
|
96
|
+
/** Tool names called in each consecutive tool-use round within the current prompt cycle. */
|
|
97
|
+
private _toolRoundSignatures;
|
|
98
|
+
constructor(config: ReactorConfig);
|
|
99
|
+
/** Subscribe to all events and start the reactor. */
|
|
100
|
+
start(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Replay USER_FOLLOWUP_QUEUED events that were appended while the reactor was idle.
|
|
103
|
+
* Skips events that have already been consumed (i.e. an AGENT_TURN_COMPLETED with a
|
|
104
|
+
* caused_by chain that includes them).
|
|
105
|
+
*
|
|
106
|
+
* For now we use a simple heuristic: count followups vs followup-driven user messages.
|
|
107
|
+
* If followups outnumber the consumed ones, replay the difference into the in-memory queue.
|
|
108
|
+
*/
|
|
109
|
+
private _replayPendingFollowUps;
|
|
110
|
+
/** Stop the reactor. Clears all subscriptions. */
|
|
111
|
+
stop(): void;
|
|
112
|
+
/** Check if the reactor is running. */
|
|
113
|
+
get isRunning(): boolean;
|
|
114
|
+
/** Abort signal for the currently active reactor run. */
|
|
115
|
+
get signal(): AbortSignal | undefined;
|
|
116
|
+
private _dispatch;
|
|
117
|
+
private _emit;
|
|
118
|
+
/** Check if the reactor has been asked to stop. */
|
|
119
|
+
private _shouldInterrupt;
|
|
120
|
+
/** Interrupt the reactor. */
|
|
121
|
+
interrupt(): void;
|
|
122
|
+
private _registerAllHandlers;
|
|
123
|
+
/**
|
|
124
|
+
* Send a user message to the agent (idle path).
|
|
125
|
+
* For interrupt-while-streaming use steer(). For after-turn-completion use followUp().
|
|
126
|
+
*/
|
|
127
|
+
prompt(content: string | Array<{
|
|
128
|
+
type: string;
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}>, images?: Array<{
|
|
131
|
+
type: "image";
|
|
132
|
+
data: string;
|
|
133
|
+
mime_type: string;
|
|
134
|
+
}>): void;
|
|
135
|
+
/**
|
|
136
|
+
* Steer: interrupt current turn with a new user message.
|
|
137
|
+
* The reactor aborts the current LLM call (if any) and treats the steer message
|
|
138
|
+
* as a fresh USER_MESSAGE once the turn settles.
|
|
139
|
+
*/
|
|
140
|
+
steer(content: string | Array<{
|
|
141
|
+
type: string;
|
|
142
|
+
[key: string]: unknown;
|
|
143
|
+
}>, images?: Array<{
|
|
144
|
+
type: "image";
|
|
145
|
+
data: string;
|
|
146
|
+
mime_type: string;
|
|
147
|
+
}>): void;
|
|
148
|
+
/**
|
|
149
|
+
* Follow-up: queue a message to be delivered after the current turn naturally completes.
|
|
150
|
+
* Does not interrupt. If the reactor is idle, behaves like prompt().
|
|
151
|
+
*/
|
|
152
|
+
followUp(content: string | Array<{
|
|
153
|
+
type: string;
|
|
154
|
+
[key: string]: unknown;
|
|
155
|
+
}>, images?: Array<{
|
|
156
|
+
type: "image";
|
|
157
|
+
data: string;
|
|
158
|
+
mime_type: string;
|
|
159
|
+
}>): void;
|
|
160
|
+
/** Number of pending follow-up messages. */
|
|
161
|
+
get pendingFollowUpCount(): number;
|
|
162
|
+
/** Number of scheduled retries waiting to re-enter the turn loop. */
|
|
163
|
+
get pendingRetryCount(): number;
|
|
164
|
+
/** Clear pending follow-ups (e.g. on user-explicit cancel). */
|
|
165
|
+
clearFollowUpQueue(): void;
|
|
166
|
+
private _onUserMessage;
|
|
167
|
+
private _onUserInterrupt;
|
|
168
|
+
private _onUserFollowupQueued;
|
|
169
|
+
private _onAgentTurnRequested;
|
|
170
|
+
private _onLlmCallRequested;
|
|
171
|
+
private _handleLlmResponse;
|
|
172
|
+
private _onAgentMessageEnd;
|
|
173
|
+
private readonly _pendingApprovals;
|
|
174
|
+
private _onIntentToolCall;
|
|
175
|
+
private _executeTool;
|
|
176
|
+
private _emitToolExecutionUpdate;
|
|
177
|
+
private _emitToolExecutionEnd;
|
|
178
|
+
private _onToolExecutionEnd;
|
|
179
|
+
private _onToolResultsAggregated;
|
|
180
|
+
/**
|
|
181
|
+
* When a session split occurs, refresh the projection to point to the new
|
|
182
|
+
* session. The new session's start_event_id is set to the current USER_MESSAGE,
|
|
183
|
+
* so buildContext() will include the user's request + tool results but exclude
|
|
184
|
+
* old conversation history. This lets the model continue working in the same
|
|
185
|
+
* turn with a clean context.
|
|
186
|
+
*/
|
|
187
|
+
private _onSessionBoundaryInferred;
|
|
188
|
+
/**
|
|
189
|
+
* Check whether the model is stuck in a loop — calling the exact same set
|
|
190
|
+
* of tool names in too many consecutive rounds.
|
|
191
|
+
*/
|
|
192
|
+
private _isInToolLoop;
|
|
193
|
+
private _onAgentTurnCompleted;
|
|
194
|
+
private _onLlmCallFailed;
|
|
195
|
+
private _scheduleRetryForCompletedError;
|
|
196
|
+
private _errorAlreadyHandledByLlmFailure;
|
|
197
|
+
private _scheduleRetry;
|
|
198
|
+
/** Walk causal chain back to find the highest retry_attempt seen. */
|
|
199
|
+
private _attemptCount;
|
|
200
|
+
private _onUserApproval;
|
|
201
|
+
private _onUserRejection;
|
|
202
|
+
private _onCompactionRequested;
|
|
203
|
+
/**
|
|
204
|
+
* Check compaction policy after a non-error turn. Emits COMPACTION_REQUESTED if
|
|
205
|
+
* threshold or overflow conditions are met.
|
|
206
|
+
*/
|
|
207
|
+
private _checkCompaction;
|
|
208
|
+
/**
|
|
209
|
+
* Walk causal chain back from the given event to find the most recent AGENT_MESSAGE_END.
|
|
210
|
+
* Replaces the mutable _lastAssistantMessageEvent field which races with synchronous dispatch.
|
|
211
|
+
*/
|
|
212
|
+
private _findLastAssistantMessage;
|
|
213
|
+
}
|