@jsonstudio/llms 0.6.2172 → 0.6.3214
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/args-mapping.js +8 -0
- package/dist/conversion/bridge-actions.js +367 -0
- package/dist/conversion/bridge-id-utils.js +13 -0
- package/dist/conversion/{shared/bridge-instructions.js → bridge-instructions.js} +2 -1
- package/dist/conversion/{shared/bridge-message-utils.d.ts → bridge-message-utils.d.ts} +1 -1
- package/dist/conversion/{shared/bridge-message-utils.js → bridge-message-utils.js} +5 -150
- package/dist/conversion/{shared/bridge-metadata.d.ts → bridge-metadata.d.ts} +1 -0
- package/dist/conversion/bridge-metadata.js +5 -0
- package/dist/conversion/bridge-policies.js +11 -0
- package/dist/conversion/codecs/gemini-openai-codec.js +27 -8
- package/dist/conversion/codecs/responses-openai-codec.js +1 -1
- package/dist/conversion/{shared/compaction-detect.d.ts → compaction-detect.d.ts} +1 -1
- package/dist/conversion/compaction-detect.js +4 -0
- package/dist/conversion/compat/actions/apply-patch-fixer.js +2 -2
- package/dist/conversion/compat/actions/deepseek-web-response.d.ts +0 -1
- package/dist/conversion/compat/actions/deepseek-web-response.js +15 -405
- package/dist/conversion/compat/actions/harvest-tool-calls-from-text.js +1 -1
- package/dist/conversion/compat/actions/lmstudio-responses-fc-ids.js +1 -1
- package/dist/conversion/compat/actions/qwen-transform.js +74 -2
- package/dist/conversion/compat/actions/snapshot.js +1 -1
- package/dist/conversion/compat/antigravity-session-signature.js +71 -1
- package/dist/conversion/compat/profiles/chat-deepseek-web.json +0 -22
- package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
- package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
- package/dist/conversion/compat/profiles/chat-glm.json +251 -72
- package/dist/conversion/compat/profiles/chat-iflow.json +174 -39
- package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -14
- 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 +12 -8
- package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +3 -3
- package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +16 -13
- package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +6 -10
- package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +21 -73
- 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.d.ts +1 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.js +165 -265
- 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.d.ts +1 -1
- package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +69 -81
- 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 +20 -3
- package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +11 -199
- 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 +54 -39
- package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +18 -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 +21 -149
- 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 +20 -26
- package/dist/conversion/hub/response/response-mappers.js +25 -27
- package/dist/conversion/hub/response/response-runtime.js +30 -98
- 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 +11 -4
- package/dist/conversion/hub/standardized-bridge.js +11 -288
- package/dist/conversion/hub/tool-governance/engine.d.ts +8 -0
- package/dist/conversion/hub/tool-governance/engine.js +25 -63
- package/dist/conversion/hub/tool-governance/rules.js +73 -69
- 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 +6 -4
- package/dist/conversion/index.d.ts +1 -2
- package/dist/conversion/index.js +1 -2
- package/dist/conversion/jsonish.js +20 -0
- package/dist/conversion/mcp-injection.js +7 -0
- package/dist/conversion/media.js +4 -0
- package/dist/conversion/{shared/metadata-passthrough.d.ts → metadata-passthrough.d.ts} +1 -1
- package/dist/conversion/metadata-passthrough.js +20 -0
- package/dist/conversion/payload-budget.js +47 -0
- package/dist/conversion/protocol-field-allowlists.d.ts +7 -0
- package/dist/conversion/protocol-field-allowlists.js +9 -0
- package/dist/conversion/{shared/protocol-state.d.ts → protocol-state.d.ts} +2 -2
- package/dist/conversion/protocol-state.js +27 -0
- package/dist/conversion/{shared/errors.d.ts → provider-protocol-error.d.ts} +0 -3
- package/dist/conversion/provider-protocol-error.js +25 -0
- package/dist/conversion/responses/responses-host-policy.js +2 -12
- package/dist/conversion/responses/responses-openai-bridge/response-payload.js +14 -87
- package/dist/conversion/responses/responses-openai-bridge/types.d.ts +2 -1
- package/dist/conversion/responses/responses-openai-bridge.d.ts +1 -1
- package/dist/conversion/responses/responses-openai-bridge.js +62 -62
- package/dist/conversion/{shared/runtime-metadata.d.ts → runtime-metadata.d.ts} +1 -1
- package/dist/conversion/runtime-metadata.js +31 -0
- package/dist/conversion/shared/anthropic-message-utils.js +170 -21
- package/dist/conversion/shared/chat-envelope-validator.js +2 -126
- package/dist/conversion/shared/chat-output-normalizer.js +2 -54
- package/dist/conversion/shared/chat-request-filters.d.ts +3 -4
- package/dist/conversion/shared/chat-request-filters.js +22 -78
- package/dist/conversion/shared/gemini-tool-utils.d.ts +1 -1
- package/dist/conversion/shared/gemini-tool-utils.js +9 -524
- package/dist/conversion/shared/openai-finalizer.js +3 -1
- package/dist/conversion/shared/openai-message-normalize.js +13 -285
- package/dist/conversion/shared/output-content-normalizer.js +9 -112
- package/dist/conversion/shared/reasoning-mapping.js +2 -6
- package/dist/conversion/shared/reasoning-normalizer.js +10 -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 +7 -8
- package/dist/conversion/shared/responses-conversation-store.js +5 -83
- package/dist/conversion/shared/responses-output-builder.js +63 -55
- package/dist/conversion/shared/responses-reasoning-registry.d.ts +14 -2
- package/dist/conversion/shared/responses-reasoning-registry.js +41 -7
- 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 +103 -14
- package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
- package/dist/conversion/shared/responses-tool-utils.js +91 -15
- package/dist/conversion/shared/streaming-text-extractor.js +2 -7
- package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +2 -2
- package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
- package/dist/conversion/shared/text-markup-normalizer.d.ts +3 -2
- package/dist/conversion/shared/text-markup-normalizer.js +2 -1
- 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-filter-pipeline.js +5 -100
- package/dist/conversion/shared/tool-governor.d.ts +6 -0
- package/dist/conversion/shared/tool-governor.js +45 -127
- package/dist/conversion/shared/tool-harvester.js +2 -8
- package/dist/conversion/shared/tool-mapping.d.ts +1 -1
- 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/conversion/{shared/snapshot-utils.d.ts → snapshot-utils.d.ts} +11 -0
- package/dist/conversion/{shared/snapshot-utils.js → snapshot-utils.js} +14 -23
- package/dist/conversion/{shared → types}/bridge-message-types.d.ts +2 -0
- package/dist/conversion/types/text-markup-normalizer.d.ts +13 -0
- package/dist/filters/special/request-tools-normalize.js +1 -1
- package/dist/filters/special/response-tool-text-canonicalize.js +2 -2
- package/dist/native/router_hotpath_napi.node +0 -0
- package/dist/quota/quota-manager.js +31 -59
- package/dist/quota/quota-state.js +14 -7
- package/dist/router/virtual-router/bootstrap/profile-builder.d.ts +1 -0
- package/dist/router/virtual-router/bootstrap/profile-builder.js +13 -0
- package/dist/router/virtual-router/bootstrap/provider-normalization.d.ts +2 -0
- package/dist/router/virtual-router/bootstrap/provider-normalization.js +4 -1
- package/dist/router/virtual-router/bootstrap/streaming-helpers.d.ts +7 -0
- package/dist/router/virtual-router/bootstrap/streaming-helpers.js +44 -0
- package/dist/router/virtual-router/bootstrap.js +2 -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.d.ts +1 -2
- package/dist/router/virtual-router/engine/routing-state/store.js +50 -14
- package/dist/router/virtual-router/engine-legacy/config.d.ts +11 -0
- package/dist/router/virtual-router/engine-legacy/config.js +108 -0
- package/dist/router/virtual-router/engine-legacy/direct-model.d.ts +10 -0
- package/dist/router/virtual-router/engine-legacy/direct-model.js +38 -0
- package/dist/router/virtual-router/engine-legacy/health.d.ts +13 -0
- package/dist/router/virtual-router/engine-legacy/health.js +104 -0
- package/dist/router/virtual-router/engine-legacy/helpers.d.ts +16 -0
- package/dist/router/virtual-router/engine-legacy/helpers.js +226 -0
- package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +9 -0
- package/dist/router/virtual-router/engine-legacy/route-finalize.js +84 -0
- package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +17 -0
- package/dist/router/virtual-router/engine-legacy/route-selection.js +205 -0
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +3 -0
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +36 -0
- package/dist/router/virtual-router/engine-legacy/route-state.d.ts +12 -0
- package/dist/router/virtual-router/engine-legacy/route-state.js +386 -0
- package/dist/router/virtual-router/engine-legacy/route-utils.d.ts +19 -0
- package/dist/router/virtual-router/engine-legacy/route-utils.js +212 -0
- package/dist/router/virtual-router/engine-legacy/routing.d.ts +8 -0
- package/dist/router/virtual-router/engine-legacy/routing.js +8 -0
- package/dist/router/virtual-router/engine-legacy/selection-core.d.ts +28 -0
- package/dist/router/virtual-router/engine-legacy/selection-core.js +112 -0
- package/dist/router/virtual-router/engine-legacy/selection-state.d.ts +16 -0
- package/dist/router/virtual-router/engine-legacy/selection-state.js +187 -0
- package/dist/router/virtual-router/engine-legacy/state-accessors.d.ts +21 -0
- package/dist/router/virtual-router/engine-legacy/state-accessors.js +118 -0
- package/dist/router/virtual-router/engine-legacy.d.ts +123 -0
- package/dist/router/virtual-router/engine-legacy.js +194 -0
- package/dist/router/virtual-router/engine-logging.d.ts +2 -0
- package/dist/router/virtual-router/engine-logging.js +11 -5
- package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
- package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -26
- 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-chat-request-filter-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.js +54 -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 +72 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +405 -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-governance-semantics.d.ts +22 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.js +154 -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 +320 -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 +151 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1371 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.js +69 -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-engine-proxy.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.js +14 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +86 -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 +216 -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 +128 -129
- package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
- package/dist/router/virtual-router/engine.d.ts +22 -105
- package/dist/router/virtual-router/engine.js +274 -1632
- package/dist/router/virtual-router/features.js +2 -2
- package/dist/router/virtual-router/load-balancer.d.ts +8 -0
- package/dist/router/virtual-router/load-balancer.js +65 -2
- package/dist/router/virtual-router/provider-registry.js +2 -0
- package/dist/router/virtual-router/routing-instructions/clean.d.ts +3 -0
- package/dist/router/virtual-router/routing-instructions/clean.js +34 -0
- package/dist/router/virtual-router/routing-instructions/parse.d.ts +18 -0
- package/dist/router/virtual-router/routing-instructions/parse.js +377 -0
- package/dist/router/virtual-router/routing-instructions/state.d.ts +4 -0
- package/dist/router/virtual-router/routing-instructions/state.js +245 -0
- package/dist/router/virtual-router/routing-instructions/types.d.ts +70 -0
- package/dist/router/virtual-router/routing-instructions/types.js +2 -0
- package/dist/router/virtual-router/routing-instructions.d.ts +5 -91
- package/dist/router/virtual-router/routing-instructions.js +4 -628
- 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.d.ts +4 -0
- package/dist/router/virtual-router/sticky-session-store.js +23 -83
- 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/tool-signals.js +21 -3
- package/dist/router/virtual-router/types.d.ts +13 -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 +29 -40
- package/dist/servertool/engine.d.ts +9 -0
- package/dist/servertool/engine.js +267 -79
- package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +3 -3
- package/dist/servertool/handlers/clock-auto.js +1 -1
- package/dist/servertool/handlers/clock.js +2 -2
- package/dist/servertool/handlers/compaction-detect.d.ts +1 -1
- package/dist/servertool/handlers/compaction-detect.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 +8 -2
- package/dist/servertool/handlers/iflow-model-error-retry.js +1 -1
- package/dist/servertool/handlers/recursive-detection-guard.js +1 -1
- package/dist/servertool/handlers/review.d.ts +1 -0
- 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 +398 -90
- 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 +36 -62
- package/dist/servertool/handlers/stop-message-auto.js +393 -77
- package/dist/servertool/handlers/vision.js +1 -1
- package/dist/servertool/handlers/web-search.js +1 -1
- package/dist/servertool/reenter-backend.js +1 -1
- package/dist/servertool/server-side-tools.d.ts +1 -0
- package/dist/servertool/server-side-tools.js +92 -54
- package/dist/servertool/stop-gateway-context.js +1 -1
- package/dist/servertool/stop-message-compare-context.js +1 -1
- package/dist/servertool/types.d.ts +17 -0
- package/dist/sse/json-to-sse/event-generators/responses.d.ts +4 -0
- package/dist/sse/json-to-sse/event-generators/responses.js +95 -1
- package/dist/sse/json-to-sse/sequencers/responses-sequencer.js +6 -4
- package/dist/sse/sse-to-json/builders/response-builder.d.ts +8 -0
- package/dist/sse/sse-to-json/builders/response-builder.js +162 -4
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +2 -0
- package/dist/sse/types/responses-types.d.ts +6 -2
- package/dist/tools/apply-patch/patch-text/normalize.js +11 -0
- package/dist/tools/apply-patch/structured/coercion.js +5 -0
- package/dist/tools/args-json.js +29 -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 +121 -10
- package/dist/conversion/shared/args-mapping.js +0 -221
- package/dist/conversion/shared/bridge-actions.js +0 -881
- package/dist/conversion/shared/bridge-id-utils.js +0 -79
- package/dist/conversion/shared/bridge-metadata.js +0 -1
- package/dist/conversion/shared/bridge-policies.js +0 -195
- package/dist/conversion/shared/compaction-detect.js +0 -59
- package/dist/conversion/shared/errors.js +0 -31
- package/dist/conversion/shared/jsonish.js +0 -177
- package/dist/conversion/shared/mcp-injection.js +0 -173
- package/dist/conversion/shared/media.js +0 -9
- package/dist/conversion/shared/metadata-passthrough.js +0 -57
- package/dist/conversion/shared/payload-budget.js +0 -248
- package/dist/conversion/shared/protocol-field-allowlists.d.ts +0 -7
- package/dist/conversion/shared/protocol-field-allowlists.js +0 -149
- package/dist/conversion/shared/protocol-state.js +0 -23
- package/dist/conversion/shared/runtime-metadata.js +0 -23
- package/dist/conversion/shared/snapshot-hooks.d.ts +0 -11
- package/dist/conversion/shared/snapshot-hooks.js +0 -503
- package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.d.ts +0 -2
- package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.js +0 -129
- package/dist/conversion/shared/text-markup-normalizer/extractors-json.d.ts +0 -4
- package/dist/conversion/shared/text-markup-normalizer/extractors-json.js +0 -637
- package/dist/conversion/shared/text-markup-normalizer/extractors-shared.d.ts +0 -21
- package/dist/conversion/shared/text-markup-normalizer/extractors-shared.js +0 -177
- package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.d.ts +0 -5
- package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.js +0 -385
- package/dist/conversion/shared/text-markup-normalizer/extractors-xml.d.ts +0 -10
- package/dist/conversion/shared/text-markup-normalizer/extractors-xml.js +0 -602
- package/dist/conversion/shared/text-markup-normalizer/extractors.d.ts +0 -5
- package/dist/conversion/shared/text-markup-normalizer/extractors.js +0 -4
- package/dist/conversion/shared/tool-canonicalizer.d.ts +0 -2
- package/dist/conversion/shared/tool-canonicalizer.js +0 -42
- 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/conversion/{shared/args-mapping.d.ts → args-mapping.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-actions.d.ts → bridge-actions.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-id-utils.d.ts → bridge-id-utils.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-instructions.d.ts → bridge-instructions.d.ts} +0 -0
- /package/dist/conversion/{shared/bridge-policies.d.ts → bridge-policies.d.ts} +0 -0
- /package/dist/conversion/{shared/jsonish.d.ts → jsonish.d.ts} +0 -0
- /package/dist/conversion/{shared/mcp-injection.d.ts → mcp-injection.d.ts} +0 -0
- /package/dist/conversion/{shared/media.d.ts → media.d.ts} +0 -0
- /package/dist/conversion/{shared/payload-budget.d.ts → payload-budget.d.ts} +0 -0
- /package/dist/conversion/{shared → types}/bridge-message-types.js +0 -0
- /package/dist/{servertool/handlers/stop-message-stage-policy/types.js → conversion/types/text-markup-normalizer.js} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { injectMcpToolsForChat } from '
|
|
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 {
|
|
484
|
-
import { resolveBudgetForModelSync } from './payload-budget.js';
|
|
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
|
}
|
|
@@ -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));
|
|
@@ -41,6 +42,9 @@ function normalizeChatChoice(choice) {
|
|
|
41
42
|
containers.forEach(container => applyNormalizedChatContent(container));
|
|
42
43
|
}
|
|
43
44
|
function applyNormalizedChatContent(container) {
|
|
45
|
+
const existingReasoning = typeof container.reasoning_content === 'string' && container.reasoning_content.trim().length
|
|
46
|
+
? container.reasoning_content.trim()
|
|
47
|
+
: undefined;
|
|
44
48
|
const normalized = normalizeChatMessageContent(container.content);
|
|
45
49
|
const role = typeof container.role === 'string' ? container.role : undefined;
|
|
46
50
|
if (normalized.contentText !== undefined && normalized.contentText.trim().length) {
|
|
@@ -55,6 +59,9 @@ function applyNormalizedChatContent(container) {
|
|
|
55
59
|
if (normalized.reasoningText && normalized.reasoningText.trim().length) {
|
|
56
60
|
container.reasoning_content = normalized.reasoningText.trim();
|
|
57
61
|
}
|
|
62
|
+
else if (existingReasoning) {
|
|
63
|
+
container.reasoning_content = existingReasoning;
|
|
64
|
+
}
|
|
58
65
|
else if ('reasoning_content' in container) {
|
|
59
66
|
delete container.reasoning_content;
|
|
60
67
|
}
|
|
@@ -253,7 +260,9 @@ function stripReasoningFromString(value) {
|
|
|
253
260
|
}
|
|
254
261
|
const segments = [];
|
|
255
262
|
const cleaned = extractReasoningSegments(value, segments);
|
|
256
|
-
|
|
263
|
+
const cleanedNative = sanitizeReasoningTaggedTextWithNative(value);
|
|
264
|
+
const stableCleaned = typeof cleanedNative === 'string' ? cleanedNative : cleaned;
|
|
265
|
+
return { cleaned: stableCleaned, segments };
|
|
257
266
|
}
|
|
258
267
|
function mergeReasoningText(existing, segments) {
|
|
259
268
|
const combined = [];
|
|
@@ -1,141 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
function flattenReasoning(value, depth = 0) {
|
|
6
|
-
if (depth > 4 || value == null) {
|
|
7
|
-
return '';
|
|
1
|
+
import { normalizeChatResponseReasoningToolsWithNative, normalizeMessageReasoningToolsWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
|
|
2
|
+
function overwriteRecordInPlace(target, source) {
|
|
3
|
+
for (const key of Object.keys(target)) {
|
|
4
|
+
delete target[key];
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
for (const [key, value] of Object.entries(source)) {
|
|
7
|
+
target[key] = value;
|
|
11
8
|
}
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
return value
|
|
14
|
-
.map((item) => flattenReasoning(item, depth + 1))
|
|
15
|
-
.filter(Boolean)
|
|
16
|
-
.join('\n');
|
|
17
|
-
}
|
|
18
|
-
if (typeof value === 'object') {
|
|
19
|
-
const record = value;
|
|
20
|
-
if (typeof record.text === 'string') {
|
|
21
|
-
return record.text;
|
|
22
|
-
}
|
|
23
|
-
if (typeof record.content === 'string') {
|
|
24
|
-
return record.content;
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(record.content) || typeof record.content === 'object') {
|
|
27
|
-
return flattenReasoning(record.content, depth + 1);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
function collectReasoningFragments(message) {
|
|
33
|
-
const fragments = [];
|
|
34
|
-
if ('reasoning_content' in message) {
|
|
35
|
-
const text = flattenReasoning(message.reasoning_content);
|
|
36
|
-
if (text) {
|
|
37
|
-
fragments.push(text);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if ('reasoning' in message) {
|
|
41
|
-
const text = flattenReasoning(message.reasoning);
|
|
42
|
-
if (text) {
|
|
43
|
-
fragments.push(text);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return fragments;
|
|
47
|
-
}
|
|
48
|
-
function writeReasoningContent(message, text) {
|
|
49
|
-
const trimmed = text.trim();
|
|
50
|
-
if (trimmed.length) {
|
|
51
|
-
message.reasoning_content = trimmed;
|
|
52
|
-
}
|
|
53
|
-
else if (Object.prototype.hasOwnProperty.call(message, 'reasoning_content')) {
|
|
54
|
-
delete message.reasoning_content;
|
|
55
|
-
}
|
|
56
|
-
if (typeof message.reasoning === 'string') {
|
|
57
|
-
if (trimmed.length) {
|
|
58
|
-
message.reasoning = trimmed;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
delete message.reasoning;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function stripReasoningTags(text) {
|
|
66
|
-
if (!text) {
|
|
67
|
-
return '';
|
|
68
|
-
}
|
|
69
|
-
return text.replace(THINK_TAG_PATTERN, '').replace(REFLECTION_TAG_PATTERN, '').trim();
|
|
70
9
|
}
|
|
71
10
|
export function normalizeMessageReasoningTools(message, options) {
|
|
72
11
|
if (!message || typeof message !== 'object') {
|
|
73
12
|
return { toolCallsAdded: 0 };
|
|
74
13
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const existing = typeof message.reasoning_content === 'string'
|
|
78
|
-
? message.reasoning_content.trim()
|
|
79
|
-
: '';
|
|
80
|
-
if (!existing && Object.prototype.hasOwnProperty.call(message, 'reasoning_content')) {
|
|
81
|
-
delete message.reasoning_content;
|
|
82
|
-
}
|
|
83
|
-
return { toolCallsAdded: 0 };
|
|
84
|
-
}
|
|
85
|
-
const combined = fragments.join('\n').trim();
|
|
86
|
-
if (!combined.length) {
|
|
87
|
-
writeReasoningContent(message, '');
|
|
88
|
-
return { toolCallsAdded: 0 };
|
|
89
|
-
}
|
|
90
|
-
const sanitized = stripReasoningTags(combined);
|
|
91
|
-
if (!sanitized.length) {
|
|
92
|
-
writeReasoningContent(message, '');
|
|
93
|
-
return { toolCallsAdded: 0 };
|
|
94
|
-
}
|
|
95
|
-
const idPrefix = options?.idPrefix ?? 'reasoning';
|
|
96
|
-
const { cleanedText, toolCalls } = extractToolCallsFromReasoningText(sanitized, { idPrefix });
|
|
97
|
-
const trimmed = (cleanedText || '').trim();
|
|
98
|
-
writeReasoningContent(message, trimmed);
|
|
99
|
-
// Chat 统一行为:如果 message 本身没有正文内容,但存在非空 reasoning_content,
|
|
100
|
-
// 则将思考内容提升到正文,前后包裹 [思考] 标记,避免客户端只看到"空回答"。
|
|
101
|
-
const rawContent = message.content;
|
|
102
|
-
if ((typeof rawContent !== 'string' || rawContent.trim().length === 0) &&
|
|
103
|
-
trimmed.length > 0) {
|
|
104
|
-
// 检查是否已经包含 [思考] 标签,避免重复嵌套
|
|
105
|
-
const hasThinkingTags = trimmed.includes('[思考]') && trimmed.includes('[/思考]');
|
|
106
|
-
message.content = hasThinkingTags ? trimmed : `[思考]\n${trimmed}\n[/思考]`;
|
|
107
|
-
}
|
|
108
|
-
if (!Array.isArray(toolCalls) || toolCalls.length === 0) {
|
|
109
|
-
return { toolCallsAdded: 0, cleanedReasoning: trimmed };
|
|
110
|
-
}
|
|
111
|
-
const current = Array.isArray(message.tool_calls)
|
|
112
|
-
? message.tool_calls
|
|
113
|
-
: undefined;
|
|
114
|
-
const merged = mergeToolCalls(current, toolCalls);
|
|
115
|
-
message.tool_calls = merged;
|
|
14
|
+
const normalized = normalizeMessageReasoningToolsWithNative(message, typeof options?.idPrefix === 'string' ? options.idPrefix : undefined);
|
|
15
|
+
overwriteRecordInPlace(message, normalized.message);
|
|
116
16
|
return {
|
|
117
|
-
toolCallsAdded:
|
|
118
|
-
cleanedReasoning
|
|
17
|
+
toolCallsAdded: normalized.toolCallsAdded,
|
|
18
|
+
...(typeof normalized.cleanedReasoning === 'string'
|
|
19
|
+
? { cleanedReasoning: normalized.cleanedReasoning }
|
|
20
|
+
: {})
|
|
119
21
|
};
|
|
120
22
|
}
|
|
121
23
|
export function normalizeChatResponseReasoningTools(response, options) {
|
|
122
24
|
if (!response || typeof response !== 'object') {
|
|
123
25
|
return;
|
|
124
26
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
: [];
|
|
128
|
-
for (let i = 0; i < choices.length; i++) {
|
|
129
|
-
const choice = choices[i];
|
|
130
|
-
if (!choice || typeof choice !== 'object') {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const message = choice.message;
|
|
134
|
-
if (!message || typeof message !== 'object') {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
normalizeMessageReasoningTools(message, {
|
|
138
|
-
idPrefix: `${options?.idPrefixBase ?? 'reasoning_choice'}_${i + 1}`
|
|
139
|
-
});
|
|
140
|
-
}
|
|
27
|
+
const normalized = normalizeChatResponseReasoningToolsWithNative(response, typeof options?.idPrefixBase === 'string' ? options.idPrefixBase : undefined);
|
|
28
|
+
overwriteRecordInPlace(response, normalized);
|
|
141
29
|
}
|