@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
|
@@ -36,7 +36,7 @@ export const AIHUBMIX_DEFAULT_BASE_URL = 'https://aihubmix.com/v1';
|
|
|
36
36
|
* fixed `APP-Code` attribution header. Callers spread the result into their
|
|
37
37
|
* `fetch` headers and may add `content-type` etc. on top.
|
|
38
38
|
*/
|
|
39
|
-
export function aihubmixHeaders({ apiKey }) {
|
|
39
|
+
export function aihubmixHeaders({ apiKey }, _optional = {}) {
|
|
40
40
|
return {
|
|
41
41
|
authorization: `Bearer ${apiKey}`,
|
|
42
42
|
...aihubmixAppCodeHeader(),
|
|
@@ -55,7 +55,7 @@ export function aihubmixHeaders({ apiKey }) {
|
|
|
55
55
|
export function aihubmixAppCodeHeader() {
|
|
56
56
|
return { 'APP-Code': AIHUBMIX_APP_CODE };
|
|
57
57
|
}
|
|
58
|
-
export function classifyAIHubMixModel({ model }) {
|
|
58
|
+
export function classifyAIHubMixModel({ model }, _optional = {}) {
|
|
59
59
|
const m = (model || '').trim().toLowerCase();
|
|
60
60
|
// Gemini: gemini*/imagen*, excluding the `-nothink`/`-search` suffixes and
|
|
61
61
|
// any embedding model (those stay on the OpenAI-compatible path per §4.1).
|
|
@@ -75,7 +75,7 @@ export function classifyAIHubMixModel({ model }) {
|
|
|
75
75
|
* anthropic -> `${origin}` (+ /v1/messages)
|
|
76
76
|
* gemini -> `${origin}/gemini` (+ /v1beta/models/{model}:...)
|
|
77
77
|
*/
|
|
78
|
-
export function aihubmixOriginFromBase({ baseUrl }) {
|
|
78
|
+
export function aihubmixOriginFromBase({ baseUrl }, _optional = {}) {
|
|
79
79
|
try {
|
|
80
80
|
return new URL(baseUrl || AIHUBMIX_DEFAULT_BASE_URL).origin;
|
|
81
81
|
}
|
|
@@ -84,7 +84,7 @@ export function aihubmixOriginFromBase({ baseUrl }) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
/** Gemini-native generateContent endpoint for an AIHubMix image model. */
|
|
87
|
-
export function aihubmixGeminiImageUrl({ baseUrl, wireModel }) {
|
|
87
|
+
export function aihubmixGeminiImageUrl({ baseUrl, wireModel }, _optional = {}) {
|
|
88
88
|
return (`${aihubmixOriginFromBase({ baseUrl: baseUrl })}/gemini/v1beta/models/`
|
|
89
89
|
+ `${encodeURIComponent(wireModel)}:generateContent`);
|
|
90
90
|
}
|
|
@@ -100,7 +100,7 @@ export function aihubmixGeminiImageUrl({ baseUrl, wireModel }) {
|
|
|
100
100
|
* dispatcher, abort signal, redirect policy). Throws on a non-OK status or a
|
|
101
101
|
* response without inline image data.
|
|
102
102
|
*/
|
|
103
|
-
export async function aihubmixGeminiImageBytes({ req, doFetch }) {
|
|
103
|
+
export async function aihubmixGeminiImageBytes({ req, doFetch }, _optional = {}) {
|
|
104
104
|
const url = aihubmixGeminiImageUrl({ baseUrl: req.baseUrl, wireModel: req.wireModel });
|
|
105
105
|
const resp = await doFetch({ url: url, init: {
|
|
106
106
|
method: 'POST',
|
|
@@ -143,7 +143,7 @@ const AIHUBMIX_WIRE_MODELS = {
|
|
|
143
143
|
'aihubmix-dall-e-3': 'dall-e-3',
|
|
144
144
|
'aihubmix-tts-1': 'tts-1',
|
|
145
145
|
};
|
|
146
|
-
export function aihubmixWireModel({ catalogId }) {
|
|
146
|
+
export function aihubmixWireModel({ catalogId }, _optional = {}) {
|
|
147
147
|
return AIHUBMIX_WIRE_MODELS[catalogId] ?? catalogId.replace(/^aihubmix-/, '');
|
|
148
148
|
}
|
|
149
149
|
// AIHubMix's unified /videos API uses a single `seconds` (string) field for
|
|
@@ -161,7 +161,7 @@ const AIHUBMIX_VIDEO_SECONDS = [
|
|
|
161
161
|
['sora', [4, 8, 12]],
|
|
162
162
|
['wan', [5, 10]],
|
|
163
163
|
];
|
|
164
|
-
export function aihubmixVideoSeconds({ wireModel, requested }) {
|
|
164
|
+
export function aihubmixVideoSeconds({ wireModel, requested }, _optional = {}) {
|
|
165
165
|
const m = (wireModel || '').toLowerCase();
|
|
166
166
|
const req = Number.isFinite(requested) ? requested : 5;
|
|
167
167
|
const allowed = AIHUBMIX_VIDEO_SECONDS.find(([prefix]) => m.startsWith(prefix))?.[1] ?? null;
|
|
@@ -173,7 +173,7 @@ export function aihubmixVideoSeconds({ wireModel, requested }) {
|
|
|
173
173
|
const snapped = allowed.reduce((best, v) => (Math.abs(v - req) < Math.abs(best - req) ? v : best), allowed[0]);
|
|
174
174
|
return String(snapped);
|
|
175
175
|
}
|
|
176
|
-
export function aihubmixCatalogUrl({ baseUrl, type }) {
|
|
176
|
+
export function aihubmixCatalogUrl({ baseUrl, type }, _optional = {}) {
|
|
177
177
|
const origin = aihubmixOriginFromBase({ baseUrl });
|
|
178
178
|
return `${origin}/api/v1/models?type=${type}`;
|
|
179
179
|
}
|
|
@@ -74,7 +74,10 @@
|
|
|
74
74
|
* for the integration-level regression proof.
|
|
75
75
|
*/
|
|
76
76
|
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
77
|
-
import {
|
|
77
|
+
import { extractProviderErrorDetail } from './response-text.js';
|
|
78
|
+
import { type PinnedFetch } from './connection-guard.js';
|
|
79
|
+
import { type DnsLookupFn } from '@jini-ai/core/contracts/agents';
|
|
80
|
+
import { parseSseJsonRecord } from './sse-decode.js';
|
|
78
81
|
import { type TurnEndReason } from './turn-end-guard.js';
|
|
79
82
|
import type { ProviderToolSnapshotOptions, ProviderSchemaFallback } from './provider-tool-policy.js';
|
|
80
83
|
export interface AnthropicTextBlockParam {
|
|
@@ -216,17 +219,15 @@ export interface AnthropicTurnResult {
|
|
|
216
219
|
}
|
|
217
220
|
export declare function anthropicRequestUrl({ baseUrl }: {
|
|
218
221
|
baseUrl: string | undefined;
|
|
219
|
-
}): string;
|
|
222
|
+
}, _optional?: Record<string, never>): string;
|
|
220
223
|
/** The `AnthropicTurnOptions` keys every caller must pass. */
|
|
221
224
|
type AnthropicRequiredOption = "apiKey" | "model" | "messages" | "maxTokens" | "onEvent";
|
|
222
225
|
export declare function anthropicHeaders(requiredArgs: Pick<AnthropicTurnOptions, AnthropicRequiredOption>, optionalArgs?: Omit<AnthropicTurnOptions, AnthropicRequiredOption>): Record<string, string>;
|
|
223
226
|
export declare function anthropicRequestBody({ options, messages }: {
|
|
224
227
|
options: AnthropicTurnOptions;
|
|
225
228
|
messages: readonly AnthropicMessageParam[];
|
|
226
|
-
}): Record<string, unknown>;
|
|
227
|
-
export declare
|
|
228
|
-
rawText: string;
|
|
229
|
-
}): string;
|
|
229
|
+
}, _optional?: Record<string, never>): Record<string, unknown>;
|
|
230
|
+
export declare const extractAnthropicErrorDetail: typeof extractProviderErrorDetail;
|
|
230
231
|
/**
|
|
231
232
|
* Validates one tool-result content block against the real API's format/size constraints.
|
|
232
233
|
* Returns the violation reason, or `null` when the block is legal to send.
|
|
@@ -241,7 +242,7 @@ export declare function extractAnthropicErrorDetail({ rawText }: {
|
|
|
241
242
|
*/
|
|
242
243
|
export declare function invalidToolResultContentBlockReason({ block }: {
|
|
243
244
|
block: AnthropicToolResultContentBlock;
|
|
244
|
-
}): string | null;
|
|
245
|
+
}, _optional?: Record<string, never>): string | null;
|
|
245
246
|
/**
|
|
246
247
|
* Runtime guard applied to every `AnthropicToolExecutor` result before it is wired onto the
|
|
247
248
|
* outbound request or reported via `onEvent`. `AnthropicToolResult` is host-owned (see
|
|
@@ -262,7 +263,7 @@ export declare function invalidToolResultContentBlockReason({ block }: {
|
|
|
262
263
|
*/
|
|
263
264
|
export declare function guardToolResult({ result }: {
|
|
264
265
|
result: AnthropicToolResult;
|
|
265
|
-
}): AnthropicToolResult;
|
|
266
|
+
}, _optional?: Record<string, never>): AnthropicToolResult;
|
|
266
267
|
export interface AnthropicBlockState {
|
|
267
268
|
readonly type: 'text' | 'tool_use' | 'other';
|
|
268
269
|
text: string;
|
|
@@ -285,13 +286,11 @@ export interface AnthropicStreamState {
|
|
|
285
286
|
usage: Record<string, unknown> | null;
|
|
286
287
|
}
|
|
287
288
|
/** 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". */
|
|
288
|
-
export declare
|
|
289
|
-
raw: string;
|
|
290
|
-
}): Record<string, unknown> | null;
|
|
289
|
+
export declare const parseAnthropicSseData: typeof parseSseJsonRecord;
|
|
291
290
|
export declare function handleContentBlockStart({ state, data }: {
|
|
292
291
|
state: AnthropicStreamState;
|
|
293
292
|
data: Record<string, unknown>;
|
|
294
|
-
}): void;
|
|
293
|
+
}, _optional?: Record<string, never>): void;
|
|
295
294
|
/**
|
|
296
295
|
* Feeds one text delta through the role-marker guard and emits the safe portion. Returns
|
|
297
296
|
* `'break'` once the guard flags contamination (the caller ends the turn immediately), otherwise
|
|
@@ -302,41 +301,41 @@ export declare function handleAnthropicTextDelta({ state, index, text, onEvent }
|
|
|
302
301
|
index: number;
|
|
303
302
|
text: string;
|
|
304
303
|
onEvent: (event: AnthropicTurnEvent) => void;
|
|
305
|
-
}): 'continue' | 'break';
|
|
304
|
+
}, _optional?: Record<string, never>): 'continue' | 'break';
|
|
306
305
|
export declare function handleAnthropicInputJsonDelta({ state, index, partialJson }: {
|
|
307
306
|
state: AnthropicStreamState;
|
|
308
307
|
index: number;
|
|
309
308
|
partialJson: string;
|
|
310
|
-
}): void;
|
|
309
|
+
}, _optional?: Record<string, never>): void;
|
|
311
310
|
export declare function handleContentBlockDelta({ state, data, onEvent }: {
|
|
312
311
|
state: AnthropicStreamState;
|
|
313
312
|
data: Record<string, unknown>;
|
|
314
313
|
onEvent: (event: AnthropicTurnEvent) => void;
|
|
315
|
-
}): 'continue' | 'break';
|
|
314
|
+
}, _optional?: Record<string, never>): 'continue' | 'break';
|
|
316
315
|
/** Parses one tool_use block's accumulated `input_json_delta` text, falling back to `{}` for empty or malformed JSON — mirrors OpenAI's identical fallback for `tool_calls[].function.arguments` in `openai-chat.ts`. */
|
|
317
316
|
export declare function parseAccumulatedToolInputJson({ inputJson }: {
|
|
318
317
|
inputJson: string;
|
|
319
|
-
}): unknown;
|
|
318
|
+
}, _optional?: Record<string, never>): unknown;
|
|
320
319
|
export declare function handleContentBlockStop({ state, data, onEvent }: {
|
|
321
320
|
state: AnthropicStreamState;
|
|
322
321
|
data: Record<string, unknown>;
|
|
323
322
|
onEvent: (event: AnthropicTurnEvent) => void;
|
|
324
|
-
}): void;
|
|
323
|
+
}, _optional?: Record<string, never>): void;
|
|
325
324
|
export declare function handleMessageDelta({ state, data, onEvent }: {
|
|
326
325
|
state: AnthropicStreamState;
|
|
327
326
|
data: Record<string, unknown>;
|
|
328
327
|
onEvent: (event: AnthropicTurnEvent) => void;
|
|
329
|
-
}): void;
|
|
328
|
+
}, _optional?: Record<string, never>): void;
|
|
330
329
|
export declare function handleAnthropicErrorFrame({ data, onEvent, apiKey }: {
|
|
331
330
|
data: Record<string, unknown>;
|
|
332
331
|
onEvent: (event: AnthropicTurnEvent) => void;
|
|
333
332
|
apiKey: string;
|
|
334
|
-
}): void;
|
|
333
|
+
}, _optional?: Record<string, never>): void;
|
|
335
334
|
/** The SSE event's dispatch key: `data.type` when present (every real Anthropic frame carries one), else the record's `event:` line, else `''` — a key that intentionally matches no entry in {@link ANTHROPIC_FRAME_HANDLERS} (`message_stop`/`ping`/future event types fall through as no-ops, same as before this frame was a lookup table). */
|
|
336
335
|
export declare function anthropicFrameKind({ data, frameEvent }: {
|
|
337
336
|
data: Record<string, unknown>;
|
|
338
337
|
frameEvent: string | null;
|
|
339
|
-
}): string;
|
|
338
|
+
}, _optional?: Record<string, never>): string;
|
|
340
339
|
/**
|
|
341
340
|
* Runs a full Anthropic Messages API turn, including the tool-execution
|
|
342
341
|
* loop when `options.executeTool` is supplied and the model requests tool
|
|
@@ -359,17 +358,17 @@ export declare function anthropicLoopExitReason({ outcome, toolTurns, maxToolTur
|
|
|
359
358
|
outcome: SingleRequestOutcome;
|
|
360
359
|
toolTurns: number;
|
|
361
360
|
maxToolTurns: number;
|
|
362
|
-
}): AnthropicTurnEndReason | null;
|
|
361
|
+
}, _optional?: Record<string, never>): AnthropicTurnEndReason | null;
|
|
363
362
|
export declare function buildAnthropicAssistantContent({ text, toolCalls }: {
|
|
364
363
|
text: string;
|
|
365
364
|
toolCalls: readonly AnthropicToolCall[];
|
|
366
|
-
}): AnthropicContentBlockParam[];
|
|
365
|
+
}, _optional?: Record<string, never>): AnthropicContentBlockParam[];
|
|
367
366
|
/** Runs every pending tool call in order and reduces the results into the `tool_result` blocks the next request's `user` message carries. Emits one `tool_result` event per call as it goes. */
|
|
368
367
|
export declare function executeAnthropicToolCalls({ executeTool, calls, onEvent }: {
|
|
369
368
|
executeTool: AnthropicToolExecutor;
|
|
370
369
|
calls: readonly AnthropicToolCall[];
|
|
371
370
|
onEvent: (event: AnthropicTurnEvent) => void;
|
|
372
|
-
}): Promise<AnthropicToolResultBlockParam[]>;
|
|
371
|
+
}, _optional?: Record<string, never>): Promise<AnthropicToolResultBlockParam[]>;
|
|
373
372
|
export declare function runAnthropicToolTurn(requiredArgs: Pick<AnthropicTurnOptions, AnthropicRequiredOption>, optionalArgs?: Omit<AnthropicTurnOptions, AnthropicRequiredOption>): Promise<AnthropicTurnResult>;
|
|
374
373
|
export {};
|
|
375
374
|
//# sourceMappingURL=anthropic-messages.d.ts.map
|
|
@@ -74,11 +74,14 @@ import { redactSecrets } from '@jini-ai/core';
|
|
|
74
74
|
* `__tests__/anthropic-messages.test.ts`'s "never emits end twice" case
|
|
75
75
|
* for the integration-level regression proof.
|
|
76
76
|
*/
|
|
77
|
-
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
77
|
+
import { createRoleMarkerGuard, emitGuardedTextDelta } from '../role-marker-guard.js';
|
|
78
|
+
import { extractProviderErrorDetail } from './response-text.js';
|
|
78
79
|
import { defaultDnsLookup, pinnedFetch, validateBaseUrlResolved } from './connection-guard.js';
|
|
79
|
-
import {
|
|
80
|
+
import {} from '@jini-ai/core/contracts/agents';
|
|
81
|
+
import { decodeSseStream, parseSseJsonRecord } from './sse-decode.js';
|
|
80
82
|
import { createTurnEndGuard } from './turn-end-guard.js';
|
|
81
83
|
import { createStrictToolRetry } from './openai-chat.js';
|
|
84
|
+
import {} from './openai-chat-types.js';
|
|
82
85
|
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
83
86
|
import { toolLoopVerdict } from './tool-loop-verdict.js';
|
|
84
87
|
import { omitKeys } from '../core/omit-keys.js';
|
|
@@ -88,7 +91,7 @@ const DEFAULT_MAX_TOOL_TURNS = 8;
|
|
|
88
91
|
function isRecord(value) {
|
|
89
92
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
90
93
|
}
|
|
91
|
-
export function anthropicRequestUrl({ baseUrl }) {
|
|
94
|
+
export function anthropicRequestUrl({ baseUrl }, _optional = {}) {
|
|
92
95
|
const base = trimCharsEnd({ text: baseUrl ?? DEFAULT_ANTHROPIC_BASE_URL, chars: '/' });
|
|
93
96
|
return `${base}/v1/messages`;
|
|
94
97
|
}
|
|
@@ -101,7 +104,7 @@ export function anthropicHeaders(requiredArgs, optionalArgs = {}) {
|
|
|
101
104
|
...(options.extraHeaders ?? {}),
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
|
-
export function anthropicRequestBody({ options, messages }) {
|
|
107
|
+
export function anthropicRequestBody({ options, messages }, _optional = {}) {
|
|
105
108
|
return {
|
|
106
109
|
model: options.model,
|
|
107
110
|
max_tokens: options.maxTokens,
|
|
@@ -112,18 +115,7 @@ export function anthropicRequestBody({ options, messages }) {
|
|
|
112
115
|
...(options.tools && options.tools.length > 0 ? { tools: options.tools } : {}),
|
|
113
116
|
};
|
|
114
117
|
}
|
|
115
|
-
export
|
|
116
|
-
try {
|
|
117
|
-
const parsed = JSON.parse(rawText);
|
|
118
|
-
if (isRecord(parsed) && isRecord(parsed.error) && typeof parsed.error.message === 'string') {
|
|
119
|
-
return parsed.error.message;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
// Non-JSON error body — fall through to the raw text below.
|
|
124
|
-
}
|
|
125
|
-
return rawText.trim().slice(0, 500);
|
|
126
|
-
}
|
|
118
|
+
export const extractAnthropicErrorDetail = extractProviderErrorDetail;
|
|
127
119
|
const ANTHROPIC_ALLOWED_IMAGE_MEDIA_TYPES = new Set([
|
|
128
120
|
'image/jpeg',
|
|
129
121
|
'image/png',
|
|
@@ -150,7 +142,7 @@ const MAX_IMAGE_BASE64_CHARS = Math.ceil((10 * 1024 * 1024 * 4) / 3);
|
|
|
150
142
|
* @complexity O(1) — reads `data.length`, never decodes or parses the base64 payload.
|
|
151
143
|
* @overallScore 100
|
|
152
144
|
*/
|
|
153
|
-
export function invalidToolResultContentBlockReason({ block }) {
|
|
145
|
+
export function invalidToolResultContentBlockReason({ block }, _optional = {}) {
|
|
154
146
|
if (block.type === 'text')
|
|
155
147
|
return null;
|
|
156
148
|
if (block.source.type === 'url')
|
|
@@ -181,7 +173,7 @@ export function invalidToolResultContentBlockReason({ block }) {
|
|
|
181
173
|
* `invalidToolResultContentBlockReason`).
|
|
182
174
|
* @overallScore 100
|
|
183
175
|
*/
|
|
184
|
-
export function guardToolResult({ result }) {
|
|
176
|
+
export function guardToolResult({ result }, _optional = {}) {
|
|
185
177
|
if (typeof result.content === 'string')
|
|
186
178
|
return result;
|
|
187
179
|
for (const block of result.content) {
|
|
@@ -193,17 +185,8 @@ export function guardToolResult({ result }) {
|
|
|
193
185
|
return result;
|
|
194
186
|
}
|
|
195
187
|
/** 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". */
|
|
196
|
-
export
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
data = JSON.parse(raw);
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
return isRecord(data) ? data : null;
|
|
205
|
-
}
|
|
206
|
-
export function handleContentBlockStart({ state, data }) {
|
|
188
|
+
export const parseAnthropicSseData = parseSseJsonRecord;
|
|
189
|
+
export function handleContentBlockStart({ state, data }, _optional = {}) {
|
|
207
190
|
if (!isRecord(data.content_block) || typeof data.index !== 'number')
|
|
208
191
|
return;
|
|
209
192
|
const block = data.content_block;
|
|
@@ -222,7 +205,7 @@ export function handleContentBlockStart({ state, data }) {
|
|
|
222
205
|
* `'break'` once the guard flags contamination (the caller ends the turn immediately), otherwise
|
|
223
206
|
* `'continue'`.
|
|
224
207
|
*/
|
|
225
|
-
export function handleAnthropicTextDelta({ state, index, text, onEvent }) {
|
|
208
|
+
export function handleAnthropicTextDelta({ state, index, text, onEvent }, _optional = {}) {
|
|
226
209
|
const blockState = state.blocks.get(index);
|
|
227
210
|
if (blockState)
|
|
228
211
|
blockState.text += text;
|
|
@@ -231,25 +214,15 @@ export function handleAnthropicTextDelta({ state, index, text, onEvent }) {
|
|
|
231
214
|
// delta in the same request can never reach this point already contaminated. (`feedText` itself
|
|
232
215
|
// is still safe to call unconditionally regardless — it early-returns `''` once contaminated,
|
|
233
216
|
// per its own doc.)
|
|
234
|
-
|
|
235
|
-
if (safe.length > 0) {
|
|
236
|
-
state.fullText += safe;
|
|
237
|
-
onEvent({ type: 'text_delta', delta: safe });
|
|
238
|
-
}
|
|
239
|
-
if (!state.guard.contaminated)
|
|
240
|
-
return 'continue';
|
|
241
|
-
const warn = state.guard.warningEvent();
|
|
242
|
-
if (warn)
|
|
243
|
-
onEvent(warn);
|
|
244
|
-
return 'break';
|
|
217
|
+
return emitGuardedTextDelta({ state, text: text, onEvent });
|
|
245
218
|
}
|
|
246
|
-
export function handleAnthropicInputJsonDelta({ state, index, partialJson }) {
|
|
219
|
+
export function handleAnthropicInputJsonDelta({ state, index, partialJson }, _optional = {}) {
|
|
247
220
|
const blockState = state.blocks.get(index);
|
|
248
221
|
if (!blockState)
|
|
249
222
|
return;
|
|
250
223
|
blockState.inputJson += partialJson;
|
|
251
224
|
}
|
|
252
|
-
export function handleContentBlockDelta({ state, data, onEvent }) {
|
|
225
|
+
export function handleContentBlockDelta({ state, data, onEvent }, _optional = {}) {
|
|
253
226
|
if (!isRecord(data.delta) || typeof data.index !== 'number')
|
|
254
227
|
return 'continue';
|
|
255
228
|
const { delta, index } = data;
|
|
@@ -262,7 +235,7 @@ export function handleContentBlockDelta({ state, data, onEvent }) {
|
|
|
262
235
|
return 'continue';
|
|
263
236
|
}
|
|
264
237
|
/** Parses one tool_use block's accumulated `input_json_delta` text, falling back to `{}` for empty or malformed JSON — mirrors OpenAI's identical fallback for `tool_calls[].function.arguments` in `openai-chat.ts`. */
|
|
265
|
-
export function parseAccumulatedToolInputJson({ inputJson }) {
|
|
238
|
+
export function parseAccumulatedToolInputJson({ inputJson }, _optional = {}) {
|
|
266
239
|
if (!inputJson.trim())
|
|
267
240
|
return {};
|
|
268
241
|
try {
|
|
@@ -272,7 +245,7 @@ export function parseAccumulatedToolInputJson({ inputJson }) {
|
|
|
272
245
|
return {};
|
|
273
246
|
}
|
|
274
247
|
}
|
|
275
|
-
export function handleContentBlockStop({ state, data, onEvent }) {
|
|
248
|
+
export function handleContentBlockStop({ state, data, onEvent }, _optional = {}) {
|
|
276
249
|
if (typeof data.index !== 'number')
|
|
277
250
|
return;
|
|
278
251
|
const blockState = state.blocks.get(data.index);
|
|
@@ -283,7 +256,7 @@ export function handleContentBlockStop({ state, data, onEvent }) {
|
|
|
283
256
|
}
|
|
284
257
|
state.blocks.delete(data.index);
|
|
285
258
|
}
|
|
286
|
-
export function handleMessageDelta({ state, data, onEvent }) {
|
|
259
|
+
export function handleMessageDelta({ state, data, onEvent }, _optional = {}) {
|
|
287
260
|
if (isRecord(data.delta) && typeof data.delta.stop_reason === 'string') {
|
|
288
261
|
state.stopReason = data.delta.stop_reason;
|
|
289
262
|
}
|
|
@@ -292,13 +265,13 @@ export function handleMessageDelta({ state, data, onEvent }) {
|
|
|
292
265
|
onEvent({ type: 'usage', usage: state.usage });
|
|
293
266
|
}
|
|
294
267
|
}
|
|
295
|
-
export function handleAnthropicErrorFrame({ data, onEvent, apiKey }) {
|
|
268
|
+
export function handleAnthropicErrorFrame({ data, onEvent, apiKey }, _optional = {}) {
|
|
296
269
|
const errorDetail = isRecord(data.error) && typeof data.error.message === 'string' ? data.error.message : 'upstream error';
|
|
297
270
|
const errorType = isRecord(data.error) && typeof data.error.type === 'string' ? data.error.type : undefined;
|
|
298
271
|
onEvent({ type: 'error', message: redactSecrets({ input: errorDetail }, { exactSecrets: [apiKey] }), ...(errorType ? { code: errorType } : {}) });
|
|
299
272
|
}
|
|
300
273
|
/** The SSE event's dispatch key: `data.type` when present (every real Anthropic frame carries one), else the record's `event:` line, else `''` — a key that intentionally matches no entry in {@link ANTHROPIC_FRAME_HANDLERS} (`message_stop`/`ping`/future event types fall through as no-ops, same as before this frame was a lookup table). */
|
|
301
|
-
export function anthropicFrameKind({ data, frameEvent }) {
|
|
274
|
+
export function anthropicFrameKind({ data, frameEvent }, _optional = {}) {
|
|
302
275
|
if (typeof data.type === 'string')
|
|
303
276
|
return data.type;
|
|
304
277
|
return frameEvent ?? '';
|
|
@@ -336,7 +309,7 @@ function refreshAnthropicTools(options, retry) {
|
|
|
336
309
|
let tools = options.getTools?.({ strict: retry.enabled }) ?? options.tools;
|
|
337
310
|
if (!retry.enabled)
|
|
338
311
|
tools = tools?.map(tool => {
|
|
339
|
-
return omitKeys(tool, ['strict']);
|
|
312
|
+
return omitKeys({ source: tool, keys: ['strict'] });
|
|
340
313
|
});
|
|
341
314
|
return { ...options, ...(tools !== undefined ? { tools } : {}) };
|
|
342
315
|
}
|
|
@@ -459,21 +432,21 @@ async function runSingleAnthropicRequest(options, messages, emitEnd, retry) {
|
|
|
459
432
|
* "stop" conditions (no/empty tool_use, no executor, turn ceiling reached) are exercised as plain
|
|
460
433
|
* value-in/value-out assertions rather than through the full request/event-emission machinery.
|
|
461
434
|
*/
|
|
462
|
-
export function anthropicLoopExitReason({ outcome, toolTurns, maxToolTurns }) {
|
|
435
|
+
export function anthropicLoopExitReason({ outcome, toolTurns, maxToolTurns }, _optional = {}) {
|
|
463
436
|
if (outcome.stopReason !== 'tool_use' || outcome.toolCalls.length === 0)
|
|
464
437
|
return 'stop';
|
|
465
438
|
if (toolTurns >= maxToolTurns)
|
|
466
439
|
return 'max_tool_turns';
|
|
467
440
|
return null;
|
|
468
441
|
}
|
|
469
|
-
export function buildAnthropicAssistantContent({ text, toolCalls }) {
|
|
442
|
+
export function buildAnthropicAssistantContent({ text, toolCalls }, _optional = {}) {
|
|
470
443
|
return [
|
|
471
444
|
...(text ? [{ type: 'text', text }] : []),
|
|
472
445
|
...toolCalls.map((call) => ({ type: 'tool_use', id: call.id, name: call.name, input: call.input })),
|
|
473
446
|
];
|
|
474
447
|
}
|
|
475
448
|
/** Runs every pending tool call in order and reduces the results into the `tool_result` blocks the next request's `user` message carries. Emits one `tool_result` event per call as it goes. */
|
|
476
|
-
export async function executeAnthropicToolCalls({ executeTool, calls, onEvent }) {
|
|
449
|
+
export async function executeAnthropicToolCalls({ executeTool, calls, onEvent }, _optional = {}) {
|
|
477
450
|
const toolResultBlocks = [];
|
|
478
451
|
for (const call of calls) {
|
|
479
452
|
const rawResult = await executeTool(call);
|
|
@@ -493,7 +466,7 @@ export async function runAnthropicToolTurn(requiredArgs, optionalArgs = {}) {
|
|
|
493
466
|
const retry = createStrictToolRetry({ protocol: 'anthropic', onSchemaFallback: options.onSchemaFallback });
|
|
494
467
|
const maxToolTurns = options.maxToolTurns ?? DEFAULT_MAX_TOOL_TURNS;
|
|
495
468
|
const executeTool = options.executeTool;
|
|
496
|
-
const endGuard = createTurnEndGuard(options.onEvent, (reason) => ({ type: 'end', reason }));
|
|
469
|
+
const endGuard = createTurnEndGuard({ onEvent: options.onEvent, makeEndEvent: (reason) => ({ type: 'end', reason }) });
|
|
497
470
|
const emitEnd = endGuard.emitEnd;
|
|
498
471
|
let messages = options.messages.slice();
|
|
499
472
|
let toolTurns = 0;
|
|
@@ -72,8 +72,9 @@
|
|
|
72
72
|
* beyond this pointer to avoid the two copies drifting.
|
|
73
73
|
* See docs/decisions/DR-001-provider-native-tool-lifecycle.md.
|
|
74
74
|
*/
|
|
75
|
-
import { type
|
|
76
|
-
import { type
|
|
75
|
+
import { type PinnedFetch } from './connection-guard.js';
|
|
76
|
+
import { type DnsLookupFn } from '@jini-ai/core/contracts/agents';
|
|
77
|
+
import { type OpenAiCompatibleRequestOutcome } from './openai-chat-types.js';
|
|
77
78
|
import type { ProviderToolSnapshotOptions, ProviderSchemaFallback } from './provider-tool-policy.js';
|
|
78
79
|
import { type TurnEndReason } from './turn-end-guard.js';
|
|
79
80
|
export interface AzureFunctionToolDef {
|
|
@@ -198,11 +199,11 @@ export declare function azureLoopExitReason({ outcome, toolTurns, maxToolTurns }
|
|
|
198
199
|
outcome: OpenAiCompatibleRequestOutcome;
|
|
199
200
|
toolTurns: number;
|
|
200
201
|
maxToolTurns: number;
|
|
201
|
-
}): AzureTurnEndReason | null;
|
|
202
|
+
}, _optional?: Record<string, never>): AzureTurnEndReason | null;
|
|
202
203
|
/** Builds the assistant continuation's `tool_calls` field — same shape as `openai-chat.ts#buildOpenAiAssistantToolCallMessage`'s `tool_calls`, since Azure's wire body is byte-identical to plain OpenAI's (see module doc). */
|
|
203
204
|
export declare function buildAzureAssistantToolCalls({ toolCalls }: {
|
|
204
205
|
toolCalls: readonly AzureToolCall[];
|
|
205
|
-
}): AzureToolCallParam[];
|
|
206
|
+
}, _optional?: Record<string, never>): AzureToolCallParam[];
|
|
206
207
|
export interface AzureToolExecutionOutcome {
|
|
207
208
|
readonly toolResultMessages: AzureMessageParam[];
|
|
208
209
|
readonly followUpParts: AzureContentPart[];
|
|
@@ -212,12 +213,12 @@ export declare function executeAzureToolCalls({ executeTool, calls, onEvent }: {
|
|
|
212
213
|
executeTool: AzureToolExecutor;
|
|
213
214
|
calls: readonly AzureToolCall[];
|
|
214
215
|
onEvent: (event: AzureTurnEvent) => void;
|
|
215
|
-
}): Promise<AzureToolExecutionOutcome>;
|
|
216
|
+
}, _optional?: Record<string, never>): Promise<AzureToolExecutionOutcome>;
|
|
216
217
|
/** Azure counterpart of `openai-chat.ts#buildOpenAiToolExchangeMessages` — appends the batch's `tool` messages plus, when present, the single labeled-image follow-up message. */
|
|
217
218
|
export declare function buildAzureToolExchangeMessages({ toolResultMessages, followUpParts }: {
|
|
218
219
|
toolResultMessages: readonly AzureMessageParam[];
|
|
219
220
|
followUpParts: readonly AzureContentPart[];
|
|
220
|
-
}): AzureMessageParam[];
|
|
221
|
+
}, _optional?: Record<string, never>): AzureMessageParam[];
|
|
221
222
|
/**
|
|
222
223
|
* Runs a full Azure OpenAI Chat Completions turn, including the
|
|
223
224
|
* tool-execution loop when `options.executeTool` is supplied and the model
|
|
@@ -73,7 +73,10 @@
|
|
|
73
73
|
* See docs/decisions/DR-001-provider-native-tool-lifecycle.md.
|
|
74
74
|
*/
|
|
75
75
|
import { defaultDnsLookup, validateBaseUrlResolved } from './connection-guard.js';
|
|
76
|
-
import {
|
|
76
|
+
import {} from '@jini-ai/core/contracts/agents';
|
|
77
|
+
import { runOpenAiCompatibleRequest } from './openai-chat-request.js';
|
|
78
|
+
import { refreshOpenAiTools, createStrictToolRetry } from './openai-chat.js';
|
|
79
|
+
import {} from './openai-chat-types.js';
|
|
77
80
|
import { buildLegacyMaxTokensParam, buildMaxCompletionTokensParam, isUnsupportedMaxTokensError } from './token-params.js';
|
|
78
81
|
import { createTurnEndGuard } from './turn-end-guard.js';
|
|
79
82
|
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
@@ -192,7 +195,7 @@ function splitAzureToolResultContent(content) {
|
|
|
192
195
|
* instead proceed to execute the pending tool calls — mirrors
|
|
193
196
|
* `anthropic-messages.ts#anthropicLoopExitReason`'s pure decision/effect split.
|
|
194
197
|
*/
|
|
195
|
-
export function azureLoopExitReason({ outcome, toolTurns, maxToolTurns }) {
|
|
198
|
+
export function azureLoopExitReason({ outcome, toolTurns, maxToolTurns }, _optional = {}) {
|
|
196
199
|
if (outcome.finishReason !== 'tool_calls' || outcome.toolCalls.length === 0)
|
|
197
200
|
return 'stop';
|
|
198
201
|
if (toolTurns >= maxToolTurns)
|
|
@@ -200,11 +203,11 @@ export function azureLoopExitReason({ outcome, toolTurns, maxToolTurns }) {
|
|
|
200
203
|
return null;
|
|
201
204
|
}
|
|
202
205
|
/** Builds the assistant continuation's `tool_calls` field — same shape as `openai-chat.ts#buildOpenAiAssistantToolCallMessage`'s `tool_calls`, since Azure's wire body is byte-identical to plain OpenAI's (see module doc). */
|
|
203
|
-
export function buildAzureAssistantToolCalls({ toolCalls }) {
|
|
206
|
+
export function buildAzureAssistantToolCalls({ toolCalls }, _optional = {}) {
|
|
204
207
|
return toolCalls.map((call) => ({ id: call.id, type: 'function', function: { name: call.name, arguments: JSON.stringify(call.input) } }));
|
|
205
208
|
}
|
|
206
209
|
/** Azure counterpart of `openai-chat.ts#executeOpenAiToolCalls` — same split (text-only `tool` message plus one labeled-image follow-up per batch) and same per-batch assembly discipline; see that function's doc and module doc's "synthetic follow-up message" note for why. */
|
|
207
|
-
export async function executeAzureToolCalls({ executeTool, calls, onEvent }) {
|
|
210
|
+
export async function executeAzureToolCalls({ executeTool, calls, onEvent }, _optional = {}) {
|
|
208
211
|
const toolResultMessages = [];
|
|
209
212
|
const followUpParts = [];
|
|
210
213
|
for (const call of calls) {
|
|
@@ -222,7 +225,7 @@ export async function executeAzureToolCalls({ executeTool, calls, onEvent }) {
|
|
|
222
225
|
return { toolResultMessages, followUpParts };
|
|
223
226
|
}
|
|
224
227
|
/** Azure counterpart of `openai-chat.ts#buildOpenAiToolExchangeMessages` — appends the batch's `tool` messages plus, when present, the single labeled-image follow-up message. */
|
|
225
|
-
export function buildAzureToolExchangeMessages({ toolResultMessages, followUpParts }) {
|
|
228
|
+
export function buildAzureToolExchangeMessages({ toolResultMessages, followUpParts }, _optional = {}) {
|
|
226
229
|
return [...toolResultMessages, ...(followUpParts.length > 0 ? [{ role: 'user', content: followUpParts }] : [])];
|
|
227
230
|
}
|
|
228
231
|
/**
|
|
@@ -236,7 +239,7 @@ export async function runAzureToolTurn(requiredArgs, optionalArgs = {}) {
|
|
|
236
239
|
const retry = createStrictToolRetry({ protocol: 'azure', onSchemaFallback: options.onSchemaFallback });
|
|
237
240
|
const maxToolTurns = options.maxToolTurns ?? DEFAULT_MAX_TOOL_TURNS;
|
|
238
241
|
const executeTool = options.executeTool;
|
|
239
|
-
const endGuard = createTurnEndGuard(options.onEvent, (reason) => ({ type: 'end', reason }));
|
|
242
|
+
const endGuard = createTurnEndGuard({ onEvent: options.onEvent, makeEndEvent: (reason) => ({ type: 'end', reason }) });
|
|
240
243
|
const emitEnd = endGuard.emitEnd;
|
|
241
244
|
let messages = options.messages.slice();
|
|
242
245
|
let toolTurns = 0;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DnsLookupAddress, DnsLookupFn } from '@jini-ai/core/contracts/agents';
|
|
1
2
|
export interface BaseUrlValidationResult {
|
|
2
3
|
parsed?: URL;
|
|
3
4
|
error?: string;
|
|
@@ -34,14 +35,7 @@ export interface BaseUrlValidationResult {
|
|
|
34
35
|
*/
|
|
35
36
|
export declare function validateBaseUrl({ baseUrl }: {
|
|
36
37
|
baseUrl: string;
|
|
37
|
-
}): BaseUrlValidationResult;
|
|
38
|
-
export type DnsLookupAddress = {
|
|
39
|
-
address: string;
|
|
40
|
-
family: number;
|
|
41
|
-
};
|
|
42
|
-
export type DnsLookupFn = (requiredArgs: {
|
|
43
|
-
hostname: string;
|
|
44
|
-
}) => Promise<DnsLookupAddress[]>;
|
|
38
|
+
}, _optional?: Record<string, never>): BaseUrlValidationResult;
|
|
45
39
|
/**
|
|
46
40
|
* DNS-aware companion to {@link validateBaseUrl}. The synchronous check only
|
|
47
41
|
* inspects the literal hostname string, so a public DNS name pointing at
|
|
@@ -85,7 +79,7 @@ export type DnsLookupFn = (requiredArgs: {
|
|
|
85
79
|
export declare function validateBaseUrlResolved({ baseUrl, lookup }: {
|
|
86
80
|
baseUrl: string;
|
|
87
81
|
lookup: DnsLookupFn;
|
|
88
|
-
}): Promise<BaseUrlValidationResult>;
|
|
82
|
+
}, _optional?: Record<string, never>): Promise<BaseUrlValidationResult>;
|
|
89
83
|
/** Request options accepted by {@link pinnedFetch} — the subset of `fetch`'s `init` this package's provider adapters actually pass. `redirect` is accepted only as documentation of intent: `pinnedFetch` never follows a redirect regardless of this field, so a caller cannot opt back into `fetch`'s default follow-redirects behavior. */
|
|
90
84
|
export interface PinnedFetchInit {
|
|
91
85
|
readonly method: string;
|
|
@@ -44,7 +44,8 @@ import { readProviderResponseText, MAX_PROVIDER_ERROR_BYTES } from './response-t
|
|
|
44
44
|
* the UI accepts an endpoint this guard then refuses — or, in the direction
|
|
45
45
|
* that actually matters, the UI accepts one this guard would have refused.
|
|
46
46
|
*/
|
|
47
|
-
import { isLoopbackApiHost, isBlockedExternalApiHostname } from '@jini-ai/
|
|
47
|
+
import { isLoopbackApiHost, isBlockedExternalApiHostname } from '@jini-ai/core/net';
|
|
48
|
+
import { isIpLiteralHostname } from '@jini-ai/core';
|
|
48
49
|
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
49
50
|
/**
|
|
50
51
|
* Synchronous base-URL check: scheme allow-list + literal-hostname block-list.
|
|
@@ -66,7 +67,7 @@ import { trimCharsEnd } from '@jini-ai/core/text';
|
|
|
66
67
|
* is the only shape that would let the block-list inspect one string while the
|
|
67
68
|
* network used another.
|
|
68
69
|
*/
|
|
69
|
-
export function validateBaseUrl({ baseUrl }) {
|
|
70
|
+
export function validateBaseUrl({ baseUrl }, _optional = {}) {
|
|
70
71
|
let parsed;
|
|
71
72
|
try {
|
|
72
73
|
// Trim BEFORE stripping trailing slashes: in `"https://x/ "` the trailing
|
|
@@ -85,14 +86,6 @@ export function validateBaseUrl({ baseUrl }) {
|
|
|
85
86
|
}
|
|
86
87
|
return { parsed };
|
|
87
88
|
}
|
|
88
|
-
function looksLikeIpLiteral(hostname) {
|
|
89
|
-
const host = hostname.startsWith('[') && hostname.endsWith(']')
|
|
90
|
-
? hostname.slice(1, -1)
|
|
91
|
-
: hostname;
|
|
92
|
-
if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(host))
|
|
93
|
-
return true;
|
|
94
|
-
return host.includes(':');
|
|
95
|
-
}
|
|
96
89
|
/**
|
|
97
90
|
* DNS-aware companion to {@link validateBaseUrl}. The synchronous check only
|
|
98
91
|
* inspects the literal hostname string, so a public DNS name pointing at
|
|
@@ -133,14 +126,12 @@ function looksLikeIpLiteral(hostname) {
|
|
|
133
126
|
* a Node host can wrap `node:dns`'s promise
|
|
134
127
|
* `lookup(hostname, { all: true, family: 0 })` in this port's object signature.
|
|
135
128
|
*/
|
|
136
|
-
export async function validateBaseUrlResolved({ baseUrl, lookup }) {
|
|
129
|
+
export async function validateBaseUrlResolved({ baseUrl, lookup }, _optional = {}) {
|
|
137
130
|
const sync = validateBaseUrl({ baseUrl: baseUrl });
|
|
138
131
|
if (sync.error || !sync.parsed)
|
|
139
132
|
return sync;
|
|
140
133
|
const hostname = sync.parsed.hostname.toLowerCase();
|
|
141
|
-
if (
|
|
142
|
-
return sync;
|
|
143
|
-
if (looksLikeIpLiteral(hostname))
|
|
134
|
+
if (skipsApiDnsLookup(hostname))
|
|
144
135
|
return sync;
|
|
145
136
|
let addresses;
|
|
146
137
|
try {
|
|
@@ -166,6 +157,7 @@ export async function validateBaseUrlResolved({ baseUrl, lookup }) {
|
|
|
166
157
|
// pre-pinning pass-through behavior. The nonempty check guarantees the first address exists.
|
|
167
158
|
return { ...sync, pinnedAddress: addresses[0] };
|
|
168
159
|
}
|
|
160
|
+
function skipsApiDnsLookup(hostname) { return isLoopbackApiHost({ hostname }) || isIpLiteralHostname({ hostname }); }
|
|
169
161
|
/**
|
|
170
162
|
* Idle-socket safety net, applied to every `pinnedFetch` request regardless of `init.signal`.
|
|
171
163
|
* Plain `http(s).request` has NO default timeout at all — unlike `fetch`, which is backed by
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
* no OD workspace-package imports, matching every other file in this
|
|
18
18
|
* directory.
|
|
19
19
|
*/
|
|
20
|
-
import type { DnsLookupFn } from '
|
|
21
|
-
import type { ConnectionTestKind, ConnectionTestProtocol } from './types.js';
|
|
20
|
+
import type { DnsLookupFn, ConnectionTestKind, ConnectionTestProtocol } from '@jini-ai/core/contracts/agents';
|
|
22
21
|
/** The four wire protocols this smoke test knows how to speak. A narrower
|
|
23
22
|
* type than {@link ConnectionTestProtocol} on purpose — see this module's
|
|
24
23
|
* header for what's out of scope and why. */
|