@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isClientInjectReady(metadata: Record<string, unknown>): boolean;
|
|
@@ -6,6 +6,7 @@ import { AnthropicSemanticMapper } from './semantic-mappers/anthropic-mapper.js'
|
|
|
6
6
|
import { ResponsesSemanticMapper } from './semantic-mappers/responses-mapper.js';
|
|
7
7
|
import { GeminiSemanticMapper } from './semantic-mappers/gemini-mapper.js';
|
|
8
8
|
import { GeminiFormatAdapter } from './format-adapters/gemini-format-adapter.js';
|
|
9
|
+
import { normalizeProviderProtocolTokenWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
9
10
|
export const HUB_PROTOCOL_REGISTRY = {
|
|
10
11
|
'openai-chat': {
|
|
11
12
|
protocol: 'openai-chat',
|
|
@@ -87,9 +88,11 @@ function instantiateOutbound(factory) {
|
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
90
|
export function createProtocolPlans(protocol) {
|
|
90
|
-
const
|
|
91
|
+
const normalizedProtocol = normalizeProviderProtocolTokenWithNative(protocol);
|
|
92
|
+
const protocolKey = normalizedProtocol ?? protocol;
|
|
93
|
+
const definition = HUB_PROTOCOL_REGISTRY[protocolKey];
|
|
91
94
|
if (!definition) {
|
|
92
|
-
throw new Error(`Unknown hub protocol: ${
|
|
95
|
+
throw new Error(`Unknown hub protocol: ${protocolKey}`);
|
|
93
96
|
}
|
|
94
97
|
return {
|
|
95
98
|
inbound: instantiateInbound(definition.inbound),
|
|
@@ -1,89 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const content = (message && typeof message === 'object') ? message.content : undefined;
|
|
3
|
-
if (Array.isArray(content)) {
|
|
4
|
-
return content
|
|
5
|
-
.map((part) => {
|
|
6
|
-
if (!part)
|
|
7
|
-
return '';
|
|
8
|
-
if (typeof part === 'string')
|
|
9
|
-
return part;
|
|
10
|
-
if (typeof part.text === 'string')
|
|
11
|
-
return part.text;
|
|
12
|
-
if (typeof part.content === 'string')
|
|
13
|
-
return part.content;
|
|
14
|
-
return '';
|
|
15
|
-
})
|
|
16
|
-
.filter(Boolean)
|
|
17
|
-
.join('\n');
|
|
18
|
-
}
|
|
19
|
-
if (typeof content === 'string')
|
|
20
|
-
return content;
|
|
21
|
-
return '';
|
|
22
|
-
}
|
|
23
|
-
function mapToolCalls(toolCalls) {
|
|
24
|
-
if (!Array.isArray(toolCalls))
|
|
25
|
-
return undefined;
|
|
26
|
-
return toolCalls
|
|
27
|
-
.map((tc) => {
|
|
28
|
-
if (!tc || typeof tc !== 'object')
|
|
29
|
-
return null;
|
|
30
|
-
const fn = tc.function || {};
|
|
31
|
-
if (typeof fn?.name !== 'string')
|
|
32
|
-
return null;
|
|
33
|
-
const args = typeof fn?.arguments === 'string' ? fn.arguments : (() => {
|
|
34
|
-
try {
|
|
35
|
-
return JSON.stringify(fn?.arguments ?? {});
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return '{}';
|
|
39
|
-
}
|
|
40
|
-
})();
|
|
41
|
-
return {
|
|
42
|
-
id: typeof tc.id === 'string' ? tc.id : `call_${Math.random().toString(36).slice(2, 10)}`,
|
|
43
|
-
type: 'function',
|
|
44
|
-
function: {
|
|
45
|
-
name: fn.name,
|
|
46
|
-
arguments: args
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
})
|
|
50
|
-
.filter(Boolean);
|
|
51
|
-
}
|
|
1
|
+
import { buildProcessedRequestFromChatResponseWithNative } from '../../../router/virtual-router/engine-selection/native-chat-process-node-result-semantics.js';
|
|
52
2
|
export function buildProcessedRequestFromChatResponse(chatResponse, options) {
|
|
53
3
|
const streamingEnabled = options?.stream === true;
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const assistantMessage = {
|
|
59
|
-
role: 'assistant',
|
|
60
|
-
content,
|
|
61
|
-
tool_calls: toolCalls
|
|
62
|
-
};
|
|
63
|
-
const processedRequest = {
|
|
64
|
-
model: typeof chatResponse?.model === 'string' ? chatResponse.model : 'unknown',
|
|
65
|
-
messages: [assistantMessage],
|
|
66
|
-
tools: undefined,
|
|
67
|
-
parameters: {},
|
|
68
|
-
metadata: {
|
|
69
|
-
originalEndpoint: 'openai-chat',
|
|
70
|
-
...(streamingEnabled ? { stream: true } : {})
|
|
71
|
-
},
|
|
72
|
-
processed: {
|
|
73
|
-
timestamp: Date.now(),
|
|
74
|
-
appliedRules: ['response-pipeline'],
|
|
75
|
-
status: 'success'
|
|
76
|
-
},
|
|
77
|
-
processingMetadata: {
|
|
78
|
-
streaming: {
|
|
79
|
-
enabled: streamingEnabled,
|
|
80
|
-
chunkCount: 0,
|
|
81
|
-
totalTokens: typeof chatResponse?.usage?.completion_tokens === 'number'
|
|
82
|
-
? chatResponse.usage.completion_tokens
|
|
83
|
-
: 0
|
|
84
|
-
},
|
|
85
|
-
context: {}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return processedRequest;
|
|
4
|
+
const payload = chatResponse && typeof chatResponse === 'object' && !Array.isArray(chatResponse)
|
|
5
|
+
? chatResponse
|
|
6
|
+
: { choices: [] };
|
|
7
|
+
return buildProcessedRequestFromChatResponseWithNative(payload, streamingEnabled);
|
|
89
8
|
}
|
|
@@ -32,6 +32,15 @@ export interface ProviderResponseConversionOptions {
|
|
|
32
32
|
body: JsonObject;
|
|
33
33
|
metadata?: JsonObject;
|
|
34
34
|
}) => Promise<ProviderResponseConversionResult>;
|
|
35
|
+
clientInjectDispatch?: (options: {
|
|
36
|
+
entryEndpoint: string;
|
|
37
|
+
requestId: string;
|
|
38
|
+
body?: JsonObject;
|
|
39
|
+
metadata?: JsonObject;
|
|
40
|
+
}) => Promise<{
|
|
41
|
+
ok: boolean;
|
|
42
|
+
reason?: string;
|
|
43
|
+
}>;
|
|
35
44
|
}
|
|
36
45
|
export interface ProviderResponseConversionResult {
|
|
37
46
|
body?: JsonObject;
|
|
@@ -18,6 +18,7 @@ import { recordResponsesResponse } from '../../shared/responses-conversation-sto
|
|
|
18
18
|
import { ProviderProtocolError } from '../../shared/errors.js';
|
|
19
19
|
import { readRuntimeMetadata } from '../../shared/runtime-metadata.js';
|
|
20
20
|
import { commitClockReservation, resolveClockConfig } from '../../../servertool/clock/task-store.js';
|
|
21
|
+
import { detectProviderResponseShapeWithNative } from '../../../router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js';
|
|
21
22
|
const PROVIDER_RESPONSE_REGISTRY = {
|
|
22
23
|
'openai-chat': {
|
|
23
24
|
createFormatAdapter: () => new ChatFormatAdapter(),
|
|
@@ -103,21 +104,6 @@ async function maybeCommitClockReservationFromContext(context) {
|
|
|
103
104
|
// best-effort: never break response conversion due to clock persistence errors
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
|
-
function detectProviderResponseShape(payload) {
|
|
107
|
-
if (!isJsonRecord(payload))
|
|
108
|
-
return 'unknown';
|
|
109
|
-
const obj = payload;
|
|
110
|
-
if (Array.isArray(obj.choices))
|
|
111
|
-
return 'openai-chat';
|
|
112
|
-
if (Array.isArray(obj.output) || obj.object === 'response')
|
|
113
|
-
return 'openai-responses';
|
|
114
|
-
if (typeof obj.type === 'string' && String(obj.type).toLowerCase() === 'message' && Array.isArray(obj.content)) {
|
|
115
|
-
return 'anthropic-messages';
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(obj.candidates))
|
|
118
|
-
return 'gemini-chat';
|
|
119
|
-
return 'unknown';
|
|
120
|
-
}
|
|
121
107
|
function inferProviderTypeFromProtocol(protocol) {
|
|
122
108
|
const p = typeof protocol === 'string' ? protocol.trim().toLowerCase() : '';
|
|
123
109
|
if (!p)
|
|
@@ -150,7 +136,7 @@ async function coerceClientPayloadToCanonicalChatCompletionOrThrow(options) {
|
|
|
150
136
|
if (isCanonicalChatCompletion(options.payload)) {
|
|
151
137
|
return options.payload;
|
|
152
138
|
}
|
|
153
|
-
const detected =
|
|
139
|
+
const detected = detectProviderResponseShapeWithNative(options.payload);
|
|
154
140
|
if (detected === 'unknown') {
|
|
155
141
|
const protocol = options.adapterContext?.providerProtocol;
|
|
156
142
|
throw new ProviderProtocolError(`[hub_response] Non-canonical response payload at ${options.scope}`, {
|
|
@@ -309,19 +295,17 @@ export async function convertProviderResponse(options) {
|
|
|
309
295
|
stageRecorder: options.stageRecorder
|
|
310
296
|
});
|
|
311
297
|
stripInternalPolicyDebugFields(compatPayload);
|
|
312
|
-
const formatAdapter = plan.createFormatAdapter();
|
|
313
298
|
const mapper = plan.createMapper();
|
|
314
299
|
const formatEnvelope = await runRespInboundStage2FormatParse({
|
|
315
300
|
adapterContext: options.context,
|
|
316
301
|
payload: compatPayload,
|
|
317
|
-
formatAdapter,
|
|
318
302
|
stageRecorder: options.stageRecorder
|
|
319
303
|
});
|
|
320
304
|
// Phase 2 (shadow): response tool surface mismatch detection (provider inbound).
|
|
321
305
|
// Only records diffs; does not rewrite payload.
|
|
322
306
|
try {
|
|
323
307
|
if (options.stageRecorder && isToolSurfaceShadowEnabled()) {
|
|
324
|
-
const detected =
|
|
308
|
+
const detected = detectProviderResponseShapeWithNative(formatEnvelope.payload);
|
|
325
309
|
if (detected !== 'unknown' && detected !== options.providerProtocol) {
|
|
326
310
|
const summary = summarizeToolCallsFromProviderResponse(formatEnvelope.payload);
|
|
327
311
|
options.stageRecorder.record('hub_toolsurface.shadow.provider_inbound', {
|
|
@@ -371,7 +355,8 @@ export async function convertProviderResponse(options) {
|
|
|
371
355
|
providerProtocol: options.providerProtocol,
|
|
372
356
|
stageRecorder: options.stageRecorder,
|
|
373
357
|
providerInvoker: options.providerInvoker,
|
|
374
|
-
reenterPipeline: options.reenterPipeline
|
|
358
|
+
reenterPipeline: options.reenterPipeline,
|
|
359
|
+
clientInjectDispatch: options.clientInjectDispatch
|
|
375
360
|
});
|
|
376
361
|
let effectiveChatResponse = orchestration.payload;
|
|
377
362
|
// Hard gate: response-side chat_process requires an OpenAI-chat-like surface (choices[].message).
|
|
@@ -423,7 +408,7 @@ export async function convertProviderResponse(options) {
|
|
|
423
408
|
// Phase 2 (shadow): response tool surface mismatch detection (client outbound).
|
|
424
409
|
try {
|
|
425
410
|
if (options.stageRecorder && isToolSurfaceShadowEnabled()) {
|
|
426
|
-
const detected =
|
|
411
|
+
const detected = detectProviderResponseShapeWithNative(clientPayload);
|
|
427
412
|
if (detected !== 'unknown' && detected !== clientProtocol) {
|
|
428
413
|
const summary = summarizeToolCallsFromProviderResponse(clientPayload);
|
|
429
414
|
options.stageRecorder.record('hub_toolsurface.shadow.client_outbound', {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { buildOpenAIChatFromGeminiResponse } from '../../codecs/gemini-openai-codec.js';
|
|
2
2
|
import { buildChatResponseFromResponses } from '../../shared/responses-response-utils.js';
|
|
3
3
|
import { buildOpenAIChatFromAnthropicMessage } from './response-runtime.js';
|
|
4
|
+
import { resolveAliasMapFromRespSemanticsWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
4
5
|
export class OpenAIChatResponseMapper {
|
|
5
6
|
toChatCompletion(format, _ctx) {
|
|
6
7
|
return (format.payload ?? {});
|
|
@@ -13,7 +14,7 @@ export class ResponsesResponseMapper {
|
|
|
13
14
|
}
|
|
14
15
|
export class AnthropicResponseMapper {
|
|
15
16
|
toChatCompletion(format, _ctx, options) {
|
|
16
|
-
const aliasMap =
|
|
17
|
+
const aliasMap = resolveAliasMapFromRespSemanticsWithNative(options?.requestSemantics);
|
|
17
18
|
return buildOpenAIChatFromAnthropicMessage(format.payload ?? {}, { aliasMap });
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -22,28 +23,3 @@ export class GeminiResponseMapper {
|
|
|
22
23
|
return buildOpenAIChatFromGeminiResponse(format.payload ?? {});
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
function extractToolNameAliasMapFromSemantics(semantics) {
|
|
26
|
-
if (!semantics || typeof semantics !== 'object' || Array.isArray(semantics)) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const toolsNode = semantics.tools;
|
|
30
|
-
const candidate = toolsNode && typeof toolsNode === 'object' && !Array.isArray(toolsNode)
|
|
31
|
-
? toolsNode.toolNameAliasMap
|
|
32
|
-
: undefined;
|
|
33
|
-
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
const normalized = {};
|
|
37
|
-
for (const [key, value] of Object.entries(candidate)) {
|
|
38
|
-
if (typeof key !== 'string' || typeof value !== 'string') {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const trimmedKey = key.trim();
|
|
42
|
-
const trimmedValue = value.trim();
|
|
43
|
-
if (!trimmedKey.length || !trimmedValue.length) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
normalized[trimmedKey] = trimmedValue;
|
|
47
|
-
}
|
|
48
|
-
return Object.keys(normalized).length ? normalized : undefined;
|
|
49
|
-
}
|
|
@@ -3,6 +3,7 @@ import { deriveToolCallKey } from '../../shared/tool-call-utils.js';
|
|
|
3
3
|
import { createBridgeActionState, runBridgeActionPipeline } from '../../shared/bridge-actions.js';
|
|
4
4
|
import { resolveBridgePolicy, resolvePolicyActions } from '../../shared/bridge-policies.js';
|
|
5
5
|
import { normalizeAnthropicToolName } from '../../shared/anthropic-message-utils.js';
|
|
6
|
+
import { buildAnthropicResponseFromChatWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
6
7
|
import { registerResponsesReasoning, consumeResponsesReasoning, registerResponsesOutputTextMeta, consumeResponsesOutputTextMeta, consumeResponsesPayloadSnapshot, registerResponsesPayloadSnapshot, consumeResponsesPassthrough, registerResponsesPassthrough } from '../../shared/responses-reasoning-registry.js';
|
|
7
8
|
function flattenAnthropicContent(content) {
|
|
8
9
|
if (typeof content === 'string')
|
|
@@ -348,7 +349,6 @@ export function buildAnthropicResponseFromChat(chatResponse, options) {
|
|
|
348
349
|
const choice = Array.isArray(chatResponse?.choices) ? chatResponse.choices[0] : undefined;
|
|
349
350
|
const message = choice && typeof choice === 'object' ? choice.message : undefined;
|
|
350
351
|
const aliasMap = options?.aliasMap;
|
|
351
|
-
const outboundAliasSerializer = createToolAliasSerializer(aliasMap);
|
|
352
352
|
if (message) {
|
|
353
353
|
try {
|
|
354
354
|
const bridgePolicy = resolveBridgePolicy({ protocol: 'anthropic-messages' });
|
|
@@ -371,98 +371,7 @@ export function buildAnthropicResponseFromChat(chatResponse, options) {
|
|
|
371
371
|
// ignore policy failures
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
-
const
|
|
375
|
-
const toolCalls = Array.isArray(message?.tool_calls) ? message.tool_calls : [];
|
|
376
|
-
const contentBlocks = [];
|
|
377
|
-
const reasoningRaw = message?.reasoning_content ?? message?.reasoning;
|
|
378
|
-
const reasoningText = typeof reasoningRaw === 'string'
|
|
379
|
-
? reasoningRaw.trim()
|
|
380
|
-
: flattenAnthropicContent(reasoningRaw).trim();
|
|
381
|
-
if (reasoningText) {
|
|
382
|
-
contentBlocks.push({ type: 'thinking', text: reasoningText });
|
|
383
|
-
}
|
|
384
|
-
if (text && text.trim().length) {
|
|
385
|
-
contentBlocks.push({ type: 'text', text });
|
|
386
|
-
}
|
|
387
|
-
for (const call of toolCalls) {
|
|
388
|
-
if (!call || typeof call !== 'object')
|
|
389
|
-
continue;
|
|
390
|
-
const fn = call.function || {};
|
|
391
|
-
if (typeof fn?.name !== 'string')
|
|
392
|
-
continue;
|
|
393
|
-
const canonicalName = normalizeAnthropicToolName(fn.name) ?? fn.name;
|
|
394
|
-
const serializedName = outboundAliasSerializer(canonicalName || fn.name);
|
|
395
|
-
let parsedArgs = {};
|
|
396
|
-
const args = fn.arguments;
|
|
397
|
-
if (typeof args === 'string') {
|
|
398
|
-
try {
|
|
399
|
-
parsedArgs = JSON.parse(args);
|
|
400
|
-
}
|
|
401
|
-
catch {
|
|
402
|
-
parsedArgs = { _raw: args };
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
parsedArgs = args ?? {};
|
|
407
|
-
}
|
|
408
|
-
if ((canonicalName || '').trim() === 'shell_command') {
|
|
409
|
-
parsedArgs = mapShellCommandArgsForAnthropic(parsedArgs);
|
|
410
|
-
}
|
|
411
|
-
contentBlocks.push({
|
|
412
|
-
type: 'tool_use',
|
|
413
|
-
id: sanitizeAnthropicToolUseId(call.id),
|
|
414
|
-
name: serializedName,
|
|
415
|
-
input: parsedArgs
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
const toolResults = extractToolResultBlocks(chatResponse);
|
|
419
|
-
for (const block of toolResults) {
|
|
420
|
-
const sanitized = {
|
|
421
|
-
type: 'tool_result',
|
|
422
|
-
tool_use_id: block.tool_use_id,
|
|
423
|
-
content: block.content ?? ''
|
|
424
|
-
};
|
|
425
|
-
if (typeof block.is_error === 'boolean') {
|
|
426
|
-
sanitized.is_error = block.is_error;
|
|
427
|
-
}
|
|
428
|
-
contentBlocks.push(sanitized);
|
|
429
|
-
}
|
|
430
|
-
const usage = chatResponse?.usage;
|
|
431
|
-
const usageInputTokens = usage && typeof usage === 'object'
|
|
432
|
-
? coerceNonNegativeNumber(usage.input_tokens, usage.prompt_tokens)
|
|
433
|
-
: undefined;
|
|
434
|
-
const usageOutputTokens = usage && typeof usage === 'object'
|
|
435
|
-
? coerceNonNegativeNumber(usage.output_tokens, usage.completion_tokens)
|
|
436
|
-
: undefined;
|
|
437
|
-
const stopReason = typeof choice?.finish_reason === 'string'
|
|
438
|
-
? choice.finish_reason
|
|
439
|
-
: undefined;
|
|
440
|
-
const stopReasonMapped = (() => {
|
|
441
|
-
switch (stopReason) {
|
|
442
|
-
case 'tool_calls': return 'tool_use';
|
|
443
|
-
case 'length': return 'max_tokens';
|
|
444
|
-
case 'content_filter': return 'stop_sequence';
|
|
445
|
-
default: return 'end_turn';
|
|
446
|
-
}
|
|
447
|
-
})();
|
|
448
|
-
const canonicalId = typeof chatResponse.request_id === 'string'
|
|
449
|
-
? chatResponse.request_id
|
|
450
|
-
: (typeof chatResponse.id === 'string' ? chatResponse.id : `resp_${Date.now()}`);
|
|
451
|
-
const raw = {
|
|
452
|
-
id: canonicalId,
|
|
453
|
-
type: 'message',
|
|
454
|
-
role: 'assistant',
|
|
455
|
-
content: contentBlocks,
|
|
456
|
-
model: typeof chatResponse.model === 'string' ? chatResponse.model : 'unknown',
|
|
457
|
-
stop_reason: stopReasonMapped,
|
|
458
|
-
usage: usage && typeof usage === 'object'
|
|
459
|
-
? {
|
|
460
|
-
input_tokens: usageInputTokens ?? 0,
|
|
461
|
-
output_tokens: usageOutputTokens ?? 0
|
|
462
|
-
}
|
|
463
|
-
: undefined
|
|
464
|
-
};
|
|
465
|
-
const sanitized = sanitizeAnthropicMessage(raw);
|
|
374
|
+
const sanitized = buildAnthropicResponseFromChatWithNative(chatResponse, aliasMap);
|
|
466
375
|
if (Array.isArray(chatResponse?.__responses_reasoning)) {
|
|
467
376
|
registerResponsesReasoning(sanitized.id, chatResponse.__responses_reasoning);
|
|
468
377
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSnapshotWriter } from '../shared/snapshot-utils.js';
|
|
2
2
|
import { jsonClone } from './types/json.js';
|
|
3
|
+
import { parseLenientJsonishWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
4
|
export class SnapshotStageRecorder {
|
|
4
5
|
options;
|
|
5
6
|
writer;
|
|
@@ -85,9 +86,6 @@ function buildOpenAIChatSnapshot(envelope) {
|
|
|
85
86
|
return snapshot;
|
|
86
87
|
}
|
|
87
88
|
function buildMetaSnapshot(metadata) {
|
|
88
|
-
if (!metadata || typeof metadata !== 'object') {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
89
|
const meta = {};
|
|
92
90
|
if (metadata.context) {
|
|
93
91
|
meta.context = jsonClone(metadata.context);
|
|
@@ -111,6 +109,15 @@ function buildMetaSnapshot(metadata) {
|
|
|
111
109
|
return Object.keys(meta).length ? meta : undefined;
|
|
112
110
|
}
|
|
113
111
|
function cloneJson(payload) {
|
|
112
|
+
try {
|
|
113
|
+
const nativeCloned = parseLenientJsonishWithNative(payload);
|
|
114
|
+
if (nativeCloned && typeof nativeCloned === 'object' && !Array.isArray(nativeCloned)) {
|
|
115
|
+
return nativeCloned;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// native clone is best-effort
|
|
120
|
+
}
|
|
114
121
|
try {
|
|
115
122
|
return JSON.parse(JSON.stringify(payload));
|
|
116
123
|
}
|