@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { redactSecrets } from '@jini-ai/core';
|
|
2
2
|
import { defaultDnsLookup, validateBaseUrlResolved } from './connection-guard.js';
|
|
3
|
+
import { appendVersionedApiPath } from './provider-url.js';
|
|
3
4
|
import { googleGenerateContentUrl } from './google.js';
|
|
4
5
|
import { buildOpenAIChatTokenParam, buildLegacyMaxTokensParam } from './token-params.js';
|
|
5
6
|
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
@@ -26,12 +27,6 @@ const SAMPLE_MAX_CHARS = 120;
|
|
|
26
27
|
function isSupportedProtocol(protocol) {
|
|
27
28
|
return protocol === 'anthropic' || protocol === 'openai' || protocol === 'azure' || protocol === 'google';
|
|
28
29
|
}
|
|
29
|
-
function appendVersionedApiPath(baseUrl, suffix) {
|
|
30
|
-
const url = new URL(baseUrl);
|
|
31
|
-
const pathname = trimCharsEnd({ text: url.pathname, chars: '/' });
|
|
32
|
-
url.pathname = /\/v\d+(\/|$)/.test(pathname) ? `${pathname}${suffix}` : `${pathname}/v1${suffix}`;
|
|
33
|
-
return url.toString();
|
|
34
|
-
}
|
|
35
30
|
/** Only ever called with the redacted string `extractText` produced, so no non-string guard is needed. */
|
|
36
31
|
function truncateSample(text) {
|
|
37
32
|
const trimmed = text.replace(/\s+/g, ' ').trim();
|
|
@@ -162,41 +157,61 @@ function emptyReplyDetail(finishReason) {
|
|
|
162
157
|
? `Provider returned a 2xx response without assistant text (finish reason: ${finishReason})`
|
|
163
158
|
: 'Provider returned a 2xx response without assistant text';
|
|
164
159
|
}
|
|
160
|
+
function extractAnthropicMessageText(data) {
|
|
161
|
+
const blocks = data.content;
|
|
162
|
+
if (!Array.isArray(blocks))
|
|
163
|
+
return '';
|
|
164
|
+
for (const block of blocks) {
|
|
165
|
+
if (block &&
|
|
166
|
+
typeof block === 'object' &&
|
|
167
|
+
block.type === 'text' &&
|
|
168
|
+
typeof block.text === 'string') {
|
|
169
|
+
return block.text;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
function extractGoogleMessageText(data) {
|
|
175
|
+
const candidates = data.candidates;
|
|
176
|
+
if (!Array.isArray(candidates) || candidates.length === 0)
|
|
177
|
+
return '';
|
|
178
|
+
const parts = candidates[0].content?.parts;
|
|
179
|
+
if (!Array.isArray(parts))
|
|
180
|
+
return '';
|
|
181
|
+
return parts
|
|
182
|
+
// Gemini 2.5 returns its hidden reasoning as ordinary parts flagged `thought: true`,
|
|
183
|
+
// interleaved with the real answer. Joining them all turns a correct "ok" into
|
|
184
|
+
// "<paragraph of reasoning>ok", which `isSmokeOkReply`'s exact match then rejects — a
|
|
185
|
+
// model that answered correctly reported as a failed connection. Only the answer counts.
|
|
186
|
+
.filter((p) => p?.thought !== true)
|
|
187
|
+
.map((p) => (typeof p?.text === 'string' ? p.text : ''))
|
|
188
|
+
.join('');
|
|
189
|
+
}
|
|
190
|
+
function buildAnthropicProviderCall({ baseUrl, apiKey, model }) {
|
|
191
|
+
return {
|
|
192
|
+
url: appendVersionedApiPath({ baseUrl, suffix: '/messages' }),
|
|
193
|
+
headers: {
|
|
194
|
+
'content-type': 'application/json',
|
|
195
|
+
'x-api-key': apiKey,
|
|
196
|
+
'anthropic-version': '2023-06-01',
|
|
197
|
+
},
|
|
198
|
+
body: {
|
|
199
|
+
model,
|
|
200
|
+
max_tokens: CONNECTION_TEST_MAX_TOKENS,
|
|
201
|
+
messages: [{ role: 'user', content: SMOKE_PROMPT }],
|
|
202
|
+
stream: false,
|
|
203
|
+
},
|
|
204
|
+
extractText: extractAnthropicMessageText,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
165
207
|
function buildProviderCall(input) {
|
|
166
208
|
const { baseUrl, apiKey, model } = input;
|
|
167
209
|
switch (input.protocol) {
|
|
168
210
|
case 'anthropic':
|
|
169
|
-
return {
|
|
170
|
-
url: appendVersionedApiPath(baseUrl, '/messages'),
|
|
171
|
-
headers: {
|
|
172
|
-
'content-type': 'application/json',
|
|
173
|
-
'x-api-key': apiKey,
|
|
174
|
-
'anthropic-version': '2023-06-01',
|
|
175
|
-
},
|
|
176
|
-
body: {
|
|
177
|
-
model,
|
|
178
|
-
max_tokens: CONNECTION_TEST_MAX_TOKENS,
|
|
179
|
-
messages: [{ role: 'user', content: SMOKE_PROMPT }],
|
|
180
|
-
stream: false,
|
|
181
|
-
},
|
|
182
|
-
extractText: (data) => {
|
|
183
|
-
const blocks = data.content;
|
|
184
|
-
if (!Array.isArray(blocks))
|
|
185
|
-
return '';
|
|
186
|
-
for (const block of blocks) {
|
|
187
|
-
if (block &&
|
|
188
|
-
typeof block === 'object' &&
|
|
189
|
-
block.type === 'text' &&
|
|
190
|
-
typeof block.text === 'string') {
|
|
191
|
-
return block.text;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return '';
|
|
195
|
-
},
|
|
196
|
-
};
|
|
211
|
+
return buildAnthropicProviderCall({ baseUrl, apiKey, model });
|
|
197
212
|
case 'openai':
|
|
198
213
|
return {
|
|
199
|
-
url: appendVersionedApiPath(baseUrl, '/chat/completions'),
|
|
214
|
+
url: appendVersionedApiPath({ baseUrl, suffix: '/chat/completions' }),
|
|
200
215
|
headers: {
|
|
201
216
|
'content-type': 'application/json',
|
|
202
217
|
authorization: `Bearer ${apiKey}`,
|
|
@@ -222,22 +237,7 @@ function buildProviderCall(input) {
|
|
|
222
237
|
contents: [{ role: 'user', parts: [{ text: SMOKE_PROMPT }] }],
|
|
223
238
|
generationConfig: { maxOutputTokens: CONNECTION_TEST_MAX_TOKENS },
|
|
224
239
|
},
|
|
225
|
-
extractText:
|
|
226
|
-
const candidates = data.candidates;
|
|
227
|
-
if (!Array.isArray(candidates) || candidates.length === 0)
|
|
228
|
-
return '';
|
|
229
|
-
const parts = candidates[0].content?.parts;
|
|
230
|
-
if (!Array.isArray(parts))
|
|
231
|
-
return '';
|
|
232
|
-
return parts
|
|
233
|
-
// Gemini 2.5 returns its hidden reasoning as ordinary parts flagged `thought: true`,
|
|
234
|
-
// interleaved with the real answer. Joining them all turns a correct "ok" into
|
|
235
|
-
// "<paragraph of reasoning>ok", which `isSmokeOkReply`'s exact match then rejects — a
|
|
236
|
-
// model that answered correctly reported as a failed connection. Only the answer counts.
|
|
237
|
-
.filter((p) => p?.thought !== true)
|
|
238
|
-
.map((p) => (typeof p?.text === 'string' ? p.text : ''))
|
|
239
|
-
.join('');
|
|
240
|
-
},
|
|
240
|
+
extractText: extractGoogleMessageText,
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
243
|
default: {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Resolve the provider credential for one bring-your-own-key turn. A credential supplied on the
|
|
3
|
+
* request wins when it is complete (someone trying a key they have not saved yet: no store read);
|
|
4
|
+
* otherwise the host's stored credential for that `(workspaceId, principalId)` is used. Absence is a
|
|
5
|
+
* value (`null`), never a throw, so a caller treats a missing or invalid credential as an ordinary
|
|
6
|
+
* client error branch.
|
|
7
|
+
*/
|
|
8
|
+
import type { ProviderProtocol } from './provider-tool-policy.js';
|
|
9
|
+
export interface ResolvedProviderCredential {
|
|
10
|
+
readonly protocol: ProviderProtocol;
|
|
11
|
+
readonly apiKey: string;
|
|
12
|
+
readonly baseUrl?: string;
|
|
13
|
+
readonly model: string;
|
|
14
|
+
readonly maxTokens?: number;
|
|
15
|
+
}
|
|
16
|
+
/** What a client sends on one request. Every field may be omitted or empty: that is exactly the signal
|
|
17
|
+
* `createStoredExecutionCredentialPort` reads as "fall back to the stored credential". */
|
|
18
|
+
export interface RequestSuppliedProviderConfig {
|
|
19
|
+
readonly protocol?: unknown;
|
|
20
|
+
readonly apiKey?: unknown;
|
|
21
|
+
readonly baseUrl?: unknown;
|
|
22
|
+
readonly model?: unknown;
|
|
23
|
+
readonly maxTokens?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** A host's stored credential row, already decrypted. `protocol` is unvalidated text. */
|
|
26
|
+
export interface StoredProviderCredential {
|
|
27
|
+
readonly protocol: string;
|
|
28
|
+
readonly apiKey: string;
|
|
29
|
+
readonly model: string | null;
|
|
30
|
+
readonly baseUrl: string | null;
|
|
31
|
+
readonly maxTokens: number | null;
|
|
32
|
+
}
|
|
33
|
+
export interface ExecutionCredentialPort {
|
|
34
|
+
/** `null` for "no usable credential". Identity-scoped and async because a stored backing reads a
|
|
35
|
+
* `(workspace, principal)` row and decrypts it; the request-only port ignores the identity fields. */
|
|
36
|
+
resolve(input: {
|
|
37
|
+
requestBody: RequestSuppliedProviderConfig;
|
|
38
|
+
workspaceId: string;
|
|
39
|
+
principalId: string;
|
|
40
|
+
}): Promise<ResolvedProviderCredential | null>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Trusts ONLY the credential sent on this one request: never reads a store, never writes anything.
|
|
44
|
+
* @complexity O(1).
|
|
45
|
+
*/
|
|
46
|
+
export declare function createRequestSuppliedExecutionCredentialPort(_options?: {}): ExecutionCredentialPort;
|
|
47
|
+
/**
|
|
48
|
+
* Request-supplied credential first; otherwise the host's stored row. A stored row whose protocol this
|
|
49
|
+
* package cannot dispatch, or with no model set (turns always need a model), is unusable.
|
|
50
|
+
* `readStored` must not throw for an undecryptable row: it returns `null`.
|
|
51
|
+
* @complexity O(1): at most one `readStored` call, only when the request supplied nothing usable.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createStoredExecutionCredentialPort({ readStored }: {
|
|
54
|
+
readStored: (required: {
|
|
55
|
+
workspaceId: string;
|
|
56
|
+
principalId: string;
|
|
57
|
+
}) => Promise<StoredProviderCredential | null>;
|
|
58
|
+
}, _options?: {}): ExecutionCredentialPort;
|
|
59
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const VALID_PROTOCOLS = new Set(['anthropic', 'openai', 'azure', 'google']);
|
|
2
|
+
/** `requestBody.protocol`'s own field parse, split out of `parseRequestSuppliedCredential` to keep its
|
|
3
|
+
* complexity under the ceiling; behaviour is unchanged. */
|
|
4
|
+
function parseProtocol({ value }, _options = {}) {
|
|
5
|
+
return typeof value === 'string' && VALID_PROTOCOLS.has(value) ? value : null;
|
|
6
|
+
}
|
|
7
|
+
/** A required, non-blank string field (`apiKey`/`model`). */
|
|
8
|
+
function parseRequiredString({ value }, _options = {}) {
|
|
9
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : null;
|
|
10
|
+
}
|
|
11
|
+
/** An optional, non-blank string field (`baseUrl`). */
|
|
12
|
+
function parseOptionalString({ value }, _options = {}) {
|
|
13
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
14
|
+
}
|
|
15
|
+
/** `requestBody.maxTokens`'s own field parse: a positive number or nothing. */
|
|
16
|
+
function parseMaxTokens({ value }, _options = {}) {
|
|
17
|
+
return typeof value === 'number' && value > 0 ? value : undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Pure parse of a client-supplied config: no I/O, `null` when any required field is missing or invalid. */
|
|
20
|
+
function parseRequestSuppliedCredential(requestBody) {
|
|
21
|
+
const protocol = parseProtocol({ value: requestBody.protocol });
|
|
22
|
+
if (!protocol)
|
|
23
|
+
return null;
|
|
24
|
+
const apiKey = parseRequiredString({ value: requestBody.apiKey });
|
|
25
|
+
if (!apiKey)
|
|
26
|
+
return null;
|
|
27
|
+
const model = parseRequiredString({ value: requestBody.model });
|
|
28
|
+
if (!model)
|
|
29
|
+
return null;
|
|
30
|
+
const baseUrl = parseOptionalString({ value: requestBody.baseUrl });
|
|
31
|
+
const maxTokens = parseMaxTokens({ value: requestBody.maxTokens });
|
|
32
|
+
return {
|
|
33
|
+
protocol,
|
|
34
|
+
apiKey,
|
|
35
|
+
model,
|
|
36
|
+
...(baseUrl ? { baseUrl } : {}),
|
|
37
|
+
...(maxTokens !== undefined ? { maxTokens } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Trusts ONLY the credential sent on this one request: never reads a store, never writes anything.
|
|
42
|
+
* @complexity O(1).
|
|
43
|
+
*/
|
|
44
|
+
export function createRequestSuppliedExecutionCredentialPort(_options = {}) {
|
|
45
|
+
return {
|
|
46
|
+
async resolve({ requestBody }) {
|
|
47
|
+
return parseRequestSuppliedCredential(requestBody);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Request-supplied credential first; otherwise the host's stored row. A stored row whose protocol this
|
|
53
|
+
* package cannot dispatch, or with no model set (turns always need a model), is unusable.
|
|
54
|
+
* `readStored` must not throw for an undecryptable row: it returns `null`.
|
|
55
|
+
* @complexity O(1): at most one `readStored` call, only when the request supplied nothing usable.
|
|
56
|
+
*/
|
|
57
|
+
export function createStoredExecutionCredentialPort({ readStored }, _options = {}) {
|
|
58
|
+
return {
|
|
59
|
+
async resolve({ requestBody, workspaceId, principalId }) {
|
|
60
|
+
const requestSupplied = parseRequestSuppliedCredential(requestBody);
|
|
61
|
+
if (requestSupplied)
|
|
62
|
+
return requestSupplied;
|
|
63
|
+
const stored = await readStored({ workspaceId, principalId });
|
|
64
|
+
if (!stored)
|
|
65
|
+
return null;
|
|
66
|
+
if (!VALID_PROTOCOLS.has(stored.protocol))
|
|
67
|
+
return null;
|
|
68
|
+
if (!stored.model || stored.model.trim().length === 0)
|
|
69
|
+
return null;
|
|
70
|
+
return {
|
|
71
|
+
protocol: stored.protocol,
|
|
72
|
+
apiKey: stored.apiKey,
|
|
73
|
+
model: stored.model,
|
|
74
|
+
...(stored.baseUrl ? { baseUrl: stored.baseUrl } : {}),
|
|
75
|
+
...(stored.maxTokens !== null ? { maxTokens: stored.maxTokens } : {}),
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Clock, HttpClientPort } from '@jini-ai/core/primitives';
|
|
2
2
|
export interface ElevenLabsVoiceOption {
|
|
3
3
|
voiceId: string;
|
|
4
4
|
name: string;
|
|
@@ -31,6 +31,7 @@ export interface ElevenLabsVoiceListOptions {
|
|
|
31
31
|
}
|
|
32
32
|
/** Owns transport, time and a bounded voice cache for one host lifecycle.
|
|
33
33
|
* Supply the existing policy-enforcing HTTP client; this factory never constructs a raw transport.
|
|
34
|
+
* Hosts build one client with their clock and HttpClientPort, keep it for the process, and call clearCache() on shutdown.
|
|
34
35
|
* @throws RangeError for an invalid cache bound; credential/transport/JSON errors propagate from listing.
|
|
35
36
|
* @complexity O(c + v) per lookup, c <= maxCacheEntries and v <= the requested page size.
|
|
36
37
|
*/
|
|
@@ -42,9 +43,4 @@ export declare function createElevenLabsVoiceClient({ http, clock }: {
|
|
|
42
43
|
clearCache: () => void;
|
|
43
44
|
};
|
|
44
45
|
export type ElevenLabsVoiceClient = ReturnType<typeof createElevenLabsVoiceClient>;
|
|
45
|
-
/** Compatibility wrapper for existing callers. New hosts retain an injected client and clear it on shutdown. */
|
|
46
|
-
export declare function listElevenLabsVoiceOptions(required: ElevenLabsVoiceListRequired, options?: {
|
|
47
|
-
limit?: number;
|
|
48
|
-
requestInit?: Pick<RequestInit, 'dispatcher'>;
|
|
49
|
-
}): Promise<ElevenLabsVoiceOption[]>;
|
|
50
46
|
//# sourceMappingURL=elevenlabs.d.ts.map
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
* ElevenLabs wire API once it has a key.
|
|
17
17
|
*/
|
|
18
18
|
import { createHash } from 'node:crypto';
|
|
19
|
-
import {
|
|
20
|
-
import { FETCH_TIMEOUT_MS, fetchWithTimeout } from '@jini-ai/platform/fetch-with-timeout';
|
|
19
|
+
import { FETCH_TIMEOUT_MS } from '@jini-ai/core/net';
|
|
21
20
|
const ELEVENLABS_DEFAULT_BASE_URL = 'https://api.elevenlabs.io';
|
|
22
21
|
const ELEVENLABS_DEFAULT_VOICE_LIMIT = 100;
|
|
23
22
|
const ELEVENLABS_MAX_VOICE_LIMIT = 100;
|
|
@@ -92,6 +91,7 @@ function readVoiceCatalog({ payload }, _options = {}) {
|
|
|
92
91
|
}
|
|
93
92
|
/** Owns transport, time and a bounded voice cache for one host lifecycle.
|
|
94
93
|
* Supply the existing policy-enforcing HTTP client; this factory never constructs a raw transport.
|
|
94
|
+
* Hosts build one client with their clock and HttpClientPort, keep it for the process, and call clearCache() on shutdown.
|
|
95
95
|
* @throws RangeError for an invalid cache bound; credential/transport/JSON errors propagate from listing.
|
|
96
96
|
* @complexity O(c + v) per lookup, c <= maxCacheEntries and v <= the requested page size.
|
|
97
97
|
*/
|
|
@@ -147,33 +147,4 @@ export function createElevenLabsVoiceClient({ http, clock }, { maxCacheEntries =
|
|
|
147
147
|
}
|
|
148
148
|
return { listVoiceOptions, clearCache };
|
|
149
149
|
}
|
|
150
|
-
/** Native defaults stay in this compatibility assembly; injected clients use HttpClientPort directly. */
|
|
151
|
-
function createCompatibilityClient(requestInit = {}) {
|
|
152
|
-
return createElevenLabsVoiceClient({ clock: createSystemClock(), http: {
|
|
153
|
-
async send({ request }) {
|
|
154
|
-
const response = await fetchWithTimeout(request.url, {
|
|
155
|
-
...requestInit, method: request.method, headers: request.headers,
|
|
156
|
-
}, { timeoutMs: FETCH_TIMEOUT_MS.QUICK });
|
|
157
|
-
// Same reads as before the port: json() on success, text() for the error message.
|
|
158
|
-
return { status: response.status, headers: {},
|
|
159
|
-
bodyText: response.ok ? JSON.stringify(await response.json()) : await response.text() };
|
|
160
|
-
},
|
|
161
|
-
} });
|
|
162
|
-
}
|
|
163
|
-
const compatibilityClient = createCompatibilityClient();
|
|
164
|
-
const dispatcherClients = new WeakMap();
|
|
165
|
-
/** Compatibility wrapper for existing callers. New hosts retain an injected client and clear it on shutdown. */
|
|
166
|
-
export async function listElevenLabsVoiceOptions(required, options = {}) {
|
|
167
|
-
let client = compatibilityClient;
|
|
168
|
-
const dispatcher = options.requestInit?.dispatcher;
|
|
169
|
-
if (dispatcher && typeof dispatcher === 'object') {
|
|
170
|
-
let owned = dispatcherClients.get(dispatcher);
|
|
171
|
-
if (!owned) {
|
|
172
|
-
owned = createCompatibilityClient(options.requestInit);
|
|
173
|
-
dispatcherClients.set(dispatcher, owned);
|
|
174
|
-
}
|
|
175
|
-
client = owned;
|
|
176
|
-
}
|
|
177
|
-
return client.listVoiceOptions(required, options);
|
|
178
|
-
}
|
|
179
150
|
//# sourceMappingURL=elevenlabs.js.map
|
|
@@ -94,7 +94,8 @@
|
|
|
94
94
|
* tool-loop body and its test file's multi-tool-call image test).
|
|
95
95
|
*/
|
|
96
96
|
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
97
|
-
import { type
|
|
97
|
+
import { type PinnedFetch } from './connection-guard.js';
|
|
98
|
+
import { type DnsLookupFn } from '@jini-ai/core/contracts/agents';
|
|
98
99
|
import { type TurnEndReason } from './turn-end-guard.js';
|
|
99
100
|
import type { ProviderToolSnapshotOptions, ProviderSchemaFallback } from './provider-tool-policy.js';
|
|
100
101
|
export interface GoogleTextPart {
|
|
@@ -256,12 +257,12 @@ export declare function applyGoogleUsage({ state, data, onEvent }: {
|
|
|
256
257
|
state: GoogleStreamState;
|
|
257
258
|
data: Record<string, unknown>;
|
|
258
259
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
259
|
-
}): void;
|
|
260
|
+
}, _optional?: Record<string, never>): void;
|
|
260
261
|
/** Checks `data.promptFeedback` for a documented block reason and, if present, emits the `error` event for it (the caller emits `end` — see `processGoogleFrame`). Returns whether the frame loop should stop. */
|
|
261
262
|
export declare function handleGoogleBlockedPrompt({ data, onEvent }: {
|
|
262
263
|
data: Record<string, unknown>;
|
|
263
264
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
264
|
-
}): boolean;
|
|
265
|
+
}, _optional?: Record<string, never>): boolean;
|
|
265
266
|
/**
|
|
266
267
|
* Feeds one text part through the role-marker guard and emits the safe portion. Returns `'break'`
|
|
267
268
|
* once the guard flags contamination (the caller ends the turn immediately), otherwise
|
|
@@ -271,19 +272,19 @@ export declare function handleGoogleTextPart({ state, text, onEvent }: {
|
|
|
271
272
|
state: GoogleStreamState;
|
|
272
273
|
text: string;
|
|
273
274
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
274
|
-
}): 'continue' | 'break';
|
|
275
|
+
}, _optional?: Record<string, never>): 'continue' | 'break';
|
|
275
276
|
/** `rawPart.functionCall` must already be confirmed a record by the caller. Reads `thoughtSignature` off `rawPart` (a sibling of `functionCall`, not a member of it) — see `GoogleFunctionCallPart.thoughtSignature`'s doc for why only a non-empty string is carried. */
|
|
276
277
|
export declare function handleGoogleFunctionCallPart({ state, rawPart, onEvent }: {
|
|
277
278
|
state: GoogleStreamState;
|
|
278
279
|
rawPart: Record<string, unknown>;
|
|
279
280
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
280
|
-
}): void;
|
|
281
|
+
}, _optional?: Record<string, never>): void;
|
|
281
282
|
/** Dispatches one part between the text and function-call handlers above. Returns `'break'` once a text part contaminates the guard, else `'continue'`. */
|
|
282
283
|
export declare function processGoogleRawPart({ state, rawPart, onEvent }: {
|
|
283
284
|
state: GoogleStreamState;
|
|
284
285
|
rawPart: unknown;
|
|
285
286
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
286
|
-
}): 'continue' | 'break';
|
|
287
|
+
}, _optional?: Record<string, never>): 'continue' | 'break';
|
|
287
288
|
/** One frame's dispatch outcome — `'end'` carries the reason `runSingleGoogleRequest`'s loop passes to `emitEnd`, matching `anthropic-messages.ts#AnthropicFrameOutcome`'s identical split (the low-level handlers below only ever *report* why to stop; only the loop itself calls `emitEnd`, keeping that call in exactly one place). */
|
|
288
289
|
export type GoogleFrameOutcome = {
|
|
289
290
|
readonly action: 'continue';
|
|
@@ -302,7 +303,7 @@ export declare function processGoogleFrame({ state, data, onEvent }: {
|
|
|
302
303
|
state: GoogleStreamState;
|
|
303
304
|
data: Record<string, unknown>;
|
|
304
305
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
305
|
-
}): GoogleFrameOutcome;
|
|
306
|
+
}, _optional?: Record<string, never>): GoogleFrameOutcome;
|
|
306
307
|
/**
|
|
307
308
|
* Decides why the tool loop should stop after one request, or returns `null` when it should
|
|
308
309
|
* instead proceed to execute the pending tool calls. Pure — no events, no I/O — mirrors
|
|
@@ -315,12 +316,12 @@ export declare function googleLoopExitReason({ outcome, toolTurns, maxToolTurns
|
|
|
315
316
|
outcome: SingleRequestOutcome;
|
|
316
317
|
toolTurns: number;
|
|
317
318
|
maxToolTurns: number;
|
|
318
|
-
}): GoogleTurnEndReason | null;
|
|
319
|
+
}, _optional?: Record<string, never>): GoogleTurnEndReason | null;
|
|
319
320
|
/** Builds the `model`-role `Content`'s `parts` recording the pending tool calls — text (if any) followed by one `functionCall` part per call, each with its `thoughtSignature` spread back on as a sibling field, in the same shape the response delivered it and only when the response actually carried one (a `functionCall` part with no signature is legal; one with an empty-string signature is not). */
|
|
320
321
|
export declare function buildGoogleAssistantParts({ text, toolCalls }: {
|
|
321
322
|
text: string;
|
|
322
323
|
toolCalls: readonly GoogleToolCall[];
|
|
323
|
-
}): GooglePart[];
|
|
324
|
+
}, _optional?: Record<string, never>): GooglePart[];
|
|
324
325
|
export interface GoogleToolExecutionOutcome {
|
|
325
326
|
readonly functionResponseParts: GooglePart[];
|
|
326
327
|
readonly followUpParts: GooglePart[];
|
|
@@ -336,7 +337,7 @@ export declare function executeGoogleToolCalls({ executeTool, calls, onEvent }:
|
|
|
336
337
|
executeTool: GoogleToolExecutor;
|
|
337
338
|
calls: readonly GoogleToolCall[];
|
|
338
339
|
onEvent: (event: GoogleTurnEvent) => void;
|
|
339
|
-
}): Promise<GoogleToolExecutionOutcome>;
|
|
340
|
+
}, _optional?: Record<string, never>): Promise<GoogleToolExecutionOutcome>;
|
|
340
341
|
/**
|
|
341
342
|
* Runs a full Gemini `streamGenerateContent` turn, including the
|
|
342
343
|
* tool-execution loop when `options.executeTool` is supplied and the model
|
|
@@ -94,12 +94,15 @@ import { redactSecrets } from '@jini-ai/core';
|
|
|
94
94
|
* matching this module's existing single-continuation-turn shape (see `runGoogleToolTurn`'s
|
|
95
95
|
* tool-loop body and its test file's multi-tool-call image test).
|
|
96
96
|
*/
|
|
97
|
-
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
97
|
+
import { createRoleMarkerGuard, emitGuardedTextDelta } from '../role-marker-guard.js';
|
|
98
|
+
import { extractProviderErrorDetail } from './response-text.js';
|
|
98
99
|
import { defaultDnsLookup, pinnedFetch, validateBaseUrlResolved } from './connection-guard.js';
|
|
100
|
+
import {} from '@jini-ai/core/contracts/agents';
|
|
99
101
|
import { googleStreamGenerateContentUrl } from './google.js';
|
|
100
102
|
import { decodeSseStream } from './sse-decode.js';
|
|
101
103
|
import { createTurnEndGuard } from './turn-end-guard.js';
|
|
102
104
|
import { createStrictToolRetry } from './openai-chat.js';
|
|
105
|
+
import {} from './openai-chat-types.js';
|
|
103
106
|
import { toolLoopVerdict } from './tool-loop-verdict.js';
|
|
104
107
|
const DEFAULT_GOOGLE_BASE_URL = 'https://generativelanguage.googleapis.com';
|
|
105
108
|
const DEFAULT_MAX_TOOL_TURNS = 8;
|
|
@@ -145,20 +148,8 @@ function googleRequestBody(options, contents, { validated = false } = {}) {
|
|
|
145
148
|
...(Object.keys(generationConfig).length > 0 ? { generationConfig } : {}),
|
|
146
149
|
};
|
|
147
150
|
}
|
|
148
|
-
function extractGoogleErrorDetail(rawText) {
|
|
149
|
-
try {
|
|
150
|
-
const parsed = JSON.parse(rawText);
|
|
151
|
-
if (isRecord(parsed) && isRecord(parsed.error) && typeof parsed.error.message === 'string') {
|
|
152
|
-
return parsed.error.message;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
// Non-JSON error body — fall through to the raw text below.
|
|
157
|
-
}
|
|
158
|
-
return rawText.trim().slice(0, 500);
|
|
159
|
-
}
|
|
160
151
|
/** Adds the shared `input_tokens`/`output_tokens` fields (the only ones the chat usage reducers read) to raw Gemini `usageMetadata` and emits usage. */
|
|
161
|
-
export function applyGoogleUsage({ state, data, onEvent }) {
|
|
152
|
+
export function applyGoogleUsage({ state, data, onEvent }, _optional = {}) {
|
|
162
153
|
if (!isRecord(data.usageMetadata))
|
|
163
154
|
return;
|
|
164
155
|
const usage = data.usageMetadata;
|
|
@@ -179,7 +170,7 @@ function firstGoogleCandidate(data) {
|
|
|
179
170
|
return candidates[0];
|
|
180
171
|
}
|
|
181
172
|
/** Checks `data.promptFeedback` for a documented block reason and, if present, emits the `error` event for it (the caller emits `end` — see `processGoogleFrame`). Returns whether the frame loop should stop. */
|
|
182
|
-
export function handleGoogleBlockedPrompt({ data, onEvent }) {
|
|
173
|
+
export function handleGoogleBlockedPrompt({ data, onEvent }, _optional = {}) {
|
|
183
174
|
if (!isRecord(data.promptFeedback) || typeof data.promptFeedback.blockReason !== 'string')
|
|
184
175
|
return false;
|
|
185
176
|
onEvent({ type: 'error', message: `prompt blocked: ${data.promptFeedback.blockReason}`, code: data.promptFeedback.blockReason });
|
|
@@ -194,21 +185,11 @@ function googleCandidateParts(candidate) {
|
|
|
194
185
|
* once the guard flags contamination (the caller ends the turn immediately), otherwise
|
|
195
186
|
* `'continue'` — same contract as `anthropic-messages.ts#handleAnthropicTextDelta`.
|
|
196
187
|
*/
|
|
197
|
-
export function handleGoogleTextPart({ state, text, onEvent }) {
|
|
198
|
-
|
|
199
|
-
if (safe.length > 0) {
|
|
200
|
-
state.fullText += safe;
|
|
201
|
-
onEvent({ type: 'text_delta', delta: safe });
|
|
202
|
-
}
|
|
203
|
-
if (!state.guard.contaminated)
|
|
204
|
-
return 'continue';
|
|
205
|
-
const warn = state.guard.warningEvent();
|
|
206
|
-
if (warn)
|
|
207
|
-
onEvent(warn);
|
|
208
|
-
return 'break';
|
|
188
|
+
export function handleGoogleTextPart({ state, text, onEvent }, _optional = {}) {
|
|
189
|
+
return emitGuardedTextDelta({ state, text: text, onEvent });
|
|
209
190
|
}
|
|
210
191
|
/** `rawPart.functionCall` must already be confirmed a record by the caller. Reads `thoughtSignature` off `rawPart` (a sibling of `functionCall`, not a member of it) — see `GoogleFunctionCallPart.thoughtSignature`'s doc for why only a non-empty string is carried. */
|
|
211
|
-
export function handleGoogleFunctionCallPart({ state, rawPart, onEvent }) {
|
|
192
|
+
export function handleGoogleFunctionCallPart({ state, rawPart, onEvent }, _optional = {}) {
|
|
212
193
|
const fc = rawPart.functionCall;
|
|
213
194
|
const name = typeof fc.name === 'string' ? fc.name : null;
|
|
214
195
|
if (!name)
|
|
@@ -220,7 +201,7 @@ export function handleGoogleFunctionCallPart({ state, rawPart, onEvent }) {
|
|
|
220
201
|
onEvent({ type: 'tool_use', id: call.id, name: call.name, input: call.input });
|
|
221
202
|
}
|
|
222
203
|
/** Dispatches one part between the text and function-call handlers above. Returns `'break'` once a text part contaminates the guard, else `'continue'`. */
|
|
223
|
-
export function processGoogleRawPart({ state, rawPart, onEvent }) {
|
|
204
|
+
export function processGoogleRawPart({ state, rawPart, onEvent }, _optional = {}) {
|
|
224
205
|
if (!isRecord(rawPart))
|
|
225
206
|
return 'continue';
|
|
226
207
|
if (typeof rawPart.text === 'string' && rawPart.text.length > 0) {
|
|
@@ -246,7 +227,7 @@ function processGoogleParts(state, parts, onEvent) {
|
|
|
246
227
|
* nesting-penalized top-level `if`s into one function call plus one outcome check — see
|
|
247
228
|
* `runSingleGoogleRequest`'s loop below.
|
|
248
229
|
*/
|
|
249
|
-
export function processGoogleFrame({ state, data, onEvent }) {
|
|
230
|
+
export function processGoogleFrame({ state, data, onEvent }, _optional = {}) {
|
|
250
231
|
applyGoogleUsage({ state: state, data: data, onEvent: onEvent });
|
|
251
232
|
const rawCandidate = firstGoogleCandidate(data);
|
|
252
233
|
if (!rawCandidate) {
|
|
@@ -278,7 +259,7 @@ async function resolveGoogleResponse({ response, options, contents, emitEnd, ret
|
|
|
278
259
|
}
|
|
279
260
|
onEvent({
|
|
280
261
|
type: 'error',
|
|
281
|
-
message: redactSecrets({ input:
|
|
262
|
+
message: redactSecrets({ input: extractProviderErrorDetail({ rawText }) }, { exactSecrets: [options.apiKey] }),
|
|
282
263
|
code: String(response.status),
|
|
283
264
|
});
|
|
284
265
|
emitEnd('error');
|
|
@@ -450,7 +431,7 @@ function splitGoogleToolResultContent(content) {
|
|
|
450
431
|
* `finishReason` comparison (see module doc, point 2, for why Gemini's `finishReason` enum cannot
|
|
451
432
|
* be used here).
|
|
452
433
|
*/
|
|
453
|
-
export function googleLoopExitReason({ outcome, toolTurns, maxToolTurns }) {
|
|
434
|
+
export function googleLoopExitReason({ outcome, toolTurns, maxToolTurns }, _optional = {}) {
|
|
454
435
|
if (outcome.toolCalls.length === 0)
|
|
455
436
|
return 'stop';
|
|
456
437
|
if (toolTurns >= maxToolTurns)
|
|
@@ -458,7 +439,7 @@ export function googleLoopExitReason({ outcome, toolTurns, maxToolTurns }) {
|
|
|
458
439
|
return null;
|
|
459
440
|
}
|
|
460
441
|
/** Builds the `model`-role `Content`'s `parts` recording the pending tool calls — text (if any) followed by one `functionCall` part per call, each with its `thoughtSignature` spread back on as a sibling field, in the same shape the response delivered it and only when the response actually carried one (a `functionCall` part with no signature is legal; one with an empty-string signature is not). */
|
|
461
|
-
export function buildGoogleAssistantParts({ text, toolCalls }) {
|
|
442
|
+
export function buildGoogleAssistantParts({ text, toolCalls }, _optional = {}) {
|
|
462
443
|
return [
|
|
463
444
|
...(text ? [{ text }] : []),
|
|
464
445
|
...toolCalls.map((call) => ({
|
|
@@ -474,7 +455,7 @@ export function buildGoogleAssistantParts({ text, toolCalls }) {
|
|
|
474
455
|
* functionResponse" section for why images travel this way instead of a separate follow-up
|
|
475
456
|
* message (unlike `openai-chat.ts`/`azure-chat.ts`).
|
|
476
457
|
*/
|
|
477
|
-
export async function executeGoogleToolCalls({ executeTool, calls, onEvent }) {
|
|
458
|
+
export async function executeGoogleToolCalls({ executeTool, calls, onEvent }, _optional = {}) {
|
|
478
459
|
const functionResponseParts = [];
|
|
479
460
|
const followUpParts = [];
|
|
480
461
|
for (const call of calls) {
|
|
@@ -518,7 +499,7 @@ export async function runGoogleToolTurn(requiredArgs, optionalArgs = {}) {
|
|
|
518
499
|
const retry = createStrictToolRetry({ protocol: 'google', onSchemaFallback: options.onSchemaFallback });
|
|
519
500
|
const maxToolTurns = options.maxToolTurns ?? DEFAULT_MAX_TOOL_TURNS;
|
|
520
501
|
const executeTool = options.executeTool;
|
|
521
|
-
const endGuard = createTurnEndGuard(options.onEvent, (reason) => ({ type: 'end', reason }));
|
|
502
|
+
const endGuard = createTurnEndGuard({ onEvent: options.onEvent, makeEndEvent: (reason) => ({ type: 'end', reason }) });
|
|
522
503
|
const emitEnd = endGuard.emitEnd;
|
|
523
504
|
let contents = options.contents.slice();
|
|
524
505
|
let toolTurns = 0;
|
|
@@ -22,5 +22,5 @@ export declare function findNumericEnumPaths({ schema }: {
|
|
|
22
22
|
export declare function coerceNumericEnumStringsToNumbers({ input, paths }: {
|
|
23
23
|
input: unknown;
|
|
24
24
|
paths: readonly string[];
|
|
25
|
-
}): unknown;
|
|
25
|
+
}, _optional?: Record<string, never>): unknown;
|
|
26
26
|
//# sourceMappingURL=google-schema.d.ts.map
|
|
@@ -259,7 +259,7 @@ export function findNumericEnumPaths({ schema }, { prefix = [] } = {}) {
|
|
|
259
259
|
return findNumericEnumPathsValue(schema, prefix);
|
|
260
260
|
}
|
|
261
261
|
/** Reverses Gemini's numeric enum stringification without mutating the incoming tool argument. Paths use dot-separated property names. */
|
|
262
|
-
export function coerceNumericEnumStringsToNumbers({ input, paths }) {
|
|
262
|
+
export function coerceNumericEnumStringsToNumbers({ input, paths }, _optional = {}) {
|
|
263
263
|
return coerceNumericEnumStringsToNumbersValue(input, paths);
|
|
264
264
|
}
|
|
265
265
|
//# sourceMappingURL=google-schema.js.map
|
|
@@ -8,28 +8,28 @@
|
|
|
8
8
|
/** Strips any trailing `/v1`/`/v1beta` API-version segment and trailing slashes from a configured base URL. */
|
|
9
9
|
export declare function googleGenerativeLanguageBaseUrl({ baseUrl }: {
|
|
10
10
|
baseUrl: string;
|
|
11
|
-
}): string;
|
|
11
|
+
}, _optional?: Record<string, never>): string;
|
|
12
12
|
/** Strips the `models/` prefix Google's API sometimes includes in a model id. */
|
|
13
13
|
export declare function normalizeGoogleModelId({ model }: {
|
|
14
14
|
model: string;
|
|
15
|
-
}): string;
|
|
15
|
+
}, _optional?: Record<string, never>): string;
|
|
16
16
|
/** URL-encodes a normalized model id for use as a path segment. */
|
|
17
17
|
export declare function googleModelPathSegment({ model }: {
|
|
18
18
|
model: string;
|
|
19
|
-
}): string;
|
|
19
|
+
}, _optional?: Record<string, never>): string;
|
|
20
20
|
/** Builds the non-streaming `generateContent` endpoint URL for a model. */
|
|
21
21
|
export declare function googleGenerateContentUrl({ baseUrl, model }: {
|
|
22
22
|
baseUrl: string;
|
|
23
23
|
model: string;
|
|
24
|
-
}): string;
|
|
24
|
+
}, _optional?: Record<string, never>): string;
|
|
25
25
|
/** Builds the SSE-streaming `streamGenerateContent` endpoint URL for a model. */
|
|
26
26
|
export declare function googleStreamGenerateContentUrl({ baseUrl, model }: {
|
|
27
27
|
baseUrl: string;
|
|
28
28
|
model: string;
|
|
29
|
-
}): string;
|
|
29
|
+
}, _optional?: Record<string, never>): string;
|
|
30
30
|
/** Builds the model-catalog listing endpoint URL, with the API key attached as a query param. */
|
|
31
31
|
export declare function googleProviderModelsUrl({ baseUrl, apiKey }: {
|
|
32
32
|
baseUrl: string;
|
|
33
33
|
apiKey: string;
|
|
34
|
-
}): string;
|
|
34
|
+
}, _optional?: Record<string, never>): string;
|
|
35
35
|
//# sourceMappingURL=google.d.ts.map
|
package/dist/providers/google.js
CHANGED
|
@@ -7,7 +7,7 @@ import { trimCharsEnd } from '@jini-ai/core/text';
|
|
|
7
7
|
* verbatim.
|
|
8
8
|
*/
|
|
9
9
|
/** Strips any trailing `/v1`/`/v1beta` API-version segment and trailing slashes from a configured base URL. */
|
|
10
|
-
export function googleGenerativeLanguageBaseUrl({ baseUrl }) {
|
|
10
|
+
export function googleGenerativeLanguageBaseUrl({ baseUrl }, _optional = {}) {
|
|
11
11
|
const url = new URL(baseUrl);
|
|
12
12
|
url.search = '';
|
|
13
13
|
url.hash = '';
|
|
@@ -16,24 +16,24 @@ export function googleGenerativeLanguageBaseUrl({ baseUrl }) {
|
|
|
16
16
|
return trimCharsEnd({ text: url.toString(), chars: '/' });
|
|
17
17
|
}
|
|
18
18
|
/** Strips the `models/` prefix Google's API sometimes includes in a model id. */
|
|
19
|
-
export function normalizeGoogleModelId({ model }) {
|
|
19
|
+
export function normalizeGoogleModelId({ model }, _optional = {}) {
|
|
20
20
|
const trimmed = model.trim();
|
|
21
21
|
return trimmed.startsWith('models/') ? trimmed.slice('models/'.length) : trimmed;
|
|
22
22
|
}
|
|
23
23
|
/** URL-encodes a normalized model id for use as a path segment. */
|
|
24
|
-
export function googleModelPathSegment({ model }) {
|
|
24
|
+
export function googleModelPathSegment({ model }, _optional = {}) {
|
|
25
25
|
return encodeURIComponent(normalizeGoogleModelId({ model: model }));
|
|
26
26
|
}
|
|
27
27
|
/** Builds the non-streaming `generateContent` endpoint URL for a model. */
|
|
28
|
-
export function googleGenerateContentUrl({ baseUrl, model }) {
|
|
28
|
+
export function googleGenerateContentUrl({ baseUrl, model }, _optional = {}) {
|
|
29
29
|
return `${googleGenerativeLanguageBaseUrl({ baseUrl: baseUrl })}/v1beta/models/${googleModelPathSegment({ model: model })}:generateContent`;
|
|
30
30
|
}
|
|
31
31
|
/** Builds the SSE-streaming `streamGenerateContent` endpoint URL for a model. */
|
|
32
|
-
export function googleStreamGenerateContentUrl({ baseUrl, model }) {
|
|
32
|
+
export function googleStreamGenerateContentUrl({ baseUrl, model }, _optional = {}) {
|
|
33
33
|
return `${googleGenerativeLanguageBaseUrl({ baseUrl: baseUrl })}/v1beta/models/${googleModelPathSegment({ model: model })}:streamGenerateContent?alt=sse`;
|
|
34
34
|
}
|
|
35
35
|
/** Builds the model-catalog listing endpoint URL, with the API key attached as a query param. */
|
|
36
|
-
export function googleProviderModelsUrl({ baseUrl, apiKey }) {
|
|
36
|
+
export function googleProviderModelsUrl({ baseUrl, apiKey }, _optional = {}) {
|
|
37
37
|
const url = new URL(`${googleGenerativeLanguageBaseUrl({ baseUrl: baseUrl })}/v1beta/models`);
|
|
38
38
|
url.searchParams.set('key', apiKey);
|
|
39
39
|
return url.toString();
|