@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
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/** @module claude-stream-frames
|
|
2
|
+
* Pure frame helpers for Claude's stream-json output: task bookkeeping, artifact-echo
|
|
3
|
+
* dedup, system/user frame handlers. Leaf module: `claude-stream-handler.ts` (the stateful
|
|
4
|
+
* handler) and `claude-stream.ts` (the public entry) both import it, so neither imports the other
|
|
5
|
+
* at runtime. `ClaudeStreamEvent` stays in `claude-stream.ts` and is imported here as a type only.
|
|
6
|
+
*/
|
|
7
|
+
import { readDelegatedResult } from '@jini-ai/protocol';
|
|
8
|
+
/** The first argument that is a string (possibly empty), or `undefined` when none is. */
|
|
9
|
+
function firstString(...values) {
|
|
10
|
+
return values.find((value) => typeof value === 'string');
|
|
11
|
+
}
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
const WRITE_TOOL_NAMES = new Set(['Write', 'Edit', 'write_file', 'replace']);
|
|
16
|
+
export function toolInputPath({ input }, _optional = {}) {
|
|
17
|
+
if (typeof input.file_path === 'string')
|
|
18
|
+
return input.file_path;
|
|
19
|
+
if (typeof input.path === 'string')
|
|
20
|
+
return input.path;
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
// Runtime-task status aliases the Claude Code wire format has used across
|
|
24
|
+
// versions, normalized to the four statuses the UI understands.
|
|
25
|
+
const TASK_STATUS_ALIASES = {
|
|
26
|
+
completed: 'completed',
|
|
27
|
+
in_progress: 'in_progress',
|
|
28
|
+
stopped: 'stopped',
|
|
29
|
+
complete: 'completed',
|
|
30
|
+
done: 'completed',
|
|
31
|
+
doing: 'in_progress',
|
|
32
|
+
active: 'in_progress',
|
|
33
|
+
failed: 'stopped',
|
|
34
|
+
canceled: 'stopped',
|
|
35
|
+
cancelled: 'stopped',
|
|
36
|
+
};
|
|
37
|
+
export function normalizeTaskStatus({ value }, _optional = {}) {
|
|
38
|
+
if (typeof value !== 'string')
|
|
39
|
+
return 'pending';
|
|
40
|
+
return TASK_STATUS_ALIASES[value] ?? 'pending';
|
|
41
|
+
}
|
|
42
|
+
function nextGeneratedRuntimeTaskId(counter) {
|
|
43
|
+
// Coverage-driven refactor (2026-07-18, no behavior change): the
|
|
44
|
+
// original OD source guarded the returned id with
|
|
45
|
+
// `while (runtimeTasks.has(String(nextRuntimeTaskId))) nextRuntimeTaskId += 1;`.
|
|
46
|
+
// Tracing every path that can insert a numeric id into `runtimeTasks`
|
|
47
|
+
// shows the guard can never trigger: the only two insertion paths are
|
|
48
|
+
// (a) this function itself, which always hands out the current
|
|
49
|
+
// `nextRuntimeTaskId` and then increments it, so that exact value is
|
|
50
|
+
// never in the map yet; and (b) `runtimeTaskIdFromCreate`'s
|
|
51
|
+
// explicit-id branch, which bumps `nextRuntimeTaskId` to
|
|
52
|
+
// `numericId + 1` (strictly past itself) BEFORE this function could
|
|
53
|
+
// ever be asked to reuse that id. Since `nextRuntimeTaskId` only ever
|
|
54
|
+
// increases, it can never equal an id already present in the map at
|
|
55
|
+
// this point. Removed per the coverage skill's Phase 6.5 "dead
|
|
56
|
+
// branch" classification rather than fake a test for an unreachable
|
|
57
|
+
// loop; see archived provenance ledger.
|
|
58
|
+
const id = String(counter.next);
|
|
59
|
+
counter.next += 1;
|
|
60
|
+
return id;
|
|
61
|
+
}
|
|
62
|
+
export function runtimeTaskIdFromCreate({ input, counter }, _optional = {}) {
|
|
63
|
+
if (typeof input.taskId === 'string' && input.taskId) {
|
|
64
|
+
const numericId = Number(input.taskId);
|
|
65
|
+
if (Number.isSafeInteger(numericId) && numericId >= counter.next) {
|
|
66
|
+
counter.next = numericId + 1;
|
|
67
|
+
}
|
|
68
|
+
return input.taskId;
|
|
69
|
+
}
|
|
70
|
+
return nextGeneratedRuntimeTaskId(counter);
|
|
71
|
+
}
|
|
72
|
+
export function applyTaskCreate({ input, tasks, counter }, _optional = {}) {
|
|
73
|
+
const content = firstString(input.subject, input.description) ?? '';
|
|
74
|
+
if (!content)
|
|
75
|
+
return false;
|
|
76
|
+
const id = runtimeTaskIdFromCreate({ input, counter });
|
|
77
|
+
const activeForm = typeof input.activeForm === 'string' ? input.activeForm : undefined;
|
|
78
|
+
tasks.set(id, {
|
|
79
|
+
id,
|
|
80
|
+
content,
|
|
81
|
+
status: normalizeTaskStatus({ value: input.status }),
|
|
82
|
+
...(activeForm ? { activeForm } : {}),
|
|
83
|
+
});
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
export function applyTaskUpdate({ input, tasks }, _optional = {}) {
|
|
87
|
+
if (typeof input.taskId !== 'string')
|
|
88
|
+
return false;
|
|
89
|
+
const existing = tasks.get(input.taskId);
|
|
90
|
+
if (!existing)
|
|
91
|
+
return false;
|
|
92
|
+
const content = firstString(input.subject, input.description) ?? existing.content;
|
|
93
|
+
const activeForm = typeof input.activeForm === 'string' ? input.activeForm : existing.activeForm;
|
|
94
|
+
tasks.set(input.taskId, {
|
|
95
|
+
...existing,
|
|
96
|
+
content,
|
|
97
|
+
status: normalizeTaskStatus({ value: input.status }),
|
|
98
|
+
...(activeForm ? { activeForm } : {}),
|
|
99
|
+
});
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
export function emitCanonicalTaskSnapshot({ toolUseId, name, input, registry, onEvent }, _optional = {}) {
|
|
103
|
+
if (typeof toolUseId !== 'string' || typeof name !== 'string' || !isRecord(input))
|
|
104
|
+
return false;
|
|
105
|
+
if (registry.seenToolUseIds.has(toolUseId))
|
|
106
|
+
return true;
|
|
107
|
+
const applied = name === 'TaskCreate'
|
|
108
|
+
? applyTaskCreate({ input, tasks: registry.tasks, counter: registry.counter })
|
|
109
|
+
: name === 'TaskUpdate' && applyTaskUpdate({ input, tasks: registry.tasks });
|
|
110
|
+
if (!applied)
|
|
111
|
+
return false;
|
|
112
|
+
// Coverage-driven refactor (2026-07-18, no behavior change): the
|
|
113
|
+
// original OD source guarded this emission with
|
|
114
|
+
// `if (!changed || runtimeTasks.size === 0) return false;`. Tracing
|
|
115
|
+
// every path into this point shows both conditions are unreachable —
|
|
116
|
+
// the `TaskCreate` and `TaskUpdate` branches above only fall through
|
|
117
|
+
// to here after an unconditional `runtimeTasks.set(...)` (so `size`
|
|
118
|
+
// can never be 0), and every early-return path above returns before
|
|
119
|
+
// reaching here (so the "changed" flag those returns guarded was
|
|
120
|
+
// always true here). Removed the dead double-guard per the coverage
|
|
121
|
+
// skill's Phase 6.5 "dead branch" classification rather than fake a
|
|
122
|
+
// test for an unreachable condition; see archived provenance ledger.
|
|
123
|
+
registry.seenToolUseIds.add(toolUseId);
|
|
124
|
+
onEvent({
|
|
125
|
+
type: 'tool_use',
|
|
126
|
+
id: `${toolUseId}:todo-task`,
|
|
127
|
+
name: 'TodoWrite',
|
|
128
|
+
input: {
|
|
129
|
+
todos: Array.from(registry.tasks.values()).map(({ content, status, activeForm }) => ({
|
|
130
|
+
content,
|
|
131
|
+
status,
|
|
132
|
+
...(activeForm ? { activeForm } : {}),
|
|
133
|
+
})),
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
export function isFileWriteToolUse({ name, input }, _optional = {}) {
|
|
139
|
+
if (typeof name !== 'string' || !isRecord(input))
|
|
140
|
+
return false;
|
|
141
|
+
if (!WRITE_TOOL_NAMES.has(name))
|
|
142
|
+
return false;
|
|
143
|
+
if (/\.(html|htm|css|js|jsx|ts|tsx|md)$/iu.test(toolInputPath({ input })))
|
|
144
|
+
return true;
|
|
145
|
+
return typeof input.content === 'string' || typeof input.new_string === 'string';
|
|
146
|
+
}
|
|
147
|
+
// Coverage-driven refactor (2026-07-18, no behavior change): both
|
|
148
|
+
// `fileWriteContent` and `isHtmlWriteToolInput` originally opened with
|
|
149
|
+
// their own `if (!isRecord(input)) return ...;` guard. Each function
|
|
150
|
+
// has exactly one call site (`emitToolUse`, for both), and both call
|
|
151
|
+
// sites already sit inside an `if (isFileWriteToolUse(name, input))`
|
|
152
|
+
// block, which itself already asserted `isRecord(input)` before
|
|
153
|
+
// returning true. So `input` is always a record by the time either
|
|
154
|
+
// function runs — the guards duplicated a check the shared caller
|
|
155
|
+
// already made. Removed the runtime early-return per the coverage
|
|
156
|
+
// skill's Phase 6.5 "dead branch" classification rather than fake a
|
|
157
|
+
// test with a non-record `input` neither function can ever actually
|
|
158
|
+
// receive (see archived provenance ledger), replaced by a one-line type assertion
|
|
159
|
+
// (classification 4: TS-required, no real runtime path) so the
|
|
160
|
+
// parameter can stay `unknown` without disturbing the call sites.
|
|
161
|
+
export function fileWriteContent({ input }, _optional = {}) {
|
|
162
|
+
const record = input;
|
|
163
|
+
if (typeof record.content === 'string')
|
|
164
|
+
return record.content;
|
|
165
|
+
if (typeof record.new_string === 'string')
|
|
166
|
+
return record.new_string;
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
export function isHtmlWriteToolInput({ input }, _optional = {}) {
|
|
170
|
+
const record = input;
|
|
171
|
+
const rawPath = record.file_path ?? record.filePath;
|
|
172
|
+
if (typeof rawPath === 'string' && /\.(?:html?|xhtml)$/i.test(rawPath))
|
|
173
|
+
return true;
|
|
174
|
+
const content = fileWriteContent({ input });
|
|
175
|
+
return typeof content === 'string' && /<!doctype\s+html\b|<html\b/i.test(content);
|
|
176
|
+
}
|
|
177
|
+
export function artifactOpenCandidateLength({ text, openTag }, _optional = {}) {
|
|
178
|
+
const max = Math.min(openTag.length - 1, text.length);
|
|
179
|
+
for (let len = max; len > 0; len -= 1) {
|
|
180
|
+
if (openTag.startsWith(text.slice(-len)))
|
|
181
|
+
return len;
|
|
182
|
+
}
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
function isHtmlArtifact(candidate) {
|
|
186
|
+
const openTag = candidate.slice(0, Math.max(0, candidate.indexOf('>') + 1));
|
|
187
|
+
return /\btype\s*=\s*["']text\/html["']/i.test(openTag);
|
|
188
|
+
}
|
|
189
|
+
export function normalizeArtifactEchoContent({ value }, _optional = {}) {
|
|
190
|
+
const normalized = value
|
|
191
|
+
.replace(/^\uFEFF/, '')
|
|
192
|
+
.replace(/\r\n?/g, '\n');
|
|
193
|
+
return trimEchoPadding(normalized);
|
|
194
|
+
}
|
|
195
|
+
/** Length of the padding token (whitespace, or a literal `\r`/`\n` escape) starting at `index`; 0 if none. */
|
|
196
|
+
function echoPaddingAt({ text, index }) {
|
|
197
|
+
if (/\s/.test(text.charAt(index)))
|
|
198
|
+
return 1;
|
|
199
|
+
return text.startsWith('\\r', index) || text.startsWith('\\n', index) ? 2 : 0;
|
|
200
|
+
}
|
|
201
|
+
/** Length of the padding token ending just before `end`; 0 if none. */
|
|
202
|
+
function echoPaddingBefore({ text, end }) {
|
|
203
|
+
if (end > 0 && /\s/.test(text.charAt(end - 1)))
|
|
204
|
+
return 1;
|
|
205
|
+
return end > 1 && echoPaddingAt({ text, index: end - 2 }) === 2 ? 2 : 0;
|
|
206
|
+
}
|
|
207
|
+
/** Strips leading and trailing runs of whitespace and literal `\r`/`\n` escapes. Same result as
|
|
208
|
+
* `text.replace(/^(?:\s|\\r|\\n)+|(?:\s|\\r|\\n)+$/g, '')`, without its quadratic backtracking. */
|
|
209
|
+
function trimEchoPadding(text) {
|
|
210
|
+
let start = 0;
|
|
211
|
+
for (let step = echoPaddingAt({ text, index: start }); step > 0; step = echoPaddingAt({ text, index: start }))
|
|
212
|
+
start += step;
|
|
213
|
+
let end = text.length;
|
|
214
|
+
for (let step = echoPaddingBefore({ text, end }); step > 0 && end - step >= start; step = echoPaddingBefore({ text, end }))
|
|
215
|
+
end -= step;
|
|
216
|
+
return text.slice(start, end);
|
|
217
|
+
}
|
|
218
|
+
export function isRedundantWrittenArtifact({ candidate, ctx }, _optional = {}) {
|
|
219
|
+
const gt = candidate.indexOf('>');
|
|
220
|
+
const close = candidate.lastIndexOf('</artifact>');
|
|
221
|
+
if (gt === -1 || close === -1 || close <= gt)
|
|
222
|
+
return false;
|
|
223
|
+
if (ctx.suppressHtmlArtifactsAfterFileWrite && isHtmlArtifact(candidate) && ctx.wroteHtmlFileThisTurn) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
const body = normalizeArtifactEchoContent({ value: candidate.slice(gt + 1, close) });
|
|
227
|
+
return ctx.recentWriteContents.some((content) => content === body);
|
|
228
|
+
}
|
|
229
|
+
export function assistantText({ content }, _optional = {}) {
|
|
230
|
+
const parts = [];
|
|
231
|
+
for (const block of content) {
|
|
232
|
+
if (isRecord(block) && block.type === 'text' && typeof block.text === 'string') {
|
|
233
|
+
parts.push(block.text);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return parts.join('\n').trim();
|
|
237
|
+
}
|
|
238
|
+
export function isUnstreamedTextBlock(block, { alreadyStreamed }) {
|
|
239
|
+
return !alreadyStreamed && block.type === 'text' && typeof block.text === 'string' && block.text.length > 0;
|
|
240
|
+
}
|
|
241
|
+
export function isUnstreamedThinkingBlock(block, { alreadyStreamed }) {
|
|
242
|
+
return (!alreadyStreamed && block.type === 'thinking' && typeof block.thinking === 'string' && block.thinking.length > 0);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The init frame's `mcp_servers`, reduced to `{name, status}`, or `undefined` when the frame has no
|
|
246
|
+
* such list. Kept on the event so a host can tell "its bridge did not connect" from "no bridge was
|
|
247
|
+
* configured": Claude Code times a dead MCP server out, reports it `failed` here, and carries on
|
|
248
|
+
* without its tools (the 2026-10-01 desktop incident). Entries without a string name and status are
|
|
249
|
+
* dropped rather than guessed at.
|
|
250
|
+
*/
|
|
251
|
+
export function initMcpServers({ obj }, _optional = {}) {
|
|
252
|
+
if (!Array.isArray(obj.mcp_servers))
|
|
253
|
+
return undefined;
|
|
254
|
+
return obj.mcp_servers.flatMap((server) => isRecord(server) && typeof server.name === 'string' && typeof server.status === 'string'
|
|
255
|
+
? [{ name: server.name, status: server.status }]
|
|
256
|
+
: []);
|
|
257
|
+
}
|
|
258
|
+
export function handleSystemMessage({ obj, onEvent }, _optional = {}) {
|
|
259
|
+
if (obj.subtype === 'init') {
|
|
260
|
+
const mcpServers = initMcpServers({ obj });
|
|
261
|
+
onEvent({
|
|
262
|
+
type: 'status',
|
|
263
|
+
label: 'initializing',
|
|
264
|
+
model: obj.model ?? null,
|
|
265
|
+
sessionId: obj.session_id ?? null,
|
|
266
|
+
...(mcpServers !== undefined ? { mcpServers } : {}),
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (obj.subtype === 'status') {
|
|
271
|
+
onEvent({ type: 'status', label: typeof obj.status === 'string' ? obj.status : 'working' });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export function stringifyToolResult({ content }, _optional = {}) {
|
|
275
|
+
if (typeof content === 'string')
|
|
276
|
+
return content;
|
|
277
|
+
if (Array.isArray(content)) {
|
|
278
|
+
return content
|
|
279
|
+
.map((c) => (isRecord(c) && c.type === 'text' ? String(c.text) : JSON.stringify(c)))
|
|
280
|
+
.join('\n');
|
|
281
|
+
}
|
|
282
|
+
return JSON.stringify(content);
|
|
283
|
+
}
|
|
284
|
+
// `user` messages in a stream-json transcript are usually tool_result
|
|
285
|
+
// wrappers from prior turns.
|
|
286
|
+
export function handleUserMessage({ obj, onEvent }, _optional = {}) {
|
|
287
|
+
if (!isRecord(obj.message) || !Array.isArray(obj.message.content))
|
|
288
|
+
return;
|
|
289
|
+
for (const block of obj.message.content) {
|
|
290
|
+
if (!isRecord(block))
|
|
291
|
+
continue;
|
|
292
|
+
if (block.type === 'tool_result') {
|
|
293
|
+
const delegated = readDelegatedResult({ content: block.content });
|
|
294
|
+
onEvent({
|
|
295
|
+
type: 'tool_result',
|
|
296
|
+
toolUseId: block.tool_use_id,
|
|
297
|
+
// Keep original pixels until the daemon verifies the run, outcome and digest.
|
|
298
|
+
content: stringifyToolResult({ content: block.content }),
|
|
299
|
+
...(delegated ? { delegatedToolUseId: delegated.marker.toolUseId, delegatedResultContent: delegated.content } : {}),
|
|
300
|
+
isError: Boolean(block.is_error),
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
export function applyInputJsonDelta({ state, partialJson, onEvent }, _optional = {}) {
|
|
306
|
+
if (!state || state.type !== 'tool_use')
|
|
307
|
+
return;
|
|
308
|
+
state.input += partialJson;
|
|
309
|
+
if (typeof state.id === 'string' && typeof state.name === 'string') {
|
|
310
|
+
onEvent({
|
|
311
|
+
type: 'tool_input_delta',
|
|
312
|
+
id: state.id,
|
|
313
|
+
name: state.name,
|
|
314
|
+
delta: partialJson,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
export function emitAssistantErrorIfPresent({ obj, content, onEvent }, _optional = {}) {
|
|
319
|
+
if (typeof obj.error !== 'string' || !obj.error.trim())
|
|
320
|
+
return;
|
|
321
|
+
onEvent({
|
|
322
|
+
type: 'error',
|
|
323
|
+
message: assistantText({ content }) || obj.error,
|
|
324
|
+
code: obj.error,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=claude-stream-frames.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type EventSink } from './claude-stream-frames.js';
|
|
2
|
+
export interface ClaudeStreamHandlerOptions {
|
|
3
|
+
suppressHtmlArtifactsAfterFileWrite?: boolean;
|
|
4
|
+
/** Clock used only when an interrupted segment omits its duration. */
|
|
5
|
+
nowMs?: () => number;
|
|
6
|
+
/** Claude's results span a session; compatible CLIs can retain per-run cost semantics. */
|
|
7
|
+
costBasis?: 'session' | 'run';
|
|
8
|
+
}
|
|
9
|
+
/** Builds the `{ feed, flush }` handler `createClaudeStreamHandler` returns. */
|
|
10
|
+
export declare function createStreamHandlerImpl({ onEvent, options }: {
|
|
11
|
+
onEvent: EventSink;
|
|
12
|
+
options: ClaudeStreamHandlerOptions;
|
|
13
|
+
}, _optional?: Record<string, never>): {
|
|
14
|
+
feed: ({ chunk }: {
|
|
15
|
+
chunk: string;
|
|
16
|
+
}) => void;
|
|
17
|
+
flush: () => void;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=claude-stream-handler.d.ts.map
|