@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,4 +1,5 @@
|
|
|
1
1
|
import { injectMcpToolsForChat } from './mcp-injection.js';
|
|
2
|
+
import { normalizeOpenaiChatMessagesWithNative, normalizeOpenaiMessageWithNative, normalizeOpenaiToolCallWithNative, normalizeOpenaiToolWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
2
3
|
// Message normalization utilities for OpenAI chat payloads (renamed to avoid confusion
|
|
3
4
|
// with the deprecated "openai-normalizer" module entry). This file contains the
|
|
4
5
|
// previously-implemented logic from openai-normalize.ts.
|
|
@@ -131,204 +132,14 @@ export function normalizeChatRequest(request) {
|
|
|
131
132
|
}
|
|
132
133
|
catch { /* ignore MCP injection */ }
|
|
133
134
|
}
|
|
134
|
-
//
|
|
135
|
-
try {
|
|
136
|
-
const msgs = Array.isArray(normalized.messages) ? normalized.messages : [];
|
|
137
|
-
for (const m of msgs) {
|
|
138
|
-
if (!m || m.role !== 'assistant' || !Array.isArray(m.tool_calls))
|
|
139
|
-
continue;
|
|
140
|
-
m.tool_calls = m.tool_calls.map((tc) => {
|
|
141
|
-
if (!tc || typeof tc !== 'object')
|
|
142
|
-
return tc;
|
|
143
|
-
const fn = tc.function || {};
|
|
144
|
-
// Only ensure arguments is a JSON string; do NOT reshape user-provided content
|
|
145
|
-
if (fn && typeof fn === 'object' && fn.arguments !== undefined && typeof fn.arguments !== 'string') {
|
|
146
|
-
try {
|
|
147
|
-
fn.arguments = JSON.stringify(fn.arguments);
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
fn.arguments = '""';
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return { ...tc, function: fn };
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
normalized.messages = msgs;
|
|
157
|
-
}
|
|
158
|
-
catch { /* ignore shell fixups */ }
|
|
159
|
-
// 删除“工具结果嵌回 assistant 文本”的逻辑,避免污染 assistant.content(统一在 role:'tool' 保留结构化结果)
|
|
160
|
-
// 始终对所有 role:'tool' 的消息做最小文本化(不截断/不添加提示),避免影响模型判断
|
|
135
|
+
// 工具消息文本化 + 最后一轮 call 结果一致化 + 空 assistant 回合清理(native)
|
|
161
136
|
try {
|
|
162
137
|
const msgs = Array.isArray(normalized.messages) ? normalized.messages : [];
|
|
163
138
|
if (msgs.length) {
|
|
164
|
-
|
|
165
|
-
// Do not truncate or annotate; return as-is
|
|
166
|
-
try {
|
|
167
|
-
return String(text ?? '');
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
return String(text ?? '');
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
const extractPlain = (raw) => {
|
|
174
|
-
try {
|
|
175
|
-
const s = String(raw ?? '');
|
|
176
|
-
if (s.trim().length === 0) {
|
|
177
|
-
return '执行成功(无输出)';
|
|
178
|
-
}
|
|
179
|
-
let obj = null;
|
|
180
|
-
try {
|
|
181
|
-
obj = JSON.parse(s);
|
|
182
|
-
}
|
|
183
|
-
catch {
|
|
184
|
-
obj = null;
|
|
185
|
-
}
|
|
186
|
-
return withTruncationNotice(s);
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return String(raw ?? '');
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
for (const m of msgs) {
|
|
193
|
-
if (!m || typeof m !== 'object')
|
|
194
|
-
continue;
|
|
195
|
-
if (String(m.role || '').toLowerCase() !== 'tool')
|
|
196
|
-
continue;
|
|
197
|
-
const c = m.content;
|
|
198
|
-
if (typeof c === 'string') {
|
|
199
|
-
m.content = extractPlain(c);
|
|
200
|
-
}
|
|
201
|
-
else if (c && typeof c === 'object') {
|
|
202
|
-
try {
|
|
203
|
-
m.content = String(JSON.stringify(c));
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
m.content = String(c);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else if (c != null) {
|
|
210
|
-
m.content = withTruncationNotice(String(c));
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
m.content = '执行成功(无输出)';
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
normalized.messages = msgs;
|
|
139
|
+
normalized.messages = normalizeOpenaiChatMessagesWithNative(msgs);
|
|
217
140
|
}
|
|
218
141
|
}
|
|
219
|
-
catch { /* ignore
|
|
220
|
-
// 对所有工具结果做最小文本化(不裁剪);同时对“最后一轮”做一致化处理。
|
|
221
|
-
try {
|
|
222
|
-
const msgs = Array.isArray(normalized.messages) ? normalized.messages : [];
|
|
223
|
-
const withTruncationNotice = (text) => {
|
|
224
|
-
// No truncation / annotation; pass-through
|
|
225
|
-
try {
|
|
226
|
-
return typeof text === 'string' ? text : String(text ?? '');
|
|
227
|
-
}
|
|
228
|
-
catch {
|
|
229
|
-
return String(text ?? '');
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
const extractPlain = (raw) => {
|
|
233
|
-
try {
|
|
234
|
-
const s = String(raw ?? '');
|
|
235
|
-
if (s.trim().length === 0) {
|
|
236
|
-
return '执行成功(无输出)';
|
|
237
|
-
}
|
|
238
|
-
let obj = null;
|
|
239
|
-
try {
|
|
240
|
-
obj = JSON.parse(s);
|
|
241
|
-
}
|
|
242
|
-
catch {
|
|
243
|
-
obj = null;
|
|
244
|
-
}
|
|
245
|
-
return withTruncationNotice(s);
|
|
246
|
-
}
|
|
247
|
-
catch {
|
|
248
|
-
return String(raw ?? '');
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
// 先对所有历史 tool 消息统一最小化+截断
|
|
252
|
-
for (const m of msgs) {
|
|
253
|
-
if (!m || typeof m !== 'object')
|
|
254
|
-
continue;
|
|
255
|
-
if (String(m.role || '').toLowerCase() !== 'tool')
|
|
256
|
-
continue;
|
|
257
|
-
const c = m.content;
|
|
258
|
-
if (typeof c === 'string') {
|
|
259
|
-
m.content = extractPlain(c);
|
|
260
|
-
}
|
|
261
|
-
else if (c && typeof c === 'object') {
|
|
262
|
-
try {
|
|
263
|
-
m.content = String(JSON.stringify(c));
|
|
264
|
-
}
|
|
265
|
-
catch {
|
|
266
|
-
m.content = String(c);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
else if (c != null) {
|
|
270
|
-
m.content = withTruncationNotice(String(c));
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
m.content = '执行成功(无输出)';
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
const lastAssistantIdx = (() => {
|
|
277
|
-
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
278
|
-
const m = msgs[i];
|
|
279
|
-
if (m && m.role === 'assistant' && Array.isArray(m.tool_calls) && m.tool_calls.length)
|
|
280
|
-
return i;
|
|
281
|
-
}
|
|
282
|
-
return -1;
|
|
283
|
-
})();
|
|
284
|
-
if (lastAssistantIdx >= 0) {
|
|
285
|
-
const callIds = new Set();
|
|
286
|
-
try {
|
|
287
|
-
for (const tc of msgs[lastAssistantIdx].tool_calls) {
|
|
288
|
-
const id = typeof tc?.id === 'string' ? tc.id : undefined;
|
|
289
|
-
if (id)
|
|
290
|
-
callIds.add(id);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
catch { /* ignore */ }
|
|
294
|
-
for (let i = lastAssistantIdx + 1; i < msgs.length; i++) {
|
|
295
|
-
const m = msgs[i];
|
|
296
|
-
if (!m || m.role !== 'tool')
|
|
297
|
-
continue;
|
|
298
|
-
const cid = typeof m.tool_call_id === 'string' ? m.tool_call_id : undefined;
|
|
299
|
-
if (!cid || !callIds.has(cid))
|
|
300
|
-
continue;
|
|
301
|
-
const plain = extractPlain(m.content);
|
|
302
|
-
m.content = withTruncationNotice(plain);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
catch { /* ignore sanitize errors */ }
|
|
307
|
-
// 删除“无 tool_calls 且内容为空/仅空白”的 assistant 回合(降噪,避免部分上游对空 turn 敏感)
|
|
308
|
-
try {
|
|
309
|
-
const msgs = Array.isArray(normalized.messages) ? normalized.messages : [];
|
|
310
|
-
const isEmptyContent = (c) => {
|
|
311
|
-
if (c === null || c === undefined)
|
|
312
|
-
return true;
|
|
313
|
-
if (typeof c === 'string')
|
|
314
|
-
return c.trim().length === 0;
|
|
315
|
-
if (Array.isArray(c)) {
|
|
316
|
-
const txt = c.map((p) => (p && typeof p.text === 'string') ? p.text : '').filter(Boolean).join('').trim();
|
|
317
|
-
return txt.length === 0;
|
|
318
|
-
}
|
|
319
|
-
return false;
|
|
320
|
-
};
|
|
321
|
-
const filtered = msgs.filter((m) => {
|
|
322
|
-
if (!m || m.role !== 'assistant')
|
|
323
|
-
return true;
|
|
324
|
-
const hasTools = Array.isArray(m.tool_calls) && m.tool_calls.length > 0;
|
|
325
|
-
if (hasTools)
|
|
326
|
-
return true;
|
|
327
|
-
return !isEmptyContent(m.content);
|
|
328
|
-
});
|
|
329
|
-
normalized.messages = filtered;
|
|
330
|
-
}
|
|
331
|
-
catch { /* ignore */ }
|
|
142
|
+
catch { /* ignore message normalization */ }
|
|
332
143
|
// 注意:不合并/删除多条 system(与 统一标准,避免高风险修改)。
|
|
333
144
|
// 基于“载荷预算”(配置驱动)进行分层裁剪,避免整体载荷超限导致上游 500。
|
|
334
145
|
try {
|
|
@@ -386,99 +197,16 @@ function normalizeChatResponse(res) {
|
|
|
386
197
|
}
|
|
387
198
|
}
|
|
388
199
|
function normalizeMessage(message) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
// 保持 null/undefined 为原样,避免将其强制为 ''。
|
|
393
|
-
// 多数 OpenAI 兼容实现允许 assistant 在包含 tool_calls 时使用 content=null。
|
|
394
|
-
if (normalizedMessage.content === undefined || normalizedMessage.content === null) {
|
|
395
|
-
// do not coerce to empty string
|
|
396
|
-
}
|
|
397
|
-
else if (typeof normalizedMessage.content === 'string') {
|
|
398
|
-
// keep as-is
|
|
399
|
-
}
|
|
400
|
-
else if (Array.isArray(normalizedMessage.content)) {
|
|
401
|
-
// keep structured array
|
|
402
|
-
}
|
|
403
|
-
else if (typeof normalizedMessage.content === 'object') {
|
|
404
|
-
// keep structured object
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
normalizedMessage.content = String(normalizedMessage.content);
|
|
408
|
-
}
|
|
409
|
-
if (normalizedMessage.role === 'assistant' && Array.isArray(normalizedMessage.tool_calls)) {
|
|
410
|
-
normalizedMessage.tool_calls = normalizedMessage.tool_calls.map((toolCall) => normalizeToolCall(toolCall));
|
|
411
|
-
}
|
|
412
|
-
return normalizedMessage;
|
|
200
|
+
const disableShellCoerce = String(process?.env?.RCC_DISABLE_SHELL_COERCE ?? process?.env?.ROUTECODEX_DISABLE_SHELL_COERCE ?? '').toLowerCase();
|
|
201
|
+
const isDisabled = disableShellCoerce === '1' || disableShellCoerce === 'true';
|
|
202
|
+
return normalizeOpenaiMessageWithNative(message, isDisabled);
|
|
413
203
|
}
|
|
414
204
|
function normalizeTool(tool) {
|
|
415
|
-
|
|
416
|
-
return tool;
|
|
417
|
-
const normalizedTool = { ...tool };
|
|
418
|
-
if (normalizedTool.type === 'function' && normalizedTool.function) {
|
|
419
|
-
const fn = { ...normalizedTool.function };
|
|
420
|
-
if (fn.parameters && typeof fn.parameters !== 'object') {
|
|
421
|
-
try {
|
|
422
|
-
fn.parameters = JSON.parse(String(fn.parameters));
|
|
423
|
-
}
|
|
424
|
-
catch {
|
|
425
|
-
fn.parameters = {};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
normalizedTool.function = fn;
|
|
429
|
-
}
|
|
430
|
-
return normalizedTool;
|
|
205
|
+
return normalizeOpenaiToolWithNative(tool);
|
|
431
206
|
}
|
|
432
207
|
function normalizeToolCall(tc) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (t.function && typeof t.function === 'object') {
|
|
437
|
-
const fn = { ...t.function };
|
|
438
|
-
const argStrIn = typeof fn.arguments === 'string' ? fn.arguments : (fn.arguments != null ? JSON.stringify(fn.arguments) : '{}');
|
|
439
|
-
let argsObj = {};
|
|
440
|
-
try {
|
|
441
|
-
argsObj = JSON.parse(argStrIn);
|
|
442
|
-
}
|
|
443
|
-
catch {
|
|
444
|
-
argsObj = {};
|
|
445
|
-
}
|
|
446
|
-
// Drop dotted-name prefix unconditionally; keep only base function name
|
|
447
|
-
if (typeof fn.name === 'string' && fn.name.includes('.')) {
|
|
448
|
-
const dot = fn.name.indexOf('.');
|
|
449
|
-
fn.name = fn.name.slice(dot + 1).trim();
|
|
450
|
-
}
|
|
451
|
-
// Shell command coercion (can be disabled via env)
|
|
452
|
-
const disableShellCoerce = String(process?.env?.RCC_DISABLE_SHELL_COERCE ?? process?.env?.ROUTECODEX_DISABLE_SHELL_COERCE ?? '').toLowerCase();
|
|
453
|
-
const isDisabled = disableShellCoerce === '1' || disableShellCoerce === 'true';
|
|
454
|
-
if (!isDisabled && String(fn.name || '').toLowerCase() === 'shell') {
|
|
455
|
-
const cmdVal = argsObj?.command;
|
|
456
|
-
if (typeof cmdVal === 'string' && cmdVal.trim().length > 0) {
|
|
457
|
-
const s = cmdVal.trim();
|
|
458
|
-
const hasMeta = /[<>|;&]/.test(s) || s.includes('&&') || s.includes('||') || s.includes('<<');
|
|
459
|
-
if (hasMeta) {
|
|
460
|
-
argsObj.command = ['bash', '-lc', s];
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
argsObj.command = splitCommandString(s);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
else if (Array.isArray(cmdVal)) {
|
|
467
|
-
const toks = cmdVal.map((x) => String(x));
|
|
468
|
-
if (toks.length > 3 && toks[0] === 'bash' && toks[1] === '-lc') {
|
|
469
|
-
argsObj.command = ['bash', '-lc', toks.slice(2).join(' ')];
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
try {
|
|
474
|
-
fn.arguments = JSON.stringify(argsObj);
|
|
475
|
-
}
|
|
476
|
-
catch {
|
|
477
|
-
fn.arguments = argStrIn;
|
|
478
|
-
}
|
|
479
|
-
t.function = fn;
|
|
480
|
-
}
|
|
481
|
-
return t;
|
|
208
|
+
const disableShellCoerce = String(process?.env?.RCC_DISABLE_SHELL_COERCE ?? process?.env?.ROUTECODEX_DISABLE_SHELL_COERCE ?? '').toLowerCase();
|
|
209
|
+
const isDisabled = disableShellCoerce === '1' || disableShellCoerce === 'true';
|
|
210
|
+
return normalizeOpenaiToolCallWithNative(tc, isDisabled);
|
|
482
211
|
}
|
|
483
|
-
import { splitCommandString } from './tooling.js';
|
|
484
212
|
import { resolveBudgetForModelSync } from './payload-budget.js';
|
|
@@ -1,119 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function collectTextAndReasoning(blocks, collector) {
|
|
3
|
-
const pushText = (value) => {
|
|
4
|
-
if (typeof value === 'string' && value.trim().length) {
|
|
5
|
-
const cleaned = extractReasoningSegments(value, collector.reasoningParts);
|
|
6
|
-
if (cleaned.length) {
|
|
7
|
-
collector.textParts.push(cleaned);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
if (typeof blocks === 'string') {
|
|
12
|
-
pushText(blocks);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (!Array.isArray(blocks))
|
|
16
|
-
return;
|
|
17
|
-
for (const block of blocks) {
|
|
18
|
-
if (!block || typeof block !== 'object')
|
|
19
|
-
continue;
|
|
20
|
-
const type = typeof block.type === 'string' ? String(block.type).toLowerCase() : '';
|
|
21
|
-
if (type === 'text' || type === 'input_text' || type === 'output_text' || type === 'commentary') {
|
|
22
|
-
pushText(block.text ?? block.content);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (Array.isArray(block.content)) {
|
|
26
|
-
collectTextAndReasoning(block.content, collector);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (typeof block.text === 'string') {
|
|
30
|
-
pushText(block.text);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { extractOutputSegmentsWithNative, normalizeContentPartWithNative, normalizeMessageContentPartsWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
34
2
|
export function extractOutputSegments(source, itemsKey = 'output') {
|
|
35
|
-
|
|
36
|
-
return { textParts: [], reasoningParts: [] };
|
|
37
|
-
}
|
|
38
|
-
const outputItems = Array.isArray(source[itemsKey]) ? source[itemsKey] : [];
|
|
39
|
-
const result = { textParts: [], reasoningParts: [] };
|
|
40
|
-
for (const item of outputItems) {
|
|
41
|
-
if (!item || typeof item !== 'object')
|
|
42
|
-
continue;
|
|
43
|
-
const type = typeof item.type === 'string' ? String(item.type).toLowerCase() : '';
|
|
44
|
-
if (type === 'message') {
|
|
45
|
-
const message = item.message && typeof item.message === 'object'
|
|
46
|
-
? item.message
|
|
47
|
-
: item;
|
|
48
|
-
const content = Array.isArray(message.content) ? message.content : [];
|
|
49
|
-
collectTextAndReasoning(content, result);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (type === 'output_text' && typeof item.text === 'string') {
|
|
53
|
-
const cleaned = extractReasoningSegments(item.text, result.reasoningParts);
|
|
54
|
-
if (cleaned.length) {
|
|
55
|
-
result.textParts.push(cleaned);
|
|
56
|
-
}
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (type === 'reasoning') {
|
|
60
|
-
const content = Array.isArray(item.content) ? item.content : [];
|
|
61
|
-
for (const block of content) {
|
|
62
|
-
if (block && typeof block === 'object' && typeof block.text === 'string') {
|
|
63
|
-
const sanitized = sanitizeReasoningTaggedText(block.text);
|
|
64
|
-
if (sanitized.length)
|
|
65
|
-
result.reasoningParts.push(sanitized);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
3
|
+
return extractOutputSegmentsWithNative(source, itemsKey);
|
|
71
4
|
}
|
|
72
5
|
export function normalizeContentPart(part, reasoningCollector) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const cleaned = extractReasoningSegments(part, reasoningCollector);
|
|
77
|
-
return { type: 'output_text', text: cleaned };
|
|
78
|
-
}
|
|
79
|
-
if (typeof part !== 'object') {
|
|
80
|
-
return { type: 'output_text', text: sanitizeReasoningTaggedText(String(part)) };
|
|
81
|
-
}
|
|
82
|
-
const clone = { ...part };
|
|
83
|
-
delete clone._initialText;
|
|
84
|
-
delete clone._hasDelta;
|
|
85
|
-
if (typeof clone.text === 'string') {
|
|
86
|
-
clone.text = extractReasoningSegments(clone.text, reasoningCollector);
|
|
87
|
-
}
|
|
88
|
-
if (clone.output_text && typeof clone.output_text === 'object' && typeof clone.output_text.text === 'string') {
|
|
89
|
-
clone.output_text = {
|
|
90
|
-
...clone.output_text,
|
|
91
|
-
text: extractReasoningSegments(clone.output_text.text, reasoningCollector)
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
if (typeof clone.content === 'string') {
|
|
95
|
-
clone.content = extractReasoningSegments(clone.content, reasoningCollector);
|
|
96
|
-
}
|
|
97
|
-
if (!clone.type)
|
|
98
|
-
clone.type = 'output_text';
|
|
99
|
-
if (clone.type === 'output_text' && typeof clone.text !== 'string') {
|
|
100
|
-
clone.text = '';
|
|
101
|
-
}
|
|
102
|
-
return clone;
|
|
6
|
+
const normalized = normalizeContentPartWithNative(part, reasoningCollector);
|
|
7
|
+
reasoningCollector.splice(0, reasoningCollector.length, ...normalized.reasoningCollector);
|
|
8
|
+
return normalized.normalized;
|
|
103
9
|
}
|
|
104
10
|
export function normalizeMessageContentParts(parts, reasoningCollector) {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const normalized = normalizeContentPart(parts, reasoningChunks);
|
|
109
|
-
if (normalized)
|
|
110
|
-
normalizedParts.push(normalized);
|
|
111
|
-
return { normalizedParts, reasoningChunks };
|
|
112
|
-
}
|
|
113
|
-
for (const part of parts) {
|
|
114
|
-
const normalized = normalizeContentPart(part, reasoningChunks);
|
|
115
|
-
if (normalized)
|
|
116
|
-
normalizedParts.push(normalized);
|
|
11
|
+
const normalized = normalizeMessageContentPartsWithNative(parts, reasoningCollector ?? []);
|
|
12
|
+
if (reasoningCollector) {
|
|
13
|
+
reasoningCollector.splice(0, reasoningCollector.length, ...normalized.reasoningChunks);
|
|
117
14
|
}
|
|
118
|
-
return
|
|
15
|
+
return normalized;
|
|
119
16
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// 4) default 200_000 bytes
|
|
7
7
|
// Safety headroom: 10% (env RCC_CONTEXT_BUDGET_SAFETY to override; default 0.1)
|
|
8
8
|
import { UnifiedConfig } from '../../config-unified/unified-config.js';
|
|
9
|
+
import { enforceChatBudgetWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
9
10
|
function isObject(v) { return !!v && typeof v === 'object' && !Array.isArray(v); }
|
|
10
11
|
function listMergedConfigsSync(configDir) {
|
|
11
12
|
try {
|
|
@@ -157,91 +158,7 @@ export function enforceChatBudget(chat, modelId) {
|
|
|
157
158
|
const n = Number(raw);
|
|
158
159
|
return Number.isFinite(n) && n >= 0 ? n : 8192;
|
|
159
160
|
})();
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
return Buffer.byteLength(JSON.stringify(obj), 'utf8');
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
return 0;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
const clamp = (s, n) => {
|
|
169
|
-
if (typeof s !== 'string')
|
|
170
|
-
return s;
|
|
171
|
-
if (n === 0)
|
|
172
|
-
return '';
|
|
173
|
-
return s.length > n ? (s.slice(0, n) + '...(truncated)') : s;
|
|
174
|
-
};
|
|
175
|
-
// 1) System message truncation
|
|
176
|
-
try {
|
|
177
|
-
if (sysLimit >= 0 && messages.length) {
|
|
178
|
-
const first = messages[0];
|
|
179
|
-
if (first && String(first.role || '').toLowerCase() === 'system' && typeof first.content === 'string') {
|
|
180
|
-
first.content = clamp(first.content, sysLimit);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch { /* ignore */ }
|
|
185
|
-
// 2) Remove empty assistant without tool_calls
|
|
186
|
-
try {
|
|
187
|
-
const kept = [];
|
|
188
|
-
for (const m of messages) {
|
|
189
|
-
if (!m || typeof m !== 'object') {
|
|
190
|
-
kept.push(m);
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
const role = String(m.role || '').toLowerCase();
|
|
194
|
-
if (role === 'assistant' && (!Array.isArray(m.tool_calls) || m.tool_calls.length === 0)) {
|
|
195
|
-
const text = typeof m.content === 'string' ? m.content.trim() : '';
|
|
196
|
-
if (!text) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
kept.push(m);
|
|
201
|
-
}
|
|
202
|
-
chat.messages = kept;
|
|
203
|
-
}
|
|
204
|
-
catch { /* ignore */ }
|
|
205
|
-
if (size(chat) <= allowed)
|
|
206
|
-
return chat;
|
|
207
|
-
// 3) Clamp tool messages iteratively
|
|
208
|
-
const passes = [4000, 1500, 400, 100];
|
|
209
|
-
for (const limit of passes) {
|
|
210
|
-
for (const m of chat.messages) {
|
|
211
|
-
try {
|
|
212
|
-
if (!m || typeof m !== 'object')
|
|
213
|
-
continue;
|
|
214
|
-
if (String(m.role || '').toLowerCase() !== 'tool')
|
|
215
|
-
continue;
|
|
216
|
-
if (typeof m.content === 'string')
|
|
217
|
-
m.content = clamp(m.content, limit);
|
|
218
|
-
}
|
|
219
|
-
catch { /* ignore */ }
|
|
220
|
-
}
|
|
221
|
-
if (size(chat) <= allowed)
|
|
222
|
-
return chat;
|
|
223
|
-
}
|
|
224
|
-
// 4) Lightly clamp assistant text if still above budget
|
|
225
|
-
for (const limit of [8000, 4000, 1500]) {
|
|
226
|
-
for (const m of chat.messages) {
|
|
227
|
-
try {
|
|
228
|
-
if (!m || typeof m !== 'object')
|
|
229
|
-
continue;
|
|
230
|
-
if (String(m.role || '').toLowerCase() !== 'assistant')
|
|
231
|
-
continue;
|
|
232
|
-
if (Array.isArray(m.tool_calls) && m.tool_calls.length > 0)
|
|
233
|
-
continue; // do not clamp assistant with tools here
|
|
234
|
-
if (typeof m.content === 'string')
|
|
235
|
-
m.content = clamp(m.content, limit);
|
|
236
|
-
else if (Array.isArray(m.content)) {
|
|
237
|
-
m.content = m.content.map((p) => (p && typeof p.text === 'string') ? { ...p, text: clamp(p.text, limit) } : p);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
catch { /* ignore */ }
|
|
241
|
-
}
|
|
242
|
-
if (size(chat) <= allowed)
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
161
|
+
return enforceChatBudgetWithNative(chat, allowed, sysLimit);
|
|
245
162
|
}
|
|
246
163
|
catch { /* ignore budget errors */ }
|
|
247
164
|
return chat;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { isJsonObject } from '../hub/types/json.js';
|
|
2
|
+
import { ensureProtocolStateWithNative, getProtocolStateWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
2
3
|
const PROTOCOL_STATE_KEY = 'protocolState';
|
|
3
4
|
export function ensureProtocolState(metadata, protocol) {
|
|
5
|
+
const native = ensureProtocolStateWithNative(metadata, protocol);
|
|
6
|
+
for (const key of Object.keys(metadata)) {
|
|
7
|
+
if (!Object.prototype.hasOwnProperty.call(native.metadata, key)) {
|
|
8
|
+
delete metadata[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
Object.assign(metadata, native.metadata);
|
|
4
12
|
if (!metadata[PROTOCOL_STATE_KEY] || !isJsonObject(metadata[PROTOCOL_STATE_KEY])) {
|
|
5
13
|
metadata[PROTOCOL_STATE_KEY] = {};
|
|
6
14
|
}
|
|
7
15
|
const container = metadata[PROTOCOL_STATE_KEY];
|
|
8
16
|
if (!isJsonObject(container[protocol])) {
|
|
9
|
-
container[protocol] =
|
|
17
|
+
container[protocol] = native.node;
|
|
10
18
|
}
|
|
11
19
|
return container[protocol];
|
|
12
20
|
}
|
|
@@ -14,10 +22,6 @@ export function getProtocolState(metadata, protocol) {
|
|
|
14
22
|
if (!metadata) {
|
|
15
23
|
return undefined;
|
|
16
24
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
const node = store[protocol];
|
|
22
|
-
return isJsonObject(node) ? node : undefined;
|
|
25
|
+
const node = getProtocolStateWithNative(metadata, protocol);
|
|
26
|
+
return node && isJsonObject(node) ? node : undefined;
|
|
23
27
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
+
import { mapReasoningContentToResponsesOutputWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
1
2
|
export function mapReasoningContentToResponsesOutput(reasoningContent) {
|
|
2
|
-
|
|
3
|
-
return [];
|
|
4
|
-
const text = Array.isArray(reasoningContent)
|
|
5
|
-
? reasoningContent.map((r) => (typeof r?.text === 'string' ? r.text : '')).filter(Boolean).join('\n')
|
|
6
|
-
: (typeof reasoningContent?.text === 'string' ? reasoningContent.text : '');
|
|
7
|
-
return text ? [{ type: 'reasoning', content: text }] : [];
|
|
3
|
+
return mapReasoningContentToResponsesOutputWithNative(reasoningContent);
|
|
8
4
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalizeChatMessageContent } from './chat-output-normalizer.js';
|
|
2
2
|
import { extractReasoningSegments } from './reasoning-utils.js';
|
|
3
3
|
import { expandResponsesMessageItem } from '../../sse/shared/responses-output-normalizer.js';
|
|
4
|
+
import { sanitizeReasoningTaggedTextWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
|
|
4
5
|
export const RESPONSES_INSTRUCTIONS_REASONING_FIELD = '__rcc_reasoning_instructions';
|
|
5
6
|
function isRecord(value) {
|
|
6
7
|
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
@@ -253,7 +254,9 @@ function stripReasoningFromString(value) {
|
|
|
253
254
|
}
|
|
254
255
|
const segments = [];
|
|
255
256
|
const cleaned = extractReasoningSegments(value, segments);
|
|
256
|
-
|
|
257
|
+
const cleanedNative = sanitizeReasoningTaggedTextWithNative(value);
|
|
258
|
+
const stableCleaned = typeof cleanedNative === 'string' ? cleanedNative : cleaned;
|
|
259
|
+
return { cleaned: stableCleaned, segments };
|
|
257
260
|
}
|
|
258
261
|
function mergeReasoningText(existing, segments) {
|
|
259
262
|
const combined = [];
|