@mariozechner/pi-coding-agent 0.31.1 → 0.32.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/CHANGELOG.md +54 -0
- package/README.md +56 -5
- package/dist/cli/file-processor.d.ts +5 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +28 -8
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session.d.ts +45 -17
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +93 -42
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +6 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +16 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/custom-tools/types.d.ts +1 -1
- package/dist/core/custom-tools/types.d.ts.map +1 -1
- package/dist/core/custom-tools/types.js.map +1 -1
- package/dist/core/hooks/loader.d.ts +4 -1
- package/dist/core/hooks/loader.d.ts.map +1 -1
- package/dist/core/hooks/loader.js +2 -2
- package/dist/core/hooks/loader.js.map +1 -1
- package/dist/core/hooks/runner.d.ts +2 -2
- package/dist/core/hooks/runner.d.ts.map +1 -1
- package/dist/core/hooks/runner.js +3 -3
- package/dist/core/hooks/runner.js.map +1 -1
- package/dist/core/hooks/types.d.ts +10 -4
- package/dist/core/hooks/types.d.ts.map +1 -1
- package/dist/core/hooks/types.js.map +1 -1
- package/dist/core/messages.d.ts +2 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +4 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -2
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +85 -49
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -0
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +9 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +17 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +41 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/index.d.ts +9 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +6 -6
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/read.d.ts +5 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +22 -5
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -5
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +6 -4
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/hook-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/hook-editor.js +3 -3
- package/dist/modes/interactive/components/hook-editor.js.map +1 -1
- package/dist/modes/interactive/components/hook-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/hook-input.js +3 -3
- package/dist/modes/interactive/components/hook-input.js.map +1 -1
- package/dist/modes/interactive/components/hook-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/hook-selector.js +3 -3
- package/dist/modes/interactive/components/hook-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +3 -3
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +3 -3
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +37 -6
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +7 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +74 -26
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +3 -3
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +12 -4
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +18 -6
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +21 -12
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +25 -6
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/image-resize.d.ts +29 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +111 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/docs/hooks.md +16 -9
- package/examples/README.md +6 -0
- package/examples/custom-tools/README.md +2 -0
- package/examples/hooks/README.md +1 -0
- package/examples/hooks/file-trigger.ts +1 -1
- package/examples/hooks/todo/index.ts +134 -0
- package/package.json +6 -5
- package/dist/modes/interactive/components/queue-mode-selector.d.ts +0 -10
- package/dist/modes/interactive/components/queue-mode-selector.d.ts.map +0 -1
- package/dist/modes/interactive/components/queue-mode-selector.js +0 -42
- package/dist/modes/interactive/components/queue-mode-selector.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-mode.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAMtD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAqB,EAAkB;IACvE,MAAM,MAAM,GAAG,CAAC,GAA4C,EAAE,EAAE,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAAA,CACjC,CAAC;IAEF,MAAM,OAAO,GAAG,CACf,EAAsB,EACtB,OAAU,EACV,IAAoB,EACN,EAAE,CAAC;QACjB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAiB,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAiB,CAAC;IAAA,CAC7E,CAAC;IAEF,MAAM,KAAK,GAAG,CAAC,EAAsB,EAAE,OAAe,EAAE,OAAe,EAAe,EAAE,CAAC;QACxF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAAA,CACzE,CAAC;IAEF,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,CAAC;IAEH,6BAA6B;IAC7B,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC,CAAC;AAAA,CAC7B","sourcesContent":["/**\n * RPC mode: Headless operation with JSON stdin/stdout protocol.\n *\n * Used for embedding the agent in other applications.\n * Receives commands as JSON on stdin, outputs events and responses as JSON on stdout.\n *\n * Protocol:\n * - Commands: JSON objects with `type` field, optional `id` for correlation\n * - Responses: JSON objects with `type: \"response\"`, `command`, `success`, and optional `data`/`error`\n * - Events: AgentSessionEvent objects streamed as they occur\n * - Hook UI: Hook UI requests are emitted, client responds with hook_ui_response\n */\n\nimport * as crypto from \"node:crypto\";\nimport * as readline from \"readline\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport type { HookUIContext } from \"../../core/hooks/index.js\";\nimport { theme } from \"../interactive/theme/theme.js\";\nimport type { RpcCommand, RpcHookUIRequest, RpcHookUIResponse, RpcResponse, RpcSessionState } from \"./rpc-types.js\";\n\n// Re-export types for consumers\nexport type { RpcCommand, RpcHookUIRequest, RpcHookUIResponse, RpcResponse, RpcSessionState } from \"./rpc-types.js\";\n\n/**\n * Run in RPC mode.\n * Listens for JSON commands on stdin, outputs events and responses on stdout.\n */\nexport async function runRpcMode(session: AgentSession): Promise<never> {\n\tconst output = (obj: RpcResponse | RpcHookUIRequest | object) => {\n\t\tconsole.log(JSON.stringify(obj));\n\t};\n\n\tconst success = <T extends RpcCommand[\"type\"]>(\n\t\tid: string | undefined,\n\t\tcommand: T,\n\t\tdata?: object | null,\n\t): RpcResponse => {\n\t\tif (data === undefined) {\n\t\t\treturn { id, type: \"response\", command, success: true } as RpcResponse;\n\t\t}\n\t\treturn { id, type: \"response\", command, success: true, data } as RpcResponse;\n\t};\n\n\tconst error = (id: string | undefined, command: string, message: string): RpcResponse => {\n\t\treturn { id, type: \"response\", command, success: false, error: message };\n\t};\n\n\t// Pending hook UI requests waiting for response\n\tconst pendingHookRequests = new Map<string, { resolve: (value: any) => void; reject: (error: Error) => void }>();\n\n\t/**\n\t * Create a hook UI context that uses the RPC protocol.\n\t */\n\tconst createHookUIContext = (): HookUIContext => ({\n\t\tasync select(title: string, options: string[]): Promise<string | undefined> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t} else if (\"value\" in response) {\n\t\t\t\t\t\t\tresolve(response.value);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"select\", title, options } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tasync confirm(title: string, message: string): Promise<boolean> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t\t} else if (\"confirmed\" in response) {\n\t\t\t\t\t\t\tresolve(response.confirmed);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"confirm\", title, message } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tasync input(title: string, placeholder?: string): Promise<string | undefined> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t} else if (\"value\" in response) {\n\t\t\t\t\t\t\tresolve(response.value);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"input\", title, placeholder } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void {\n\t\t\t// Fire and forget - no response needed\n\t\t\toutput({\n\t\t\t\ttype: \"hook_ui_request\",\n\t\t\t\tid: crypto.randomUUID(),\n\t\t\t\tmethod: \"notify\",\n\t\t\t\tmessage,\n\t\t\t\tnotifyType: type,\n\t\t\t} as RpcHookUIRequest);\n\t\t},\n\n\t\tsetStatus(key: string, text: string | undefined): void {\n\t\t\t// Fire and forget - no response needed\n\t\t\toutput({\n\t\t\t\ttype: \"hook_ui_request\",\n\t\t\t\tid: crypto.randomUUID(),\n\t\t\t\tmethod: \"setStatus\",\n\t\t\t\tstatusKey: key,\n\t\t\t\tstatusText: text,\n\t\t\t} as RpcHookUIRequest);\n\t\t},\n\n\t\tasync custom() {\n\t\t\t// Custom UI not supported in RPC mode\n\t\t\treturn undefined as never;\n\t\t},\n\n\t\tsetEditorText(text: string): void {\n\t\t\t// Fire and forget - host can implement editor control\n\t\t\toutput({\n\t\t\t\ttype: \"hook_ui_request\",\n\t\t\t\tid: crypto.randomUUID(),\n\t\t\t\tmethod: \"set_editor_text\",\n\t\t\t\ttext,\n\t\t\t} as RpcHookUIRequest);\n\t\t},\n\n\t\tgetEditorText(): string {\n\t\t\t// Synchronous method can't wait for RPC response\n\t\t\t// Host should track editor state locally if needed\n\t\t\treturn \"\";\n\t\t},\n\n\t\tasync editor(title: string, prefill?: string): Promise<string | undefined> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t} else if (\"value\" in response) {\n\t\t\t\t\t\t\tresolve(response.value);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"editor\", title, prefill } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tget theme() {\n\t\t\treturn theme;\n\t\t},\n\t});\n\n\t// Set up hooks with RPC-based UI context\n\tconst hookRunner = session.hookRunner;\n\tif (hookRunner) {\n\t\thookRunner.initialize({\n\t\t\tgetModel: () => session.agent.state.model,\n\t\t\tsendMessageHandler: (message, triggerTurn) => {\n\t\t\t\tsession.sendHookMessage(message, triggerTurn).catch((e) => {\n\t\t\t\t\toutput(error(undefined, \"hook_send\", e.message));\n\t\t\t\t});\n\t\t\t},\n\t\t\tappendEntryHandler: (customType, data) => {\n\t\t\t\tsession.sessionManager.appendCustomEntry(customType, data);\n\t\t\t},\n\t\t\tuiContext: createHookUIContext(),\n\t\t\thasUI: false,\n\t\t});\n\t\thookRunner.onError((err) => {\n\t\t\toutput({ type: \"hook_error\", hookPath: err.hookPath, event: err.event, error: err.error });\n\t\t});\n\t\t// Emit session_start event\n\t\tawait hookRunner.emit({\n\t\t\ttype: \"session_start\",\n\t\t});\n\t}\n\n\t// Emit session start event to custom tools\n\t// Note: Tools get no-op UI context in RPC mode (host handles UI via protocol)\n\tfor (const { tool } of session.customTools) {\n\t\tif (tool.onSession) {\n\t\t\ttry {\n\t\t\t\tawait tool.onSession(\n\t\t\t\t\t{\n\t\t\t\t\t\tpreviousSessionFile: undefined,\n\t\t\t\t\t\treason: \"start\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tsessionManager: session.sessionManager,\n\t\t\t\t\t\tmodelRegistry: session.modelRegistry,\n\t\t\t\t\t\tmodel: session.model,\n\t\t\t\t\t\tisIdle: () => !session.isStreaming,\n\t\t\t\t\t\thasQueuedMessages: () => session.queuedMessageCount > 0,\n\t\t\t\t\t\tabort: () => {\n\t\t\t\t\t\t\tsession.abort();\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (_err) {\n\t\t\t\t// Silently ignore tool errors\n\t\t\t}\n\t\t}\n\t}\n\n\t// Output all agent events as JSON\n\tsession.subscribe((event) => {\n\t\toutput(event);\n\t});\n\n\t// Handle a single command\n\tconst handleCommand = async (command: RpcCommand): Promise<RpcResponse> => {\n\t\tconst id = command.id;\n\n\t\tswitch (command.type) {\n\t\t\t// =================================================================\n\t\t\t// Prompting\n\t\t\t// =================================================================\n\n\t\t\tcase \"prompt\": {\n\t\t\t\t// Don't await - events will stream\n\t\t\t\t// Hook commands and file slash commands are handled in session.prompt()\n\t\t\t\tsession\n\t\t\t\t\t.prompt(command.message, {\n\t\t\t\t\t\timages: command.images,\n\t\t\t\t\t})\n\t\t\t\t\t.catch((e) => output(error(id, \"prompt\", e.message)));\n\t\t\t\treturn success(id, \"prompt\");\n\t\t\t}\n\n\t\t\tcase \"queue_message\": {\n\t\t\t\tawait session.queueMessage(command.message);\n\t\t\t\treturn success(id, \"queue_message\");\n\t\t\t}\n\n\t\t\tcase \"abort\": {\n\t\t\t\tawait session.abort();\n\t\t\t\treturn success(id, \"abort\");\n\t\t\t}\n\n\t\t\tcase \"new_session\": {\n\t\t\t\tconst options = command.parentSession ? { parentSession: command.parentSession } : undefined;\n\t\t\t\tconst cancelled = !(await session.newSession(options));\n\t\t\t\treturn success(id, \"new_session\", { cancelled });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// State\n\t\t\t// =================================================================\n\n\t\t\tcase \"get_state\": {\n\t\t\t\tconst state: RpcSessionState = {\n\t\t\t\t\tmodel: session.model,\n\t\t\t\t\tthinkingLevel: session.thinkingLevel,\n\t\t\t\t\tisStreaming: session.isStreaming,\n\t\t\t\t\tisCompacting: session.isCompacting,\n\t\t\t\t\tqueueMode: session.queueMode,\n\t\t\t\t\tsessionFile: session.sessionFile,\n\t\t\t\t\tsessionId: session.sessionId,\n\t\t\t\t\tautoCompactionEnabled: session.autoCompactionEnabled,\n\t\t\t\t\tmessageCount: session.messages.length,\n\t\t\t\t\tqueuedMessageCount: session.queuedMessageCount,\n\t\t\t\t};\n\t\t\t\treturn success(id, \"get_state\", state);\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Model\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_model\": {\n\t\t\t\tconst models = await session.getAvailableModels();\n\t\t\t\tconst model = models.find((m) => m.provider === command.provider && m.id === command.modelId);\n\t\t\t\tif (!model) {\n\t\t\t\t\treturn error(id, \"set_model\", `Model not found: ${command.provider}/${command.modelId}`);\n\t\t\t\t}\n\t\t\t\tawait session.setModel(model);\n\t\t\t\treturn success(id, \"set_model\", model);\n\t\t\t}\n\n\t\t\tcase \"cycle_model\": {\n\t\t\t\tconst result = await session.cycleModel();\n\t\t\t\tif (!result) {\n\t\t\t\t\treturn success(id, \"cycle_model\", null);\n\t\t\t\t}\n\t\t\t\treturn success(id, \"cycle_model\", result);\n\t\t\t}\n\n\t\t\tcase \"get_available_models\": {\n\t\t\t\tconst models = await session.getAvailableModels();\n\t\t\t\treturn success(id, \"get_available_models\", { models });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Thinking\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_thinking_level\": {\n\t\t\t\tsession.setThinkingLevel(command.level);\n\t\t\t\treturn success(id, \"set_thinking_level\");\n\t\t\t}\n\n\t\t\tcase \"cycle_thinking_level\": {\n\t\t\t\tconst level = session.cycleThinkingLevel();\n\t\t\t\tif (!level) {\n\t\t\t\t\treturn success(id, \"cycle_thinking_level\", null);\n\t\t\t\t}\n\t\t\t\treturn success(id, \"cycle_thinking_level\", { level });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Queue Mode\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_queue_mode\": {\n\t\t\t\tsession.setQueueMode(command.mode);\n\t\t\t\treturn success(id, \"set_queue_mode\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Compaction\n\t\t\t// =================================================================\n\n\t\t\tcase \"compact\": {\n\t\t\t\tconst result = await session.compact(command.customInstructions);\n\t\t\t\treturn success(id, \"compact\", result);\n\t\t\t}\n\n\t\t\tcase \"set_auto_compaction\": {\n\t\t\t\tsession.setAutoCompactionEnabled(command.enabled);\n\t\t\t\treturn success(id, \"set_auto_compaction\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Retry\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_auto_retry\": {\n\t\t\t\tsession.setAutoRetryEnabled(command.enabled);\n\t\t\t\treturn success(id, \"set_auto_retry\");\n\t\t\t}\n\n\t\t\tcase \"abort_retry\": {\n\t\t\t\tsession.abortRetry();\n\t\t\t\treturn success(id, \"abort_retry\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Bash\n\t\t\t// =================================================================\n\n\t\t\tcase \"bash\": {\n\t\t\t\tconst result = await session.executeBash(command.command);\n\t\t\t\treturn success(id, \"bash\", result);\n\t\t\t}\n\n\t\t\tcase \"abort_bash\": {\n\t\t\t\tsession.abortBash();\n\t\t\t\treturn success(id, \"abort_bash\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Session\n\t\t\t// =================================================================\n\n\t\t\tcase \"get_session_stats\": {\n\t\t\t\tconst stats = session.getSessionStats();\n\t\t\t\treturn success(id, \"get_session_stats\", stats);\n\t\t\t}\n\n\t\t\tcase \"export_html\": {\n\t\t\t\tconst path = session.exportToHtml(command.outputPath);\n\t\t\t\treturn success(id, \"export_html\", { path });\n\t\t\t}\n\n\t\t\tcase \"switch_session\": {\n\t\t\t\tconst cancelled = !(await session.switchSession(command.sessionPath));\n\t\t\t\treturn success(id, \"switch_session\", { cancelled });\n\t\t\t}\n\n\t\t\tcase \"branch\": {\n\t\t\t\tconst result = await session.branch(command.entryId);\n\t\t\t\treturn success(id, \"branch\", { text: result.selectedText, cancelled: result.cancelled });\n\t\t\t}\n\n\t\t\tcase \"get_branch_messages\": {\n\t\t\t\tconst messages = session.getUserMessagesForBranching();\n\t\t\t\treturn success(id, \"get_branch_messages\", { messages });\n\t\t\t}\n\n\t\t\tcase \"get_last_assistant_text\": {\n\t\t\t\tconst text = session.getLastAssistantText();\n\t\t\t\treturn success(id, \"get_last_assistant_text\", { text });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Messages\n\t\t\t// =================================================================\n\n\t\t\tcase \"get_messages\": {\n\t\t\t\treturn success(id, \"get_messages\", { messages: session.messages });\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tconst unknownCommand = command as { type: string };\n\t\t\t\treturn error(undefined, unknownCommand.type, `Unknown command: ${unknownCommand.type}`);\n\t\t\t}\n\t\t}\n\t};\n\n\t// Listen for JSON input\n\tconst rl = readline.createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t\tterminal: false,\n\t});\n\n\trl.on(\"line\", async (line: string) => {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(line);\n\n\t\t\t// Handle hook UI responses\n\t\t\tif (parsed.type === \"hook_ui_response\") {\n\t\t\t\tconst response = parsed as RpcHookUIResponse;\n\t\t\t\tconst pending = pendingHookRequests.get(response.id);\n\t\t\t\tif (pending) {\n\t\t\t\t\tpendingHookRequests.delete(response.id);\n\t\t\t\t\tpending.resolve(response);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Handle regular commands\n\t\t\tconst command = parsed as RpcCommand;\n\t\t\tconst response = await handleCommand(command);\n\t\t\toutput(response);\n\t\t} catch (e: any) {\n\t\t\toutput(error(undefined, \"parse\", `Failed to parse command: ${e.message}`));\n\t\t}\n\t});\n\n\t// Keep process alive forever\n\treturn new Promise(() => {});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-mode.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAMtD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAqB,EAAkB;IACvE,MAAM,MAAM,GAAG,CAAC,GAA4C,EAAE,EAAE,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAAA,CACjC,CAAC;IAEF,MAAM,OAAO,GAAG,CACf,EAAsB,EACtB,OAAU,EACV,IAAoB,EACN,EAAE,CAAC;QACjB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAiB,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAiB,CAAC;IAAA,CAC7E,CAAC;IAEF,MAAM,KAAK,GAAG,CAAC,EAAsB,EAAE,OAAe,EAAE,OAAe,EAAe,EAAE,CAAC;QACxF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAAA,CACzE,CAAC;IAEF,gDAAgD;IAChD,MAAM,mBAAmB,GAAG,IAAI,G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AA0B;YAC1B,MAAM,OAAO,GAAG,MAAoB,CAAC;YACrC,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;YAC9C,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YACjB,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,4BAA4B,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC5E,CAAC;IAAA,CACD,CAAC,CAAC;IAEH,6BAA6B;IAC7B,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC,CAAC;AAAA,CAC7B","sourcesContent":["/**\n * RPC mode: Headless operation with JSON stdin/stdout protocol.\n *\n * Used for embedding the agent in other applications.\n * Receives commands as JSON on stdin, outputs events and responses as JSON on stdout.\n *\n * Protocol:\n * - Commands: JSON objects with `type` field, optional `id` for correlation\n * - Responses: JSON objects with `type: \"response\"`, `command`, `success`, and optional `data`/`error`\n * - Events: AgentSessionEvent objects streamed as they occur\n * - Hook UI: Hook UI requests are emitted, client responds with hook_ui_response\n */\n\nimport * as crypto from \"node:crypto\";\nimport * as readline from \"readline\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport type { HookUIContext } from \"../../core/hooks/index.js\";\nimport { theme } from \"../interactive/theme/theme.js\";\nimport type { RpcCommand, RpcHookUIRequest, RpcHookUIResponse, RpcResponse, RpcSessionState } from \"./rpc-types.js\";\n\n// Re-export types for consumers\nexport type { RpcCommand, RpcHookUIRequest, RpcHookUIResponse, RpcResponse, RpcSessionState } from \"./rpc-types.js\";\n\n/**\n * Run in RPC mode.\n * Listens for JSON commands on stdin, outputs events and responses on stdout.\n */\nexport async function runRpcMode(session: AgentSession): Promise<never> {\n\tconst output = (obj: RpcResponse | RpcHookUIRequest | object) => {\n\t\tconsole.log(JSON.stringify(obj));\n\t};\n\n\tconst success = <T extends RpcCommand[\"type\"]>(\n\t\tid: string | undefined,\n\t\tcommand: T,\n\t\tdata?: object | null,\n\t): RpcResponse => {\n\t\tif (data === undefined) {\n\t\t\treturn { id, type: \"response\", command, success: true } as RpcResponse;\n\t\t}\n\t\treturn { id, type: \"response\", command, success: true, data } as RpcResponse;\n\t};\n\n\tconst error = (id: string | undefined, command: string, message: string): RpcResponse => {\n\t\treturn { id, type: \"response\", command, success: false, error: message };\n\t};\n\n\t// Pending hook UI requests waiting for response\n\tconst pendingHookRequests = new Map<string, { resolve: (value: any) => void; reject: (error: Error) => void }>();\n\n\t/**\n\t * Create a hook UI context that uses the RPC protocol.\n\t */\n\tconst createHookUIContext = (): HookUIContext => ({\n\t\tasync select(title: string, options: string[]): Promise<string | undefined> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t} else if (\"value\" in response) {\n\t\t\t\t\t\t\tresolve(response.value);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"select\", title, options } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tasync confirm(title: string, message: string): Promise<boolean> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t\t} else if (\"confirmed\" in response) {\n\t\t\t\t\t\t\tresolve(response.confirmed);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"confirm\", title, message } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tasync input(title: string, placeholder?: string): Promise<string | undefined> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t} else if (\"value\" in response) {\n\t\t\t\t\t\t\tresolve(response.value);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"input\", title, placeholder } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void {\n\t\t\t// Fire and forget - no response needed\n\t\t\toutput({\n\t\t\t\ttype: \"hook_ui_request\",\n\t\t\t\tid: crypto.randomUUID(),\n\t\t\t\tmethod: \"notify\",\n\t\t\t\tmessage,\n\t\t\t\tnotifyType: type,\n\t\t\t} as RpcHookUIRequest);\n\t\t},\n\n\t\tsetStatus(key: string, text: string | undefined): void {\n\t\t\t// Fire and forget - no response needed\n\t\t\toutput({\n\t\t\t\ttype: \"hook_ui_request\",\n\t\t\t\tid: crypto.randomUUID(),\n\t\t\t\tmethod: \"setStatus\",\n\t\t\t\tstatusKey: key,\n\t\t\t\tstatusText: text,\n\t\t\t} as RpcHookUIRequest);\n\t\t},\n\n\t\tasync custom() {\n\t\t\t// Custom UI not supported in RPC mode\n\t\t\treturn undefined as never;\n\t\t},\n\n\t\tsetEditorText(text: string): void {\n\t\t\t// Fire and forget - host can implement editor control\n\t\t\toutput({\n\t\t\t\ttype: \"hook_ui_request\",\n\t\t\t\tid: crypto.randomUUID(),\n\t\t\t\tmethod: \"set_editor_text\",\n\t\t\t\ttext,\n\t\t\t} as RpcHookUIRequest);\n\t\t},\n\n\t\tgetEditorText(): string {\n\t\t\t// Synchronous method can't wait for RPC response\n\t\t\t// Host should track editor state locally if needed\n\t\t\treturn \"\";\n\t\t},\n\n\t\tasync editor(title: string, prefill?: string): Promise<string | undefined> {\n\t\t\tconst id = crypto.randomUUID();\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tpendingHookRequests.set(id, {\n\t\t\t\t\tresolve: (response: RpcHookUIResponse) => {\n\t\t\t\t\t\tif (\"cancelled\" in response && response.cancelled) {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t} else if (\"value\" in response) {\n\t\t\t\t\t\t\tresolve(response.value);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\treject,\n\t\t\t\t});\n\t\t\t\toutput({ type: \"hook_ui_request\", id, method: \"editor\", title, prefill } as RpcHookUIRequest);\n\t\t\t});\n\t\t},\n\n\t\tget theme() {\n\t\t\treturn theme;\n\t\t},\n\t});\n\n\t// Set up hooks with RPC-based UI context\n\tconst hookRunner = session.hookRunner;\n\tif (hookRunner) {\n\t\thookRunner.initialize({\n\t\t\tgetModel: () => session.agent.state.model,\n\t\t\tsendMessageHandler: (message, options) => {\n\t\t\t\tsession.sendHookMessage(message, options).catch((e) => {\n\t\t\t\t\toutput(error(undefined, \"hook_send\", e.message));\n\t\t\t\t});\n\t\t\t},\n\t\t\tappendEntryHandler: (customType, data) => {\n\t\t\t\tsession.sessionManager.appendCustomEntry(customType, data);\n\t\t\t},\n\t\t\tuiContext: createHookUIContext(),\n\t\t\thasUI: false,\n\t\t});\n\t\thookRunner.onError((err) => {\n\t\t\toutput({ type: \"hook_error\", hookPath: err.hookPath, event: err.event, error: err.error });\n\t\t});\n\t\t// Emit session_start event\n\t\tawait hookRunner.emit({\n\t\t\ttype: \"session_start\",\n\t\t});\n\t}\n\n\t// Emit session start event to custom tools\n\t// Note: Tools get no-op UI context in RPC mode (host handles UI via protocol)\n\tfor (const { tool } of session.customTools) {\n\t\tif (tool.onSession) {\n\t\t\ttry {\n\t\t\t\tawait tool.onSession(\n\t\t\t\t\t{\n\t\t\t\t\t\tpreviousSessionFile: undefined,\n\t\t\t\t\t\treason: \"start\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tsessionManager: session.sessionManager,\n\t\t\t\t\t\tmodelRegistry: session.modelRegistry,\n\t\t\t\t\t\tmodel: session.model,\n\t\t\t\t\t\tisIdle: () => !session.isStreaming,\n\t\t\t\t\t\thasPendingMessages: () => session.pendingMessageCount > 0,\n\t\t\t\t\t\tabort: () => {\n\t\t\t\t\t\t\tsession.abort();\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (_err) {\n\t\t\t\t// Silently ignore tool errors\n\t\t\t}\n\t\t}\n\t}\n\n\t// Output all agent events as JSON\n\tsession.subscribe((event) => {\n\t\toutput(event);\n\t});\n\n\t// Handle a single command\n\tconst handleCommand = async (command: RpcCommand): Promise<RpcResponse> => {\n\t\tconst id = command.id;\n\n\t\tswitch (command.type) {\n\t\t\t// =================================================================\n\t\t\t// Prompting\n\t\t\t// =================================================================\n\n\t\t\tcase \"prompt\": {\n\t\t\t\t// Don't await - events will stream\n\t\t\t\t// Hook commands and file slash commands are handled in session.prompt()\n\t\t\t\tsession\n\t\t\t\t\t.prompt(command.message, {\n\t\t\t\t\t\timages: command.images,\n\t\t\t\t\t})\n\t\t\t\t\t.catch((e) => output(error(id, \"prompt\", e.message)));\n\t\t\t\treturn success(id, \"prompt\");\n\t\t\t}\n\n\t\t\tcase \"steer\": {\n\t\t\t\tawait session.steer(command.message);\n\t\t\t\treturn success(id, \"steer\");\n\t\t\t}\n\n\t\t\tcase \"follow_up\": {\n\t\t\t\tawait session.followUp(command.message);\n\t\t\t\treturn success(id, \"follow_up\");\n\t\t\t}\n\n\t\t\tcase \"abort\": {\n\t\t\t\tawait session.abort();\n\t\t\t\treturn success(id, \"abort\");\n\t\t\t}\n\n\t\t\tcase \"new_session\": {\n\t\t\t\tconst options = command.parentSession ? { parentSession: command.parentSession } : undefined;\n\t\t\t\tconst cancelled = !(await session.newSession(options));\n\t\t\t\treturn success(id, \"new_session\", { cancelled });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// State\n\t\t\t// =================================================================\n\n\t\t\tcase \"get_state\": {\n\t\t\t\tconst state: RpcSessionState = {\n\t\t\t\t\tmodel: session.model,\n\t\t\t\t\tthinkingLevel: session.thinkingLevel,\n\t\t\t\t\tisStreaming: session.isStreaming,\n\t\t\t\t\tisCompacting: session.isCompacting,\n\t\t\t\t\tsteeringMode: session.steeringMode,\n\t\t\t\t\tfollowUpMode: session.followUpMode,\n\t\t\t\t\tsessionFile: session.sessionFile,\n\t\t\t\t\tsessionId: session.sessionId,\n\t\t\t\t\tautoCompactionEnabled: session.autoCompactionEnabled,\n\t\t\t\t\tmessageCount: session.messages.length,\n\t\t\t\t\tpendingMessageCount: session.pendingMessageCount,\n\t\t\t\t};\n\t\t\t\treturn success(id, \"get_state\", state);\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Model\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_model\": {\n\t\t\t\tconst models = await session.getAvailableModels();\n\t\t\t\tconst model = models.find((m) => m.provider === command.provider && m.id === command.modelId);\n\t\t\t\tif (!model) {\n\t\t\t\t\treturn error(id, \"set_model\", `Model not found: ${command.provider}/${command.modelId}`);\n\t\t\t\t}\n\t\t\t\tawait session.setModel(model);\n\t\t\t\treturn success(id, \"set_model\", model);\n\t\t\t}\n\n\t\t\tcase \"cycle_model\": {\n\t\t\t\tconst result = await session.cycleModel();\n\t\t\t\tif (!result) {\n\t\t\t\t\treturn success(id, \"cycle_model\", null);\n\t\t\t\t}\n\t\t\t\treturn success(id, \"cycle_model\", result);\n\t\t\t}\n\n\t\t\tcase \"get_available_models\": {\n\t\t\t\tconst models = await session.getAvailableModels();\n\t\t\t\treturn success(id, \"get_available_models\", { models });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Thinking\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_thinking_level\": {\n\t\t\t\tsession.setThinkingLevel(command.level);\n\t\t\t\treturn success(id, \"set_thinking_level\");\n\t\t\t}\n\n\t\t\tcase \"cycle_thinking_level\": {\n\t\t\t\tconst level = session.cycleThinkingLevel();\n\t\t\t\tif (!level) {\n\t\t\t\t\treturn success(id, \"cycle_thinking_level\", null);\n\t\t\t\t}\n\t\t\t\treturn success(id, \"cycle_thinking_level\", { level });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Queue Modes\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_steering_mode\": {\n\t\t\t\tsession.setSteeringMode(command.mode);\n\t\t\t\treturn success(id, \"set_steering_mode\");\n\t\t\t}\n\n\t\t\tcase \"set_follow_up_mode\": {\n\t\t\t\tsession.setFollowUpMode(command.mode);\n\t\t\t\treturn success(id, \"set_follow_up_mode\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Compaction\n\t\t\t// =================================================================\n\n\t\t\tcase \"compact\": {\n\t\t\t\tconst result = await session.compact(command.customInstructions);\n\t\t\t\treturn success(id, \"compact\", result);\n\t\t\t}\n\n\t\t\tcase \"set_auto_compaction\": {\n\t\t\t\tsession.setAutoCompactionEnabled(command.enabled);\n\t\t\t\treturn success(id, \"set_auto_compaction\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Retry\n\t\t\t// =================================================================\n\n\t\t\tcase \"set_auto_retry\": {\n\t\t\t\tsession.setAutoRetryEnabled(command.enabled);\n\t\t\t\treturn success(id, \"set_auto_retry\");\n\t\t\t}\n\n\t\t\tcase \"abort_retry\": {\n\t\t\t\tsession.abortRetry();\n\t\t\t\treturn success(id, \"abort_retry\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Bash\n\t\t\t// =================================================================\n\n\t\t\tcase \"bash\": {\n\t\t\t\tconst result = await session.executeBash(command.command);\n\t\t\t\treturn success(id, \"bash\", result);\n\t\t\t}\n\n\t\t\tcase \"abort_bash\": {\n\t\t\t\tsession.abortBash();\n\t\t\t\treturn success(id, \"abort_bash\");\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Session\n\t\t\t// =================================================================\n\n\t\t\tcase \"get_session_stats\": {\n\t\t\t\tconst stats = session.getSessionStats();\n\t\t\t\treturn success(id, \"get_session_stats\", stats);\n\t\t\t}\n\n\t\t\tcase \"export_html\": {\n\t\t\t\tconst path = session.exportToHtml(command.outputPath);\n\t\t\t\treturn success(id, \"export_html\", { path });\n\t\t\t}\n\n\t\t\tcase \"switch_session\": {\n\t\t\t\tconst cancelled = !(await session.switchSession(command.sessionPath));\n\t\t\t\treturn success(id, \"switch_session\", { cancelled });\n\t\t\t}\n\n\t\t\tcase \"branch\": {\n\t\t\t\tconst result = await session.branch(command.entryId);\n\t\t\t\treturn success(id, \"branch\", { text: result.selectedText, cancelled: result.cancelled });\n\t\t\t}\n\n\t\t\tcase \"get_branch_messages\": {\n\t\t\t\tconst messages = session.getUserMessagesForBranching();\n\t\t\t\treturn success(id, \"get_branch_messages\", { messages });\n\t\t\t}\n\n\t\t\tcase \"get_last_assistant_text\": {\n\t\t\t\tconst text = session.getLastAssistantText();\n\t\t\t\treturn success(id, \"get_last_assistant_text\", { text });\n\t\t\t}\n\n\t\t\t// =================================================================\n\t\t\t// Messages\n\t\t\t// =================================================================\n\n\t\t\tcase \"get_messages\": {\n\t\t\t\treturn success(id, \"get_messages\", { messages: session.messages });\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tconst unknownCommand = command as { type: string };\n\t\t\t\treturn error(undefined, unknownCommand.type, `Unknown command: ${unknownCommand.type}`);\n\t\t\t}\n\t\t}\n\t};\n\n\t// Listen for JSON input\n\tconst rl = readline.createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t\tterminal: false,\n\t});\n\n\trl.on(\"line\", async (line: string) => {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(line);\n\n\t\t\t// Handle hook UI responses\n\t\t\tif (parsed.type === \"hook_ui_response\") {\n\t\t\t\tconst response = parsed as RpcHookUIResponse;\n\t\t\t\tconst pending = pendingHookRequests.get(response.id);\n\t\t\t\tif (pending) {\n\t\t\t\t\tpendingHookRequests.delete(response.id);\n\t\t\t\t\tpending.resolve(response);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Handle regular commands\n\t\t\tconst command = parsed as RpcCommand;\n\t\t\tconst response = await handleCommand(command);\n\t\t\toutput(response);\n\t\t} catch (e: any) {\n\t\t\toutput(error(undefined, \"parse\", `Failed to parse command: ${e.message}`));\n\t\t}\n\t});\n\n\t// Keep process alive forever\n\treturn new Promise(() => {});\n}\n"]}
|
|
@@ -16,7 +16,11 @@ export type RpcCommand = {
|
|
|
16
16
|
images?: ImageContent[];
|
|
17
17
|
} | {
|
|
18
18
|
id?: string;
|
|
19
|
-
type: "
|
|
19
|
+
type: "steer";
|
|
20
|
+
message: string;
|
|
21
|
+
} | {
|
|
22
|
+
id?: string;
|
|
23
|
+
type: "follow_up";
|
|
20
24
|
message: string;
|
|
21
25
|
} | {
|
|
22
26
|
id?: string;
|
|
@@ -48,7 +52,11 @@ export type RpcCommand = {
|
|
|
48
52
|
type: "cycle_thinking_level";
|
|
49
53
|
} | {
|
|
50
54
|
id?: string;
|
|
51
|
-
type: "
|
|
55
|
+
type: "set_steering_mode";
|
|
56
|
+
mode: "all" | "one-at-a-time";
|
|
57
|
+
} | {
|
|
58
|
+
id?: string;
|
|
59
|
+
type: "set_follow_up_mode";
|
|
52
60
|
mode: "all" | "one-at-a-time";
|
|
53
61
|
} | {
|
|
54
62
|
id?: string;
|
|
@@ -102,12 +110,13 @@ export interface RpcSessionState {
|
|
|
102
110
|
thinkingLevel: ThinkingLevel;
|
|
103
111
|
isStreaming: boolean;
|
|
104
112
|
isCompacting: boolean;
|
|
105
|
-
|
|
113
|
+
steeringMode: "all" | "one-at-a-time";
|
|
114
|
+
followUpMode: "all" | "one-at-a-time";
|
|
106
115
|
sessionFile?: string;
|
|
107
116
|
sessionId: string;
|
|
108
117
|
autoCompactionEnabled: boolean;
|
|
109
118
|
messageCount: number;
|
|
110
|
-
|
|
119
|
+
pendingMessageCount: number;
|
|
111
120
|
}
|
|
112
121
|
export type RpcResponse = {
|
|
113
122
|
id?: string;
|
|
@@ -117,7 +126,12 @@ export type RpcResponse = {
|
|
|
117
126
|
} | {
|
|
118
127
|
id?: string;
|
|
119
128
|
type: "response";
|
|
120
|
-
command: "
|
|
129
|
+
command: "steer";
|
|
130
|
+
success: true;
|
|
131
|
+
} | {
|
|
132
|
+
id?: string;
|
|
133
|
+
type: "response";
|
|
134
|
+
command: "follow_up";
|
|
121
135
|
success: true;
|
|
122
136
|
} | {
|
|
123
137
|
id?: string;
|
|
@@ -178,7 +192,12 @@ export type RpcResponse = {
|
|
|
178
192
|
} | {
|
|
179
193
|
id?: string;
|
|
180
194
|
type: "response";
|
|
181
|
-
command: "
|
|
195
|
+
command: "set_steering_mode";
|
|
196
|
+
success: true;
|
|
197
|
+
} | {
|
|
198
|
+
id?: string;
|
|
199
|
+
type: "response";
|
|
200
|
+
command: "set_follow_up_mode";
|
|
182
201
|
success: true;
|
|
183
202
|
} | {
|
|
184
203
|
id?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,KAAK,EAAE,YA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AAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC/G;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAMpF,oCAAoC;AACpC,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAM7D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AgentMessage, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model } from \"@mariozechner/pi-ai\";\nimport type { SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\nimport type { CompactionResult } from \"../../core/compaction/index.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; images?: ImageContent[] }\n\t| { id?: string; type: \"queue_message\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"new_session\"; parentSession?: string }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue mode\n\t| { id?: string; type: \"set_queue_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryId: string }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel?: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tqueueMode: \"all\" | \"one-at-a-time\";\n\tsessionFile?: string;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tqueuedMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"queue_message\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"new_session\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue mode\n\t| { id?: string; type: \"response\"; command: \"set_queue_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string; cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryId: string; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AgentMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"editor\"; title: string; prefill?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t }\n\t| { type: \"hook_ui_request\"; id: string; method: \"setStatus\"; statusKey: string; statusText: string | undefined }\n\t| { type: \"hook_ui_request\"; id: string; method: \"set_editor_text\"; text: string };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../../src/modes/r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;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC;AAM7D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AgentMessage, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model } from \"@mariozechner/pi-ai\";\nimport type { SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\nimport type { CompactionResult } from \"../../core/compaction/index.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; images?: ImageContent[] }\n\t| { id?: string; type: \"steer\"; message: string }\n\t| { id?: string; type: \"follow_up\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"new_session\"; parentSession?: string }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue modes\n\t| { id?: string; type: \"set_steering_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\t| { id?: string; type: \"set_follow_up_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryId: string }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel?: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\tsessionFile?: string;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tpendingMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"steer\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"follow_up\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"new_session\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue modes\n\t| { id?: string; type: \"response\"; command: \"set_steering_mode\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"set_follow_up_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string; cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryId: string; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AgentMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"editor\"; title: string; prefill?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t }\n\t| { type: \"hook_ui_request\"; id: string; method: \"setStatus\"; statusKey: string; statusText: string | undefined }\n\t| { type: \"hook_ui_request\"; id: string; method: \"set_editor_text\"; text: string };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AgentMessage, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model } from \"@mariozechner/pi-ai\";\nimport type { SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\nimport type { CompactionResult } from \"../../core/compaction/index.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; images?: ImageContent[] }\n\t| { id?: string; type: \"
|
|
1
|
+
{"version":3,"file":"rpc-types.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * RPC protocol types for headless operation.\n *\n * Commands are sent as JSON lines on stdin.\n * Responses and events are emitted as JSON lines on stdout.\n */\n\nimport type { AgentMessage, ThinkingLevel } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Model } from \"@mariozechner/pi-ai\";\nimport type { SessionStats } from \"../../core/agent-session.js\";\nimport type { BashResult } from \"../../core/bash-executor.js\";\nimport type { CompactionResult } from \"../../core/compaction/index.js\";\n\n// ============================================================================\n// RPC Commands (stdin)\n// ============================================================================\n\nexport type RpcCommand =\n\t// Prompting\n\t| { id?: string; type: \"prompt\"; message: string; images?: ImageContent[] }\n\t| { id?: string; type: \"steer\"; message: string }\n\t| { id?: string; type: \"follow_up\"; message: string }\n\t| { id?: string; type: \"abort\" }\n\t| { id?: string; type: \"new_session\"; parentSession?: string }\n\n\t// State\n\t| { id?: string; type: \"get_state\" }\n\n\t// Model\n\t| { id?: string; type: \"set_model\"; provider: string; modelId: string }\n\t| { id?: string; type: \"cycle_model\" }\n\t| { id?: string; type: \"get_available_models\" }\n\n\t// Thinking\n\t| { id?: string; type: \"set_thinking_level\"; level: ThinkingLevel }\n\t| { id?: string; type: \"cycle_thinking_level\" }\n\n\t// Queue modes\n\t| { id?: string; type: \"set_steering_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\t| { id?: string; type: \"set_follow_up_mode\"; mode: \"all\" | \"one-at-a-time\" }\n\n\t// Compaction\n\t| { id?: string; type: \"compact\"; customInstructions?: string }\n\t| { id?: string; type: \"set_auto_compaction\"; enabled: boolean }\n\n\t// Retry\n\t| { id?: string; type: \"set_auto_retry\"; enabled: boolean }\n\t| { id?: string; type: \"abort_retry\" }\n\n\t// Bash\n\t| { id?: string; type: \"bash\"; command: string }\n\t| { id?: string; type: \"abort_bash\" }\n\n\t// Session\n\t| { id?: string; type: \"get_session_stats\" }\n\t| { id?: string; type: \"export_html\"; outputPath?: string }\n\t| { id?: string; type: \"switch_session\"; sessionPath: string }\n\t| { id?: string; type: \"branch\"; entryId: string }\n\t| { id?: string; type: \"get_branch_messages\" }\n\t| { id?: string; type: \"get_last_assistant_text\" }\n\n\t// Messages\n\t| { id?: string; type: \"get_messages\" };\n\n// ============================================================================\n// RPC State\n// ============================================================================\n\nexport interface RpcSessionState {\n\tmodel?: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tsteeringMode: \"all\" | \"one-at-a-time\";\n\tfollowUpMode: \"all\" | \"one-at-a-time\";\n\tsessionFile?: string;\n\tsessionId: string;\n\tautoCompactionEnabled: boolean;\n\tmessageCount: number;\n\tpendingMessageCount: number;\n}\n\n// ============================================================================\n// RPC Responses (stdout)\n// ============================================================================\n\n// Success responses with data\nexport type RpcResponse =\n\t// Prompting (async - events follow)\n\t| { id?: string; type: \"response\"; command: \"prompt\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"steer\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"follow_up\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"new_session\"; success: true; data: { cancelled: boolean } }\n\n\t// State\n\t| { id?: string; type: \"response\"; command: \"get_state\"; success: true; data: RpcSessionState }\n\n\t// Model\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"set_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: Model<any>;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_model\";\n\t\t\tsuccess: true;\n\t\t\tdata: { model: Model<any>; thinkingLevel: ThinkingLevel; isScoped: boolean } | null;\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_available_models\";\n\t\t\tsuccess: true;\n\t\t\tdata: { models: Model<any>[] };\n\t }\n\n\t// Thinking\n\t| { id?: string; type: \"response\"; command: \"set_thinking_level\"; success: true }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"cycle_thinking_level\";\n\t\t\tsuccess: true;\n\t\t\tdata: { level: ThinkingLevel } | null;\n\t }\n\n\t// Queue modes\n\t| { id?: string; type: \"response\"; command: \"set_steering_mode\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"set_follow_up_mode\"; success: true }\n\n\t// Compaction\n\t| { id?: string; type: \"response\"; command: \"compact\"; success: true; data: CompactionResult }\n\t| { id?: string; type: \"response\"; command: \"set_auto_compaction\"; success: true }\n\n\t// Retry\n\t| { id?: string; type: \"response\"; command: \"set_auto_retry\"; success: true }\n\t| { id?: string; type: \"response\"; command: \"abort_retry\"; success: true }\n\n\t// Bash\n\t| { id?: string; type: \"response\"; command: \"bash\"; success: true; data: BashResult }\n\t| { id?: string; type: \"response\"; command: \"abort_bash\"; success: true }\n\n\t// Session\n\t| { id?: string; type: \"response\"; command: \"get_session_stats\"; success: true; data: SessionStats }\n\t| { id?: string; type: \"response\"; command: \"export_html\"; success: true; data: { path: string } }\n\t| { id?: string; type: \"response\"; command: \"switch_session\"; success: true; data: { cancelled: boolean } }\n\t| { id?: string; type: \"response\"; command: \"branch\"; success: true; data: { text: string; cancelled: boolean } }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_branch_messages\";\n\t\t\tsuccess: true;\n\t\t\tdata: { messages: Array<{ entryId: string; text: string }> };\n\t }\n\t| {\n\t\t\tid?: string;\n\t\t\ttype: \"response\";\n\t\t\tcommand: \"get_last_assistant_text\";\n\t\t\tsuccess: true;\n\t\t\tdata: { text: string | null };\n\t }\n\n\t// Messages\n\t| { id?: string; type: \"response\"; command: \"get_messages\"; success: true; data: { messages: AgentMessage[] } }\n\n\t// Error response (any command can fail)\n\t| { id?: string; type: \"response\"; command: string; success: false; error: string };\n\n// ============================================================================\n// Hook UI Events (stdout)\n// ============================================================================\n\n/** Emitted when a hook needs user input */\nexport type RpcHookUIRequest =\n\t| { type: \"hook_ui_request\"; id: string; method: \"select\"; title: string; options: string[] }\n\t| { type: \"hook_ui_request\"; id: string; method: \"confirm\"; title: string; message: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"input\"; title: string; placeholder?: string }\n\t| { type: \"hook_ui_request\"; id: string; method: \"editor\"; title: string; prefill?: string }\n\t| {\n\t\t\ttype: \"hook_ui_request\";\n\t\t\tid: string;\n\t\t\tmethod: \"notify\";\n\t\t\tmessage: string;\n\t\t\tnotifyType?: \"info\" | \"warning\" | \"error\";\n\t }\n\t| { type: \"hook_ui_request\"; id: string; method: \"setStatus\"; statusKey: string; statusText: string | undefined }\n\t| { type: \"hook_ui_request\"; id: string; method: \"set_editor_text\"; text: string };\n\n// ============================================================================\n// Hook UI Commands (stdin)\n// ============================================================================\n\n/** Response to a hook UI request */\nexport type RpcHookUIResponse =\n\t| { type: \"hook_ui_response\"; id: string; value: string }\n\t| { type: \"hook_ui_response\"; id: string; confirmed: boolean }\n\t| { type: \"hook_ui_response\"; id: string; cancelled: true };\n\n// ============================================================================\n// Helper type for extracting command types\n// ============================================================================\n\nexport type RpcCommandType = RpcCommand[\"type\"];\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ImageContent } from "@mariozechner/pi-ai";
|
|
2
|
+
export interface ImageResizeOptions {
|
|
3
|
+
maxWidth?: number;
|
|
4
|
+
maxHeight?: number;
|
|
5
|
+
jpegQuality?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ResizedImage {
|
|
8
|
+
data: string;
|
|
9
|
+
mimeType: string;
|
|
10
|
+
originalWidth: number;
|
|
11
|
+
originalHeight: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
wasResized: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resize an image to fit within the specified max dimensions.
|
|
18
|
+
* Returns the original image if it already fits within the limits.
|
|
19
|
+
*
|
|
20
|
+
* Uses sharp for image processing. If sharp is not available (e.g., in some
|
|
21
|
+
* environments), returns the original image unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage>;
|
|
24
|
+
/**
|
|
25
|
+
* Format a dimension note for resized images.
|
|
26
|
+
* This helps the model understand the coordinate mapping.
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatDimensionNote(result: ResizedImage): string | undefined;
|
|
29
|
+
//# sourceMappingURL=image-resize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-resize.d.ts","sourceRoot":"","sources":["../../src/utils/image-resize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACpB;AAQD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CA2FxG;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAO5E","sourcesContent":["import type { ImageContent } from \"@mariozechner/pi-ai\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tjpegQuality: 80,\n};\n\n/**\n * Resize an image to fit within the specified max dimensions.\n * Returns the original image if it already fits within the limits.\n *\n * Uses sharp for image processing. If sharp is not available (e.g., in some\n * environments), returns the original image unchanged.\n */\nexport async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst buffer = Buffer.from(img.data, \"base64\");\n\n\tlet sharp: typeof import(\"sharp\") | undefined;\n\ttry {\n\t\tsharp = (await import(\"sharp\")).default;\n\t} catch {\n\t\t// Sharp not available - return original image\n\t\t// We can't get dimensions without sharp, so return 0s\n\t\treturn {\n\t\t\tdata: img.data,\n\t\t\tmimeType: img.mimeType,\n\t\t\toriginalWidth: 0,\n\t\t\toriginalHeight: 0,\n\t\t\twidth: 0,\n\t\t\theight: 0,\n\t\t\twasResized: false,\n\t\t};\n\t}\n\n\tconst sharpImg = sharp(buffer);\n\tconst metadata = await sharpImg.metadata();\n\n\tconst width = metadata.width ?? 0;\n\tconst height = metadata.height ?? 0;\n\tconst format = metadata.format ?? img.mimeType?.split(\"/\")[1] ?? \"png\";\n\n\t// Check if already within limits\n\tif (width <= opts.maxWidth && height <= opts.maxHeight) {\n\t\treturn {\n\t\t\tdata: img.data,\n\t\t\tmimeType: img.mimeType ?? `image/${format}`,\n\t\t\toriginalWidth: width,\n\t\t\toriginalHeight: height,\n\t\t\twidth,\n\t\t\theight,\n\t\t\twasResized: false,\n\t\t};\n\t}\n\n\t// Calculate new dimensions maintaining aspect ratio\n\tlet newWidth = width;\n\tlet newHeight = height;\n\n\tif (newWidth > opts.maxWidth) {\n\t\tnewHeight = Math.round((newHeight * opts.maxWidth) / newWidth);\n\t\tnewWidth = opts.maxWidth;\n\t}\n\tif (newHeight > opts.maxHeight) {\n\t\tnewWidth = Math.round((newWidth * opts.maxHeight) / newHeight);\n\t\tnewHeight = opts.maxHeight;\n\t}\n\n\t// Resize the image\n\tconst resized = await sharp(buffer)\n\t\t.resize(newWidth, newHeight, { fit: \"inside\", withoutEnlargement: true })\n\t\t.toBuffer();\n\n\t// Determine output format - preserve original if possible, otherwise use JPEG\n\tlet outputMimeType: string;\n\tlet outputBuffer: Buffer;\n\n\tif (format === \"jpeg\" || format === \"jpg\") {\n\t\toutputBuffer = await sharp(resized).jpeg({ quality: opts.jpegQuality }).toBuffer();\n\t\toutputMimeType = \"image/jpeg\";\n\t} else if (format === \"png\") {\n\t\toutputBuffer = resized;\n\t\toutputMimeType = \"image/png\";\n\t} else if (format === \"gif\") {\n\t\t// GIF resize might not preserve animation; convert to PNG for quality\n\t\toutputBuffer = resized;\n\t\toutputMimeType = \"image/png\";\n\t} else if (format === \"webp\") {\n\t\toutputBuffer = resized;\n\t\toutputMimeType = \"image/webp\";\n\t} else {\n\t\t// Default to JPEG for unknown formats\n\t\toutputBuffer = await sharp(resized).jpeg({ quality: opts.jpegQuality }).toBuffer();\n\t\toutputMimeType = \"image/jpeg\";\n\t}\n\n\treturn {\n\t\tdata: outputBuffer.toString(\"base64\"),\n\t\tmimeType: outputMimeType,\n\t\toriginalWidth: width,\n\t\toriginalHeight: height,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t\twasResized: true,\n\t};\n}\n\n/**\n * Format a dimension note for resized images.\n * This helps the model understand the coordinate mapping.\n */\nexport function formatDimensionNote(result: ResizedImage): string | undefined {\n\tif (!result.wasResized) {\n\t\treturn undefined;\n\t}\n\n\tconst scale = result.originalWidth / result.width;\n\treturn `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;\n}\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
|
+
maxWidth: 2000,
|
|
3
|
+
maxHeight: 2000,
|
|
4
|
+
jpegQuality: 80,
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Resize an image to fit within the specified max dimensions.
|
|
8
|
+
* Returns the original image if it already fits within the limits.
|
|
9
|
+
*
|
|
10
|
+
* Uses sharp for image processing. If sharp is not available (e.g., in some
|
|
11
|
+
* environments), returns the original image unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export async function resizeImage(img, options) {
|
|
14
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
15
|
+
const buffer = Buffer.from(img.data, "base64");
|
|
16
|
+
let sharp;
|
|
17
|
+
try {
|
|
18
|
+
sharp = (await import("sharp")).default;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Sharp not available - return original image
|
|
22
|
+
// We can't get dimensions without sharp, so return 0s
|
|
23
|
+
return {
|
|
24
|
+
data: img.data,
|
|
25
|
+
mimeType: img.mimeType,
|
|
26
|
+
originalWidth: 0,
|
|
27
|
+
originalHeight: 0,
|
|
28
|
+
width: 0,
|
|
29
|
+
height: 0,
|
|
30
|
+
wasResized: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const sharpImg = sharp(buffer);
|
|
34
|
+
const metadata = await sharpImg.metadata();
|
|
35
|
+
const width = metadata.width ?? 0;
|
|
36
|
+
const height = metadata.height ?? 0;
|
|
37
|
+
const format = metadata.format ?? img.mimeType?.split("/")[1] ?? "png";
|
|
38
|
+
// Check if already within limits
|
|
39
|
+
if (width <= opts.maxWidth && height <= opts.maxHeight) {
|
|
40
|
+
return {
|
|
41
|
+
data: img.data,
|
|
42
|
+
mimeType: img.mimeType ?? `image/${format}`,
|
|
43
|
+
originalWidth: width,
|
|
44
|
+
originalHeight: height,
|
|
45
|
+
width,
|
|
46
|
+
height,
|
|
47
|
+
wasResized: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Calculate new dimensions maintaining aspect ratio
|
|
51
|
+
let newWidth = width;
|
|
52
|
+
let newHeight = height;
|
|
53
|
+
if (newWidth > opts.maxWidth) {
|
|
54
|
+
newHeight = Math.round((newHeight * opts.maxWidth) / newWidth);
|
|
55
|
+
newWidth = opts.maxWidth;
|
|
56
|
+
}
|
|
57
|
+
if (newHeight > opts.maxHeight) {
|
|
58
|
+
newWidth = Math.round((newWidth * opts.maxHeight) / newHeight);
|
|
59
|
+
newHeight = opts.maxHeight;
|
|
60
|
+
}
|
|
61
|
+
// Resize the image
|
|
62
|
+
const resized = await sharp(buffer)
|
|
63
|
+
.resize(newWidth, newHeight, { fit: "inside", withoutEnlargement: true })
|
|
64
|
+
.toBuffer();
|
|
65
|
+
// Determine output format - preserve original if possible, otherwise use JPEG
|
|
66
|
+
let outputMimeType;
|
|
67
|
+
let outputBuffer;
|
|
68
|
+
if (format === "jpeg" || format === "jpg") {
|
|
69
|
+
outputBuffer = await sharp(resized).jpeg({ quality: opts.jpegQuality }).toBuffer();
|
|
70
|
+
outputMimeType = "image/jpeg";
|
|
71
|
+
}
|
|
72
|
+
else if (format === "png") {
|
|
73
|
+
outputBuffer = resized;
|
|
74
|
+
outputMimeType = "image/png";
|
|
75
|
+
}
|
|
76
|
+
else if (format === "gif") {
|
|
77
|
+
// GIF resize might not preserve animation; convert to PNG for quality
|
|
78
|
+
outputBuffer = resized;
|
|
79
|
+
outputMimeType = "image/png";
|
|
80
|
+
}
|
|
81
|
+
else if (format === "webp") {
|
|
82
|
+
outputBuffer = resized;
|
|
83
|
+
outputMimeType = "image/webp";
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Default to JPEG for unknown formats
|
|
87
|
+
outputBuffer = await sharp(resized).jpeg({ quality: opts.jpegQuality }).toBuffer();
|
|
88
|
+
outputMimeType = "image/jpeg";
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
data: outputBuffer.toString("base64"),
|
|
92
|
+
mimeType: outputMimeType,
|
|
93
|
+
originalWidth: width,
|
|
94
|
+
originalHeight: height,
|
|
95
|
+
width: newWidth,
|
|
96
|
+
height: newHeight,
|
|
97
|
+
wasResized: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Format a dimension note for resized images.
|
|
102
|
+
* This helps the model understand the coordinate mapping.
|
|
103
|
+
*/
|
|
104
|
+
export function formatDimensionNote(result) {
|
|
105
|
+
if (!result.wasResized) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const scale = result.originalWidth / result.width;
|
|
109
|
+
return `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=image-resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-resize.js","sourceRoot":"","sources":["../../src/utils/image-resize.ts"],"names":[],"mappings":"AAkBA,MAAM,eAAe,GAAiC;IACrD,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,EAAE;CACf,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAiB,EAAE,OAA4B,EAAyB;IACzG,MAAM,IAAI,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE/C,IAAI,KAAyC,CAAC;IAC9C,IAA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AAc,GAAG,YAAY,CAAC;IAC/B,CAAC;SAAM,CAAC;QACP,sCAAsC;QACtC,YAAY,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACnF,cAAc,GAAG,YAAY,CAAC;IAC/B,CAAC;IAED,OAAO;QACN,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACrC,QAAQ,EAAE,cAAc;QACxB,aAAa,EAAE,KAAK;QACpB,cAAc,EAAE,MAAM;QACtB,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE,IAAI;KAChB,CAAC;AAAA,CACF;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAoB,EAAsB;IAC7E,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;IAClD,OAAO,oBAAoB,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,cAAc,kBAAkB,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,6BAA6B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;AAAA,CAClM","sourcesContent":["import type { ImageContent } from \"@mariozechner/pi-ai\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tjpegQuality: 80,\n};\n\n/**\n * Resize an image to fit within the specified max dimensions.\n * Returns the original image if it already fits within the limits.\n *\n * Uses sharp for image processing. If sharp is not available (e.g., in some\n * environments), returns the original image unchanged.\n */\nexport async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst buffer = Buffer.from(img.data, \"base64\");\n\n\tlet sharp: typeof import(\"sharp\") | undefined;\n\ttry {\n\t\tsharp = (await import(\"sharp\")).default;\n\t} catch {\n\t\t// Sharp not available - return original image\n\t\t// We can't get dimensions without sharp, so return 0s\n\t\treturn {\n\t\t\tdata: img.data,\n\t\t\tmimeType: img.mimeType,\n\t\t\toriginalWidth: 0,\n\t\t\toriginalHeight: 0,\n\t\t\twidth: 0,\n\t\t\theight: 0,\n\t\t\twasResized: false,\n\t\t};\n\t}\n\n\tconst sharpImg = sharp(buffer);\n\tconst metadata = await sharpImg.metadata();\n\n\tconst width = metadata.width ?? 0;\n\tconst height = metadata.height ?? 0;\n\tconst format = metadata.format ?? img.mimeType?.split(\"/\")[1] ?? \"png\";\n\n\t// Check if already within limits\n\tif (width <= opts.maxWidth && height <= opts.maxHeight) {\n\t\treturn {\n\t\t\tdata: img.data,\n\t\t\tmimeType: img.mimeType ?? `image/${format}`,\n\t\t\toriginalWidth: width,\n\t\t\toriginalHeight: height,\n\t\t\twidth,\n\t\t\theight,\n\t\t\twasResized: false,\n\t\t};\n\t}\n\n\t// Calculate new dimensions maintaining aspect ratio\n\tlet newWidth = width;\n\tlet newHeight = height;\n\n\tif (newWidth > opts.maxWidth) {\n\t\tnewHeight = Math.round((newHeight * opts.maxWidth) / newWidth);\n\t\tnewWidth = opts.maxWidth;\n\t}\n\tif (newHeight > opts.maxHeight) {\n\t\tnewWidth = Math.round((newWidth * opts.maxHeight) / newHeight);\n\t\tnewHeight = opts.maxHeight;\n\t}\n\n\t// Resize the image\n\tconst resized = await sharp(buffer)\n\t\t.resize(newWidth, newHeight, { fit: \"inside\", withoutEnlargement: true })\n\t\t.toBuffer();\n\n\t// Determine output format - preserve original if possible, otherwise use JPEG\n\tlet outputMimeType: string;\n\tlet outputBuffer: Buffer;\n\n\tif (format === \"jpeg\" || format === \"jpg\") {\n\t\toutputBuffer = await sharp(resized).jpeg({ quality: opts.jpegQuality }).toBuffer();\n\t\toutputMimeType = \"image/jpeg\";\n\t} else if (format === \"png\") {\n\t\toutputBuffer = resized;\n\t\toutputMimeType = \"image/png\";\n\t} else if (format === \"gif\") {\n\t\t// GIF resize might not preserve animation; convert to PNG for quality\n\t\toutputBuffer = resized;\n\t\toutputMimeType = \"image/png\";\n\t} else if (format === \"webp\") {\n\t\toutputBuffer = resized;\n\t\toutputMimeType = \"image/webp\";\n\t} else {\n\t\t// Default to JPEG for unknown formats\n\t\toutputBuffer = await sharp(resized).jpeg({ quality: opts.jpegQuality }).toBuffer();\n\t\toutputMimeType = \"image/jpeg\";\n\t}\n\n\treturn {\n\t\tdata: outputBuffer.toString(\"base64\"),\n\t\tmimeType: outputMimeType,\n\t\toriginalWidth: width,\n\t\toriginalHeight: height,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t\twasResized: true,\n\t};\n}\n\n/**\n * Format a dimension note for resized images.\n * This helps the model understand the coordinate mapping.\n */\nexport function formatDimensionNote(result: ResizedImage): string | undefined {\n\tif (!result.wasResized) {\n\t\treturn undefined;\n\t}\n\n\tconst scale = result.originalWidth / result.width;\n\treturn `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;\n}\n"]}
|
package/docs/hooks.md
CHANGED
|
@@ -465,10 +465,12 @@ const result = await ctx.ui.custom((tui, theme, done) => {
|
|
|
465
465
|
|
|
466
466
|
doWork(loader.signal).then(done).catch(() => done(null));
|
|
467
467
|
|
|
468
|
-
return loader;
|
|
468
|
+
return loader; // Return the component directly, do NOT wrap in Box/Container
|
|
469
469
|
});
|
|
470
470
|
```
|
|
471
471
|
|
|
472
|
+
**Important:** Return your component directly from the callback. Do not wrap it in a `Box` or `Container`, as this breaks input handling.
|
|
473
|
+
|
|
472
474
|
Your component can:
|
|
473
475
|
- Implement `handleInput(data: string)` to receive keyboard input
|
|
474
476
|
- Implement `render(width: number): string[]` to render lines
|
|
@@ -563,13 +565,13 @@ Abort the current agent operation (fire-and-forget, does not wait):
|
|
|
563
565
|
await ctx.abort();
|
|
564
566
|
```
|
|
565
567
|
|
|
566
|
-
### ctx.
|
|
568
|
+
### ctx.hasPendingMessages()
|
|
567
569
|
|
|
568
|
-
Check if there are messages
|
|
570
|
+
Check if there are messages pending (user typed while agent was streaming):
|
|
569
571
|
|
|
570
572
|
```typescript
|
|
571
|
-
if (ctx.
|
|
572
|
-
// Skip interactive prompt, let
|
|
573
|
+
if (ctx.hasPendingMessages()) {
|
|
574
|
+
// Skip interactive prompt, let pending messages take over
|
|
573
575
|
return;
|
|
574
576
|
}
|
|
575
577
|
```
|
|
@@ -636,7 +638,7 @@ const result = await ctx.navigateTree("entry-id-456", {
|
|
|
636
638
|
|
|
637
639
|
Subscribe to events. See [Events](#events) for all event types.
|
|
638
640
|
|
|
639
|
-
### pi.sendMessage(message,
|
|
641
|
+
### pi.sendMessage(message, options?)
|
|
640
642
|
|
|
641
643
|
Inject a message into the session. Creates a `CustomMessageEntry` that participates in the LLM context.
|
|
642
644
|
|
|
@@ -646,12 +648,17 @@ pi.sendMessage({
|
|
|
646
648
|
content: "Message text", // string or (TextContent | ImageContent)[]
|
|
647
649
|
display: true, // Show in TUI
|
|
648
650
|
details: { ... }, // Optional metadata (not sent to LLM)
|
|
649
|
-
},
|
|
651
|
+
}, {
|
|
652
|
+
triggerTurn: true, // If true and agent is idle, triggers LLM response
|
|
653
|
+
deliverAs: "steer", // "steer" (default) or "followUp" when agent is streaming
|
|
654
|
+
});
|
|
650
655
|
```
|
|
651
656
|
|
|
652
657
|
**Storage and timing:**
|
|
653
658
|
- The message is appended to the session file immediately as a `CustomMessageEntry`
|
|
654
|
-
- If the agent is currently streaming
|
|
659
|
+
- If the agent is currently streaming:
|
|
660
|
+
- `deliverAs: "steer"` (default): Delivered after current tool execution, interrupts remaining tools
|
|
661
|
+
- `deliverAs: "followUp"`: Delivered only after agent finishes all work
|
|
655
662
|
- If `triggerTurn` is true and the agent is idle, a new agent loop starts
|
|
656
663
|
|
|
657
664
|
**LLM context:**
|
|
@@ -698,7 +705,7 @@ pi.registerCommand("stats", {
|
|
|
698
705
|
|
|
699
706
|
For long-running commands (e.g., LLM calls), use `ctx.ui.custom()` with a loader. See [examples/hooks/qna.ts](../examples/hooks/qna.ts).
|
|
700
707
|
|
|
701
|
-
To trigger LLM after command, call `pi.sendMessage(..., true)`.
|
|
708
|
+
To trigger LLM after command, call `pi.sendMessage(..., { triggerTurn: true })`.
|
|
702
709
|
|
|
703
710
|
### pi.registerMessageRenderer(customType, renderer)
|
|
704
711
|
|
package/examples/README.md
CHANGED
|
@@ -13,6 +13,12 @@ Example hooks for intercepting tool calls, adding safety gates, and integrating
|
|
|
13
13
|
### [custom-tools/](custom-tools/)
|
|
14
14
|
Example custom tools that extend the agent's capabilities.
|
|
15
15
|
|
|
16
|
+
## Tool + Hook Combinations
|
|
17
|
+
|
|
18
|
+
Some examples are designed to work together:
|
|
19
|
+
|
|
20
|
+
- **todo/** - The [custom tool](custom-tools/todo/) lets the LLM manage a todo list, while the [hook](hooks/todo/) adds a `/todos` command for users to view todos at any time.
|
|
21
|
+
|
|
16
22
|
## Documentation
|
|
17
23
|
|
|
18
24
|
- [SDK Reference](sdk/README.md)
|
|
@@ -19,6 +19,8 @@ Full-featured example demonstrating:
|
|
|
19
19
|
- Proper branching support via details storage
|
|
20
20
|
- State management without external files
|
|
21
21
|
|
|
22
|
+
**Companion hook:** [hooks/todo/](../hooks/todo/) adds a `/todos` command for users to view the todo list.
|
|
23
|
+
|
|
22
24
|
### subagent/
|
|
23
25
|
Delegate tasks to specialized subagents with isolated context windows. Includes:
|
|
24
26
|
- `index.ts` - The custom tool (single, parallel, and chain modes)
|
package/examples/hooks/README.md
CHANGED
|
@@ -28,6 +28,7 @@ cp permission-gate.ts ~/.pi/agent/hooks/
|
|
|
28
28
|
| `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
|
|
29
29
|
| `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
|
|
30
30
|
| `handoff.ts` | Transfer context to a new focused session via `/handoff <goal>` |
|
|
31
|
+
| `todo/` | Adds `/todos` command to view todos managed by the [todo custom tool](../custom-tools/todo/) |
|
|
31
32
|
|
|
32
33
|
## Writing Hooks
|
|
33
34
|
|