@mastra/core 1.2.1-alpha.0 → 1.3.0-alpha.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/CHANGELOG.md +341 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +2093 -262
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +12 -3
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/message-list.d.ts.map +1 -1
- package/dist/agent/types.d.ts +6 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +3 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/base.cjs +2 -2
- package/dist/base.d.ts +13 -1
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/cache/index.cjs +3 -3
- package/dist/cache/index.js +1 -1
- package/dist/{chunk-ENCTSDWC.js → chunk-2GWTJFVM.js} +2410 -1402
- package/dist/chunk-2GWTJFVM.js.map +1 -0
- package/dist/{chunk-OB4V67IX.cjs → chunk-2K5PNW2U.cjs} +4 -4
- package/dist/{chunk-OB4V67IX.cjs.map → chunk-2K5PNW2U.cjs.map} +1 -1
- package/dist/{chunk-VZXYBFCX.cjs → chunk-2P6DD7M5.cjs} +10 -10
- package/dist/{chunk-VZXYBFCX.cjs.map → chunk-2P6DD7M5.cjs.map} +1 -1
- package/dist/{chunk-Q2D7LERO.cjs → chunk-2VD5OGOT.cjs} +4 -4
- package/dist/{chunk-Q2D7LERO.cjs.map → chunk-2VD5OGOT.cjs.map} +1 -1
- package/dist/{chunk-2DMSFLJY.cjs → chunk-6TZKQI4R.cjs} +8 -8
- package/dist/chunk-6TZKQI4R.cjs.map +1 -0
- package/dist/{chunk-4NG7CKEG.js → chunk-6VGCVSP4.js} +3 -3
- package/dist/{chunk-4NG7CKEG.js.map → chunk-6VGCVSP4.js.map} +1 -1
- package/dist/{chunk-IIZF4W7B.cjs → chunk-7UWHFWST.cjs} +52 -5
- package/dist/chunk-7UWHFWST.cjs.map +1 -0
- package/dist/{chunk-VW7YQWDW.cjs → chunk-BFIOQFGF.cjs} +28 -2
- package/dist/chunk-BFIOQFGF.cjs.map +1 -0
- package/dist/{chunk-E3VFKTIA.js → chunk-BXLLXTT4.js} +2245 -179
- package/dist/chunk-BXLLXTT4.js.map +1 -0
- package/dist/{chunk-HMCXNOF6.cjs → chunk-CGPH7CMG.cjs} +2431 -1417
- package/dist/chunk-CGPH7CMG.cjs.map +1 -0
- package/dist/{chunk-GVLPTDJA.cjs → chunk-D5JZT6EK.cjs} +236 -63
- package/dist/chunk-D5JZT6EK.cjs.map +1 -0
- package/dist/{chunk-5SOS47PH.cjs → chunk-FLHFB23E.cjs} +454 -222
- package/dist/chunk-FLHFB23E.cjs.map +1 -0
- package/dist/{chunk-XCPEEIHI.cjs → chunk-GCTAD6B7.cjs} +3012 -927
- package/dist/chunk-GCTAD6B7.cjs.map +1 -0
- package/dist/{chunk-W3AQUG66.js → chunk-GIY5BINT.js} +4 -4
- package/dist/{chunk-W3AQUG66.js.map → chunk-GIY5BINT.js.map} +1 -1
- package/dist/{chunk-M6VFJX5A.js → chunk-GMSAGYTB.js} +3 -3
- package/dist/{chunk-M6VFJX5A.js.map → chunk-GMSAGYTB.js.map} +1 -1
- package/dist/{chunk-JRJJ5VQE.cjs → chunk-GZD6443M.cjs} +99 -55
- package/dist/chunk-GZD6443M.cjs.map +1 -0
- package/dist/{chunk-Z6NRYYOH.js → chunk-ILQXPZCD.js} +9 -4
- package/dist/chunk-ILQXPZCD.js.map +1 -0
- package/dist/{chunk-5YVR7B4R.js → chunk-JQNREL64.js} +29 -9
- package/dist/chunk-JQNREL64.js.map +1 -0
- package/dist/{chunk-QOFI2WBM.cjs → chunk-JU6K7UDX.cjs} +991 -229
- package/dist/chunk-JU6K7UDX.cjs.map +1 -0
- package/dist/{chunk-HN2MSTR6.cjs → chunk-KAJNBNWP.cjs} +283 -38
- package/dist/chunk-KAJNBNWP.cjs.map +1 -0
- package/dist/{chunk-MSWXEOZC.js → chunk-KL2JPSRX.js} +5 -5
- package/dist/chunk-KL2JPSRX.js.map +1 -0
- package/dist/{chunk-MQB7XFXP.js → chunk-LHRHOPUC.js} +3 -3
- package/dist/{chunk-MQB7XFXP.js.map → chunk-LHRHOPUC.js.map} +1 -1
- package/dist/{chunk-VX7UA3SO.js → chunk-MOOJ3H3C.js} +974 -217
- package/dist/chunk-MOOJ3H3C.js.map +1 -0
- package/dist/{chunk-HU2ONA2W.cjs → chunk-ON2KVIUJ.cjs} +17 -17
- package/dist/{chunk-HU2ONA2W.cjs.map → chunk-ON2KVIUJ.cjs.map} +1 -1
- package/dist/{chunk-I66TMZJ3.cjs → chunk-OOCEAC6U.cjs} +21 -18
- package/dist/chunk-OOCEAC6U.cjs.map +1 -0
- package/dist/{chunk-MNWW2R3U.js → chunk-OV7OOUUR.js} +90 -54
- package/dist/chunk-OV7OOUUR.js.map +1 -0
- package/dist/{chunk-C4WWWQHT.cjs → chunk-RO47SMI7.cjs} +23 -3
- package/dist/chunk-RO47SMI7.cjs.map +1 -0
- package/dist/{chunk-6FG6FU5Y.cjs → chunk-RQ56ZSIR.cjs} +4 -4
- package/dist/{chunk-6FG6FU5Y.cjs.map → chunk-RQ56ZSIR.cjs.map} +1 -1
- package/dist/{chunk-IW3BNL7A.js → chunk-RS6CZXGA.js} +50 -3
- package/dist/chunk-RS6CZXGA.js.map +1 -0
- package/dist/{chunk-AIJLACR2.js → chunk-S53FKKVL.js} +27 -3
- package/dist/chunk-S53FKKVL.js.map +1 -0
- package/dist/{chunk-G6E3QNJC.js → chunk-SBPPGJL6.js} +4078 -4333
- package/dist/chunk-SBPPGJL6.js.map +1 -0
- package/dist/{chunk-UZL4H5P2.cjs → chunk-SH4PCZ3X.cjs} +5375 -5648
- package/dist/chunk-SH4PCZ3X.cjs.map +1 -0
- package/dist/{chunk-ZWM2CAIM.js → chunk-STKNQDVA.js} +4 -4
- package/dist/{chunk-ZWM2CAIM.js.map → chunk-STKNQDVA.js.map} +1 -1
- package/dist/{chunk-A5QFWX67.cjs → chunk-U2CABSMC.cjs} +79 -59
- package/dist/chunk-U2CABSMC.cjs.map +1 -0
- package/dist/{chunk-7MDVYPWX.cjs → chunk-UE2G2LRP.cjs} +9 -4
- package/dist/chunk-UE2G2LRP.cjs.map +1 -0
- package/dist/{chunk-AUF6U2BL.js → chunk-VM25PDSW.js} +5 -5
- package/dist/{chunk-AUF6U2BL.js.map → chunk-VM25PDSW.js.map} +1 -1
- package/dist/{chunk-RXD5EGQF.js → chunk-VVD56FI4.js} +228 -55
- package/dist/chunk-VVD56FI4.js.map +1 -0
- package/dist/{chunk-JIT2OY3X.js → chunk-WCAFTXGK.js} +23 -3
- package/dist/chunk-WCAFTXGK.js.map +1 -0
- package/dist/{chunk-P62OJXQ4.js → chunk-WL3AW3YA.js} +282 -37
- package/dist/chunk-WL3AW3YA.js.map +1 -0
- package/dist/{chunk-YLODOPYM.cjs → chunk-XDD5V446.cjs} +4163 -5352
- package/dist/chunk-XDD5V446.cjs.map +1 -0
- package/dist/{chunk-B4M33FCS.cjs → chunk-XQVYEOI7.cjs} +7 -7
- package/dist/{chunk-B4M33FCS.cjs.map → chunk-XQVYEOI7.cjs.map} +1 -1
- package/dist/{chunk-BP2TSCBW.js → chunk-ZATLLPIH.js} +4391 -5561
- package/dist/chunk-ZATLLPIH.js.map +1 -0
- package/dist/{chunk-T6PRRKMW.js → chunk-ZHFM7HCQ.js} +9 -6
- package/dist/chunk-ZHFM7HCQ.js.map +1 -0
- package/dist/{chunk-WFUNLRQX.js → chunk-ZRUTE56J.js} +366 -134
- package/dist/chunk-ZRUTE56J.js.map +1 -0
- package/dist/deployer/index.cjs +2 -2
- package/dist/deployer/index.js +1 -1
- package/dist/docs/SKILL.md +2 -9
- package/dist/docs/assets/SOURCE_MAP.json +399 -342
- package/dist/docs/references/docs-agents-agent-memory.md +45 -1
- package/dist/docs/references/docs-agents-network-approval.md +1 -1
- package/dist/docs/references/docs-agents-networks.md +3 -3
- package/dist/docs/references/docs-agents-overview.md +8 -0
- package/dist/docs/references/docs-agents-using-tools.md +82 -72
- package/dist/docs/references/docs-memory-observational-memory.md +11 -8
- package/dist/docs/references/docs-observability-overview.md +1 -1
- package/dist/docs/references/docs-observability-tracing-exporters-langsmith.md +70 -0
- package/dist/docs/references/docs-observability-tracing-overview.md +1 -1
- package/dist/docs/references/docs-server-middleware.md +0 -2
- package/dist/docs/references/docs-server-request-context.md +17 -0
- package/dist/docs/references/docs-workflows-agents-and-tools.md +2 -2
- package/dist/docs/references/docs-workflows-overview.md +1 -1
- package/dist/docs/references/docs-workspace-filesystem.md +2 -0
- package/dist/docs/references/docs-workspace-overview.md +3 -1
- package/dist/docs/references/docs-workspace-sandbox.md +2 -0
- package/dist/docs/references/docs-workspace-search.md +2 -0
- package/dist/docs/references/docs-workspace-skills.md +3 -1
- package/dist/docs/references/reference-agents-getTools.md +1 -6
- package/dist/docs/references/reference-agents-listAgents.md +1 -1
- package/dist/docs/references/reference-agents-network.md +0 -2
- package/dist/docs/references/reference-cli-mastra.md +29 -4
- package/dist/docs/references/reference-client-js-agents.md +1 -1
- package/dist/docs/references/reference-configuration.md +1 -1
- package/dist/docs/references/reference-core-getStoredAgentById.md +2 -2
- package/dist/docs/references/reference-core-listStoredAgents.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +2 -0
- package/dist/docs/references/reference-tools-mcp-client.md +0 -2
- package/dist/docs/references/reference-workflows-step.md +2 -0
- package/dist/docs/references/reference-workflows-workflow-methods-map.md +2 -2
- package/dist/docs/references/reference-workspace-filesystem.md +2 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +2 -0
- package/dist/docs/references/reference-workspace-local-sandbox.md +2 -0
- package/dist/docs/references/reference-workspace-sandbox.md +2 -0
- package/dist/docs/references/reference-workspace-workspace-class.md +2 -0
- package/dist/docs/references/reference.md +7 -2
- package/dist/editor/index.d.ts +1 -1
- package/dist/editor/index.d.ts.map +1 -1
- package/dist/editor/types.d.ts +53 -48
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/evals/base.d.ts +15 -0
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/run/index.d.ts +3 -3
- package/dist/evals/run/index.d.ts.map +1 -1
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/features/index.cjs +1 -1
- package/dist/features/index.cjs.map +1 -1
- package/dist/features/index.d.ts.map +1 -1
- package/dist/features/index.js +1 -1
- package/dist/features/index.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +16 -16
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/gateways/constants.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +128 -10
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +3 -3
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/network/run-command-tool.d.ts +1 -1
- package/dist/loop/types.d.ts +13 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +9 -9
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +7 -7
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +3 -3
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +9 -9
- package/dist/loop/workflows/schema.d.ts +12 -12
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +91 -5
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/memory/mock.d.ts.map +1 -1
- package/dist/memory/types.d.ts +128 -0
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-FQVUTQ7L.js +3 -0
- package/dist/{models-dev-Z45JSLWD.js.map → models-dev-FQVUTQ7L.js.map} +1 -1
- package/dist/models-dev-PPIXUUCU.cjs +12 -0
- package/dist/{models-dev-OQKVMEIT.cjs.map → models-dev-PPIXUUCU.cjs.map} +1 -1
- package/dist/netlify-4RIKF7Y3.js +3 -0
- package/dist/{netlify-SSWMYSAX.js.map → netlify-4RIKF7Y3.js.map} +1 -1
- package/dist/netlify-V5F7JEJH.cjs +12 -0
- package/dist/{netlify-TXZZCT6N.cjs.map → netlify-V5F7JEJH.cjs.map} +1 -1
- package/dist/processors/index.cjs +41 -41
- package/dist/processors/index.js +1 -1
- package/dist/processors/step-schema.d.ts +44 -44
- package/dist/provider-registry-C6XCYX44.cjs +40 -0
- package/dist/{provider-registry-NR7FXV2Q.cjs.map → provider-registry-C6XCYX44.cjs.map} +1 -1
- package/dist/provider-registry-NWU4YFQW.js +3 -0
- package/dist/{provider-registry-RPOTQNHI.js.map → provider-registry-NWU4YFQW.js.map} +1 -1
- package/dist/provider-registry.json +278 -33
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.cjs +3 -3
- package/dist/server/index.js +1 -1
- package/dist/storage/base.d.ts +3 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.cjs +51 -19
- package/dist/storage/constants.d.ts +10 -2
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/agents/base.d.ts +13 -164
- package/dist/storage/domains/agents/base.d.ts.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +0 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/agents/inmemory.d.ts +6 -10
- package/dist/storage/domains/agents/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/index.d.ts +3 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +7 -1
- package/dist/storage/domains/inmemory-db.d.ts.map +1 -1
- package/dist/storage/domains/memory/base.d.ts +45 -5
- package/dist/storage/domains/memory/base.d.ts.map +1 -1
- package/dist/storage/domains/memory/inmemory.d.ts +7 -7
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/types.d.ts +62 -62
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/base.d.ts +47 -0
- package/dist/storage/domains/prompt-blocks/base.d.ts.map +1 -0
- package/dist/storage/domains/prompt-blocks/index.d.ts +3 -0
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
- package/dist/storage/domains/prompt-blocks/inmemory.d.ts +31 -0
- package/dist/storage/domains/prompt-blocks/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/base.d.ts +47 -0
- package/dist/storage/domains/scorer-definitions/base.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts +3 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/inmemory.d.ts +31 -0
- package/dist/storage/domains/scorer-definitions/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/versioned.d.ts +136 -0
- package/dist/storage/domains/versioned.d.ts.map +1 -0
- package/dist/storage/index.cjs +156 -104
- package/dist/storage/index.js +2 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +481 -27
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/RunOutput.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts +4 -0
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/types.d.ts +15 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/tts/index.cjs +2 -2
- package/dist/tts/index.js +1 -1
- package/dist/types/zod-compat.d.ts +2 -2
- package/dist/types/zod-compat.d.ts.map +1 -1
- package/dist/utils/zod-utils.d.ts +19 -0
- package/dist/utils/zod-utils.d.ts.map +1 -1
- package/dist/utils.cjs +28 -28
- package/dist/utils.d.ts +7 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -2
- package/dist/vector/index.cjs +9 -9
- package/dist/vector/index.js +2 -2
- package/dist/voice/index.cjs +6 -6
- package/dist/voice/index.js +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +3 -1
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +4 -3
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +2 -1
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +12 -4
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/dist/workspace/errors.d.ts +6 -0
- package/dist/workspace/errors.d.ts.map +1 -1
- package/dist/workspace/filesystem/composite-filesystem.d.ts +93 -0
- package/dist/workspace/filesystem/composite-filesystem.d.ts.map +1 -0
- package/dist/workspace/filesystem/filesystem.d.ts +35 -0
- package/dist/workspace/filesystem/filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/index.d.ts +2 -0
- package/dist/workspace/filesystem/index.d.ts.map +1 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts +9 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/mastra-filesystem.d.ts +92 -3
- package/dist/workspace/filesystem/mastra-filesystem.d.ts.map +1 -1
- package/dist/workspace/filesystem/mount.d.ts +34 -0
- package/dist/workspace/filesystem/mount.d.ts.map +1 -0
- package/dist/workspace/index.cjs +62 -34
- package/dist/workspace/index.d.ts +6 -2
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/lifecycle.d.ts +29 -0
- package/dist/workspace/lifecycle.d.ts.map +1 -1
- package/dist/workspace/sandbox/errors.d.ts +50 -0
- package/dist/workspace/sandbox/errors.d.ts.map +1 -0
- package/dist/workspace/sandbox/index.d.ts +3 -0
- package/dist/workspace/sandbox/index.d.ts.map +1 -1
- package/dist/workspace/sandbox/local-sandbox.d.ts +17 -2
- package/dist/workspace/sandbox/local-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/mastra-sandbox.d.ts +153 -6
- package/dist/workspace/sandbox/mastra-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/mount-manager.d.ts +195 -0
- package/dist/workspace/sandbox/mount-manager.d.ts.map +1 -0
- package/dist/workspace/sandbox/sandbox.d.ts +37 -84
- package/dist/workspace/sandbox/sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/types.d.ts +92 -0
- package/dist/workspace/sandbox/types.d.ts.map +1 -0
- package/dist/workspace/tools/tools.d.ts.map +1 -1
- package/dist/workspace/tools/tree-formatter.d.ts.map +1 -1
- package/dist/workspace/workspace.d.ts +73 -3
- package/dist/workspace/workspace.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/llm/model/provider-types.generated.d.ts +128 -10
- package/dist/chunk-2DMSFLJY.cjs.map +0 -1
- package/dist/chunk-5SOS47PH.cjs.map +0 -1
- package/dist/chunk-5YVR7B4R.js.map +0 -1
- package/dist/chunk-7MDVYPWX.cjs.map +0 -1
- package/dist/chunk-A5QFWX67.cjs.map +0 -1
- package/dist/chunk-AIJLACR2.js.map +0 -1
- package/dist/chunk-BP2TSCBW.js.map +0 -1
- package/dist/chunk-C4WWWQHT.cjs.map +0 -1
- package/dist/chunk-E3VFKTIA.js.map +0 -1
- package/dist/chunk-ENCTSDWC.js.map +0 -1
- package/dist/chunk-G6E3QNJC.js.map +0 -1
- package/dist/chunk-GVLPTDJA.cjs.map +0 -1
- package/dist/chunk-HMCXNOF6.cjs.map +0 -1
- package/dist/chunk-HN2MSTR6.cjs.map +0 -1
- package/dist/chunk-I66TMZJ3.cjs.map +0 -1
- package/dist/chunk-IIZF4W7B.cjs.map +0 -1
- package/dist/chunk-IW3BNL7A.js.map +0 -1
- package/dist/chunk-JIT2OY3X.js.map +0 -1
- package/dist/chunk-JRJJ5VQE.cjs.map +0 -1
- package/dist/chunk-MNWW2R3U.js.map +0 -1
- package/dist/chunk-MSWXEOZC.js.map +0 -1
- package/dist/chunk-P62OJXQ4.js.map +0 -1
- package/dist/chunk-QOFI2WBM.cjs.map +0 -1
- package/dist/chunk-RXD5EGQF.js.map +0 -1
- package/dist/chunk-T6PRRKMW.js.map +0 -1
- package/dist/chunk-UZL4H5P2.cjs.map +0 -1
- package/dist/chunk-VW7YQWDW.cjs.map +0 -1
- package/dist/chunk-VX7UA3SO.js.map +0 -1
- package/dist/chunk-WFUNLRQX.js.map +0 -1
- package/dist/chunk-XCPEEIHI.cjs.map +0 -1
- package/dist/chunk-YLODOPYM.cjs.map +0 -1
- package/dist/chunk-Z6NRYYOH.js.map +0 -1
- package/dist/docs/references/docs-tools-mcp-advanced-usage.md +0 -143
- package/dist/docs/references/docs-tools-mcp-mcp-overview.md +0 -383
- package/dist/docs/references/docs-tools-mcp-overview.md +0 -78
- package/dist/docs/references/docs-workflows-input-data-mapping.md +0 -102
- package/dist/docs/references/reference-deployer-netlify.md +0 -14
- package/dist/docs/references/reference-deployer-vercel.md +0 -39
- package/dist/docs/references/reference-tools-client.md +0 -228
- package/dist/models-dev-OQKVMEIT.cjs +0 -12
- package/dist/models-dev-Z45JSLWD.js +0 -3
- package/dist/netlify-SSWMYSAX.js +0 -3
- package/dist/netlify-TXZZCT6N.cjs +0 -12
- package/dist/provider-registry-NR7FXV2Q.cjs +0 -40
- package/dist/provider-registry-RPOTQNHI.js +0 -3
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { ModelsDevGateway, parseModelRouterId } from './chunk-
|
|
2
|
-
import { NetlifyGateway } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import { PROVIDER_REGISTRY, GatewayRegistry } from './chunk-
|
|
5
|
-
import { AISDKV5LanguageModel, createStreamFromGenerateResult } from './chunk-
|
|
1
|
+
import { ModelsDevGateway, parseModelRouterId } from './chunk-ZATLLPIH.js';
|
|
2
|
+
import { NetlifyGateway } from './chunk-GIY5BINT.js';
|
|
3
|
+
import { MastraModelGateway, createOpenAICompatible, createOpenAI, createGoogleGenerativeAI, EventSourceParserStream } from './chunk-SBPPGJL6.js';
|
|
4
|
+
import { PROVIDER_REGISTRY, GatewayRegistry } from './chunk-WL3AW3YA.js';
|
|
5
|
+
import { AISDKV5LanguageModel, createStreamFromGenerateResult } from './chunk-VM25PDSW.js';
|
|
6
6
|
import { RequestContext } from './chunk-CCLV5CAA.js';
|
|
7
7
|
import { MastraError } from './chunk-FJEVLHJT.js';
|
|
8
|
-
import { InMemoryServerCache } from './chunk-
|
|
8
|
+
import { InMemoryServerCache } from './chunk-GMSAGYTB.js';
|
|
9
9
|
import { createHash } from 'crypto';
|
|
10
|
+
import * as z4 from 'zod/v4';
|
|
10
11
|
import { z } from 'zod/v4';
|
|
12
|
+
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
11
13
|
|
|
12
14
|
// src/llm/model/aisdk/v6/model.ts
|
|
13
15
|
var AISDKV6LanguageModel = class {
|
|
@@ -52,6 +54,2104 @@ var AISDKV6LanguageModel = class {
|
|
|
52
54
|
return await this.#model.doStream(options);
|
|
53
55
|
}
|
|
54
56
|
};
|
|
57
|
+
|
|
58
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider@2.0.0/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
59
|
+
var marker = "vercel.ai.error";
|
|
60
|
+
var symbol = Symbol.for(marker);
|
|
61
|
+
var _a;
|
|
62
|
+
var _AISDKError = class _AISDKError2 extends Error {
|
|
63
|
+
/**
|
|
64
|
+
* Creates an AI SDK Error.
|
|
65
|
+
*
|
|
66
|
+
* @param {Object} params - The parameters for creating the error.
|
|
67
|
+
* @param {string} params.name - The name of the error.
|
|
68
|
+
* @param {string} params.message - The error message.
|
|
69
|
+
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
70
|
+
*/
|
|
71
|
+
constructor({
|
|
72
|
+
name: name14,
|
|
73
|
+
message,
|
|
74
|
+
cause
|
|
75
|
+
}) {
|
|
76
|
+
super(message);
|
|
77
|
+
this[_a] = true;
|
|
78
|
+
this.name = name14;
|
|
79
|
+
this.cause = cause;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the given error is an AI SDK Error.
|
|
83
|
+
* @param {unknown} error - The error to check.
|
|
84
|
+
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
85
|
+
*/
|
|
86
|
+
static isInstance(error) {
|
|
87
|
+
return _AISDKError2.hasMarker(error, marker);
|
|
88
|
+
}
|
|
89
|
+
static hasMarker(error, marker15) {
|
|
90
|
+
const markerSymbol = Symbol.for(marker15);
|
|
91
|
+
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
_a = symbol;
|
|
95
|
+
var AISDKError = _AISDKError;
|
|
96
|
+
var name = "AI_APICallError";
|
|
97
|
+
var marker2 = `vercel.ai.error.${name}`;
|
|
98
|
+
var symbol2 = Symbol.for(marker2);
|
|
99
|
+
var _a2;
|
|
100
|
+
var APICallError = class extends AISDKError {
|
|
101
|
+
constructor({
|
|
102
|
+
message,
|
|
103
|
+
url,
|
|
104
|
+
requestBodyValues,
|
|
105
|
+
statusCode,
|
|
106
|
+
responseHeaders,
|
|
107
|
+
responseBody,
|
|
108
|
+
cause,
|
|
109
|
+
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
|
110
|
+
statusCode === 409 || // conflict
|
|
111
|
+
statusCode === 429 || // too many requests
|
|
112
|
+
statusCode >= 500),
|
|
113
|
+
// server error
|
|
114
|
+
data
|
|
115
|
+
}) {
|
|
116
|
+
super({ name, message, cause });
|
|
117
|
+
this[_a2] = true;
|
|
118
|
+
this.url = url;
|
|
119
|
+
this.requestBodyValues = requestBodyValues;
|
|
120
|
+
this.statusCode = statusCode;
|
|
121
|
+
this.responseHeaders = responseHeaders;
|
|
122
|
+
this.responseBody = responseBody;
|
|
123
|
+
this.isRetryable = isRetryable;
|
|
124
|
+
this.data = data;
|
|
125
|
+
}
|
|
126
|
+
static isInstance(error) {
|
|
127
|
+
return AISDKError.hasMarker(error, marker2);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
_a2 = symbol2;
|
|
131
|
+
var name2 = "AI_EmptyResponseBodyError";
|
|
132
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
133
|
+
var symbol3 = Symbol.for(marker3);
|
|
134
|
+
var _a3;
|
|
135
|
+
var EmptyResponseBodyError = class extends AISDKError {
|
|
136
|
+
// used in isInstance
|
|
137
|
+
constructor({ message = "Empty response body" } = {}) {
|
|
138
|
+
super({ name: name2, message });
|
|
139
|
+
this[_a3] = true;
|
|
140
|
+
}
|
|
141
|
+
static isInstance(error) {
|
|
142
|
+
return AISDKError.hasMarker(error, marker3);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
_a3 = symbol3;
|
|
146
|
+
function getErrorMessage(error) {
|
|
147
|
+
if (error == null) {
|
|
148
|
+
return "unknown error";
|
|
149
|
+
}
|
|
150
|
+
if (typeof error === "string") {
|
|
151
|
+
return error;
|
|
152
|
+
}
|
|
153
|
+
if (error instanceof Error) {
|
|
154
|
+
return error.message;
|
|
155
|
+
}
|
|
156
|
+
return JSON.stringify(error);
|
|
157
|
+
}
|
|
158
|
+
var name3 = "AI_InvalidArgumentError";
|
|
159
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
|
160
|
+
var symbol4 = Symbol.for(marker4);
|
|
161
|
+
var _a4;
|
|
162
|
+
var InvalidArgumentError = class extends AISDKError {
|
|
163
|
+
constructor({
|
|
164
|
+
message,
|
|
165
|
+
cause,
|
|
166
|
+
argument
|
|
167
|
+
}) {
|
|
168
|
+
super({ name: name3, message, cause });
|
|
169
|
+
this[_a4] = true;
|
|
170
|
+
this.argument = argument;
|
|
171
|
+
}
|
|
172
|
+
static isInstance(error) {
|
|
173
|
+
return AISDKError.hasMarker(error, marker4);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
_a4 = symbol4;
|
|
177
|
+
var name4 = "AI_InvalidPromptError";
|
|
178
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
|
179
|
+
var symbol5 = Symbol.for(marker5);
|
|
180
|
+
var _a5;
|
|
181
|
+
var InvalidPromptError = class extends AISDKError {
|
|
182
|
+
constructor({
|
|
183
|
+
prompt,
|
|
184
|
+
message,
|
|
185
|
+
cause
|
|
186
|
+
}) {
|
|
187
|
+
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
188
|
+
this[_a5] = true;
|
|
189
|
+
this.prompt = prompt;
|
|
190
|
+
}
|
|
191
|
+
static isInstance(error) {
|
|
192
|
+
return AISDKError.hasMarker(error, marker5);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
_a5 = symbol5;
|
|
196
|
+
var name5 = "AI_InvalidResponseDataError";
|
|
197
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
|
198
|
+
var symbol6 = Symbol.for(marker6);
|
|
199
|
+
var _a6;
|
|
200
|
+
var InvalidResponseDataError = class extends AISDKError {
|
|
201
|
+
constructor({
|
|
202
|
+
data,
|
|
203
|
+
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
204
|
+
}) {
|
|
205
|
+
super({ name: name5, message });
|
|
206
|
+
this[_a6] = true;
|
|
207
|
+
this.data = data;
|
|
208
|
+
}
|
|
209
|
+
static isInstance(error) {
|
|
210
|
+
return AISDKError.hasMarker(error, marker6);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
_a6 = symbol6;
|
|
214
|
+
var name6 = "AI_JSONParseError";
|
|
215
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
|
216
|
+
var symbol7 = Symbol.for(marker7);
|
|
217
|
+
var _a7;
|
|
218
|
+
var JSONParseError = class extends AISDKError {
|
|
219
|
+
constructor({ text, cause }) {
|
|
220
|
+
super({
|
|
221
|
+
name: name6,
|
|
222
|
+
message: `JSON parsing failed: Text: ${text}.
|
|
223
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
224
|
+
cause
|
|
225
|
+
});
|
|
226
|
+
this[_a7] = true;
|
|
227
|
+
this.text = text;
|
|
228
|
+
}
|
|
229
|
+
static isInstance(error) {
|
|
230
|
+
return AISDKError.hasMarker(error, marker7);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
_a7 = symbol7;
|
|
234
|
+
var name7 = "AI_LoadAPIKeyError";
|
|
235
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
|
236
|
+
var symbol8 = Symbol.for(marker8);
|
|
237
|
+
var _a8;
|
|
238
|
+
var LoadAPIKeyError = class extends AISDKError {
|
|
239
|
+
// used in isInstance
|
|
240
|
+
constructor({ message }) {
|
|
241
|
+
super({ name: name7, message });
|
|
242
|
+
this[_a8] = true;
|
|
243
|
+
}
|
|
244
|
+
static isInstance(error) {
|
|
245
|
+
return AISDKError.hasMarker(error, marker8);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
_a8 = symbol8;
|
|
249
|
+
var name8 = "AI_LoadSettingError";
|
|
250
|
+
var marker9 = `vercel.ai.error.${name8}`;
|
|
251
|
+
var symbol9 = Symbol.for(marker9);
|
|
252
|
+
var _a9;
|
|
253
|
+
var LoadSettingError = class extends AISDKError {
|
|
254
|
+
// used in isInstance
|
|
255
|
+
constructor({ message }) {
|
|
256
|
+
super({ name: name8, message });
|
|
257
|
+
this[_a9] = true;
|
|
258
|
+
}
|
|
259
|
+
static isInstance(error) {
|
|
260
|
+
return AISDKError.hasMarker(error, marker9);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
_a9 = symbol9;
|
|
264
|
+
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
265
|
+
var marker12 = `vercel.ai.error.${name11}`;
|
|
266
|
+
var symbol12 = Symbol.for(marker12);
|
|
267
|
+
var _a12;
|
|
268
|
+
var TooManyEmbeddingValuesForCallError = class extends AISDKError {
|
|
269
|
+
constructor(options) {
|
|
270
|
+
super({
|
|
271
|
+
name: name11,
|
|
272
|
+
message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
|
|
273
|
+
});
|
|
274
|
+
this[_a12] = true;
|
|
275
|
+
this.provider = options.provider;
|
|
276
|
+
this.modelId = options.modelId;
|
|
277
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
278
|
+
this.values = options.values;
|
|
279
|
+
}
|
|
280
|
+
static isInstance(error) {
|
|
281
|
+
return AISDKError.hasMarker(error, marker12);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
_a12 = symbol12;
|
|
285
|
+
var name12 = "AI_TypeValidationError";
|
|
286
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
287
|
+
var symbol13 = Symbol.for(marker13);
|
|
288
|
+
var _a13;
|
|
289
|
+
var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
|
|
290
|
+
constructor({ value, cause }) {
|
|
291
|
+
super({
|
|
292
|
+
name: name12,
|
|
293
|
+
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
|
294
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
295
|
+
cause
|
|
296
|
+
});
|
|
297
|
+
this[_a13] = true;
|
|
298
|
+
this.value = value;
|
|
299
|
+
}
|
|
300
|
+
static isInstance(error) {
|
|
301
|
+
return AISDKError.hasMarker(error, marker13);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Wraps an error into a TypeValidationError.
|
|
305
|
+
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
306
|
+
* Otherwise, it creates a new TypeValidationError.
|
|
307
|
+
*
|
|
308
|
+
* @param {Object} params - The parameters for wrapping the error.
|
|
309
|
+
* @param {unknown} params.value - The value that failed validation.
|
|
310
|
+
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
311
|
+
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
312
|
+
*/
|
|
313
|
+
static wrap({
|
|
314
|
+
value,
|
|
315
|
+
cause
|
|
316
|
+
}) {
|
|
317
|
+
return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
_a13 = symbol13;
|
|
321
|
+
var TypeValidationError = _TypeValidationError;
|
|
322
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
323
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
324
|
+
var symbol14 = Symbol.for(marker14);
|
|
325
|
+
var _a14;
|
|
326
|
+
var UnsupportedFunctionalityError = class extends AISDKError {
|
|
327
|
+
constructor({
|
|
328
|
+
functionality,
|
|
329
|
+
message = `'${functionality}' functionality not supported.`
|
|
330
|
+
}) {
|
|
331
|
+
super({ name: name13, message });
|
|
332
|
+
this[_a14] = true;
|
|
333
|
+
this.functionality = functionality;
|
|
334
|
+
}
|
|
335
|
+
static isInstance(error) {
|
|
336
|
+
return AISDKError.hasMarker(error, marker14);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
_a14 = symbol14;
|
|
340
|
+
function combineHeaders(...headers) {
|
|
341
|
+
return headers.reduce(
|
|
342
|
+
(combinedHeaders, currentHeaders) => ({
|
|
343
|
+
...combinedHeaders,
|
|
344
|
+
...currentHeaders != null ? currentHeaders : {}
|
|
345
|
+
}),
|
|
346
|
+
{}
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
function extractResponseHeaders(response) {
|
|
350
|
+
return Object.fromEntries([...response.headers]);
|
|
351
|
+
}
|
|
352
|
+
var createIdGenerator = ({
|
|
353
|
+
prefix,
|
|
354
|
+
size = 16,
|
|
355
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
356
|
+
separator = "-"
|
|
357
|
+
} = {}) => {
|
|
358
|
+
const generator = () => {
|
|
359
|
+
const alphabetLength = alphabet.length;
|
|
360
|
+
const chars = new Array(size);
|
|
361
|
+
for (let i = 0; i < size; i++) {
|
|
362
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
363
|
+
}
|
|
364
|
+
return chars.join("");
|
|
365
|
+
};
|
|
366
|
+
if (prefix == null) {
|
|
367
|
+
return generator;
|
|
368
|
+
}
|
|
369
|
+
if (alphabet.includes(separator)) {
|
|
370
|
+
throw new InvalidArgumentError({
|
|
371
|
+
argument: "separator",
|
|
372
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
376
|
+
};
|
|
377
|
+
var generateId = createIdGenerator();
|
|
378
|
+
function isAbortError(error) {
|
|
379
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
380
|
+
error.name === "TimeoutError");
|
|
381
|
+
}
|
|
382
|
+
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
383
|
+
function handleFetchError({
|
|
384
|
+
error,
|
|
385
|
+
url,
|
|
386
|
+
requestBodyValues
|
|
387
|
+
}) {
|
|
388
|
+
if (isAbortError(error)) {
|
|
389
|
+
return error;
|
|
390
|
+
}
|
|
391
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
392
|
+
const cause = error.cause;
|
|
393
|
+
if (cause != null) {
|
|
394
|
+
return new APICallError({
|
|
395
|
+
message: `Cannot connect to API: ${cause.message}`,
|
|
396
|
+
cause,
|
|
397
|
+
url,
|
|
398
|
+
requestBodyValues,
|
|
399
|
+
isRetryable: true
|
|
400
|
+
// retry when network error
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return error;
|
|
405
|
+
}
|
|
406
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
407
|
+
var _a15, _b, _c;
|
|
408
|
+
if (globalThisAny.window) {
|
|
409
|
+
return `runtime/browser`;
|
|
410
|
+
}
|
|
411
|
+
if ((_a15 = globalThisAny.navigator) == null ? void 0 : _a15.userAgent) {
|
|
412
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
413
|
+
}
|
|
414
|
+
if ((_c = (_b = globalThisAny.process) == null ? void 0 : _b.versions) == null ? void 0 : _c.node) {
|
|
415
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
416
|
+
}
|
|
417
|
+
if (globalThisAny.EdgeRuntime) {
|
|
418
|
+
return `runtime/vercel-edge`;
|
|
419
|
+
}
|
|
420
|
+
return "runtime/unknown";
|
|
421
|
+
}
|
|
422
|
+
function normalizeHeaders(headers) {
|
|
423
|
+
if (headers == null) {
|
|
424
|
+
return {};
|
|
425
|
+
}
|
|
426
|
+
const normalized = {};
|
|
427
|
+
if (headers instanceof Headers) {
|
|
428
|
+
headers.forEach((value, key) => {
|
|
429
|
+
normalized[key.toLowerCase()] = value;
|
|
430
|
+
});
|
|
431
|
+
} else {
|
|
432
|
+
if (!Array.isArray(headers)) {
|
|
433
|
+
headers = Object.entries(headers);
|
|
434
|
+
}
|
|
435
|
+
for (const [key, value] of headers) {
|
|
436
|
+
if (value != null) {
|
|
437
|
+
normalized[key.toLowerCase()] = value;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return normalized;
|
|
442
|
+
}
|
|
443
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
444
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
445
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
446
|
+
normalizedHeaders.set(
|
|
447
|
+
"user-agent",
|
|
448
|
+
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
449
|
+
);
|
|
450
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
451
|
+
}
|
|
452
|
+
var VERSION = "3.0.17" ;
|
|
453
|
+
function loadApiKey({
|
|
454
|
+
apiKey,
|
|
455
|
+
environmentVariableName,
|
|
456
|
+
apiKeyParameterName = "apiKey",
|
|
457
|
+
description
|
|
458
|
+
}) {
|
|
459
|
+
if (typeof apiKey === "string") {
|
|
460
|
+
return apiKey;
|
|
461
|
+
}
|
|
462
|
+
if (apiKey != null) {
|
|
463
|
+
throw new LoadAPIKeyError({
|
|
464
|
+
message: `${description} API key must be a string.`
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
if (typeof process === "undefined") {
|
|
468
|
+
throw new LoadAPIKeyError({
|
|
469
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
apiKey = process.env[environmentVariableName];
|
|
473
|
+
if (apiKey == null) {
|
|
474
|
+
throw new LoadAPIKeyError({
|
|
475
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (typeof apiKey !== "string") {
|
|
479
|
+
throw new LoadAPIKeyError({
|
|
480
|
+
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
return apiKey;
|
|
484
|
+
}
|
|
485
|
+
function loadSetting({
|
|
486
|
+
settingValue,
|
|
487
|
+
environmentVariableName,
|
|
488
|
+
settingName,
|
|
489
|
+
description
|
|
490
|
+
}) {
|
|
491
|
+
if (typeof settingValue === "string") {
|
|
492
|
+
return settingValue;
|
|
493
|
+
}
|
|
494
|
+
if (settingValue != null) {
|
|
495
|
+
throw new LoadSettingError({
|
|
496
|
+
message: `${description} setting must be a string.`
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (typeof process === "undefined") {
|
|
500
|
+
throw new LoadSettingError({
|
|
501
|
+
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.`
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
settingValue = process.env[environmentVariableName];
|
|
505
|
+
if (settingValue == null) {
|
|
506
|
+
throw new LoadSettingError({
|
|
507
|
+
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
if (typeof settingValue !== "string") {
|
|
511
|
+
throw new LoadSettingError({
|
|
512
|
+
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
return settingValue;
|
|
516
|
+
}
|
|
517
|
+
function mediaTypeToExtension(mediaType) {
|
|
518
|
+
var _a15;
|
|
519
|
+
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
520
|
+
return (_a15 = {
|
|
521
|
+
mpeg: "mp3",
|
|
522
|
+
"x-wav": "wav",
|
|
523
|
+
opus: "ogg",
|
|
524
|
+
mp4: "m4a",
|
|
525
|
+
"x-m4a": "m4a"
|
|
526
|
+
}[subtype]) != null ? _a15 : subtype;
|
|
527
|
+
}
|
|
528
|
+
var suspectProtoRx = /"__proto__"\s*:/;
|
|
529
|
+
var suspectConstructorRx = /"constructor"\s*:/;
|
|
530
|
+
function _parse(text) {
|
|
531
|
+
const obj = JSON.parse(text);
|
|
532
|
+
if (obj === null || typeof obj !== "object") {
|
|
533
|
+
return obj;
|
|
534
|
+
}
|
|
535
|
+
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
536
|
+
return obj;
|
|
537
|
+
}
|
|
538
|
+
return filter(obj);
|
|
539
|
+
}
|
|
540
|
+
function filter(obj) {
|
|
541
|
+
let next = [obj];
|
|
542
|
+
while (next.length) {
|
|
543
|
+
const nodes = next;
|
|
544
|
+
next = [];
|
|
545
|
+
for (const node of nodes) {
|
|
546
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
547
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
548
|
+
}
|
|
549
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
550
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
551
|
+
}
|
|
552
|
+
for (const key in node) {
|
|
553
|
+
const value = node[key];
|
|
554
|
+
if (value && typeof value === "object") {
|
|
555
|
+
next.push(value);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return obj;
|
|
561
|
+
}
|
|
562
|
+
function secureJsonParse(text) {
|
|
563
|
+
const { stackTraceLimit } = Error;
|
|
564
|
+
try {
|
|
565
|
+
Error.stackTraceLimit = 0;
|
|
566
|
+
} catch (e) {
|
|
567
|
+
return _parse(text);
|
|
568
|
+
}
|
|
569
|
+
try {
|
|
570
|
+
return _parse(text);
|
|
571
|
+
} finally {
|
|
572
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
576
|
+
function validator(validate) {
|
|
577
|
+
return { [validatorSymbol]: true, validate };
|
|
578
|
+
}
|
|
579
|
+
function isValidator(value) {
|
|
580
|
+
return typeof value === "object" && value !== null && validatorSymbol in value && value[validatorSymbol] === true && "validate" in value;
|
|
581
|
+
}
|
|
582
|
+
function lazyValidator(createValidator) {
|
|
583
|
+
let validator2;
|
|
584
|
+
return () => {
|
|
585
|
+
if (validator2 == null) {
|
|
586
|
+
validator2 = createValidator();
|
|
587
|
+
}
|
|
588
|
+
return validator2;
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
function asValidator(value) {
|
|
592
|
+
return isValidator(value) ? value : typeof value === "function" ? value() : standardSchemaValidator(value);
|
|
593
|
+
}
|
|
594
|
+
function standardSchemaValidator(standardSchema) {
|
|
595
|
+
return validator(async (value) => {
|
|
596
|
+
const result = await standardSchema["~standard"].validate(value);
|
|
597
|
+
return result.issues == null ? { success: true, value: result.value } : {
|
|
598
|
+
success: false,
|
|
599
|
+
error: new TypeValidationError({
|
|
600
|
+
value,
|
|
601
|
+
cause: result.issues
|
|
602
|
+
})
|
|
603
|
+
};
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
async function validateTypes({
|
|
607
|
+
value,
|
|
608
|
+
schema
|
|
609
|
+
}) {
|
|
610
|
+
const result = await safeValidateTypes({ value, schema });
|
|
611
|
+
if (!result.success) {
|
|
612
|
+
throw TypeValidationError.wrap({ value, cause: result.error });
|
|
613
|
+
}
|
|
614
|
+
return result.value;
|
|
615
|
+
}
|
|
616
|
+
async function safeValidateTypes({
|
|
617
|
+
value,
|
|
618
|
+
schema
|
|
619
|
+
}) {
|
|
620
|
+
const validator2 = asValidator(schema);
|
|
621
|
+
try {
|
|
622
|
+
if (validator2.validate == null) {
|
|
623
|
+
return { success: true, value, rawValue: value };
|
|
624
|
+
}
|
|
625
|
+
const result = await validator2.validate(value);
|
|
626
|
+
if (result.success) {
|
|
627
|
+
return { success: true, value: result.value, rawValue: value };
|
|
628
|
+
}
|
|
629
|
+
return {
|
|
630
|
+
success: false,
|
|
631
|
+
error: TypeValidationError.wrap({ value, cause: result.error }),
|
|
632
|
+
rawValue: value
|
|
633
|
+
};
|
|
634
|
+
} catch (error) {
|
|
635
|
+
return {
|
|
636
|
+
success: false,
|
|
637
|
+
error: TypeValidationError.wrap({ value, cause: error }),
|
|
638
|
+
rawValue: value
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
async function parseJSON({
|
|
643
|
+
text,
|
|
644
|
+
schema
|
|
645
|
+
}) {
|
|
646
|
+
try {
|
|
647
|
+
const value = secureJsonParse(text);
|
|
648
|
+
if (schema == null) {
|
|
649
|
+
return value;
|
|
650
|
+
}
|
|
651
|
+
return validateTypes({ value, schema });
|
|
652
|
+
} catch (error) {
|
|
653
|
+
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
|
|
654
|
+
throw error;
|
|
655
|
+
}
|
|
656
|
+
throw new JSONParseError({ text, cause: error });
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
async function safeParseJSON({
|
|
660
|
+
text,
|
|
661
|
+
schema
|
|
662
|
+
}) {
|
|
663
|
+
try {
|
|
664
|
+
const value = secureJsonParse(text);
|
|
665
|
+
if (schema == null) {
|
|
666
|
+
return { success: true, value, rawValue: value };
|
|
667
|
+
}
|
|
668
|
+
return await safeValidateTypes({ value, schema });
|
|
669
|
+
} catch (error) {
|
|
670
|
+
return {
|
|
671
|
+
success: false,
|
|
672
|
+
error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text, cause: error }),
|
|
673
|
+
rawValue: void 0
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function isParsableJson(input) {
|
|
678
|
+
try {
|
|
679
|
+
secureJsonParse(input);
|
|
680
|
+
return true;
|
|
681
|
+
} catch (e) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
function parseJsonEventStream({
|
|
686
|
+
stream,
|
|
687
|
+
schema
|
|
688
|
+
}) {
|
|
689
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
690
|
+
new TransformStream({
|
|
691
|
+
async transform({ data }, controller) {
|
|
692
|
+
if (data === "[DONE]") {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
controller.enqueue(await safeParseJSON({ text: data, schema }));
|
|
696
|
+
}
|
|
697
|
+
})
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
async function parseProviderOptions({
|
|
701
|
+
provider,
|
|
702
|
+
providerOptions,
|
|
703
|
+
schema
|
|
704
|
+
}) {
|
|
705
|
+
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
|
|
706
|
+
return void 0;
|
|
707
|
+
}
|
|
708
|
+
const parsedProviderOptions = await safeValidateTypes({
|
|
709
|
+
value: providerOptions[provider],
|
|
710
|
+
schema
|
|
711
|
+
});
|
|
712
|
+
if (!parsedProviderOptions.success) {
|
|
713
|
+
throw new InvalidArgumentError({
|
|
714
|
+
argument: "providerOptions",
|
|
715
|
+
message: `invalid ${provider} provider options`,
|
|
716
|
+
cause: parsedProviderOptions.error
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
return parsedProviderOptions.value;
|
|
720
|
+
}
|
|
721
|
+
var getOriginalFetch2 = () => globalThis.fetch;
|
|
722
|
+
var postJsonToApi = async ({
|
|
723
|
+
url,
|
|
724
|
+
headers,
|
|
725
|
+
body,
|
|
726
|
+
failedResponseHandler,
|
|
727
|
+
successfulResponseHandler,
|
|
728
|
+
abortSignal,
|
|
729
|
+
fetch: fetch2
|
|
730
|
+
}) => postToApi({
|
|
731
|
+
url,
|
|
732
|
+
headers: {
|
|
733
|
+
"Content-Type": "application/json",
|
|
734
|
+
...headers
|
|
735
|
+
},
|
|
736
|
+
body: {
|
|
737
|
+
content: JSON.stringify(body),
|
|
738
|
+
values: body
|
|
739
|
+
},
|
|
740
|
+
failedResponseHandler,
|
|
741
|
+
successfulResponseHandler,
|
|
742
|
+
abortSignal,
|
|
743
|
+
fetch: fetch2
|
|
744
|
+
});
|
|
745
|
+
var postFormDataToApi = async ({
|
|
746
|
+
url,
|
|
747
|
+
headers,
|
|
748
|
+
formData,
|
|
749
|
+
failedResponseHandler,
|
|
750
|
+
successfulResponseHandler,
|
|
751
|
+
abortSignal,
|
|
752
|
+
fetch: fetch2
|
|
753
|
+
}) => postToApi({
|
|
754
|
+
url,
|
|
755
|
+
headers,
|
|
756
|
+
body: {
|
|
757
|
+
content: formData,
|
|
758
|
+
values: Object.fromEntries(formData.entries())
|
|
759
|
+
},
|
|
760
|
+
failedResponseHandler,
|
|
761
|
+
successfulResponseHandler,
|
|
762
|
+
abortSignal,
|
|
763
|
+
fetch: fetch2
|
|
764
|
+
});
|
|
765
|
+
var postToApi = async ({
|
|
766
|
+
url,
|
|
767
|
+
headers = {},
|
|
768
|
+
body,
|
|
769
|
+
successfulResponseHandler,
|
|
770
|
+
failedResponseHandler,
|
|
771
|
+
abortSignal,
|
|
772
|
+
fetch: fetch2 = getOriginalFetch2()
|
|
773
|
+
}) => {
|
|
774
|
+
try {
|
|
775
|
+
const response = await fetch2(url, {
|
|
776
|
+
method: "POST",
|
|
777
|
+
headers: withUserAgentSuffix(
|
|
778
|
+
headers,
|
|
779
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
|
780
|
+
getRuntimeEnvironmentUserAgent()
|
|
781
|
+
),
|
|
782
|
+
body: body.content,
|
|
783
|
+
signal: abortSignal
|
|
784
|
+
});
|
|
785
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
786
|
+
if (!response.ok) {
|
|
787
|
+
let errorInformation;
|
|
788
|
+
try {
|
|
789
|
+
errorInformation = await failedResponseHandler({
|
|
790
|
+
response,
|
|
791
|
+
url,
|
|
792
|
+
requestBodyValues: body.values
|
|
793
|
+
});
|
|
794
|
+
} catch (error) {
|
|
795
|
+
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
796
|
+
throw error;
|
|
797
|
+
}
|
|
798
|
+
throw new APICallError({
|
|
799
|
+
message: "Failed to process error response",
|
|
800
|
+
cause: error,
|
|
801
|
+
statusCode: response.status,
|
|
802
|
+
url,
|
|
803
|
+
responseHeaders,
|
|
804
|
+
requestBodyValues: body.values
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
throw errorInformation.value;
|
|
808
|
+
}
|
|
809
|
+
try {
|
|
810
|
+
return await successfulResponseHandler({
|
|
811
|
+
response,
|
|
812
|
+
url,
|
|
813
|
+
requestBodyValues: body.values
|
|
814
|
+
});
|
|
815
|
+
} catch (error) {
|
|
816
|
+
if (error instanceof Error) {
|
|
817
|
+
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
818
|
+
throw error;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
throw new APICallError({
|
|
822
|
+
message: "Failed to process successful response",
|
|
823
|
+
cause: error,
|
|
824
|
+
statusCode: response.status,
|
|
825
|
+
url,
|
|
826
|
+
responseHeaders,
|
|
827
|
+
requestBodyValues: body.values
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
} catch (error) {
|
|
831
|
+
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
function tool(tool2) {
|
|
835
|
+
return tool2;
|
|
836
|
+
}
|
|
837
|
+
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
838
|
+
id,
|
|
839
|
+
name: name14,
|
|
840
|
+
inputSchema,
|
|
841
|
+
outputSchema
|
|
842
|
+
}) {
|
|
843
|
+
return ({
|
|
844
|
+
execute,
|
|
845
|
+
toModelOutput,
|
|
846
|
+
onInputStart,
|
|
847
|
+
onInputDelta,
|
|
848
|
+
onInputAvailable,
|
|
849
|
+
...args
|
|
850
|
+
}) => tool({
|
|
851
|
+
type: "provider-defined",
|
|
852
|
+
id,
|
|
853
|
+
name: name14,
|
|
854
|
+
args,
|
|
855
|
+
inputSchema,
|
|
856
|
+
outputSchema,
|
|
857
|
+
execute,
|
|
858
|
+
toModelOutput,
|
|
859
|
+
onInputStart,
|
|
860
|
+
onInputDelta,
|
|
861
|
+
onInputAvailable
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
var createJsonErrorResponseHandler = ({
|
|
865
|
+
errorSchema,
|
|
866
|
+
errorToMessage,
|
|
867
|
+
isRetryable
|
|
868
|
+
}) => async ({ response, url, requestBodyValues }) => {
|
|
869
|
+
const responseBody = await response.text();
|
|
870
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
871
|
+
if (responseBody.trim() === "") {
|
|
872
|
+
return {
|
|
873
|
+
responseHeaders,
|
|
874
|
+
value: new APICallError({
|
|
875
|
+
message: response.statusText,
|
|
876
|
+
url,
|
|
877
|
+
requestBodyValues,
|
|
878
|
+
statusCode: response.status,
|
|
879
|
+
responseHeaders,
|
|
880
|
+
responseBody,
|
|
881
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
882
|
+
})
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
try {
|
|
886
|
+
const parsedError = await parseJSON({
|
|
887
|
+
text: responseBody,
|
|
888
|
+
schema: errorSchema
|
|
889
|
+
});
|
|
890
|
+
return {
|
|
891
|
+
responseHeaders,
|
|
892
|
+
value: new APICallError({
|
|
893
|
+
message: errorToMessage(parsedError),
|
|
894
|
+
url,
|
|
895
|
+
requestBodyValues,
|
|
896
|
+
statusCode: response.status,
|
|
897
|
+
responseHeaders,
|
|
898
|
+
responseBody,
|
|
899
|
+
data: parsedError,
|
|
900
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
901
|
+
})
|
|
902
|
+
};
|
|
903
|
+
} catch (parseError) {
|
|
904
|
+
return {
|
|
905
|
+
responseHeaders,
|
|
906
|
+
value: new APICallError({
|
|
907
|
+
message: response.statusText,
|
|
908
|
+
url,
|
|
909
|
+
requestBodyValues,
|
|
910
|
+
statusCode: response.status,
|
|
911
|
+
responseHeaders,
|
|
912
|
+
responseBody,
|
|
913
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
914
|
+
})
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
919
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
920
|
+
if (response.body == null) {
|
|
921
|
+
throw new EmptyResponseBodyError({});
|
|
922
|
+
}
|
|
923
|
+
return {
|
|
924
|
+
responseHeaders,
|
|
925
|
+
value: parseJsonEventStream({
|
|
926
|
+
stream: response.body,
|
|
927
|
+
schema: chunkSchema
|
|
928
|
+
})
|
|
929
|
+
};
|
|
930
|
+
};
|
|
931
|
+
var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
932
|
+
const responseBody = await response.text();
|
|
933
|
+
const parsedResult = await safeParseJSON({
|
|
934
|
+
text: responseBody,
|
|
935
|
+
schema: responseSchema
|
|
936
|
+
});
|
|
937
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
938
|
+
if (!parsedResult.success) {
|
|
939
|
+
throw new APICallError({
|
|
940
|
+
message: "Invalid JSON response",
|
|
941
|
+
cause: parsedResult.error,
|
|
942
|
+
statusCode: response.status,
|
|
943
|
+
responseHeaders,
|
|
944
|
+
responseBody,
|
|
945
|
+
url,
|
|
946
|
+
requestBodyValues
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
return {
|
|
950
|
+
responseHeaders,
|
|
951
|
+
value: parsedResult.value,
|
|
952
|
+
rawValue: parsedResult.rawValue
|
|
953
|
+
};
|
|
954
|
+
};
|
|
955
|
+
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
956
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
957
|
+
if (!response.body) {
|
|
958
|
+
throw new APICallError({
|
|
959
|
+
message: "Response body is empty",
|
|
960
|
+
url,
|
|
961
|
+
requestBodyValues,
|
|
962
|
+
statusCode: response.status,
|
|
963
|
+
responseHeaders,
|
|
964
|
+
responseBody: void 0
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
try {
|
|
968
|
+
const buffer = await response.arrayBuffer();
|
|
969
|
+
return {
|
|
970
|
+
responseHeaders,
|
|
971
|
+
value: new Uint8Array(buffer)
|
|
972
|
+
};
|
|
973
|
+
} catch (error) {
|
|
974
|
+
throw new APICallError({
|
|
975
|
+
message: "Failed to read response as array buffer",
|
|
976
|
+
url,
|
|
977
|
+
requestBodyValues,
|
|
978
|
+
statusCode: response.status,
|
|
979
|
+
responseHeaders,
|
|
980
|
+
responseBody: void 0,
|
|
981
|
+
cause: error
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var getRelativePath = (pathA, pathB) => {
|
|
986
|
+
let i = 0;
|
|
987
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
988
|
+
if (pathA[i] !== pathB[i]) break;
|
|
989
|
+
}
|
|
990
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
991
|
+
};
|
|
992
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
993
|
+
"Let zodToJsonSchema decide on which parser to use"
|
|
994
|
+
);
|
|
995
|
+
var defaultOptions = {
|
|
996
|
+
name: void 0,
|
|
997
|
+
$refStrategy: "root",
|
|
998
|
+
basePath: ["#"],
|
|
999
|
+
effectStrategy: "input",
|
|
1000
|
+
pipeStrategy: "all",
|
|
1001
|
+
dateStrategy: "format:date-time",
|
|
1002
|
+
mapStrategy: "entries",
|
|
1003
|
+
removeAdditionalStrategy: "passthrough",
|
|
1004
|
+
allowedAdditionalProperties: true,
|
|
1005
|
+
rejectedAdditionalProperties: false,
|
|
1006
|
+
definitionPath: "definitions",
|
|
1007
|
+
strictUnions: false,
|
|
1008
|
+
definitions: {},
|
|
1009
|
+
errorMessages: false,
|
|
1010
|
+
patternStrategy: "escape",
|
|
1011
|
+
applyRegexFlags: false,
|
|
1012
|
+
emailStrategy: "format:email",
|
|
1013
|
+
base64Strategy: "contentEncoding:base64",
|
|
1014
|
+
nameStrategy: "ref"
|
|
1015
|
+
};
|
|
1016
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
1017
|
+
...defaultOptions,
|
|
1018
|
+
name: options
|
|
1019
|
+
} : {
|
|
1020
|
+
...defaultOptions,
|
|
1021
|
+
...options
|
|
1022
|
+
};
|
|
1023
|
+
function parseAnyDef() {
|
|
1024
|
+
return {};
|
|
1025
|
+
}
|
|
1026
|
+
function parseArrayDef(def, refs) {
|
|
1027
|
+
var _a15, _b, _c;
|
|
1028
|
+
const res = {
|
|
1029
|
+
type: "array"
|
|
1030
|
+
};
|
|
1031
|
+
if (((_a15 = def.type) == null ? void 0 : _a15._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
1032
|
+
res.items = parseDef(def.type._def, {
|
|
1033
|
+
...refs,
|
|
1034
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
if (def.minLength) {
|
|
1038
|
+
res.minItems = def.minLength.value;
|
|
1039
|
+
}
|
|
1040
|
+
if (def.maxLength) {
|
|
1041
|
+
res.maxItems = def.maxLength.value;
|
|
1042
|
+
}
|
|
1043
|
+
if (def.exactLength) {
|
|
1044
|
+
res.minItems = def.exactLength.value;
|
|
1045
|
+
res.maxItems = def.exactLength.value;
|
|
1046
|
+
}
|
|
1047
|
+
return res;
|
|
1048
|
+
}
|
|
1049
|
+
function parseBigintDef(def) {
|
|
1050
|
+
const res = {
|
|
1051
|
+
type: "integer",
|
|
1052
|
+
format: "int64"
|
|
1053
|
+
};
|
|
1054
|
+
if (!def.checks) return res;
|
|
1055
|
+
for (const check of def.checks) {
|
|
1056
|
+
switch (check.kind) {
|
|
1057
|
+
case "min":
|
|
1058
|
+
if (check.inclusive) {
|
|
1059
|
+
res.minimum = check.value;
|
|
1060
|
+
} else {
|
|
1061
|
+
res.exclusiveMinimum = check.value;
|
|
1062
|
+
}
|
|
1063
|
+
break;
|
|
1064
|
+
case "max":
|
|
1065
|
+
if (check.inclusive) {
|
|
1066
|
+
res.maximum = check.value;
|
|
1067
|
+
} else {
|
|
1068
|
+
res.exclusiveMaximum = check.value;
|
|
1069
|
+
}
|
|
1070
|
+
break;
|
|
1071
|
+
case "multipleOf":
|
|
1072
|
+
res.multipleOf = check.value;
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return res;
|
|
1077
|
+
}
|
|
1078
|
+
function parseBooleanDef() {
|
|
1079
|
+
return { type: "boolean" };
|
|
1080
|
+
}
|
|
1081
|
+
function parseBrandedDef(_def, refs) {
|
|
1082
|
+
return parseDef(_def.type._def, refs);
|
|
1083
|
+
}
|
|
1084
|
+
var parseCatchDef = (def, refs) => {
|
|
1085
|
+
return parseDef(def.innerType._def, refs);
|
|
1086
|
+
};
|
|
1087
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
1088
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
1089
|
+
if (Array.isArray(strategy)) {
|
|
1090
|
+
return {
|
|
1091
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
switch (strategy) {
|
|
1095
|
+
case "string":
|
|
1096
|
+
case "format:date-time":
|
|
1097
|
+
return {
|
|
1098
|
+
type: "string",
|
|
1099
|
+
format: "date-time"
|
|
1100
|
+
};
|
|
1101
|
+
case "format:date":
|
|
1102
|
+
return {
|
|
1103
|
+
type: "string",
|
|
1104
|
+
format: "date"
|
|
1105
|
+
};
|
|
1106
|
+
case "integer":
|
|
1107
|
+
return integerDateParser(def);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
var integerDateParser = (def) => {
|
|
1111
|
+
const res = {
|
|
1112
|
+
type: "integer",
|
|
1113
|
+
format: "unix-time"
|
|
1114
|
+
};
|
|
1115
|
+
for (const check of def.checks) {
|
|
1116
|
+
switch (check.kind) {
|
|
1117
|
+
case "min":
|
|
1118
|
+
res.minimum = check.value;
|
|
1119
|
+
break;
|
|
1120
|
+
case "max":
|
|
1121
|
+
res.maximum = check.value;
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return res;
|
|
1126
|
+
};
|
|
1127
|
+
function parseDefaultDef(_def, refs) {
|
|
1128
|
+
return {
|
|
1129
|
+
...parseDef(_def.innerType._def, refs),
|
|
1130
|
+
default: _def.defaultValue()
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function parseEffectsDef(_def, refs) {
|
|
1134
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
1135
|
+
}
|
|
1136
|
+
function parseEnumDef(def) {
|
|
1137
|
+
return {
|
|
1138
|
+
type: "string",
|
|
1139
|
+
enum: Array.from(def.values)
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
1143
|
+
if ("type" in type && type.type === "string") return false;
|
|
1144
|
+
return "allOf" in type;
|
|
1145
|
+
};
|
|
1146
|
+
function parseIntersectionDef(def, refs) {
|
|
1147
|
+
const allOf = [
|
|
1148
|
+
parseDef(def.left._def, {
|
|
1149
|
+
...refs,
|
|
1150
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1151
|
+
}),
|
|
1152
|
+
parseDef(def.right._def, {
|
|
1153
|
+
...refs,
|
|
1154
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
1155
|
+
})
|
|
1156
|
+
].filter((x) => !!x);
|
|
1157
|
+
const mergedAllOf = [];
|
|
1158
|
+
allOf.forEach((schema) => {
|
|
1159
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
1160
|
+
mergedAllOf.push(...schema.allOf);
|
|
1161
|
+
} else {
|
|
1162
|
+
let nestedSchema = schema;
|
|
1163
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1164
|
+
const { additionalProperties, ...rest } = schema;
|
|
1165
|
+
nestedSchema = rest;
|
|
1166
|
+
}
|
|
1167
|
+
mergedAllOf.push(nestedSchema);
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
1171
|
+
}
|
|
1172
|
+
function parseLiteralDef(def) {
|
|
1173
|
+
const parsedType = typeof def.value;
|
|
1174
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
1175
|
+
return {
|
|
1176
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
return {
|
|
1180
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1181
|
+
const: def.value
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
var emojiRegex = void 0;
|
|
1185
|
+
var zodPatterns = {
|
|
1186
|
+
/**
|
|
1187
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
1188
|
+
*/
|
|
1189
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
1190
|
+
cuid2: /^[0-9a-z]+$/,
|
|
1191
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
1192
|
+
/**
|
|
1193
|
+
* `a-z` was added to replicate /i flag
|
|
1194
|
+
*/
|
|
1195
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
1196
|
+
/**
|
|
1197
|
+
* Constructed a valid Unicode RegExp
|
|
1198
|
+
*
|
|
1199
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
1200
|
+
* in all envs (e.g. React Native).
|
|
1201
|
+
*
|
|
1202
|
+
* See:
|
|
1203
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
1204
|
+
* Fix in Zod:
|
|
1205
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
1206
|
+
*/
|
|
1207
|
+
emoji: () => {
|
|
1208
|
+
if (emojiRegex === void 0) {
|
|
1209
|
+
emojiRegex = RegExp(
|
|
1210
|
+
"^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
1211
|
+
"u"
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
return emojiRegex;
|
|
1215
|
+
},
|
|
1216
|
+
/**
|
|
1217
|
+
* Unused
|
|
1218
|
+
*/
|
|
1219
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
1220
|
+
/**
|
|
1221
|
+
* Unused
|
|
1222
|
+
*/
|
|
1223
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
1224
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
1225
|
+
/**
|
|
1226
|
+
* Unused
|
|
1227
|
+
*/
|
|
1228
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
1229
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
1230
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1231
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1232
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1233
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1234
|
+
};
|
|
1235
|
+
function parseStringDef(def, refs) {
|
|
1236
|
+
const res = {
|
|
1237
|
+
type: "string"
|
|
1238
|
+
};
|
|
1239
|
+
if (def.checks) {
|
|
1240
|
+
for (const check of def.checks) {
|
|
1241
|
+
switch (check.kind) {
|
|
1242
|
+
case "min":
|
|
1243
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1244
|
+
break;
|
|
1245
|
+
case "max":
|
|
1246
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1247
|
+
break;
|
|
1248
|
+
case "email":
|
|
1249
|
+
switch (refs.emailStrategy) {
|
|
1250
|
+
case "format:email":
|
|
1251
|
+
addFormat(res, "email", check.message, refs);
|
|
1252
|
+
break;
|
|
1253
|
+
case "format:idn-email":
|
|
1254
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
1255
|
+
break;
|
|
1256
|
+
case "pattern:zod":
|
|
1257
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1258
|
+
break;
|
|
1259
|
+
}
|
|
1260
|
+
break;
|
|
1261
|
+
case "url":
|
|
1262
|
+
addFormat(res, "uri", check.message, refs);
|
|
1263
|
+
break;
|
|
1264
|
+
case "uuid":
|
|
1265
|
+
addFormat(res, "uuid", check.message, refs);
|
|
1266
|
+
break;
|
|
1267
|
+
case "regex":
|
|
1268
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1269
|
+
break;
|
|
1270
|
+
case "cuid":
|
|
1271
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1272
|
+
break;
|
|
1273
|
+
case "cuid2":
|
|
1274
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1275
|
+
break;
|
|
1276
|
+
case "startsWith":
|
|
1277
|
+
addPattern(
|
|
1278
|
+
res,
|
|
1279
|
+
RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
|
|
1280
|
+
check.message,
|
|
1281
|
+
refs
|
|
1282
|
+
);
|
|
1283
|
+
break;
|
|
1284
|
+
case "endsWith":
|
|
1285
|
+
addPattern(
|
|
1286
|
+
res,
|
|
1287
|
+
RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
|
|
1288
|
+
check.message,
|
|
1289
|
+
refs
|
|
1290
|
+
);
|
|
1291
|
+
break;
|
|
1292
|
+
case "datetime":
|
|
1293
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1294
|
+
break;
|
|
1295
|
+
case "date":
|
|
1296
|
+
addFormat(res, "date", check.message, refs);
|
|
1297
|
+
break;
|
|
1298
|
+
case "time":
|
|
1299
|
+
addFormat(res, "time", check.message, refs);
|
|
1300
|
+
break;
|
|
1301
|
+
case "duration":
|
|
1302
|
+
addFormat(res, "duration", check.message, refs);
|
|
1303
|
+
break;
|
|
1304
|
+
case "length":
|
|
1305
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1306
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1307
|
+
break;
|
|
1308
|
+
case "includes": {
|
|
1309
|
+
addPattern(
|
|
1310
|
+
res,
|
|
1311
|
+
RegExp(escapeLiteralCheckValue(check.value, refs)),
|
|
1312
|
+
check.message,
|
|
1313
|
+
refs
|
|
1314
|
+
);
|
|
1315
|
+
break;
|
|
1316
|
+
}
|
|
1317
|
+
case "ip": {
|
|
1318
|
+
if (check.version !== "v6") {
|
|
1319
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
1320
|
+
}
|
|
1321
|
+
if (check.version !== "v4") {
|
|
1322
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
1323
|
+
}
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
case "base64url":
|
|
1327
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1328
|
+
break;
|
|
1329
|
+
case "jwt":
|
|
1330
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1331
|
+
break;
|
|
1332
|
+
case "cidr": {
|
|
1333
|
+
if (check.version !== "v6") {
|
|
1334
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1335
|
+
}
|
|
1336
|
+
if (check.version !== "v4") {
|
|
1337
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1338
|
+
}
|
|
1339
|
+
break;
|
|
1340
|
+
}
|
|
1341
|
+
case "emoji":
|
|
1342
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1343
|
+
break;
|
|
1344
|
+
case "ulid": {
|
|
1345
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
case "base64": {
|
|
1349
|
+
switch (refs.base64Strategy) {
|
|
1350
|
+
case "format:binary": {
|
|
1351
|
+
addFormat(res, "binary", check.message, refs);
|
|
1352
|
+
break;
|
|
1353
|
+
}
|
|
1354
|
+
case "contentEncoding:base64": {
|
|
1355
|
+
res.contentEncoding = "base64";
|
|
1356
|
+
break;
|
|
1357
|
+
}
|
|
1358
|
+
case "pattern:zod": {
|
|
1359
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
break;
|
|
1364
|
+
}
|
|
1365
|
+
case "nanoid": {
|
|
1366
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return res;
|
|
1372
|
+
}
|
|
1373
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1374
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1375
|
+
}
|
|
1376
|
+
var ALPHA_NUMERIC = new Set(
|
|
1377
|
+
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
1378
|
+
);
|
|
1379
|
+
function escapeNonAlphaNumeric(source) {
|
|
1380
|
+
let result = "";
|
|
1381
|
+
for (let i = 0; i < source.length; i++) {
|
|
1382
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
1383
|
+
result += "\\";
|
|
1384
|
+
}
|
|
1385
|
+
result += source[i];
|
|
1386
|
+
}
|
|
1387
|
+
return result;
|
|
1388
|
+
}
|
|
1389
|
+
function addFormat(schema, value, message, refs) {
|
|
1390
|
+
var _a15;
|
|
1391
|
+
if (schema.format || ((_a15 = schema.anyOf) == null ? void 0 : _a15.some((x) => x.format))) {
|
|
1392
|
+
if (!schema.anyOf) {
|
|
1393
|
+
schema.anyOf = [];
|
|
1394
|
+
}
|
|
1395
|
+
if (schema.format) {
|
|
1396
|
+
schema.anyOf.push({
|
|
1397
|
+
format: schema.format
|
|
1398
|
+
});
|
|
1399
|
+
delete schema.format;
|
|
1400
|
+
}
|
|
1401
|
+
schema.anyOf.push({
|
|
1402
|
+
format: value,
|
|
1403
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
1404
|
+
});
|
|
1405
|
+
} else {
|
|
1406
|
+
schema.format = value;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
function addPattern(schema, regex, message, refs) {
|
|
1410
|
+
var _a15;
|
|
1411
|
+
if (schema.pattern || ((_a15 = schema.allOf) == null ? void 0 : _a15.some((x) => x.pattern))) {
|
|
1412
|
+
if (!schema.allOf) {
|
|
1413
|
+
schema.allOf = [];
|
|
1414
|
+
}
|
|
1415
|
+
if (schema.pattern) {
|
|
1416
|
+
schema.allOf.push({
|
|
1417
|
+
pattern: schema.pattern
|
|
1418
|
+
});
|
|
1419
|
+
delete schema.pattern;
|
|
1420
|
+
}
|
|
1421
|
+
schema.allOf.push({
|
|
1422
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
1423
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
1424
|
+
});
|
|
1425
|
+
} else {
|
|
1426
|
+
schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1430
|
+
var _a15;
|
|
1431
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1432
|
+
return regex.source;
|
|
1433
|
+
}
|
|
1434
|
+
const flags = {
|
|
1435
|
+
i: regex.flags.includes("i"),
|
|
1436
|
+
// Case-insensitive
|
|
1437
|
+
m: regex.flags.includes("m"),
|
|
1438
|
+
// `^` and `$` matches adjacent to newline characters
|
|
1439
|
+
s: regex.flags.includes("s")
|
|
1440
|
+
// `.` matches newlines
|
|
1441
|
+
};
|
|
1442
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1443
|
+
let pattern = "";
|
|
1444
|
+
let isEscaped = false;
|
|
1445
|
+
let inCharGroup = false;
|
|
1446
|
+
let inCharRange = false;
|
|
1447
|
+
for (let i = 0; i < source.length; i++) {
|
|
1448
|
+
if (isEscaped) {
|
|
1449
|
+
pattern += source[i];
|
|
1450
|
+
isEscaped = false;
|
|
1451
|
+
continue;
|
|
1452
|
+
}
|
|
1453
|
+
if (flags.i) {
|
|
1454
|
+
if (inCharGroup) {
|
|
1455
|
+
if (source[i].match(/[a-z]/)) {
|
|
1456
|
+
if (inCharRange) {
|
|
1457
|
+
pattern += source[i];
|
|
1458
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1459
|
+
inCharRange = false;
|
|
1460
|
+
} else if (source[i + 1] === "-" && ((_a15 = source[i + 2]) == null ? void 0 : _a15.match(/[a-z]/))) {
|
|
1461
|
+
pattern += source[i];
|
|
1462
|
+
inCharRange = true;
|
|
1463
|
+
} else {
|
|
1464
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1465
|
+
}
|
|
1466
|
+
continue;
|
|
1467
|
+
}
|
|
1468
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1469
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
if (flags.m) {
|
|
1474
|
+
if (source[i] === "^") {
|
|
1475
|
+
pattern += `(^|(?<=[\r
|
|
1476
|
+
]))`;
|
|
1477
|
+
continue;
|
|
1478
|
+
} else if (source[i] === "$") {
|
|
1479
|
+
pattern += `($|(?=[\r
|
|
1480
|
+
]))`;
|
|
1481
|
+
continue;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
if (flags.s && source[i] === ".") {
|
|
1485
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1486
|
+
` : `[${source[i]}\r
|
|
1487
|
+
]`;
|
|
1488
|
+
continue;
|
|
1489
|
+
}
|
|
1490
|
+
pattern += source[i];
|
|
1491
|
+
if (source[i] === "\\") {
|
|
1492
|
+
isEscaped = true;
|
|
1493
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
1494
|
+
inCharGroup = false;
|
|
1495
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
1496
|
+
inCharGroup = true;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return pattern;
|
|
1500
|
+
}
|
|
1501
|
+
function parseRecordDef(def, refs) {
|
|
1502
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1503
|
+
const schema = {
|
|
1504
|
+
type: "object",
|
|
1505
|
+
additionalProperties: (_a15 = parseDef(def.valueType._def, {
|
|
1506
|
+
...refs,
|
|
1507
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1508
|
+
})) != null ? _a15 : refs.allowedAdditionalProperties
|
|
1509
|
+
};
|
|
1510
|
+
if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1511
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1512
|
+
return {
|
|
1513
|
+
...schema,
|
|
1514
|
+
propertyNames: keyType
|
|
1515
|
+
};
|
|
1516
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind.ZodEnum) {
|
|
1517
|
+
return {
|
|
1518
|
+
...schema,
|
|
1519
|
+
propertyNames: {
|
|
1520
|
+
enum: def.keyType._def.values
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
1524
|
+
const { type, ...keyType } = parseBrandedDef(
|
|
1525
|
+
def.keyType._def,
|
|
1526
|
+
refs
|
|
1527
|
+
);
|
|
1528
|
+
return {
|
|
1529
|
+
...schema,
|
|
1530
|
+
propertyNames: keyType
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
return schema;
|
|
1534
|
+
}
|
|
1535
|
+
function parseMapDef(def, refs) {
|
|
1536
|
+
if (refs.mapStrategy === "record") {
|
|
1537
|
+
return parseRecordDef(def, refs);
|
|
1538
|
+
}
|
|
1539
|
+
const keys = parseDef(def.keyType._def, {
|
|
1540
|
+
...refs,
|
|
1541
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
1542
|
+
}) || parseAnyDef();
|
|
1543
|
+
const values = parseDef(def.valueType._def, {
|
|
1544
|
+
...refs,
|
|
1545
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
1546
|
+
}) || parseAnyDef();
|
|
1547
|
+
return {
|
|
1548
|
+
type: "array",
|
|
1549
|
+
maxItems: 125,
|
|
1550
|
+
items: {
|
|
1551
|
+
type: "array",
|
|
1552
|
+
items: [keys, values],
|
|
1553
|
+
minItems: 2,
|
|
1554
|
+
maxItems: 2
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
function parseNativeEnumDef(def) {
|
|
1559
|
+
const object = def.values;
|
|
1560
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1561
|
+
return typeof object[object[key]] !== "number";
|
|
1562
|
+
});
|
|
1563
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
1564
|
+
const parsedTypes = Array.from(
|
|
1565
|
+
new Set(actualValues.map((values) => typeof values))
|
|
1566
|
+
);
|
|
1567
|
+
return {
|
|
1568
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1569
|
+
enum: actualValues
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
function parseNeverDef() {
|
|
1573
|
+
return { not: parseAnyDef() };
|
|
1574
|
+
}
|
|
1575
|
+
function parseNullDef() {
|
|
1576
|
+
return {
|
|
1577
|
+
type: "null"
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
var primitiveMappings = {
|
|
1581
|
+
ZodString: "string",
|
|
1582
|
+
ZodNumber: "number",
|
|
1583
|
+
ZodBigInt: "integer",
|
|
1584
|
+
ZodBoolean: "boolean",
|
|
1585
|
+
ZodNull: "null"
|
|
1586
|
+
};
|
|
1587
|
+
function parseUnionDef(def, refs) {
|
|
1588
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1589
|
+
if (options.every(
|
|
1590
|
+
(x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
|
|
1591
|
+
)) {
|
|
1592
|
+
const types = options.reduce((types2, x) => {
|
|
1593
|
+
const type = primitiveMappings[x._def.typeName];
|
|
1594
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
1595
|
+
}, []);
|
|
1596
|
+
return {
|
|
1597
|
+
type: types.length > 1 ? types : types[0]
|
|
1598
|
+
};
|
|
1599
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1600
|
+
const types = options.reduce(
|
|
1601
|
+
(acc, x) => {
|
|
1602
|
+
const type = typeof x._def.value;
|
|
1603
|
+
switch (type) {
|
|
1604
|
+
case "string":
|
|
1605
|
+
case "number":
|
|
1606
|
+
case "boolean":
|
|
1607
|
+
return [...acc, type];
|
|
1608
|
+
case "bigint":
|
|
1609
|
+
return [...acc, "integer"];
|
|
1610
|
+
case "object":
|
|
1611
|
+
if (x._def.value === null) return [...acc, "null"];
|
|
1612
|
+
case "symbol":
|
|
1613
|
+
case "undefined":
|
|
1614
|
+
case "function":
|
|
1615
|
+
default:
|
|
1616
|
+
return acc;
|
|
1617
|
+
}
|
|
1618
|
+
},
|
|
1619
|
+
[]
|
|
1620
|
+
);
|
|
1621
|
+
if (types.length === options.length) {
|
|
1622
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1623
|
+
return {
|
|
1624
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1625
|
+
enum: options.reduce(
|
|
1626
|
+
(acc, x) => {
|
|
1627
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1628
|
+
},
|
|
1629
|
+
[]
|
|
1630
|
+
)
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
1634
|
+
return {
|
|
1635
|
+
type: "string",
|
|
1636
|
+
enum: options.reduce(
|
|
1637
|
+
(acc, x) => [
|
|
1638
|
+
...acc,
|
|
1639
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
1640
|
+
],
|
|
1641
|
+
[]
|
|
1642
|
+
)
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
return asAnyOf(def, refs);
|
|
1646
|
+
}
|
|
1647
|
+
var asAnyOf = (def, refs) => {
|
|
1648
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
|
|
1649
|
+
(x, i) => parseDef(x._def, {
|
|
1650
|
+
...refs,
|
|
1651
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
1652
|
+
})
|
|
1653
|
+
).filter(
|
|
1654
|
+
(x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
|
|
1655
|
+
);
|
|
1656
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
1657
|
+
};
|
|
1658
|
+
function parseNullableDef(def, refs) {
|
|
1659
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1660
|
+
def.innerType._def.typeName
|
|
1661
|
+
) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1662
|
+
return {
|
|
1663
|
+
type: [
|
|
1664
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
1665
|
+
"null"
|
|
1666
|
+
]
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
const base = parseDef(def.innerType._def, {
|
|
1670
|
+
...refs,
|
|
1671
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
1672
|
+
});
|
|
1673
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1674
|
+
}
|
|
1675
|
+
function parseNumberDef(def) {
|
|
1676
|
+
const res = {
|
|
1677
|
+
type: "number"
|
|
1678
|
+
};
|
|
1679
|
+
if (!def.checks) return res;
|
|
1680
|
+
for (const check of def.checks) {
|
|
1681
|
+
switch (check.kind) {
|
|
1682
|
+
case "int":
|
|
1683
|
+
res.type = "integer";
|
|
1684
|
+
break;
|
|
1685
|
+
case "min":
|
|
1686
|
+
if (check.inclusive) {
|
|
1687
|
+
res.minimum = check.value;
|
|
1688
|
+
} else {
|
|
1689
|
+
res.exclusiveMinimum = check.value;
|
|
1690
|
+
}
|
|
1691
|
+
break;
|
|
1692
|
+
case "max":
|
|
1693
|
+
if (check.inclusive) {
|
|
1694
|
+
res.maximum = check.value;
|
|
1695
|
+
} else {
|
|
1696
|
+
res.exclusiveMaximum = check.value;
|
|
1697
|
+
}
|
|
1698
|
+
break;
|
|
1699
|
+
case "multipleOf":
|
|
1700
|
+
res.multipleOf = check.value;
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return res;
|
|
1705
|
+
}
|
|
1706
|
+
function parseObjectDef(def, refs) {
|
|
1707
|
+
const result = {
|
|
1708
|
+
type: "object",
|
|
1709
|
+
properties: {}
|
|
1710
|
+
};
|
|
1711
|
+
const required = [];
|
|
1712
|
+
const shape = def.shape();
|
|
1713
|
+
for (const propName in shape) {
|
|
1714
|
+
let propDef = shape[propName];
|
|
1715
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
const propOptional = safeIsOptional(propDef);
|
|
1719
|
+
const parsedDef = parseDef(propDef._def, {
|
|
1720
|
+
...refs,
|
|
1721
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1722
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1723
|
+
});
|
|
1724
|
+
if (parsedDef === void 0) {
|
|
1725
|
+
continue;
|
|
1726
|
+
}
|
|
1727
|
+
result.properties[propName] = parsedDef;
|
|
1728
|
+
if (!propOptional) {
|
|
1729
|
+
required.push(propName);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (required.length) {
|
|
1733
|
+
result.required = required;
|
|
1734
|
+
}
|
|
1735
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1736
|
+
if (additionalProperties !== void 0) {
|
|
1737
|
+
result.additionalProperties = additionalProperties;
|
|
1738
|
+
}
|
|
1739
|
+
return result;
|
|
1740
|
+
}
|
|
1741
|
+
function decideAdditionalProperties(def, refs) {
|
|
1742
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
1743
|
+
return parseDef(def.catchall._def, {
|
|
1744
|
+
...refs,
|
|
1745
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
switch (def.unknownKeys) {
|
|
1749
|
+
case "passthrough":
|
|
1750
|
+
return refs.allowedAdditionalProperties;
|
|
1751
|
+
case "strict":
|
|
1752
|
+
return refs.rejectedAdditionalProperties;
|
|
1753
|
+
case "strip":
|
|
1754
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
function safeIsOptional(schema) {
|
|
1758
|
+
try {
|
|
1759
|
+
return schema.isOptional();
|
|
1760
|
+
} catch (e) {
|
|
1761
|
+
return true;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
var parseOptionalDef = (def, refs) => {
|
|
1765
|
+
var _a15;
|
|
1766
|
+
if (refs.currentPath.toString() === ((_a15 = refs.propertyPath) == null ? void 0 : _a15.toString())) {
|
|
1767
|
+
return parseDef(def.innerType._def, refs);
|
|
1768
|
+
}
|
|
1769
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
1770
|
+
...refs,
|
|
1771
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1772
|
+
});
|
|
1773
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
1774
|
+
};
|
|
1775
|
+
var parsePipelineDef = (def, refs) => {
|
|
1776
|
+
if (refs.pipeStrategy === "input") {
|
|
1777
|
+
return parseDef(def.in._def, refs);
|
|
1778
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1779
|
+
return parseDef(def.out._def, refs);
|
|
1780
|
+
}
|
|
1781
|
+
const a = parseDef(def.in._def, {
|
|
1782
|
+
...refs,
|
|
1783
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1784
|
+
});
|
|
1785
|
+
const b = parseDef(def.out._def, {
|
|
1786
|
+
...refs,
|
|
1787
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1788
|
+
});
|
|
1789
|
+
return {
|
|
1790
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1791
|
+
};
|
|
1792
|
+
};
|
|
1793
|
+
function parsePromiseDef(def, refs) {
|
|
1794
|
+
return parseDef(def.type._def, refs);
|
|
1795
|
+
}
|
|
1796
|
+
function parseSetDef(def, refs) {
|
|
1797
|
+
const items = parseDef(def.valueType._def, {
|
|
1798
|
+
...refs,
|
|
1799
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1800
|
+
});
|
|
1801
|
+
const schema = {
|
|
1802
|
+
type: "array",
|
|
1803
|
+
uniqueItems: true,
|
|
1804
|
+
items
|
|
1805
|
+
};
|
|
1806
|
+
if (def.minSize) {
|
|
1807
|
+
schema.minItems = def.minSize.value;
|
|
1808
|
+
}
|
|
1809
|
+
if (def.maxSize) {
|
|
1810
|
+
schema.maxItems = def.maxSize.value;
|
|
1811
|
+
}
|
|
1812
|
+
return schema;
|
|
1813
|
+
}
|
|
1814
|
+
function parseTupleDef(def, refs) {
|
|
1815
|
+
if (def.rest) {
|
|
1816
|
+
return {
|
|
1817
|
+
type: "array",
|
|
1818
|
+
minItems: def.items.length,
|
|
1819
|
+
items: def.items.map(
|
|
1820
|
+
(x, i) => parseDef(x._def, {
|
|
1821
|
+
...refs,
|
|
1822
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1823
|
+
})
|
|
1824
|
+
).reduce(
|
|
1825
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1826
|
+
[]
|
|
1827
|
+
),
|
|
1828
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1829
|
+
...refs,
|
|
1830
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1831
|
+
})
|
|
1832
|
+
};
|
|
1833
|
+
} else {
|
|
1834
|
+
return {
|
|
1835
|
+
type: "array",
|
|
1836
|
+
minItems: def.items.length,
|
|
1837
|
+
maxItems: def.items.length,
|
|
1838
|
+
items: def.items.map(
|
|
1839
|
+
(x, i) => parseDef(x._def, {
|
|
1840
|
+
...refs,
|
|
1841
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1842
|
+
})
|
|
1843
|
+
).reduce(
|
|
1844
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1845
|
+
[]
|
|
1846
|
+
)
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
function parseUndefinedDef() {
|
|
1851
|
+
return {
|
|
1852
|
+
not: parseAnyDef()
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
function parseUnknownDef() {
|
|
1856
|
+
return parseAnyDef();
|
|
1857
|
+
}
|
|
1858
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1859
|
+
return parseDef(def.innerType._def, refs);
|
|
1860
|
+
};
|
|
1861
|
+
var selectParser = (def, typeName, refs) => {
|
|
1862
|
+
switch (typeName) {
|
|
1863
|
+
case ZodFirstPartyTypeKind.ZodString:
|
|
1864
|
+
return parseStringDef(def, refs);
|
|
1865
|
+
case ZodFirstPartyTypeKind.ZodNumber:
|
|
1866
|
+
return parseNumberDef(def);
|
|
1867
|
+
case ZodFirstPartyTypeKind.ZodObject:
|
|
1868
|
+
return parseObjectDef(def, refs);
|
|
1869
|
+
case ZodFirstPartyTypeKind.ZodBigInt:
|
|
1870
|
+
return parseBigintDef(def);
|
|
1871
|
+
case ZodFirstPartyTypeKind.ZodBoolean:
|
|
1872
|
+
return parseBooleanDef();
|
|
1873
|
+
case ZodFirstPartyTypeKind.ZodDate:
|
|
1874
|
+
return parseDateDef(def, refs);
|
|
1875
|
+
case ZodFirstPartyTypeKind.ZodUndefined:
|
|
1876
|
+
return parseUndefinedDef();
|
|
1877
|
+
case ZodFirstPartyTypeKind.ZodNull:
|
|
1878
|
+
return parseNullDef();
|
|
1879
|
+
case ZodFirstPartyTypeKind.ZodArray:
|
|
1880
|
+
return parseArrayDef(def, refs);
|
|
1881
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
1882
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
1883
|
+
return parseUnionDef(def, refs);
|
|
1884
|
+
case ZodFirstPartyTypeKind.ZodIntersection:
|
|
1885
|
+
return parseIntersectionDef(def, refs);
|
|
1886
|
+
case ZodFirstPartyTypeKind.ZodTuple:
|
|
1887
|
+
return parseTupleDef(def, refs);
|
|
1888
|
+
case ZodFirstPartyTypeKind.ZodRecord:
|
|
1889
|
+
return parseRecordDef(def, refs);
|
|
1890
|
+
case ZodFirstPartyTypeKind.ZodLiteral:
|
|
1891
|
+
return parseLiteralDef(def);
|
|
1892
|
+
case ZodFirstPartyTypeKind.ZodEnum:
|
|
1893
|
+
return parseEnumDef(def);
|
|
1894
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
1895
|
+
return parseNativeEnumDef(def);
|
|
1896
|
+
case ZodFirstPartyTypeKind.ZodNullable:
|
|
1897
|
+
return parseNullableDef(def, refs);
|
|
1898
|
+
case ZodFirstPartyTypeKind.ZodOptional:
|
|
1899
|
+
return parseOptionalDef(def, refs);
|
|
1900
|
+
case ZodFirstPartyTypeKind.ZodMap:
|
|
1901
|
+
return parseMapDef(def, refs);
|
|
1902
|
+
case ZodFirstPartyTypeKind.ZodSet:
|
|
1903
|
+
return parseSetDef(def, refs);
|
|
1904
|
+
case ZodFirstPartyTypeKind.ZodLazy:
|
|
1905
|
+
return () => def.getter()._def;
|
|
1906
|
+
case ZodFirstPartyTypeKind.ZodPromise:
|
|
1907
|
+
return parsePromiseDef(def, refs);
|
|
1908
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
1909
|
+
case ZodFirstPartyTypeKind.ZodNever:
|
|
1910
|
+
return parseNeverDef();
|
|
1911
|
+
case ZodFirstPartyTypeKind.ZodEffects:
|
|
1912
|
+
return parseEffectsDef(def, refs);
|
|
1913
|
+
case ZodFirstPartyTypeKind.ZodAny:
|
|
1914
|
+
return parseAnyDef();
|
|
1915
|
+
case ZodFirstPartyTypeKind.ZodUnknown:
|
|
1916
|
+
return parseUnknownDef();
|
|
1917
|
+
case ZodFirstPartyTypeKind.ZodDefault:
|
|
1918
|
+
return parseDefaultDef(def, refs);
|
|
1919
|
+
case ZodFirstPartyTypeKind.ZodBranded:
|
|
1920
|
+
return parseBrandedDef(def, refs);
|
|
1921
|
+
case ZodFirstPartyTypeKind.ZodReadonly:
|
|
1922
|
+
return parseReadonlyDef(def, refs);
|
|
1923
|
+
case ZodFirstPartyTypeKind.ZodCatch:
|
|
1924
|
+
return parseCatchDef(def, refs);
|
|
1925
|
+
case ZodFirstPartyTypeKind.ZodPipeline:
|
|
1926
|
+
return parsePipelineDef(def, refs);
|
|
1927
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
1928
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
1929
|
+
case ZodFirstPartyTypeKind.ZodSymbol:
|
|
1930
|
+
return void 0;
|
|
1931
|
+
default:
|
|
1932
|
+
return /* @__PURE__ */ ((_) => void 0)();
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1936
|
+
var _a15;
|
|
1937
|
+
const seenItem = refs.seen.get(def);
|
|
1938
|
+
if (refs.override) {
|
|
1939
|
+
const overrideResult = (_a15 = refs.override) == null ? void 0 : _a15.call(
|
|
1940
|
+
refs,
|
|
1941
|
+
def,
|
|
1942
|
+
refs,
|
|
1943
|
+
seenItem,
|
|
1944
|
+
forceResolution
|
|
1945
|
+
);
|
|
1946
|
+
if (overrideResult !== ignoreOverride) {
|
|
1947
|
+
return overrideResult;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
if (seenItem && !forceResolution) {
|
|
1951
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1952
|
+
if (seenSchema !== void 0) {
|
|
1953
|
+
return seenSchema;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1957
|
+
refs.seen.set(def, newItem);
|
|
1958
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1959
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1960
|
+
if (jsonSchema2) {
|
|
1961
|
+
addMeta(def, refs, jsonSchema2);
|
|
1962
|
+
}
|
|
1963
|
+
if (refs.postProcess) {
|
|
1964
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
1965
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1966
|
+
return postProcessResult;
|
|
1967
|
+
}
|
|
1968
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1969
|
+
return jsonSchema2;
|
|
1970
|
+
}
|
|
1971
|
+
var get$ref = (item, refs) => {
|
|
1972
|
+
switch (refs.$refStrategy) {
|
|
1973
|
+
case "root":
|
|
1974
|
+
return { $ref: item.path.join("/") };
|
|
1975
|
+
case "relative":
|
|
1976
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1977
|
+
case "none":
|
|
1978
|
+
case "seen": {
|
|
1979
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1980
|
+
console.warn(
|
|
1981
|
+
`Recursive reference detected at ${refs.currentPath.join(
|
|
1982
|
+
"/"
|
|
1983
|
+
)}! Defaulting to any`
|
|
1984
|
+
);
|
|
1985
|
+
return parseAnyDef();
|
|
1986
|
+
}
|
|
1987
|
+
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
};
|
|
1991
|
+
var addMeta = (def, refs, jsonSchema2) => {
|
|
1992
|
+
if (def.description) {
|
|
1993
|
+
jsonSchema2.description = def.description;
|
|
1994
|
+
}
|
|
1995
|
+
return jsonSchema2;
|
|
1996
|
+
};
|
|
1997
|
+
var getRefs = (options) => {
|
|
1998
|
+
const _options = getDefaultOptions(options);
|
|
1999
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
2000
|
+
return {
|
|
2001
|
+
..._options,
|
|
2002
|
+
currentPath,
|
|
2003
|
+
propertyPath: void 0,
|
|
2004
|
+
seen: new Map(
|
|
2005
|
+
Object.entries(_options.definitions).map(([name14, def]) => [
|
|
2006
|
+
def._def,
|
|
2007
|
+
{
|
|
2008
|
+
def: def._def,
|
|
2009
|
+
path: [..._options.basePath, _options.definitionPath, name14],
|
|
2010
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
2011
|
+
jsonSchema: void 0
|
|
2012
|
+
}
|
|
2013
|
+
])
|
|
2014
|
+
)
|
|
2015
|
+
};
|
|
2016
|
+
};
|
|
2017
|
+
var zodToJsonSchema = (schema, options) => {
|
|
2018
|
+
var _a15;
|
|
2019
|
+
const refs = getRefs(options);
|
|
2020
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
2021
|
+
(acc, [name22, schema2]) => {
|
|
2022
|
+
var _a22;
|
|
2023
|
+
return {
|
|
2024
|
+
...acc,
|
|
2025
|
+
[name22]: (_a22 = parseDef(
|
|
2026
|
+
schema2._def,
|
|
2027
|
+
{
|
|
2028
|
+
...refs,
|
|
2029
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
2030
|
+
},
|
|
2031
|
+
true
|
|
2032
|
+
)) != null ? _a22 : parseAnyDef()
|
|
2033
|
+
};
|
|
2034
|
+
},
|
|
2035
|
+
{}
|
|
2036
|
+
) : void 0;
|
|
2037
|
+
const name14 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2038
|
+
const main = (_a15 = parseDef(
|
|
2039
|
+
schema._def,
|
|
2040
|
+
name14 === void 0 ? refs : {
|
|
2041
|
+
...refs,
|
|
2042
|
+
currentPath: [...refs.basePath, refs.definitionPath, name14]
|
|
2043
|
+
},
|
|
2044
|
+
false
|
|
2045
|
+
)) != null ? _a15 : parseAnyDef();
|
|
2046
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2047
|
+
if (title !== void 0) {
|
|
2048
|
+
main.title = title;
|
|
2049
|
+
}
|
|
2050
|
+
const combined = name14 === void 0 ? definitions ? {
|
|
2051
|
+
...main,
|
|
2052
|
+
[refs.definitionPath]: definitions
|
|
2053
|
+
} : main : {
|
|
2054
|
+
$ref: [
|
|
2055
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2056
|
+
refs.definitionPath,
|
|
2057
|
+
name14
|
|
2058
|
+
].join("/"),
|
|
2059
|
+
[refs.definitionPath]: {
|
|
2060
|
+
...definitions,
|
|
2061
|
+
[name14]: main
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
2065
|
+
return combined;
|
|
2066
|
+
};
|
|
2067
|
+
var zod_to_json_schema_default = zodToJsonSchema;
|
|
2068
|
+
function zod3Schema(zodSchema2, options) {
|
|
2069
|
+
var _a15;
|
|
2070
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
2071
|
+
return jsonSchema(
|
|
2072
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2073
|
+
() => zod_to_json_schema_default(zodSchema2, {
|
|
2074
|
+
$refStrategy: useReferences ? "root" : "none"
|
|
2075
|
+
}),
|
|
2076
|
+
{
|
|
2077
|
+
validate: async (value) => {
|
|
2078
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
2079
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
);
|
|
2083
|
+
}
|
|
2084
|
+
function zod4Schema(zodSchema2, options) {
|
|
2085
|
+
var _a15;
|
|
2086
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
2087
|
+
return jsonSchema(
|
|
2088
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2089
|
+
() => z4.toJSONSchema(zodSchema2, {
|
|
2090
|
+
target: "draft-7",
|
|
2091
|
+
io: "output",
|
|
2092
|
+
reused: useReferences ? "ref" : "inline"
|
|
2093
|
+
}),
|
|
2094
|
+
{
|
|
2095
|
+
validate: async (value) => {
|
|
2096
|
+
const result = await z4.safeParseAsync(zodSchema2, value);
|
|
2097
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
function isZod4Schema(zodSchema2) {
|
|
2103
|
+
return "_zod" in zodSchema2;
|
|
2104
|
+
}
|
|
2105
|
+
function zodSchema(zodSchema2, options) {
|
|
2106
|
+
if (isZod4Schema(zodSchema2)) {
|
|
2107
|
+
return zod4Schema(zodSchema2);
|
|
2108
|
+
} else {
|
|
2109
|
+
return zod3Schema(zodSchema2);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2113
|
+
function lazySchema(createSchema) {
|
|
2114
|
+
let schema;
|
|
2115
|
+
return () => {
|
|
2116
|
+
if (schema == null) {
|
|
2117
|
+
schema = createSchema();
|
|
2118
|
+
}
|
|
2119
|
+
return schema;
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function jsonSchema(jsonSchema2, {
|
|
2123
|
+
validate
|
|
2124
|
+
} = {}) {
|
|
2125
|
+
return {
|
|
2126
|
+
[schemaSymbol]: true,
|
|
2127
|
+
_type: void 0,
|
|
2128
|
+
// should never be used directly
|
|
2129
|
+
[validatorSymbol]: true,
|
|
2130
|
+
get jsonSchema() {
|
|
2131
|
+
if (typeof jsonSchema2 === "function") {
|
|
2132
|
+
jsonSchema2 = jsonSchema2();
|
|
2133
|
+
}
|
|
2134
|
+
return jsonSchema2;
|
|
2135
|
+
},
|
|
2136
|
+
validate
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
var { btoa, atob } = globalThis;
|
|
2140
|
+
function convertBase64ToUint8Array(base64String) {
|
|
2141
|
+
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
2142
|
+
const latin1string = atob(base64Url);
|
|
2143
|
+
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
2144
|
+
}
|
|
2145
|
+
function convertUint8ArrayToBase64(array) {
|
|
2146
|
+
let latin1string = "";
|
|
2147
|
+
for (let i = 0; i < array.length; i++) {
|
|
2148
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
2149
|
+
}
|
|
2150
|
+
return btoa(latin1string);
|
|
2151
|
+
}
|
|
2152
|
+
function convertToBase64(value) {
|
|
2153
|
+
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
2154
|
+
}
|
|
55
2155
|
var openaiErrorDataSchema = z.object({
|
|
56
2156
|
error: z.object({
|
|
57
2157
|
message: z.string(),
|
|
@@ -63,7 +2163,7 @@ var openaiErrorDataSchema = z.object({
|
|
|
63
2163
|
code: z.union([z.string(), z.number()]).nullish()
|
|
64
2164
|
})
|
|
65
2165
|
});
|
|
66
|
-
var openaiFailedResponseHandler =
|
|
2166
|
+
var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
67
2167
|
errorSchema: openaiErrorDataSchema,
|
|
68
2168
|
errorToMessage: (data) => data.error.message
|
|
69
2169
|
});
|
|
@@ -109,7 +2209,7 @@ function convertToOpenAIChatMessages({
|
|
|
109
2209
|
messages.push({
|
|
110
2210
|
role: "user",
|
|
111
2211
|
content: content.map((part, index) => {
|
|
112
|
-
var
|
|
2212
|
+
var _a15, _b, _c;
|
|
113
2213
|
switch (part.type) {
|
|
114
2214
|
case "text": {
|
|
115
2215
|
return { type: "text", text: part.text };
|
|
@@ -120,14 +2220,14 @@ function convertToOpenAIChatMessages({
|
|
|
120
2220
|
return {
|
|
121
2221
|
type: "image_url",
|
|
122
2222
|
image_url: {
|
|
123
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
2223
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
124
2224
|
// OpenAI specific extension: image detail
|
|
125
|
-
detail: (_b = (
|
|
2225
|
+
detail: (_b = (_a15 = part.providerOptions) == null ? void 0 : _a15.openai) == null ? void 0 : _b.imageDetail
|
|
126
2226
|
}
|
|
127
2227
|
};
|
|
128
2228
|
} else if (part.mediaType.startsWith("audio/")) {
|
|
129
2229
|
if (part.data instanceof URL) {
|
|
130
|
-
throw new
|
|
2230
|
+
throw new UnsupportedFunctionalityError({
|
|
131
2231
|
functionality: "audio file parts with URLs"
|
|
132
2232
|
});
|
|
133
2233
|
}
|
|
@@ -136,7 +2236,7 @@ function convertToOpenAIChatMessages({
|
|
|
136
2236
|
return {
|
|
137
2237
|
type: "input_audio",
|
|
138
2238
|
input_audio: {
|
|
139
|
-
data:
|
|
2239
|
+
data: convertToBase64(part.data),
|
|
140
2240
|
format: "wav"
|
|
141
2241
|
}
|
|
142
2242
|
};
|
|
@@ -146,20 +2246,20 @@ function convertToOpenAIChatMessages({
|
|
|
146
2246
|
return {
|
|
147
2247
|
type: "input_audio",
|
|
148
2248
|
input_audio: {
|
|
149
|
-
data:
|
|
2249
|
+
data: convertToBase64(part.data),
|
|
150
2250
|
format: "mp3"
|
|
151
2251
|
}
|
|
152
2252
|
};
|
|
153
2253
|
}
|
|
154
2254
|
default: {
|
|
155
|
-
throw new
|
|
2255
|
+
throw new UnsupportedFunctionalityError({
|
|
156
2256
|
functionality: `audio content parts with media type ${part.mediaType}`
|
|
157
2257
|
});
|
|
158
2258
|
}
|
|
159
2259
|
}
|
|
160
2260
|
} else if (part.mediaType === "application/pdf") {
|
|
161
2261
|
if (part.data instanceof URL) {
|
|
162
|
-
throw new
|
|
2262
|
+
throw new UnsupportedFunctionalityError({
|
|
163
2263
|
functionality: "PDF file parts with URLs"
|
|
164
2264
|
});
|
|
165
2265
|
}
|
|
@@ -167,11 +2267,11 @@ function convertToOpenAIChatMessages({
|
|
|
167
2267
|
type: "file",
|
|
168
2268
|
file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
|
|
169
2269
|
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
170
|
-
file_data: `data:application/pdf;base64,${
|
|
2270
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
171
2271
|
}
|
|
172
2272
|
};
|
|
173
2273
|
} else {
|
|
174
|
-
throw new
|
|
2274
|
+
throw new UnsupportedFunctionalityError({
|
|
175
2275
|
functionality: `file part media type ${part.mediaType}`
|
|
176
2276
|
});
|
|
177
2277
|
}
|
|
@@ -515,21 +2615,21 @@ function prepareChatTools({
|
|
|
515
2615
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
516
2616
|
}
|
|
517
2617
|
const openaiTools = [];
|
|
518
|
-
for (const
|
|
519
|
-
switch (
|
|
2618
|
+
for (const tool2 of tools) {
|
|
2619
|
+
switch (tool2.type) {
|
|
520
2620
|
case "function":
|
|
521
2621
|
openaiTools.push({
|
|
522
2622
|
type: "function",
|
|
523
2623
|
function: {
|
|
524
|
-
name:
|
|
525
|
-
description:
|
|
526
|
-
parameters:
|
|
2624
|
+
name: tool2.name,
|
|
2625
|
+
description: tool2.description,
|
|
2626
|
+
parameters: tool2.inputSchema,
|
|
527
2627
|
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
528
2628
|
}
|
|
529
2629
|
});
|
|
530
2630
|
break;
|
|
531
2631
|
default:
|
|
532
|
-
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
2632
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
|
|
533
2633
|
break;
|
|
534
2634
|
}
|
|
535
2635
|
}
|
|
@@ -555,7 +2655,7 @@ function prepareChatTools({
|
|
|
555
2655
|
};
|
|
556
2656
|
default: {
|
|
557
2657
|
const _exhaustiveCheck = type;
|
|
558
|
-
throw new
|
|
2658
|
+
throw new UnsupportedFunctionalityError({
|
|
559
2659
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
560
2660
|
});
|
|
561
2661
|
}
|
|
@@ -588,13 +2688,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
588
2688
|
toolChoice,
|
|
589
2689
|
providerOptions
|
|
590
2690
|
}) {
|
|
591
|
-
var
|
|
2691
|
+
var _a15, _b, _c, _d;
|
|
592
2692
|
const warnings = [];
|
|
593
|
-
const openaiOptions = (
|
|
2693
|
+
const openaiOptions = (_a15 = await parseProviderOptions({
|
|
594
2694
|
provider: "openai",
|
|
595
2695
|
providerOptions,
|
|
596
2696
|
schema: openaiChatLanguageModelOptions
|
|
597
|
-
})) != null ?
|
|
2697
|
+
})) != null ? _a15 : {};
|
|
598
2698
|
const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
|
|
599
2699
|
if (topK != null) {
|
|
600
2700
|
warnings.push({
|
|
@@ -764,21 +2864,21 @@ var OpenAIChatLanguageModel = class {
|
|
|
764
2864
|
};
|
|
765
2865
|
}
|
|
766
2866
|
async doGenerate(options) {
|
|
767
|
-
var
|
|
2867
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
768
2868
|
const { args: body, warnings } = await this.getArgs(options);
|
|
769
2869
|
const {
|
|
770
2870
|
responseHeaders,
|
|
771
2871
|
value: response,
|
|
772
2872
|
rawValue: rawResponse
|
|
773
|
-
} = await
|
|
2873
|
+
} = await postJsonToApi({
|
|
774
2874
|
url: this.config.url({
|
|
775
2875
|
path: "/chat/completions",
|
|
776
2876
|
modelId: this.modelId
|
|
777
2877
|
}),
|
|
778
|
-
headers:
|
|
2878
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
779
2879
|
body,
|
|
780
2880
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
781
|
-
successfulResponseHandler:
|
|
2881
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
782
2882
|
openaiChatResponseSchema
|
|
783
2883
|
),
|
|
784
2884
|
abortSignal: options.abortSignal,
|
|
@@ -790,10 +2890,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
790
2890
|
if (text != null && text.length > 0) {
|
|
791
2891
|
content.push({ type: "text", text });
|
|
792
2892
|
}
|
|
793
|
-
for (const toolCall of (
|
|
2893
|
+
for (const toolCall of (_a15 = choice.message.tool_calls) != null ? _a15 : []) {
|
|
794
2894
|
content.push({
|
|
795
2895
|
type: "tool-call",
|
|
796
|
-
toolCallId: (_b = toolCall.id) != null ? _b :
|
|
2896
|
+
toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
|
|
797
2897
|
toolName: toolCall.function.name,
|
|
798
2898
|
input: toolCall.function.arguments
|
|
799
2899
|
});
|
|
@@ -802,7 +2902,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
802
2902
|
content.push({
|
|
803
2903
|
type: "source",
|
|
804
2904
|
sourceType: "url",
|
|
805
|
-
id:
|
|
2905
|
+
id: generateId(),
|
|
806
2906
|
url: annotation.url,
|
|
807
2907
|
title: annotation.title
|
|
808
2908
|
});
|
|
@@ -848,15 +2948,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
848
2948
|
include_usage: true
|
|
849
2949
|
}
|
|
850
2950
|
};
|
|
851
|
-
const { responseHeaders, value: response } = await
|
|
2951
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
852
2952
|
url: this.config.url({
|
|
853
2953
|
path: "/chat/completions",
|
|
854
2954
|
modelId: this.modelId
|
|
855
2955
|
}),
|
|
856
|
-
headers:
|
|
2956
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
857
2957
|
body,
|
|
858
2958
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
859
|
-
successfulResponseHandler:
|
|
2959
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
860
2960
|
openaiChatChunkSchema
|
|
861
2961
|
),
|
|
862
2962
|
abortSignal: options.abortSignal,
|
|
@@ -879,7 +2979,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
879
2979
|
controller.enqueue({ type: "stream-start", warnings });
|
|
880
2980
|
},
|
|
881
2981
|
transform(chunk, controller) {
|
|
882
|
-
var
|
|
2982
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
883
2983
|
if (options.includeRawChunks) {
|
|
884
2984
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
885
2985
|
}
|
|
@@ -905,7 +3005,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
905
3005
|
}
|
|
906
3006
|
}
|
|
907
3007
|
if (value.usage != null) {
|
|
908
|
-
usage.inputTokens = (
|
|
3008
|
+
usage.inputTokens = (_a15 = value.usage.prompt_tokens) != null ? _a15 : void 0;
|
|
909
3009
|
usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
|
|
910
3010
|
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
|
|
911
3011
|
usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
|
|
@@ -944,19 +3044,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
944
3044
|
const index = toolCallDelta.index;
|
|
945
3045
|
if (toolCalls[index] == null) {
|
|
946
3046
|
if (toolCallDelta.type !== "function") {
|
|
947
|
-
throw new
|
|
3047
|
+
throw new InvalidResponseDataError({
|
|
948
3048
|
data: toolCallDelta,
|
|
949
3049
|
message: `Expected 'function' type.`
|
|
950
3050
|
});
|
|
951
3051
|
}
|
|
952
3052
|
if (toolCallDelta.id == null) {
|
|
953
|
-
throw new
|
|
3053
|
+
throw new InvalidResponseDataError({
|
|
954
3054
|
data: toolCallDelta,
|
|
955
3055
|
message: `Expected 'id' to be a string.`
|
|
956
3056
|
});
|
|
957
3057
|
}
|
|
958
3058
|
if (((_m = toolCallDelta.function) == null ? void 0 : _m.name) == null) {
|
|
959
|
-
throw new
|
|
3059
|
+
throw new InvalidResponseDataError({
|
|
960
3060
|
data: toolCallDelta,
|
|
961
3061
|
message: `Expected 'function.name' to be a string.`
|
|
962
3062
|
});
|
|
@@ -984,14 +3084,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
984
3084
|
delta: toolCall2.function.arguments
|
|
985
3085
|
});
|
|
986
3086
|
}
|
|
987
|
-
if (
|
|
3087
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
988
3088
|
controller.enqueue({
|
|
989
3089
|
type: "tool-input-end",
|
|
990
3090
|
id: toolCall2.id
|
|
991
3091
|
});
|
|
992
3092
|
controller.enqueue({
|
|
993
3093
|
type: "tool-call",
|
|
994
|
-
toolCallId: (_q = toolCall2.id) != null ? _q :
|
|
3094
|
+
toolCallId: (_q = toolCall2.id) != null ? _q : generateId(),
|
|
995
3095
|
toolName: toolCall2.function.name,
|
|
996
3096
|
input: toolCall2.function.arguments
|
|
997
3097
|
});
|
|
@@ -1012,14 +3112,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
1012
3112
|
id: toolCall.id,
|
|
1013
3113
|
delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
|
|
1014
3114
|
});
|
|
1015
|
-
if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null &&
|
|
3115
|
+
if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1016
3116
|
controller.enqueue({
|
|
1017
3117
|
type: "tool-input-end",
|
|
1018
3118
|
id: toolCall.id
|
|
1019
3119
|
});
|
|
1020
3120
|
controller.enqueue({
|
|
1021
3121
|
type: "tool-call",
|
|
1022
|
-
toolCallId: (_x = toolCall.id) != null ? _x :
|
|
3122
|
+
toolCallId: (_x = toolCall.id) != null ? _x : generateId(),
|
|
1023
3123
|
toolName: toolCall.function.name,
|
|
1024
3124
|
input: toolCall.function.arguments
|
|
1025
3125
|
});
|
|
@@ -1032,7 +3132,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1032
3132
|
controller.enqueue({
|
|
1033
3133
|
type: "source",
|
|
1034
3134
|
sourceType: "url",
|
|
1035
|
-
id:
|
|
3135
|
+
id: generateId(),
|
|
1036
3136
|
url: annotation.url,
|
|
1037
3137
|
title: annotation.title
|
|
1038
3138
|
});
|
|
@@ -1067,11 +3167,11 @@ function supportsPriorityProcessing(modelId) {
|
|
|
1067
3167
|
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
1068
3168
|
}
|
|
1069
3169
|
function getSystemMessageMode(modelId) {
|
|
1070
|
-
var
|
|
3170
|
+
var _a15, _b;
|
|
1071
3171
|
if (!isReasoningModel(modelId)) {
|
|
1072
3172
|
return "system";
|
|
1073
3173
|
}
|
|
1074
|
-
return (_b = (
|
|
3174
|
+
return (_b = (_a15 = reasoningModels[modelId]) == null ? void 0 : _a15.systemMessageMode) != null ? _b : "developer";
|
|
1075
3175
|
}
|
|
1076
3176
|
var reasoningModels = {
|
|
1077
3177
|
o3: {
|
|
@@ -1108,7 +3208,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
1108
3208
|
for (const { role, content } of prompt) {
|
|
1109
3209
|
switch (role) {
|
|
1110
3210
|
case "system": {
|
|
1111
|
-
throw new
|
|
3211
|
+
throw new InvalidPromptError({
|
|
1112
3212
|
message: "Unexpected system message in prompt: ${content}",
|
|
1113
3213
|
prompt
|
|
1114
3214
|
});
|
|
@@ -1134,7 +3234,7 @@ ${userMessage}
|
|
|
1134
3234
|
return part.text;
|
|
1135
3235
|
}
|
|
1136
3236
|
case "tool-call": {
|
|
1137
|
-
throw new
|
|
3237
|
+
throw new UnsupportedFunctionalityError({
|
|
1138
3238
|
functionality: "tool-call messages"
|
|
1139
3239
|
});
|
|
1140
3240
|
}
|
|
@@ -1147,7 +3247,7 @@ ${assistantMessage}
|
|
|
1147
3247
|
break;
|
|
1148
3248
|
}
|
|
1149
3249
|
case "tool": {
|
|
1150
|
-
throw new
|
|
3250
|
+
throw new UnsupportedFunctionalityError({
|
|
1151
3251
|
functionality: "tool messages"
|
|
1152
3252
|
});
|
|
1153
3253
|
}
|
|
@@ -1321,12 +3421,12 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1321
3421
|
}) {
|
|
1322
3422
|
const warnings = [];
|
|
1323
3423
|
const openaiOptions = {
|
|
1324
|
-
...await
|
|
3424
|
+
...await parseProviderOptions({
|
|
1325
3425
|
provider: "openai",
|
|
1326
3426
|
providerOptions,
|
|
1327
3427
|
schema: openaiCompletionProviderOptions
|
|
1328
3428
|
}),
|
|
1329
|
-
...await
|
|
3429
|
+
...await parseProviderOptions({
|
|
1330
3430
|
provider: this.providerOptionsName,
|
|
1331
3431
|
providerOptions,
|
|
1332
3432
|
schema: openaiCompletionProviderOptions
|
|
@@ -1376,21 +3476,21 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1376
3476
|
};
|
|
1377
3477
|
}
|
|
1378
3478
|
async doGenerate(options) {
|
|
1379
|
-
var
|
|
3479
|
+
var _a15, _b, _c;
|
|
1380
3480
|
const { args, warnings } = await this.getArgs(options);
|
|
1381
3481
|
const {
|
|
1382
3482
|
responseHeaders,
|
|
1383
3483
|
value: response,
|
|
1384
3484
|
rawValue: rawResponse
|
|
1385
|
-
} = await
|
|
3485
|
+
} = await postJsonToApi({
|
|
1386
3486
|
url: this.config.url({
|
|
1387
3487
|
path: "/completions",
|
|
1388
3488
|
modelId: this.modelId
|
|
1389
3489
|
}),
|
|
1390
|
-
headers:
|
|
3490
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1391
3491
|
body: args,
|
|
1392
3492
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1393
|
-
successfulResponseHandler:
|
|
3493
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1394
3494
|
openaiCompletionResponseSchema
|
|
1395
3495
|
),
|
|
1396
3496
|
abortSignal: options.abortSignal,
|
|
@@ -1404,7 +3504,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1404
3504
|
return {
|
|
1405
3505
|
content: [{ type: "text", text: choice.text }],
|
|
1406
3506
|
usage: {
|
|
1407
|
-
inputTokens: (
|
|
3507
|
+
inputTokens: (_a15 = response.usage) == null ? void 0 : _a15.prompt_tokens,
|
|
1408
3508
|
outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
|
|
1409
3509
|
totalTokens: (_c = response.usage) == null ? void 0 : _c.total_tokens
|
|
1410
3510
|
},
|
|
@@ -1428,15 +3528,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1428
3528
|
include_usage: true
|
|
1429
3529
|
}
|
|
1430
3530
|
};
|
|
1431
|
-
const { responseHeaders, value: response } = await
|
|
3531
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1432
3532
|
url: this.config.url({
|
|
1433
3533
|
path: "/completions",
|
|
1434
3534
|
modelId: this.modelId
|
|
1435
3535
|
}),
|
|
1436
|
-
headers:
|
|
3536
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1437
3537
|
body,
|
|
1438
3538
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1439
|
-
successfulResponseHandler:
|
|
3539
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
1440
3540
|
openaiCompletionChunkSchema
|
|
1441
3541
|
),
|
|
1442
3542
|
abortSignal: options.abortSignal,
|
|
@@ -1558,30 +3658,30 @@ var OpenAIEmbeddingModel = class {
|
|
|
1558
3658
|
abortSignal,
|
|
1559
3659
|
providerOptions
|
|
1560
3660
|
}) {
|
|
1561
|
-
var
|
|
3661
|
+
var _a15;
|
|
1562
3662
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1563
|
-
throw new
|
|
3663
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
1564
3664
|
provider: this.provider,
|
|
1565
3665
|
modelId: this.modelId,
|
|
1566
3666
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1567
3667
|
values
|
|
1568
3668
|
});
|
|
1569
3669
|
}
|
|
1570
|
-
const openaiOptions = (
|
|
3670
|
+
const openaiOptions = (_a15 = await parseProviderOptions({
|
|
1571
3671
|
provider: "openai",
|
|
1572
3672
|
providerOptions,
|
|
1573
3673
|
schema: openaiEmbeddingProviderOptions
|
|
1574
|
-
})) != null ?
|
|
3674
|
+
})) != null ? _a15 : {};
|
|
1575
3675
|
const {
|
|
1576
3676
|
responseHeaders,
|
|
1577
3677
|
value: response,
|
|
1578
3678
|
rawValue
|
|
1579
|
-
} = await
|
|
3679
|
+
} = await postJsonToApi({
|
|
1580
3680
|
url: this.config.url({
|
|
1581
3681
|
path: "/embeddings",
|
|
1582
3682
|
modelId: this.modelId
|
|
1583
3683
|
}),
|
|
1584
|
-
headers:
|
|
3684
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
1585
3685
|
body: {
|
|
1586
3686
|
model: this.modelId,
|
|
1587
3687
|
input: values,
|
|
@@ -1590,7 +3690,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1590
3690
|
user: openaiOptions.user
|
|
1591
3691
|
},
|
|
1592
3692
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1593
|
-
successfulResponseHandler:
|
|
3693
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1594
3694
|
openaiTextEmbeddingResponseSchema
|
|
1595
3695
|
),
|
|
1596
3696
|
abortSignal,
|
|
@@ -1632,8 +3732,8 @@ var OpenAIImageModel = class {
|
|
|
1632
3732
|
this.specificationVersion = "v2";
|
|
1633
3733
|
}
|
|
1634
3734
|
get maxImagesPerCall() {
|
|
1635
|
-
var
|
|
1636
|
-
return (
|
|
3735
|
+
var _a15;
|
|
3736
|
+
return (_a15 = modelMaxImagesPerCall[this.modelId]) != null ? _a15 : 1;
|
|
1637
3737
|
}
|
|
1638
3738
|
get provider() {
|
|
1639
3739
|
return this.config.provider;
|
|
@@ -1648,7 +3748,7 @@ var OpenAIImageModel = class {
|
|
|
1648
3748
|
headers,
|
|
1649
3749
|
abortSignal
|
|
1650
3750
|
}) {
|
|
1651
|
-
var
|
|
3751
|
+
var _a15, _b, _c, _d;
|
|
1652
3752
|
const warnings = [];
|
|
1653
3753
|
if (aspectRatio != null) {
|
|
1654
3754
|
warnings.push({
|
|
@@ -1660,13 +3760,13 @@ var OpenAIImageModel = class {
|
|
|
1660
3760
|
if (seed != null) {
|
|
1661
3761
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1662
3762
|
}
|
|
1663
|
-
const currentDate = (_c = (_b = (
|
|
1664
|
-
const { value: response, responseHeaders } = await
|
|
3763
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3764
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1665
3765
|
url: this.config.url({
|
|
1666
3766
|
path: "/images/generations",
|
|
1667
3767
|
modelId: this.modelId
|
|
1668
3768
|
}),
|
|
1669
|
-
headers:
|
|
3769
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
1670
3770
|
body: {
|
|
1671
3771
|
model: this.modelId,
|
|
1672
3772
|
prompt,
|
|
@@ -1676,7 +3776,7 @@ var OpenAIImageModel = class {
|
|
|
1676
3776
|
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1677
3777
|
},
|
|
1678
3778
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1679
|
-
successfulResponseHandler:
|
|
3779
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1680
3780
|
openaiImageResponseSchema
|
|
1681
3781
|
),
|
|
1682
3782
|
abortSignal,
|
|
@@ -1834,7 +3934,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1834
3934
|
providerOptions
|
|
1835
3935
|
}) {
|
|
1836
3936
|
const warnings = [];
|
|
1837
|
-
const openAIOptions = await
|
|
3937
|
+
const openAIOptions = await parseProviderOptions({
|
|
1838
3938
|
provider: "openai",
|
|
1839
3939
|
providerOptions,
|
|
1840
3940
|
schema: openAITranscriptionProviderOptions
|
|
@@ -1880,8 +3980,8 @@ var OpenAITranscriptionModel = class {
|
|
|
1880
3980
|
};
|
|
1881
3981
|
}
|
|
1882
3982
|
async doGenerate(options) {
|
|
1883
|
-
var
|
|
1884
|
-
const currentDate = (_c = (_b = (
|
|
3983
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h;
|
|
3984
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1885
3985
|
const { formData, warnings } = await this.getArgs(options);
|
|
1886
3986
|
const {
|
|
1887
3987
|
value: response,
|
|
@@ -1892,10 +3992,10 @@ var OpenAITranscriptionModel = class {
|
|
|
1892
3992
|
path: "/audio/transcriptions",
|
|
1893
3993
|
modelId: this.modelId
|
|
1894
3994
|
}),
|
|
1895
|
-
headers:
|
|
3995
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1896
3996
|
formData,
|
|
1897
3997
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1898
|
-
successfulResponseHandler:
|
|
3998
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1899
3999
|
openaiTranscriptionResponseSchema
|
|
1900
4000
|
),
|
|
1901
4001
|
abortSignal: options.abortSignal,
|
|
@@ -1952,7 +4052,7 @@ var OpenAISpeechModel = class {
|
|
|
1952
4052
|
providerOptions
|
|
1953
4053
|
}) {
|
|
1954
4054
|
const warnings = [];
|
|
1955
|
-
const openAIOptions = await
|
|
4055
|
+
const openAIOptions = await parseProviderOptions({
|
|
1956
4056
|
provider: "openai",
|
|
1957
4057
|
providerOptions,
|
|
1958
4058
|
schema: openaiSpeechProviderOptionsSchema
|
|
@@ -1998,19 +4098,19 @@ var OpenAISpeechModel = class {
|
|
|
1998
4098
|
};
|
|
1999
4099
|
}
|
|
2000
4100
|
async doGenerate(options) {
|
|
2001
|
-
var
|
|
2002
|
-
const currentDate = (_c = (_b = (
|
|
4101
|
+
var _a15, _b, _c;
|
|
4102
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2003
4103
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
2004
4104
|
const {
|
|
2005
4105
|
value: audio,
|
|
2006
4106
|
responseHeaders,
|
|
2007
4107
|
rawValue: rawResponse
|
|
2008
|
-
} = await
|
|
4108
|
+
} = await postJsonToApi({
|
|
2009
4109
|
url: this.config.url({
|
|
2010
4110
|
path: "/audio/speech",
|
|
2011
4111
|
modelId: this.modelId
|
|
2012
4112
|
}),
|
|
2013
|
-
headers:
|
|
4113
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
2014
4114
|
body: requestBody,
|
|
2015
4115
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2016
4116
|
successfulResponseHandler: createBinaryResponseHandler(),
|
|
@@ -2049,12 +4149,6 @@ var localShellInputSchema = lazySchema(
|
|
|
2049
4149
|
var localShellOutputSchema = lazySchema(
|
|
2050
4150
|
() => zodSchema(z.object({ output: z.string() }))
|
|
2051
4151
|
);
|
|
2052
|
-
createProviderDefinedToolFactoryWithOutputSchema({
|
|
2053
|
-
id: "openai.local_shell",
|
|
2054
|
-
name: "local_shell",
|
|
2055
|
-
inputSchema: localShellInputSchema,
|
|
2056
|
-
outputSchema: localShellOutputSchema
|
|
2057
|
-
});
|
|
2058
4152
|
function isFileId(data, prefixes) {
|
|
2059
4153
|
if (!prefixes) return false;
|
|
2060
4154
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -2066,7 +4160,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2066
4160
|
store,
|
|
2067
4161
|
hasLocalShellTool = false
|
|
2068
4162
|
}) {
|
|
2069
|
-
var
|
|
4163
|
+
var _a15, _b, _c, _d;
|
|
2070
4164
|
const input = [];
|
|
2071
4165
|
const warnings = [];
|
|
2072
4166
|
for (const { role, content } of prompt) {
|
|
@@ -2101,7 +4195,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2101
4195
|
input.push({
|
|
2102
4196
|
role: "user",
|
|
2103
4197
|
content: content.map((part, index) => {
|
|
2104
|
-
var
|
|
4198
|
+
var _a22, _b2, _c2;
|
|
2105
4199
|
switch (part.type) {
|
|
2106
4200
|
case "text": {
|
|
2107
4201
|
return { type: "input_text", text: part.text };
|
|
@@ -2112,9 +4206,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2112
4206
|
return {
|
|
2113
4207
|
type: "input_image",
|
|
2114
4208
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2115
|
-
image_url: `data:${mediaType};base64,${
|
|
4209
|
+
image_url: `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
2116
4210
|
},
|
|
2117
|
-
detail: (_b2 = (
|
|
4211
|
+
detail: (_b2 = (_a22 = part.providerOptions) == null ? void 0 : _a22.openai) == null ? void 0 : _b2.imageDetail
|
|
2118
4212
|
};
|
|
2119
4213
|
} else if (part.mediaType === "application/pdf") {
|
|
2120
4214
|
if (part.data instanceof URL) {
|
|
@@ -2127,11 +4221,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
2127
4221
|
type: "input_file",
|
|
2128
4222
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2129
4223
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
2130
|
-
file_data: `data:application/pdf;base64,${
|
|
4224
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
2131
4225
|
}
|
|
2132
4226
|
};
|
|
2133
4227
|
} else {
|
|
2134
|
-
throw new
|
|
4228
|
+
throw new UnsupportedFunctionalityError({
|
|
2135
4229
|
functionality: `file part media type ${part.mediaType}`
|
|
2136
4230
|
});
|
|
2137
4231
|
}
|
|
@@ -2146,7 +4240,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2146
4240
|
for (const part of content) {
|
|
2147
4241
|
switch (part.type) {
|
|
2148
4242
|
case "text": {
|
|
2149
|
-
const id = (_b = (
|
|
4243
|
+
const id = (_b = (_a15 = part.providerOptions) == null ? void 0 : _a15.openai) == null ? void 0 : _b.itemId;
|
|
2150
4244
|
if (store && id != null) {
|
|
2151
4245
|
input.push({ type: "item_reference", id });
|
|
2152
4246
|
break;
|
|
@@ -2209,7 +4303,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2209
4303
|
break;
|
|
2210
4304
|
}
|
|
2211
4305
|
case "reasoning": {
|
|
2212
|
-
const providerOptions = await
|
|
4306
|
+
const providerOptions = await parseProviderOptions({
|
|
2213
4307
|
provider: "openai",
|
|
2214
4308
|
providerOptions: part.providerOptions,
|
|
2215
4309
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
@@ -2960,40 +5054,6 @@ var webSearchArgsSchema = lazySchema(
|
|
|
2960
5054
|
})
|
|
2961
5055
|
)
|
|
2962
5056
|
);
|
|
2963
|
-
var webSearchInputSchema = lazySchema(() => zodSchema(z.object({})));
|
|
2964
|
-
var webSearchOutputSchema = lazySchema(
|
|
2965
|
-
() => zodSchema(
|
|
2966
|
-
z.object({
|
|
2967
|
-
action: z.discriminatedUnion("type", [
|
|
2968
|
-
z.object({
|
|
2969
|
-
type: z.literal("search"),
|
|
2970
|
-
query: z.string().optional()
|
|
2971
|
-
}),
|
|
2972
|
-
z.object({
|
|
2973
|
-
type: z.literal("openPage"),
|
|
2974
|
-
url: z.string()
|
|
2975
|
-
}),
|
|
2976
|
-
z.object({
|
|
2977
|
-
type: z.literal("find"),
|
|
2978
|
-
url: z.string(),
|
|
2979
|
-
pattern: z.string()
|
|
2980
|
-
})
|
|
2981
|
-
]),
|
|
2982
|
-
sources: z.array(
|
|
2983
|
-
z.discriminatedUnion("type", [
|
|
2984
|
-
z.object({ type: z.literal("url"), url: z.string() }),
|
|
2985
|
-
z.object({ type: z.literal("api"), name: z.string() })
|
|
2986
|
-
])
|
|
2987
|
-
).optional()
|
|
2988
|
-
})
|
|
2989
|
-
)
|
|
2990
|
-
);
|
|
2991
|
-
createProviderDefinedToolFactoryWithOutputSchema({
|
|
2992
|
-
id: "openai.web_search",
|
|
2993
|
-
name: "web_search",
|
|
2994
|
-
inputSchema: webSearchInputSchema,
|
|
2995
|
-
outputSchema: webSearchOutputSchema
|
|
2996
|
-
});
|
|
2997
5057
|
var webSearchPreviewArgsSchema = lazySchema(
|
|
2998
5058
|
() => zodSchema(
|
|
2999
5059
|
z.object({
|
|
@@ -3081,22 +5141,22 @@ async function prepareResponsesTools({
|
|
|
3081
5141
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
3082
5142
|
}
|
|
3083
5143
|
const openaiTools = [];
|
|
3084
|
-
for (const
|
|
3085
|
-
switch (
|
|
5144
|
+
for (const tool2 of tools) {
|
|
5145
|
+
switch (tool2.type) {
|
|
3086
5146
|
case "function":
|
|
3087
5147
|
openaiTools.push({
|
|
3088
5148
|
type: "function",
|
|
3089
|
-
name:
|
|
3090
|
-
description:
|
|
3091
|
-
parameters:
|
|
5149
|
+
name: tool2.name,
|
|
5150
|
+
description: tool2.description,
|
|
5151
|
+
parameters: tool2.inputSchema,
|
|
3092
5152
|
strict: strictJsonSchema
|
|
3093
5153
|
});
|
|
3094
5154
|
break;
|
|
3095
5155
|
case "provider-defined": {
|
|
3096
|
-
switch (
|
|
5156
|
+
switch (tool2.id) {
|
|
3097
5157
|
case "openai.file_search": {
|
|
3098
5158
|
const args = await validateTypes({
|
|
3099
|
-
value:
|
|
5159
|
+
value: tool2.args,
|
|
3100
5160
|
schema: fileSearchArgsSchema
|
|
3101
5161
|
});
|
|
3102
5162
|
openaiTools.push({
|
|
@@ -3119,7 +5179,7 @@ async function prepareResponsesTools({
|
|
|
3119
5179
|
}
|
|
3120
5180
|
case "openai.web_search_preview": {
|
|
3121
5181
|
const args = await validateTypes({
|
|
3122
|
-
value:
|
|
5182
|
+
value: tool2.args,
|
|
3123
5183
|
schema: webSearchPreviewArgsSchema
|
|
3124
5184
|
});
|
|
3125
5185
|
openaiTools.push({
|
|
@@ -3131,7 +5191,7 @@ async function prepareResponsesTools({
|
|
|
3131
5191
|
}
|
|
3132
5192
|
case "openai.web_search": {
|
|
3133
5193
|
const args = await validateTypes({
|
|
3134
|
-
value:
|
|
5194
|
+
value: tool2.args,
|
|
3135
5195
|
schema: webSearchArgsSchema
|
|
3136
5196
|
});
|
|
3137
5197
|
openaiTools.push({
|
|
@@ -3145,7 +5205,7 @@ async function prepareResponsesTools({
|
|
|
3145
5205
|
}
|
|
3146
5206
|
case "openai.code_interpreter": {
|
|
3147
5207
|
const args = await validateTypes({
|
|
3148
|
-
value:
|
|
5208
|
+
value: tool2.args,
|
|
3149
5209
|
schema: codeInterpreterArgsSchema
|
|
3150
5210
|
});
|
|
3151
5211
|
openaiTools.push({
|
|
@@ -3156,7 +5216,7 @@ async function prepareResponsesTools({
|
|
|
3156
5216
|
}
|
|
3157
5217
|
case "openai.image_generation": {
|
|
3158
5218
|
const args = await validateTypes({
|
|
3159
|
-
value:
|
|
5219
|
+
value: tool2.args,
|
|
3160
5220
|
schema: imageGenerationArgsSchema
|
|
3161
5221
|
});
|
|
3162
5222
|
openaiTools.push({
|
|
@@ -3180,7 +5240,7 @@ async function prepareResponsesTools({
|
|
|
3180
5240
|
break;
|
|
3181
5241
|
}
|
|
3182
5242
|
default:
|
|
3183
|
-
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
5243
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
|
|
3184
5244
|
break;
|
|
3185
5245
|
}
|
|
3186
5246
|
}
|
|
@@ -3201,7 +5261,7 @@ async function prepareResponsesTools({
|
|
|
3201
5261
|
};
|
|
3202
5262
|
default: {
|
|
3203
5263
|
const _exhaustiveCheck = type;
|
|
3204
|
-
throw new
|
|
5264
|
+
throw new UnsupportedFunctionalityError({
|
|
3205
5265
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
3206
5266
|
});
|
|
3207
5267
|
}
|
|
@@ -3235,7 +5295,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3235
5295
|
toolChoice,
|
|
3236
5296
|
responseFormat
|
|
3237
5297
|
}) {
|
|
3238
|
-
var
|
|
5298
|
+
var _a15, _b, _c, _d;
|
|
3239
5299
|
const warnings = [];
|
|
3240
5300
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
3241
5301
|
if (topK != null) {
|
|
@@ -3259,7 +5319,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3259
5319
|
if (stopSequences != null) {
|
|
3260
5320
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
3261
5321
|
}
|
|
3262
|
-
const openaiOptions = await
|
|
5322
|
+
const openaiOptions = await parseProviderOptions({
|
|
3263
5323
|
provider: "openai",
|
|
3264
5324
|
providerOptions,
|
|
3265
5325
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -3275,7 +5335,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3275
5335
|
prompt,
|
|
3276
5336
|
systemMessageMode: modelConfig.systemMessageMode,
|
|
3277
5337
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
3278
|
-
store: (
|
|
5338
|
+
store: (_a15 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a15 : true,
|
|
3279
5339
|
hasLocalShellTool: hasOpenAITool("openai.local_shell")
|
|
3280
5340
|
});
|
|
3281
5341
|
warnings.push(...inputWarnings);
|
|
@@ -3290,7 +5350,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3290
5350
|
}
|
|
3291
5351
|
function hasOpenAITool(id) {
|
|
3292
5352
|
return (tools == null ? void 0 : tools.find(
|
|
3293
|
-
(
|
|
5353
|
+
(tool2) => tool2.type === "provider-defined" && tool2.id === id
|
|
3294
5354
|
)) != null;
|
|
3295
5355
|
}
|
|
3296
5356
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
@@ -3298,7 +5358,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3298
5358
|
addInclude("message.output_text.logprobs");
|
|
3299
5359
|
}
|
|
3300
5360
|
const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
|
|
3301
|
-
(
|
|
5361
|
+
(tool2) => tool2.type === "provider-defined" && (tool2.id === "openai.web_search" || tool2.id === "openai.web_search_preview")
|
|
3302
5362
|
)) == null ? void 0 : _c.name;
|
|
3303
5363
|
if (webSearchToolName) {
|
|
3304
5364
|
addInclude("web_search_call.action.sources");
|
|
@@ -3430,7 +5490,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3430
5490
|
};
|
|
3431
5491
|
}
|
|
3432
5492
|
async doGenerate(options) {
|
|
3433
|
-
var
|
|
5493
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
3434
5494
|
const {
|
|
3435
5495
|
args: body,
|
|
3436
5496
|
warnings,
|
|
@@ -3444,12 +5504,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3444
5504
|
responseHeaders,
|
|
3445
5505
|
value: response,
|
|
3446
5506
|
rawValue: rawResponse
|
|
3447
|
-
} = await
|
|
5507
|
+
} = await postJsonToApi({
|
|
3448
5508
|
url,
|
|
3449
|
-
headers:
|
|
5509
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3450
5510
|
body,
|
|
3451
5511
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
3452
|
-
successfulResponseHandler:
|
|
5512
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
3453
5513
|
openaiResponsesResponseSchema
|
|
3454
5514
|
),
|
|
3455
5515
|
abortSignal: options.abortSignal,
|
|
@@ -3482,7 +5542,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3482
5542
|
providerMetadata: {
|
|
3483
5543
|
openai: {
|
|
3484
5544
|
itemId: part.id,
|
|
3485
|
-
reasoningEncryptedContent: (
|
|
5545
|
+
reasoningEncryptedContent: (_a15 = part.encrypted_content) != null ? _a15 : null
|
|
3486
5546
|
}
|
|
3487
5547
|
}
|
|
3488
5548
|
});
|
|
@@ -3543,7 +5603,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3543
5603
|
content.push({
|
|
3544
5604
|
type: "source",
|
|
3545
5605
|
sourceType: "url",
|
|
3546
|
-
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f :
|
|
5606
|
+
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : generateId(),
|
|
3547
5607
|
url: annotation.url,
|
|
3548
5608
|
title: annotation.title
|
|
3549
5609
|
});
|
|
@@ -3551,7 +5611,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3551
5611
|
content.push({
|
|
3552
5612
|
type: "source",
|
|
3553
5613
|
sourceType: "document",
|
|
3554
|
-
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i :
|
|
5614
|
+
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId(),
|
|
3555
5615
|
mediaType: "text/plain",
|
|
3556
5616
|
title: (_k = (_j = annotation.quote) != null ? _j : annotation.filename) != null ? _k : "Document",
|
|
3557
5617
|
filename: (_l = annotation.filename) != null ? _l : annotation.file_id,
|
|
@@ -3714,18 +5774,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3714
5774
|
webSearchToolName,
|
|
3715
5775
|
store
|
|
3716
5776
|
} = await this.getArgs(options);
|
|
3717
|
-
const { responseHeaders, value: response } = await
|
|
5777
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
3718
5778
|
url: this.config.url({
|
|
3719
5779
|
path: "/responses",
|
|
3720
5780
|
modelId: this.modelId
|
|
3721
5781
|
}),
|
|
3722
|
-
headers:
|
|
5782
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3723
5783
|
body: {
|
|
3724
5784
|
...body,
|
|
3725
5785
|
stream: true
|
|
3726
5786
|
},
|
|
3727
5787
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
3728
|
-
successfulResponseHandler:
|
|
5788
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
3729
5789
|
openaiResponsesChunkSchema
|
|
3730
5790
|
),
|
|
3731
5791
|
abortSignal: options.abortSignal,
|
|
@@ -3752,7 +5812,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3752
5812
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3753
5813
|
},
|
|
3754
5814
|
transform(chunk, controller) {
|
|
3755
|
-
var
|
|
5815
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
3756
5816
|
if (options.includeRawChunks) {
|
|
3757
5817
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3758
5818
|
}
|
|
@@ -3863,7 +5923,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3863
5923
|
providerMetadata: {
|
|
3864
5924
|
openai: {
|
|
3865
5925
|
itemId: value.item.id,
|
|
3866
|
-
reasoningEncryptedContent: (
|
|
5926
|
+
reasoningEncryptedContent: (_a15 = value.item.encrypted_content) != null ? _a15 : null
|
|
3867
5927
|
}
|
|
3868
5928
|
}
|
|
3869
5929
|
});
|
|
@@ -4129,7 +6189,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4129
6189
|
controller.enqueue({
|
|
4130
6190
|
type: "source",
|
|
4131
6191
|
sourceType: "url",
|
|
4132
|
-
id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p :
|
|
6192
|
+
id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId(),
|
|
4133
6193
|
url: value.annotation.url,
|
|
4134
6194
|
title: value.annotation.title
|
|
4135
6195
|
});
|
|
@@ -4137,7 +6197,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4137
6197
|
controller.enqueue({
|
|
4138
6198
|
type: "source",
|
|
4139
6199
|
sourceType: "document",
|
|
4140
|
-
id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s :
|
|
6200
|
+
id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId(),
|
|
4141
6201
|
mediaType: "text/plain",
|
|
4142
6202
|
title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
|
|
4143
6203
|
filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id,
|
|
@@ -4250,11 +6310,11 @@ function getResponsesModelConfig(modelId) {
|
|
|
4250
6310
|
};
|
|
4251
6311
|
}
|
|
4252
6312
|
function mapWebSearchOutput(action) {
|
|
4253
|
-
var
|
|
6313
|
+
var _a15;
|
|
4254
6314
|
switch (action.type) {
|
|
4255
6315
|
case "search":
|
|
4256
6316
|
return {
|
|
4257
|
-
action: { type: "search", query: (
|
|
6317
|
+
action: { type: "search", query: (_a15 = action.query) != null ? _a15 : void 0 },
|
|
4258
6318
|
// include sources when provided by the Responses API (behind include flag)
|
|
4259
6319
|
...action.sources != null && { sources: action.sources }
|
|
4260
6320
|
};
|
|
@@ -4274,19 +6334,19 @@ var azureOpenaiTools = {
|
|
|
4274
6334
|
imageGeneration,
|
|
4275
6335
|
webSearchPreview
|
|
4276
6336
|
};
|
|
4277
|
-
var
|
|
6337
|
+
var VERSION2 = "2.0.74" ;
|
|
4278
6338
|
function createAzure(options = {}) {
|
|
4279
|
-
var
|
|
6339
|
+
var _a15;
|
|
4280
6340
|
const getHeaders = () => {
|
|
4281
6341
|
const baseHeaders = {
|
|
4282
|
-
"api-key":
|
|
6342
|
+
"api-key": loadApiKey({
|
|
4283
6343
|
apiKey: options.apiKey,
|
|
4284
6344
|
environmentVariableName: "AZURE_API_KEY",
|
|
4285
6345
|
description: "Azure OpenAI"
|
|
4286
6346
|
}),
|
|
4287
6347
|
...options.headers
|
|
4288
6348
|
};
|
|
4289
|
-
return
|
|
6349
|
+
return withUserAgentSuffix(baseHeaders, `ai-sdk/azure/${VERSION2}`);
|
|
4290
6350
|
};
|
|
4291
6351
|
const getResourceName = () => loadSetting({
|
|
4292
6352
|
settingValue: options.resourceName,
|
|
@@ -4294,10 +6354,10 @@ function createAzure(options = {}) {
|
|
|
4294
6354
|
environmentVariableName: "AZURE_RESOURCE_NAME",
|
|
4295
6355
|
description: "Azure OpenAI resource name"
|
|
4296
6356
|
});
|
|
4297
|
-
const apiVersion = (
|
|
6357
|
+
const apiVersion = (_a15 = options.apiVersion) != null ? _a15 : "v1";
|
|
4298
6358
|
const url = ({ path, modelId }) => {
|
|
4299
|
-
var
|
|
4300
|
-
const baseUrlPrefix = (
|
|
6359
|
+
var _a22;
|
|
6360
|
+
const baseUrlPrefix = (_a22 = options.baseURL) != null ? _a22 : `https://${getResourceName()}.openai.azure.com/openai`;
|
|
4301
6361
|
let fullUrl;
|
|
4302
6362
|
if (options.useDeploymentBasedUrls) {
|
|
4303
6363
|
fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`);
|
|
@@ -4610,8 +6670,8 @@ function findGatewayForModel(gatewayId, gateways) {
|
|
|
4610
6670
|
function isLanguageModelV3(model) {
|
|
4611
6671
|
return model.specificationVersion === "v3";
|
|
4612
6672
|
}
|
|
4613
|
-
function getStaticProvidersByGateway(
|
|
4614
|
-
return Object.fromEntries(Object.entries(PROVIDER_REGISTRY).filter(([_provider, config]) => config.gateway ===
|
|
6673
|
+
function getStaticProvidersByGateway(name14) {
|
|
6674
|
+
return Object.fromEntries(Object.entries(PROVIDER_REGISTRY).filter(([_provider, config]) => config.gateway === name14));
|
|
4615
6675
|
}
|
|
4616
6676
|
var defaultGateways = [new NetlifyGateway(), new ModelsDevGateway(getStaticProvidersByGateway(`models.dev`))];
|
|
4617
6677
|
var ModelRouterLanguageModel = class _ModelRouterLanguageModel {
|
|
@@ -4837,6 +6897,12 @@ async function resolveModelConfig(modelConfig, requestContext = new RequestConte
|
|
|
4837
6897
|
if (modelConfig.specificationVersion === "v3") {
|
|
4838
6898
|
return new AISDKV6LanguageModel(modelConfig);
|
|
4839
6899
|
}
|
|
6900
|
+
if (modelConfig.specificationVersion === "v1") {
|
|
6901
|
+
return modelConfig;
|
|
6902
|
+
}
|
|
6903
|
+
if (typeof modelConfig.doStream === "function" && typeof modelConfig.doGenerate === "function") {
|
|
6904
|
+
return new AISDKV5LanguageModel(modelConfig);
|
|
6905
|
+
}
|
|
4840
6906
|
return modelConfig;
|
|
4841
6907
|
}
|
|
4842
6908
|
const gatewayRecord = mastra?.listGateways();
|
|
@@ -4982,5 +7048,5 @@ var ModelRouterEmbeddingModel = class {
|
|
|
4982
7048
|
};
|
|
4983
7049
|
|
|
4984
7050
|
export { AzureOpenAIGateway, EMBEDDING_MODELS, ModelRouterEmbeddingModel, ModelRouterLanguageModel, resolveModelConfig };
|
|
4985
|
-
//# sourceMappingURL=chunk-
|
|
4986
|
-
//# sourceMappingURL=chunk-
|
|
7051
|
+
//# sourceMappingURL=chunk-BXLLXTT4.js.map
|
|
7052
|
+
//# sourceMappingURL=chunk-BXLLXTT4.js.map
|