@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,293 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
const HUB_CAPTURE_KEY = '__hub_capture';
|
|
1
|
+
import { chatEnvelopeToStandardizedWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
|
|
2
|
+
import { standardizedToChatEnvelopeWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
|
|
4
3
|
export function chatEnvelopeToStandardized(chat, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const metadataCaptured = {};
|
|
11
|
-
const hubState = {};
|
|
12
|
-
if (Array.isArray(chat.metadata?.missingFields) && chat.metadata?.missingFields.length) {
|
|
13
|
-
hubState.missingFields = chat.metadata.missingFields;
|
|
14
|
-
}
|
|
15
|
-
if (isJsonObject(chat.metadata?.providerMetadata)) {
|
|
16
|
-
hubState.providerMetadata = chat.metadata?.providerMetadata;
|
|
17
|
-
}
|
|
18
|
-
if (isJsonObject(chat.metadata?.protocolState)) {
|
|
19
|
-
hubState.protocolState = chat.metadata?.protocolState;
|
|
20
|
-
}
|
|
21
|
-
hubState.context = options.adapterContext;
|
|
22
|
-
if (hubStateContextPopulated(hubState)) {
|
|
23
|
-
metadataCaptured[HUB_CAPTURE_KEY] = hubState;
|
|
24
|
-
}
|
|
25
|
-
const standardized = {
|
|
26
|
-
model,
|
|
27
|
-
messages,
|
|
28
|
-
tools,
|
|
29
|
-
parameters: {
|
|
30
|
-
...parameters
|
|
31
|
-
},
|
|
32
|
-
metadata: {
|
|
33
|
-
originalEndpoint: options.endpoint,
|
|
34
|
-
capturedContext: metadataCaptured,
|
|
35
|
-
requestId: options.requestId,
|
|
36
|
-
stream: parameters.stream === true
|
|
37
|
-
},
|
|
38
|
-
semantics
|
|
39
|
-
};
|
|
40
|
-
return standardized;
|
|
41
|
-
}
|
|
42
|
-
export function standardizedToChatEnvelope(request, options) {
|
|
43
|
-
const adapterContext = options.adapterContext;
|
|
44
|
-
const hubState = extractHubCapture(request);
|
|
45
|
-
const messages = request.messages.map((message) => {
|
|
46
|
-
const restoredContent = restoreMessageContent(message.content);
|
|
47
|
-
return {
|
|
48
|
-
role: message.role,
|
|
49
|
-
content: restoredContent,
|
|
50
|
-
tool_calls: mapToolCalls(message.tool_calls),
|
|
51
|
-
tool_call_id: message.tool_call_id,
|
|
52
|
-
name: message.name
|
|
53
|
-
};
|
|
4
|
+
return chatEnvelopeToStandardizedWithNative({
|
|
5
|
+
chatEnvelope: chat,
|
|
6
|
+
adapterContext: options.adapterContext,
|
|
7
|
+
endpoint: options.endpoint,
|
|
8
|
+
requestId: options.requestId
|
|
54
9
|
});
|
|
55
|
-
const tools = mapStandardizedTools(request.tools);
|
|
56
|
-
const parameters = {
|
|
57
|
-
...(request.parameters ?? {}),
|
|
58
|
-
model: request.model
|
|
59
|
-
};
|
|
60
|
-
const metadata = {
|
|
61
|
-
context: adapterContext
|
|
62
|
-
};
|
|
63
|
-
const sourceMeta = (request.metadata && typeof request.metadata === 'object'
|
|
64
|
-
? request.metadata
|
|
65
|
-
: undefined);
|
|
66
|
-
// E1: internal runtime metadata must live under the __rt carrier (never as top-level metadata keys).
|
|
67
|
-
// Merge runtime hints from AdapterContext + StandardizedRequest.metadata (legacy/compat).
|
|
68
|
-
try {
|
|
69
|
-
const merged = {
|
|
70
|
-
...(cloneRuntimeMetadata(adapterContext) ?? {}),
|
|
71
|
-
...(cloneRuntimeMetadata(sourceMeta ?? null) ?? {})
|
|
72
|
-
};
|
|
73
|
-
if (sourceMeta && typeof sourceMeta === 'object') {
|
|
74
|
-
if (sourceMeta.webSearch && typeof sourceMeta.webSearch === 'object' && merged.webSearch === undefined) {
|
|
75
|
-
merged.webSearch = sourceMeta.webSearch;
|
|
76
|
-
}
|
|
77
|
-
if (sourceMeta.forceWebSearch === true && merged.forceWebSearch === undefined) {
|
|
78
|
-
merged.forceWebSearch = true;
|
|
79
|
-
}
|
|
80
|
-
if (sourceMeta.forceVision === true && merged.forceVision === undefined) {
|
|
81
|
-
merged.forceVision = true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (Object.keys(merged).length) {
|
|
85
|
-
metadata.__rt = merged;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// best-effort
|
|
90
|
-
}
|
|
91
|
-
if (typeof adapterContext.toolCallIdStyle === 'string' && adapterContext.toolCallIdStyle.length) {
|
|
92
|
-
metadata.toolCallIdStyle = adapterContext.toolCallIdStyle;
|
|
93
|
-
}
|
|
94
|
-
if (hubState?.missingFields) {
|
|
95
|
-
metadata.missingFields = hubState.missingFields;
|
|
96
|
-
}
|
|
97
|
-
if (hubState?.providerMetadata) {
|
|
98
|
-
metadata.providerMetadata = hubState.providerMetadata;
|
|
99
|
-
}
|
|
100
|
-
if (hubState?.protocolState) {
|
|
101
|
-
metadata.protocolState = hubState.protocolState;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
messages,
|
|
105
|
-
tools,
|
|
106
|
-
parameters,
|
|
107
|
-
metadata,
|
|
108
|
-
semantics: cloneSemantics(request.semantics)
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function extractModel(parameters) {
|
|
112
|
-
const candidate = parameters.model;
|
|
113
|
-
if (typeof candidate === 'string' && candidate.trim()) {
|
|
114
|
-
return candidate.trim();
|
|
115
|
-
}
|
|
116
|
-
throw new Error('ChatEnvelope parameters must include model string');
|
|
117
|
-
}
|
|
118
|
-
function cloneSemantics(value) {
|
|
119
|
-
if (!value) {
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
return jsonClone(value);
|
|
123
10
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
-
if (Array.isArray(message.tool_calls) && message.tool_calls.length) {
|
|
130
|
-
normalized.tool_calls = message.tool_calls
|
|
131
|
-
.map((tool) => normalizeToolCall(tool))
|
|
132
|
-
.filter((tool) => Boolean(tool));
|
|
133
|
-
}
|
|
134
|
-
if (typeof message.tool_call_id === 'string') {
|
|
135
|
-
normalized.tool_call_id = message.tool_call_id.trim();
|
|
136
|
-
}
|
|
137
|
-
if (typeof message.name === 'string' && message.name.trim()) {
|
|
138
|
-
normalized.name = message.name.trim();
|
|
139
|
-
}
|
|
140
|
-
return normalized;
|
|
141
|
-
}
|
|
142
|
-
function cloneMessageContent(content) {
|
|
143
|
-
if (content === undefined || content === null) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
if (typeof content === 'string') {
|
|
147
|
-
return content;
|
|
148
|
-
}
|
|
149
|
-
if (Array.isArray(content)) {
|
|
150
|
-
return cloneContentArray(content);
|
|
151
|
-
}
|
|
152
|
-
return String(content);
|
|
153
|
-
}
|
|
154
|
-
function restoreMessageContent(content) {
|
|
155
|
-
if (content === undefined) {
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
if (content === null) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
if (typeof content === 'string') {
|
|
162
|
-
return content;
|
|
163
|
-
}
|
|
164
|
-
return cloneContentArray(content);
|
|
165
|
-
}
|
|
166
|
-
function cloneContentArray(parts) {
|
|
167
|
-
return parts.map((part) => {
|
|
168
|
-
if (part && typeof part === 'object') {
|
|
169
|
-
return jsonClone(part);
|
|
170
|
-
}
|
|
171
|
-
const text = typeof part === 'string' ? part : String(part ?? '');
|
|
172
|
-
const fallback = {
|
|
173
|
-
type: 'text',
|
|
174
|
-
text
|
|
175
|
-
};
|
|
176
|
-
return fallback;
|
|
11
|
+
export function standardizedToChatEnvelope(request, options) {
|
|
12
|
+
return standardizedToChatEnvelopeWithNative({
|
|
13
|
+
request: request,
|
|
14
|
+
adapterContext: options.adapterContext
|
|
177
15
|
});
|
|
178
16
|
}
|
|
179
|
-
function normalizeToolCall(toolCall) {
|
|
180
|
-
if (!toolCall || typeof toolCall !== 'object') {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
const { id, type, function: fn } = toolCall;
|
|
184
|
-
if (typeof id !== 'string' || !id.trim()) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
if (type !== 'function') {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
const fnRecord = fn && typeof fn === 'object' ? fn : undefined;
|
|
191
|
-
const rawName = typeof fnRecord?.name === 'string' ? fnRecord.name : '';
|
|
192
|
-
const normalizedName = rawName.trim();
|
|
193
|
-
const args = fnRecord?.arguments;
|
|
194
|
-
const serializedArgs = typeof args === 'string' ? args : safeStringify(args ?? {});
|
|
195
|
-
return {
|
|
196
|
-
id: id.trim(),
|
|
197
|
-
type: 'function',
|
|
198
|
-
function: {
|
|
199
|
-
name: normalizedName.length ? normalizedName : rawName,
|
|
200
|
-
arguments: serializedArgs
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function mapToolCalls(toolCalls) {
|
|
205
|
-
if (!Array.isArray(toolCalls) || !toolCalls.length) {
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
return toolCalls.map((tool) => ({
|
|
209
|
-
id: tool.id,
|
|
210
|
-
type: 'function',
|
|
211
|
-
function: {
|
|
212
|
-
name: tool.function.name,
|
|
213
|
-
arguments: tool.function.arguments
|
|
214
|
-
}
|
|
215
|
-
}));
|
|
216
|
-
}
|
|
217
|
-
function mapStandardizedTools(tools) {
|
|
218
|
-
if (!Array.isArray(tools) || !tools.length) {
|
|
219
|
-
return undefined;
|
|
220
|
-
}
|
|
221
|
-
return tools.map((tool) => ({
|
|
222
|
-
type: tool.type,
|
|
223
|
-
function: {
|
|
224
|
-
name: tool.function.name,
|
|
225
|
-
description: tool.function.description,
|
|
226
|
-
parameters: tool.function.parameters,
|
|
227
|
-
strict: tool.function.strict
|
|
228
|
-
}
|
|
229
|
-
}));
|
|
230
|
-
}
|
|
231
|
-
function normalizeTools(tools) {
|
|
232
|
-
if (!Array.isArray(tools) || !tools.length) {
|
|
233
|
-
return [];
|
|
234
|
-
}
|
|
235
|
-
const normalized = [];
|
|
236
|
-
for (const tool of tools) {
|
|
237
|
-
if (!tool || typeof tool !== 'object')
|
|
238
|
-
continue;
|
|
239
|
-
if (tool.type !== 'function')
|
|
240
|
-
continue;
|
|
241
|
-
const fn = tool.function;
|
|
242
|
-
if (!fn || typeof fn !== 'object')
|
|
243
|
-
continue;
|
|
244
|
-
const name = fn.name;
|
|
245
|
-
if (typeof name !== 'string' || !name.trim())
|
|
246
|
-
continue;
|
|
247
|
-
const parametersCast = fn.parameters;
|
|
248
|
-
normalized.push({
|
|
249
|
-
type: 'function',
|
|
250
|
-
function: {
|
|
251
|
-
name: name.trim(),
|
|
252
|
-
description: typeof fn.description === 'string'
|
|
253
|
-
? fn.description
|
|
254
|
-
: undefined,
|
|
255
|
-
parameters: parametersCast ?? {
|
|
256
|
-
type: 'object',
|
|
257
|
-
properties: {}
|
|
258
|
-
},
|
|
259
|
-
strict: typeof fn.strict === 'boolean'
|
|
260
|
-
? fn.strict
|
|
261
|
-
: undefined
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
return normalized;
|
|
266
|
-
}
|
|
267
|
-
function extractHubCapture(request) {
|
|
268
|
-
const captured = request.metadata?.capturedContext;
|
|
269
|
-
if (!captured || typeof captured !== 'object') {
|
|
270
|
-
return undefined;
|
|
271
|
-
}
|
|
272
|
-
const state = captured[HUB_CAPTURE_KEY];
|
|
273
|
-
if (!state || typeof state !== 'object') {
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
276
|
-
return state;
|
|
277
|
-
}
|
|
278
|
-
function safeStringify(value) {
|
|
279
|
-
if (typeof value === 'string')
|
|
280
|
-
return value;
|
|
281
|
-
try {
|
|
282
|
-
return JSON.stringify(value ?? {});
|
|
283
|
-
}
|
|
284
|
-
catch {
|
|
285
|
-
return String(value);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
function hubStateContextPopulated(state) {
|
|
289
|
-
return Boolean(state.context ||
|
|
290
|
-
(state.missingFields && state.missingFields.length) ||
|
|
291
|
-
state.providerMetadata ||
|
|
292
|
-
(state.protocolState && Object.keys(state.protocolState).length));
|
|
293
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_TOOL_GOVERNANCE_RULES } from './rules.js';
|
|
2
|
+
import { sanitizeResponsesFunctionNameWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
2
3
|
export class ToolGovernanceError extends Error {
|
|
3
4
|
protocol;
|
|
4
5
|
direction;
|
|
@@ -188,6 +189,10 @@ function createStats(protocol, direction) {
|
|
|
188
189
|
function sanitizeName(rawName, rules, stats, field) {
|
|
189
190
|
const defaultName = rules.defaultName ?? 'tool';
|
|
190
191
|
let next = typeof rawName === 'string' ? rawName : '';
|
|
192
|
+
const nativeSanitized = sanitizeResponsesFunctionNameWithNative(next);
|
|
193
|
+
if (typeof nativeSanitized === 'string' && nativeSanitized.trim().length) {
|
|
194
|
+
next = nativeSanitized;
|
|
195
|
+
}
|
|
191
196
|
let changed = false;
|
|
192
197
|
if (rules.trimWhitespace !== false) {
|
|
193
198
|
next = next.trim();
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
+
import { sanitizeResponsesFunctionNameWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
|
|
1
2
|
const ALPHA_NUMERIC = /[A-Za-z0-9_-]/;
|
|
2
3
|
const LOWER_SNAKE = /[a-z0-9_-]/;
|
|
3
4
|
function clonePattern(pattern) {
|
|
4
|
-
if (!pattern)
|
|
5
|
-
return undefined;
|
|
6
5
|
const flags = pattern.flags.replace(/g/g, '');
|
|
7
6
|
return new RegExp(pattern.source, flags);
|
|
8
7
|
}
|
|
8
|
+
const DEFAULT_TOOL_NAME = sanitizeResponsesFunctionNameWithNative('tool') ?? 'tool';
|
|
9
9
|
export const DEFAULT_TOOL_GOVERNANCE_RULES = {
|
|
10
10
|
'openai-chat': {
|
|
11
11
|
request: {
|
|
12
12
|
maxNameLength: 64,
|
|
13
13
|
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
14
|
-
defaultName:
|
|
14
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
15
15
|
trimWhitespace: true,
|
|
16
16
|
onViolation: 'truncate'
|
|
17
17
|
},
|
|
18
18
|
response: {
|
|
19
19
|
maxNameLength: 64,
|
|
20
20
|
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
21
|
-
defaultName:
|
|
21
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
22
22
|
trimWhitespace: true,
|
|
23
23
|
onViolation: 'truncate'
|
|
24
24
|
}
|
|
@@ -27,14 +27,14 @@ export const DEFAULT_TOOL_GOVERNANCE_RULES = {
|
|
|
27
27
|
request: {
|
|
28
28
|
maxNameLength: 64,
|
|
29
29
|
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
30
|
-
defaultName:
|
|
30
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
31
31
|
trimWhitespace: true,
|
|
32
32
|
onViolation: 'truncate'
|
|
33
33
|
},
|
|
34
34
|
response: {
|
|
35
35
|
maxNameLength: 64,
|
|
36
36
|
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
37
|
-
defaultName:
|
|
37
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
38
38
|
trimWhitespace: true,
|
|
39
39
|
onViolation: 'truncate'
|
|
40
40
|
}
|
|
@@ -44,7 +44,7 @@ export const DEFAULT_TOOL_GOVERNANCE_RULES = {
|
|
|
44
44
|
maxNameLength: 64,
|
|
45
45
|
allowedCharacters: clonePattern(LOWER_SNAKE),
|
|
46
46
|
forceCase: 'lower',
|
|
47
|
-
defaultName:
|
|
47
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
48
48
|
trimWhitespace: true,
|
|
49
49
|
onViolation: 'truncate'
|
|
50
50
|
},
|
|
@@ -52,7 +52,7 @@ export const DEFAULT_TOOL_GOVERNANCE_RULES = {
|
|
|
52
52
|
maxNameLength: 64,
|
|
53
53
|
allowedCharacters: clonePattern(LOWER_SNAKE),
|
|
54
54
|
forceCase: 'lower',
|
|
55
|
-
defaultName:
|
|
55
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
56
56
|
trimWhitespace: true,
|
|
57
57
|
onViolation: 'truncate'
|
|
58
58
|
}
|
|
@@ -61,14 +61,14 @@ export const DEFAULT_TOOL_GOVERNANCE_RULES = {
|
|
|
61
61
|
request: {
|
|
62
62
|
maxNameLength: 64,
|
|
63
63
|
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
64
|
-
defaultName:
|
|
64
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
65
65
|
trimWhitespace: true,
|
|
66
66
|
onViolation: 'truncate'
|
|
67
67
|
},
|
|
68
68
|
response: {
|
|
69
69
|
maxNameLength: 64,
|
|
70
70
|
allowedCharacters: clonePattern(ALPHA_NUMERIC),
|
|
71
|
-
defaultName:
|
|
71
|
+
defaultName: DEFAULT_TOOL_NAME,
|
|
72
72
|
trimWhitespace: true,
|
|
73
73
|
onViolation: 'truncate'
|
|
74
74
|
}
|
|
@@ -3,11 +3,11 @@ import type { AdapterContext } from './types/chat-envelope.js';
|
|
|
3
3
|
type ToolHistoryStatus = 'ok' | 'error' | 'unknown';
|
|
4
4
|
export interface ToolHistoryMessageRecord {
|
|
5
5
|
role: 'user' | 'assistant' | 'tool';
|
|
6
|
-
|
|
6
|
+
toolUse?: {
|
|
7
7
|
id: string;
|
|
8
8
|
name?: string;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
toolResult?: {
|
|
11
11
|
id: string;
|
|
12
12
|
name?: string;
|
|
13
13
|
status: ToolHistoryStatus;
|
|
@@ -3,132 +3,8 @@ import fsSync from 'node:fs';
|
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { extractSessionIdentifiersFromMetadata } from './pipeline/session-identifiers.js';
|
|
6
|
+
import { normalizeToolSessionMessagesWithNative, updateToolSessionHistoryWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
|
|
6
7
|
const TOOL_HISTORY_ROOT = path.join(os.homedir(), '.routecodex', 'tool-history');
|
|
7
|
-
const TOOL_UNKNOWN_PREFIX = '[RouteCodex] Tool call result unknown';
|
|
8
|
-
function ensureArray(value) {
|
|
9
|
-
return Array.isArray(value) ? value : [];
|
|
10
|
-
}
|
|
11
|
-
function normalizeToolCallId(call) {
|
|
12
|
-
if (!call || typeof call !== 'object') {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
const raw = call.id ??
|
|
16
|
-
call.tool_call_id ??
|
|
17
|
-
call.call_id;
|
|
18
|
-
if (typeof raw !== 'string') {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
const trimmed = raw.trim();
|
|
22
|
-
return trimmed.length ? trimmed : undefined;
|
|
23
|
-
}
|
|
24
|
-
function normalizeToolMessageId(message) {
|
|
25
|
-
if (!message || typeof message !== 'object') {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const raw = message.tool_call_id ??
|
|
29
|
-
message.call_id ??
|
|
30
|
-
message.id;
|
|
31
|
-
if (typeof raw !== 'string') {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
const trimmed = raw.trim();
|
|
35
|
-
return trimmed.length ? trimmed : undefined;
|
|
36
|
-
}
|
|
37
|
-
function findFirstNonToolIndex(messages, startIndex) {
|
|
38
|
-
let index = startIndex;
|
|
39
|
-
while (index < messages.length) {
|
|
40
|
-
const msg = messages[index];
|
|
41
|
-
if (!msg || typeof msg !== 'object') {
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
const role = String(msg.role || '').toLowerCase();
|
|
45
|
-
if (role !== 'tool') {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
index += 1;
|
|
49
|
-
}
|
|
50
|
-
return index;
|
|
51
|
-
}
|
|
52
|
-
function findToolMessageIndex(messages, startIndex, callId) {
|
|
53
|
-
for (let i = startIndex; i < messages.length; i += 1) {
|
|
54
|
-
const msg = messages[i];
|
|
55
|
-
if (!msg || typeof msg !== 'object') {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const role = String(msg.role || '').toLowerCase();
|
|
59
|
-
if (role !== 'tool') {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const id = normalizeToolMessageId(msg);
|
|
63
|
-
if (id === callId) {
|
|
64
|
-
return i;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return -1;
|
|
68
|
-
}
|
|
69
|
-
function createUnknownToolMessage(callId, call) {
|
|
70
|
-
let name;
|
|
71
|
-
const fn = call && typeof call === 'object' ? call.function : undefined;
|
|
72
|
-
if (fn && typeof fn.name === 'string' && fn.name.trim().length) {
|
|
73
|
-
name = fn.name.trim();
|
|
74
|
-
}
|
|
75
|
-
const description = name ? `tool "${name}"` : 'tool call';
|
|
76
|
-
const content = `${TOOL_UNKNOWN_PREFIX}: ${description} (${callId}) did not produce a result in this session. Treat this tool as failed with unknown status.`;
|
|
77
|
-
const msg = {
|
|
78
|
-
role: 'tool',
|
|
79
|
-
tool_call_id: callId,
|
|
80
|
-
content
|
|
81
|
-
};
|
|
82
|
-
if (name) {
|
|
83
|
-
msg.name = name;
|
|
84
|
-
}
|
|
85
|
-
return msg;
|
|
86
|
-
}
|
|
87
|
-
function normalizeToolCallOrdering(messages) {
|
|
88
|
-
let index = 0;
|
|
89
|
-
while (index < messages.length) {
|
|
90
|
-
const message = messages[index];
|
|
91
|
-
if (!message || typeof message !== 'object') {
|
|
92
|
-
index += 1;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const role = String(message.role || '').toLowerCase();
|
|
96
|
-
if (role !== 'assistant') {
|
|
97
|
-
index += 1;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
const toolCalls = ensureArray(message.tool_calls);
|
|
101
|
-
if (!toolCalls.length) {
|
|
102
|
-
index += 1;
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
let insertionIndex = index + 1;
|
|
106
|
-
for (const call of toolCalls) {
|
|
107
|
-
if (!call || typeof call !== 'object') {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const callId = normalizeToolCallId(call);
|
|
111
|
-
if (!callId) {
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
const existingIndex = findToolMessageIndex(messages, insertionIndex, callId);
|
|
115
|
-
if (existingIndex >= 0) {
|
|
116
|
-
if (existingIndex === insertionIndex) {
|
|
117
|
-
insertionIndex += 1;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const [relocated] = messages.splice(existingIndex, 1);
|
|
121
|
-
messages.splice(insertionIndex, 0, relocated);
|
|
122
|
-
insertionIndex += 1;
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
const placeholder = createUnknownToolMessage(callId, call);
|
|
126
|
-
messages.splice(insertionIndex, 0, placeholder);
|
|
127
|
-
insertionIndex += 1;
|
|
128
|
-
}
|
|
129
|
-
index = Math.max(index + 1, insertionIndex);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
8
|
function sanitizeSessionId(raw) {
|
|
133
9
|
const trimmed = raw.trim();
|
|
134
10
|
if (!trimmed) {
|
|
@@ -173,116 +49,24 @@ async function persistSessionHistory(sessionId, history) {
|
|
|
173
49
|
// history persistence must never block the main flow
|
|
174
50
|
}
|
|
175
51
|
}
|
|
176
|
-
function collectToolHistoryRecords(messages) {
|
|
177
|
-
const now = new Date().toISOString();
|
|
178
|
-
const records = [];
|
|
179
|
-
for (const msg of messages) {
|
|
180
|
-
if (!msg || typeof msg !== 'object') {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
const role = String(msg.role || '').toLowerCase();
|
|
184
|
-
if (role === 'assistant') {
|
|
185
|
-
const toolCalls = ensureArray(msg.tool_calls);
|
|
186
|
-
for (const call of toolCalls) {
|
|
187
|
-
const id = normalizeToolCallId(call);
|
|
188
|
-
if (!id) {
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
const fn = call.function;
|
|
192
|
-
const name = fn && typeof fn.name === 'string' && fn.name.trim().length
|
|
193
|
-
? fn.name.trim()
|
|
194
|
-
: undefined;
|
|
195
|
-
records.push({
|
|
196
|
-
role: 'assistant',
|
|
197
|
-
tool_use: { id, name },
|
|
198
|
-
ts: now
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (role === 'tool') {
|
|
204
|
-
const id = normalizeToolMessageId(msg);
|
|
205
|
-
if (!id) {
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
const rawName = msg.name;
|
|
209
|
-
const name = typeof rawName === 'string' && rawName.trim().length ? rawName.trim() : undefined;
|
|
210
|
-
const content = msg.content;
|
|
211
|
-
const status = typeof content === 'string' && content.startsWith(TOOL_UNKNOWN_PREFIX) ? 'unknown' : 'ok';
|
|
212
|
-
records.push({
|
|
213
|
-
role: 'tool',
|
|
214
|
-
tool_result: { id, name, status },
|
|
215
|
-
ts: now
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return records;
|
|
220
|
-
}
|
|
221
|
-
function buildUpdatedHistory(existing, delta) {
|
|
222
|
-
const prevMessages = existing?.lastMessages ?? [];
|
|
223
|
-
const combined = [...prevMessages, ...delta];
|
|
224
|
-
const trimmed = combined.slice(-10);
|
|
225
|
-
const pending = {};
|
|
226
|
-
for (const entry of trimmed) {
|
|
227
|
-
if (entry.tool_use) {
|
|
228
|
-
pending[entry.tool_use.id] = {
|
|
229
|
-
name: entry.tool_use.name,
|
|
230
|
-
ts: entry.ts
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (entry.tool_result) {
|
|
234
|
-
delete pending[entry.tool_result.id];
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
lastMessages: trimmed,
|
|
239
|
-
pendingToolUses: pending,
|
|
240
|
-
updatedAt: new Date().toISOString()
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
52
|
export async function applyToolSessionCompat(chat, ctx) {
|
|
244
53
|
if (!chat || !Array.isArray(chat.messages) || chat.messages.length === 0) {
|
|
245
54
|
return;
|
|
246
55
|
}
|
|
56
|
+
const normalized = normalizeToolSessionMessagesWithNative({
|
|
57
|
+
messages: chat.messages,
|
|
58
|
+
...(Array.isArray(chat.toolOutputs) && chat.toolOutputs.length
|
|
59
|
+
? { toolOutputs: chat.toolOutputs }
|
|
60
|
+
: {})
|
|
61
|
+
});
|
|
62
|
+
chat.messages = normalized.messages;
|
|
63
|
+
chat.toolOutputs = Array.isArray(normalized.toolOutputs) && normalized.toolOutputs.length
|
|
64
|
+
? normalized.toolOutputs
|
|
65
|
+
: undefined;
|
|
247
66
|
const entry = (ctx.entryEndpoint || '').toLowerCase();
|
|
248
67
|
if (!entry.includes('/v1/messages')) {
|
|
249
|
-
normalizeToolCallOrdering(chat.messages);
|
|
250
68
|
return;
|
|
251
69
|
}
|
|
252
|
-
normalizeToolCallOrdering(chat.messages);
|
|
253
|
-
const validCallIds = new Set();
|
|
254
|
-
for (const msg of chat.messages) {
|
|
255
|
-
if (!msg || typeof msg !== 'object') {
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
const role = String(msg.role || '').toLowerCase();
|
|
259
|
-
if (role !== 'assistant') {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
const toolCalls = ensureArray(msg.tool_calls);
|
|
263
|
-
for (const call of toolCalls) {
|
|
264
|
-
const id = normalizeToolCallId(call);
|
|
265
|
-
if (id) {
|
|
266
|
-
validCallIds.add(id);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
if (Array.isArray(chat.toolOutputs) && chat.toolOutputs.length) {
|
|
271
|
-
const filtered = chat.toolOutputs.filter((entry) => {
|
|
272
|
-
if (!entry || typeof entry !== 'object') {
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
const rawId = entry.tool_call_id ??
|
|
276
|
-
entry.call_id ??
|
|
277
|
-
entry.id;
|
|
278
|
-
if (typeof rawId !== 'string') {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
const trimmed = rawId.trim();
|
|
282
|
-
return trimmed.length > 0 && validCallIds.has(trimmed);
|
|
283
|
-
});
|
|
284
|
-
chat.toolOutputs = filtered.length ? filtered : undefined;
|
|
285
|
-
}
|
|
286
70
|
const metadata = (chat.metadata || {});
|
|
287
71
|
const identifiers = extractSessionIdentifiersFromMetadata(metadata);
|
|
288
72
|
const sessionId = identifiers.sessionId;
|
|
@@ -290,10 +74,12 @@ export async function applyToolSessionCompat(chat, ctx) {
|
|
|
290
74
|
return;
|
|
291
75
|
}
|
|
292
76
|
const history = await loadSessionHistory(sessionId);
|
|
293
|
-
const
|
|
294
|
-
|
|
77
|
+
const updated = updateToolSessionHistoryWithNative({
|
|
78
|
+
messages: chat.messages,
|
|
79
|
+
...(history ? { existingHistory: history } : {})
|
|
80
|
+
});
|
|
81
|
+
if (!updated.history) {
|
|
295
82
|
return;
|
|
296
83
|
}
|
|
297
|
-
|
|
298
|
-
await persistSessionHistory(sessionId, updated);
|
|
84
|
+
await persistSessionHistory(sessionId, updated.history);
|
|
299
85
|
}
|