@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
|
@@ -25,7 +25,7 @@ function resetPendingJson(state) {
|
|
|
25
25
|
state.pendingJson = '';
|
|
26
26
|
state.pendingJsonLineCount = 0;
|
|
27
27
|
}
|
|
28
|
-
export function emitJsonLine(candidate, onMessage) {
|
|
28
|
+
export function emitJsonLine({ candidate, onMessage }, _optional = {}) {
|
|
29
29
|
try {
|
|
30
30
|
onMessage({ message: JSON.parse(candidate), rawLine: candidate });
|
|
31
31
|
return true;
|
|
@@ -37,54 +37,54 @@ export function emitJsonLine(candidate, onMessage) {
|
|
|
37
37
|
// Continues an in-progress multiline candidate with the next trimmed line.
|
|
38
38
|
// Either resolves it (parses, or gives up and re-processes `trimmed` fresh)
|
|
39
39
|
// or keeps accumulating.
|
|
40
|
-
export function continuePendingJsonLine(state, trimmed, onMessage, onError) {
|
|
40
|
+
export function continuePendingJsonLine({ state, trimmed, onMessage }, { onError } = {}) {
|
|
41
41
|
// Enforce aggregate limits before JSON.parse; a complete closing line earns no exemption.
|
|
42
42
|
if (state.pendingJson.length + 1 + trimmed.length > 128_000 || state.pendingJsonLineCount >= 256) {
|
|
43
43
|
resetPendingJson(state);
|
|
44
44
|
onError?.(new RangeError(MULTILINE_LIMIT_MESSAGE));
|
|
45
45
|
// A complete physical frame may follow a stray opening line; its own line budget still applies.
|
|
46
|
-
handleJsonLine(state, trimmed, onMessage, onError);
|
|
46
|
+
handleJsonLine({ state, line: trimmed, onMessage }, { onError });
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
const nextCandidate = `${state.pendingJson}\n${trimmed}`;
|
|
50
|
-
if (emitJsonLine(nextCandidate, onMessage)) {
|
|
50
|
+
if (emitJsonLine({ candidate: nextCandidate, onMessage })) {
|
|
51
51
|
resetPendingJson(state);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
state.pendingJsonLineCount += 1;
|
|
55
|
-
const classification = classifyJsonCandidate(nextCandidate);
|
|
55
|
+
const classification = classifyJsonCandidate({ value: nextCandidate });
|
|
56
56
|
if (classification === 'incomplete') {
|
|
57
57
|
state.pendingJson = nextCandidate;
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
resetPendingJson(state);
|
|
61
|
-
handleJsonLine(state, trimmed, onMessage, onError);
|
|
61
|
+
handleJsonLine({ state, line: trimmed, onMessage }, { onError });
|
|
62
62
|
}
|
|
63
63
|
// ACP is line-delimited JSON-RPC, but a few bridges have emitted
|
|
64
64
|
// pretty-printed JSON during startup. Keep a bounded aggregate so an
|
|
65
65
|
// otherwise valid multiline initialize response does not get discarded
|
|
66
66
|
// line-by-line and leave the session stuck in spawn pending.
|
|
67
|
-
export function tryStartPendingJsonLine(state, trimmed, onError) {
|
|
67
|
+
export function tryStartPendingJsonLine({ state, trimmed }, { onError } = {}) {
|
|
68
68
|
if (!trimmed.startsWith('{') && !trimmed.startsWith('['))
|
|
69
69
|
return;
|
|
70
70
|
if (trimmed.length > 128_000) {
|
|
71
71
|
onError?.(new RangeError(MULTILINE_LIMIT_MESSAGE));
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
if (classifyJsonCandidate(trimmed) === 'incomplete')
|
|
74
|
+
if (classifyJsonCandidate({ value: trimmed }) === 'incomplete')
|
|
75
75
|
startPendingJson(state, trimmed);
|
|
76
76
|
}
|
|
77
|
-
export function handleJsonLine(state, line, onMessage, onError) {
|
|
77
|
+
export function handleJsonLine({ state, line, onMessage }, { onError } = {}) {
|
|
78
78
|
const trimmed = line.trim();
|
|
79
79
|
if (!trimmed)
|
|
80
80
|
return;
|
|
81
81
|
if (state.pendingJson) {
|
|
82
|
-
continuePendingJsonLine(state, trimmed, onMessage, onError);
|
|
82
|
+
continuePendingJsonLine({ state, trimmed, onMessage }, { onError });
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
if (emitJsonLine(trimmed, onMessage))
|
|
85
|
+
if (emitJsonLine({ candidate: trimmed, onMessage }))
|
|
86
86
|
return;
|
|
87
|
-
tryStartPendingJsonLine(state, trimmed, onError);
|
|
87
|
+
tryStartPendingJsonLine({ state, trimmed }, { onError });
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Creates a streaming JSON-line parser over a raw byte/string stream.
|
|
@@ -99,15 +99,15 @@ export function handleJsonLine(state, line, onMessage, onError) {
|
|
|
99
99
|
*
|
|
100
100
|
* @param requiredArgs.onMessage - Called with `{ message, rawLine }` for each
|
|
101
101
|
* successfully parsed JSON value and its raw reassembled line string.
|
|
102
|
-
* @param
|
|
102
|
+
* @param optionalArgs.onError - Reports a physical-line or multiline overflow to the host's failure path.
|
|
103
103
|
* When omitted, feed throws RangeError. Oversized content is never delivered.
|
|
104
104
|
* @returns An object with `feed({ chunk })` for incremental input and `flush()` to
|
|
105
105
|
* drain any residual buffered content at stream end.
|
|
106
106
|
*/
|
|
107
|
-
export function createJsonLineStream({ onMessage, onError = error => { throw error; } }) {
|
|
107
|
+
export function createJsonLineStream({ onMessage }, { onError = error => { throw error; } } = {}) {
|
|
108
108
|
const state = { pendingJson: '', pendingJsonLineCount: 0 };
|
|
109
109
|
const lines = createBoundedLineStream({
|
|
110
|
-
onLine: line => handleJsonLine(state, line, onMessage, onError),
|
|
110
|
+
onLine: line => handleJsonLine({ state, line, onMessage }, { onError }),
|
|
111
111
|
onOverflow: error => { resetPendingJson(state); onError(error); },
|
|
112
112
|
});
|
|
113
113
|
return {
|
|
@@ -131,7 +131,7 @@ export function createJsonLineStream({ onMessage, onError = error => { throw err
|
|
|
131
131
|
},
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
-
export function afterValue(state) {
|
|
134
|
+
export function afterValue({ state }, _optional = {}) {
|
|
135
135
|
const parent = state.stack.at(-1);
|
|
136
136
|
if (!parent) {
|
|
137
137
|
state.rootComplete = true;
|
|
@@ -151,9 +151,9 @@ export function afterValue(state) {
|
|
|
151
151
|
// dead-branch discipline. See archived provenance ledger.
|
|
152
152
|
function closeFrame(state) {
|
|
153
153
|
state.stack.pop();
|
|
154
|
-
afterValue(state);
|
|
154
|
+
afterValue({ state });
|
|
155
155
|
}
|
|
156
|
-
export function parseString(value, start) {
|
|
156
|
+
export function parseString({ value, start }, _optional = {}) {
|
|
157
157
|
for (let index = start + 1; index < value.length; index += 1) {
|
|
158
158
|
const char = value[index];
|
|
159
159
|
if (char === '\\') {
|
|
@@ -165,7 +165,7 @@ export function parseString(value, start) {
|
|
|
165
165
|
}
|
|
166
166
|
return null;
|
|
167
167
|
}
|
|
168
|
-
export function parseLiteral(value, start, literal) {
|
|
168
|
+
export function parseLiteral({ value, start, literal }, _optional = {}) {
|
|
169
169
|
for (let offset = 0; offset < literal.length; offset += 1) {
|
|
170
170
|
const char = value[start + offset];
|
|
171
171
|
if (char === undefined)
|
|
@@ -187,14 +187,14 @@ function consumeDigits(value, start) {
|
|
|
187
187
|
function parseOptionalSign(value, start) {
|
|
188
188
|
return value[start] === '-' ? start + 1 : start;
|
|
189
189
|
}
|
|
190
|
-
export function parseIntegerDigits(value, start) {
|
|
190
|
+
export function parseIntegerDigits({ value, start }, _optional = {}) {
|
|
191
191
|
if (value[start] === '0')
|
|
192
192
|
return start + 1;
|
|
193
193
|
if (isDigit(value[start]))
|
|
194
194
|
return consumeDigits(value, start);
|
|
195
195
|
return false;
|
|
196
196
|
}
|
|
197
|
-
export function parseFractionDigits(value, start) {
|
|
197
|
+
export function parseFractionDigits({ value, start }, _optional = {}) {
|
|
198
198
|
if (value[start] !== '.')
|
|
199
199
|
return start;
|
|
200
200
|
const digitsStart = start + 1;
|
|
@@ -202,7 +202,7 @@ export function parseFractionDigits(value, start) {
|
|
|
202
202
|
return false;
|
|
203
203
|
return consumeDigits(value, digitsStart);
|
|
204
204
|
}
|
|
205
|
-
export function parseExponentDigits(value, start) {
|
|
205
|
+
export function parseExponentDigits({ value, start }, _optional = {}) {
|
|
206
206
|
if (value[start] !== 'e' && value[start] !== 'E')
|
|
207
207
|
return start;
|
|
208
208
|
let digitsStart = start + 1;
|
|
@@ -212,94 +212,94 @@ export function parseExponentDigits(value, start) {
|
|
|
212
212
|
return false;
|
|
213
213
|
return consumeDigits(value, digitsStart);
|
|
214
214
|
}
|
|
215
|
-
export function parseNumber(value, start) {
|
|
215
|
+
export function parseNumber({ value, start }, _optional = {}) {
|
|
216
216
|
const afterSign = parseOptionalSign(value, start);
|
|
217
|
-
const afterInteger = parseIntegerDigits(value, afterSign);
|
|
217
|
+
const afterInteger = parseIntegerDigits({ value, start: afterSign });
|
|
218
218
|
if (afterInteger === false)
|
|
219
219
|
return false;
|
|
220
|
-
const afterFraction = parseFractionDigits(value, afterInteger);
|
|
220
|
+
const afterFraction = parseFractionDigits({ value, start: afterInteger });
|
|
221
221
|
if (afterFraction === false)
|
|
222
222
|
return false;
|
|
223
|
-
const afterExponent = parseExponentDigits(value, afterFraction);
|
|
223
|
+
const afterExponent = parseExponentDigits({ value, start: afterFraction });
|
|
224
224
|
if (afterExponent === false)
|
|
225
225
|
return false;
|
|
226
226
|
return afterExponent - 1;
|
|
227
227
|
}
|
|
228
|
-
export function parseStringValue(state, index) {
|
|
229
|
-
const end = parseString(state.value, index);
|
|
228
|
+
export function parseStringValue({ state, index }, _optional = {}) {
|
|
229
|
+
const end = parseString({ value: state.value, start: index });
|
|
230
230
|
if (end === null)
|
|
231
231
|
return null;
|
|
232
|
-
afterValue(state);
|
|
232
|
+
afterValue({ state });
|
|
233
233
|
return end;
|
|
234
234
|
}
|
|
235
|
-
export function parseNumberValue(state, index) {
|
|
236
|
-
const end = parseNumber(state.value, index);
|
|
235
|
+
export function parseNumberValue({ state, index }, _optional = {}) {
|
|
236
|
+
const end = parseNumber({ value: state.value, start: index });
|
|
237
237
|
if (end === false)
|
|
238
238
|
return false;
|
|
239
|
-
afterValue(state);
|
|
239
|
+
afterValue({ state });
|
|
240
240
|
return end;
|
|
241
241
|
}
|
|
242
242
|
function openContainer(state, index, frame) {
|
|
243
243
|
state.stack.push(frame);
|
|
244
244
|
return index;
|
|
245
245
|
}
|
|
246
|
-
export function parseLiteralValue(state, index, literal) {
|
|
247
|
-
const end = parseLiteral(state.value, index, literal);
|
|
246
|
+
export function parseLiteralValue({ state, index, literal }, _optional = {}) {
|
|
247
|
+
const end = parseLiteral({ value: state.value, start: index, literal });
|
|
248
248
|
if (typeof end === 'number')
|
|
249
|
-
afterValue(state);
|
|
249
|
+
afterValue({ state });
|
|
250
250
|
return end;
|
|
251
251
|
}
|
|
252
252
|
const LITERAL_STARTS = { t: 'true', f: 'false', n: 'null' };
|
|
253
|
-
export function parseValue(state, index) {
|
|
253
|
+
export function parseValue({ state, index }, _optional = {}) {
|
|
254
254
|
const char = state.value[index];
|
|
255
255
|
if (char === '"')
|
|
256
|
-
return parseStringValue(state, index);
|
|
256
|
+
return parseStringValue({ state, index });
|
|
257
257
|
if (char === '{')
|
|
258
258
|
return openContainer(state, index, { kind: 'object', expect: 'keyOrEnd' });
|
|
259
259
|
if (char === '[')
|
|
260
260
|
return openContainer(state, index, { kind: 'array', expect: 'valueOrEnd' });
|
|
261
261
|
if (char !== undefined && char in LITERAL_STARTS) {
|
|
262
262
|
// `char in LITERAL_STARTS` just confirmed this key is present.
|
|
263
|
-
return parseLiteralValue(state, index, LITERAL_STARTS[char]);
|
|
263
|
+
return parseLiteralValue({ state, index, literal: LITERAL_STARTS[char] });
|
|
264
264
|
}
|
|
265
265
|
// `parseValue` is only ever called (below, and from the step handlers)
|
|
266
266
|
// with an `index` already known to be within `value`'s bounds, so `char`
|
|
267
267
|
// is always defined here; the non-null assertion documents that instead
|
|
268
268
|
// of a `?? ''` fallback that could never actually be exercised.
|
|
269
269
|
if (char === '-' || /\d/.test(char))
|
|
270
|
-
return parseNumberValue(state, index);
|
|
270
|
+
return parseNumberValue({ state, index });
|
|
271
271
|
return false;
|
|
272
272
|
}
|
|
273
|
-
export function stepRootFrame(state, index) {
|
|
273
|
+
export function stepRootFrame({ state, index }, _optional = {}) {
|
|
274
274
|
if (state.rootComplete)
|
|
275
275
|
return 'invalid';
|
|
276
|
-
const end = parseValue(state, index);
|
|
276
|
+
const end = parseValue({ state, index });
|
|
277
277
|
if (end === false)
|
|
278
278
|
return 'invalid';
|
|
279
279
|
if (end === null)
|
|
280
280
|
return 'incomplete';
|
|
281
281
|
return { nextIndex: end };
|
|
282
282
|
}
|
|
283
|
-
export function stepObjectKeyOrEnd(state, current, index, char) {
|
|
283
|
+
export function stepObjectKeyOrEnd({ state, current, index, char }, _optional = {}) {
|
|
284
284
|
if (char === '}') {
|
|
285
285
|
closeFrame(state);
|
|
286
286
|
return { nextIndex: index };
|
|
287
287
|
}
|
|
288
288
|
if (char !== '"')
|
|
289
289
|
return 'invalid';
|
|
290
|
-
const end = parseString(state.value, index);
|
|
290
|
+
const end = parseString({ value: state.value, start: index });
|
|
291
291
|
if (end === null)
|
|
292
292
|
return 'incomplete';
|
|
293
293
|
current.expect = 'colon';
|
|
294
294
|
return { nextIndex: end };
|
|
295
295
|
}
|
|
296
|
-
export function stepObjectColon(current, index, char) {
|
|
296
|
+
export function stepObjectColon({ current, index, char }, _optional = {}) {
|
|
297
297
|
if (char !== ':')
|
|
298
298
|
return 'invalid';
|
|
299
299
|
current.expect = 'value';
|
|
300
300
|
return { nextIndex: index };
|
|
301
301
|
}
|
|
302
|
-
export function stepObjectCommaOrEnd(state, current, index, char) {
|
|
302
|
+
export function stepObjectCommaOrEnd({ state, current, index, char }, _optional = {}) {
|
|
303
303
|
if (char === '}') {
|
|
304
304
|
closeFrame(state);
|
|
305
305
|
return { nextIndex: index };
|
|
@@ -309,34 +309,34 @@ export function stepObjectCommaOrEnd(state, current, index, char) {
|
|
|
309
309
|
current.expect = 'keyOrEnd';
|
|
310
310
|
return { nextIndex: index };
|
|
311
311
|
}
|
|
312
|
-
export function stepObjectFrame(state, current, index, char) {
|
|
312
|
+
export function stepObjectFrame({ state, current, index, char }, _optional = {}) {
|
|
313
313
|
if (current.expect === 'keyOrEnd')
|
|
314
|
-
return stepObjectKeyOrEnd(state, current, index, char);
|
|
314
|
+
return stepObjectKeyOrEnd({ state, current, index, char });
|
|
315
315
|
if (current.expect === 'colon')
|
|
316
|
-
return stepObjectColon(current, index, char);
|
|
316
|
+
return stepObjectColon({ current, index, char });
|
|
317
317
|
if (current.expect === 'value') {
|
|
318
|
-
const end = parseValue(state, index);
|
|
318
|
+
const end = parseValue({ state, index });
|
|
319
319
|
if (end === false)
|
|
320
320
|
return 'invalid';
|
|
321
321
|
if (end === null)
|
|
322
322
|
return 'incomplete';
|
|
323
323
|
return { nextIndex: end };
|
|
324
324
|
}
|
|
325
|
-
return stepObjectCommaOrEnd(state, current, index, char);
|
|
325
|
+
return stepObjectCommaOrEnd({ state, current, index, char });
|
|
326
326
|
}
|
|
327
|
-
export function stepArrayValueOrEnd(state, index, char) {
|
|
327
|
+
export function stepArrayValueOrEnd({ state, index, char }, _optional = {}) {
|
|
328
328
|
if (char === ']') {
|
|
329
329
|
closeFrame(state);
|
|
330
330
|
return { nextIndex: index };
|
|
331
331
|
}
|
|
332
|
-
const end = parseValue(state, index);
|
|
332
|
+
const end = parseValue({ state, index });
|
|
333
333
|
if (end === false)
|
|
334
334
|
return 'invalid';
|
|
335
335
|
if (end === null)
|
|
336
336
|
return 'incomplete';
|
|
337
337
|
return { nextIndex: end };
|
|
338
338
|
}
|
|
339
|
-
export function stepArrayCommaOrEnd(state, current, index, char) {
|
|
339
|
+
export function stepArrayCommaOrEnd({ state, current, index, char }, _optional = {}) {
|
|
340
340
|
if (char === ']') {
|
|
341
341
|
closeFrame(state);
|
|
342
342
|
return { nextIndex: index };
|
|
@@ -346,20 +346,20 @@ export function stepArrayCommaOrEnd(state, current, index, char) {
|
|
|
346
346
|
current.expect = 'valueOrEnd';
|
|
347
347
|
return { nextIndex: index };
|
|
348
348
|
}
|
|
349
|
-
export function stepArrayFrame(state, current, index, char) {
|
|
349
|
+
export function stepArrayFrame({ state, current, index, char }, _optional = {}) {
|
|
350
350
|
return current.expect === 'valueOrEnd'
|
|
351
|
-
? stepArrayValueOrEnd(state, index, char)
|
|
352
|
-
: stepArrayCommaOrEnd(state, current, index, char);
|
|
351
|
+
? stepArrayValueOrEnd({ state, index, char })
|
|
352
|
+
: stepArrayCommaOrEnd({ state, current, index, char });
|
|
353
353
|
}
|
|
354
354
|
// Dispatches to the step handler for whatever frame is on top of the
|
|
355
355
|
// stack (or the root frame when the stack is empty).
|
|
356
|
-
export function selectStep(state, index, char) {
|
|
356
|
+
export function selectStep({ state, index, char }, _optional = {}) {
|
|
357
357
|
const current = state.stack.at(-1);
|
|
358
358
|
if (!current)
|
|
359
|
-
return stepRootFrame(state, index);
|
|
359
|
+
return stepRootFrame({ state, index });
|
|
360
360
|
return current.kind === 'object'
|
|
361
|
-
? stepObjectFrame(state, current, index, char)
|
|
362
|
-
: stepArrayFrame(state, current, index, char);
|
|
361
|
+
? stepObjectFrame({ state, current, index, char })
|
|
362
|
+
: stepArrayFrame({ state, current, index, char });
|
|
363
363
|
}
|
|
364
364
|
/**
|
|
365
365
|
* Incremental JSON completeness classifier used by `createJsonLineStream` to
|
|
@@ -376,7 +376,7 @@ export function selectStep(state, index, char) {
|
|
|
376
376
|
* @param value - A string candidate to classify, typically one or more
|
|
377
377
|
* accumulated stdout lines from an ACP subprocess.
|
|
378
378
|
*/
|
|
379
|
-
export function classifyJsonCandidate(value) {
|
|
379
|
+
export function classifyJsonCandidate({ value }, _optional = {}) {
|
|
380
380
|
const state = { value, stack: [], rootComplete: false };
|
|
381
381
|
let index = 0;
|
|
382
382
|
while (index < value.length) {
|
|
@@ -386,7 +386,7 @@ export function classifyJsonCandidate(value) {
|
|
|
386
386
|
// guard that could never actually trigger.
|
|
387
387
|
const char = value[index];
|
|
388
388
|
// Whitespace between tokens is skipped; a step reports the last index it consumed.
|
|
389
|
-
const step = /\s/.test(char) ? null : selectStep(state, index, char);
|
|
389
|
+
const step = /\s/.test(char) ? null : selectStep({ state, index, char });
|
|
390
390
|
if (step === 'invalid' || step === 'incomplete')
|
|
391
391
|
return step;
|
|
392
392
|
index = (step === null ? index : step.nextIndex) + 1;
|
|
@@ -16,9 +16,19 @@ export declare function handleAgentStart(_raw: JsonRecord, send: SendAgentEvent)
|
|
|
16
16
|
export declare function handleAgentEnd(): 'agent_end';
|
|
17
17
|
export declare function handleTurnStart(_raw: JsonRecord, send: SendAgentEvent): null;
|
|
18
18
|
/** Extracts the subset of pi's `message.usage` fields the daemon reports as token usage. */
|
|
19
|
-
export declare function buildTokenUsage(u
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export declare function buildTokenUsage({ u }: {
|
|
20
|
+
u: JsonRecord;
|
|
21
|
+
}, _optional?: Record<string, never>): TokenUsage;
|
|
22
|
+
export declare function emitTurnEndUsage({ u, send, ctx }: {
|
|
23
|
+
u: JsonRecord;
|
|
24
|
+
send: SendAgentEvent;
|
|
25
|
+
ctx: PiRpcContext;
|
|
26
|
+
}, _optional?: Record<string, never>): void;
|
|
27
|
+
export declare function emitTurnEndErrorIfPresent({ message, raw, send }: {
|
|
28
|
+
message: JsonRecord | undefined;
|
|
29
|
+
raw: JsonRecord;
|
|
30
|
+
send: SendAgentEvent;
|
|
31
|
+
}, _optional?: Record<string, never>): void;
|
|
22
32
|
export declare function handleTurnEnd(raw: JsonRecord, send: SendAgentEvent, ctx: PiRpcContext): null;
|
|
23
33
|
export declare function handleAssistantTextDelta(ev: JsonRecord, send: SendAgentEvent, ctx: PiRpcContext): void;
|
|
24
34
|
export declare function handleAssistantThinkingDelta(ev: JsonRecord, send: SendAgentEvent): void;
|
|
@@ -47,5 +57,5 @@ export declare function mapPiRpcEvent({ raw, send, ctx }: {
|
|
|
47
57
|
raw: JsonRecord;
|
|
48
58
|
send: SendAgentEvent;
|
|
49
59
|
ctx: PiRpcContext;
|
|
50
|
-
}): 'agent_end' | null;
|
|
60
|
+
}, _optional?: Record<string, never>): 'agent_end' | null;
|
|
51
61
|
//# sourceMappingURL=events.d.ts.map
|
|
@@ -7,7 +7,7 @@ function nonEmptyString(value) {
|
|
|
7
7
|
function toolResultText(content) {
|
|
8
8
|
return content
|
|
9
9
|
.map((c) => {
|
|
10
|
-
const item = getRecord(c);
|
|
10
|
+
const item = getRecord({ value: c });
|
|
11
11
|
return item?.type === 'text' ? String(item.text ?? '') : JSON.stringify(c);
|
|
12
12
|
})
|
|
13
13
|
.join('\n');
|
|
@@ -28,7 +28,7 @@ export function handleTurnStart(_raw, send) {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
/** Extracts the subset of pi's `message.usage` fields the daemon reports as token usage. */
|
|
31
|
-
export function buildTokenUsage(u) {
|
|
31
|
+
export function buildTokenUsage({ u }, _optional = {}) {
|
|
32
32
|
const usage = {};
|
|
33
33
|
if (typeof u.input === 'number')
|
|
34
34
|
usage.input_tokens = u.input;
|
|
@@ -42,11 +42,11 @@ export function buildTokenUsage(u) {
|
|
|
42
42
|
usage.total_tokens = u.totalTokens;
|
|
43
43
|
return usage;
|
|
44
44
|
}
|
|
45
|
-
export function emitTurnEndUsage(u, send, ctx) {
|
|
46
|
-
const usage = buildTokenUsage(u);
|
|
45
|
+
export function emitTurnEndUsage({ u, send, ctx }, _optional = {}) {
|
|
46
|
+
const usage = buildTokenUsage({ u });
|
|
47
47
|
if (Object.keys(usage).length === 0)
|
|
48
48
|
return;
|
|
49
|
-
const cost = getRecord(u.cost);
|
|
49
|
+
const cost = getRecord({ value: u.cost });
|
|
50
50
|
send({ event: 'agent', payload: {
|
|
51
51
|
type: 'usage',
|
|
52
52
|
usage,
|
|
@@ -54,7 +54,7 @@ export function emitTurnEndUsage(u, send, ctx) {
|
|
|
54
54
|
durationMs: Date.now() - ctx.runStartedAt,
|
|
55
55
|
} });
|
|
56
56
|
}
|
|
57
|
-
export function emitTurnEndErrorIfPresent(message, raw, send) {
|
|
57
|
+
export function emitTurnEndErrorIfPresent({ message, raw, send }, _optional = {}) {
|
|
58
58
|
if (message?.stopReason !== 'error')
|
|
59
59
|
return;
|
|
60
60
|
const messageText = typeof message.errorMessage === 'string' && message.errorMessage.length > 0
|
|
@@ -63,11 +63,11 @@ export function emitTurnEndErrorIfPresent(message, raw, send) {
|
|
|
63
63
|
send({ event: 'agent', payload: { type: 'error', message: messageText, raw } });
|
|
64
64
|
}
|
|
65
65
|
export function handleTurnEnd(raw, send, ctx) {
|
|
66
|
-
const message = getRecord(raw.message);
|
|
67
|
-
const messageUsage = getRecord(message?.usage);
|
|
66
|
+
const message = getRecord({ value: raw.message });
|
|
67
|
+
const messageUsage = getRecord({ value: message?.usage });
|
|
68
68
|
if (messageUsage)
|
|
69
|
-
emitTurnEndUsage(messageUsage, send, ctx);
|
|
70
|
-
emitTurnEndErrorIfPresent(message, raw, send);
|
|
69
|
+
emitTurnEndUsage({ u: messageUsage, send, ctx });
|
|
70
|
+
emitTurnEndErrorIfPresent({ message, raw, send });
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
export function handleAssistantTextDelta(ev, send, ctx) {
|
|
@@ -110,7 +110,7 @@ const ASSISTANT_MESSAGE_EVENT_HANDLERS = {
|
|
|
110
110
|
error: handleAssistantError,
|
|
111
111
|
};
|
|
112
112
|
export function handleMessageUpdate(raw, send, ctx) {
|
|
113
|
-
const ev = getRecord(raw.assistantMessageEvent);
|
|
113
|
+
const ev = getRecord({ value: raw.assistantMessageEvent });
|
|
114
114
|
const handler = typeof ev?.type === 'string' ? ASSISTANT_MESSAGE_EVENT_HANDLERS[ev.type] : undefined;
|
|
115
115
|
if (ev && handler)
|
|
116
116
|
handler(ev, send, ctx, raw);
|
|
@@ -132,7 +132,7 @@ export function handleToolExecutionStart(raw, send) {
|
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
134
|
export function handleToolExecutionEnd(raw, send) {
|
|
135
|
-
const result = getRecord(raw.result);
|
|
135
|
+
const result = getRecord({ value: raw.result });
|
|
136
136
|
const content = result?.content;
|
|
137
137
|
const text = Array.isArray(content) ? toolResultText(content) : nonArrayToolResultText(content);
|
|
138
138
|
send({ event: 'agent', payload: {
|
|
@@ -196,8 +196,8 @@ const PI_RPC_EVENT_HANDLERS = {
|
|
|
196
196
|
* @param ctx - Per-run context: start timestamp and first-token sentinel.
|
|
197
197
|
* @returns `'agent_end'` on run completion, `null` otherwise.
|
|
198
198
|
*/
|
|
199
|
-
export function mapPiRpcEvent({ raw, send, ctx }) {
|
|
200
|
-
const message = getRecord(raw.message);
|
|
199
|
+
export function mapPiRpcEvent({ raw, send, ctx }, _optional = {}) {
|
|
200
|
+
const message = getRecord({ value: raw.message });
|
|
201
201
|
if (message?.role === 'assistant' && typeof message.model === 'string' && typeof message.provider === 'string') {
|
|
202
202
|
send({ event: 'agent', payload: { type: 'status', label: 'model', model: `${message.provider}/${message.model}` } });
|
|
203
203
|
}
|
|
@@ -29,7 +29,9 @@ export declare function isRecord(value: unknown): value is JsonRecord;
|
|
|
29
29
|
*
|
|
30
30
|
* @param err - Any caught value from a try/catch or error callback.
|
|
31
31
|
*/
|
|
32
|
-
export declare function errorMessage(err
|
|
32
|
+
export declare function errorMessage({ err }: {
|
|
33
|
+
err: unknown;
|
|
34
|
+
}, _optional?: Record<string, never>): string;
|
|
33
35
|
/**
|
|
34
36
|
* Extracts the `code` property from an unknown thrown value when it is a
|
|
35
37
|
* string — useful for matching Node.js system-error codes such as `EPIPE`.
|
|
@@ -37,12 +39,16 @@ export declare function errorMessage(err: unknown): string;
|
|
|
37
39
|
*
|
|
38
40
|
* @param err - Any caught value from a try/catch or error callback.
|
|
39
41
|
*/
|
|
40
|
-
export declare function errorCode(err
|
|
42
|
+
export declare function errorCode({ err }: {
|
|
43
|
+
err: unknown;
|
|
44
|
+
}, _optional?: Record<string, never>): string | undefined;
|
|
41
45
|
/**
|
|
42
46
|
* Returns `value` cast to `JsonRecord` when it is a non-null object, or
|
|
43
47
|
* `undefined` otherwise — a narrowing helper for optional nested fields.
|
|
44
48
|
*
|
|
45
49
|
* @param value - An arbitrary value from a parsed JSON payload.
|
|
46
50
|
*/
|
|
47
|
-
export declare function getRecord(value
|
|
51
|
+
export declare function getRecord({ value }: {
|
|
52
|
+
value: unknown;
|
|
53
|
+
}, _optional?: Record<string, never>): JsonRecord | undefined;
|
|
48
54
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -16,7 +16,7 @@ export function isRecord(value) {
|
|
|
16
16
|
*
|
|
17
17
|
* @param err - Any caught value from a try/catch or error callback.
|
|
18
18
|
*/
|
|
19
|
-
export function errorMessage(err) {
|
|
19
|
+
export function errorMessage({ err }, _optional = {}) {
|
|
20
20
|
return err instanceof Error ? err.message : String(err);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -26,7 +26,7 @@ export function errorMessage(err) {
|
|
|
26
26
|
*
|
|
27
27
|
* @param err - Any caught value from a try/catch or error callback.
|
|
28
28
|
*/
|
|
29
|
-
export function errorCode(err) {
|
|
29
|
+
export function errorCode({ err }, _optional = {}) {
|
|
30
30
|
return isRecord(err) && typeof err.code === 'string' ? err.code : undefined;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -35,7 +35,7 @@ export function errorCode(err) {
|
|
|
35
35
|
*
|
|
36
36
|
* @param value - An arbitrary value from a parsed JSON payload.
|
|
37
37
|
*/
|
|
38
|
-
export function getRecord(value) {
|
|
38
|
+
export function getRecord({ value }, _optional = {}) {
|
|
39
39
|
return isRecord(value) ? value : undefined;
|
|
40
40
|
}
|
|
41
41
|
//# sourceMappingURL=internal.js.map
|
|
@@ -2,22 +2,8 @@
|
|
|
2
2
|
* Parses `pi --list-models` tabular stdout into the daemon's model-picker format.
|
|
3
3
|
* No network I/O — accepts the raw stdout string and returns a typed array or null.
|
|
4
4
|
*/
|
|
5
|
+
import type { RuntimeModelOption } from '@jini-ai/core/contracts/agents';
|
|
5
6
|
/** A single model entry for the daemon's model-picker: an opaque id and a display label. */
|
|
6
|
-
export type PiModelOption =
|
|
7
|
-
|
|
8
|
-
label: string;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Parses the tabular stdout of `pi --list-models` into an array of model options.
|
|
12
|
-
* The first entry is always the `default` sentinel ("Default (CLI config)").
|
|
13
|
-
* Provider/model pairs are de-duplicated; the header line is skipped.
|
|
14
|
-
* Returns `null` when the output is empty or contains no parseable rows beyond
|
|
15
|
-
* the header.
|
|
16
|
-
*
|
|
17
|
-
* @param stdout - Raw stdout captured from `pi --list-models`, as a string or Buffer.
|
|
18
|
-
* @returns Parsed model array (at least 2 entries), or `null` when nothing is found.
|
|
19
|
-
*/
|
|
20
|
-
export declare function parsePiModels({ stdout }: {
|
|
21
|
-
stdout: unknown;
|
|
22
|
-
}): PiModelOption[] | null;
|
|
7
|
+
export type PiModelOption = RuntimeModelOption;
|
|
8
|
+
export { parsePiModels } from '../../pi-models.js';
|
|
23
9
|
//# sourceMappingURL=models.d.ts.map
|
|
@@ -2,49 +2,5 @@
|
|
|
2
2
|
* Parses `pi --list-models` tabular stdout into the daemon's model-picker format.
|
|
3
3
|
* No network I/O — accepts the raw stdout string and returns a typed array or null.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
* Parses the tabular stdout of `pi --list-models` into an array of model options.
|
|
7
|
-
* The first entry is always the `default` sentinel ("Default (CLI config)").
|
|
8
|
-
* Provider/model pairs are de-duplicated; the header line is skipped.
|
|
9
|
-
* Returns `null` when the output is empty or contains no parseable rows beyond
|
|
10
|
-
* the header.
|
|
11
|
-
*
|
|
12
|
-
* @param stdout - Raw stdout captured from `pi --list-models`, as a string or Buffer.
|
|
13
|
-
* @returns Parsed model array (at least 2 entries), or `null` when nothing is found.
|
|
14
|
-
*/
|
|
15
|
-
export function parsePiModels({ stdout }) {
|
|
16
|
-
const lines = String(stdout || '')
|
|
17
|
-
.split('\n')
|
|
18
|
-
.map((l) => l.trim())
|
|
19
|
-
.filter((l) => l.length > 0 && !l.startsWith('#'));
|
|
20
|
-
if (lines.length === 0)
|
|
21
|
-
return null;
|
|
22
|
-
const DEFAULT_MODEL_OPTION = { id: 'default', label: 'Default (CLI config)' };
|
|
23
|
-
// First line is the header; skip it.
|
|
24
|
-
const entries = [DEFAULT_MODEL_OPTION];
|
|
25
|
-
const seen = new Set(['default']);
|
|
26
|
-
for (let i = 1; i < lines.length; i++) {
|
|
27
|
-
// The loop bound (`i < lines.length`) guarantees `lines[i]` is always
|
|
28
|
-
// defined; the non-null assertion documents that runtime invariant
|
|
29
|
-
// instead of a `noUncheckedIndexedAccess`-driven guard that could never
|
|
30
|
-
// actually trigger.
|
|
31
|
-
const fullId = providerModelId(lines[i]);
|
|
32
|
-
// Skip rows without both columns, and duplicates (some providers list the
|
|
33
|
-
// same model under multiple names).
|
|
34
|
-
if (fullId === null || seen.has(fullId))
|
|
35
|
-
continue;
|
|
36
|
-
seen.add(fullId);
|
|
37
|
-
entries.push({ id: fullId, label: fullId });
|
|
38
|
-
}
|
|
39
|
-
return entries.length > 1 ? entries : null;
|
|
40
|
-
}
|
|
41
|
-
/** `provider/model` from one table row's first two whitespace-separated columns, or `null` when
|
|
42
|
-
* the row has fewer than two. */
|
|
43
|
-
function providerModelId(line) {
|
|
44
|
-
const parts = line.split(/\s+/);
|
|
45
|
-
if (parts.length < 2)
|
|
46
|
-
return null;
|
|
47
|
-
// `parts.length >= 2` (just checked) guarantees both indices are defined.
|
|
48
|
-
return `${parts[0]}/${parts[1]}`;
|
|
49
|
-
}
|
|
5
|
+
export { parsePiModels } from '../../pi-models.js';
|
|
50
6
|
//# sourceMappingURL=models.js.map
|