@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
|
@@ -11,6 +11,7 @@ import './handlers/clock-auto.js';
|
|
|
11
11
|
import './handlers/exec-command-guard.js';
|
|
12
12
|
import './handlers/apply-patch-guard.js';
|
|
13
13
|
import './handlers/continue-execution.js';
|
|
14
|
+
import './handlers/review.js';
|
|
14
15
|
import { runPreCommandHooks } from './pre-command-hooks.js';
|
|
15
16
|
import { readRuntimeMetadata } from '../conversion/shared/runtime-metadata.js';
|
|
16
17
|
function traceAutoHook(options, event) {
|
|
@@ -21,7 +22,7 @@ function traceAutoHook(options, event) {
|
|
|
21
22
|
// best-effort trace callback
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
const OPTIONAL_PRIMARY_HOOK_ORDER = ['empty_reply_continue', '
|
|
25
|
+
const OPTIONAL_PRIMARY_HOOK_ORDER = ['empty_reply_continue', 'clock_auto', 'stop_message_auto'];
|
|
25
26
|
const MANDATORY_HOOK_ORDER = [];
|
|
26
27
|
let fallbackToolCallIdSeq = 0;
|
|
27
28
|
function ensureToolCallId(record) {
|
|
@@ -81,6 +82,33 @@ function buildAutoHookQueues(hooks) {
|
|
|
81
82
|
}
|
|
82
83
|
return { optionalQueue, mandatoryQueue };
|
|
83
84
|
}
|
|
85
|
+
function normalizeFilterTokenSet(values) {
|
|
86
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const normalized = new Set();
|
|
90
|
+
for (const raw of values) {
|
|
91
|
+
if (typeof raw !== 'string') {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const value = raw.trim().toLowerCase();
|
|
95
|
+
if (!value) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
normalized.add(value);
|
|
99
|
+
}
|
|
100
|
+
return normalized.size > 0 ? normalized : null;
|
|
101
|
+
}
|
|
102
|
+
function isNameIncluded(name, includeSet, excludeSet) {
|
|
103
|
+
const normalized = name.trim().toLowerCase();
|
|
104
|
+
if (includeSet && !includeSet.has(normalized)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (excludeSet && excludeSet.has(normalized)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
84
112
|
function extractToolCallsFromMessage(message) {
|
|
85
113
|
const toolCalls = getArray(message.tool_calls);
|
|
86
114
|
const out = [];
|
|
@@ -259,6 +287,10 @@ export async function runServerSideToolEngine(options) {
|
|
|
259
287
|
providerInvoker: typeof options.providerInvoker === 'function'
|
|
260
288
|
}
|
|
261
289
|
};
|
|
290
|
+
const includeToolCallNames = normalizeFilterTokenSet(options.includeToolCallHandlerNames);
|
|
291
|
+
const excludeToolCallNames = normalizeFilterTokenSet(options.excludeToolCallHandlerNames);
|
|
292
|
+
const includeAutoHookIds = normalizeFilterTokenSet(options.includeAutoHookIds);
|
|
293
|
+
const excludeAutoHookIds = normalizeFilterTokenSet(options.excludeAutoHookIds);
|
|
262
294
|
// Tool-call servertools: execute all executable servertool calls first, then decide:
|
|
263
295
|
// - if only servertools were present -> followup via reenter (existing behavior)
|
|
264
296
|
// - if mixed (servertool + client tools) -> persist servertool results, return remaining tool_calls to client
|
|
@@ -282,59 +314,64 @@ export async function runServerSideToolEngine(options) {
|
|
|
282
314
|
continue;
|
|
283
315
|
attemptedToolCallsByMessage.push(...extractToolCallsFromMessage(message));
|
|
284
316
|
}
|
|
285
|
-
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
providerProtocol: options.providerProtocol,
|
|
290
|
-
toolName: toolCall.name,
|
|
291
|
-
toolCallId: toolCall.id,
|
|
292
|
-
toolArguments: toolCall.arguments,
|
|
293
|
-
preCommandState: runtimePreCommandState
|
|
294
|
-
});
|
|
295
|
-
for (const trace of preHookResult.traces) {
|
|
296
|
-
traceAutoHook(options, trace);
|
|
297
|
-
}
|
|
298
|
-
if (preHookResult.changed && preHookResult.toolArguments !== toolCall.arguments) {
|
|
299
|
-
toolCall.arguments = preHookResult.toolArguments;
|
|
300
|
-
patchToolCallArgumentsById(base, toolCall.id, preHookResult.toolArguments);
|
|
301
|
-
patchToolCallArgumentsById(baseForExecution, toolCall.id, preHookResult.toolArguments);
|
|
302
|
-
}
|
|
303
|
-
const entry = getServerToolHandler(toolCall.name);
|
|
304
|
-
if (!entry || entry.trigger !== 'tool_call') {
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
const ctx = { ...contextBase, base: baseForExecution, toolCall };
|
|
308
|
-
let planned = null;
|
|
309
|
-
let lastErr;
|
|
310
|
-
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
311
|
-
try {
|
|
312
|
-
planned = await runHandler(entry.handler, ctx);
|
|
313
|
-
lastErr = undefined;
|
|
314
|
-
break;
|
|
317
|
+
if (options.disableToolCallHandlers !== true) {
|
|
318
|
+
for (const { parsed: toolCall } of attemptedToolCallsByMessage) {
|
|
319
|
+
if (!isNameIncluded(toolCall.name, includeToolCallNames, excludeToolCallNames)) {
|
|
320
|
+
continue;
|
|
315
321
|
}
|
|
316
|
-
|
|
317
|
-
|
|
322
|
+
const preHookResult = runPreCommandHooks({
|
|
323
|
+
requestId: options.requestId,
|
|
324
|
+
entryEndpoint: options.entryEndpoint,
|
|
325
|
+
providerProtocol: options.providerProtocol,
|
|
326
|
+
toolName: toolCall.name,
|
|
327
|
+
toolCallId: toolCall.id,
|
|
328
|
+
toolArguments: toolCall.arguments,
|
|
329
|
+
preCommandState: runtimePreCommandState
|
|
330
|
+
});
|
|
331
|
+
for (const trace of preHookResult.traces) {
|
|
332
|
+
traceAutoHook(options, trace);
|
|
318
333
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (
|
|
326
|
-
|
|
334
|
+
if (preHookResult.changed && preHookResult.toolArguments !== toolCall.arguments) {
|
|
335
|
+
toolCall.arguments = preHookResult.toolArguments;
|
|
336
|
+
patchToolCallArgumentsById(base, toolCall.id, preHookResult.toolArguments);
|
|
337
|
+
patchToolCallArgumentsById(baseForExecution, toolCall.id, preHookResult.toolArguments);
|
|
338
|
+
}
|
|
339
|
+
const entry = getServerToolHandler(toolCall.name);
|
|
340
|
+
if (!entry || entry.trigger !== 'tool_call') {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const ctx = { ...contextBase, base: baseForExecution, toolCall };
|
|
344
|
+
let planned = null;
|
|
345
|
+
let lastErr;
|
|
346
|
+
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
347
|
+
try {
|
|
348
|
+
planned = await runHandler(entry.handler, ctx);
|
|
349
|
+
lastErr = undefined;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
catch (err) {
|
|
353
|
+
lastErr = err;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const result = planned ? await materializePlannedResult(planned, options) : null;
|
|
357
|
+
if (result) {
|
|
358
|
+
replaceJsonObjectInPlace(baseForExecution, cloneJson(result.chatResponse));
|
|
359
|
+
executedToolCalls.push(toolCall);
|
|
360
|
+
executedIds.add(toolCall.id);
|
|
361
|
+
if (result.execution?.flowId && typeof result.execution.flowId === 'string' && result.execution.flowId.trim()) {
|
|
362
|
+
executedFlowIds.push(result.execution.flowId.trim());
|
|
363
|
+
}
|
|
364
|
+
lastExecution = result.execution;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (lastErr) {
|
|
368
|
+
// Handler failed: report tool error as a tool_output, but do not crash the whole pipeline.
|
|
369
|
+
const message = lastErr instanceof Error ? lastErr.message : String(lastErr ?? 'unknown');
|
|
370
|
+
appendToolOutput(baseForExecution, toolCall.id, toolCall.name, JSON.stringify({ ok: false, tool: toolCall.name, message, retryable: true }));
|
|
371
|
+
executedToolCalls.push(toolCall);
|
|
372
|
+
executedIds.add(toolCall.id);
|
|
373
|
+
executedFlowIds.push(`${toolCall.name}_error`);
|
|
327
374
|
}
|
|
328
|
-
lastExecution = result.execution;
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
if (lastErr) {
|
|
332
|
-
// Handler failed: report tool error as a tool_output, but do not crash the whole pipeline.
|
|
333
|
-
const message = lastErr instanceof Error ? lastErr.message : String(lastErr ?? 'unknown');
|
|
334
|
-
appendToolOutput(baseForExecution, toolCall.id, toolCall.name, JSON.stringify({ ok: false, tool: toolCall.name, message, retryable: true }));
|
|
335
|
-
executedToolCalls.push(toolCall);
|
|
336
|
-
executedIds.add(toolCall.id);
|
|
337
|
-
executedFlowIds.push(`${toolCall.name}_error`);
|
|
338
375
|
}
|
|
339
376
|
}
|
|
340
377
|
if (executedToolCalls.length > 0) {
|
|
@@ -409,7 +446,8 @@ export async function runServerSideToolEngine(options) {
|
|
|
409
446
|
};
|
|
410
447
|
}
|
|
411
448
|
const autoHookExecutionList = listAutoServerToolHooks();
|
|
412
|
-
const
|
|
449
|
+
const filteredAutoHooks = autoHookExecutionList.filter((hook) => isNameIncluded(hook.id, includeAutoHookIds, excludeAutoHookIds));
|
|
450
|
+
const { optionalQueue, mandatoryQueue } = buildAutoHookQueues(filteredAutoHooks);
|
|
413
451
|
const optionalResult = await runAutoHookQueue({
|
|
414
452
|
queueName: 'A_optional',
|
|
415
453
|
hooks: optionalQueue,
|
|
@@ -48,6 +48,11 @@ export interface ServerSideToolEngineOptions {
|
|
|
48
48
|
entryEndpoint: string;
|
|
49
49
|
requestId: string;
|
|
50
50
|
providerProtocol: string;
|
|
51
|
+
disableToolCallHandlers?: boolean;
|
|
52
|
+
includeAutoHookIds?: string[];
|
|
53
|
+
excludeAutoHookIds?: string[];
|
|
54
|
+
includeToolCallHandlerNames?: string[];
|
|
55
|
+
excludeToolCallHandlerNames?: string[];
|
|
51
56
|
providerInvoker?: ProviderInvoker;
|
|
52
57
|
reenterPipeline?: (options: {
|
|
53
58
|
entryEndpoint: string;
|
|
@@ -59,6 +64,15 @@ export interface ServerSideToolEngineOptions {
|
|
|
59
64
|
__sse_responses?: unknown;
|
|
60
65
|
format?: string;
|
|
61
66
|
}>;
|
|
67
|
+
clientInjectDispatch?: (options: {
|
|
68
|
+
entryEndpoint: string;
|
|
69
|
+
requestId: string;
|
|
70
|
+
body?: JsonObject;
|
|
71
|
+
metadata?: JsonObject;
|
|
72
|
+
}) => Promise<{
|
|
73
|
+
ok: boolean;
|
|
74
|
+
reason?: string;
|
|
75
|
+
}>;
|
|
62
76
|
onAutoHookTrace?: (event: ServerToolAutoHookTraceEvent) => void;
|
|
63
77
|
}
|
|
64
78
|
export type ServerToolFollowupInjectionOp = {
|
|
@@ -103,6 +117,9 @@ export type ServerToolFollowupPlan = {
|
|
|
103
117
|
injection: ServerToolFollowupInjectionPlan;
|
|
104
118
|
metadata?: JsonObject;
|
|
105
119
|
entryEndpoint?: string;
|
|
120
|
+
} | {
|
|
121
|
+
requestIdSuffix: string;
|
|
122
|
+
metadata?: JsonObject;
|
|
106
123
|
};
|
|
107
124
|
export type ServerToolBackendPlan = {
|
|
108
125
|
kind: 'vision_analysis';
|
|
@@ -179,6 +179,16 @@ const stripConflictMarkers = (text) => {
|
|
|
179
179
|
return text;
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
+
const splitInlineBeginPatchFileHeader = (text) => {
|
|
183
|
+
if (!text)
|
|
184
|
+
return text;
|
|
185
|
+
return text.replace(/\*\*\*\s*Begin Patch(?:\s*\*\*\*)?\s*(Create|Add|Update|Delete)\s+File:\s*([^\n]+?)(?:\s+\*\*\*)?(?=\n|$)/gi, (_m, actionRaw, pathRaw) => {
|
|
186
|
+
const action = String(actionRaw || '').trim().toLowerCase();
|
|
187
|
+
const mappedAction = action === 'create' ? 'Add' : `${action.charAt(0).toUpperCase()}${action.slice(1)}`;
|
|
188
|
+
const path = String(pathRaw || '').trim();
|
|
189
|
+
return `*** Begin Patch\n*** ${mappedAction} File: ${path}`;
|
|
190
|
+
});
|
|
191
|
+
};
|
|
182
192
|
export const normalizeApplyPatchText = (raw) => {
|
|
183
193
|
if (!raw)
|
|
184
194
|
return raw;
|
|
@@ -189,6 +199,7 @@ export const normalizeApplyPatchText = (raw) => {
|
|
|
189
199
|
if (!text)
|
|
190
200
|
return raw;
|
|
191
201
|
text = stripConflictMarkers(text);
|
|
202
|
+
text = splitInlineBeginPatchFileHeader(text);
|
|
192
203
|
text = normalizeBeginEndMarkers(text);
|
|
193
204
|
// Some models emit a GNU unified diff wrapped in apply_patch markers, e.g.:
|
|
194
205
|
// *** Begin Patch ***
|
|
@@ -4,4 +4,7 @@ export type ExecCommandValidationResult = {
|
|
|
4
4
|
message?: string;
|
|
5
5
|
normalizedArgs?: string;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type ExecCommandValidationOptions = {
|
|
8
|
+
policyFile?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function validateExecCommandArgs(argsString: string, rawArgs: unknown, options?: ExecCommandValidationOptions): ExecCommandValidationResult;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { parseToolArgsJson } from '../args-json.js';
|
|
2
2
|
import { normalizeExecCommandArgs } from './normalize.js';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
3
6
|
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
7
|
const toJson = (value) => {
|
|
5
8
|
try {
|
|
@@ -9,6 +12,7 @@ const toJson = (value) => {
|
|
|
9
12
|
return '{}';
|
|
10
13
|
}
|
|
11
14
|
};
|
|
15
|
+
const POLICY_CACHE = new Map();
|
|
12
16
|
const GIT_RESET_HARD_PATTERN = /\bgit\s+reset\s+--hard(?:\s|$)/i;
|
|
13
17
|
const GIT_CHECKOUT_PATTERN = /\bgit\s+checkout\b/i;
|
|
14
18
|
const SHELL_SEPARATORS = new Set([';', '&&', '||', '|', '&']);
|
|
@@ -124,10 +128,90 @@ function evaluateGitCheckoutScope(command) {
|
|
|
124
128
|
}
|
|
125
129
|
return null;
|
|
126
130
|
}
|
|
127
|
-
function
|
|
131
|
+
function resolvePolicyPath(rawPath) {
|
|
132
|
+
const trimmed = rawPath.trim();
|
|
133
|
+
if (!trimmed) {
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
if (trimmed.startsWith('~/')) {
|
|
137
|
+
return path.join(os.homedir(), trimmed.slice(2));
|
|
138
|
+
}
|
|
139
|
+
return path.resolve(trimmed);
|
|
140
|
+
}
|
|
141
|
+
function loadPolicyRules(policyFile) {
|
|
142
|
+
const resolved = typeof policyFile === 'string' ? resolvePolicyPath(policyFile) : '';
|
|
143
|
+
if (!resolved) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const stat = fs.statSync(resolved);
|
|
148
|
+
if (!stat.isFile()) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
const cached = POLICY_CACHE.get(resolved);
|
|
152
|
+
if (cached && cached.mtimeMs === stat.mtimeMs) {
|
|
153
|
+
return cached.rules;
|
|
154
|
+
}
|
|
155
|
+
const raw = fs.readFileSync(resolved, 'utf8');
|
|
156
|
+
const parsed = raw.trim() ? JSON.parse(raw) : {};
|
|
157
|
+
const rulesNode = isRecord(parsed) && Array.isArray(parsed.rules) ? parsed.rules : [];
|
|
158
|
+
const rules = [];
|
|
159
|
+
for (const item of rulesNode) {
|
|
160
|
+
if (!isRecord(item)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const type = typeof item.type === 'string' ? item.type.trim().toLowerCase() : '';
|
|
164
|
+
if (type !== 'regex') {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const pattern = typeof item.pattern === 'string' ? item.pattern : '';
|
|
168
|
+
if (!pattern.trim()) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const id = typeof item.id === 'string' && item.id.trim() ? item.id.trim() : `rule_${rules.length + 1}`;
|
|
172
|
+
const reason = typeof item.reason === 'string' && item.reason.trim()
|
|
173
|
+
? item.reason.trim()
|
|
174
|
+
: `policy rule "${id}" blocked this command`;
|
|
175
|
+
const flagsRaw = typeof item.flags === 'string' ? item.flags.trim() : '';
|
|
176
|
+
let regex;
|
|
177
|
+
try {
|
|
178
|
+
regex = new RegExp(pattern, flagsRaw || 'i');
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
rules.push({ id, regex, reason });
|
|
184
|
+
}
|
|
185
|
+
POLICY_CACHE.set(resolved, { mtimeMs: stat.mtimeMs, rules });
|
|
186
|
+
return rules;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function detectPolicyRuleViolation(command, options) {
|
|
193
|
+
const rules = loadPolicyRules(options?.policyFile);
|
|
194
|
+
if (!rules.length) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
for (const rule of rules) {
|
|
198
|
+
if (rule.regex.test(command)) {
|
|
199
|
+
return {
|
|
200
|
+
reason: 'forbidden_exec_command_policy',
|
|
201
|
+
message: rule.reason
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
function detectPolicyViolation(command, options) {
|
|
128
208
|
if (!command || !command.trim()) {
|
|
129
209
|
return null;
|
|
130
210
|
}
|
|
211
|
+
const policyViolation = detectPolicyRuleViolation(command, options);
|
|
212
|
+
if (policyViolation) {
|
|
213
|
+
return policyViolation;
|
|
214
|
+
}
|
|
131
215
|
if (GIT_RESET_HARD_PATTERN.test(command)) {
|
|
132
216
|
return {
|
|
133
217
|
reason: 'forbidden_git_reset_hard',
|
|
@@ -136,7 +220,7 @@ function detectPolicyViolation(command) {
|
|
|
136
220
|
}
|
|
137
221
|
return evaluateGitCheckoutScope(command);
|
|
138
222
|
}
|
|
139
|
-
export function validateExecCommandArgs(argsString, rawArgs) {
|
|
223
|
+
export function validateExecCommandArgs(argsString, rawArgs, options) {
|
|
140
224
|
const raw = typeof argsString === 'string' ? argsString : String(argsString ?? '');
|
|
141
225
|
const parsed = isRecord(rawArgs) && Object.keys(rawArgs).length > 0
|
|
142
226
|
? rawArgs
|
|
@@ -146,7 +230,7 @@ export function validateExecCommandArgs(argsString, rawArgs) {
|
|
|
146
230
|
return { ok: false, reason: normalized.reason };
|
|
147
231
|
}
|
|
148
232
|
const command = typeof normalized.normalized.cmd === 'string' ? normalized.normalized.cmd : '';
|
|
149
|
-
const violation = detectPolicyViolation(command);
|
|
233
|
+
const violation = detectPolicyViolation(command, options);
|
|
150
234
|
if (violation) {
|
|
151
235
|
return { ok: false, reason: violation.reason, message: violation.message };
|
|
152
236
|
}
|
|
@@ -5,5 +5,11 @@ export interface ToolValidationResult {
|
|
|
5
5
|
warnings?: Array<Record<string, unknown>>;
|
|
6
6
|
normalizedArgs?: string;
|
|
7
7
|
}
|
|
8
|
+
export interface ToolValidationOptions {
|
|
9
|
+
execCommandGuard?: {
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
policyFile?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
8
14
|
export declare function getAllowedToolNames(): string[];
|
|
9
|
-
export declare function validateToolCall(name: string, argsString: string): ToolValidationResult;
|
|
15
|
+
export declare function validateToolCall(name: string, argsString: string, options?: ToolValidationOptions): ToolValidationResult;
|
|
@@ -81,7 +81,7 @@ export function getAllowedToolNames() {
|
|
|
81
81
|
'list_mcp_resource_templates'
|
|
82
82
|
];
|
|
83
83
|
}
|
|
84
|
-
export function validateToolCall(name, argsString) {
|
|
84
|
+
export function validateToolCall(name, argsString, options) {
|
|
85
85
|
const normalizedName = String(name || '').trim();
|
|
86
86
|
if (!normalizedName) {
|
|
87
87
|
return { ok: false, reason: 'empty_tool_name' };
|
|
@@ -93,7 +93,8 @@ export function validateToolCall(name, argsString) {
|
|
|
93
93
|
const rawArgsAny = parseToolArgsJson(typeof argsString === 'string' ? argsString : '{}');
|
|
94
94
|
switch (normalizedName) {
|
|
95
95
|
case 'exec_command': {
|
|
96
|
-
const
|
|
96
|
+
const guard = options?.execCommandGuard;
|
|
97
|
+
const validation = validateExecCommandArgs(argsString, rawArgsAny, guard && guard.enabled ? { policyFile: guard.policyFile } : undefined);
|
|
97
98
|
if (!validation.ok) {
|
|
98
99
|
const reason = validation.reason || 'unknown';
|
|
99
100
|
captureExecCommandRegression({
|