@tomsun28/pizza 0.0.9 → 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 -25
- package/dist/extension/index.js +0 -303
- package/dist/extension/index.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/themes/pizza.json +0 -87
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event-Sourced Runtime
|
|
3
|
+
*
|
|
4
|
+
* Top-level runtime that assembles EventStore + SessionManager + Reactor.
|
|
5
|
+
* Provides unified interface for UI layers.
|
|
6
|
+
*/
|
|
7
|
+
import type { EventBase, ImageContent } from "../event-store/types.js";
|
|
8
|
+
import type { EventStore, SubscribeOptions } from "../event-store/store.js";
|
|
9
|
+
import type { SessionDescriptor } from "../projection/types.js";
|
|
10
|
+
import type { ToolRegistry, ApprovalHandler } from "../intent/types.js";
|
|
11
|
+
import type { LLMClient, ModelConfig, ToolDefinition } from "./llm-types.js";
|
|
12
|
+
import { SessionManager } from "../projection/session-manager.js";
|
|
13
|
+
import { SessionProjection } from "../projection/session-projection.js";
|
|
14
|
+
import { type TimelineQueryOptions } from "../projection/timeline-projection.js";
|
|
15
|
+
import { IntentClassifier, type ClassifierConfig } from "../intent/classifier.js";
|
|
16
|
+
import type { CheckpointRef, RuntimeAdapter, RuntimeStatus } from "./types.js";
|
|
17
|
+
import { type CompactionEngineSettings } from "../compaction/compaction-engine.js";
|
|
18
|
+
export interface EventSourcedRuntimeConfig {
|
|
19
|
+
/** Working directory (used to derive workspace_id) */
|
|
20
|
+
cwd: string;
|
|
21
|
+
/** Agent directory for storage */
|
|
22
|
+
agentDir?: string;
|
|
23
|
+
/** SQLite database path for events (overrides default) */
|
|
24
|
+
storagePath?: string;
|
|
25
|
+
/** Session index path (overrides default) */
|
|
26
|
+
sessionIndexPath?: string;
|
|
27
|
+
/** Pre-configured EventStore (optional, will create if not provided) */
|
|
28
|
+
store?: EventStore;
|
|
29
|
+
/** Thread ID for event isolation. When set, the runtime wraps its store so every appended event carries thread_id = threadId. */
|
|
30
|
+
threadId?: string;
|
|
31
|
+
/** Pre-configured SessionManager (optional, will create if not provided) */
|
|
32
|
+
sessionManager?: SessionManager;
|
|
33
|
+
/** Classifier configuration */
|
|
34
|
+
classifierConfig?: ClassifierConfig;
|
|
35
|
+
/** Tool registry */
|
|
36
|
+
toolRegistry: ToolRegistry;
|
|
37
|
+
/** Runtime adapter for deterministic tool execution and checkpoints */
|
|
38
|
+
runtimeAdapter?: RuntimeAdapter;
|
|
39
|
+
/** Approval handler for UI */
|
|
40
|
+
approvalHandler?: ApprovalHandler;
|
|
41
|
+
/** LLM client */
|
|
42
|
+
llmClient: LLMClient;
|
|
43
|
+
/** System prompt */
|
|
44
|
+
systemPrompt: string;
|
|
45
|
+
/** Model configuration */
|
|
46
|
+
model: ModelConfig;
|
|
47
|
+
/** Tools available to the agent */
|
|
48
|
+
tools: ToolDefinition[];
|
|
49
|
+
/** Context token budget */
|
|
50
|
+
contextBudget?: number;
|
|
51
|
+
/** Retry policy (default: DefaultRetryPolicy). */
|
|
52
|
+
retryPolicy?: import("./policies.js").RetryPolicy;
|
|
53
|
+
/** Whether assistant messages that complete with stop_reason=error should be retried by the reactor. */
|
|
54
|
+
retryAssistantErrorCompletions?: boolean;
|
|
55
|
+
/** Compaction policy (default: NoopCompactionPolicy). */
|
|
56
|
+
compactionPolicy?: import("./policies.js").CompactionPolicy;
|
|
57
|
+
/** Settings for the default event-sourced compaction engine. Ignored when compactionPolicy is provided. */
|
|
58
|
+
compactionEngineSettings?: CompactionEngineSettings;
|
|
59
|
+
}
|
|
60
|
+
export interface RuntimeCompactOptions {
|
|
61
|
+
reason?: "manual" | "threshold" | "overflow";
|
|
62
|
+
token_count?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* EventSourcedRuntime - the primary LLM execution engine.
|
|
66
|
+
*
|
|
67
|
+
* Assembles EventStore + SessionManager + Reactor.
|
|
68
|
+
* Provides unified interface for UI layers.
|
|
69
|
+
*/
|
|
70
|
+
export declare class EventSourcedRuntime {
|
|
71
|
+
readonly store: EventStore;
|
|
72
|
+
readonly sessionManager: SessionManager | undefined;
|
|
73
|
+
readonly runtimeAdapter: RuntimeAdapter;
|
|
74
|
+
readonly classifier: IntentClassifier;
|
|
75
|
+
private reactor;
|
|
76
|
+
private config;
|
|
77
|
+
private readonly ownsStore;
|
|
78
|
+
/** Working directory for this runtime */
|
|
79
|
+
get cwd(): string;
|
|
80
|
+
/** Agent data directory */
|
|
81
|
+
get agentDir(): string;
|
|
82
|
+
private _isProcessing;
|
|
83
|
+
private _turnCompletionWaiters;
|
|
84
|
+
private _turnSubscription;
|
|
85
|
+
private _resolveSettled;
|
|
86
|
+
constructor(config: EventSourcedRuntimeConfig);
|
|
87
|
+
/**
|
|
88
|
+
* Process user input. Drives the reactor to completion (one turn cycle).
|
|
89
|
+
*/
|
|
90
|
+
prompt(text: string, images?: ImageContent[]): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if runtime is currently processing.
|
|
93
|
+
*/
|
|
94
|
+
get isRunning(): boolean;
|
|
95
|
+
get signal(): AbortSignal | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve when the current prompt cycle is fully settled.
|
|
98
|
+
*/
|
|
99
|
+
waitForIdle(): Promise<void>;
|
|
100
|
+
private _resolveIdleWaiters;
|
|
101
|
+
/**
|
|
102
|
+
* Interrupt current execution.
|
|
103
|
+
*
|
|
104
|
+
* Sets _abortedByUser on the reactor, which causes _onAgentTurnCompleted to discard
|
|
105
|
+
* queued follow-ups and let the reactor settle. The settled promise resolves naturally
|
|
106
|
+
* when the current turn finishes (via _waitUntilSettled).
|
|
107
|
+
*
|
|
108
|
+
* Edge case: if no turn is running (no AGENT_TURN_COMPLETED will fire), also resolve
|
|
109
|
+
* the settled promise immediately so the caller doesn't hang.
|
|
110
|
+
*/
|
|
111
|
+
abort(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Inject a steer message — interrupts the current turn and delivers the message
|
|
114
|
+
* as a follow-up after the current turn settles.
|
|
115
|
+
*/
|
|
116
|
+
steer(text: string, images?: ImageContent[]): void;
|
|
117
|
+
/**
|
|
118
|
+
* Queue a follow-up message — delivered after the current turn naturally completes.
|
|
119
|
+
* If the runtime is not processing, queues it for the next prompt.
|
|
120
|
+
*/
|
|
121
|
+
followUp(text: string, images?: ImageContent[]): void;
|
|
122
|
+
/**
|
|
123
|
+
* Request context compaction. The active reactor handles this immediately when
|
|
124
|
+
* running; otherwise the request is recorded for the event stream.
|
|
125
|
+
*/
|
|
126
|
+
compact(options?: RuntimeCompactOptions): void;
|
|
127
|
+
setModel(provider: string, modelId: string): void;
|
|
128
|
+
getModel(): ModelConfig;
|
|
129
|
+
setThinkingLevel(level: string): void;
|
|
130
|
+
getThinkingLevel(): string | undefined;
|
|
131
|
+
getProjection(): SessionProjection;
|
|
132
|
+
getTools(): ToolDefinition[];
|
|
133
|
+
setTools(tools: ToolDefinition[]): void;
|
|
134
|
+
getSystemPrompt(): string;
|
|
135
|
+
setSystemPrompt(prompt: string): void;
|
|
136
|
+
private _createDefaultProjection;
|
|
137
|
+
/**
|
|
138
|
+
* Wait until the reactor has settled — i.e. an AGENT_TURN_COMPLETED fires AND
|
|
139
|
+
* no further USER_MESSAGE has been appended in the same tick (e.g. by follow-up draining).
|
|
140
|
+
*/
|
|
141
|
+
private _waitUntilSettled;
|
|
142
|
+
/**
|
|
143
|
+
* Approve a pending intent.
|
|
144
|
+
*/
|
|
145
|
+
approve(intentEventId: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* Reject a pending intent.
|
|
148
|
+
*/
|
|
149
|
+
reject(intentEventId: string): void;
|
|
150
|
+
/**
|
|
151
|
+
* Subscribe to real-time events (for UI).
|
|
152
|
+
*/
|
|
153
|
+
subscribe(handler: (event: EventBase) => void, options?: SubscribeOptions): () => void;
|
|
154
|
+
/**
|
|
155
|
+
* Query the activity timeline (for UI rendering).
|
|
156
|
+
*/
|
|
157
|
+
getTimeline(options?: TimelineQueryOptions): import("../projection/timeline-projection.js").TimelineEntry[];
|
|
158
|
+
/**
|
|
159
|
+
* Fork session at a specific event.
|
|
160
|
+
*/
|
|
161
|
+
fork(eventId: string): SessionDescriptor;
|
|
162
|
+
/**
|
|
163
|
+
* Switch to a different session.
|
|
164
|
+
*/
|
|
165
|
+
switchSession(sessionId: string): void;
|
|
166
|
+
/**
|
|
167
|
+
* Create a new session.
|
|
168
|
+
*/
|
|
169
|
+
createSession(name?: string): SessionDescriptor;
|
|
170
|
+
/**
|
|
171
|
+
* Get current session descriptor.
|
|
172
|
+
*/
|
|
173
|
+
getCurrentSession(): SessionDescriptor | undefined;
|
|
174
|
+
createCheckpoint(label?: string): Promise<CheckpointRef>;
|
|
175
|
+
restoreCheckpoint(checkpoint: CheckpointRef): Promise<void>;
|
|
176
|
+
getRuntimeStatus(): Promise<RuntimeStatus>;
|
|
177
|
+
/**
|
|
178
|
+
* Dispose the runtime.
|
|
179
|
+
*/
|
|
180
|
+
dispose(): void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Create an EventSourcedRuntime from existing components.
|
|
184
|
+
*/
|
|
185
|
+
/**
|
|
186
|
+
* Create an EventSourcedRuntime from existing components.
|
|
187
|
+
*
|
|
188
|
+
* Note: This factory bypasses the constructor to allow injection of
|
|
189
|
+
* pre-configured EventStore and SessionManager instances.
|
|
190
|
+
*/
|
|
191
|
+
export declare function createEventSourcedRuntime(store: EventStore, sessionManager: SessionManager, config: Omit<EventSourcedRuntimeConfig, "cwd" | "storagePath" | "sessionIndexPath">): EventSourcedRuntime;
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event-Sourced Runtime
|
|
3
|
+
*
|
|
4
|
+
* Top-level runtime that assembles EventStore + SessionManager + Reactor.
|
|
5
|
+
* Provides unified interface for UI layers.
|
|
6
|
+
*/
|
|
7
|
+
import { SqliteEventStore } from "../event-store/sqlite-store.js";
|
|
8
|
+
import { ThreadScopedStore } from "../event-store/thread-scoped-store.js";
|
|
9
|
+
import { deriveWorkspaceId, getEventDatabasePath, getSessionIndexPath } from "../event-store/workspace.js";
|
|
10
|
+
import { SessionManager } from "../projection/session-manager.js";
|
|
11
|
+
import { SessionProjection } from "../projection/session-projection.js";
|
|
12
|
+
import { TimelineProjection } from "../projection/timeline-projection.js";
|
|
13
|
+
import { IntentClassifier } from "../intent/classifier.js";
|
|
14
|
+
import { Reactor } from "./reactor.js";
|
|
15
|
+
import { LocalRuntimeAdapter } from "./local-runtime.js";
|
|
16
|
+
import { CompactionEngine } from "../compaction/compaction-engine.js";
|
|
17
|
+
import { getAgentDir } from "../../config.js";
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Event-Sourced Runtime
|
|
20
|
+
// ============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* EventSourcedRuntime - the primary LLM execution engine.
|
|
23
|
+
*
|
|
24
|
+
* Assembles EventStore + SessionManager + Reactor.
|
|
25
|
+
* Provides unified interface for UI layers.
|
|
26
|
+
*/
|
|
27
|
+
export class EventSourcedRuntime {
|
|
28
|
+
/** Working directory for this runtime */
|
|
29
|
+
get cwd() { return this.config.cwd; }
|
|
30
|
+
/** Agent data directory */
|
|
31
|
+
get agentDir() { return this.config.agentDir ?? getAgentDir(); }
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this.reactor = null;
|
|
34
|
+
this._isProcessing = false;
|
|
35
|
+
this._turnCompletionWaiters = [];
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.ownsStore = !config.store;
|
|
38
|
+
// 1. Create or use provided EventStore
|
|
39
|
+
const workspaceId = deriveWorkspaceId(config.cwd);
|
|
40
|
+
const rawStore = config.store ?? new SqliteEventStore(workspaceId, config.storagePath ?? getEventDatabasePath(workspaceId, config.agentDir));
|
|
41
|
+
this.store = config.threadId ? new ThreadScopedStore(rawStore, config.threadId) : rawStore;
|
|
42
|
+
this.runtimeAdapter = config.runtimeAdapter ?? new LocalRuntimeAdapter({
|
|
43
|
+
workspace_id: this.store.workspace_id,
|
|
44
|
+
cwd: config.cwd,
|
|
45
|
+
agentDir: config.agentDir,
|
|
46
|
+
toolRegistry: config.toolRegistry,
|
|
47
|
+
});
|
|
48
|
+
// 2. Create or use provided SessionManager (optional for migration)
|
|
49
|
+
this.sessionManager = config.sessionManager ?? (config.sessionManager !== undefined ? new SessionManager(this.store, config.sessionIndexPath ?? getSessionIndexPath(this.store.workspace_id, config.agentDir)) : undefined);
|
|
50
|
+
// 3. Create IntentClassifier
|
|
51
|
+
this.classifier = new IntentClassifier(config.classifierConfig);
|
|
52
|
+
this.store.append({
|
|
53
|
+
actor_id: "runtime",
|
|
54
|
+
type: "RUNTIME_STARTED",
|
|
55
|
+
payload: { runtime_id: this.runtimeAdapter.runtime_id, kind: this.runtimeAdapter.kind, cwd: config.cwd },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Process user input. Drives the reactor to completion (one turn cycle).
|
|
60
|
+
*/
|
|
61
|
+
async prompt(text, images) {
|
|
62
|
+
if (this._isProcessing) {
|
|
63
|
+
throw new Error("EventSourcedRuntime is already processing a prompt. Use steer() or followUp() to queue messages, or wait for completion.");
|
|
64
|
+
}
|
|
65
|
+
this._isProcessing = true;
|
|
66
|
+
try {
|
|
67
|
+
// Lazy-create the reactor and start it. Reactor lives only as long as the prompt cycle.
|
|
68
|
+
const projection = this.getProjection();
|
|
69
|
+
this.reactor = new Reactor({
|
|
70
|
+
store: this.store,
|
|
71
|
+
projection,
|
|
72
|
+
llmClient: this.config.llmClient,
|
|
73
|
+
classifier: this.classifier,
|
|
74
|
+
toolRegistry: this.config.toolRegistry,
|
|
75
|
+
approvalHandler: this.config.approvalHandler,
|
|
76
|
+
runtimeAdapter: this.runtimeAdapter,
|
|
77
|
+
systemPrompt: this.config.systemPrompt,
|
|
78
|
+
model: this.config.model,
|
|
79
|
+
contextBudget: this.config.contextBudget ?? 128000,
|
|
80
|
+
tools: this.config.tools,
|
|
81
|
+
retryPolicy: this.config.retryPolicy,
|
|
82
|
+
retryAssistantErrorCompletions: this.config.retryAssistantErrorCompletions,
|
|
83
|
+
compactionPolicy: this.config.compactionPolicy ?? new CompactionEngine({
|
|
84
|
+
store: this.store,
|
|
85
|
+
projection,
|
|
86
|
+
llmClient: this.config.llmClient,
|
|
87
|
+
model: this.config.model,
|
|
88
|
+
settings: {
|
|
89
|
+
contextWindow: this.config.contextBudget ?? 128000,
|
|
90
|
+
...this.config.compactionEngineSettings,
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
sessionManager: this.sessionManager,
|
|
94
|
+
});
|
|
95
|
+
await this.reactor.start();
|
|
96
|
+
// Wait until the reactor reaches a fully idle state. The reactor may chain
|
|
97
|
+
// multiple turns (e.g. follow-up queue draining), so we keep waiting until settled.
|
|
98
|
+
const settledPromise = this._waitUntilSettled();
|
|
99
|
+
// Append the user message — the reactor will pick it up
|
|
100
|
+
this.store.append({
|
|
101
|
+
actor_id: "user",
|
|
102
|
+
type: "USER_MESSAGE",
|
|
103
|
+
payload: { content: text, images },
|
|
104
|
+
});
|
|
105
|
+
await settledPromise;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
this._turnSubscription?.();
|
|
109
|
+
this._turnSubscription = undefined;
|
|
110
|
+
this.reactor?.stop();
|
|
111
|
+
this.reactor = null;
|
|
112
|
+
this._isProcessing = false;
|
|
113
|
+
this._resolveIdleWaiters();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if runtime is currently processing.
|
|
118
|
+
*/
|
|
119
|
+
get isRunning() {
|
|
120
|
+
return this._isProcessing;
|
|
121
|
+
}
|
|
122
|
+
get signal() {
|
|
123
|
+
return this.reactor?.signal;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Resolve when the current prompt cycle is fully settled.
|
|
127
|
+
*/
|
|
128
|
+
waitForIdle() {
|
|
129
|
+
if (!this._isProcessing)
|
|
130
|
+
return Promise.resolve();
|
|
131
|
+
return new Promise((resolve) => {
|
|
132
|
+
this._turnCompletionWaiters.push(resolve);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
_resolveIdleWaiters() {
|
|
136
|
+
const waiters = this._turnCompletionWaiters.splice(0);
|
|
137
|
+
for (const resolve of waiters)
|
|
138
|
+
resolve();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Interrupt current execution.
|
|
142
|
+
*
|
|
143
|
+
* Sets _abortedByUser on the reactor, which causes _onAgentTurnCompleted to discard
|
|
144
|
+
* queued follow-ups and let the reactor settle. The settled promise resolves naturally
|
|
145
|
+
* when the current turn finishes (via _waitUntilSettled).
|
|
146
|
+
*
|
|
147
|
+
* Edge case: if no turn is running (no AGENT_TURN_COMPLETED will fire), also resolve
|
|
148
|
+
* the settled promise immediately so the caller doesn't hang.
|
|
149
|
+
*/
|
|
150
|
+
abort() {
|
|
151
|
+
this.store.append({
|
|
152
|
+
actor_id: "user",
|
|
153
|
+
type: "USER_INTERRUPT",
|
|
154
|
+
payload: {},
|
|
155
|
+
});
|
|
156
|
+
this.reactor?.interrupt();
|
|
157
|
+
// The _waitUntilSettled subscription will resolve when AGENT_TURN_COMPLETED fires.
|
|
158
|
+
// But if no turn is running (or the turn fails before starting), we resolve immediately.
|
|
159
|
+
if (!this._isProcessing && this._resolveSettled) {
|
|
160
|
+
this._resolveSettled();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Inject a steer message — interrupts the current turn and delivers the message
|
|
165
|
+
* as a follow-up after the current turn settles.
|
|
166
|
+
*/
|
|
167
|
+
steer(text, images) {
|
|
168
|
+
if (!this._isProcessing) {
|
|
169
|
+
this.store.append({
|
|
170
|
+
actor_id: "user",
|
|
171
|
+
type: "USER_MESSAGE",
|
|
172
|
+
payload: { content: text, images },
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
this.store.append({
|
|
177
|
+
actor_id: "user",
|
|
178
|
+
type: "USER_INTERRUPT",
|
|
179
|
+
payload: { content: text, images, reason: "steer" },
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Queue a follow-up message — delivered after the current turn naturally completes.
|
|
184
|
+
* If the runtime is not processing, queues it for the next prompt.
|
|
185
|
+
*/
|
|
186
|
+
followUp(text, images) {
|
|
187
|
+
this.store.append({
|
|
188
|
+
actor_id: "user",
|
|
189
|
+
type: "USER_FOLLOWUP_QUEUED",
|
|
190
|
+
payload: { content: text, images },
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Request context compaction. The active reactor handles this immediately when
|
|
195
|
+
* running; otherwise the request is recorded for the event stream.
|
|
196
|
+
*/
|
|
197
|
+
compact(options) {
|
|
198
|
+
this.store.append({
|
|
199
|
+
actor_id: "user",
|
|
200
|
+
type: "COMPACTION_REQUESTED",
|
|
201
|
+
payload: {
|
|
202
|
+
reason: options?.reason ?? "manual",
|
|
203
|
+
token_count: options?.token_count ?? 0,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
setModel(provider, modelId) {
|
|
208
|
+
const previous_provider = this.config.model.provider;
|
|
209
|
+
const previous_model_id = this.config.model.model_id;
|
|
210
|
+
this.config.model.provider = provider;
|
|
211
|
+
this.config.model.model_id = modelId;
|
|
212
|
+
this.store.append({
|
|
213
|
+
actor_id: "user",
|
|
214
|
+
type: "MODEL_CHANGED",
|
|
215
|
+
payload: {
|
|
216
|
+
provider,
|
|
217
|
+
model_id: modelId,
|
|
218
|
+
previous_provider,
|
|
219
|
+
previous_model_id,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
getModel() {
|
|
224
|
+
return { ...this.config.model };
|
|
225
|
+
}
|
|
226
|
+
setThinkingLevel(level) {
|
|
227
|
+
const previous_level = this.config.model.thinking_level;
|
|
228
|
+
this.config.model.thinking_level = level;
|
|
229
|
+
this.store.append({
|
|
230
|
+
actor_id: "user",
|
|
231
|
+
type: "THINKING_LEVEL_CHANGED",
|
|
232
|
+
payload: { level, previous_level },
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getThinkingLevel() {
|
|
236
|
+
return this.config.model.thinking_level;
|
|
237
|
+
}
|
|
238
|
+
getProjection() {
|
|
239
|
+
return this.sessionManager?.getActiveSession() ?? this._createDefaultProjection();
|
|
240
|
+
}
|
|
241
|
+
getTools() {
|
|
242
|
+
return [...this.config.tools];
|
|
243
|
+
}
|
|
244
|
+
setTools(tools) {
|
|
245
|
+
this.config.tools.splice(0, this.config.tools.length, ...tools);
|
|
246
|
+
this.store.append({
|
|
247
|
+
actor_id: "user",
|
|
248
|
+
type: "USER_CONFIG_CHANGE",
|
|
249
|
+
payload: { key: "tools", old_value: undefined, new_value: tools.map((tool) => tool.name) },
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
getSystemPrompt() {
|
|
253
|
+
return this.config.systemPrompt;
|
|
254
|
+
}
|
|
255
|
+
setSystemPrompt(prompt) {
|
|
256
|
+
const old_value = this.config.systemPrompt;
|
|
257
|
+
this.config.systemPrompt = prompt;
|
|
258
|
+
this.store.append({
|
|
259
|
+
actor_id: "user",
|
|
260
|
+
type: "USER_CONFIG_CHANGE",
|
|
261
|
+
payload: { key: "systemPrompt", old_value, new_value: prompt },
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
_createDefaultProjection() {
|
|
265
|
+
const desc = {
|
|
266
|
+
session_id: "default",
|
|
267
|
+
thread_id: "default",
|
|
268
|
+
workspace_id: this.store.workspace_id,
|
|
269
|
+
event_range: { start_event_id: "ORIGIN", end_event_id: "HEAD" },
|
|
270
|
+
created_by: "user_explicit",
|
|
271
|
+
created_at: Date.now(),
|
|
272
|
+
};
|
|
273
|
+
return new SessionProjection(this.store, desc);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Wait until the reactor has settled — i.e. an AGENT_TURN_COMPLETED fires AND
|
|
277
|
+
* no further USER_MESSAGE has been appended in the same tick (e.g. by follow-up draining).
|
|
278
|
+
*/
|
|
279
|
+
_waitUntilSettled() {
|
|
280
|
+
return new Promise((resolve) => {
|
|
281
|
+
this._resolveSettled = resolve;
|
|
282
|
+
let pendingCheck = false;
|
|
283
|
+
const unsub = this.store.subscribe(() => {
|
|
284
|
+
if (pendingCheck)
|
|
285
|
+
return;
|
|
286
|
+
pendingCheck = true;
|
|
287
|
+
queueMicrotask(() => {
|
|
288
|
+
pendingCheck = false;
|
|
289
|
+
const followUpsRemaining = this.reactor?.pendingFollowUpCount ?? 0;
|
|
290
|
+
if (followUpsRemaining > 0)
|
|
291
|
+
return;
|
|
292
|
+
const retriesRemaining = this.reactor?.pendingRetryCount ?? 0;
|
|
293
|
+
if (retriesRemaining > 0)
|
|
294
|
+
return;
|
|
295
|
+
const lastMsg = this.store.query({ types: ["USER_MESSAGE"], reverse: true, limit: 1 })[0];
|
|
296
|
+
const lastCompleted = this.store.query({
|
|
297
|
+
types: ["AGENT_TURN_COMPLETED"],
|
|
298
|
+
reverse: true,
|
|
299
|
+
limit: 1,
|
|
300
|
+
})[0];
|
|
301
|
+
if (lastMsg && lastCompleted && lastMsg.sequence > lastCompleted.sequence)
|
|
302
|
+
return;
|
|
303
|
+
unsub();
|
|
304
|
+
resolve();
|
|
305
|
+
});
|
|
306
|
+
}, { types: ["AGENT_TURN_COMPLETED"] });
|
|
307
|
+
this._turnSubscription = unsub;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Approve a pending intent.
|
|
312
|
+
*/
|
|
313
|
+
approve(intentEventId) {
|
|
314
|
+
this.store.append({
|
|
315
|
+
actor_id: "user",
|
|
316
|
+
type: "USER_APPROVAL",
|
|
317
|
+
payload: { intent_event_id: intentEventId },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Reject a pending intent.
|
|
322
|
+
*/
|
|
323
|
+
reject(intentEventId) {
|
|
324
|
+
this.store.append({
|
|
325
|
+
actor_id: "user",
|
|
326
|
+
type: "USER_REJECTION",
|
|
327
|
+
payload: { intent_event_id: intentEventId },
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Subscribe to real-time events (for UI).
|
|
332
|
+
*/
|
|
333
|
+
subscribe(handler, options) {
|
|
334
|
+
return this.store.subscribe(handler, options);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Query the activity timeline (for UI rendering).
|
|
338
|
+
*/
|
|
339
|
+
getTimeline(options) {
|
|
340
|
+
const projection = new TimelineProjection(this.store);
|
|
341
|
+
return projection.query(options);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Fork session at a specific event.
|
|
345
|
+
*/
|
|
346
|
+
fork(eventId) {
|
|
347
|
+
return this.sessionManager?.forkAt(eventId);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Switch to a different session.
|
|
351
|
+
*/
|
|
352
|
+
switchSession(sessionId) {
|
|
353
|
+
this.sessionManager?.switchTo(sessionId);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Create a new session.
|
|
357
|
+
*/
|
|
358
|
+
createSession(name) {
|
|
359
|
+
return this.sessionManager?.createSession("user_explicit", name);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Get current session descriptor.
|
|
363
|
+
*/
|
|
364
|
+
getCurrentSession() {
|
|
365
|
+
const sessionId = this.sessionManager?.getActiveSessionId();
|
|
366
|
+
return sessionId ? this.sessionManager?.getSession(sessionId) : undefined;
|
|
367
|
+
}
|
|
368
|
+
async createCheckpoint(label) {
|
|
369
|
+
const checkpoint = await this.runtimeAdapter.createCheckpoint({
|
|
370
|
+
cwd: this.config.cwd,
|
|
371
|
+
event_head: this.store.head,
|
|
372
|
+
event_head_sequence: this.store.head_sequence,
|
|
373
|
+
label,
|
|
374
|
+
});
|
|
375
|
+
this.store.append({
|
|
376
|
+
actor_id: "runtime",
|
|
377
|
+
type: "CHECKPOINT_CREATED",
|
|
378
|
+
payload: checkpoint,
|
|
379
|
+
caused_by: this.store.head,
|
|
380
|
+
});
|
|
381
|
+
return checkpoint;
|
|
382
|
+
}
|
|
383
|
+
async restoreCheckpoint(checkpoint) {
|
|
384
|
+
try {
|
|
385
|
+
await this.runtimeAdapter.restoreCheckpoint(checkpoint);
|
|
386
|
+
this.store.append({
|
|
387
|
+
actor_id: "runtime",
|
|
388
|
+
type: "CHECKPOINT_RESTORED",
|
|
389
|
+
payload: checkpoint,
|
|
390
|
+
caused_by: checkpoint.event_head,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
this.store.append({
|
|
395
|
+
actor_id: "runtime",
|
|
396
|
+
type: "CHECKPOINT_FAILED",
|
|
397
|
+
payload: {
|
|
398
|
+
checkpoint,
|
|
399
|
+
error_message: error instanceof Error ? error.message : String(error),
|
|
400
|
+
},
|
|
401
|
+
caused_by: checkpoint.event_head,
|
|
402
|
+
});
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
async getRuntimeStatus() {
|
|
407
|
+
return this.runtimeAdapter.getStatus();
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Dispose the runtime.
|
|
411
|
+
*/
|
|
412
|
+
dispose() {
|
|
413
|
+
this.sessionManager?.dispose();
|
|
414
|
+
if (this.ownsStore) {
|
|
415
|
+
this.store.close?.();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
// ============================================================================
|
|
420
|
+
// Factory
|
|
421
|
+
// ============================================================================
|
|
422
|
+
/**
|
|
423
|
+
* Create an EventSourcedRuntime from existing components.
|
|
424
|
+
*/
|
|
425
|
+
/**
|
|
426
|
+
* Create an EventSourcedRuntime from existing components.
|
|
427
|
+
*
|
|
428
|
+
* Note: This factory bypasses the constructor to allow injection of
|
|
429
|
+
* pre-configured EventStore and SessionManager instances.
|
|
430
|
+
*/
|
|
431
|
+
export function createEventSourcedRuntime(store, sessionManager, config) {
|
|
432
|
+
return new EventSourcedRuntime({
|
|
433
|
+
cwd: store.workspace_id, // workspace_id is used as cwd proxy
|
|
434
|
+
store,
|
|
435
|
+
sessionManager,
|
|
436
|
+
toolRegistry: config.toolRegistry,
|
|
437
|
+
classifierConfig: config.classifierConfig,
|
|
438
|
+
runtimeAdapter: config.runtimeAdapter,
|
|
439
|
+
approvalHandler: config.approvalHandler,
|
|
440
|
+
llmClient: config.llmClient,
|
|
441
|
+
systemPrompt: config.systemPrompt,
|
|
442
|
+
model: config.model,
|
|
443
|
+
tools: config.tools,
|
|
444
|
+
contextBudget: config.contextBudget,
|
|
445
|
+
retryPolicy: config.retryPolicy,
|
|
446
|
+
compactionPolicy: config.compactionPolicy,
|
|
447
|
+
compactionEngineSettings: config.compactionEngineSettings,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { EventBase } from "../event-store/types.js";
|
|
2
|
+
import type { ToolExecutionResult, ToolExecutionUpdate } from "../intent/types.js";
|
|
3
|
+
export type RuntimeKind = "local" | "cloud" | "container";
|
|
4
|
+
export interface ToolExecutionRequest {
|
|
5
|
+
tool_call_id: string;
|
|
6
|
+
tool_name: string;
|
|
7
|
+
arguments: Record<string, unknown>;
|
|
8
|
+
caused_by?: string;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
onUpdate?: (partial: ToolExecutionUpdate) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface CheckpointRequest {
|
|
13
|
+
cwd: string;
|
|
14
|
+
event_head?: string;
|
|
15
|
+
event_head_sequence?: number;
|
|
16
|
+
label?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CheckpointRef {
|
|
19
|
+
checkpoint_id: string;
|
|
20
|
+
path: string;
|
|
21
|
+
created_at: number;
|
|
22
|
+
event_head?: string;
|
|
23
|
+
event_head_sequence?: number;
|
|
24
|
+
label?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RuntimeStatus {
|
|
27
|
+
runtime_id: string;
|
|
28
|
+
workspace_id: string;
|
|
29
|
+
kind: RuntimeKind;
|
|
30
|
+
cwd: string;
|
|
31
|
+
status: "idle" | "running" | "paused" | "error";
|
|
32
|
+
}
|
|
33
|
+
export interface RuntimeAdapter {
|
|
34
|
+
readonly runtime_id: string;
|
|
35
|
+
readonly workspace_id: string;
|
|
36
|
+
readonly kind: RuntimeKind;
|
|
37
|
+
executeTool(request: ToolExecutionRequest): Promise<ToolExecutionResult>;
|
|
38
|
+
createCheckpoint(request: CheckpointRequest): Promise<CheckpointRef>;
|
|
39
|
+
restoreCheckpoint(ref: CheckpointRef): Promise<void>;
|
|
40
|
+
getStatus(): Promise<RuntimeStatus>;
|
|
41
|
+
subscribeEvents?(after?: string): AsyncIterable<EventBase>;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public SDK entry point.
|
|
3
|
+
*
|
|
4
|
+
* Exposes `createSessionFacade()` as the primary session creation API,
|
|
5
|
+
* plus tool factories and type exports for extension development.
|
|
6
|
+
*/
|
|
7
|
+
export { createSessionFacade, type CreateSessionFacadeOptions, type CreateSessionFacadeResult, } from "./session-facade-factory.js";
|
|
8
|
+
export type { ExtensionAPI, ExtensionCommandContext, ExtensionContext, ExtensionFactory, SlashCommandInfo, SlashCommandSource, ToolDefinition, } from "./extensions/index.js";
|
|
9
|
+
export type { PromptTemplate } from "./prompt-templates.js";
|
|
10
|
+
export type { Skill } from "./skills.js";
|
|
11
|
+
export type { Tool } from "./tools/index.js";
|
|
12
|
+
export { withFileMutationQueue, createCodingTools, createReadOnlyTools, createReadTool, createBashTool, createEditTool, createWriteTool, createGrepTool, createFindTool, createLsTool, } from "./tools/index.js";
|