@jsonstudio/llms 0.6.2172 → 0.6.2979
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/compat/antigravity-session-signature.js +35 -1
- package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
- package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
- 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 +10 -6
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +2 -2
- package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +10 -10
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +4 -8
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +19 -65
- 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.js +115 -262
- 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.js +12 -86
- 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 +18 -3
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +10 -198
- 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 +12 -10
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +6 -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 +20 -148
- 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 +6 -21
- package/dist/conversion/hub/response/response-mappers.js +2 -26
- package/dist/conversion/hub/response/response-runtime.js +2 -93
- 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 +10 -3
- package/dist/conversion/hub/standardized-bridge.js +11 -288
- package/dist/conversion/hub/tool-governance/engine.js +5 -0
- package/dist/conversion/hub/tool-governance/rules.js +10 -10
- 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 +5 -3
- package/dist/conversion/responses/responses-host-policy.js +2 -12
- package/dist/conversion/responses/responses-openai-bridge/response-payload.js +6 -82
- package/dist/conversion/responses/responses-openai-bridge/types.d.ts +1 -0
- package/dist/conversion/responses/responses-openai-bridge.js +21 -54
- package/dist/conversion/shared/anthropic-message-utils.js +151 -13
- package/dist/conversion/shared/args-mapping.js +2 -146
- package/dist/conversion/shared/bridge-actions.js +203 -718
- package/dist/conversion/shared/bridge-id-utils.js +5 -71
- package/dist/conversion/shared/bridge-instructions.js +2 -1
- package/dist/conversion/shared/bridge-message-types.d.ts +2 -0
- package/dist/conversion/shared/bridge-message-utils.js +1 -2
- package/dist/conversion/shared/bridge-metadata.d.ts +1 -0
- package/dist/conversion/shared/bridge-metadata.js +4 -0
- package/dist/conversion/shared/bridge-policies.js +5 -189
- package/dist/conversion/shared/chat-envelope-validator.js +2 -126
- package/dist/conversion/shared/chat-output-normalizer.js +2 -54
- package/dist/conversion/shared/compaction-detect.js +2 -57
- package/dist/conversion/shared/gemini-tool-utils.js +9 -524
- package/dist/conversion/shared/jsonish.js +3 -160
- package/dist/conversion/shared/mcp-injection.js +3 -169
- package/dist/conversion/shared/media.js +2 -7
- package/dist/conversion/shared/metadata-passthrough.js +9 -46
- package/dist/conversion/shared/openai-finalizer.js +2 -1
- package/dist/conversion/shared/openai-message-normalize.js +11 -283
- package/dist/conversion/shared/output-content-normalizer.js +9 -112
- package/dist/conversion/shared/payload-budget.js +2 -85
- package/dist/conversion/shared/protocol-state.js +11 -7
- package/dist/conversion/shared/reasoning-mapping.js +2 -6
- package/dist/conversion/shared/reasoning-normalizer.js +4 -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 +2 -6
- package/dist/conversion/shared/responses-conversation-store.js +4 -82
- package/dist/conversion/shared/responses-output-builder.js +11 -47
- package/dist/conversion/shared/responses-reasoning-registry.js +7 -1
- 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 +6 -7
- package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
- package/dist/conversion/shared/responses-tool-utils.js +90 -14
- package/dist/conversion/shared/runtime-metadata.js +13 -5
- package/dist/conversion/shared/streaming-text-extractor.js +2 -7
- package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +1 -1
- package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
- package/dist/conversion/shared/text-markup-normalizer.d.ts +1 -0
- package/dist/conversion/shared/text-markup-normalizer.js +1 -0
- 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-canonicalizer.js +25 -29
- package/dist/conversion/shared/tool-filter-pipeline.js +4 -99
- package/dist/conversion/shared/tool-governor.d.ts +6 -0
- package/dist/conversion/shared/tool-governor.js +43 -125
- package/dist/conversion/shared/tool-harvester.js +2 -8
- 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/native/router_hotpath_napi.node +0 -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.js +48 -12
- package/dist/router/virtual-router/engine-logging.js +4 -3
- package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
- package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -23
- 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-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 +62 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +338 -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-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 +284 -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 +76 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1166 -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-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 +116 -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 +29 -129
- package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
- package/dist/router/virtual-router/engine.js +258 -249
- package/dist/router/virtual-router/features.js +2 -2
- package/dist/router/virtual-router/routing-instructions.d.ts +5 -7
- package/dist/router/virtual-router/routing-instructions.js +93 -66
- 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.js +4 -2
- 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/types.d.ts +9 -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 +5 -47
- package/dist/servertool/engine.d.ts +9 -0
- package/dist/servertool/engine.js +196 -79
- package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +2 -2
- package/dist/servertool/handlers/clock.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 +7 -1
- 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 +397 -89
- 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 +35 -61
- package/dist/servertool/handlers/stop-message-auto.js +392 -76
- package/dist/servertool/server-side-tools.d.ts +1 -0
- package/dist/servertool/server-side-tools.js +90 -52
- package/dist/servertool/types.d.ts +17 -0
- package/dist/tools/apply-patch/patch-text/normalize.js +11 -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 +115 -7
- 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/servertool/handlers/{stop-message-stage-policy/types.js → review.d.ts} +0 -0
|
@@ -4,6 +4,7 @@ import { buildGeminiToolsFromBridge, prepareGeminiToolsForBridge } from '../../s
|
|
|
4
4
|
import { mapAnthropicToolsToChat, mapChatToolsToAnthropicTools } from '../../shared/anthropic-message-utils.js';
|
|
5
5
|
import { convertBridgeInputToChatMessages, convertMessagesToBridgeInput } from '../../shared/bridge-message-utils.js';
|
|
6
6
|
import { resolveHubProtocolSpec } from '../policy/protocol-spec.js';
|
|
7
|
+
import { normalizeProviderProtocolTokenWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
7
8
|
function clampSampleRate(value) {
|
|
8
9
|
const num = typeof value === 'number' && Number.isFinite(value) ? value : 1;
|
|
9
10
|
if (num <= 0)
|
|
@@ -428,16 +429,17 @@ export function applyProviderOutboundToolSurface(args) {
|
|
|
428
429
|
if (!shouldSample(config, args.requestId)) {
|
|
429
430
|
return args.payload;
|
|
430
431
|
}
|
|
432
|
+
const normalizedProviderProtocol = normalizeProviderProtocolTokenWithNative(args.providerProtocol) ?? args.providerProtocol;
|
|
431
433
|
const payload = args.payload;
|
|
432
434
|
const tools = payload.tools;
|
|
433
|
-
const candidate = buildCandidateTools({ providerProtocol:
|
|
435
|
+
const candidate = buildCandidateTools({ providerProtocol: normalizedProviderProtocol, tools });
|
|
434
436
|
if (!candidate) {
|
|
435
437
|
// Still allow history/tool-call surface observation even when tool definitions don't need conversion.
|
|
436
438
|
}
|
|
437
439
|
const stageBase = `hub_toolsurface.${config.mode}.provider_outbound`;
|
|
438
440
|
const toolSchemaCandidate = candidate?.candidateTools;
|
|
439
441
|
const schemaDiff = candidate ? computeToolSchemaDiff(tools, toolSchemaCandidate) : { diffCount: 0, diffHead: [] };
|
|
440
|
-
const expectedHistoryCarrier = resolveExpectedHistoryCarrier(
|
|
442
|
+
const expectedHistoryCarrier = resolveExpectedHistoryCarrier(normalizedProviderProtocol);
|
|
441
443
|
let historyReason = undefined;
|
|
442
444
|
let historyBaseline = undefined;
|
|
443
445
|
let historyCandidate = undefined;
|
|
@@ -492,7 +494,7 @@ export function applyProviderOutboundToolSurface(args) {
|
|
|
492
494
|
}
|
|
493
495
|
args.stageRecorder?.record(stageBase, {
|
|
494
496
|
kind: 'provider_outbound',
|
|
495
|
-
providerProtocol:
|
|
497
|
+
providerProtocol: normalizedProviderProtocol,
|
|
496
498
|
reason: candidate?.reason ?? historyReason,
|
|
497
499
|
diffCount: totalDiffCount,
|
|
498
500
|
diffHead: diffHeadMerged,
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
+
import { evaluateResponsesHostPolicyWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
1
2
|
export function evaluateResponsesHostPolicy(context, targetProtocol) {
|
|
2
|
-
|
|
3
|
-
? targetProtocol
|
|
4
|
-
: (typeof context?.targetProtocol === 'string' && context.targetProtocol.trim()
|
|
5
|
-
? context.targetProtocol
|
|
6
|
-
: 'responses');
|
|
7
|
-
const normalized = protocol.toLowerCase();
|
|
8
|
-
const shouldStrip = normalized !== 'openai-responses' &&
|
|
9
|
-
normalized !== 'responses';
|
|
10
|
-
return {
|
|
11
|
-
shouldStripHostManagedFields: shouldStrip,
|
|
12
|
-
targetProtocol: normalized
|
|
13
|
-
};
|
|
3
|
+
return evaluateResponsesHostPolicyWithNative(context, targetProtocol);
|
|
14
4
|
}
|
|
@@ -7,6 +7,7 @@ import { buildResponsesOutputFromChat } from '../../shared/responses-output-buil
|
|
|
7
7
|
import { consumeResponsesPayloadSnapshot, consumeResponsesPassthrough } from '../../shared/responses-reasoning-registry.js';
|
|
8
8
|
import { sanitizeResponsesFunctionName, stripInternalToolingMetadata } from '../../shared/responses-tool-utils.js';
|
|
9
9
|
import { ProviderProtocolError } from '../../shared/errors.js';
|
|
10
|
+
import { normalizeResponsesToolCallArgumentsForClientWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
10
11
|
function isPlainObject(value) {
|
|
11
12
|
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
12
13
|
}
|
|
@@ -267,90 +268,13 @@ function normalizeResponsesToolCallArgumentsForClient(responsesPayload, context)
|
|
|
267
268
|
if (!toolsRaw.length) {
|
|
268
269
|
return;
|
|
269
270
|
}
|
|
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;
|
|
271
|
+
const normalized = normalizeResponsesToolCallArgumentsForClientWithNative(responsesPayload, toolsRaw);
|
|
272
|
+
for (const key of Object.keys(responsesPayload)) {
|
|
273
|
+
if (!Object.prototype.hasOwnProperty.call(normalized, key)) {
|
|
274
|
+
delete responsesPayload[key];
|
|
351
275
|
}
|
|
352
|
-
call.arguments = normalizedArgs;
|
|
353
276
|
}
|
|
277
|
+
Object.assign(responsesPayload, normalized);
|
|
354
278
|
}
|
|
355
279
|
function unwrapData(value) {
|
|
356
280
|
let current = value;
|
|
@@ -5,6 +5,7 @@ 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;
|
|
@@ -3,13 +3,15 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { ensureBridgeInstructions } from '../shared/bridge-instructions.js';
|
|
5
5
|
import { evaluateResponsesHostPolicy } from './responses-host-policy.js';
|
|
6
|
-
import {
|
|
6
|
+
import { convertBridgeInputToChatMessages } from '../shared/bridge-message-utils.js';
|
|
7
7
|
import { createToolCallIdTransformer, enforceToolCallIdStyle, resolveToolCallIdStyle, sanitizeResponsesFunctionName } from '../shared/responses-tool-utils.js';
|
|
8
|
-
import {
|
|
8
|
+
import { mapChatToolsToBridge } from '../shared/tool-mapping.js';
|
|
9
9
|
import { ProviderProtocolError } from '../shared/errors.js';
|
|
10
10
|
import { readRuntimeMetadata } from '../shared/runtime-metadata.js';
|
|
11
11
|
import { clampResponsesInputItemId } from '../shared/bridge-id-utils.js';
|
|
12
12
|
import { isImagePath } from '../shared/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
16
|
import { createBridgeActionState, runBridgeActionPipeline } from '../shared/bridge-actions.js';
|
|
15
17
|
import { resolveBridgePolicy, resolvePolicyActions } from '../shared/bridge-policies.js';
|
|
@@ -236,65 +238,30 @@ 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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
245
|
+
const captured = captureReqInboundResponsesContextSnapshotWithNative({
|
|
246
|
+
rawRequest: requestForCapture,
|
|
247
|
+
requestId: dto?.route?.requestId,
|
|
248
|
+
toolCallIdStyle: payload?.toolCallIdStyle ?? payload?.metadata?.toolCallIdStyle
|
|
249
|
+
});
|
|
250
|
+
if (preservedInput) {
|
|
251
|
+
captured.input = preservedInput;
|
|
284
252
|
}
|
|
285
|
-
if (
|
|
286
|
-
|
|
253
|
+
if (!captured.systemInstruction && typeof payload.instructions === 'string' && payload.instructions.trim().length) {
|
|
254
|
+
captured.systemInstruction = payload.instructions;
|
|
287
255
|
}
|
|
288
|
-
|
|
289
|
-
return context;
|
|
256
|
+
return captured;
|
|
290
257
|
}
|
|
291
258
|
export function buildChatRequestFromResponses(payload, context) {
|
|
292
259
|
// V3: 对 Responses 路径仅做“形状转换”,不做参数解析/修复。
|
|
293
260
|
// 将顶层 { type,name,description,parameters,strict } 归一为 OpenAI Chat tools 形状:
|
|
294
261
|
// { type:'function', function:{ name,description,parameters,strict? } }
|
|
295
|
-
const toolsNormalized =
|
|
296
|
-
|
|
297
|
-
|
|
262
|
+
const toolsNormalized = Array.isArray(context.toolsNormalized) && context.toolsNormalized.length
|
|
263
|
+
? cloneBridgeEntries(context.toolsNormalized)
|
|
264
|
+
: mapReqInboundBridgeToolsToChatWithNative(payload.tools);
|
|
298
265
|
// 不在 Responses 路径进行 MCP 工具注入;统一由 Chat 后半段治理注入
|
|
299
266
|
let messages = convertBridgeInputToChatMessages({
|
|
300
267
|
input: context.input,
|
|
@@ -614,7 +581,7 @@ export function buildResponsesRequestFromChat(payload, ctx, extras) {
|
|
|
614
581
|
sanitizeBridgeHistory(normalizeBridgeHistory(envelopeMetadata?.bridgeHistory)) ??
|
|
615
582
|
sanitizeBridgeHistory(fallbackHistory);
|
|
616
583
|
const history = historySeed ??
|
|
617
|
-
sanitizeBridgeHistory(
|
|
584
|
+
sanitizeBridgeHistory(buildBridgeHistoryWithNative({
|
|
618
585
|
messages,
|
|
619
586
|
tools: Array.isArray(out.tools) ? out.tools : undefined
|
|
620
587
|
}));
|
|
@@ -4,6 +4,7 @@ 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
6
|
import { ProviderProtocolError } from './errors.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) {
|
|
@@ -564,12 +609,8 @@ export function buildAnthropicFromOpenAIChat(oa, options) {
|
|
|
564
609
|
const argsRaw = fn.arguments;
|
|
565
610
|
let input;
|
|
566
611
|
if (typeof argsRaw === 'string') {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
catch {
|
|
571
|
-
input = { _raw: argsRaw };
|
|
572
|
-
}
|
|
612
|
+
const parsed = parseLenientJsonishWithNative(argsRaw);
|
|
613
|
+
input = parsed && typeof parsed === 'object' ? parsed : { _raw: argsRaw };
|
|
573
614
|
}
|
|
574
615
|
else {
|
|
575
616
|
input = argsRaw ?? {};
|
|
@@ -991,12 +1032,8 @@ export function buildAnthropicRequestFromOpenAIChat(chatReq) {
|
|
|
991
1032
|
const argsRaw = fn.arguments;
|
|
992
1033
|
let input;
|
|
993
1034
|
if (typeof argsRaw === 'string') {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
catch {
|
|
998
|
-
input = { _raw: argsRaw };
|
|
999
|
-
}
|
|
1035
|
+
const parsed = parseLenientJsonishWithNative(argsRaw);
|
|
1036
|
+
input = parsed && typeof parsed === 'object' ? parsed : { _raw: argsRaw };
|
|
1000
1037
|
}
|
|
1001
1038
|
else {
|
|
1002
1039
|
input = argsRaw ?? {};
|
|
@@ -1095,6 +1132,107 @@ function cloneAnthropicSchema(value) {
|
|
|
1095
1132
|
}
|
|
1096
1133
|
return { type: 'object', properties: {} };
|
|
1097
1134
|
}
|
|
1135
|
+
function normalizeAnthropicSchemaType(value) {
|
|
1136
|
+
if (typeof value === 'string') {
|
|
1137
|
+
const trimmed = value.trim().toLowerCase();
|
|
1138
|
+
if (trimmed === 'string' ||
|
|
1139
|
+
trimmed === 'number' ||
|
|
1140
|
+
trimmed === 'integer' ||
|
|
1141
|
+
trimmed === 'boolean' ||
|
|
1142
|
+
trimmed === 'object' ||
|
|
1143
|
+
trimmed === 'array') {
|
|
1144
|
+
return trimmed;
|
|
1145
|
+
}
|
|
1146
|
+
return undefined;
|
|
1147
|
+
}
|
|
1148
|
+
if (Array.isArray(value)) {
|
|
1149
|
+
for (const entry of value) {
|
|
1150
|
+
const normalized = normalizeAnthropicSchemaType(entry);
|
|
1151
|
+
if (normalized) {
|
|
1152
|
+
return normalized;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return undefined;
|
|
1157
|
+
}
|
|
1158
|
+
function compactAnthropicPropertySchema(schema) {
|
|
1159
|
+
if (!isPlainRecord(schema)) {
|
|
1160
|
+
return { type: 'string' };
|
|
1161
|
+
}
|
|
1162
|
+
const out = {};
|
|
1163
|
+
const type = normalizeAnthropicSchemaType(schema.type);
|
|
1164
|
+
if (type) {
|
|
1165
|
+
out.type = type;
|
|
1166
|
+
}
|
|
1167
|
+
if (typeof schema.description === 'string' && schema.description.trim()) {
|
|
1168
|
+
out.description = schema.description;
|
|
1169
|
+
}
|
|
1170
|
+
const enumRaw = Array.isArray(schema.enum) ? schema.enum : undefined;
|
|
1171
|
+
if (enumRaw && enumRaw.length) {
|
|
1172
|
+
const enumValues = enumRaw
|
|
1173
|
+
.filter((entry) => {
|
|
1174
|
+
const entryType = typeof entry;
|
|
1175
|
+
return entryType === 'string' || entryType === 'number' || entryType === 'boolean';
|
|
1176
|
+
})
|
|
1177
|
+
.slice(0, 64);
|
|
1178
|
+
if (enumValues.length) {
|
|
1179
|
+
out.enum = enumValues;
|
|
1180
|
+
if (!out.type) {
|
|
1181
|
+
const inferred = typeof enumValues[0];
|
|
1182
|
+
out.type = inferred === 'boolean' ? 'boolean' : inferred === 'number' ? 'number' : 'string';
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
if (out.type === 'array') {
|
|
1187
|
+
const items = isPlainRecord(schema.items) ? schema.items : {};
|
|
1188
|
+
const itemType = normalizeAnthropicSchemaType(items.type) ?? 'string';
|
|
1189
|
+
out.items = { type: itemType };
|
|
1190
|
+
}
|
|
1191
|
+
else if (out.type === 'object') {
|
|
1192
|
+
out.properties = {};
|
|
1193
|
+
out.additionalProperties = false;
|
|
1194
|
+
}
|
|
1195
|
+
if (!out.type) {
|
|
1196
|
+
out.type = 'string';
|
|
1197
|
+
}
|
|
1198
|
+
return out;
|
|
1199
|
+
}
|
|
1200
|
+
function sanitizeAnthropicBuiltinInputSchema(toolName, schemaSource) {
|
|
1201
|
+
const normalizedName = toolName.trim().toLowerCase();
|
|
1202
|
+
if (!ANTHROPIC_STABLE_TOOL_SCHEMA_NAMES.has(normalizedName)) {
|
|
1203
|
+
return cloneAnthropicSchema(schemaSource);
|
|
1204
|
+
}
|
|
1205
|
+
const source = cloneAnthropicSchema(schemaSource);
|
|
1206
|
+
const sourceProperties = isPlainRecord(source.properties) ? source.properties : {};
|
|
1207
|
+
const allowedKeys = ANTHROPIC_STABLE_TOOL_SCHEMA_KEYS.get(normalizedName);
|
|
1208
|
+
const sanitizedProperties = {};
|
|
1209
|
+
for (const [key, value] of Object.entries(sourceProperties)) {
|
|
1210
|
+
if (allowedKeys && !allowedKeys.has(key)) {
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
sanitizedProperties[key] = compactAnthropicPropertySchema(value);
|
|
1214
|
+
}
|
|
1215
|
+
const required = Array.isArray(source.required)
|
|
1216
|
+
? source.required.filter((entry) => typeof entry === 'string' && entry.trim().length > 0)
|
|
1217
|
+
: [];
|
|
1218
|
+
const filteredRequired = allowedKeys
|
|
1219
|
+
? required.filter((key) => allowedKeys.has(key))
|
|
1220
|
+
: required;
|
|
1221
|
+
for (const key of filteredRequired) {
|
|
1222
|
+
if (!Object.prototype.hasOwnProperty.call(sanitizedProperties, key)) {
|
|
1223
|
+
sanitizedProperties[key] = { type: 'string' };
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
const output = {
|
|
1227
|
+
type: 'object',
|
|
1228
|
+
properties: sanitizedProperties,
|
|
1229
|
+
additionalProperties: false
|
|
1230
|
+
};
|
|
1231
|
+
if (filteredRequired.length) {
|
|
1232
|
+
output.required = Array.from(new Set(filteredRequired));
|
|
1233
|
+
}
|
|
1234
|
+
return output;
|
|
1235
|
+
}
|
|
1098
1236
|
function prepareAnthropicBridgeTools(rawTools, missing) {
|
|
1099
1237
|
if (!Array.isArray(rawTools) || rawTools.length === 0) {
|
|
1100
1238
|
return undefined;
|
|
@@ -1151,7 +1289,7 @@ function convertBridgeToolToAnthropic(def) {
|
|
|
1151
1289
|
? def.description
|
|
1152
1290
|
: undefined;
|
|
1153
1291
|
const schemaSource = fnNode?.parameters ?? def.parameters;
|
|
1154
|
-
const inputSchema =
|
|
1292
|
+
const inputSchema = sanitizeAnthropicBuiltinInputSchema(name, schemaSource);
|
|
1155
1293
|
const tool = {
|
|
1156
1294
|
name,
|
|
1157
1295
|
input_schema: inputSchema
|
|
@@ -1,154 +1,10 @@
|
|
|
1
1
|
import { buildShellDescription, hasApplyPatchToolDeclared, isShellToolName } from '../../tools/tool-description-utils.js';
|
|
2
|
+
import { normalizeArgsBySchemaWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
2
3
|
function isObject(v) {
|
|
3
4
|
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
4
5
|
}
|
|
5
|
-
const normKey = (k) => k.toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
6
|
-
function getDefaultAliases(prop) {
|
|
7
|
-
const p = prop.toLowerCase();
|
|
8
|
-
switch (p) {
|
|
9
|
-
case 'file_path': return ['path', 'file', 'filepath', 'filePath'];
|
|
10
|
-
case 'pattern': return ['glob', 'include', 'includes', 'query', 'regex'];
|
|
11
|
-
case 'content': return ['text', 'data', 'body'];
|
|
12
|
-
case 'old_string': return ['old', 'from', 'before', 'oldString', 'previous'];
|
|
13
|
-
case 'new_string': return ['new', 'to', 'after', 'newString', 'next'];
|
|
14
|
-
case 'command': return ['cmd', 'command_list', 'commandList'];
|
|
15
|
-
case 'path': return ['dir', 'directory'];
|
|
16
|
-
case 'glob': return ['include', 'includes', 'patterns'];
|
|
17
|
-
case 'todos': return ['items', 'list', 'tasks'];
|
|
18
|
-
case 'replace_all': return ['replaceAll', 'all', 'allOccurrences'];
|
|
19
|
-
default: return [];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function buildPropertyMap(schema) {
|
|
23
|
-
const map = new Map();
|
|
24
|
-
const props = schema?.properties || {};
|
|
25
|
-
for (const [p, s] of Object.entries(props)) {
|
|
26
|
-
map.set(normKey(p), p);
|
|
27
|
-
const aliases = s['x-aliases'];
|
|
28
|
-
if (Array.isArray(aliases)) {
|
|
29
|
-
for (const a of aliases) {
|
|
30
|
-
if (typeof a === 'string') {
|
|
31
|
-
map.set(normKey(a), p);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
for (const a of getDefaultAliases(p)) {
|
|
36
|
-
map.set(normKey(a), p);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return map;
|
|
40
|
-
}
|
|
41
|
-
function coerceType(value, schema) {
|
|
42
|
-
const t = schema?.type;
|
|
43
|
-
const want = Array.isArray(t) ? t[0] : t;
|
|
44
|
-
if (!want) {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
switch (want) {
|
|
48
|
-
case 'string':
|
|
49
|
-
if (typeof value === 'string')
|
|
50
|
-
return value;
|
|
51
|
-
if (Array.isArray(value))
|
|
52
|
-
return value.map(v => String(v)).join(' ');
|
|
53
|
-
if (value === null || value === undefined)
|
|
54
|
-
return value;
|
|
55
|
-
return String(value);
|
|
56
|
-
case 'number':
|
|
57
|
-
if (typeof value === 'number')
|
|
58
|
-
return value;
|
|
59
|
-
if (typeof value === 'string') {
|
|
60
|
-
const n = Number(value);
|
|
61
|
-
return Number.isFinite(n) ? n : value;
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
case 'integer':
|
|
65
|
-
if (typeof value === 'number')
|
|
66
|
-
return Math.trunc(value);
|
|
67
|
-
if (typeof value === 'string') {
|
|
68
|
-
const n = parseInt(value, 10);
|
|
69
|
-
return Number.isFinite(n) ? n : value;
|
|
70
|
-
}
|
|
71
|
-
return value;
|
|
72
|
-
case 'boolean':
|
|
73
|
-
if (typeof value === 'boolean')
|
|
74
|
-
return value;
|
|
75
|
-
if (typeof value === 'string') {
|
|
76
|
-
const s = value.toLowerCase();
|
|
77
|
-
if (s === 'true')
|
|
78
|
-
return true;
|
|
79
|
-
if (s === 'false')
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
return value;
|
|
83
|
-
case 'array':
|
|
84
|
-
if (Array.isArray(value))
|
|
85
|
-
return value;
|
|
86
|
-
if (typeof value === 'string') {
|
|
87
|
-
// conservative: split commas/newlines; caller controls format
|
|
88
|
-
const parts = value.split(/[\n,]+/).map(s => s.trim()).filter(Boolean);
|
|
89
|
-
return parts.length ? parts : value;
|
|
90
|
-
}
|
|
91
|
-
return value;
|
|
92
|
-
case 'object':
|
|
93
|
-
if (value && typeof value === 'object')
|
|
94
|
-
return value;
|
|
95
|
-
return value;
|
|
96
|
-
default:
|
|
97
|
-
return value;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
6
|
export function normalizeArgsBySchema(input, schema) {
|
|
101
|
-
|
|
102
|
-
const ok = !!(isObject(input) && Object.keys(input).length > 0);
|
|
103
|
-
return ok ? { ok: true, value: input } : { ok: false, errors: ['no_schema_or_invalid_input'] };
|
|
104
|
-
}
|
|
105
|
-
const propMap = buildPropertyMap(schema);
|
|
106
|
-
const out = {};
|
|
107
|
-
const errors = [];
|
|
108
|
-
const additional = schema.additionalProperties !== false;
|
|
109
|
-
const reqList = Array.isArray(schema.required) ? schema.required : [];
|
|
110
|
-
if (Object.keys(input).length === 1 && typeof input._raw === 'string' && reqList.length === 1) {
|
|
111
|
-
const only = reqList[0];
|
|
112
|
-
const child = (schema.properties || {})[only];
|
|
113
|
-
if (child) {
|
|
114
|
-
const coerced = coerceType(input._raw, child);
|
|
115
|
-
if (typeof coerced === 'string' && coerced.trim().length > 0)
|
|
116
|
-
out[only] = coerced;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const [k, v] of Object.entries(input)) {
|
|
120
|
-
const key = normKey(k);
|
|
121
|
-
const target = propMap.get(key);
|
|
122
|
-
if (target) {
|
|
123
|
-
const childSchema = schema.properties[target];
|
|
124
|
-
out[target] = coerceType(v, childSchema);
|
|
125
|
-
}
|
|
126
|
-
else if (additional) {
|
|
127
|
-
out[k] = v;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const req = schema.required || [];
|
|
131
|
-
for (const r of req) {
|
|
132
|
-
if (!(r in out)) {
|
|
133
|
-
errors.push(`missing_required:${r}`);
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const v = out[r];
|
|
137
|
-
if (typeof v === 'string' && v.trim().length === 0) {
|
|
138
|
-
errors.push(`missing_required:${r}`);
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (Array.isArray(v) && v.length === 0) {
|
|
142
|
-
errors.push(`missing_required:${r}`);
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
if (v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) {
|
|
146
|
-
errors.push(`missing_required:${r}`);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const ok = errors.length === 0;
|
|
151
|
-
return ok ? { ok, value: out } : { ok, value: out, errors };
|
|
7
|
+
return normalizeArgsBySchemaWithNative(input, schema);
|
|
152
8
|
}
|
|
153
9
|
// Tools normalizer (OpenAI-like)
|
|
154
10
|
export function normalizeTools(tools) {
|