@mastra/core 1.0.0-beta.11 → 1.0.0-beta.13
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 +173 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7549 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/test.d.ts +65 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +8396 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/test.d.ts +1708 -0
- package/dist/_types/@internal_external-types/dist/index.d.ts +858 -0
- package/dist/agent/agent-legacy.d.ts +1 -1
- package/dist/agent/agent.d.ts +1 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +5 -1
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.d.ts +4 -3
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/message-list/prompt/attachments-to-parts.d.ts +1 -1
- package/dist/agent/message-list/prompt/invalid-content-error.d.ts +1 -1
- package/dist/agent/message-list/types.d.ts +3 -3
- package/dist/agent/message-list/types.d.ts.map +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/core-model-message.d.ts +1 -1
- package/dist/agent/message-list/utils/ai-v4-v5/ui-message.d.ts +1 -1
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts +2 -2
- package/dist/agent/message-list/utils/ai-v5/gemini-compatibility.d.ts.map +1 -1
- package/dist/agent/message-list/utils/convert-messages.d.ts +2 -2
- package/dist/agent/message-list/utils/convert-messages.d.ts.map +1 -1
- package/dist/agent/types.d.ts +3 -3
- package/dist/agent/utils.d.ts +3 -3
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-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/bundler/types.d.ts +14 -1
- package/dist/bundler/types.d.ts.map +1 -1
- package/dist/{chunk-U3XOLEPX.js → chunk-2IU4RGU5.js} +6 -32
- package/dist/chunk-2IU4RGU5.js.map +1 -0
- package/dist/chunk-2SQB3WBT.js +4574 -0
- package/dist/chunk-2SQB3WBT.js.map +1 -0
- package/dist/{chunk-THZTRBFS.js → chunk-373OC54J.js} +8 -8
- package/dist/chunk-373OC54J.js.map +1 -0
- package/dist/{chunk-F2GAJSBI.js → chunk-4BC5FUAO.js} +8 -6
- package/dist/{chunk-F2GAJSBI.js.map → chunk-4BC5FUAO.js.map} +1 -1
- package/dist/chunk-55VPMN3N.js +250 -0
- package/dist/chunk-55VPMN3N.js.map +1 -0
- package/dist/{chunk-QM5SRDJX.js → chunk-5PTZG26U.js} +66 -84
- package/dist/chunk-5PTZG26U.js.map +1 -0
- package/dist/chunk-5VZGJTPR.js +4837 -0
- package/dist/chunk-5VZGJTPR.js.map +1 -0
- package/dist/{chunk-C36YRTZ6.js → chunk-62Q7K656.js} +6 -7
- package/dist/chunk-62Q7K656.js.map +1 -0
- package/dist/chunk-6PMMP3FR.js +7 -0
- package/dist/chunk-6PMMP3FR.js.map +1 -0
- package/dist/{chunk-DZUJEN5N.cjs → chunk-6SZKM6EC.cjs} +10 -3
- package/dist/{chunk-DZUJEN5N.cjs.map → chunk-6SZKM6EC.cjs.map} +1 -1
- package/dist/{chunk-5WRI5ZAA.js → chunk-7D4SUZUM.js} +10 -4
- package/dist/{chunk-5WRI5ZAA.js.map → chunk-7D4SUZUM.js.map} +1 -1
- package/dist/{chunk-YWMMBIOM.cjs → chunk-7HEAVZRS.cjs} +15 -15
- package/dist/{chunk-YWMMBIOM.cjs.map → chunk-7HEAVZRS.cjs.map} +1 -1
- package/dist/{chunk-BUKY6CTR.cjs → chunk-AGHLXC4I.cjs} +106 -36
- package/dist/chunk-AGHLXC4I.cjs.map +1 -0
- package/dist/{chunk-PK2A5WBG.js → chunk-ARAQIW6E.js} +222 -604
- package/dist/chunk-ARAQIW6E.js.map +1 -0
- package/dist/{chunk-US2U7ECW.js → chunk-BQDZIQ3G.js} +156 -90
- package/dist/chunk-BQDZIQ3G.js.map +1 -0
- package/dist/chunk-D22XABFZ.js +79 -0
- package/dist/chunk-D22XABFZ.js.map +1 -0
- package/dist/{chunk-2ULLRN4Y.js → chunk-E5BQRAJK.js} +943 -626
- package/dist/chunk-E5BQRAJK.js.map +1 -0
- package/dist/chunk-FST2G2FQ.cjs +84 -0
- package/dist/chunk-FST2G2FQ.cjs.map +1 -0
- package/dist/chunk-FVQTJUBD.cjs +2120 -0
- package/dist/chunk-FVQTJUBD.cjs.map +1 -0
- package/dist/chunk-G6E6V2Z4.js +2070 -0
- package/dist/chunk-G6E6V2Z4.js.map +1 -0
- package/dist/{chunk-7P6BNIJH.js → chunk-GIWC35YQ.js} +105 -35
- package/dist/chunk-GIWC35YQ.js.map +1 -0
- package/dist/{chunk-4JKEUSCC.cjs → chunk-H4VUIOWU.cjs} +22 -20
- package/dist/chunk-H4VUIOWU.cjs.map +1 -0
- package/dist/{chunk-TWH4PTDG.cjs → chunk-HWMMIRIF.cjs} +32 -27
- package/dist/chunk-HWMMIRIF.cjs.map +1 -0
- package/dist/chunk-IXZ2T2QX.cjs +448 -0
- package/dist/chunk-IXZ2T2QX.cjs.map +1 -0
- package/dist/chunk-L3NKIMF5.cjs +10 -0
- package/dist/chunk-L3NKIMF5.cjs.map +1 -0
- package/dist/chunk-L4JCRWDY.cjs +252 -0
- package/dist/chunk-L4JCRWDY.cjs.map +1 -0
- package/dist/{chunk-BJXKH4LG.cjs → chunk-LGB4VNZI.cjs} +43 -78
- package/dist/chunk-LGB4VNZI.cjs.map +1 -0
- package/dist/{chunk-PG5H6QIO.cjs → chunk-MLKE7HRS.cjs} +41 -21
- package/dist/chunk-MLKE7HRS.cjs.map +1 -0
- package/dist/{chunk-OEIVMCWX.js → chunk-MRRFTNF4.js} +2537 -84
- package/dist/chunk-MRRFTNF4.js.map +1 -0
- package/dist/chunk-MXBVP7HX.cjs +4842 -0
- package/dist/chunk-MXBVP7HX.cjs.map +1 -0
- package/dist/chunk-NESKUIRE.cjs +4586 -0
- package/dist/chunk-NESKUIRE.cjs.map +1 -0
- package/dist/{chunk-SVLMF4UZ.cjs → chunk-NIOEY3N3.cjs} +66 -85
- package/dist/chunk-NIOEY3N3.cjs.map +1 -0
- package/dist/{chunk-CZEJQSWB.cjs → chunk-OWIEOL55.cjs} +295 -677
- package/dist/chunk-OWIEOL55.cjs.map +1 -0
- package/dist/{chunk-WTSZBHIZ.cjs → chunk-PJAK4U6R.cjs} +24 -24
- package/dist/{chunk-WTSZBHIZ.cjs.map → chunk-PJAK4U6R.cjs.map} +1 -1
- package/dist/{chunk-52RSUALV.cjs → chunk-R5AJGM55.cjs} +1314 -995
- package/dist/chunk-R5AJGM55.cjs.map +1 -0
- package/dist/{chunk-IVV5TOMD.js → chunk-RCJLMMTO.js} +32 -12
- package/dist/chunk-RCJLMMTO.js.map +1 -0
- package/dist/{chunk-S73Z3PBJ.cjs → chunk-SZYSDJTN.cjs} +27 -28
- package/dist/chunk-SZYSDJTN.cjs.map +1 -0
- package/dist/{chunk-YC6PJEPH.cjs → chunk-U4CSOY6T.cjs} +188 -122
- package/dist/chunk-U4CSOY6T.cjs.map +1 -0
- package/dist/chunk-UBSPZTQX.js +434 -0
- package/dist/chunk-UBSPZTQX.js.map +1 -0
- package/dist/{chunk-SCUWP4II.cjs → chunk-VEPP75C4.cjs} +47 -74
- package/dist/chunk-VEPP75C4.cjs.map +1 -0
- package/dist/{chunk-JIGDJK2O.js → chunk-VETAQUW3.js} +4 -39
- package/dist/chunk-VETAQUW3.js.map +1 -0
- package/dist/{chunk-Z57R5WS4.js → chunk-WPTTKULS.js} +4 -4
- package/dist/{chunk-Z57R5WS4.js.map → chunk-WPTTKULS.js.map} +1 -1
- package/dist/{chunk-O2BJW7YA.js → chunk-WYGUWVTF.js} +5 -5
- package/dist/{chunk-O2BJW7YA.js.map → chunk-WYGUWVTF.js.map} +1 -1
- package/dist/{chunk-SXNQRJQD.js → chunk-WYWRMIQC.js} +127 -22
- package/dist/chunk-WYWRMIQC.js.map +1 -0
- package/dist/{chunk-5Q6WAYEY.cjs → chunk-X6IBA7FP.cjs} +137 -50
- package/dist/chunk-X6IBA7FP.cjs.map +1 -0
- package/dist/{chunk-MRFUISXC.cjs → chunk-Y7MZ5LJT.cjs} +2632 -179
- package/dist/chunk-Y7MZ5LJT.cjs.map +1 -0
- package/dist/{chunk-JJ5O45LH.js → chunk-YPLZDWG7.js} +32 -27
- package/dist/chunk-YPLZDWG7.js.map +1 -0
- package/dist/{chunk-MGCGWPQJ.cjs → chunk-Z55SJVEC.cjs} +8 -8
- package/dist/chunk-Z55SJVEC.cjs.map +1 -0
- package/dist/error/index.cjs +6 -6
- package/dist/error/index.d.ts +26 -20
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +1 -1
- package/dist/error/utils.d.ts +19 -5
- package/dist/error/utils.d.ts.map +1 -1
- package/dist/evals/index.cjs +4 -4
- package/dist/evals/index.js +1 -1
- package/dist/evals/run/index.d.ts +1 -1
- package/dist/evals/scoreTraces/index.cjs +8 -8
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/evals/types.d.ts +1 -1
- package/dist/events/event-emitter.d.ts +6 -1
- package/dist/events/event-emitter.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +15 -15
- package/dist/llm/index.d.ts +2 -2
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/aisdk/v5/model.d.ts +1 -1
- package/dist/llm/model/base.types.d.ts +2 -2
- package/dist/llm/model/model.d.ts +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +2 -2
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/model.loop.types.d.ts +1 -1
- package/dist/llm/model/model.loop.types.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +51 -11
- package/dist/llm/model/shared.types.d.ts +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/loop.d.ts +2 -2
- package/dist/loop/loop.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/test-utils/streamObject.d.ts +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/loop/test-utils/tools.d.ts.map +1 -1
- package/dist/loop/types.d.ts +3 -1
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +13 -13
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +10 -10
- 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 +5 -5
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +22 -21
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +13 -13
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +6 -6
- package/dist/loop/workflows/schema.d.ts.map +1 -1
- package/dist/loop/workflows/stream.d.ts +2 -2
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +4 -4
- package/dist/mcp/index.js +1 -1
- package/dist/memory/index.cjs +6 -6
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +1 -1
- package/dist/memory/types.d.ts +3 -3
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/models-dev-D3EKFGAO.cjs +12 -0
- package/dist/{models-dev-EO3SUIY2.cjs.map → models-dev-D3EKFGAO.cjs.map} +1 -1
- package/dist/models-dev-EO22XOXQ.js +3 -0
- package/dist/{models-dev-23RN2WHG.js.map → models-dev-EO22XOXQ.js.map} +1 -1
- package/dist/netlify-AE4LNCAI.js +3 -0
- package/dist/{netlify-GXJ5D5DD.js.map → netlify-AE4LNCAI.js.map} +1 -1
- package/dist/netlify-WE42TZIT.cjs +12 -0
- package/dist/{netlify-KJLY3GFS.cjs.map → netlify-WE42TZIT.cjs.map} +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +2 -2
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/step-schema.d.ts +1267 -1267
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-6LF3NGC5.js +3 -0
- package/dist/{provider-registry-F67Y6OF2.js.map → provider-registry-6LF3NGC5.js.map} +1 -1
- package/dist/provider-registry-73FKMXJV.cjs +40 -0
- package/dist/{provider-registry-3TG2KUD2.cjs.map → provider-registry-73FKMXJV.cjs.map} +1 -1
- package/dist/provider-registry.json +100 -30
- package/dist/{registry-generator-UMTNPBJX.js → registry-generator-AVQXI3GX.js} +2 -2
- package/dist/{registry-generator-UMTNPBJX.js.map → registry-generator-AVQXI3GX.js.map} +1 -1
- package/dist/{registry-generator-34SC4TAU.cjs → registry-generator-KOFNIIWJ.cjs} +2 -2
- package/dist/{registry-generator-34SC4TAU.cjs.map → registry-generator-KOFNIIWJ.cjs.map} +1 -1
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.cjs +5 -5
- package/dist/server/index.js +1 -1
- package/dist/storage/base.d.ts +2 -10
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/base.d.ts +2 -8
- package/dist/storage/domains/workflows/base.d.ts.map +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts +2 -8
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +38 -38
- package/dist/storage/index.js +1 -1
- package/dist/storage/mock.d.ts +2 -8
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +9 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/RunOutput.d.ts +1 -1
- package/dist/stream/aisdk/v4/input.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/content.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/content.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/validation.d.ts +1 -1
- package/dist/stream/aisdk/v5/compat/validation.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts +2 -2
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/input.d.ts +1 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output-helpers.d.ts +12 -27
- package/dist/stream/aisdk/v5/output-helpers.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/output.d.ts +41 -91
- package/dist/stream/aisdk/v5/output.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts +1 -1
- package/dist/stream/aisdk/v5/transform.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +1 -1
- package/dist/stream/base/output.d.ts +9 -31
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/base/schema.d.ts +2 -2
- package/dist/stream/base/schema.d.ts.map +1 -1
- package/dist/stream/index.cjs +12 -12
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +3 -2
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.cjs +14587 -14
- package/dist/test-utils/llm-mock.cjs.map +1 -1
- package/dist/test-utils/llm-mock.d.ts +3 -3
- package/dist/test-utils/llm-mock.d.ts.map +1 -1
- package/dist/test-utils/llm-mock.js +14577 -4
- package/dist/test-utils/llm-mock.js.map +1 -1
- package/dist/token-6GSAFR2W-SGVIXFCP.cjs +63 -0
- package/dist/token-6GSAFR2W-SGVIXFCP.cjs.map +1 -0
- package/dist/token-6GSAFR2W-SPYPLMBM.js +61 -0
- package/dist/token-6GSAFR2W-SPYPLMBM.js.map +1 -0
- package/dist/token-util-NEHG7TUY-7GMW5FXI.cjs +10 -0
- package/dist/token-util-NEHG7TUY-7GMW5FXI.cjs.map +1 -0
- package/dist/token-util-NEHG7TUY-JRJTGTAB.js +8 -0
- package/dist/token-util-NEHG7TUY-JRJTGTAB.js.map +1 -0
- 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 +2 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +3 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/embed.d.ts +2 -2
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +11 -11
- package/dist/vector/index.js +3 -3
- package/dist/vector/vector.d.ts +1 -1
- package/dist/voice/aisdk/speech.d.ts +1 -1
- package/dist/voice/aisdk/speech.d.ts.map +1 -1
- package/dist/voice/aisdk/transcription.d.ts +1 -1
- package/dist/voice/aisdk/transcription.d.ts.map +1 -1
- package/dist/voice/composite-voice.d.ts +1 -1
- package/dist/voice/composite-voice.d.ts.map +1 -1
- package/dist/voice/index.cjs +6 -6
- package/dist/voice/index.js +1 -1
- package/dist/workflows/constants.cjs +4 -4
- package/dist/workflows/constants.d.ts +1 -1
- package/dist/workflows/constants.d.ts.map +1 -1
- package/dist/workflows/constants.js +1 -1
- package/dist/workflows/default.d.ts +9 -16
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +3 -2
- package/dist/workflows/evented/execution-engine.d.ts.map +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 +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +15 -0
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +25 -2
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts +6 -5
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/entry.d.ts +5 -3
- package/dist/workflows/handlers/entry.d.ts.map +1 -1
- package/dist/workflows/handlers/sleep.d.ts +4 -3
- package/dist/workflows/handlers/sleep.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts +5 -3
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +26 -22
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +5 -4
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +66 -14
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +11 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +26 -8
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/llm/model/provider-types.generated.d.ts +51 -11
- package/dist/agent/__tests__/mock-model.d.ts +0 -8
- package/dist/agent/__tests__/mock-model.d.ts.map +0 -1
- package/dist/agent/agent-types.test-d.d.ts +0 -2
- package/dist/agent/agent-types.test-d.d.ts.map +0 -1
- package/dist/ai-sdk.types.d.ts +0 -4705
- package/dist/chunk-2ULLRN4Y.js.map +0 -1
- package/dist/chunk-3E3ILV6T.cjs +0 -518
- package/dist/chunk-3E3ILV6T.cjs.map +0 -1
- package/dist/chunk-4JKEUSCC.cjs.map +0 -1
- package/dist/chunk-52RSUALV.cjs.map +0 -1
- package/dist/chunk-5PAEYE3Q.js +0 -513
- package/dist/chunk-5PAEYE3Q.js.map +0 -1
- package/dist/chunk-5Q6WAYEY.cjs.map +0 -1
- package/dist/chunk-7P6BNIJH.js.map +0 -1
- package/dist/chunk-ABJOUEVA.cjs +0 -10
- package/dist/chunk-ABJOUEVA.cjs.map +0 -1
- package/dist/chunk-BJXKH4LG.cjs.map +0 -1
- package/dist/chunk-BUKY6CTR.cjs.map +0 -1
- package/dist/chunk-C36YRTZ6.js.map +0 -1
- package/dist/chunk-CZEJQSWB.cjs.map +0 -1
- package/dist/chunk-IVV5TOMD.js.map +0 -1
- package/dist/chunk-JIGDJK2O.js.map +0 -1
- package/dist/chunk-JJ5O45LH.js.map +0 -1
- package/dist/chunk-MGCGWPQJ.cjs.map +0 -1
- package/dist/chunk-MRFUISXC.cjs.map +0 -1
- package/dist/chunk-NLNKQD2T.js +0 -7
- package/dist/chunk-NLNKQD2T.js.map +0 -1
- package/dist/chunk-OEIVMCWX.js.map +0 -1
- package/dist/chunk-PG5H6QIO.cjs.map +0 -1
- package/dist/chunk-PK2A5WBG.js.map +0 -1
- package/dist/chunk-QM5SRDJX.js.map +0 -1
- package/dist/chunk-S73Z3PBJ.cjs.map +0 -1
- package/dist/chunk-SCUWP4II.cjs.map +0 -1
- package/dist/chunk-SVLMF4UZ.cjs.map +0 -1
- package/dist/chunk-SXNQRJQD.js.map +0 -1
- package/dist/chunk-THZTRBFS.js.map +0 -1
- package/dist/chunk-TWH4PTDG.cjs.map +0 -1
- package/dist/chunk-U3XOLEPX.js.map +0 -1
- package/dist/chunk-US2U7ECW.js.map +0 -1
- package/dist/chunk-YC6PJEPH.cjs.map +0 -1
- package/dist/models-dev-23RN2WHG.js +0 -3
- package/dist/models-dev-EO3SUIY2.cjs +0 -12
- package/dist/netlify-GXJ5D5DD.js +0 -3
- package/dist/netlify-KJLY3GFS.cjs +0 -12
- package/dist/provider-registry-3TG2KUD2.cjs +0 -40
- package/dist/provider-registry-F67Y6OF2.js +0 -3
- package/dist/tools/tool-stream-types.test-d.d.ts +0 -2
- package/dist/tools/tool-stream-types.test-d.d.ts.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkOWIEOL55_cjs = require('./chunk-OWIEOL55.cjs');
|
|
4
|
+
var chunkIXZ2T2QX_cjs = require('./chunk-IXZ2T2QX.cjs');
|
|
4
5
|
var z4 = require('zod/v4');
|
|
5
6
|
var v3 = require('zod/v3');
|
|
6
|
-
var aiSdkProviderV5 = require('@openrouter/ai-sdk-provider-v5');
|
|
7
7
|
|
|
8
8
|
function _interopNamespace(e) {
|
|
9
9
|
if (e && e.__esModule) return e;
|
|
@@ -55,7 +55,7 @@ var createIdGenerator = ({
|
|
|
55
55
|
return generator;
|
|
56
56
|
}
|
|
57
57
|
if (alphabet.includes(separator)) {
|
|
58
|
-
throw new
|
|
58
|
+
throw new chunkIXZ2T2QX_cjs.InvalidArgumentError({
|
|
59
59
|
argument: "separator",
|
|
60
60
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
61
61
|
});
|
|
@@ -79,7 +79,7 @@ function handleFetchError({
|
|
|
79
79
|
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
80
80
|
const cause = error.cause;
|
|
81
81
|
if (cause != null) {
|
|
82
|
-
return new
|
|
82
|
+
return new chunkIXZ2T2QX_cjs.APICallError({
|
|
83
83
|
message: `Cannot connect to API: ${cause.message}`,
|
|
84
84
|
cause,
|
|
85
85
|
url,
|
|
@@ -92,11 +92,11 @@ function handleFetchError({
|
|
|
92
92
|
return error;
|
|
93
93
|
}
|
|
94
94
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
95
|
-
var
|
|
95
|
+
var _a15, _b, _c;
|
|
96
96
|
if (globalThisAny.window) {
|
|
97
97
|
return `runtime/browser`;
|
|
98
98
|
}
|
|
99
|
-
if ((
|
|
99
|
+
if ((_a15 = globalThisAny.navigator) == null ? void 0 : _a15.userAgent) {
|
|
100
100
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
101
101
|
}
|
|
102
102
|
if ((_c = (_b = globalThisAny.process) == null ? void 0 : _b.versions) == null ? void 0 : _c.node) {
|
|
@@ -148,23 +148,23 @@ function loadApiKey2({
|
|
|
148
148
|
return apiKey;
|
|
149
149
|
}
|
|
150
150
|
if (apiKey != null) {
|
|
151
|
-
throw new
|
|
151
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
152
152
|
message: `${description} API key must be a string.`
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
if (typeof process === "undefined") {
|
|
156
|
-
throw new
|
|
156
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
157
157
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
apiKey = process.env[environmentVariableName];
|
|
161
161
|
if (apiKey == null) {
|
|
162
|
-
throw new
|
|
162
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
163
163
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
if (typeof apiKey !== "string") {
|
|
167
|
-
throw new
|
|
167
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
168
168
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
169
169
|
});
|
|
170
170
|
}
|
|
@@ -232,7 +232,7 @@ function standardSchemaValidator(standardSchema) {
|
|
|
232
232
|
const result = await standardSchema["~standard"].validate(value);
|
|
233
233
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
234
234
|
success: false,
|
|
235
|
-
error: new
|
|
235
|
+
error: new chunkIXZ2T2QX_cjs.TypeValidationError({
|
|
236
236
|
value,
|
|
237
237
|
cause: result.issues
|
|
238
238
|
})
|
|
@@ -245,7 +245,7 @@ async function validateTypes({
|
|
|
245
245
|
}) {
|
|
246
246
|
const result = await safeValidateTypes({ value, schema });
|
|
247
247
|
if (!result.success) {
|
|
248
|
-
throw
|
|
248
|
+
throw chunkIXZ2T2QX_cjs.TypeValidationError.wrap({ value, cause: result.error });
|
|
249
249
|
}
|
|
250
250
|
return result.value;
|
|
251
251
|
}
|
|
@@ -264,13 +264,13 @@ async function safeValidateTypes({
|
|
|
264
264
|
}
|
|
265
265
|
return {
|
|
266
266
|
success: false,
|
|
267
|
-
error:
|
|
267
|
+
error: chunkIXZ2T2QX_cjs.TypeValidationError.wrap({ value, cause: result.error }),
|
|
268
268
|
rawValue: value
|
|
269
269
|
};
|
|
270
270
|
} catch (error) {
|
|
271
271
|
return {
|
|
272
272
|
success: false,
|
|
273
|
-
error:
|
|
273
|
+
error: chunkIXZ2T2QX_cjs.TypeValidationError.wrap({ value, cause: error }),
|
|
274
274
|
rawValue: value
|
|
275
275
|
};
|
|
276
276
|
}
|
|
@@ -286,10 +286,10 @@ async function parseJSON({
|
|
|
286
286
|
}
|
|
287
287
|
return validateTypes({ value, schema });
|
|
288
288
|
} catch (error) {
|
|
289
|
-
if (
|
|
289
|
+
if (chunkIXZ2T2QX_cjs.JSONParseError.isInstance(error) || chunkIXZ2T2QX_cjs.TypeValidationError.isInstance(error)) {
|
|
290
290
|
throw error;
|
|
291
291
|
}
|
|
292
|
-
throw new
|
|
292
|
+
throw new chunkIXZ2T2QX_cjs.JSONParseError({ text, cause: error });
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
async function safeParseJSON({
|
|
@@ -305,7 +305,7 @@ async function safeParseJSON({
|
|
|
305
305
|
} catch (error) {
|
|
306
306
|
return {
|
|
307
307
|
success: false,
|
|
308
|
-
error:
|
|
308
|
+
error: chunkIXZ2T2QX_cjs.JSONParseError.isInstance(error) ? error : new chunkIXZ2T2QX_cjs.JSONParseError({ text, cause: error }),
|
|
309
309
|
rawValue: void 0
|
|
310
310
|
};
|
|
311
311
|
}
|
|
@@ -322,7 +322,7 @@ function parseJsonEventStream({
|
|
|
322
322
|
stream,
|
|
323
323
|
schema
|
|
324
324
|
}) {
|
|
325
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
325
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new chunkIXZ2T2QX_cjs.EventSourceParserStream()).pipeThrough(
|
|
326
326
|
new TransformStream({
|
|
327
327
|
async transform({ data }, controller) {
|
|
328
328
|
if (data === "[DONE]") {
|
|
@@ -346,7 +346,7 @@ async function parseProviderOptions2({
|
|
|
346
346
|
schema
|
|
347
347
|
});
|
|
348
348
|
if (!parsedProviderOptions.success) {
|
|
349
|
-
throw new
|
|
349
|
+
throw new chunkIXZ2T2QX_cjs.InvalidArgumentError({
|
|
350
350
|
argument: "providerOptions",
|
|
351
351
|
message: `invalid ${provider} provider options`,
|
|
352
352
|
cause: parsedProviderOptions.error
|
|
@@ -408,10 +408,10 @@ var postToApi = async ({
|
|
|
408
408
|
requestBodyValues: body.values
|
|
409
409
|
});
|
|
410
410
|
} catch (error) {
|
|
411
|
-
if (isAbortError(error) ||
|
|
411
|
+
if (isAbortError(error) || chunkIXZ2T2QX_cjs.APICallError.isInstance(error)) {
|
|
412
412
|
throw error;
|
|
413
413
|
}
|
|
414
|
-
throw new
|
|
414
|
+
throw new chunkIXZ2T2QX_cjs.APICallError({
|
|
415
415
|
message: "Failed to process error response",
|
|
416
416
|
cause: error,
|
|
417
417
|
statusCode: response.status,
|
|
@@ -430,11 +430,11 @@ var postToApi = async ({
|
|
|
430
430
|
});
|
|
431
431
|
} catch (error) {
|
|
432
432
|
if (error instanceof Error) {
|
|
433
|
-
if (isAbortError(error) ||
|
|
433
|
+
if (isAbortError(error) || chunkIXZ2T2QX_cjs.APICallError.isInstance(error)) {
|
|
434
434
|
throw error;
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
|
-
throw new
|
|
437
|
+
throw new chunkIXZ2T2QX_cjs.APICallError({
|
|
438
438
|
message: "Failed to process successful response",
|
|
439
439
|
cause: error,
|
|
440
440
|
statusCode: response.status,
|
|
@@ -457,7 +457,7 @@ var createJsonErrorResponseHandler2 = ({
|
|
|
457
457
|
if (responseBody.trim() === "") {
|
|
458
458
|
return {
|
|
459
459
|
responseHeaders,
|
|
460
|
-
value: new
|
|
460
|
+
value: new chunkIXZ2T2QX_cjs.APICallError({
|
|
461
461
|
message: response.statusText,
|
|
462
462
|
url,
|
|
463
463
|
requestBodyValues,
|
|
@@ -475,7 +475,7 @@ var createJsonErrorResponseHandler2 = ({
|
|
|
475
475
|
});
|
|
476
476
|
return {
|
|
477
477
|
responseHeaders,
|
|
478
|
-
value: new
|
|
478
|
+
value: new chunkIXZ2T2QX_cjs.APICallError({
|
|
479
479
|
message: errorToMessage2(parsedError),
|
|
480
480
|
url,
|
|
481
481
|
requestBodyValues,
|
|
@@ -489,7 +489,7 @@ var createJsonErrorResponseHandler2 = ({
|
|
|
489
489
|
} catch (parseError) {
|
|
490
490
|
return {
|
|
491
491
|
responseHeaders,
|
|
492
|
-
value: new
|
|
492
|
+
value: new chunkIXZ2T2QX_cjs.APICallError({
|
|
493
493
|
message: response.statusText,
|
|
494
494
|
url,
|
|
495
495
|
requestBodyValues,
|
|
@@ -504,7 +504,7 @@ var createJsonErrorResponseHandler2 = ({
|
|
|
504
504
|
var createEventSourceResponseHandler2 = (chunkSchema) => async ({ response }) => {
|
|
505
505
|
const responseHeaders = extractResponseHeaders(response);
|
|
506
506
|
if (response.body == null) {
|
|
507
|
-
throw new
|
|
507
|
+
throw new chunkIXZ2T2QX_cjs.EmptyResponseBodyError({});
|
|
508
508
|
}
|
|
509
509
|
return {
|
|
510
510
|
responseHeaders,
|
|
@@ -522,7 +522,7 @@ var createJsonResponseHandler2 = (responseSchema) => async ({ response, url, req
|
|
|
522
522
|
});
|
|
523
523
|
const responseHeaders = extractResponseHeaders(response);
|
|
524
524
|
if (!parsedResult.success) {
|
|
525
|
-
throw new
|
|
525
|
+
throw new chunkIXZ2T2QX_cjs.APICallError({
|
|
526
526
|
message: "Invalid JSON response",
|
|
527
527
|
cause: parsedResult.error,
|
|
528
528
|
statusCode: response.status,
|
|
@@ -580,11 +580,11 @@ function parseAnyDef() {
|
|
|
580
580
|
return {};
|
|
581
581
|
}
|
|
582
582
|
function parseArrayDef(def, refs) {
|
|
583
|
-
var
|
|
583
|
+
var _a15, _b, _c;
|
|
584
584
|
const res = {
|
|
585
585
|
type: "array"
|
|
586
586
|
};
|
|
587
|
-
if (((
|
|
587
|
+
if (((_a15 = def.type) == null ? void 0 : _a15._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== v3.ZodFirstPartyTypeKind.ZodAny) {
|
|
588
588
|
res.items = parseDef(def.type._def, {
|
|
589
589
|
...refs,
|
|
590
590
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -943,8 +943,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
943
943
|
return result;
|
|
944
944
|
}
|
|
945
945
|
function addFormat(schema, value, message, refs) {
|
|
946
|
-
var
|
|
947
|
-
if (schema.format || ((
|
|
946
|
+
var _a15;
|
|
947
|
+
if (schema.format || ((_a15 = schema.anyOf) == null ? void 0 : _a15.some((x) => x.format))) {
|
|
948
948
|
if (!schema.anyOf) {
|
|
949
949
|
schema.anyOf = [];
|
|
950
950
|
}
|
|
@@ -963,8 +963,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
963
963
|
}
|
|
964
964
|
}
|
|
965
965
|
function addPattern(schema, regex, message, refs) {
|
|
966
|
-
var
|
|
967
|
-
if (schema.pattern || ((
|
|
966
|
+
var _a15;
|
|
967
|
+
if (schema.pattern || ((_a15 = schema.allOf) == null ? void 0 : _a15.some((x) => x.pattern))) {
|
|
968
968
|
if (!schema.allOf) {
|
|
969
969
|
schema.allOf = [];
|
|
970
970
|
}
|
|
@@ -983,7 +983,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
985
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
986
|
-
var
|
|
986
|
+
var _a15;
|
|
987
987
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
988
988
|
return regex.source;
|
|
989
989
|
}
|
|
@@ -1013,7 +1013,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1013
1013
|
pattern += source[i];
|
|
1014
1014
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1015
1015
|
inCharRange = false;
|
|
1016
|
-
} else if (source[i + 1] === "-" && ((
|
|
1016
|
+
} else if (source[i + 1] === "-" && ((_a15 = source[i + 2]) == null ? void 0 : _a15.match(/[a-z]/))) {
|
|
1017
1017
|
pattern += source[i];
|
|
1018
1018
|
inCharRange = true;
|
|
1019
1019
|
} else {
|
|
@@ -1055,13 +1055,13 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1055
1055
|
return pattern;
|
|
1056
1056
|
}
|
|
1057
1057
|
function parseRecordDef(def, refs) {
|
|
1058
|
-
var
|
|
1058
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1059
1059
|
const schema = {
|
|
1060
1060
|
type: "object",
|
|
1061
|
-
additionalProperties: (
|
|
1061
|
+
additionalProperties: (_a15 = parseDef(def.valueType._def, {
|
|
1062
1062
|
...refs,
|
|
1063
1063
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1064
|
-
})) != null ?
|
|
1064
|
+
})) != null ? _a15 : refs.allowedAdditionalProperties
|
|
1065
1065
|
};
|
|
1066
1066
|
if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === v3.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1067
1067
|
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
@@ -1318,8 +1318,8 @@ function safeIsOptional(schema) {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
}
|
|
1320
1320
|
var parseOptionalDef = (def, refs) => {
|
|
1321
|
-
var
|
|
1322
|
-
if (refs.currentPath.toString() === ((
|
|
1321
|
+
var _a15;
|
|
1322
|
+
if (refs.currentPath.toString() === ((_a15 = refs.propertyPath) == null ? void 0 : _a15.toString())) {
|
|
1323
1323
|
return parseDef(def.innerType._def, refs);
|
|
1324
1324
|
}
|
|
1325
1325
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -1489,10 +1489,10 @@ var selectParser = (def, typeName, refs) => {
|
|
|
1489
1489
|
}
|
|
1490
1490
|
};
|
|
1491
1491
|
function parseDef(def, refs, forceResolution = false) {
|
|
1492
|
-
var
|
|
1492
|
+
var _a15;
|
|
1493
1493
|
const seenItem = refs.seen.get(def);
|
|
1494
1494
|
if (refs.override) {
|
|
1495
|
-
const overrideResult = (
|
|
1495
|
+
const overrideResult = (_a15 = refs.override) == null ? void 0 : _a15.call(
|
|
1496
1496
|
refs,
|
|
1497
1497
|
def,
|
|
1498
1498
|
refs,
|
|
@@ -1558,11 +1558,11 @@ var getRefs = (options) => {
|
|
|
1558
1558
|
currentPath,
|
|
1559
1559
|
propertyPath: void 0,
|
|
1560
1560
|
seen: new Map(
|
|
1561
|
-
Object.entries(_options.definitions).map(([
|
|
1561
|
+
Object.entries(_options.definitions).map(([name14, def]) => [
|
|
1562
1562
|
def._def,
|
|
1563
1563
|
{
|
|
1564
1564
|
def: def._def,
|
|
1565
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
1565
|
+
path: [..._options.basePath, _options.definitionPath, name14],
|
|
1566
1566
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1567
1567
|
jsonSchema: void 0
|
|
1568
1568
|
}
|
|
@@ -1571,50 +1571,50 @@ var getRefs = (options) => {
|
|
|
1571
1571
|
};
|
|
1572
1572
|
};
|
|
1573
1573
|
var zodToJsonSchema = (schema, options) => {
|
|
1574
|
-
var
|
|
1574
|
+
var _a15;
|
|
1575
1575
|
const refs = getRefs(options);
|
|
1576
1576
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
1577
|
-
(acc, [
|
|
1578
|
-
var
|
|
1577
|
+
(acc, [name22, schema2]) => {
|
|
1578
|
+
var _a22;
|
|
1579
1579
|
return {
|
|
1580
1580
|
...acc,
|
|
1581
|
-
[
|
|
1581
|
+
[name22]: (_a22 = parseDef(
|
|
1582
1582
|
schema2._def,
|
|
1583
1583
|
{
|
|
1584
1584
|
...refs,
|
|
1585
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
1585
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
1586
1586
|
},
|
|
1587
1587
|
true
|
|
1588
|
-
)) != null ?
|
|
1588
|
+
)) != null ? _a22 : parseAnyDef()
|
|
1589
1589
|
};
|
|
1590
1590
|
},
|
|
1591
1591
|
{}
|
|
1592
1592
|
) : void 0;
|
|
1593
|
-
const
|
|
1594
|
-
const main = (
|
|
1593
|
+
const name14 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
1594
|
+
const main = (_a15 = parseDef(
|
|
1595
1595
|
schema._def,
|
|
1596
|
-
|
|
1596
|
+
name14 === void 0 ? refs : {
|
|
1597
1597
|
...refs,
|
|
1598
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
1598
|
+
currentPath: [...refs.basePath, refs.definitionPath, name14]
|
|
1599
1599
|
},
|
|
1600
1600
|
false
|
|
1601
|
-
)) != null ?
|
|
1601
|
+
)) != null ? _a15 : parseAnyDef();
|
|
1602
1602
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1603
1603
|
if (title !== void 0) {
|
|
1604
1604
|
main.title = title;
|
|
1605
1605
|
}
|
|
1606
|
-
const combined =
|
|
1606
|
+
const combined = name14 === void 0 ? definitions ? {
|
|
1607
1607
|
...main,
|
|
1608
1608
|
[refs.definitionPath]: definitions
|
|
1609
1609
|
} : main : {
|
|
1610
1610
|
$ref: [
|
|
1611
1611
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1612
1612
|
refs.definitionPath,
|
|
1613
|
-
|
|
1613
|
+
name14
|
|
1614
1614
|
].join("/"),
|
|
1615
1615
|
[refs.definitionPath]: {
|
|
1616
1616
|
...definitions,
|
|
1617
|
-
[
|
|
1617
|
+
[name14]: main
|
|
1618
1618
|
}
|
|
1619
1619
|
};
|
|
1620
1620
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -1622,8 +1622,8 @@ var zodToJsonSchema = (schema, options) => {
|
|
|
1622
1622
|
};
|
|
1623
1623
|
var zod_to_json_schema_default = zodToJsonSchema;
|
|
1624
1624
|
function zod3Schema(zodSchema2, options) {
|
|
1625
|
-
var
|
|
1626
|
-
const useReferences = (
|
|
1625
|
+
var _a15;
|
|
1626
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
1627
1627
|
return jsonSchema(
|
|
1628
1628
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1629
1629
|
() => zod_to_json_schema_default(zodSchema2, {
|
|
@@ -1638,8 +1638,8 @@ function zod3Schema(zodSchema2, options) {
|
|
|
1638
1638
|
);
|
|
1639
1639
|
}
|
|
1640
1640
|
function zod4Schema(zodSchema2, options) {
|
|
1641
|
-
var
|
|
1642
|
-
const useReferences = (
|
|
1641
|
+
var _a15;
|
|
1642
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
1643
1643
|
return jsonSchema(
|
|
1644
1644
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1645
1645
|
() => z4__namespace.toJSONSchema(zodSchema2, {
|
|
@@ -1954,7 +1954,7 @@ function prepareTools({
|
|
|
1954
1954
|
};
|
|
1955
1955
|
default: {
|
|
1956
1956
|
const _exhaustiveCheck = type;
|
|
1957
|
-
throw new
|
|
1957
|
+
throw new chunkIXZ2T2QX_cjs.UnsupportedFunctionalityError({
|
|
1958
1958
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1959
1959
|
});
|
|
1960
1960
|
}
|
|
@@ -2019,12 +2019,12 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2019
2019
|
toolChoice,
|
|
2020
2020
|
seed
|
|
2021
2021
|
}) {
|
|
2022
|
-
var
|
|
2023
|
-
const deepseekOptions = (
|
|
2022
|
+
var _a15, _b;
|
|
2023
|
+
const deepseekOptions = (_a15 = await parseProviderOptions2({
|
|
2024
2024
|
provider: this.providerOptionsName,
|
|
2025
2025
|
providerOptions,
|
|
2026
2026
|
schema: deepseekChatOptions
|
|
2027
|
-
})) != null ?
|
|
2027
|
+
})) != null ? _a15 : {};
|
|
2028
2028
|
const { messages, warnings } = convertToDeepSeekChatMessages({
|
|
2029
2029
|
prompt,
|
|
2030
2030
|
responseFormat
|
|
@@ -2062,7 +2062,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2062
2062
|
};
|
|
2063
2063
|
}
|
|
2064
2064
|
async doGenerate(options) {
|
|
2065
|
-
var
|
|
2065
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2066
2066
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
2067
2067
|
const {
|
|
2068
2068
|
responseHeaders,
|
|
@@ -2095,7 +2095,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2095
2095
|
for (const toolCall of choice.message.tool_calls) {
|
|
2096
2096
|
content.push({
|
|
2097
2097
|
type: "tool-call",
|
|
2098
|
-
toolCallId: (
|
|
2098
|
+
toolCallId: (_a15 = toolCall.id) != null ? _a15 : generateId2(),
|
|
2099
2099
|
toolName: toolCall.function.name,
|
|
2100
2100
|
input: toolCall.function.arguments
|
|
2101
2101
|
});
|
|
@@ -2165,7 +2165,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2165
2165
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2166
2166
|
},
|
|
2167
2167
|
transform(chunk, controller) {
|
|
2168
|
-
var
|
|
2168
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2169
2169
|
if (options.includeRawChunks) {
|
|
2170
2170
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2171
2171
|
}
|
|
@@ -2243,13 +2243,13 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2243
2243
|
const index = toolCallDelta.index;
|
|
2244
2244
|
if (toolCalls[index] == null) {
|
|
2245
2245
|
if (toolCallDelta.id == null) {
|
|
2246
|
-
throw new
|
|
2246
|
+
throw new chunkIXZ2T2QX_cjs.InvalidResponseDataError({
|
|
2247
2247
|
data: toolCallDelta,
|
|
2248
2248
|
message: `Expected 'id' to be a string.`
|
|
2249
2249
|
});
|
|
2250
2250
|
}
|
|
2251
|
-
if (((
|
|
2252
|
-
throw new
|
|
2251
|
+
if (((_a15 = toolCallDelta.function) == null ? void 0 : _a15.name) == null) {
|
|
2252
|
+
throw new chunkIXZ2T2QX_cjs.InvalidResponseDataError({
|
|
2253
2253
|
data: toolCallDelta,
|
|
2254
2254
|
message: `Expected 'function.name' to be a string.`
|
|
2255
2255
|
});
|
|
@@ -2322,7 +2322,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2322
2322
|
}
|
|
2323
2323
|
},
|
|
2324
2324
|
flush(controller) {
|
|
2325
|
-
var
|
|
2325
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2326
2326
|
if (isActiveReasoning) {
|
|
2327
2327
|
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
2328
2328
|
}
|
|
@@ -2338,7 +2338,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2338
2338
|
});
|
|
2339
2339
|
controller.enqueue({
|
|
2340
2340
|
type: "tool-call",
|
|
2341
|
-
toolCallId: (
|
|
2341
|
+
toolCallId: (_a15 = toolCall.id) != null ? _a15 : generateId2(),
|
|
2342
2342
|
toolName: toolCall.function.name,
|
|
2343
2343
|
input: toolCall.function.arguments
|
|
2344
2344
|
});
|
|
@@ -2370,9 +2370,9 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2370
2370
|
};
|
|
2371
2371
|
var VERSION2 = "1.0.31" ;
|
|
2372
2372
|
function createDeepSeek(options = {}) {
|
|
2373
|
-
var
|
|
2373
|
+
var _a15;
|
|
2374
2374
|
const baseURL = withoutTrailingSlash2(
|
|
2375
|
-
(
|
|
2375
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.deepseek.com"
|
|
2376
2376
|
);
|
|
2377
2377
|
const getHeaders = () => withUserAgentSuffix2(
|
|
2378
2378
|
{
|
|
@@ -2397,10 +2397,10 @@ function createDeepSeek(options = {}) {
|
|
|
2397
2397
|
provider.languageModel = createLanguageModel;
|
|
2398
2398
|
provider.chat = createLanguageModel;
|
|
2399
2399
|
provider.textEmbeddingModel = (modelId) => {
|
|
2400
|
-
throw new
|
|
2400
|
+
throw new chunkIXZ2T2QX_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
2401
2401
|
};
|
|
2402
2402
|
provider.imageModel = (modelId) => {
|
|
2403
|
-
throw new
|
|
2403
|
+
throw new chunkIXZ2T2QX_cjs.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
2404
2404
|
};
|
|
2405
2405
|
return provider;
|
|
2406
2406
|
}
|
|
@@ -2428,7 +2428,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
2428
2428
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
2429
2429
|
return {
|
|
2430
2430
|
type: "image_url",
|
|
2431
|
-
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
2431
|
+
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${chunkOWIEOL55_cjs.convertToBase64(part.data)}`
|
|
2432
2432
|
};
|
|
2433
2433
|
} else if (part.mediaType === "application/pdf") {
|
|
2434
2434
|
return {
|
|
@@ -2436,7 +2436,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
2436
2436
|
document_url: part.data.toString()
|
|
2437
2437
|
};
|
|
2438
2438
|
} else {
|
|
2439
|
-
throw new
|
|
2439
|
+
throw new chunkIXZ2T2QX_cjs.UnsupportedFunctionalityError({
|
|
2440
2440
|
functionality: "Only images and PDF file parts are supported"
|
|
2441
2441
|
});
|
|
2442
2442
|
}
|
|
@@ -2577,7 +2577,7 @@ var mistralErrorDataSchema = z4.z.object({
|
|
|
2577
2577
|
param: z4.z.string().nullable(),
|
|
2578
2578
|
code: z4.z.string().nullable()
|
|
2579
2579
|
});
|
|
2580
|
-
var mistralFailedResponseHandler =
|
|
2580
|
+
var mistralFailedResponseHandler = chunkOWIEOL55_cjs.createJsonErrorResponseHandler({
|
|
2581
2581
|
errorSchema: mistralErrorDataSchema,
|
|
2582
2582
|
errorToMessage: (data) => data.message
|
|
2583
2583
|
});
|
|
@@ -2627,7 +2627,7 @@ function prepareTools2({
|
|
|
2627
2627
|
};
|
|
2628
2628
|
default: {
|
|
2629
2629
|
const _exhaustiveCheck = type;
|
|
2630
|
-
throw new
|
|
2630
|
+
throw new chunkIXZ2T2QX_cjs.UnsupportedFunctionalityError({
|
|
2631
2631
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
2632
2632
|
});
|
|
2633
2633
|
}
|
|
@@ -2639,10 +2639,10 @@ var MistralChatLanguageModel = class {
|
|
|
2639
2639
|
this.supportedUrls = {
|
|
2640
2640
|
"application/pdf": [/^https:\/\/.*$/]
|
|
2641
2641
|
};
|
|
2642
|
-
var
|
|
2642
|
+
var _a15;
|
|
2643
2643
|
this.modelId = modelId;
|
|
2644
2644
|
this.config = config;
|
|
2645
|
-
this.generateId = (
|
|
2645
|
+
this.generateId = (_a15 = config.generateId) != null ? _a15 : chunkOWIEOL55_cjs.generateId;
|
|
2646
2646
|
}
|
|
2647
2647
|
get provider() {
|
|
2648
2648
|
return this.config.provider;
|
|
@@ -2662,13 +2662,13 @@ var MistralChatLanguageModel = class {
|
|
|
2662
2662
|
tools,
|
|
2663
2663
|
toolChoice
|
|
2664
2664
|
}) {
|
|
2665
|
-
var
|
|
2665
|
+
var _a15, _b, _c, _d;
|
|
2666
2666
|
const warnings = [];
|
|
2667
|
-
const options = (
|
|
2667
|
+
const options = (_a15 = await chunkOWIEOL55_cjs.parseProviderOptions({
|
|
2668
2668
|
provider: "mistral",
|
|
2669
2669
|
providerOptions,
|
|
2670
2670
|
schema: mistralLanguageModelOptions
|
|
2671
|
-
})) != null ?
|
|
2671
|
+
})) != null ? _a15 : {};
|
|
2672
2672
|
if (topK != null) {
|
|
2673
2673
|
warnings.push({
|
|
2674
2674
|
type: "unsupported-setting",
|
|
@@ -2696,7 +2696,7 @@ var MistralChatLanguageModel = class {
|
|
|
2696
2696
|
const structuredOutputs = (_b = options.structuredOutputs) != null ? _b : true;
|
|
2697
2697
|
const strictJsonSchema = (_c = options.strictJsonSchema) != null ? _c : false;
|
|
2698
2698
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && !(responseFormat == null ? void 0 : responseFormat.schema)) {
|
|
2699
|
-
prompt =
|
|
2699
|
+
prompt = chunkOWIEOL55_cjs.injectJsonInstructionIntoMessages({
|
|
2700
2700
|
messages: prompt,
|
|
2701
2701
|
schema: responseFormat.schema
|
|
2702
2702
|
});
|
|
@@ -2751,12 +2751,12 @@ var MistralChatLanguageModel = class {
|
|
|
2751
2751
|
responseHeaders,
|
|
2752
2752
|
value: response,
|
|
2753
2753
|
rawValue: rawResponse
|
|
2754
|
-
} = await
|
|
2754
|
+
} = await chunkOWIEOL55_cjs.postJsonToApi({
|
|
2755
2755
|
url: `${this.config.baseURL}/chat/completions`,
|
|
2756
|
-
headers:
|
|
2756
|
+
headers: chunkOWIEOL55_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
2757
2757
|
body,
|
|
2758
2758
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
2759
|
-
successfulResponseHandler:
|
|
2759
|
+
successfulResponseHandler: chunkOWIEOL55_cjs.createJsonResponseHandler(
|
|
2760
2760
|
mistralChatResponseSchema
|
|
2761
2761
|
),
|
|
2762
2762
|
abortSignal: options.abortSignal,
|
|
@@ -2813,12 +2813,12 @@ var MistralChatLanguageModel = class {
|
|
|
2813
2813
|
async doStream(options) {
|
|
2814
2814
|
const { args, warnings } = await this.getArgs(options);
|
|
2815
2815
|
const body = { ...args, stream: true };
|
|
2816
|
-
const { responseHeaders, value: response } = await
|
|
2816
|
+
const { responseHeaders, value: response } = await chunkOWIEOL55_cjs.postJsonToApi({
|
|
2817
2817
|
url: `${this.config.baseURL}/chat/completions`,
|
|
2818
|
-
headers:
|
|
2818
|
+
headers: chunkOWIEOL55_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
2819
2819
|
body,
|
|
2820
2820
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
2821
|
-
successfulResponseHandler:
|
|
2821
|
+
successfulResponseHandler: chunkOWIEOL55_cjs.createEventSourceResponseHandler(
|
|
2822
2822
|
mistralChatChunkSchema
|
|
2823
2823
|
),
|
|
2824
2824
|
abortSignal: options.abortSignal,
|
|
@@ -3091,7 +3091,7 @@ var MistralEmbeddingModel = class {
|
|
|
3091
3091
|
headers
|
|
3092
3092
|
}) {
|
|
3093
3093
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
3094
|
-
throw new
|
|
3094
|
+
throw new chunkIXZ2T2QX_cjs.TooManyEmbeddingValuesForCallError({
|
|
3095
3095
|
provider: this.provider,
|
|
3096
3096
|
modelId: this.modelId,
|
|
3097
3097
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -3102,16 +3102,16 @@ var MistralEmbeddingModel = class {
|
|
|
3102
3102
|
responseHeaders,
|
|
3103
3103
|
value: response,
|
|
3104
3104
|
rawValue
|
|
3105
|
-
} = await
|
|
3105
|
+
} = await chunkOWIEOL55_cjs.postJsonToApi({
|
|
3106
3106
|
url: `${this.config.baseURL}/embeddings`,
|
|
3107
|
-
headers:
|
|
3107
|
+
headers: chunkOWIEOL55_cjs.combineHeaders(this.config.headers(), headers),
|
|
3108
3108
|
body: {
|
|
3109
3109
|
model: this.modelId,
|
|
3110
3110
|
input: values,
|
|
3111
3111
|
encoding_format: "float"
|
|
3112
3112
|
},
|
|
3113
3113
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
3114
|
-
successfulResponseHandler:
|
|
3114
|
+
successfulResponseHandler: chunkOWIEOL55_cjs.createJsonResponseHandler(
|
|
3115
3115
|
MistralTextEmbeddingResponseSchema
|
|
3116
3116
|
),
|
|
3117
3117
|
abortSignal,
|
|
@@ -3130,11 +3130,11 @@ var MistralTextEmbeddingResponseSchema = z4.z.object({
|
|
|
3130
3130
|
});
|
|
3131
3131
|
var VERSION3 = "2.0.24" ;
|
|
3132
3132
|
function createMistral(options = {}) {
|
|
3133
|
-
var
|
|
3134
|
-
const baseURL = (
|
|
3135
|
-
const getHeaders = () =>
|
|
3133
|
+
var _a15;
|
|
3134
|
+
const baseURL = (_a15 = chunkOWIEOL55_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a15 : "https://api.mistral.ai/v1";
|
|
3135
|
+
const getHeaders = () => chunkOWIEOL55_cjs.withUserAgentSuffix(
|
|
3136
3136
|
{
|
|
3137
|
-
Authorization: `Bearer ${
|
|
3137
|
+
Authorization: `Bearer ${chunkOWIEOL55_cjs.loadApiKey({
|
|
3138
3138
|
apiKey: options.apiKey,
|
|
3139
3139
|
environmentVariableName: "MISTRAL_API_KEY",
|
|
3140
3140
|
description: "Mistral"
|
|
@@ -3170,7 +3170,7 @@ function createMistral(options = {}) {
|
|
|
3170
3170
|
provider.textEmbedding = createEmbeddingModel;
|
|
3171
3171
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
3172
3172
|
provider.imageModel = (modelId) => {
|
|
3173
|
-
throw new
|
|
3173
|
+
throw new chunkIXZ2T2QX_cjs.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
3174
3174
|
};
|
|
3175
3175
|
return provider;
|
|
3176
3176
|
}
|
|
@@ -3210,7 +3210,7 @@ var createIdGenerator2 = ({
|
|
|
3210
3210
|
return generator;
|
|
3211
3211
|
}
|
|
3212
3212
|
if (alphabet.includes(separator)) {
|
|
3213
|
-
throw new
|
|
3213
|
+
throw new chunkIXZ2T2QX_cjs.InvalidArgumentError({
|
|
3214
3214
|
argument: "separator",
|
|
3215
3215
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
3216
3216
|
});
|
|
@@ -3234,7 +3234,7 @@ function handleFetchError2({
|
|
|
3234
3234
|
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES2.includes(error.message.toLowerCase())) {
|
|
3235
3235
|
const cause = error.cause;
|
|
3236
3236
|
if (cause != null) {
|
|
3237
|
-
return new
|
|
3237
|
+
return new chunkIXZ2T2QX_cjs.APICallError({
|
|
3238
3238
|
message: `Cannot connect to API: ${cause.message}`,
|
|
3239
3239
|
cause,
|
|
3240
3240
|
url,
|
|
@@ -3261,23 +3261,23 @@ function loadApiKey3({
|
|
|
3261
3261
|
return apiKey;
|
|
3262
3262
|
}
|
|
3263
3263
|
if (apiKey != null) {
|
|
3264
|
-
throw new
|
|
3264
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
3265
3265
|
message: `${description} API key must be a string.`
|
|
3266
3266
|
});
|
|
3267
3267
|
}
|
|
3268
3268
|
if (typeof process === "undefined") {
|
|
3269
|
-
throw new
|
|
3269
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
3270
3270
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
3271
3271
|
});
|
|
3272
3272
|
}
|
|
3273
3273
|
apiKey = process.env[environmentVariableName];
|
|
3274
3274
|
if (apiKey == null) {
|
|
3275
|
-
throw new
|
|
3275
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
3276
3276
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
3277
3277
|
});
|
|
3278
3278
|
}
|
|
3279
3279
|
if (typeof apiKey !== "string") {
|
|
3280
|
-
throw new
|
|
3280
|
+
throw new chunkIXZ2T2QX_cjs.LoadAPIKeyError({
|
|
3281
3281
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
3282
3282
|
});
|
|
3283
3283
|
}
|
|
@@ -3341,7 +3341,7 @@ function standardSchemaValidator2(standardSchema) {
|
|
|
3341
3341
|
const result = await standardSchema["~standard"].validate(value);
|
|
3342
3342
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
3343
3343
|
success: false,
|
|
3344
|
-
error: new
|
|
3344
|
+
error: new chunkIXZ2T2QX_cjs.TypeValidationError({
|
|
3345
3345
|
value,
|
|
3346
3346
|
cause: result.issues
|
|
3347
3347
|
})
|
|
@@ -3354,7 +3354,7 @@ async function validateTypes2({
|
|
|
3354
3354
|
}) {
|
|
3355
3355
|
const result = await safeValidateTypes2({ value, schema });
|
|
3356
3356
|
if (!result.success) {
|
|
3357
|
-
throw
|
|
3357
|
+
throw chunkIXZ2T2QX_cjs.TypeValidationError.wrap({ value, cause: result.error });
|
|
3358
3358
|
}
|
|
3359
3359
|
return result.value;
|
|
3360
3360
|
}
|
|
@@ -3373,13 +3373,13 @@ async function safeValidateTypes2({
|
|
|
3373
3373
|
}
|
|
3374
3374
|
return {
|
|
3375
3375
|
success: false,
|
|
3376
|
-
error:
|
|
3376
|
+
error: chunkIXZ2T2QX_cjs.TypeValidationError.wrap({ value, cause: result.error }),
|
|
3377
3377
|
rawValue: value
|
|
3378
3378
|
};
|
|
3379
3379
|
} catch (error) {
|
|
3380
3380
|
return {
|
|
3381
3381
|
success: false,
|
|
3382
|
-
error:
|
|
3382
|
+
error: chunkIXZ2T2QX_cjs.TypeValidationError.wrap({ value, cause: error }),
|
|
3383
3383
|
rawValue: value
|
|
3384
3384
|
};
|
|
3385
3385
|
}
|
|
@@ -3395,10 +3395,10 @@ async function parseJSON2({
|
|
|
3395
3395
|
}
|
|
3396
3396
|
return validateTypes2({ value, schema });
|
|
3397
3397
|
} catch (error) {
|
|
3398
|
-
if (
|
|
3398
|
+
if (chunkIXZ2T2QX_cjs.JSONParseError.isInstance(error) || chunkIXZ2T2QX_cjs.TypeValidationError.isInstance(error)) {
|
|
3399
3399
|
throw error;
|
|
3400
3400
|
}
|
|
3401
|
-
throw new
|
|
3401
|
+
throw new chunkIXZ2T2QX_cjs.JSONParseError({ text, cause: error });
|
|
3402
3402
|
}
|
|
3403
3403
|
}
|
|
3404
3404
|
async function safeParseJSON2({
|
|
@@ -3414,7 +3414,7 @@ async function safeParseJSON2({
|
|
|
3414
3414
|
} catch (error) {
|
|
3415
3415
|
return {
|
|
3416
3416
|
success: false,
|
|
3417
|
-
error:
|
|
3417
|
+
error: chunkIXZ2T2QX_cjs.JSONParseError.isInstance(error) ? error : new chunkIXZ2T2QX_cjs.JSONParseError({ text, cause: error }),
|
|
3418
3418
|
rawValue: void 0
|
|
3419
3419
|
};
|
|
3420
3420
|
}
|
|
@@ -3423,7 +3423,7 @@ function parseJsonEventStream2({
|
|
|
3423
3423
|
stream,
|
|
3424
3424
|
schema
|
|
3425
3425
|
}) {
|
|
3426
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
3426
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new chunkIXZ2T2QX_cjs.EventSourceParserStream()).pipeThrough(
|
|
3427
3427
|
new TransformStream({
|
|
3428
3428
|
async transform({ data }, controller) {
|
|
3429
3429
|
if (data === "[DONE]") {
|
|
@@ -3484,10 +3484,10 @@ var postToApi2 = async ({
|
|
|
3484
3484
|
requestBodyValues: body.values
|
|
3485
3485
|
});
|
|
3486
3486
|
} catch (error) {
|
|
3487
|
-
if (isAbortError2(error) ||
|
|
3487
|
+
if (isAbortError2(error) || chunkIXZ2T2QX_cjs.APICallError.isInstance(error)) {
|
|
3488
3488
|
throw error;
|
|
3489
3489
|
}
|
|
3490
|
-
throw new
|
|
3490
|
+
throw new chunkIXZ2T2QX_cjs.APICallError({
|
|
3491
3491
|
message: "Failed to process error response",
|
|
3492
3492
|
cause: error,
|
|
3493
3493
|
statusCode: response.status,
|
|
@@ -3506,11 +3506,11 @@ var postToApi2 = async ({
|
|
|
3506
3506
|
});
|
|
3507
3507
|
} catch (error) {
|
|
3508
3508
|
if (error instanceof Error) {
|
|
3509
|
-
if (isAbortError2(error) ||
|
|
3509
|
+
if (isAbortError2(error) || chunkIXZ2T2QX_cjs.APICallError.isInstance(error)) {
|
|
3510
3510
|
throw error;
|
|
3511
3511
|
}
|
|
3512
3512
|
}
|
|
3513
|
-
throw new
|
|
3513
|
+
throw new chunkIXZ2T2QX_cjs.APICallError({
|
|
3514
3514
|
message: "Failed to process successful response",
|
|
3515
3515
|
cause: error,
|
|
3516
3516
|
statusCode: response.status,
|
|
@@ -3533,7 +3533,7 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
3533
3533
|
if (responseBody.trim() === "") {
|
|
3534
3534
|
return {
|
|
3535
3535
|
responseHeaders,
|
|
3536
|
-
value: new
|
|
3536
|
+
value: new chunkIXZ2T2QX_cjs.APICallError({
|
|
3537
3537
|
message: response.statusText,
|
|
3538
3538
|
url,
|
|
3539
3539
|
requestBodyValues,
|
|
@@ -3551,7 +3551,7 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
3551
3551
|
});
|
|
3552
3552
|
return {
|
|
3553
3553
|
responseHeaders,
|
|
3554
|
-
value: new
|
|
3554
|
+
value: new chunkIXZ2T2QX_cjs.APICallError({
|
|
3555
3555
|
message: errorToMessage2(parsedError),
|
|
3556
3556
|
url,
|
|
3557
3557
|
requestBodyValues,
|
|
@@ -3565,7 +3565,7 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
3565
3565
|
} catch (parseError) {
|
|
3566
3566
|
return {
|
|
3567
3567
|
responseHeaders,
|
|
3568
|
-
value: new
|
|
3568
|
+
value: new chunkIXZ2T2QX_cjs.APICallError({
|
|
3569
3569
|
message: response.statusText,
|
|
3570
3570
|
url,
|
|
3571
3571
|
requestBodyValues,
|
|
@@ -3580,7 +3580,7 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
3580
3580
|
var createEventSourceResponseHandler3 = (chunkSchema) => async ({ response }) => {
|
|
3581
3581
|
const responseHeaders = extractResponseHeaders2(response);
|
|
3582
3582
|
if (response.body == null) {
|
|
3583
|
-
throw new
|
|
3583
|
+
throw new chunkIXZ2T2QX_cjs.EmptyResponseBodyError({});
|
|
3584
3584
|
}
|
|
3585
3585
|
return {
|
|
3586
3586
|
responseHeaders,
|
|
@@ -3598,7 +3598,7 @@ var createJsonResponseHandler3 = (responseSchema) => async ({ response, url, req
|
|
|
3598
3598
|
});
|
|
3599
3599
|
const responseHeaders = extractResponseHeaders2(response);
|
|
3600
3600
|
if (!parsedResult.success) {
|
|
3601
|
-
throw new
|
|
3601
|
+
throw new chunkIXZ2T2QX_cjs.APICallError({
|
|
3602
3602
|
message: "Invalid JSON response",
|
|
3603
3603
|
cause: parsedResult.error,
|
|
3604
3604
|
statusCode: response.status,
|
|
@@ -3639,7 +3639,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
3639
3639
|
(part) => part.type === "file" && part.mediaType.startsWith("image/")
|
|
3640
3640
|
);
|
|
3641
3641
|
const messageContent = content.map((part) => {
|
|
3642
|
-
var
|
|
3642
|
+
var _a15;
|
|
3643
3643
|
switch (part.type) {
|
|
3644
3644
|
case "text": {
|
|
3645
3645
|
return {
|
|
@@ -3656,7 +3656,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
3656
3656
|
} : {
|
|
3657
3657
|
type: "image_url",
|
|
3658
3658
|
image_url: {
|
|
3659
|
-
url: `data:${(
|
|
3659
|
+
url: `data:${(_a15 = part.mediaType) != null ? _a15 : "image/jpeg"};base64,${typeof part.data === "string" ? part.data : convertUint8ArrayToBase64(part.data)}`
|
|
3660
3660
|
}
|
|
3661
3661
|
};
|
|
3662
3662
|
}
|
|
@@ -3669,7 +3669,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
3669
3669
|
break;
|
|
3670
3670
|
}
|
|
3671
3671
|
case "tool": {
|
|
3672
|
-
throw new
|
|
3672
|
+
throw new chunkIXZ2T2QX_cjs.UnsupportedFunctionalityError({
|
|
3673
3673
|
functionality: "Tool messages"
|
|
3674
3674
|
});
|
|
3675
3675
|
}
|
|
@@ -3713,7 +3713,7 @@ var PerplexityLanguageModel = class {
|
|
|
3713
3713
|
seed,
|
|
3714
3714
|
providerOptions
|
|
3715
3715
|
}) {
|
|
3716
|
-
var
|
|
3716
|
+
var _a15;
|
|
3717
3717
|
const warnings = [];
|
|
3718
3718
|
if (topK != null) {
|
|
3719
3719
|
warnings.push({
|
|
@@ -3750,7 +3750,7 @@ var PerplexityLanguageModel = class {
|
|
|
3750
3750
|
json_schema: { schema: responseFormat.schema }
|
|
3751
3751
|
} : void 0,
|
|
3752
3752
|
// provider extensions
|
|
3753
|
-
...(
|
|
3753
|
+
...(_a15 = providerOptions == null ? void 0 : providerOptions.perplexity) != null ? _a15 : {},
|
|
3754
3754
|
// messages:
|
|
3755
3755
|
messages: convertToPerplexityMessages(prompt)
|
|
3756
3756
|
},
|
|
@@ -3758,7 +3758,7 @@ var PerplexityLanguageModel = class {
|
|
|
3758
3758
|
};
|
|
3759
3759
|
}
|
|
3760
3760
|
async doGenerate(options) {
|
|
3761
|
-
var
|
|
3761
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3762
3762
|
const { args: body, warnings } = this.getArgs(options);
|
|
3763
3763
|
const {
|
|
3764
3764
|
responseHeaders,
|
|
@@ -3798,7 +3798,7 @@ var PerplexityLanguageModel = class {
|
|
|
3798
3798
|
content,
|
|
3799
3799
|
finishReason: mapPerplexityFinishReason(choice.finish_reason),
|
|
3800
3800
|
usage: {
|
|
3801
|
-
inputTokens: (
|
|
3801
|
+
inputTokens: (_a15 = response.usage) == null ? void 0 : _a15.prompt_tokens,
|
|
3802
3802
|
outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
|
|
3803
3803
|
totalTokens: (_d = (_c = response.usage) == null ? void 0 : _c.total_tokens) != null ? _d : void 0
|
|
3804
3804
|
},
|
|
@@ -3867,7 +3867,7 @@ var PerplexityLanguageModel = class {
|
|
|
3867
3867
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3868
3868
|
},
|
|
3869
3869
|
transform(chunk, controller) {
|
|
3870
|
-
var
|
|
3870
|
+
var _a15, _b, _c;
|
|
3871
3871
|
if (options.includeRawChunks) {
|
|
3872
3872
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3873
3873
|
}
|
|
@@ -3881,7 +3881,7 @@ var PerplexityLanguageModel = class {
|
|
|
3881
3881
|
type: "response-metadata",
|
|
3882
3882
|
...getResponseMetadata3(value)
|
|
3883
3883
|
});
|
|
3884
|
-
(
|
|
3884
|
+
(_a15 = value.citations) == null ? void 0 : _a15.forEach((url) => {
|
|
3885
3885
|
controller.enqueue({
|
|
3886
3886
|
type: "source",
|
|
3887
3887
|
sourceType: "url",
|
|
@@ -4012,8 +4012,8 @@ var perplexityErrorSchema = z4.z.object({
|
|
|
4012
4012
|
})
|
|
4013
4013
|
});
|
|
4014
4014
|
var errorToMessage = (data) => {
|
|
4015
|
-
var
|
|
4016
|
-
return (_b = (
|
|
4015
|
+
var _a15, _b;
|
|
4016
|
+
return (_b = (_a15 = data.error.message) != null ? _a15 : data.error.type) != null ? _b : "unknown error";
|
|
4017
4017
|
};
|
|
4018
4018
|
function createPerplexity(options = {}) {
|
|
4019
4019
|
const getHeaders = () => ({
|
|
@@ -4025,10 +4025,10 @@ function createPerplexity(options = {}) {
|
|
|
4025
4025
|
...options.headers
|
|
4026
4026
|
});
|
|
4027
4027
|
const createLanguageModel = (modelId) => {
|
|
4028
|
-
var
|
|
4028
|
+
var _a15;
|
|
4029
4029
|
return new PerplexityLanguageModel(modelId, {
|
|
4030
4030
|
baseURL: withoutTrailingSlash3(
|
|
4031
|
-
(
|
|
4031
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.perplexity.ai"
|
|
4032
4032
|
),
|
|
4033
4033
|
headers: getHeaders,
|
|
4034
4034
|
generateId: generateId3,
|
|
@@ -4038,10 +4038,10 @@ function createPerplexity(options = {}) {
|
|
|
4038
4038
|
const provider = (modelId) => createLanguageModel(modelId);
|
|
4039
4039
|
provider.languageModel = createLanguageModel;
|
|
4040
4040
|
provider.textEmbeddingModel = (modelId) => {
|
|
4041
|
-
throw new
|
|
4041
|
+
throw new chunkIXZ2T2QX_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
4042
4042
|
};
|
|
4043
4043
|
provider.imageModel = (modelId) => {
|
|
4044
|
-
throw new
|
|
4044
|
+
throw new chunkIXZ2T2QX_cjs.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
4045
4045
|
};
|
|
4046
4046
|
return provider;
|
|
4047
4047
|
}
|
|
@@ -4073,11 +4073,11 @@ function convertToXaiChatMessages(prompt) {
|
|
|
4073
4073
|
return {
|
|
4074
4074
|
type: "image_url",
|
|
4075
4075
|
image_url: {
|
|
4076
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
4076
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${chunkOWIEOL55_cjs.convertToBase64(part.data)}`
|
|
4077
4077
|
}
|
|
4078
4078
|
};
|
|
4079
4079
|
} else {
|
|
4080
|
-
throw new
|
|
4080
|
+
throw new chunkIXZ2T2QX_cjs.UnsupportedFunctionalityError({
|
|
4081
4081
|
functionality: `file part media type ${part.mediaType}`
|
|
4082
4082
|
});
|
|
4083
4083
|
}
|
|
@@ -4258,7 +4258,7 @@ var xaiErrorDataSchema = z4.z.object({
|
|
|
4258
4258
|
code: z4.z.union([z4.z.string(), z4.z.number()]).nullish()
|
|
4259
4259
|
})
|
|
4260
4260
|
});
|
|
4261
|
-
var xaiFailedResponseHandler =
|
|
4261
|
+
var xaiFailedResponseHandler = chunkOWIEOL55_cjs.createJsonErrorResponseHandler({
|
|
4262
4262
|
errorSchema: xaiErrorDataSchema,
|
|
4263
4263
|
errorToMessage: (data) => data.error.message
|
|
4264
4264
|
});
|
|
@@ -4307,7 +4307,7 @@ function prepareTools3({
|
|
|
4307
4307
|
};
|
|
4308
4308
|
default: {
|
|
4309
4309
|
const _exhaustiveCheck = type;
|
|
4310
|
-
throw new
|
|
4310
|
+
throw new chunkIXZ2T2QX_cjs.UnsupportedFunctionalityError({
|
|
4311
4311
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
4312
4312
|
});
|
|
4313
4313
|
}
|
|
@@ -4340,13 +4340,13 @@ var XaiChatLanguageModel = class {
|
|
|
4340
4340
|
tools,
|
|
4341
4341
|
toolChoice
|
|
4342
4342
|
}) {
|
|
4343
|
-
var
|
|
4343
|
+
var _a15, _b, _c;
|
|
4344
4344
|
const warnings = [];
|
|
4345
|
-
const options = (
|
|
4345
|
+
const options = (_a15 = await chunkOWIEOL55_cjs.parseProviderOptions({
|
|
4346
4346
|
provider: "xai",
|
|
4347
4347
|
providerOptions,
|
|
4348
4348
|
schema: xaiProviderOptions
|
|
4349
|
-
})) != null ?
|
|
4349
|
+
})) != null ? _a15 : {};
|
|
4350
4350
|
if (topK != null) {
|
|
4351
4351
|
warnings.push({
|
|
4352
4352
|
type: "unsupported-setting",
|
|
@@ -4410,7 +4410,7 @@ var XaiChatLanguageModel = class {
|
|
|
4410
4410
|
to_date: options.searchParameters.toDate,
|
|
4411
4411
|
max_search_results: options.searchParameters.maxSearchResults,
|
|
4412
4412
|
sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
|
|
4413
|
-
var
|
|
4413
|
+
var _a22;
|
|
4414
4414
|
return {
|
|
4415
4415
|
type: source.type,
|
|
4416
4416
|
...source.type === "web" && {
|
|
@@ -4421,7 +4421,7 @@ var XaiChatLanguageModel = class {
|
|
|
4421
4421
|
},
|
|
4422
4422
|
...source.type === "x" && {
|
|
4423
4423
|
excluded_x_handles: source.excludedXHandles,
|
|
4424
|
-
included_x_handles: (
|
|
4424
|
+
included_x_handles: (_a22 = source.includedXHandles) != null ? _a22 : source.xHandles,
|
|
4425
4425
|
post_favorite_count: source.postFavoriteCount,
|
|
4426
4426
|
post_view_count: source.postViewCount
|
|
4427
4427
|
},
|
|
@@ -4448,18 +4448,18 @@ var XaiChatLanguageModel = class {
|
|
|
4448
4448
|
};
|
|
4449
4449
|
}
|
|
4450
4450
|
async doGenerate(options) {
|
|
4451
|
-
var
|
|
4451
|
+
var _a15, _b, _c;
|
|
4452
4452
|
const { args: body, warnings } = await this.getArgs(options);
|
|
4453
4453
|
const {
|
|
4454
4454
|
responseHeaders,
|
|
4455
4455
|
value: response,
|
|
4456
4456
|
rawValue: rawResponse
|
|
4457
|
-
} = await
|
|
4458
|
-
url: `${(
|
|
4459
|
-
headers:
|
|
4457
|
+
} = await chunkOWIEOL55_cjs.postJsonToApi({
|
|
4458
|
+
url: `${(_a15 = this.config.baseURL) != null ? _a15 : "https://api.x.ai/v1"}/chat/completions`,
|
|
4459
|
+
headers: chunkOWIEOL55_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
4460
4460
|
body,
|
|
4461
4461
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4462
|
-
successfulResponseHandler:
|
|
4462
|
+
successfulResponseHandler: chunkOWIEOL55_cjs.createJsonResponseHandler(
|
|
4463
4463
|
xaiChatResponseSchema
|
|
4464
4464
|
),
|
|
4465
4465
|
abortSignal: options.abortSignal,
|
|
@@ -4522,7 +4522,7 @@ var XaiChatLanguageModel = class {
|
|
|
4522
4522
|
};
|
|
4523
4523
|
}
|
|
4524
4524
|
async doStream(options) {
|
|
4525
|
-
var
|
|
4525
|
+
var _a15;
|
|
4526
4526
|
const { args, warnings } = await this.getArgs(options);
|
|
4527
4527
|
const body = {
|
|
4528
4528
|
...args,
|
|
@@ -4531,12 +4531,12 @@ var XaiChatLanguageModel = class {
|
|
|
4531
4531
|
include_usage: true
|
|
4532
4532
|
}
|
|
4533
4533
|
};
|
|
4534
|
-
const { responseHeaders, value: response } = await
|
|
4535
|
-
url: `${(
|
|
4536
|
-
headers:
|
|
4534
|
+
const { responseHeaders, value: response } = await chunkOWIEOL55_cjs.postJsonToApi({
|
|
4535
|
+
url: `${(_a15 = this.config.baseURL) != null ? _a15 : "https://api.x.ai/v1"}/chat/completions`,
|
|
4536
|
+
headers: chunkOWIEOL55_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
4537
4537
|
body,
|
|
4538
4538
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
4539
|
-
successfulResponseHandler:
|
|
4539
|
+
successfulResponseHandler: chunkOWIEOL55_cjs.createEventSourceResponseHandler(xaiChatChunkSchema),
|
|
4540
4540
|
abortSignal: options.abortSignal,
|
|
4541
4541
|
fetch: this.config.fetch
|
|
4542
4542
|
});
|
|
@@ -4557,7 +4557,7 @@ var XaiChatLanguageModel = class {
|
|
|
4557
4557
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4558
4558
|
},
|
|
4559
4559
|
transform(chunk, controller) {
|
|
4560
|
-
var
|
|
4560
|
+
var _a22, _b;
|
|
4561
4561
|
if (options.includeRawChunks) {
|
|
4562
4562
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4563
4563
|
}
|
|
@@ -4587,7 +4587,7 @@ var XaiChatLanguageModel = class {
|
|
|
4587
4587
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
4588
4588
|
usage.outputTokens = value.usage.completion_tokens;
|
|
4589
4589
|
usage.totalTokens = value.usage.total_tokens;
|
|
4590
|
-
usage.reasoningTokens = (_b = (
|
|
4590
|
+
usage.reasoningTokens = (_b = (_a22 = value.usage.completion_tokens_details) == null ? void 0 : _a22.reasoning_tokens) != null ? _b : void 0;
|
|
4591
4591
|
}
|
|
4592
4592
|
const choice = value.choices[0];
|
|
4593
4593
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -4750,13 +4750,13 @@ var xaiErrorStructure = {
|
|
|
4750
4750
|
errorToMessage: (data) => data.error.message
|
|
4751
4751
|
};
|
|
4752
4752
|
function createXai(options = {}) {
|
|
4753
|
-
var
|
|
4754
|
-
const baseURL =
|
|
4755
|
-
(
|
|
4753
|
+
var _a15;
|
|
4754
|
+
const baseURL = chunkOWIEOL55_cjs.withoutTrailingSlash(
|
|
4755
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.x.ai/v1"
|
|
4756
4756
|
);
|
|
4757
|
-
const getHeaders = () =>
|
|
4757
|
+
const getHeaders = () => chunkOWIEOL55_cjs.withUserAgentSuffix(
|
|
4758
4758
|
{
|
|
4759
|
-
Authorization: `Bearer ${
|
|
4759
|
+
Authorization: `Bearer ${chunkOWIEOL55_cjs.loadApiKey({
|
|
4760
4760
|
apiKey: options.apiKey,
|
|
4761
4761
|
environmentVariableName: "XAI_API_KEY",
|
|
4762
4762
|
description: "xAI API key"
|
|
@@ -4770,12 +4770,12 @@ function createXai(options = {}) {
|
|
|
4770
4770
|
provider: "xai.chat",
|
|
4771
4771
|
baseURL,
|
|
4772
4772
|
headers: getHeaders,
|
|
4773
|
-
generateId:
|
|
4773
|
+
generateId: chunkOWIEOL55_cjs.generateId,
|
|
4774
4774
|
fetch: options.fetch
|
|
4775
4775
|
});
|
|
4776
4776
|
};
|
|
4777
4777
|
const createImageModel = (modelId) => {
|
|
4778
|
-
return new
|
|
4778
|
+
return new chunkOWIEOL55_cjs.OpenAICompatibleImageModel(modelId, {
|
|
4779
4779
|
provider: "xai.image",
|
|
4780
4780
|
url: ({ path }) => `${baseURL}${path}`,
|
|
4781
4781
|
headers: getHeaders,
|
|
@@ -4787,13 +4787,2466 @@ function createXai(options = {}) {
|
|
|
4787
4787
|
provider.languageModel = createLanguageModel;
|
|
4788
4788
|
provider.chat = createLanguageModel;
|
|
4789
4789
|
provider.textEmbeddingModel = (modelId) => {
|
|
4790
|
-
throw new
|
|
4790
|
+
throw new chunkIXZ2T2QX_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
4791
4791
|
};
|
|
4792
4792
|
provider.imageModel = createImageModel;
|
|
4793
4793
|
provider.image = createImageModel;
|
|
4794
4794
|
return provider;
|
|
4795
4795
|
}
|
|
4796
4796
|
createXai();
|
|
4797
|
+
var __defProp = Object.defineProperty;
|
|
4798
|
+
var __defProps = Object.defineProperties;
|
|
4799
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4800
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4801
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4802
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4803
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4804
|
+
var __spreadValues = (a, b) => {
|
|
4805
|
+
for (var prop in b || (b = {}))
|
|
4806
|
+
if (__hasOwnProp.call(b, prop))
|
|
4807
|
+
__defNormalProp(a, prop, b[prop]);
|
|
4808
|
+
if (__getOwnPropSymbols)
|
|
4809
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
4810
|
+
if (__propIsEnum.call(b, prop))
|
|
4811
|
+
__defNormalProp(a, prop, b[prop]);
|
|
4812
|
+
}
|
|
4813
|
+
return a;
|
|
4814
|
+
};
|
|
4815
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
4816
|
+
var marker = "vercel.ai.error";
|
|
4817
|
+
var symbol = Symbol.for(marker);
|
|
4818
|
+
var _a;
|
|
4819
|
+
var _AISDKError = class _AISDKError2 extends Error {
|
|
4820
|
+
/**
|
|
4821
|
+
* Creates an AI SDK Error.
|
|
4822
|
+
*
|
|
4823
|
+
* @param {Object} params - The parameters for creating the error.
|
|
4824
|
+
* @param {string} params.name - The name of the error.
|
|
4825
|
+
* @param {string} params.message - The error message.
|
|
4826
|
+
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
4827
|
+
*/
|
|
4828
|
+
constructor({
|
|
4829
|
+
name: name14,
|
|
4830
|
+
message,
|
|
4831
|
+
cause
|
|
4832
|
+
}) {
|
|
4833
|
+
super(message);
|
|
4834
|
+
this[_a] = true;
|
|
4835
|
+
this.name = name14;
|
|
4836
|
+
this.cause = cause;
|
|
4837
|
+
}
|
|
4838
|
+
/**
|
|
4839
|
+
* Checks if the given error is an AI SDK Error.
|
|
4840
|
+
* @param {unknown} error - The error to check.
|
|
4841
|
+
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
4842
|
+
*/
|
|
4843
|
+
static isInstance(error) {
|
|
4844
|
+
return _AISDKError2.hasMarker(error, marker);
|
|
4845
|
+
}
|
|
4846
|
+
static hasMarker(error, marker15) {
|
|
4847
|
+
const markerSymbol = Symbol.for(marker15);
|
|
4848
|
+
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
4849
|
+
}
|
|
4850
|
+
};
|
|
4851
|
+
_a = symbol;
|
|
4852
|
+
var AISDKError = _AISDKError;
|
|
4853
|
+
var name = "AI_APICallError";
|
|
4854
|
+
var marker2 = `vercel.ai.error.${name}`;
|
|
4855
|
+
var symbol2 = Symbol.for(marker2);
|
|
4856
|
+
var _a2;
|
|
4857
|
+
var APICallError2 = class extends AISDKError {
|
|
4858
|
+
constructor({
|
|
4859
|
+
message,
|
|
4860
|
+
url,
|
|
4861
|
+
requestBodyValues,
|
|
4862
|
+
statusCode,
|
|
4863
|
+
responseHeaders,
|
|
4864
|
+
responseBody,
|
|
4865
|
+
cause,
|
|
4866
|
+
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
|
4867
|
+
statusCode === 409 || // conflict
|
|
4868
|
+
statusCode === 429 || // too many requests
|
|
4869
|
+
statusCode >= 500),
|
|
4870
|
+
// server error
|
|
4871
|
+
data
|
|
4872
|
+
}) {
|
|
4873
|
+
super({ name, message, cause });
|
|
4874
|
+
this[_a2] = true;
|
|
4875
|
+
this.url = url;
|
|
4876
|
+
this.requestBodyValues = requestBodyValues;
|
|
4877
|
+
this.statusCode = statusCode;
|
|
4878
|
+
this.responseHeaders = responseHeaders;
|
|
4879
|
+
this.responseBody = responseBody;
|
|
4880
|
+
this.isRetryable = isRetryable;
|
|
4881
|
+
this.data = data;
|
|
4882
|
+
}
|
|
4883
|
+
static isInstance(error) {
|
|
4884
|
+
return AISDKError.hasMarker(error, marker2);
|
|
4885
|
+
}
|
|
4886
|
+
};
|
|
4887
|
+
_a2 = symbol2;
|
|
4888
|
+
var name2 = "AI_EmptyResponseBodyError";
|
|
4889
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
4890
|
+
var symbol3 = Symbol.for(marker3);
|
|
4891
|
+
var _a3;
|
|
4892
|
+
var EmptyResponseBodyError2 = class extends AISDKError {
|
|
4893
|
+
// used in isInstance
|
|
4894
|
+
constructor({ message = "Empty response body" } = {}) {
|
|
4895
|
+
super({ name: name2, message });
|
|
4896
|
+
this[_a3] = true;
|
|
4897
|
+
}
|
|
4898
|
+
static isInstance(error) {
|
|
4899
|
+
return AISDKError.hasMarker(error, marker3);
|
|
4900
|
+
}
|
|
4901
|
+
};
|
|
4902
|
+
_a3 = symbol3;
|
|
4903
|
+
function getErrorMessage(error) {
|
|
4904
|
+
if (error == null) {
|
|
4905
|
+
return "unknown error";
|
|
4906
|
+
}
|
|
4907
|
+
if (typeof error === "string") {
|
|
4908
|
+
return error;
|
|
4909
|
+
}
|
|
4910
|
+
if (error instanceof Error) {
|
|
4911
|
+
return error.message;
|
|
4912
|
+
}
|
|
4913
|
+
return JSON.stringify(error);
|
|
4914
|
+
}
|
|
4915
|
+
var name3 = "AI_InvalidArgumentError";
|
|
4916
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
|
4917
|
+
var symbol4 = Symbol.for(marker4);
|
|
4918
|
+
var _a4;
|
|
4919
|
+
var InvalidArgumentError2 = class extends AISDKError {
|
|
4920
|
+
constructor({
|
|
4921
|
+
message,
|
|
4922
|
+
cause,
|
|
4923
|
+
argument
|
|
4924
|
+
}) {
|
|
4925
|
+
super({ name: name3, message, cause });
|
|
4926
|
+
this[_a4] = true;
|
|
4927
|
+
this.argument = argument;
|
|
4928
|
+
}
|
|
4929
|
+
static isInstance(error) {
|
|
4930
|
+
return AISDKError.hasMarker(error, marker4);
|
|
4931
|
+
}
|
|
4932
|
+
};
|
|
4933
|
+
_a4 = symbol4;
|
|
4934
|
+
var name4 = "AI_InvalidPromptError";
|
|
4935
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
|
4936
|
+
var symbol5 = Symbol.for(marker5);
|
|
4937
|
+
var _a5;
|
|
4938
|
+
var InvalidPromptError = class extends AISDKError {
|
|
4939
|
+
constructor({
|
|
4940
|
+
prompt,
|
|
4941
|
+
message,
|
|
4942
|
+
cause
|
|
4943
|
+
}) {
|
|
4944
|
+
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
4945
|
+
this[_a5] = true;
|
|
4946
|
+
this.prompt = prompt;
|
|
4947
|
+
}
|
|
4948
|
+
static isInstance(error) {
|
|
4949
|
+
return AISDKError.hasMarker(error, marker5);
|
|
4950
|
+
}
|
|
4951
|
+
};
|
|
4952
|
+
_a5 = symbol5;
|
|
4953
|
+
var name5 = "AI_InvalidResponseDataError";
|
|
4954
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
|
4955
|
+
var symbol6 = Symbol.for(marker6);
|
|
4956
|
+
var _a6;
|
|
4957
|
+
var InvalidResponseDataError2 = class extends AISDKError {
|
|
4958
|
+
constructor({
|
|
4959
|
+
data,
|
|
4960
|
+
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
4961
|
+
}) {
|
|
4962
|
+
super({ name: name5, message });
|
|
4963
|
+
this[_a6] = true;
|
|
4964
|
+
this.data = data;
|
|
4965
|
+
}
|
|
4966
|
+
static isInstance(error) {
|
|
4967
|
+
return AISDKError.hasMarker(error, marker6);
|
|
4968
|
+
}
|
|
4969
|
+
};
|
|
4970
|
+
_a6 = symbol6;
|
|
4971
|
+
var name6 = "AI_JSONParseError";
|
|
4972
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
|
4973
|
+
var symbol7 = Symbol.for(marker7);
|
|
4974
|
+
var _a7;
|
|
4975
|
+
var JSONParseError2 = class extends AISDKError {
|
|
4976
|
+
constructor({ text, cause }) {
|
|
4977
|
+
super({
|
|
4978
|
+
name: name6,
|
|
4979
|
+
message: `JSON parsing failed: Text: ${text}.
|
|
4980
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
4981
|
+
cause
|
|
4982
|
+
});
|
|
4983
|
+
this[_a7] = true;
|
|
4984
|
+
this.text = text;
|
|
4985
|
+
}
|
|
4986
|
+
static isInstance(error) {
|
|
4987
|
+
return AISDKError.hasMarker(error, marker7);
|
|
4988
|
+
}
|
|
4989
|
+
};
|
|
4990
|
+
_a7 = symbol7;
|
|
4991
|
+
var name7 = "AI_LoadAPIKeyError";
|
|
4992
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
|
4993
|
+
var symbol8 = Symbol.for(marker8);
|
|
4994
|
+
var _a8;
|
|
4995
|
+
var LoadAPIKeyError2 = class extends AISDKError {
|
|
4996
|
+
// used in isInstance
|
|
4997
|
+
constructor({ message }) {
|
|
4998
|
+
super({ name: name7, message });
|
|
4999
|
+
this[_a8] = true;
|
|
5000
|
+
}
|
|
5001
|
+
static isInstance(error) {
|
|
5002
|
+
return AISDKError.hasMarker(error, marker8);
|
|
5003
|
+
}
|
|
5004
|
+
};
|
|
5005
|
+
_a8 = symbol8;
|
|
5006
|
+
var name9 = "AI_NoContentGeneratedError";
|
|
5007
|
+
var marker10 = `vercel.ai.error.${name9}`;
|
|
5008
|
+
var symbol10 = Symbol.for(marker10);
|
|
5009
|
+
var _a10;
|
|
5010
|
+
var NoContentGeneratedError = class extends AISDKError {
|
|
5011
|
+
// used in isInstance
|
|
5012
|
+
constructor({
|
|
5013
|
+
message = "No content generated."
|
|
5014
|
+
} = {}) {
|
|
5015
|
+
super({ name: name9, message });
|
|
5016
|
+
this[_a10] = true;
|
|
5017
|
+
}
|
|
5018
|
+
static isInstance(error) {
|
|
5019
|
+
return AISDKError.hasMarker(error, marker10);
|
|
5020
|
+
}
|
|
5021
|
+
};
|
|
5022
|
+
_a10 = symbol10;
|
|
5023
|
+
var name12 = "AI_TypeValidationError";
|
|
5024
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
5025
|
+
var symbol13 = Symbol.for(marker13);
|
|
5026
|
+
var _a13;
|
|
5027
|
+
var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
|
|
5028
|
+
constructor({ value, cause }) {
|
|
5029
|
+
super({
|
|
5030
|
+
name: name12,
|
|
5031
|
+
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
|
5032
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
5033
|
+
cause
|
|
5034
|
+
});
|
|
5035
|
+
this[_a13] = true;
|
|
5036
|
+
this.value = value;
|
|
5037
|
+
}
|
|
5038
|
+
static isInstance(error) {
|
|
5039
|
+
return AISDKError.hasMarker(error, marker13);
|
|
5040
|
+
}
|
|
5041
|
+
/**
|
|
5042
|
+
* Wraps an error into a TypeValidationError.
|
|
5043
|
+
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
5044
|
+
* Otherwise, it creates a new TypeValidationError.
|
|
5045
|
+
*
|
|
5046
|
+
* @param {Object} params - The parameters for wrapping the error.
|
|
5047
|
+
* @param {unknown} params.value - The value that failed validation.
|
|
5048
|
+
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
5049
|
+
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
5050
|
+
*/
|
|
5051
|
+
static wrap({
|
|
5052
|
+
value,
|
|
5053
|
+
cause
|
|
5054
|
+
}) {
|
|
5055
|
+
return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
|
|
5056
|
+
}
|
|
5057
|
+
};
|
|
5058
|
+
_a13 = symbol13;
|
|
5059
|
+
var TypeValidationError2 = _TypeValidationError;
|
|
5060
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
5061
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
5062
|
+
var symbol14 = Symbol.for(marker14);
|
|
5063
|
+
var _a14;
|
|
5064
|
+
var UnsupportedFunctionalityError2 = class extends AISDKError {
|
|
5065
|
+
constructor({
|
|
5066
|
+
functionality,
|
|
5067
|
+
message = `'${functionality}' functionality not supported.`
|
|
5068
|
+
}) {
|
|
5069
|
+
super({ name: name13, message });
|
|
5070
|
+
this[_a14] = true;
|
|
5071
|
+
this.functionality = functionality;
|
|
5072
|
+
}
|
|
5073
|
+
static isInstance(error) {
|
|
5074
|
+
return AISDKError.hasMarker(error, marker14);
|
|
5075
|
+
}
|
|
5076
|
+
};
|
|
5077
|
+
_a14 = symbol14;
|
|
5078
|
+
var ParseError = class extends Error {
|
|
5079
|
+
constructor(message, options) {
|
|
5080
|
+
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
5081
|
+
}
|
|
5082
|
+
};
|
|
5083
|
+
function noop(_arg) {
|
|
5084
|
+
}
|
|
5085
|
+
function createParser(callbacks) {
|
|
5086
|
+
if (typeof callbacks == "function")
|
|
5087
|
+
throw new TypeError(
|
|
5088
|
+
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
5089
|
+
);
|
|
5090
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
5091
|
+
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
5092
|
+
function feed(newChunk) {
|
|
5093
|
+
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
|
|
5094
|
+
for (const line of complete)
|
|
5095
|
+
parseLine(line);
|
|
5096
|
+
incompleteLine = incomplete, isFirstChunk = false;
|
|
5097
|
+
}
|
|
5098
|
+
function parseLine(line) {
|
|
5099
|
+
if (line === "") {
|
|
5100
|
+
dispatchEvent();
|
|
5101
|
+
return;
|
|
5102
|
+
}
|
|
5103
|
+
if (line.startsWith(":")) {
|
|
5104
|
+
onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
|
|
5105
|
+
return;
|
|
5106
|
+
}
|
|
5107
|
+
const fieldSeparatorIndex = line.indexOf(":");
|
|
5108
|
+
if (fieldSeparatorIndex !== -1) {
|
|
5109
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
5110
|
+
processField(field, value, line);
|
|
5111
|
+
return;
|
|
5112
|
+
}
|
|
5113
|
+
processField(line, "", line);
|
|
5114
|
+
}
|
|
5115
|
+
function processField(field, value, line) {
|
|
5116
|
+
switch (field) {
|
|
5117
|
+
case "event":
|
|
5118
|
+
eventType = value;
|
|
5119
|
+
break;
|
|
5120
|
+
case "data":
|
|
5121
|
+
data = `${data}${value}
|
|
5122
|
+
`;
|
|
5123
|
+
break;
|
|
5124
|
+
case "id":
|
|
5125
|
+
id = value.includes("\0") ? void 0 : value;
|
|
5126
|
+
break;
|
|
5127
|
+
case "retry":
|
|
5128
|
+
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
5129
|
+
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
5130
|
+
type: "invalid-retry",
|
|
5131
|
+
value,
|
|
5132
|
+
line
|
|
5133
|
+
})
|
|
5134
|
+
);
|
|
5135
|
+
break;
|
|
5136
|
+
default:
|
|
5137
|
+
onError(
|
|
5138
|
+
new ParseError(
|
|
5139
|
+
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
5140
|
+
{ type: "unknown-field", field, value, line }
|
|
5141
|
+
)
|
|
5142
|
+
);
|
|
5143
|
+
break;
|
|
5144
|
+
}
|
|
5145
|
+
}
|
|
5146
|
+
function dispatchEvent() {
|
|
5147
|
+
data.length > 0 && onEvent({
|
|
5148
|
+
id,
|
|
5149
|
+
event: eventType || void 0,
|
|
5150
|
+
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
5151
|
+
// then remove the last character from the data buffer.
|
|
5152
|
+
data: data.endsWith(`
|
|
5153
|
+
`) ? data.slice(0, -1) : data
|
|
5154
|
+
}), id = void 0, data = "", eventType = "";
|
|
5155
|
+
}
|
|
5156
|
+
function reset(options = {}) {
|
|
5157
|
+
incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
|
|
5158
|
+
}
|
|
5159
|
+
return { feed, reset };
|
|
5160
|
+
}
|
|
5161
|
+
function splitLines(chunk) {
|
|
5162
|
+
const lines = [];
|
|
5163
|
+
let incompleteLine = "", searchIndex = 0;
|
|
5164
|
+
for (; searchIndex < chunk.length; ) {
|
|
5165
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
5166
|
+
`, searchIndex);
|
|
5167
|
+
let lineEnd = -1;
|
|
5168
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
5169
|
+
incompleteLine = chunk.slice(searchIndex);
|
|
5170
|
+
break;
|
|
5171
|
+
} else {
|
|
5172
|
+
const line = chunk.slice(searchIndex, lineEnd);
|
|
5173
|
+
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
5174
|
+
` && searchIndex++;
|
|
5175
|
+
}
|
|
5176
|
+
}
|
|
5177
|
+
return [lines, incompleteLine];
|
|
5178
|
+
}
|
|
5179
|
+
var EventSourceParserStream2 = class extends TransformStream {
|
|
5180
|
+
constructor({ onError, onRetry, onComment } = {}) {
|
|
5181
|
+
let parser;
|
|
5182
|
+
super({
|
|
5183
|
+
start(controller) {
|
|
5184
|
+
parser = createParser({
|
|
5185
|
+
onEvent: (event) => {
|
|
5186
|
+
controller.enqueue(event);
|
|
5187
|
+
},
|
|
5188
|
+
onError(error) {
|
|
5189
|
+
onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
|
|
5190
|
+
},
|
|
5191
|
+
onRetry,
|
|
5192
|
+
onComment
|
|
5193
|
+
});
|
|
5194
|
+
},
|
|
5195
|
+
transform(chunk) {
|
|
5196
|
+
parser.feed(chunk);
|
|
5197
|
+
}
|
|
5198
|
+
});
|
|
5199
|
+
}
|
|
5200
|
+
};
|
|
5201
|
+
new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
5202
|
+
function combineHeaders4(...headers) {
|
|
5203
|
+
return headers.reduce(
|
|
5204
|
+
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
5205
|
+
{}
|
|
5206
|
+
);
|
|
5207
|
+
}
|
|
5208
|
+
function extractResponseHeaders3(response) {
|
|
5209
|
+
return Object.fromEntries([...response.headers]);
|
|
5210
|
+
}
|
|
5211
|
+
var createIdGenerator3 = ({
|
|
5212
|
+
prefix,
|
|
5213
|
+
size = 16,
|
|
5214
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
5215
|
+
separator = "-"
|
|
5216
|
+
} = {}) => {
|
|
5217
|
+
const generator = () => {
|
|
5218
|
+
const alphabetLength = alphabet.length;
|
|
5219
|
+
const chars = new Array(size);
|
|
5220
|
+
for (let i = 0; i < size; i++) {
|
|
5221
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
5222
|
+
}
|
|
5223
|
+
return chars.join("");
|
|
5224
|
+
};
|
|
5225
|
+
if (prefix == null) {
|
|
5226
|
+
return generator;
|
|
5227
|
+
}
|
|
5228
|
+
if (alphabet.includes(separator)) {
|
|
5229
|
+
throw new InvalidArgumentError2({
|
|
5230
|
+
argument: "separator",
|
|
5231
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
5232
|
+
});
|
|
5233
|
+
}
|
|
5234
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
5235
|
+
};
|
|
5236
|
+
var generateId4 = createIdGenerator3();
|
|
5237
|
+
function isAbortError3(error) {
|
|
5238
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
5239
|
+
error.name === "TimeoutError");
|
|
5240
|
+
}
|
|
5241
|
+
var FETCH_FAILED_ERROR_MESSAGES3 = ["fetch failed", "failed to fetch"];
|
|
5242
|
+
function handleFetchError3({
|
|
5243
|
+
error,
|
|
5244
|
+
url,
|
|
5245
|
+
requestBodyValues
|
|
5246
|
+
}) {
|
|
5247
|
+
if (isAbortError3(error)) {
|
|
5248
|
+
return error;
|
|
5249
|
+
}
|
|
5250
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES3.includes(error.message.toLowerCase())) {
|
|
5251
|
+
const cause = error.cause;
|
|
5252
|
+
if (cause != null) {
|
|
5253
|
+
return new APICallError2({
|
|
5254
|
+
message: `Cannot connect to API: ${cause.message}`,
|
|
5255
|
+
cause,
|
|
5256
|
+
url,
|
|
5257
|
+
requestBodyValues,
|
|
5258
|
+
isRetryable: true
|
|
5259
|
+
// retry when network error
|
|
5260
|
+
});
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
return error;
|
|
5264
|
+
}
|
|
5265
|
+
function removeUndefinedEntries2(record) {
|
|
5266
|
+
return Object.fromEntries(
|
|
5267
|
+
Object.entries(record).filter(([_key, value]) => value != null)
|
|
5268
|
+
);
|
|
5269
|
+
}
|
|
5270
|
+
function loadApiKey4({
|
|
5271
|
+
apiKey,
|
|
5272
|
+
environmentVariableName,
|
|
5273
|
+
apiKeyParameterName = "apiKey",
|
|
5274
|
+
description
|
|
5275
|
+
}) {
|
|
5276
|
+
if (typeof apiKey === "string") {
|
|
5277
|
+
return apiKey;
|
|
5278
|
+
}
|
|
5279
|
+
if (apiKey != null) {
|
|
5280
|
+
throw new LoadAPIKeyError2({
|
|
5281
|
+
message: `${description} API key must be a string.`
|
|
5282
|
+
});
|
|
5283
|
+
}
|
|
5284
|
+
if (typeof process === "undefined") {
|
|
5285
|
+
throw new LoadAPIKeyError2({
|
|
5286
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
5287
|
+
});
|
|
5288
|
+
}
|
|
5289
|
+
apiKey = process.env[environmentVariableName];
|
|
5290
|
+
if (apiKey == null) {
|
|
5291
|
+
throw new LoadAPIKeyError2({
|
|
5292
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
5293
|
+
});
|
|
5294
|
+
}
|
|
5295
|
+
if (typeof apiKey !== "string") {
|
|
5296
|
+
throw new LoadAPIKeyError2({
|
|
5297
|
+
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
5298
|
+
});
|
|
5299
|
+
}
|
|
5300
|
+
return apiKey;
|
|
5301
|
+
}
|
|
5302
|
+
var suspectProtoRx3 = /"__proto__"\s*:/;
|
|
5303
|
+
var suspectConstructorRx3 = /"constructor"\s*:/;
|
|
5304
|
+
function _parse3(text) {
|
|
5305
|
+
const obj = JSON.parse(text);
|
|
5306
|
+
if (obj === null || typeof obj !== "object") {
|
|
5307
|
+
return obj;
|
|
5308
|
+
}
|
|
5309
|
+
if (suspectProtoRx3.test(text) === false && suspectConstructorRx3.test(text) === false) {
|
|
5310
|
+
return obj;
|
|
5311
|
+
}
|
|
5312
|
+
return filter3(obj);
|
|
5313
|
+
}
|
|
5314
|
+
function filter3(obj) {
|
|
5315
|
+
let next = [obj];
|
|
5316
|
+
while (next.length) {
|
|
5317
|
+
const nodes = next;
|
|
5318
|
+
next = [];
|
|
5319
|
+
for (const node of nodes) {
|
|
5320
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
5321
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
5322
|
+
}
|
|
5323
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
5324
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
5325
|
+
}
|
|
5326
|
+
for (const key in node) {
|
|
5327
|
+
const value = node[key];
|
|
5328
|
+
if (value && typeof value === "object") {
|
|
5329
|
+
next.push(value);
|
|
5330
|
+
}
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
}
|
|
5334
|
+
return obj;
|
|
5335
|
+
}
|
|
5336
|
+
function secureJsonParse3(text) {
|
|
5337
|
+
const { stackTraceLimit } = Error;
|
|
5338
|
+
Error.stackTraceLimit = 0;
|
|
5339
|
+
try {
|
|
5340
|
+
return _parse3(text);
|
|
5341
|
+
} finally {
|
|
5342
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
|
+
var validatorSymbol3 = Symbol.for("vercel.ai.validator");
|
|
5346
|
+
function validator3(validate) {
|
|
5347
|
+
return { [validatorSymbol3]: true, validate };
|
|
5348
|
+
}
|
|
5349
|
+
function isValidator3(value) {
|
|
5350
|
+
return typeof value === "object" && value !== null && validatorSymbol3 in value && value[validatorSymbol3] === true && "validate" in value;
|
|
5351
|
+
}
|
|
5352
|
+
function asValidator3(value) {
|
|
5353
|
+
return isValidator3(value) ? value : standardSchemaValidator3(value);
|
|
5354
|
+
}
|
|
5355
|
+
function standardSchemaValidator3(standardSchema) {
|
|
5356
|
+
return validator3(async (value) => {
|
|
5357
|
+
const result = await standardSchema["~standard"].validate(value);
|
|
5358
|
+
return result.issues == null ? { success: true, value: result.value } : {
|
|
5359
|
+
success: false,
|
|
5360
|
+
error: new TypeValidationError2({
|
|
5361
|
+
value,
|
|
5362
|
+
cause: result.issues
|
|
5363
|
+
})
|
|
5364
|
+
};
|
|
5365
|
+
});
|
|
5366
|
+
}
|
|
5367
|
+
async function validateTypes3({
|
|
5368
|
+
value,
|
|
5369
|
+
schema
|
|
5370
|
+
}) {
|
|
5371
|
+
const result = await safeValidateTypes3({ value, schema });
|
|
5372
|
+
if (!result.success) {
|
|
5373
|
+
throw TypeValidationError2.wrap({ value, cause: result.error });
|
|
5374
|
+
}
|
|
5375
|
+
return result.value;
|
|
5376
|
+
}
|
|
5377
|
+
async function safeValidateTypes3({
|
|
5378
|
+
value,
|
|
5379
|
+
schema
|
|
5380
|
+
}) {
|
|
5381
|
+
const validator22 = asValidator3(schema);
|
|
5382
|
+
try {
|
|
5383
|
+
if (validator22.validate == null) {
|
|
5384
|
+
return { success: true, value, rawValue: value };
|
|
5385
|
+
}
|
|
5386
|
+
const result = await validator22.validate(value);
|
|
5387
|
+
if (result.success) {
|
|
5388
|
+
return { success: true, value: result.value, rawValue: value };
|
|
5389
|
+
}
|
|
5390
|
+
return {
|
|
5391
|
+
success: false,
|
|
5392
|
+
error: TypeValidationError2.wrap({ value, cause: result.error }),
|
|
5393
|
+
rawValue: value
|
|
5394
|
+
};
|
|
5395
|
+
} catch (error) {
|
|
5396
|
+
return {
|
|
5397
|
+
success: false,
|
|
5398
|
+
error: TypeValidationError2.wrap({ value, cause: error }),
|
|
5399
|
+
rawValue: value
|
|
5400
|
+
};
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
async function parseJSON3({
|
|
5404
|
+
text,
|
|
5405
|
+
schema
|
|
5406
|
+
}) {
|
|
5407
|
+
try {
|
|
5408
|
+
const value = secureJsonParse3(text);
|
|
5409
|
+
if (schema == null) {
|
|
5410
|
+
return value;
|
|
5411
|
+
}
|
|
5412
|
+
return validateTypes3({ value, schema });
|
|
5413
|
+
} catch (error) {
|
|
5414
|
+
if (JSONParseError2.isInstance(error) || TypeValidationError2.isInstance(error)) {
|
|
5415
|
+
throw error;
|
|
5416
|
+
}
|
|
5417
|
+
throw new JSONParseError2({ text, cause: error });
|
|
5418
|
+
}
|
|
5419
|
+
}
|
|
5420
|
+
async function safeParseJSON3({
|
|
5421
|
+
text,
|
|
5422
|
+
schema
|
|
5423
|
+
}) {
|
|
5424
|
+
try {
|
|
5425
|
+
const value = secureJsonParse3(text);
|
|
5426
|
+
if (schema == null) {
|
|
5427
|
+
return { success: true, value, rawValue: value };
|
|
5428
|
+
}
|
|
5429
|
+
return await safeValidateTypes3({ value, schema });
|
|
5430
|
+
} catch (error) {
|
|
5431
|
+
return {
|
|
5432
|
+
success: false,
|
|
5433
|
+
error: JSONParseError2.isInstance(error) ? error : new JSONParseError2({ text, cause: error }),
|
|
5434
|
+
rawValue: void 0
|
|
5435
|
+
};
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
function isParsableJson2(input) {
|
|
5439
|
+
try {
|
|
5440
|
+
secureJsonParse3(input);
|
|
5441
|
+
return true;
|
|
5442
|
+
} catch (e) {
|
|
5443
|
+
return false;
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
function parseJsonEventStream3({
|
|
5447
|
+
stream,
|
|
5448
|
+
schema
|
|
5449
|
+
}) {
|
|
5450
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2()).pipeThrough(
|
|
5451
|
+
new TransformStream({
|
|
5452
|
+
async transform({ data }, controller) {
|
|
5453
|
+
if (data === "[DONE]") {
|
|
5454
|
+
return;
|
|
5455
|
+
}
|
|
5456
|
+
controller.enqueue(await safeParseJSON3({ text: data, schema }));
|
|
5457
|
+
}
|
|
5458
|
+
})
|
|
5459
|
+
);
|
|
5460
|
+
}
|
|
5461
|
+
var getOriginalFetch23 = () => globalThis.fetch;
|
|
5462
|
+
var postJsonToApi4 = async ({
|
|
5463
|
+
url,
|
|
5464
|
+
headers,
|
|
5465
|
+
body,
|
|
5466
|
+
failedResponseHandler,
|
|
5467
|
+
successfulResponseHandler,
|
|
5468
|
+
abortSignal,
|
|
5469
|
+
fetch: fetch2
|
|
5470
|
+
}) => postToApi3({
|
|
5471
|
+
url,
|
|
5472
|
+
headers: __spreadValues({
|
|
5473
|
+
"Content-Type": "application/json"
|
|
5474
|
+
}, headers),
|
|
5475
|
+
body: {
|
|
5476
|
+
content: JSON.stringify(body),
|
|
5477
|
+
values: body
|
|
5478
|
+
},
|
|
5479
|
+
failedResponseHandler,
|
|
5480
|
+
successfulResponseHandler,
|
|
5481
|
+
abortSignal,
|
|
5482
|
+
fetch: fetch2
|
|
5483
|
+
});
|
|
5484
|
+
var postToApi3 = async ({
|
|
5485
|
+
url,
|
|
5486
|
+
headers = {},
|
|
5487
|
+
body,
|
|
5488
|
+
successfulResponseHandler,
|
|
5489
|
+
failedResponseHandler,
|
|
5490
|
+
abortSignal,
|
|
5491
|
+
fetch: fetch2 = getOriginalFetch23()
|
|
5492
|
+
}) => {
|
|
5493
|
+
try {
|
|
5494
|
+
const response = await fetch2(url, {
|
|
5495
|
+
method: "POST",
|
|
5496
|
+
headers: removeUndefinedEntries2(headers),
|
|
5497
|
+
body: body.content,
|
|
5498
|
+
signal: abortSignal
|
|
5499
|
+
});
|
|
5500
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5501
|
+
if (!response.ok) {
|
|
5502
|
+
let errorInformation;
|
|
5503
|
+
try {
|
|
5504
|
+
errorInformation = await failedResponseHandler({
|
|
5505
|
+
response,
|
|
5506
|
+
url,
|
|
5507
|
+
requestBodyValues: body.values
|
|
5508
|
+
});
|
|
5509
|
+
} catch (error) {
|
|
5510
|
+
if (isAbortError3(error) || APICallError2.isInstance(error)) {
|
|
5511
|
+
throw error;
|
|
5512
|
+
}
|
|
5513
|
+
throw new APICallError2({
|
|
5514
|
+
message: "Failed to process error response",
|
|
5515
|
+
cause: error,
|
|
5516
|
+
statusCode: response.status,
|
|
5517
|
+
url,
|
|
5518
|
+
responseHeaders,
|
|
5519
|
+
requestBodyValues: body.values
|
|
5520
|
+
});
|
|
5521
|
+
}
|
|
5522
|
+
throw errorInformation.value;
|
|
5523
|
+
}
|
|
5524
|
+
try {
|
|
5525
|
+
return await successfulResponseHandler({
|
|
5526
|
+
response,
|
|
5527
|
+
url,
|
|
5528
|
+
requestBodyValues: body.values
|
|
5529
|
+
});
|
|
5530
|
+
} catch (error) {
|
|
5531
|
+
if (error instanceof Error) {
|
|
5532
|
+
if (isAbortError3(error) || APICallError2.isInstance(error)) {
|
|
5533
|
+
throw error;
|
|
5534
|
+
}
|
|
5535
|
+
}
|
|
5536
|
+
throw new APICallError2({
|
|
5537
|
+
message: "Failed to process successful response",
|
|
5538
|
+
cause: error,
|
|
5539
|
+
statusCode: response.status,
|
|
5540
|
+
url,
|
|
5541
|
+
responseHeaders,
|
|
5542
|
+
requestBodyValues: body.values
|
|
5543
|
+
});
|
|
5544
|
+
}
|
|
5545
|
+
} catch (error) {
|
|
5546
|
+
throw handleFetchError3({ error, url, requestBodyValues: body.values });
|
|
5547
|
+
}
|
|
5548
|
+
};
|
|
5549
|
+
var createJsonErrorResponseHandler4 = ({
|
|
5550
|
+
errorSchema,
|
|
5551
|
+
errorToMessage: errorToMessage2,
|
|
5552
|
+
isRetryable
|
|
5553
|
+
}) => async ({ response, url, requestBodyValues }) => {
|
|
5554
|
+
const responseBody = await response.text();
|
|
5555
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5556
|
+
if (responseBody.trim() === "") {
|
|
5557
|
+
return {
|
|
5558
|
+
responseHeaders,
|
|
5559
|
+
value: new APICallError2({
|
|
5560
|
+
message: response.statusText,
|
|
5561
|
+
url,
|
|
5562
|
+
requestBodyValues,
|
|
5563
|
+
statusCode: response.status,
|
|
5564
|
+
responseHeaders,
|
|
5565
|
+
responseBody,
|
|
5566
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
5567
|
+
})
|
|
5568
|
+
};
|
|
5569
|
+
}
|
|
5570
|
+
try {
|
|
5571
|
+
const parsedError = await parseJSON3({
|
|
5572
|
+
text: responseBody,
|
|
5573
|
+
schema: errorSchema
|
|
5574
|
+
});
|
|
5575
|
+
return {
|
|
5576
|
+
responseHeaders,
|
|
5577
|
+
value: new APICallError2({
|
|
5578
|
+
message: errorToMessage2(parsedError),
|
|
5579
|
+
url,
|
|
5580
|
+
requestBodyValues,
|
|
5581
|
+
statusCode: response.status,
|
|
5582
|
+
responseHeaders,
|
|
5583
|
+
responseBody,
|
|
5584
|
+
data: parsedError,
|
|
5585
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
5586
|
+
})
|
|
5587
|
+
};
|
|
5588
|
+
} catch (parseError) {
|
|
5589
|
+
return {
|
|
5590
|
+
responseHeaders,
|
|
5591
|
+
value: new APICallError2({
|
|
5592
|
+
message: response.statusText,
|
|
5593
|
+
url,
|
|
5594
|
+
requestBodyValues,
|
|
5595
|
+
statusCode: response.status,
|
|
5596
|
+
responseHeaders,
|
|
5597
|
+
responseBody,
|
|
5598
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
5599
|
+
})
|
|
5600
|
+
};
|
|
5601
|
+
}
|
|
5602
|
+
};
|
|
5603
|
+
var createEventSourceResponseHandler4 = (chunkSchema) => async ({ response }) => {
|
|
5604
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5605
|
+
if (response.body == null) {
|
|
5606
|
+
throw new EmptyResponseBodyError2({});
|
|
5607
|
+
}
|
|
5608
|
+
return {
|
|
5609
|
+
responseHeaders,
|
|
5610
|
+
value: parseJsonEventStream3({
|
|
5611
|
+
stream: response.body,
|
|
5612
|
+
schema: chunkSchema
|
|
5613
|
+
})
|
|
5614
|
+
};
|
|
5615
|
+
};
|
|
5616
|
+
var createJsonResponseHandler4 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
5617
|
+
const responseBody = await response.text();
|
|
5618
|
+
const parsedResult = await safeParseJSON3({
|
|
5619
|
+
text: responseBody,
|
|
5620
|
+
schema: responseSchema
|
|
5621
|
+
});
|
|
5622
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5623
|
+
if (!parsedResult.success) {
|
|
5624
|
+
throw new APICallError2({
|
|
5625
|
+
message: "Invalid JSON response",
|
|
5626
|
+
cause: parsedResult.error,
|
|
5627
|
+
statusCode: response.status,
|
|
5628
|
+
responseHeaders,
|
|
5629
|
+
responseBody,
|
|
5630
|
+
url,
|
|
5631
|
+
requestBodyValues
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
return {
|
|
5635
|
+
responseHeaders,
|
|
5636
|
+
value: parsedResult.value,
|
|
5637
|
+
rawValue: parsedResult.rawValue
|
|
5638
|
+
};
|
|
5639
|
+
};
|
|
5640
|
+
var { btoa: btoa3} = globalThis;
|
|
5641
|
+
function convertUint8ArrayToBase642(array) {
|
|
5642
|
+
let latin1string = "";
|
|
5643
|
+
for (let i = 0; i < array.length; i++) {
|
|
5644
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
5645
|
+
}
|
|
5646
|
+
return btoa3(latin1string);
|
|
5647
|
+
}
|
|
5648
|
+
function withoutTrailingSlash4(url) {
|
|
5649
|
+
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
5650
|
+
}
|
|
5651
|
+
function isDefinedOrNotNull(value) {
|
|
5652
|
+
return value !== null && value !== void 0;
|
|
5653
|
+
}
|
|
5654
|
+
var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
5655
|
+
ReasoningFormat2["Unknown"] = "unknown";
|
|
5656
|
+
ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
|
|
5657
|
+
ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
|
|
5658
|
+
ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
|
|
5659
|
+
return ReasoningFormat2;
|
|
5660
|
+
})(ReasoningFormat || {});
|
|
5661
|
+
var CommonReasoningDetailSchema = z4.z.object({
|
|
5662
|
+
id: z4.z.string().nullish(),
|
|
5663
|
+
format: z4.z.nativeEnum(ReasoningFormat).nullish(),
|
|
5664
|
+
index: z4.z.number().optional()
|
|
5665
|
+
}).passthrough();
|
|
5666
|
+
var ReasoningDetailSummarySchema = z4.z.object({
|
|
5667
|
+
type: z4.z.literal(
|
|
5668
|
+
"reasoning.summary"
|
|
5669
|
+
/* Summary */
|
|
5670
|
+
),
|
|
5671
|
+
summary: z4.z.string()
|
|
5672
|
+
}).extend(CommonReasoningDetailSchema.shape);
|
|
5673
|
+
var ReasoningDetailEncryptedSchema = z4.z.object({
|
|
5674
|
+
type: z4.z.literal(
|
|
5675
|
+
"reasoning.encrypted"
|
|
5676
|
+
/* Encrypted */
|
|
5677
|
+
),
|
|
5678
|
+
data: z4.z.string()
|
|
5679
|
+
}).extend(CommonReasoningDetailSchema.shape);
|
|
5680
|
+
var ReasoningDetailTextSchema = z4.z.object({
|
|
5681
|
+
type: z4.z.literal(
|
|
5682
|
+
"reasoning.text"
|
|
5683
|
+
/* Text */
|
|
5684
|
+
),
|
|
5685
|
+
text: z4.z.string().nullish(),
|
|
5686
|
+
signature: z4.z.string().nullish()
|
|
5687
|
+
}).extend(CommonReasoningDetailSchema.shape);
|
|
5688
|
+
var ReasoningDetailUnionSchema = z4.z.union([
|
|
5689
|
+
ReasoningDetailSummarySchema,
|
|
5690
|
+
ReasoningDetailEncryptedSchema,
|
|
5691
|
+
ReasoningDetailTextSchema
|
|
5692
|
+
]);
|
|
5693
|
+
var ReasoningDetailsWithUnknownSchema = z4.z.union([
|
|
5694
|
+
ReasoningDetailUnionSchema,
|
|
5695
|
+
z4.z.unknown().transform(() => null)
|
|
5696
|
+
]);
|
|
5697
|
+
var ReasoningDetailArraySchema = z4.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
5698
|
+
z4.z.union([
|
|
5699
|
+
z4.z.object({
|
|
5700
|
+
delta: z4.z.object({
|
|
5701
|
+
reasoning_details: z4.z.array(ReasoningDetailsWithUnknownSchema)
|
|
5702
|
+
})
|
|
5703
|
+
}).transform(
|
|
5704
|
+
(data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
|
|
5705
|
+
),
|
|
5706
|
+
z4.z.object({
|
|
5707
|
+
message: z4.z.object({
|
|
5708
|
+
reasoning_details: z4.z.array(ReasoningDetailsWithUnknownSchema)
|
|
5709
|
+
})
|
|
5710
|
+
}).transform(
|
|
5711
|
+
(data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
|
|
5712
|
+
),
|
|
5713
|
+
z4.z.object({
|
|
5714
|
+
text: z4.z.string(),
|
|
5715
|
+
reasoning_details: z4.z.array(ReasoningDetailsWithUnknownSchema)
|
|
5716
|
+
}).transform((data) => data.reasoning_details.filter(isDefinedOrNotNull))
|
|
5717
|
+
]);
|
|
5718
|
+
var OpenRouterErrorResponseSchema = z4.z.object({
|
|
5719
|
+
error: z4.z.object({
|
|
5720
|
+
code: z4.z.union([z4.z.string(), z4.z.number()]).nullable().optional().default(null),
|
|
5721
|
+
message: z4.z.string(),
|
|
5722
|
+
type: z4.z.string().nullable().optional().default(null),
|
|
5723
|
+
param: z4.z.any().nullable().optional().default(null)
|
|
5724
|
+
}).passthrough()
|
|
5725
|
+
}).passthrough();
|
|
5726
|
+
var openrouterFailedResponseHandler = createJsonErrorResponseHandler4({
|
|
5727
|
+
errorSchema: OpenRouterErrorResponseSchema,
|
|
5728
|
+
errorToMessage: (data) => data.error.message
|
|
5729
|
+
});
|
|
5730
|
+
var OpenRouterProviderMetadataSchema = z4.z.object({
|
|
5731
|
+
provider: z4.z.string(),
|
|
5732
|
+
reasoning_details: z4.z.array(ReasoningDetailUnionSchema).optional(),
|
|
5733
|
+
usage: z4.z.object({
|
|
5734
|
+
promptTokens: z4.z.number(),
|
|
5735
|
+
promptTokensDetails: z4.z.object({
|
|
5736
|
+
cachedTokens: z4.z.number()
|
|
5737
|
+
}).passthrough().optional(),
|
|
5738
|
+
completionTokens: z4.z.number(),
|
|
5739
|
+
completionTokensDetails: z4.z.object({
|
|
5740
|
+
reasoningTokens: z4.z.number()
|
|
5741
|
+
}).passthrough().optional(),
|
|
5742
|
+
totalTokens: z4.z.number(),
|
|
5743
|
+
cost: z4.z.number().optional(),
|
|
5744
|
+
costDetails: z4.z.object({
|
|
5745
|
+
upstreamInferenceCost: z4.z.number()
|
|
5746
|
+
}).passthrough()
|
|
5747
|
+
}).passthrough()
|
|
5748
|
+
}).passthrough();
|
|
5749
|
+
var OpenRouterProviderOptionsSchema = z4.z.object({
|
|
5750
|
+
openrouter: z4.z.object({
|
|
5751
|
+
reasoning_details: z4.z.array(ReasoningDetailUnionSchema).optional()
|
|
5752
|
+
}).optional()
|
|
5753
|
+
}).optional();
|
|
5754
|
+
function mapOpenRouterFinishReason(finishReason) {
|
|
5755
|
+
switch (finishReason) {
|
|
5756
|
+
case "stop":
|
|
5757
|
+
return "stop";
|
|
5758
|
+
case "length":
|
|
5759
|
+
return "length";
|
|
5760
|
+
case "content_filter":
|
|
5761
|
+
return "content-filter";
|
|
5762
|
+
case "function_call":
|
|
5763
|
+
case "tool_calls":
|
|
5764
|
+
return "tool-calls";
|
|
5765
|
+
default:
|
|
5766
|
+
return "unknown";
|
|
5767
|
+
}
|
|
5768
|
+
}
|
|
5769
|
+
function isUrl({
|
|
5770
|
+
url,
|
|
5771
|
+
protocols
|
|
5772
|
+
}) {
|
|
5773
|
+
try {
|
|
5774
|
+
const urlObj = new URL(url);
|
|
5775
|
+
return protocols.has(urlObj.protocol);
|
|
5776
|
+
} catch (_) {
|
|
5777
|
+
return false;
|
|
5778
|
+
}
|
|
5779
|
+
}
|
|
5780
|
+
function getFileUrl({
|
|
5781
|
+
part,
|
|
5782
|
+
defaultMediaType
|
|
5783
|
+
}) {
|
|
5784
|
+
var _a15, _b;
|
|
5785
|
+
if (part.data instanceof Uint8Array) {
|
|
5786
|
+
const base64 = convertUint8ArrayToBase642(part.data);
|
|
5787
|
+
return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
|
|
5788
|
+
}
|
|
5789
|
+
const stringUrl = part.data.toString();
|
|
5790
|
+
if (isUrl({
|
|
5791
|
+
url: stringUrl,
|
|
5792
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
5793
|
+
})) {
|
|
5794
|
+
return stringUrl;
|
|
5795
|
+
}
|
|
5796
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
5797
|
+
}
|
|
5798
|
+
function getMediaType(dataUrl, defaultMediaType) {
|
|
5799
|
+
var _a15;
|
|
5800
|
+
const match = dataUrl.match(/^data:([^;]+)/);
|
|
5801
|
+
return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
|
|
5802
|
+
}
|
|
5803
|
+
function getBase64FromDataUrl(dataUrl) {
|
|
5804
|
+
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
5805
|
+
return match ? match[1] : dataUrl;
|
|
5806
|
+
}
|
|
5807
|
+
function getCacheControl(providerMetadata) {
|
|
5808
|
+
var _a15, _b, _c;
|
|
5809
|
+
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
5810
|
+
const openrouter2 = providerMetadata == null ? void 0 : providerMetadata.openrouter;
|
|
5811
|
+
return (_c = (_b = (_a15 = openrouter2 == null ? void 0 : openrouter2.cacheControl) != null ? _a15 : openrouter2 == null ? void 0 : openrouter2.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
5812
|
+
}
|
|
5813
|
+
function convertToOpenRouterChatMessages(prompt) {
|
|
5814
|
+
var _a15, _b, _c, _d, _e;
|
|
5815
|
+
const messages = [];
|
|
5816
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
5817
|
+
switch (role) {
|
|
5818
|
+
case "system": {
|
|
5819
|
+
messages.push({
|
|
5820
|
+
role: "system",
|
|
5821
|
+
content,
|
|
5822
|
+
cache_control: getCacheControl(providerOptions)
|
|
5823
|
+
});
|
|
5824
|
+
break;
|
|
5825
|
+
}
|
|
5826
|
+
case "user": {
|
|
5827
|
+
if (content.length === 1 && ((_a15 = content[0]) == null ? void 0 : _a15.type) === "text") {
|
|
5828
|
+
const cacheControl = (_b = getCacheControl(providerOptions)) != null ? _b : getCacheControl(content[0].providerOptions);
|
|
5829
|
+
const contentWithCacheControl = cacheControl ? [
|
|
5830
|
+
{
|
|
5831
|
+
type: "text",
|
|
5832
|
+
text: content[0].text,
|
|
5833
|
+
cache_control: cacheControl
|
|
5834
|
+
}
|
|
5835
|
+
] : content[0].text;
|
|
5836
|
+
messages.push({
|
|
5837
|
+
role: "user",
|
|
5838
|
+
content: contentWithCacheControl
|
|
5839
|
+
});
|
|
5840
|
+
break;
|
|
5841
|
+
}
|
|
5842
|
+
const messageCacheControl = getCacheControl(providerOptions);
|
|
5843
|
+
const contentParts = content.map(
|
|
5844
|
+
(part) => {
|
|
5845
|
+
var _a16, _b2, _c2, _d2, _e2, _f;
|
|
5846
|
+
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
5847
|
+
switch (part.type) {
|
|
5848
|
+
case "text":
|
|
5849
|
+
return {
|
|
5850
|
+
type: "text",
|
|
5851
|
+
text: part.text,
|
|
5852
|
+
// For text parts, only use part-specific cache control
|
|
5853
|
+
cache_control: cacheControl
|
|
5854
|
+
};
|
|
5855
|
+
case "file": {
|
|
5856
|
+
if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
|
|
5857
|
+
const url = getFileUrl({
|
|
5858
|
+
part,
|
|
5859
|
+
defaultMediaType: "image/jpeg"
|
|
5860
|
+
});
|
|
5861
|
+
return {
|
|
5862
|
+
type: "image_url",
|
|
5863
|
+
image_url: {
|
|
5864
|
+
url
|
|
5865
|
+
},
|
|
5866
|
+
// For image parts, use part-specific or message-level cache control
|
|
5867
|
+
cache_control: cacheControl
|
|
5868
|
+
};
|
|
5869
|
+
}
|
|
5870
|
+
const fileName = String(
|
|
5871
|
+
(_f = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f : ""
|
|
5872
|
+
);
|
|
5873
|
+
const fileData = getFileUrl({
|
|
5874
|
+
part,
|
|
5875
|
+
defaultMediaType: "application/pdf"
|
|
5876
|
+
});
|
|
5877
|
+
if (isUrl({
|
|
5878
|
+
url: fileData,
|
|
5879
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
5880
|
+
})) {
|
|
5881
|
+
return {
|
|
5882
|
+
type: "file",
|
|
5883
|
+
file: {
|
|
5884
|
+
filename: fileName,
|
|
5885
|
+
file_data: fileData
|
|
5886
|
+
}
|
|
5887
|
+
};
|
|
5888
|
+
}
|
|
5889
|
+
return {
|
|
5890
|
+
type: "file",
|
|
5891
|
+
file: {
|
|
5892
|
+
filename: fileName,
|
|
5893
|
+
file_data: fileData
|
|
5894
|
+
},
|
|
5895
|
+
cache_control: cacheControl
|
|
5896
|
+
};
|
|
5897
|
+
}
|
|
5898
|
+
default: {
|
|
5899
|
+
return {
|
|
5900
|
+
type: "text",
|
|
5901
|
+
text: "",
|
|
5902
|
+
cache_control: cacheControl
|
|
5903
|
+
};
|
|
5904
|
+
}
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
);
|
|
5908
|
+
messages.push({
|
|
5909
|
+
role: "user",
|
|
5910
|
+
content: contentParts
|
|
5911
|
+
});
|
|
5912
|
+
break;
|
|
5913
|
+
}
|
|
5914
|
+
case "assistant": {
|
|
5915
|
+
let text = "";
|
|
5916
|
+
let reasoning = "";
|
|
5917
|
+
const toolCalls = [];
|
|
5918
|
+
for (const part of content) {
|
|
5919
|
+
switch (part.type) {
|
|
5920
|
+
case "text": {
|
|
5921
|
+
text += part.text;
|
|
5922
|
+
break;
|
|
5923
|
+
}
|
|
5924
|
+
case "tool-call": {
|
|
5925
|
+
toolCalls.push({
|
|
5926
|
+
id: part.toolCallId,
|
|
5927
|
+
type: "function",
|
|
5928
|
+
function: {
|
|
5929
|
+
name: part.toolName,
|
|
5930
|
+
arguments: JSON.stringify(part.input)
|
|
5931
|
+
}
|
|
5932
|
+
});
|
|
5933
|
+
break;
|
|
5934
|
+
}
|
|
5935
|
+
case "reasoning": {
|
|
5936
|
+
reasoning += part.text;
|
|
5937
|
+
break;
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
}
|
|
5941
|
+
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
5942
|
+
const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
|
|
5943
|
+
messages.push({
|
|
5944
|
+
role: "assistant",
|
|
5945
|
+
content: text,
|
|
5946
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
5947
|
+
reasoning: reasoning || void 0,
|
|
5948
|
+
// Only include reasoning_details if we have the preserved original version
|
|
5949
|
+
reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
|
|
5950
|
+
cache_control: getCacheControl(providerOptions)
|
|
5951
|
+
});
|
|
5952
|
+
break;
|
|
5953
|
+
}
|
|
5954
|
+
case "tool": {
|
|
5955
|
+
for (const toolResponse of content) {
|
|
5956
|
+
const content2 = getToolResultContent(toolResponse);
|
|
5957
|
+
messages.push({
|
|
5958
|
+
role: "tool",
|
|
5959
|
+
tool_call_id: toolResponse.toolCallId,
|
|
5960
|
+
content: content2,
|
|
5961
|
+
cache_control: (_e = getCacheControl(providerOptions)) != null ? _e : getCacheControl(toolResponse.providerOptions)
|
|
5962
|
+
});
|
|
5963
|
+
}
|
|
5964
|
+
break;
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
return messages;
|
|
5969
|
+
}
|
|
5970
|
+
function getToolResultContent(input) {
|
|
5971
|
+
return input.output.type === "text" ? input.output.value : JSON.stringify(input.output.value);
|
|
5972
|
+
}
|
|
5973
|
+
z4.z.union([
|
|
5974
|
+
z4.z.literal("auto"),
|
|
5975
|
+
z4.z.literal("none"),
|
|
5976
|
+
z4.z.literal("required"),
|
|
5977
|
+
z4.z.object({
|
|
5978
|
+
type: z4.z.literal("function"),
|
|
5979
|
+
function: z4.z.object({
|
|
5980
|
+
name: z4.z.string()
|
|
5981
|
+
})
|
|
5982
|
+
})
|
|
5983
|
+
]);
|
|
5984
|
+
function getChatCompletionToolChoice(toolChoice) {
|
|
5985
|
+
switch (toolChoice.type) {
|
|
5986
|
+
case "auto":
|
|
5987
|
+
case "none":
|
|
5988
|
+
case "required":
|
|
5989
|
+
return toolChoice.type;
|
|
5990
|
+
case "tool": {
|
|
5991
|
+
return {
|
|
5992
|
+
type: "function",
|
|
5993
|
+
function: { name: toolChoice.toolName }
|
|
5994
|
+
};
|
|
5995
|
+
}
|
|
5996
|
+
default: {
|
|
5997
|
+
throw new InvalidArgumentError2({
|
|
5998
|
+
argument: "toolChoice",
|
|
5999
|
+
message: `Invalid tool choice type: ${JSON.stringify(toolChoice)}`
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
}
|
|
6003
|
+
}
|
|
6004
|
+
var ImageResponseSchema = z4.z.object({
|
|
6005
|
+
type: z4.z.literal("image_url"),
|
|
6006
|
+
image_url: z4.z.object({
|
|
6007
|
+
url: z4.z.string()
|
|
6008
|
+
}).passthrough()
|
|
6009
|
+
}).passthrough();
|
|
6010
|
+
var ImageResponseWithUnknownSchema = z4.z.union([
|
|
6011
|
+
ImageResponseSchema,
|
|
6012
|
+
z4.z.unknown().transform(() => null)
|
|
6013
|
+
]);
|
|
6014
|
+
var ImageResponseArraySchema = z4.z.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
6015
|
+
var OpenRouterChatCompletionBaseResponseSchema = z4.z.object({
|
|
6016
|
+
id: z4.z.string().optional(),
|
|
6017
|
+
model: z4.z.string().optional(),
|
|
6018
|
+
provider: z4.z.string().optional(),
|
|
6019
|
+
usage: z4.z.object({
|
|
6020
|
+
prompt_tokens: z4.z.number(),
|
|
6021
|
+
prompt_tokens_details: z4.z.object({
|
|
6022
|
+
cached_tokens: z4.z.number()
|
|
6023
|
+
}).passthrough().nullish(),
|
|
6024
|
+
completion_tokens: z4.z.number(),
|
|
6025
|
+
completion_tokens_details: z4.z.object({
|
|
6026
|
+
reasoning_tokens: z4.z.number()
|
|
6027
|
+
}).passthrough().nullish(),
|
|
6028
|
+
total_tokens: z4.z.number(),
|
|
6029
|
+
cost: z4.z.number().optional(),
|
|
6030
|
+
cost_details: z4.z.object({
|
|
6031
|
+
upstream_inference_cost: z4.z.number().nullish()
|
|
6032
|
+
}).passthrough().nullish()
|
|
6033
|
+
}).passthrough().nullish()
|
|
6034
|
+
}).passthrough();
|
|
6035
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = z4.z.union([
|
|
6036
|
+
// Success response with choices
|
|
6037
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
6038
|
+
choices: z4.z.array(
|
|
6039
|
+
z4.z.object({
|
|
6040
|
+
message: z4.z.object({
|
|
6041
|
+
role: z4.z.literal("assistant"),
|
|
6042
|
+
content: z4.z.string().nullable().optional(),
|
|
6043
|
+
reasoning: z4.z.string().nullable().optional(),
|
|
6044
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
6045
|
+
images: ImageResponseArraySchema.nullish(),
|
|
6046
|
+
tool_calls: z4.z.array(
|
|
6047
|
+
z4.z.object({
|
|
6048
|
+
id: z4.z.string().optional().nullable(),
|
|
6049
|
+
type: z4.z.literal("function"),
|
|
6050
|
+
function: z4.z.object({
|
|
6051
|
+
name: z4.z.string(),
|
|
6052
|
+
arguments: z4.z.string()
|
|
6053
|
+
}).passthrough()
|
|
6054
|
+
}).passthrough()
|
|
6055
|
+
).optional(),
|
|
6056
|
+
annotations: z4.z.array(
|
|
6057
|
+
z4.z.union([
|
|
6058
|
+
// URL citation from web search
|
|
6059
|
+
z4.z.object({
|
|
6060
|
+
type: z4.z.literal("url_citation"),
|
|
6061
|
+
url_citation: z4.z.object({
|
|
6062
|
+
end_index: z4.z.number(),
|
|
6063
|
+
start_index: z4.z.number(),
|
|
6064
|
+
title: z4.z.string(),
|
|
6065
|
+
url: z4.z.string(),
|
|
6066
|
+
content: z4.z.string().optional()
|
|
6067
|
+
}).passthrough()
|
|
6068
|
+
}).passthrough(),
|
|
6069
|
+
// File annotation from FileParserPlugin (old format)
|
|
6070
|
+
z4.z.object({
|
|
6071
|
+
type: z4.z.literal("file_annotation"),
|
|
6072
|
+
file_annotation: z4.z.object({
|
|
6073
|
+
file_id: z4.z.string(),
|
|
6074
|
+
quote: z4.z.string().optional()
|
|
6075
|
+
}).passthrough()
|
|
6076
|
+
}).passthrough(),
|
|
6077
|
+
// File annotation from FileParserPlugin (new format)
|
|
6078
|
+
z4.z.object({
|
|
6079
|
+
type: z4.z.literal("file"),
|
|
6080
|
+
file: z4.z.object({
|
|
6081
|
+
hash: z4.z.string(),
|
|
6082
|
+
name: z4.z.string(),
|
|
6083
|
+
content: z4.z.array(
|
|
6084
|
+
z4.z.object({
|
|
6085
|
+
type: z4.z.string(),
|
|
6086
|
+
text: z4.z.string()
|
|
6087
|
+
}).passthrough()
|
|
6088
|
+
).optional()
|
|
6089
|
+
}).passthrough()
|
|
6090
|
+
}).passthrough()
|
|
6091
|
+
])
|
|
6092
|
+
).nullish()
|
|
6093
|
+
}).passthrough(),
|
|
6094
|
+
index: z4.z.number().nullish(),
|
|
6095
|
+
logprobs: z4.z.object({
|
|
6096
|
+
content: z4.z.array(
|
|
6097
|
+
z4.z.object({
|
|
6098
|
+
token: z4.z.string(),
|
|
6099
|
+
logprob: z4.z.number(),
|
|
6100
|
+
top_logprobs: z4.z.array(
|
|
6101
|
+
z4.z.object({
|
|
6102
|
+
token: z4.z.string(),
|
|
6103
|
+
logprob: z4.z.number()
|
|
6104
|
+
}).passthrough()
|
|
6105
|
+
)
|
|
6106
|
+
}).passthrough()
|
|
6107
|
+
).nullable()
|
|
6108
|
+
}).passthrough().nullable().optional(),
|
|
6109
|
+
finish_reason: z4.z.string().optional().nullable()
|
|
6110
|
+
}).passthrough()
|
|
6111
|
+
)
|
|
6112
|
+
}),
|
|
6113
|
+
// Error response (HTTP 200 with error payload)
|
|
6114
|
+
OpenRouterErrorResponseSchema.extend({
|
|
6115
|
+
user_id: z4.z.string().optional()
|
|
6116
|
+
})
|
|
6117
|
+
]);
|
|
6118
|
+
var OpenRouterStreamChatCompletionChunkSchema = z4.z.union([
|
|
6119
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
6120
|
+
choices: z4.z.array(
|
|
6121
|
+
z4.z.object({
|
|
6122
|
+
delta: z4.z.object({
|
|
6123
|
+
role: z4.z.enum(["assistant"]).optional(),
|
|
6124
|
+
content: z4.z.string().nullish(),
|
|
6125
|
+
reasoning: z4.z.string().nullish().optional(),
|
|
6126
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
6127
|
+
images: ImageResponseArraySchema.nullish(),
|
|
6128
|
+
tool_calls: z4.z.array(
|
|
6129
|
+
z4.z.object({
|
|
6130
|
+
index: z4.z.number().nullish(),
|
|
6131
|
+
id: z4.z.string().nullish(),
|
|
6132
|
+
type: z4.z.literal("function").optional(),
|
|
6133
|
+
function: z4.z.object({
|
|
6134
|
+
name: z4.z.string().nullish(),
|
|
6135
|
+
arguments: z4.z.string().nullish()
|
|
6136
|
+
}).passthrough()
|
|
6137
|
+
}).passthrough()
|
|
6138
|
+
).nullish(),
|
|
6139
|
+
annotations: z4.z.array(
|
|
6140
|
+
z4.z.union([
|
|
6141
|
+
// URL citation from web search
|
|
6142
|
+
z4.z.object({
|
|
6143
|
+
type: z4.z.literal("url_citation"),
|
|
6144
|
+
url_citation: z4.z.object({
|
|
6145
|
+
end_index: z4.z.number(),
|
|
6146
|
+
start_index: z4.z.number(),
|
|
6147
|
+
title: z4.z.string(),
|
|
6148
|
+
url: z4.z.string(),
|
|
6149
|
+
content: z4.z.string().optional()
|
|
6150
|
+
}).passthrough()
|
|
6151
|
+
}).passthrough(),
|
|
6152
|
+
// File annotation from FileParserPlugin (old format)
|
|
6153
|
+
z4.z.object({
|
|
6154
|
+
type: z4.z.literal("file_annotation"),
|
|
6155
|
+
file_annotation: z4.z.object({
|
|
6156
|
+
file_id: z4.z.string(),
|
|
6157
|
+
quote: z4.z.string().optional()
|
|
6158
|
+
}).passthrough()
|
|
6159
|
+
}).passthrough(),
|
|
6160
|
+
// File annotation from FileParserPlugin (new format)
|
|
6161
|
+
z4.z.object({
|
|
6162
|
+
type: z4.z.literal("file"),
|
|
6163
|
+
file: z4.z.object({
|
|
6164
|
+
hash: z4.z.string(),
|
|
6165
|
+
name: z4.z.string(),
|
|
6166
|
+
content: z4.z.array(
|
|
6167
|
+
z4.z.object({
|
|
6168
|
+
type: z4.z.string(),
|
|
6169
|
+
text: z4.z.string()
|
|
6170
|
+
}).passthrough()
|
|
6171
|
+
).optional()
|
|
6172
|
+
}).passthrough()
|
|
6173
|
+
}).passthrough()
|
|
6174
|
+
])
|
|
6175
|
+
).nullish()
|
|
6176
|
+
}).passthrough().nullish(),
|
|
6177
|
+
logprobs: z4.z.object({
|
|
6178
|
+
content: z4.z.array(
|
|
6179
|
+
z4.z.object({
|
|
6180
|
+
token: z4.z.string(),
|
|
6181
|
+
logprob: z4.z.number(),
|
|
6182
|
+
top_logprobs: z4.z.array(
|
|
6183
|
+
z4.z.object({
|
|
6184
|
+
token: z4.z.string(),
|
|
6185
|
+
logprob: z4.z.number()
|
|
6186
|
+
}).passthrough()
|
|
6187
|
+
)
|
|
6188
|
+
}).passthrough()
|
|
6189
|
+
).nullable()
|
|
6190
|
+
}).passthrough().nullish(),
|
|
6191
|
+
finish_reason: z4.z.string().nullable().optional(),
|
|
6192
|
+
index: z4.z.number().nullish()
|
|
6193
|
+
}).passthrough()
|
|
6194
|
+
)
|
|
6195
|
+
}),
|
|
6196
|
+
OpenRouterErrorResponseSchema
|
|
6197
|
+
]);
|
|
6198
|
+
var OpenRouterChatLanguageModel = class {
|
|
6199
|
+
constructor(modelId, settings, config) {
|
|
6200
|
+
this.specificationVersion = "v2";
|
|
6201
|
+
this.provider = "openrouter";
|
|
6202
|
+
this.defaultObjectGenerationMode = "tool";
|
|
6203
|
+
this.supportedUrls = {
|
|
6204
|
+
"image/*": [
|
|
6205
|
+
/^data:image\/[a-zA-Z]+;base64,/,
|
|
6206
|
+
/^https?:\/\/.+\.(jpg|jpeg|png|gif|webp)$/i
|
|
6207
|
+
],
|
|
6208
|
+
// 'text/*': [/^data:text\//, /^https?:\/\/.+$/],
|
|
6209
|
+
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
6210
|
+
};
|
|
6211
|
+
this.modelId = modelId;
|
|
6212
|
+
this.settings = settings;
|
|
6213
|
+
this.config = config;
|
|
6214
|
+
}
|
|
6215
|
+
getArgs({
|
|
6216
|
+
prompt,
|
|
6217
|
+
maxOutputTokens,
|
|
6218
|
+
temperature,
|
|
6219
|
+
topP,
|
|
6220
|
+
frequencyPenalty,
|
|
6221
|
+
presencePenalty,
|
|
6222
|
+
seed,
|
|
6223
|
+
stopSequences,
|
|
6224
|
+
responseFormat,
|
|
6225
|
+
topK,
|
|
6226
|
+
tools,
|
|
6227
|
+
toolChoice
|
|
6228
|
+
}) {
|
|
6229
|
+
var _a15;
|
|
6230
|
+
const baseArgs = __spreadValues(__spreadValues({
|
|
6231
|
+
// model id:
|
|
6232
|
+
model: this.modelId,
|
|
6233
|
+
models: this.settings.models,
|
|
6234
|
+
// model specific settings:
|
|
6235
|
+
logit_bias: this.settings.logitBias,
|
|
6236
|
+
logprobs: this.settings.logprobs === true || typeof this.settings.logprobs === "number" ? true : void 0,
|
|
6237
|
+
top_logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
6238
|
+
user: this.settings.user,
|
|
6239
|
+
parallel_tool_calls: this.settings.parallelToolCalls,
|
|
6240
|
+
// standardized settings:
|
|
6241
|
+
max_tokens: maxOutputTokens,
|
|
6242
|
+
temperature,
|
|
6243
|
+
top_p: topP,
|
|
6244
|
+
frequency_penalty: frequencyPenalty,
|
|
6245
|
+
presence_penalty: presencePenalty,
|
|
6246
|
+
seed,
|
|
6247
|
+
stop: stopSequences,
|
|
6248
|
+
response_format: responseFormat,
|
|
6249
|
+
top_k: topK,
|
|
6250
|
+
// messages:
|
|
6251
|
+
messages: convertToOpenRouterChatMessages(prompt),
|
|
6252
|
+
// OpenRouter specific settings:
|
|
6253
|
+
include_reasoning: this.settings.includeReasoning,
|
|
6254
|
+
reasoning: this.settings.reasoning,
|
|
6255
|
+
usage: this.settings.usage,
|
|
6256
|
+
// Web search settings:
|
|
6257
|
+
plugins: this.settings.plugins,
|
|
6258
|
+
web_search_options: this.settings.web_search_options,
|
|
6259
|
+
// Provider routing settings:
|
|
6260
|
+
provider: this.settings.provider
|
|
6261
|
+
}, this.config.extraBody), this.settings.extraBody);
|
|
6262
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
6263
|
+
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
6264
|
+
response_format: {
|
|
6265
|
+
type: "json_schema",
|
|
6266
|
+
json_schema: __spreadValues({
|
|
6267
|
+
schema: responseFormat.schema,
|
|
6268
|
+
strict: true,
|
|
6269
|
+
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
6270
|
+
}, responseFormat.description && {
|
|
6271
|
+
description: responseFormat.description
|
|
6272
|
+
})
|
|
6273
|
+
}
|
|
6274
|
+
});
|
|
6275
|
+
}
|
|
6276
|
+
if (tools && tools.length > 0) {
|
|
6277
|
+
const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
|
|
6278
|
+
type: "function",
|
|
6279
|
+
function: {
|
|
6280
|
+
name: tool.name,
|
|
6281
|
+
description: tool.description,
|
|
6282
|
+
parameters: tool.inputSchema
|
|
6283
|
+
}
|
|
6284
|
+
}));
|
|
6285
|
+
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
6286
|
+
tools: mappedTools,
|
|
6287
|
+
tool_choice: toolChoice ? getChatCompletionToolChoice(toolChoice) : void 0
|
|
6288
|
+
});
|
|
6289
|
+
}
|
|
6290
|
+
return baseArgs;
|
|
6291
|
+
}
|
|
6292
|
+
async doGenerate(options) {
|
|
6293
|
+
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, _y;
|
|
6294
|
+
const providerOptions = options.providerOptions || {};
|
|
6295
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
6296
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
6297
|
+
const { value: responseValue, responseHeaders } = await postJsonToApi4({
|
|
6298
|
+
url: this.config.url({
|
|
6299
|
+
path: "/chat/completions",
|
|
6300
|
+
modelId: this.modelId
|
|
6301
|
+
}),
|
|
6302
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
6303
|
+
body: args,
|
|
6304
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
6305
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
6306
|
+
OpenRouterNonStreamChatCompletionResponseSchema
|
|
6307
|
+
),
|
|
6308
|
+
abortSignal: options.abortSignal,
|
|
6309
|
+
fetch: this.config.fetch
|
|
6310
|
+
});
|
|
6311
|
+
if ("error" in responseValue) {
|
|
6312
|
+
const errorData = responseValue.error;
|
|
6313
|
+
throw new APICallError2({
|
|
6314
|
+
message: errorData.message,
|
|
6315
|
+
url: this.config.url({
|
|
6316
|
+
path: "/chat/completions",
|
|
6317
|
+
modelId: this.modelId
|
|
6318
|
+
}),
|
|
6319
|
+
requestBodyValues: args,
|
|
6320
|
+
statusCode: 200,
|
|
6321
|
+
responseHeaders,
|
|
6322
|
+
data: errorData
|
|
6323
|
+
});
|
|
6324
|
+
}
|
|
6325
|
+
const response = responseValue;
|
|
6326
|
+
const choice = response.choices[0];
|
|
6327
|
+
if (!choice) {
|
|
6328
|
+
throw new NoContentGeneratedError({
|
|
6329
|
+
message: "No choice in response"
|
|
6330
|
+
});
|
|
6331
|
+
}
|
|
6332
|
+
const usageInfo = response.usage ? {
|
|
6333
|
+
inputTokens: (_a15 = response.usage.prompt_tokens) != null ? _a15 : 0,
|
|
6334
|
+
outputTokens: (_b = response.usage.completion_tokens) != null ? _b : 0,
|
|
6335
|
+
totalTokens: ((_c = response.usage.prompt_tokens) != null ? _c : 0) + ((_d = response.usage.completion_tokens) != null ? _d : 0),
|
|
6336
|
+
reasoningTokens: (_f = (_e = response.usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0,
|
|
6337
|
+
cachedInputTokens: (_h = (_g = response.usage.prompt_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : 0
|
|
6338
|
+
} : {
|
|
6339
|
+
inputTokens: 0,
|
|
6340
|
+
outputTokens: 0,
|
|
6341
|
+
totalTokens: 0,
|
|
6342
|
+
reasoningTokens: 0,
|
|
6343
|
+
cachedInputTokens: 0
|
|
6344
|
+
};
|
|
6345
|
+
const reasoningDetails = (_i = choice.message.reasoning_details) != null ? _i : [];
|
|
6346
|
+
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
6347
|
+
switch (detail.type) {
|
|
6348
|
+
case "reasoning.text": {
|
|
6349
|
+
if (detail.text) {
|
|
6350
|
+
return {
|
|
6351
|
+
type: "reasoning",
|
|
6352
|
+
text: detail.text
|
|
6353
|
+
};
|
|
6354
|
+
}
|
|
6355
|
+
break;
|
|
6356
|
+
}
|
|
6357
|
+
case "reasoning.summary": {
|
|
6358
|
+
if (detail.summary) {
|
|
6359
|
+
return {
|
|
6360
|
+
type: "reasoning",
|
|
6361
|
+
text: detail.summary
|
|
6362
|
+
};
|
|
6363
|
+
}
|
|
6364
|
+
break;
|
|
6365
|
+
}
|
|
6366
|
+
case "reasoning.encrypted": {
|
|
6367
|
+
if (detail.data) {
|
|
6368
|
+
return {
|
|
6369
|
+
type: "reasoning",
|
|
6370
|
+
text: "[REDACTED]"
|
|
6371
|
+
};
|
|
6372
|
+
}
|
|
6373
|
+
break;
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
return null;
|
|
6377
|
+
}).filter((p) => p !== null) : choice.message.reasoning ? [
|
|
6378
|
+
{
|
|
6379
|
+
type: "reasoning",
|
|
6380
|
+
text: choice.message.reasoning
|
|
6381
|
+
}
|
|
6382
|
+
] : [];
|
|
6383
|
+
const content = [];
|
|
6384
|
+
content.push(...reasoning);
|
|
6385
|
+
if (choice.message.content) {
|
|
6386
|
+
content.push({
|
|
6387
|
+
type: "text",
|
|
6388
|
+
text: choice.message.content
|
|
6389
|
+
});
|
|
6390
|
+
}
|
|
6391
|
+
if (choice.message.tool_calls) {
|
|
6392
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
6393
|
+
content.push({
|
|
6394
|
+
type: "tool-call",
|
|
6395
|
+
toolCallId: (_j = toolCall.id) != null ? _j : generateId4(),
|
|
6396
|
+
toolName: toolCall.function.name,
|
|
6397
|
+
input: toolCall.function.arguments
|
|
6398
|
+
});
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
6401
|
+
if (choice.message.images) {
|
|
6402
|
+
for (const image of choice.message.images) {
|
|
6403
|
+
content.push({
|
|
6404
|
+
type: "file",
|
|
6405
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
6406
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
6407
|
+
});
|
|
6408
|
+
}
|
|
6409
|
+
}
|
|
6410
|
+
if (choice.message.annotations) {
|
|
6411
|
+
for (const annotation of choice.message.annotations) {
|
|
6412
|
+
if (annotation.type === "url_citation") {
|
|
6413
|
+
content.push({
|
|
6414
|
+
type: "source",
|
|
6415
|
+
sourceType: "url",
|
|
6416
|
+
id: annotation.url_citation.url,
|
|
6417
|
+
url: annotation.url_citation.url,
|
|
6418
|
+
title: annotation.url_citation.title,
|
|
6419
|
+
providerMetadata: {
|
|
6420
|
+
openrouter: {
|
|
6421
|
+
content: annotation.url_citation.content || ""
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
});
|
|
6425
|
+
}
|
|
6426
|
+
}
|
|
6427
|
+
}
|
|
6428
|
+
return {
|
|
6429
|
+
content,
|
|
6430
|
+
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
6431
|
+
usage: usageInfo,
|
|
6432
|
+
warnings: [],
|
|
6433
|
+
providerMetadata: {
|
|
6434
|
+
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
6435
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
6436
|
+
reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
|
|
6437
|
+
usage: {
|
|
6438
|
+
promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
|
|
6439
|
+
completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
|
|
6440
|
+
totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
|
|
6441
|
+
cost: (_p = response.usage) == null ? void 0 : _p.cost,
|
|
6442
|
+
promptTokensDetails: {
|
|
6443
|
+
cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
|
|
6444
|
+
},
|
|
6445
|
+
completionTokensDetails: {
|
|
6446
|
+
reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
|
|
6447
|
+
},
|
|
6448
|
+
costDetails: {
|
|
6449
|
+
upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6452
|
+
})
|
|
6453
|
+
},
|
|
6454
|
+
request: { body: args },
|
|
6455
|
+
response: {
|
|
6456
|
+
id: response.id,
|
|
6457
|
+
modelId: response.model,
|
|
6458
|
+
headers: responseHeaders
|
|
6459
|
+
}
|
|
6460
|
+
};
|
|
6461
|
+
}
|
|
6462
|
+
async doStream(options) {
|
|
6463
|
+
var _a15;
|
|
6464
|
+
const providerOptions = options.providerOptions || {};
|
|
6465
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
6466
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
6467
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
6468
|
+
url: this.config.url({
|
|
6469
|
+
path: "/chat/completions",
|
|
6470
|
+
modelId: this.modelId
|
|
6471
|
+
}),
|
|
6472
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
6473
|
+
body: __spreadProps(__spreadValues({}, args), {
|
|
6474
|
+
stream: true,
|
|
6475
|
+
// only include stream_options when in strict compatibility mode:
|
|
6476
|
+
stream_options: this.config.compatibility === "strict" ? __spreadValues({
|
|
6477
|
+
include_usage: true
|
|
6478
|
+
}, ((_a15 = this.settings.usage) == null ? void 0 : _a15.include) ? { include_usage: true } : {}) : void 0
|
|
6479
|
+
}),
|
|
6480
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
6481
|
+
successfulResponseHandler: createEventSourceResponseHandler4(
|
|
6482
|
+
OpenRouterStreamChatCompletionChunkSchema
|
|
6483
|
+
),
|
|
6484
|
+
abortSignal: options.abortSignal,
|
|
6485
|
+
fetch: this.config.fetch
|
|
6486
|
+
});
|
|
6487
|
+
const toolCalls = [];
|
|
6488
|
+
let finishReason = "other";
|
|
6489
|
+
const usage = {
|
|
6490
|
+
inputTokens: Number.NaN,
|
|
6491
|
+
outputTokens: Number.NaN,
|
|
6492
|
+
totalTokens: Number.NaN,
|
|
6493
|
+
reasoningTokens: Number.NaN,
|
|
6494
|
+
cachedInputTokens: Number.NaN
|
|
6495
|
+
};
|
|
6496
|
+
const openrouterUsage = {};
|
|
6497
|
+
const accumulatedReasoningDetails = [];
|
|
6498
|
+
let textStarted = false;
|
|
6499
|
+
let reasoningStarted = false;
|
|
6500
|
+
let textId;
|
|
6501
|
+
let reasoningId;
|
|
6502
|
+
let openrouterResponseId;
|
|
6503
|
+
let provider;
|
|
6504
|
+
return {
|
|
6505
|
+
stream: response.pipeThrough(
|
|
6506
|
+
new TransformStream({
|
|
6507
|
+
transform(chunk, controller) {
|
|
6508
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
6509
|
+
if (!chunk.success) {
|
|
6510
|
+
finishReason = "error";
|
|
6511
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
6512
|
+
return;
|
|
6513
|
+
}
|
|
6514
|
+
const value = chunk.value;
|
|
6515
|
+
if ("error" in value) {
|
|
6516
|
+
finishReason = "error";
|
|
6517
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
6518
|
+
return;
|
|
6519
|
+
}
|
|
6520
|
+
if (value.provider) {
|
|
6521
|
+
provider = value.provider;
|
|
6522
|
+
}
|
|
6523
|
+
if (value.id) {
|
|
6524
|
+
openrouterResponseId = value.id;
|
|
6525
|
+
controller.enqueue({
|
|
6526
|
+
type: "response-metadata",
|
|
6527
|
+
id: value.id
|
|
6528
|
+
});
|
|
6529
|
+
}
|
|
6530
|
+
if (value.model) {
|
|
6531
|
+
controller.enqueue({
|
|
6532
|
+
type: "response-metadata",
|
|
6533
|
+
modelId: value.model
|
|
6534
|
+
});
|
|
6535
|
+
}
|
|
6536
|
+
if (value.usage != null) {
|
|
6537
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
6538
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
6539
|
+
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
6540
|
+
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
6541
|
+
if (value.usage.prompt_tokens_details) {
|
|
6542
|
+
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
6543
|
+
usage.cachedInputTokens = cachedInputTokens;
|
|
6544
|
+
openrouterUsage.promptTokensDetails = {
|
|
6545
|
+
cachedTokens: cachedInputTokens
|
|
6546
|
+
};
|
|
6547
|
+
}
|
|
6548
|
+
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
6549
|
+
if (value.usage.completion_tokens_details) {
|
|
6550
|
+
const reasoningTokens = (_b = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b : 0;
|
|
6551
|
+
usage.reasoningTokens = reasoningTokens;
|
|
6552
|
+
openrouterUsage.completionTokensDetails = {
|
|
6553
|
+
reasoningTokens
|
|
6554
|
+
};
|
|
6555
|
+
}
|
|
6556
|
+
openrouterUsage.cost = value.usage.cost;
|
|
6557
|
+
openrouterUsage.totalTokens = value.usage.total_tokens;
|
|
6558
|
+
}
|
|
6559
|
+
const choice = value.choices[0];
|
|
6560
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
6561
|
+
finishReason = mapOpenRouterFinishReason(choice.finish_reason);
|
|
6562
|
+
}
|
|
6563
|
+
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
6564
|
+
return;
|
|
6565
|
+
}
|
|
6566
|
+
const delta = choice.delta;
|
|
6567
|
+
const emitReasoningChunk = (chunkText) => {
|
|
6568
|
+
if (!reasoningStarted) {
|
|
6569
|
+
reasoningId = openrouterResponseId || generateId4();
|
|
6570
|
+
controller.enqueue({
|
|
6571
|
+
type: "reasoning-start",
|
|
6572
|
+
id: reasoningId
|
|
6573
|
+
});
|
|
6574
|
+
reasoningStarted = true;
|
|
6575
|
+
}
|
|
6576
|
+
controller.enqueue({
|
|
6577
|
+
type: "reasoning-delta",
|
|
6578
|
+
delta: chunkText,
|
|
6579
|
+
id: reasoningId || generateId4()
|
|
6580
|
+
});
|
|
6581
|
+
};
|
|
6582
|
+
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
6583
|
+
accumulatedReasoningDetails.push(...delta.reasoning_details);
|
|
6584
|
+
for (const detail of delta.reasoning_details) {
|
|
6585
|
+
switch (detail.type) {
|
|
6586
|
+
case "reasoning.text": {
|
|
6587
|
+
if (detail.text) {
|
|
6588
|
+
emitReasoningChunk(detail.text);
|
|
6589
|
+
}
|
|
6590
|
+
break;
|
|
6591
|
+
}
|
|
6592
|
+
case "reasoning.encrypted": {
|
|
6593
|
+
if (detail.data) {
|
|
6594
|
+
emitReasoningChunk("[REDACTED]");
|
|
6595
|
+
}
|
|
6596
|
+
break;
|
|
6597
|
+
}
|
|
6598
|
+
case "reasoning.summary": {
|
|
6599
|
+
if (detail.summary) {
|
|
6600
|
+
emitReasoningChunk(detail.summary);
|
|
6601
|
+
}
|
|
6602
|
+
break;
|
|
6603
|
+
}
|
|
6604
|
+
}
|
|
6605
|
+
}
|
|
6606
|
+
} else if (delta.reasoning) {
|
|
6607
|
+
emitReasoningChunk(delta.reasoning);
|
|
6608
|
+
}
|
|
6609
|
+
if (delta.content) {
|
|
6610
|
+
if (reasoningStarted && !textStarted) {
|
|
6611
|
+
controller.enqueue({
|
|
6612
|
+
type: "reasoning-end",
|
|
6613
|
+
id: reasoningId || generateId4()
|
|
6614
|
+
});
|
|
6615
|
+
reasoningStarted = false;
|
|
6616
|
+
}
|
|
6617
|
+
if (!textStarted) {
|
|
6618
|
+
textId = openrouterResponseId || generateId4();
|
|
6619
|
+
controller.enqueue({
|
|
6620
|
+
type: "text-start",
|
|
6621
|
+
id: textId
|
|
6622
|
+
});
|
|
6623
|
+
textStarted = true;
|
|
6624
|
+
}
|
|
6625
|
+
controller.enqueue({
|
|
6626
|
+
type: "text-delta",
|
|
6627
|
+
delta: delta.content,
|
|
6628
|
+
id: textId || generateId4()
|
|
6629
|
+
});
|
|
6630
|
+
}
|
|
6631
|
+
if (delta.annotations) {
|
|
6632
|
+
for (const annotation of delta.annotations) {
|
|
6633
|
+
if (annotation.type === "url_citation") {
|
|
6634
|
+
controller.enqueue({
|
|
6635
|
+
type: "source",
|
|
6636
|
+
sourceType: "url",
|
|
6637
|
+
id: annotation.url_citation.url,
|
|
6638
|
+
url: annotation.url_citation.url,
|
|
6639
|
+
title: annotation.url_citation.title,
|
|
6640
|
+
providerMetadata: {
|
|
6641
|
+
openrouter: {
|
|
6642
|
+
content: annotation.url_citation.content || ""
|
|
6643
|
+
}
|
|
6644
|
+
}
|
|
6645
|
+
});
|
|
6646
|
+
}
|
|
6647
|
+
}
|
|
6648
|
+
}
|
|
6649
|
+
if (delta.tool_calls != null) {
|
|
6650
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
6651
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
6652
|
+
if (toolCalls[index] == null) {
|
|
6653
|
+
if (toolCallDelta.type !== "function") {
|
|
6654
|
+
throw new InvalidResponseDataError2({
|
|
6655
|
+
data: toolCallDelta,
|
|
6656
|
+
message: `Expected 'function' type.`
|
|
6657
|
+
});
|
|
6658
|
+
}
|
|
6659
|
+
if (toolCallDelta.id == null) {
|
|
6660
|
+
throw new InvalidResponseDataError2({
|
|
6661
|
+
data: toolCallDelta,
|
|
6662
|
+
message: `Expected 'id' to be a string.`
|
|
6663
|
+
});
|
|
6664
|
+
}
|
|
6665
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
6666
|
+
throw new InvalidResponseDataError2({
|
|
6667
|
+
data: toolCallDelta,
|
|
6668
|
+
message: `Expected 'function.name' to be a string.`
|
|
6669
|
+
});
|
|
6670
|
+
}
|
|
6671
|
+
toolCalls[index] = {
|
|
6672
|
+
id: toolCallDelta.id,
|
|
6673
|
+
type: "function",
|
|
6674
|
+
function: {
|
|
6675
|
+
name: toolCallDelta.function.name,
|
|
6676
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
6677
|
+
},
|
|
6678
|
+
inputStarted: false,
|
|
6679
|
+
sent: false
|
|
6680
|
+
};
|
|
6681
|
+
const toolCall2 = toolCalls[index];
|
|
6682
|
+
if (toolCall2 == null) {
|
|
6683
|
+
throw new InvalidResponseDataError2({
|
|
6684
|
+
data: { index, toolCallsLength: toolCalls.length },
|
|
6685
|
+
message: `Tool call at index ${index} is missing after creation.`
|
|
6686
|
+
});
|
|
6687
|
+
}
|
|
6688
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson2(toolCall2.function.arguments)) {
|
|
6689
|
+
toolCall2.inputStarted = true;
|
|
6690
|
+
controller.enqueue({
|
|
6691
|
+
type: "tool-input-start",
|
|
6692
|
+
id: toolCall2.id,
|
|
6693
|
+
toolName: toolCall2.function.name
|
|
6694
|
+
});
|
|
6695
|
+
controller.enqueue({
|
|
6696
|
+
type: "tool-input-delta",
|
|
6697
|
+
id: toolCall2.id,
|
|
6698
|
+
delta: toolCall2.function.arguments
|
|
6699
|
+
});
|
|
6700
|
+
controller.enqueue({
|
|
6701
|
+
type: "tool-input-end",
|
|
6702
|
+
id: toolCall2.id
|
|
6703
|
+
});
|
|
6704
|
+
controller.enqueue({
|
|
6705
|
+
type: "tool-call",
|
|
6706
|
+
toolCallId: toolCall2.id,
|
|
6707
|
+
toolName: toolCall2.function.name,
|
|
6708
|
+
input: toolCall2.function.arguments
|
|
6709
|
+
});
|
|
6710
|
+
toolCall2.sent = true;
|
|
6711
|
+
}
|
|
6712
|
+
continue;
|
|
6713
|
+
}
|
|
6714
|
+
const toolCall = toolCalls[index];
|
|
6715
|
+
if (toolCall == null) {
|
|
6716
|
+
throw new InvalidResponseDataError2({
|
|
6717
|
+
data: {
|
|
6718
|
+
index,
|
|
6719
|
+
toolCallsLength: toolCalls.length,
|
|
6720
|
+
toolCallDelta
|
|
6721
|
+
},
|
|
6722
|
+
message: `Tool call at index ${index} is missing during merge.`
|
|
6723
|
+
});
|
|
6724
|
+
}
|
|
6725
|
+
if (!toolCall.inputStarted) {
|
|
6726
|
+
toolCall.inputStarted = true;
|
|
6727
|
+
controller.enqueue({
|
|
6728
|
+
type: "tool-input-start",
|
|
6729
|
+
id: toolCall.id,
|
|
6730
|
+
toolName: toolCall.function.name
|
|
6731
|
+
});
|
|
6732
|
+
}
|
|
6733
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
6734
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
6735
|
+
}
|
|
6736
|
+
controller.enqueue({
|
|
6737
|
+
type: "tool-input-delta",
|
|
6738
|
+
id: toolCall.id,
|
|
6739
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
6740
|
+
});
|
|
6741
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson2(toolCall.function.arguments)) {
|
|
6742
|
+
controller.enqueue({
|
|
6743
|
+
type: "tool-call",
|
|
6744
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId4(),
|
|
6745
|
+
toolName: toolCall.function.name,
|
|
6746
|
+
input: toolCall.function.arguments
|
|
6747
|
+
});
|
|
6748
|
+
toolCall.sent = true;
|
|
6749
|
+
}
|
|
6750
|
+
}
|
|
6751
|
+
}
|
|
6752
|
+
if (delta.images != null) {
|
|
6753
|
+
for (const image of delta.images) {
|
|
6754
|
+
controller.enqueue({
|
|
6755
|
+
type: "file",
|
|
6756
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
6757
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
6758
|
+
});
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6761
|
+
},
|
|
6762
|
+
flush(controller) {
|
|
6763
|
+
var _a16;
|
|
6764
|
+
if (finishReason === "tool-calls") {
|
|
6765
|
+
for (const toolCall of toolCalls) {
|
|
6766
|
+
if (toolCall && !toolCall.sent) {
|
|
6767
|
+
controller.enqueue({
|
|
6768
|
+
type: "tool-call",
|
|
6769
|
+
toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId4(),
|
|
6770
|
+
toolName: toolCall.function.name,
|
|
6771
|
+
// Coerce invalid arguments to an empty JSON object
|
|
6772
|
+
input: isParsableJson2(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
6773
|
+
});
|
|
6774
|
+
toolCall.sent = true;
|
|
6775
|
+
}
|
|
6776
|
+
}
|
|
6777
|
+
}
|
|
6778
|
+
if (reasoningStarted) {
|
|
6779
|
+
controller.enqueue({
|
|
6780
|
+
type: "reasoning-end",
|
|
6781
|
+
id: reasoningId || generateId4()
|
|
6782
|
+
});
|
|
6783
|
+
}
|
|
6784
|
+
if (textStarted) {
|
|
6785
|
+
controller.enqueue({
|
|
6786
|
+
type: "text-end",
|
|
6787
|
+
id: textId || generateId4()
|
|
6788
|
+
});
|
|
6789
|
+
}
|
|
6790
|
+
const openrouterMetadata = {
|
|
6791
|
+
usage: openrouterUsage
|
|
6792
|
+
};
|
|
6793
|
+
if (provider !== void 0) {
|
|
6794
|
+
openrouterMetadata.provider = provider;
|
|
6795
|
+
}
|
|
6796
|
+
if (accumulatedReasoningDetails.length > 0) {
|
|
6797
|
+
openrouterMetadata.reasoning_details = accumulatedReasoningDetails;
|
|
6798
|
+
}
|
|
6799
|
+
controller.enqueue({
|
|
6800
|
+
type: "finish",
|
|
6801
|
+
finishReason,
|
|
6802
|
+
usage,
|
|
6803
|
+
providerMetadata: {
|
|
6804
|
+
openrouter: openrouterMetadata
|
|
6805
|
+
}
|
|
6806
|
+
});
|
|
6807
|
+
}
|
|
6808
|
+
})
|
|
6809
|
+
),
|
|
6810
|
+
warnings: [],
|
|
6811
|
+
request: { body: args },
|
|
6812
|
+
response: { headers: responseHeaders }
|
|
6813
|
+
};
|
|
6814
|
+
}
|
|
6815
|
+
};
|
|
6816
|
+
function convertToOpenRouterCompletionPrompt({
|
|
6817
|
+
prompt,
|
|
6818
|
+
inputFormat,
|
|
6819
|
+
user = "user",
|
|
6820
|
+
assistant = "assistant"
|
|
6821
|
+
}) {
|
|
6822
|
+
if (prompt.length === 1 && prompt[0] && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0] && prompt[0].content[0].type === "text") {
|
|
6823
|
+
return { prompt: prompt[0].content[0].text };
|
|
6824
|
+
}
|
|
6825
|
+
let text = "";
|
|
6826
|
+
if (prompt[0] && prompt[0].role === "system") {
|
|
6827
|
+
text += `${prompt[0].content}
|
|
6828
|
+
|
|
6829
|
+
`;
|
|
6830
|
+
prompt = prompt.slice(1);
|
|
6831
|
+
}
|
|
6832
|
+
for (const { role, content } of prompt) {
|
|
6833
|
+
switch (role) {
|
|
6834
|
+
case "system": {
|
|
6835
|
+
throw new InvalidPromptError({
|
|
6836
|
+
message: `Unexpected system message in prompt: ${content}`,
|
|
6837
|
+
prompt
|
|
6838
|
+
});
|
|
6839
|
+
}
|
|
6840
|
+
case "user": {
|
|
6841
|
+
const userMessage = content.map((part) => {
|
|
6842
|
+
switch (part.type) {
|
|
6843
|
+
case "text": {
|
|
6844
|
+
return part.text;
|
|
6845
|
+
}
|
|
6846
|
+
case "file": {
|
|
6847
|
+
throw new UnsupportedFunctionalityError2({
|
|
6848
|
+
functionality: "file attachments"
|
|
6849
|
+
});
|
|
6850
|
+
}
|
|
6851
|
+
default: {
|
|
6852
|
+
return "";
|
|
6853
|
+
}
|
|
6854
|
+
}
|
|
6855
|
+
}).join("");
|
|
6856
|
+
text += `${user}:
|
|
6857
|
+
${userMessage}
|
|
6858
|
+
|
|
6859
|
+
`;
|
|
6860
|
+
break;
|
|
6861
|
+
}
|
|
6862
|
+
case "assistant": {
|
|
6863
|
+
const assistantMessage = content.map(
|
|
6864
|
+
(part) => {
|
|
6865
|
+
switch (part.type) {
|
|
6866
|
+
case "text": {
|
|
6867
|
+
return part.text;
|
|
6868
|
+
}
|
|
6869
|
+
case "tool-call": {
|
|
6870
|
+
throw new UnsupportedFunctionalityError2({
|
|
6871
|
+
functionality: "tool-call messages"
|
|
6872
|
+
});
|
|
6873
|
+
}
|
|
6874
|
+
case "tool-result": {
|
|
6875
|
+
throw new UnsupportedFunctionalityError2({
|
|
6876
|
+
functionality: "tool-result messages"
|
|
6877
|
+
});
|
|
6878
|
+
}
|
|
6879
|
+
case "reasoning": {
|
|
6880
|
+
throw new UnsupportedFunctionalityError2({
|
|
6881
|
+
functionality: "reasoning messages"
|
|
6882
|
+
});
|
|
6883
|
+
}
|
|
6884
|
+
case "file": {
|
|
6885
|
+
throw new UnsupportedFunctionalityError2({
|
|
6886
|
+
functionality: "file attachments"
|
|
6887
|
+
});
|
|
6888
|
+
}
|
|
6889
|
+
default: {
|
|
6890
|
+
return "";
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6894
|
+
).join("");
|
|
6895
|
+
text += `${assistant}:
|
|
6896
|
+
${assistantMessage}
|
|
6897
|
+
|
|
6898
|
+
`;
|
|
6899
|
+
break;
|
|
6900
|
+
}
|
|
6901
|
+
case "tool": {
|
|
6902
|
+
throw new UnsupportedFunctionalityError2({
|
|
6903
|
+
functionality: "tool messages"
|
|
6904
|
+
});
|
|
6905
|
+
}
|
|
6906
|
+
}
|
|
6907
|
+
}
|
|
6908
|
+
text += `${assistant}:
|
|
6909
|
+
`;
|
|
6910
|
+
return {
|
|
6911
|
+
prompt: text
|
|
6912
|
+
};
|
|
6913
|
+
}
|
|
6914
|
+
var OpenRouterCompletionChunkSchema = z4.z.union([
|
|
6915
|
+
z4.z.object({
|
|
6916
|
+
id: z4.z.string().optional(),
|
|
6917
|
+
model: z4.z.string().optional(),
|
|
6918
|
+
choices: z4.z.array(
|
|
6919
|
+
z4.z.object({
|
|
6920
|
+
text: z4.z.string(),
|
|
6921
|
+
reasoning: z4.z.string().nullish().optional(),
|
|
6922
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
6923
|
+
finish_reason: z4.z.string().nullish(),
|
|
6924
|
+
index: z4.z.number().nullish(),
|
|
6925
|
+
logprobs: z4.z.object({
|
|
6926
|
+
tokens: z4.z.array(z4.z.string()),
|
|
6927
|
+
token_logprobs: z4.z.array(z4.z.number()),
|
|
6928
|
+
top_logprobs: z4.z.array(z4.z.record(z4.z.string(), z4.z.number())).nullable()
|
|
6929
|
+
}).passthrough().nullable().optional()
|
|
6930
|
+
}).passthrough()
|
|
6931
|
+
),
|
|
6932
|
+
usage: z4.z.object({
|
|
6933
|
+
prompt_tokens: z4.z.number(),
|
|
6934
|
+
prompt_tokens_details: z4.z.object({
|
|
6935
|
+
cached_tokens: z4.z.number()
|
|
6936
|
+
}).passthrough().nullish(),
|
|
6937
|
+
completion_tokens: z4.z.number(),
|
|
6938
|
+
completion_tokens_details: z4.z.object({
|
|
6939
|
+
reasoning_tokens: z4.z.number()
|
|
6940
|
+
}).passthrough().nullish(),
|
|
6941
|
+
total_tokens: z4.z.number(),
|
|
6942
|
+
cost: z4.z.number().optional()
|
|
6943
|
+
}).passthrough().nullish()
|
|
6944
|
+
}).passthrough(),
|
|
6945
|
+
OpenRouterErrorResponseSchema
|
|
6946
|
+
]);
|
|
6947
|
+
var OpenRouterCompletionLanguageModel = class {
|
|
6948
|
+
constructor(modelId, settings, config) {
|
|
6949
|
+
this.specificationVersion = "v2";
|
|
6950
|
+
this.provider = "openrouter";
|
|
6951
|
+
this.supportedUrls = {
|
|
6952
|
+
"image/*": [
|
|
6953
|
+
/^data:image\/[a-zA-Z]+;base64,/,
|
|
6954
|
+
/^https?:\/\/.+\.(jpg|jpeg|png|gif|webp)$/i
|
|
6955
|
+
],
|
|
6956
|
+
"text/*": [/^data:text\//, /^https?:\/\/.+$/],
|
|
6957
|
+
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
6958
|
+
};
|
|
6959
|
+
this.defaultObjectGenerationMode = void 0;
|
|
6960
|
+
this.modelId = modelId;
|
|
6961
|
+
this.settings = settings;
|
|
6962
|
+
this.config = config;
|
|
6963
|
+
}
|
|
6964
|
+
getArgs({
|
|
6965
|
+
prompt,
|
|
6966
|
+
maxOutputTokens,
|
|
6967
|
+
temperature,
|
|
6968
|
+
topP,
|
|
6969
|
+
frequencyPenalty,
|
|
6970
|
+
presencePenalty,
|
|
6971
|
+
seed,
|
|
6972
|
+
responseFormat,
|
|
6973
|
+
topK,
|
|
6974
|
+
stopSequences,
|
|
6975
|
+
tools,
|
|
6976
|
+
toolChoice
|
|
6977
|
+
}) {
|
|
6978
|
+
const { prompt: completionPrompt } = convertToOpenRouterCompletionPrompt({
|
|
6979
|
+
prompt,
|
|
6980
|
+
inputFormat: "prompt"
|
|
6981
|
+
});
|
|
6982
|
+
if (tools == null ? void 0 : tools.length) {
|
|
6983
|
+
throw new UnsupportedFunctionalityError2({
|
|
6984
|
+
functionality: "tools"
|
|
6985
|
+
});
|
|
6986
|
+
}
|
|
6987
|
+
if (toolChoice) {
|
|
6988
|
+
throw new UnsupportedFunctionalityError2({
|
|
6989
|
+
functionality: "toolChoice"
|
|
6990
|
+
});
|
|
6991
|
+
}
|
|
6992
|
+
return __spreadValues(__spreadValues({
|
|
6993
|
+
// model id:
|
|
6994
|
+
model: this.modelId,
|
|
6995
|
+
models: this.settings.models,
|
|
6996
|
+
// model specific settings:
|
|
6997
|
+
logit_bias: this.settings.logitBias,
|
|
6998
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
6999
|
+
suffix: this.settings.suffix,
|
|
7000
|
+
user: this.settings.user,
|
|
7001
|
+
// standardized settings:
|
|
7002
|
+
max_tokens: maxOutputTokens,
|
|
7003
|
+
temperature,
|
|
7004
|
+
top_p: topP,
|
|
7005
|
+
frequency_penalty: frequencyPenalty,
|
|
7006
|
+
presence_penalty: presencePenalty,
|
|
7007
|
+
seed,
|
|
7008
|
+
stop: stopSequences,
|
|
7009
|
+
response_format: responseFormat,
|
|
7010
|
+
top_k: topK,
|
|
7011
|
+
// prompt:
|
|
7012
|
+
prompt: completionPrompt,
|
|
7013
|
+
// OpenRouter specific settings:
|
|
7014
|
+
include_reasoning: this.settings.includeReasoning,
|
|
7015
|
+
reasoning: this.settings.reasoning
|
|
7016
|
+
}, this.config.extraBody), this.settings.extraBody);
|
|
7017
|
+
}
|
|
7018
|
+
async doGenerate(options) {
|
|
7019
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
7020
|
+
const providerOptions = options.providerOptions || {};
|
|
7021
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
7022
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
7023
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
7024
|
+
url: this.config.url({
|
|
7025
|
+
path: "/completions",
|
|
7026
|
+
modelId: this.modelId
|
|
7027
|
+
}),
|
|
7028
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
7029
|
+
body: args,
|
|
7030
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
7031
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
7032
|
+
OpenRouterCompletionChunkSchema
|
|
7033
|
+
),
|
|
7034
|
+
abortSignal: options.abortSignal,
|
|
7035
|
+
fetch: this.config.fetch
|
|
7036
|
+
});
|
|
7037
|
+
if ("error" in response) {
|
|
7038
|
+
const errorData = response.error;
|
|
7039
|
+
throw new APICallError2({
|
|
7040
|
+
message: errorData.message,
|
|
7041
|
+
url: this.config.url({
|
|
7042
|
+
path: "/completions",
|
|
7043
|
+
modelId: this.modelId
|
|
7044
|
+
}),
|
|
7045
|
+
requestBodyValues: args,
|
|
7046
|
+
statusCode: 200,
|
|
7047
|
+
responseHeaders,
|
|
7048
|
+
data: errorData
|
|
7049
|
+
});
|
|
7050
|
+
}
|
|
7051
|
+
const choice = response.choices[0];
|
|
7052
|
+
if (!choice) {
|
|
7053
|
+
throw new NoContentGeneratedError({
|
|
7054
|
+
message: "No choice in OpenRouter completion response"
|
|
7055
|
+
});
|
|
7056
|
+
}
|
|
7057
|
+
return {
|
|
7058
|
+
content: [
|
|
7059
|
+
{
|
|
7060
|
+
type: "text",
|
|
7061
|
+
text: (_a15 = choice.text) != null ? _a15 : ""
|
|
7062
|
+
}
|
|
7063
|
+
],
|
|
7064
|
+
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
7065
|
+
usage: {
|
|
7066
|
+
inputTokens: (_c = (_b = response.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : 0,
|
|
7067
|
+
outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
|
|
7068
|
+
totalTokens: ((_g = (_f = response.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : 0) + ((_i = (_h = response.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : 0),
|
|
7069
|
+
reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
|
|
7070
|
+
cachedInputTokens: (_o = (_n = (_m = response.usage) == null ? void 0 : _m.prompt_tokens_details) == null ? void 0 : _n.cached_tokens) != null ? _o : 0
|
|
7071
|
+
},
|
|
7072
|
+
warnings: [],
|
|
7073
|
+
response: {
|
|
7074
|
+
headers: responseHeaders
|
|
7075
|
+
}
|
|
7076
|
+
};
|
|
7077
|
+
}
|
|
7078
|
+
async doStream(options) {
|
|
7079
|
+
const providerOptions = options.providerOptions || {};
|
|
7080
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
7081
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
7082
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
7083
|
+
url: this.config.url({
|
|
7084
|
+
path: "/completions",
|
|
7085
|
+
modelId: this.modelId
|
|
7086
|
+
}),
|
|
7087
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
7088
|
+
body: __spreadProps(__spreadValues({}, args), {
|
|
7089
|
+
stream: true,
|
|
7090
|
+
// only include stream_options when in strict compatibility mode:
|
|
7091
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
7092
|
+
}),
|
|
7093
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
7094
|
+
successfulResponseHandler: createEventSourceResponseHandler4(
|
|
7095
|
+
OpenRouterCompletionChunkSchema
|
|
7096
|
+
),
|
|
7097
|
+
abortSignal: options.abortSignal,
|
|
7098
|
+
fetch: this.config.fetch
|
|
7099
|
+
});
|
|
7100
|
+
let finishReason = "other";
|
|
7101
|
+
const usage = {
|
|
7102
|
+
inputTokens: Number.NaN,
|
|
7103
|
+
outputTokens: Number.NaN,
|
|
7104
|
+
totalTokens: Number.NaN,
|
|
7105
|
+
reasoningTokens: Number.NaN,
|
|
7106
|
+
cachedInputTokens: Number.NaN
|
|
7107
|
+
};
|
|
7108
|
+
const openrouterUsage = {};
|
|
7109
|
+
return {
|
|
7110
|
+
stream: response.pipeThrough(
|
|
7111
|
+
new TransformStream({
|
|
7112
|
+
transform(chunk, controller) {
|
|
7113
|
+
var _a15, _b;
|
|
7114
|
+
if (!chunk.success) {
|
|
7115
|
+
finishReason = "error";
|
|
7116
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
7117
|
+
return;
|
|
7118
|
+
}
|
|
7119
|
+
const value = chunk.value;
|
|
7120
|
+
if ("error" in value) {
|
|
7121
|
+
finishReason = "error";
|
|
7122
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
7123
|
+
return;
|
|
7124
|
+
}
|
|
7125
|
+
if (value.usage != null) {
|
|
7126
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
7127
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
7128
|
+
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
7129
|
+
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
7130
|
+
if (value.usage.prompt_tokens_details) {
|
|
7131
|
+
const cachedInputTokens = (_a15 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a15 : 0;
|
|
7132
|
+
usage.cachedInputTokens = cachedInputTokens;
|
|
7133
|
+
openrouterUsage.promptTokensDetails = {
|
|
7134
|
+
cachedTokens: cachedInputTokens
|
|
7135
|
+
};
|
|
7136
|
+
}
|
|
7137
|
+
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
7138
|
+
if (value.usage.completion_tokens_details) {
|
|
7139
|
+
const reasoningTokens = (_b = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b : 0;
|
|
7140
|
+
usage.reasoningTokens = reasoningTokens;
|
|
7141
|
+
openrouterUsage.completionTokensDetails = {
|
|
7142
|
+
reasoningTokens
|
|
7143
|
+
};
|
|
7144
|
+
}
|
|
7145
|
+
openrouterUsage.cost = value.usage.cost;
|
|
7146
|
+
openrouterUsage.totalTokens = value.usage.total_tokens;
|
|
7147
|
+
}
|
|
7148
|
+
const choice = value.choices[0];
|
|
7149
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
7150
|
+
finishReason = mapOpenRouterFinishReason(choice.finish_reason);
|
|
7151
|
+
}
|
|
7152
|
+
if ((choice == null ? void 0 : choice.text) != null) {
|
|
7153
|
+
controller.enqueue({
|
|
7154
|
+
type: "text-delta",
|
|
7155
|
+
delta: choice.text,
|
|
7156
|
+
id: generateId4()
|
|
7157
|
+
});
|
|
7158
|
+
}
|
|
7159
|
+
},
|
|
7160
|
+
flush(controller) {
|
|
7161
|
+
controller.enqueue({
|
|
7162
|
+
type: "finish",
|
|
7163
|
+
finishReason,
|
|
7164
|
+
usage,
|
|
7165
|
+
providerMetadata: {
|
|
7166
|
+
openrouter: {
|
|
7167
|
+
usage: openrouterUsage
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7170
|
+
});
|
|
7171
|
+
}
|
|
7172
|
+
})
|
|
7173
|
+
),
|
|
7174
|
+
response: {
|
|
7175
|
+
headers: responseHeaders
|
|
7176
|
+
}
|
|
7177
|
+
};
|
|
7178
|
+
}
|
|
7179
|
+
};
|
|
7180
|
+
function removeUndefinedEntries22(record) {
|
|
7181
|
+
return Object.fromEntries(
|
|
7182
|
+
Object.entries(record).filter(([, value]) => value !== null)
|
|
7183
|
+
);
|
|
7184
|
+
}
|
|
7185
|
+
function withUserAgentSuffix3(headers, ...userAgentSuffixParts) {
|
|
7186
|
+
const cleanedHeaders = removeUndefinedEntries22(
|
|
7187
|
+
headers != null ? headers : {}
|
|
7188
|
+
);
|
|
7189
|
+
const currentUserAgentHeader = cleanedHeaders["user-agent"] || "";
|
|
7190
|
+
const newUserAgent = [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ");
|
|
7191
|
+
return __spreadProps(__spreadValues({}, cleanedHeaders), {
|
|
7192
|
+
"user-agent": newUserAgent
|
|
7193
|
+
});
|
|
7194
|
+
}
|
|
7195
|
+
var VERSION5 = "1.2.3";
|
|
7196
|
+
function createOpenRouter(options = {}) {
|
|
7197
|
+
var _a15, _b, _c;
|
|
7198
|
+
const baseURL = (_b = withoutTrailingSlash4((_a15 = options.baseURL) != null ? _a15 : options.baseUrl)) != null ? _b : "https://openrouter.ai/api/v1";
|
|
7199
|
+
const compatibility = (_c = options.compatibility) != null ? _c : "compatible";
|
|
7200
|
+
const getHeaders = () => withUserAgentSuffix3(
|
|
7201
|
+
__spreadValues({
|
|
7202
|
+
Authorization: `Bearer ${loadApiKey4({
|
|
7203
|
+
apiKey: options.apiKey,
|
|
7204
|
+
environmentVariableName: "OPENROUTER_API_KEY",
|
|
7205
|
+
description: "OpenRouter"
|
|
7206
|
+
})}`
|
|
7207
|
+
}, options.headers),
|
|
7208
|
+
`ai-sdk/openrouter/${VERSION5}`
|
|
7209
|
+
);
|
|
7210
|
+
const createChatModel = (modelId, settings = {}) => new OpenRouterChatLanguageModel(modelId, settings, {
|
|
7211
|
+
provider: "openrouter.chat",
|
|
7212
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
7213
|
+
headers: getHeaders,
|
|
7214
|
+
compatibility,
|
|
7215
|
+
fetch: options.fetch,
|
|
7216
|
+
extraBody: options.extraBody
|
|
7217
|
+
});
|
|
7218
|
+
const createCompletionModel = (modelId, settings = {}) => new OpenRouterCompletionLanguageModel(modelId, settings, {
|
|
7219
|
+
provider: "openrouter.completion",
|
|
7220
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
7221
|
+
headers: getHeaders,
|
|
7222
|
+
compatibility,
|
|
7223
|
+
fetch: options.fetch,
|
|
7224
|
+
extraBody: options.extraBody
|
|
7225
|
+
});
|
|
7226
|
+
const createLanguageModel = (modelId, settings) => {
|
|
7227
|
+
if (new.target) {
|
|
7228
|
+
throw new Error(
|
|
7229
|
+
"The OpenRouter model function cannot be called with the new keyword."
|
|
7230
|
+
);
|
|
7231
|
+
}
|
|
7232
|
+
if (modelId === "openai/gpt-3.5-turbo-instruct") {
|
|
7233
|
+
return createCompletionModel(
|
|
7234
|
+
modelId,
|
|
7235
|
+
settings
|
|
7236
|
+
);
|
|
7237
|
+
}
|
|
7238
|
+
return createChatModel(modelId, settings);
|
|
7239
|
+
};
|
|
7240
|
+
const provider = (modelId, settings) => createLanguageModel(modelId, settings);
|
|
7241
|
+
provider.languageModel = createLanguageModel;
|
|
7242
|
+
provider.chat = createChatModel;
|
|
7243
|
+
provider.completion = createCompletionModel;
|
|
7244
|
+
return provider;
|
|
7245
|
+
}
|
|
7246
|
+
createOpenRouter({
|
|
7247
|
+
compatibility: "strict"
|
|
7248
|
+
// strict for OpenRouter API
|
|
7249
|
+
});
|
|
4797
7250
|
|
|
4798
7251
|
// src/llm/model/gateway-resolver.ts
|
|
4799
7252
|
function parseModelRouterId(routerId, gatewayPrefix) {
|
|
@@ -4864,7 +7317,7 @@ var OPENAI_COMPATIBLE_OVERRIDES = {
|
|
|
4864
7317
|
apiKeyEnvVar: "AI_GATEWAY_API_KEY"
|
|
4865
7318
|
}
|
|
4866
7319
|
};
|
|
4867
|
-
var ModelsDevGateway = class extends
|
|
7320
|
+
var ModelsDevGateway = class extends chunkOWIEOL55_cjs.MastraModelGateway {
|
|
4868
7321
|
id = "models.dev";
|
|
4869
7322
|
name = "models.dev";
|
|
4870
7323
|
providerConfigs = {};
|
|
@@ -4944,18 +7397,18 @@ var ModelsDevGateway = class extends chunkCZEJQSWB_cjs.MastraModelGateway {
|
|
|
4944
7397
|
const baseURL = this.buildUrl(`${providerId}/${modelId}`);
|
|
4945
7398
|
switch (providerId) {
|
|
4946
7399
|
case "openai":
|
|
4947
|
-
return
|
|
7400
|
+
return chunkOWIEOL55_cjs.createOpenAI({ apiKey }).responses(modelId);
|
|
4948
7401
|
case "gemini":
|
|
4949
7402
|
case "google":
|
|
4950
|
-
return
|
|
7403
|
+
return chunkOWIEOL55_cjs.createGoogleGenerativeAI({
|
|
4951
7404
|
apiKey
|
|
4952
7405
|
}).chat(modelId);
|
|
4953
7406
|
case "anthropic":
|
|
4954
|
-
return
|
|
7407
|
+
return chunkOWIEOL55_cjs.createAnthropic({ apiKey })(modelId);
|
|
4955
7408
|
case "mistral":
|
|
4956
7409
|
return createMistral({ apiKey })(modelId);
|
|
4957
7410
|
case "openrouter":
|
|
4958
|
-
return
|
|
7411
|
+
return createOpenRouter({ apiKey, headers })(modelId);
|
|
4959
7412
|
case "xai":
|
|
4960
7413
|
return createXai({
|
|
4961
7414
|
apiKey
|
|
@@ -4968,7 +7421,7 @@ var ModelsDevGateway = class extends chunkCZEJQSWB_cjs.MastraModelGateway {
|
|
|
4968
7421
|
return createPerplexity({ apiKey })(modelId);
|
|
4969
7422
|
default:
|
|
4970
7423
|
if (!baseURL) throw new Error(`No API URL found for ${providerId}/${modelId}`);
|
|
4971
|
-
return
|
|
7424
|
+
return chunkOWIEOL55_cjs.createOpenAICompatible({ name: providerId, apiKey, baseURL, supportsStructuredOutputs: true }).chatModel(
|
|
4972
7425
|
modelId
|
|
4973
7426
|
);
|
|
4974
7427
|
}
|
|
@@ -4977,5 +7430,5 @@ var ModelsDevGateway = class extends chunkCZEJQSWB_cjs.MastraModelGateway {
|
|
|
4977
7430
|
|
|
4978
7431
|
exports.ModelsDevGateway = ModelsDevGateway;
|
|
4979
7432
|
exports.parseModelRouterId = parseModelRouterId;
|
|
4980
|
-
//# sourceMappingURL=chunk-
|
|
4981
|
-
//# sourceMappingURL=chunk-
|
|
7433
|
+
//# sourceMappingURL=chunk-Y7MZ5LJT.cjs.map
|
|
7434
|
+
//# sourceMappingURL=chunk-Y7MZ5LJT.cjs.map
|