@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,19 +1,6 @@
|
|
|
1
|
-
import type { AdapterContext } from '../../../../types/chat-envelope.js';
|
|
2
|
-
import type { JsonObject } from '../../../../types/json.js';
|
|
3
|
-
import type { StageRecorder } from '../../../../format-adapters/index.js';
|
|
4
1
|
import type { ResponsesRequestContext } from '../../../../../responses/responses-openai-bridge.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
adapterContext: AdapterContext;
|
|
8
|
-
stageRecorder?: StageRecorder;
|
|
9
|
-
}
|
|
10
|
-
export type ContextCaptureHandler = (options: ContextCaptureOptions) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined;
|
|
11
|
-
export interface ReqInboundStage3ContextCaptureOptions {
|
|
12
|
-
rawRequest: JsonObject;
|
|
13
|
-
adapterContext: AdapterContext;
|
|
14
|
-
captureContext?: ContextCaptureHandler;
|
|
15
|
-
stageRecorder?: StageRecorder;
|
|
16
|
-
}
|
|
2
|
+
import type { ContextCaptureOptions, ReqInboundStage3ContextCaptureOptions } from './context-capture-orchestration.js';
|
|
3
|
+
export type { ContextCaptureHandler, ContextCaptureOptions, ReqInboundStage3ContextCaptureOptions } from './context-capture-orchestration.js';
|
|
17
4
|
export declare function runReqInboundStage3ContextCapture(options: ReqInboundStage3ContextCaptureOptions): Promise<Record<string, unknown> | undefined>;
|
|
18
5
|
export declare function runChatContextCapture(options: ContextCaptureOptions): Promise<Record<string, unknown> | undefined>;
|
|
19
6
|
export declare function captureResponsesContextSnapshot(options: ContextCaptureOptions): ResponsesRequestContext;
|
package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js
CHANGED
|
@@ -1,47 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { buildToolOutputSnapshot } from './tool-output-snapshot.js';
|
|
2
|
+
import { captureResponsesContextSnapshot as captureResponsesContextSnapshotModule } from './responses-context-snapshot.js';
|
|
3
|
+
import { runReqInboundStage3ContextCaptureOrchestration } from './context-capture-orchestration.js';
|
|
4
|
+
import { normalizeProviderProtocolTokenWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
5
5
|
export async function runReqInboundStage3ContextCapture(options) {
|
|
6
|
-
|
|
7
|
-
// 跳过工具输出扫描与 apply_patch 诊断日志,避免在内部流中重复放大客户端已收到的
|
|
8
|
-
// 工具错误信息。此类请求的工具治理在 chat-process 阶段完成,这里仅保留最小快照。
|
|
9
|
-
try {
|
|
10
|
-
const ctx = options.adapterContext;
|
|
11
|
-
const rt = readRuntimeMetadata(ctx);
|
|
12
|
-
const followupFlag = rt?.serverToolFollowup;
|
|
13
|
-
const isFollowup = followupFlag === true ||
|
|
14
|
-
(typeof followupFlag === 'string' && followupFlag.trim().toLowerCase() === 'true');
|
|
15
|
-
if (isFollowup) {
|
|
16
|
-
const snapshot = {
|
|
17
|
-
providerProtocol: options.adapterContext.providerProtocol ?? 'unknown',
|
|
18
|
-
tool_outputs: []
|
|
19
|
-
};
|
|
20
|
-
recordStage(options.stageRecorder, 'chat_process.req.stage3.context_capture', snapshot);
|
|
21
|
-
return snapshot;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
// best-effort: 若检测 serverToolFollowup 失败,则继续走通用路径
|
|
26
|
-
}
|
|
27
|
-
let context;
|
|
28
|
-
if (options.captureContext) {
|
|
29
|
-
try {
|
|
30
|
-
context = await options.captureContext({
|
|
31
|
-
rawRequest: options.rawRequest,
|
|
32
|
-
adapterContext: options.adapterContext
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
context = undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const fallbackSnapshot = buildToolOutputSnapshot(options.rawRequest, options.adapterContext.providerProtocol);
|
|
40
|
-
const snapshot = context
|
|
41
|
-
? augmentContextSnapshot(context, fallbackSnapshot)
|
|
42
|
-
: fallbackSnapshot;
|
|
43
|
-
recordStage(options.stageRecorder, 'chat_process.req.stage3.context_capture', snapshot);
|
|
44
|
-
return context ?? snapshot;
|
|
6
|
+
return runReqInboundStage3ContextCaptureOrchestration(options);
|
|
45
7
|
}
|
|
46
8
|
export function runChatContextCapture(options) {
|
|
47
9
|
return runReqInboundStage3ContextCapture({
|
|
@@ -52,558 +14,9 @@ export function runChatContextCapture(options) {
|
|
|
52
14
|
});
|
|
53
15
|
}
|
|
54
16
|
export function captureResponsesContextSnapshot(options) {
|
|
55
|
-
|
|
56
|
-
route: { requestId: options.adapterContext.requestId }
|
|
57
|
-
});
|
|
58
|
-
const style = normalizeToolCallIdStyleCandidate(options.adapterContext.toolCallIdStyle);
|
|
59
|
-
if (style) {
|
|
60
|
-
context.toolCallIdStyle = style;
|
|
61
|
-
if (!context.metadata || typeof context.metadata !== 'object') {
|
|
62
|
-
context.metadata = {};
|
|
63
|
-
}
|
|
64
|
-
context.metadata.toolCallIdStyle = style;
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
const built = buildChatRequestFromResponses(options.rawRequest, context);
|
|
68
|
-
if (built.toolsNormalized) {
|
|
69
|
-
context.toolsNormalized = built.toolsNormalized;
|
|
70
|
-
}
|
|
71
|
-
const captured = collectToolOutputs(options.rawRequest);
|
|
72
|
-
if (captured.length) {
|
|
73
|
-
context.__captured_tool_results = captured;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
// best-effort context capture
|
|
78
|
-
}
|
|
79
|
-
// OpenAI Responses tool loop: store the request context keyed by requestId so that
|
|
80
|
-
// `/v1/responses/:id/submit_tool_outputs` can resume the conversation later.
|
|
81
|
-
//
|
|
82
|
-
// This must be done on the hub pipeline inbound path (not in host/provider), because:
|
|
83
|
-
// - the tool loop is a client-protocol behavior (/v1/responses), independent of providerProtocol;
|
|
84
|
-
// - providers must remain transport-only;
|
|
85
|
-
// - the host may later enhance requestId with providerKey/model for logging, which is handled via rebind.
|
|
86
|
-
try {
|
|
87
|
-
const requestId = typeof options.adapterContext.requestId === 'string' && options.adapterContext.requestId.trim().length
|
|
88
|
-
? options.adapterContext.requestId
|
|
89
|
-
: undefined;
|
|
90
|
-
if (requestId) {
|
|
91
|
-
captureResponsesRequestContext({
|
|
92
|
-
requestId,
|
|
93
|
-
payload: options.rawRequest,
|
|
94
|
-
context: context
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
// best-effort: capture failures must not block the request path
|
|
100
|
-
}
|
|
101
|
-
return context;
|
|
17
|
+
return captureResponsesContextSnapshotModule(options);
|
|
102
18
|
}
|
|
103
19
|
function captureChatContextSnapshot(options) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
function normalizeToolCallIdStyleCandidate(value) {
|
|
107
|
-
if (typeof value !== 'string') {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
const normalized = value.trim().toLowerCase();
|
|
111
|
-
if (normalized === 'fc') {
|
|
112
|
-
return 'fc';
|
|
113
|
-
}
|
|
114
|
-
if (normalized === 'preserve') {
|
|
115
|
-
return 'preserve';
|
|
116
|
-
}
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
function augmentContextSnapshot(context, fallback) {
|
|
120
|
-
if (!fallback.tool_outputs || Array.isArray(context.tool_outputs)) {
|
|
121
|
-
return context;
|
|
122
|
-
}
|
|
123
|
-
if (!Array.isArray(context.tool_outputs) && Array.isArray(fallback.tool_outputs)) {
|
|
124
|
-
context.tool_outputs = fallback.tool_outputs;
|
|
125
|
-
}
|
|
126
|
-
return context;
|
|
127
|
-
}
|
|
128
|
-
function buildToolOutputSnapshot(payload, providerProtocol) {
|
|
129
|
-
const snapshot = {
|
|
130
|
-
providerProtocol: providerProtocol ?? 'unknown'
|
|
131
|
-
};
|
|
132
|
-
try {
|
|
133
|
-
normalizeShellLikeToolCallsBeforeGovernance(payload);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
// shape repair is best-effort; never block main flow
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
injectApplyPatchDiagnostics(payload);
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
// diagnostics are best-effort; never block main flow
|
|
143
|
-
}
|
|
144
|
-
const toolOutputs = collectToolOutputs(payload);
|
|
145
|
-
if (toolOutputs.length) {
|
|
146
|
-
snapshot.tool_outputs = toolOutputs;
|
|
147
|
-
}
|
|
148
|
-
return snapshot;
|
|
149
|
-
}
|
|
150
|
-
const SHELL_LIKE_TOOL_NAMES = new Set(['exec_command', 'shell_command', 'shell', 'bash', 'terminal']);
|
|
151
|
-
function readTrimmedString(value) {
|
|
152
|
-
if (typeof value !== 'string') {
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
const trimmed = value.trim();
|
|
156
|
-
return trimmed.length ? trimmed : undefined;
|
|
157
|
-
}
|
|
158
|
-
function isRecord(value) {
|
|
159
|
-
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
160
|
-
}
|
|
161
|
-
function readStringArrayCommand(value) {
|
|
162
|
-
if (!Array.isArray(value)) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
const tokens = value
|
|
166
|
-
.map((item) => (item == null ? '' : String(item).trim()))
|
|
167
|
-
.filter((item) => item.length > 0);
|
|
168
|
-
return tokens.length ? tokens.join(' ') : undefined;
|
|
169
|
-
}
|
|
170
|
-
function parseJsonRecord(value) {
|
|
171
|
-
if (isRecord(value)) {
|
|
172
|
-
return value;
|
|
173
|
-
}
|
|
174
|
-
if (typeof value !== 'string') {
|
|
175
|
-
return undefined;
|
|
176
|
-
}
|
|
177
|
-
const trimmed = value.trim();
|
|
178
|
-
if (!trimmed) {
|
|
179
|
-
return {};
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
const parsed = JSON.parse(trimmed);
|
|
183
|
-
return isRecord(parsed) ? parsed : undefined;
|
|
184
|
-
}
|
|
185
|
-
catch {
|
|
186
|
-
return undefined;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function readCommandFromArgs(args) {
|
|
190
|
-
const input = isRecord(args.input) ? args.input : undefined;
|
|
191
|
-
const direct = readTrimmedString(args.cmd) ??
|
|
192
|
-
readTrimmedString(args.command) ??
|
|
193
|
-
readTrimmedString(args.script) ??
|
|
194
|
-
readTrimmedString(args.toon) ??
|
|
195
|
-
readStringArrayCommand(args.cmd) ??
|
|
196
|
-
readStringArrayCommand(args.command);
|
|
197
|
-
if (direct) {
|
|
198
|
-
return direct;
|
|
199
|
-
}
|
|
200
|
-
if (!input) {
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
return (readTrimmedString(input.cmd) ??
|
|
204
|
-
readTrimmedString(input.command) ??
|
|
205
|
-
readTrimmedString(input.script) ??
|
|
206
|
-
readStringArrayCommand(input.cmd) ??
|
|
207
|
-
readStringArrayCommand(input.command));
|
|
208
|
-
}
|
|
209
|
-
function readWorkdirFromArgs(args) {
|
|
210
|
-
const input = isRecord(args.input) ? args.input : undefined;
|
|
211
|
-
return (readTrimmedString(args.workdir) ??
|
|
212
|
-
readTrimmedString(args.cwd) ??
|
|
213
|
-
readTrimmedString(args.workDir) ??
|
|
214
|
-
readTrimmedString(input?.workdir) ??
|
|
215
|
-
readTrimmedString(input?.cwd));
|
|
216
|
-
}
|
|
217
|
-
function collectRequestedToolNames(payload) {
|
|
218
|
-
const names = new Set();
|
|
219
|
-
const root = payload;
|
|
220
|
-
const tools = Array.isArray(root.tools) ? root.tools : [];
|
|
221
|
-
for (const tool of tools) {
|
|
222
|
-
if (!isRecord(tool))
|
|
223
|
-
continue;
|
|
224
|
-
const fn = isRecord(tool.function) ? tool.function : undefined;
|
|
225
|
-
const name = readTrimmedString(fn?.name) ?? readTrimmedString(tool.name);
|
|
226
|
-
if (name) {
|
|
227
|
-
names.add(name);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return names;
|
|
231
|
-
}
|
|
232
|
-
function resolveShellLikeToolName(rawName, requestedToolNames) {
|
|
233
|
-
if (requestedToolNames.size === 0) {
|
|
234
|
-
return rawName;
|
|
235
|
-
}
|
|
236
|
-
if (requestedToolNames.has(rawName)) {
|
|
237
|
-
return rawName;
|
|
238
|
-
}
|
|
239
|
-
if (requestedToolNames.has('exec_command')) {
|
|
240
|
-
return 'exec_command';
|
|
241
|
-
}
|
|
242
|
-
if (requestedToolNames.has('shell_command')) {
|
|
243
|
-
return 'shell_command';
|
|
244
|
-
}
|
|
245
|
-
return rawName;
|
|
246
|
-
}
|
|
247
|
-
function normalizeShellLikeToolCallsBeforeGovernance(payload) {
|
|
248
|
-
const root = payload;
|
|
249
|
-
const messages = Array.isArray(root.messages) ? root.messages : [];
|
|
250
|
-
if (!messages.length) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const requestedToolNames = collectRequestedToolNames(payload);
|
|
254
|
-
for (const message of messages) {
|
|
255
|
-
if (!isRecord(message))
|
|
256
|
-
continue;
|
|
257
|
-
const role = readTrimmedString(message.role)?.toLowerCase();
|
|
258
|
-
if (role !== 'assistant')
|
|
259
|
-
continue;
|
|
260
|
-
const toolCalls = Array.isArray(message.tool_calls) ? message.tool_calls : [];
|
|
261
|
-
if (!toolCalls.length)
|
|
262
|
-
continue;
|
|
263
|
-
for (const call of toolCalls) {
|
|
264
|
-
if (!isRecord(call))
|
|
265
|
-
continue;
|
|
266
|
-
const fn = isRecord(call.function) ? call.function : undefined;
|
|
267
|
-
if (!fn)
|
|
268
|
-
continue;
|
|
269
|
-
const rawName = readTrimmedString(fn.name);
|
|
270
|
-
if (!rawName)
|
|
271
|
-
continue;
|
|
272
|
-
if (!SHELL_LIKE_TOOL_NAMES.has(rawName.toLowerCase()))
|
|
273
|
-
continue;
|
|
274
|
-
const resolvedName = resolveShellLikeToolName(rawName, requestedToolNames);
|
|
275
|
-
if (resolvedName !== rawName) {
|
|
276
|
-
fn.name = resolvedName;
|
|
277
|
-
}
|
|
278
|
-
const parsedArgs = parseJsonRecord(fn.arguments);
|
|
279
|
-
const args = parsedArgs ?? {};
|
|
280
|
-
const cmd = readCommandFromArgs(args);
|
|
281
|
-
if (!cmd) {
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
const nextArgs = {
|
|
285
|
-
...args,
|
|
286
|
-
cmd,
|
|
287
|
-
command: cmd
|
|
288
|
-
};
|
|
289
|
-
const workdir = readWorkdirFromArgs(args);
|
|
290
|
-
if (workdir) {
|
|
291
|
-
nextArgs.workdir = workdir;
|
|
292
|
-
}
|
|
293
|
-
if (Object.prototype.hasOwnProperty.call(nextArgs, 'toon')) {
|
|
294
|
-
delete nextArgs.toon;
|
|
295
|
-
}
|
|
296
|
-
try {
|
|
297
|
-
fn.arguments = JSON.stringify(nextArgs);
|
|
298
|
-
}
|
|
299
|
-
catch {
|
|
300
|
-
fn.arguments = JSON.stringify({ cmd, command: cmd, ...(workdir ? { workdir } : {}) });
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
function collectToolOutputs(payload) {
|
|
306
|
-
const aggregated = [];
|
|
307
|
-
const seen = new Set();
|
|
308
|
-
const append = (entry) => {
|
|
309
|
-
const id = (entry.tool_call_id || entry.call_id || '').trim();
|
|
310
|
-
if (!id) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
if (seen.has(id)) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
seen.add(id);
|
|
317
|
-
aggregated.push({
|
|
318
|
-
tool_call_id: entry.tool_call_id ?? entry.call_id,
|
|
319
|
-
call_id: entry.call_id ?? entry.tool_call_id,
|
|
320
|
-
output: entry.output,
|
|
321
|
-
name: entry.name
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
for (const record of readArray(payload, 'tool_outputs')) {
|
|
325
|
-
append(record);
|
|
326
|
-
}
|
|
327
|
-
for (const record of readRequiredActionOutputs(payload)) {
|
|
328
|
-
append(record);
|
|
329
|
-
}
|
|
330
|
-
for (const record of readMessageToolOutputs(payload)) {
|
|
331
|
-
append(record);
|
|
332
|
-
}
|
|
333
|
-
for (const record of readMessageContentToolOutputs(payload)) {
|
|
334
|
-
append(record);
|
|
335
|
-
}
|
|
336
|
-
for (const record of readResponsesInputToolOutputs(payload)) {
|
|
337
|
-
append(record);
|
|
338
|
-
}
|
|
339
|
-
return aggregated;
|
|
340
|
-
}
|
|
341
|
-
function readArray(payload, field) {
|
|
342
|
-
const raw = payload[field];
|
|
343
|
-
if (!Array.isArray(raw)) {
|
|
344
|
-
return [];
|
|
345
|
-
}
|
|
346
|
-
return raw
|
|
347
|
-
.map((entry) => normalizeToolOutputEntry(entry))
|
|
348
|
-
.filter((entry) => Boolean(entry));
|
|
349
|
-
}
|
|
350
|
-
function readRequiredActionOutputs(payload) {
|
|
351
|
-
const required = payload.required_action;
|
|
352
|
-
if (!required || typeof required !== 'object') {
|
|
353
|
-
return [];
|
|
354
|
-
}
|
|
355
|
-
const submit = required.submit_tool_outputs;
|
|
356
|
-
if (!submit || typeof submit !== 'object') {
|
|
357
|
-
return [];
|
|
358
|
-
}
|
|
359
|
-
return readArray(submit, 'tool_outputs');
|
|
360
|
-
}
|
|
361
|
-
function readMessageToolOutputs(payload) {
|
|
362
|
-
const messages = payload.messages;
|
|
363
|
-
if (!Array.isArray(messages)) {
|
|
364
|
-
return [];
|
|
365
|
-
}
|
|
366
|
-
return messages
|
|
367
|
-
.map((entry) => {
|
|
368
|
-
if (!entry || typeof entry !== 'object') {
|
|
369
|
-
return undefined;
|
|
370
|
-
}
|
|
371
|
-
const record = entry;
|
|
372
|
-
const role = String(record.role || '').toLowerCase();
|
|
373
|
-
if (role !== 'tool') {
|
|
374
|
-
return undefined;
|
|
375
|
-
}
|
|
376
|
-
return normalizeToolOutputEntry({
|
|
377
|
-
tool_call_id: record.tool_call_id ?? record.call_id ?? record.id,
|
|
378
|
-
call_id: record.call_id ?? record.tool_call_id ?? record.id,
|
|
379
|
-
name: typeof record.name === 'string' ? record.name : undefined,
|
|
380
|
-
output: record.content ?? record.output
|
|
381
|
-
});
|
|
382
|
-
})
|
|
383
|
-
.filter((entry) => Boolean(entry));
|
|
384
|
-
}
|
|
385
|
-
function readMessageContentToolOutputs(payload) {
|
|
386
|
-
const messages = payload.messages;
|
|
387
|
-
if (!Array.isArray(messages)) {
|
|
388
|
-
return [];
|
|
389
|
-
}
|
|
390
|
-
const outputs = [];
|
|
391
|
-
for (const entry of messages) {
|
|
392
|
-
if (!entry || typeof entry !== 'object') {
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
const record = entry;
|
|
396
|
-
const contentList = record.content;
|
|
397
|
-
if (!Array.isArray(contentList)) {
|
|
398
|
-
continue;
|
|
399
|
-
}
|
|
400
|
-
for (const block of contentList) {
|
|
401
|
-
if (!block || typeof block !== 'object') {
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
const blockRecord = block;
|
|
405
|
-
const type = typeof blockRecord.type === 'string' ? blockRecord.type.toLowerCase() : '';
|
|
406
|
-
if (type !== 'tool_result' && type !== 'function_call_output' && type !== 'tool_message') {
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
const normalized = normalizeToolOutputEntry({
|
|
410
|
-
tool_call_id: blockRecord.tool_use_id ?? blockRecord.tool_call_id ?? blockRecord.call_id ?? blockRecord.id,
|
|
411
|
-
call_id: blockRecord.tool_use_id ?? blockRecord.tool_call_id ?? blockRecord.call_id ?? blockRecord.id,
|
|
412
|
-
name: typeof blockRecord.name === 'string' ? blockRecord.name : undefined,
|
|
413
|
-
output: blockRecord.content ?? blockRecord.output
|
|
414
|
-
});
|
|
415
|
-
if (normalized) {
|
|
416
|
-
outputs.push(normalized);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return outputs;
|
|
421
|
-
}
|
|
422
|
-
function readResponsesInputToolOutputs(payload) {
|
|
423
|
-
const input = payload.input;
|
|
424
|
-
if (!Array.isArray(input)) {
|
|
425
|
-
return [];
|
|
426
|
-
}
|
|
427
|
-
return input
|
|
428
|
-
.map((entry) => {
|
|
429
|
-
if (!entry || typeof entry !== 'object') {
|
|
430
|
-
return undefined;
|
|
431
|
-
}
|
|
432
|
-
const record = entry;
|
|
433
|
-
const type = String(record.type || '').toLowerCase();
|
|
434
|
-
if (type !== 'tool_result' && type !== 'tool_message' && type !== 'function_call_output') {
|
|
435
|
-
return undefined;
|
|
436
|
-
}
|
|
437
|
-
return normalizeToolOutputEntry({
|
|
438
|
-
tool_call_id: record.tool_call_id ?? record.call_id ?? record.tool_use_id,
|
|
439
|
-
call_id: record.call_id ?? record.tool_call_id ?? record.tool_use_id,
|
|
440
|
-
name: typeof record.name === 'string' ? record.name : undefined,
|
|
441
|
-
output: record.output
|
|
442
|
-
});
|
|
443
|
-
})
|
|
444
|
-
.filter((entry) => Boolean(entry));
|
|
445
|
-
}
|
|
446
|
-
const loggedApplyPatchErrorIds = new Set();
|
|
447
|
-
function normalizeToolOutputEntry(entry) {
|
|
448
|
-
if (!entry || typeof entry !== 'object') {
|
|
449
|
-
return undefined;
|
|
450
|
-
}
|
|
451
|
-
const record = entry;
|
|
452
|
-
const tool_call_id = typeof record.tool_call_id === 'string' && record.tool_call_id.trim().length
|
|
453
|
-
? record.tool_call_id.trim()
|
|
454
|
-
: undefined;
|
|
455
|
-
const call_id = typeof record.call_id === 'string' && record.call_id.trim().length
|
|
456
|
-
? record.call_id.trim()
|
|
457
|
-
: undefined;
|
|
458
|
-
const id = tool_call_id ?? call_id;
|
|
459
|
-
if (!id) {
|
|
460
|
-
return undefined;
|
|
461
|
-
}
|
|
462
|
-
let output;
|
|
463
|
-
const rawOutput = 'output' in record ? record.output : record.content;
|
|
464
|
-
if (typeof rawOutput === 'string') {
|
|
465
|
-
output = rawOutput;
|
|
466
|
-
}
|
|
467
|
-
else if (rawOutput !== undefined) {
|
|
468
|
-
try {
|
|
469
|
-
output = JSON.stringify(rawOutput);
|
|
470
|
-
}
|
|
471
|
-
catch {
|
|
472
|
-
output = String(rawOutput);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
const name = typeof record.name === 'string' && record.name.trim().length ? record.name.trim() : undefined;
|
|
476
|
-
return {
|
|
477
|
-
tool_call_id,
|
|
478
|
-
call_id,
|
|
479
|
-
output,
|
|
480
|
-
name
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
function buildToolParseDiagnostics(output) {
|
|
484
|
-
if (!output || typeof output !== 'string') {
|
|
485
|
-
return undefined;
|
|
486
|
-
}
|
|
487
|
-
const lower = output.toLowerCase();
|
|
488
|
-
if (!lower.includes('failed to parse function arguments')) {
|
|
489
|
-
return undefined;
|
|
490
|
-
}
|
|
491
|
-
if (output.includes('missing field `input`')) {
|
|
492
|
-
return {
|
|
493
|
-
kind: 'apply_patch',
|
|
494
|
-
text: '\n\n[RouteCodex precheck] apply_patch 参数解析失败:缺少字段 "input"。当前 RouteCodex 期望 { input, patch } 形态,并且两个字段都应包含完整统一 diff 文本。'
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
if (output.includes('invalid type: map, expected a string')) {
|
|
498
|
-
return {
|
|
499
|
-
kind: 'apply_patch',
|
|
500
|
-
text: '\n\n[RouteCodex precheck] apply_patch 参数类型错误:检测到 JSON 对象(map),但客户端期望字符串。请先对参数做 JSON.stringify 再写入 arguments,或直接提供 { patch: "<统一 diff>" } 形式。'
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
if (output.includes('missing field `command`')) {
|
|
504
|
-
return {
|
|
505
|
-
kind: 'shell_like',
|
|
506
|
-
text: '\n\n[RouteCodex precheck] shell/exec 参数解析失败:缺少字段 "command"。请改为 {"tool_calls":[{"name":"shell_command","input":{"command":"<cmd>"}}]};若调用 exec_command,建议同时提供 {"cmd":"<cmd>","command":"<cmd>"}。'
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
if (output.includes('missing field `cmd`')) {
|
|
510
|
-
return {
|
|
511
|
-
kind: 'shell_like',
|
|
512
|
-
text: '\n\n[RouteCodex precheck] shell/exec 参数解析失败:缺少字段 "cmd"。exec_command 推荐形状为 {"cmd":"<cmd>","command":"<cmd>","workdir":"<path>"}。'
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
return undefined;
|
|
516
|
-
}
|
|
517
|
-
function appendDiagnosticsToRecord(record) {
|
|
518
|
-
const name = typeof record.name === 'string' ? record.name.trim() : undefined;
|
|
519
|
-
let text;
|
|
520
|
-
if (typeof record.output === 'string') {
|
|
521
|
-
text = record.output;
|
|
522
|
-
}
|
|
523
|
-
else if (typeof record.content === 'string') {
|
|
524
|
-
text = record.content;
|
|
525
|
-
}
|
|
526
|
-
if (!text || text.includes('[RouteCodex precheck]')) {
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const diag = buildToolParseDiagnostics(text);
|
|
530
|
-
if (!diag) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
const normalizedName = name?.toLowerCase();
|
|
534
|
-
if (diag.kind === 'apply_patch' && normalizedName && normalizedName !== 'apply_patch') {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
if (diag.kind === 'shell_like' &&
|
|
538
|
-
normalizedName &&
|
|
539
|
-
!SHELL_LIKE_TOOL_NAMES.has(normalizedName)) {
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
const merged = `${text}${diag.text}`;
|
|
543
|
-
if (typeof record.output === 'string') {
|
|
544
|
-
record.output = merged;
|
|
545
|
-
}
|
|
546
|
-
else if (typeof record.content === 'string') {
|
|
547
|
-
record.content = merged;
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
record.output = merged;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
function injectApplyPatchDiagnostics(payload) {
|
|
554
|
-
const root = payload;
|
|
555
|
-
const topOutputs = root.tool_outputs;
|
|
556
|
-
if (Array.isArray(topOutputs)) {
|
|
557
|
-
for (const entry of topOutputs) {
|
|
558
|
-
if (entry && typeof entry === 'object') {
|
|
559
|
-
appendDiagnosticsToRecord(entry);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
const required = root.required_action;
|
|
564
|
-
if (required && typeof required === 'object') {
|
|
565
|
-
const submit = required.submit_tool_outputs;
|
|
566
|
-
if (submit && typeof submit === 'object') {
|
|
567
|
-
const submitOutputs = submit.tool_outputs;
|
|
568
|
-
if (Array.isArray(submitOutputs)) {
|
|
569
|
-
for (const entry of submitOutputs) {
|
|
570
|
-
if (entry && typeof entry === 'object') {
|
|
571
|
-
appendDiagnosticsToRecord(entry);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
const messages = root.messages;
|
|
578
|
-
if (Array.isArray(messages)) {
|
|
579
|
-
for (const entry of messages) {
|
|
580
|
-
if (!entry || typeof entry !== 'object')
|
|
581
|
-
continue;
|
|
582
|
-
const record = entry;
|
|
583
|
-
const role = typeof record.role === 'string' ? record.role.toLowerCase() : '';
|
|
584
|
-
if (role === 'tool') {
|
|
585
|
-
appendDiagnosticsToRecord(record);
|
|
586
|
-
}
|
|
587
|
-
const content = record.content;
|
|
588
|
-
if (Array.isArray(content)) {
|
|
589
|
-
for (const block of content) {
|
|
590
|
-
if (!block || typeof block !== 'object')
|
|
591
|
-
continue;
|
|
592
|
-
appendDiagnosticsToRecord(block);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
const responsesInput = root.input;
|
|
598
|
-
if (Array.isArray(responsesInput)) {
|
|
599
|
-
for (const entry of responsesInput) {
|
|
600
|
-
if (!entry || typeof entry !== 'object')
|
|
601
|
-
continue;
|
|
602
|
-
const record = entry;
|
|
603
|
-
const type = typeof record.type === 'string' ? record.type.toLowerCase() : '';
|
|
604
|
-
if (type === 'tool_result' || type === 'tool_message' || type === 'function_call_output') {
|
|
605
|
-
appendDiagnosticsToRecord(record);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
20
|
+
const protocol = normalizeProviderProtocolTokenWithNative(options.adapterContext.providerProtocol);
|
|
21
|
+
return buildToolOutputSnapshot(options.rawRequest, protocol);
|
|
609
22
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AdapterContext } from '../../../../types/chat-envelope.js';
|
|
2
|
+
import type { JsonObject } from '../../../../types/json.js';
|
|
3
|
+
import type { ResponsesRequestContext } from '../../../../../responses/responses-openai-bridge.js';
|
|
4
|
+
export interface ResponsesContextCaptureOptions {
|
|
5
|
+
rawRequest: JsonObject;
|
|
6
|
+
adapterContext: AdapterContext;
|
|
7
|
+
}
|
|
8
|
+
export declare function captureResponsesContextSnapshot(options: ResponsesContextCaptureOptions): ResponsesRequestContext;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { captureResponsesRequestContext } from '../../../../../shared/responses-conversation-store.js';
|
|
2
|
+
import { captureReqInboundResponsesContextSnapshotWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
3
|
+
export function captureResponsesContextSnapshot(options) {
|
|
4
|
+
const context = captureReqInboundResponsesContextSnapshotWithNative({
|
|
5
|
+
rawRequest: options.rawRequest,
|
|
6
|
+
requestId: options.adapterContext.requestId,
|
|
7
|
+
toolCallIdStyle: options.adapterContext.toolCallIdStyle
|
|
8
|
+
});
|
|
9
|
+
// OpenAI Responses tool loop: store the request context keyed by requestId so that
|
|
10
|
+
// `/v1/responses/:id/submit_tool_outputs` can resume the conversation later.
|
|
11
|
+
//
|
|
12
|
+
// This must be done on the hub pipeline inbound path (not in host/provider), because:
|
|
13
|
+
// - the tool loop is a client-protocol behavior (/v1/responses), independent of providerProtocol;
|
|
14
|
+
// - providers must remain transport-only;
|
|
15
|
+
// - the host may later enhance requestId with providerKey/model for logging, which is handled via rebind.
|
|
16
|
+
const requestId = typeof options.adapterContext.requestId === 'string' && options.adapterContext.requestId.trim().length
|
|
17
|
+
? options.adapterContext.requestId
|
|
18
|
+
: undefined;
|
|
19
|
+
if (requestId) {
|
|
20
|
+
// captureResponsesRequestContext already best-effort wraps store failures.
|
|
21
|
+
captureResponsesRequestContext({
|
|
22
|
+
requestId,
|
|
23
|
+
payload: options.rawRequest,
|
|
24
|
+
context: context
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
28
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { injectReqInboundToolParseDiagnosticsWithNative } from '../../../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
2
|
+
export function injectApplyPatchDiagnostics(payload) {
|
|
3
|
+
injectReqInboundToolParseDiagnosticsWithNative(payload);
|
|
4
|
+
}
|