@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,124 @@
|
|
|
1
|
+
import {} from './openai-chat-types.js';
|
|
2
|
+
const OPENAI_ALLOWED_IMAGE_MEDIA_TYPES = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/gif']);
|
|
3
|
+
/**
|
|
4
|
+
* OpenAI documents a 512 MB total-payload cap and a 1500-image-per-request cap for the Chat
|
|
5
|
+
* Completions API (see module doc's "Image support" section) but no single-image byte limit. This
|
|
6
|
+
* module still bounds one image's base64 length defensively, matching
|
|
7
|
+
* `anthropic-messages.ts`'s posture — 20 MB is this module's own conservative choice (not an
|
|
8
|
+
* OpenAI-documented per-image number), anchored to Gemini's documented 20 MB total-inline-request
|
|
9
|
+
* budget (`google-messages.ts`) as the closest real, vendor-documented single-request inline-image
|
|
10
|
+
* bound available across this package's providers. Approximated from the base64 *string* length,
|
|
11
|
+
* not decoded byte count — see `anthropic-messages.ts#MAX_IMAGE_BASE64_CHARS`'s doc for why that's
|
|
12
|
+
* the right thing to measure (O(1), no decode step, negligible rounding slack at this size).
|
|
13
|
+
*/
|
|
14
|
+
const MAX_IMAGE_DATA_URI_BASE64_CHARS = Math.ceil((20 * 1024 * 1024 * 4) / 3);
|
|
15
|
+
/** OpenAI's documented per-request image count cap (see module doc). Applied per tool-result content array as a conservative simplification — a real request can also carry images from earlier turns this module doesn't track. */
|
|
16
|
+
const MAX_IMAGES_PER_OPENAI_TOOL_RESULT = 1500;
|
|
17
|
+
const OPENAI_DATA_URI_PATTERN = /^data:([^;,]+)(?:;charset=[^;,]+)?;base64,(.+)$/su;
|
|
18
|
+
/**
|
|
19
|
+
* Validates one content part against OpenAI's real format/size constraints. Returns the violation
|
|
20
|
+
* reason, or `null` when the part is legal to send.
|
|
21
|
+
*
|
|
22
|
+
* A plain `https://` `image_url` (not a `data:` URI) is intentionally not size-checked: OpenAI's
|
|
23
|
+
* servers fetch that URL, not this adapter, so there is no local payload to bound — same threat-
|
|
24
|
+
* model split as `anthropic-messages.ts`'s URL-sourced skip (`connection-guard.ts`'s SSRF guard
|
|
25
|
+
* protects this adapter's own outbound `baseUrl` request, a different thing; an `image_url` that
|
|
26
|
+
* points at attacker-chosen infrastructure is a request OpenAI's own servers make, not this one).
|
|
27
|
+
*
|
|
28
|
+
* @complexity O(1) — reads `data.length`, never decodes or parses the base64 payload.
|
|
29
|
+
*/
|
|
30
|
+
export function invalidOpenAiContentPartReason({ part }, _optional = {}) {
|
|
31
|
+
if (part.type === 'text')
|
|
32
|
+
return null;
|
|
33
|
+
const dataUriMatch = OPENAI_DATA_URI_PATTERN.exec(part.image_url.url);
|
|
34
|
+
if (!dataUriMatch)
|
|
35
|
+
return null;
|
|
36
|
+
const [, mediaType, base64Data] = dataUriMatch;
|
|
37
|
+
if (!mediaType || !OPENAI_ALLOWED_IMAGE_MEDIA_TYPES.has(mediaType.toLowerCase())) {
|
|
38
|
+
return `unsupported image media type ${JSON.stringify(mediaType)} (OpenAI's Chat Completions API supports image/jpeg, image/png, image/webp, and non-animated image/gif)`;
|
|
39
|
+
}
|
|
40
|
+
if (base64Data && base64Data.length > MAX_IMAGE_DATA_URI_BASE64_CHARS) {
|
|
41
|
+
return `image exceeds this adapter's 20 MB base64 size guard (${base64Data.length} base64 chars)`;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Runtime guard applied to every `OpenAiToolExecutor` result before it is wired onto the outbound
|
|
47
|
+
* request or reported via `onEvent`. `OpenAiToolResult` is host-owned (see `OpenAiToolExecutor`'s
|
|
48
|
+
* "Host-owned tool execution" doc comment) — the TS content-part union only constrains a
|
|
49
|
+
* well-behaved host at compile time, not a buggy one at runtime, e.g. a screenshot helper that
|
|
50
|
+
* hands back an oversized PNG or a HEIC file mislabeled as `image/jpeg`. Rather than forwarding an
|
|
51
|
+
* invalid part and letting OpenAI reject the *entire* turn with an opaque upstream 400, this
|
|
52
|
+
* substitutes a plain-text `isError: true` result the model can see and react to — matching this
|
|
53
|
+
* package's existing security-conscious posture (`connection-guard.ts`'s SSRF guard,
|
|
54
|
+
* `role-marker-guard.ts`'s contamination guard, and `anthropic-messages.ts`'s identical guard).
|
|
55
|
+
*
|
|
56
|
+
* @complexity O(n) in the number of content parts; O(1) per part (see `invalidOpenAiContentPartReason`).
|
|
57
|
+
*/
|
|
58
|
+
export function sanitizeOpenAiToolResult({ result }, _optional = {}) {
|
|
59
|
+
if (typeof result.content === 'string')
|
|
60
|
+
return { content: result.content, isError: false };
|
|
61
|
+
if (result.content.length > MAX_IMAGES_PER_OPENAI_TOOL_RESULT) {
|
|
62
|
+
return { content: `tool result rejected: exceeds the ${MAX_IMAGES_PER_OPENAI_TOOL_RESULT}-image-per-request guard (${result.content.length} parts)`, isError: true };
|
|
63
|
+
}
|
|
64
|
+
for (const part of result.content) {
|
|
65
|
+
const reason = invalidOpenAiContentPartReason({ part: part });
|
|
66
|
+
if (reason)
|
|
67
|
+
return { content: `tool result rejected: ${reason}`, isError: true };
|
|
68
|
+
}
|
|
69
|
+
return { content: result.content, isError: false };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Splits one (already-sanitized) tool result's content into what can legally sit on the wire
|
|
73
|
+
* `role: 'tool'` message (text only — see module doc's "Tool messages cannot carry an image"
|
|
74
|
+
* section) and the `image_url` parts that must instead travel on a follow-up `user` message.
|
|
75
|
+
*
|
|
76
|
+
* A string `content` is left untouched (`imageParts: []`) — this is the pre-existing, unchanged
|
|
77
|
+
* path every current caller already exercises. For an array, text parts are kept in order for the
|
|
78
|
+
* `tool` message; if there is no text at all (an image-only result), a single placeholder text part
|
|
79
|
+
* is substituted so the `tool` message's content is never empty (OpenAI rejects empty content).
|
|
80
|
+
*
|
|
81
|
+
* @complexity O(n) in the number of content parts.
|
|
82
|
+
*/
|
|
83
|
+
export function splitOpenAiToolResultContent({ content }, _optional = {}) {
|
|
84
|
+
if (typeof content === 'string')
|
|
85
|
+
return { toolMessageContent: content, imageParts: [] };
|
|
86
|
+
const textParts = content.filter((part) => part.type === 'text');
|
|
87
|
+
const imageParts = content.filter((part) => part.type === 'image_url');
|
|
88
|
+
const toolMessageContent = textParts.length > 0 ? textParts : [{ type: 'text', text: '(tool result included only non-text content; see the following message)' }];
|
|
89
|
+
return { toolMessageContent, imageParts };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Runs every pending tool call in order, sanitizing and splitting each result into its `tool`
|
|
93
|
+
* message plus any labeled image parts for the batch's single follow-up `user` message — see
|
|
94
|
+
* module doc's "Tool messages cannot carry an image" section for why the split exists and why the
|
|
95
|
+
* follow-up is assembled once per batch rather than per call.
|
|
96
|
+
*/
|
|
97
|
+
export async function executeOpenAiToolCalls({ executeTool, calls, onEvent }, _optional = {}) {
|
|
98
|
+
const toolResultMessages = [];
|
|
99
|
+
const followUpParts = [];
|
|
100
|
+
for (const call of calls) {
|
|
101
|
+
const result = await executeTool(call);
|
|
102
|
+
const sanitized = sanitizeOpenAiToolResult({ result: result });
|
|
103
|
+
onEvent({ type: 'tool_result', toolUseId: call.id, content: sanitized.content, isError: sanitized.isError });
|
|
104
|
+
const split = splitOpenAiToolResultContent({ content: sanitized.content });
|
|
105
|
+
toolResultMessages.push({ role: 'tool', content: split.toolMessageContent, tool_call_id: call.id });
|
|
106
|
+
if (split.imageParts.length > 0) {
|
|
107
|
+
// Attribution label — without it, the model cannot tell this image apart from a human
|
|
108
|
+
// having just pasted one into the conversation (see module doc). Named per-call so a batch
|
|
109
|
+
// with multiple image-bearing tool calls stays disambiguated in one follow-up message.
|
|
110
|
+
followUpParts.push({ type: 'text', text: `Image output from tool \`${call.name}\` (tool_call_id: ${call.id}):` });
|
|
111
|
+
followUpParts.push(...split.imageParts);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { toolResultMessages, followUpParts };
|
|
115
|
+
}
|
|
116
|
+
/** Builds the assistant turn that records the model's pending tool calls in `messages` history — `content` falls back to `null` (never `''`) per the wire schema. */
|
|
117
|
+
export function buildOpenAiAssistantToolCallMessage({ text, toolCalls }, _optional = {}) {
|
|
118
|
+
return { role: 'assistant', content: text || null, tool_calls: toolCalls };
|
|
119
|
+
}
|
|
120
|
+
/** Appends the batch's `tool` messages plus, when present, the single labeled-image follow-up message — see module doc's "Tool messages cannot carry an image" section for why the follow-up is at most one message per batch. */
|
|
121
|
+
export function buildOpenAiToolExchangeMessages({ toolResultMessages, followUpParts }, _optional = {}) {
|
|
122
|
+
return [...toolResultMessages, ...(followUpParts.length > 0 ? [{ role: 'user', content: followUpParts }] : [])];
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=openai-chat-tool-results.js.map
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
2
|
+
import { type PinnedFetch } from './connection-guard.js';
|
|
3
|
+
import { type TurnEndReason } from './turn-end-guard.js';
|
|
4
|
+
import type { ProviderToolSnapshotOptions, ProviderSchemaFallback } from './provider-tool-policy.js';
|
|
5
|
+
export interface OpenAiFunctionToolDef {
|
|
6
|
+
readonly type: 'function';
|
|
7
|
+
readonly function: {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly description?: string;
|
|
10
|
+
readonly parameters: Record<string, unknown>;
|
|
11
|
+
readonly strict?: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface OpenAiToolCallParam {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly type: 'function';
|
|
17
|
+
readonly function: {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly arguments: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface OpenAiTextPart {
|
|
23
|
+
readonly type: 'text';
|
|
24
|
+
readonly text: string;
|
|
25
|
+
}
|
|
26
|
+
/** `detail` defaults to `'auto'` server-side when omitted — never sent unless the caller supplies it. */
|
|
27
|
+
export interface OpenAiImageUrlPart {
|
|
28
|
+
readonly type: 'image_url';
|
|
29
|
+
readonly image_url: {
|
|
30
|
+
readonly url: string;
|
|
31
|
+
readonly detail?: 'auto' | 'low' | 'high';
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** A user/system/assistant message's `content` array item. Not legal inside a `role: 'tool'` message — see module doc's "Tool messages cannot carry an image" section. */
|
|
35
|
+
export type OpenAiContentPart = OpenAiTextPart | OpenAiImageUrlPart;
|
|
36
|
+
export interface OpenAiMessageParam {
|
|
37
|
+
readonly role: 'system' | 'user' | 'assistant' | 'tool';
|
|
38
|
+
readonly content: string | null | readonly OpenAiContentPart[];
|
|
39
|
+
readonly tool_calls?: readonly OpenAiToolCallParam[];
|
|
40
|
+
readonly tool_call_id?: string;
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface OpenAiToolCall {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly input: unknown;
|
|
47
|
+
}
|
|
48
|
+
/** `content` may include `OpenAiImageUrlPart`s (e.g. a vision self-check's screenshot) even though the wire `tool` message can't carry them directly — `runOpenAiToolTurn` splits them onto a follow-up `user` message; see module doc. */
|
|
49
|
+
export interface OpenAiToolResult {
|
|
50
|
+
readonly content: string | readonly OpenAiContentPart[];
|
|
51
|
+
}
|
|
52
|
+
/** Host-owned tool execution — same "the collaborator is always supplied" convention as `anthropic-messages.ts#AnthropicToolExecutor`. */
|
|
53
|
+
export type OpenAiToolExecutor = (call: OpenAiToolCall) => Promise<OpenAiToolResult>;
|
|
54
|
+
export type OpenAiTurnEndReason = TurnEndReason;
|
|
55
|
+
export type OpenAiTurnEvent = {
|
|
56
|
+
readonly type: 'status';
|
|
57
|
+
readonly label: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: 'text_delta';
|
|
60
|
+
readonly delta: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: 'tool_use';
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly input: unknown;
|
|
66
|
+
} | {
|
|
67
|
+
readonly type: 'tool_result';
|
|
68
|
+
readonly toolUseId: string;
|
|
69
|
+
readonly content: string | readonly OpenAiContentPart[];
|
|
70
|
+
readonly isError: boolean;
|
|
71
|
+
} | {
|
|
72
|
+
readonly type: 'usage';
|
|
73
|
+
readonly usage: Record<string, unknown> | null;
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: 'fabricated_role_marker';
|
|
76
|
+
readonly marker: string;
|
|
77
|
+
readonly messageId: string;
|
|
78
|
+
} | {
|
|
79
|
+
readonly type: 'error';
|
|
80
|
+
readonly message: string;
|
|
81
|
+
readonly code?: string;
|
|
82
|
+
} | {
|
|
83
|
+
readonly type: 'end';
|
|
84
|
+
readonly reason: OpenAiTurnEndReason;
|
|
85
|
+
};
|
|
86
|
+
export interface OpenAiTurnOptions {
|
|
87
|
+
readonly apiKey: string;
|
|
88
|
+
/** Defaults to `https://api.openai.com`. Overridable for OpenAI-compatible gateways (matching `providers/model-catalog.ts`'s `openai`-protocol `baseUrl` convention). */
|
|
89
|
+
readonly baseUrl?: string;
|
|
90
|
+
readonly model: string;
|
|
91
|
+
readonly messages: readonly OpenAiMessageParam[];
|
|
92
|
+
readonly tools?: readonly OpenAiFunctionToolDef[];
|
|
93
|
+
/** Refresh the run's projection immediately before each HTTP request. */
|
|
94
|
+
readonly getTools?: (options?: ProviderToolSnapshotOptions) => readonly OpenAiFunctionToolDef[];
|
|
95
|
+
readonly onSchemaFallback?: (event: ProviderSchemaFallback) => void;
|
|
96
|
+
readonly temperature?: number;
|
|
97
|
+
/** Defaults to {@link DEFAULT_OPENAI_MAX_TOKENS} (8192) when omitted or not a positive number — a token limit is always sent, matching OD's real behavior (see module doc). */
|
|
98
|
+
readonly maxTokens?: number;
|
|
99
|
+
/** Same bound and rationale as `AnthropicTurnOptions.maxToolTurns`. Defaults to 8. */
|
|
100
|
+
readonly maxToolTurns?: number;
|
|
101
|
+
readonly executeTool?: OpenAiToolExecutor;
|
|
102
|
+
readonly onEvent: (event: OpenAiTurnEvent) => void;
|
|
103
|
+
readonly signal?: AbortSignal;
|
|
104
|
+
/** Caller-supplied extra headers — see `anthropic-messages.ts#AnthropicTurnOptions.extraHeaders`'s doc for why this exists and what it fixes. */
|
|
105
|
+
readonly extraHeaders?: Record<string, string>;
|
|
106
|
+
/** Injectable HTTP transport, defaulting to {@link pinnedFetch} (SSRF-guarded, DNS-pinned). See `anthropic-messages.ts#AnthropicTurnOptions.fetchImpl`'s doc for the seam this exists for and why production wiring must never override it. Forwarded to {@link runOpenAiCompatibleRequest} via `OpenAiCompatibleRequestInit.fetchImpl` — `azure-chat.ts`/`ollama-chat.ts` accept and forward their own copy of this field the same way. */
|
|
107
|
+
readonly fetchImpl?: PinnedFetch;
|
|
108
|
+
/** Injectable DNS resolver for {@link validateBaseUrlResolved}'s DNS-pinning check, defaulting to {@link defaultDnsLookup}. Same test-only override rationale as `fetchImpl`. */
|
|
109
|
+
readonly dnsLookup?: import('@jini-ai/core/contracts/agents').DnsLookupFn;
|
|
110
|
+
}
|
|
111
|
+
export interface OpenAiTurnResult {
|
|
112
|
+
readonly finishReason: string | null;
|
|
113
|
+
readonly toolTurns: number;
|
|
114
|
+
}
|
|
115
|
+
export interface PendingToolCall {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
argsJson: string;
|
|
119
|
+
}
|
|
120
|
+
/** Shared return shape for one reduced OpenAI-compatible streaming request — exported so every OpenAI-compatible provider turn-runner (`azure-chat.ts`, `ollama-chat.ts`) can type its own internal single-request helper against it without re-declaring an identical interface. */
|
|
121
|
+
export interface OpenAiCompatibleRequestOutcome {
|
|
122
|
+
readonly finishReason: string | null;
|
|
123
|
+
readonly toolCalls: readonly OpenAiToolCall[];
|
|
124
|
+
readonly text: string;
|
|
125
|
+
}
|
|
126
|
+
/** Injected parameters for {@link runOpenAiCompatibleRequest}. Every OpenAI-compatible provider builds its own URL/headers/body (its own auth scheme, its own base-URL default and SSRF validation) and hands the finished request to this shared reducer — see that function's doc for why. */
|
|
127
|
+
export interface OpenAiCompatibleRequestInit {
|
|
128
|
+
readonly url: string;
|
|
129
|
+
readonly headers: Record<string, string>;
|
|
130
|
+
readonly body: Record<string, unknown>;
|
|
131
|
+
/** The address `validateBaseUrlResolved` validated for `url`'s hostname, forwarded verbatim to `pinnedFetch` so the connection dials it directly instead of re-resolving DNS. `undefined` for the loopback-literal / IP-literal hosts that skip resolution — see `pinnedFetch`'s doc. */
|
|
132
|
+
readonly pinnedAddress?: import('@jini-ai/core/contracts/agents').DnsLookupAddress;
|
|
133
|
+
readonly signal?: AbortSignal;
|
|
134
|
+
/** Secrets to strip out of any error message surfaced to the caller (e.g. the request's API key) — forwarded verbatim to `redactSecrets`'s `exactSecrets` parameter. */
|
|
135
|
+
readonly redactSecretsList: ReadonlyArray<string | undefined | null>;
|
|
136
|
+
/** Role-marker guard message id — distinguishes each provider's stream in guard telemetry (`'openai-turn'`, `'azure-turn'`, `'ollama-turn'`). */
|
|
137
|
+
readonly guardMessageId: string;
|
|
138
|
+
/** Human-readable provider name used in the "response had no body" fallback error message (e.g. `'OpenAI'`, `'Azure OpenAI'`, `'Ollama'`). */
|
|
139
|
+
readonly providerLabel: string;
|
|
140
|
+
readonly onEvent: (event: OpenAiTurnEvent) => void;
|
|
141
|
+
readonly emitEnd: (reason: OpenAiTurnEndReason) => void;
|
|
142
|
+
readonly hasEnded: () => boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Optional single-retry hook: called with the HTTP status and raw error
|
|
145
|
+
* body text on a non-ok response, before the error is treated as
|
|
146
|
+
* terminal. Return a replacement request body to retry once with, or
|
|
147
|
+
* `null`/`undefined` to fall through to the normal error path. Matches
|
|
148
|
+
* OD's real `[proxy:azure]` handler, which retries a 400
|
|
149
|
+
* `isUnsupportedMaxTokensError` response with `max_completion_tokens`
|
|
150
|
+
* (see `azure-chat.ts`). Cleared on the retried call so a second failure
|
|
151
|
+
* cannot retry again.
|
|
152
|
+
*/
|
|
153
|
+
readonly retryableBody?: (status: number, rawErrorText: string) => Record<string, unknown> | null | undefined;
|
|
154
|
+
/** Independent of the legacy token-parameter retry; consumed only on a recognized tool rejection. */
|
|
155
|
+
readonly retryToolBody?: (input: {
|
|
156
|
+
status: number;
|
|
157
|
+
rawErrorText: string;
|
|
158
|
+
body: Record<string, unknown>;
|
|
159
|
+
}) => Record<string, unknown> | null;
|
|
160
|
+
/** Injectable HTTP transport, defaulting to {@link pinnedFetch} (SSRF-guarded, DNS-pinned) — forwarded verbatim from the calling provider's own `OpenAiTurnOptions.fetchImpl`/`AzureTurnOptions.fetchImpl`/`OllamaTurnOptions.fetchImpl`. See `anthropic-messages.ts#AnthropicTurnOptions.fetchImpl`'s doc for the seam this exists for. */
|
|
161
|
+
readonly fetchImpl?: PinnedFetch;
|
|
162
|
+
}
|
|
163
|
+
/** Mutable reduction state threaded through one streaming request's SSE frame handlers (below). Grouped into one object so each handler takes a single parameter instead of several. Exported so a unit test can construct one directly (e.g. `{ guard: createRoleMarkerGuard('t'), toolCalls: new Map(), fullText: '', finishReason: null, usage: null }`) without going through a full `runOpenAiToolTurn` call. */
|
|
164
|
+
export interface OpenAiStreamState {
|
|
165
|
+
readonly guard: ReturnType<typeof createRoleMarkerGuard>;
|
|
166
|
+
readonly toolCalls: Map<number, PendingToolCall>;
|
|
167
|
+
fullText: string;
|
|
168
|
+
finishReason: string | null;
|
|
169
|
+
usage: Record<string, unknown> | null;
|
|
170
|
+
}
|
|
171
|
+
/** Per-turn state shared by the wire adapters; never retries streams or executes tools. */
|
|
172
|
+
export interface StrictToolRetryState {
|
|
173
|
+
readonly enabled: boolean;
|
|
174
|
+
readonly downgrade: (input: {
|
|
175
|
+
status: number;
|
|
176
|
+
rawErrorText: string;
|
|
177
|
+
toolNames: readonly string[];
|
|
178
|
+
}) => boolean;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=openai-chat-types.d.ts.map
|