@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
|
@@ -1,141 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
function flattenReasoning(value, depth = 0) {
|
|
6
|
-
if (depth > 4 || value == null) {
|
|
7
|
-
return '';
|
|
1
|
+
import { normalizeChatResponseReasoningToolsWithNative, normalizeMessageReasoningToolsWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
2
|
+
function overwriteRecordInPlace(target, source) {
|
|
3
|
+
for (const key of Object.keys(target)) {
|
|
4
|
+
delete target[key];
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
for (const [key, value] of Object.entries(source)) {
|
|
7
|
+
target[key] = value;
|
|
11
8
|
}
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
return value
|
|
14
|
-
.map((item) => flattenReasoning(item, depth + 1))
|
|
15
|
-
.filter(Boolean)
|
|
16
|
-
.join('\n');
|
|
17
|
-
}
|
|
18
|
-
if (typeof value === 'object') {
|
|
19
|
-
const record = value;
|
|
20
|
-
if (typeof record.text === 'string') {
|
|
21
|
-
return record.text;
|
|
22
|
-
}
|
|
23
|
-
if (typeof record.content === 'string') {
|
|
24
|
-
return record.content;
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(record.content) || typeof record.content === 'object') {
|
|
27
|
-
return flattenReasoning(record.content, depth + 1);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
function collectReasoningFragments(message) {
|
|
33
|
-
const fragments = [];
|
|
34
|
-
if ('reasoning_content' in message) {
|
|
35
|
-
const text = flattenReasoning(message.reasoning_content);
|
|
36
|
-
if (text) {
|
|
37
|
-
fragments.push(text);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if ('reasoning' in message) {
|
|
41
|
-
const text = flattenReasoning(message.reasoning);
|
|
42
|
-
if (text) {
|
|
43
|
-
fragments.push(text);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return fragments;
|
|
47
|
-
}
|
|
48
|
-
function writeReasoningContent(message, text) {
|
|
49
|
-
const trimmed = text.trim();
|
|
50
|
-
if (trimmed.length) {
|
|
51
|
-
message.reasoning_content = trimmed;
|
|
52
|
-
}
|
|
53
|
-
else if (Object.prototype.hasOwnProperty.call(message, 'reasoning_content')) {
|
|
54
|
-
delete message.reasoning_content;
|
|
55
|
-
}
|
|
56
|
-
if (typeof message.reasoning === 'string') {
|
|
57
|
-
if (trimmed.length) {
|
|
58
|
-
message.reasoning = trimmed;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
delete message.reasoning;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function stripReasoningTags(text) {
|
|
66
|
-
if (!text) {
|
|
67
|
-
return '';
|
|
68
|
-
}
|
|
69
|
-
return text.replace(THINK_TAG_PATTERN, '').replace(REFLECTION_TAG_PATTERN, '').trim();
|
|
70
9
|
}
|
|
71
10
|
export function normalizeMessageReasoningTools(message, options) {
|
|
72
11
|
if (!message || typeof message !== 'object') {
|
|
73
12
|
return { toolCallsAdded: 0 };
|
|
74
13
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const existing = typeof message.reasoning_content === 'string'
|
|
78
|
-
? message.reasoning_content.trim()
|
|
79
|
-
: '';
|
|
80
|
-
if (!existing && Object.prototype.hasOwnProperty.call(message, 'reasoning_content')) {
|
|
81
|
-
delete message.reasoning_content;
|
|
82
|
-
}
|
|
83
|
-
return { toolCallsAdded: 0 };
|
|
84
|
-
}
|
|
85
|
-
const combined = fragments.join('\n').trim();
|
|
86
|
-
if (!combined.length) {
|
|
87
|
-
writeReasoningContent(message, '');
|
|
88
|
-
return { toolCallsAdded: 0 };
|
|
89
|
-
}
|
|
90
|
-
const sanitized = stripReasoningTags(combined);
|
|
91
|
-
if (!sanitized.length) {
|
|
92
|
-
writeReasoningContent(message, '');
|
|
93
|
-
return { toolCallsAdded: 0 };
|
|
94
|
-
}
|
|
95
|
-
const idPrefix = options?.idPrefix ?? 'reasoning';
|
|
96
|
-
const { cleanedText, toolCalls } = extractToolCallsFromReasoningText(sanitized, { idPrefix });
|
|
97
|
-
const trimmed = (cleanedText || '').trim();
|
|
98
|
-
writeReasoningContent(message, trimmed);
|
|
99
|
-
// Chat 统一行为:如果 message 本身没有正文内容,但存在非空 reasoning_content,
|
|
100
|
-
// 则将思考内容提升到正文,前后包裹 [思考] 标记,避免客户端只看到"空回答"。
|
|
101
|
-
const rawContent = message.content;
|
|
102
|
-
if ((typeof rawContent !== 'string' || rawContent.trim().length === 0) &&
|
|
103
|
-
trimmed.length > 0) {
|
|
104
|
-
// 检查是否已经包含 [思考] 标签,避免重复嵌套
|
|
105
|
-
const hasThinkingTags = trimmed.includes('[思考]') && trimmed.includes('[/思考]');
|
|
106
|
-
message.content = hasThinkingTags ? trimmed : `[思考]\n${trimmed}\n[/思考]`;
|
|
107
|
-
}
|
|
108
|
-
if (!Array.isArray(toolCalls) || toolCalls.length === 0) {
|
|
109
|
-
return { toolCallsAdded: 0, cleanedReasoning: trimmed };
|
|
110
|
-
}
|
|
111
|
-
const current = Array.isArray(message.tool_calls)
|
|
112
|
-
? message.tool_calls
|
|
113
|
-
: undefined;
|
|
114
|
-
const merged = mergeToolCalls(current, toolCalls);
|
|
115
|
-
message.tool_calls = merged;
|
|
14
|
+
const normalized = normalizeMessageReasoningToolsWithNative(message, typeof options?.idPrefix === 'string' ? options.idPrefix : undefined);
|
|
15
|
+
overwriteRecordInPlace(message, normalized.message);
|
|
116
16
|
return {
|
|
117
|
-
toolCallsAdded:
|
|
118
|
-
cleanedReasoning
|
|
17
|
+
toolCallsAdded: normalized.toolCallsAdded,
|
|
18
|
+
...(typeof normalized.cleanedReasoning === 'string'
|
|
19
|
+
? { cleanedReasoning: normalized.cleanedReasoning }
|
|
20
|
+
: {})
|
|
119
21
|
};
|
|
120
22
|
}
|
|
121
23
|
export function normalizeChatResponseReasoningTools(response, options) {
|
|
122
24
|
if (!response || typeof response !== 'object') {
|
|
123
25
|
return;
|
|
124
26
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
: [];
|
|
128
|
-
for (let i = 0; i < choices.length; i++) {
|
|
129
|
-
const choice = choices[i];
|
|
130
|
-
if (!choice || typeof choice !== 'object') {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const message = choice.message;
|
|
134
|
-
if (!message || typeof message !== 'object') {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
normalizeMessageReasoningTools(message, {
|
|
138
|
-
idPrefix: `${options?.idPrefixBase ?? 'reasoning_choice'}_${i + 1}`
|
|
139
|
-
});
|
|
140
|
-
}
|
|
27
|
+
const normalized = normalizeChatResponseReasoningToolsWithNative(response, typeof options?.idPrefixBase === 'string' ? options.idPrefixBase : undefined);
|
|
28
|
+
overwriteRecordInPlace(response, normalized);
|
|
141
29
|
}
|
|
@@ -1,95 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const FENCE_PATTERN = /```(?:tool_call|tool_calls|function_call|json)?\s*([\s\S]*?)\s*```/gi;
|
|
3
|
-
const TAG_PATTERN = /<(tool_call|function_call)(?:\s+name="([^"]+)")?\s*>([\s\S]*?)<\/\1>/gi;
|
|
4
|
-
const BRACKET_PATTERN = /\[(tool_call|function_call)(?:\s+name="([^"]+)")?\]([\s\S]*?)\[\/\1\]/gi;
|
|
5
|
-
const LABEL_PATTERN = /(tool_call|function_call)\s*[:=]\s*({[\s\S]+?})/gi;
|
|
1
|
+
import { extractToolCallsFromReasoningTextWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
6
2
|
export function extractToolCallsFromReasoningText(text, options) {
|
|
7
3
|
if (typeof text !== 'string' || !text.trim()) {
|
|
8
4
|
return { cleanedText: typeof text === 'string' ? text : '', toolCalls: [] };
|
|
9
5
|
}
|
|
10
6
|
const idPrefix = options?.idPrefix ?? 'reasoning';
|
|
11
|
-
const
|
|
12
|
-
const consume = (pattern, getPayload) => {
|
|
13
|
-
pattern.lastIndex = 0;
|
|
14
|
-
let match;
|
|
15
|
-
while ((match = pattern.exec(text))) {
|
|
16
|
-
const payload = getPayload(match);
|
|
17
|
-
if (!payload) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
const parsed = parseToolCall(payload.body, payload.nameHint);
|
|
21
|
-
if (!parsed) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
matches.push({ start: match.index, end: match.index + match[0].length, call: parsed });
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
consume(FENCE_PATTERN, match => ({ body: match[1] ?? '' }));
|
|
28
|
-
consume(TAG_PATTERN, match => ({ body: match[3] ?? '', nameHint: match[2] }));
|
|
29
|
-
consume(BRACKET_PATTERN, match => ({ body: match[3] ?? '', nameHint: match[2] }));
|
|
30
|
-
consume(LABEL_PATTERN, match => ({ body: match[2] ?? '' }));
|
|
31
|
-
if (!matches.length) {
|
|
32
|
-
const parsed = parseToolCall(text);
|
|
33
|
-
if (parsed) {
|
|
34
|
-
return {
|
|
35
|
-
cleanedText: '',
|
|
36
|
-
toolCalls: [buildToolCall(parsed, idPrefix, 0)]
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return { cleanedText: text, toolCalls: [] };
|
|
40
|
-
}
|
|
41
|
-
const toolCalls = matches.map((entry, index) => buildToolCall(entry.call, idPrefix, index));
|
|
42
|
-
matches.sort((a, b) => b.start - a.start);
|
|
43
|
-
let cleaned = text;
|
|
44
|
-
for (const entry of matches) {
|
|
45
|
-
cleaned = cleaned.slice(0, entry.start) + cleaned.slice(entry.end);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
cleanedText: cleaned.trim(),
|
|
49
|
-
toolCalls
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function parseToolCall(raw, nameHint) {
|
|
53
|
-
if (!raw || typeof raw !== 'string') {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
const trimmed = raw.trim();
|
|
57
|
-
if (!trimmed) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const parsed = parseLenient(trimmed);
|
|
61
|
-
if (!parsed || typeof parsed !== 'object') {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const candidateName = parsed.name ??
|
|
65
|
-
parsed.function?.name ??
|
|
66
|
-
parsed.tool_name ??
|
|
67
|
-
parsed.tool ??
|
|
68
|
-
nameHint;
|
|
69
|
-
const name = typeof candidateName === 'string' ? candidateName.trim() : undefined;
|
|
70
|
-
if (!name) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
const argsSource = parsed.function?.arguments ??
|
|
74
|
-
parsed.arguments ??
|
|
75
|
-
parsed.input ??
|
|
76
|
-
parsed.params ??
|
|
77
|
-
parsed.parameters ??
|
|
78
|
-
parsed.payload ??
|
|
79
|
-
{};
|
|
80
|
-
const args = repairArgumentsToString(argsSource);
|
|
81
|
-
return {
|
|
82
|
-
name,
|
|
83
|
-
args
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function buildToolCall(parsed, prefix, index) {
|
|
7
|
+
const output = extractToolCallsFromReasoningTextWithNative(text, idPrefix);
|
|
87
8
|
return {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function: {
|
|
91
|
-
name: parsed.name,
|
|
92
|
-
arguments: parsed.args
|
|
93
|
-
}
|
|
9
|
+
cleanedText: output.cleanedText,
|
|
10
|
+
toolCalls: output.toolCalls
|
|
94
11
|
};
|
|
95
12
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sanitizeReasoningTaggedTextWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
1
2
|
export function extractReasoningSegments(source, reasoningCollector) {
|
|
2
3
|
let working = source ?? '';
|
|
3
4
|
const hasExplicitOpen = /<think>/i.test(source) ||
|
|
@@ -33,10 +34,5 @@ export function extractReasoningSegments(source, reasoningCollector) {
|
|
|
33
34
|
return working.trim();
|
|
34
35
|
}
|
|
35
36
|
export function sanitizeReasoningTaggedText(value) {
|
|
36
|
-
|
|
37
|
-
return extractReasoningSegments(value);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
37
|
+
return sanitizeReasoningTaggedTextWithNative(value);
|
|
42
38
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProviderProtocolError } from './errors.js';
|
|
2
|
-
import { normalizeFunctionCallOutputId } from '
|
|
2
|
+
import { normalizeFunctionCallOutputIdWithNative as normalizeFunctionCallOutputId } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
|
+
import { convertResponsesOutputToInputItemsWithNative, pickResponsesPersistedFieldsWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
3
4
|
const TTL_MS = 1000 * 60 * 30; // 30min
|
|
4
5
|
function cloneDeep(value) {
|
|
5
6
|
try {
|
|
@@ -28,89 +29,10 @@ function coerceTools(tools) {
|
|
|
28
29
|
return cloneDeep(tools);
|
|
29
30
|
}
|
|
30
31
|
function pickPersistedFields(payload) {
|
|
31
|
-
|
|
32
|
-
'model',
|
|
33
|
-
'instructions',
|
|
34
|
-
'metadata',
|
|
35
|
-
'include',
|
|
36
|
-
'store',
|
|
37
|
-
'tool_choice',
|
|
38
|
-
'parallel_tool_calls',
|
|
39
|
-
'response_format',
|
|
40
|
-
'temperature',
|
|
41
|
-
'top_p',
|
|
42
|
-
'max_output_tokens',
|
|
43
|
-
'max_tokens',
|
|
44
|
-
'stop',
|
|
45
|
-
'user',
|
|
46
|
-
'modal',
|
|
47
|
-
'truncation_strategy',
|
|
48
|
-
'previous_response_id',
|
|
49
|
-
'reasoning',
|
|
50
|
-
'attachments',
|
|
51
|
-
'input_audio',
|
|
52
|
-
'output_audio'
|
|
53
|
-
];
|
|
54
|
-
const next = {};
|
|
55
|
-
for (const key of fields) {
|
|
56
|
-
if (payload[key] !== undefined) {
|
|
57
|
-
next[key] = cloneDeep(payload[key]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return next;
|
|
61
|
-
}
|
|
62
|
-
function normalizeOutputItemToInput(item) {
|
|
63
|
-
if (!item || typeof item !== 'object') {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
const type = typeof item.type === 'string' ? item.type : '';
|
|
67
|
-
if (type === 'message' || type === 'reasoning') {
|
|
68
|
-
const role = typeof item.role === 'string' ? item.role : 'assistant';
|
|
69
|
-
const content = Array.isArray(item.content)
|
|
70
|
-
? cloneDeep(item.content)
|
|
71
|
-
: typeof item.text === 'string'
|
|
72
|
-
? [{ type: 'text', text: item.text }]
|
|
73
|
-
: [];
|
|
74
|
-
return {
|
|
75
|
-
type: 'message',
|
|
76
|
-
role,
|
|
77
|
-
content,
|
|
78
|
-
message: { role, content }
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (type === 'function_call') {
|
|
82
|
-
const callId = typeof item.call_id === 'string'
|
|
83
|
-
? item.call_id
|
|
84
|
-
: typeof item.id === 'string'
|
|
85
|
-
? item.id
|
|
86
|
-
: undefined;
|
|
87
|
-
return {
|
|
88
|
-
type: 'function_call',
|
|
89
|
-
role: 'assistant',
|
|
90
|
-
id: typeof item.id === 'string' ? item.id : undefined,
|
|
91
|
-
call_id: callId,
|
|
92
|
-
name: typeof item.name === 'string' ? item.name : undefined,
|
|
93
|
-
arguments: item.arguments,
|
|
94
|
-
function: isRecord(item.function)
|
|
95
|
-
? cloneDeep(item.function)
|
|
96
|
-
: typeof item.name === 'string'
|
|
97
|
-
? { name: item.name, arguments: item.arguments }
|
|
98
|
-
: undefined
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
32
|
+
return pickResponsesPersistedFieldsWithNative(payload);
|
|
102
33
|
}
|
|
103
34
|
function convertOutputToInputItems(response) {
|
|
104
|
-
|
|
105
|
-
const items = [];
|
|
106
|
-
for (const entry of output) {
|
|
107
|
-
if (!entry || typeof entry !== 'object')
|
|
108
|
-
continue;
|
|
109
|
-
const mapped = normalizeOutputItemToInput(entry);
|
|
110
|
-
if (mapped)
|
|
111
|
-
items.push(mapped);
|
|
112
|
-
}
|
|
113
|
-
return items;
|
|
35
|
+
return convertResponsesOutputToInputItemsWithNative(response);
|
|
114
36
|
}
|
|
115
37
|
function normalizeSubmittedToolOutputs(toolOutputs, callIdToFunctionItemId) {
|
|
116
38
|
const items = [];
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { normalizeFunctionCallId, normalizeFunctionCallOutputId } from './bridge-id-utils.js';
|
|
2
2
|
import { normalizeContentPart } from './output-content-normalizer.js';
|
|
3
3
|
import { expandResponsesMessageItem } from '../../sse/shared/responses-output-normalizer.js';
|
|
4
|
+
import { normalizeResponsesUsageWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
5
|
+
function isStableToolCallId(raw) {
|
|
6
|
+
return /^((fc|call)_[A-Za-z0-9_-]+)$/i.test(raw);
|
|
7
|
+
}
|
|
4
8
|
function buildToolOutputIndex(response) {
|
|
5
9
|
const ids = new Set();
|
|
6
10
|
try {
|
|
@@ -161,50 +165,7 @@ export function buildResponsesOutputFromChat(options) {
|
|
|
161
165
|
};
|
|
162
166
|
}
|
|
163
167
|
function normalizeUsage(usageRaw) {
|
|
164
|
-
|
|
165
|
-
return usageRaw;
|
|
166
|
-
}
|
|
167
|
-
const usage = { ...usageRaw };
|
|
168
|
-
// 统一 Responses 与 Chat 两种 usage 形态:
|
|
169
|
-
// - Responses: input_tokens / output_tokens / total_tokens
|
|
170
|
-
// - Chat: prompt_tokens / completion_tokens / total_tokens
|
|
171
|
-
const inputTokens = typeof usage.input_tokens === 'number'
|
|
172
|
-
? usage.input_tokens
|
|
173
|
-
: typeof usage.prompt_tokens === 'number'
|
|
174
|
-
? usage.prompt_tokens
|
|
175
|
-
: undefined;
|
|
176
|
-
const outputTokens = typeof usage.output_tokens === 'number'
|
|
177
|
-
? usage.output_tokens
|
|
178
|
-
: typeof usage.completion_tokens === 'number'
|
|
179
|
-
? usage.completion_tokens
|
|
180
|
-
: undefined;
|
|
181
|
-
let totalTokens = typeof usage.total_tokens === 'number'
|
|
182
|
-
? usage.total_tokens
|
|
183
|
-
: undefined;
|
|
184
|
-
if (totalTokens === undefined && inputTokens !== undefined && outputTokens !== undefined) {
|
|
185
|
-
const total = Number(inputTokens) + Number(outputTokens);
|
|
186
|
-
if (!Number.isNaN(total)) {
|
|
187
|
-
totalTokens = total;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// Responses 规范字段:input_tokens / output_tokens / total_tokens
|
|
191
|
-
if (inputTokens !== undefined) {
|
|
192
|
-
usage.input_tokens = inputTokens;
|
|
193
|
-
}
|
|
194
|
-
if (outputTokens !== undefined) {
|
|
195
|
-
usage.output_tokens = outputTokens;
|
|
196
|
-
}
|
|
197
|
-
if (totalTokens !== undefined) {
|
|
198
|
-
usage.total_tokens = totalTokens;
|
|
199
|
-
}
|
|
200
|
-
// 为了兼容内部统计逻辑,保留 prompt_tokens / completion_tokens 映射(如果原本没有)
|
|
201
|
-
if (usage.prompt_tokens == null && inputTokens !== undefined) {
|
|
202
|
-
usage.prompt_tokens = inputTokens;
|
|
203
|
-
}
|
|
204
|
-
if (usage.completion_tokens == null && outputTokens !== undefined) {
|
|
205
|
-
usage.completion_tokens = outputTokens;
|
|
206
|
-
}
|
|
207
|
-
return usage;
|
|
168
|
+
return normalizeResponsesUsageWithNative(usageRaw);
|
|
208
169
|
}
|
|
209
170
|
function buildFunctionCallOutput(call, allocateOutputId, sanitizeFunctionName, baseCount, offset) {
|
|
210
171
|
try {
|
|
@@ -229,10 +190,13 @@ function buildFunctionCallOutput(call, allocateOutputId, sanitizeFunctionName, b
|
|
|
229
190
|
const originalCallId = typeof call.id === 'string' && call.id.trim().length
|
|
230
191
|
? String(call.id)
|
|
231
192
|
: (typeof call.call_id === 'string' && call.call_id.trim().length ? String(call.call_id) : undefined);
|
|
232
|
-
|
|
233
|
-
// across tool_call → submit_tool_outputs). Only generate/normalize when missing.
|
|
234
|
-
const callId = typeof originalCallId === 'string' && originalCallId.trim().length
|
|
193
|
+
const stableOriginalCallId = typeof originalCallId === 'string' && originalCallId.trim().length && isStableToolCallId(originalCallId.trim())
|
|
235
194
|
? originalCallId.trim()
|
|
195
|
+
: undefined;
|
|
196
|
+
// Preserve original tool call IDs when they already follow supported call-id styles.
|
|
197
|
+
// Otherwise normalize to fc_* to keep tool_call_id invariants stable across outputs.
|
|
198
|
+
const callId = typeof stableOriginalCallId === 'string' && stableOriginalCallId.length
|
|
199
|
+
? stableOriginalCallId
|
|
236
200
|
: normalizeFunctionCallId({
|
|
237
201
|
callId: originalCallId,
|
|
238
202
|
fallback: `fc_call_${baseCount + offset}`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseLenientJsonishWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
1
2
|
const registry = new Map();
|
|
2
3
|
function ensureEntry(id) {
|
|
3
4
|
let entry = registry.get(id);
|
|
@@ -26,7 +27,12 @@ function cloneSnapshot(snapshot) {
|
|
|
26
27
|
/* ignore structuredClone failures */
|
|
27
28
|
}
|
|
28
29
|
try {
|
|
29
|
-
|
|
30
|
+
const serialized = JSON.stringify(snapshot);
|
|
31
|
+
const parsed = parseLenientJsonishWithNative(serialized);
|
|
32
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
33
|
+
return parsed;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
30
36
|
}
|
|
31
37
|
catch {
|
|
32
38
|
return undefined;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { BuildChatRequestResult, ResponsesRequestContext } from '../responses/responses-openai-bridge/types.js';
|
|
2
|
+
export declare function captureResponsesContext(payload: Record<string, unknown>, dto?: {
|
|
3
|
+
route?: {
|
|
4
|
+
requestId?: string;
|
|
5
|
+
};
|
|
6
|
+
}): ResponsesRequestContext;
|
|
7
|
+
export declare function buildChatRequestFromResponses(payload: Record<string, unknown>, context: ResponsesRequestContext): BuildChatRequestResult;
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { buildChatRequestFromResponses as buildChatRequestFromResponsesImpl, captureResponsesContext as captureResponsesContextImpl } from '../responses/responses-openai-bridge.js';
|
|
2
|
+
import { normalizeProviderProtocolTokenWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
3
|
+
function assertResponsesNativeBoundary() {
|
|
4
|
+
// Keep adapter as a thin boundary while forcing native capability presence.
|
|
5
|
+
normalizeProviderProtocolTokenWithNative('openai-responses');
|
|
6
|
+
}
|
|
7
|
+
export function captureResponsesContext(payload, dto) {
|
|
8
|
+
assertResponsesNativeBoundary();
|
|
9
|
+
return captureResponsesContextImpl(payload, dto);
|
|
10
|
+
}
|
|
11
|
+
export function buildChatRequestFromResponses(payload, context) {
|
|
12
|
+
assertResponsesNativeBoundary();
|
|
13
|
+
return buildChatRequestFromResponsesImpl(payload, context);
|
|
14
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { sanitizeResponsesFunctionName } from './responses-tool-utils.js';
|
|
2
|
-
import { normalizeFunctionCallId } from './bridge-id-utils.js';
|
|
3
1
|
import { extractOutputSegments } from './output-content-normalizer.js';
|
|
4
|
-
import { sanitizeReasoningTaggedText } from './reasoning-utils.js';
|
|
5
2
|
import { createBridgeActionState, runBridgeActionPipeline } from './bridge-actions.js';
|
|
6
3
|
import { resolveBridgePolicy, resolvePolicyActions } from './bridge-policies.js';
|
|
7
4
|
import { registerResponsesPayloadSnapshot, registerResponsesPassthrough } from './responses-reasoning-registry.js';
|
|
5
|
+
import { normalizeFunctionCallIdWithNative, sanitizeReasoningTaggedTextWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
6
|
+
import { sanitizeResponsesFunctionNameWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
8
7
|
function selectCallId(entry) {
|
|
9
8
|
const candidates = [
|
|
10
9
|
entry?.call_id,
|
|
@@ -23,7 +22,7 @@ function normalizeToolCall(entry, fallbackPrefix) {
|
|
|
23
22
|
if (!entry || typeof entry !== 'object')
|
|
24
23
|
return null;
|
|
25
24
|
const fn = entry.function || {};
|
|
26
|
-
const rawName =
|
|
25
|
+
const rawName = sanitizeResponsesFunctionNameWithNative(fn.name ?? entry.name);
|
|
27
26
|
if (!rawName)
|
|
28
27
|
return null;
|
|
29
28
|
const argsRaw = fn.arguments ?? entry.arguments ?? {};
|
|
@@ -40,7 +39,7 @@ function normalizeToolCall(entry, fallbackPrefix) {
|
|
|
40
39
|
const callIdRaw = selectCallId(entry);
|
|
41
40
|
const callId = typeof callIdRaw === 'string' && callIdRaw.length
|
|
42
41
|
? callIdRaw
|
|
43
|
-
:
|
|
42
|
+
: normalizeFunctionCallIdWithNative({
|
|
44
43
|
callId: callIdRaw,
|
|
45
44
|
fallback: `${fallbackPrefix}_${Math.random().toString(36).slice(2, 10)}`
|
|
46
45
|
});
|
|
@@ -187,7 +186,7 @@ export function buildChatResponseFromResponses(payload) {
|
|
|
187
186
|
const { textParts, reasoningParts } = extractOutputSegments(response);
|
|
188
187
|
const rawReasoningSegments = collectRawReasoningSegments(response);
|
|
189
188
|
const explicitOutput = typeof response.output_text === 'string' && response.output_text.trim().length
|
|
190
|
-
?
|
|
189
|
+
? sanitizeReasoningTaggedTextWithNative(response.output_text)
|
|
191
190
|
: undefined;
|
|
192
191
|
const messageContentText = explicitOutput || textParts.join('\n').trim();
|
|
193
192
|
const messageContent = messageContentText || '';
|
|
@@ -244,7 +243,7 @@ export function buildChatResponseFromResponses(payload) {
|
|
|
244
243
|
chat.__responses_output_text_meta = {
|
|
245
244
|
hasField: hasOutputTextField,
|
|
246
245
|
value: hasOutputTextField && typeof response.output_text === 'string'
|
|
247
|
-
?
|
|
246
|
+
? sanitizeReasoningTaggedTextWithNative(response.output_text)
|
|
248
247
|
: undefined
|
|
249
248
|
};
|
|
250
249
|
if (usage !== undefined) {
|
|
@@ -7,6 +7,7 @@ export interface CallIdTransformer {
|
|
|
7
7
|
}
|
|
8
8
|
export declare function createToolCallIdTransformer(style: ToolCallIdStyle): CallIdTransformer | null;
|
|
9
9
|
export declare function enforceToolCallIdStyle(input: BridgeInputItem[], transformer: CallIdTransformer): void;
|
|
10
|
+
export declare function normalizeResponsesToolCallIds(payload: Record<string, unknown> | null | undefined): void;
|
|
10
11
|
export declare function resolveToolCallIdStyle(metadata: Record<string, unknown> | undefined): ToolCallIdStyle;
|
|
11
12
|
export declare function stripInternalToolingMetadata(metadata: unknown): void;
|
|
12
13
|
export declare function sanitizeResponsesFunctionName(rawName: unknown): string | undefined;
|