@jini-ai/agent-runtime 0.1.0
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/LICENSE +201 -0
- package/README.md +43 -0
- package/dist/acp-model-probe.d.ts +48 -0
- package/dist/acp-model-probe.d.ts.map +1 -0
- package/dist/acp-model-probe.js +15 -0
- package/dist/acp-model-probe.js.map +1 -0
- package/dist/agent-protocol/acp/account-failure.d.ts +54 -0
- package/dist/agent-protocol/acp/account-failure.d.ts.map +1 -0
- package/dist/agent-protocol/acp/account-failure.js +37 -0
- package/dist/agent-protocol/acp/account-failure.js.map +1 -0
- package/dist/agent-protocol/acp/constants.d.ts +26 -0
- package/dist/agent-protocol/acp/constants.d.ts.map +1 -0
- package/dist/agent-protocol/acp/constants.js +39 -0
- package/dist/agent-protocol/acp/constants.js.map +1 -0
- package/dist/agent-protocol/acp/index.d.ts +14 -0
- package/dist/agent-protocol/acp/index.d.ts.map +1 -0
- package/dist/agent-protocol/acp/index.js +14 -0
- package/dist/agent-protocol/acp/index.js.map +1 -0
- package/dist/agent-protocol/acp/json.d.ts +82 -0
- package/dist/agent-protocol/acp/json.d.ts.map +1 -0
- package/dist/agent-protocol/acp/json.js +144 -0
- package/dist/agent-protocol/acp/json.js.map +1 -0
- package/dist/agent-protocol/acp/models.d.ts +112 -0
- package/dist/agent-protocol/acp/models.d.ts.map +1 -0
- package/dist/agent-protocol/acp/models.js +293 -0
- package/dist/agent-protocol/acp/models.js.map +1 -0
- package/dist/agent-protocol/acp/rpc.d.ts +107 -0
- package/dist/agent-protocol/acp/rpc.d.ts.map +1 -0
- package/dist/agent-protocol/acp/rpc.js +162 -0
- package/dist/agent-protocol/acp/rpc.js.map +1 -0
- package/dist/agent-protocol/acp/session-params.d.ts +55 -0
- package/dist/agent-protocol/acp/session-params.d.ts.map +1 -0
- package/dist/agent-protocol/acp/session-params.js +81 -0
- package/dist/agent-protocol/acp/session-params.js.map +1 -0
- package/dist/agent-protocol/acp/session.d.ts +101 -0
- package/dist/agent-protocol/acp/session.d.ts.map +1 -0
- package/dist/agent-protocol/acp/session.js +832 -0
- package/dist/agent-protocol/acp/session.js.map +1 -0
- package/dist/agent-protocol/acp/text-suppression.d.ts +73 -0
- package/dist/agent-protocol/acp/text-suppression.d.ts.map +1 -0
- package/dist/agent-protocol/acp/text-suppression.js +229 -0
- package/dist/agent-protocol/acp/text-suppression.js.map +1 -0
- package/dist/agent-protocol/acp/types.d.ts +27 -0
- package/dist/agent-protocol/acp/types.d.ts.map +1 -0
- package/dist/agent-protocol/acp/types.js +2 -0
- package/dist/agent-protocol/acp/types.js.map +1 -0
- package/dist/agent-protocol/acp/updates.d.ts +166 -0
- package/dist/agent-protocol/acp/updates.d.ts.map +1 -0
- package/dist/agent-protocol/acp/updates.js +268 -0
- package/dist/agent-protocol/acp/updates.js.map +1 -0
- package/dist/agent-protocol/core/index.d.ts +6 -0
- package/dist/agent-protocol/core/index.d.ts.map +1 -0
- package/dist/agent-protocol/core/index.js +6 -0
- package/dist/agent-protocol/core/index.js.map +1 -0
- package/dist/agent-protocol/core/json-line-stream.d.ts +42 -0
- package/dist/agent-protocol/core/json-line-stream.d.ts.map +1 -0
- package/dist/agent-protocol/core/json-line-stream.js +333 -0
- package/dist/agent-protocol/core/json-line-stream.js.map +1 -0
- package/dist/agent-protocol/index.d.ts +8 -0
- package/dist/agent-protocol/index.d.ts.map +1 -0
- package/dist/agent-protocol/index.js +8 -0
- package/dist/agent-protocol/index.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/events.d.ts +26 -0
- package/dist/agent-protocol/pi-rpc/events.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/events.js +167 -0
- package/dist/agent-protocol/pi-rpc/events.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/index.d.ts +11 -0
- package/dist/agent-protocol/pi-rpc/index.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/index.js +11 -0
- package/dist/agent-protocol/pi-rpc/index.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/internal.d.ts +45 -0
- package/dist/agent-protocol/pi-rpc/internal.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/internal.js +41 -0
- package/dist/agent-protocol/pi-rpc/internal.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/models.d.ts +21 -0
- package/dist/agent-protocol/pi-rpc/models.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/models.js +48 -0
- package/dist/agent-protocol/pi-rpc/models.js.map +1 -0
- package/dist/agent-protocol/pi-rpc/session.d.ts +106 -0
- package/dist/agent-protocol/pi-rpc/session.d.ts.map +1 -0
- package/dist/agent-protocol/pi-rpc/session.js +371 -0
- package/dist/agent-protocol/pi-rpc/session.js.map +1 -0
- package/dist/amr-model-cache.d.ts +40 -0
- package/dist/amr-model-cache.d.ts.map +1 -0
- package/dist/amr-model-cache.js +79 -0
- package/dist/amr-model-cache.js.map +1 -0
- package/dist/amr-profile-resolver.d.ts +21 -0
- package/dist/amr-profile-resolver.d.ts.map +1 -0
- package/dist/amr-profile-resolver.js +4 -0
- package/dist/amr-profile-resolver.js.map +1 -0
- package/dist/artifact-taxonomy.d.ts +27 -0
- package/dist/artifact-taxonomy.d.ts.map +1 -0
- package/dist/artifact-taxonomy.js +5 -0
- package/dist/artifact-taxonomy.js.map +1 -0
- package/dist/auth.d.ts +25 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +332 -0
- package/dist/auth.js.map +1 -0
- package/dist/capabilities.d.ts +9 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +2 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/claude-stream.d.ts +37 -0
- package/dist/claude-stream.d.ts.map +1 -0
- package/dist/claude-stream.js +660 -0
- package/dist/claude-stream.js.map +1 -0
- package/dist/copilot-stream.d.ts +37 -0
- package/dist/copilot-stream.d.ts.map +1 -0
- package/dist/copilot-stream.js +136 -0
- package/dist/copilot-stream.js.map +1 -0
- package/dist/defs/aider.d.ts +13 -0
- package/dist/defs/aider.d.ts.map +1 -0
- package/dist/defs/aider.js +63 -0
- package/dist/defs/aider.js.map +1 -0
- package/dist/defs/amp.d.ts +12 -0
- package/dist/defs/amp.d.ts.map +1 -0
- package/dist/defs/amp.js +56 -0
- package/dist/defs/amp.js.map +1 -0
- package/dist/defs/amr.d.ts +37 -0
- package/dist/defs/amr.d.ts.map +1 -0
- package/dist/defs/amr.js +303 -0
- package/dist/defs/amr.js.map +1 -0
- package/dist/defs/antigravity.d.ts +25 -0
- package/dist/defs/antigravity.d.ts.map +1 -0
- package/dist/defs/antigravity.js +213 -0
- package/dist/defs/antigravity.js.map +1 -0
- package/dist/defs/claude.d.ts +30 -0
- package/dist/defs/claude.d.ts.map +1 -0
- package/dist/defs/claude.js +130 -0
- package/dist/defs/claude.js.map +1 -0
- package/dist/defs/codebuddy.d.ts +26 -0
- package/dist/defs/codebuddy.d.ts.map +1 -0
- package/dist/defs/codebuddy.js +124 -0
- package/dist/defs/codebuddy.js.map +1 -0
- package/dist/defs/codex.d.ts +30 -0
- package/dist/defs/codex.d.ts.map +1 -0
- package/dist/defs/codex.js +196 -0
- package/dist/defs/codex.js.map +1 -0
- package/dist/defs/copilot.d.ts +12 -0
- package/dist/defs/copilot.d.ts.map +1 -0
- package/dist/defs/copilot.js +88 -0
- package/dist/defs/copilot.js.map +1 -0
- package/dist/defs/cursor-agent.d.ts +27 -0
- package/dist/defs/cursor-agent.d.ts.map +1 -0
- package/dist/defs/cursor-agent.js +93 -0
- package/dist/defs/cursor-agent.js.map +1 -0
- package/dist/defs/deepseek.d.ts +12 -0
- package/dist/defs/deepseek.d.ts.map +1 -0
- package/dist/defs/deepseek.js +53 -0
- package/dist/defs/deepseek.js.map +1 -0
- package/dist/defs/devin.d.ts +12 -0
- package/dist/defs/devin.d.ts.map +1 -0
- package/dist/defs/devin.js +45 -0
- package/dist/defs/devin.js.map +1 -0
- package/dist/defs/grok-build.d.ts +26 -0
- package/dist/defs/grok-build.d.ts.map +1 -0
- package/dist/defs/grok-build.js +105 -0
- package/dist/defs/grok-build.js.map +1 -0
- package/dist/defs/hermes.d.ts +13 -0
- package/dist/defs/hermes.d.ts.map +1 -0
- package/dist/defs/hermes.js +51 -0
- package/dist/defs/hermes.js.map +1 -0
- package/dist/defs/index.d.ts +33 -0
- package/dist/defs/index.d.ts.map +1 -0
- package/dist/defs/index.js +33 -0
- package/dist/defs/index.js.map +1 -0
- package/dist/defs/kilo.d.ts +12 -0
- package/dist/defs/kilo.d.ts.map +1 -0
- package/dist/defs/kilo.js +20 -0
- package/dist/defs/kilo.js.map +1 -0
- package/dist/defs/kimi.d.ts +13 -0
- package/dist/defs/kimi.d.ts.map +1 -0
- package/dist/defs/kimi.js +26 -0
- package/dist/defs/kimi.js.map +1 -0
- package/dist/defs/kiro.d.ts +12 -0
- package/dist/defs/kiro.d.ts.map +1 -0
- package/dist/defs/kiro.js +20 -0
- package/dist/defs/kiro.js.map +1 -0
- package/dist/defs/mimo.d.ts +13 -0
- package/dist/defs/mimo.d.ts.map +1 -0
- package/dist/defs/mimo.js +26 -0
- package/dist/defs/mimo.js.map +1 -0
- package/dist/defs/opencode.d.ts +27 -0
- package/dist/defs/opencode.d.ts.map +1 -0
- package/dist/defs/opencode.js +89 -0
- package/dist/defs/opencode.js.map +1 -0
- package/dist/defs/pi.d.ts +18 -0
- package/dist/defs/pi.d.ts.map +1 -0
- package/dist/defs/pi.js +94 -0
- package/dist/defs/pi.js.map +1 -0
- package/dist/defs/qoder.d.ts +11 -0
- package/dist/defs/qoder.d.ts.map +1 -0
- package/dist/defs/qoder.js +50 -0
- package/dist/defs/qoder.js.map +1 -0
- package/dist/defs/qwen.d.ts +11 -0
- package/dist/defs/qwen.d.ts.map +1 -0
- package/dist/defs/qwen.js +28 -0
- package/dist/defs/qwen.js.map +1 -0
- package/dist/defs/reasonix.d.ts +20 -0
- package/dist/defs/reasonix.d.ts.map +1 -0
- package/dist/defs/reasonix.js +60 -0
- package/dist/defs/reasonix.js.map +1 -0
- package/dist/defs/shared.d.ts +23 -0
- package/dist/defs/shared.d.ts.map +1 -0
- package/dist/defs/shared.js +58 -0
- package/dist/defs/shared.js.map +1 -0
- package/dist/defs/trae-cli.d.ts +14 -0
- package/dist/defs/trae-cli.d.ts.map +1 -0
- package/dist/defs/trae-cli.js +22 -0
- package/dist/defs/trae-cli.js.map +1 -0
- package/dist/defs/vibe.d.ts +12 -0
- package/dist/defs/vibe.d.ts.map +1 -0
- package/dist/defs/vibe.js +20 -0
- package/dist/defs/vibe.js.map +1 -0
- package/dist/detection.d.ts +14 -0
- package/dist/detection.d.ts.map +1 -0
- package/dist/detection.js +266 -0
- package/dist/detection.js.map +1 -0
- package/dist/diagnostics.d.ts +8 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +95 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +95 -0
- package/dist/env.js.map +1 -0
- package/dist/executables.d.ts +24 -0
- package/dist/executables.d.ts.map +1 -0
- package/dist/executables.js +349 -0
- package/dist/executables.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/invocation.d.ts +6 -0
- package/dist/invocation.d.ts.map +1 -0
- package/dist/invocation.js +47 -0
- package/dist/invocation.js.map +1 -0
- package/dist/json-event-stream.d.ts +9 -0
- package/dist/json-event-stream.d.ts.map +1 -0
- package/dist/json-event-stream.js +856 -0
- package/dist/json-event-stream.js.map +1 -0
- package/dist/launch.d.ts +12 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/launch.js +221 -0
- package/dist/launch.js.map +1 -0
- package/dist/mcp.d.ts +44 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +12 -0
- package/dist/mcp.js.map +1 -0
- package/dist/metadata.d.ts +24 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +100 -0
- package/dist/metadata.js.map +1 -0
- package/dist/mmd-routes.d.ts +12 -0
- package/dist/mmd-routes.d.ts.map +1 -0
- package/dist/mmd-routes.js +146 -0
- package/dist/mmd-routes.js.map +1 -0
- package/dist/model-registry.d.ts +120 -0
- package/dist/model-registry.d.ts.map +1 -0
- package/dist/model-registry.js +77 -0
- package/dist/model-registry.js.map +1 -0
- package/dist/models.d.ts +16 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +93 -0
- package/dist/models.js.map +1 -0
- package/dist/opencode-log.d.ts +16 -0
- package/dist/opencode-log.d.ts.map +1 -0
- package/dist/opencode-log.js +163 -0
- package/dist/opencode-log.js.map +1 -0
- package/dist/paths.d.ts +3 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +29 -0
- package/dist/paths.js.map +1 -0
- package/dist/pi-models.d.ts +13 -0
- package/dist/pi-models.d.ts.map +1 -0
- package/dist/pi-models.js +36 -0
- package/dist/pi-models.js.map +1 -0
- package/dist/prompt-augmenter.d.ts +60 -0
- package/dist/prompt-augmenter.d.ts.map +1 -0
- package/dist/prompt-augmenter.js +26 -0
- package/dist/prompt-augmenter.js.map +1 -0
- package/dist/prompt-budget.d.ts +20 -0
- package/dist/prompt-budget.d.ts.map +1 -0
- package/dist/prompt-budget.js +226 -0
- package/dist/prompt-budget.js.map +1 -0
- package/dist/prompt-file.d.ts +7 -0
- package/dist/prompt-file.d.ts.map +1 -0
- package/dist/prompt-file.js +27 -0
- package/dist/prompt-file.js.map +1 -0
- package/dist/providers/aihubmix.d.ts +99 -0
- package/dist/providers/aihubmix.d.ts.map +1 -0
- package/dist/providers/aihubmix.js +239 -0
- package/dist/providers/aihubmix.js.map +1 -0
- package/dist/providers/anthropic-messages.d.ts +116 -0
- package/dist/providers/anthropic-messages.d.ts.map +1 -0
- package/dist/providers/anthropic-messages.js +313 -0
- package/dist/providers/anthropic-messages.js.map +1 -0
- package/dist/providers/azure-chat.d.ts +99 -0
- package/dist/providers/azure-chat.d.ts.map +1 -0
- package/dist/providers/azure-chat.js +164 -0
- package/dist/providers/azure-chat.js.map +1 -0
- package/dist/providers/connection-guard.d.ts +67 -0
- package/dist/providers/connection-guard.d.ts.map +1 -0
- package/dist/providers/connection-guard.js +211 -0
- package/dist/providers/connection-guard.js.map +1 -0
- package/dist/providers/elevenlabs.d.ts +28 -0
- package/dist/providers/elevenlabs.d.ts.map +1 -0
- package/dist/providers/elevenlabs.js +138 -0
- package/dist/providers/elevenlabs.js.map +1 -0
- package/dist/providers/google-messages.d.ts +108 -0
- package/dist/providers/google-messages.d.ts.map +1 -0
- package/dist/providers/google-messages.js +284 -0
- package/dist/providers/google-messages.js.map +1 -0
- package/dist/providers/google.d.ts +20 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/index.d.ts +39 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +39 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/model-catalog.d.ts +32 -0
- package/dist/providers/model-catalog.d.ts.map +1 -0
- package/dist/providers/model-catalog.js +394 -0
- package/dist/providers/model-catalog.js.map +1 -0
- package/dist/providers/oauth-callback-server.d.ts +35 -0
- package/dist/providers/oauth-callback-server.d.ts.map +1 -0
- package/dist/providers/oauth-callback-server.js +217 -0
- package/dist/providers/oauth-callback-server.js.map +1 -0
- package/dist/providers/oauth-credentials.d.ts +29 -0
- package/dist/providers/oauth-credentials.d.ts.map +1 -0
- package/dist/providers/oauth-credentials.js +70 -0
- package/dist/providers/oauth-credentials.js.map +1 -0
- package/dist/providers/oauth-provider.d.ts +95 -0
- package/dist/providers/oauth-provider.d.ts.map +1 -0
- package/dist/providers/oauth-provider.js +130 -0
- package/dist/providers/oauth-provider.js.map +1 -0
- package/dist/providers/oauth-tokens.d.ts +35 -0
- package/dist/providers/oauth-tokens.d.ts.map +1 -0
- package/dist/providers/oauth-tokens.js +136 -0
- package/dist/providers/oauth-tokens.js.map +1 -0
- package/dist/providers/ollama-chat.d.ts +106 -0
- package/dist/providers/ollama-chat.d.ts.map +1 -0
- package/dist/providers/ollama-chat.js +292 -0
- package/dist/providers/ollama-chat.js.map +1 -0
- package/dist/providers/openai-chat.d.ts +147 -0
- package/dist/providers/openai-chat.d.ts.map +1 -0
- package/dist/providers/openai-chat.js +302 -0
- package/dist/providers/openai-chat.js.map +1 -0
- package/dist/providers/pkce.d.ts +81 -0
- package/dist/providers/pkce.d.ts.map +1 -0
- package/dist/providers/pkce.js +176 -0
- package/dist/providers/pkce.js.map +1 -0
- package/dist/providers/sse-decode.d.ts +47 -0
- package/dist/providers/sse-decode.d.ts.map +1 -0
- package/dist/providers/sse-decode.js +109 -0
- package/dist/providers/sse-decode.js.map +1 -0
- package/dist/providers/token-params.d.ts +29 -0
- package/dist/providers/token-params.d.ts.map +1 -0
- package/dist/providers/token-params.js +41 -0
- package/dist/providers/token-params.js.map +1 -0
- package/dist/providers/turn-end-guard.d.ts +37 -0
- package/dist/providers/turn-end-guard.d.ts.map +1 -0
- package/dist/providers/turn-end-guard.js +42 -0
- package/dist/providers/turn-end-guard.js.map +1 -0
- package/dist/providers/types.d.ts +36 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +13 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/qoder-stream.d.ts +19 -0
- package/dist/qoder-stream.d.ts.map +1 -0
- package/dist/qoder-stream.js +167 -0
- package/dist/qoder-stream.js.map +1 -0
- package/dist/registry.d.ts +5 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +58 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolution.d.ts +2 -0
- package/dist/resolution.d.ts.map +1 -0
- package/dist/resolution.js +19 -0
- package/dist/resolution.js.map +1 -0
- package/dist/role-marker-guard.d.ts +53 -0
- package/dist/role-marker-guard.d.ts.map +1 -0
- package/dist/role-marker-guard.js +280 -0
- package/dist/role-marker-guard.js.map +1 -0
- package/dist/telemetry-sink.d.ts +35 -0
- package/dist/telemetry-sink.d.ts.map +1 -0
- package/dist/telemetry-sink.js +5 -0
- package/dist/telemetry-sink.js.map +1 -0
- package/dist/terminal-launch.d.ts +11 -0
- package/dist/terminal-launch.d.ts.map +1 -0
- package/dist/terminal-launch.js +123 -0
- package/dist/terminal-launch.js.map +1 -0
- package/dist/types.d.ts +185 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/** @module agent-protocol/pi-rpc/session
|
|
2
|
+
* Attaches a pi `--mode rpc` session to an already-spawned child process.
|
|
3
|
+
* Owns prompt delivery, session-file capture, image forwarding (with count and
|
|
4
|
+
* byte budgets), extension-UI auto-resolution, and abort signalling.
|
|
5
|
+
* Consumes `createJsonLineStream` from core/ and `mapPiRpcEvent` from pi-rpc/events.
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { createJsonLineStream } from '../core/index.js';
|
|
10
|
+
import { mapPiRpcEvent } from './events.js';
|
|
11
|
+
import { isRecord, errorMessage, errorCode, getRecord } from './internal.js';
|
|
12
|
+
// Image forwarding budgets to prevent large synchronous base64 work.
|
|
13
|
+
/** Maximum number of images forwarded per prompt turn. */
|
|
14
|
+
export const MAX_IMAGE_COUNT = 10;
|
|
15
|
+
/** Total byte ceiling for all images forwarded in one prompt turn. */
|
|
16
|
+
export const MAX_TOTAL_IMAGE_BYTES = 20 * 1024 * 1024; // 20 MB
|
|
17
|
+
/** File extensions accepted in pi's `images` RPC field. */
|
|
18
|
+
export const ALLOWED_IMAGE_EXTENSIONS = new Set(['.png', '.jpg', '.jpeg', '.gif', '.webp']);
|
|
19
|
+
/** Extension UI methods that expect no response — silently consumed without reply. */
|
|
20
|
+
export const FIRE_AND_FORGET_METHODS = new Set([
|
|
21
|
+
'setStatus',
|
|
22
|
+
'setWidget',
|
|
23
|
+
'notify',
|
|
24
|
+
'setTitle',
|
|
25
|
+
'set_editor_text',
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* Writes a JSON-RPC response to pi's stdin for an `extension_ui_request` event,
|
|
29
|
+
* keeping pi unblocked without surfacing an interactive dialog to the daemon caller.
|
|
30
|
+
* Fire-and-forget methods are silently consumed. Dialog methods are auto-resolved:
|
|
31
|
+
* `confirm` → `{ confirmed: true }`; select/input/editor → first option or cancelled.
|
|
32
|
+
*
|
|
33
|
+
* @param writable - The child process stdin stream.
|
|
34
|
+
* @param raw - The parsed `extension_ui_request` RPC object from pi's stdout.
|
|
35
|
+
*/
|
|
36
|
+
export function replyExtensionUi(writable, raw) {
|
|
37
|
+
if (raw?.id == null)
|
|
38
|
+
return;
|
|
39
|
+
// Fire-and-forget: no response expected. Silently consume.
|
|
40
|
+
if (typeof raw.method === 'string' && FIRE_AND_FORGET_METHODS.has(raw.method))
|
|
41
|
+
return;
|
|
42
|
+
// Dialog methods: auto-resolve to keep pi unblocked.
|
|
43
|
+
// confirm → true, select/input/editor → empty-ish default
|
|
44
|
+
let result;
|
|
45
|
+
if (raw.method === 'confirm') {
|
|
46
|
+
result = { confirmed: true };
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// select: pick first option if available, else cancel
|
|
50
|
+
const params = getRecord(raw.params);
|
|
51
|
+
const opts = params?.options ?? raw.options;
|
|
52
|
+
if (Array.isArray(opts) && opts.length > 0) {
|
|
53
|
+
const first = opts[0];
|
|
54
|
+
result =
|
|
55
|
+
typeof first === 'string'
|
|
56
|
+
? { value: first }
|
|
57
|
+
: { value: getRecord(first)?.label ?? getRecord(first)?.value ?? '' };
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
result = { cancelled: true };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
writable.write(`${JSON.stringify({ type: 'extension_ui_response', id: raw.id, ...result })}\n`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads `.pi/sessions/*.jsonl` entries from the given working directory,
|
|
67
|
+
* returning file paths with their mtime and size. Returns an empty array
|
|
68
|
+
* when the directory is absent, empty, or unreadable.
|
|
69
|
+
*
|
|
70
|
+
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
71
|
+
*/
|
|
72
|
+
export function readPiSessionFiles(cwd) {
|
|
73
|
+
if (typeof cwd !== 'string' || cwd.length === 0)
|
|
74
|
+
return [];
|
|
75
|
+
const sessionsDir = path.join(cwd, '.pi', 'sessions');
|
|
76
|
+
let entries;
|
|
77
|
+
try {
|
|
78
|
+
entries = fs.readdirSync(sessionsDir, { withFileTypes: true });
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const files = [];
|
|
84
|
+
for (const entry of entries) {
|
|
85
|
+
if (!entry.isFile() || !entry.name.endsWith('.jsonl'))
|
|
86
|
+
continue;
|
|
87
|
+
try {
|
|
88
|
+
const full = path.join(sessionsDir, entry.name);
|
|
89
|
+
const stat = fs.statSync(full);
|
|
90
|
+
files.push({ path: full, mtimeMs: stat.mtimeMs, size: stat.size });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Skip unreadable entries.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return files;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Takes a before-snapshot of `.pi/sessions/` to enable changed-file detection
|
|
100
|
+
* after the prompt completes.
|
|
101
|
+
*
|
|
102
|
+
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
103
|
+
*/
|
|
104
|
+
export function snapshotPiSessionFiles(cwd) {
|
|
105
|
+
const snapshot = new Map();
|
|
106
|
+
for (const file of readPiSessionFiles(cwd)) {
|
|
107
|
+
snapshot.set(file.path, { mtimeMs: file.mtimeMs, size: file.size });
|
|
108
|
+
}
|
|
109
|
+
return snapshot;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Compares the current `.pi/sessions/` directory against a before-snapshot
|
|
113
|
+
* and returns the path of the single changed file. Returns `null` when zero
|
|
114
|
+
* or more than one file changed — concurrent pi processes are detected this
|
|
115
|
+
* way to avoid associating the wrong session with this run.
|
|
116
|
+
*
|
|
117
|
+
* @param cwd - Absolute path to the pi working directory; may be undefined.
|
|
118
|
+
* @param before - Snapshot taken before the prompt was sent.
|
|
119
|
+
* @returns Absolute path of the changed session file, or `null`.
|
|
120
|
+
*/
|
|
121
|
+
export function resolveSessionPathChangedSince(cwd, before) {
|
|
122
|
+
const changed = readPiSessionFiles(cwd).filter((file) => {
|
|
123
|
+
const previous = before.get(file.path);
|
|
124
|
+
return !previous || file.mtimeMs > previous.mtimeMs || file.size !== previous.size;
|
|
125
|
+
});
|
|
126
|
+
// `changed.length === 1` guarantees `changed[0]` is defined; the non-null
|
|
127
|
+
// assertion documents that instead of a `?? null` fallback that could
|
|
128
|
+
// never actually be exercised.
|
|
129
|
+
return changed.length === 1 ? changed[0].path : null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Attaches the daemon's run lifecycle to an already-spawned `pi --mode rpc` child process.
|
|
133
|
+
*
|
|
134
|
+
* Responsibilities:
|
|
135
|
+
* - Sends a `new_session` RPC command (with `parentSession`) before the prompt when
|
|
136
|
+
* resuming a prior conversation, waiting for acknowledgement before the prompt is sent.
|
|
137
|
+
* This preserves conversation history across edit rounds; if the parent session is
|
|
138
|
+
* rejected, the run is failed immediately rather than continuing without prior context.
|
|
139
|
+
* - Encodes and forwards `imagePaths` as base64 in the `prompt` RPC command, subject to
|
|
140
|
+
* `MAX_IMAGE_COUNT` and `MAX_TOTAL_IMAGE_BYTES` budgets. Symlinks are resolved via
|
|
141
|
+
* `realpathSync` and re-verified against `uploadRoot` to prevent path-escape attacks.
|
|
142
|
+
* - Streams pi's stdout through `createJsonLineStream`, delegating each parsed object to
|
|
143
|
+
* `mapPiRpcEvent` for typed SSE event dispatch, and auto-resolving extension-UI requests
|
|
144
|
+
* via `replyExtensionUi` so pi does not block waiting for interactive dialogs.
|
|
145
|
+
* - On `agent_end`, captures the changed `.pi/sessions/` file path for conversational
|
|
146
|
+
* resume, closes stdin, and schedules a SIGTERM fallback after
|
|
147
|
+
* `PI_GRACEFUL_SHUTDOWN_MS` ms (default 5000).
|
|
148
|
+
*
|
|
149
|
+
* @param options - Session parameters: child process, prompt string, optional model,
|
|
150
|
+
* image paths, upload root for symlink verification, and optional
|
|
151
|
+
* parent session path for conversation resume.
|
|
152
|
+
* @returns A `PiRpcSession` handle with `hasFatalError`, `getLastSessionPath`, and `abort`.
|
|
153
|
+
*/
|
|
154
|
+
export function attachPiRpcSession({ child, prompt, cwd, model, send, imagePaths, uploadRoot, parentSession, }) {
|
|
155
|
+
const stdin = child.stdin;
|
|
156
|
+
const stdout = child.stdout;
|
|
157
|
+
if (stdin === null) {
|
|
158
|
+
throw new Error('pi RPC child process is missing stdin');
|
|
159
|
+
}
|
|
160
|
+
if (stdout === null) {
|
|
161
|
+
throw new Error('pi RPC child process is missing stdout');
|
|
162
|
+
}
|
|
163
|
+
const runStartedAt = Date.now();
|
|
164
|
+
const sessionFilesBeforePrompt = snapshotPiSessionFiles(cwd);
|
|
165
|
+
let finished = false;
|
|
166
|
+
let fatal = false;
|
|
167
|
+
const sentFirstToken = { value: false };
|
|
168
|
+
let capturedSessionPath = null;
|
|
169
|
+
let nextRpcId = 1;
|
|
170
|
+
let stdinOpen = true;
|
|
171
|
+
function sendCommand(writable, type, params = {}) {
|
|
172
|
+
if (!stdinOpen)
|
|
173
|
+
return null;
|
|
174
|
+
const id = nextRpcId++;
|
|
175
|
+
writable.write(`${JSON.stringify({ id, type, ...params })}\n`);
|
|
176
|
+
return id;
|
|
177
|
+
}
|
|
178
|
+
// Track RPC ids so resume and prompt failures are attributed to the right
|
|
179
|
+
// request. A resumed turn must not send the trimmed prompt until pi confirms
|
|
180
|
+
// it loaded the parent session.
|
|
181
|
+
let parentSessionRpcId = null;
|
|
182
|
+
let promptRpcId = null;
|
|
183
|
+
const fail = (message, code) => {
|
|
184
|
+
if (finished)
|
|
185
|
+
return;
|
|
186
|
+
finished = true;
|
|
187
|
+
fatal = true;
|
|
188
|
+
send('error', { message, ...(code ? { code } : {}) });
|
|
189
|
+
if (!child.killed)
|
|
190
|
+
child.kill('SIGTERM');
|
|
191
|
+
};
|
|
192
|
+
// Emit initial status with model name immediately — before pi even
|
|
193
|
+
// responds — so the UI header shows the model name at session start.
|
|
194
|
+
send('agent', {
|
|
195
|
+
type: 'status',
|
|
196
|
+
label: 'initializing',
|
|
197
|
+
model: typeof model === 'string' && model ? model : null,
|
|
198
|
+
});
|
|
199
|
+
// ---- Outbound: send new_session (if parentSession provided) then prompt via RPC ----
|
|
200
|
+
stdin.on('error', (err) => {
|
|
201
|
+
if (errorCode(err) !== 'EPIPE') {
|
|
202
|
+
fail(`stdin: ${errorMessage(err)}`);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
stdin.on('close', () => {
|
|
206
|
+
stdinOpen = false;
|
|
207
|
+
});
|
|
208
|
+
// If a prior session file path is provided, send new_session with
|
|
209
|
+
// parentSession so pi loads the prior conversation history into the
|
|
210
|
+
// new session, enabling conversational continuity across edit rounds.
|
|
211
|
+
// Build the images array for pi's prompt command. pi's RPC protocol
|
|
212
|
+
// accepts `images` as an array of {type, data, mimeType} objects where
|
|
213
|
+
// `data` is base64-encoded file contents. The daemon's safeImages guard
|
|
214
|
+
// already validated that each path exists under UPLOAD_DIR.
|
|
215
|
+
//
|
|
216
|
+
// Security: realpath resolves symlinks so we re-check that the resolved
|
|
217
|
+
// path is still a regular file (no /proc/self/mem or symlink escape).
|
|
218
|
+
// We also enforce a count and total-byte budget to prevent large
|
|
219
|
+
// synchronous base64 reads from blocking the event loop.
|
|
220
|
+
const images = [];
|
|
221
|
+
if (Array.isArray(imagePaths) && imagePaths.length > 0) {
|
|
222
|
+
let totalBytes = 0;
|
|
223
|
+
for (const imgPath of imagePaths) {
|
|
224
|
+
if (images.length >= MAX_IMAGE_COUNT)
|
|
225
|
+
break;
|
|
226
|
+
if (typeof imgPath !== 'string' || !imgPath.length)
|
|
227
|
+
continue;
|
|
228
|
+
try {
|
|
229
|
+
// Resolve symlinks and verify it's a regular file.
|
|
230
|
+
const realPath = fs.realpathSync(imgPath);
|
|
231
|
+
const stat = fs.statSync(realPath);
|
|
232
|
+
if (!stat.isFile())
|
|
233
|
+
continue;
|
|
234
|
+
// Re-verify the resolved path stays inside the upload root.
|
|
235
|
+
// Without this, a path that passed server.ts's safeImages prefix
|
|
236
|
+
// check (under UPLOAD_DIR) could be a symlink pointing to a file
|
|
237
|
+
// outside UPLOAD_DIR, and we'd read/base64-forward it to pi.
|
|
238
|
+
if (uploadRoot) {
|
|
239
|
+
const resolvedRoot = fs.realpathSync(uploadRoot);
|
|
240
|
+
if (realPath !== resolvedRoot && !realPath.startsWith(resolvedRoot + path.sep))
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const ext = path.extname(realPath).toLowerCase();
|
|
244
|
+
if (!ALLOWED_IMAGE_EXTENSIONS.has(ext))
|
|
245
|
+
continue;
|
|
246
|
+
// Enforce total byte budget.
|
|
247
|
+
if (totalBytes + stat.size > MAX_TOTAL_IMAGE_BYTES)
|
|
248
|
+
continue;
|
|
249
|
+
const buf = fs.readFileSync(realPath);
|
|
250
|
+
const mimeType = ext === '.png' ? 'image/png' :
|
|
251
|
+
ext === '.gif' ? 'image/gif' :
|
|
252
|
+
ext === '.webp' ? 'image/webp' :
|
|
253
|
+
'image/jpeg'; // .jpg, .jpeg, and unknown
|
|
254
|
+
images.push({
|
|
255
|
+
type: 'image',
|
|
256
|
+
data: buf.toString('base64'),
|
|
257
|
+
mimeType,
|
|
258
|
+
});
|
|
259
|
+
totalBytes += stat.size;
|
|
260
|
+
}
|
|
261
|
+
catch (_err) {
|
|
262
|
+
// Skip unreadable images rather than failing the entire run.
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const sendPromptCommand = () => {
|
|
267
|
+
promptRpcId = sendCommand(stdin, 'prompt', {
|
|
268
|
+
message: prompt,
|
|
269
|
+
...(images.length > 0 ? { images } : {}),
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
// If a prior session file path is provided, send new_session with
|
|
273
|
+
// parentSession so pi loads the prior conversation history into the
|
|
274
|
+
// new session, enabling conversational continuity across edit rounds.
|
|
275
|
+
// Do not send the prompt until pi acknowledges this RPC: resumed prompts
|
|
276
|
+
// intentionally contain only the latest user turn, so continuing after a
|
|
277
|
+
// failed parent load would silently drop prior conversation context.
|
|
278
|
+
if (parentSession) {
|
|
279
|
+
parentSessionRpcId = sendCommand(stdin, 'new_session', { parentSession });
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
sendPromptCommand();
|
|
283
|
+
}
|
|
284
|
+
// ---- Inbound: parse stdout events ----
|
|
285
|
+
const parser = createJsonLineStream((raw) => {
|
|
286
|
+
if (!isRecord(raw))
|
|
287
|
+
return;
|
|
288
|
+
// Once finished (agent_end or abort), stop processing — the run is
|
|
289
|
+
// over, so no more agent events should be emitted. We still drain
|
|
290
|
+
// stdout via parser.feed() so the pipe doesn't break; we just skip
|
|
291
|
+
// acting on the parsed objects.
|
|
292
|
+
if (finished)
|
|
293
|
+
return;
|
|
294
|
+
// Extension UI requests: auto-resolve to keep pi unblocked.
|
|
295
|
+
if (raw.type === 'extension_ui_request') {
|
|
296
|
+
replyExtensionUi(stdin, raw);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
// RPC responses (prompt accepted, set_model ack, etc.) — not
|
|
300
|
+
// agent events. Log the prompt acceptance, ignore the rest.
|
|
301
|
+
if (raw.type === 'response') {
|
|
302
|
+
if (raw.id === parentSessionRpcId) {
|
|
303
|
+
if (raw.success === false) {
|
|
304
|
+
fail(`parent session rejected: ${String(raw.error ?? 'unknown')}`, 'PI_PARENT_SESSION_FAILED');
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
sendPromptCommand();
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (raw.id === promptRpcId && raw.success === false) {
|
|
311
|
+
fail(`prompt rejected: ${String(raw.error ?? 'unknown')}`);
|
|
312
|
+
}
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// Agent events: delegate to the pure mapper.
|
|
316
|
+
const result = mapPiRpcEvent(raw, send, { runStartedAt, sentFirstToken });
|
|
317
|
+
if (result === 'agent_end') {
|
|
318
|
+
finished = true;
|
|
319
|
+
// Capture only the session file changed by this run. If another pi
|
|
320
|
+
// process wrote to the shared session directory concurrently, the
|
|
321
|
+
// resolver returns null instead of risking cross-conversation resume.
|
|
322
|
+
capturedSessionPath = resolveSessionPathChangedSince(cwd, sessionFilesBeforePrompt);
|
|
323
|
+
// pi's RPC process stays alive after agent_end (designed for
|
|
324
|
+
// multi-prompt sessions). The daemon's /api/chat is single-shot,
|
|
325
|
+
// so close stdin and let the process exit naturally, or kill it
|
|
326
|
+
// after a grace period.
|
|
327
|
+
try {
|
|
328
|
+
stdin.end();
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
fail(`stdin close: ${errorMessage(err)}`);
|
|
332
|
+
}
|
|
333
|
+
// Grace period before SIGTERM. Configurable via PI_GRACEFUL_SHUTDOWN_MS
|
|
334
|
+
// for resource-constrained machines where the event loop drains slowly.
|
|
335
|
+
const shutdownMs = Number(process.env.PI_GRACEFUL_SHUTDOWN_MS) || 5000;
|
|
336
|
+
setTimeout(() => {
|
|
337
|
+
if (!child.killed)
|
|
338
|
+
child.kill('SIGTERM');
|
|
339
|
+
}, shutdownMs);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
stdout.on('data', (chunk) => {
|
|
343
|
+
try {
|
|
344
|
+
parser.feed(typeof chunk === 'string' ? chunk : chunk.toString('utf8'));
|
|
345
|
+
}
|
|
346
|
+
catch (err) {
|
|
347
|
+
fail(`parser: ${errorMessage(err)}`);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
stdout.on('close', () => parser.flush());
|
|
351
|
+
child.on('error', (err) => fail(errorMessage(err)));
|
|
352
|
+
return {
|
|
353
|
+
hasFatalError() {
|
|
354
|
+
return fatal;
|
|
355
|
+
},
|
|
356
|
+
getLastSessionPath() {
|
|
357
|
+
return capturedSessionPath;
|
|
358
|
+
},
|
|
359
|
+
abort() {
|
|
360
|
+
// Send RPC abort so pi can clean up gracefully (flush logs,
|
|
361
|
+
// finalize session files, etc.). The termination guarantee
|
|
362
|
+
// (SIGTERM fallback) is owned by the caller (runs.cancel()),
|
|
363
|
+
// not by this method.
|
|
364
|
+
if (finished || child.killed)
|
|
365
|
+
return;
|
|
366
|
+
finished = true;
|
|
367
|
+
sendCommand(stdin, 'abort');
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/agent-protocol/pi-rpc/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AA2B7E,qEAAqE;AACrE,0DAA0D;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,sEAAsE;AACtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,QAAQ;AAC/D,2DAA2D;AAC3D,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,GAAG,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alog cache that returns a cached remote list instantly
|
|
5
|
+
* while refreshing in the background, falling back to a static preset
|
|
6
|
+
* list on cold start. Ported verbatim from OD's
|
|
7
|
+
* `apps/daemon/src/runtimes/amr/amr-model-cache.ts` with one change: the
|
|
8
|
+
* `AmrModelsResponse` return type is now vendored locally (a small,
|
|
9
|
+
* self-contained shape) instead of imported from OD's contracts workspace
|
|
10
|
+
* package.
|
|
11
|
+
*
|
|
12
|
+
* Named for its origin use (the AMR/vela agent's live model list), but the
|
|
13
|
+
* caching pattern itself is generic to any agent with a similarly-shaped
|
|
14
|
+
* "cheap static preset + slower authoritative remote list" catalog.
|
|
15
|
+
*/
|
|
16
|
+
import type { RuntimeModelOption } from './types.js';
|
|
17
|
+
export type AmrModelsResponse = {
|
|
18
|
+
source: 'remote' | 'preset';
|
|
19
|
+
models: RuntimeModelOption[];
|
|
20
|
+
refreshing: boolean;
|
|
21
|
+
stale?: boolean;
|
|
22
|
+
remoteError?: string;
|
|
23
|
+
};
|
|
24
|
+
type Fetchers = {
|
|
25
|
+
fetchPreset: () => Promise<RuntimeModelOption[]>;
|
|
26
|
+
fetchRemote: () => Promise<RuntimeModelOption[]>;
|
|
27
|
+
};
|
|
28
|
+
export declare class AmrModelLoadingCache {
|
|
29
|
+
private readonly refreshIntervalMs;
|
|
30
|
+
private readonly states;
|
|
31
|
+
constructor(refreshIntervalMs?: number);
|
|
32
|
+
get(cacheKey: string, fetchers: Fetchers): Promise<AmrModelsResponse>;
|
|
33
|
+
warm(cacheKey: string, fetchRemote: () => Promise<RuntimeModelOption[]>): void;
|
|
34
|
+
resetForTests(): void;
|
|
35
|
+
private stateFor;
|
|
36
|
+
private startRefresh;
|
|
37
|
+
}
|
|
38
|
+
export declare const amrModelLoadingCache: AmrModelLoadingCache;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=amr-model-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amr-model-cache.d.ts","sourceRoot":"","sources":["../src/amr-model-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAOF,KAAK,QAAQ,GAAG;IACd,WAAW,EAAE,MAAM,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACjD,WAAW,EAAE,MAAM,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAClD,CAAC;AAsBF,qBAAa,oBAAoB;IAGnB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAF9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiC;gBAE3B,iBAAiB,SAAqC;IAE7E,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAyB3E,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC,kBAAkB,EAAE,CAAC,GAAG,IAAI;IAI9E,aAAa,IAAI,IAAI;IAIrB,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,YAAY;CAiBrB;AAED,eAAO,MAAM,oBAAoB,sBAA6B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The AMR model catalog changes rarely (new models land on the order of
|
|
2
|
+
// days), and a cached remote list is returned immediately while a refresh
|
|
3
|
+
// runs in the background — `get()` never blocks on the network when a
|
|
4
|
+
// cached entry exists. The per-run preflight also reads this cache, so a
|
|
5
|
+
// tight interval would spawn `vela model list` far more often than the
|
|
6
|
+
// catalog actually changes. Refresh at most once every 10 minutes per
|
|
7
|
+
// cache key; callers always get the last-known catalog instantly in
|
|
8
|
+
// between.
|
|
9
|
+
const DEFAULT_REMOTE_REFRESH_INTERVAL_MS = 10 * 60_000;
|
|
10
|
+
function errorMessage(error) {
|
|
11
|
+
return error instanceof Error ? error.message : String(error ?? 'unknown error');
|
|
12
|
+
}
|
|
13
|
+
export class AmrModelLoadingCache {
|
|
14
|
+
refreshIntervalMs;
|
|
15
|
+
states = new Map();
|
|
16
|
+
constructor(refreshIntervalMs = DEFAULT_REMOTE_REFRESH_INTERVAL_MS) {
|
|
17
|
+
this.refreshIntervalMs = refreshIntervalMs;
|
|
18
|
+
}
|
|
19
|
+
async get(cacheKey, fetchers) {
|
|
20
|
+
const state = this.stateFor(cacheKey);
|
|
21
|
+
const now = Date.now();
|
|
22
|
+
if (state.remote) {
|
|
23
|
+
const staleByAge = now - state.remote.fetchedAt >= this.refreshIntervalMs;
|
|
24
|
+
if (staleByAge)
|
|
25
|
+
this.startRefresh(state, fetchers.fetchRemote);
|
|
26
|
+
return {
|
|
27
|
+
source: 'remote',
|
|
28
|
+
models: state.remote.models,
|
|
29
|
+
refreshing: state.inFlight !== null,
|
|
30
|
+
...(state.inFlight || state.lastRemoteError ? { stale: true } : {}),
|
|
31
|
+
...(state.lastRemoteError ? { remoteError: state.lastRemoteError } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const preset = await fetchers.fetchPreset();
|
|
35
|
+
this.startRefresh(state, fetchers.fetchRemote);
|
|
36
|
+
return {
|
|
37
|
+
source: 'preset',
|
|
38
|
+
models: preset,
|
|
39
|
+
refreshing: state.inFlight !== null,
|
|
40
|
+
...(state.lastRemoteError ? { remoteError: state.lastRemoteError } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
warm(cacheKey, fetchRemote) {
|
|
44
|
+
this.startRefresh(this.stateFor(cacheKey), fetchRemote);
|
|
45
|
+
}
|
|
46
|
+
resetForTests() {
|
|
47
|
+
this.states.clear();
|
|
48
|
+
}
|
|
49
|
+
stateFor(cacheKey) {
|
|
50
|
+
const existing = this.states.get(cacheKey);
|
|
51
|
+
if (existing)
|
|
52
|
+
return existing;
|
|
53
|
+
const created = { remote: null, inFlight: null, lastRemoteError: null };
|
|
54
|
+
this.states.set(cacheKey, created);
|
|
55
|
+
return created;
|
|
56
|
+
}
|
|
57
|
+
startRefresh(state, fetchRemote) {
|
|
58
|
+
if (state.inFlight)
|
|
59
|
+
return;
|
|
60
|
+
state.inFlight = (async () => {
|
|
61
|
+
try {
|
|
62
|
+
const models = await fetchRemote();
|
|
63
|
+
if (models.length === 0) {
|
|
64
|
+
throw new Error('AMR remote model list returned no chat models');
|
|
65
|
+
}
|
|
66
|
+
state.remote = { models, fetchedAt: Date.now() };
|
|
67
|
+
state.lastRemoteError = null;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
state.lastRemoteError = errorMessage(error);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
state.inFlight = null;
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export const amrModelLoadingCache = new AmrModelLoadingCache();
|
|
79
|
+
//# sourceMappingURL=amr-model-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amr-model-cache.js","sourceRoot":"","sources":["../src/amr-model-cache.ts"],"names":[],"mappings":"AAyCA,wEAAwE;AACxE,0EAA0E;AAC1E,sEAAsE;AACtE,yEAAyE;AACzE,uEAAuE;AACvE,sEAAsE;AACtE,oEAAoE;AACpE,WAAW;AACX,MAAM,kCAAkC,GAAG,EAAE,GAAG,MAAM,CAAC;AAEvD,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,eAAe,CAAC,CAAC;AACnF,CAAC;AAED,MAAM,OA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EAAE,CAAC;gBACf,KAAK,CAAC,eAAe,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAC9C,CAAC;oBAAS,CAAC;gBACT,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module amr-profile-resolver
|
|
3
|
+
*
|
|
4
|
+
* Port replacing OD's `resolveAmrProfile` import
|
|
5
|
+
* (`apps/daemon/src/integrations/vela.js`) inside `detection.ts`. OD uses
|
|
6
|
+
* this to scope the remembered-live-models cache for the `amr` agent id by
|
|
7
|
+
* "profile" — an AMR/vela-vendor concept (which OpenRouter-compatible
|
|
8
|
+
* account/link config is active) that has no generic runtime meaning.
|
|
9
|
+
*
|
|
10
|
+
* `detection.ts` accepts an `AmrProfileResolver` and calls it only for the
|
|
11
|
+
* `amr` def id; every other agent's scoping is unaffected. The default
|
|
12
|
+
* no-op resolver returns a constant scope (equivalent to "no profile
|
|
13
|
+
* scoping"), so a non-OD consumer's AMR-model cache degrades gracefully —
|
|
14
|
+
* it just doesn't split by profile — until it supplies a real resolver.
|
|
15
|
+
*/
|
|
16
|
+
export interface AmrProfileResolver {
|
|
17
|
+
/** Return a scope key for the `amr` agent's remembered-live-models cache, derived from the spawn env. */
|
|
18
|
+
resolveProfile(env: NodeJS.ProcessEnv): string;
|
|
19
|
+
}
|
|
20
|
+
export declare const noopAmrProfileResolver: AmrProfileResolver;
|
|
21
|
+
//# sourceMappingURL=amr-profile-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amr-profile-resolver.d.ts","sourceRoot":"","sources":["../src/amr-profile-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,kBAAkB;IACjC,yGAAyG;IACzG,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;CAChD;AAED,eAAO,MAAM,sBAAsB,EAAE,kBAEpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amr-profile-resolver.js","sourceRoot":"","sources":["../src/amr-profile-resolver.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,sBAAsB,GAAuB;IACxD,cAAc,EAAE,GAAG,EAAE,CAAC,SAAS;CAChC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module artifact-taxonomy
|
|
3
|
+
*
|
|
4
|
+
* Port replacing the classification half of OD's
|
|
5
|
+
* `runtimes/runs/run-artifacts.ts` (`isArtifactPath`, `isDesignSystemFile`,
|
|
6
|
+
* `isPreviewModulePath`, `didRunCreateDesignSystemFile`,
|
|
7
|
+
* `countDesignSystemPreviewModules`). That file's real behavior is entirely
|
|
8
|
+
* OD-product classification (HTML-prototype/SVG/design-system-file
|
|
9
|
+
* taxonomy feeding PostHog `run_finished.artifact_count` /
|
|
10
|
+
* `design_system_created` analytics) plus OD-specific imports into OD's own
|
|
11
|
+
* analytics-contracts and question-form-detection modules — none of it is
|
|
12
|
+
* ported.
|
|
13
|
+
*
|
|
14
|
+
* Per r1b §1b, only the taxonomy/classification *interface* belongs to
|
|
15
|
+
* this package. `ArtifactTaxonomy`'s companion `ArtifactStore` (actual
|
|
16
|
+
* read/write persistence) is explicitly a later storage/sqlite task's
|
|
17
|
+
* concern — not defined here.
|
|
18
|
+
*/
|
|
19
|
+
export interface ArtifactTaxonomy {
|
|
20
|
+
/** Does this file path count as a user-facing artifact? (OD: html/svg/prototype/live-artifact.) */
|
|
21
|
+
isArtifact(path: string): boolean;
|
|
22
|
+
/** Optional finer buckets a host tracks for analytics; the engine treats all buckets as opaque. */
|
|
23
|
+
classify?(path: string): string | null;
|
|
24
|
+
}
|
|
25
|
+
/** Classifies nothing as an artifact and provides no finer buckets — a safe default until a host supplies its own taxonomy. */
|
|
26
|
+
export declare const noopArtifactTaxonomy: ArtifactTaxonomy;
|
|
27
|
+
//# sourceMappingURL=artifact-taxonomy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-taxonomy.d.ts","sourceRoot":"","sources":["../src/artifact-taxonomy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mGAAmG;IACnG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,mGAAmG;IACnG,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,+HAA+H;AAC/H,eAAO,MAAM,oBAAoB,EAAE,gBAElC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-taxonomy.js","sourceRoot":"","sources":["../src/artifact-taxonomy.ts"],"names":[],"mappings":"AAyBA,+HAA+H;AAC/H,MAAM,CAAC,MAAM,oBAAoB,GAAqB;IACpD,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK;CACxB,CAAC"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RuntimeAgentDef, RuntimeEnv } from './types.js';
|
|
2
|
+
export type AgentAuthProbeResult = {
|
|
3
|
+
status: 'ok' | 'missing' | 'unknown';
|
|
4
|
+
message?: string;
|
|
5
|
+
stdoutTail?: string;
|
|
6
|
+
stderrTail?: string;
|
|
7
|
+
exitCode?: number | null;
|
|
8
|
+
signal?: string | null;
|
|
9
|
+
};
|
|
10
|
+
export declare function cursorAuthGuidance(hostName?: string): string;
|
|
11
|
+
export declare function deepseekAuthGuidance(hostName?: string): string;
|
|
12
|
+
export declare function antigravityAuthGuidance(hostName?: string): string;
|
|
13
|
+
export declare function antigravityQuotaGuidance(): string;
|
|
14
|
+
export declare function reasonixAuthGuidance(hostName?: string): string;
|
|
15
|
+
export declare function claudeAuthGuidance(hostName?: string): string;
|
|
16
|
+
export declare function isCursorAuthFailureText(text: string): boolean;
|
|
17
|
+
export declare function isAntigravityAuthFailureText(text: string): boolean;
|
|
18
|
+
export declare function isDeepSeekAuthFailureText(text: string): boolean;
|
|
19
|
+
export declare function isReasonixAuthFailureText(text: string): boolean;
|
|
20
|
+
export declare function isClaudeAuthFailureText(text: string): boolean;
|
|
21
|
+
export declare function classifyAgentAuthFailure(agentId: string, text: string, hostName?: string): AgentAuthProbeResult | null;
|
|
22
|
+
export type AgentServiceFailureCode = 'AGENT_AUTH_REQUIRED' | 'RATE_LIMITED' | 'UPSTREAM_UNAVAILABLE';
|
|
23
|
+
export declare function classifyAgentServiceFailure(text: string): AgentServiceFailureCode | null;
|
|
24
|
+
export declare function probeAgentAuthStatus(def: Pick<RuntimeAgentDef, 'id' | 'name' | 'authProbe'>, resolvedBin: string, env: RuntimeEnv, hostName?: string): Promise<AgentAuthProbeResult | null>;
|
|
25
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AA6CF,wBAAgB,kBAAkB,CAAC,QAAQ,GAAE,MAA0B,GAAG,MA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