@jsonstudio/llms 0.6.2172 → 0.6.3214
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/README.md +2 -0
- package/dist/conversion/args-mapping.js +8 -0
- package/dist/conversion/bridge-actions.js +367 -0
- package/dist/conversion/bridge-id-utils.js +13 -0
- package/dist/conversion/{shared/bridge-instructions.js → bridge-instructions.js} +2 -1
- package/dist/conversion/{shared/bridge-message-utils.d.ts → bridge-message-utils.d.ts} +1 -1
- package/dist/conversion/{shared/bridge-message-utils.js → bridge-message-utils.js} +5 -150
- package/dist/conversion/{shared/bridge-metadata.d.ts → bridge-metadata.d.ts} +1 -0
- package/dist/conversion/bridge-metadata.js +5 -0
- package/dist/conversion/bridge-policies.js +11 -0
- package/dist/conversion/codecs/gemini-openai-codec.js +27 -8
- package/dist/conversion/codecs/responses-openai-codec.js +1 -1
- package/dist/conversion/{shared/compaction-detect.d.ts → compaction-detect.d.ts} +1 -1
- package/dist/conversion/compaction-detect.js +4 -0
- package/dist/conversion/compat/actions/apply-patch-fixer.js +2 -2
- package/dist/conversion/compat/actions/deepseek-web-response.d.ts +0 -1
- package/dist/conversion/compat/actions/deepseek-web-response.js +15 -405
- package/dist/conversion/compat/actions/harvest-tool-calls-from-text.js +1 -1
- package/dist/conversion/compat/actions/lmstudio-responses-fc-ids.js +1 -1
- package/dist/conversion/compat/actions/qwen-transform.js +74 -2
- package/dist/conversion/compat/actions/snapshot.js +1 -1
- package/dist/conversion/compat/antigravity-session-signature.js +71 -1
- package/dist/conversion/compat/profiles/chat-deepseek-web.json +0 -22
- package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
- package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
- package/dist/conversion/compat/profiles/chat-glm.json +251 -72
- package/dist/conversion/compat/profiles/chat-iflow.json +174 -39
- package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -14
- package/dist/conversion/hub/core/detour-registry.d.ts +2 -0
- package/dist/conversion/hub/core/hub-context.d.ts +3 -1
- package/dist/conversion/hub/core/index.d.ts +1 -0
- package/dist/conversion/hub/core/stage-driver.js +2 -0
- package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +15 -4
- package/dist/conversion/hub/format-adapters/chat-format-adapter.js +15 -4
- package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +15 -4
- package/dist/conversion/hub/format-adapters/responses-format-adapter.js +15 -4
- package/dist/conversion/hub/hub-feature.js +3 -2
- package/dist/conversion/hub/node-support.js +9 -4
- package/dist/conversion/hub/operation-table/operation-table-runner.js +12 -8
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +3 -3
- package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +16 -13
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +6 -10
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +21 -73
- package/dist/conversion/hub/ops/operations.js +2 -121
- package/dist/conversion/hub/pipeline/compat/compat-engine.js +6 -0
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +1 -1
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +33 -1042
- package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +2 -0
- package/dist/conversion/hub/pipeline/compat/compat-profile-store.js +2 -0
- package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +14 -17
- package/dist/conversion/hub/pipeline/compat/native-adapter-context.d.ts +3 -0
- package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +39 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +1 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.js +165 -265
- package/dist/conversion/hub/pipeline/session-identifiers.js +6 -196
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +1 -2
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +69 -81
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.d.ts +14 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.js +24 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.d.ts +2 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.js +157 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +16 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +29 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +3 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.d.ts +2 -15
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +8 -595
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +8 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +28 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.d.ts +2 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.js +4 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.d.ts +10 -0
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.js +12 -0
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +3 -0
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +30 -0
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +9 -129
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.d.ts +1 -4
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.js +9 -26
- package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +32 -14
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +2 -2
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +48 -8
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +20 -3
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +11 -199
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.d.ts +3 -0
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.js +81 -0
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.d.ts +1 -2
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js +36 -1
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js +3 -1
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.d.ts +6 -0
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.js +17 -0
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.d.ts +9 -0
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.js +28 -0
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.d.ts +1 -2
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +14 -102
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js +3 -1
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +54 -39
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +18 -5
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.d.ts +11 -1
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.js +10 -32
- package/dist/conversion/hub/pipeline/stages/utils.js +17 -1
- package/dist/conversion/hub/pipeline/target-utils.js +14 -91
- package/dist/conversion/hub/pipelines/inbound.js +3 -1
- package/dist/conversion/hub/pipelines/outbound.js +2 -0
- package/dist/conversion/hub/policy/policy-engine.js +9 -3
- package/dist/conversion/hub/policy/protocol-spec.js +21 -149
- package/dist/conversion/hub/process/chat-process-anthropic-alias.d.ts +2 -0
- package/dist/conversion/hub/process/chat-process-anthropic-alias.js +36 -0
- package/dist/conversion/hub/process/chat-process-clock-directive-parser.d.ts +5 -0
- package/dist/conversion/hub/process/chat-process-clock-directive-parser.js +48 -0
- package/dist/conversion/hub/process/chat-process-clock-directives.d.ts +24 -0
- package/dist/conversion/hub/process/chat-process-clock-directives.js +98 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-directives.d.ts +8 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-directives.js +42 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.d.ts +14 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.js +10 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-messages.d.ts +5 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-messages.js +10 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.d.ts +30 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.js +68 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.d.ts +9 -0
- package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.js +18 -0
- package/dist/conversion/hub/process/chat-process-clock-reminders.d.ts +2 -0
- package/dist/conversion/hub/process/chat-process-clock-reminders.js +104 -0
- package/dist/conversion/hub/process/chat-process-clock-tool-schemas.d.ts +3 -0
- package/dist/conversion/hub/process/chat-process-clock-tool-schemas.js +233 -0
- package/dist/conversion/hub/process/chat-process-clock-tools.d.ts +6 -0
- package/dist/conversion/hub/process/chat-process-clock-tools.js +41 -0
- package/dist/conversion/hub/process/chat-process-continue-execution.d.ts +11 -0
- package/dist/conversion/hub/process/chat-process-continue-execution.js +82 -0
- package/dist/conversion/hub/process/chat-process-governance-context.d.ts +15 -0
- package/dist/conversion/hub/process/chat-process-governance-context.js +7 -0
- package/dist/conversion/hub/process/chat-process-governance-finalize.d.ts +16 -0
- package/dist/conversion/hub/process/chat-process-governance-finalize.js +11 -0
- package/dist/conversion/hub/process/chat-process-governance-orchestration.d.ts +9 -0
- package/dist/conversion/hub/process/chat-process-governance-orchestration.js +47 -0
- package/dist/conversion/hub/process/chat-process-governed-control-ops.d.ts +8 -0
- package/dist/conversion/hub/process/chat-process-governed-control-ops.js +5 -0
- package/dist/conversion/hub/process/chat-process-governed-filter-call.d.ts +12 -0
- package/dist/conversion/hub/process/chat-process-governed-filter-call.js +18 -0
- package/dist/conversion/hub/process/chat-process-governed-merge.d.ts +8 -0
- package/dist/conversion/hub/process/chat-process-governed-merge.js +11 -0
- package/dist/conversion/hub/process/chat-process-media.d.ts +3 -0
- package/dist/conversion/hub/process/chat-process-media.js +18 -0
- package/dist/conversion/hub/process/chat-process-node-result.d.ts +23 -0
- package/dist/conversion/hub/process/chat-process-node-result.js +24 -0
- package/dist/conversion/hub/process/chat-process-pending-tool-sync.d.ts +14 -0
- package/dist/conversion/hub/process/chat-process-pending-tool-sync.js +52 -0
- package/dist/conversion/hub/process/chat-process-post-governed-normalization.d.ts +8 -0
- package/dist/conversion/hub/process/chat-process-post-governed-normalization.js +16 -0
- package/dist/conversion/hub/process/chat-process-review.d.ts +2 -0
- package/dist/conversion/hub/process/chat-process-review.js +8 -0
- package/dist/conversion/hub/process/chat-process-servertool-orchestration.d.ts +8 -0
- package/dist/conversion/hub/process/chat-process-servertool-orchestration.js +22 -0
- package/dist/conversion/hub/process/chat-process-tool-normalization.d.ts +2 -0
- package/dist/conversion/hub/process/chat-process-tool-normalization.js +4 -0
- package/dist/conversion/hub/process/chat-process-web-search-intent.d.ts +12 -0
- package/dist/conversion/hub/process/chat-process-web-search-intent.js +13 -0
- package/dist/conversion/hub/process/chat-process-web-search-tool-schema.d.ts +3 -0
- package/dist/conversion/hub/process/chat-process-web-search-tool-schema.js +4 -0
- package/dist/conversion/hub/process/chat-process-web-search.d.ts +8 -0
- package/dist/conversion/hub/process/chat-process-web-search.js +26 -0
- package/dist/conversion/hub/process/chat-process.d.ts +2 -19
- package/dist/conversion/hub/process/chat-process.js +12 -1701
- package/dist/conversion/hub/process/client-inject-readiness.d.ts +1 -0
- package/dist/conversion/hub/process/client-inject-readiness.js +4 -0
- package/dist/conversion/hub/registry.js +5 -2
- package/dist/conversion/hub/response/chat-response-utils.js +5 -86
- package/dist/conversion/hub/response/provider-response.d.ts +9 -0
- package/dist/conversion/hub/response/provider-response.js +20 -26
- package/dist/conversion/hub/response/response-mappers.js +25 -27
- package/dist/conversion/hub/response/response-runtime.js +30 -98
- package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +1 -0
- package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +1 -0
- package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +1 -0
- package/dist/conversion/hub/semantic-mappers/chat-mapper.js +1 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +1 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +1 -0
- package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +1 -0
- package/dist/conversion/hub/semantic-mappers/responses-mapper.js +1 -0
- package/dist/conversion/hub/snapshot-recorder.js +11 -4
- package/dist/conversion/hub/standardized-bridge.js +11 -288
- package/dist/conversion/hub/tool-governance/engine.d.ts +8 -0
- package/dist/conversion/hub/tool-governance/engine.js +25 -63
- package/dist/conversion/hub/tool-governance/rules.js +73 -69
- package/dist/conversion/hub/tool-session-compat.d.ts +2 -2
- package/dist/conversion/hub/tool-session-compat.js +17 -231
- package/dist/conversion/hub/tool-surface/tool-surface-engine.js +6 -4
- package/dist/conversion/index.d.ts +1 -2
- package/dist/conversion/index.js +1 -2
- package/dist/conversion/jsonish.js +20 -0
- package/dist/conversion/mcp-injection.js +7 -0
- package/dist/conversion/media.js +4 -0
- package/dist/conversion/{shared/metadata-passthrough.d.ts → metadata-passthrough.d.ts} +1 -1
- package/dist/conversion/metadata-passthrough.js +20 -0
- package/dist/conversion/payload-budget.js +47 -0
- package/dist/conversion/protocol-field-allowlists.d.ts +7 -0
- package/dist/conversion/protocol-field-allowlists.js +9 -0
- package/dist/conversion/{shared/protocol-state.d.ts → protocol-state.d.ts} +2 -2
- package/dist/conversion/protocol-state.js +27 -0
- package/dist/conversion/{shared/errors.d.ts → provider-protocol-error.d.ts} +0 -3
- package/dist/conversion/provider-protocol-error.js +25 -0
- package/dist/conversion/responses/responses-host-policy.js +2 -12
- package/dist/conversion/responses/responses-openai-bridge/response-payload.js +14 -87
- package/dist/conversion/responses/responses-openai-bridge/types.d.ts +2 -1
- package/dist/conversion/responses/responses-openai-bridge.d.ts +1 -1
- package/dist/conversion/responses/responses-openai-bridge.js +62 -62
- package/dist/conversion/{shared/runtime-metadata.d.ts → runtime-metadata.d.ts} +1 -1
- package/dist/conversion/runtime-metadata.js +31 -0
- package/dist/conversion/shared/anthropic-message-utils.js +170 -21
- package/dist/conversion/shared/chat-envelope-validator.js +2 -126
- package/dist/conversion/shared/chat-output-normalizer.js +2 -54
- package/dist/conversion/shared/chat-request-filters.d.ts +3 -4
- package/dist/conversion/shared/chat-request-filters.js +22 -78
- package/dist/conversion/shared/gemini-tool-utils.d.ts +1 -1
- package/dist/conversion/shared/gemini-tool-utils.js +9 -524
- package/dist/conversion/shared/openai-finalizer.js +3 -1
- package/dist/conversion/shared/openai-message-normalize.js +13 -285
- package/dist/conversion/shared/output-content-normalizer.js +9 -112
- package/dist/conversion/shared/reasoning-mapping.js +2 -6
- package/dist/conversion/shared/reasoning-normalizer.js +10 -1
- package/dist/conversion/shared/reasoning-tool-normalizer.js +14 -126
- package/dist/conversion/shared/reasoning-tool-parser.js +4 -87
- package/dist/conversion/shared/reasoning-utils.js +7 -8
- package/dist/conversion/shared/responses-conversation-store.js +5 -83
- package/dist/conversion/shared/responses-output-builder.js +63 -55
- package/dist/conversion/shared/responses-reasoning-registry.d.ts +14 -2
- package/dist/conversion/shared/responses-reasoning-registry.js +41 -7
- package/dist/conversion/shared/responses-request-adapter.d.ts +7 -1
- package/dist/conversion/shared/responses-request-adapter.js +14 -1
- package/dist/conversion/shared/responses-response-utils.js +103 -14
- package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
- package/dist/conversion/shared/responses-tool-utils.js +91 -15
- package/dist/conversion/shared/streaming-text-extractor.js +2 -7
- package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +2 -2
- package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
- package/dist/conversion/shared/text-markup-normalizer.d.ts +3 -2
- package/dist/conversion/shared/text-markup-normalizer.js +2 -1
- package/dist/conversion/shared/thought-signature-validator.js +3 -2
- package/dist/conversion/shared/tool-argument-repairer.js +2 -2
- package/dist/conversion/shared/tool-call-id-manager.js +5 -7
- package/dist/conversion/shared/tool-call-utils.js +3 -45
- package/dist/conversion/shared/tool-filter-pipeline.js +5 -100
- package/dist/conversion/shared/tool-governor.d.ts +6 -0
- package/dist/conversion/shared/tool-governor.js +45 -127
- package/dist/conversion/shared/tool-harvester.js +2 -8
- package/dist/conversion/shared/tool-mapping.d.ts +1 -1
- package/dist/conversion/shared/tool-mapping.js +2 -5
- package/dist/conversion/shared/tooling.d.ts +0 -4
- package/dist/conversion/shared/tooling.js +18 -0
- package/dist/conversion/{shared/snapshot-utils.d.ts → snapshot-utils.d.ts} +11 -0
- package/dist/conversion/{shared/snapshot-utils.js → snapshot-utils.js} +14 -23
- package/dist/conversion/{shared → types}/bridge-message-types.d.ts +2 -0
- package/dist/conversion/types/text-markup-normalizer.d.ts +13 -0
- package/dist/filters/special/request-tools-normalize.js +1 -1
- package/dist/filters/special/response-tool-text-canonicalize.js +2 -2
- package/dist/native/router_hotpath_napi.node +0 -0
- package/dist/quota/quota-manager.js +31 -59
- package/dist/quota/quota-state.js +14 -7
- package/dist/router/virtual-router/bootstrap/profile-builder.d.ts +1 -0
- package/dist/router/virtual-router/bootstrap/profile-builder.js +13 -0
- package/dist/router/virtual-router/bootstrap/provider-normalization.d.ts +2 -0
- package/dist/router/virtual-router/bootstrap/provider-normalization.js +4 -1
- package/dist/router/virtual-router/bootstrap/streaming-helpers.d.ts +7 -0
- package/dist/router/virtual-router/bootstrap/streaming-helpers.js +44 -0
- package/dist/router/virtual-router/bootstrap.js +2 -0
- package/dist/router/virtual-router/engine/provider-key/parse.d.ts +1 -6
- package/dist/router/virtual-router/engine/provider-key/parse.js +1 -43
- package/dist/router/virtual-router/engine/routing-state/store.d.ts +1 -2
- package/dist/router/virtual-router/engine/routing-state/store.js +50 -14
- package/dist/router/virtual-router/engine-legacy/config.d.ts +11 -0
- package/dist/router/virtual-router/engine-legacy/config.js +108 -0
- package/dist/router/virtual-router/engine-legacy/direct-model.d.ts +10 -0
- package/dist/router/virtual-router/engine-legacy/direct-model.js +38 -0
- package/dist/router/virtual-router/engine-legacy/health.d.ts +13 -0
- package/dist/router/virtual-router/engine-legacy/health.js +104 -0
- package/dist/router/virtual-router/engine-legacy/helpers.d.ts +16 -0
- package/dist/router/virtual-router/engine-legacy/helpers.js +226 -0
- package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +9 -0
- package/dist/router/virtual-router/engine-legacy/route-finalize.js +84 -0
- package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +17 -0
- package/dist/router/virtual-router/engine-legacy/route-selection.js +205 -0
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +3 -0
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +36 -0
- package/dist/router/virtual-router/engine-legacy/route-state.d.ts +12 -0
- package/dist/router/virtual-router/engine-legacy/route-state.js +386 -0
- package/dist/router/virtual-router/engine-legacy/route-utils.d.ts +19 -0
- package/dist/router/virtual-router/engine-legacy/route-utils.js +212 -0
- package/dist/router/virtual-router/engine-legacy/routing.d.ts +8 -0
- package/dist/router/virtual-router/engine-legacy/routing.js +8 -0
- package/dist/router/virtual-router/engine-legacy/selection-core.d.ts +28 -0
- package/dist/router/virtual-router/engine-legacy/selection-core.js +112 -0
- package/dist/router/virtual-router/engine-legacy/selection-state.d.ts +16 -0
- package/dist/router/virtual-router/engine-legacy/selection-state.js +187 -0
- package/dist/router/virtual-router/engine-legacy/state-accessors.d.ts +21 -0
- package/dist/router/virtual-router/engine-legacy/state-accessors.js +118 -0
- package/dist/router/virtual-router/engine-legacy.d.ts +123 -0
- package/dist/router/virtual-router/engine-legacy.js +194 -0
- package/dist/router/virtual-router/engine-logging.d.ts +2 -0
- package/dist/router/virtual-router/engine-logging.js +11 -5
- package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
- package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -26
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.d.ts +20 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.js +163 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.d.ts +7 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.js +103 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.d.ts +10 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.js +110 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.d.ts +8 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.js +281 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.js +25 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.d.ts +4 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.js +44 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.js +62 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.d.ts +40 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.js +484 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +9 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +64 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.d.ts +5 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.js +163 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.js +49 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.d.ts +30 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js +446 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.js +49 -0
- package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.js +54 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +134 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +729 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.d.ts +72 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +405 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +18 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +317 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.d.ts +22 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.js +154 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +22 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +426 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.d.ts +57 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.js +705 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.d.ts +46 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js +503 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +146 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js +570 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.d.ts +25 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.js +148 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +25 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +637 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.d.ts +11 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.js +207 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.d.ts +3 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.js +128 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.d.ts +57 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.js +217 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.d.ts +5 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +320 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.d.ts +5 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.js +18 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.d.ts +25 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.js +85 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath.d.ts +59 -0
- package/dist/router/virtual-router/engine-selection/native-router-hotpath.js +117 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +151 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1371 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.js +69 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.js +96 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.js +14 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +86 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.d.ts +6 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.js +85 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.d.ts +9 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.js +70 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.js +76 -0
- package/dist/router/virtual-router/engine-selection/route-utils.js +1 -1
- package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.d.ts +10 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.js +231 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.d.ts +4 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.js +43 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.d.ts +27 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +216 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-select.d.ts +1 -1
- package/dist/router/virtual-router/engine-selection/tier-selection-select.js +128 -129
- package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
- package/dist/router/virtual-router/engine.d.ts +22 -105
- package/dist/router/virtual-router/engine.js +274 -1632
- package/dist/router/virtual-router/features.js +2 -2
- package/dist/router/virtual-router/load-balancer.d.ts +8 -0
- package/dist/router/virtual-router/load-balancer.js +65 -2
- package/dist/router/virtual-router/provider-registry.js +2 -0
- package/dist/router/virtual-router/routing-instructions/clean.d.ts +3 -0
- package/dist/router/virtual-router/routing-instructions/clean.js +34 -0
- package/dist/router/virtual-router/routing-instructions/parse.d.ts +18 -0
- package/dist/router/virtual-router/routing-instructions/parse.js +377 -0
- package/dist/router/virtual-router/routing-instructions/state.d.ts +4 -0
- package/dist/router/virtual-router/routing-instructions/state.js +245 -0
- package/dist/router/virtual-router/routing-instructions/types.d.ts +70 -0
- package/dist/router/virtual-router/routing-instructions/types.js +2 -0
- package/dist/router/virtual-router/routing-instructions.d.ts +5 -91
- package/dist/router/virtual-router/routing-instructions.js +4 -628
- package/dist/router/virtual-router/routing-stop-message-actions.js +91 -112
- package/dist/router/virtual-router/routing-stop-message-parser.js +9 -132
- package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +1 -0
- package/dist/router/virtual-router/routing-stop-message-state-codec.js +58 -71
- package/dist/router/virtual-router/sticky-session-store.d.ts +4 -0
- package/dist/router/virtual-router/sticky-session-store.js +23 -83
- package/dist/router/virtual-router/stop-message-file-resolver.d.ts +1 -0
- package/dist/router/virtual-router/stop-message-file-resolver.js +10 -0
- package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
- package/dist/router/virtual-router/stop-message-state-sync.js +3 -7
- package/dist/router/virtual-router/token-counter.js +0 -9
- package/dist/router/virtual-router/tool-signals.js +21 -3
- package/dist/router/virtual-router/types.d.ts +13 -7
- package/dist/servertool/clock/config.js +23 -51
- package/dist/servertool/clock/io.js +1 -0
- package/dist/servertool/clock/session-scope.d.ts +2 -2
- package/dist/servertool/clock/session-scope.js +29 -40
- package/dist/servertool/engine.d.ts +9 -0
- package/dist/servertool/engine.js +267 -79
- package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +3 -3
- package/dist/servertool/handlers/clock-auto.js +1 -1
- package/dist/servertool/handlers/clock.js +2 -2
- package/dist/servertool/handlers/compaction-detect.d.ts +1 -1
- package/dist/servertool/handlers/compaction-detect.js +1 -1
- package/dist/servertool/handlers/continue-execution.js +8 -4
- package/dist/servertool/handlers/followup-request-builder.js +18 -1
- package/dist/servertool/handlers/gemini-empty-reply-continue.js +8 -2
- package/dist/servertool/handlers/iflow-model-error-retry.js +1 -1
- package/dist/servertool/handlers/recursive-detection-guard.js +1 -1
- package/dist/servertool/handlers/review.d.ts +1 -0
- package/dist/servertool/handlers/review.js +180 -0
- package/dist/servertool/handlers/stop-message-auto/blocked-report.js +59 -1
- package/dist/servertool/handlers/stop-message-auto/iflow-followup.d.ts +23 -2
- package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +398 -90
- package/dist/servertool/handlers/stop-message-auto/routing-state.d.ts +5 -15
- package/dist/servertool/handlers/stop-message-auto/routing-state.js +29 -55
- package/dist/servertool/handlers/stop-message-auto/runtime-utils.d.ts +6 -0
- package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +36 -62
- package/dist/servertool/handlers/stop-message-auto.js +393 -77
- package/dist/servertool/handlers/vision.js +1 -1
- package/dist/servertool/handlers/web-search.js +1 -1
- package/dist/servertool/reenter-backend.js +1 -1
- package/dist/servertool/server-side-tools.d.ts +1 -0
- package/dist/servertool/server-side-tools.js +92 -54
- package/dist/servertool/stop-gateway-context.js +1 -1
- package/dist/servertool/stop-message-compare-context.js +1 -1
- package/dist/servertool/types.d.ts +17 -0
- package/dist/sse/json-to-sse/event-generators/responses.d.ts +4 -0
- package/dist/sse/json-to-sse/event-generators/responses.js +95 -1
- package/dist/sse/json-to-sse/sequencers/responses-sequencer.js +6 -4
- package/dist/sse/sse-to-json/builders/response-builder.d.ts +8 -0
- package/dist/sse/sse-to-json/builders/response-builder.js +162 -4
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +2 -0
- package/dist/sse/types/responses-types.d.ts +6 -2
- package/dist/tools/apply-patch/patch-text/normalize.js +11 -0
- package/dist/tools/apply-patch/structured/coercion.js +5 -0
- package/dist/tools/args-json.js +29 -0
- package/dist/tools/exec-command/validator.d.ts +4 -1
- package/dist/tools/exec-command/validator.js +87 -3
- package/dist/tools/tool-registry.d.ts +7 -1
- package/dist/tools/tool-registry.js +3 -2
- package/package.json +121 -10
- package/dist/conversion/shared/args-mapping.js +0 -221
- package/dist/conversion/shared/bridge-actions.js +0 -881
- package/dist/conversion/shared/bridge-id-utils.js +0 -79
- package/dist/conversion/shared/bridge-metadata.js +0 -1
- package/dist/conversion/shared/bridge-policies.js +0 -195
- package/dist/conversion/shared/compaction-detect.js +0 -59
- package/dist/conversion/shared/errors.js +0 -31
- package/dist/conversion/shared/jsonish.js +0 -177
- package/dist/conversion/shared/mcp-injection.js +0 -173
- package/dist/conversion/shared/media.js +0 -9
- package/dist/conversion/shared/metadata-passthrough.js +0 -57
- package/dist/conversion/shared/payload-budget.js +0 -248
- package/dist/conversion/shared/protocol-field-allowlists.d.ts +0 -7
- package/dist/conversion/shared/protocol-field-allowlists.js +0 -149
- package/dist/conversion/shared/protocol-state.js +0 -23
- package/dist/conversion/shared/runtime-metadata.js +0 -23
- package/dist/conversion/shared/snapshot-hooks.d.ts +0 -11
- package/dist/conversion/shared/snapshot-hooks.js +0 -503
- package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.d.ts +0 -2
- package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.js +0 -129
- package/dist/conversion/shared/text-markup-normalizer/extractors-json.d.ts +0 -4
- package/dist/conversion/shared/text-markup-normalizer/extractors-json.js +0 -637
- package/dist/conversion/shared/text-markup-normalizer/extractors-shared.d.ts +0 -21
- package/dist/conversion/shared/text-markup-normalizer/extractors-shared.js +0 -177
- package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.d.ts +0 -5
- package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.js +0 -385
- package/dist/conversion/shared/text-markup-normalizer/extractors-xml.d.ts +0 -10
- package/dist/conversion/shared/text-markup-normalizer/extractors-xml.js +0 -602
- package/dist/conversion/shared/text-markup-normalizer/extractors.d.ts +0 -5
- package/dist/conversion/shared/text-markup-normalizer/extractors.js +0 -4
- package/dist/conversion/shared/tool-canonicalizer.d.ts +0 -2
- package/dist/conversion/shared/tool-canonicalizer.js +0 -42
- package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.d.ts +0 -18
- package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.js +0 -398
- package/dist/servertool/handlers/stop-message-stage-policy/decision.d.ts +0 -9
- package/dist/servertool/handlers/stop-message-stage-policy/decision.js +0 -127
- package/dist/servertool/handlers/stop-message-stage-policy/observation.d.ts +0 -2
- package/dist/servertool/handlers/stop-message-stage-policy/observation.js +0 -179
- package/dist/servertool/handlers/stop-message-stage-policy/templates.d.ts +0 -4
- package/dist/servertool/handlers/stop-message-stage-policy/templates.js +0 -96
- package/dist/servertool/handlers/stop-message-stage-policy/text-utils.d.ts +0 -9
- package/dist/servertool/handlers/stop-message-stage-policy/text-utils.js +0 -89
- package/dist/servertool/handlers/stop-message-stage-policy/types.d.ts +0 -59
- package/dist/servertool/handlers/stop-message-stage-policy.d.ts +0 -3
- package/dist/servertool/handlers/stop-message-stage-policy.js +0 -2
- /package/dist/conversion/{shared/args-mapping.d.ts → args-mapping.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-actions.d.ts → bridge-actions.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-id-utils.d.ts → bridge-id-utils.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-instructions.d.ts → bridge-instructions.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-policies.d.ts → bridge-policies.d.ts} +0 -0
- /package/dist/conversion/{shared/jsonish.d.ts → jsonish.d.ts} +0 -0
- /package/dist/conversion/{shared/mcp-injection.d.ts → mcp-injection.d.ts} +0 -0
- /package/dist/conversion/{shared/media.d.ts → media.d.ts} +0 -0
- /package/dist/conversion/{shared/payload-budget.d.ts → payload-budget.d.ts} +0 -0
- /package/dist/conversion/{shared → types}/bridge-message-types.js +0 -0
- /package/dist/{servertool/handlers/stop-message-stage-policy/types.js → conversion/types/text-markup-normalizer.js} +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { evaluateResponsesHostPolicy } from '../responses-host-policy.js';
|
|
2
|
-
import { canonicalizeChatResponseTools } from '../../shared/tool-canonicalizer.js';
|
|
3
2
|
import { normalizeMessageReasoningTools } from '../../shared/reasoning-tool-normalizer.js';
|
|
4
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '../../
|
|
5
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '../../
|
|
3
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../../bridge-actions.js';
|
|
4
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../../bridge-policies.js';
|
|
6
5
|
import { buildResponsesOutputFromChat } from '../../shared/responses-output-builder.js';
|
|
7
6
|
import { consumeResponsesPayloadSnapshot, consumeResponsesPassthrough } from '../../shared/responses-reasoning-registry.js';
|
|
8
7
|
import { sanitizeResponsesFunctionName, stripInternalToolingMetadata } from '../../shared/responses-tool-utils.js';
|
|
9
|
-
import { ProviderProtocolError } from '../../
|
|
8
|
+
import { ProviderProtocolError } from '../../provider-protocol-error.js';
|
|
9
|
+
import { normalizeResponsesToolCallArgumentsForClientWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
10
|
+
import { normalizeChatResponseReasoningToolsWithNative } from '../../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
10
11
|
function isPlainObject(value) {
|
|
11
12
|
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
12
13
|
}
|
|
@@ -76,6 +77,9 @@ function mergeResponseOutputItems(baseOutput, sourceOutput) {
|
|
|
76
77
|
if (isMissingResponseField(baseItem.summary) && sourceItem.summary !== undefined) {
|
|
77
78
|
baseItem.summary = deepCloneRecord({ value: sourceItem.summary }).value;
|
|
78
79
|
}
|
|
80
|
+
if (isMissingResponseField(baseItem.encrypted_content) && sourceItem.encrypted_content !== undefined) {
|
|
81
|
+
baseItem.encrypted_content = deepCloneRecord({ value: sourceItem.encrypted_content }).value;
|
|
82
|
+
}
|
|
79
83
|
return baseItem;
|
|
80
84
|
});
|
|
81
85
|
}
|
|
@@ -267,90 +271,13 @@ function normalizeResponsesToolCallArgumentsForClient(responsesPayload, context)
|
|
|
267
271
|
if (!toolsRaw.length) {
|
|
268
272
|
return;
|
|
269
273
|
}
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const normalizeCallArgs = (toolName, argsRaw) => {
|
|
275
|
-
const spec = toolIndex.get(toolName);
|
|
276
|
-
if (!spec)
|
|
277
|
-
return argsRaw;
|
|
278
|
-
// format:"freeform" means client expects raw text (not JSON) in the arguments field.
|
|
279
|
-
if (typeof spec.format === 'string' && spec.format.trim().toLowerCase() === 'freeform') {
|
|
280
|
-
const rawText = extractFreeformTextFromArgs(argsRaw);
|
|
281
|
-
if (rawText && rawText.trim().length) {
|
|
282
|
-
return rawText;
|
|
283
|
-
}
|
|
284
|
-
return argsRaw;
|
|
285
|
-
}
|
|
286
|
-
// Schema-aware key alignment for common server-side tools.
|
|
287
|
-
const params = spec.parameters;
|
|
288
|
-
if (!params)
|
|
289
|
-
return argsRaw;
|
|
290
|
-
const schema = extractJsonSchemaLike(params);
|
|
291
|
-
if (!schema)
|
|
292
|
-
return argsRaw;
|
|
293
|
-
const parsed = tryParseJson(argsRaw);
|
|
294
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
295
|
-
return argsRaw;
|
|
296
|
-
}
|
|
297
|
-
const record = parsed;
|
|
298
|
-
const repaired = repairToolArgsBySchemaKeys(toolName, record, schema);
|
|
299
|
-
if (!repaired) {
|
|
300
|
-
return argsRaw;
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
return JSON.stringify(repaired);
|
|
304
|
-
}
|
|
305
|
-
catch {
|
|
306
|
-
return argsRaw;
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
// 1) output[] function_call items
|
|
310
|
-
const output = Array.isArray(responsesPayload.output) ? responsesPayload.output : [];
|
|
311
|
-
for (const item of output) {
|
|
312
|
-
if (!item || typeof item !== 'object')
|
|
313
|
-
continue;
|
|
314
|
-
const type = typeof item.type === 'string' ? String(item.type).trim().toLowerCase() : '';
|
|
315
|
-
if (type !== 'function_call')
|
|
316
|
-
continue;
|
|
317
|
-
const name = typeof item.name === 'string' ? String(item.name).trim() : '';
|
|
318
|
-
if (!name)
|
|
319
|
-
continue;
|
|
320
|
-
const targetName = resolveClientToolName(toolIndex, name);
|
|
321
|
-
if (!targetName)
|
|
322
|
-
continue;
|
|
323
|
-
if (targetName !== name) {
|
|
324
|
-
item.name = targetName;
|
|
325
|
-
}
|
|
326
|
-
item.arguments = normalizeCallArgs(targetName, item.arguments);
|
|
327
|
-
}
|
|
328
|
-
// 2) required_action.submit_tool_outputs.tool_calls[] tool calls
|
|
329
|
-
const toolCalls = responsesPayload?.required_action?.submit_tool_outputs?.tool_calls;
|
|
330
|
-
const calls = Array.isArray(toolCalls) ? toolCalls : [];
|
|
331
|
-
for (const call of calls) {
|
|
332
|
-
if (!call || typeof call !== 'object')
|
|
333
|
-
continue;
|
|
334
|
-
const fn = call.function && typeof call.function === 'object' && !Array.isArray(call.function) ? call.function : null;
|
|
335
|
-
const name = (typeof fn?.name === 'string' ? String(fn.name).trim() : '') ||
|
|
336
|
-
(typeof call.name === 'string' ? String(call.name).trim() : '');
|
|
337
|
-
if (!name)
|
|
338
|
-
continue;
|
|
339
|
-
const targetName = resolveClientToolName(toolIndex, name);
|
|
340
|
-
if (!targetName)
|
|
341
|
-
continue;
|
|
342
|
-
if (typeof call.name === 'string' && call.name !== targetName) {
|
|
343
|
-
call.name = targetName;
|
|
344
|
-
}
|
|
345
|
-
if (fn && typeof fn === 'object' && fn.name !== targetName) {
|
|
346
|
-
fn.name = targetName;
|
|
347
|
-
}
|
|
348
|
-
const normalizedArgs = normalizeCallArgs(targetName, fn?.arguments ?? call.arguments);
|
|
349
|
-
if (fn && typeof fn === 'object') {
|
|
350
|
-
fn.arguments = normalizedArgs;
|
|
274
|
+
const normalized = normalizeResponsesToolCallArgumentsForClientWithNative(responsesPayload, toolsRaw);
|
|
275
|
+
for (const key of Object.keys(responsesPayload)) {
|
|
276
|
+
if (!Object.prototype.hasOwnProperty.call(normalized, key)) {
|
|
277
|
+
delete responsesPayload[key];
|
|
351
278
|
}
|
|
352
|
-
call.arguments = normalizedArgs;
|
|
353
279
|
}
|
|
280
|
+
Object.assign(responsesPayload, normalized);
|
|
354
281
|
}
|
|
355
282
|
function unwrapData(value) {
|
|
356
283
|
let current = value;
|
|
@@ -457,7 +384,7 @@ export function buildResponsesPayloadFromChat(payload, context) {
|
|
|
457
384
|
}
|
|
458
385
|
return mergedFallback;
|
|
459
386
|
}
|
|
460
|
-
const canonical =
|
|
387
|
+
const canonical = normalizeChatResponseReasoningToolsWithNative(response);
|
|
461
388
|
const choices = Array.isArray(canonical?.choices) ? canonical.choices : [];
|
|
462
389
|
const primaryChoice = choices[0] && typeof choices[0] === 'object' ? choices[0] : undefined;
|
|
463
390
|
const message = primaryChoice && typeof primaryChoice.message === 'object' ? primaryChoice.message : undefined;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { BridgeInputItem, BridgeToolDefinition } from '../../
|
|
1
|
+
import type { BridgeInputItem, BridgeToolDefinition } from '../../types/bridge-message-types.js';
|
|
2
2
|
import type { ChatToolDefinition } from '../../hub/types/chat-envelope.js';
|
|
3
3
|
import type { JsonObject, JsonValue } from '../../hub/types/json.js';
|
|
4
4
|
import type { ToolCallIdStyle } from '../../shared/responses-tool-utils.js';
|
|
5
5
|
export type Unknown = Record<string, unknown>;
|
|
6
6
|
export interface ResponsesRequestContext extends Unknown {
|
|
7
7
|
requestId?: string;
|
|
8
|
+
targetProtocol?: string;
|
|
8
9
|
originalSystemMessages?: string[];
|
|
9
10
|
input?: BridgeInputItem[];
|
|
10
11
|
include?: unknown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BridgeInputBuildResult } from '../
|
|
1
|
+
import type { BridgeInputBuildResult } from '../bridge-message-utils.js';
|
|
2
2
|
import type { BuildChatRequestResult, BuildResponsesRequestResult, ResponsesRequestContext } from './responses-openai-bridge/types.js';
|
|
3
3
|
export type { BuildChatRequestResult, BuildResponsesRequestResult, ResponsesRequestContext } from './responses-openai-bridge/types.js';
|
|
4
4
|
export declare function captureResponsesContext(payload: Record<string, unknown>, dto?: {
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { ensureBridgeInstructions } from '../
|
|
4
|
+
import { ensureBridgeInstructions } from '../bridge-instructions.js';
|
|
5
5
|
import { evaluateResponsesHostPolicy } from './responses-host-policy.js';
|
|
6
|
-
import {
|
|
6
|
+
import { convertBridgeInputToChatMessages } from '../bridge-message-utils.js';
|
|
7
7
|
import { createToolCallIdTransformer, enforceToolCallIdStyle, resolveToolCallIdStyle, sanitizeResponsesFunctionName } from '../shared/responses-tool-utils.js';
|
|
8
|
-
import {
|
|
9
|
-
import { ProviderProtocolError } from '../
|
|
10
|
-
import { readRuntimeMetadata } from '../
|
|
11
|
-
import { clampResponsesInputItemId } from '../
|
|
12
|
-
import { isImagePath } from '../
|
|
8
|
+
import { mapChatToolsToBridge } from '../shared/tool-mapping.js';
|
|
9
|
+
import { ProviderProtocolError } from '../provider-protocol-error.js';
|
|
10
|
+
import { readRuntimeMetadata } from '../runtime-metadata.js';
|
|
11
|
+
import { clampResponsesInputItemId } from '../bridge-id-utils.js';
|
|
12
|
+
import { isImagePath } from '../media.js';
|
|
13
|
+
import { captureReqInboundResponsesContextSnapshotWithNative, mapReqInboundBridgeToolsToChatWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
14
|
+
import { buildBridgeHistoryWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
13
15
|
// --- Utilities (ported strictly) ---
|
|
14
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '../
|
|
15
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '../
|
|
16
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../bridge-actions.js';
|
|
17
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../bridge-policies.js';
|
|
16
18
|
function isObject(v) {
|
|
17
19
|
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
18
20
|
}
|
|
@@ -43,7 +45,7 @@ function filterBridgeInputForUpstream(input, options) {
|
|
|
43
45
|
return [clone];
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
|
-
// normalizeTools unified in ../
|
|
48
|
+
// normalizeTools unified in ../args-mapping.ts
|
|
47
49
|
// --- Structured self-repair helpers for tool failures (Responses path) ---
|
|
48
50
|
const IMAGE_MIME_BY_EXT = {
|
|
49
51
|
'.png': 'image/png',
|
|
@@ -236,65 +238,40 @@ function appendLocalImageBlockOnLatestUserInput(messages, context) {
|
|
|
236
238
|
export function captureResponsesContext(payload, dto) {
|
|
237
239
|
const preservedInput = cloneBridgeEntries(payload.input);
|
|
238
240
|
ensureBridgeInstructions(payload);
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
: {}
|
|
242
|
-
const topLevelParameterKeys = [
|
|
243
|
-
'temperature',
|
|
244
|
-
'top_p',
|
|
245
|
-
'max_tokens',
|
|
246
|
-
'max_output_tokens',
|
|
247
|
-
'seed',
|
|
248
|
-
'logit_bias',
|
|
249
|
-
'user',
|
|
250
|
-
'parallel_tool_calls',
|
|
251
|
-
'tool_choice',
|
|
252
|
-
'response_format',
|
|
253
|
-
'service_tier',
|
|
254
|
-
'truncation',
|
|
255
|
-
'include',
|
|
256
|
-
'store',
|
|
257
|
-
'prompt_cache_key',
|
|
258
|
-
'reasoning'
|
|
259
|
-
];
|
|
260
|
-
for (const key of topLevelParameterKeys) {
|
|
261
|
-
if (payload[key] !== undefined && inheritedParameters[key] === undefined) {
|
|
262
|
-
inheritedParameters[key] = payload[key];
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const context = {
|
|
266
|
-
requestId: dto?.route?.requestId,
|
|
267
|
-
input: preservedInput,
|
|
268
|
-
include: payload.include,
|
|
269
|
-
store: payload.store,
|
|
270
|
-
serviceTier: payload.service_tier,
|
|
271
|
-
truncation: payload.truncation,
|
|
272
|
-
toolChoice: payload.tool_choice,
|
|
273
|
-
parallelToolCalls: typeof payload.parallel_tool_calls === 'boolean' ? payload.parallel_tool_calls : undefined,
|
|
274
|
-
metadata: (payload.metadata && typeof payload.metadata === 'object') ? payload.metadata : undefined,
|
|
275
|
-
responseFormat: payload.response_format,
|
|
276
|
-
stream: typeof payload.stream === 'boolean' ? payload.stream : undefined,
|
|
277
|
-
isChatPayload: Array.isArray(payload.messages)
|
|
241
|
+
const requestForCapture = {
|
|
242
|
+
...payload,
|
|
243
|
+
...(preservedInput ? { input: preservedInput } : {})
|
|
278
244
|
};
|
|
279
|
-
|
|
280
|
-
|
|
245
|
+
const captured = captureReqInboundResponsesContextSnapshotWithNative({
|
|
246
|
+
rawRequest: requestForCapture,
|
|
247
|
+
requestId: dto?.route?.requestId,
|
|
248
|
+
toolCallIdStyle: payload?.toolCallIdStyle ?? payload?.metadata?.toolCallIdStyle
|
|
249
|
+
});
|
|
250
|
+
const instructionReasoning = payload?.__rcc_reasoning_instructions;
|
|
251
|
+
if (instructionReasoning !== undefined && instructionReasoning !== null) {
|
|
252
|
+
const segments = Array.isArray(instructionReasoning) ? instructionReasoning : [instructionReasoning];
|
|
253
|
+
const normalized = segments
|
|
254
|
+
.map((entry) => (typeof entry === 'string' ? entry.trim() : String(entry ?? '').trim()))
|
|
255
|
+
.filter((entry) => entry.length > 0);
|
|
256
|
+
if (normalized.length) {
|
|
257
|
+
captured.__rcc_reasoning_instructions_segments = normalized;
|
|
258
|
+
}
|
|
281
259
|
}
|
|
282
|
-
if (
|
|
283
|
-
|
|
260
|
+
if (preservedInput) {
|
|
261
|
+
captured.input = preservedInput;
|
|
284
262
|
}
|
|
285
|
-
if (
|
|
286
|
-
|
|
263
|
+
if (!captured.systemInstruction && typeof payload.instructions === 'string' && payload.instructions.trim().length) {
|
|
264
|
+
captured.systemInstruction = payload.instructions;
|
|
287
265
|
}
|
|
288
|
-
|
|
289
|
-
return context;
|
|
266
|
+
return captured;
|
|
290
267
|
}
|
|
291
268
|
export function buildChatRequestFromResponses(payload, context) {
|
|
292
269
|
// V3: 对 Responses 路径仅做“形状转换”,不做参数解析/修复。
|
|
293
270
|
// 将顶层 { type,name,description,parameters,strict } 归一为 OpenAI Chat tools 形状:
|
|
294
271
|
// { type:'function', function:{ name,description,parameters,strict? } }
|
|
295
|
-
const toolsNormalized =
|
|
296
|
-
|
|
297
|
-
|
|
272
|
+
const toolsNormalized = Array.isArray(context.toolsNormalized) && context.toolsNormalized.length
|
|
273
|
+
? cloneBridgeEntries(context.toolsNormalized)
|
|
274
|
+
: mapReqInboundBridgeToolsToChatWithNative(payload.tools);
|
|
298
275
|
// 不在 Responses 路径进行 MCP 工具注入;统一由 Chat 后半段治理注入
|
|
299
276
|
let messages = convertBridgeInputToChatMessages({
|
|
300
277
|
input: context.input,
|
|
@@ -614,7 +591,7 @@ export function buildResponsesRequestFromChat(payload, ctx, extras) {
|
|
|
614
591
|
sanitizeBridgeHistory(normalizeBridgeHistory(envelopeMetadata?.bridgeHistory)) ??
|
|
615
592
|
sanitizeBridgeHistory(fallbackHistory);
|
|
616
593
|
const history = historySeed ??
|
|
617
|
-
sanitizeBridgeHistory(
|
|
594
|
+
sanitizeBridgeHistory(buildBridgeHistoryWithNative({
|
|
618
595
|
messages,
|
|
619
596
|
tools: Array.isArray(out.tools) ? out.tools : undefined
|
|
620
597
|
}));
|
|
@@ -629,12 +606,35 @@ export function buildResponsesRequestFromChat(payload, ctx, extras) {
|
|
|
629
606
|
typeof envelopeMetadata?.systemInstruction === 'string' && envelopeMetadata.systemInstruction.trim().length ? envelopeMetadata.systemInstruction.trim() : undefined,
|
|
630
607
|
combinedSystemInstruction && combinedSystemInstruction.length > 0 ? combinedSystemInstruction : undefined
|
|
631
608
|
];
|
|
609
|
+
let resolvedInstruction;
|
|
632
610
|
for (const candidate of instructionCandidates) {
|
|
633
611
|
if (candidate && candidate.length) {
|
|
634
|
-
|
|
612
|
+
resolvedInstruction = candidate;
|
|
635
613
|
break;
|
|
636
614
|
}
|
|
637
615
|
}
|
|
616
|
+
if (resolvedInstruction && resolvedInstruction.length) {
|
|
617
|
+
const reasoningSegments = (() => {
|
|
618
|
+
if (!ctx || typeof ctx !== 'object')
|
|
619
|
+
return [];
|
|
620
|
+
const ctxAny = ctx;
|
|
621
|
+
const raw = ctxAny.__rcc_reasoning_instructions_segments;
|
|
622
|
+
if (!raw)
|
|
623
|
+
return [];
|
|
624
|
+
const segments = Array.isArray(raw) ? raw : [raw];
|
|
625
|
+
return segments
|
|
626
|
+
.map((entry) => (typeof entry === 'string' ? entry.trim() : String(entry ?? '').trim()))
|
|
627
|
+
.filter((entry) => entry.length > 0);
|
|
628
|
+
})();
|
|
629
|
+
if (reasoningSegments.length) {
|
|
630
|
+
const combined = `${reasoningSegments.join('\n')}\n${resolvedInstruction}`.trim();
|
|
631
|
+
out.instructions = combined;
|
|
632
|
+
out.instructions_is_raw = true;
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
out.instructions = resolvedInstruction;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
638
|
// 不追加 metadata,以便 roundtrip 与原始 payload 对齐;系统提示直接写入 instructions。
|
|
639
639
|
const upstreamInput = filterBridgeInputForUpstream(input, { allowToolCallId: toolCallIdStyle === 'preserve' });
|
|
640
640
|
if (upstreamInput.length) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isJsonObject, jsonClone } from './hub/types/json.js';
|
|
2
|
+
import { cloneRuntimeMetadataWithNative, ensureRuntimeMetadataCarrierWithNative, readRuntimeMetadataWithNative } from '../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
|
+
export function readRuntimeMetadata(carrier) {
|
|
4
|
+
if (!carrier || typeof carrier !== 'object') {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const candidate = readRuntimeMetadataWithNative(carrier);
|
|
8
|
+
return candidate && isJsonObject(candidate) ? candidate : undefined;
|
|
9
|
+
}
|
|
10
|
+
export function ensureRuntimeMetadata(carrier) {
|
|
11
|
+
if (!carrier || typeof carrier !== 'object') {
|
|
12
|
+
throw new Error('ensureRuntimeMetadata requires object carrier');
|
|
13
|
+
}
|
|
14
|
+
const nextCarrier = ensureRuntimeMetadataCarrierWithNative(carrier);
|
|
15
|
+
for (const key of Object.keys(carrier)) {
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(nextCarrier, key)) {
|
|
17
|
+
delete carrier[key];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
Object.assign(carrier, nextCarrier);
|
|
21
|
+
const existing = carrier.__rt;
|
|
22
|
+
if (existing && isJsonObject(existing)) {
|
|
23
|
+
return existing;
|
|
24
|
+
}
|
|
25
|
+
carrier.__rt = {};
|
|
26
|
+
return carrier.__rt;
|
|
27
|
+
}
|
|
28
|
+
export function cloneRuntimeMetadata(carrier) {
|
|
29
|
+
const rt = cloneRuntimeMetadataWithNative(carrier);
|
|
30
|
+
return rt && isJsonObject(rt) ? jsonClone(rt) : undefined;
|
|
31
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { createBridgeActionState, runBridgeActionPipeline } from '
|
|
2
|
-
import { resolveBridgePolicy, resolvePolicyActions } from '
|
|
1
|
+
import { createBridgeActionState, runBridgeActionPipeline } from '../bridge-actions.js';
|
|
2
|
+
import { resolveBridgePolicy, resolvePolicyActions } from '../bridge-policies.js';
|
|
3
3
|
import { normalizeChatMessageContent } from './chat-output-normalizer.js';
|
|
4
4
|
import { mapBridgeToolsToChat, mapChatToolsToBridge } from './tool-mapping.js';
|
|
5
5
|
import { jsonClone } from '../hub/types/json.js';
|
|
6
|
-
import { ProviderProtocolError } from '
|
|
6
|
+
import { ProviderProtocolError } from '../provider-protocol-error.js';
|
|
7
|
+
import { parseLenientJsonishWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
7
8
|
function isObject(v) {
|
|
8
9
|
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
9
10
|
}
|
|
@@ -15,6 +16,27 @@ function safeJson(v) {
|
|
|
15
16
|
return '{}';
|
|
16
17
|
}
|
|
17
18
|
}
|
|
19
|
+
function stripOpenAIChatToolAliasFields(messages) {
|
|
20
|
+
for (const message of messages) {
|
|
21
|
+
if (!message || typeof message !== 'object') {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const role = String(message.role || '').toLowerCase();
|
|
25
|
+
if (role === 'assistant' && Array.isArray(message.tool_calls)) {
|
|
26
|
+
for (const call of message.tool_calls) {
|
|
27
|
+
if (!call || typeof call !== 'object') {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
delete call.tool_call_id;
|
|
31
|
+
delete call.call_id;
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (role === 'tool') {
|
|
36
|
+
delete message.call_id;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
18
40
|
function sanitizeToolUseId(raw) {
|
|
19
41
|
const trimmed = typeof raw === 'string' ? raw.trim() : '';
|
|
20
42
|
if (!trimmed) {
|
|
@@ -186,6 +208,28 @@ const ANTHROPIC_TOP_LEVEL_FIELDS = new Set([
|
|
|
186
208
|
'tool_choice',
|
|
187
209
|
'thinking'
|
|
188
210
|
]);
|
|
211
|
+
const ANTHROPIC_STABLE_TOOL_SCHEMA_NAMES = new Set([
|
|
212
|
+
'exec_command',
|
|
213
|
+
'write_stdin',
|
|
214
|
+
'apply_patch',
|
|
215
|
+
'request_user_input',
|
|
216
|
+
'update_plan',
|
|
217
|
+
'view_image',
|
|
218
|
+
'web_search',
|
|
219
|
+
'clock',
|
|
220
|
+
'continue_execution',
|
|
221
|
+
'review'
|
|
222
|
+
]);
|
|
223
|
+
const ANTHROPIC_STABLE_TOOL_SCHEMA_KEYS = new Map([
|
|
224
|
+
['exec_command', new Set(['cmd', 'command', 'workdir', 'justification', 'login', 'max_output_tokens', 'sandbox_permissions', 'shell', 'yield_time_ms', 'tty', 'prefix_rule'])],
|
|
225
|
+
['write_stdin', new Set(['session_id', 'chars', 'text', 'yield_time_ms', 'max_output_tokens'])],
|
|
226
|
+
['apply_patch', new Set(['patch', 'input', 'instructions', 'text', 'file', 'changes'])],
|
|
227
|
+
['request_user_input', new Set(['questions'])],
|
|
228
|
+
['update_plan', new Set(['explanation', 'plan'])],
|
|
229
|
+
['view_image', new Set(['path'])],
|
|
230
|
+
['web_search', new Set(['query', 'q', 'domains', 'recency'])],
|
|
231
|
+
['clock', new Set(['action', 'items', 'taskId'])]
|
|
232
|
+
]);
|
|
189
233
|
export function normalizeAnthropicToolName(value) {
|
|
190
234
|
if (typeof value !== 'string') {
|
|
191
235
|
return undefined;
|
|
@@ -505,6 +549,7 @@ export function buildOpenAIChatFromAnthropic(payload) {
|
|
|
505
549
|
catch {
|
|
506
550
|
// ignore policy failures
|
|
507
551
|
}
|
|
552
|
+
stripOpenAIChatToolAliasFields(newMessages);
|
|
508
553
|
return request;
|
|
509
554
|
}
|
|
510
555
|
export function buildAnthropicFromOpenAIChat(oa, options) {
|
|
@@ -545,11 +590,22 @@ export function buildAnthropicFromOpenAIChat(oa, options) {
|
|
|
545
590
|
blocks.push({ type: 'text', text });
|
|
546
591
|
}
|
|
547
592
|
}
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
593
|
+
const extensionReasoning = body?.__responses_reasoning;
|
|
594
|
+
const extensionContent = Array.isArray(extensionReasoning?.content)
|
|
595
|
+
? extensionReasoning?.content?.map((entry) => String(entry.text ?? '')).filter((text) => text.trim().length > 0)
|
|
596
|
+
: [];
|
|
597
|
+
const extensionSummary = Array.isArray(extensionReasoning?.summary)
|
|
598
|
+
? extensionReasoning?.summary?.map((entry) => String(entry.text ?? '')).filter((text) => text.trim().length > 0)
|
|
599
|
+
: [];
|
|
600
|
+
const extensionText = extensionContent.length > 0
|
|
601
|
+
? extensionContent.join('\n')
|
|
602
|
+
: (extensionSummary.length > 0 ? extensionSummary.join('\n') : undefined);
|
|
603
|
+
const reasoningField = extensionText ??
|
|
604
|
+
(typeof msg?.reasoning_content === 'string'
|
|
605
|
+
? msg.reasoning_content
|
|
606
|
+
: typeof msg?.reasoning === 'string'
|
|
607
|
+
? msg.reasoning
|
|
608
|
+
: undefined);
|
|
553
609
|
if (reasoningField && reasoningField.trim().length) {
|
|
554
610
|
blocks.push({ type: 'thinking', text: reasoningField.trim() });
|
|
555
611
|
}
|
|
@@ -564,12 +620,8 @@ export function buildAnthropicFromOpenAIChat(oa, options) {
|
|
|
564
620
|
const argsRaw = fn.arguments;
|
|
565
621
|
let input;
|
|
566
622
|
if (typeof argsRaw === 'string') {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
catch {
|
|
571
|
-
input = { _raw: argsRaw };
|
|
572
|
-
}
|
|
623
|
+
const parsed = parseLenientJsonishWithNative(argsRaw);
|
|
624
|
+
input = parsed && typeof parsed === 'object' ? parsed : { _raw: argsRaw };
|
|
573
625
|
}
|
|
574
626
|
else {
|
|
575
627
|
input = argsRaw ?? {};
|
|
@@ -991,12 +1043,8 @@ export function buildAnthropicRequestFromOpenAIChat(chatReq) {
|
|
|
991
1043
|
const argsRaw = fn.arguments;
|
|
992
1044
|
let input;
|
|
993
1045
|
if (typeof argsRaw === 'string') {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
catch {
|
|
998
|
-
input = { _raw: argsRaw };
|
|
999
|
-
}
|
|
1046
|
+
const parsed = parseLenientJsonishWithNative(argsRaw);
|
|
1047
|
+
input = parsed && typeof parsed === 'object' ? parsed : { _raw: argsRaw };
|
|
1000
1048
|
}
|
|
1001
1049
|
else {
|
|
1002
1050
|
input = argsRaw ?? {};
|
|
@@ -1095,6 +1143,107 @@ function cloneAnthropicSchema(value) {
|
|
|
1095
1143
|
}
|
|
1096
1144
|
return { type: 'object', properties: {} };
|
|
1097
1145
|
}
|
|
1146
|
+
function normalizeAnthropicSchemaType(value) {
|
|
1147
|
+
if (typeof value === 'string') {
|
|
1148
|
+
const trimmed = value.trim().toLowerCase();
|
|
1149
|
+
if (trimmed === 'string' ||
|
|
1150
|
+
trimmed === 'number' ||
|
|
1151
|
+
trimmed === 'integer' ||
|
|
1152
|
+
trimmed === 'boolean' ||
|
|
1153
|
+
trimmed === 'object' ||
|
|
1154
|
+
trimmed === 'array') {
|
|
1155
|
+
return trimmed;
|
|
1156
|
+
}
|
|
1157
|
+
return undefined;
|
|
1158
|
+
}
|
|
1159
|
+
if (Array.isArray(value)) {
|
|
1160
|
+
for (const entry of value) {
|
|
1161
|
+
const normalized = normalizeAnthropicSchemaType(entry);
|
|
1162
|
+
if (normalized) {
|
|
1163
|
+
return normalized;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return undefined;
|
|
1168
|
+
}
|
|
1169
|
+
function compactAnthropicPropertySchema(schema) {
|
|
1170
|
+
if (!isPlainRecord(schema)) {
|
|
1171
|
+
return { type: 'string' };
|
|
1172
|
+
}
|
|
1173
|
+
const out = {};
|
|
1174
|
+
const type = normalizeAnthropicSchemaType(schema.type);
|
|
1175
|
+
if (type) {
|
|
1176
|
+
out.type = type;
|
|
1177
|
+
}
|
|
1178
|
+
if (typeof schema.description === 'string' && schema.description.trim()) {
|
|
1179
|
+
out.description = schema.description;
|
|
1180
|
+
}
|
|
1181
|
+
const enumRaw = Array.isArray(schema.enum) ? schema.enum : undefined;
|
|
1182
|
+
if (enumRaw && enumRaw.length) {
|
|
1183
|
+
const enumValues = enumRaw
|
|
1184
|
+
.filter((entry) => {
|
|
1185
|
+
const entryType = typeof entry;
|
|
1186
|
+
return entryType === 'string' || entryType === 'number' || entryType === 'boolean';
|
|
1187
|
+
})
|
|
1188
|
+
.slice(0, 64);
|
|
1189
|
+
if (enumValues.length) {
|
|
1190
|
+
out.enum = enumValues;
|
|
1191
|
+
if (!out.type) {
|
|
1192
|
+
const inferred = typeof enumValues[0];
|
|
1193
|
+
out.type = inferred === 'boolean' ? 'boolean' : inferred === 'number' ? 'number' : 'string';
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
if (out.type === 'array') {
|
|
1198
|
+
const items = isPlainRecord(schema.items) ? schema.items : {};
|
|
1199
|
+
const itemType = normalizeAnthropicSchemaType(items.type) ?? 'string';
|
|
1200
|
+
out.items = { type: itemType };
|
|
1201
|
+
}
|
|
1202
|
+
else if (out.type === 'object') {
|
|
1203
|
+
out.properties = {};
|
|
1204
|
+
out.additionalProperties = false;
|
|
1205
|
+
}
|
|
1206
|
+
if (!out.type) {
|
|
1207
|
+
out.type = 'string';
|
|
1208
|
+
}
|
|
1209
|
+
return out;
|
|
1210
|
+
}
|
|
1211
|
+
function sanitizeAnthropicBuiltinInputSchema(toolName, schemaSource) {
|
|
1212
|
+
const normalizedName = toolName.trim().toLowerCase();
|
|
1213
|
+
if (!ANTHROPIC_STABLE_TOOL_SCHEMA_NAMES.has(normalizedName)) {
|
|
1214
|
+
return cloneAnthropicSchema(schemaSource);
|
|
1215
|
+
}
|
|
1216
|
+
const source = cloneAnthropicSchema(schemaSource);
|
|
1217
|
+
const sourceProperties = isPlainRecord(source.properties) ? source.properties : {};
|
|
1218
|
+
const allowedKeys = ANTHROPIC_STABLE_TOOL_SCHEMA_KEYS.get(normalizedName);
|
|
1219
|
+
const sanitizedProperties = {};
|
|
1220
|
+
for (const [key, value] of Object.entries(sourceProperties)) {
|
|
1221
|
+
if (allowedKeys && !allowedKeys.has(key)) {
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
sanitizedProperties[key] = compactAnthropicPropertySchema(value);
|
|
1225
|
+
}
|
|
1226
|
+
const required = Array.isArray(source.required)
|
|
1227
|
+
? source.required.filter((entry) => typeof entry === 'string' && entry.trim().length > 0)
|
|
1228
|
+
: [];
|
|
1229
|
+
const filteredRequired = allowedKeys
|
|
1230
|
+
? required.filter((key) => allowedKeys.has(key))
|
|
1231
|
+
: required;
|
|
1232
|
+
for (const key of filteredRequired) {
|
|
1233
|
+
if (!Object.prototype.hasOwnProperty.call(sanitizedProperties, key)) {
|
|
1234
|
+
sanitizedProperties[key] = { type: 'string' };
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
const output = {
|
|
1238
|
+
type: 'object',
|
|
1239
|
+
properties: sanitizedProperties,
|
|
1240
|
+
additionalProperties: false
|
|
1241
|
+
};
|
|
1242
|
+
if (filteredRequired.length) {
|
|
1243
|
+
output.required = Array.from(new Set(filteredRequired));
|
|
1244
|
+
}
|
|
1245
|
+
return output;
|
|
1246
|
+
}
|
|
1098
1247
|
function prepareAnthropicBridgeTools(rawTools, missing) {
|
|
1099
1248
|
if (!Array.isArray(rawTools) || rawTools.length === 0) {
|
|
1100
1249
|
return undefined;
|
|
@@ -1151,7 +1300,7 @@ function convertBridgeToolToAnthropic(def) {
|
|
|
1151
1300
|
? def.description
|
|
1152
1301
|
: undefined;
|
|
1153
1302
|
const schemaSource = fnNode?.parameters ?? def.parameters;
|
|
1154
|
-
const inputSchema =
|
|
1303
|
+
const inputSchema = sanitizeAnthropicBuiltinInputSchema(name, schemaSource);
|
|
1155
1304
|
const tool = {
|
|
1156
1305
|
name,
|
|
1157
1306
|
input_schema: inputSchema
|