@jsonstudio/llms 0.4.2
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 +265 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.js +11 -0
- package/dist/api/llmswitch-config.d.ts +15 -0
- package/dist/api/llmswitch-config.js +415 -0
- package/dist/api/llmswitch-types.d.ts +412 -0
- package/dist/api/llmswitch-types.js +60 -0
- package/dist/bridge/routecodex-adapter.d.ts +74 -0
- package/dist/bridge/routecodex-adapter.js +226 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +5 -0
- package/dist/config-unified/enhanced-path-resolver.d.ts +5 -0
- package/dist/config-unified/enhanced-path-resolver.js +38 -0
- package/dist/config-unified/unified-config.d.ts +26 -0
- package/dist/config-unified/unified-config.js +187 -0
- package/dist/conversion/codec-registry.d.ts +10 -0
- package/dist/conversion/codec-registry.js +25 -0
- package/dist/conversion/codecs/anthropic-openai-codec.d.ts +23 -0
- package/dist/conversion/codecs/anthropic-openai-codec.js +546 -0
- package/dist/conversion/codecs/gemini-openai-codec.d.ts +16 -0
- package/dist/conversion/codecs/gemini-openai-codec.js +437 -0
- package/dist/conversion/codecs/openai-openai-codec.d.ts +12 -0
- package/dist/conversion/codecs/openai-openai-codec.js +125 -0
- package/dist/conversion/codecs/responses-openai-codec.d.ts +12 -0
- package/dist/conversion/codecs/responses-openai-codec.js +154 -0
- package/dist/conversion/config/config-manager.d.ts +212 -0
- package/dist/conversion/config/config-manager.js +310 -0
- package/dist/conversion/conversion-v3/adapters/index.d.ts +2 -0
- package/dist/conversion/conversion-v3/adapters/index.js +1 -0
- package/dist/conversion/conversion-v3/adapters/v3-to-standard-adapter.d.ts +38 -0
- package/dist/conversion/conversion-v3/adapters/v3-to-standard-adapter.js +55 -0
- package/dist/conversion/conversion-v3/compatibility/compatibility-profiles.d.ts +22 -0
- package/dist/conversion/conversion-v3/compatibility/compatibility-profiles.js +84 -0
- package/dist/conversion/conversion-v3/compatibility/compatibility-stages.d.ts +4 -0
- package/dist/conversion/conversion-v3/compatibility/compatibility-stages.js +285 -0
- package/dist/conversion/conversion-v3/compatibility/index.d.ts +3 -0
- package/dist/conversion/conversion-v3/compatibility/index.js +2 -0
- package/dist/conversion/conversion-v3/config/default-configs.d.ts +48 -0
- package/dist/conversion/conversion-v3/config/default-configs.js +1083 -0
- package/dist/conversion/conversion-v3/config/index.d.ts +5 -0
- package/dist/conversion/conversion-v3/config/index.js +5 -0
- package/dist/conversion/conversion-v3/config/pipeline-config-manager.d.ts +49 -0
- package/dist/conversion/conversion-v3/config/pipeline-config-manager.js +65 -0
- package/dist/conversion/conversion-v3/index.d.ts +11 -0
- package/dist/conversion/conversion-v3/index.js +17 -0
- package/dist/conversion/conversion-v3/nodes/index.d.ts +56 -0
- package/dist/conversion/conversion-v3/nodes/index.js +149 -0
- package/dist/conversion/conversion-v3/nodes/input/anthropic-input-node.d.ts +25 -0
- package/dist/conversion/conversion-v3/nodes/input/anthropic-input-node.js +56 -0
- package/dist/conversion/conversion-v3/nodes/input/base-input-node.d.ts +75 -0
- package/dist/conversion/conversion-v3/nodes/input/base-input-node.js +237 -0
- package/dist/conversion/conversion-v3/nodes/input/chat-input-node.d.ts +25 -0
- package/dist/conversion/conversion-v3/nodes/input/chat-input-node.js +56 -0
- package/dist/conversion/conversion-v3/nodes/input/chat-shape-helpers.d.ts +4 -0
- package/dist/conversion/conversion-v3/nodes/input/chat-shape-helpers.js +197 -0
- package/dist/conversion/conversion-v3/nodes/input/gemini-input-node.d.ts +16 -0
- package/dist/conversion/conversion-v3/nodes/input/gemini-input-node.js +125 -0
- package/dist/conversion/conversion-v3/nodes/input/index.d.ts +8 -0
- package/dist/conversion/conversion-v3/nodes/input/index.js +8 -0
- package/dist/conversion/conversion-v3/nodes/input/input-decision.d.ts +46 -0
- package/dist/conversion/conversion-v3/nodes/input/input-decision.js +125 -0
- package/dist/conversion/conversion-v3/nodes/input/responses-input-node.d.ts +20 -0
- package/dist/conversion/conversion-v3/nodes/input/responses-input-node.js +51 -0
- package/dist/conversion/conversion-v3/nodes/output/anthropic-output-node.d.ts +71 -0
- package/dist/conversion/conversion-v3/nodes/output/anthropic-output-node.js +320 -0
- package/dist/conversion/conversion-v3/nodes/output/base-output-node.d.ts +116 -0
- package/dist/conversion/conversion-v3/nodes/output/base-output-node.js +512 -0
- package/dist/conversion/conversion-v3/nodes/output/index.d.ts +7 -0
- package/dist/conversion/conversion-v3/nodes/output/index.js +7 -0
- package/dist/conversion/conversion-v3/nodes/output/openai-output-node.d.ts +71 -0
- package/dist/conversion/conversion-v3/nodes/output/openai-output-node.js +293 -0
- package/dist/conversion/conversion-v3/nodes/output/output-decision.d.ts +68 -0
- package/dist/conversion/conversion-v3/nodes/output/output-decision.js +161 -0
- package/dist/conversion/conversion-v3/nodes/output/responses-output-node.d.ts +64 -0
- package/dist/conversion/conversion-v3/nodes/output/responses-output-node.js +323 -0
- package/dist/conversion/conversion-v3/nodes/process/base-process-node.d.ts +72 -0
- package/dist/conversion/conversion-v3/nodes/process/base-process-node.js +246 -0
- package/dist/conversion/conversion-v3/nodes/process/chat-process-node.d.ts +135 -0
- package/dist/conversion/conversion-v3/nodes/process/chat-process-node.js +854 -0
- package/dist/conversion/conversion-v3/nodes/process/compatibility-process-node.d.ts +29 -0
- package/dist/conversion/conversion-v3/nodes/process/compatibility-process-node.js +181 -0
- package/dist/conversion/conversion-v3/nodes/process/index.d.ts +10 -0
- package/dist/conversion/conversion-v3/nodes/process/index.js +10 -0
- package/dist/conversion/conversion-v3/nodes/process/passthrough-process-node.d.ts +59 -0
- package/dist/conversion/conversion-v3/nodes/process/passthrough-process-node.js +243 -0
- package/dist/conversion/conversion-v3/nodes/process/response-process-node.d.ts +17 -0
- package/dist/conversion/conversion-v3/nodes/process/response-process-node.js +213 -0
- package/dist/conversion/conversion-v3/nodes/process/tool-process-node.d.ts +26 -0
- package/dist/conversion/conversion-v3/nodes/process/tool-process-node.js +299 -0
- package/dist/conversion/conversion-v3/nodes/process/virtual-router-process-node.d.ts +40 -0
- package/dist/conversion/conversion-v3/nodes/process/virtual-router-process-node.js +430 -0
- package/dist/conversion/conversion-v3/nodes/response/anthropic-response-input-node.d.ts +12 -0
- package/dist/conversion/conversion-v3/nodes/response/anthropic-response-input-node.js +129 -0
- package/dist/conversion/conversion-v3/nodes/response/chat-to-responses-response-node.d.ts +15 -0
- package/dist/conversion/conversion-v3/nodes/response/chat-to-responses-response-node.js +57 -0
- package/dist/conversion/conversion-v3/nodes/response/index.d.ts +4 -0
- package/dist/conversion/conversion-v3/nodes/response/index.js +4 -0
- package/dist/conversion/conversion-v3/nodes/response/openai-response-input-node.d.ts +15 -0
- package/dist/conversion/conversion-v3/nodes/response/openai-response-input-node.js +87 -0
- package/dist/conversion/conversion-v3/nodes/response/response-utils.d.ts +1 -0
- package/dist/conversion/conversion-v3/nodes/response/response-utils.js +1 -0
- package/dist/conversion/conversion-v3/nodes/response/responses-response-input-node.d.ts +12 -0
- package/dist/conversion/conversion-v3/nodes/response/responses-response-input-node.js +67 -0
- package/dist/conversion/conversion-v3/nodes/sse/index.d.ts +3 -0
- package/dist/conversion/conversion-v3/nodes/sse/index.js +3 -0
- package/dist/conversion/conversion-v3/nodes/sse/sse-input-node.d.ts +27 -0
- package/dist/conversion/conversion-v3/nodes/sse/sse-input-node.js +165 -0
- package/dist/conversion/conversion-v3/nodes/sse/sse-output-node.d.ts +19 -0
- package/dist/conversion/conversion-v3/nodes/sse/sse-output-node.js +267 -0
- package/dist/conversion/conversion-v3/nodes/sse/sse-passthrough-node.d.ts +18 -0
- package/dist/conversion/conversion-v3/nodes/sse/sse-passthrough-node.js +48 -0
- package/dist/conversion/conversion-v3/pipelines/index.d.ts +6 -0
- package/dist/conversion/conversion-v3/pipelines/index.js +6 -0
- package/dist/conversion/conversion-v3/pipelines/super-pipeline.d.ts +112 -0
- package/dist/conversion/conversion-v3/pipelines/super-pipeline.js +566 -0
- package/dist/conversion/conversion-v3/response/provider-response-converter.d.ts +28 -0
- package/dist/conversion/conversion-v3/response/provider-response-converter.js +249 -0
- package/dist/conversion/conversion-v3/sse/index.d.ts +140 -0
- package/dist/conversion/conversion-v3/sse/index.js +115 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/anthropic-json-to-sse-converter.d.ts +11 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/anthropic-json-to-sse-converter.js +79 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/chat-json-to-sse-converter.d.ts +79 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/chat-json-to-sse-converter.js +296 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/chat.d.ts +55 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/chat.js +233 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/responses.d.ts +99 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/event-generators/responses.js +599 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/index.d.ts +6 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/index.js +7 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/responses-json-to-sse-converter.d.ts +79 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/responses-json-to-sse-converter.js +322 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/chat-sequencer.d.ts +37 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/chat-sequencer.js +218 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/responses-sequencer.d.ts +40 -0
- package/dist/conversion/conversion-v3/sse/json-to-sse/sequencers/responses-sequencer.js +263 -0
- package/dist/conversion/conversion-v3/sse/registry/sse-codec-registry.d.ts +32 -0
- package/dist/conversion/conversion-v3/sse/registry/sse-codec-registry.js +106 -0
- package/dist/conversion/conversion-v3/sse/shared/chat-serializer.d.ts +4 -0
- package/dist/conversion/conversion-v3/sse/shared/chat-serializer.js +40 -0
- package/dist/conversion/conversion-v3/sse/shared/constants.d.ts +272 -0
- package/dist/conversion/conversion-v3/sse/shared/constants.js +321 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/base-serializer.d.ts +158 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/base-serializer.js +210 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/chat-event-serializer.d.ts +82 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/chat-event-serializer.js +275 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/index.d.ts +39 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/index.js +54 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/responses-event-serializer.d.ts +123 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/responses-event-serializer.js +356 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/types.d.ts +51 -0
- package/dist/conversion/conversion-v3/sse/shared/serializers/types.js +4 -0
- package/dist/conversion/conversion-v3/sse/shared/utils.d.ts +254 -0
- package/dist/conversion/conversion-v3/sse/shared/utils.js +543 -0
- package/dist/conversion/conversion-v3/sse/shared/writer.d.ts +111 -0
- package/dist/conversion/conversion-v3/sse/shared/writer.js +268 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +13 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/anthropic-sse-to-json-converter.js +139 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/builders/response-builder.d.ts +165 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/builders/response-builder.js +776 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/chat-sse-to-json-converter.d.ts +106 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/chat-sse-to-json-converter.js +540 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/index.d.ts +6 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/index.js +7 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/parsers/sse-parser.d.ts +73 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/parsers/sse-parser.js +332 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/responses-sse-to-json-converter.d.ts +59 -0
- package/dist/conversion/conversion-v3/sse/sse-to-json/responses-sse-to-json-converter.js +270 -0
- package/dist/conversion/conversion-v3/sse/types/anthropic-types.d.ts +87 -0
- package/dist/conversion/conversion-v3/sse/types/anthropic-types.js +5 -0
- package/dist/conversion/conversion-v3/sse/types/chat-types.d.ts +308 -0
- package/dist/conversion/conversion-v3/sse/types/chat-types.js +32 -0
- package/dist/conversion/conversion-v3/sse/types/conversion-context.d.ts +211 -0
- package/dist/conversion/conversion-v3/sse/types/conversion-context.js +20 -0
- package/dist/conversion/conversion-v3/sse/types/core-interfaces.d.ts +90 -0
- package/dist/conversion/conversion-v3/sse/types/core-interfaces.js +5 -0
- package/dist/conversion/conversion-v3/sse/types/index.d.ts +14 -0
- package/dist/conversion/conversion-v3/sse/types/index.js +7 -0
- package/dist/conversion/conversion-v3/sse/types/responses-types.d.ts +328 -0
- package/dist/conversion/conversion-v3/sse/types/responses-types.js +38 -0
- package/dist/conversion/conversion-v3/sse/types/sse-events.d.ts +180 -0
- package/dist/conversion/conversion-v3/sse/types/sse-events.js +150 -0
- package/dist/conversion/conversion-v3/sse/types/stream-state.d.ts +204 -0
- package/dist/conversion/conversion-v3/sse/types/stream-state.js +44 -0
- package/dist/conversion/conversion-v3/sse/types/utility-types.d.ts +230 -0
- package/dist/conversion/conversion-v3/sse/types/utility-types.js +49 -0
- package/dist/conversion/conversion-v3/standards/context-adapter.d.ts +146 -0
- package/dist/conversion/conversion-v3/standards/context-adapter.js +438 -0
- package/dist/conversion/conversion-v3/standards/errors.d.ts +38 -0
- package/dist/conversion/conversion-v3/standards/errors.js +27 -0
- package/dist/conversion/conversion-v3/standards/index.d.ts +15 -0
- package/dist/conversion/conversion-v3/standards/index.js +11 -0
- package/dist/conversion/conversion-v3/standards/node-capabilities.d.ts +123 -0
- package/dist/conversion/conversion-v3/standards/node-capabilities.js +330 -0
- package/dist/conversion/conversion-v3/standards/pipeline-context.d.ts +237 -0
- package/dist/conversion/conversion-v3/standards/pipeline-context.js +84 -0
- package/dist/conversion/conversion-v3/standards/pipeline-node.d.ts +196 -0
- package/dist/conversion/conversion-v3/standards/pipeline-node.js +316 -0
- package/dist/conversion/conversion-v3/standards/snapshot-handles.d.ts +24 -0
- package/dist/conversion/conversion-v3/standards/snapshot-handles.js +49 -0
- package/dist/conversion/conversion-v3/types/config-types.d.ts +242 -0
- package/dist/conversion/conversion-v3/types/config-types.js +13 -0
- package/dist/conversion/conversion-v3/types/index.d.ts +8 -0
- package/dist/conversion/conversion-v3/types/index.js +11 -0
- package/dist/conversion/conversion-v3/types/node-types.d.ts +211 -0
- package/dist/conversion/conversion-v3/types/node-types.js +20 -0
- package/dist/conversion/conversion-v3/types/pipeline-types.d.ts +246 -0
- package/dist/conversion/conversion-v3/types/pipeline-types.js +26 -0
- package/dist/conversion/conversion-v3/types/request-types.d.ts +293 -0
- package/dist/conversion/conversion-v3/types/request-types.js +26 -0
- package/dist/conversion/conversion-v3/utils/provider-payload-sanitizer.d.ts +10 -0
- package/dist/conversion/conversion-v3/utils/provider-payload-sanitizer.js +103 -0
- package/dist/conversion/conversion-v3/validations/index.d.ts +8 -0
- package/dist/conversion/conversion-v3/validations/index.js +7 -0
- package/dist/conversion/conversion-v3/validations/node-graph-validator.d.ts +116 -0
- package/dist/conversion/conversion-v3/validations/node-graph-validator.js +505 -0
- package/dist/conversion/conversion-v3/validations/tool-governance-enforcer.d.ts +139 -0
- package/dist/conversion/conversion-v3/validations/tool-governance-enforcer.js +338 -0
- package/dist/conversion/hub/config/types.d.ts +26 -0
- package/dist/conversion/hub/config/types.js +1 -0
- package/dist/conversion/hub/core/detour-registry.d.ts +9 -0
- package/dist/conversion/hub/core/detour-registry.js +23 -0
- package/dist/conversion/hub/core/hub-context.d.ts +21 -0
- package/dist/conversion/hub/core/hub-context.js +1 -0
- package/dist/conversion/hub/core/index.d.ts +3 -0
- package/dist/conversion/hub/core/index.js +3 -0
- package/dist/conversion/hub/core/stage-driver.d.ts +30 -0
- package/dist/conversion/hub/core/stage-driver.js +31 -0
- package/dist/conversion/hub/format-adapters/anthropic-format-adapter.d.ts +16 -0
- package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +23 -0
- package/dist/conversion/hub/format-adapters/chat-format-adapter.d.ts +17 -0
- package/dist/conversion/hub/format-adapters/chat-format-adapter.js +23 -0
- package/dist/conversion/hub/format-adapters/gemini-format-adapter.d.ts +16 -0
- package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +23 -0
- package/dist/conversion/hub/format-adapters/index.d.ts +21 -0
- package/dist/conversion/hub/format-adapters/index.js +4 -0
- package/dist/conversion/hub/format-adapters/responses-format-adapter.d.ts +17 -0
- package/dist/conversion/hub/format-adapters/responses-format-adapter.js +23 -0
- package/dist/conversion/hub/hub-feature.d.ts +1 -0
- package/dist/conversion/hub/hub-feature.js +25 -0
- package/dist/conversion/hub/node-support.d.ts +19 -0
- package/dist/conversion/hub/node-support.js +115 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +68 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.js +421 -0
- package/dist/conversion/hub/pipelines/inbound.d.ts +22 -0
- package/dist/conversion/hub/pipelines/inbound.js +64 -0
- package/dist/conversion/hub/pipelines/outbound.d.ts +22 -0
- package/dist/conversion/hub/pipelines/outbound.js +57 -0
- package/dist/conversion/hub/process/chat-process.d.ts +13 -0
- package/dist/conversion/hub/process/chat-process.js +50 -0
- package/dist/conversion/hub/registry.d.ts +28 -0
- package/dist/conversion/hub/registry.js +98 -0
- package/dist/conversion/hub/response/chat-response-utils.d.ts +6 -0
- package/dist/conversion/hub/response/chat-response-utils.js +89 -0
- package/dist/conversion/hub/response/provider-response.d.ts +20 -0
- package/dist/conversion/hub/response/provider-response.js +196 -0
- package/dist/conversion/hub/response/response-mappers.d.ts +19 -0
- package/dist/conversion/hub/response/response-mappers.js +23 -0
- package/dist/conversion/hub/response/response-runtime.d.ts +3 -0
- package/dist/conversion/hub/response/response-runtime.js +206 -0
- package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +7 -0
- package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +308 -0
- package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +7 -0
- package/dist/conversion/hub/semantic-mappers/chat-mapper.js +304 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +7 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +477 -0
- package/dist/conversion/hub/semantic-mappers/index.d.ts +4 -0
- package/dist/conversion/hub/semantic-mappers/index.js +4 -0
- package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +21 -0
- package/dist/conversion/hub/semantic-mappers/responses-mapper.js +379 -0
- package/dist/conversion/hub/snapshot-recorder.d.ts +12 -0
- package/dist/conversion/hub/snapshot-recorder.js +69 -0
- package/dist/conversion/hub/standardized-bridge.d.ts +12 -0
- package/dist/conversion/hub/standardized-bridge.js +248 -0
- package/dist/conversion/hub/types/chat-envelope.d.ts +67 -0
- package/dist/conversion/hub/types/chat-envelope.js +1 -0
- package/dist/conversion/hub/types/chat-schema.d.ts +112 -0
- package/dist/conversion/hub/types/chat-schema.js +1 -0
- package/dist/conversion/hub/types/errors.d.ts +5 -0
- package/dist/conversion/hub/types/errors.js +13 -0
- package/dist/conversion/hub/types/format-envelope.d.ts +7 -0
- package/dist/conversion/hub/types/format-envelope.js +1 -0
- package/dist/conversion/hub/types/index.d.ts +6 -0
- package/dist/conversion/hub/types/index.js +6 -0
- package/dist/conversion/hub/types/json.d.ts +9 -0
- package/dist/conversion/hub/types/json.js +9 -0
- package/dist/conversion/hub/types/node.d.ts +31 -0
- package/dist/conversion/hub/types/node.js +1 -0
- package/dist/conversion/hub/types/standardized.d.ts +94 -0
- package/dist/conversion/hub/types/standardized.js +1 -0
- package/dist/conversion/index.d.ts +28 -0
- package/dist/conversion/index.js +28 -0
- package/dist/conversion/responses/responses-openai-bridge.d.ts +95 -0
- package/dist/conversion/responses/responses-openai-bridge.js +1330 -0
- package/dist/conversion/schema-validator.d.ts +7 -0
- package/dist/conversion/schema-validator.js +67 -0
- package/dist/conversion/shared/args-mapping.d.ts +18 -0
- package/dist/conversion/shared/args-mapping.js +213 -0
- package/dist/conversion/shared/chat-request-filters.d.ts +9 -0
- package/dist/conversion/shared/chat-request-filters.js +74 -0
- package/dist/conversion/shared/jsonish.d.ts +3 -0
- package/dist/conversion/shared/jsonish.js +177 -0
- package/dist/conversion/shared/mcp-injection.d.ts +2 -0
- package/dist/conversion/shared/mcp-injection.js +89 -0
- package/dist/conversion/shared/media.d.ts +1 -0
- package/dist/conversion/shared/media.js +9 -0
- package/dist/conversion/shared/openai-finalizer.d.ts +9 -0
- package/dist/conversion/shared/openai-finalizer.js +104 -0
- package/dist/conversion/shared/openai-message-normalize.d.ts +1 -0
- package/dist/conversion/shared/openai-message-normalize.js +442 -0
- package/dist/conversion/shared/payload-budget.d.ts +13 -0
- package/dist/conversion/shared/payload-budget.js +248 -0
- package/dist/conversion/shared/reasoning-mapping.d.ts +5 -0
- package/dist/conversion/shared/reasoning-mapping.js +8 -0
- package/dist/conversion/shared/responses-conversation-store.d.ts +41 -0
- package/dist/conversion/shared/responses-conversation-store.js +285 -0
- package/dist/conversion/shared/responses-id-utils.d.ts +7 -0
- package/dist/conversion/shared/responses-id-utils.js +29 -0
- package/dist/conversion/shared/responses-instructions.d.ts +1 -0
- package/dist/conversion/shared/responses-instructions.js +113 -0
- package/dist/conversion/shared/responses-metadata.d.ts +1 -0
- package/dist/conversion/shared/responses-metadata.js +1 -0
- package/dist/conversion/shared/responses-request-adapter.d.ts +66 -0
- package/dist/conversion/shared/responses-request-adapter.js +461 -0
- package/dist/conversion/shared/snapshot-hooks.d.ts +12 -0
- package/dist/conversion/shared/snapshot-hooks.js +7 -0
- package/dist/conversion/shared/streaming-text-extractor.d.ts +26 -0
- package/dist/conversion/shared/streaming-text-extractor.js +145 -0
- package/dist/conversion/shared/text-markup-normalizer.d.ts +9 -0
- package/dist/conversion/shared/text-markup-normalizer.js +319 -0
- package/dist/conversion/shared/tool-canonicalizer.d.ts +2 -0
- package/dist/conversion/shared/tool-canonicalizer.js +50 -0
- package/dist/conversion/shared/tool-filter-pipeline.d.ts +17 -0
- package/dist/conversion/shared/tool-filter-pipeline.js +79 -0
- package/dist/conversion/shared/tool-governor.d.ts +27 -0
- package/dist/conversion/shared/tool-governor.js +269 -0
- package/dist/conversion/shared/tool-harvester.d.ts +31 -0
- package/dist/conversion/shared/tool-harvester.js +321 -0
- package/dist/conversion/shared/tool-mapping.d.ts +10 -0
- package/dist/conversion/shared/tool-mapping.js +10 -0
- package/dist/conversion/shared/tooling.d.ts +26 -0
- package/dist/conversion/shared/tooling.js +143 -0
- package/dist/conversion/types.d.ts +33 -0
- package/dist/conversion/types.js +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +9 -0
- package/dist/core/llmswitch-engine-v2.d.ts +132 -0
- package/dist/core/llmswitch-engine-v2.js +649 -0
- package/dist/core/llmswitch-factory-v2.d.ts +123 -0
- package/dist/core/llmswitch-factory-v2.js +521 -0
- package/dist/endpoints/base-endpoint-handler.d.ts +128 -0
- package/dist/endpoints/base-endpoint-handler.js +545 -0
- package/dist/endpoints/chat-endpoint-handler.d.ts +115 -0
- package/dist/endpoints/chat-endpoint-handler.js +218 -0
- package/dist/endpoints/endpoint-router.d.ts +127 -0
- package/dist/endpoints/endpoint-router.js +438 -0
- package/dist/endpoints/index.d.ts +13 -0
- package/dist/endpoints/index.js +11 -0
- package/dist/endpoints/messages-endpoint-handler.d.ts +171 -0
- package/dist/endpoints/messages-endpoint-handler.js +238 -0
- package/dist/endpoints/responses-endpoint-handler.d.ts +147 -0
- package/dist/endpoints/responses-endpoint-handler.js +233 -0
- package/dist/filters/builtin/add-fields-filter.d.ts +8 -0
- package/dist/filters/builtin/add-fields-filter.js +16 -0
- package/dist/filters/builtin/blacklist-filter.d.ts +8 -0
- package/dist/filters/builtin/blacklist-filter.js +19 -0
- package/dist/filters/builtin/whitelist-filter.d.ts +8 -0
- package/dist/filters/builtin/whitelist-filter.js +19 -0
- package/dist/filters/engine.d.ts +16 -0
- package/dist/filters/engine.js +167 -0
- package/dist/filters/index.d.ts +19 -0
- package/dist/filters/index.js +24 -0
- package/dist/filters/special/request-streaming-to-nonstreaming.d.ts +12 -0
- package/dist/filters/special/request-streaming-to-nonstreaming.js +27 -0
- package/dist/filters/special/request-tool-choice-policy.d.ts +11 -0
- package/dist/filters/special/request-tool-choice-policy.js +27 -0
- package/dist/filters/special/request-tool-list-filter.d.ts +11 -0
- package/dist/filters/special/request-tool-list-filter.js +167 -0
- package/dist/filters/special/request-toolcalls-stringify.d.ts +10 -0
- package/dist/filters/special/request-toolcalls-stringify.js +44 -0
- package/dist/filters/special/request-tools-normalize.d.ts +12 -0
- package/dist/filters/special/request-tools-normalize.js +140 -0
- package/dist/filters/special/response-finish-invariants.d.ts +11 -0
- package/dist/filters/special/response-finish-invariants.js +30 -0
- package/dist/filters/special/response-openai-to-responses-bridge.d.ts +13 -0
- package/dist/filters/special/response-openai-to-responses-bridge.js +24 -0
- package/dist/filters/special/response-tool-arguments-blacklist.d.ts +12 -0
- package/dist/filters/special/response-tool-arguments-blacklist.js +63 -0
- package/dist/filters/special/response-tool-arguments-schema-converge.d.ts +13 -0
- package/dist/filters/special/response-tool-arguments-schema-converge.js +63 -0
- package/dist/filters/special/response-tool-arguments-stringify.d.ts +9 -0
- package/dist/filters/special/response-tool-arguments-stringify.js +134 -0
- package/dist/filters/special/response-tool-arguments-toon-decode.d.ts +10 -0
- package/dist/filters/special/response-tool-arguments-toon-decode.js +94 -0
- package/dist/filters/special/response-tool-arguments-whitelist.d.ts +11 -0
- package/dist/filters/special/response-tool-arguments-whitelist.js +56 -0
- package/dist/filters/special/response-tool-text-canonicalize.d.ts +10 -0
- package/dist/filters/special/response-tool-text-canonicalize.js +20 -0
- package/dist/filters/special/tool-filter-hooks.d.ts +19 -0
- package/dist/filters/special/tool-filter-hooks.js +341 -0
- package/dist/filters/special/tool-post-constraints.d.ts +31 -0
- package/dist/filters/special/tool-post-constraints.js +120 -0
- package/dist/filters/types.d.ts +68 -0
- package/dist/filters/types.js +3 -0
- package/dist/filters/utils/fieldmap-loader.d.ts +2 -0
- package/dist/filters/utils/fieldmap-loader.js +16 -0
- package/dist/filters/utils/snapshot-writer.d.ts +10 -0
- package/dist/filters/utils/snapshot-writer.js +47 -0
- package/dist/guidance/index.d.ts +3 -0
- package/dist/guidance/index.js +228 -0
- package/dist/hooks/hooks-integration.d.ts +161 -0
- package/dist/hooks/hooks-integration.js +519 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.js +13 -0
- package/dist/html-to-markdown.d.ts +5 -0
- package/dist/html-to-markdown.js +66 -0
- package/dist/http/sse-response.d.ts +22 -0
- package/dist/http/sse-response.js +103 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/router/virtual-router/bootstrap.d.ts +6 -0
- package/dist/router/virtual-router/bootstrap.js +620 -0
- package/dist/router/virtual-router/classifier.d.ts +10 -0
- package/dist/router/virtual-router/classifier.js +99 -0
- package/dist/router/virtual-router/engine.d.ts +35 -0
- package/dist/router/virtual-router/engine.js +260 -0
- package/dist/router/virtual-router/error-center.d.ts +10 -0
- package/dist/router/virtual-router/error-center.js +39 -0
- package/dist/router/virtual-router/features.d.ts +3 -0
- package/dist/router/virtual-router/features.js +162 -0
- package/dist/router/virtual-router/health-manager.d.ts +18 -0
- package/dist/router/virtual-router/health-manager.js +98 -0
- package/dist/router/virtual-router/load-balancer.d.ts +18 -0
- package/dist/router/virtual-router/load-balancer.js +67 -0
- package/dist/router/virtual-router/provider-registry.d.ts +11 -0
- package/dist/router/virtual-router/provider-registry.js +74 -0
- package/dist/router/virtual-router/types.d.ts +206 -0
- package/dist/router/virtual-router/types.js +31 -0
- package/dist/sse/index.d.ts +140 -0
- package/dist/sse/index.js +115 -0
- package/dist/sse/json-to-sse/anthropic-json-to-sse-converter.d.ts +11 -0
- package/dist/sse/json-to-sse/anthropic-json-to-sse-converter.js +79 -0
- package/dist/sse/json-to-sse/chat-json-to-sse-converter.d.ts +79 -0
- package/dist/sse/json-to-sse/chat-json-to-sse-converter.js +296 -0
- package/dist/sse/json-to-sse/event-generators/chat.d.ts +55 -0
- package/dist/sse/json-to-sse/event-generators/chat.js +233 -0
- package/dist/sse/json-to-sse/event-generators/responses.d.ts +99 -0
- package/dist/sse/json-to-sse/event-generators/responses.js +599 -0
- package/dist/sse/json-to-sse/index.d.ts +6 -0
- package/dist/sse/json-to-sse/index.js +7 -0
- package/dist/sse/json-to-sse/responses-json-to-sse-converter.d.ts +79 -0
- package/dist/sse/json-to-sse/responses-json-to-sse-converter.js +322 -0
- package/dist/sse/json-to-sse/sequencers/chat-sequencer.d.ts +37 -0
- package/dist/sse/json-to-sse/sequencers/chat-sequencer.js +218 -0
- package/dist/sse/json-to-sse/sequencers/responses-sequencer.d.ts +40 -0
- package/dist/sse/json-to-sse/sequencers/responses-sequencer.js +263 -0
- package/dist/sse/registry/sse-codec-registry.d.ts +32 -0
- package/dist/sse/registry/sse-codec-registry.js +106 -0
- package/dist/sse/shared/chat-serializer.d.ts +4 -0
- package/dist/sse/shared/chat-serializer.js +40 -0
- package/dist/sse/shared/constants.d.ts +272 -0
- package/dist/sse/shared/constants.js +321 -0
- package/dist/sse/shared/serializers/base-serializer.d.ts +158 -0
- package/dist/sse/shared/serializers/base-serializer.js +210 -0
- package/dist/sse/shared/serializers/chat-event-serializer.d.ts +82 -0
- package/dist/sse/shared/serializers/chat-event-serializer.js +275 -0
- package/dist/sse/shared/serializers/index.d.ts +39 -0
- package/dist/sse/shared/serializers/index.js +54 -0
- package/dist/sse/shared/serializers/responses-event-serializer.d.ts +123 -0
- package/dist/sse/shared/serializers/responses-event-serializer.js +356 -0
- package/dist/sse/shared/serializers/types.d.ts +51 -0
- package/dist/sse/shared/serializers/types.js +4 -0
- package/dist/sse/shared/utils.d.ts +254 -0
- package/dist/sse/shared/utils.js +543 -0
- package/dist/sse/shared/writer.d.ts +111 -0
- package/dist/sse/shared/writer.js +268 -0
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +13 -0
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.js +139 -0
- package/dist/sse/sse-to-json/builders/response-builder.d.ts +165 -0
- package/dist/sse/sse-to-json/builders/response-builder.js +776 -0
- package/dist/sse/sse-to-json/chat-sse-to-json-converter.d.ts +106 -0
- package/dist/sse/sse-to-json/chat-sse-to-json-converter.js +540 -0
- package/dist/sse/sse-to-json/index.d.ts +6 -0
- package/dist/sse/sse-to-json/index.js +7 -0
- package/dist/sse/sse-to-json/parsers/sse-parser.d.ts +73 -0
- package/dist/sse/sse-to-json/parsers/sse-parser.js +340 -0
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.d.ts +59 -0
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +270 -0
- package/dist/sse/types/anthropic-types.d.ts +87 -0
- package/dist/sse/types/anthropic-types.js +5 -0
- package/dist/sse/types/chat-types.d.ts +308 -0
- package/dist/sse/types/chat-types.js +32 -0
- package/dist/sse/types/conversion-context.d.ts +211 -0
- package/dist/sse/types/conversion-context.js +20 -0
- package/dist/sse/types/core-interfaces.d.ts +90 -0
- package/dist/sse/types/core-interfaces.js +5 -0
- package/dist/sse/types/index.d.ts +14 -0
- package/dist/sse/types/index.js +7 -0
- package/dist/sse/types/responses-types.d.ts +328 -0
- package/dist/sse/types/responses-types.js +38 -0
- package/dist/sse/types/sse-events.d.ts +180 -0
- package/dist/sse/types/sse-events.js +150 -0
- package/dist/sse/types/stream-state.d.ts +204 -0
- package/dist/sse/types/stream-state.js +44 -0
- package/dist/sse/types/utility-types.d.ts +230 -0
- package/dist/sse/types/utility-types.js +49 -0
- package/dist/tools/proxy/anthropic-tool-proxy.d.ts +19 -0
- package/dist/tools/proxy/anthropic-tool-proxy.js +57 -0
- package/dist/tools/proxy/executors/web-fetch.d.ts +6 -0
- package/dist/tools/proxy/executors/web-fetch.js +39 -0
- package/dist/tools/proxy/registry.d.ts +8 -0
- package/dist/tools/proxy/registry.js +14 -0
- package/dist/tools/proxy/types.d.ts +29 -0
- package/dist/tools/proxy/types.js +1 -0
- package/dist/tools/tool-registry.d.ts +8 -0
- package/dist/tools/tool-registry.js +154 -0
- package/dist/tools/web-fetch-html.d.ts +15 -0
- package/dist/tools/web-fetch-html.js +83 -0
- package/dist/utils/conversion-adapter.d.ts +65 -0
- package/dist/utils/conversion-adapter.js +183 -0
- package/dist/utils/error-factory.d.ts +88 -0
- package/dist/utils/error-factory.js +138 -0
- package/dist/utils/error-utils.d.ts +334 -0
- package/dist/utils/error-utils.js +782 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +13 -0
- package/dist/utils/performance-utils.d.ts +205 -0
- package/dist/utils/performance-utils.js +440 -0
- package/dist/utils/profile-mapper.d.ts +32 -0
- package/dist/utils/profile-mapper.js +269 -0
- package/dist/utils/request-processor.d.ts +52 -0
- package/dist/utils/request-processor.js +210 -0
- package/dist/utils/request-utils.d.ts +117 -0
- package/dist/utils/request-utils.js +333 -0
- package/dist/utils/response-utils.d.ts +127 -0
- package/dist/utils/response-utils.js +516 -0
- package/dist/utils/token-counter.d.ts +89 -0
- package/dist/utils/token-counter.js +541 -0
- package/package.json +65 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
function collectTextFromBlocks(blocks) {
|
|
2
|
+
const parts = [];
|
|
3
|
+
for (const block of blocks) {
|
|
4
|
+
if (!block || typeof block !== 'object')
|
|
5
|
+
continue;
|
|
6
|
+
const type = typeof block.type === 'string' ? block.type.toLowerCase() : '';
|
|
7
|
+
if ((type === 'input_text' || type === 'output_text' || type === 'text' || type === 'commentary') && typeof block.text === 'string') {
|
|
8
|
+
const text = block.text.trim();
|
|
9
|
+
if (text)
|
|
10
|
+
parts.push(text);
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (type === 'message' && Array.isArray(block.content)) {
|
|
14
|
+
const nested = collectTextFromBlocks(block.content);
|
|
15
|
+
if (nested)
|
|
16
|
+
parts.push(nested);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (typeof block.content === 'string') {
|
|
20
|
+
const text = block.content.trim();
|
|
21
|
+
if (text)
|
|
22
|
+
parts.push(text);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(block.content)) {
|
|
26
|
+
const nested = collectTextFromBlocks(block.content);
|
|
27
|
+
if (nested)
|
|
28
|
+
parts.push(nested);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (typeof block.text === 'string') {
|
|
32
|
+
const text = block.text.trim();
|
|
33
|
+
if (text)
|
|
34
|
+
parts.push(text);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return parts.join('\n');
|
|
38
|
+
}
|
|
39
|
+
function extractSystemInstruction(entry) {
|
|
40
|
+
if (!entry || typeof entry !== 'object')
|
|
41
|
+
return null;
|
|
42
|
+
const roleSource = entry.role ?? entry.message?.role;
|
|
43
|
+
const role = typeof roleSource === 'string' ? roleSource.toLowerCase() : '';
|
|
44
|
+
if (role !== 'system')
|
|
45
|
+
return null;
|
|
46
|
+
const collected = [];
|
|
47
|
+
if (Array.isArray(entry.content)) {
|
|
48
|
+
const text = collectTextFromBlocks(entry.content);
|
|
49
|
+
if (text.trim())
|
|
50
|
+
collected.push(text.trim());
|
|
51
|
+
}
|
|
52
|
+
else if (typeof entry.content === 'string') {
|
|
53
|
+
const text = entry.content.trim();
|
|
54
|
+
if (text)
|
|
55
|
+
collected.push(text);
|
|
56
|
+
}
|
|
57
|
+
if (typeof entry.text === 'string') {
|
|
58
|
+
const text = entry.text.trim();
|
|
59
|
+
if (text)
|
|
60
|
+
collected.push(text);
|
|
61
|
+
}
|
|
62
|
+
const message = entry.message;
|
|
63
|
+
if (message && typeof message === 'object') {
|
|
64
|
+
if (Array.isArray(message.content)) {
|
|
65
|
+
const text = collectTextFromBlocks(message.content);
|
|
66
|
+
if (text.trim())
|
|
67
|
+
collected.push(text.trim());
|
|
68
|
+
}
|
|
69
|
+
else if (typeof message.content === 'string') {
|
|
70
|
+
const text = message.content.trim();
|
|
71
|
+
if (text)
|
|
72
|
+
collected.push(text);
|
|
73
|
+
}
|
|
74
|
+
if (typeof message.text === 'string') {
|
|
75
|
+
const text = String(message.text).trim();
|
|
76
|
+
if (text)
|
|
77
|
+
collected.push(text);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const merged = collected.join('\n').trim();
|
|
81
|
+
return merged ? merged : null;
|
|
82
|
+
}
|
|
83
|
+
export function ensureResponsesInstructions(payload) {
|
|
84
|
+
let instructions = typeof payload.instructions === 'string' ? payload.instructions : '';
|
|
85
|
+
const hasClientInstruction = typeof payload.instructions === 'string' && payload.instructions.length > 0;
|
|
86
|
+
const input = Array.isArray(payload.input) ? payload.input : undefined;
|
|
87
|
+
if (input && input.length) {
|
|
88
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
89
|
+
const entry = input[i];
|
|
90
|
+
const roleSource = entry?.role ?? entry?.message?.role;
|
|
91
|
+
const role = typeof roleSource === 'string' ? roleSource.toLowerCase() : '';
|
|
92
|
+
if (role === 'system') {
|
|
93
|
+
const text = extractSystemInstruction(entry);
|
|
94
|
+
input.splice(i, 1);
|
|
95
|
+
i -= 1;
|
|
96
|
+
if (text && text.trim()) {
|
|
97
|
+
if (!hasClientInstruction && !instructions) {
|
|
98
|
+
instructions = text.trim();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (instructions) {
|
|
106
|
+
payload.instructions = instructions;
|
|
107
|
+
return instructions;
|
|
108
|
+
}
|
|
109
|
+
if (typeof payload.instructions !== 'undefined') {
|
|
110
|
+
delete payload.instructions;
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RESPONSES_RAW_SYSTEM_METADATA_KEY = "__rcc_raw_system";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const RESPONSES_RAW_SYSTEM_METADATA_KEY = '__rcc_raw_system';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type ResponsesContentPart = {
|
|
2
|
+
type: string;
|
|
3
|
+
text?: string;
|
|
4
|
+
content?: unknown;
|
|
5
|
+
};
|
|
6
|
+
export type ResponsesInputItem = {
|
|
7
|
+
type: string;
|
|
8
|
+
role?: string;
|
|
9
|
+
content?: Array<ResponsesContentPart> | null;
|
|
10
|
+
name?: string;
|
|
11
|
+
arguments?: unknown;
|
|
12
|
+
call_id?: string;
|
|
13
|
+
output?: unknown;
|
|
14
|
+
function?: {
|
|
15
|
+
name?: string;
|
|
16
|
+
arguments?: unknown;
|
|
17
|
+
};
|
|
18
|
+
message?: {
|
|
19
|
+
role?: string;
|
|
20
|
+
content?: Array<ResponsesContentPart>;
|
|
21
|
+
};
|
|
22
|
+
id?: string;
|
|
23
|
+
tool_call_id?: string;
|
|
24
|
+
tool_use_id?: string;
|
|
25
|
+
text?: string;
|
|
26
|
+
};
|
|
27
|
+
export type ResponsesToolDefinition = {
|
|
28
|
+
type: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
strict?: boolean;
|
|
32
|
+
parameters?: unknown;
|
|
33
|
+
function?: {
|
|
34
|
+
name?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
strict?: boolean;
|
|
37
|
+
parameters?: unknown;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export interface ResponsesRequestContext {
|
|
41
|
+
requestId?: string;
|
|
42
|
+
instructions?: string;
|
|
43
|
+
originalSystemMessages?: string[];
|
|
44
|
+
input?: ResponsesInputItem[];
|
|
45
|
+
include?: unknown;
|
|
46
|
+
store?: unknown;
|
|
47
|
+
toolChoice?: unknown;
|
|
48
|
+
parallelToolCalls?: boolean;
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
responseFormat?: unknown;
|
|
51
|
+
toolsRaw?: ResponsesToolDefinition[];
|
|
52
|
+
stream?: boolean;
|
|
53
|
+
instructionsIsRaw?: boolean;
|
|
54
|
+
isChatPayload?: boolean;
|
|
55
|
+
isResponsesPayload?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface BuildChatRequestResult {
|
|
58
|
+
request: Record<string, unknown>;
|
|
59
|
+
toolsNormalized?: Array<Record<string, unknown>>;
|
|
60
|
+
}
|
|
61
|
+
export declare function captureResponsesContext(payload: Record<string, unknown>, dto?: {
|
|
62
|
+
route?: {
|
|
63
|
+
requestId?: string;
|
|
64
|
+
};
|
|
65
|
+
}): ResponsesRequestContext;
|
|
66
|
+
export declare function buildChatRequestFromResponses(payload: Record<string, unknown>, context: ResponsesRequestContext): BuildChatRequestResult;
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { normalizeFunctionCallId, normalizeFunctionCallOutputId } from './responses-id-utils.js';
|
|
2
|
+
import { ensureResponsesInstructions } from './responses-instructions.js';
|
|
3
|
+
export function captureResponsesContext(payload, dto) {
|
|
4
|
+
ensureResponsesInstructions(payload);
|
|
5
|
+
const context = {
|
|
6
|
+
requestId: dto?.route?.requestId,
|
|
7
|
+
instructions: typeof payload.instructions === 'string' ? payload.instructions : undefined,
|
|
8
|
+
input: Array.isArray(payload.input) ? payload.input : undefined,
|
|
9
|
+
include: payload.include,
|
|
10
|
+
store: payload.store,
|
|
11
|
+
toolChoice: payload.tool_choice,
|
|
12
|
+
parallelToolCalls: typeof payload.parallel_tool_calls === 'boolean' ? payload.parallel_tool_calls : undefined,
|
|
13
|
+
metadata: (payload.metadata && typeof payload.metadata === 'object') ? { ...payload.metadata } : undefined,
|
|
14
|
+
responseFormat: payload.response_format,
|
|
15
|
+
stream: typeof payload.stream === 'boolean' ? payload.stream : undefined,
|
|
16
|
+
instructionsIsRaw: payload.instructions_is_raw === true,
|
|
17
|
+
isChatPayload: Array.isArray(payload.messages)
|
|
18
|
+
};
|
|
19
|
+
if (Array.isArray(payload.tools)) {
|
|
20
|
+
context.toolsRaw = payload.tools;
|
|
21
|
+
}
|
|
22
|
+
context.isResponsesPayload = !context.isChatPayload && Array.isArray(context.input);
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
25
|
+
export function buildChatRequestFromResponses(payload, context) {
|
|
26
|
+
const toolOutputs = Array.isArray(payload.tool_outputs)
|
|
27
|
+
? payload.tool_outputs
|
|
28
|
+
: undefined;
|
|
29
|
+
const responseId = typeof payload.response_id === 'string' ? payload.response_id : undefined;
|
|
30
|
+
const hasInput = Array.isArray(payload.input) && payload.input.length > 0;
|
|
31
|
+
const submitOnlyMode = !!toolOutputs && !!responseId && !hasInput;
|
|
32
|
+
if (submitOnlyMode) {
|
|
33
|
+
return {
|
|
34
|
+
request: {
|
|
35
|
+
type: 'submit_tool_outputs',
|
|
36
|
+
model: payload.model,
|
|
37
|
+
response_id: responseId,
|
|
38
|
+
tool_outputs: toolOutputs,
|
|
39
|
+
stream: payload.stream === true
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
let toolsNormalized = Array.isArray(payload.tools)
|
|
44
|
+
? normalizeTools(payload.tools)
|
|
45
|
+
: undefined;
|
|
46
|
+
// Inject MCP tools (CCR style) if enabled
|
|
47
|
+
try {
|
|
48
|
+
const enableMcp = String(process.env?.ROUTECODEX_MCP_ENABLE ?? '1') !== '0';
|
|
49
|
+
if (enableMcp) {
|
|
50
|
+
// Discover servers from prior inputs if present (best-effort; depends on client payload)
|
|
51
|
+
const discovered = new Set();
|
|
52
|
+
try {
|
|
53
|
+
const input = Array.isArray(payload.input) ? payload.input : [];
|
|
54
|
+
for (const it of input) {
|
|
55
|
+
const t = (it && typeof it === 'object') ? it : {};
|
|
56
|
+
const isToolCall = (t.type === 'function_call' || t.type === 'tool_call');
|
|
57
|
+
const isToolMsg = (t.type === 'tool_message' || t.type === 'tool_result');
|
|
58
|
+
if (isToolCall) {
|
|
59
|
+
const args = typeof t.arguments === 'string' ? (() => { try {
|
|
60
|
+
return JSON.parse(t.arguments);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return {};
|
|
64
|
+
} })() : (t.arguments || {});
|
|
65
|
+
const sv = (args && typeof args === 'object') ? args.server : undefined;
|
|
66
|
+
if (typeof sv === 'string' && sv.trim())
|
|
67
|
+
discovered.add(sv.trim());
|
|
68
|
+
}
|
|
69
|
+
else if (isToolMsg) {
|
|
70
|
+
const output = t?.output;
|
|
71
|
+
const val = (typeof output === 'string') ? (() => { try {
|
|
72
|
+
return JSON.parse(output);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
} })() : (output || null);
|
|
77
|
+
const args = (val && typeof val === 'object') ? val.arguments : undefined;
|
|
78
|
+
const sv = (args && typeof args === 'object') ? args.server : undefined;
|
|
79
|
+
if (typeof sv === 'string' && sv.trim())
|
|
80
|
+
discovered.add(sv.trim());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch { /* ignore */ }
|
|
85
|
+
const list = toolsNormalized && Array.isArray(toolsNormalized) ? toolsNormalized : [];
|
|
86
|
+
const have = new Set(list.map((t) => (t?.function?.name || '').toString()));
|
|
87
|
+
const addTool = (def) => { if (!have.has(def.function.name)) {
|
|
88
|
+
list.push(def);
|
|
89
|
+
have.add(def.function.name);
|
|
90
|
+
} };
|
|
91
|
+
const obj = (props, req) => ({ type: 'object', properties: props, required: req, additionalProperties: false });
|
|
92
|
+
const serversRaw = String(process.env?.ROUTECODEX_MCP_SERVERS || '').trim();
|
|
93
|
+
const envServers = serversRaw ? serversRaw.split(',').map((s) => s.trim()).filter(Boolean) : [];
|
|
94
|
+
const merged = Array.from(new Set([...envServers, ...Array.from(discovered)]));
|
|
95
|
+
const serverProp = merged.length ? { type: 'string', enum: merged } : { type: 'string' };
|
|
96
|
+
// 初始仅注入 list_mcp_resources;有已知 server 后再注入其余 MCP 工具
|
|
97
|
+
// 与 Chat 路径保持一致:server 可选(不强制要求)
|
|
98
|
+
addTool({ type: 'function', function: { name: 'list_mcp_resources', strict: true, description: 'List resources from a given MCP server (arguments.server = server label).', parameters: obj({ server: serverProp, filter: { type: 'string' }, root: { type: 'string' } }, [] /* server optional */) } });
|
|
99
|
+
if (merged.length > 0) {
|
|
100
|
+
addTool({ type: 'function', function: { name: 'read_mcp_resource', strict: true, description: 'Read a resource via MCP server.', parameters: obj({ server: serverProp, uri: { type: 'string' } }, ['server', 'uri']) } });
|
|
101
|
+
addTool({ type: 'function', function: { name: 'list_mcp_resource_templates', strict: true, description: 'List resource templates via MCP server.', parameters: obj({ server: serverProp }, ['server']) } });
|
|
102
|
+
}
|
|
103
|
+
toolsNormalized = list;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch { /* ignore MCP injection */ }
|
|
107
|
+
const mergedInput = mergeToolOutputsIntoInput(context.input, payload.tool_outputs);
|
|
108
|
+
let messages = mapResponsesInputToChat({
|
|
109
|
+
instructions: context.instructions,
|
|
110
|
+
input: mergedInput,
|
|
111
|
+
toolsNormalized
|
|
112
|
+
});
|
|
113
|
+
const preservedSystemMessages = Array.isArray(context.originalSystemMessages)
|
|
114
|
+
? context.originalSystemMessages
|
|
115
|
+
.map((text) => (typeof text === 'string' ? text.trim() : ''))
|
|
116
|
+
.filter((text) => text.length > 0)
|
|
117
|
+
.map((text) => ({ role: 'system', content: text }))
|
|
118
|
+
: undefined;
|
|
119
|
+
if (preservedSystemMessages && preservedSystemMessages.length) {
|
|
120
|
+
const nonSystemMessages = messages.filter((msg) => String(msg?.role || '').toLowerCase() !== 'system');
|
|
121
|
+
messages = [...preservedSystemMessages, ...nonSystemMessages];
|
|
122
|
+
}
|
|
123
|
+
const request = {
|
|
124
|
+
model: payload.model || 'gpt-4.1-mini',
|
|
125
|
+
messages
|
|
126
|
+
};
|
|
127
|
+
for (const key of ['temperature', 'top_p', 'max_tokens', 'tool_choice', 'parallel_tool_calls', 'user', 'logit_bias', 'seed', 'response_format']) {
|
|
128
|
+
if (payload[key] !== undefined) {
|
|
129
|
+
request[key] = payload[key];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(toolsNormalized) && toolsNormalized.length) {
|
|
133
|
+
request.tools = toolsNormalized;
|
|
134
|
+
}
|
|
135
|
+
if (typeof payload.stream === 'boolean') {
|
|
136
|
+
request.stream = payload.stream;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
request,
|
|
140
|
+
toolsNormalized
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function mergeToolOutputsIntoInput(input, toolOutputsRaw) {
|
|
144
|
+
const result = Array.isArray(input) ? [...input] : [];
|
|
145
|
+
if (!Array.isArray(toolOutputsRaw)) {
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
for (const entry of toolOutputsRaw) {
|
|
149
|
+
if (!entry || typeof entry !== 'object')
|
|
150
|
+
continue;
|
|
151
|
+
const data = entry;
|
|
152
|
+
const callIdRaw = data.tool_call_id ?? data.call_id ?? data.id;
|
|
153
|
+
if (typeof callIdRaw !== 'string' || !callIdRaw.trim())
|
|
154
|
+
continue;
|
|
155
|
+
const outputRaw = data.output;
|
|
156
|
+
const outputText = normalizeToolOutputPayload(outputRaw);
|
|
157
|
+
const normalizedCallId = normalizeFunctionCallId({ callId: callIdRaw, fallback: callIdRaw });
|
|
158
|
+
const outputId = normalizeFunctionCallOutputId({ callId: normalizedCallId, fallback: normalizedCallId });
|
|
159
|
+
result.push({
|
|
160
|
+
type: 'function_call_output',
|
|
161
|
+
id: outputId,
|
|
162
|
+
call_id: normalizedCallId,
|
|
163
|
+
output: outputText
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function normalizeToolOutputPayload(payload) {
|
|
169
|
+
if (typeof payload === 'string') {
|
|
170
|
+
return payload;
|
|
171
|
+
}
|
|
172
|
+
if (payload == null) {
|
|
173
|
+
return '';
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
return JSON.stringify(payload);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return String(payload);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function mapResponsesInputToChat(options) {
|
|
183
|
+
const { instructions, input, toolsNormalized } = options;
|
|
184
|
+
const messages = [];
|
|
185
|
+
if (typeof instructions === 'string' && instructions.length) {
|
|
186
|
+
messages.push({ role: 'system', content: instructions });
|
|
187
|
+
}
|
|
188
|
+
if (!Array.isArray(input))
|
|
189
|
+
return messages;
|
|
190
|
+
const toolNameById = new Map();
|
|
191
|
+
const toolCallIdAliases = new Map();
|
|
192
|
+
let lastToolCallId = null;
|
|
193
|
+
for (const entry of input) {
|
|
194
|
+
if (!entry || typeof entry !== 'object')
|
|
195
|
+
continue;
|
|
196
|
+
const entryType = typeof entry.type === 'string' ? entry.type.toLowerCase() : 'message';
|
|
197
|
+
if (typeof entry.content === 'string') {
|
|
198
|
+
const directText = (entry.content || '').toString().trim();
|
|
199
|
+
if (directText.length) {
|
|
200
|
+
const normalizedRole = normalizeResponseRole(entry.role || 'user');
|
|
201
|
+
messages.push({ role: normalizedRole, content: directText });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (entryType === 'function_call' || entryType === 'tool_call') {
|
|
206
|
+
const rawName = typeof entry.name === 'string' ? entry.name : (typeof entry?.function?.name === 'string' ? entry.function.name : undefined);
|
|
207
|
+
const name = (typeof rawName === 'string' && rawName.includes('.')) ? rawName.slice(rawName.indexOf('.') + 1).trim() : rawName;
|
|
208
|
+
if (typeof name !== 'string' || !name.trim() || name.toLowerCase() === 'tool') {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const args = entry.arguments ?? entry?.function?.arguments ?? {};
|
|
212
|
+
const parsedArgs = args;
|
|
213
|
+
const callIdRaw = typeof entry.id === 'string' ? entry.id : (typeof entry.call_id === 'string' ? entry.call_id : `call_${Math.random().toString(36).slice(2, 8)}`);
|
|
214
|
+
const callId = normalizeFunctionCallId({ callId: callIdRaw, fallback: `fc_call_${messages.length + 1}` });
|
|
215
|
+
if (callIdRaw && callIdRaw !== callId) {
|
|
216
|
+
toolCallIdAliases.set(callIdRaw, callId);
|
|
217
|
+
}
|
|
218
|
+
const serialized = normalizeArgumentsBySchema(parsedArgs, name, toolsNormalized).trim();
|
|
219
|
+
toolNameById.set(callId, name);
|
|
220
|
+
messages.push({ role: 'assistant', tool_calls: [{ id: callId, type: 'function', function: { name, arguments: serialized } }] });
|
|
221
|
+
lastToolCallId = callId;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (entryType === 'function_call_output' || entryType === 'tool_result' || entryType === 'tool_message') {
|
|
225
|
+
let toolCallId = entry.tool_call_id || entry.call_id || entry.tool_use_id || entry.id || lastToolCallId;
|
|
226
|
+
if (toolCallId && toolCallIdAliases.has(String(toolCallId))) {
|
|
227
|
+
toolCallId = toolCallIdAliases.get(String(toolCallId)) || toolCallId;
|
|
228
|
+
}
|
|
229
|
+
else if (typeof toolCallId === 'string' && toolCallId.trim().length) {
|
|
230
|
+
const normalized = normalizeFunctionCallId({ callId: toolCallId, fallback: toolCallId });
|
|
231
|
+
if (normalized !== toolCallId) {
|
|
232
|
+
toolCallIdAliases.set(toolCallId, normalized);
|
|
233
|
+
}
|
|
234
|
+
toolCallId = normalized;
|
|
235
|
+
}
|
|
236
|
+
const output = normalizeToolOutput(entry);
|
|
237
|
+
if (toolCallId) {
|
|
238
|
+
try {
|
|
239
|
+
let contentStr = output != null ? String(output) : '';
|
|
240
|
+
if (!contentStr || contentStr.trim().length === 0) {
|
|
241
|
+
contentStr = 'Command succeeded (no output).';
|
|
242
|
+
}
|
|
243
|
+
const nm = toolNameById.get(String(toolCallId));
|
|
244
|
+
const toolMsg = { role: 'tool', tool_call_id: String(toolCallId), content: contentStr };
|
|
245
|
+
if (typeof nm === 'string' && nm.trim().length)
|
|
246
|
+
toolMsg.name = nm;
|
|
247
|
+
messages.push(toolMsg);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
const fallback = (output ?? '');
|
|
251
|
+
const nm = toolNameById.get(String(toolCallId));
|
|
252
|
+
const toolMsg = { role: 'tool', tool_call_id: String(toolCallId), content: String(fallback) };
|
|
253
|
+
if (typeof nm === 'string' && nm.trim().length)
|
|
254
|
+
toolMsg.name = nm;
|
|
255
|
+
messages.push(toolMsg);
|
|
256
|
+
}
|
|
257
|
+
lastToolCallId = null;
|
|
258
|
+
}
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
let handledViaExplicitMessage = false;
|
|
262
|
+
if (entry && typeof entry.message === 'object' && Array.isArray(entry.message?.content)) {
|
|
263
|
+
const explicit = entry.message;
|
|
264
|
+
const { text, toolCalls, toolMessages, lastCallId } = processMessageBlocks(Array.isArray(explicit.content) ? explicit.content : [], toolsNormalized, toolNameById, toolCallIdAliases, lastToolCallId);
|
|
265
|
+
if (toolCalls.length)
|
|
266
|
+
messages.push({ role: 'assistant', tool_calls: toolCalls });
|
|
267
|
+
for (const msg of toolMessages)
|
|
268
|
+
messages.push(msg);
|
|
269
|
+
const normalizedRole = normalizeResponseRole((explicit.role ?? entry.role) || 'user');
|
|
270
|
+
if (typeof text === 'string' && text.trim().length) {
|
|
271
|
+
messages.push({ role: normalizedRole, content: text.trim() });
|
|
272
|
+
}
|
|
273
|
+
lastToolCallId = lastCallId;
|
|
274
|
+
handledViaExplicitMessage = true;
|
|
275
|
+
}
|
|
276
|
+
if (!handledViaExplicitMessage) {
|
|
277
|
+
const { text, toolCalls, toolMessages, lastCallId } = processMessageBlocks(Array.isArray(entry.content) ? entry.content : [], toolsNormalized, toolNameById, toolCallIdAliases, lastToolCallId);
|
|
278
|
+
if (toolCalls.length)
|
|
279
|
+
messages.push({ role: 'assistant', tool_calls: toolCalls });
|
|
280
|
+
for (const msg of toolMessages)
|
|
281
|
+
messages.push(msg);
|
|
282
|
+
const normalizedRole = normalizeResponseRole(entry.role || 'user');
|
|
283
|
+
if (typeof text === 'string' && text.trim().length) {
|
|
284
|
+
messages.push({ role: normalizedRole, content: text.trim() });
|
|
285
|
+
}
|
|
286
|
+
lastToolCallId = lastCallId;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
const t = String(entry.type || '').toLowerCase();
|
|
290
|
+
if ((t === 'input_text' || t === 'text' || t === 'output_text' || t === 'commentary') && typeof entry.text === 'string') {
|
|
291
|
+
const normalizedRole = normalizeResponseRole(entry.role || 'user');
|
|
292
|
+
const s = entry.text;
|
|
293
|
+
if (s && s.length)
|
|
294
|
+
messages.push({ role: normalizedRole, content: s });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch { /* ignore */ }
|
|
298
|
+
}
|
|
299
|
+
return messages;
|
|
300
|
+
}
|
|
301
|
+
function processMessageBlocks(blocks, toolsNormalized, toolNameById, toolCallIdAliases, lastToolCallId) {
|
|
302
|
+
const textParts = [];
|
|
303
|
+
const toolCalls = [];
|
|
304
|
+
const toolMessages = [];
|
|
305
|
+
let currentLastCall = lastToolCallId;
|
|
306
|
+
for (const block of blocks) {
|
|
307
|
+
if (!block || typeof block !== 'object')
|
|
308
|
+
continue;
|
|
309
|
+
const type = typeof block.type === 'string' ? block.type.toLowerCase() : '';
|
|
310
|
+
if (type === 'input_text' || type === 'output_text' || type === 'text' || type === 'commentary') {
|
|
311
|
+
if (typeof block.text === 'string')
|
|
312
|
+
textParts.push(block.text);
|
|
313
|
+
else if (typeof block.content === 'string')
|
|
314
|
+
textParts.push(block.content);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (type === 'message' && Array.isArray(block.content)) {
|
|
318
|
+
const nested = processMessageBlocks(block.content, toolsNormalized, toolNameById, toolCallIdAliases, currentLastCall);
|
|
319
|
+
if (nested.text)
|
|
320
|
+
textParts.push(nested.text);
|
|
321
|
+
for (const tc of nested.toolCalls)
|
|
322
|
+
toolCalls.push(tc);
|
|
323
|
+
for (const tm of nested.toolMessages)
|
|
324
|
+
toolMessages.push(tm);
|
|
325
|
+
currentLastCall = nested.lastCallId;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (type === 'function_call') {
|
|
329
|
+
const rawName = typeof block.name === 'string' ? block.name : (typeof block?.function?.name === 'string' ? block.function.name : undefined);
|
|
330
|
+
const name = (typeof rawName === 'string' && rawName.includes('.')) ? rawName.slice(rawName.indexOf('.') + 1).trim() : rawName;
|
|
331
|
+
const args = block.arguments ?? block?.function?.arguments ?? {};
|
|
332
|
+
const parsedArgs = args;
|
|
333
|
+
const callIdRaw = typeof block.id === 'string' ? block.id : (typeof block.call_id === 'string' ? block.call_id : `call_${Math.random().toString(36).slice(2, 8)}`);
|
|
334
|
+
const callId = normalizeFunctionCallId({ callId: callIdRaw, fallback: `fc_call_${toolCalls.length + 1}` });
|
|
335
|
+
if (callIdRaw && callIdRaw !== callId) {
|
|
336
|
+
toolCallIdAliases.set(callIdRaw, callId);
|
|
337
|
+
}
|
|
338
|
+
if (typeof name !== 'string' || !name.trim()) {
|
|
339
|
+
currentLastCall = null;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const serialized = normalizeArgumentsBySchema(parsedArgs, name, toolsNormalized).trim();
|
|
343
|
+
toolNameById.set(callId, name);
|
|
344
|
+
toolCalls.push({ id: callId, type: 'function', function: { name, arguments: serialized } });
|
|
345
|
+
currentLastCall = callId;
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (type === 'function_call_output' || type === 'tool_result' || type === 'tool_message') {
|
|
349
|
+
let toolCallId = block.tool_call_id || block.call_id || block.tool_use_id || block.id || currentLastCall;
|
|
350
|
+
if (toolCallId && toolCallIdAliases.has(String(toolCallId))) {
|
|
351
|
+
toolCallId = toolCallIdAliases.get(String(toolCallId)) || toolCallId;
|
|
352
|
+
}
|
|
353
|
+
else if (typeof toolCallId === 'string' && toolCallId.trim().length) {
|
|
354
|
+
const normalized = normalizeFunctionCallId({ callId: toolCallId, fallback: toolCallId });
|
|
355
|
+
if (normalized !== toolCallId) {
|
|
356
|
+
toolCallIdAliases.set(toolCallId, normalized);
|
|
357
|
+
}
|
|
358
|
+
toolCallId = normalized;
|
|
359
|
+
}
|
|
360
|
+
const output = normalizeToolOutput(block);
|
|
361
|
+
if (toolCallId) {
|
|
362
|
+
try {
|
|
363
|
+
let contentStr = output != null ? String(output) : '';
|
|
364
|
+
if (!contentStr || contentStr.trim().length === 0) {
|
|
365
|
+
contentStr = 'Command succeeded (no output).';
|
|
366
|
+
}
|
|
367
|
+
const nm = toolNameById.get(String(toolCallId));
|
|
368
|
+
const toolMsg = { role: 'tool', tool_call_id: String(toolCallId), content: contentStr };
|
|
369
|
+
if (typeof nm === 'string' && nm.trim().length)
|
|
370
|
+
toolMsg.name = nm;
|
|
371
|
+
toolMessages.push(toolMsg);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
const fallback = (output ?? '');
|
|
375
|
+
const nm = toolNameById.get(String(toolCallId));
|
|
376
|
+
const toolMsg = { role: 'tool', tool_call_id: String(toolCallId), content: String(fallback) };
|
|
377
|
+
if (typeof nm === 'string' && nm.trim().length)
|
|
378
|
+
toolMsg.name = nm;
|
|
379
|
+
toolMessages.push(toolMsg);
|
|
380
|
+
}
|
|
381
|
+
currentLastCall = null;
|
|
382
|
+
}
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
text: textParts.length ? textParts.join('\n') : null,
|
|
388
|
+
toolCalls,
|
|
389
|
+
toolMessages,
|
|
390
|
+
lastCallId: currentLastCall
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function normalizeResponseRole(role) {
|
|
394
|
+
if (typeof role === 'string') {
|
|
395
|
+
const normalized = role.toLowerCase();
|
|
396
|
+
if (normalized === 'system' || normalized === 'assistant' || normalized === 'user' || normalized === 'tool')
|
|
397
|
+
return normalized;
|
|
398
|
+
}
|
|
399
|
+
return 'user';
|
|
400
|
+
}
|
|
401
|
+
function normalizeArgumentsBySchema(argsStringOrObj, _functionName, _tools) {
|
|
402
|
+
if (typeof argsStringOrObj === 'string')
|
|
403
|
+
return argsStringOrObj;
|
|
404
|
+
try {
|
|
405
|
+
return JSON.stringify(argsStringOrObj ?? {});
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
return String(argsStringOrObj);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function normalizeToolOutput(entry) {
|
|
412
|
+
const out = entry?.output;
|
|
413
|
+
if (typeof out === 'string')
|
|
414
|
+
return out;
|
|
415
|
+
if (out && typeof out === 'object') {
|
|
416
|
+
try {
|
|
417
|
+
return JSON.stringify(out);
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
return String(out);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
function normalizeTools(tools) {
|
|
426
|
+
const normalized = [];
|
|
427
|
+
for (const tool of tools) {
|
|
428
|
+
if (!tool || typeof tool !== 'object')
|
|
429
|
+
continue;
|
|
430
|
+
const originalType = typeof tool.type === 'string' ? tool.type : 'function';
|
|
431
|
+
const mappedType = ['function', 'custom'].includes(originalType.toLowerCase())
|
|
432
|
+
? 'function'
|
|
433
|
+
: originalType;
|
|
434
|
+
const fn = (tool.function && typeof tool.function === 'object')
|
|
435
|
+
? tool.function
|
|
436
|
+
: {};
|
|
437
|
+
const topName = typeof tool.name === 'string' ? tool.name : undefined;
|
|
438
|
+
const fnName = typeof fn.name === 'string' ? fn.name : undefined;
|
|
439
|
+
const name = (fnName || topName || '').trim();
|
|
440
|
+
if (!name)
|
|
441
|
+
continue;
|
|
442
|
+
const topDesc = typeof tool.description === 'string' ? tool.description : undefined;
|
|
443
|
+
const fnDesc = typeof fn.description === 'string' ? fn.description : undefined;
|
|
444
|
+
const description = fnDesc || topDesc;
|
|
445
|
+
const fnParams = Object.prototype.hasOwnProperty.call(fn, 'parameters') ? fn.parameters : undefined;
|
|
446
|
+
const topParams = Object.prototype.hasOwnProperty.call(tool, 'parameters') ? tool.parameters : undefined;
|
|
447
|
+
const parameters = fnParams !== undefined ? fnParams : topParams;
|
|
448
|
+
const strict = typeof fn.strict === 'boolean' ? fn.strict :
|
|
449
|
+
typeof tool.strict === 'boolean' ? tool.strict :
|
|
450
|
+
undefined;
|
|
451
|
+
const fnOut = { name };
|
|
452
|
+
if (description)
|
|
453
|
+
fnOut.description = description;
|
|
454
|
+
if (parameters !== undefined)
|
|
455
|
+
fnOut.parameters = parameters;
|
|
456
|
+
if (strict !== undefined)
|
|
457
|
+
fnOut.strict = strict;
|
|
458
|
+
normalized.push({ type: mappedType, function: fnOut });
|
|
459
|
+
}
|
|
460
|
+
return normalized;
|
|
461
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SnapshotHookOptions {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
stage: string;
|
|
4
|
+
requestId: string;
|
|
5
|
+
data: unknown;
|
|
6
|
+
verbosity?: 'minimal' | 'verbose';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Hub pipeline no longer exposes the legacy hooks runtime.
|
|
10
|
+
* Keep a tiny shim so existing callers can continue awaiting the same API surface.
|
|
11
|
+
*/
|
|
12
|
+
export declare function writeSnapshotViaHooks(_options: SnapshotHookOptions): Promise<void>;
|