@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
|
@@ -0,0 +1,1166 @@
|
|
|
1
|
+
import { failNativeRequired, isNativeDisabledByEnv } from './native-router-hotpath-policy.js';
|
|
2
|
+
import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
|
|
3
|
+
function readNativeFunction(name) {
|
|
4
|
+
const binding = loadNativeRouterHotpathBindingForInternalUse();
|
|
5
|
+
const fn = binding?.[name];
|
|
6
|
+
return typeof fn === 'function' ? fn : null;
|
|
7
|
+
}
|
|
8
|
+
function safeStringify(value) {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.stringify(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function parseJson(raw) {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(raw);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function parseRecord(raw) {
|
|
25
|
+
const parsed = parseJson(raw);
|
|
26
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
function parseExtractToolCallsOutput(raw) {
|
|
32
|
+
const parsed = parseJson(raw);
|
|
33
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const row = parsed;
|
|
37
|
+
if (typeof row.cleanedText !== 'string' || !Array.isArray(row.toolCalls)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const toolCalls = row.toolCalls.filter((entry) => entry && typeof entry === 'object');
|
|
41
|
+
return {
|
|
42
|
+
cleanedText: row.cleanedText,
|
|
43
|
+
toolCalls
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function parseReasoningItems(raw) {
|
|
47
|
+
const parsed = parseJson(raw);
|
|
48
|
+
if (!Array.isArray(parsed)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const entry of parsed) {
|
|
53
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const row = entry;
|
|
57
|
+
if (row.type !== 'reasoning' || typeof row.content !== 'string') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
out.push({ type: 'reasoning', content: row.content });
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
export function parseLenientJsonishWithNative(value) {
|
|
65
|
+
const capability = 'parseLenientJsonishJson';
|
|
66
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
67
|
+
if (isNativeDisabledByEnv()) {
|
|
68
|
+
return fail('native disabled');
|
|
69
|
+
}
|
|
70
|
+
const fn = readNativeFunction(capability);
|
|
71
|
+
if (!fn) {
|
|
72
|
+
return fail();
|
|
73
|
+
}
|
|
74
|
+
const valueJson = safeStringify(value ?? null);
|
|
75
|
+
if (!valueJson) {
|
|
76
|
+
return fail('json stringify failed');
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const raw = fn(valueJson);
|
|
80
|
+
if (typeof raw !== 'string' || !raw) {
|
|
81
|
+
return fail('empty result');
|
|
82
|
+
}
|
|
83
|
+
const parsed = parseJson(raw);
|
|
84
|
+
return parsed === null ? fail('invalid payload') : parsed;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
88
|
+
return fail(reason);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function repairArgumentsToStringWithNative(value) {
|
|
92
|
+
const capability = 'repairArgumentsToStringJsonishJson';
|
|
93
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
94
|
+
if (isNativeDisabledByEnv()) {
|
|
95
|
+
return fail('native disabled');
|
|
96
|
+
}
|
|
97
|
+
const fn = readNativeFunction(capability);
|
|
98
|
+
if (!fn) {
|
|
99
|
+
return fail();
|
|
100
|
+
}
|
|
101
|
+
const valueJson = safeStringify(value ?? null);
|
|
102
|
+
if (!valueJson) {
|
|
103
|
+
return fail('json stringify failed');
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const raw = fn(valueJson);
|
|
107
|
+
if (typeof raw !== 'string') {
|
|
108
|
+
return fail('invalid payload');
|
|
109
|
+
}
|
|
110
|
+
return raw;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
114
|
+
return fail(reason);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export function extractToolCallsFromReasoningTextWithNative(text, idPrefix) {
|
|
118
|
+
const capability = 'extractToolCallsFromReasoningTextJson';
|
|
119
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
120
|
+
if (isNativeDisabledByEnv()) {
|
|
121
|
+
return fail('native disabled');
|
|
122
|
+
}
|
|
123
|
+
const fn = readNativeFunction(capability);
|
|
124
|
+
if (!fn) {
|
|
125
|
+
return fail();
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const raw = fn(String(text ?? ''), idPrefix);
|
|
129
|
+
if (typeof raw !== 'string' || !raw) {
|
|
130
|
+
return fail('empty result');
|
|
131
|
+
}
|
|
132
|
+
const parsed = parseExtractToolCallsOutput(raw);
|
|
133
|
+
return parsed ?? fail('invalid payload');
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
137
|
+
return fail(reason);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function sanitizeReasoningTaggedTextWithNative(text) {
|
|
141
|
+
const capability = 'sanitizeReasoningTaggedTextJson';
|
|
142
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
143
|
+
if (isNativeDisabledByEnv()) {
|
|
144
|
+
return fail('native disabled');
|
|
145
|
+
}
|
|
146
|
+
const fn = readNativeFunction(capability);
|
|
147
|
+
if (!fn) {
|
|
148
|
+
return fail();
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const raw = fn(String(text ?? ''));
|
|
152
|
+
if (typeof raw !== 'string') {
|
|
153
|
+
return fail('invalid payload');
|
|
154
|
+
}
|
|
155
|
+
return raw;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
159
|
+
return fail(reason);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export function deriveToolCallKeyWithNative(call) {
|
|
163
|
+
const capability = 'deriveToolCallKeyJson';
|
|
164
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
165
|
+
if (isNativeDisabledByEnv()) {
|
|
166
|
+
return fail('native disabled');
|
|
167
|
+
}
|
|
168
|
+
const fn = readNativeFunction(capability);
|
|
169
|
+
if (!fn) {
|
|
170
|
+
return fail();
|
|
171
|
+
}
|
|
172
|
+
const callJson = safeStringify(call ?? null);
|
|
173
|
+
if (!callJson) {
|
|
174
|
+
return fail('json stringify failed');
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const raw = fn(callJson);
|
|
178
|
+
if (typeof raw !== 'string' || !raw) {
|
|
179
|
+
return fail('empty result');
|
|
180
|
+
}
|
|
181
|
+
const parsed = parseJson(raw);
|
|
182
|
+
if (parsed === null) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return typeof parsed === 'string' ? parsed : fail('invalid payload');
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
189
|
+
return fail(reason);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export function mergeToolCallsWithNative(existing, additions) {
|
|
193
|
+
const capability = 'mergeToolCallsJson';
|
|
194
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
195
|
+
if (isNativeDisabledByEnv()) {
|
|
196
|
+
return fail('native disabled');
|
|
197
|
+
}
|
|
198
|
+
const fn = readNativeFunction(capability);
|
|
199
|
+
if (!fn) {
|
|
200
|
+
return fail();
|
|
201
|
+
}
|
|
202
|
+
const existingJson = safeStringify(existing ?? []);
|
|
203
|
+
const additionsJson = safeStringify(additions ?? []);
|
|
204
|
+
if (!existingJson || !additionsJson) {
|
|
205
|
+
return fail('json stringify failed');
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const raw = fn(existingJson, additionsJson);
|
|
209
|
+
if (typeof raw !== 'string' || !raw) {
|
|
210
|
+
return fail('empty result');
|
|
211
|
+
}
|
|
212
|
+
const parsed = parseJson(raw);
|
|
213
|
+
if (!Array.isArray(parsed)) {
|
|
214
|
+
return fail('invalid payload');
|
|
215
|
+
}
|
|
216
|
+
return parsed.filter((entry) => entry && typeof entry === 'object');
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
220
|
+
return fail(reason);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export function mapReasoningContentToResponsesOutputWithNative(reasoningContent) {
|
|
224
|
+
const capability = 'mapReasoningContentToResponsesOutputJson';
|
|
225
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
226
|
+
if (isNativeDisabledByEnv()) {
|
|
227
|
+
return fail('native disabled');
|
|
228
|
+
}
|
|
229
|
+
const fn = readNativeFunction(capability);
|
|
230
|
+
if (!fn) {
|
|
231
|
+
return fail();
|
|
232
|
+
}
|
|
233
|
+
const contentJson = safeStringify(reasoningContent ?? null);
|
|
234
|
+
if (!contentJson) {
|
|
235
|
+
return fail('json stringify failed');
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const raw = fn(contentJson);
|
|
239
|
+
if (typeof raw !== 'string' || !raw) {
|
|
240
|
+
return fail('empty result');
|
|
241
|
+
}
|
|
242
|
+
const parsed = parseReasoningItems(raw);
|
|
243
|
+
return parsed ?? fail('invalid payload');
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
247
|
+
return fail(reason);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
export function isImagePathWithNative(pathValue) {
|
|
251
|
+
const capability = 'isImagePathJson';
|
|
252
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
253
|
+
if (isNativeDisabledByEnv()) {
|
|
254
|
+
return fail('native disabled');
|
|
255
|
+
}
|
|
256
|
+
const fn = readNativeFunction(capability);
|
|
257
|
+
if (!fn) {
|
|
258
|
+
return fail();
|
|
259
|
+
}
|
|
260
|
+
const pathJson = safeStringify(pathValue ?? null);
|
|
261
|
+
if (!pathJson) {
|
|
262
|
+
return fail('json stringify failed');
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const raw = fn(pathJson);
|
|
266
|
+
if (typeof raw !== 'string' || !raw) {
|
|
267
|
+
return fail('empty result');
|
|
268
|
+
}
|
|
269
|
+
const parsed = parseJson(raw);
|
|
270
|
+
return typeof parsed === 'boolean' ? parsed : fail('invalid payload');
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
274
|
+
return fail(reason);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
export function isCompactionRequestWithNative(payload) {
|
|
278
|
+
const capability = 'isCompactionRequestJson';
|
|
279
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
280
|
+
if (isNativeDisabledByEnv()) {
|
|
281
|
+
return fail('native disabled');
|
|
282
|
+
}
|
|
283
|
+
const fn = readNativeFunction(capability);
|
|
284
|
+
if (!fn) {
|
|
285
|
+
return fail();
|
|
286
|
+
}
|
|
287
|
+
const payloadJson = safeStringify(payload ?? null);
|
|
288
|
+
if (!payloadJson) {
|
|
289
|
+
return fail('json stringify failed');
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
const raw = fn(payloadJson);
|
|
293
|
+
if (typeof raw !== 'string' || !raw) {
|
|
294
|
+
return fail('empty result');
|
|
295
|
+
}
|
|
296
|
+
const parsed = parseJson(raw);
|
|
297
|
+
return typeof parsed === 'boolean' ? parsed : fail('invalid payload');
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
301
|
+
return fail(reason);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
export function encodeMetadataPassthroughWithNative(parameters, prefix, keys) {
|
|
305
|
+
const capability = 'encodeMetadataPassthroughJson';
|
|
306
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
307
|
+
if (isNativeDisabledByEnv()) {
|
|
308
|
+
return fail('native disabled');
|
|
309
|
+
}
|
|
310
|
+
const fn = readNativeFunction(capability);
|
|
311
|
+
if (!fn) {
|
|
312
|
+
return fail();
|
|
313
|
+
}
|
|
314
|
+
const parametersJson = safeStringify(parameters ?? null);
|
|
315
|
+
const keysJson = safeStringify(Array.isArray(keys) ? keys : []);
|
|
316
|
+
if (!parametersJson || !keysJson) {
|
|
317
|
+
return fail('json stringify failed');
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const raw = fn(parametersJson, String(prefix || ''), keysJson);
|
|
321
|
+
if (typeof raw !== 'string' || !raw) {
|
|
322
|
+
return fail('empty result');
|
|
323
|
+
}
|
|
324
|
+
const parsed = parseJson(raw);
|
|
325
|
+
if (parsed === null) {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
329
|
+
return fail('invalid payload');
|
|
330
|
+
}
|
|
331
|
+
const out = {};
|
|
332
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
333
|
+
if (typeof key !== 'string' || typeof value !== 'string') {
|
|
334
|
+
return fail('invalid payload');
|
|
335
|
+
}
|
|
336
|
+
out[key] = value;
|
|
337
|
+
}
|
|
338
|
+
return Object.keys(out).length ? out : undefined;
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
342
|
+
return fail(reason);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
export function extractMetadataPassthroughWithNative(metadataField, prefix, keys) {
|
|
346
|
+
const capability = 'extractMetadataPassthroughJson';
|
|
347
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
348
|
+
if (isNativeDisabledByEnv()) {
|
|
349
|
+
return fail('native disabled');
|
|
350
|
+
}
|
|
351
|
+
const fn = readNativeFunction(capability);
|
|
352
|
+
if (!fn) {
|
|
353
|
+
return fail();
|
|
354
|
+
}
|
|
355
|
+
const metadataJson = safeStringify(metadataField ?? null);
|
|
356
|
+
const keysJson = safeStringify(Array.isArray(keys) ? keys : []);
|
|
357
|
+
if (!metadataJson || !keysJson) {
|
|
358
|
+
return fail('json stringify failed');
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const raw = fn(metadataJson, String(prefix || ''), keysJson);
|
|
362
|
+
if (typeof raw !== 'string' || !raw) {
|
|
363
|
+
return fail('empty result');
|
|
364
|
+
}
|
|
365
|
+
const parsed = parseRecord(raw);
|
|
366
|
+
if (!parsed) {
|
|
367
|
+
return fail('invalid payload');
|
|
368
|
+
}
|
|
369
|
+
const metadata = parsed.metadata && typeof parsed.metadata === 'object' && !Array.isArray(parsed.metadata)
|
|
370
|
+
? parsed.metadata
|
|
371
|
+
: undefined;
|
|
372
|
+
const passthrough = parsed.passthrough && typeof parsed.passthrough === 'object' && !Array.isArray(parsed.passthrough)
|
|
373
|
+
? parsed.passthrough
|
|
374
|
+
: undefined;
|
|
375
|
+
return {
|
|
376
|
+
...(metadata ? { metadata } : {}),
|
|
377
|
+
...(passthrough ? { passthrough } : {})
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
382
|
+
return fail(reason);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
export function ensureProtocolStateWithNative(metadata, protocol) {
|
|
386
|
+
const capability = 'ensureProtocolStateJson';
|
|
387
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
388
|
+
if (isNativeDisabledByEnv()) {
|
|
389
|
+
return fail('native disabled');
|
|
390
|
+
}
|
|
391
|
+
const fn = readNativeFunction(capability);
|
|
392
|
+
if (!fn) {
|
|
393
|
+
return fail();
|
|
394
|
+
}
|
|
395
|
+
const metadataJson = safeStringify(metadata ?? {});
|
|
396
|
+
if (!metadataJson) {
|
|
397
|
+
return fail('json stringify failed');
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
const raw = fn(metadataJson, String(protocol ?? ''));
|
|
401
|
+
if (typeof raw !== 'string' || !raw) {
|
|
402
|
+
return fail('empty result');
|
|
403
|
+
}
|
|
404
|
+
const parsed = parseRecord(raw);
|
|
405
|
+
if (!parsed) {
|
|
406
|
+
return fail('invalid payload');
|
|
407
|
+
}
|
|
408
|
+
const metadataOut = parsed.metadata && typeof parsed.metadata === 'object' && !Array.isArray(parsed.metadata)
|
|
409
|
+
? parsed.metadata
|
|
410
|
+
: undefined;
|
|
411
|
+
const nodeOut = parsed.node && typeof parsed.node === 'object' && !Array.isArray(parsed.node)
|
|
412
|
+
? parsed.node
|
|
413
|
+
: undefined;
|
|
414
|
+
if (!metadataOut || !nodeOut) {
|
|
415
|
+
return fail('invalid payload');
|
|
416
|
+
}
|
|
417
|
+
return { metadata: metadataOut, node: nodeOut };
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
421
|
+
return fail(reason);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
export function getProtocolStateWithNative(metadata, protocol) {
|
|
425
|
+
const capability = 'getProtocolStateJson';
|
|
426
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
427
|
+
if (isNativeDisabledByEnv()) {
|
|
428
|
+
return fail('native disabled');
|
|
429
|
+
}
|
|
430
|
+
const fn = readNativeFunction(capability);
|
|
431
|
+
if (!fn) {
|
|
432
|
+
return fail();
|
|
433
|
+
}
|
|
434
|
+
const metadataJson = safeStringify(metadata ?? null);
|
|
435
|
+
if (!metadataJson) {
|
|
436
|
+
return fail('json stringify failed');
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
const raw = fn(metadataJson, String(protocol ?? ''));
|
|
440
|
+
if (typeof raw !== 'string' || !raw) {
|
|
441
|
+
return fail('empty result');
|
|
442
|
+
}
|
|
443
|
+
const parsed = parseJson(raw);
|
|
444
|
+
if (parsed === null) {
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
448
|
+
? parsed
|
|
449
|
+
: fail('invalid payload');
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
453
|
+
return fail(reason);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
export function readRuntimeMetadataWithNative(carrier) {
|
|
457
|
+
const capability = 'readRuntimeMetadataJson';
|
|
458
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
459
|
+
if (isNativeDisabledByEnv()) {
|
|
460
|
+
return fail('native disabled');
|
|
461
|
+
}
|
|
462
|
+
const fn = readNativeFunction(capability);
|
|
463
|
+
if (!fn) {
|
|
464
|
+
return fail();
|
|
465
|
+
}
|
|
466
|
+
const carrierJson = safeStringify(carrier ?? null);
|
|
467
|
+
if (!carrierJson) {
|
|
468
|
+
return fail('json stringify failed');
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
const raw = fn(carrierJson);
|
|
472
|
+
if (typeof raw !== 'string' || !raw) {
|
|
473
|
+
return fail('empty result');
|
|
474
|
+
}
|
|
475
|
+
const parsed = parseJson(raw);
|
|
476
|
+
if (parsed === null) {
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
480
|
+
? parsed
|
|
481
|
+
: fail('invalid payload');
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
485
|
+
return fail(reason);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
export function ensureRuntimeMetadataCarrierWithNative(carrier) {
|
|
489
|
+
const capability = 'ensureRuntimeMetadataJson';
|
|
490
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
491
|
+
if (isNativeDisabledByEnv()) {
|
|
492
|
+
return fail('native disabled');
|
|
493
|
+
}
|
|
494
|
+
const fn = readNativeFunction(capability);
|
|
495
|
+
if (!fn) {
|
|
496
|
+
return fail();
|
|
497
|
+
}
|
|
498
|
+
const carrierJson = safeStringify(carrier);
|
|
499
|
+
if (!carrierJson) {
|
|
500
|
+
return fail('json stringify failed');
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
const raw = fn(carrierJson);
|
|
504
|
+
if (typeof raw !== 'string' || !raw) {
|
|
505
|
+
return fail('empty result');
|
|
506
|
+
}
|
|
507
|
+
const parsed = parseRecord(raw);
|
|
508
|
+
return parsed ?? fail('invalid payload');
|
|
509
|
+
}
|
|
510
|
+
catch (error) {
|
|
511
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
512
|
+
return fail(reason);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
export function cloneRuntimeMetadataWithNative(carrier) {
|
|
516
|
+
const capability = 'cloneRuntimeMetadataJson';
|
|
517
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
518
|
+
if (isNativeDisabledByEnv()) {
|
|
519
|
+
return fail('native disabled');
|
|
520
|
+
}
|
|
521
|
+
const fn = readNativeFunction(capability);
|
|
522
|
+
if (!fn) {
|
|
523
|
+
return fail();
|
|
524
|
+
}
|
|
525
|
+
const carrierJson = safeStringify(carrier ?? null);
|
|
526
|
+
if (!carrierJson) {
|
|
527
|
+
return fail('json stringify failed');
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
530
|
+
const raw = fn(carrierJson);
|
|
531
|
+
if (typeof raw !== 'string' || !raw) {
|
|
532
|
+
return fail('empty result');
|
|
533
|
+
}
|
|
534
|
+
const parsed = parseJson(raw);
|
|
535
|
+
if (parsed === null) {
|
|
536
|
+
return undefined;
|
|
537
|
+
}
|
|
538
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
539
|
+
? parsed
|
|
540
|
+
: fail('invalid payload');
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
544
|
+
return fail(reason);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
export function injectMcpToolsForChatWithNative(tools, discoveredServers) {
|
|
548
|
+
const capability = 'injectMcpToolsForChatJson';
|
|
549
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
550
|
+
if (isNativeDisabledByEnv()) {
|
|
551
|
+
return fail('native disabled');
|
|
552
|
+
}
|
|
553
|
+
const fn = readNativeFunction(capability);
|
|
554
|
+
if (!fn) {
|
|
555
|
+
return fail();
|
|
556
|
+
}
|
|
557
|
+
const toolsJson = safeStringify(Array.isArray(tools) ? tools : []);
|
|
558
|
+
const serversJson = safeStringify(Array.isArray(discoveredServers) ? discoveredServers : []);
|
|
559
|
+
if (!toolsJson || !serversJson) {
|
|
560
|
+
return fail('json stringify failed');
|
|
561
|
+
}
|
|
562
|
+
try {
|
|
563
|
+
const raw = fn(toolsJson, serversJson);
|
|
564
|
+
if (typeof raw !== 'string' || !raw) {
|
|
565
|
+
return fail('empty result');
|
|
566
|
+
}
|
|
567
|
+
const parsed = parseJson(raw);
|
|
568
|
+
return Array.isArray(parsed) ? parsed : fail('invalid payload');
|
|
569
|
+
}
|
|
570
|
+
catch (error) {
|
|
571
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
572
|
+
return fail(reason);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
export function normalizeArgsBySchemaWithNative(input, schema) {
|
|
576
|
+
const capability = 'normalizeArgsBySchemaJson';
|
|
577
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
578
|
+
if (isNativeDisabledByEnv()) {
|
|
579
|
+
return fail('native disabled');
|
|
580
|
+
}
|
|
581
|
+
const fn = readNativeFunction(capability);
|
|
582
|
+
if (!fn) {
|
|
583
|
+
return fail();
|
|
584
|
+
}
|
|
585
|
+
const inputJson = safeStringify(input ?? null);
|
|
586
|
+
const schemaJson = safeStringify(schema ?? null);
|
|
587
|
+
if (!inputJson || !schemaJson) {
|
|
588
|
+
return fail('json stringify failed');
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
const raw = fn(inputJson, schemaJson);
|
|
592
|
+
if (typeof raw !== 'string' || !raw) {
|
|
593
|
+
return fail('empty result');
|
|
594
|
+
}
|
|
595
|
+
const parsed = parseRecord(raw);
|
|
596
|
+
if (!parsed || typeof parsed.ok !== 'boolean') {
|
|
597
|
+
return fail('invalid payload');
|
|
598
|
+
}
|
|
599
|
+
const value = parsed.value && typeof parsed.value === 'object' && !Array.isArray(parsed.value)
|
|
600
|
+
? parsed.value
|
|
601
|
+
: undefined;
|
|
602
|
+
const errors = Array.isArray(parsed.errors)
|
|
603
|
+
? parsed.errors.filter((entry) => typeof entry === 'string')
|
|
604
|
+
: undefined;
|
|
605
|
+
return {
|
|
606
|
+
ok: parsed.ok,
|
|
607
|
+
...(value ? { value } : {}),
|
|
608
|
+
...(errors && errors.length ? { errors } : {})
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
catch (error) {
|
|
612
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
613
|
+
return fail(reason);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
export function extractOutputSegmentsWithNative(source, itemsKey = 'output') {
|
|
617
|
+
const capability = 'extractOutputSegmentsJson';
|
|
618
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
619
|
+
if (isNativeDisabledByEnv()) {
|
|
620
|
+
return fail('native disabled');
|
|
621
|
+
}
|
|
622
|
+
const fn = readNativeFunction(capability);
|
|
623
|
+
if (!fn) {
|
|
624
|
+
return fail();
|
|
625
|
+
}
|
|
626
|
+
const sourceJson = safeStringify(source ?? null);
|
|
627
|
+
if (!sourceJson) {
|
|
628
|
+
return fail('json stringify failed');
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
const raw = fn(sourceJson, String(itemsKey || 'output'));
|
|
632
|
+
if (typeof raw !== 'string' || !raw) {
|
|
633
|
+
return fail('empty result');
|
|
634
|
+
}
|
|
635
|
+
const parsed = parseRecord(raw);
|
|
636
|
+
if (!parsed) {
|
|
637
|
+
return fail('invalid payload');
|
|
638
|
+
}
|
|
639
|
+
const textParts = Array.isArray(parsed.textParts)
|
|
640
|
+
? parsed.textParts.filter((entry) => typeof entry === 'string')
|
|
641
|
+
: [];
|
|
642
|
+
const reasoningParts = Array.isArray(parsed.reasoningParts)
|
|
643
|
+
? parsed.reasoningParts.filter((entry) => typeof entry === 'string')
|
|
644
|
+
: [];
|
|
645
|
+
return { textParts, reasoningParts };
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
649
|
+
return fail(reason);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
export function normalizeContentPartWithNative(part, reasoningCollector) {
|
|
653
|
+
const capability = 'normalizeOutputContentPartJson';
|
|
654
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
655
|
+
if (isNativeDisabledByEnv()) {
|
|
656
|
+
return fail('native disabled');
|
|
657
|
+
}
|
|
658
|
+
const fn = readNativeFunction(capability);
|
|
659
|
+
if (!fn) {
|
|
660
|
+
return fail();
|
|
661
|
+
}
|
|
662
|
+
const partJson = safeStringify(part ?? null);
|
|
663
|
+
const collectorJson = safeStringify(Array.isArray(reasoningCollector) ? reasoningCollector : []);
|
|
664
|
+
if (!partJson || !collectorJson) {
|
|
665
|
+
return fail('json stringify failed');
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
const raw = fn(partJson, collectorJson);
|
|
669
|
+
if (typeof raw !== 'string' || !raw) {
|
|
670
|
+
return fail('empty result');
|
|
671
|
+
}
|
|
672
|
+
const parsed = parseRecord(raw);
|
|
673
|
+
if (!parsed) {
|
|
674
|
+
return fail('invalid payload');
|
|
675
|
+
}
|
|
676
|
+
const normalized = parsed.normalized === null
|
|
677
|
+
? null
|
|
678
|
+
: parsed.normalized && typeof parsed.normalized === 'object' && !Array.isArray(parsed.normalized)
|
|
679
|
+
? parsed.normalized
|
|
680
|
+
: fail('invalid payload');
|
|
681
|
+
const nextCollector = Array.isArray(parsed.reasoningCollector)
|
|
682
|
+
? parsed.reasoningCollector.filter((entry) => typeof entry === 'string')
|
|
683
|
+
: [];
|
|
684
|
+
return { normalized, reasoningCollector: nextCollector };
|
|
685
|
+
}
|
|
686
|
+
catch (error) {
|
|
687
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
688
|
+
return fail(reason);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
export function normalizeMessageContentPartsWithNative(parts, reasoningCollector) {
|
|
692
|
+
const capability = 'normalizeMessageContentPartsJson';
|
|
693
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
694
|
+
if (isNativeDisabledByEnv()) {
|
|
695
|
+
return fail('native disabled');
|
|
696
|
+
}
|
|
697
|
+
const fn = readNativeFunction(capability);
|
|
698
|
+
if (!fn) {
|
|
699
|
+
return fail();
|
|
700
|
+
}
|
|
701
|
+
const partsJson = safeStringify(parts ?? null);
|
|
702
|
+
const collectorJson = safeStringify(Array.isArray(reasoningCollector) ? reasoningCollector : []);
|
|
703
|
+
if (!partsJson || !collectorJson) {
|
|
704
|
+
return fail('json stringify failed');
|
|
705
|
+
}
|
|
706
|
+
try {
|
|
707
|
+
const raw = fn(partsJson, collectorJson);
|
|
708
|
+
if (typeof raw !== 'string' || !raw) {
|
|
709
|
+
return fail('empty result');
|
|
710
|
+
}
|
|
711
|
+
const parsed = parseRecord(raw);
|
|
712
|
+
if (!parsed) {
|
|
713
|
+
return fail('invalid payload');
|
|
714
|
+
}
|
|
715
|
+
const normalizedParts = Array.isArray(parsed.normalizedParts)
|
|
716
|
+
? parsed.normalizedParts.filter((entry) => !!entry && typeof entry === 'object' && !Array.isArray(entry))
|
|
717
|
+
: [];
|
|
718
|
+
const reasoningChunks = Array.isArray(parsed.reasoningChunks)
|
|
719
|
+
? parsed.reasoningChunks.filter((entry) => typeof entry === 'string')
|
|
720
|
+
: [];
|
|
721
|
+
return { normalizedParts, reasoningChunks };
|
|
722
|
+
}
|
|
723
|
+
catch (error) {
|
|
724
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
725
|
+
return fail(reason);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
export function normalizeChatMessageContentWithNative(content) {
|
|
729
|
+
const capability = 'normalizeChatMessageContentJson';
|
|
730
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
731
|
+
if (isNativeDisabledByEnv()) {
|
|
732
|
+
return fail('native disabled');
|
|
733
|
+
}
|
|
734
|
+
const fn = readNativeFunction(capability);
|
|
735
|
+
if (!fn) {
|
|
736
|
+
return fail();
|
|
737
|
+
}
|
|
738
|
+
const contentJson = safeStringify(content ?? null);
|
|
739
|
+
if (!contentJson) {
|
|
740
|
+
return fail('json stringify failed');
|
|
741
|
+
}
|
|
742
|
+
try {
|
|
743
|
+
const raw = fn(contentJson);
|
|
744
|
+
if (typeof raw !== 'string' || !raw) {
|
|
745
|
+
return fail('empty result');
|
|
746
|
+
}
|
|
747
|
+
const parsed = parseRecord(raw);
|
|
748
|
+
if (!parsed) {
|
|
749
|
+
return fail('invalid payload');
|
|
750
|
+
}
|
|
751
|
+
const contentText = typeof parsed.contentText === 'string' ? parsed.contentText : undefined;
|
|
752
|
+
const reasoningText = typeof parsed.reasoningText === 'string' ? parsed.reasoningText : undefined;
|
|
753
|
+
return {
|
|
754
|
+
...(contentText ? { contentText } : {}),
|
|
755
|
+
...(reasoningText ? { reasoningText } : {})
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
catch (error) {
|
|
759
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
760
|
+
return fail(reason);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
export function normalizeOpenaiMessageWithNative(message, disableShellCoerce) {
|
|
764
|
+
const capability = 'normalizeOpenaiMessageJson';
|
|
765
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
766
|
+
if (isNativeDisabledByEnv()) {
|
|
767
|
+
return fail('native disabled');
|
|
768
|
+
}
|
|
769
|
+
const fn = readNativeFunction(capability);
|
|
770
|
+
if (!fn) {
|
|
771
|
+
return fail();
|
|
772
|
+
}
|
|
773
|
+
const payloadJson = safeStringify(message ?? null);
|
|
774
|
+
if (!payloadJson) {
|
|
775
|
+
return fail('json stringify failed');
|
|
776
|
+
}
|
|
777
|
+
try {
|
|
778
|
+
const raw = fn(payloadJson, Boolean(disableShellCoerce));
|
|
779
|
+
if (typeof raw !== 'string' || !raw) {
|
|
780
|
+
return fail('empty result');
|
|
781
|
+
}
|
|
782
|
+
try {
|
|
783
|
+
return JSON.parse(raw);
|
|
784
|
+
}
|
|
785
|
+
catch {
|
|
786
|
+
return fail('invalid payload');
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
catch (error) {
|
|
790
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
791
|
+
return fail(reason);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
export function normalizeOpenaiToolWithNative(tool) {
|
|
795
|
+
const capability = 'normalizeOpenaiToolJson';
|
|
796
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
797
|
+
if (isNativeDisabledByEnv()) {
|
|
798
|
+
return fail('native disabled');
|
|
799
|
+
}
|
|
800
|
+
const fn = readNativeFunction(capability);
|
|
801
|
+
if (!fn) {
|
|
802
|
+
return fail();
|
|
803
|
+
}
|
|
804
|
+
const payloadJson = safeStringify(tool ?? null);
|
|
805
|
+
if (!payloadJson) {
|
|
806
|
+
return fail('json stringify failed');
|
|
807
|
+
}
|
|
808
|
+
try {
|
|
809
|
+
const raw = fn(payloadJson);
|
|
810
|
+
if (typeof raw !== 'string' || !raw) {
|
|
811
|
+
return fail('empty result');
|
|
812
|
+
}
|
|
813
|
+
try {
|
|
814
|
+
return JSON.parse(raw);
|
|
815
|
+
}
|
|
816
|
+
catch {
|
|
817
|
+
return fail('invalid payload');
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
822
|
+
return fail(reason);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
export function normalizeOpenaiChatMessagesWithNative(messages) {
|
|
826
|
+
const capability = 'normalizeOpenaiChatMessagesJson';
|
|
827
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
828
|
+
if (isNativeDisabledByEnv()) {
|
|
829
|
+
return fail('native disabled');
|
|
830
|
+
}
|
|
831
|
+
const fn = readNativeFunction(capability);
|
|
832
|
+
if (!fn) {
|
|
833
|
+
return fail();
|
|
834
|
+
}
|
|
835
|
+
const payloadJson = safeStringify(messages ?? null);
|
|
836
|
+
if (!payloadJson) {
|
|
837
|
+
return fail('json stringify failed');
|
|
838
|
+
}
|
|
839
|
+
try {
|
|
840
|
+
const raw = fn(payloadJson);
|
|
841
|
+
if (typeof raw !== 'string' || !raw) {
|
|
842
|
+
return fail('empty result');
|
|
843
|
+
}
|
|
844
|
+
const parsed = parseJson(raw);
|
|
845
|
+
return Array.isArray(parsed) ? parsed : fail('invalid payload');
|
|
846
|
+
}
|
|
847
|
+
catch (error) {
|
|
848
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
849
|
+
return fail(reason);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
export function normalizeOpenaiToolCallWithNative(toolCall, disableShellCoerce) {
|
|
853
|
+
const capability = 'normalizeOpenaiToolCallJson';
|
|
854
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
855
|
+
if (isNativeDisabledByEnv()) {
|
|
856
|
+
return fail('native disabled');
|
|
857
|
+
}
|
|
858
|
+
const fn = readNativeFunction(capability);
|
|
859
|
+
if (!fn) {
|
|
860
|
+
return fail();
|
|
861
|
+
}
|
|
862
|
+
const payloadJson = safeStringify(toolCall ?? null);
|
|
863
|
+
if (!payloadJson) {
|
|
864
|
+
return fail('json stringify failed');
|
|
865
|
+
}
|
|
866
|
+
try {
|
|
867
|
+
const raw = fn(payloadJson, Boolean(disableShellCoerce));
|
|
868
|
+
if (typeof raw !== 'string' || !raw) {
|
|
869
|
+
return fail('empty result');
|
|
870
|
+
}
|
|
871
|
+
try {
|
|
872
|
+
return JSON.parse(raw);
|
|
873
|
+
}
|
|
874
|
+
catch {
|
|
875
|
+
return fail('invalid payload');
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
catch (error) {
|
|
879
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
880
|
+
return fail(reason);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
export function prepareGeminiToolsForBridgeWithNative(rawTools, missing) {
|
|
884
|
+
const capability = 'prepareGeminiToolsForBridgeJson';
|
|
885
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
886
|
+
if (isNativeDisabledByEnv()) {
|
|
887
|
+
return fail('native disabled');
|
|
888
|
+
}
|
|
889
|
+
const fn = readNativeFunction(capability);
|
|
890
|
+
if (!fn) {
|
|
891
|
+
return fail();
|
|
892
|
+
}
|
|
893
|
+
const rawToolsJson = safeStringify(rawTools ?? null);
|
|
894
|
+
const missingJson = safeStringify(Array.isArray(missing) ? missing : []);
|
|
895
|
+
if (!rawToolsJson || !missingJson) {
|
|
896
|
+
return fail('json stringify failed');
|
|
897
|
+
}
|
|
898
|
+
try {
|
|
899
|
+
const raw = fn(rawToolsJson, missingJson);
|
|
900
|
+
if (typeof raw !== 'string' || !raw) {
|
|
901
|
+
return fail('empty result');
|
|
902
|
+
}
|
|
903
|
+
const parsed = parseRecord(raw);
|
|
904
|
+
if (!parsed) {
|
|
905
|
+
return fail('invalid payload');
|
|
906
|
+
}
|
|
907
|
+
const defs = Array.isArray(parsed.defs)
|
|
908
|
+
? parsed.defs.filter((entry) => !!entry && typeof entry === 'object' && !Array.isArray(entry))
|
|
909
|
+
: undefined;
|
|
910
|
+
const nextMissing = Array.isArray(parsed.missing)
|
|
911
|
+
? parsed.missing.filter((entry) => !!entry && typeof entry === 'object' && !Array.isArray(entry))
|
|
912
|
+
: [];
|
|
913
|
+
return {
|
|
914
|
+
...(defs && defs.length ? { defs } : {}),
|
|
915
|
+
missing: nextMissing
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
catch (error) {
|
|
919
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
920
|
+
return fail(reason);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
export function buildGeminiToolsFromBridgeWithNative(defs, mode = 'default') {
|
|
924
|
+
const capability = 'buildGeminiToolsFromBridgeJson';
|
|
925
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
926
|
+
if (isNativeDisabledByEnv()) {
|
|
927
|
+
return fail('native disabled');
|
|
928
|
+
}
|
|
929
|
+
const fn = readNativeFunction(capability);
|
|
930
|
+
if (!fn) {
|
|
931
|
+
return fail();
|
|
932
|
+
}
|
|
933
|
+
const defsJson = safeStringify(defs ?? null);
|
|
934
|
+
if (!defsJson) {
|
|
935
|
+
return fail('json stringify failed');
|
|
936
|
+
}
|
|
937
|
+
try {
|
|
938
|
+
const raw = fn(defsJson, mode);
|
|
939
|
+
if (typeof raw !== 'string' || !raw) {
|
|
940
|
+
return fail('empty result');
|
|
941
|
+
}
|
|
942
|
+
const parsed = parseJson(raw);
|
|
943
|
+
if (parsed == null) {
|
|
944
|
+
return undefined;
|
|
945
|
+
}
|
|
946
|
+
if (!Array.isArray(parsed)) {
|
|
947
|
+
return fail('invalid payload');
|
|
948
|
+
}
|
|
949
|
+
return parsed.filter((entry) => !!entry && typeof entry === 'object' && !Array.isArray(entry));
|
|
950
|
+
}
|
|
951
|
+
catch (error) {
|
|
952
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
953
|
+
return fail(reason);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
export function pickResponsesPersistedFieldsWithNative(payload) {
|
|
957
|
+
const capability = 'pickResponsesPersistedFieldsJson';
|
|
958
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
959
|
+
if (isNativeDisabledByEnv()) {
|
|
960
|
+
return fail('native disabled');
|
|
961
|
+
}
|
|
962
|
+
const fn = readNativeFunction(capability);
|
|
963
|
+
if (!fn) {
|
|
964
|
+
return fail();
|
|
965
|
+
}
|
|
966
|
+
const payloadJson = safeStringify(payload ?? null);
|
|
967
|
+
if (!payloadJson) {
|
|
968
|
+
return fail('json stringify failed');
|
|
969
|
+
}
|
|
970
|
+
try {
|
|
971
|
+
const raw = fn(payloadJson);
|
|
972
|
+
if (typeof raw !== 'string' || !raw) {
|
|
973
|
+
return fail('empty result');
|
|
974
|
+
}
|
|
975
|
+
const parsed = parseRecord(raw);
|
|
976
|
+
return parsed ?? fail('invalid payload');
|
|
977
|
+
}
|
|
978
|
+
catch (error) {
|
|
979
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
980
|
+
return fail(reason);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
export function convertResponsesOutputToInputItemsWithNative(response) {
|
|
984
|
+
const capability = 'convertResponsesOutputToInputItemsJson';
|
|
985
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
986
|
+
if (isNativeDisabledByEnv()) {
|
|
987
|
+
return fail('native disabled');
|
|
988
|
+
}
|
|
989
|
+
const fn = readNativeFunction(capability);
|
|
990
|
+
if (!fn) {
|
|
991
|
+
return fail();
|
|
992
|
+
}
|
|
993
|
+
const responseJson = safeStringify(response ?? null);
|
|
994
|
+
if (!responseJson) {
|
|
995
|
+
return fail('json stringify failed');
|
|
996
|
+
}
|
|
997
|
+
try {
|
|
998
|
+
const raw = fn(responseJson);
|
|
999
|
+
if (typeof raw !== 'string' || !raw) {
|
|
1000
|
+
return fail('empty result');
|
|
1001
|
+
}
|
|
1002
|
+
const parsed = parseJson(raw);
|
|
1003
|
+
if (!Array.isArray(parsed)) {
|
|
1004
|
+
return fail('invalid payload');
|
|
1005
|
+
}
|
|
1006
|
+
return parsed.filter((entry) => !!entry && typeof entry === 'object' && !Array.isArray(entry));
|
|
1007
|
+
}
|
|
1008
|
+
catch (error) {
|
|
1009
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1010
|
+
return fail(reason);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
export function enforceChatBudgetWithNative(chat, allowedBytes, systemTextLimit) {
|
|
1014
|
+
const capability = 'enforceChatBudgetJson';
|
|
1015
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
1016
|
+
if (isNativeDisabledByEnv()) {
|
|
1017
|
+
return fail('native disabled');
|
|
1018
|
+
}
|
|
1019
|
+
const fn = readNativeFunction(capability);
|
|
1020
|
+
if (!fn) {
|
|
1021
|
+
return fail();
|
|
1022
|
+
}
|
|
1023
|
+
const chatJson = safeStringify(chat ?? null);
|
|
1024
|
+
if (!chatJson) {
|
|
1025
|
+
return fail('json stringify failed');
|
|
1026
|
+
}
|
|
1027
|
+
try {
|
|
1028
|
+
const raw = fn(chatJson, Number(allowedBytes), Number(systemTextLimit));
|
|
1029
|
+
if (typeof raw !== 'string' || !raw) {
|
|
1030
|
+
return fail('empty result');
|
|
1031
|
+
}
|
|
1032
|
+
const parsed = parseJson(raw);
|
|
1033
|
+
return parsed ?? fail('invalid payload');
|
|
1034
|
+
}
|
|
1035
|
+
catch (error) {
|
|
1036
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1037
|
+
return fail(reason);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
export function injectMcpToolsForResponsesWithNative(tools, discoveredServers) {
|
|
1041
|
+
const capability = 'injectMcpToolsForResponsesJson';
|
|
1042
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
1043
|
+
if (isNativeDisabledByEnv()) {
|
|
1044
|
+
return fail('native disabled');
|
|
1045
|
+
}
|
|
1046
|
+
const fn = readNativeFunction(capability);
|
|
1047
|
+
if (!fn) {
|
|
1048
|
+
return fail();
|
|
1049
|
+
}
|
|
1050
|
+
const toolsJson = safeStringify(Array.isArray(tools) ? tools : []);
|
|
1051
|
+
const serversJson = safeStringify(Array.isArray(discoveredServers) ? discoveredServers : []);
|
|
1052
|
+
if (!toolsJson || !serversJson) {
|
|
1053
|
+
return fail('json stringify failed');
|
|
1054
|
+
}
|
|
1055
|
+
try {
|
|
1056
|
+
const raw = fn(toolsJson, serversJson);
|
|
1057
|
+
if (typeof raw !== 'string' || !raw) {
|
|
1058
|
+
return fail('empty result');
|
|
1059
|
+
}
|
|
1060
|
+
const parsed = parseJson(raw);
|
|
1061
|
+
return Array.isArray(parsed) ? parsed : fail('invalid payload');
|
|
1062
|
+
}
|
|
1063
|
+
catch (error) {
|
|
1064
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1065
|
+
return fail(reason);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
export function normalizeFunctionCallIdWithNative(input) {
|
|
1069
|
+
const capability = 'normalizeFunctionCallIdJson';
|
|
1070
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
1071
|
+
if (isNativeDisabledByEnv()) {
|
|
1072
|
+
return fail('native disabled');
|
|
1073
|
+
}
|
|
1074
|
+
const fn = readNativeFunction(capability);
|
|
1075
|
+
if (!fn) {
|
|
1076
|
+
return fail();
|
|
1077
|
+
}
|
|
1078
|
+
const inputJson = safeStringify(input ?? {});
|
|
1079
|
+
if (!inputJson) {
|
|
1080
|
+
return fail('json stringify failed');
|
|
1081
|
+
}
|
|
1082
|
+
try {
|
|
1083
|
+
const raw = fn(inputJson);
|
|
1084
|
+
return typeof raw === 'string' && raw ? raw : fail('invalid payload');
|
|
1085
|
+
}
|
|
1086
|
+
catch (error) {
|
|
1087
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1088
|
+
return fail(reason);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
export function normalizeFunctionCallOutputIdWithNative(input) {
|
|
1092
|
+
const capability = 'normalizeFunctionCallOutputIdJson';
|
|
1093
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
1094
|
+
if (isNativeDisabledByEnv()) {
|
|
1095
|
+
return fail('native disabled');
|
|
1096
|
+
}
|
|
1097
|
+
const fn = readNativeFunction(capability);
|
|
1098
|
+
if (!fn) {
|
|
1099
|
+
return fail();
|
|
1100
|
+
}
|
|
1101
|
+
const inputJson = safeStringify(input ?? {});
|
|
1102
|
+
if (!inputJson) {
|
|
1103
|
+
return fail('json stringify failed');
|
|
1104
|
+
}
|
|
1105
|
+
try {
|
|
1106
|
+
const raw = fn(inputJson);
|
|
1107
|
+
return typeof raw === 'string' && raw ? raw : fail('invalid payload');
|
|
1108
|
+
}
|
|
1109
|
+
catch (error) {
|
|
1110
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1111
|
+
return fail(reason);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
export function normalizeResponsesCallIdWithNative(input) {
|
|
1115
|
+
const capability = 'normalizeResponsesCallIdJson';
|
|
1116
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
1117
|
+
if (isNativeDisabledByEnv()) {
|
|
1118
|
+
return fail('native disabled');
|
|
1119
|
+
}
|
|
1120
|
+
const fn = readNativeFunction(capability);
|
|
1121
|
+
if (!fn) {
|
|
1122
|
+
return fail();
|
|
1123
|
+
}
|
|
1124
|
+
const inputJson = safeStringify(input ?? {});
|
|
1125
|
+
if (!inputJson) {
|
|
1126
|
+
return fail('json stringify failed');
|
|
1127
|
+
}
|
|
1128
|
+
try {
|
|
1129
|
+
const raw = fn(inputJson);
|
|
1130
|
+
return typeof raw === 'string' && raw ? raw : fail('invalid payload');
|
|
1131
|
+
}
|
|
1132
|
+
catch (error) {
|
|
1133
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1134
|
+
return fail(reason);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
export function clampResponsesInputItemIdWithNative(rawValue) {
|
|
1138
|
+
const capability = 'clampResponsesInputItemIdJson';
|
|
1139
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
1140
|
+
if (isNativeDisabledByEnv()) {
|
|
1141
|
+
return fail('native disabled');
|
|
1142
|
+
}
|
|
1143
|
+
const fn = readNativeFunction(capability);
|
|
1144
|
+
if (!fn) {
|
|
1145
|
+
return fail();
|
|
1146
|
+
}
|
|
1147
|
+
const rawJson = safeStringify(rawValue ?? null);
|
|
1148
|
+
if (!rawJson) {
|
|
1149
|
+
return fail('json stringify failed');
|
|
1150
|
+
}
|
|
1151
|
+
try {
|
|
1152
|
+
const raw = fn(rawJson);
|
|
1153
|
+
if (typeof raw !== 'string' || !raw) {
|
|
1154
|
+
return fail('empty result');
|
|
1155
|
+
}
|
|
1156
|
+
const parsed = parseJson(raw);
|
|
1157
|
+
if (parsed === null) {
|
|
1158
|
+
return undefined;
|
|
1159
|
+
}
|
|
1160
|
+
return typeof parsed === 'string' ? parsed : fail('invalid payload');
|
|
1161
|
+
}
|
|
1162
|
+
catch (error) {
|
|
1163
|
+
const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
|
|
1164
|
+
return fail(reason);
|
|
1165
|
+
}
|
|
1166
|
+
}
|