@jini-ai/agent-runtime 0.7.1 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +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 +3 -1
- package/dist/agent-protocol/acp/constants.js +2 -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 +157 -129
- 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 +226 -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 +27 -15
- 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/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,353 @@
|
|
|
1
|
+
import { sanitizeUntrustedText } from '@jini-ai/core/text';
|
|
2
|
+
import { dispatchFrame, extractErrorMessage, isRecord, nonEmptyString, pickUsage, safeParseJson, stringifyContent, todoWriteInputFromItems, trimmedNonBlank } from '../../json-event-stream-shared.js';
|
|
3
|
+
export function createCodexStreamState() {
|
|
4
|
+
return { toolUses: new Set(), errorEmitted: false, previousEventWasAgentMessage: false, lastAgentMessageEndedWithNewline: false };
|
|
5
|
+
}
|
|
6
|
+
function parseJsonObjectsFromContent(value) {
|
|
7
|
+
// The caller requires CONNECTOR_TOOL_NOT_FOUND before parsing. Empty input also reaches the
|
|
8
|
+
// existing [] fallback naturally, so no separate empty-string branch is needed.
|
|
9
|
+
const trimmed = value.trim();
|
|
10
|
+
const direct = safeParseJson({ value: trimmed });
|
|
11
|
+
if (isRecord(direct))
|
|
12
|
+
return [direct];
|
|
13
|
+
const objects = [];
|
|
14
|
+
for (const line of trimmed.split(/\r?\n/u)) {
|
|
15
|
+
const parsedLine = safeParseJson({ value: line.trim() });
|
|
16
|
+
if (isRecord(parsedLine))
|
|
17
|
+
objects.push(parsedLine);
|
|
18
|
+
}
|
|
19
|
+
return objects;
|
|
20
|
+
}
|
|
21
|
+
function extractConnectorApiError(value) {
|
|
22
|
+
if (isRecord(value.error)) {
|
|
23
|
+
if (typeof value.error.code === 'string')
|
|
24
|
+
return value.error;
|
|
25
|
+
if (isRecord(value.error.data) && isRecord(value.error.data.error)) {
|
|
26
|
+
const wrappedError = value.error.data.error;
|
|
27
|
+
if (typeof wrappedError.code === 'string')
|
|
28
|
+
return wrappedError;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function connectorToolSelectionErrorMessage(content) {
|
|
34
|
+
if (!content.includes('CONNECTOR_TOOL_NOT_FOUND'))
|
|
35
|
+
return null;
|
|
36
|
+
const error = parseJsonObjectsFromContent(content)
|
|
37
|
+
.map(extractConnectorApiError)
|
|
38
|
+
.find((parsedError) => parsedError?.code === 'CONNECTOR_TOOL_NOT_FOUND');
|
|
39
|
+
if (!error)
|
|
40
|
+
return null;
|
|
41
|
+
const details = isRecord(error.details) ? error.details : {};
|
|
42
|
+
const connectorId = nonEmptyString({ value: details.connectorId });
|
|
43
|
+
const toolName = nonEmptyString({ value: details.toolName }) ?? 'the requested connector tool';
|
|
44
|
+
const target = connectorId
|
|
45
|
+
? `Connector tool ${toolName} is not allowed for connector ${connectorId}.`
|
|
46
|
+
: `Connector tool ${toolName} is not allowed.`;
|
|
47
|
+
return `${target} Re-list the connector catalog and choose one of the currently allowed read-only tools.`;
|
|
48
|
+
}
|
|
49
|
+
function isRecoverableCodexReconnect(message) {
|
|
50
|
+
return (message.startsWith('Reconnecting...') &&
|
|
51
|
+
(message.includes('timeout waiting for child process to exit') ||
|
|
52
|
+
message.includes('stream disconnected before completion')));
|
|
53
|
+
}
|
|
54
|
+
function codexTodoListInput(item) {
|
|
55
|
+
if (item.type !== 'todo_list' || !Array.isArray(item.items))
|
|
56
|
+
return null;
|
|
57
|
+
return todoWriteInputFromItems({ items: item.items });
|
|
58
|
+
}
|
|
59
|
+
function emitCodexTodoList(item, onEvent) {
|
|
60
|
+
if (typeof item.id !== 'string')
|
|
61
|
+
return false;
|
|
62
|
+
const input = codexTodoListInput(item);
|
|
63
|
+
if (!input)
|
|
64
|
+
return false;
|
|
65
|
+
onEvent({
|
|
66
|
+
type: 'tool_use',
|
|
67
|
+
id: item.id,
|
|
68
|
+
name: 'TodoWrite',
|
|
69
|
+
input,
|
|
70
|
+
});
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function hasStringId(item) {
|
|
74
|
+
return typeof item.id === 'string';
|
|
75
|
+
}
|
|
76
|
+
/** Marks `key` as emitted in `state.codex.toolUses`; `true` only the first time (Codex repeats frames per call). */
|
|
77
|
+
function claimCodexToolUse(state, key) {
|
|
78
|
+
if (state.codex.toolUses.has(key))
|
|
79
|
+
return false;
|
|
80
|
+
state.codex.toolUses.add(key);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
function resetCodexAgentMessageBoundary(state) {
|
|
84
|
+
state.codex.previousEventWasAgentMessage = false;
|
|
85
|
+
state.codex.lastAgentMessageEndedWithNewline = false;
|
|
86
|
+
}
|
|
87
|
+
/** Emits a Codex `error` only for the first error of the stream; later ones are dropped. */
|
|
88
|
+
function emitCodexErrorOnce(message, onEvent, state) {
|
|
89
|
+
if (state.codex.errorEmitted)
|
|
90
|
+
return;
|
|
91
|
+
state.codex.errorEmitted = true;
|
|
92
|
+
onEvent({ type: 'error', message });
|
|
93
|
+
}
|
|
94
|
+
function codexMcpToolName(item) {
|
|
95
|
+
const tool = nonEmptyString({ value: item.tool });
|
|
96
|
+
// Preserve the bridge's catalog names; external MCP must never masquerade as Bash/Edit.
|
|
97
|
+
// A Jini call is named `mcp__jini__X` exactly as Claude Code names it: the daemon bridge also
|
|
98
|
+
// reports a direct call as its own `X` row, and @jini-ai/chat folds the pair into one row only
|
|
99
|
+
// when the CLI row carries the MCP prefix (a bare `X` drew every Codex direct call twice).
|
|
100
|
+
const server = typeof item.server === 'string' ? item.server : 'external';
|
|
101
|
+
return `mcp__${server}__${tool ?? 'call'}`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Emits the `tool_use` for one `item.type: 'mcp_tool_call'` item, deduped per `item.id` via
|
|
105
|
+
* `state.codex.toolUses` (the same dedup `command_execution`'s two call sites — `item.started` and
|
|
106
|
+
* `item.completed` — already rely on, since Codex reports both frames for one call).
|
|
107
|
+
*
|
|
108
|
+
* `item.tool` — the literal MCP tool name Codex called (`search_tools`, `describe_tool`,
|
|
109
|
+
* `execute_delegated_tool`) — is used verbatim (behind the `mcp__jini__` prefix, see
|
|
110
|
+
* {@link codexMcpToolName}) as the emitted `name`, never unwrapped to the
|
|
111
|
+
* delegated `toolId` inside `item.arguments`: `@jini-ai/chat`'s `ToolCard`/`DelegatedToolCard`
|
|
112
|
+
* already recover that id from `{toolId, input}` for `execute_delegated_tool` specifically (see that
|
|
113
|
+
* component's own doc), so duplicating the unwrap here would be a second, driftable copy of the same
|
|
114
|
+
* decision.
|
|
115
|
+
*
|
|
116
|
+
* @param item - The `item.started`/`item.completed` payload's `item` object.
|
|
117
|
+
* @param onEvent - Sink for the emitted `tool_use`.
|
|
118
|
+
* @param state - Parser state; only `codexToolUses` is read/written.
|
|
119
|
+
* @returns `true` iff this item is an `mcp_tool_call` with a usable id (whether or not a `tool_use`
|
|
120
|
+
* was newly emitted vs. already deduped) — this is what `handleCodexEvent`'s `item.started` branch
|
|
121
|
+
* uses to decide the frame was handled.
|
|
122
|
+
* @complexity O(1).
|
|
123
|
+
* @overallScore 100
|
|
124
|
+
*/
|
|
125
|
+
function emitCodexMcpToolUse(item, onEvent, state) {
|
|
126
|
+
if (item.type !== 'mcp_tool_call' || !hasStringId(item))
|
|
127
|
+
return false;
|
|
128
|
+
if (claimCodexToolUse(state, item.id)) {
|
|
129
|
+
onEvent({
|
|
130
|
+
type: 'tool_use',
|
|
131
|
+
id: item.id,
|
|
132
|
+
name: codexMcpToolName(item),
|
|
133
|
+
input: item.arguments ?? {},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
function emitCodexBashToolUse(item, onEvent, state) {
|
|
139
|
+
if (!claimCodexToolUse(state, item.id))
|
|
140
|
+
return;
|
|
141
|
+
onEvent({
|
|
142
|
+
type: 'tool_use',
|
|
143
|
+
id: item.id,
|
|
144
|
+
name: 'Bash',
|
|
145
|
+
input: {
|
|
146
|
+
command: typeof item.command === 'string' ? item.command : '',
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function emitCodexCollabToolCall(item, completed, onEvent, state) {
|
|
151
|
+
if (claimCodexToolUse(state, item.id)) {
|
|
152
|
+
onEvent({ type: 'tool_use', id: item.id,
|
|
153
|
+
name: typeof item.tool === 'string' ? item.tool : 'collab_tool_call', input: {} });
|
|
154
|
+
}
|
|
155
|
+
if (completed && claimCodexToolUse(state, `${item.id}:completed`)) {
|
|
156
|
+
onEvent({ type: 'tool_result', toolUseId: item.id,
|
|
157
|
+
content: 'Native agent action completed.', isError: item.status === 'failed' });
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
function handleCodexItemStarted(item, onEvent, state) {
|
|
162
|
+
if (emitCodexTodoList(item, onEvent)) {
|
|
163
|
+
resetCodexAgentMessageBoundary(state);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (item.type === 'command_execution' && hasStringId(item)) {
|
|
167
|
+
resetCodexAgentMessageBoundary(state);
|
|
168
|
+
emitCodexBashToolUse(item, onEvent, state);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
if (item.type !== 'mcp_tool_call')
|
|
172
|
+
return false;
|
|
173
|
+
resetCodexAgentMessageBoundary(state);
|
|
174
|
+
return emitCodexMcpToolUse(item, onEvent, state);
|
|
175
|
+
}
|
|
176
|
+
function handleCodexItemUpdated(item, onEvent, state) {
|
|
177
|
+
if (!emitCodexTodoList(item, onEvent))
|
|
178
|
+
return false;
|
|
179
|
+
resetCodexAgentMessageBoundary(state);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
function completeCodexFileChange(item, onEvent, state) {
|
|
183
|
+
// Codex reports direct patches as file_change, rather than command_execution. Surface paths
|
|
184
|
+
// through the SAME native-tool event channel so audit sees edits without persisting patches.
|
|
185
|
+
if (claimCodexToolUse(state, item.id))
|
|
186
|
+
emitCodexFileChange(item, onEvent);
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
function emitCodexFileChange(item, onEvent) {
|
|
190
|
+
const changes = Array.isArray(item.changes) ? item.changes : [];
|
|
191
|
+
onEvent({ type: 'tool_use', id: item.id, name: 'apply_patch',
|
|
192
|
+
input: { paths: changes.filter(isRecord).map(change => change.path).filter(path => typeof path === 'string') } });
|
|
193
|
+
onEvent({ type: 'tool_result', toolUseId: item.id, content: 'File change reported by Codex.', isError: item.status === 'failed' });
|
|
194
|
+
}
|
|
195
|
+
function completeCodexCommand(item, onEvent, state) {
|
|
196
|
+
resetCodexAgentMessageBoundary(state);
|
|
197
|
+
emitCodexBashToolUse(item, onEvent, state);
|
|
198
|
+
const content = stringifyContent({ value: item.aggregated_output ?? '' });
|
|
199
|
+
onEvent({
|
|
200
|
+
type: 'tool_result',
|
|
201
|
+
toolUseId: item.id,
|
|
202
|
+
content,
|
|
203
|
+
isError: typeof item.exit_code === 'number' ? item.exit_code !== 0 : item.status === 'failed',
|
|
204
|
+
});
|
|
205
|
+
const connectorToolError = connectorToolSelectionErrorMessage(content);
|
|
206
|
+
if (connectorToolError)
|
|
207
|
+
emitCodexErrorOnce(connectorToolError, onEvent, state);
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Select a failed MCP call's diagnostic without exposing arguments or result metadata.
|
|
212
|
+
* Codex 0.161.0's exec mapper carries result content/structured_content independently of error:
|
|
213
|
+
* https://github.com/openai/codex/blob/rust-v0.161.0/codex-rs/exec/src/event_processor_with_jsonl_output.rs#L195
|
|
214
|
+
* @returns Sanitized error text, or the generic failure when no diagnostic is present.
|
|
215
|
+
* @complexity O(n) time/space for n diagnostic characters, including the shared sanitizer pass.
|
|
216
|
+
*/
|
|
217
|
+
function codexMcpFailureContent({ item }, _options = {}) {
|
|
218
|
+
const error = trimmedNonBlank({ value: extractErrorMessage({ value: item.error, fallback: '' }) });
|
|
219
|
+
const result = isRecord(item.result) ? item.result : {};
|
|
220
|
+
const blocks = Array.isArray(result.content) ? result.content : [];
|
|
221
|
+
// Keep text verbatim until sanitizing so JSON error envelopes retain codes and recovery hints.
|
|
222
|
+
const text = blocks.filter(isRecord)
|
|
223
|
+
.filter(block => block.type === 'text')
|
|
224
|
+
.map(block => trimmedNonBlank({ value: block.text }))
|
|
225
|
+
.filter(Boolean)
|
|
226
|
+
.join('\n');
|
|
227
|
+
const structuredText = extractErrorMessage({ value: result.structured_content, fallback: '' });
|
|
228
|
+
const diagnostic = error || text || trimmedNonBlank({ value: structuredText }) || 'MCP tool call failed';
|
|
229
|
+
return sanitizeUntrustedText({ text: diagnostic });
|
|
230
|
+
}
|
|
231
|
+
function completeCodexMcpToolCall(item, onEvent, state) {
|
|
232
|
+
resetCodexAgentMessageBoundary(state);
|
|
233
|
+
// `item.started` normally already emitted the matching `tool_use` (see
|
|
234
|
+
// `emitCodexMcpToolUse`); this call is a no-op then, and only actually emits one for a
|
|
235
|
+
// call whose `item.started` frame this parser never saw (a truncated/mid-stream feed —
|
|
236
|
+
// the same fallback shape `command_execution`'s own `item.completed` branch above uses).
|
|
237
|
+
emitCodexMcpToolUse(item, onEvent, state);
|
|
238
|
+
// A call Codex's own approval gate denies before ever reaching the target MCP server
|
|
239
|
+
// reports back exactly this shape — `status: 'failed'`, `result: null`, an `error` object
|
|
240
|
+
// — which is otherwise indistinguishable from "never happened" downstream: no
|
|
241
|
+
// `tool_use`/`tool_result` pair means no audit row, no error card, nothing an operator or
|
|
242
|
+
// the model itself can ground a claim on. `isError` on `status !== 'completed'` (not a
|
|
243
|
+
// truthiness check on `item.error`) matches every other status branch in this file and
|
|
244
|
+
// stays correct even for a hypothetical future status this union does not name yet.
|
|
245
|
+
const isError = item.status !== 'completed';
|
|
246
|
+
const content = isError
|
|
247
|
+
? codexMcpFailureContent({ item })
|
|
248
|
+
: stringifyContent({ value: item.result });
|
|
249
|
+
onEvent({ type: 'tool_result', toolUseId: item.id, content, isError });
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
function emitCodexAgentMessage(item, onEvent, state) {
|
|
253
|
+
const text = item.type === 'agent_message' ? nonEmptyString({ value: item.text }) : null;
|
|
254
|
+
if (!text)
|
|
255
|
+
return false;
|
|
256
|
+
const needsBoundary = state.codex.previousEventWasAgentMessage &&
|
|
257
|
+
!state.codex.lastAgentMessageEndedWithNewline &&
|
|
258
|
+
!text.startsWith('\n');
|
|
259
|
+
const delta = needsBoundary ? `\n${text}` : text;
|
|
260
|
+
onEvent({ type: 'text_delta', delta });
|
|
261
|
+
state.codex.previousEventWasAgentMessage = true;
|
|
262
|
+
state.codex.lastAgentMessageEndedWithNewline = text.endsWith('\n');
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
function handleCodexItemCompleted(item, onEvent, state) {
|
|
266
|
+
if (item.type === 'file_change' && hasStringId(item))
|
|
267
|
+
return completeCodexFileChange(item, onEvent, state);
|
|
268
|
+
if (emitCodexTodoList(item, onEvent)) {
|
|
269
|
+
resetCodexAgentMessageBoundary(state);
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
if (item.type === 'command_execution' && hasStringId(item))
|
|
273
|
+
return completeCodexCommand(item, onEvent, state);
|
|
274
|
+
if (item.type === 'mcp_tool_call' && hasStringId(item))
|
|
275
|
+
return completeCodexMcpToolCall(item, onEvent, state);
|
|
276
|
+
return emitCodexAgentMessage(item, onEvent, state);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Wraps a per-frame item handler with the checks every `item.*` frame shares: a record `item`, and
|
|
280
|
+
* native `collab_tool_call` items, which report the same way on started/updated/completed.
|
|
281
|
+
*/
|
|
282
|
+
function codexItemFrame(handleItem) {
|
|
283
|
+
return (obj, onEvent, state) => {
|
|
284
|
+
if (!isRecord(obj.item))
|
|
285
|
+
return false;
|
|
286
|
+
const item = obj.item;
|
|
287
|
+
if (item.type === 'collab_tool_call' && hasStringId(item)) {
|
|
288
|
+
return emitCodexCollabToolCall(item, obj.type === 'item.completed', onEvent, state);
|
|
289
|
+
}
|
|
290
|
+
return handleItem(item, onEvent, state);
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function handleCodexError(obj, onEvent, state) {
|
|
294
|
+
const message = extractErrorMessage({ value: obj.message ?? obj.error, fallback: 'Codex error' });
|
|
295
|
+
// Reconnecting events are recoverable — treat as status warning, not fatal
|
|
296
|
+
if (isRecoverableCodexReconnect(message)) {
|
|
297
|
+
onEvent({ type: 'status', label: message });
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
emitCodexErrorOnce(message, onEvent, state);
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
function handleCodexTurnFailed(obj, onEvent, state) {
|
|
304
|
+
emitCodexErrorOnce(extractErrorMessage({ value: obj.error ?? obj.message, fallback: 'Codex turn failed' }), onEvent, state);
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
function handleCodexThreadStarted(obj, onEvent) {
|
|
308
|
+
// `thread_id` is Codex's own session handle, surfaced on the same
|
|
309
|
+
// `sessionId` status channel claude uses (claude-stream.ts). It serves two
|
|
310
|
+
// consumers: (1) the daemon persists it to `agent_sessions` and replays it
|
|
311
|
+
// as `exec resume <thread_id>` on the next turn (capture-style resume), and
|
|
312
|
+
// (2) it identifies this run's rollout file
|
|
313
|
+
// (`$CODEX_HOME/sessions/**/rollout-*-<thread_id>.jsonl`), the only place
|
|
314
|
+
// codex records per-call usage, which run_finished reads to recover the
|
|
315
|
+
// turn's first-call cache hit (codex's stream usage is cumulative only).
|
|
316
|
+
// Codex emits this both for a fresh `exec` and for `exec resume` (echoing
|
|
317
|
+
// the resumed id), so it is a stable capture point either way.
|
|
318
|
+
onEvent({ type: 'status', label: 'initializing', sessionId: nonEmptyString({ value: obj.thread_id }) });
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
function handleCodexTurnStarted(_obj, onEvent, state) {
|
|
322
|
+
resetCodexAgentMessageBoundary(state);
|
|
323
|
+
onEvent({ type: 'status', label: 'thinking' });
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
const CODEX_USAGE_FIELDS = [
|
|
327
|
+
['input_tokens', 'input_tokens'],
|
|
328
|
+
['output_tokens', 'output_tokens'],
|
|
329
|
+
['reasoning_output_tokens', 'thought_tokens'],
|
|
330
|
+
['cached_input_tokens', 'cached_read_tokens'],
|
|
331
|
+
];
|
|
332
|
+
function handleCodexTurnCompleted(obj, onEvent) {
|
|
333
|
+
if (!isRecord(obj.usage))
|
|
334
|
+
return false;
|
|
335
|
+
onEvent({ type: 'usage', usage: pickUsage({ source: obj.usage, fields: CODEX_USAGE_FIELDS }) });
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
const CODEX_FRAME_HANDLERS = new Map([
|
|
339
|
+
['error', handleCodexError],
|
|
340
|
+
['turn.failed', handleCodexTurnFailed],
|
|
341
|
+
['thread.started', handleCodexThreadStarted],
|
|
342
|
+
['turn.started', handleCodexTurnStarted],
|
|
343
|
+
['item.started', codexItemFrame(handleCodexItemStarted)],
|
|
344
|
+
['item.updated', codexItemFrame(handleCodexItemUpdated)],
|
|
345
|
+
['item.completed', codexItemFrame(handleCodexItemCompleted)],
|
|
346
|
+
['turn.completed', handleCodexTurnCompleted],
|
|
347
|
+
]);
|
|
348
|
+
export function handleCodexEvent(obj, onEvent, state) {
|
|
349
|
+
if (!isRecord(obj))
|
|
350
|
+
return false;
|
|
351
|
+
return dispatchFrame({ handlers: CODEX_FRAME_HANDLERS, obj, onEvent, state });
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=event-stream.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExecutableResolutionHelpers, ResolvedExecutableOptions } from '../../executable-helpers.js';
|
|
2
|
+
export declare function codexAppBundleExecutable(options: ResolvedExecutableOptions, services: ExecutableResolutionHelpers): string | null;
|
|
3
|
+
export declare function codexBundleCandidates({ options, services }: {
|
|
4
|
+
options: ResolvedExecutableOptions;
|
|
5
|
+
services: ExecutableResolutionHelpers;
|
|
6
|
+
}, _optional?: Record<string, never>): string[];
|
|
7
|
+
//# sourceMappingURL=executable-resolution.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
// The official OpenAI Codex desktop app ships the `codex` CLI *inside* its
|
|
3
|
+
// macOS application bundle and does NOT add it to PATH unless the user
|
|
4
|
+
// explicitly runs the app's "Install command line tool" action. Users who
|
|
5
|
+
// installed Codex only through the app therefore see a "not installed"
|
|
6
|
+
// agent card even though a healthy native `codex` binary exists on disk,
|
|
7
|
+
// because neither PATH nor the user-toolchain search dirs cover the app
|
|
8
|
+
// bundle. Probe the well-known bundle locations so app-only installs are
|
|
9
|
+
// detected. This is a last-resort fallback that ranks below PATH, so an
|
|
10
|
+
// explicit `npm i -g` / Homebrew / version-manager install always wins.
|
|
11
|
+
export function codexAppBundleExecutable(options, services) {
|
|
12
|
+
for (const candidate of codexBundleCandidates({ options, services })) {
|
|
13
|
+
const resolved = services.executableFilePath(candidate, options);
|
|
14
|
+
if (resolved)
|
|
15
|
+
return resolved;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export function codexBundleCandidates({ options, services }, _optional = {}) {
|
|
20
|
+
// The Codex app bundle is a macOS-only concept; other platforms have no
|
|
21
|
+
// analogous standalone install of the `codex` CLI to probe for here.
|
|
22
|
+
if (process.platform !== 'darwin')
|
|
23
|
+
return [];
|
|
24
|
+
const { home, hasOverride } = services.resolveDetectionHome(options);
|
|
25
|
+
const bundleSuffix = ['Codex.app', 'Contents', 'Resources', 'codex'];
|
|
26
|
+
// User-scoped install (~/Applications). Honors the override home so
|
|
27
|
+
// sandboxed detection runs and tests stay deterministic.
|
|
28
|
+
const candidates = [path.join(home, 'Applications', ...bundleSuffix)];
|
|
29
|
+
// System-wide /Applications install. Skip it under an override home for
|
|
30
|
+
// the same isolation reason `userToolchainDirs` skips Homebrew/system
|
|
31
|
+
// bins.
|
|
32
|
+
if (!hasOverride) {
|
|
33
|
+
candidates.unshift(path.join('/Applications', ...bundleSuffix));
|
|
34
|
+
}
|
|
35
|
+
return candidates;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=executable-resolution.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AgentLaunchResolution } from '@jini-ai/core/contracts/agents';
|
|
2
|
+
export declare function resolveCodexLaunch(selectedPath: string, childPathPrepend: string[]): Pick<AgentLaunchResolution, 'launchPath' | 'launchKind' | 'childPathPrepend' | 'diagnostic'>;
|
|
3
|
+
//# sourceMappingURL=launch.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { accessSync, closeSync, constants, openSync, readdirSync, readSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function resolveCodexLaunch(selectedPath, childPathPrepend) {
|
|
4
|
+
const native = tryResolveCodexNativeBinary(selectedPath);
|
|
5
|
+
return {
|
|
6
|
+
launchPath: native.path ?? selectedPath,
|
|
7
|
+
launchKind: native.path ? 'codex-native' : 'selected',
|
|
8
|
+
childPathPrepend: [...childPathPrepend, ...native.childPathPrepend],
|
|
9
|
+
diagnostic: native.diagnostic,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function tryResolveCodexNativeBinary(wrapperPath) {
|
|
13
|
+
const packageSuffix = codexNativePackageSuffix();
|
|
14
|
+
const targetTriple = codexNativeTargetTriple();
|
|
15
|
+
for (const root of codexSearchRoots(wrapperPath)) {
|
|
16
|
+
for (const candidate of codexNativeCandidates(root, packageSuffix, targetTriple)) {
|
|
17
|
+
if (isExecutableFile(candidate.path)) {
|
|
18
|
+
return { path: candidate.path, childPathPrepend: existingDirectories(candidate.childPathPrepend), diagnostic: null };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!looksLikeCodexNodeWrapper(wrapperPath))
|
|
23
|
+
return { path: null, childPathPrepend: [], diagnostic: null };
|
|
24
|
+
return {
|
|
25
|
+
path: null,
|
|
26
|
+
childPathPrepend: [],
|
|
27
|
+
diagnostic: `Codex native binary was not found for ${packageSuffix}/${targetTriple}; falling back to wrapper ${wrapperPath}. Set CODEX_BIN to a native Codex binary if this wrapper cannot launch from a GUI environment.`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function codexSearchRoots(wrapperPath) {
|
|
31
|
+
const resolved = safeRealpath(wrapperPath) ?? wrapperPath;
|
|
32
|
+
const directory = path.dirname(resolved);
|
|
33
|
+
// npm bin symlinks resolve inside @openai/codex/bin. Only that package's
|
|
34
|
+
// install directory owns the upgrade; ancestors of the shim or package do not.
|
|
35
|
+
if (path.basename(directory) !== 'bin' || path.basename(path.dirname(directory)) !== 'codex')
|
|
36
|
+
return [directory];
|
|
37
|
+
const packageDir = path.dirname(directory);
|
|
38
|
+
const scopeDir = path.dirname(packageDir);
|
|
39
|
+
// Hoisted npm and pnpm layouts put the native package beside @openai/codex in the same
|
|
40
|
+
// node_modules; that tree already owns the wrapper, so it is not an ancestor search.
|
|
41
|
+
const ownsHoistedSibling = path.basename(scopeDir) === '@openai' && path.basename(path.dirname(scopeDir)) === 'node_modules';
|
|
42
|
+
return ownsHoistedSibling ? [packageDir, path.dirname(path.dirname(scopeDir))] : [packageDir];
|
|
43
|
+
}
|
|
44
|
+
function codexNativeCandidates(root, packageSuffix, targetTriple) {
|
|
45
|
+
const scoped = path.join(root, 'node_modules', '@openai');
|
|
46
|
+
const packageDirs = [path.join(scoped, `codex-${packageSuffix}`)];
|
|
47
|
+
try {
|
|
48
|
+
for (const entry of readdirSync(scoped, { encoding: 'utf8', withFileTypes: true })) {
|
|
49
|
+
if (entry.isDirectory() && entry.name.startsWith('codex-'))
|
|
50
|
+
packageDirs.push(path.join(scoped, entry.name));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Optional package layouts vary by npm version; absence uses wrapper fallback.
|
|
55
|
+
}
|
|
56
|
+
return [...new Set(packageDirs)].flatMap((dir) => {
|
|
57
|
+
const vendorPathDir = path.join(dir, 'vendor', targetTriple, 'path');
|
|
58
|
+
const childPathPrepend = [vendorPathDir];
|
|
59
|
+
return [
|
|
60
|
+
{ path: path.join(dir, 'vendor', targetTriple, 'codex', 'codex'), childPathPrepend },
|
|
61
|
+
{ path: path.join(dir, 'vendor', targetTriple, 'codex', 'codex.exe'), childPathPrepend },
|
|
62
|
+
{ path: path.join(dir, 'codex'), childPathPrepend },
|
|
63
|
+
{ path: path.join(dir, 'bin', 'codex'), childPathPrepend },
|
|
64
|
+
{ path: path.join(dir, 'vendor', 'codex'), childPathPrepend },
|
|
65
|
+
{ path: path.join(dir, 'codex.exe'), childPathPrepend },
|
|
66
|
+
{ path: path.join(dir, 'bin', 'codex.exe'), childPathPrepend },
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function codexNativePackageSuffix() {
|
|
71
|
+
return `${process.platform}-${process.arch}`;
|
|
72
|
+
}
|
|
73
|
+
const CODEX_NATIVE_TARGET_TRIPLES = new Map([
|
|
74
|
+
['darwin-arm64', 'aarch64-apple-darwin'],
|
|
75
|
+
['darwin-x64', 'x86_64-apple-darwin'],
|
|
76
|
+
['linux-arm64', 'aarch64-unknown-linux-musl'],
|
|
77
|
+
['linux-x64', 'x86_64-unknown-linux-musl'],
|
|
78
|
+
['win32-arm64', 'aarch64-pc-windows-msvc'],
|
|
79
|
+
['win32-x64', 'x86_64-pc-windows-msvc'],
|
|
80
|
+
]);
|
|
81
|
+
// Unmapped platform/arch pairs fall back to the npm package suffix itself.
|
|
82
|
+
function codexNativeTargetTriple() {
|
|
83
|
+
const suffix = codexNativePackageSuffix();
|
|
84
|
+
return CODEX_NATIVE_TARGET_TRIPLES.get(suffix) ?? suffix;
|
|
85
|
+
}
|
|
86
|
+
function looksLikeCodexNodeWrapper(filePath) {
|
|
87
|
+
// Read only the first 64KB rather than slurping the whole file: the
|
|
88
|
+
// selected codex path can now be the native Codex.app binary (~190MB),
|
|
89
|
+
// and `readFileSync` would otherwise load all of it into a string just
|
|
90
|
+
// to sniff a shebang. A node wrapper is a tiny script, so the header is
|
|
91
|
+
// enough.
|
|
92
|
+
let fd = null;
|
|
93
|
+
// `looksLikeWrapper` + a trailing `return looksLikeWrapper;`, rather than
|
|
94
|
+
// returning directly from inside `catch` (the `try` above keeps its own
|
|
95
|
+
// direct early `return`): a v8/istanbul coverage-instrumentation artifact
|
|
96
|
+
// for `try { return A } catch { return B } finally {}`, re-derived
|
|
97
|
+
// empirically (see `providers/model-catalog.ts`'s `listProviderModels`,
|
|
98
|
+
// which hit the exact same phantom branch at its own `finally` clause
|
|
99
|
+
// opening and got the same fix) — a minimal repro of this shape leaves an
|
|
100
|
+
// uncoverable phantom branch at the `finally` clause's own opening brace
|
|
101
|
+
// no matter which real path a test drives through. Only `catch` needed to
|
|
102
|
+
// change.
|
|
103
|
+
let looksLikeWrapper;
|
|
104
|
+
try {
|
|
105
|
+
fd = openSync(filePath, 'r');
|
|
106
|
+
const buffer = Buffer.alloc(64_000);
|
|
107
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, 0);
|
|
108
|
+
return /node|@openai\/codex|codex-/i.test(buffer.toString('utf8', 0, bytesRead));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
looksLikeWrapper = false;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
if (fd !== null) {
|
|
115
|
+
try {
|
|
116
|
+
closeSync(fd);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Best-effort close; nothing actionable if it fails.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return looksLikeWrapper;
|
|
124
|
+
}
|
|
125
|
+
function safeRealpath(filePath) {
|
|
126
|
+
try {
|
|
127
|
+
return realpathSync(filePath);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function existingDirectories(dirs) {
|
|
134
|
+
return dirs.filter((dir) => {
|
|
135
|
+
try {
|
|
136
|
+
return statSync(dir).isDirectory();
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function isExecutableFile(filePath) {
|
|
144
|
+
try {
|
|
145
|
+
if (!statSync(filePath).isFile())
|
|
146
|
+
return false;
|
|
147
|
+
if (process.platform !== 'win32')
|
|
148
|
+
accessSync(filePath, constants.X_OK);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=launch.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
function codexConfigFiles({ env, context, user, local }) {
|
|
3
|
+
const root = env.CODEX_HOME || user('.codex');
|
|
4
|
+
return [{ path: join(root, 'config.toml'), format: 'toml' },
|
|
5
|
+
...(context.profile ? [{ path: join(root, `${context.profile}.config.toml`), format: 'toml' }] : []),
|
|
6
|
+
{ path: local('.codex/config.toml'), format: 'toml' }];
|
|
7
|
+
}
|
|
8
|
+
export const codexModelConfig = {
|
|
9
|
+
files: codexConfigFiles,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=model-discovery.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @file Codex definition config. A host policy that only the Codex definition reads; it never enters a
|
|
2
|
+
* neutral contract (owner rule: vendor code lives with its vendor). Environment defaults are read at native composition. */
|
|
3
|
+
export interface CodexDefOptions {
|
|
4
|
+
/** Pass `--disable plugins` to every Codex run. */
|
|
5
|
+
readonly disablePlugins?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Explicit host/run policy wins; this is the environment default native composition falls back to. */
|
|
8
|
+
export declare function codexDefOptionsFromEnv(required: {
|
|
9
|
+
env: Record<string, string | undefined>;
|
|
10
|
+
}, _optional?: Record<string, never>): CodexDefOptions;
|
|
11
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Explicit host/run policy wins; this is the environment default native composition falls back to. */
|
|
2
|
+
export function codexDefOptionsFromEnv(required, _optional = {}) {
|
|
3
|
+
return { disablePlugins: required.env.CODEX_DISABLE_PLUGINS === '1' };
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=options.js.map
|
package/dist/defs/codex.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RuntimeModelOption, RuntimeReasoningOption } from '
|
|
2
|
-
import type {
|
|
1
|
+
import type { RuntimeModelOption, RuntimeReasoningOption, RuntimeAgentDef, RuntimeBuildOptions, RuntimeContext } from '@jini-ai/core/contracts/agents';
|
|
2
|
+
import type { CodexDefOptions } from './codex/options.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parses `codex debug models` stdout into the Local-CLI picker's model rows.
|
|
5
5
|
*
|
|
@@ -36,6 +36,12 @@ export declare function codexNeedsDangerFullAccessSandbox({}: {}, { platform, en
|
|
|
36
36
|
platform?: NodeJS.Platform;
|
|
37
37
|
env?: NodeJS.ProcessEnv;
|
|
38
38
|
}): boolean;
|
|
39
|
+
type CodexBuildArgs = RuntimeAgentDef['buildArgs'];
|
|
40
|
+
/** Codex argv. `codex` is this definition's own host config (see `defs/codex/options.ts`); the neutral
|
|
41
|
+
* `buildArgs` passes none, and only a binding that owns the host policy supplies it. */
|
|
42
|
+
export declare function buildCodexArgs({ imagePaths }: Parameters<CodexBuildArgs>[0], { extraAllowedDirs, options, runtimeContext, codex }?: NonNullable<Parameters<CodexBuildArgs>[1]> & {
|
|
43
|
+
codex?: CodexDefOptions;
|
|
44
|
+
}): string[];
|
|
39
45
|
export declare const codexAgentDef: {
|
|
40
46
|
id: string;
|
|
41
47
|
supportsNativeToolAccess: true;
|
|
@@ -58,10 +64,10 @@ export declare const codexAgentDef: {
|
|
|
58
64
|
label: string;
|
|
59
65
|
}[];
|
|
60
66
|
deriveReasoningOptions: typeof unionModelReasoningOptions;
|
|
61
|
-
buildArgs: (
|
|
67
|
+
buildArgs: (required: {
|
|
62
68
|
prompt: string;
|
|
63
69
|
imagePaths: string[];
|
|
64
|
-
},
|
|
70
|
+
}, optional?: {
|
|
65
71
|
extraAllowedDirs?: string[];
|
|
66
72
|
options?: RuntimeBuildOptions;
|
|
67
73
|
runtimeContext?: RuntimeContext;
|
|
@@ -75,19 +81,20 @@ export declare const codexAgentDef: {
|
|
|
75
81
|
mcpHttp: true;
|
|
76
82
|
externalMcpInjection: "codex-toml";
|
|
77
83
|
discoverModels(requiredArgs: {
|
|
78
|
-
context: import("
|
|
84
|
+
context: import("@jini-ai/core/contracts/agents").ModelDiscoveryContext;
|
|
79
85
|
}, optionalArgs?: {
|
|
80
86
|
signal?: AbortSignal;
|
|
81
87
|
force?: boolean;
|
|
82
88
|
staleWhileRevalidate?: boolean;
|
|
83
|
-
deps?: import("
|
|
84
|
-
}): Promise<import("
|
|
89
|
+
deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
|
|
90
|
+
}): Promise<import("@jini-ai/core/contracts/agents").ModelCatalogSnapshot>;
|
|
85
91
|
resolveDefaultModel(requiredArgs: {
|
|
86
|
-
context: import("
|
|
87
|
-
catalog: import("
|
|
92
|
+
context: import("@jini-ai/core/contracts/agents").ModelDiscoveryContext;
|
|
93
|
+
catalog: import("@jini-ai/core/contracts/agents").ModelCatalogSnapshot;
|
|
88
94
|
}, optionalArgs?: {
|
|
89
95
|
signal?: AbortSignal;
|
|
90
|
-
deps?: import("
|
|
91
|
-
}): Promise<import("
|
|
96
|
+
deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
|
|
97
|
+
}): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
|
|
92
98
|
};
|
|
99
|
+
export {};
|
|
93
100
|
//# sourceMappingURL=codex.d.ts.map
|