@openadapter/koda 1.0.0-beta.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/CHANGELOG.md +4448 -0
- package/README.md +665 -0
- package/dist/bun/cli.d.ts +2 -0
- package/dist/bun/cli.js +2 -0
- package/dist/bun/register-bedrock.d.ts +1 -0
- package/dist/bun/register-bedrock.js +1 -0
- package/dist/bun/restore-sandbox-env.d.ts +12 -0
- package/dist/bun/restore-sandbox-env.js +1 -0
- package/dist/cli/args.d.ts +55 -0
- package/dist/cli/args.js +167 -0
- package/dist/cli/config-selector.d.ts +13 -0
- package/dist/cli/config-selector.js +1 -0
- package/dist/cli/file-processor.d.ts +14 -0
- package/dist/cli/file-processor.js +7 -0
- package/dist/cli/import-sessions.d.ts +34 -0
- package/dist/cli/import-sessions.js +6 -0
- package/dist/cli/initial-message.d.ts +17 -0
- package/dist/cli/initial-message.js +1 -0
- package/dist/cli/list-models.d.ts +8 -0
- package/dist/cli/list-models.js +2 -0
- package/dist/cli/openadapter-setup.d.ts +29 -0
- package/dist/cli/openadapter-setup.js +3 -0
- package/dist/cli/session-picker.d.ts +8 -0
- package/dist/cli/session-picker.js +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2 -0
- package/dist/config.d.ts +92 -0
- package/dist/config.js +1 -0
- package/dist/core/agent-session-runtime.d.ts +116 -0
- package/dist/core/agent-session-runtime.js +1 -0
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session.d.ts +747 -0
- package/dist/core/agent-session.js +32 -0
- package/dist/core/auth-guidance.d.ts +4 -0
- package/dist/core/auth-guidance.js +8 -0
- package/dist/core/auth-storage.d.ts +140 -0
- package/dist/core/auth-storage.js +1 -0
- package/dist/core/bash-executor.d.ts +31 -0
- package/dist/core/bash-executor.js +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +89 -0
- package/dist/core/compaction/branch-summarization.js +38 -0
- package/dist/core/compaction/compaction.d.ts +120 -0
- package/dist/core/compaction/compaction.js +104 -0
- package/dist/core/compaction/index.d.ts +6 -0
- package/dist/core/compaction/index.js +1 -0
- package/dist/core/compaction/utils.d.ts +37 -0
- package/dist/core/compaction/utils.js +19 -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 +0 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/event-bus.js +1 -0
- package/dist/core/exec.d.ts +28 -0
- package/dist/core/exec.js +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +21 -0
- package/dist/core/export-html/ansi-to-html.js +1 -0
- package/dist/core/export-html/index.d.ts +36 -0
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +72 -0
- package/dist/core/export-html/tool-renderer.d.ts +33 -0
- package/dist/core/export-html/tool-renderer.js +1 -0
- package/dist/core/export-html/vendor/highlight.min.js +8 -0
- package/dist/core/export-html/vendor/marked.min.js +56 -0
- package/dist/core/extensions/index.d.ts +11 -0
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/loader.d.ts +23 -0
- package/dist/core/extensions/loader.js +1 -0
- package/dist/core/extensions/runner.d.ts +160 -0
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/types.d.ts +1180 -0
- package/dist/core/extensions/types.js +1 -0
- package/dist/core/extensions/wrapper.d.ts +19 -0
- package/dist/core/extensions/wrapper.js +1 -0
- package/dist/core/footer-data-provider.d.ts +53 -0
- package/dist/core/footer-data-provider.js +1 -0
- package/dist/core/http-dispatcher.d.ts +20 -0
- package/dist/core/http-dispatcher.js +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.js +1 -0
- package/dist/core/keybindings.d.ts +352 -0
- package/dist/core/keybindings.js +1 -0
- package/dist/core/messages.d.ts +76 -0
- package/dist/core/messages.js +17 -0
- package/dist/core/model-registry.d.ts +149 -0
- package/dist/core/model-registry.js +9 -0
- package/dist/core/model-resolver.d.ts +109 -0
- package/dist/core/model-resolver.js +1 -0
- package/dist/core/output-guard.d.ts +6 -0
- package/dist/core/output-guard.js +1 -0
- package/dist/core/package-manager.d.ts +203 -0
- package/dist/core/package-manager.js +3 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.js +2 -0
- package/dist/core/provider-attribution.d.ts +3 -0
- package/dist/core/provider-attribution.js +1 -0
- package/dist/core/provider-display-names.d.ts +1 -0
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/resolve-config-value.d.ts +30 -0
- package/dist/core/resolve-config-value.js +1 -0
- package/dist/core/resource-loader.d.ts +193 -0
- package/dist/core/resource-loader.js +1 -0
- package/dist/core/sdk.d.ts +108 -0
- package/dist/core/sdk.js +1 -0
- package/dist/core/session-cwd.d.ts +18 -0
- package/dist/core/session-cwd.js +7 -0
- package/dist/core/session-manager.d.ts +331 -0
- package/dist/core/session-manager.js +11 -0
- package/dist/core/settings-manager.d.ts +265 -0
- package/dist/core/settings-manager.js +1 -0
- package/dist/core/skills.d.ts +59 -0
- package/dist/core/skills.js +4 -0
- package/dist/core/slash-commands.d.ts +13 -0
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/source-info.js +1 -0
- package/dist/core/system-prompt.d.ts +27 -0
- package/dist/core/system-prompt.js +52 -0
- package/dist/core/telemetry.d.ts +2 -0
- package/dist/core/telemetry.js +1 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.js +3 -0
- package/dist/core/tools/bash.d.ts +67 -0
- package/dist/core/tools/bash.js +18 -0
- package/dist/core/tools/edit-diff.d.ts +86 -0
- package/dist/core/tools/edit-diff.js +16 -0
- package/dist/core/tools/edit.d.ts +50 -0
- package/dist/core/tools/edit.js +2 -0
- package/dist/core/tools/file-mutation-queue.d.ts +5 -0
- package/dist/core/tools/file-mutation-queue.js +1 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +13 -0
- package/dist/core/tools/grep.d.ts +36 -0
- package/dist/core/tools/grep.js +13 -0
- package/dist/core/tools/index.d.ts +39 -0
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/ls.d.ts +36 -0
- package/dist/core/tools/ls.js +9 -0
- package/dist/core/tools/output-accumulator.d.ts +51 -0
- package/dist/core/tools/output-accumulator.js +4 -0
- package/dist/core/tools/path-utils.d.ts +9 -0
- package/dist/core/tools/path-utils.js +1 -0
- package/dist/core/tools/read.d.ts +34 -0
- package/dist/core/tools/read.js +22 -0
- package/dist/core/tools/render-utils.d.ts +23 -0
- package/dist/core/tools/render-utils.js +4 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
- package/dist/core/tools/tool-definition-wrapper.js +1 -0
- package/dist/core/tools/truncate.d.ts +69 -0
- package/dist/core/tools/truncate.js +5 -0
- package/dist/core/tools/write.d.ts +25 -0
- package/dist/core/tools/write.js +13 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +1 -0
- package/dist/main.d.ts +11 -0
- package/dist/main.js +1 -0
- package/dist/migrations.d.ts +32 -0
- package/dist/migrations.js +8 -0
- package/dist/modes/index.d.ts +8 -0
- package/dist/modes/index.js +1 -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 +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
- package/dist/modes/interactive/components/assistant-message.js +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
- package/dist/modes/interactive/components/bash-execution.js +13 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.js +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/branch-summary-message.js +3 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +3 -0
- package/dist/modes/interactive/components/config-selector.d.ts +70 -0
- package/dist/modes/interactive/components/config-selector.js +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
- package/dist/modes/interactive/components/countdown-timer.js +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +20 -0
- package/dist/modes/interactive/components/custom-editor.js +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +19 -0
- package/dist/modes/interactive/components/custom-message.js +2 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
- package/dist/modes/interactive/components/daxnuts.js +1 -0
- package/dist/modes/interactive/components/diff.d.ts +11 -0
- package/dist/modes/interactive/components/diff.js +3 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
- package/dist/modes/interactive/components/dynamic-border.js +1 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
- package/dist/modes/interactive/components/earendil-announcement.js +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-editor.js +3 -0
- package/dist/modes/interactive/components/extension-input.d.ts +22 -0
- package/dist/modes/interactive/components/extension-input.js +2 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +25 -0
- package/dist/modes/interactive/components/extension-selector.js +2 -0
- package/dist/modes/interactive/components/footer.d.ts +27 -0
- package/dist/modes/interactive/components/footer.js +1 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +12 -0
- package/dist/modes/interactive/components/keybinding-hints.js +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +51 -0
- package/dist/modes/interactive/components/login-dialog.js +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +46 -0
- package/dist/modes/interactive/components/model-selector.js +2 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +30 -0
- package/dist/modes/interactive/components/oauth-selector.js +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +41 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
- package/dist/modes/interactive/components/session-selector-search.js +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.js +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +68 -0
- package/dist/modes/interactive/components/settings-selector.js +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
- package/dist/modes/interactive/components/show-images-selector.js +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +3 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
- package/dist/modes/interactive/components/theme-selector.js +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
- package/dist/modes/interactive/components/thinking-selector.js +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +62 -0
- package/dist/modes/interactive/components/tool-execution.js +4 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
- package/dist/modes/interactive/components/tree-selector.js +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
- package/dist/modes/interactive/components/user-message-selector.js +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.js +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
- package/dist/modes/interactive/components/visual-truncate.js +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +417 -0
- package/dist/modes/interactive/interactive-mode.js +116 -0
- package/dist/modes/interactive/theme/dark.json +86 -0
- package/dist/modes/interactive/theme/light.json +85 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +101 -0
- package/dist/modes/interactive/theme/theme.js +18 -0
- package/dist/modes/print-mode.d.ts +27 -0
- package/dist/modes/print-mode.js +4 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +3 -0
- package/dist/modes/rpc/rpc-client.d.ts +226 -0
- package/dist/modes/rpc/rpc-client.js +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +19 -0
- package/dist/modes/rpc/rpc-mode.js +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +419 -0
- package/dist/modes/rpc/rpc-types.js +0 -0
- package/dist/package-manager-cli.d.ts +3 -0
- package/dist/package-manager-cli.js +49 -0
- package/dist/utils/ansi.d.ts +1 -0
- package/dist/utils/ansi.js +1 -0
- package/dist/utils/auto-update.d.ts +13 -0
- package/dist/utils/auto-update.js +1 -0
- package/dist/utils/changelog.d.ts +20 -0
- package/dist/utils/changelog.js +4 -0
- package/dist/utils/child-process.d.ts +14 -0
- package/dist/utils/child-process.js +1 -0
- package/dist/utils/clipboard-image.d.ts +10 -0
- package/dist/utils/clipboard-image.js +1 -0
- package/dist/utils/clipboard-native.d.ts +9 -0
- package/dist/utils/clipboard-native.js +1 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +1 -0
- package/dist/utils/deprecation.d.ts +3 -0
- package/dist/utils/deprecation.js +1 -0
- package/dist/utils/exif-orientation.d.ts +4 -0
- package/dist/utils/exif-orientation.js +1 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/frontmatter.js +4 -0
- package/dist/utils/fs-watch.d.ts +4 -0
- package/dist/utils/fs-watch.js +1 -0
- package/dist/utils/git.d.ts +25 -0
- package/dist/utils/git.js +1 -0
- package/dist/utils/html.d.ts +6 -0
- package/dist/utils/html.js +1 -0
- package/dist/utils/image-convert.d.ts +8 -0
- package/dist/utils/image-convert.js +1 -0
- package/dist/utils/image-resize-core.d.ts +29 -0
- package/dist/utils/image-resize-core.js +1 -0
- package/dist/utils/image-resize-worker.d.ts +1 -0
- package/dist/utils/image-resize-worker.js +1 -0
- package/dist/utils/image-resize.d.ts +15 -0
- package/dist/utils/image-resize.js +1 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.js +1 -0
- package/dist/utils/koda-user-agent.d.ts +1 -0
- package/dist/utils/koda-user-agent.js +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.js +1 -0
- package/dist/utils/paths.d.ts +30 -0
- package/dist/utils/paths.js +1 -0
- package/dist/utils/photon.d.ts +20 -0
- package/dist/utils/photon.js +1 -0
- package/dist/utils/shell.d.ts +29 -0
- package/dist/utils/shell.js +8 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/sleep.js +1 -0
- package/dist/utils/syntax-highlight.d.ts +11 -0
- package/dist/utils/syntax-highlight.js +2 -0
- package/dist/utils/tools-manager.d.ts +2 -0
- package/dist/utils/tools-manager.js +1 -0
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.js +1 -0
- package/dist/utils/windows-self-update.d.ts +2 -0
- package/dist/utils/windows-self-update.js +1 -0
- package/docs/compaction.md +394 -0
- package/docs/custom-provider.md +736 -0
- package/docs/development.md +71 -0
- package/docs/docs.json +148 -0
- package/docs/extensions.md +2626 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +80 -0
- package/docs/json.md +82 -0
- package/docs/keybindings.md +197 -0
- package/docs/models.md +493 -0
- package/docs/packages.md +226 -0
- package/docs/prompt-templates.md +88 -0
- package/docs/providers.md +253 -0
- package/docs/quickstart.md +165 -0
- package/docs/rpc.md +1408 -0
- package/docs/sdk.md +1137 -0
- package/docs/session-format.md +412 -0
- package/docs/sessions.md +145 -0
- package/docs/settings.md +281 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +231 -0
- package/docs/terminal-setup.md +114 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tmux.md +61 -0
- package/docs/tui.md +927 -0
- package/docs/usage.md +288 -0
- package/docs/windows.md +17 -0
- package/npm-shrinkwrap.json +1792 -0
- package/openadapter/extensions/koda-ask.js +12 -0
- package/openadapter/extensions/koda-bg.js +14 -0
- package/openadapter/extensions/koda-commands.mjs +15 -0
- package/openadapter/extensions/koda-help.js +8 -0
- package/openadapter/extensions/koda-memory.js +16 -0
- package/openadapter/extensions/koda-status.js +1 -0
- package/openadapter/extensions/koda-todo.js +4 -0
- package/openadapter/extensions/koda-vision.js +4 -0
- package/openadapter/extensions/koda-web.js +7 -0
- package/openadapter/setup.mjs +173 -0
- package/openadapter/skills/code-review/SKILL.md +22 -0
- package/openadapter/skills/debugging/SKILL.md +28 -0
- package/openadapter/skills/frontend/SKILL.md +38 -0
- package/package.json +108 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC Client for programmatic access to the coding agent.
|
|
3
|
+
*
|
|
4
|
+
* Spawns the agent in RPC mode and provides a typed API for all operations.
|
|
5
|
+
*/
|
|
6
|
+
import type { AgentEvent, AgentMessage, ThinkingLevel } from "@openadapter/koda-agent-core";
|
|
7
|
+
import type { ImageContent } from "@openadapter/koda-ai";
|
|
8
|
+
import type { SessionStats } from "../../core/agent-session.ts";
|
|
9
|
+
import type { BashResult } from "../../core/bash-executor.ts";
|
|
10
|
+
import type { CompactionResult } from "../../core/compaction/index.ts";
|
|
11
|
+
import type { RpcSessionState, RpcSlashCommand } from "./rpc-types.ts";
|
|
12
|
+
export interface RpcClientOptions {
|
|
13
|
+
/** Path to the CLI entry point (default: searches for dist/cli.js) */
|
|
14
|
+
cliPath?: string;
|
|
15
|
+
/** Working directory for the agent */
|
|
16
|
+
cwd?: string;
|
|
17
|
+
/** Environment variables */
|
|
18
|
+
env?: Record<string, string>;
|
|
19
|
+
/** Provider to use */
|
|
20
|
+
provider?: string;
|
|
21
|
+
/** Model ID to use */
|
|
22
|
+
model?: string;
|
|
23
|
+
/** Additional CLI arguments */
|
|
24
|
+
args?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface ModelInfo {
|
|
27
|
+
provider: string;
|
|
28
|
+
id: string;
|
|
29
|
+
contextWindow: number;
|
|
30
|
+
reasoning: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type RpcEventListener = (event: AgentEvent) => void;
|
|
33
|
+
export declare class RpcClient {
|
|
34
|
+
private process;
|
|
35
|
+
private stopReadingStdout;
|
|
36
|
+
private eventListeners;
|
|
37
|
+
private pendingRequests;
|
|
38
|
+
private requestId;
|
|
39
|
+
private stderr;
|
|
40
|
+
private exitError;
|
|
41
|
+
private options;
|
|
42
|
+
constructor(options?: RpcClientOptions);
|
|
43
|
+
/**
|
|
44
|
+
* Start the RPC agent process.
|
|
45
|
+
*/
|
|
46
|
+
start(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Stop the RPC agent process.
|
|
49
|
+
*/
|
|
50
|
+
stop(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to agent events.
|
|
53
|
+
*/
|
|
54
|
+
onEvent(listener: RpcEventListener): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Get collected stderr output (useful for debugging).
|
|
57
|
+
*/
|
|
58
|
+
getStderr(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Send a prompt to the agent.
|
|
61
|
+
* Returns immediately after sending; use onEvent() to receive streaming events.
|
|
62
|
+
* Use waitForIdle() to wait for completion.
|
|
63
|
+
*/
|
|
64
|
+
prompt(message: string, images?: ImageContent[]): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Queue a steering message to interrupt the agent mid-run.
|
|
67
|
+
*/
|
|
68
|
+
steer(message: string, images?: ImageContent[]): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Queue a follow-up message to be processed after the agent finishes.
|
|
71
|
+
*/
|
|
72
|
+
followUp(message: string, images?: ImageContent[]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Abort current operation.
|
|
75
|
+
*/
|
|
76
|
+
abort(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Start a new session, optionally with parent tracking.
|
|
79
|
+
* @param parentSession - Optional parent session path for lineage tracking
|
|
80
|
+
* @returns Object with `cancelled: true` if an extension cancelled the new session
|
|
81
|
+
*/
|
|
82
|
+
newSession(parentSession?: string): Promise<{
|
|
83
|
+
cancelled: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Get current session state.
|
|
87
|
+
*/
|
|
88
|
+
getState(): Promise<RpcSessionState>;
|
|
89
|
+
/**
|
|
90
|
+
* Set model by provider and ID.
|
|
91
|
+
*/
|
|
92
|
+
setModel(provider: string, modelId: string): Promise<{
|
|
93
|
+
provider: string;
|
|
94
|
+
id: string;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Cycle to next model.
|
|
98
|
+
*/
|
|
99
|
+
cycleModel(): Promise<{
|
|
100
|
+
model: {
|
|
101
|
+
provider: string;
|
|
102
|
+
id: string;
|
|
103
|
+
};
|
|
104
|
+
thinkingLevel: ThinkingLevel;
|
|
105
|
+
isScoped: boolean;
|
|
106
|
+
} | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Get list of available models.
|
|
109
|
+
*/
|
|
110
|
+
getAvailableModels(): Promise<ModelInfo[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Set thinking level.
|
|
113
|
+
*/
|
|
114
|
+
setThinkingLevel(level: ThinkingLevel): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Cycle thinking level.
|
|
117
|
+
*/
|
|
118
|
+
cycleThinkingLevel(): Promise<{
|
|
119
|
+
level: ThinkingLevel;
|
|
120
|
+
} | null>;
|
|
121
|
+
/**
|
|
122
|
+
* Set steering mode.
|
|
123
|
+
*/
|
|
124
|
+
setSteeringMode(mode: "all" | "one-at-a-time"): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Set follow-up mode.
|
|
127
|
+
*/
|
|
128
|
+
setFollowUpMode(mode: "all" | "one-at-a-time"): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Compact session context.
|
|
131
|
+
*/
|
|
132
|
+
compact(customInstructions?: string): Promise<CompactionResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Set auto-compaction enabled/disabled.
|
|
135
|
+
*/
|
|
136
|
+
setAutoCompaction(enabled: boolean): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Set auto-retry enabled/disabled.
|
|
139
|
+
*/
|
|
140
|
+
setAutoRetry(enabled: boolean): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Abort in-progress retry.
|
|
143
|
+
*/
|
|
144
|
+
abortRetry(): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Execute a bash command.
|
|
147
|
+
*/
|
|
148
|
+
bash(command: string): Promise<BashResult>;
|
|
149
|
+
/**
|
|
150
|
+
* Abort running bash command.
|
|
151
|
+
*/
|
|
152
|
+
abortBash(): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Get session statistics.
|
|
155
|
+
*/
|
|
156
|
+
getSessionStats(): Promise<SessionStats>;
|
|
157
|
+
/**
|
|
158
|
+
* Export session to HTML.
|
|
159
|
+
*/
|
|
160
|
+
exportHtml(outputPath?: string): Promise<{
|
|
161
|
+
path: string;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Switch to a different session file.
|
|
165
|
+
* @returns Object with `cancelled: true` if an extension cancelled the switch
|
|
166
|
+
*/
|
|
167
|
+
switchSession(sessionPath: string): Promise<{
|
|
168
|
+
cancelled: boolean;
|
|
169
|
+
}>;
|
|
170
|
+
/**
|
|
171
|
+
* Fork from a specific message.
|
|
172
|
+
* @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)
|
|
173
|
+
*/
|
|
174
|
+
fork(entryId: string): Promise<{
|
|
175
|
+
text: string;
|
|
176
|
+
cancelled: boolean;
|
|
177
|
+
}>;
|
|
178
|
+
/**
|
|
179
|
+
* Clone the current active branch into a new session.
|
|
180
|
+
* @returns Object with `cancelled: true` if an extension cancelled the clone
|
|
181
|
+
*/
|
|
182
|
+
clone(): Promise<{
|
|
183
|
+
cancelled: boolean;
|
|
184
|
+
}>;
|
|
185
|
+
/**
|
|
186
|
+
* Get messages available for forking.
|
|
187
|
+
*/
|
|
188
|
+
getForkMessages(): Promise<Array<{
|
|
189
|
+
entryId: string;
|
|
190
|
+
text: string;
|
|
191
|
+
}>>;
|
|
192
|
+
/**
|
|
193
|
+
* Get text of last assistant message.
|
|
194
|
+
*/
|
|
195
|
+
getLastAssistantText(): Promise<string | null>;
|
|
196
|
+
/**
|
|
197
|
+
* Set the session display name.
|
|
198
|
+
*/
|
|
199
|
+
setSessionName(name: string): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Get all messages in the session.
|
|
202
|
+
*/
|
|
203
|
+
getMessages(): Promise<AgentMessage[]>;
|
|
204
|
+
/**
|
|
205
|
+
* Get available commands (extension commands, prompt templates, skills).
|
|
206
|
+
*/
|
|
207
|
+
getCommands(): Promise<RpcSlashCommand[]>;
|
|
208
|
+
/**
|
|
209
|
+
* Wait for agent to become idle (no streaming).
|
|
210
|
+
* Resolves when agent_end event is received.
|
|
211
|
+
*/
|
|
212
|
+
waitForIdle(timeout?: number): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Collect events until agent becomes idle.
|
|
215
|
+
*/
|
|
216
|
+
collectEvents(timeout?: number): Promise<AgentEvent[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Send prompt and wait for completion, returning all events.
|
|
219
|
+
*/
|
|
220
|
+
promptAndWait(message: string, images?: ImageContent[], timeout?: number): Promise<AgentEvent[]>;
|
|
221
|
+
private handleLine;
|
|
222
|
+
private createProcessExitError;
|
|
223
|
+
private rejectPendingRequests;
|
|
224
|
+
private send;
|
|
225
|
+
private getData;
|
|
226
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=Object.defineProperty;var c=(h,t)=>u(h,"name",{value:t,configurable:!0});import{spawn as g}from"node:child_process";import{attachJsonlLineReader as y,serializeJsonLine as w}from"./jsonl.js";class f{static{c(this,"RpcClient")}process=null;stopReadingStdout=null;eventListeners=[];pendingRequests=new Map;requestId=0;stderr="";exitError=null;options;constructor(t={}){this.options=t}async start(){if(this.process)throw new Error("Client already started");this.exitError=null;const t=this.options.cliPath??"dist/cli.js",e=["--mode","rpc"];this.options.provider&&e.push("--provider",this.options.provider),this.options.model&&e.push("--model",this.options.model),this.options.args&&e.push(...this.options.args);const s=g("node",[t,...e],{cwd:this.options.cwd,env:{...process.env,...this.options.env},stdio:["pipe","pipe","pipe"]});if(this.process=s,s.stderr?.on("data",r=>{this.stderr+=r.toString(),process.stderr.write(r)}),s.once("exit",(r,n)=>{if(this.process!==s)return;const i=this.createProcessExitError(r,n);this.exitError=i,this.rejectPendingRequests(i)}),s.once("error",r=>{if(this.process!==s)return;const n=new Error(`Agent process error: ${r.message}. Stderr: ${this.stderr}`);this.exitError=n,this.rejectPendingRequests(n)}),s.stdin?.on("error",r=>{if(this.process!==s)return;const n=this.exitError??new Error(`Agent process stdin error: ${r.message}. Stderr: ${this.stderr}`);this.exitError=n,this.rejectPendingRequests(n)}),this.stopReadingStdout=y(s.stdout,r=>{this.handleLine(r)}),await new Promise(r=>setTimeout(r,100)),this.process.exitCode!==null){const r=this.exitError??this.createProcessExitError(this.process.exitCode,this.process.signalCode);throw this.exitError=r,r}}async stop(){this.process&&(this.stopReadingStdout?.(),this.stopReadingStdout=null,this.process.kill("SIGTERM"),await new Promise(t=>{const e=setTimeout(()=>{this.process?.kill("SIGKILL"),t()},1e3);this.process?.on("exit",()=>{clearTimeout(e),t()})}),this.process=null,this.pendingRequests.clear())}onEvent(t){return this.eventListeners.push(t),()=>{const e=this.eventListeners.indexOf(t);e!==-1&&this.eventListeners.splice(e,1)}}getStderr(){return this.stderr}async prompt(t,e){await this.send({type:"prompt",message:t,images:e})}async steer(t,e){await this.send({type:"steer",message:t,images:e})}async followUp(t,e){await this.send({type:"follow_up",message:t,images:e})}async abort(){await this.send({type:"abort"})}async newSession(t){const e=await this.send({type:"new_session",parentSession:t});return this.getData(e)}async getState(){const t=await this.send({type:"get_state"});return this.getData(t)}async setModel(t,e){const s=await this.send({type:"set_model",provider:t,modelId:e});return this.getData(s)}async cycleModel(){const t=await this.send({type:"cycle_model"});return this.getData(t)}async getAvailableModels(){const t=await this.send({type:"get_available_models"});return this.getData(t).models}async setThinkingLevel(t){await this.send({type:"set_thinking_level",level:t})}async cycleThinkingLevel(){const t=await this.send({type:"cycle_thinking_level"});return this.getData(t)}async setSteeringMode(t){await this.send({type:"set_steering_mode",mode:t})}async setFollowUpMode(t){await this.send({type:"set_follow_up_mode",mode:t})}async compact(t){const e=await this.send({type:"compact",customInstructions:t});return this.getData(e)}async setAutoCompaction(t){await this.send({type:"set_auto_compaction",enabled:t})}async setAutoRetry(t){await this.send({type:"set_auto_retry",enabled:t})}async abortRetry(){await this.send({type:"abort_retry"})}async bash(t){const e=await this.send({type:"bash",command:t});return this.getData(e)}async abortBash(){await this.send({type:"abort_bash"})}async getSessionStats(){const t=await this.send({type:"get_session_stats"});return this.getData(t)}async exportHtml(t){const e=await this.send({type:"export_html",outputPath:t});return this.getData(e)}async switchSession(t){const e=await this.send({type:"switch_session",sessionPath:t});return this.getData(e)}async fork(t){const e=await this.send({type:"fork",entryId:t});return this.getData(e)}async clone(){const t=await this.send({type:"clone"});return this.getData(t)}async getForkMessages(){const t=await this.send({type:"get_fork_messages"});return this.getData(t).messages}async getLastAssistantText(){const t=await this.send({type:"get_last_assistant_text"});return this.getData(t).text}async setSessionName(t){await this.send({type:"set_session_name",name:t})}async getMessages(){const t=await this.send({type:"get_messages"});return this.getData(t).messages}async getCommands(){const t=await this.send({type:"get_commands"});return this.getData(t).commands}waitForIdle(t=6e4){return new Promise((e,s)=>{const r=setTimeout(()=>{n(),s(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`))},t),n=this.onEvent(i=>{i.type==="agent_end"&&(clearTimeout(r),n(),e())})})}collectEvents(t=6e4){return new Promise((e,s)=>{const r=[],n=setTimeout(()=>{i(),s(new Error(`Timeout collecting events. Stderr: ${this.stderr}`))},t),i=this.onEvent(a=>{r.push(a),a.type==="agent_end"&&(clearTimeout(n),i(),e(r))})})}async promptAndWait(t,e,s=6e4){const r=this.collectEvents(s);return await this.prompt(t,e),r}handleLine(t){try{const e=JSON.parse(t);if(e.type==="response"&&e.id&&this.pendingRequests.has(e.id)){const s=this.pendingRequests.get(e.id);this.pendingRequests.delete(e.id),s.resolve(e);return}for(const s of this.eventListeners)s(e)}catch{}}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t){const e=this.process,s=e?.stdin;if(!e||!s)throw new Error("Client not started");if(this.exitError)throw this.exitError;if(e.exitCode!==null){const i=this.createProcessExitError(e.exitCode,e.signalCode);throw this.exitError=i,i}if(s.destroyed||!s.writable){const i=new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);throw this.exitError=i,i}const r=`req_${++this.requestId}`,n={...t,id:r};return new Promise((i,a)=>{const d=setTimeout(()=>{this.pendingRequests.delete(r),a(new Error(`Timeout waiting for response to ${t.type}. Stderr: ${this.stderr}`))},3e4);this.pendingRequests.set(r,{resolve:c(o=>{clearTimeout(d),i(o)},"resolve"),reject:c(o=>{clearTimeout(d),a(o)},"reject")});try{s.write(w(n))}catch(o){const p=o instanceof Error?o:new Error(String(o)),l=this.pendingRequests.get(r);this.pendingRequests.delete(r),l?.reject(p)}})}getData(t){if(!t.success){const s=t;throw new Error(s.error)}return t.data}}export{f as RpcClient};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC mode: Headless operation with JSON stdin/stdout protocol.
|
|
3
|
+
*
|
|
4
|
+
* Used for embedding the agent in other applications.
|
|
5
|
+
* Receives commands as JSON on stdin, outputs events and responses as JSON on stdout.
|
|
6
|
+
*
|
|
7
|
+
* Protocol:
|
|
8
|
+
* - Commands: JSON objects with `type` field, optional `id` for correlation
|
|
9
|
+
* - Responses: JSON objects with `type: "response"`, `command`, `success`, and optional `data`/`error`
|
|
10
|
+
* - Events: AgentSessionEvent objects streamed as they occur
|
|
11
|
+
* - Extension UI: Extension UI requests are emitted, client responds with extension_ui_response
|
|
12
|
+
*/
|
|
13
|
+
import type { AgentSessionRuntime } from "../../core/agent-session-runtime.ts";
|
|
14
|
+
export type { RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, RpcSessionState, } from "./rpc-types.ts";
|
|
15
|
+
/**
|
|
16
|
+
* Run in RPC mode.
|
|
17
|
+
* Listens for JSON commands on stdin, outputs events and responses on stdout.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runRpcMode(runtimeHost: AgentSessionRuntime): Promise<never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var A=Object.defineProperty;var r=(c,o)=>A(c,"name",{value:o,configurable:!0});import*as p from"node:crypto";import{flushRawStdout as q,takeOverStdout as D,waitForRawStdoutBackpressure as g,writeRawStdout as B}from"../../core/output-guard.js";import{killTrackedDetachedChildren as N}from"../../utils/shell.js";import{theme as W}from"../interactive/theme/theme.js";import{attachJsonlLineReader as $,serializeJsonLine as G}from"./jsonl.js";async function Q(c){D();let o=c.session,_,h;const a=r(e=>{B(G(e))},"output"),i=r((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=r((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),f=new Map;let v=!1,I=!1;const k=[];function w(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const l=p.randomUUID();return new Promise((u,P)=>{let b;const x=r(()=>{b&&clearTimeout(b),e?.signal?.removeEventListener("abort",E),f.delete(l)},"cleanup"),E=r(()=>{x(),u(t)},"onAbort");e?.signal?.addEventListener("abort",E,{once:!0}),e?.timeout&&(b=setTimeout(()=>{x(),u(t)},e.timeout)),f.set(l,{resolve:r(F=>{x(),u(n(F))},"resolve"),reject:P}),a({type:"extension_ui_request",id:l,...s})})}r(w,"createDialogPromise");const U=r(()=>({select:r((e,t,s)=>w(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:r((e,t,s)=>w(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:r((e,t,s)=>w(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){a({type:"extension_ui_request",id:p.randomUUID(),method:"notify",message:e,notifyType:t})},onTerminalInput(){return()=>{}},setStatus(e,t){a({type:"extension_ui_request",id:p.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&a({type:"extension_ui_request",id:p.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){a({type:"extension_ui_request",id:p.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){a({type:"extension_ui_request",id:p.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=p.randomUUID();return new Promise((n,l)=>{f.set(s,{resolve:r(u=>{"cancelled"in u&&u.cancelled?n(void 0):"value"in u?n(u.value):n(void 0)},"resolve"),reject:l}),a({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return W},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");c.setRebindSession(async()=>{await m()});const m=r(async()=>{o=c.session,await o.bindExtensions({uiContext:U(),mode:"rpc",commandContextActions:{waitForIdle:r(()=>o.agent.waitForIdle(),"waitForIdle"),newSession:r(async e=>c.newSession(e),"newSession"),fork:r(async(e,t)=>({cancelled:(await c.fork(e,t)).cancelled}),"fork"),navigateTree:r(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:r(async(e,t)=>c.switchSession(e,t),"switchSession"),reload:r(async()=>{await o.reload()},"reload")},shutdownHandler:r(()=>{v=!0},"shutdownHandler"),onError:r(e=>{a({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")}),_?.(),h?.(),_=o.subscribe(e=>{a(e)}),h=o.agent.subscribe(async()=>{await g()})},"rebindSession"),C=r(()=>{const e=["SIGTERM"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=r(()=>{N(),y(t==="SIGHUP"?129:143,t)},"handler");process.on(t,s),k.push(()=>process.off(t,s))}},"registerSignalHandlers");await m(),C();const R=r(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:r(n=>{n&&(s=!0,a(i(t,"prompt")))},"preflightResult")}).catch(n=>{s||a(d(t,"prompt",n.message))});return}case"steer":return await o.steer(e.message,e.images),i(t,"steer");case"follow_up":return await o.followUp(e.message,e.images),i(t,"follow_up");case"abort":return await o.abort(),i(t,"abort");case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await c.newSession(s);return n.cancelled||await m(),i(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return i(t,"get_state",s)}case"set_model":{const n=(await o.modelRegistry.getAvailable()).find(l=>l.provider===e.provider&&l.id===e.modelId);return n?(await o.setModel(n),i(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?i(t,"cycle_model",s):i(t,"cycle_model",null)}case"get_available_models":{const s=await o.modelRegistry.getAvailable();return i(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),i(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?i(t,"cycle_thinking_level",{level:s}):i(t,"cycle_thinking_level",null)}case"set_steering_mode":return o.setSteeringMode(e.mode),i(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),i(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return i(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),i(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),i(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),i(t,"abort_retry");case"bash":{const s=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext});return i(t,"bash",s)}case"abort_bash":return o.abortBash(),i(t,"abort_bash");case"get_session_stats":{const s=o.getSessionStats();return i(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return i(t,"export_html",{path:s})}case"switch_session":{const s=await c.switchSession(e.sessionPath);return s.cancelled||await m(),i(t,"switch_session",s)}case"fork":{const s=await c.fork(e.entryId);return s.cancelled||await m(),i(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await c.fork(s,{position:"at"});return n.cancelled||await m(),i(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return i(t,"get_fork_messages",{messages:s})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return i(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),i(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":return i(t,"get_messages",{messages:o.messages});case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return i(t,"get_commands",{commands:s})}default:{const s=e;return d(void 0,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let S=r(()=>{},"detachInput");async function y(e=0,t){I&&process.exit(e),I=!0;for(const s of k)s();_?.(),h?.(),await c.dispose(),S(),process.stdin.pause(),t!=="SIGTERM"&&await q(),process.exit(e)}r(y,"shutdown");async function M(){v&&await y()}r(M,"checkShutdownRequested");const L=r(async e=>{let t;try{t=JSON.parse(e)}catch(n){a(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await g();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,l=f.get(n.id);l&&(f.delete(n.id),l.resolve(n));return}const s=t;try{const n=await R(s);n&&(a(n),await g()),await M()}catch(n){a(d(s.id,s.type,n instanceof Error?n.message:String(n))),await g()}},"handleInputLine"),T=r(()=>{y()},"onInputEnd");return process.stdin.on("end",T),S=(()=>{const e=$(process.stdin,t=>{L(t)});return()=>{e(),process.stdin.off("end",T)}})(),new Promise(()=>{})}r(Q,"runRpcMode");export{Q as runRpcMode};
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC protocol types for headless operation.
|
|
3
|
+
*
|
|
4
|
+
* Commands are sent as JSON lines on stdin.
|
|
5
|
+
* Responses and events are emitted as JSON lines on stdout.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentMessage, ThinkingLevel } from "@openadapter/koda-agent-core";
|
|
8
|
+
import type { ImageContent, Model } from "@openadapter/koda-ai";
|
|
9
|
+
import type { SessionStats } from "../../core/agent-session.ts";
|
|
10
|
+
import type { BashResult } from "../../core/bash-executor.ts";
|
|
11
|
+
import type { CompactionResult } from "../../core/compaction/index.ts";
|
|
12
|
+
import type { SourceInfo } from "../../core/source-info.ts";
|
|
13
|
+
export type RpcCommand = {
|
|
14
|
+
id?: string;
|
|
15
|
+
type: "prompt";
|
|
16
|
+
message: string;
|
|
17
|
+
images?: ImageContent[];
|
|
18
|
+
streamingBehavior?: "steer" | "followUp";
|
|
19
|
+
} | {
|
|
20
|
+
id?: string;
|
|
21
|
+
type: "steer";
|
|
22
|
+
message: string;
|
|
23
|
+
images?: ImageContent[];
|
|
24
|
+
} | {
|
|
25
|
+
id?: string;
|
|
26
|
+
type: "follow_up";
|
|
27
|
+
message: string;
|
|
28
|
+
images?: ImageContent[];
|
|
29
|
+
} | {
|
|
30
|
+
id?: string;
|
|
31
|
+
type: "abort";
|
|
32
|
+
} | {
|
|
33
|
+
id?: string;
|
|
34
|
+
type: "new_session";
|
|
35
|
+
parentSession?: string;
|
|
36
|
+
} | {
|
|
37
|
+
id?: string;
|
|
38
|
+
type: "get_state";
|
|
39
|
+
} | {
|
|
40
|
+
id?: string;
|
|
41
|
+
type: "set_model";
|
|
42
|
+
provider: string;
|
|
43
|
+
modelId: string;
|
|
44
|
+
} | {
|
|
45
|
+
id?: string;
|
|
46
|
+
type: "cycle_model";
|
|
47
|
+
} | {
|
|
48
|
+
id?: string;
|
|
49
|
+
type: "get_available_models";
|
|
50
|
+
} | {
|
|
51
|
+
id?: string;
|
|
52
|
+
type: "set_thinking_level";
|
|
53
|
+
level: ThinkingLevel;
|
|
54
|
+
} | {
|
|
55
|
+
id?: string;
|
|
56
|
+
type: "cycle_thinking_level";
|
|
57
|
+
} | {
|
|
58
|
+
id?: string;
|
|
59
|
+
type: "set_steering_mode";
|
|
60
|
+
mode: "all" | "one-at-a-time";
|
|
61
|
+
} | {
|
|
62
|
+
id?: string;
|
|
63
|
+
type: "set_follow_up_mode";
|
|
64
|
+
mode: "all" | "one-at-a-time";
|
|
65
|
+
} | {
|
|
66
|
+
id?: string;
|
|
67
|
+
type: "compact";
|
|
68
|
+
customInstructions?: string;
|
|
69
|
+
} | {
|
|
70
|
+
id?: string;
|
|
71
|
+
type: "set_auto_compaction";
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
} | {
|
|
74
|
+
id?: string;
|
|
75
|
+
type: "set_auto_retry";
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
} | {
|
|
78
|
+
id?: string;
|
|
79
|
+
type: "abort_retry";
|
|
80
|
+
} | {
|
|
81
|
+
id?: string;
|
|
82
|
+
type: "bash";
|
|
83
|
+
command: string;
|
|
84
|
+
excludeFromContext?: boolean;
|
|
85
|
+
} | {
|
|
86
|
+
id?: string;
|
|
87
|
+
type: "abort_bash";
|
|
88
|
+
} | {
|
|
89
|
+
id?: string;
|
|
90
|
+
type: "get_session_stats";
|
|
91
|
+
} | {
|
|
92
|
+
id?: string;
|
|
93
|
+
type: "export_html";
|
|
94
|
+
outputPath?: string;
|
|
95
|
+
} | {
|
|
96
|
+
id?: string;
|
|
97
|
+
type: "switch_session";
|
|
98
|
+
sessionPath: string;
|
|
99
|
+
} | {
|
|
100
|
+
id?: string;
|
|
101
|
+
type: "fork";
|
|
102
|
+
entryId: string;
|
|
103
|
+
} | {
|
|
104
|
+
id?: string;
|
|
105
|
+
type: "clone";
|
|
106
|
+
} | {
|
|
107
|
+
id?: string;
|
|
108
|
+
type: "get_fork_messages";
|
|
109
|
+
} | {
|
|
110
|
+
id?: string;
|
|
111
|
+
type: "get_last_assistant_text";
|
|
112
|
+
} | {
|
|
113
|
+
id?: string;
|
|
114
|
+
type: "set_session_name";
|
|
115
|
+
name: string;
|
|
116
|
+
} | {
|
|
117
|
+
id?: string;
|
|
118
|
+
type: "get_messages";
|
|
119
|
+
} | {
|
|
120
|
+
id?: string;
|
|
121
|
+
type: "get_commands";
|
|
122
|
+
};
|
|
123
|
+
/** A command available for invocation via prompt */
|
|
124
|
+
export interface RpcSlashCommand {
|
|
125
|
+
/** Command name (without leading slash) */
|
|
126
|
+
name: string;
|
|
127
|
+
/** Human-readable description */
|
|
128
|
+
description?: string;
|
|
129
|
+
/** What kind of command this is */
|
|
130
|
+
source: "extension" | "prompt" | "skill";
|
|
131
|
+
/** Source metadata for the owning resource */
|
|
132
|
+
sourceInfo: SourceInfo;
|
|
133
|
+
}
|
|
134
|
+
export interface RpcSessionState {
|
|
135
|
+
model?: Model<any>;
|
|
136
|
+
thinkingLevel: ThinkingLevel;
|
|
137
|
+
isStreaming: boolean;
|
|
138
|
+
isCompacting: boolean;
|
|
139
|
+
steeringMode: "all" | "one-at-a-time";
|
|
140
|
+
followUpMode: "all" | "one-at-a-time";
|
|
141
|
+
sessionFile?: string;
|
|
142
|
+
sessionId: string;
|
|
143
|
+
sessionName?: string;
|
|
144
|
+
autoCompactionEnabled: boolean;
|
|
145
|
+
messageCount: number;
|
|
146
|
+
pendingMessageCount: number;
|
|
147
|
+
}
|
|
148
|
+
export type RpcResponse = {
|
|
149
|
+
id?: string;
|
|
150
|
+
type: "response";
|
|
151
|
+
command: "prompt";
|
|
152
|
+
success: true;
|
|
153
|
+
} | {
|
|
154
|
+
id?: string;
|
|
155
|
+
type: "response";
|
|
156
|
+
command: "steer";
|
|
157
|
+
success: true;
|
|
158
|
+
} | {
|
|
159
|
+
id?: string;
|
|
160
|
+
type: "response";
|
|
161
|
+
command: "follow_up";
|
|
162
|
+
success: true;
|
|
163
|
+
} | {
|
|
164
|
+
id?: string;
|
|
165
|
+
type: "response";
|
|
166
|
+
command: "abort";
|
|
167
|
+
success: true;
|
|
168
|
+
} | {
|
|
169
|
+
id?: string;
|
|
170
|
+
type: "response";
|
|
171
|
+
command: "new_session";
|
|
172
|
+
success: true;
|
|
173
|
+
data: {
|
|
174
|
+
cancelled: boolean;
|
|
175
|
+
};
|
|
176
|
+
} | {
|
|
177
|
+
id?: string;
|
|
178
|
+
type: "response";
|
|
179
|
+
command: "get_state";
|
|
180
|
+
success: true;
|
|
181
|
+
data: RpcSessionState;
|
|
182
|
+
} | {
|
|
183
|
+
id?: string;
|
|
184
|
+
type: "response";
|
|
185
|
+
command: "set_model";
|
|
186
|
+
success: true;
|
|
187
|
+
data: Model<any>;
|
|
188
|
+
} | {
|
|
189
|
+
id?: string;
|
|
190
|
+
type: "response";
|
|
191
|
+
command: "cycle_model";
|
|
192
|
+
success: true;
|
|
193
|
+
data: {
|
|
194
|
+
model: Model<any>;
|
|
195
|
+
thinkingLevel: ThinkingLevel;
|
|
196
|
+
isScoped: boolean;
|
|
197
|
+
} | null;
|
|
198
|
+
} | {
|
|
199
|
+
id?: string;
|
|
200
|
+
type: "response";
|
|
201
|
+
command: "get_available_models";
|
|
202
|
+
success: true;
|
|
203
|
+
data: {
|
|
204
|
+
models: Model<any>[];
|
|
205
|
+
};
|
|
206
|
+
} | {
|
|
207
|
+
id?: string;
|
|
208
|
+
type: "response";
|
|
209
|
+
command: "set_thinking_level";
|
|
210
|
+
success: true;
|
|
211
|
+
} | {
|
|
212
|
+
id?: string;
|
|
213
|
+
type: "response";
|
|
214
|
+
command: "cycle_thinking_level";
|
|
215
|
+
success: true;
|
|
216
|
+
data: {
|
|
217
|
+
level: ThinkingLevel;
|
|
218
|
+
} | null;
|
|
219
|
+
} | {
|
|
220
|
+
id?: string;
|
|
221
|
+
type: "response";
|
|
222
|
+
command: "set_steering_mode";
|
|
223
|
+
success: true;
|
|
224
|
+
} | {
|
|
225
|
+
id?: string;
|
|
226
|
+
type: "response";
|
|
227
|
+
command: "set_follow_up_mode";
|
|
228
|
+
success: true;
|
|
229
|
+
} | {
|
|
230
|
+
id?: string;
|
|
231
|
+
type: "response";
|
|
232
|
+
command: "compact";
|
|
233
|
+
success: true;
|
|
234
|
+
data: CompactionResult;
|
|
235
|
+
} | {
|
|
236
|
+
id?: string;
|
|
237
|
+
type: "response";
|
|
238
|
+
command: "set_auto_compaction";
|
|
239
|
+
success: true;
|
|
240
|
+
} | {
|
|
241
|
+
id?: string;
|
|
242
|
+
type: "response";
|
|
243
|
+
command: "set_auto_retry";
|
|
244
|
+
success: true;
|
|
245
|
+
} | {
|
|
246
|
+
id?: string;
|
|
247
|
+
type: "response";
|
|
248
|
+
command: "abort_retry";
|
|
249
|
+
success: true;
|
|
250
|
+
} | {
|
|
251
|
+
id?: string;
|
|
252
|
+
type: "response";
|
|
253
|
+
command: "bash";
|
|
254
|
+
success: true;
|
|
255
|
+
data: BashResult;
|
|
256
|
+
} | {
|
|
257
|
+
id?: string;
|
|
258
|
+
type: "response";
|
|
259
|
+
command: "abort_bash";
|
|
260
|
+
success: true;
|
|
261
|
+
} | {
|
|
262
|
+
id?: string;
|
|
263
|
+
type: "response";
|
|
264
|
+
command: "get_session_stats";
|
|
265
|
+
success: true;
|
|
266
|
+
data: SessionStats;
|
|
267
|
+
} | {
|
|
268
|
+
id?: string;
|
|
269
|
+
type: "response";
|
|
270
|
+
command: "export_html";
|
|
271
|
+
success: true;
|
|
272
|
+
data: {
|
|
273
|
+
path: string;
|
|
274
|
+
};
|
|
275
|
+
} | {
|
|
276
|
+
id?: string;
|
|
277
|
+
type: "response";
|
|
278
|
+
command: "switch_session";
|
|
279
|
+
success: true;
|
|
280
|
+
data: {
|
|
281
|
+
cancelled: boolean;
|
|
282
|
+
};
|
|
283
|
+
} | {
|
|
284
|
+
id?: string;
|
|
285
|
+
type: "response";
|
|
286
|
+
command: "fork";
|
|
287
|
+
success: true;
|
|
288
|
+
data: {
|
|
289
|
+
text: string;
|
|
290
|
+
cancelled: boolean;
|
|
291
|
+
};
|
|
292
|
+
} | {
|
|
293
|
+
id?: string;
|
|
294
|
+
type: "response";
|
|
295
|
+
command: "clone";
|
|
296
|
+
success: true;
|
|
297
|
+
data: {
|
|
298
|
+
cancelled: boolean;
|
|
299
|
+
};
|
|
300
|
+
} | {
|
|
301
|
+
id?: string;
|
|
302
|
+
type: "response";
|
|
303
|
+
command: "get_fork_messages";
|
|
304
|
+
success: true;
|
|
305
|
+
data: {
|
|
306
|
+
messages: Array<{
|
|
307
|
+
entryId: string;
|
|
308
|
+
text: string;
|
|
309
|
+
}>;
|
|
310
|
+
};
|
|
311
|
+
} | {
|
|
312
|
+
id?: string;
|
|
313
|
+
type: "response";
|
|
314
|
+
command: "get_last_assistant_text";
|
|
315
|
+
success: true;
|
|
316
|
+
data: {
|
|
317
|
+
text: string | null;
|
|
318
|
+
};
|
|
319
|
+
} | {
|
|
320
|
+
id?: string;
|
|
321
|
+
type: "response";
|
|
322
|
+
command: "set_session_name";
|
|
323
|
+
success: true;
|
|
324
|
+
} | {
|
|
325
|
+
id?: string;
|
|
326
|
+
type: "response";
|
|
327
|
+
command: "get_messages";
|
|
328
|
+
success: true;
|
|
329
|
+
data: {
|
|
330
|
+
messages: AgentMessage[];
|
|
331
|
+
};
|
|
332
|
+
} | {
|
|
333
|
+
id?: string;
|
|
334
|
+
type: "response";
|
|
335
|
+
command: "get_commands";
|
|
336
|
+
success: true;
|
|
337
|
+
data: {
|
|
338
|
+
commands: RpcSlashCommand[];
|
|
339
|
+
};
|
|
340
|
+
} | {
|
|
341
|
+
id?: string;
|
|
342
|
+
type: "response";
|
|
343
|
+
command: string;
|
|
344
|
+
success: false;
|
|
345
|
+
error: string;
|
|
346
|
+
};
|
|
347
|
+
/** Emitted when an extension needs user input */
|
|
348
|
+
export type RpcExtensionUIRequest = {
|
|
349
|
+
type: "extension_ui_request";
|
|
350
|
+
id: string;
|
|
351
|
+
method: "select";
|
|
352
|
+
title: string;
|
|
353
|
+
options: string[];
|
|
354
|
+
timeout?: number;
|
|
355
|
+
} | {
|
|
356
|
+
type: "extension_ui_request";
|
|
357
|
+
id: string;
|
|
358
|
+
method: "confirm";
|
|
359
|
+
title: string;
|
|
360
|
+
message: string;
|
|
361
|
+
timeout?: number;
|
|
362
|
+
} | {
|
|
363
|
+
type: "extension_ui_request";
|
|
364
|
+
id: string;
|
|
365
|
+
method: "input";
|
|
366
|
+
title: string;
|
|
367
|
+
placeholder?: string;
|
|
368
|
+
timeout?: number;
|
|
369
|
+
} | {
|
|
370
|
+
type: "extension_ui_request";
|
|
371
|
+
id: string;
|
|
372
|
+
method: "editor";
|
|
373
|
+
title: string;
|
|
374
|
+
prefill?: string;
|
|
375
|
+
} | {
|
|
376
|
+
type: "extension_ui_request";
|
|
377
|
+
id: string;
|
|
378
|
+
method: "notify";
|
|
379
|
+
message: string;
|
|
380
|
+
notifyType?: "info" | "warning" | "error";
|
|
381
|
+
} | {
|
|
382
|
+
type: "extension_ui_request";
|
|
383
|
+
id: string;
|
|
384
|
+
method: "setStatus";
|
|
385
|
+
statusKey: string;
|
|
386
|
+
statusText: string | undefined;
|
|
387
|
+
} | {
|
|
388
|
+
type: "extension_ui_request";
|
|
389
|
+
id: string;
|
|
390
|
+
method: "setWidget";
|
|
391
|
+
widgetKey: string;
|
|
392
|
+
widgetLines: string[] | undefined;
|
|
393
|
+
widgetPlacement?: "aboveEditor" | "belowEditor";
|
|
394
|
+
} | {
|
|
395
|
+
type: "extension_ui_request";
|
|
396
|
+
id: string;
|
|
397
|
+
method: "setTitle";
|
|
398
|
+
title: string;
|
|
399
|
+
} | {
|
|
400
|
+
type: "extension_ui_request";
|
|
401
|
+
id: string;
|
|
402
|
+
method: "set_editor_text";
|
|
403
|
+
text: string;
|
|
404
|
+
};
|
|
405
|
+
/** Response to an extension UI request */
|
|
406
|
+
export type RpcExtensionUIResponse = {
|
|
407
|
+
type: "extension_ui_response";
|
|
408
|
+
id: string;
|
|
409
|
+
value: string;
|
|
410
|
+
} | {
|
|
411
|
+
type: "extension_ui_response";
|
|
412
|
+
id: string;
|
|
413
|
+
confirmed: boolean;
|
|
414
|
+
} | {
|
|
415
|
+
type: "extension_ui_response";
|
|
416
|
+
id: string;
|
|
417
|
+
cancelled: true;
|
|
418
|
+
};
|
|
419
|
+
export type RpcCommandType = RpcCommand["type"];
|
|
File without changes
|