@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
package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js
CHANGED
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
import { defaultSseCodecRegistry } from '../../../../../../sse/index.js';
|
|
2
2
|
import { recordStage } from '../../../stages/utils.js';
|
|
3
3
|
import { ProviderProtocolError } from '../../../../../shared/errors.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
function findSseWrapperError(record, depth) {
|
|
8
|
-
if (!record || typeof record !== 'object' || depth < 0) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
const mode = record.mode;
|
|
12
|
-
const errVal = record.error;
|
|
13
|
-
if (mode === 'sse' && typeof errVal === 'string' && errVal.trim()) {
|
|
14
|
-
return errVal.trim();
|
|
15
|
-
}
|
|
16
|
-
const nestedKeys = ['body', 'data', 'payload', 'response'];
|
|
17
|
-
for (const key of nestedKeys) {
|
|
18
|
-
const nested = record[key];
|
|
19
|
-
if (!nested || typeof nested !== 'object' || Array.isArray(nested)) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
const found = findSseWrapperError(nested, depth - 1);
|
|
23
|
-
if (found) {
|
|
24
|
-
return found;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
4
|
+
import { extractContextLengthDiagnosticsWithNative, extractSseWrapperErrorWithNative, isContextLengthExceededSignalWithNative, parseJsonObjectCandidateWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
5
|
+
import { tryDecodeJsonBodyFromStream } from './stream-json-sniffer.js';
|
|
29
6
|
function resolveProviderType(protocol) {
|
|
30
7
|
if (protocol === 'openai-chat')
|
|
31
8
|
return 'openai';
|
|
@@ -37,66 +14,12 @@ function resolveProviderType(protocol) {
|
|
|
37
14
|
return 'gemini';
|
|
38
15
|
return undefined;
|
|
39
16
|
}
|
|
40
|
-
function
|
|
41
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
42
|
-
return Math.floor(value);
|
|
43
|
-
}
|
|
44
|
-
if (typeof value === 'string') {
|
|
45
|
-
const trimmed = value.trim();
|
|
46
|
-
if (!trimmed.length) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
const parsed = Number(trimmed);
|
|
50
|
-
if (Number.isFinite(parsed)) {
|
|
51
|
-
return Math.floor(parsed);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
function readObject(value) {
|
|
17
|
+
function readObjectFallback(value) {
|
|
57
18
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
58
19
|
return undefined;
|
|
59
20
|
}
|
|
60
21
|
return value;
|
|
61
22
|
}
|
|
62
|
-
function extractContextLengthDiagnostics(adapterContext) {
|
|
63
|
-
const ctx = readObject(adapterContext);
|
|
64
|
-
if (!ctx) {
|
|
65
|
-
return {};
|
|
66
|
-
}
|
|
67
|
-
const runtimeNode = readObject(ctx.__rt);
|
|
68
|
-
const targetNode = readObject(ctx.target);
|
|
69
|
-
const estimatedPromptTokens = readFiniteNumber(ctx.estimatedInputTokens) ??
|
|
70
|
-
readFiniteNumber(ctx.requestTokens) ??
|
|
71
|
-
readFiniteNumber(ctx.reqTokens) ??
|
|
72
|
-
readFiniteNumber(runtimeNode?.estimatedInputTokens) ??
|
|
73
|
-
readFiniteNumber(runtimeNode?.requestTokens) ??
|
|
74
|
-
readFiniteNumber(runtimeNode?.reqTokens);
|
|
75
|
-
const maxContextTokens = readFiniteNumber(targetNode?.maxContextTokens) ??
|
|
76
|
-
readFiniteNumber(ctx.maxContextTokens) ??
|
|
77
|
-
readFiniteNumber(runtimeNode?.maxContextTokens);
|
|
78
|
-
return {
|
|
79
|
-
...(typeof estimatedPromptTokens === 'number' ? { estimatedPromptTokens } : {}),
|
|
80
|
-
...(typeof maxContextTokens === 'number' ? { maxContextTokens } : {})
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function isContextLengthExceededSignal(args) {
|
|
84
|
-
const code = typeof args.code === 'string' ? args.code.trim().toLowerCase() : '';
|
|
85
|
-
if (code.includes('context_length_exceeded')) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
const message = args.message.toLowerCase();
|
|
89
|
-
if (message.includes('context_length_exceeded') || message.includes('达到对话长度上限') || message.includes('对话长度上限')) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
const finishReason = typeof args.context?.errorData === 'object' &&
|
|
93
|
-
args.context.errorData &&
|
|
94
|
-
!Array.isArray(args.context.errorData) &&
|
|
95
|
-
typeof args.context.errorData.finish_reason === 'string'
|
|
96
|
-
? String(args.context.errorData.finish_reason).trim().toLowerCase()
|
|
97
|
-
: '';
|
|
98
|
-
return finishReason === 'context_length_exceeded';
|
|
99
|
-
}
|
|
100
23
|
export async function runRespInboundStage1SseDecode(options) {
|
|
101
24
|
// Transport compatibility: some HTTP clients return JSON bodies as plain strings when the upstream
|
|
102
25
|
// mislabels `Content-Type`. Best-effort parse JSON text early so downstream format adapters and
|
|
@@ -111,7 +34,7 @@ export async function runRespInboundStage1SseDecode(options) {
|
|
|
111
34
|
});
|
|
112
35
|
return { payload: maybeJsonText, decodedFromSse: false };
|
|
113
36
|
}
|
|
114
|
-
const wrapperError =
|
|
37
|
+
const wrapperError = extractSseWrapperErrorWithNative(options.payload);
|
|
115
38
|
const stream = extractSseStream(options.payload);
|
|
116
39
|
// 某些 mock-provider / 捕获样本在 SSE 连接被异常终止时会携带 error 标记,
|
|
117
40
|
// 即使仍保留 __sse_responses 流,也应视为上游异常并终止。
|
|
@@ -187,13 +110,9 @@ export async function runRespInboundStage1SseDecode(options) {
|
|
|
187
110
|
const message = error instanceof Error ? error.message : String(error);
|
|
188
111
|
const errRecord = error;
|
|
189
112
|
const upstreamCode = typeof errRecord.code === 'string' ? errRecord.code : undefined;
|
|
190
|
-
const upstreamContext =
|
|
191
|
-
const contextLengthExceeded =
|
|
192
|
-
|
|
193
|
-
message,
|
|
194
|
-
context: upstreamContext
|
|
195
|
-
});
|
|
196
|
-
const diagnostics = extractContextLengthDiagnostics(options.adapterContext);
|
|
113
|
+
const upstreamContext = readObjectFallback(errRecord.context);
|
|
114
|
+
const contextLengthExceeded = isContextLengthExceededSignalWithNative(upstreamCode, message, upstreamContext);
|
|
115
|
+
const diagnostics = extractContextLengthDiagnosticsWithNative(options.adapterContext);
|
|
197
116
|
recordStage(options.stageRecorder, 'chat_process.resp.stage1.sse_decode', {
|
|
198
117
|
streamDetected: true,
|
|
199
118
|
decoded: false,
|
|
@@ -223,118 +142,11 @@ function supportsSseProtocol(protocol) {
|
|
|
223
142
|
return protocol === 'openai-chat' || protocol === 'openai-responses' || protocol === 'anthropic-messages' || protocol === 'gemini-chat';
|
|
224
143
|
}
|
|
225
144
|
function tryDecodeJsonBodyFromText(payload) {
|
|
226
|
-
|
|
227
|
-
if (typeof payload !== 'string') {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
// Normalize common prefixes / wrappers from OpenAI-compatible upstreams.
|
|
231
|
-
let text = payload.trimStart();
|
|
232
|
-
// anti-XSSI prefix: ")]}',\n{...}"
|
|
233
|
-
text = text.replace(/^\)\]\}',?\s*/u, '');
|
|
234
|
-
// single-line SSE-like wrapper sometimes returned as plain text
|
|
235
|
-
text = text.replace(/^data:\s*/iu, '');
|
|
236
|
-
const looksLikeJson = text.startsWith('{') || text.startsWith('[');
|
|
237
|
-
if (!looksLikeJson) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
// Guard: avoid unbounded parsing for pathological payloads.
|
|
241
|
-
if (text.length > 10 * 1024 * 1024) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
const parsed = JSON.parse(text);
|
|
245
|
-
return (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) ? parsed : null;
|
|
246
|
-
}
|
|
247
|
-
catch {
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
async function tryDecodeJsonBodyFromStream(stream) {
|
|
252
|
-
// Peek the first chunk; if it looks like JSON (starts with `{` or `[`), consume full body and parse.
|
|
253
|
-
const iterator = stream[Symbol.asyncIterator]();
|
|
254
|
-
const first = await iterator.next();
|
|
255
|
-
if (first.done || first.value == null) {
|
|
145
|
+
if (typeof payload !== 'string') {
|
|
256
146
|
return null;
|
|
257
147
|
}
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
let prefix = chunkToUtf8(firstChunk).trimStart();
|
|
261
|
-
prefix = prefix.replace(/^\)\]\}',?\s*/u, '');
|
|
262
|
-
prefix = prefix.replace(/^data:\s*/iu, '');
|
|
263
|
-
const looksLikeJson = prefix.startsWith('{') || prefix.startsWith('[');
|
|
264
|
-
if (!looksLikeJson) {
|
|
265
|
-
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
let body = chunkToUtf8(firstChunk);
|
|
269
|
-
while (true) {
|
|
270
|
-
const next = await iterator.next();
|
|
271
|
-
if (next.done)
|
|
272
|
-
break;
|
|
273
|
-
consumedChunks.push(next.value);
|
|
274
|
-
body += chunkToUtf8(next.value);
|
|
275
|
-
// Guard: avoid unbounded buffering if the upstream is actually SSE but starts with whitespace.
|
|
276
|
-
if (body.length > 1024 * 1024) {
|
|
277
|
-
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
try {
|
|
282
|
-
const parsed = JSON.parse(body);
|
|
283
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
284
|
-
return parsed;
|
|
285
|
-
}
|
|
286
|
-
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function chunkToUtf8(chunk) {
|
|
295
|
-
if (typeof chunk === 'string') {
|
|
296
|
-
return chunk;
|
|
297
|
-
}
|
|
298
|
-
if (Buffer.isBuffer(chunk)) {
|
|
299
|
-
return chunk.toString('utf8');
|
|
300
|
-
}
|
|
301
|
-
if (chunk instanceof Uint8Array) {
|
|
302
|
-
return Buffer.from(chunk).toString('utf8');
|
|
303
|
-
}
|
|
304
|
-
if (chunk instanceof ArrayBuffer) {
|
|
305
|
-
return Buffer.from(new Uint8Array(chunk)).toString('utf8');
|
|
306
|
-
}
|
|
307
|
-
return String(chunk ?? '');
|
|
308
|
-
}
|
|
309
|
-
function rewindStreamWithConsumedChunks(stream, consumedChunks, iterator) {
|
|
310
|
-
// Rewind by re-wrapping the iterator so downstream SSE decoder still sees everything consumed here.
|
|
311
|
-
// eslint-disable-next-line no-param-reassign
|
|
312
|
-
stream[Symbol.asyncIterator] = () => replayIterator(consumedChunks, iterator);
|
|
313
|
-
}
|
|
314
|
-
function replayIterator(consumedChunks, iterator) {
|
|
315
|
-
let replayIndex = 0;
|
|
316
|
-
return {
|
|
317
|
-
async next() {
|
|
318
|
-
if (replayIndex < consumedChunks.length) {
|
|
319
|
-
const value = consumedChunks[replayIndex];
|
|
320
|
-
replayIndex += 1;
|
|
321
|
-
return { done: false, value };
|
|
322
|
-
}
|
|
323
|
-
return iterator.next();
|
|
324
|
-
},
|
|
325
|
-
async return(value) {
|
|
326
|
-
if (typeof iterator.return === 'function') {
|
|
327
|
-
return iterator.return(value);
|
|
328
|
-
}
|
|
329
|
-
return { done: true, value };
|
|
330
|
-
},
|
|
331
|
-
async throw(err) {
|
|
332
|
-
if (typeof iterator.throw === 'function') {
|
|
333
|
-
return iterator.throw(err);
|
|
334
|
-
}
|
|
335
|
-
throw err;
|
|
336
|
-
}
|
|
337
|
-
};
|
|
148
|
+
const parsed = parseJsonObjectCandidateWithNative(payload, 10 * 1024 * 1024);
|
|
149
|
+
return parsed ?? null;
|
|
338
150
|
}
|
|
339
151
|
function extractSseStream(payload) {
|
|
340
152
|
if (!payload || typeof payload !== 'object') {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { looksLikeJsonStreamPrefixWithNative, parseJsonObjectCandidateWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
2
|
+
const STREAM_JSON_MAX_BYTES = 1024 * 1024;
|
|
3
|
+
export async function tryDecodeJsonBodyFromStream(stream) {
|
|
4
|
+
// Peek the first chunk; if it looks like JSON (starts with `{` or `[`), consume full body and parse.
|
|
5
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
6
|
+
const first = await iterator.next();
|
|
7
|
+
if (first.done || first.value == null) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const consumedChunks = [first.value];
|
|
11
|
+
const firstChunk = first.value;
|
|
12
|
+
const looksLikeJson = looksLikeJsonStreamPrefixWithNative(chunkToUtf8(firstChunk));
|
|
13
|
+
if (!looksLikeJson) {
|
|
14
|
+
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
let body = chunkToUtf8(firstChunk);
|
|
18
|
+
while (true) {
|
|
19
|
+
const next = await iterator.next();
|
|
20
|
+
if (next.done)
|
|
21
|
+
break;
|
|
22
|
+
consumedChunks.push(next.value);
|
|
23
|
+
body += chunkToUtf8(next.value);
|
|
24
|
+
// Guard: avoid unbounded buffering if the upstream is actually SSE but starts with whitespace.
|
|
25
|
+
if (body.length > STREAM_JSON_MAX_BYTES) {
|
|
26
|
+
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const parsed = parseJsonObjectCandidateWithNative(body, STREAM_JSON_MAX_BYTES);
|
|
31
|
+
if (!parsed) {
|
|
32
|
+
rewindStreamWithConsumedChunks(stream, consumedChunks, iterator);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
function chunkToUtf8(chunk) {
|
|
38
|
+
if (typeof chunk === 'string') {
|
|
39
|
+
return chunk;
|
|
40
|
+
}
|
|
41
|
+
if (Buffer.isBuffer(chunk)) {
|
|
42
|
+
return chunk.toString('utf8');
|
|
43
|
+
}
|
|
44
|
+
if (chunk instanceof Uint8Array) {
|
|
45
|
+
return Buffer.from(chunk).toString('utf8');
|
|
46
|
+
}
|
|
47
|
+
if (chunk instanceof ArrayBuffer) {
|
|
48
|
+
return Buffer.from(new Uint8Array(chunk)).toString('utf8');
|
|
49
|
+
}
|
|
50
|
+
return String(chunk ?? '');
|
|
51
|
+
}
|
|
52
|
+
function rewindStreamWithConsumedChunks(stream, consumedChunks, iterator) {
|
|
53
|
+
// Rewind by re-wrapping the iterator so downstream SSE decoder still sees everything consumed here.
|
|
54
|
+
// eslint-disable-next-line no-param-reassign
|
|
55
|
+
stream[Symbol.asyncIterator] = () => replayIterator(consumedChunks, iterator);
|
|
56
|
+
}
|
|
57
|
+
function replayIterator(consumedChunks, iterator) {
|
|
58
|
+
let replayIndex = 0;
|
|
59
|
+
return {
|
|
60
|
+
async next() {
|
|
61
|
+
if (replayIndex < consumedChunks.length) {
|
|
62
|
+
const value = consumedChunks[replayIndex];
|
|
63
|
+
replayIndex += 1;
|
|
64
|
+
return { done: false, value };
|
|
65
|
+
}
|
|
66
|
+
return iterator.next();
|
|
67
|
+
},
|
|
68
|
+
async return(value) {
|
|
69
|
+
if (typeof iterator.return === 'function') {
|
|
70
|
+
return iterator.return(value);
|
|
71
|
+
}
|
|
72
|
+
return { done: true, value };
|
|
73
|
+
},
|
|
74
|
+
async throw(err) {
|
|
75
|
+
if (typeof iterator.throw === 'function') {
|
|
76
|
+
return iterator.throw(err);
|
|
77
|
+
}
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { AdapterContext } from '../../../../types/chat-envelope.js';
|
|
2
2
|
import type { FormatEnvelope } from '../../../../types/format-envelope.js';
|
|
3
3
|
import type { JsonObject } from '../../../../types/json.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { StageRecorder } from '../../../../format-adapters/index.js';
|
|
5
5
|
export interface RespInboundStage2FormatParseOptions {
|
|
6
6
|
adapterContext: AdapterContext;
|
|
7
7
|
payload: JsonObject;
|
|
8
|
-
formatAdapter: Pick<FormatAdapter, 'parseResponse'>;
|
|
9
8
|
stageRecorder?: StageRecorder;
|
|
10
9
|
}
|
|
11
10
|
export declare function runRespInboundStage2FormatParse(options: RespInboundStage2FormatParseOptions): Promise<FormatEnvelope<JsonObject>>;
|
package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
import { recordStage } from '../../../stages/utils.js';
|
|
2
|
+
import { parseRespInboundFormatEnvelopeWithNative, sanitizeFormatEnvelopeWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
|
|
3
|
+
import { normalizeReasoningInAnthropicPayload, normalizeReasoningInChatPayload, normalizeReasoningInGeminiPayload, normalizeReasoningInResponsesPayload } from '../../../../../shared/reasoning-normalizer.js';
|
|
4
|
+
function resolveProtocolToken(adapterContext) {
|
|
5
|
+
const candidate = typeof adapterContext.providerProtocol === 'string' && adapterContext.providerProtocol.trim().length
|
|
6
|
+
? adapterContext.providerProtocol.trim().toLowerCase()
|
|
7
|
+
: '';
|
|
8
|
+
if (candidate === 'openai-chat' || candidate === 'openai-responses' || candidate === 'anthropic-messages' || candidate === 'gemini-chat') {
|
|
9
|
+
return candidate;
|
|
10
|
+
}
|
|
11
|
+
return 'openai-chat';
|
|
12
|
+
}
|
|
13
|
+
function applyReasoningNormalization(payload, protocol) {
|
|
14
|
+
if (protocol === 'openai-responses') {
|
|
15
|
+
normalizeReasoningInResponsesPayload(payload, {
|
|
16
|
+
includeOutput: true,
|
|
17
|
+
includeRequiredAction: true
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (protocol === 'anthropic-messages') {
|
|
22
|
+
normalizeReasoningInAnthropicPayload(payload);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (protocol === 'gemini-chat') {
|
|
26
|
+
normalizeReasoningInGeminiPayload(payload);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
normalizeReasoningInChatPayload(payload);
|
|
30
|
+
}
|
|
2
31
|
export async function runRespInboundStage2FormatParse(options) {
|
|
3
|
-
const
|
|
32
|
+
const protocol = resolveProtocolToken(options.adapterContext);
|
|
33
|
+
applyReasoningNormalization(options.payload, protocol);
|
|
34
|
+
const envelopeRaw = parseRespInboundFormatEnvelopeWithNative({
|
|
35
|
+
payload: options.payload,
|
|
36
|
+
protocol
|
|
37
|
+
});
|
|
38
|
+
const envelope = sanitizeFormatEnvelopeWithNative(envelopeRaw);
|
|
4
39
|
recordStage(options.stageRecorder, 'chat_process.resp.stage2.format_parse', envelope);
|
|
5
40
|
return envelope;
|
|
6
41
|
}
|
package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { recordStage } from '../../../stages/utils.js';
|
|
2
|
+
import { sanitizeChatCompletionLikeWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
|
|
2
3
|
export async function runRespInboundStage3SemanticMap(options) {
|
|
3
|
-
const
|
|
4
|
+
const chatResponseRaw = await options.mapper.toChatCompletion(options.formatEnvelope, options.adapterContext, {
|
|
4
5
|
requestSemantics: options.requestSemantics
|
|
5
6
|
});
|
|
7
|
+
const chatResponse = sanitizeChatCompletionLikeWithNative(chatResponseRaw);
|
|
6
8
|
recordStage(options.stageRecorder, 'chat_process.resp.stage4.semantic_map_to_chat', chatResponse);
|
|
7
9
|
return chatResponse;
|
|
8
10
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JsonObject } from '../../../../types/json.js';
|
|
2
|
+
import type { BridgeToolDefinition } from '../../../../../shared/bridge-message-types.js';
|
|
3
|
+
export declare function resolveAliasMapFromSemantics(semantics?: JsonObject): Record<string, string> | undefined;
|
|
4
|
+
export declare function normalizeAliasMap(candidate: unknown): Record<string, string> | undefined;
|
|
5
|
+
export declare function resolveClientToolsRawFromSemantics(semantics?: JsonObject): BridgeToolDefinition[] | undefined;
|
|
6
|
+
export declare function resolveClientToolsRaw(candidate: unknown): BridgeToolDefinition[] | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolveAliasMapFromRespSemanticsWithNative, resolveClientToolsRawFromRespSemanticsWithNative, normalizeAliasMapWithNative, resolveClientToolsRawWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
2
|
+
// Three-stage contract:
|
|
3
|
+
// inbound -> chat_process -> outbound
|
|
4
|
+
// This module is the outbound-side bridge that consumes chat_process semantics
|
|
5
|
+
// and remaps client-facing tool semantics without mutating chat_process internals.
|
|
6
|
+
export function resolveAliasMapFromSemantics(semantics) {
|
|
7
|
+
return resolveAliasMapFromRespSemanticsWithNative(semantics);
|
|
8
|
+
}
|
|
9
|
+
export function normalizeAliasMap(candidate) {
|
|
10
|
+
return normalizeAliasMapWithNative(candidate);
|
|
11
|
+
}
|
|
12
|
+
export function resolveClientToolsRawFromSemantics(semantics) {
|
|
13
|
+
return resolveClientToolsRawFromRespSemanticsWithNative(semantics);
|
|
14
|
+
}
|
|
15
|
+
export function resolveClientToolsRaw(candidate) {
|
|
16
|
+
return resolveClientToolsRawWithNative(candidate);
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type JsonObject } from '../../../../types/json.js';
|
|
2
|
+
export type ClientProtocol = 'openai-chat' | 'openai-responses' | 'anthropic-messages';
|
|
3
|
+
export interface ClientRemapProtocolSwitchOptions {
|
|
4
|
+
payload: JsonObject;
|
|
5
|
+
clientProtocol: ClientProtocol;
|
|
6
|
+
requestId: string;
|
|
7
|
+
requestSemantics?: JsonObject;
|
|
8
|
+
}
|
|
9
|
+
export declare function buildClientPayloadForProtocol(options: ClientRemapProtocolSwitchOptions): JsonObject;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { buildAnthropicResponseFromChat } from '../../../../response/response-runtime.js';
|
|
2
|
+
import { normalizeResponsesToolCallIds } from '../../../../../shared/responses-tool-utils.js';
|
|
3
|
+
import { applyClientPassthroughPatchWithNative, buildResponsesPayloadFromChatWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
4
|
+
import { resolveAliasMapFromSemantics, resolveClientToolsRawFromSemantics } from './chat-process-semantics-bridge.js';
|
|
5
|
+
export function buildClientPayloadForProtocol(options) {
|
|
6
|
+
let clientPayload;
|
|
7
|
+
if (options.clientProtocol === 'openai-chat') {
|
|
8
|
+
clientPayload = options.payload;
|
|
9
|
+
}
|
|
10
|
+
else if (options.clientProtocol === 'anthropic-messages') {
|
|
11
|
+
clientPayload = buildAnthropicResponseFromChat(options.payload, {
|
|
12
|
+
aliasMap: resolveAliasMapFromSemantics(options.requestSemantics)
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const toolsRaw = resolveClientToolsRawFromSemantics(options.requestSemantics);
|
|
17
|
+
clientPayload = buildResponsesPayloadFromChatWithNative(options.payload, {
|
|
18
|
+
requestId: options.requestId,
|
|
19
|
+
...(toolsRaw ? { toolsRaw } : {})
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const patchedPayload = applyClientPassthroughPatchWithNative(clientPayload, options.payload);
|
|
23
|
+
Object.assign(clientPayload, patchedPayload);
|
|
24
|
+
if (options.clientProtocol === 'openai-responses') {
|
|
25
|
+
normalizeResponsesToolCallIds(clientPayload);
|
|
26
|
+
}
|
|
27
|
+
return clientPayload;
|
|
28
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StageRecorder } from '../../../../format-adapters/index.js';
|
|
2
2
|
import type { JsonObject } from '../../../../types/json.js';
|
|
3
3
|
import type { AdapterContext } from '../../../../types/chat-envelope.js';
|
|
4
|
-
type ClientProtocol
|
|
4
|
+
import { type ClientProtocol } from './client-remap-protocol-switch.js';
|
|
5
5
|
export interface RespOutboundStage1ClientRemapOptions {
|
|
6
6
|
payload: JsonObject;
|
|
7
7
|
clientProtocol: ClientProtocol;
|
|
@@ -11,4 +11,3 @@ export interface RespOutboundStage1ClientRemapOptions {
|
|
|
11
11
|
stageRecorder?: StageRecorder;
|
|
12
12
|
}
|
|
13
13
|
export declare function runRespOutboundStage1ClientRemap(options: RespOutboundStage1ClientRemapOptions): JsonObject;
|
|
14
|
-
export {};
|
package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js
CHANGED
|
@@ -1,107 +1,19 @@
|
|
|
1
|
-
import { isJsonObject, jsonClone } from '../../../../types/json.js';
|
|
2
|
-
import { buildAnthropicResponseFromChat } from '../../../../response/response-runtime.js';
|
|
3
|
-
import { buildResponsesPayloadFromChat } from '../../../../../responses/responses-openai-bridge.js';
|
|
4
|
-
import { buildAnthropicToolAliasMap } from '../../../../../shared/anthropic-message-utils.js';
|
|
5
1
|
import { recordStage } from '../../../stages/utils.js';
|
|
2
|
+
import { buildClientPayloadForProtocol } from './client-remap-protocol-switch.js';
|
|
3
|
+
import { normalizeProviderProtocolTokenWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
6
4
|
export function runRespOutboundStage1ClientRemap(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
requestId: options.requestId,
|
|
20
|
-
...(toolsRaw ? { toolsRaw } : {})
|
|
21
|
-
});
|
|
22
|
-
if (options.payload && typeof options.payload === 'object' && !Array.isArray(options.payload)) {
|
|
23
|
-
const source = options.payload;
|
|
24
|
-
const passthrough = ['metadata', 'temperature', 'top_p', 'prompt_cache_key', 'reasoning'];
|
|
25
|
-
for (const key of passthrough) {
|
|
26
|
-
if (clientPayload[key] === undefined && source[key] !== undefined) {
|
|
27
|
-
clientPayload[key] = jsonClone(source[key]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// Preserve upstream error envelope when present (used by host status mapping + servertool auto flows).
|
|
33
|
-
try {
|
|
34
|
-
const err = options.payload.error;
|
|
35
|
-
if (isJsonObject(err)) {
|
|
36
|
-
clientPayload.error = jsonClone(err);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
// best-effort
|
|
41
|
-
}
|
|
5
|
+
const normalizedProtocol = normalizeProviderProtocolTokenWithNative(options.clientProtocol);
|
|
6
|
+
const clientProtocol = normalizedProtocol === 'openai-chat' ||
|
|
7
|
+
normalizedProtocol === 'openai-responses' ||
|
|
8
|
+
normalizedProtocol === 'anthropic-messages'
|
|
9
|
+
? normalizedProtocol
|
|
10
|
+
: options.clientProtocol;
|
|
11
|
+
const clientPayload = buildClientPayloadForProtocol({
|
|
12
|
+
payload: options.payload,
|
|
13
|
+
clientProtocol,
|
|
14
|
+
requestId: options.requestId,
|
|
15
|
+
requestSemantics: options.requestSemantics
|
|
16
|
+
});
|
|
42
17
|
recordStage(options.stageRecorder, 'chat_process.resp.stage9.client_remap', clientPayload);
|
|
43
18
|
return clientPayload;
|
|
44
19
|
}
|
|
45
|
-
function resolveAliasMapFromSemantics(semantics) {
|
|
46
|
-
if (!semantics || typeof semantics !== 'object' || Array.isArray(semantics)) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
const toolsNode = semantics.tools;
|
|
50
|
-
if (!toolsNode || typeof toolsNode !== 'object' || Array.isArray(toolsNode)) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
const toolsRecord = toolsNode;
|
|
54
|
-
// Prefer explicit alias map.
|
|
55
|
-
const candidate = toolsRecord.toolNameAliasMap;
|
|
56
|
-
const fromCandidate = normalizeAliasMap(candidate);
|
|
57
|
-
if (fromCandidate) {
|
|
58
|
-
return fromCandidate;
|
|
59
|
-
}
|
|
60
|
-
// Fallback: derive from captured raw client tools if present.
|
|
61
|
-
// This covers callers that captured `clientToolsRaw` but did not persist `toolNameAliasMap`.
|
|
62
|
-
const rawTools = toolsRecord.clientToolsRaw;
|
|
63
|
-
const derived = buildAnthropicToolAliasMap(rawTools);
|
|
64
|
-
return normalizeAliasMap(derived);
|
|
65
|
-
}
|
|
66
|
-
function normalizeAliasMap(candidate) {
|
|
67
|
-
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const map = {};
|
|
71
|
-
for (const [key, value] of Object.entries(candidate)) {
|
|
72
|
-
if (typeof key !== 'string' || typeof value !== 'string') {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const trimmedKey = key.trim();
|
|
76
|
-
const trimmedValue = value.trim();
|
|
77
|
-
if (!trimmedKey.length || !trimmedValue.length) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
map[trimmedKey] = trimmedValue;
|
|
81
|
-
}
|
|
82
|
-
return Object.keys(map).length ? map : undefined;
|
|
83
|
-
}
|
|
84
|
-
function resolveClientToolsRawFromSemantics(semantics) {
|
|
85
|
-
if (!semantics || typeof semantics !== 'object' || Array.isArray(semantics)) {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
const toolsNode = semantics.tools;
|
|
89
|
-
if (!toolsNode || typeof toolsNode !== 'object' || Array.isArray(toolsNode)) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
const candidate = toolsNode.clientToolsRaw;
|
|
93
|
-
if (!candidate || !Array.isArray(candidate)) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
const filtered = [];
|
|
97
|
-
for (const entry of candidate) {
|
|
98
|
-
if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
|
|
99
|
-
const type = entry.type;
|
|
100
|
-
if (typeof type !== 'string' || !type.trim()) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
filtered.push(entry);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return filtered.length ? filtered : undefined;
|
|
107
|
-
}
|
package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { defaultSseCodecRegistry } from '../../../../../../sse/index.js';
|
|
2
2
|
import { recordStage } from '../../../stages/utils.js';
|
|
3
|
+
import { resolveSseStreamModeWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
|
|
3
4
|
export async function runRespOutboundStage2SseStream(options) {
|
|
4
|
-
|
|
5
|
+
const shouldStream = resolveSseStreamModeWithNative(options.wantsStream, options.clientProtocol);
|
|
6
|
+
if (!shouldStream) {
|
|
5
7
|
recordStage(options.stageRecorder, 'chat_process.resp.stage10.sse_stream', {
|
|
6
8
|
passthrough: false,
|
|
7
9
|
protocol: options.clientProtocol,
|