@jini-ai/agent-runtime 0.7.2 → 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 -13
- 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/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
|
@@ -1,266 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* OpenAI Chat Completions API wire adapter + tool-loop turn-runner. Built
|
|
5
|
-
* fresh against OpenAI's real, current public API docs/reference
|
|
6
|
-
* (`developers.openai.com/api/docs/guides/function-calling` for the
|
|
7
|
-
* `tools`/`tool_calls`/tool-result-message shapes; the streaming delta
|
|
8
|
-
* accumulation shape below matches the long-stable, widely-documented
|
|
9
|
-
* `chat.completion.chunk` SSE format every OpenAI-compatible gateway this
|
|
10
|
-
* package's `providers/model-catalog.ts` already targets — `openai`/
|
|
11
|
-
* `senseaudio`/`aihubmix` protocols — implements identically), per this
|
|
12
|
-
* repo's "verify against real API docs, don't guess from memory"
|
|
13
|
-
* convention. Only the *shape* (a turn-runner with a tool-execution loop)
|
|
14
|
-
* is modeled on OD's `apps/daemon/src/routes/chat.ts`'s `runTurn` per
|
|
15
|
-
* `ADS-memory/reports/proposals/PROP-http-route-packs-chat-model-proxy-
|
|
16
|
-
* 2026-07-21.md` — this task did not have direct access to that file.
|
|
17
|
-
* Sibling of `anthropic-messages.ts`; see that module's header for the
|
|
18
|
-
* shared design rationale (package placement, `extraHeaders` fix for the
|
|
19
|
-
* confirmed OpenRouter product-identity leak, the `turn-end-guard.ts` fix
|
|
20
|
-
* for the confirmed duplicate-`end`-event bug — both apply identically
|
|
21
|
-
* here).
|
|
22
|
-
*
|
|
23
|
-
* **Token-limit fix**: an earlier version of this module sent no
|
|
24
|
-
* `max_tokens`/`max_completion_tokens` field at all — a live comparison
|
|
25
|
-
* against a running Open Design daemon found OD always sends one (defaulting
|
|
26
|
-
* to 8192), model-aware between the legacy and newer field name. This
|
|
27
|
-
* module now wires in `./token-params.js#buildOpenAIChatTokenParam` — that
|
|
28
|
-
* module already existed, itself a verbatim port of OD's real
|
|
29
|
-
* `apps/daemon/src/integrations/openai-chat-token-params.ts`, but was never
|
|
30
|
-
* actually called from here until this fix. `azure-chat.ts` reuses the same
|
|
31
|
-
* module's `buildLegacyMaxTokensParam` (always the legacy `max_tokens`
|
|
32
|
-
* field, not model-aware) — matching OD's own azure handler, which never
|
|
33
|
-
* uses the model-aware picker (Azure deployment names are caller-defined
|
|
34
|
-
* strings, not necessarily matching OpenAI's own model-naming scheme).
|
|
35
|
-
*
|
|
36
|
-
* **Image support**: verified against `developers.openai.com/api/docs/api-reference/chat/create`
|
|
37
|
-
* (the Chat Completions endpoint specifically — a redirect from the older
|
|
38
|
-
* `platform.openai.com/docs/guides/vision` URL now leads to a *different*, newer Responses API
|
|
39
|
-
* guide that uses `input_text`/`input_image` part names; those do not apply here and are not
|
|
40
|
-
* modeled). A user/system/assistant message's `content` may be an array mixing `{type:'text'}` and
|
|
41
|
-
* `{type:'image_url', image_url:{url, detail?}}` parts; `url` is either an `https://` URL (OpenAI's
|
|
42
|
-
* servers fetch it — see `invalidOpenAiContentPartReason`'s doc for why this module does not size-
|
|
43
|
-
* check that case) or a `data:<mime>;base64,<data>` URI. Supported formats per the same reference:
|
|
44
|
-
* PNG/JPEG/WEBP/non-animated GIF; documented limits are a 512 MB total request payload and 1500
|
|
45
|
-
* images per request (this module also applies its own conservative single-image guard — see
|
|
46
|
-
* `MAX_IMAGE_DATA_URI_BASE64_CHARS`'s doc).
|
|
47
|
-
*
|
|
48
|
-
* **Tool messages cannot carry an image** — confirmed against the same API reference: a `role:
|
|
49
|
-
* 'tool'` message's `content` is documented as `string | ChatCompletionContentPartText[]` only
|
|
50
|
-
* ("For tool messages, only type text is supported"). So a vision self-check whose tool result
|
|
51
|
-
* includes a screenshot cannot put that image on the `tool` message itself. `runOpenAiToolTurn`
|
|
52
|
-
* instead keeps the `tool` message text-only (see `splitOpenAiToolResultContent`) and appends one
|
|
53
|
-
* synthetic `role: 'user'` message carrying every image from the batch, built up while iterating
|
|
54
|
-
* every `tool_call` in the batch but appended exactly once, after every one of that batch's `tool`
|
|
55
|
-
* messages — never interleaved between them or emitted per-call, since OpenAI requires every `tool`
|
|
56
|
-
* message answering a batch of parallel `tool_calls` to directly follow the assistant message with
|
|
57
|
-
* nothing else in between. This is a real 400 if violated, not a style concern — see
|
|
58
|
-
* `runOpenAiToolTurn`'s tool-loop body and its test file's multi-tool-call image test.
|
|
59
|
-
*
|
|
60
|
-
* **This synthetic follow-up message is a workaround for the OpenAI wire protocol's own text-only
|
|
61
|
-
* `tool` message, not structure this module invented.** Anthropic's `tool_result` content block can
|
|
62
|
-
* carry an image directly (see `anthropic-messages.ts`) and needs no such split. Each image (or run
|
|
63
|
-
* of images) in the follow-up is preceded by a plain-text label naming the tool call it answers
|
|
64
|
-
* (name + `tool_call_id`) — an unlabeled image sitting alone in a `user` message is indistinguishable
|
|
65
|
-
* from a human having just pasted a screenshot, which in a vision self-check loop risks the model
|
|
66
|
-
* treating its own tool's output as a brand-new user request instead of a continuation of its own
|
|
67
|
-
* reasoning.
|
|
68
|
-
*/
|
|
69
|
-
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
70
|
-
import { type DnsLookupAddress, type DnsLookupFn, type PinnedFetch } from './connection-guard.js';
|
|
71
|
-
import { type DecodedSseEvent } from './sse-decode.js';
|
|
72
|
-
import { type TurnEndReason } from './turn-end-guard.js';
|
|
73
|
-
import type { ProviderToolSnapshotOptions, ProviderSchemaFallback, ProviderProtocol } from './provider-tool-policy.js';
|
|
74
|
-
export interface OpenAiFunctionToolDef {
|
|
75
|
-
readonly type: 'function';
|
|
76
|
-
readonly function: {
|
|
77
|
-
readonly name: string;
|
|
78
|
-
readonly description?: string;
|
|
79
|
-
readonly parameters: Record<string, unknown>;
|
|
80
|
-
readonly strict?: boolean;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
export interface OpenAiToolCallParam {
|
|
84
|
-
readonly id: string;
|
|
85
|
-
readonly type: 'function';
|
|
86
|
-
readonly function: {
|
|
87
|
-
readonly name: string;
|
|
88
|
-
readonly arguments: string;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export interface OpenAiTextPart {
|
|
92
|
-
readonly type: 'text';
|
|
93
|
-
readonly text: string;
|
|
94
|
-
}
|
|
95
|
-
/** `detail` defaults to `'auto'` server-side when omitted — never sent unless the caller supplies it. */
|
|
96
|
-
export interface OpenAiImageUrlPart {
|
|
97
|
-
readonly type: 'image_url';
|
|
98
|
-
readonly image_url: {
|
|
99
|
-
readonly url: string;
|
|
100
|
-
readonly detail?: 'auto' | 'low' | 'high';
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/** 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. */
|
|
104
|
-
export type OpenAiContentPart = OpenAiTextPart | OpenAiImageUrlPart;
|
|
105
|
-
export interface OpenAiMessageParam {
|
|
106
|
-
readonly role: 'system' | 'user' | 'assistant' | 'tool';
|
|
107
|
-
readonly content: string | null | readonly OpenAiContentPart[];
|
|
108
|
-
readonly tool_calls?: readonly OpenAiToolCallParam[];
|
|
109
|
-
readonly tool_call_id?: string;
|
|
110
|
-
readonly name?: string;
|
|
111
|
-
}
|
|
112
|
-
export interface OpenAiToolCall {
|
|
113
|
-
readonly id: string;
|
|
114
|
-
readonly name: string;
|
|
115
|
-
readonly input: unknown;
|
|
116
|
-
}
|
|
117
|
-
/** `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. */
|
|
118
|
-
export interface OpenAiToolResult {
|
|
119
|
-
readonly content: string | readonly OpenAiContentPart[];
|
|
120
|
-
}
|
|
121
|
-
/** Host-owned tool execution — same "the collaborator is always supplied" convention as `anthropic-messages.ts#AnthropicToolExecutor`. */
|
|
122
|
-
export type OpenAiToolExecutor = (call: OpenAiToolCall) => Promise<OpenAiToolResult>;
|
|
123
|
-
export type OpenAiTurnEndReason = TurnEndReason;
|
|
124
|
-
export type OpenAiTurnEvent = {
|
|
125
|
-
readonly type: 'status';
|
|
126
|
-
readonly label: string;
|
|
127
|
-
} | {
|
|
128
|
-
readonly type: 'text_delta';
|
|
129
|
-
readonly delta: string;
|
|
130
|
-
} | {
|
|
131
|
-
readonly type: 'tool_use';
|
|
132
|
-
readonly id: string;
|
|
133
|
-
readonly name: string;
|
|
134
|
-
readonly input: unknown;
|
|
135
|
-
} | {
|
|
136
|
-
readonly type: 'tool_result';
|
|
137
|
-
readonly toolUseId: string;
|
|
138
|
-
readonly content: string | readonly OpenAiContentPart[];
|
|
139
|
-
readonly isError: boolean;
|
|
140
|
-
} | {
|
|
141
|
-
readonly type: 'usage';
|
|
142
|
-
readonly usage: Record<string, unknown> | null;
|
|
143
|
-
} | {
|
|
144
|
-
readonly type: 'fabricated_role_marker';
|
|
145
|
-
readonly marker: string;
|
|
146
|
-
readonly messageId: string;
|
|
147
|
-
} | {
|
|
148
|
-
readonly type: 'error';
|
|
149
|
-
readonly message: string;
|
|
150
|
-
readonly code?: string;
|
|
151
|
-
} | {
|
|
152
|
-
readonly type: 'end';
|
|
153
|
-
readonly reason: OpenAiTurnEndReason;
|
|
154
|
-
};
|
|
155
|
-
export interface OpenAiTurnOptions {
|
|
156
|
-
readonly apiKey: string;
|
|
157
|
-
/** Defaults to `https://api.openai.com`. Overridable for OpenAI-compatible gateways (matching `providers/model-catalog.ts`'s `openai`-protocol `baseUrl` convention). */
|
|
158
|
-
readonly baseUrl?: string;
|
|
159
|
-
readonly model: string;
|
|
160
|
-
readonly messages: readonly OpenAiMessageParam[];
|
|
161
|
-
readonly tools?: readonly OpenAiFunctionToolDef[];
|
|
162
|
-
/** Refresh the run's projection immediately before each HTTP request. */
|
|
163
|
-
readonly getTools?: (options?: ProviderToolSnapshotOptions) => readonly OpenAiFunctionToolDef[];
|
|
164
|
-
readonly onSchemaFallback?: (event: ProviderSchemaFallback) => void;
|
|
165
|
-
readonly temperature?: number;
|
|
166
|
-
/** 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). */
|
|
167
|
-
readonly maxTokens?: number;
|
|
168
|
-
/** Same bound and rationale as `AnthropicTurnOptions.maxToolTurns`. Defaults to 8. */
|
|
169
|
-
readonly maxToolTurns?: number;
|
|
170
|
-
readonly executeTool?: OpenAiToolExecutor;
|
|
171
|
-
readonly onEvent: (event: OpenAiTurnEvent) => void;
|
|
172
|
-
readonly signal?: AbortSignal;
|
|
173
|
-
/** Caller-supplied extra headers — see `anthropic-messages.ts#AnthropicTurnOptions.extraHeaders`'s doc for why this exists and what it fixes. */
|
|
174
|
-
readonly extraHeaders?: Record<string, string>;
|
|
175
|
-
/** 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. */
|
|
176
|
-
readonly fetchImpl?: PinnedFetch;
|
|
177
|
-
/** Injectable DNS resolver for {@link validateBaseUrlResolved}'s DNS-pinning check, defaulting to {@link defaultDnsLookup}. Same test-only override rationale as `fetchImpl`. */
|
|
178
|
-
readonly dnsLookup?: DnsLookupFn;
|
|
179
|
-
}
|
|
180
|
-
export interface OpenAiTurnResult {
|
|
181
|
-
readonly finishReason: string | null;
|
|
182
|
-
readonly toolTurns: number;
|
|
183
|
-
}
|
|
1
|
+
import type { ProviderSchemaFallback, ProviderProtocol } from './provider-tool-policy.js';
|
|
2
|
+
import { type OpenAiTurnOptions, type OpenAiMessageParam, type StrictToolRetryState, type OpenAiTurnEndReason, type OpenAiCompatibleRequestOutcome, type OpenAiTurnResult } from './openai-chat-types.js';
|
|
184
3
|
/** Matches OD's own default (`apps/daemon/src/routes/chat.ts`'s openai/azure handlers both fall back to this when the caller doesn't supply one) — a real, explicit bound is always sent, never an unbounded request. */
|
|
185
4
|
export declare const DEFAULT_OPENAI_MAX_TOKENS = 8192;
|
|
186
5
|
export declare function openAiRequestUrl({ baseUrl }: {
|
|
187
6
|
baseUrl: string | undefined;
|
|
188
|
-
}): string;
|
|
7
|
+
}, _optional?: Record<string, never>): string;
|
|
189
8
|
/** The `OpenAiTurnOptions` keys every caller must pass. */
|
|
190
9
|
type OpenAiRequiredOption = "apiKey" | "model" | "messages" | "onEvent";
|
|
191
10
|
export declare function openAiHeaders(requiredArgs: Pick<OpenAiTurnOptions, OpenAiRequiredOption>, optionalArgs?: Omit<OpenAiTurnOptions, OpenAiRequiredOption>): Record<string, string>;
|
|
192
11
|
export declare function openAiRequestBody({ options, messages }: {
|
|
193
12
|
options: OpenAiTurnOptions;
|
|
194
13
|
messages: readonly OpenAiMessageParam[];
|
|
195
|
-
}): Record<string, unknown>;
|
|
196
|
-
export declare function extractOpenAiErrorDetail({ rawText }: {
|
|
197
|
-
rawText: string;
|
|
198
|
-
}): string;
|
|
199
|
-
export interface PendingToolCall {
|
|
200
|
-
id: string;
|
|
201
|
-
name: string;
|
|
202
|
-
argsJson: string;
|
|
203
|
-
}
|
|
204
|
-
/** 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. */
|
|
205
|
-
export interface OpenAiCompatibleRequestOutcome {
|
|
206
|
-
readonly finishReason: string | null;
|
|
207
|
-
readonly toolCalls: readonly OpenAiToolCall[];
|
|
208
|
-
readonly text: string;
|
|
209
|
-
}
|
|
210
|
-
/** 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. */
|
|
211
|
-
export interface OpenAiCompatibleRequestInit {
|
|
212
|
-
readonly url: string;
|
|
213
|
-
readonly headers: Record<string, string>;
|
|
214
|
-
readonly body: Record<string, unknown>;
|
|
215
|
-
/** 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. */
|
|
216
|
-
readonly pinnedAddress?: DnsLookupAddress;
|
|
217
|
-
readonly signal?: AbortSignal;
|
|
218
|
-
/** 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. */
|
|
219
|
-
readonly redactSecretsList: ReadonlyArray<string | undefined | null>;
|
|
220
|
-
/** Role-marker guard message id — distinguishes each provider's stream in guard telemetry (`'openai-turn'`, `'azure-turn'`, `'ollama-turn'`). */
|
|
221
|
-
readonly guardMessageId: string;
|
|
222
|
-
/** Human-readable provider name used in the "response had no body" fallback error message (e.g. `'OpenAI'`, `'Azure OpenAI'`, `'Ollama'`). */
|
|
223
|
-
readonly providerLabel: string;
|
|
224
|
-
readonly onEvent: (event: OpenAiTurnEvent) => void;
|
|
225
|
-
readonly emitEnd: (reason: OpenAiTurnEndReason) => void;
|
|
226
|
-
readonly hasEnded: () => boolean;
|
|
227
|
-
/**
|
|
228
|
-
* Optional single-retry hook: called with the HTTP status and raw error
|
|
229
|
-
* body text on a non-ok response, before the error is treated as
|
|
230
|
-
* terminal. Return a replacement request body to retry once with, or
|
|
231
|
-
* `null`/`undefined` to fall through to the normal error path. Matches
|
|
232
|
-
* OD's real `[proxy:azure]` handler, which retries a 400
|
|
233
|
-
* `isUnsupportedMaxTokensError` response with `max_completion_tokens`
|
|
234
|
-
* (see `azure-chat.ts`). Cleared on the retried call so a second failure
|
|
235
|
-
* cannot retry again.
|
|
236
|
-
*/
|
|
237
|
-
readonly retryableBody?: (status: number, rawErrorText: string) => Record<string, unknown> | null | undefined;
|
|
238
|
-
/** Independent of the legacy token-parameter retry; consumed only on a recognized tool rejection. */
|
|
239
|
-
readonly retryToolBody?: (input: {
|
|
240
|
-
status: number;
|
|
241
|
-
rawErrorText: string;
|
|
242
|
-
body: Record<string, unknown>;
|
|
243
|
-
}) => Record<string, unknown> | null;
|
|
244
|
-
/** 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. */
|
|
245
|
-
readonly fetchImpl?: PinnedFetch;
|
|
246
|
-
}
|
|
247
|
-
/** 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. */
|
|
248
|
-
export interface OpenAiStreamState {
|
|
249
|
-
readonly guard: ReturnType<typeof createRoleMarkerGuard>;
|
|
250
|
-
readonly toolCalls: Map<number, PendingToolCall>;
|
|
251
|
-
fullText: string;
|
|
252
|
-
finishReason: string | null;
|
|
253
|
-
usage: Record<string, unknown> | null;
|
|
254
|
-
}
|
|
255
|
-
/** Per-turn state shared by the wire adapters; never retries streams or executes tools. */
|
|
256
|
-
export interface StrictToolRetryState {
|
|
257
|
-
readonly enabled: boolean;
|
|
258
|
-
readonly downgrade: (input: {
|
|
259
|
-
status: number;
|
|
260
|
-
rawErrorText: string;
|
|
261
|
-
toolNames: readonly string[];
|
|
262
|
-
}) => boolean;
|
|
263
|
-
}
|
|
14
|
+
}, _optional?: Record<string, never>): Record<string, unknown>;
|
|
264
15
|
/**
|
|
265
16
|
* Allow one recognized pre-generation downgrade for this turn. Diagnostic callbacks receive
|
|
266
17
|
* names and a closed reason code, never the provider's error text or tool arguments.
|
|
@@ -283,132 +34,6 @@ export declare function refreshOpenAiTools<T extends OpenAiTurnOptions>({ option
|
|
|
283
34
|
options: T;
|
|
284
35
|
retry: StrictToolRetryState;
|
|
285
36
|
}, _optional?: {}): T;
|
|
286
|
-
/** Parses one SSE frame's data as a JSON object, or `null` for a malformed/empty keep-alive frame or a non-object payload — both are tolerated by the caller as "nothing to do this frame". */
|
|
287
|
-
export declare function parseOpenAiSseData({ raw }: {
|
|
288
|
-
raw: string;
|
|
289
|
-
}): Record<string, unknown> | null;
|
|
290
|
-
export declare function applyOpenAiStreamUsage({ state, data, onEvent }: {
|
|
291
|
-
state: OpenAiStreamState;
|
|
292
|
-
data: Record<string, unknown>;
|
|
293
|
-
onEvent: (event: OpenAiTurnEvent) => void;
|
|
294
|
-
}): void;
|
|
295
|
-
/** The chunk's first (and, for Chat Completions, only) choice — `null` when the chunk carries no choice at all (e.g. a usage-only trailer chunk). */
|
|
296
|
-
export declare function firstOpenAiChoice({ data }: {
|
|
297
|
-
data: Record<string, unknown>;
|
|
298
|
-
}): Record<string, unknown> | null;
|
|
299
|
-
/**
|
|
300
|
-
* Feeds one text delta through the role-marker guard and emits the safe portion. Returns
|
|
301
|
-
* `'break'` once the guard flags contamination (the caller ends the turn immediately), otherwise
|
|
302
|
-
* `'continue'` — same contract as `anthropic-messages.ts#handleAnthropicTextDelta`.
|
|
303
|
-
*/
|
|
304
|
-
export declare function handleOpenAiTextContentDelta({ state, content, onEvent }: {
|
|
305
|
-
state: OpenAiStreamState;
|
|
306
|
-
content: string;
|
|
307
|
-
onEvent: (event: OpenAiTurnEvent) => void;
|
|
308
|
-
}): 'continue' | 'break';
|
|
309
|
-
/** Builds a fresh `PendingToolCall` from the streaming chunk that first mentions a given tool-call index — OpenAI sends `id`/`function.name` once, on that first chunk, then dribbles `function.arguments` in across subsequent chunks (accumulated separately by the caller). */
|
|
310
|
-
export declare function newPendingOpenAiToolCall({ rawCall, index }: {
|
|
311
|
-
rawCall: Record<string, unknown>;
|
|
312
|
-
index: number;
|
|
313
|
-
}): PendingToolCall;
|
|
314
|
-
/** Accumulates one `delta.tool_calls[]` entry from a streaming chunk into its running `PendingToolCall`. */
|
|
315
|
-
export declare function accumulateOpenAiToolCallDelta({ state, rawCall }: {
|
|
316
|
-
state: OpenAiStreamState;
|
|
317
|
-
rawCall: unknown;
|
|
318
|
-
}): void;
|
|
319
|
-
/** Reduces one chunk's `choices[0]` — `finish_reason`, text content, and tool-call deltas — into `state`. Returns `'break'` when the text-delta guard detects contamination. */
|
|
320
|
-
export declare function handleOpenAiChoiceDelta({ state, choice, onEvent }: {
|
|
321
|
-
state: OpenAiStreamState;
|
|
322
|
-
choice: Record<string, unknown>;
|
|
323
|
-
onEvent: (event: OpenAiTurnEvent) => void;
|
|
324
|
-
}): 'continue' | 'break';
|
|
325
|
-
/** Parses one accumulated tool call's `argsJson`, falling back to `{}` for empty or malformed JSON — mirrors Anthropic's identical fallback for `input_json_delta` accumulation in `anthropic-messages.ts`. */
|
|
326
|
-
export declare function resolveOpenAiToolCalls({ pending }: {
|
|
327
|
-
pending: ReadonlyMap<number, PendingToolCall>;
|
|
328
|
-
}): OpenAiToolCall[];
|
|
329
|
-
export type OpenAiFrameResult = 'continue' | 'done' | 'contaminated';
|
|
330
|
-
/**
|
|
331
|
-
* Reduces one decoded SSE frame into `state`, reporting what the caller's loop should do next:
|
|
332
|
-
* `'done'` on the `[DONE]` sentinel, `'contaminated'` once the role-marker guard trips on this
|
|
333
|
-
* frame's text delta, otherwise `'continue'`. Pulling per-frame dispatch out of the loop body
|
|
334
|
-
* turns what would be four sequential, nesting-penalized `if`s into a single function call plus
|
|
335
|
-
* one outcome check — see `runOpenAiCompatibleRequest`'s loop below.
|
|
336
|
-
*/
|
|
337
|
-
export declare function processOpenAiStreamFrame({ state, frame, onEvent }: {
|
|
338
|
-
state: OpenAiStreamState;
|
|
339
|
-
frame: DecodedSseEvent;
|
|
340
|
-
onEvent: (event: OpenAiTurnEvent) => void;
|
|
341
|
-
}): OpenAiFrameResult;
|
|
342
|
-
/**
|
|
343
|
-
* Runs exactly one OpenAI-compatible (Chat Completions JSON wire format)
|
|
344
|
-
* streaming HTTP request and reduces its SSE events into a single outcome.
|
|
345
|
-
* Extracted so this SSE-reduction loop has exactly one implementation
|
|
346
|
-
* shared by every OpenAI-compatible provider turn-runner in this package:
|
|
347
|
-
* `runOpenAiToolTurn` itself (below), plus `azure-chat.ts#runAzureToolTurn`
|
|
348
|
-
* and `ollama-chat.ts#runOllamaToolTurn` — both target byte-identical
|
|
349
|
-
* chat-completions JSON, differing only in URL and auth. Callers own their
|
|
350
|
-
* own base-URL SSRF validation (`validateBaseUrl`) and URL/header/body
|
|
351
|
-
* construction *before* calling this function — it only knows how to run
|
|
352
|
-
* *a* request against whatever URL/headers/body it is handed, and has no
|
|
353
|
-
* opinion on any provider's defaults. Mirrors
|
|
354
|
-
* `anthropic-messages.ts#runSingleAnthropicRequest`'s `emitEnd` contract —
|
|
355
|
-
* see that function's doc.
|
|
356
|
-
*/
|
|
357
|
-
export declare function runOpenAiCompatibleRequest(requiredArgs: Pick<OpenAiCompatibleRequestInit, "url" | "headers" | "body" | "redactSecretsList" | "guardMessageId" | "providerLabel" | "onEvent" | "emitEnd" | "hasEnded">, optionalArgs?: Omit<OpenAiCompatibleRequestInit, "url" | "headers" | "body" | "redactSecretsList" | "guardMessageId" | "providerLabel" | "onEvent" | "emitEnd" | "hasEnded">): Promise<OpenAiCompatibleRequestOutcome>;
|
|
358
|
-
/**
|
|
359
|
-
* Validates one content part against OpenAI's real format/size constraints. Returns the violation
|
|
360
|
-
* reason, or `null` when the part is legal to send.
|
|
361
|
-
*
|
|
362
|
-
* A plain `https://` `image_url` (not a `data:` URI) is intentionally not size-checked: OpenAI's
|
|
363
|
-
* servers fetch that URL, not this adapter, so there is no local payload to bound — same threat-
|
|
364
|
-
* model split as `anthropic-messages.ts`'s URL-sourced skip (`connection-guard.ts`'s SSRF guard
|
|
365
|
-
* protects this adapter's own outbound `baseUrl` request, a different thing; an `image_url` that
|
|
366
|
-
* points at attacker-chosen infrastructure is a request OpenAI's own servers make, not this one).
|
|
367
|
-
*
|
|
368
|
-
* @complexity O(1) — reads `data.length`, never decodes or parses the base64 payload.
|
|
369
|
-
*/
|
|
370
|
-
export declare function invalidOpenAiContentPartReason({ part }: {
|
|
371
|
-
part: OpenAiContentPart;
|
|
372
|
-
}): string | null;
|
|
373
|
-
export interface SanitizedOpenAiToolResult {
|
|
374
|
-
readonly content: string | readonly OpenAiContentPart[];
|
|
375
|
-
readonly isError: boolean;
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Runtime guard applied to every `OpenAiToolExecutor` result before it is wired onto the outbound
|
|
379
|
-
* request or reported via `onEvent`. `OpenAiToolResult` is host-owned (see `OpenAiToolExecutor`'s
|
|
380
|
-
* "Host-owned tool execution" doc comment) — the TS content-part union only constrains a
|
|
381
|
-
* well-behaved host at compile time, not a buggy one at runtime, e.g. a screenshot helper that
|
|
382
|
-
* hands back an oversized PNG or a HEIC file mislabeled as `image/jpeg`. Rather than forwarding an
|
|
383
|
-
* invalid part and letting OpenAI reject the *entire* turn with an opaque upstream 400, this
|
|
384
|
-
* substitutes a plain-text `isError: true` result the model can see and react to — matching this
|
|
385
|
-
* package's existing security-conscious posture (`connection-guard.ts`'s SSRF guard,
|
|
386
|
-
* `role-marker-guard.ts`'s contamination guard, and `anthropic-messages.ts`'s identical guard).
|
|
387
|
-
*
|
|
388
|
-
* @complexity O(n) in the number of content parts; O(1) per part (see `invalidOpenAiContentPartReason`).
|
|
389
|
-
*/
|
|
390
|
-
export declare function sanitizeOpenAiToolResult({ result }: {
|
|
391
|
-
result: OpenAiToolResult;
|
|
392
|
-
}): SanitizedOpenAiToolResult;
|
|
393
|
-
export interface SplitOpenAiToolResultContent {
|
|
394
|
-
readonly toolMessageContent: string | readonly OpenAiTextPart[];
|
|
395
|
-
readonly imageParts: readonly OpenAiImageUrlPart[];
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Splits one (already-sanitized) tool result's content into what can legally sit on the wire
|
|
399
|
-
* `role: 'tool'` message (text only — see module doc's "Tool messages cannot carry an image"
|
|
400
|
-
* section) and the `image_url` parts that must instead travel on a follow-up `user` message.
|
|
401
|
-
*
|
|
402
|
-
* A string `content` is left untouched (`imageParts: []`) — this is the pre-existing, unchanged
|
|
403
|
-
* path every current caller already exercises. For an array, text parts are kept in order for the
|
|
404
|
-
* `tool` message; if there is no text at all (an image-only result), a single placeholder text part
|
|
405
|
-
* is substituted so the `tool` message's content is never empty (OpenAI rejects empty content).
|
|
406
|
-
*
|
|
407
|
-
* @complexity O(n) in the number of content parts.
|
|
408
|
-
*/
|
|
409
|
-
export declare function splitOpenAiToolResultContent({ content }: {
|
|
410
|
-
content: string | readonly OpenAiContentPart[];
|
|
411
|
-
}): SplitOpenAiToolResultContent;
|
|
412
37
|
/**
|
|
413
38
|
* Decides why the tool loop should stop after one request, or returns `null` when it should
|
|
414
39
|
* instead proceed to execute the pending tool calls — mirrors
|
|
@@ -418,32 +43,7 @@ export declare function openAiLoopExitReason({ outcome, toolTurns, maxToolTurns
|
|
|
418
43
|
outcome: OpenAiCompatibleRequestOutcome;
|
|
419
44
|
toolTurns: number;
|
|
420
45
|
maxToolTurns: number;
|
|
421
|
-
}): OpenAiTurnEndReason | null;
|
|
422
|
-
export interface OpenAiToolExecutionOutcome {
|
|
423
|
-
readonly toolResultMessages: OpenAiMessageParam[];
|
|
424
|
-
readonly followUpParts: OpenAiContentPart[];
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Runs every pending tool call in order, sanitizing and splitting each result into its `tool`
|
|
428
|
-
* message plus any labeled image parts for the batch's single follow-up `user` message — see
|
|
429
|
-
* module doc's "Tool messages cannot carry an image" section for why the split exists and why the
|
|
430
|
-
* follow-up is assembled once per batch rather than per call.
|
|
431
|
-
*/
|
|
432
|
-
export declare function executeOpenAiToolCalls({ executeTool, calls, onEvent }: {
|
|
433
|
-
executeTool: OpenAiToolExecutor;
|
|
434
|
-
calls: readonly OpenAiToolCall[];
|
|
435
|
-
onEvent: (event: OpenAiTurnEvent) => void;
|
|
436
|
-
}): Promise<OpenAiToolExecutionOutcome>;
|
|
437
|
-
/** 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. */
|
|
438
|
-
export declare function buildOpenAiAssistantToolCallMessage({ text, toolCalls }: {
|
|
439
|
-
text: string;
|
|
440
|
-
toolCalls: readonly OpenAiToolCallParam[];
|
|
441
|
-
}): OpenAiMessageParam;
|
|
442
|
-
/** 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. */
|
|
443
|
-
export declare function buildOpenAiToolExchangeMessages({ toolResultMessages, followUpParts }: {
|
|
444
|
-
toolResultMessages: readonly OpenAiMessageParam[];
|
|
445
|
-
followUpParts: readonly OpenAiContentPart[];
|
|
446
|
-
}): OpenAiMessageParam[];
|
|
46
|
+
}, _optional?: Record<string, never>): OpenAiTurnEndReason | null;
|
|
447
47
|
/**
|
|
448
48
|
* Runs a full OpenAI Chat Completions turn, including the tool-execution
|
|
449
49
|
* loop when `options.executeTool` is supplied and the model requests a
|