@jini-ai/agent-runtime 0.7.2 → 0.7.3-next.2
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 +3 -3
- package/README.md +1 -0
- package/dist/acp-model-probe.d.ts +2 -3
- package/dist/acp-model-probe.js +1 -1
- package/dist/agent-protocol/acp/account-failure.d.ts +3 -1
- package/dist/agent-protocol/acp/account-failure.js +1 -1
- package/dist/agent-protocol/acp/constants.d.ts +6 -1
- package/dist/agent-protocol/acp/constants.js +7 -0
- package/dist/agent-protocol/acp/index.d.ts +2 -1
- package/dist/agent-protocol/acp/index.js +2 -1
- package/dist/agent-protocol/acp/json.d.ts +26 -7
- package/dist/agent-protocol/acp/json.js +11 -11
- package/dist/agent-protocol/acp/models.d.ts +26 -6
- package/dist/agent-protocol/acp/models.js +161 -128
- package/dist/agent-protocol/acp/rpc.d.ts +37 -9
- package/dist/agent-protocol/acp/rpc.js +19 -16
- package/dist/agent-protocol/acp/session-params.d.ts +4 -1
- package/dist/agent-protocol/acp/session-params.js +1 -1
- package/dist/agent-protocol/acp/session-permission.d.ts +13 -0
- package/dist/agent-protocol/acp/session-permission.js +110 -0
- package/dist/agent-protocol/acp/session-results.d.ts +61 -0
- package/dist/agent-protocol/acp/session-results.js +231 -0
- package/dist/agent-protocol/acp/session-run.d.ts +92 -0
- package/dist/agent-protocol/acp/session-run.js +555 -0
- package/dist/agent-protocol/acp/session-state.d.ts +9 -0
- package/dist/agent-protocol/acp/session-state.js +29 -0
- package/dist/agent-protocol/acp/session-text-updates.d.ts +56 -0
- package/dist/agent-protocol/acp/session-text-updates.js +119 -0
- package/dist/agent-protocol/acp/session-tool-updates.d.ts +21 -0
- package/dist/agent-protocol/acp/session-tool-updates.js +90 -0
- package/dist/agent-protocol/acp/session-types.d.ts +166 -0
- package/dist/agent-protocol/acp/session-types.js +4 -0
- package/dist/agent-protocol/acp/session.d.ts +4 -280
- package/dist/agent-protocol/acp/session.js +65 -998
- package/dist/agent-protocol/acp/text-suppression.d.ts +5 -1
- package/dist/agent-protocol/acp/text-suppression.js +1 -1
- package/dist/agent-protocol/acp/updates.d.ts +43 -12
- package/dist/agent-protocol/acp/updates.js +34 -34
- package/dist/agent-protocol/core/json-line-stream.d.ts +133 -36
- package/dist/agent-protocol/core/json-line-stream.js +62 -62
- package/dist/agent-protocol/pi-rpc/events.d.ts +14 -4
- package/dist/agent-protocol/pi-rpc/events.js +14 -14
- package/dist/agent-protocol/pi-rpc/internal.d.ts +9 -3
- package/dist/agent-protocol/pi-rpc/internal.js +3 -3
- package/dist/agent-protocol/pi-rpc/models.d.ts +3 -17
- package/dist/agent-protocol/pi-rpc/models.js +1 -45
- package/dist/agent-protocol/pi-rpc/session.d.ts +36 -12
- package/dist/agent-protocol/pi-rpc/session.js +134 -122
- package/dist/amr-model-cache.d.ts +1 -1
- package/dist/anthropic-live-models.d.ts +8 -3
- package/dist/anthropic-live-models.js +0 -0
- package/dist/auth-common.d.ts +2 -0
- package/dist/auth-common.js +2 -0
- package/dist/auth.d.ts +7 -34
- package/dist/auth.js +25 -139
- package/dist/capabilities.d.ts +1 -1
- package/dist/claude-code-models.d.ts +13 -5
- package/dist/claude-code-models.js +12 -10
- package/dist/claude-filesystem-policy.d.ts +1 -1
- package/dist/claude-stream-frames.d.ts +125 -0
- package/dist/claude-stream-frames.js +327 -0
- package/dist/claude-stream-handler.d.ts +19 -0
- package/dist/claude-stream-handler.js +480 -0
- package/dist/claude-stream.d.ts +3 -72
- package/dist/claude-stream.js +2 -801
- package/dist/core/model-discovery-shared.d.ts +14 -8
- package/dist/core/model-discovery-shared.js +6 -9
- package/dist/core/omit-keys.d.ts +4 -1
- package/dist/core/omit-keys.js +1 -1
- package/dist/defs/aider/executable.d.ts +2 -0
- package/dist/defs/aider/executable.js +2 -0
- package/dist/defs/aider/model-discovery.d.ts +3 -0
- package/dist/defs/aider/model-discovery.js +6 -0
- package/dist/defs/aider.d.ts +10 -10
- package/dist/defs/amp/index.d.ts +35 -0
- package/dist/defs/amp/index.js +75 -0
- package/dist/defs/amp.d.ts +1 -34
- package/dist/defs/amp.js +1 -74
- package/dist/defs/amr/executable-resolution.d.ts +7 -0
- package/dist/defs/amr/executable-resolution.js +50 -0
- package/dist/defs/amr/executable.d.ts +2 -0
- package/dist/defs/amr/executable.js +2 -0
- package/dist/defs/amr/index.d.ts +69 -0
- package/dist/defs/amr/index.js +279 -0
- package/dist/defs/amr/model-discovery.d.ts +3 -0
- package/dist/defs/amr/model-discovery.js +4 -0
- package/dist/defs/amr.d.ts +1 -68
- package/dist/defs/amr.js +1 -291
- package/dist/defs/antigravity/auth.d.ts +14 -0
- package/dist/defs/antigravity/auth.js +47 -0
- package/dist/defs/antigravity/index.d.ts +9 -9
- package/dist/defs/antigravity/index.js +3 -3
- package/dist/defs/antigravity/model-discovery.d.ts +3 -0
- package/dist/defs/antigravity/model-discovery.js +5 -0
- package/dist/defs/auggie/executable.d.ts +2 -0
- package/dist/defs/auggie/executable.js +2 -0
- package/dist/defs/auggie.d.ts +13 -13
- package/dist/defs/auggie.js +2 -9
- package/dist/defs/claude/auth.d.ts +15 -0
- package/dist/defs/claude/auth.js +47 -0
- package/dist/defs/claude/executable.d.ts +2 -0
- package/dist/defs/claude/executable.js +2 -0
- package/dist/defs/claude/model-discovery.d.ts +3 -0
- package/dist/defs/claude/model-discovery.js +20 -0
- package/dist/defs/claude-compatible-args.d.ts +10 -6
- package/dist/defs/claude-compatible-args.js +5 -5
- package/dist/defs/claude.d.ts +11 -11
- package/dist/defs/claude.js +5 -4
- package/dist/defs/cline/executable.d.ts +2 -0
- package/dist/defs/cline/executable.js +2 -0
- package/dist/defs/cline.d.ts +13 -13
- package/dist/defs/cline.js +2 -9
- package/dist/defs/codebuddy/executable.d.ts +2 -0
- package/dist/defs/codebuddy/executable.js +2 -0
- package/dist/defs/codebuddy/index.d.ts +48 -0
- package/dist/defs/codebuddy/index.js +121 -0
- package/dist/defs/codebuddy/model-discovery.d.ts +3 -0
- package/dist/defs/codebuddy/model-discovery.js +5 -0
- package/dist/defs/codebuddy.d.ts +1 -47
- package/dist/defs/codebuddy.js +1 -120
- package/dist/defs/codex/auth.d.ts +4 -0
- package/dist/defs/codex/auth.js +2 -0
- package/dist/defs/codex/event-stream.d.ts +10 -0
- package/dist/defs/codex/event-stream.js +353 -0
- package/dist/defs/codex/executable-resolution.d.ts +7 -0
- package/dist/defs/codex/executable-resolution.js +37 -0
- package/dist/defs/codex/executable.d.ts +2 -0
- package/dist/defs/codex/executable.js +2 -0
- package/dist/defs/codex/launch.d.ts +3 -0
- package/dist/defs/codex/launch.js +155 -0
- package/dist/defs/codex/model-discovery.d.ts +3 -0
- package/dist/defs/codex/model-discovery.js +11 -0
- package/dist/defs/codex/options.d.ts +11 -0
- package/dist/defs/codex/options.js +5 -0
- package/dist/defs/codex.d.ts +18 -11
- package/dist/defs/codex.js +32 -29
- package/dist/defs/crush/executable.d.ts +2 -0
- package/dist/defs/crush/executable.js +2 -0
- package/dist/defs/crush/model-discovery.d.ts +3 -0
- package/dist/defs/crush/model-discovery.js +6 -0
- package/dist/defs/crush.d.ts +10 -10
- package/dist/defs/cursor-agent/auth.d.ts +13 -0
- package/dist/defs/cursor-agent/auth.js +22 -0
- package/dist/defs/cursor-agent/event-stream.d.ts +8 -0
- package/dist/defs/cursor-agent/event-stream.js +104 -0
- package/dist/defs/cursor-agent/executable.d.ts +2 -0
- package/dist/defs/cursor-agent/executable.js +2 -0
- package/dist/defs/cursor-agent/model-discovery.d.ts +3 -0
- package/dist/defs/cursor-agent/model-discovery.js +5 -0
- package/dist/defs/cursor-agent.d.ts +11 -13
- package/dist/defs/cursor-agent.js +1 -1
- package/dist/defs/deepseek/auth.d.ts +13 -0
- package/dist/defs/deepseek/auth.js +18 -0
- package/dist/defs/deepseek/executable.d.ts +2 -0
- package/dist/defs/deepseek/executable.js +2 -0
- package/dist/defs/deepseek/model-discovery.d.ts +3 -0
- package/dist/defs/deepseek/model-discovery.js +5 -0
- package/dist/defs/deepseek.d.ts +10 -10
- package/dist/defs/devin/executable.d.ts +2 -0
- package/dist/defs/devin/executable.js +2 -0
- package/dist/defs/devin.d.ts +15 -15
- package/dist/defs/devin.js +3 -10
- package/dist/defs/droid/executable.d.ts +2 -0
- package/dist/defs/droid/executable.js +2 -0
- package/dist/defs/droid/model-discovery.d.ts +3 -0
- package/dist/defs/droid/model-discovery.js +5 -0
- package/dist/defs/droid.d.ts +10 -10
- package/dist/defs/gemini/event-stream.d.ts +14 -0
- package/dist/defs/gemini/event-stream.js +193 -0
- package/dist/defs/goose/executable.d.ts +2 -0
- package/dist/defs/goose/executable.js +2 -0
- package/dist/defs/goose.d.ts +13 -13
- package/dist/defs/goose.js +2 -9
- package/dist/defs/grok-build/model-discovery.d.ts +3 -0
- package/dist/defs/grok-build/model-discovery.js +5 -0
- package/dist/defs/grok-build.d.ts +10 -10
- package/dist/defs/hermes/executable.d.ts +2 -0
- package/dist/defs/hermes/executable.js +2 -0
- package/dist/defs/hermes/index.d.ts +34 -0
- package/dist/defs/hermes/index.js +57 -0
- package/dist/defs/hermes.d.ts +1 -33
- package/dist/defs/hermes.js +1 -56
- package/dist/defs/index.d.ts +1 -0
- package/dist/defs/index.js +1 -0
- package/dist/defs/kilo/executable.d.ts +2 -0
- package/dist/defs/kilo/executable.js +2 -0
- package/dist/defs/kilo.d.ts +13 -13
- package/dist/defs/kilo.js +2 -9
- package/dist/defs/kimi/event-stream.d.ts +3 -0
- package/dist/defs/kimi/event-stream.js +46 -0
- package/dist/defs/kimi/executable.d.ts +2 -0
- package/dist/defs/kimi/executable.js +2 -0
- package/dist/defs/kimi.d.ts +13 -13
- package/dist/defs/kimi.js +2 -9
- package/dist/defs/kiro/executable.d.ts +2 -0
- package/dist/defs/kiro/executable.js +2 -0
- package/dist/defs/kiro.d.ts +13 -13
- package/dist/defs/kiro.js +2 -9
- package/dist/defs/mimo/executable.d.ts +2 -0
- package/dist/defs/mimo/executable.js +2 -0
- package/dist/defs/mimo/model-discovery.d.ts +3 -0
- package/dist/defs/mimo/model-discovery.js +7 -0
- package/dist/defs/mimo.d.ts +10 -10
- package/dist/defs/opencode/event-stream.d.ts +8 -0
- package/dist/defs/opencode/event-stream.js +108 -0
- package/dist/defs/opencode/executable.d.ts +2 -0
- package/dist/defs/opencode/executable.js +2 -0
- package/dist/defs/opencode/model-discovery.d.ts +4 -0
- package/dist/defs/opencode/model-discovery.js +14 -0
- package/dist/defs/opencode-acp.d.ts +42 -0
- package/dist/defs/opencode-acp.js +23 -0
- package/dist/defs/opencode.d.ts +9 -9
- package/dist/defs/pi/executable.d.ts +2 -0
- package/dist/defs/pi/executable.js +2 -0
- package/dist/defs/pi/model-discovery.d.ts +4 -0
- package/dist/defs/pi/model-discovery.js +16 -0
- package/dist/defs/pi/options.d.ts +11 -0
- package/dist/defs/pi/options.js +5 -0
- package/dist/defs/pi.d.ts +10 -10
- package/dist/defs/qoder/executable.d.ts +2 -0
- package/dist/defs/qoder/executable.js +2 -0
- package/dist/defs/qoder/model-discovery.d.ts +3 -0
- package/dist/defs/qoder/model-discovery.js +7 -0
- package/dist/defs/qoder.d.ts +9 -9
- package/dist/defs/qwen/executable.d.ts +2 -0
- package/dist/defs/qwen/executable.js +2 -0
- package/dist/defs/qwen/model-discovery.d.ts +3 -0
- package/dist/defs/qwen/model-discovery.js +7 -0
- package/dist/defs/qwen.d.ts +10 -10
- package/dist/defs/reasonix/auth.d.ts +13 -0
- package/dist/defs/reasonix/auth.js +18 -0
- package/dist/defs/reasonix/executable.d.ts +2 -0
- package/dist/defs/reasonix/executable.js +2 -0
- package/dist/defs/reasonix.d.ts +13 -13
- package/dist/defs/reasonix.js +2 -9
- package/dist/defs/shared.d.ts +10 -2
- package/dist/defs/shared.js +5 -1
- package/dist/defs/trae-cli/executable.d.ts +2 -0
- package/dist/defs/trae-cli/executable.js +2 -0
- package/dist/defs/trae-cli.d.ts +15 -15
- package/dist/defs/trae-cli.js +2 -9
- package/dist/defs/vibe/executable.d.ts +2 -0
- package/dist/defs/vibe/executable.js +2 -0
- package/dist/defs/vibe.d.ts +13 -13
- package/dist/defs/vibe.js +2 -9
- package/dist/detection.d.ts +4 -3
- package/dist/detection.js +22 -22
- package/dist/diagnostics.d.ts +4 -4
- package/dist/diagnostics.js +2 -2
- package/dist/env.js +2 -1
- package/dist/executable-helpers.d.ts +21 -0
- package/dist/executable-helpers.js +2 -0
- package/dist/executables.d.ts +2 -2
- package/dist/executables.js +68 -114
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -1
- package/dist/invocation.d.ts +22 -6
- package/dist/invocation.js +19 -17
- package/dist/json-event-stream-shared.d.ts +81 -0
- package/dist/json-event-stream-shared.js +147 -0
- package/dist/json-event-stream.d.ts +2 -4
- package/dist/json-event-stream.js +15 -940
- package/dist/launch.d.ts +1 -9
- package/dist/launch.js +6 -155
- package/dist/log-file.d.ts +2 -8
- package/dist/log-file.js +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +1 -1
- package/dist/mmd-routes.d.ts +7 -7
- package/dist/mmd-routes.js +19 -27
- package/dist/model-discovery-adapters.d.ts +47 -11
- package/dist/model-discovery-adapters.js +47 -41
- package/dist/model-discovery-config-types.d.ts +44 -0
- package/dist/model-discovery-config-types.js +20 -0
- package/dist/model-discovery-config.d.ts +19 -11
- package/dist/model-discovery-config.js +64 -87
- package/dist/model-discovery-native.d.ts +2 -1
- package/dist/model-discovery-native.js +3 -3
- package/dist/model-discovery-sdk.d.ts +6 -2
- package/dist/model-discovery-sdk.js +2 -2
- package/dist/model-discovery-types.d.ts +1 -138
- package/dist/model-discovery-yaml.d.ts +3 -1
- package/dist/model-discovery-yaml.js +1 -1
- package/dist/model-discovery.d.ts +15 -5
- package/dist/model-discovery.js +119 -105
- package/dist/model-loading-state.d.ts +1 -1
- package/dist/model-loading-state.js +1 -1
- package/dist/model-registry.d.ts +5 -5
- package/dist/model-registry.js +7 -6
- package/dist/models.d.ts +4 -3
- package/dist/models.js +2 -2
- package/dist/native-permissions.d.ts +47 -0
- package/dist/native-permissions.js +80 -0
- package/dist/native-runtime.d.ts +11 -8
- package/dist/native-runtime.js +8 -4
- package/dist/native-tool-policy.d.ts +1 -40
- package/dist/opencode-log.d.ts +3 -3
- package/dist/opencode-log.js +5 -3
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/pi-models.d.ts +12 -2
- package/dist/pi-models.js +11 -1
- package/dist/prompt-augmenter.d.ts +1 -37
- package/dist/prompt-augmenter.js +0 -6
- package/dist/prompt-budget.d.ts +3 -3
- package/dist/prompt-budget.js +2 -2
- package/dist/prompt-file.d.ts +2 -6
- package/dist/prompt-file.js +1 -1
- package/dist/providers/aihubmix.d.ts +8 -8
- package/dist/providers/aihubmix.js +8 -8
- package/dist/providers/anthropic-messages.d.ts +22 -23
- package/dist/providers/anthropic-messages.js +26 -53
- package/dist/providers/azure-chat.d.ts +7 -6
- package/dist/providers/azure-chat.js +9 -6
- package/dist/providers/connection-guard.d.ts +3 -9
- package/dist/providers/connection-guard.js +6 -14
- package/dist/providers/connection-test.d.ts +1 -2
- package/dist/providers/connection-test.js +51 -51
- package/dist/providers/credentials.d.ts +59 -0
- package/dist/providers/credentials.js +80 -0
- package/dist/providers/elevenlabs.d.ts +2 -6
- package/dist/providers/elevenlabs.js +2 -31
- package/dist/providers/google-messages.d.ts +11 -10
- package/dist/providers/google-messages.js +16 -35
- package/dist/providers/google-schema.d.ts +1 -1
- package/dist/providers/google-schema.js +1 -1
- package/dist/providers/google.d.ts +6 -6
- package/dist/providers/google.js +6 -6
- package/dist/providers/index.d.ts +5 -2
- package/dist/providers/index.js +5 -2
- package/dist/providers/model-catalog.d.ts +4 -9
- package/dist/providers/model-catalog.js +3 -11
- package/dist/providers/oauth-callback-server.js +93 -87
- package/dist/providers/oauth-provider.d.ts +1 -1
- package/dist/providers/oauth-provider.js +1 -1
- package/dist/providers/oauth-tokens.d.ts +5 -5
- package/dist/providers/oauth-tokens.js +8 -9
- package/dist/providers/ollama-chat.d.ts +13 -12
- package/dist/providers/ollama-chat.js +15 -24
- package/dist/providers/openai-chat-request.d.ts +34 -0
- package/dist/providers/openai-chat-request.js +152 -0
- package/dist/providers/openai-chat-stream.d.ts +48 -0
- package/dist/providers/openai-chat-stream.js +89 -0
- package/dist/providers/openai-chat-tool-results.d.ts +81 -0
- package/dist/providers/openai-chat-tool-results.js +124 -0
- package/dist/providers/openai-chat-types.d.ts +180 -0
- package/dist/providers/openai-chat-types.js +3 -0
- package/dist/providers/openai-chat.d.ts +5 -405
- package/dist/providers/openai-chat.js +9 -388
- package/dist/providers/pkce.d.ts +1 -1
- package/dist/providers/pkce.js +1 -1
- package/dist/providers/provider-url.d.ts +6 -0
- package/dist/providers/provider-url.js +9 -0
- package/dist/providers/response-text.d.ts +4 -0
- package/dist/providers/response-text.js +16 -0
- package/dist/providers/sse-decode.d.ts +4 -0
- package/dist/providers/sse-decode.js +11 -0
- package/dist/providers/token-params.d.ts +5 -5
- package/dist/providers/token-params.js +5 -5
- package/dist/providers/tool-loop-verdict.d.ts +1 -1
- package/dist/providers/tool-loop-verdict.js +1 -1
- package/dist/providers/tool-turn-types.d.ts +2 -1
- package/dist/providers/tool-turn.js +30 -50
- package/dist/providers/turn-end-guard.d.ts +4 -1
- package/dist/providers/turn-end-guard.js +1 -1
- package/dist/qoder-stream.d.ts +1 -1
- package/dist/qoder-stream.js +1 -1
- package/dist/registry.d.ts +5 -5
- package/dist/registry.js +4 -4
- package/dist/role-marker-guard.d.ts +13 -1
- package/dist/role-marker-guard.js +15 -1
- package/dist/runtime-def-binding.d.ts +15 -0
- package/dist/runtime-def-binding.js +19 -0
- package/dist/runtime-port-bindings.d.ts +181 -0
- package/dist/runtime-port-bindings.js +95 -0
- package/dist/runtime-state.d.ts +2 -11
- package/dist/runtime-state.js +0 -13
- package/dist/types.d.ts +1 -454
- package/package.json +28 -16
- package/dist/ai-trace/capture.d.ts +0 -17
- package/dist/ai-trace/capture.js +0 -43
- package/dist/ai-trace/classify.d.ts +0 -12
- package/dist/ai-trace/classify.js +0 -16
- package/dist/ai-trace/index.d.ts +0 -13
- package/dist/ai-trace/index.js +0 -6
- package/dist/ai-trace/recorder.d.ts +0 -64
- package/dist/ai-trace/recorder.js +0 -258
- package/dist/ai-trace/sinks.d.ts +0 -51
- package/dist/ai-trace/sinks.js +0 -153
- package/dist/ai-trace/types.d.ts +0 -123
- package/dist/ai-trace/types.js +0 -17
- package/dist/ai-trace/usage.d.ts +0 -13
- package/dist/ai-trace/usage.js +0 -45
- package/dist/copilot-stream.d.ts +0 -65
- package/dist/copilot-stream.js +0 -131
- package/dist/defs/antigravity.d.ts +0 -94
- package/dist/defs/antigravity.js +0 -320
- package/dist/defs/copilot.d.ts +0 -34
- package/dist/defs/copilot.js +0 -96
- package/dist/defs/gemini.d.ts +0 -24
- package/dist/defs/gemini.js +0 -81
- package/dist/model-contracts.d.ts +0 -29
- package/dist/model-contracts.js +0 -2
- package/dist/providers/types.d.ts +0 -36
- package/dist/providers/types.js +0 -13
|
@@ -33,9 +33,9 @@ export declare const MAX_IMAGE_COUNT = 10;
|
|
|
33
33
|
/** Total byte ceiling for all images forwarded in one prompt turn. */
|
|
34
34
|
export declare const MAX_TOTAL_IMAGE_BYTES: number;
|
|
35
35
|
/** File extensions accepted in pi's `images` RPC field. */
|
|
36
|
-
export declare const ALLOWED_IMAGE_EXTENSIONS:
|
|
36
|
+
export declare const ALLOWED_IMAGE_EXTENSIONS: ReadonlySet<string>;
|
|
37
37
|
/** Extension UI methods that expect no response — silently consumed without reply. */
|
|
38
|
-
export declare const FIRE_AND_FORGET_METHODS:
|
|
38
|
+
export declare const FIRE_AND_FORGET_METHODS: ReadonlySet<string>;
|
|
39
39
|
/**
|
|
40
40
|
* Writes a JSON-RPC response to pi's stdin for an `extension_ui_request` event,
|
|
41
41
|
* keeping pi unblocked without surfacing an interactive dialog to the daemon caller.
|
|
@@ -45,8 +45,13 @@ export declare const FIRE_AND_FORGET_METHODS: Set<string>;
|
|
|
45
45
|
* @param writable - The child process stdin stream.
|
|
46
46
|
* @param raw - The parsed `extension_ui_request` RPC object from pi's stdout.
|
|
47
47
|
*/
|
|
48
|
-
export declare function firstDialogOptionResult(opts
|
|
49
|
-
|
|
48
|
+
export declare function firstDialogOptionResult({ opts }: {
|
|
49
|
+
opts: unknown;
|
|
50
|
+
}, _optional?: Record<string, never>): Record<string, unknown>;
|
|
51
|
+
export declare function replyExtensionUi({ writable, raw }: {
|
|
52
|
+
writable: Writable;
|
|
53
|
+
raw: JsonRecord;
|
|
54
|
+
}, _optional?: Record<string, never>): void;
|
|
50
55
|
/** Snapshot of `.pi/sessions/` file metadata taken before a prompt is sent. */
|
|
51
56
|
export type PiSessionFileSnapshot = Map<string, {
|
|
52
57
|
mtimeMs: number;
|
|
@@ -59,7 +64,9 @@ export type PiSessionFileSnapshot = Map<string, {
|
|
|
59
64
|
*
|
|
60
65
|
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
61
66
|
*/
|
|
62
|
-
export declare function readPiSessionFiles(cwd
|
|
67
|
+
export declare function readPiSessionFiles({ cwd }: {
|
|
68
|
+
cwd: string | undefined;
|
|
69
|
+
}, _optional?: Record<string, never>): Array<{
|
|
63
70
|
path: string;
|
|
64
71
|
mtimeMs: number;
|
|
65
72
|
size: number;
|
|
@@ -70,7 +77,9 @@ export declare function readPiSessionFiles(cwd: string | undefined): Array<{
|
|
|
70
77
|
*
|
|
71
78
|
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
72
79
|
*/
|
|
73
|
-
export declare function snapshotPiSessionFiles(cwd
|
|
80
|
+
export declare function snapshotPiSessionFiles({ cwd }: {
|
|
81
|
+
cwd: string | undefined;
|
|
82
|
+
}, _optional?: Record<string, never>): PiSessionFileSnapshot;
|
|
74
83
|
/**
|
|
75
84
|
* Compares the current `.pi/sessions/` directory against a before-snapshot
|
|
76
85
|
* and returns the path of the single changed file. Returns `null` when zero
|
|
@@ -81,9 +90,17 @@ export declare function snapshotPiSessionFiles(cwd: string | undefined): PiSessi
|
|
|
81
90
|
* @param before - Snapshot taken before the prompt was sent.
|
|
82
91
|
* @returns Absolute path of the changed session file, or `null`.
|
|
83
92
|
*/
|
|
84
|
-
export declare function resolveSessionPathChangedSince(cwd
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
export declare function resolveSessionPathChangedSince({ cwd, before }: {
|
|
94
|
+
cwd: string | undefined;
|
|
95
|
+
before: PiSessionFileSnapshot;
|
|
96
|
+
}, _optional?: Record<string, never>): string | null;
|
|
97
|
+
export declare function piImageMimeType({ ext }: {
|
|
98
|
+
ext: string;
|
|
99
|
+
}, _optional?: Record<string, never>): string;
|
|
100
|
+
export declare function isPathUnderRoot({ realPath, resolvedRoot }: {
|
|
101
|
+
realPath: string;
|
|
102
|
+
resolvedRoot: string;
|
|
103
|
+
}, _optional?: Record<string, never>): boolean;
|
|
87
104
|
/**
|
|
88
105
|
* Validates and reads one candidate image path for pi's `images` prompt
|
|
89
106
|
* field: resolves symlinks, re-verifies the resolved path is a regular file
|
|
@@ -91,7 +108,11 @@ export declare function isPathUnderRoot(realPath: string, resolvedRoot: string):
|
|
|
91
108
|
* remaining total-byte budget. Returns `null` for any rejection or read
|
|
92
109
|
* failure rather than throwing, so one bad image never fails the whole run.
|
|
93
110
|
*/
|
|
94
|
-
export declare function tryReadImagePayload(imgPath
|
|
111
|
+
export declare function tryReadImagePayload({ imgPath, uploadRoot, totalBytesSoFar }: {
|
|
112
|
+
imgPath: unknown;
|
|
113
|
+
uploadRoot: string | undefined;
|
|
114
|
+
totalBytesSoFar: number;
|
|
115
|
+
}, _optional?: Record<string, never>): {
|
|
95
116
|
payload: PiImagePayload;
|
|
96
117
|
size: number;
|
|
97
118
|
} | null;
|
|
@@ -102,7 +123,10 @@ export declare function tryReadImagePayload(imgPath: unknown, uploadRoot: string
|
|
|
102
123
|
* daemon's safeImages guard already validated that each path exists under
|
|
103
124
|
* UPLOAD_DIR; see {@link tryReadImagePayload} for the per-path re-checks.
|
|
104
125
|
*/
|
|
105
|
-
export declare function buildPiImagePayloads(imagePaths
|
|
126
|
+
export declare function buildPiImagePayloads({ imagePaths, uploadRoot }: {
|
|
127
|
+
imagePaths: string[] | undefined;
|
|
128
|
+
uploadRoot: string | undefined;
|
|
129
|
+
}, _optional?: Record<string, never>): PiImagePayload[];
|
|
106
130
|
/**
|
|
107
131
|
* Routes one `response`-type frame from pi's RPC stdout: a rejected parent
|
|
108
132
|
* session fails the run immediately (a resumed turn must not continue
|
|
@@ -119,7 +143,7 @@ export declare function handlePiResponseMessage({ raw, parentSessionRpcId, promp
|
|
|
119
143
|
promptRpcId: number | null;
|
|
120
144
|
fail: (message: string, code?: string) => void;
|
|
121
145
|
sendPromptCommand: () => void;
|
|
122
|
-
}): void;
|
|
146
|
+
}, _optional?: Record<string, never>): void;
|
|
123
147
|
/**
|
|
124
148
|
* Attaches the daemon's run lifecycle to an already-spawned `pi --mode rpc` child process.
|
|
125
149
|
*
|
|
@@ -34,15 +34,15 @@ export const FIRE_AND_FORGET_METHODS = new Set([
|
|
|
34
34
|
* @param raw - The parsed `extension_ui_request` RPC object from pi's stdout.
|
|
35
35
|
*/
|
|
36
36
|
// select: pick the first option if available, else cancel.
|
|
37
|
-
export function firstDialogOptionResult(opts) {
|
|
37
|
+
export function firstDialogOptionResult({ opts }, _optional = {}) {
|
|
38
38
|
if (!Array.isArray(opts) || opts.length === 0)
|
|
39
39
|
return { cancelled: true };
|
|
40
40
|
const first = opts[0];
|
|
41
41
|
return typeof first === 'string'
|
|
42
42
|
? { value: first }
|
|
43
|
-
: { value: getRecord(first)?.label ?? getRecord(first)?.value ?? '' };
|
|
43
|
+
: { value: getRecord({ value: first })?.label ?? getRecord({ value: first })?.value ?? '' };
|
|
44
44
|
}
|
|
45
|
-
export function replyExtensionUi(writable, raw) {
|
|
45
|
+
export function replyExtensionUi({ writable, raw }, _optional = {}) {
|
|
46
46
|
if (raw?.id == null)
|
|
47
47
|
return;
|
|
48
48
|
// Fire-and-forget: no response expected. Silently consume.
|
|
@@ -52,7 +52,7 @@ export function replyExtensionUi(writable, raw) {
|
|
|
52
52
|
// confirm → true, select/input/editor → empty-ish default
|
|
53
53
|
const result = raw.method === 'confirm'
|
|
54
54
|
? { confirmed: true }
|
|
55
|
-
: firstDialogOptionResult(getRecord(raw.params)?.options ?? raw.options);
|
|
55
|
+
: firstDialogOptionResult({ opts: getRecord({ value: raw.params })?.options ?? raw.options });
|
|
56
56
|
writable.write(`${JSON.stringify({ type: 'extension_ui_response', id: raw.id, ...result })}\n`);
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
@@ -62,7 +62,7 @@ export function replyExtensionUi(writable, raw) {
|
|
|
62
62
|
*
|
|
63
63
|
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
64
64
|
*/
|
|
65
|
-
export function readPiSessionFiles(cwd) {
|
|
65
|
+
export function readPiSessionFiles({ cwd }, _optional = {}) {
|
|
66
66
|
if (typeof cwd !== 'string' || cwd.length === 0)
|
|
67
67
|
return [];
|
|
68
68
|
const sessionsDir = path.join(cwd, '.pi', 'sessions');
|
|
@@ -94,9 +94,9 @@ export function readPiSessionFiles(cwd) {
|
|
|
94
94
|
*
|
|
95
95
|
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
96
96
|
*/
|
|
97
|
-
export function snapshotPiSessionFiles(cwd) {
|
|
97
|
+
export function snapshotPiSessionFiles({ cwd }, _optional = {}) {
|
|
98
98
|
const snapshot = new Map();
|
|
99
|
-
for (const file of readPiSessionFiles(cwd)) {
|
|
99
|
+
for (const file of readPiSessionFiles({ cwd })) {
|
|
100
100
|
snapshot.set(file.path, { mtimeMs: file.mtimeMs, size: file.size });
|
|
101
101
|
}
|
|
102
102
|
return snapshot;
|
|
@@ -111,8 +111,8 @@ export function snapshotPiSessionFiles(cwd) {
|
|
|
111
111
|
* @param before - Snapshot taken before the prompt was sent.
|
|
112
112
|
* @returns Absolute path of the changed session file, or `null`.
|
|
113
113
|
*/
|
|
114
|
-
export function resolveSessionPathChangedSince(cwd, before) {
|
|
115
|
-
const changed = readPiSessionFiles(cwd).filter((file) => {
|
|
114
|
+
export function resolveSessionPathChangedSince({ cwd, before }, _optional = {}) {
|
|
115
|
+
const changed = readPiSessionFiles({ cwd }).filter((file) => {
|
|
116
116
|
const previous = before.get(file.path);
|
|
117
117
|
return !previous || file.mtimeMs > previous.mtimeMs || file.size !== previous.size;
|
|
118
118
|
});
|
|
@@ -121,7 +121,7 @@ export function resolveSessionPathChangedSince(cwd, before) {
|
|
|
121
121
|
// never actually be exercised.
|
|
122
122
|
return changed.length === 1 ? changed[0].path : null;
|
|
123
123
|
}
|
|
124
|
-
export function piImageMimeType(ext) {
|
|
124
|
+
export function piImageMimeType({ ext }, _optional = {}) {
|
|
125
125
|
if (ext === '.png')
|
|
126
126
|
return 'image/png';
|
|
127
127
|
if (ext === '.gif')
|
|
@@ -137,7 +137,7 @@ export function piImageMimeType(ext) {
|
|
|
137
137
|
// Exported for direct testing: the `+ path.sep` is load-bearing and easy to
|
|
138
138
|
// drop in a later edit, so it is pinned by its own unit test rather than only
|
|
139
139
|
// exercised through `tryReadImagePayload`.
|
|
140
|
-
export function isPathUnderRoot(realPath, resolvedRoot) {
|
|
140
|
+
export function isPathUnderRoot({ realPath, resolvedRoot }, _optional = {}) {
|
|
141
141
|
return realPath === resolvedRoot || realPath.startsWith(resolvedRoot + path.sep);
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
@@ -147,7 +147,7 @@ export function isPathUnderRoot(realPath, resolvedRoot) {
|
|
|
147
147
|
* remaining total-byte budget. Returns `null` for any rejection or read
|
|
148
148
|
* failure rather than throwing, so one bad image never fails the whole run.
|
|
149
149
|
*/
|
|
150
|
-
export function tryReadImagePayload(imgPath, uploadRoot, totalBytesSoFar) {
|
|
150
|
+
export function tryReadImagePayload({ imgPath, uploadRoot, totalBytesSoFar }, _optional = {}) {
|
|
151
151
|
if (typeof imgPath !== 'string' || !imgPath.length)
|
|
152
152
|
return null;
|
|
153
153
|
try {
|
|
@@ -158,7 +158,7 @@ export function tryReadImagePayload(imgPath, uploadRoot, totalBytesSoFar) {
|
|
|
158
158
|
return null;
|
|
159
159
|
if (uploadRoot) {
|
|
160
160
|
const resolvedRoot = fs.realpathSync(uploadRoot);
|
|
161
|
-
if (!isPathUnderRoot(realPath, resolvedRoot))
|
|
161
|
+
if (!isPathUnderRoot({ realPath, resolvedRoot }))
|
|
162
162
|
return null;
|
|
163
163
|
}
|
|
164
164
|
const ext = path.extname(realPath).toLowerCase();
|
|
@@ -169,7 +169,7 @@ export function tryReadImagePayload(imgPath, uploadRoot, totalBytesSoFar) {
|
|
|
169
169
|
return null;
|
|
170
170
|
const buf = fs.readFileSync(realPath);
|
|
171
171
|
return {
|
|
172
|
-
payload: { type: 'image', data: buf.toString('base64'), mimeType: piImageMimeType(ext) },
|
|
172
|
+
payload: { type: 'image', data: buf.toString('base64'), mimeType: piImageMimeType({ ext }) },
|
|
173
173
|
size: stat.size,
|
|
174
174
|
};
|
|
175
175
|
}
|
|
@@ -187,7 +187,7 @@ export function tryReadImagePayload(imgPath, uploadRoot, totalBytesSoFar) {
|
|
|
187
187
|
* daemon's safeImages guard already validated that each path exists under
|
|
188
188
|
* UPLOAD_DIR; see {@link tryReadImagePayload} for the per-path re-checks.
|
|
189
189
|
*/
|
|
190
|
-
export function buildPiImagePayloads(imagePaths, uploadRoot) {
|
|
190
|
+
export function buildPiImagePayloads({ imagePaths, uploadRoot }, _optional = {}) {
|
|
191
191
|
const images = [];
|
|
192
192
|
if (!Array.isArray(imagePaths) || imagePaths.length === 0)
|
|
193
193
|
return images;
|
|
@@ -195,7 +195,7 @@ export function buildPiImagePayloads(imagePaths, uploadRoot) {
|
|
|
195
195
|
for (const imgPath of imagePaths) {
|
|
196
196
|
if (images.length >= MAX_IMAGE_COUNT)
|
|
197
197
|
break;
|
|
198
|
-
const read = tryReadImagePayload(imgPath, uploadRoot, totalBytes);
|
|
198
|
+
const read = tryReadImagePayload({ imgPath, uploadRoot, totalBytesSoFar: totalBytes });
|
|
199
199
|
if (read) {
|
|
200
200
|
images.push(read.payload);
|
|
201
201
|
totalBytes += read.size;
|
|
@@ -213,7 +213,7 @@ export function buildPiImagePayloads(imagePaths, uploadRoot) {
|
|
|
213
213
|
* touches `attachPiRpcSession`'s other session state — so it is directly
|
|
214
214
|
* testable without spinning up a session.
|
|
215
215
|
*/
|
|
216
|
-
export function handlePiResponseMessage({ raw, parentSessionRpcId, promptRpcId, fail, sendPromptCommand, }) {
|
|
216
|
+
export function handlePiResponseMessage({ raw, parentSessionRpcId, promptRpcId, fail, sendPromptCommand, }, _optional = {}) {
|
|
217
217
|
if (raw.id === parentSessionRpcId) {
|
|
218
218
|
if (raw.success === false) {
|
|
219
219
|
fail(`parent session rejected: ${String(raw.error ?? 'unknown')}`, 'PI_PARENT_SESSION_FAILED');
|
|
@@ -250,7 +250,8 @@ export function handlePiResponseMessage({ raw, parentSessionRpcId, promptRpcId,
|
|
|
250
250
|
* @returns A `PiRpcSession` handle with `hasFatalError`, `getLastSessionPath`, and `abort`.
|
|
251
251
|
*/
|
|
252
252
|
export function attachPiRpcSession(requiredArgs, optionalArgs = {}) {
|
|
253
|
-
const
|
|
253
|
+
const options = { ...optionalArgs, ...requiredArgs };
|
|
254
|
+
const { child, cwd, model, send, imagePaths, uploadRoot, parentSession } = options;
|
|
254
255
|
const { stdin, stdout } = child;
|
|
255
256
|
if (stdin === null) {
|
|
256
257
|
throw new Error('pi RPC child process is missing stdin');
|
|
@@ -258,35 +259,11 @@ export function attachPiRpcSession(requiredArgs, optionalArgs = {}) {
|
|
|
258
259
|
if (stdout === null) {
|
|
259
260
|
throw new Error('pi RPC child process is missing stdout');
|
|
260
261
|
}
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
let capturedSessionPath = null;
|
|
267
|
-
let nextRpcId = 1;
|
|
268
|
-
let stdinOpen = true;
|
|
269
|
-
function sendCommand(writable, type, params = {}) {
|
|
270
|
-
if (!stdinOpen)
|
|
271
|
-
return null;
|
|
272
|
-
const id = nextRpcId;
|
|
273
|
-
nextRpcId += 1;
|
|
274
|
-
writable.write(`${JSON.stringify({ id, type, ...params })}\n`);
|
|
275
|
-
return id;
|
|
276
|
-
}
|
|
277
|
-
// Track RPC ids so resume and prompt failures are attributed to the right
|
|
278
|
-
// request. A resumed turn must not send the trimmed prompt until pi confirms
|
|
279
|
-
// it loaded the parent session.
|
|
280
|
-
let parentSessionRpcId = null;
|
|
281
|
-
let promptRpcId = null;
|
|
282
|
-
const fail = (message, code) => {
|
|
283
|
-
if (finished)
|
|
284
|
-
return;
|
|
285
|
-
finished = true;
|
|
286
|
-
fatal = true;
|
|
287
|
-
send({ event: 'error', payload: { message, ...(code ? { code } : {}) } });
|
|
288
|
-
if (!child.killed)
|
|
289
|
-
child.kill('SIGTERM');
|
|
262
|
+
const run = {
|
|
263
|
+
options, stdin, runStartedAt: Date.now(), sessionFilesBeforePrompt: snapshotPiSessionFiles({ cwd }),
|
|
264
|
+
finished: false, fatal: false, sentFirstToken: { value: false }, capturedSessionPath: null,
|
|
265
|
+
nextRpcId: 1, stdinOpen: true, parentSessionRpcId: null, promptRpcId: null,
|
|
266
|
+
images: [],
|
|
290
267
|
};
|
|
291
268
|
// Emit initial status with model name immediately — before pi even
|
|
292
269
|
// responds — so the UI header shows the model name at session start.
|
|
@@ -295,28 +272,12 @@ export function attachPiRpcSession(requiredArgs, optionalArgs = {}) {
|
|
|
295
272
|
label: 'initializing',
|
|
296
273
|
model: typeof model === 'string' && model ? model : null,
|
|
297
274
|
} });
|
|
298
|
-
|
|
299
|
-
stdin.on('error', (err) => {
|
|
300
|
-
if (errorCode(err) !== 'EPIPE') {
|
|
301
|
-
fail(`stdin: ${errorMessage(err)}`);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
stdin.on('close', () => {
|
|
305
|
-
stdinOpen = false;
|
|
306
|
-
});
|
|
307
|
-
// If a prior session file path is provided, send new_session with
|
|
308
|
-
// parentSession so pi loads the prior conversation history into the
|
|
309
|
-
// new session, enabling conversational continuity across edit rounds.
|
|
275
|
+
wirePiStdin(run);
|
|
310
276
|
// Build the images array for pi's prompt command. pi's RPC protocol
|
|
311
277
|
// accepts `images` as an array of {type, data, mimeType} objects where
|
|
312
278
|
// `data` is base64-encoded file contents.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
promptRpcId = sendCommand(stdin, 'prompt', {
|
|
316
|
-
message: prompt,
|
|
317
|
-
...(images.length > 0 ? { images } : {}),
|
|
318
|
-
});
|
|
319
|
-
};
|
|
279
|
+
run.images = buildPiImagePayloads({ imagePaths, uploadRoot });
|
|
280
|
+
// ---- Outbound: send new_session (if parentSession provided) then prompt via RPC ----
|
|
320
281
|
// If a prior session file path is provided, send new_session with
|
|
321
282
|
// parentSession so pi loads the prior conversation history into the
|
|
322
283
|
// new session, enabling conversational continuity across edit rounds.
|
|
@@ -324,85 +285,136 @@ export function attachPiRpcSession(requiredArgs, optionalArgs = {}) {
|
|
|
324
285
|
// intentionally contain only the latest user turn, so continuing after a
|
|
325
286
|
// failed parent load would silently drop prior conversation context.
|
|
326
287
|
if (parentSession) {
|
|
327
|
-
parentSessionRpcId =
|
|
288
|
+
run.parentSessionRpcId = sendPiCommand({ run, type: 'new_session' }, { params: { parentSession } });
|
|
328
289
|
}
|
|
329
290
|
else {
|
|
330
|
-
|
|
291
|
+
sendPiPrompt(run);
|
|
331
292
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
293
|
+
wirePiOutput({ run, child, stdout });
|
|
294
|
+
return buildPiRpcSession(run);
|
|
295
|
+
}
|
|
296
|
+
function sendPiCommand({ run, type }, { params = {} } = {}) {
|
|
297
|
+
if (!run.stdinOpen)
|
|
298
|
+
return null;
|
|
299
|
+
const id = run.nextRpcId;
|
|
300
|
+
run.nextRpcId += 1;
|
|
301
|
+
run.stdin.write(`${JSON.stringify({ id, type, ...params })}\n`);
|
|
302
|
+
return id;
|
|
303
|
+
}
|
|
304
|
+
function sendPiPrompt(run) {
|
|
305
|
+
run.promptRpcId = sendPiCommand({ run, type: 'prompt' }, {
|
|
306
|
+
params: {
|
|
307
|
+
message: run.options.prompt,
|
|
308
|
+
...(run.images.length > 0 ? { images: run.images } : {}),
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function failPi({ run, message }, { code } = {}) {
|
|
313
|
+
if (run.finished)
|
|
314
|
+
return;
|
|
315
|
+
run.finished = true;
|
|
316
|
+
run.fatal = true;
|
|
317
|
+
run.options.send({ event: 'error', payload: { message, ...(code ? { code } : {}) } });
|
|
318
|
+
if (!run.options.child.killed)
|
|
319
|
+
run.options.child.kill('SIGTERM');
|
|
320
|
+
}
|
|
321
|
+
function wirePiStdin(run) {
|
|
322
|
+
run.stdin.on('error', (err) => {
|
|
323
|
+
if (errorCode({ err }) !== 'EPIPE') {
|
|
324
|
+
failPi({ run, message: `stdin: ${errorMessage({ err })}` });
|
|
347
325
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
326
|
+
});
|
|
327
|
+
run.stdin.on('close', () => {
|
|
328
|
+
run.stdinOpen = false;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function handlePiAgentEnd(run) {
|
|
332
|
+
const { child, cwd, gracefulShutdownMs = 5000 } = run.options;
|
|
333
|
+
run.finished = true;
|
|
334
|
+
// Capture only the session file changed by this run. If another pi
|
|
335
|
+
// process wrote to the shared session directory concurrently, the
|
|
336
|
+
// resolver returns null instead of risking cross-conversation resume.
|
|
337
|
+
run.capturedSessionPath = resolveSessionPathChangedSince({ cwd, before: run.sessionFilesBeforePrompt });
|
|
338
|
+
// pi's RPC process stays alive after agent_end (designed for
|
|
339
|
+
// multi-prompt sessions). The daemon's /api/chat is single-shot,
|
|
340
|
+
// so close stdin and let the process exit naturally, or kill it
|
|
341
|
+
// after a grace period.
|
|
342
|
+
try {
|
|
343
|
+
run.stdin.end();
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
failPi({ run, message: `stdin close: ${errorMessage({ err })}` });
|
|
347
|
+
}
|
|
348
|
+
// Grace period before SIGTERM lets resource-constrained machines drain a slow event loop.
|
|
349
|
+
// The host supplies timing explicitly, resolving PI_GRACEFUL_SHUTDOWN_MS at composition.
|
|
350
|
+
setTimeout(() => {
|
|
351
|
+
if (!child.killed)
|
|
352
|
+
child.kill('SIGTERM');
|
|
353
|
+
}, gracefulShutdownMs);
|
|
354
|
+
}
|
|
355
|
+
function handlePiMessage({ run, raw }) {
|
|
356
|
+
if (!isRecord(raw))
|
|
357
|
+
return;
|
|
358
|
+
// Once finished (agent_end or abort), stop processing — the run is
|
|
359
|
+
// over, so no more agent events should be emitted. We still drain
|
|
360
|
+
// stdout via parser.feed() so the pipe doesn't break; we just skip
|
|
361
|
+
// acting on the parsed objects.
|
|
362
|
+
if (run.finished)
|
|
363
|
+
return;
|
|
364
|
+
// Extension UI requests: auto-resolve to keep pi unblocked.
|
|
365
|
+
if (raw.type === 'extension_ui_request') {
|
|
366
|
+
replyExtensionUi({ writable: run.stdin, raw });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (raw.type === 'response') {
|
|
370
|
+
handlePiResponseMessage({
|
|
371
|
+
raw,
|
|
372
|
+
parentSessionRpcId: run.parentSessionRpcId,
|
|
373
|
+
promptRpcId: run.promptRpcId,
|
|
374
|
+
fail: (message, code) => failPi({ run, message }, code === undefined ? {} : { code }),
|
|
375
|
+
sendPromptCommand: () => sendPiPrompt(run),
|
|
376
|
+
});
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
// Agent events: delegate to the pure mapper.
|
|
380
|
+
const result = mapPiRpcEvent({ raw: raw, send: run.options.send, ctx: { runStartedAt: run.runStartedAt, sentFirstToken: run.sentFirstToken } });
|
|
381
|
+
if (result === 'agent_end') {
|
|
382
|
+
handlePiAgentEnd(run);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// ---- Inbound: parse stdout events ----
|
|
386
|
+
function wirePiOutput({ run, child, stdout }) {
|
|
387
|
+
const parser = createJsonLineStream({
|
|
388
|
+
onMessage: ({ message: raw }) => handlePiMessage({ run, raw }),
|
|
389
|
+
}, { onError: error => failPi({ run, message: `parser: ${error.message}` }) });
|
|
380
390
|
stdout.on('data', (chunk) => {
|
|
381
391
|
try {
|
|
382
392
|
parser.feed({ chunk: typeof chunk === 'string' ? chunk : chunk.toString('utf8') });
|
|
383
393
|
}
|
|
384
394
|
catch (err) {
|
|
385
|
-
|
|
395
|
+
failPi({ run, message: `parser: ${errorMessage({ err })}` });
|
|
386
396
|
}
|
|
387
397
|
});
|
|
388
398
|
stdout.on('close', () => parser.flush());
|
|
389
|
-
child.on('error', (err) =>
|
|
399
|
+
child.on('error', (err) => failPi({ run, message: errorMessage({ err }) }));
|
|
400
|
+
}
|
|
401
|
+
function buildPiRpcSession(run) {
|
|
390
402
|
return {
|
|
391
403
|
hasFatalError() {
|
|
392
|
-
return fatal;
|
|
404
|
+
return run.fatal;
|
|
393
405
|
},
|
|
394
406
|
getLastSessionPath() {
|
|
395
|
-
return capturedSessionPath;
|
|
407
|
+
return run.capturedSessionPath;
|
|
396
408
|
},
|
|
397
409
|
abort() {
|
|
398
410
|
// Send RPC abort so pi can clean up gracefully (flush logs,
|
|
399
411
|
// finalize session files, etc.). The termination guarantee
|
|
400
412
|
// (SIGTERM fallback) is owned by the caller (runs.cancel()),
|
|
401
413
|
// not by this method.
|
|
402
|
-
if (finished || child.killed)
|
|
414
|
+
if (run.finished || run.options.child.killed)
|
|
403
415
|
return;
|
|
404
|
-
finished = true;
|
|
405
|
-
|
|
416
|
+
run.finished = true;
|
|
417
|
+
sendPiCommand({ run, type: 'abort' });
|
|
406
418
|
},
|
|
407
419
|
};
|
|
408
420
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Return cached remote models while refreshing, with static presets on cold start. This caching
|
|
4
4
|
* pattern also serves other agents with cheap presets and slower authoritative remote catalogs.
|
|
5
5
|
*/
|
|
6
|
-
import type { RuntimeModelOption } from '
|
|
6
|
+
import type { RuntimeModelOption } from '@jini-ai/core/contracts/agents';
|
|
7
7
|
export type AmrModelsResponse = {
|
|
8
8
|
source: 'remote' | 'preset';
|
|
9
9
|
models: RuntimeModelOption[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { listProviderModels } from './providers/model-catalog.js';
|
|
2
|
-
import type { RuntimeEnv, RuntimeModelOption } from '
|
|
2
|
+
import type { RuntimeEnv, RuntimeModelOption } from '@jini-ai/core/contracts/agents';
|
|
3
3
|
/** Test-only reset — this module-scope cache would otherwise leak a stubbed `fetch`'s result across
|
|
4
4
|
* test cases. */
|
|
5
5
|
export declare function resetAnthropicLiveModelCacheForTesting(): void;
|
|
@@ -19,7 +19,9 @@ export type AnthropicCredential = {
|
|
|
19
19
|
* network call whatsoever.
|
|
20
20
|
* @complexity O(1).
|
|
21
21
|
*/
|
|
22
|
-
export declare function resolveAnthropicCredential(env
|
|
22
|
+
export declare function resolveAnthropicCredential({ env }: {
|
|
23
|
+
env: RuntimeEnv;
|
|
24
|
+
}, _optional?: Record<string, never>): AnthropicCredential | null;
|
|
23
25
|
/**
|
|
24
26
|
* Appends live-discovered models to the static fallback list.
|
|
25
27
|
*
|
|
@@ -29,7 +31,10 @@ export declare function resolveAnthropicCredential(env: RuntimeEnv): AnthropicCr
|
|
|
29
31
|
*
|
|
30
32
|
* @complexity O(f + l) — one `Set` over the fallback, one pass over the live list.
|
|
31
33
|
*/
|
|
32
|
-
export declare function mergeLiveModels(fallback
|
|
34
|
+
export declare function mergeLiveModels({ fallback, live }: {
|
|
35
|
+
fallback: readonly RuntimeModelOption[];
|
|
36
|
+
live: readonly RuntimeModelOption[];
|
|
37
|
+
}, _optional?: Record<string, never>): RuntimeModelOption[];
|
|
33
38
|
/**
|
|
34
39
|
* Returns the Claude model list with the account's live catalog merged in, or `null` when there is
|
|
35
40
|
* nothing to merge.
|
|
Binary file
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type { RuntimeAgentDef, RuntimeEnv } from '
|
|
1
|
+
import type { AgentServiceFailureCode, RuntimeAgentDef, RuntimeEnv } from '@jini-ai/core/contracts/agents';
|
|
2
|
+
export { claudeAuthGuidance, isClaudeAuthFailureText } from './defs/claude/auth.js';
|
|
3
|
+
export { cursorAuthGuidance, isCursorAuthFailureText } from './defs/cursor-agent/auth.js';
|
|
4
|
+
export { deepseekAuthGuidance, isDeepSeekAuthFailureText } from './defs/deepseek/auth.js';
|
|
5
|
+
export { antigravityAuthGuidance, antigravityQuotaGuidance, isAntigravityAuthFailureText } from './defs/antigravity/auth.js';
|
|
6
|
+
export { reasonixAuthGuidance, isReasonixAuthFailureText } from './defs/reasonix/auth.js';
|
|
2
7
|
export type AgentAuthProbeResult = {
|
|
3
8
|
status: 'ok' | 'missing' | 'unknown';
|
|
4
9
|
message?: string;
|
|
@@ -7,47 +12,15 @@ export type AgentAuthProbeResult = {
|
|
|
7
12
|
exitCode?: number | null;
|
|
8
13
|
signal?: string | null;
|
|
9
14
|
};
|
|
10
|
-
export declare function cursorAuthGuidance({}: {}, { hostName }?: {
|
|
11
|
-
hostName?: string;
|
|
12
|
-
}): string;
|
|
13
|
-
export declare function deepseekAuthGuidance({}: {}, { hostName }?: {
|
|
14
|
-
hostName?: string;
|
|
15
|
-
}): string;
|
|
16
|
-
export declare function antigravityAuthGuidance({}: {}, { hostName }?: {
|
|
17
|
-
hostName?: string;
|
|
18
|
-
}): string;
|
|
19
|
-
export declare function antigravityQuotaGuidance(): string;
|
|
20
|
-
export declare function reasonixAuthGuidance({}: {}, { hostName }?: {
|
|
21
|
-
hostName?: string;
|
|
22
|
-
}): string;
|
|
23
|
-
export declare function claudeAuthGuidance({}: {}, { hostName }?: {
|
|
24
|
-
hostName?: string;
|
|
25
|
-
}): string;
|
|
26
|
-
export declare function isCursorAuthFailureText({ text }: {
|
|
27
|
-
text: string;
|
|
28
|
-
}): boolean;
|
|
29
|
-
export declare function isAntigravityAuthFailureText({ text }: {
|
|
30
|
-
text: string;
|
|
31
|
-
}): boolean;
|
|
32
|
-
export declare function isDeepSeekAuthFailureText({ text }: {
|
|
33
|
-
text: string;
|
|
34
|
-
}): boolean;
|
|
35
|
-
export declare function isReasonixAuthFailureText({ text }: {
|
|
36
|
-
text: string;
|
|
37
|
-
}): boolean;
|
|
38
|
-
export declare function isClaudeAuthFailureText({ text }: {
|
|
39
|
-
text: string;
|
|
40
|
-
}): boolean;
|
|
41
15
|
export declare function classifyAgentAuthFailure({ agentId, text }: {
|
|
42
16
|
agentId: string;
|
|
43
17
|
text: string;
|
|
44
18
|
}, { hostName }?: {
|
|
45
19
|
hostName?: string;
|
|
46
20
|
}): AgentAuthProbeResult | null;
|
|
47
|
-
export type AgentServiceFailureCode = 'AGENT_AUTH_REQUIRED' | 'RATE_LIMITED' | 'UPSTREAM_UNAVAILABLE';
|
|
48
21
|
export declare function classifyAgentServiceFailure({ text }: {
|
|
49
22
|
text: string;
|
|
50
|
-
}): AgentServiceFailureCode | null;
|
|
23
|
+
}, _optional?: Record<string, never>): AgentServiceFailureCode | null;
|
|
51
24
|
export declare function probeAgentAuthStatus({ def, resolvedBin, env }: {
|
|
52
25
|
def: Pick<RuntimeAgentDef, 'id' | 'name' | 'authProbe'>;
|
|
53
26
|
resolvedBin: string;
|