@mastra/core 1.0.0-beta.11 → 1.0.0-beta.14
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 +343 -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 +3 -3
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.types.d.ts +11 -8
- package/dist/agent/agent.types.d.ts.map +1 -1
- package/dist/agent/index.cjs +17 -9
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- 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/trip-wire.d.ts +2 -2
- package/dist/agent/trip-wire.d.ts.map +1 -1
- package/dist/agent/types.d.ts +3 -3
- package/dist/agent/utils.d.ts +7 -4
- package/dist/agent/utils.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +4 -3
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +3 -3
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +3 -3
- 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 +15 -1
- package/dist/bundler/types.d.ts.map +1 -1
- package/dist/chunk-2AU5ZHBL.js +79 -0
- package/dist/chunk-2AU5ZHBL.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-US2U7ECW.js → chunk-3IP3DZ7G.js} +234 -101
- package/dist/chunk-3IP3DZ7G.js.map +1 -0
- package/dist/{chunk-SXNQRJQD.js → chunk-4AT6YQKZ.js} +26 -20
- package/dist/chunk-4AT6YQKZ.js.map +1 -0
- package/dist/{chunk-C36YRTZ6.js → chunk-4CMIJQF6.js} +117 -114
- package/dist/chunk-4CMIJQF6.js.map +1 -0
- package/dist/chunk-53SZJCBX.cjs +4888 -0
- package/dist/chunk-53SZJCBX.cjs.map +1 -0
- 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-U3XOLEPX.js → chunk-5UQ5TB6J.js} +6 -32
- package/dist/chunk-5UQ5TB6J.js.map +1 -0
- package/dist/{chunk-O2BJW7YA.js → chunk-67LM2UCT.js} +9 -9
- package/dist/chunk-67LM2UCT.js.map +1 -0
- package/dist/{chunk-YC6PJEPH.cjs → chunk-6CG7IY57.cjs} +266 -133
- package/dist/chunk-6CG7IY57.cjs.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-5Q6WAYEY.cjs → chunk-72E3YF6A.cjs} +35 -49
- package/dist/chunk-72E3YF6A.cjs.map +1 -0
- 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-7P6BNIJH.js → chunk-AYBJ5GAD.js} +281 -35
- package/dist/chunk-AYBJ5GAD.js.map +1 -0
- package/dist/chunk-D22XABFZ.js +79 -0
- package/dist/chunk-D22XABFZ.js.map +1 -0
- package/dist/{chunk-SCUWP4II.cjs → chunk-DBW6S25C.cjs} +47 -74
- package/dist/chunk-DBW6S25C.cjs.map +1 -0
- package/dist/{chunk-MRFUISXC.cjs → chunk-EGHGFLL3.cjs} +2631 -179
- package/dist/chunk-EGHGFLL3.cjs.map +1 -0
- package/dist/{chunk-BJXKH4LG.cjs → chunk-ETWAR2YE.cjs} +43 -78
- package/dist/chunk-ETWAR2YE.cjs.map +1 -0
- package/dist/{chunk-CZEJQSWB.cjs → chunk-F75EQ574.cjs} +65 -6
- package/dist/chunk-F75EQ574.cjs.map +1 -0
- package/dist/{chunk-BUKY6CTR.cjs → chunk-FPDJ4XN6.cjs} +282 -36
- package/dist/chunk-FPDJ4XN6.cjs.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-JIGDJK2O.js → chunk-GBQXIVL6.js} +4 -39
- package/dist/chunk-GBQXIVL6.js.map +1 -0
- package/dist/{chunk-F2GAJSBI.js → chunk-GELVUDUY.js} +11 -8
- package/dist/chunk-GELVUDUY.js.map +1 -0
- package/dist/chunk-GVAPYQRO.cjs +252 -0
- package/dist/chunk-GVAPYQRO.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-52RSUALV.cjs → chunk-JAGQZZ43.cjs} +1660 -1196
- package/dist/chunk-JAGQZZ43.cjs.map +1 -0
- package/dist/{chunk-PK2A5WBG.js → chunk-K66U47VL.js} +54 -7
- package/dist/chunk-K66U47VL.js.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-IVV5TOMD.js → chunk-LDXKZYOV.js} +31 -11
- package/dist/chunk-LDXKZYOV.js.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-PG5H6QIO.cjs → chunk-O3ULBGV6.cjs} +40 -20
- package/dist/chunk-O3ULBGV6.cjs.map +1 -0
- package/dist/{chunk-WTSZBHIZ.cjs → chunk-O5BQBZEF.cjs} +28 -28
- package/dist/chunk-O5BQBZEF.cjs.map +1 -0
- package/dist/{chunk-4JKEUSCC.cjs → chunk-OOUFPYSX.cjs} +25 -22
- package/dist/chunk-OOUFPYSX.cjs.map +1 -0
- package/dist/chunk-QDVYP2T7.js +4883 -0
- package/dist/chunk-QDVYP2T7.js.map +1 -0
- package/dist/{chunk-2ULLRN4Y.js → chunk-QF4MHFSU.js} +1294 -834
- package/dist/chunk-QF4MHFSU.js.map +1 -0
- package/dist/{chunk-Z57R5WS4.js → chunk-SLBWA2F3.js} +4 -4
- package/dist/{chunk-Z57R5WS4.js.map → chunk-SLBWA2F3.js.map} +1 -1
- package/dist/chunk-ST7NBF4H.cjs +84 -0
- package/dist/chunk-ST7NBF4H.cjs.map +1 -0
- package/dist/{chunk-YWMMBIOM.cjs → chunk-TDM43G4I.cjs} +15 -15
- package/dist/{chunk-YWMMBIOM.cjs.map → chunk-TDM43G4I.cjs.map} +1 -1
- package/dist/{chunk-S73Z3PBJ.cjs → chunk-TRUNX3AX.cjs} +138 -134
- package/dist/chunk-TRUNX3AX.cjs.map +1 -0
- package/dist/chunk-VE6HQ7H6.js +250 -0
- package/dist/chunk-VE6HQ7H6.js.map +1 -0
- package/dist/{chunk-OEIVMCWX.js → chunk-VZJOEGQA.js} +2536 -84
- package/dist/chunk-VZJOEGQA.js.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/run/index.d.ts.map +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/generate-to-stream.d.ts +20 -0
- package/dist/llm/model/aisdk/generate-to-stream.d.ts.map +1 -0
- package/dist/llm/model/aisdk/v5/model.d.ts +5 -1
- package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
- package/dist/llm/model/aisdk/v6/model.d.ts +51 -0
- package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -0
- 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 +3 -3
- 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 +135 -11
- package/dist/llm/model/resolve-model.d.ts +2 -2
- package/dist/llm/model/resolve-model.d.ts.map +1 -1
- package/dist/llm/model/shared.types.d.ts +19 -8
- package/dist/llm/model/shared.types.d.ts.map +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/network/index.d.ts +2 -2
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts +2 -2
- package/dist/loop/test-utils/MastraLanguageModelV2Mock.d.ts.map +1 -1
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts +37 -0
- package/dist/loop/test-utils/MastraLanguageModelV3Mock.d.ts.map +1 -0
- package/dist/loop/test-utils/fullStream.d.ts +2 -1
- package/dist/loop/test-utils/fullStream.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/test-utils/resultObject.d.ts +2 -1
- package/dist/loop/test-utils/resultObject.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/test-utils/utils-v3.d.ts +55 -0
- package/dist/loop/test-utils/utils-v3.d.ts.map +1 -0
- package/dist/loop/types.d.ts +8 -7
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +49 -49
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +34 -34
- 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 +17 -17
- 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 +49 -49
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +2 -2
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +18 -18
- 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-E3WWI7VA.js +3 -0
- package/dist/{models-dev-23RN2WHG.js.map → models-dev-E3WWI7VA.js.map} +1 -1
- package/dist/models-dev-PPS7X4JM.cjs +12 -0
- package/dist/{models-dev-EO3SUIY2.cjs.map → models-dev-PPS7X4JM.cjs.map} +1 -1
- package/dist/netlify-TY656UYF.js +3 -0
- package/dist/{netlify-GXJ5D5DD.js.map → netlify-TY656UYF.js.map} +1 -1
- package/dist/netlify-VZFM5UH3.cjs +12 -0
- package/dist/{netlify-KJLY3GFS.cjs.map → netlify-VZFM5UH3.cjs.map} +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.d.ts +9 -9
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +1293 -1293
- package/dist/processors/step-schema.d.ts.map +1 -1
- package/dist/provider-registry-NXVD764B.js +3 -0
- package/dist/{provider-registry-F67Y6OF2.js.map → provider-registry-NXVD764B.js.map} +1 -1
- package/dist/provider-registry-ZIWSEUQE.cjs +40 -0
- package/dist/{provider-registry-3TG2KUD2.cjs.map → provider-registry-ZIWSEUQE.cjs.map} +1 -1
- package/dist/provider-registry.json +276 -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 +3 -3
- package/dist/relevance/index.cjs.map +1 -1
- package/dist/relevance/index.js +2 -2
- package/dist/relevance/index.js.map +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 +6 -6
- 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 +16 -36
- 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 +32 -23
- 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-LTZ7QQUP.js +61 -0
- package/dist/token-6GSAFR2W-LTZ7QQUP.js.map +1 -0
- 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-6GSAFR2W-UEEINYAN.cjs +63 -0
- package/dist/token-6GSAFR2W-UEEINYAN.cjs.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/token-util-NEHG7TUY-QTFZ26EN.js +8 -0
- package/dist/token-util-NEHG7TUY-QTFZ26EN.js.map +1 -0
- package/dist/token-util-NEHG7TUY-WZL2DNCG.cjs +10 -0
- package/dist/token-util-NEHG7TUY-WZL2DNCG.cjs.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 +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/embed.d.ts +3 -2
- package/dist/vector/embed.d.ts.map +1 -1
- package/dist/vector/index.cjs +5316 -16
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.js +5282 -4
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/vector.d.ts +15 -2
- package/dist/vector/vector.d.ts.map +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 +5 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +16 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +20 -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 +30 -9
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +13 -14
- package/src/llm/model/provider-types.generated.d.ts +135 -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-F2GAJSBI.js.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-O2BJW7YA.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-WTSZBHIZ.cjs.map +0 -1
- package/dist/chunk-YC6PJEPH.cjs.map +0 -1
- package/dist/llm/model/is-v2-model.d.ts +0 -3
- package/dist/llm/model/is-v2-model.d.ts.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,8 +1,7 @@
|
|
|
1
|
-
import { createJsonErrorResponseHandler, InvalidArgumentError, withoutTrailingSlash, generateId, withUserAgentSuffix, InvalidResponseDataError, parseProviderOptions, injectJsonInstructionIntoMessages, postJsonToApi, createJsonResponseHandler, combineHeaders, createEventSourceResponseHandler, loadApiKey, APICallError, UnsupportedFunctionalityError, LoadAPIKeyError, convertToBase64, JSONParseError, TypeValidationError, EmptyResponseBodyError, EventSourceParserStream, NoSuchModelError, MastraModelGateway, createOpenAICompatible, createAnthropic, createGoogleGenerativeAI, createOpenAI, TooManyEmbeddingValuesForCallError, OpenAICompatibleImageModel } from './chunk-
|
|
1
|
+
import { createJsonErrorResponseHandler, InvalidArgumentError, withoutTrailingSlash, generateId, withUserAgentSuffix, InvalidResponseDataError, parseProviderOptions, injectJsonInstructionIntoMessages, postJsonToApi, createJsonResponseHandler, combineHeaders, createEventSourceResponseHandler, loadApiKey, APICallError, UnsupportedFunctionalityError, LoadAPIKeyError, convertToBase64, JSONParseError, TypeValidationError, EmptyResponseBodyError, EventSourceParserStream, NoSuchModelError, MastraModelGateway, createOpenAICompatible, createAnthropic, createGoogleGenerativeAI, createOpenAI, TooManyEmbeddingValuesForCallError, OpenAICompatibleImageModel } from './chunk-K66U47VL.js';
|
|
2
2
|
import * as z4 from 'zod/v4';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
5
|
-
import { createOpenRouter } from '@openrouter/ai-sdk-provider-v5';
|
|
6
5
|
|
|
7
6
|
function combineHeaders2(...headers) {
|
|
8
7
|
return headers.reduce(
|
|
@@ -71,11 +70,11 @@ function handleFetchError({
|
|
|
71
70
|
return error;
|
|
72
71
|
}
|
|
73
72
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
74
|
-
var
|
|
73
|
+
var _a15, _b, _c;
|
|
75
74
|
if (globalThisAny.window) {
|
|
76
75
|
return `runtime/browser`;
|
|
77
76
|
}
|
|
78
|
-
if ((
|
|
77
|
+
if ((_a15 = globalThisAny.navigator) == null ? void 0 : _a15.userAgent) {
|
|
79
78
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
80
79
|
}
|
|
81
80
|
if ((_c = (_b = globalThisAny.process) == null ? void 0 : _b.versions) == null ? void 0 : _c.node) {
|
|
@@ -559,11 +558,11 @@ function parseAnyDef() {
|
|
|
559
558
|
return {};
|
|
560
559
|
}
|
|
561
560
|
function parseArrayDef(def, refs) {
|
|
562
|
-
var
|
|
561
|
+
var _a15, _b, _c;
|
|
563
562
|
const res = {
|
|
564
563
|
type: "array"
|
|
565
564
|
};
|
|
566
|
-
if (((
|
|
565
|
+
if (((_a15 = def.type) == null ? void 0 : _a15._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
567
566
|
res.items = parseDef(def.type._def, {
|
|
568
567
|
...refs,
|
|
569
568
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -922,8 +921,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
922
921
|
return result;
|
|
923
922
|
}
|
|
924
923
|
function addFormat(schema, value, message, refs) {
|
|
925
|
-
var
|
|
926
|
-
if (schema.format || ((
|
|
924
|
+
var _a15;
|
|
925
|
+
if (schema.format || ((_a15 = schema.anyOf) == null ? void 0 : _a15.some((x) => x.format))) {
|
|
927
926
|
if (!schema.anyOf) {
|
|
928
927
|
schema.anyOf = [];
|
|
929
928
|
}
|
|
@@ -942,8 +941,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
942
941
|
}
|
|
943
942
|
}
|
|
944
943
|
function addPattern(schema, regex, message, refs) {
|
|
945
|
-
var
|
|
946
|
-
if (schema.pattern || ((
|
|
944
|
+
var _a15;
|
|
945
|
+
if (schema.pattern || ((_a15 = schema.allOf) == null ? void 0 : _a15.some((x) => x.pattern))) {
|
|
947
946
|
if (!schema.allOf) {
|
|
948
947
|
schema.allOf = [];
|
|
949
948
|
}
|
|
@@ -962,7 +961,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
962
961
|
}
|
|
963
962
|
}
|
|
964
963
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
965
|
-
var
|
|
964
|
+
var _a15;
|
|
966
965
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
967
966
|
return regex.source;
|
|
968
967
|
}
|
|
@@ -992,7 +991,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
992
991
|
pattern += source[i];
|
|
993
992
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
994
993
|
inCharRange = false;
|
|
995
|
-
} else if (source[i + 1] === "-" && ((
|
|
994
|
+
} else if (source[i + 1] === "-" && ((_a15 = source[i + 2]) == null ? void 0 : _a15.match(/[a-z]/))) {
|
|
996
995
|
pattern += source[i];
|
|
997
996
|
inCharRange = true;
|
|
998
997
|
} else {
|
|
@@ -1034,13 +1033,13 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1034
1033
|
return pattern;
|
|
1035
1034
|
}
|
|
1036
1035
|
function parseRecordDef(def, refs) {
|
|
1037
|
-
var
|
|
1036
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1038
1037
|
const schema = {
|
|
1039
1038
|
type: "object",
|
|
1040
|
-
additionalProperties: (
|
|
1039
|
+
additionalProperties: (_a15 = parseDef(def.valueType._def, {
|
|
1041
1040
|
...refs,
|
|
1042
1041
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1043
|
-
})) != null ?
|
|
1042
|
+
})) != null ? _a15 : refs.allowedAdditionalProperties
|
|
1044
1043
|
};
|
|
1045
1044
|
if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1046
1045
|
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
@@ -1297,8 +1296,8 @@ function safeIsOptional(schema) {
|
|
|
1297
1296
|
}
|
|
1298
1297
|
}
|
|
1299
1298
|
var parseOptionalDef = (def, refs) => {
|
|
1300
|
-
var
|
|
1301
|
-
if (refs.currentPath.toString() === ((
|
|
1299
|
+
var _a15;
|
|
1300
|
+
if (refs.currentPath.toString() === ((_a15 = refs.propertyPath) == null ? void 0 : _a15.toString())) {
|
|
1302
1301
|
return parseDef(def.innerType._def, refs);
|
|
1303
1302
|
}
|
|
1304
1303
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -1468,10 +1467,10 @@ var selectParser = (def, typeName, refs) => {
|
|
|
1468
1467
|
}
|
|
1469
1468
|
};
|
|
1470
1469
|
function parseDef(def, refs, forceResolution = false) {
|
|
1471
|
-
var
|
|
1470
|
+
var _a15;
|
|
1472
1471
|
const seenItem = refs.seen.get(def);
|
|
1473
1472
|
if (refs.override) {
|
|
1474
|
-
const overrideResult = (
|
|
1473
|
+
const overrideResult = (_a15 = refs.override) == null ? void 0 : _a15.call(
|
|
1475
1474
|
refs,
|
|
1476
1475
|
def,
|
|
1477
1476
|
refs,
|
|
@@ -1537,11 +1536,11 @@ var getRefs = (options) => {
|
|
|
1537
1536
|
currentPath,
|
|
1538
1537
|
propertyPath: void 0,
|
|
1539
1538
|
seen: new Map(
|
|
1540
|
-
Object.entries(_options.definitions).map(([
|
|
1539
|
+
Object.entries(_options.definitions).map(([name14, def]) => [
|
|
1541
1540
|
def._def,
|
|
1542
1541
|
{
|
|
1543
1542
|
def: def._def,
|
|
1544
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
1543
|
+
path: [..._options.basePath, _options.definitionPath, name14],
|
|
1545
1544
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1546
1545
|
jsonSchema: void 0
|
|
1547
1546
|
}
|
|
@@ -1550,50 +1549,50 @@ var getRefs = (options) => {
|
|
|
1550
1549
|
};
|
|
1551
1550
|
};
|
|
1552
1551
|
var zodToJsonSchema = (schema, options) => {
|
|
1553
|
-
var
|
|
1552
|
+
var _a15;
|
|
1554
1553
|
const refs = getRefs(options);
|
|
1555
1554
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
1556
|
-
(acc, [
|
|
1557
|
-
var
|
|
1555
|
+
(acc, [name22, schema2]) => {
|
|
1556
|
+
var _a22;
|
|
1558
1557
|
return {
|
|
1559
1558
|
...acc,
|
|
1560
|
-
[
|
|
1559
|
+
[name22]: (_a22 = parseDef(
|
|
1561
1560
|
schema2._def,
|
|
1562
1561
|
{
|
|
1563
1562
|
...refs,
|
|
1564
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
1563
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
1565
1564
|
},
|
|
1566
1565
|
true
|
|
1567
|
-
)) != null ?
|
|
1566
|
+
)) != null ? _a22 : parseAnyDef()
|
|
1568
1567
|
};
|
|
1569
1568
|
},
|
|
1570
1569
|
{}
|
|
1571
1570
|
) : void 0;
|
|
1572
|
-
const
|
|
1573
|
-
const main = (
|
|
1571
|
+
const name14 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
1572
|
+
const main = (_a15 = parseDef(
|
|
1574
1573
|
schema._def,
|
|
1575
|
-
|
|
1574
|
+
name14 === void 0 ? refs : {
|
|
1576
1575
|
...refs,
|
|
1577
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
1576
|
+
currentPath: [...refs.basePath, refs.definitionPath, name14]
|
|
1578
1577
|
},
|
|
1579
1578
|
false
|
|
1580
|
-
)) != null ?
|
|
1579
|
+
)) != null ? _a15 : parseAnyDef();
|
|
1581
1580
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1582
1581
|
if (title !== void 0) {
|
|
1583
1582
|
main.title = title;
|
|
1584
1583
|
}
|
|
1585
|
-
const combined =
|
|
1584
|
+
const combined = name14 === void 0 ? definitions ? {
|
|
1586
1585
|
...main,
|
|
1587
1586
|
[refs.definitionPath]: definitions
|
|
1588
1587
|
} : main : {
|
|
1589
1588
|
$ref: [
|
|
1590
1589
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1591
1590
|
refs.definitionPath,
|
|
1592
|
-
|
|
1591
|
+
name14
|
|
1593
1592
|
].join("/"),
|
|
1594
1593
|
[refs.definitionPath]: {
|
|
1595
1594
|
...definitions,
|
|
1596
|
-
[
|
|
1595
|
+
[name14]: main
|
|
1597
1596
|
}
|
|
1598
1597
|
};
|
|
1599
1598
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -1601,8 +1600,8 @@ var zodToJsonSchema = (schema, options) => {
|
|
|
1601
1600
|
};
|
|
1602
1601
|
var zod_to_json_schema_default = zodToJsonSchema;
|
|
1603
1602
|
function zod3Schema(zodSchema2, options) {
|
|
1604
|
-
var
|
|
1605
|
-
const useReferences = (
|
|
1603
|
+
var _a15;
|
|
1604
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
1606
1605
|
return jsonSchema(
|
|
1607
1606
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1608
1607
|
() => zod_to_json_schema_default(zodSchema2, {
|
|
@@ -1617,8 +1616,8 @@ function zod3Schema(zodSchema2, options) {
|
|
|
1617
1616
|
);
|
|
1618
1617
|
}
|
|
1619
1618
|
function zod4Schema(zodSchema2, options) {
|
|
1620
|
-
var
|
|
1621
|
-
const useReferences = (
|
|
1619
|
+
var _a15;
|
|
1620
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
1622
1621
|
return jsonSchema(
|
|
1623
1622
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1624
1623
|
() => z4.toJSONSchema(zodSchema2, {
|
|
@@ -1998,12 +1997,12 @@ var DeepSeekChatLanguageModel = class {
|
|
|
1998
1997
|
toolChoice,
|
|
1999
1998
|
seed
|
|
2000
1999
|
}) {
|
|
2001
|
-
var
|
|
2002
|
-
const deepseekOptions = (
|
|
2000
|
+
var _a15, _b;
|
|
2001
|
+
const deepseekOptions = (_a15 = await parseProviderOptions2({
|
|
2003
2002
|
provider: this.providerOptionsName,
|
|
2004
2003
|
providerOptions,
|
|
2005
2004
|
schema: deepseekChatOptions
|
|
2006
|
-
})) != null ?
|
|
2005
|
+
})) != null ? _a15 : {};
|
|
2007
2006
|
const { messages, warnings } = convertToDeepSeekChatMessages({
|
|
2008
2007
|
prompt,
|
|
2009
2008
|
responseFormat
|
|
@@ -2041,7 +2040,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2041
2040
|
};
|
|
2042
2041
|
}
|
|
2043
2042
|
async doGenerate(options) {
|
|
2044
|
-
var
|
|
2043
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2045
2044
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
2046
2045
|
const {
|
|
2047
2046
|
responseHeaders,
|
|
@@ -2074,7 +2073,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2074
2073
|
for (const toolCall of choice.message.tool_calls) {
|
|
2075
2074
|
content.push({
|
|
2076
2075
|
type: "tool-call",
|
|
2077
|
-
toolCallId: (
|
|
2076
|
+
toolCallId: (_a15 = toolCall.id) != null ? _a15 : generateId2(),
|
|
2078
2077
|
toolName: toolCall.function.name,
|
|
2079
2078
|
input: toolCall.function.arguments
|
|
2080
2079
|
});
|
|
@@ -2144,7 +2143,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2144
2143
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2145
2144
|
},
|
|
2146
2145
|
transform(chunk, controller) {
|
|
2147
|
-
var
|
|
2146
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2148
2147
|
if (options.includeRawChunks) {
|
|
2149
2148
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2150
2149
|
}
|
|
@@ -2227,7 +2226,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2227
2226
|
message: `Expected 'id' to be a string.`
|
|
2228
2227
|
});
|
|
2229
2228
|
}
|
|
2230
|
-
if (((
|
|
2229
|
+
if (((_a15 = toolCallDelta.function) == null ? void 0 : _a15.name) == null) {
|
|
2231
2230
|
throw new InvalidResponseDataError({
|
|
2232
2231
|
data: toolCallDelta,
|
|
2233
2232
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -2301,7 +2300,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2301
2300
|
}
|
|
2302
2301
|
},
|
|
2303
2302
|
flush(controller) {
|
|
2304
|
-
var
|
|
2303
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2305
2304
|
if (isActiveReasoning) {
|
|
2306
2305
|
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
2307
2306
|
}
|
|
@@ -2317,7 +2316,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2317
2316
|
});
|
|
2318
2317
|
controller.enqueue({
|
|
2319
2318
|
type: "tool-call",
|
|
2320
|
-
toolCallId: (
|
|
2319
|
+
toolCallId: (_a15 = toolCall.id) != null ? _a15 : generateId2(),
|
|
2321
2320
|
toolName: toolCall.function.name,
|
|
2322
2321
|
input: toolCall.function.arguments
|
|
2323
2322
|
});
|
|
@@ -2349,9 +2348,9 @@ var DeepSeekChatLanguageModel = class {
|
|
|
2349
2348
|
};
|
|
2350
2349
|
var VERSION2 = "1.0.31" ;
|
|
2351
2350
|
function createDeepSeek(options = {}) {
|
|
2352
|
-
var
|
|
2351
|
+
var _a15;
|
|
2353
2352
|
const baseURL = withoutTrailingSlash2(
|
|
2354
|
-
(
|
|
2353
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.deepseek.com"
|
|
2355
2354
|
);
|
|
2356
2355
|
const getHeaders = () => withUserAgentSuffix2(
|
|
2357
2356
|
{
|
|
@@ -2618,10 +2617,10 @@ var MistralChatLanguageModel = class {
|
|
|
2618
2617
|
this.supportedUrls = {
|
|
2619
2618
|
"application/pdf": [/^https:\/\/.*$/]
|
|
2620
2619
|
};
|
|
2621
|
-
var
|
|
2620
|
+
var _a15;
|
|
2622
2621
|
this.modelId = modelId;
|
|
2623
2622
|
this.config = config;
|
|
2624
|
-
this.generateId = (
|
|
2623
|
+
this.generateId = (_a15 = config.generateId) != null ? _a15 : generateId;
|
|
2625
2624
|
}
|
|
2626
2625
|
get provider() {
|
|
2627
2626
|
return this.config.provider;
|
|
@@ -2641,13 +2640,13 @@ var MistralChatLanguageModel = class {
|
|
|
2641
2640
|
tools,
|
|
2642
2641
|
toolChoice
|
|
2643
2642
|
}) {
|
|
2644
|
-
var
|
|
2643
|
+
var _a15, _b, _c, _d;
|
|
2645
2644
|
const warnings = [];
|
|
2646
|
-
const options = (
|
|
2645
|
+
const options = (_a15 = await parseProviderOptions({
|
|
2647
2646
|
provider: "mistral",
|
|
2648
2647
|
providerOptions,
|
|
2649
2648
|
schema: mistralLanguageModelOptions
|
|
2650
|
-
})) != null ?
|
|
2649
|
+
})) != null ? _a15 : {};
|
|
2651
2650
|
if (topK != null) {
|
|
2652
2651
|
warnings.push({
|
|
2653
2652
|
type: "unsupported-setting",
|
|
@@ -3109,8 +3108,8 @@ var MistralTextEmbeddingResponseSchema = z.object({
|
|
|
3109
3108
|
});
|
|
3110
3109
|
var VERSION3 = "2.0.24" ;
|
|
3111
3110
|
function createMistral(options = {}) {
|
|
3112
|
-
var
|
|
3113
|
-
const baseURL = (
|
|
3111
|
+
var _a15;
|
|
3112
|
+
const baseURL = (_a15 = withoutTrailingSlash(options.baseURL)) != null ? _a15 : "https://api.mistral.ai/v1";
|
|
3114
3113
|
const getHeaders = () => withUserAgentSuffix(
|
|
3115
3114
|
{
|
|
3116
3115
|
Authorization: `Bearer ${loadApiKey({
|
|
@@ -3618,7 +3617,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
3618
3617
|
(part) => part.type === "file" && part.mediaType.startsWith("image/")
|
|
3619
3618
|
);
|
|
3620
3619
|
const messageContent = content.map((part) => {
|
|
3621
|
-
var
|
|
3620
|
+
var _a15;
|
|
3622
3621
|
switch (part.type) {
|
|
3623
3622
|
case "text": {
|
|
3624
3623
|
return {
|
|
@@ -3635,7 +3634,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
3635
3634
|
} : {
|
|
3636
3635
|
type: "image_url",
|
|
3637
3636
|
image_url: {
|
|
3638
|
-
url: `data:${(
|
|
3637
|
+
url: `data:${(_a15 = part.mediaType) != null ? _a15 : "image/jpeg"};base64,${typeof part.data === "string" ? part.data : convertUint8ArrayToBase64(part.data)}`
|
|
3639
3638
|
}
|
|
3640
3639
|
};
|
|
3641
3640
|
}
|
|
@@ -3692,7 +3691,7 @@ var PerplexityLanguageModel = class {
|
|
|
3692
3691
|
seed,
|
|
3693
3692
|
providerOptions
|
|
3694
3693
|
}) {
|
|
3695
|
-
var
|
|
3694
|
+
var _a15;
|
|
3696
3695
|
const warnings = [];
|
|
3697
3696
|
if (topK != null) {
|
|
3698
3697
|
warnings.push({
|
|
@@ -3729,7 +3728,7 @@ var PerplexityLanguageModel = class {
|
|
|
3729
3728
|
json_schema: { schema: responseFormat.schema }
|
|
3730
3729
|
} : void 0,
|
|
3731
3730
|
// provider extensions
|
|
3732
|
-
...(
|
|
3731
|
+
...(_a15 = providerOptions == null ? void 0 : providerOptions.perplexity) != null ? _a15 : {},
|
|
3733
3732
|
// messages:
|
|
3734
3733
|
messages: convertToPerplexityMessages(prompt)
|
|
3735
3734
|
},
|
|
@@ -3737,7 +3736,7 @@ var PerplexityLanguageModel = class {
|
|
|
3737
3736
|
};
|
|
3738
3737
|
}
|
|
3739
3738
|
async doGenerate(options) {
|
|
3740
|
-
var
|
|
3739
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3741
3740
|
const { args: body, warnings } = this.getArgs(options);
|
|
3742
3741
|
const {
|
|
3743
3742
|
responseHeaders,
|
|
@@ -3777,7 +3776,7 @@ var PerplexityLanguageModel = class {
|
|
|
3777
3776
|
content,
|
|
3778
3777
|
finishReason: mapPerplexityFinishReason(choice.finish_reason),
|
|
3779
3778
|
usage: {
|
|
3780
|
-
inputTokens: (
|
|
3779
|
+
inputTokens: (_a15 = response.usage) == null ? void 0 : _a15.prompt_tokens,
|
|
3781
3780
|
outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
|
|
3782
3781
|
totalTokens: (_d = (_c = response.usage) == null ? void 0 : _c.total_tokens) != null ? _d : void 0
|
|
3783
3782
|
},
|
|
@@ -3846,7 +3845,7 @@ var PerplexityLanguageModel = class {
|
|
|
3846
3845
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3847
3846
|
},
|
|
3848
3847
|
transform(chunk, controller) {
|
|
3849
|
-
var
|
|
3848
|
+
var _a15, _b, _c;
|
|
3850
3849
|
if (options.includeRawChunks) {
|
|
3851
3850
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3852
3851
|
}
|
|
@@ -3860,7 +3859,7 @@ var PerplexityLanguageModel = class {
|
|
|
3860
3859
|
type: "response-metadata",
|
|
3861
3860
|
...getResponseMetadata3(value)
|
|
3862
3861
|
});
|
|
3863
|
-
(
|
|
3862
|
+
(_a15 = value.citations) == null ? void 0 : _a15.forEach((url) => {
|
|
3864
3863
|
controller.enqueue({
|
|
3865
3864
|
type: "source",
|
|
3866
3865
|
sourceType: "url",
|
|
@@ -3991,8 +3990,8 @@ var perplexityErrorSchema = z.object({
|
|
|
3991
3990
|
})
|
|
3992
3991
|
});
|
|
3993
3992
|
var errorToMessage = (data) => {
|
|
3994
|
-
var
|
|
3995
|
-
return (_b = (
|
|
3993
|
+
var _a15, _b;
|
|
3994
|
+
return (_b = (_a15 = data.error.message) != null ? _a15 : data.error.type) != null ? _b : "unknown error";
|
|
3996
3995
|
};
|
|
3997
3996
|
function createPerplexity(options = {}) {
|
|
3998
3997
|
const getHeaders = () => ({
|
|
@@ -4004,10 +4003,10 @@ function createPerplexity(options = {}) {
|
|
|
4004
4003
|
...options.headers
|
|
4005
4004
|
});
|
|
4006
4005
|
const createLanguageModel = (modelId) => {
|
|
4007
|
-
var
|
|
4006
|
+
var _a15;
|
|
4008
4007
|
return new PerplexityLanguageModel(modelId, {
|
|
4009
4008
|
baseURL: withoutTrailingSlash3(
|
|
4010
|
-
(
|
|
4009
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.perplexity.ai"
|
|
4011
4010
|
),
|
|
4012
4011
|
headers: getHeaders,
|
|
4013
4012
|
generateId: generateId3,
|
|
@@ -4319,13 +4318,13 @@ var XaiChatLanguageModel = class {
|
|
|
4319
4318
|
tools,
|
|
4320
4319
|
toolChoice
|
|
4321
4320
|
}) {
|
|
4322
|
-
var
|
|
4321
|
+
var _a15, _b, _c;
|
|
4323
4322
|
const warnings = [];
|
|
4324
|
-
const options = (
|
|
4323
|
+
const options = (_a15 = await parseProviderOptions({
|
|
4325
4324
|
provider: "xai",
|
|
4326
4325
|
providerOptions,
|
|
4327
4326
|
schema: xaiProviderOptions
|
|
4328
|
-
})) != null ?
|
|
4327
|
+
})) != null ? _a15 : {};
|
|
4329
4328
|
if (topK != null) {
|
|
4330
4329
|
warnings.push({
|
|
4331
4330
|
type: "unsupported-setting",
|
|
@@ -4389,7 +4388,7 @@ var XaiChatLanguageModel = class {
|
|
|
4389
4388
|
to_date: options.searchParameters.toDate,
|
|
4390
4389
|
max_search_results: options.searchParameters.maxSearchResults,
|
|
4391
4390
|
sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
|
|
4392
|
-
var
|
|
4391
|
+
var _a22;
|
|
4393
4392
|
return {
|
|
4394
4393
|
type: source.type,
|
|
4395
4394
|
...source.type === "web" && {
|
|
@@ -4400,7 +4399,7 @@ var XaiChatLanguageModel = class {
|
|
|
4400
4399
|
},
|
|
4401
4400
|
...source.type === "x" && {
|
|
4402
4401
|
excluded_x_handles: source.excludedXHandles,
|
|
4403
|
-
included_x_handles: (
|
|
4402
|
+
included_x_handles: (_a22 = source.includedXHandles) != null ? _a22 : source.xHandles,
|
|
4404
4403
|
post_favorite_count: source.postFavoriteCount,
|
|
4405
4404
|
post_view_count: source.postViewCount
|
|
4406
4405
|
},
|
|
@@ -4427,14 +4426,14 @@ var XaiChatLanguageModel = class {
|
|
|
4427
4426
|
};
|
|
4428
4427
|
}
|
|
4429
4428
|
async doGenerate(options) {
|
|
4430
|
-
var
|
|
4429
|
+
var _a15, _b, _c;
|
|
4431
4430
|
const { args: body, warnings } = await this.getArgs(options);
|
|
4432
4431
|
const {
|
|
4433
4432
|
responseHeaders,
|
|
4434
4433
|
value: response,
|
|
4435
4434
|
rawValue: rawResponse
|
|
4436
4435
|
} = await postJsonToApi({
|
|
4437
|
-
url: `${(
|
|
4436
|
+
url: `${(_a15 = this.config.baseURL) != null ? _a15 : "https://api.x.ai/v1"}/chat/completions`,
|
|
4438
4437
|
headers: combineHeaders(this.config.headers(), options.headers),
|
|
4439
4438
|
body,
|
|
4440
4439
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -4501,7 +4500,7 @@ var XaiChatLanguageModel = class {
|
|
|
4501
4500
|
};
|
|
4502
4501
|
}
|
|
4503
4502
|
async doStream(options) {
|
|
4504
|
-
var
|
|
4503
|
+
var _a15;
|
|
4505
4504
|
const { args, warnings } = await this.getArgs(options);
|
|
4506
4505
|
const body = {
|
|
4507
4506
|
...args,
|
|
@@ -4511,7 +4510,7 @@ var XaiChatLanguageModel = class {
|
|
|
4511
4510
|
}
|
|
4512
4511
|
};
|
|
4513
4512
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
4514
|
-
url: `${(
|
|
4513
|
+
url: `${(_a15 = this.config.baseURL) != null ? _a15 : "https://api.x.ai/v1"}/chat/completions`,
|
|
4515
4514
|
headers: combineHeaders(this.config.headers(), options.headers),
|
|
4516
4515
|
body,
|
|
4517
4516
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
@@ -4536,7 +4535,7 @@ var XaiChatLanguageModel = class {
|
|
|
4536
4535
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4537
4536
|
},
|
|
4538
4537
|
transform(chunk, controller) {
|
|
4539
|
-
var
|
|
4538
|
+
var _a22, _b;
|
|
4540
4539
|
if (options.includeRawChunks) {
|
|
4541
4540
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4542
4541
|
}
|
|
@@ -4566,7 +4565,7 @@ var XaiChatLanguageModel = class {
|
|
|
4566
4565
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
4567
4566
|
usage.outputTokens = value.usage.completion_tokens;
|
|
4568
4567
|
usage.totalTokens = value.usage.total_tokens;
|
|
4569
|
-
usage.reasoningTokens = (_b = (
|
|
4568
|
+
usage.reasoningTokens = (_b = (_a22 = value.usage.completion_tokens_details) == null ? void 0 : _a22.reasoning_tokens) != null ? _b : void 0;
|
|
4570
4569
|
}
|
|
4571
4570
|
const choice = value.choices[0];
|
|
4572
4571
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -4729,9 +4728,9 @@ var xaiErrorStructure = {
|
|
|
4729
4728
|
errorToMessage: (data) => data.error.message
|
|
4730
4729
|
};
|
|
4731
4730
|
function createXai(options = {}) {
|
|
4732
|
-
var
|
|
4731
|
+
var _a15;
|
|
4733
4732
|
const baseURL = withoutTrailingSlash(
|
|
4734
|
-
(
|
|
4733
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.x.ai/v1"
|
|
4735
4734
|
);
|
|
4736
4735
|
const getHeaders = () => withUserAgentSuffix(
|
|
4737
4736
|
{
|
|
@@ -4773,6 +4772,2459 @@ function createXai(options = {}) {
|
|
|
4773
4772
|
return provider;
|
|
4774
4773
|
}
|
|
4775
4774
|
createXai();
|
|
4775
|
+
var __defProp = Object.defineProperty;
|
|
4776
|
+
var __defProps = Object.defineProperties;
|
|
4777
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4778
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4779
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4780
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4781
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4782
|
+
var __spreadValues = (a, b) => {
|
|
4783
|
+
for (var prop in b || (b = {}))
|
|
4784
|
+
if (__hasOwnProp.call(b, prop))
|
|
4785
|
+
__defNormalProp(a, prop, b[prop]);
|
|
4786
|
+
if (__getOwnPropSymbols)
|
|
4787
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
4788
|
+
if (__propIsEnum.call(b, prop))
|
|
4789
|
+
__defNormalProp(a, prop, b[prop]);
|
|
4790
|
+
}
|
|
4791
|
+
return a;
|
|
4792
|
+
};
|
|
4793
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
4794
|
+
var marker = "vercel.ai.error";
|
|
4795
|
+
var symbol = Symbol.for(marker);
|
|
4796
|
+
var _a;
|
|
4797
|
+
var _AISDKError = class _AISDKError2 extends Error {
|
|
4798
|
+
/**
|
|
4799
|
+
* Creates an AI SDK Error.
|
|
4800
|
+
*
|
|
4801
|
+
* @param {Object} params - The parameters for creating the error.
|
|
4802
|
+
* @param {string} params.name - The name of the error.
|
|
4803
|
+
* @param {string} params.message - The error message.
|
|
4804
|
+
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
4805
|
+
*/
|
|
4806
|
+
constructor({
|
|
4807
|
+
name: name14,
|
|
4808
|
+
message,
|
|
4809
|
+
cause
|
|
4810
|
+
}) {
|
|
4811
|
+
super(message);
|
|
4812
|
+
this[_a] = true;
|
|
4813
|
+
this.name = name14;
|
|
4814
|
+
this.cause = cause;
|
|
4815
|
+
}
|
|
4816
|
+
/**
|
|
4817
|
+
* Checks if the given error is an AI SDK Error.
|
|
4818
|
+
* @param {unknown} error - The error to check.
|
|
4819
|
+
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
4820
|
+
*/
|
|
4821
|
+
static isInstance(error) {
|
|
4822
|
+
return _AISDKError2.hasMarker(error, marker);
|
|
4823
|
+
}
|
|
4824
|
+
static hasMarker(error, marker15) {
|
|
4825
|
+
const markerSymbol = Symbol.for(marker15);
|
|
4826
|
+
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
4827
|
+
}
|
|
4828
|
+
};
|
|
4829
|
+
_a = symbol;
|
|
4830
|
+
var AISDKError = _AISDKError;
|
|
4831
|
+
var name = "AI_APICallError";
|
|
4832
|
+
var marker2 = `vercel.ai.error.${name}`;
|
|
4833
|
+
var symbol2 = Symbol.for(marker2);
|
|
4834
|
+
var _a2;
|
|
4835
|
+
var APICallError2 = class extends AISDKError {
|
|
4836
|
+
constructor({
|
|
4837
|
+
message,
|
|
4838
|
+
url,
|
|
4839
|
+
requestBodyValues,
|
|
4840
|
+
statusCode,
|
|
4841
|
+
responseHeaders,
|
|
4842
|
+
responseBody,
|
|
4843
|
+
cause,
|
|
4844
|
+
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
|
4845
|
+
statusCode === 409 || // conflict
|
|
4846
|
+
statusCode === 429 || // too many requests
|
|
4847
|
+
statusCode >= 500),
|
|
4848
|
+
// server error
|
|
4849
|
+
data
|
|
4850
|
+
}) {
|
|
4851
|
+
super({ name, message, cause });
|
|
4852
|
+
this[_a2] = true;
|
|
4853
|
+
this.url = url;
|
|
4854
|
+
this.requestBodyValues = requestBodyValues;
|
|
4855
|
+
this.statusCode = statusCode;
|
|
4856
|
+
this.responseHeaders = responseHeaders;
|
|
4857
|
+
this.responseBody = responseBody;
|
|
4858
|
+
this.isRetryable = isRetryable;
|
|
4859
|
+
this.data = data;
|
|
4860
|
+
}
|
|
4861
|
+
static isInstance(error) {
|
|
4862
|
+
return AISDKError.hasMarker(error, marker2);
|
|
4863
|
+
}
|
|
4864
|
+
};
|
|
4865
|
+
_a2 = symbol2;
|
|
4866
|
+
var name2 = "AI_EmptyResponseBodyError";
|
|
4867
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
4868
|
+
var symbol3 = Symbol.for(marker3);
|
|
4869
|
+
var _a3;
|
|
4870
|
+
var EmptyResponseBodyError2 = class extends AISDKError {
|
|
4871
|
+
// used in isInstance
|
|
4872
|
+
constructor({ message = "Empty response body" } = {}) {
|
|
4873
|
+
super({ name: name2, message });
|
|
4874
|
+
this[_a3] = true;
|
|
4875
|
+
}
|
|
4876
|
+
static isInstance(error) {
|
|
4877
|
+
return AISDKError.hasMarker(error, marker3);
|
|
4878
|
+
}
|
|
4879
|
+
};
|
|
4880
|
+
_a3 = symbol3;
|
|
4881
|
+
function getErrorMessage(error) {
|
|
4882
|
+
if (error == null) {
|
|
4883
|
+
return "unknown error";
|
|
4884
|
+
}
|
|
4885
|
+
if (typeof error === "string") {
|
|
4886
|
+
return error;
|
|
4887
|
+
}
|
|
4888
|
+
if (error instanceof Error) {
|
|
4889
|
+
return error.message;
|
|
4890
|
+
}
|
|
4891
|
+
return JSON.stringify(error);
|
|
4892
|
+
}
|
|
4893
|
+
var name3 = "AI_InvalidArgumentError";
|
|
4894
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
|
4895
|
+
var symbol4 = Symbol.for(marker4);
|
|
4896
|
+
var _a4;
|
|
4897
|
+
var InvalidArgumentError2 = class extends AISDKError {
|
|
4898
|
+
constructor({
|
|
4899
|
+
message,
|
|
4900
|
+
cause,
|
|
4901
|
+
argument
|
|
4902
|
+
}) {
|
|
4903
|
+
super({ name: name3, message, cause });
|
|
4904
|
+
this[_a4] = true;
|
|
4905
|
+
this.argument = argument;
|
|
4906
|
+
}
|
|
4907
|
+
static isInstance(error) {
|
|
4908
|
+
return AISDKError.hasMarker(error, marker4);
|
|
4909
|
+
}
|
|
4910
|
+
};
|
|
4911
|
+
_a4 = symbol4;
|
|
4912
|
+
var name4 = "AI_InvalidPromptError";
|
|
4913
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
|
4914
|
+
var symbol5 = Symbol.for(marker5);
|
|
4915
|
+
var _a5;
|
|
4916
|
+
var InvalidPromptError = class extends AISDKError {
|
|
4917
|
+
constructor({
|
|
4918
|
+
prompt,
|
|
4919
|
+
message,
|
|
4920
|
+
cause
|
|
4921
|
+
}) {
|
|
4922
|
+
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
4923
|
+
this[_a5] = true;
|
|
4924
|
+
this.prompt = prompt;
|
|
4925
|
+
}
|
|
4926
|
+
static isInstance(error) {
|
|
4927
|
+
return AISDKError.hasMarker(error, marker5);
|
|
4928
|
+
}
|
|
4929
|
+
};
|
|
4930
|
+
_a5 = symbol5;
|
|
4931
|
+
var name5 = "AI_InvalidResponseDataError";
|
|
4932
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
|
4933
|
+
var symbol6 = Symbol.for(marker6);
|
|
4934
|
+
var _a6;
|
|
4935
|
+
var InvalidResponseDataError2 = class extends AISDKError {
|
|
4936
|
+
constructor({
|
|
4937
|
+
data,
|
|
4938
|
+
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
4939
|
+
}) {
|
|
4940
|
+
super({ name: name5, message });
|
|
4941
|
+
this[_a6] = true;
|
|
4942
|
+
this.data = data;
|
|
4943
|
+
}
|
|
4944
|
+
static isInstance(error) {
|
|
4945
|
+
return AISDKError.hasMarker(error, marker6);
|
|
4946
|
+
}
|
|
4947
|
+
};
|
|
4948
|
+
_a6 = symbol6;
|
|
4949
|
+
var name6 = "AI_JSONParseError";
|
|
4950
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
|
4951
|
+
var symbol7 = Symbol.for(marker7);
|
|
4952
|
+
var _a7;
|
|
4953
|
+
var JSONParseError2 = class extends AISDKError {
|
|
4954
|
+
constructor({ text, cause }) {
|
|
4955
|
+
super({
|
|
4956
|
+
name: name6,
|
|
4957
|
+
message: `JSON parsing failed: Text: ${text}.
|
|
4958
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
4959
|
+
cause
|
|
4960
|
+
});
|
|
4961
|
+
this[_a7] = true;
|
|
4962
|
+
this.text = text;
|
|
4963
|
+
}
|
|
4964
|
+
static isInstance(error) {
|
|
4965
|
+
return AISDKError.hasMarker(error, marker7);
|
|
4966
|
+
}
|
|
4967
|
+
};
|
|
4968
|
+
_a7 = symbol7;
|
|
4969
|
+
var name7 = "AI_LoadAPIKeyError";
|
|
4970
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
|
4971
|
+
var symbol8 = Symbol.for(marker8);
|
|
4972
|
+
var _a8;
|
|
4973
|
+
var LoadAPIKeyError2 = class extends AISDKError {
|
|
4974
|
+
// used in isInstance
|
|
4975
|
+
constructor({ message }) {
|
|
4976
|
+
super({ name: name7, message });
|
|
4977
|
+
this[_a8] = true;
|
|
4978
|
+
}
|
|
4979
|
+
static isInstance(error) {
|
|
4980
|
+
return AISDKError.hasMarker(error, marker8);
|
|
4981
|
+
}
|
|
4982
|
+
};
|
|
4983
|
+
_a8 = symbol8;
|
|
4984
|
+
var name9 = "AI_NoContentGeneratedError";
|
|
4985
|
+
var marker10 = `vercel.ai.error.${name9}`;
|
|
4986
|
+
var symbol10 = Symbol.for(marker10);
|
|
4987
|
+
var _a10;
|
|
4988
|
+
var NoContentGeneratedError = class extends AISDKError {
|
|
4989
|
+
// used in isInstance
|
|
4990
|
+
constructor({
|
|
4991
|
+
message = "No content generated."
|
|
4992
|
+
} = {}) {
|
|
4993
|
+
super({ name: name9, message });
|
|
4994
|
+
this[_a10] = true;
|
|
4995
|
+
}
|
|
4996
|
+
static isInstance(error) {
|
|
4997
|
+
return AISDKError.hasMarker(error, marker10);
|
|
4998
|
+
}
|
|
4999
|
+
};
|
|
5000
|
+
_a10 = symbol10;
|
|
5001
|
+
var name12 = "AI_TypeValidationError";
|
|
5002
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
5003
|
+
var symbol13 = Symbol.for(marker13);
|
|
5004
|
+
var _a13;
|
|
5005
|
+
var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
|
|
5006
|
+
constructor({ value, cause }) {
|
|
5007
|
+
super({
|
|
5008
|
+
name: name12,
|
|
5009
|
+
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
|
5010
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
5011
|
+
cause
|
|
5012
|
+
});
|
|
5013
|
+
this[_a13] = true;
|
|
5014
|
+
this.value = value;
|
|
5015
|
+
}
|
|
5016
|
+
static isInstance(error) {
|
|
5017
|
+
return AISDKError.hasMarker(error, marker13);
|
|
5018
|
+
}
|
|
5019
|
+
/**
|
|
5020
|
+
* Wraps an error into a TypeValidationError.
|
|
5021
|
+
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
5022
|
+
* Otherwise, it creates a new TypeValidationError.
|
|
5023
|
+
*
|
|
5024
|
+
* @param {Object} params - The parameters for wrapping the error.
|
|
5025
|
+
* @param {unknown} params.value - The value that failed validation.
|
|
5026
|
+
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
5027
|
+
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
5028
|
+
*/
|
|
5029
|
+
static wrap({
|
|
5030
|
+
value,
|
|
5031
|
+
cause
|
|
5032
|
+
}) {
|
|
5033
|
+
return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
|
|
5034
|
+
}
|
|
5035
|
+
};
|
|
5036
|
+
_a13 = symbol13;
|
|
5037
|
+
var TypeValidationError2 = _TypeValidationError;
|
|
5038
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
5039
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
5040
|
+
var symbol14 = Symbol.for(marker14);
|
|
5041
|
+
var _a14;
|
|
5042
|
+
var UnsupportedFunctionalityError2 = class extends AISDKError {
|
|
5043
|
+
constructor({
|
|
5044
|
+
functionality,
|
|
5045
|
+
message = `'${functionality}' functionality not supported.`
|
|
5046
|
+
}) {
|
|
5047
|
+
super({ name: name13, message });
|
|
5048
|
+
this[_a14] = true;
|
|
5049
|
+
this.functionality = functionality;
|
|
5050
|
+
}
|
|
5051
|
+
static isInstance(error) {
|
|
5052
|
+
return AISDKError.hasMarker(error, marker14);
|
|
5053
|
+
}
|
|
5054
|
+
};
|
|
5055
|
+
_a14 = symbol14;
|
|
5056
|
+
var ParseError = class extends Error {
|
|
5057
|
+
constructor(message, options) {
|
|
5058
|
+
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
5059
|
+
}
|
|
5060
|
+
};
|
|
5061
|
+
function noop(_arg) {
|
|
5062
|
+
}
|
|
5063
|
+
function createParser(callbacks) {
|
|
5064
|
+
if (typeof callbacks == "function")
|
|
5065
|
+
throw new TypeError(
|
|
5066
|
+
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
5067
|
+
);
|
|
5068
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
5069
|
+
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
5070
|
+
function feed(newChunk) {
|
|
5071
|
+
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
|
|
5072
|
+
for (const line of complete)
|
|
5073
|
+
parseLine(line);
|
|
5074
|
+
incompleteLine = incomplete, isFirstChunk = false;
|
|
5075
|
+
}
|
|
5076
|
+
function parseLine(line) {
|
|
5077
|
+
if (line === "") {
|
|
5078
|
+
dispatchEvent();
|
|
5079
|
+
return;
|
|
5080
|
+
}
|
|
5081
|
+
if (line.startsWith(":")) {
|
|
5082
|
+
onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
|
|
5083
|
+
return;
|
|
5084
|
+
}
|
|
5085
|
+
const fieldSeparatorIndex = line.indexOf(":");
|
|
5086
|
+
if (fieldSeparatorIndex !== -1) {
|
|
5087
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
5088
|
+
processField(field, value, line);
|
|
5089
|
+
return;
|
|
5090
|
+
}
|
|
5091
|
+
processField(line, "", line);
|
|
5092
|
+
}
|
|
5093
|
+
function processField(field, value, line) {
|
|
5094
|
+
switch (field) {
|
|
5095
|
+
case "event":
|
|
5096
|
+
eventType = value;
|
|
5097
|
+
break;
|
|
5098
|
+
case "data":
|
|
5099
|
+
data = `${data}${value}
|
|
5100
|
+
`;
|
|
5101
|
+
break;
|
|
5102
|
+
case "id":
|
|
5103
|
+
id = value.includes("\0") ? void 0 : value;
|
|
5104
|
+
break;
|
|
5105
|
+
case "retry":
|
|
5106
|
+
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
5107
|
+
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
5108
|
+
type: "invalid-retry",
|
|
5109
|
+
value,
|
|
5110
|
+
line
|
|
5111
|
+
})
|
|
5112
|
+
);
|
|
5113
|
+
break;
|
|
5114
|
+
default:
|
|
5115
|
+
onError(
|
|
5116
|
+
new ParseError(
|
|
5117
|
+
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
5118
|
+
{ type: "unknown-field", field, value, line }
|
|
5119
|
+
)
|
|
5120
|
+
);
|
|
5121
|
+
break;
|
|
5122
|
+
}
|
|
5123
|
+
}
|
|
5124
|
+
function dispatchEvent() {
|
|
5125
|
+
data.length > 0 && onEvent({
|
|
5126
|
+
id,
|
|
5127
|
+
event: eventType || void 0,
|
|
5128
|
+
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
5129
|
+
// then remove the last character from the data buffer.
|
|
5130
|
+
data: data.endsWith(`
|
|
5131
|
+
`) ? data.slice(0, -1) : data
|
|
5132
|
+
}), id = void 0, data = "", eventType = "";
|
|
5133
|
+
}
|
|
5134
|
+
function reset(options = {}) {
|
|
5135
|
+
incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
|
|
5136
|
+
}
|
|
5137
|
+
return { feed, reset };
|
|
5138
|
+
}
|
|
5139
|
+
function splitLines(chunk) {
|
|
5140
|
+
const lines = [];
|
|
5141
|
+
let incompleteLine = "", searchIndex = 0;
|
|
5142
|
+
for (; searchIndex < chunk.length; ) {
|
|
5143
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
5144
|
+
`, searchIndex);
|
|
5145
|
+
let lineEnd = -1;
|
|
5146
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
5147
|
+
incompleteLine = chunk.slice(searchIndex);
|
|
5148
|
+
break;
|
|
5149
|
+
} else {
|
|
5150
|
+
const line = chunk.slice(searchIndex, lineEnd);
|
|
5151
|
+
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
5152
|
+
` && searchIndex++;
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
return [lines, incompleteLine];
|
|
5156
|
+
}
|
|
5157
|
+
var EventSourceParserStream2 = class extends TransformStream {
|
|
5158
|
+
constructor({ onError, onRetry, onComment } = {}) {
|
|
5159
|
+
let parser;
|
|
5160
|
+
super({
|
|
5161
|
+
start(controller) {
|
|
5162
|
+
parser = createParser({
|
|
5163
|
+
onEvent: (event) => {
|
|
5164
|
+
controller.enqueue(event);
|
|
5165
|
+
},
|
|
5166
|
+
onError(error) {
|
|
5167
|
+
onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
|
|
5168
|
+
},
|
|
5169
|
+
onRetry,
|
|
5170
|
+
onComment
|
|
5171
|
+
});
|
|
5172
|
+
},
|
|
5173
|
+
transform(chunk) {
|
|
5174
|
+
parser.feed(chunk);
|
|
5175
|
+
}
|
|
5176
|
+
});
|
|
5177
|
+
}
|
|
5178
|
+
};
|
|
5179
|
+
new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
5180
|
+
function combineHeaders4(...headers) {
|
|
5181
|
+
return headers.reduce(
|
|
5182
|
+
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
5183
|
+
{}
|
|
5184
|
+
);
|
|
5185
|
+
}
|
|
5186
|
+
function extractResponseHeaders3(response) {
|
|
5187
|
+
return Object.fromEntries([...response.headers]);
|
|
5188
|
+
}
|
|
5189
|
+
var createIdGenerator3 = ({
|
|
5190
|
+
prefix,
|
|
5191
|
+
size = 16,
|
|
5192
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
5193
|
+
separator = "-"
|
|
5194
|
+
} = {}) => {
|
|
5195
|
+
const generator = () => {
|
|
5196
|
+
const alphabetLength = alphabet.length;
|
|
5197
|
+
const chars = new Array(size);
|
|
5198
|
+
for (let i = 0; i < size; i++) {
|
|
5199
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
5200
|
+
}
|
|
5201
|
+
return chars.join("");
|
|
5202
|
+
};
|
|
5203
|
+
if (prefix == null) {
|
|
5204
|
+
return generator;
|
|
5205
|
+
}
|
|
5206
|
+
if (alphabet.includes(separator)) {
|
|
5207
|
+
throw new InvalidArgumentError2({
|
|
5208
|
+
argument: "separator",
|
|
5209
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
5210
|
+
});
|
|
5211
|
+
}
|
|
5212
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
5213
|
+
};
|
|
5214
|
+
var generateId4 = createIdGenerator3();
|
|
5215
|
+
function isAbortError3(error) {
|
|
5216
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
5217
|
+
error.name === "TimeoutError");
|
|
5218
|
+
}
|
|
5219
|
+
var FETCH_FAILED_ERROR_MESSAGES3 = ["fetch failed", "failed to fetch"];
|
|
5220
|
+
function handleFetchError3({
|
|
5221
|
+
error,
|
|
5222
|
+
url,
|
|
5223
|
+
requestBodyValues
|
|
5224
|
+
}) {
|
|
5225
|
+
if (isAbortError3(error)) {
|
|
5226
|
+
return error;
|
|
5227
|
+
}
|
|
5228
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES3.includes(error.message.toLowerCase())) {
|
|
5229
|
+
const cause = error.cause;
|
|
5230
|
+
if (cause != null) {
|
|
5231
|
+
return new APICallError2({
|
|
5232
|
+
message: `Cannot connect to API: ${cause.message}`,
|
|
5233
|
+
cause,
|
|
5234
|
+
url,
|
|
5235
|
+
requestBodyValues,
|
|
5236
|
+
isRetryable: true
|
|
5237
|
+
// retry when network error
|
|
5238
|
+
});
|
|
5239
|
+
}
|
|
5240
|
+
}
|
|
5241
|
+
return error;
|
|
5242
|
+
}
|
|
5243
|
+
function removeUndefinedEntries2(record) {
|
|
5244
|
+
return Object.fromEntries(
|
|
5245
|
+
Object.entries(record).filter(([_key, value]) => value != null)
|
|
5246
|
+
);
|
|
5247
|
+
}
|
|
5248
|
+
function loadApiKey4({
|
|
5249
|
+
apiKey,
|
|
5250
|
+
environmentVariableName,
|
|
5251
|
+
apiKeyParameterName = "apiKey",
|
|
5252
|
+
description
|
|
5253
|
+
}) {
|
|
5254
|
+
if (typeof apiKey === "string") {
|
|
5255
|
+
return apiKey;
|
|
5256
|
+
}
|
|
5257
|
+
if (apiKey != null) {
|
|
5258
|
+
throw new LoadAPIKeyError2({
|
|
5259
|
+
message: `${description} API key must be a string.`
|
|
5260
|
+
});
|
|
5261
|
+
}
|
|
5262
|
+
if (typeof process === "undefined") {
|
|
5263
|
+
throw new LoadAPIKeyError2({
|
|
5264
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
5265
|
+
});
|
|
5266
|
+
}
|
|
5267
|
+
apiKey = process.env[environmentVariableName];
|
|
5268
|
+
if (apiKey == null) {
|
|
5269
|
+
throw new LoadAPIKeyError2({
|
|
5270
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
5271
|
+
});
|
|
5272
|
+
}
|
|
5273
|
+
if (typeof apiKey !== "string") {
|
|
5274
|
+
throw new LoadAPIKeyError2({
|
|
5275
|
+
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
5276
|
+
});
|
|
5277
|
+
}
|
|
5278
|
+
return apiKey;
|
|
5279
|
+
}
|
|
5280
|
+
var suspectProtoRx3 = /"__proto__"\s*:/;
|
|
5281
|
+
var suspectConstructorRx3 = /"constructor"\s*:/;
|
|
5282
|
+
function _parse3(text) {
|
|
5283
|
+
const obj = JSON.parse(text);
|
|
5284
|
+
if (obj === null || typeof obj !== "object") {
|
|
5285
|
+
return obj;
|
|
5286
|
+
}
|
|
5287
|
+
if (suspectProtoRx3.test(text) === false && suspectConstructorRx3.test(text) === false) {
|
|
5288
|
+
return obj;
|
|
5289
|
+
}
|
|
5290
|
+
return filter3(obj);
|
|
5291
|
+
}
|
|
5292
|
+
function filter3(obj) {
|
|
5293
|
+
let next = [obj];
|
|
5294
|
+
while (next.length) {
|
|
5295
|
+
const nodes = next;
|
|
5296
|
+
next = [];
|
|
5297
|
+
for (const node of nodes) {
|
|
5298
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
5299
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
5300
|
+
}
|
|
5301
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
5302
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
5303
|
+
}
|
|
5304
|
+
for (const key in node) {
|
|
5305
|
+
const value = node[key];
|
|
5306
|
+
if (value && typeof value === "object") {
|
|
5307
|
+
next.push(value);
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
}
|
|
5312
|
+
return obj;
|
|
5313
|
+
}
|
|
5314
|
+
function secureJsonParse3(text) {
|
|
5315
|
+
const { stackTraceLimit } = Error;
|
|
5316
|
+
Error.stackTraceLimit = 0;
|
|
5317
|
+
try {
|
|
5318
|
+
return _parse3(text);
|
|
5319
|
+
} finally {
|
|
5320
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
5321
|
+
}
|
|
5322
|
+
}
|
|
5323
|
+
var validatorSymbol3 = Symbol.for("vercel.ai.validator");
|
|
5324
|
+
function validator3(validate) {
|
|
5325
|
+
return { [validatorSymbol3]: true, validate };
|
|
5326
|
+
}
|
|
5327
|
+
function isValidator3(value) {
|
|
5328
|
+
return typeof value === "object" && value !== null && validatorSymbol3 in value && value[validatorSymbol3] === true && "validate" in value;
|
|
5329
|
+
}
|
|
5330
|
+
function asValidator3(value) {
|
|
5331
|
+
return isValidator3(value) ? value : standardSchemaValidator3(value);
|
|
5332
|
+
}
|
|
5333
|
+
function standardSchemaValidator3(standardSchema) {
|
|
5334
|
+
return validator3(async (value) => {
|
|
5335
|
+
const result = await standardSchema["~standard"].validate(value);
|
|
5336
|
+
return result.issues == null ? { success: true, value: result.value } : {
|
|
5337
|
+
success: false,
|
|
5338
|
+
error: new TypeValidationError2({
|
|
5339
|
+
value,
|
|
5340
|
+
cause: result.issues
|
|
5341
|
+
})
|
|
5342
|
+
};
|
|
5343
|
+
});
|
|
5344
|
+
}
|
|
5345
|
+
async function validateTypes3({
|
|
5346
|
+
value,
|
|
5347
|
+
schema
|
|
5348
|
+
}) {
|
|
5349
|
+
const result = await safeValidateTypes3({ value, schema });
|
|
5350
|
+
if (!result.success) {
|
|
5351
|
+
throw TypeValidationError2.wrap({ value, cause: result.error });
|
|
5352
|
+
}
|
|
5353
|
+
return result.value;
|
|
5354
|
+
}
|
|
5355
|
+
async function safeValidateTypes3({
|
|
5356
|
+
value,
|
|
5357
|
+
schema
|
|
5358
|
+
}) {
|
|
5359
|
+
const validator22 = asValidator3(schema);
|
|
5360
|
+
try {
|
|
5361
|
+
if (validator22.validate == null) {
|
|
5362
|
+
return { success: true, value, rawValue: value };
|
|
5363
|
+
}
|
|
5364
|
+
const result = await validator22.validate(value);
|
|
5365
|
+
if (result.success) {
|
|
5366
|
+
return { success: true, value: result.value, rawValue: value };
|
|
5367
|
+
}
|
|
5368
|
+
return {
|
|
5369
|
+
success: false,
|
|
5370
|
+
error: TypeValidationError2.wrap({ value, cause: result.error }),
|
|
5371
|
+
rawValue: value
|
|
5372
|
+
};
|
|
5373
|
+
} catch (error) {
|
|
5374
|
+
return {
|
|
5375
|
+
success: false,
|
|
5376
|
+
error: TypeValidationError2.wrap({ value, cause: error }),
|
|
5377
|
+
rawValue: value
|
|
5378
|
+
};
|
|
5379
|
+
}
|
|
5380
|
+
}
|
|
5381
|
+
async function parseJSON3({
|
|
5382
|
+
text,
|
|
5383
|
+
schema
|
|
5384
|
+
}) {
|
|
5385
|
+
try {
|
|
5386
|
+
const value = secureJsonParse3(text);
|
|
5387
|
+
if (schema == null) {
|
|
5388
|
+
return value;
|
|
5389
|
+
}
|
|
5390
|
+
return validateTypes3({ value, schema });
|
|
5391
|
+
} catch (error) {
|
|
5392
|
+
if (JSONParseError2.isInstance(error) || TypeValidationError2.isInstance(error)) {
|
|
5393
|
+
throw error;
|
|
5394
|
+
}
|
|
5395
|
+
throw new JSONParseError2({ text, cause: error });
|
|
5396
|
+
}
|
|
5397
|
+
}
|
|
5398
|
+
async function safeParseJSON3({
|
|
5399
|
+
text,
|
|
5400
|
+
schema
|
|
5401
|
+
}) {
|
|
5402
|
+
try {
|
|
5403
|
+
const value = secureJsonParse3(text);
|
|
5404
|
+
if (schema == null) {
|
|
5405
|
+
return { success: true, value, rawValue: value };
|
|
5406
|
+
}
|
|
5407
|
+
return await safeValidateTypes3({ value, schema });
|
|
5408
|
+
} catch (error) {
|
|
5409
|
+
return {
|
|
5410
|
+
success: false,
|
|
5411
|
+
error: JSONParseError2.isInstance(error) ? error : new JSONParseError2({ text, cause: error }),
|
|
5412
|
+
rawValue: void 0
|
|
5413
|
+
};
|
|
5414
|
+
}
|
|
5415
|
+
}
|
|
5416
|
+
function isParsableJson2(input) {
|
|
5417
|
+
try {
|
|
5418
|
+
secureJsonParse3(input);
|
|
5419
|
+
return true;
|
|
5420
|
+
} catch (e) {
|
|
5421
|
+
return false;
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
function parseJsonEventStream3({
|
|
5425
|
+
stream,
|
|
5426
|
+
schema
|
|
5427
|
+
}) {
|
|
5428
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2()).pipeThrough(
|
|
5429
|
+
new TransformStream({
|
|
5430
|
+
async transform({ data }, controller) {
|
|
5431
|
+
if (data === "[DONE]") {
|
|
5432
|
+
return;
|
|
5433
|
+
}
|
|
5434
|
+
controller.enqueue(await safeParseJSON3({ text: data, schema }));
|
|
5435
|
+
}
|
|
5436
|
+
})
|
|
5437
|
+
);
|
|
5438
|
+
}
|
|
5439
|
+
var getOriginalFetch23 = () => globalThis.fetch;
|
|
5440
|
+
var postJsonToApi4 = async ({
|
|
5441
|
+
url,
|
|
5442
|
+
headers,
|
|
5443
|
+
body,
|
|
5444
|
+
failedResponseHandler,
|
|
5445
|
+
successfulResponseHandler,
|
|
5446
|
+
abortSignal,
|
|
5447
|
+
fetch: fetch2
|
|
5448
|
+
}) => postToApi3({
|
|
5449
|
+
url,
|
|
5450
|
+
headers: __spreadValues({
|
|
5451
|
+
"Content-Type": "application/json"
|
|
5452
|
+
}, headers),
|
|
5453
|
+
body: {
|
|
5454
|
+
content: JSON.stringify(body),
|
|
5455
|
+
values: body
|
|
5456
|
+
},
|
|
5457
|
+
failedResponseHandler,
|
|
5458
|
+
successfulResponseHandler,
|
|
5459
|
+
abortSignal,
|
|
5460
|
+
fetch: fetch2
|
|
5461
|
+
});
|
|
5462
|
+
var postToApi3 = async ({
|
|
5463
|
+
url,
|
|
5464
|
+
headers = {},
|
|
5465
|
+
body,
|
|
5466
|
+
successfulResponseHandler,
|
|
5467
|
+
failedResponseHandler,
|
|
5468
|
+
abortSignal,
|
|
5469
|
+
fetch: fetch2 = getOriginalFetch23()
|
|
5470
|
+
}) => {
|
|
5471
|
+
try {
|
|
5472
|
+
const response = await fetch2(url, {
|
|
5473
|
+
method: "POST",
|
|
5474
|
+
headers: removeUndefinedEntries2(headers),
|
|
5475
|
+
body: body.content,
|
|
5476
|
+
signal: abortSignal
|
|
5477
|
+
});
|
|
5478
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5479
|
+
if (!response.ok) {
|
|
5480
|
+
let errorInformation;
|
|
5481
|
+
try {
|
|
5482
|
+
errorInformation = await failedResponseHandler({
|
|
5483
|
+
response,
|
|
5484
|
+
url,
|
|
5485
|
+
requestBodyValues: body.values
|
|
5486
|
+
});
|
|
5487
|
+
} catch (error) {
|
|
5488
|
+
if (isAbortError3(error) || APICallError2.isInstance(error)) {
|
|
5489
|
+
throw error;
|
|
5490
|
+
}
|
|
5491
|
+
throw new APICallError2({
|
|
5492
|
+
message: "Failed to process error response",
|
|
5493
|
+
cause: error,
|
|
5494
|
+
statusCode: response.status,
|
|
5495
|
+
url,
|
|
5496
|
+
responseHeaders,
|
|
5497
|
+
requestBodyValues: body.values
|
|
5498
|
+
});
|
|
5499
|
+
}
|
|
5500
|
+
throw errorInformation.value;
|
|
5501
|
+
}
|
|
5502
|
+
try {
|
|
5503
|
+
return await successfulResponseHandler({
|
|
5504
|
+
response,
|
|
5505
|
+
url,
|
|
5506
|
+
requestBodyValues: body.values
|
|
5507
|
+
});
|
|
5508
|
+
} catch (error) {
|
|
5509
|
+
if (error instanceof Error) {
|
|
5510
|
+
if (isAbortError3(error) || APICallError2.isInstance(error)) {
|
|
5511
|
+
throw error;
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
throw new APICallError2({
|
|
5515
|
+
message: "Failed to process successful response",
|
|
5516
|
+
cause: error,
|
|
5517
|
+
statusCode: response.status,
|
|
5518
|
+
url,
|
|
5519
|
+
responseHeaders,
|
|
5520
|
+
requestBodyValues: body.values
|
|
5521
|
+
});
|
|
5522
|
+
}
|
|
5523
|
+
} catch (error) {
|
|
5524
|
+
throw handleFetchError3({ error, url, requestBodyValues: body.values });
|
|
5525
|
+
}
|
|
5526
|
+
};
|
|
5527
|
+
var createJsonErrorResponseHandler4 = ({
|
|
5528
|
+
errorSchema,
|
|
5529
|
+
errorToMessage: errorToMessage2,
|
|
5530
|
+
isRetryable
|
|
5531
|
+
}) => async ({ response, url, requestBodyValues }) => {
|
|
5532
|
+
const responseBody = await response.text();
|
|
5533
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5534
|
+
if (responseBody.trim() === "") {
|
|
5535
|
+
return {
|
|
5536
|
+
responseHeaders,
|
|
5537
|
+
value: new APICallError2({
|
|
5538
|
+
message: response.statusText,
|
|
5539
|
+
url,
|
|
5540
|
+
requestBodyValues,
|
|
5541
|
+
statusCode: response.status,
|
|
5542
|
+
responseHeaders,
|
|
5543
|
+
responseBody,
|
|
5544
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
5545
|
+
})
|
|
5546
|
+
};
|
|
5547
|
+
}
|
|
5548
|
+
try {
|
|
5549
|
+
const parsedError = await parseJSON3({
|
|
5550
|
+
text: responseBody,
|
|
5551
|
+
schema: errorSchema
|
|
5552
|
+
});
|
|
5553
|
+
return {
|
|
5554
|
+
responseHeaders,
|
|
5555
|
+
value: new APICallError2({
|
|
5556
|
+
message: errorToMessage2(parsedError),
|
|
5557
|
+
url,
|
|
5558
|
+
requestBodyValues,
|
|
5559
|
+
statusCode: response.status,
|
|
5560
|
+
responseHeaders,
|
|
5561
|
+
responseBody,
|
|
5562
|
+
data: parsedError,
|
|
5563
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
5564
|
+
})
|
|
5565
|
+
};
|
|
5566
|
+
} catch (parseError) {
|
|
5567
|
+
return {
|
|
5568
|
+
responseHeaders,
|
|
5569
|
+
value: new APICallError2({
|
|
5570
|
+
message: response.statusText,
|
|
5571
|
+
url,
|
|
5572
|
+
requestBodyValues,
|
|
5573
|
+
statusCode: response.status,
|
|
5574
|
+
responseHeaders,
|
|
5575
|
+
responseBody,
|
|
5576
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
5577
|
+
})
|
|
5578
|
+
};
|
|
5579
|
+
}
|
|
5580
|
+
};
|
|
5581
|
+
var createEventSourceResponseHandler4 = (chunkSchema) => async ({ response }) => {
|
|
5582
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5583
|
+
if (response.body == null) {
|
|
5584
|
+
throw new EmptyResponseBodyError2({});
|
|
5585
|
+
}
|
|
5586
|
+
return {
|
|
5587
|
+
responseHeaders,
|
|
5588
|
+
value: parseJsonEventStream3({
|
|
5589
|
+
stream: response.body,
|
|
5590
|
+
schema: chunkSchema
|
|
5591
|
+
})
|
|
5592
|
+
};
|
|
5593
|
+
};
|
|
5594
|
+
var createJsonResponseHandler4 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
5595
|
+
const responseBody = await response.text();
|
|
5596
|
+
const parsedResult = await safeParseJSON3({
|
|
5597
|
+
text: responseBody,
|
|
5598
|
+
schema: responseSchema
|
|
5599
|
+
});
|
|
5600
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
5601
|
+
if (!parsedResult.success) {
|
|
5602
|
+
throw new APICallError2({
|
|
5603
|
+
message: "Invalid JSON response",
|
|
5604
|
+
cause: parsedResult.error,
|
|
5605
|
+
statusCode: response.status,
|
|
5606
|
+
responseHeaders,
|
|
5607
|
+
responseBody,
|
|
5608
|
+
url,
|
|
5609
|
+
requestBodyValues
|
|
5610
|
+
});
|
|
5611
|
+
}
|
|
5612
|
+
return {
|
|
5613
|
+
responseHeaders,
|
|
5614
|
+
value: parsedResult.value,
|
|
5615
|
+
rawValue: parsedResult.rawValue
|
|
5616
|
+
};
|
|
5617
|
+
};
|
|
5618
|
+
var { btoa: btoa3} = globalThis;
|
|
5619
|
+
function convertUint8ArrayToBase642(array) {
|
|
5620
|
+
let latin1string = "";
|
|
5621
|
+
for (let i = 0; i < array.length; i++) {
|
|
5622
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
5623
|
+
}
|
|
5624
|
+
return btoa3(latin1string);
|
|
5625
|
+
}
|
|
5626
|
+
function withoutTrailingSlash4(url) {
|
|
5627
|
+
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
5628
|
+
}
|
|
5629
|
+
function isDefinedOrNotNull(value) {
|
|
5630
|
+
return value !== null && value !== void 0;
|
|
5631
|
+
}
|
|
5632
|
+
var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
5633
|
+
ReasoningFormat2["Unknown"] = "unknown";
|
|
5634
|
+
ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
|
|
5635
|
+
ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
|
|
5636
|
+
ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
|
|
5637
|
+
return ReasoningFormat2;
|
|
5638
|
+
})(ReasoningFormat || {});
|
|
5639
|
+
var CommonReasoningDetailSchema = z.object({
|
|
5640
|
+
id: z.string().nullish(),
|
|
5641
|
+
format: z.nativeEnum(ReasoningFormat).nullish(),
|
|
5642
|
+
index: z.number().optional()
|
|
5643
|
+
}).passthrough();
|
|
5644
|
+
var ReasoningDetailSummarySchema = z.object({
|
|
5645
|
+
type: z.literal(
|
|
5646
|
+
"reasoning.summary"
|
|
5647
|
+
/* Summary */
|
|
5648
|
+
),
|
|
5649
|
+
summary: z.string()
|
|
5650
|
+
}).extend(CommonReasoningDetailSchema.shape);
|
|
5651
|
+
var ReasoningDetailEncryptedSchema = z.object({
|
|
5652
|
+
type: z.literal(
|
|
5653
|
+
"reasoning.encrypted"
|
|
5654
|
+
/* Encrypted */
|
|
5655
|
+
),
|
|
5656
|
+
data: z.string()
|
|
5657
|
+
}).extend(CommonReasoningDetailSchema.shape);
|
|
5658
|
+
var ReasoningDetailTextSchema = z.object({
|
|
5659
|
+
type: z.literal(
|
|
5660
|
+
"reasoning.text"
|
|
5661
|
+
/* Text */
|
|
5662
|
+
),
|
|
5663
|
+
text: z.string().nullish(),
|
|
5664
|
+
signature: z.string().nullish()
|
|
5665
|
+
}).extend(CommonReasoningDetailSchema.shape);
|
|
5666
|
+
var ReasoningDetailUnionSchema = z.union([
|
|
5667
|
+
ReasoningDetailSummarySchema,
|
|
5668
|
+
ReasoningDetailEncryptedSchema,
|
|
5669
|
+
ReasoningDetailTextSchema
|
|
5670
|
+
]);
|
|
5671
|
+
var ReasoningDetailsWithUnknownSchema = z.union([
|
|
5672
|
+
ReasoningDetailUnionSchema,
|
|
5673
|
+
z.unknown().transform(() => null)
|
|
5674
|
+
]);
|
|
5675
|
+
var ReasoningDetailArraySchema = z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
5676
|
+
z.union([
|
|
5677
|
+
z.object({
|
|
5678
|
+
delta: z.object({
|
|
5679
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
5680
|
+
})
|
|
5681
|
+
}).transform(
|
|
5682
|
+
(data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
|
|
5683
|
+
),
|
|
5684
|
+
z.object({
|
|
5685
|
+
message: z.object({
|
|
5686
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
5687
|
+
})
|
|
5688
|
+
}).transform(
|
|
5689
|
+
(data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
|
|
5690
|
+
),
|
|
5691
|
+
z.object({
|
|
5692
|
+
text: z.string(),
|
|
5693
|
+
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
5694
|
+
}).transform((data) => data.reasoning_details.filter(isDefinedOrNotNull))
|
|
5695
|
+
]);
|
|
5696
|
+
var OpenRouterErrorResponseSchema = z.object({
|
|
5697
|
+
error: z.object({
|
|
5698
|
+
code: z.union([z.string(), z.number()]).nullable().optional().default(null),
|
|
5699
|
+
message: z.string(),
|
|
5700
|
+
type: z.string().nullable().optional().default(null),
|
|
5701
|
+
param: z.any().nullable().optional().default(null)
|
|
5702
|
+
}).passthrough()
|
|
5703
|
+
}).passthrough();
|
|
5704
|
+
var openrouterFailedResponseHandler = createJsonErrorResponseHandler4({
|
|
5705
|
+
errorSchema: OpenRouterErrorResponseSchema,
|
|
5706
|
+
errorToMessage: (data) => data.error.message
|
|
5707
|
+
});
|
|
5708
|
+
var OpenRouterProviderMetadataSchema = z.object({
|
|
5709
|
+
provider: z.string(),
|
|
5710
|
+
reasoning_details: z.array(ReasoningDetailUnionSchema).optional(),
|
|
5711
|
+
usage: z.object({
|
|
5712
|
+
promptTokens: z.number(),
|
|
5713
|
+
promptTokensDetails: z.object({
|
|
5714
|
+
cachedTokens: z.number()
|
|
5715
|
+
}).passthrough().optional(),
|
|
5716
|
+
completionTokens: z.number(),
|
|
5717
|
+
completionTokensDetails: z.object({
|
|
5718
|
+
reasoningTokens: z.number()
|
|
5719
|
+
}).passthrough().optional(),
|
|
5720
|
+
totalTokens: z.number(),
|
|
5721
|
+
cost: z.number().optional(),
|
|
5722
|
+
costDetails: z.object({
|
|
5723
|
+
upstreamInferenceCost: z.number()
|
|
5724
|
+
}).passthrough()
|
|
5725
|
+
}).passthrough()
|
|
5726
|
+
}).passthrough();
|
|
5727
|
+
var OpenRouterProviderOptionsSchema = z.object({
|
|
5728
|
+
openrouter: z.object({
|
|
5729
|
+
reasoning_details: z.array(ReasoningDetailUnionSchema).optional()
|
|
5730
|
+
}).optional()
|
|
5731
|
+
}).optional();
|
|
5732
|
+
function mapOpenRouterFinishReason(finishReason) {
|
|
5733
|
+
switch (finishReason) {
|
|
5734
|
+
case "stop":
|
|
5735
|
+
return "stop";
|
|
5736
|
+
case "length":
|
|
5737
|
+
return "length";
|
|
5738
|
+
case "content_filter":
|
|
5739
|
+
return "content-filter";
|
|
5740
|
+
case "function_call":
|
|
5741
|
+
case "tool_calls":
|
|
5742
|
+
return "tool-calls";
|
|
5743
|
+
default:
|
|
5744
|
+
return "unknown";
|
|
5745
|
+
}
|
|
5746
|
+
}
|
|
5747
|
+
function isUrl({
|
|
5748
|
+
url,
|
|
5749
|
+
protocols
|
|
5750
|
+
}) {
|
|
5751
|
+
try {
|
|
5752
|
+
const urlObj = new URL(url);
|
|
5753
|
+
return protocols.has(urlObj.protocol);
|
|
5754
|
+
} catch (_) {
|
|
5755
|
+
return false;
|
|
5756
|
+
}
|
|
5757
|
+
}
|
|
5758
|
+
function getFileUrl({
|
|
5759
|
+
part,
|
|
5760
|
+
defaultMediaType
|
|
5761
|
+
}) {
|
|
5762
|
+
var _a15, _b;
|
|
5763
|
+
if (part.data instanceof Uint8Array) {
|
|
5764
|
+
const base64 = convertUint8ArrayToBase642(part.data);
|
|
5765
|
+
return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
|
|
5766
|
+
}
|
|
5767
|
+
const stringUrl = part.data.toString();
|
|
5768
|
+
if (isUrl({
|
|
5769
|
+
url: stringUrl,
|
|
5770
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
5771
|
+
})) {
|
|
5772
|
+
return stringUrl;
|
|
5773
|
+
}
|
|
5774
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
5775
|
+
}
|
|
5776
|
+
function getMediaType(dataUrl, defaultMediaType) {
|
|
5777
|
+
var _a15;
|
|
5778
|
+
const match = dataUrl.match(/^data:([^;]+)/);
|
|
5779
|
+
return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
|
|
5780
|
+
}
|
|
5781
|
+
function getBase64FromDataUrl(dataUrl) {
|
|
5782
|
+
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
5783
|
+
return match ? match[1] : dataUrl;
|
|
5784
|
+
}
|
|
5785
|
+
function getCacheControl(providerMetadata) {
|
|
5786
|
+
var _a15, _b, _c;
|
|
5787
|
+
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
5788
|
+
const openrouter2 = providerMetadata == null ? void 0 : providerMetadata.openrouter;
|
|
5789
|
+
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;
|
|
5790
|
+
}
|
|
5791
|
+
function convertToOpenRouterChatMessages(prompt) {
|
|
5792
|
+
var _a15, _b, _c, _d, _e;
|
|
5793
|
+
const messages = [];
|
|
5794
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
5795
|
+
switch (role) {
|
|
5796
|
+
case "system": {
|
|
5797
|
+
messages.push({
|
|
5798
|
+
role: "system",
|
|
5799
|
+
content,
|
|
5800
|
+
cache_control: getCacheControl(providerOptions)
|
|
5801
|
+
});
|
|
5802
|
+
break;
|
|
5803
|
+
}
|
|
5804
|
+
case "user": {
|
|
5805
|
+
if (content.length === 1 && ((_a15 = content[0]) == null ? void 0 : _a15.type) === "text") {
|
|
5806
|
+
const cacheControl = (_b = getCacheControl(providerOptions)) != null ? _b : getCacheControl(content[0].providerOptions);
|
|
5807
|
+
const contentWithCacheControl = cacheControl ? [
|
|
5808
|
+
{
|
|
5809
|
+
type: "text",
|
|
5810
|
+
text: content[0].text,
|
|
5811
|
+
cache_control: cacheControl
|
|
5812
|
+
}
|
|
5813
|
+
] : content[0].text;
|
|
5814
|
+
messages.push({
|
|
5815
|
+
role: "user",
|
|
5816
|
+
content: contentWithCacheControl
|
|
5817
|
+
});
|
|
5818
|
+
break;
|
|
5819
|
+
}
|
|
5820
|
+
const messageCacheControl = getCacheControl(providerOptions);
|
|
5821
|
+
const contentParts = content.map(
|
|
5822
|
+
(part) => {
|
|
5823
|
+
var _a16, _b2, _c2, _d2, _e2, _f;
|
|
5824
|
+
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
5825
|
+
switch (part.type) {
|
|
5826
|
+
case "text":
|
|
5827
|
+
return {
|
|
5828
|
+
type: "text",
|
|
5829
|
+
text: part.text,
|
|
5830
|
+
// For text parts, only use part-specific cache control
|
|
5831
|
+
cache_control: cacheControl
|
|
5832
|
+
};
|
|
5833
|
+
case "file": {
|
|
5834
|
+
if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
|
|
5835
|
+
const url = getFileUrl({
|
|
5836
|
+
part,
|
|
5837
|
+
defaultMediaType: "image/jpeg"
|
|
5838
|
+
});
|
|
5839
|
+
return {
|
|
5840
|
+
type: "image_url",
|
|
5841
|
+
image_url: {
|
|
5842
|
+
url
|
|
5843
|
+
},
|
|
5844
|
+
// For image parts, use part-specific or message-level cache control
|
|
5845
|
+
cache_control: cacheControl
|
|
5846
|
+
};
|
|
5847
|
+
}
|
|
5848
|
+
const fileName = String(
|
|
5849
|
+
(_f = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f : ""
|
|
5850
|
+
);
|
|
5851
|
+
const fileData = getFileUrl({
|
|
5852
|
+
part,
|
|
5853
|
+
defaultMediaType: "application/pdf"
|
|
5854
|
+
});
|
|
5855
|
+
if (isUrl({
|
|
5856
|
+
url: fileData,
|
|
5857
|
+
protocols: /* @__PURE__ */ new Set(["http:", "https:"])
|
|
5858
|
+
})) {
|
|
5859
|
+
return {
|
|
5860
|
+
type: "file",
|
|
5861
|
+
file: {
|
|
5862
|
+
filename: fileName,
|
|
5863
|
+
file_data: fileData
|
|
5864
|
+
}
|
|
5865
|
+
};
|
|
5866
|
+
}
|
|
5867
|
+
return {
|
|
5868
|
+
type: "file",
|
|
5869
|
+
file: {
|
|
5870
|
+
filename: fileName,
|
|
5871
|
+
file_data: fileData
|
|
5872
|
+
},
|
|
5873
|
+
cache_control: cacheControl
|
|
5874
|
+
};
|
|
5875
|
+
}
|
|
5876
|
+
default: {
|
|
5877
|
+
return {
|
|
5878
|
+
type: "text",
|
|
5879
|
+
text: "",
|
|
5880
|
+
cache_control: cacheControl
|
|
5881
|
+
};
|
|
5882
|
+
}
|
|
5883
|
+
}
|
|
5884
|
+
}
|
|
5885
|
+
);
|
|
5886
|
+
messages.push({
|
|
5887
|
+
role: "user",
|
|
5888
|
+
content: contentParts
|
|
5889
|
+
});
|
|
5890
|
+
break;
|
|
5891
|
+
}
|
|
5892
|
+
case "assistant": {
|
|
5893
|
+
let text = "";
|
|
5894
|
+
let reasoning = "";
|
|
5895
|
+
const toolCalls = [];
|
|
5896
|
+
for (const part of content) {
|
|
5897
|
+
switch (part.type) {
|
|
5898
|
+
case "text": {
|
|
5899
|
+
text += part.text;
|
|
5900
|
+
break;
|
|
5901
|
+
}
|
|
5902
|
+
case "tool-call": {
|
|
5903
|
+
toolCalls.push({
|
|
5904
|
+
id: part.toolCallId,
|
|
5905
|
+
type: "function",
|
|
5906
|
+
function: {
|
|
5907
|
+
name: part.toolName,
|
|
5908
|
+
arguments: JSON.stringify(part.input)
|
|
5909
|
+
}
|
|
5910
|
+
});
|
|
5911
|
+
break;
|
|
5912
|
+
}
|
|
5913
|
+
case "reasoning": {
|
|
5914
|
+
reasoning += part.text;
|
|
5915
|
+
break;
|
|
5916
|
+
}
|
|
5917
|
+
}
|
|
5918
|
+
}
|
|
5919
|
+
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
5920
|
+
const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
|
|
5921
|
+
messages.push({
|
|
5922
|
+
role: "assistant",
|
|
5923
|
+
content: text,
|
|
5924
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
5925
|
+
reasoning: reasoning || void 0,
|
|
5926
|
+
// Only include reasoning_details if we have the preserved original version
|
|
5927
|
+
reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
|
|
5928
|
+
cache_control: getCacheControl(providerOptions)
|
|
5929
|
+
});
|
|
5930
|
+
break;
|
|
5931
|
+
}
|
|
5932
|
+
case "tool": {
|
|
5933
|
+
for (const toolResponse of content) {
|
|
5934
|
+
const content2 = getToolResultContent(toolResponse);
|
|
5935
|
+
messages.push({
|
|
5936
|
+
role: "tool",
|
|
5937
|
+
tool_call_id: toolResponse.toolCallId,
|
|
5938
|
+
content: content2,
|
|
5939
|
+
cache_control: (_e = getCacheControl(providerOptions)) != null ? _e : getCacheControl(toolResponse.providerOptions)
|
|
5940
|
+
});
|
|
5941
|
+
}
|
|
5942
|
+
break;
|
|
5943
|
+
}
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
return messages;
|
|
5947
|
+
}
|
|
5948
|
+
function getToolResultContent(input) {
|
|
5949
|
+
return input.output.type === "text" ? input.output.value : JSON.stringify(input.output.value);
|
|
5950
|
+
}
|
|
5951
|
+
z.union([
|
|
5952
|
+
z.literal("auto"),
|
|
5953
|
+
z.literal("none"),
|
|
5954
|
+
z.literal("required"),
|
|
5955
|
+
z.object({
|
|
5956
|
+
type: z.literal("function"),
|
|
5957
|
+
function: z.object({
|
|
5958
|
+
name: z.string()
|
|
5959
|
+
})
|
|
5960
|
+
})
|
|
5961
|
+
]);
|
|
5962
|
+
function getChatCompletionToolChoice(toolChoice) {
|
|
5963
|
+
switch (toolChoice.type) {
|
|
5964
|
+
case "auto":
|
|
5965
|
+
case "none":
|
|
5966
|
+
case "required":
|
|
5967
|
+
return toolChoice.type;
|
|
5968
|
+
case "tool": {
|
|
5969
|
+
return {
|
|
5970
|
+
type: "function",
|
|
5971
|
+
function: { name: toolChoice.toolName }
|
|
5972
|
+
};
|
|
5973
|
+
}
|
|
5974
|
+
default: {
|
|
5975
|
+
throw new InvalidArgumentError2({
|
|
5976
|
+
argument: "toolChoice",
|
|
5977
|
+
message: `Invalid tool choice type: ${JSON.stringify(toolChoice)}`
|
|
5978
|
+
});
|
|
5979
|
+
}
|
|
5980
|
+
}
|
|
5981
|
+
}
|
|
5982
|
+
var ImageResponseSchema = z.object({
|
|
5983
|
+
type: z.literal("image_url"),
|
|
5984
|
+
image_url: z.object({
|
|
5985
|
+
url: z.string()
|
|
5986
|
+
}).passthrough()
|
|
5987
|
+
}).passthrough();
|
|
5988
|
+
var ImageResponseWithUnknownSchema = z.union([
|
|
5989
|
+
ImageResponseSchema,
|
|
5990
|
+
z.unknown().transform(() => null)
|
|
5991
|
+
]);
|
|
5992
|
+
var ImageResponseArraySchema = z.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
5993
|
+
var OpenRouterChatCompletionBaseResponseSchema = z.object({
|
|
5994
|
+
id: z.string().optional(),
|
|
5995
|
+
model: z.string().optional(),
|
|
5996
|
+
provider: z.string().optional(),
|
|
5997
|
+
usage: z.object({
|
|
5998
|
+
prompt_tokens: z.number(),
|
|
5999
|
+
prompt_tokens_details: z.object({
|
|
6000
|
+
cached_tokens: z.number()
|
|
6001
|
+
}).passthrough().nullish(),
|
|
6002
|
+
completion_tokens: z.number(),
|
|
6003
|
+
completion_tokens_details: z.object({
|
|
6004
|
+
reasoning_tokens: z.number()
|
|
6005
|
+
}).passthrough().nullish(),
|
|
6006
|
+
total_tokens: z.number(),
|
|
6007
|
+
cost: z.number().optional(),
|
|
6008
|
+
cost_details: z.object({
|
|
6009
|
+
upstream_inference_cost: z.number().nullish()
|
|
6010
|
+
}).passthrough().nullish()
|
|
6011
|
+
}).passthrough().nullish()
|
|
6012
|
+
}).passthrough();
|
|
6013
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = z.union([
|
|
6014
|
+
// Success response with choices
|
|
6015
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
6016
|
+
choices: z.array(
|
|
6017
|
+
z.object({
|
|
6018
|
+
message: z.object({
|
|
6019
|
+
role: z.literal("assistant"),
|
|
6020
|
+
content: z.string().nullable().optional(),
|
|
6021
|
+
reasoning: z.string().nullable().optional(),
|
|
6022
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
6023
|
+
images: ImageResponseArraySchema.nullish(),
|
|
6024
|
+
tool_calls: z.array(
|
|
6025
|
+
z.object({
|
|
6026
|
+
id: z.string().optional().nullable(),
|
|
6027
|
+
type: z.literal("function"),
|
|
6028
|
+
function: z.object({
|
|
6029
|
+
name: z.string(),
|
|
6030
|
+
arguments: z.string()
|
|
6031
|
+
}).passthrough()
|
|
6032
|
+
}).passthrough()
|
|
6033
|
+
).optional(),
|
|
6034
|
+
annotations: z.array(
|
|
6035
|
+
z.union([
|
|
6036
|
+
// URL citation from web search
|
|
6037
|
+
z.object({
|
|
6038
|
+
type: z.literal("url_citation"),
|
|
6039
|
+
url_citation: z.object({
|
|
6040
|
+
end_index: z.number(),
|
|
6041
|
+
start_index: z.number(),
|
|
6042
|
+
title: z.string(),
|
|
6043
|
+
url: z.string(),
|
|
6044
|
+
content: z.string().optional()
|
|
6045
|
+
}).passthrough()
|
|
6046
|
+
}).passthrough(),
|
|
6047
|
+
// File annotation from FileParserPlugin (old format)
|
|
6048
|
+
z.object({
|
|
6049
|
+
type: z.literal("file_annotation"),
|
|
6050
|
+
file_annotation: z.object({
|
|
6051
|
+
file_id: z.string(),
|
|
6052
|
+
quote: z.string().optional()
|
|
6053
|
+
}).passthrough()
|
|
6054
|
+
}).passthrough(),
|
|
6055
|
+
// File annotation from FileParserPlugin (new format)
|
|
6056
|
+
z.object({
|
|
6057
|
+
type: z.literal("file"),
|
|
6058
|
+
file: z.object({
|
|
6059
|
+
hash: z.string(),
|
|
6060
|
+
name: z.string(),
|
|
6061
|
+
content: z.array(
|
|
6062
|
+
z.object({
|
|
6063
|
+
type: z.string(),
|
|
6064
|
+
text: z.string()
|
|
6065
|
+
}).passthrough()
|
|
6066
|
+
).optional()
|
|
6067
|
+
}).passthrough()
|
|
6068
|
+
}).passthrough()
|
|
6069
|
+
])
|
|
6070
|
+
).nullish()
|
|
6071
|
+
}).passthrough(),
|
|
6072
|
+
index: z.number().nullish(),
|
|
6073
|
+
logprobs: z.object({
|
|
6074
|
+
content: z.array(
|
|
6075
|
+
z.object({
|
|
6076
|
+
token: z.string(),
|
|
6077
|
+
logprob: z.number(),
|
|
6078
|
+
top_logprobs: z.array(
|
|
6079
|
+
z.object({
|
|
6080
|
+
token: z.string(),
|
|
6081
|
+
logprob: z.number()
|
|
6082
|
+
}).passthrough()
|
|
6083
|
+
)
|
|
6084
|
+
}).passthrough()
|
|
6085
|
+
).nullable()
|
|
6086
|
+
}).passthrough().nullable().optional(),
|
|
6087
|
+
finish_reason: z.string().optional().nullable()
|
|
6088
|
+
}).passthrough()
|
|
6089
|
+
)
|
|
6090
|
+
}),
|
|
6091
|
+
// Error response (HTTP 200 with error payload)
|
|
6092
|
+
OpenRouterErrorResponseSchema.extend({
|
|
6093
|
+
user_id: z.string().optional()
|
|
6094
|
+
})
|
|
6095
|
+
]);
|
|
6096
|
+
var OpenRouterStreamChatCompletionChunkSchema = z.union([
|
|
6097
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
6098
|
+
choices: z.array(
|
|
6099
|
+
z.object({
|
|
6100
|
+
delta: z.object({
|
|
6101
|
+
role: z.enum(["assistant"]).optional(),
|
|
6102
|
+
content: z.string().nullish(),
|
|
6103
|
+
reasoning: z.string().nullish().optional(),
|
|
6104
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
6105
|
+
images: ImageResponseArraySchema.nullish(),
|
|
6106
|
+
tool_calls: z.array(
|
|
6107
|
+
z.object({
|
|
6108
|
+
index: z.number().nullish(),
|
|
6109
|
+
id: z.string().nullish(),
|
|
6110
|
+
type: z.literal("function").optional(),
|
|
6111
|
+
function: z.object({
|
|
6112
|
+
name: z.string().nullish(),
|
|
6113
|
+
arguments: z.string().nullish()
|
|
6114
|
+
}).passthrough()
|
|
6115
|
+
}).passthrough()
|
|
6116
|
+
).nullish(),
|
|
6117
|
+
annotations: z.array(
|
|
6118
|
+
z.union([
|
|
6119
|
+
// URL citation from web search
|
|
6120
|
+
z.object({
|
|
6121
|
+
type: z.literal("url_citation"),
|
|
6122
|
+
url_citation: z.object({
|
|
6123
|
+
end_index: z.number(),
|
|
6124
|
+
start_index: z.number(),
|
|
6125
|
+
title: z.string(),
|
|
6126
|
+
url: z.string(),
|
|
6127
|
+
content: z.string().optional()
|
|
6128
|
+
}).passthrough()
|
|
6129
|
+
}).passthrough(),
|
|
6130
|
+
// File annotation from FileParserPlugin (old format)
|
|
6131
|
+
z.object({
|
|
6132
|
+
type: z.literal("file_annotation"),
|
|
6133
|
+
file_annotation: z.object({
|
|
6134
|
+
file_id: z.string(),
|
|
6135
|
+
quote: z.string().optional()
|
|
6136
|
+
}).passthrough()
|
|
6137
|
+
}).passthrough(),
|
|
6138
|
+
// File annotation from FileParserPlugin (new format)
|
|
6139
|
+
z.object({
|
|
6140
|
+
type: z.literal("file"),
|
|
6141
|
+
file: z.object({
|
|
6142
|
+
hash: z.string(),
|
|
6143
|
+
name: z.string(),
|
|
6144
|
+
content: z.array(
|
|
6145
|
+
z.object({
|
|
6146
|
+
type: z.string(),
|
|
6147
|
+
text: z.string()
|
|
6148
|
+
}).passthrough()
|
|
6149
|
+
).optional()
|
|
6150
|
+
}).passthrough()
|
|
6151
|
+
}).passthrough()
|
|
6152
|
+
])
|
|
6153
|
+
).nullish()
|
|
6154
|
+
}).passthrough().nullish(),
|
|
6155
|
+
logprobs: z.object({
|
|
6156
|
+
content: z.array(
|
|
6157
|
+
z.object({
|
|
6158
|
+
token: z.string(),
|
|
6159
|
+
logprob: z.number(),
|
|
6160
|
+
top_logprobs: z.array(
|
|
6161
|
+
z.object({
|
|
6162
|
+
token: z.string(),
|
|
6163
|
+
logprob: z.number()
|
|
6164
|
+
}).passthrough()
|
|
6165
|
+
)
|
|
6166
|
+
}).passthrough()
|
|
6167
|
+
).nullable()
|
|
6168
|
+
}).passthrough().nullish(),
|
|
6169
|
+
finish_reason: z.string().nullable().optional(),
|
|
6170
|
+
index: z.number().nullish()
|
|
6171
|
+
}).passthrough()
|
|
6172
|
+
)
|
|
6173
|
+
}),
|
|
6174
|
+
OpenRouterErrorResponseSchema
|
|
6175
|
+
]);
|
|
6176
|
+
var OpenRouterChatLanguageModel = class {
|
|
6177
|
+
constructor(modelId, settings, config) {
|
|
6178
|
+
this.specificationVersion = "v2";
|
|
6179
|
+
this.provider = "openrouter";
|
|
6180
|
+
this.defaultObjectGenerationMode = "tool";
|
|
6181
|
+
this.supportedUrls = {
|
|
6182
|
+
"image/*": [
|
|
6183
|
+
/^data:image\/[a-zA-Z]+;base64,/,
|
|
6184
|
+
/^https?:\/\/.+\.(jpg|jpeg|png|gif|webp)$/i
|
|
6185
|
+
],
|
|
6186
|
+
// 'text/*': [/^data:text\//, /^https?:\/\/.+$/],
|
|
6187
|
+
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
6188
|
+
};
|
|
6189
|
+
this.modelId = modelId;
|
|
6190
|
+
this.settings = settings;
|
|
6191
|
+
this.config = config;
|
|
6192
|
+
}
|
|
6193
|
+
getArgs({
|
|
6194
|
+
prompt,
|
|
6195
|
+
maxOutputTokens,
|
|
6196
|
+
temperature,
|
|
6197
|
+
topP,
|
|
6198
|
+
frequencyPenalty,
|
|
6199
|
+
presencePenalty,
|
|
6200
|
+
seed,
|
|
6201
|
+
stopSequences,
|
|
6202
|
+
responseFormat,
|
|
6203
|
+
topK,
|
|
6204
|
+
tools,
|
|
6205
|
+
toolChoice
|
|
6206
|
+
}) {
|
|
6207
|
+
var _a15;
|
|
6208
|
+
const baseArgs = __spreadValues(__spreadValues({
|
|
6209
|
+
// model id:
|
|
6210
|
+
model: this.modelId,
|
|
6211
|
+
models: this.settings.models,
|
|
6212
|
+
// model specific settings:
|
|
6213
|
+
logit_bias: this.settings.logitBias,
|
|
6214
|
+
logprobs: this.settings.logprobs === true || typeof this.settings.logprobs === "number" ? true : void 0,
|
|
6215
|
+
top_logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
6216
|
+
user: this.settings.user,
|
|
6217
|
+
parallel_tool_calls: this.settings.parallelToolCalls,
|
|
6218
|
+
// standardized settings:
|
|
6219
|
+
max_tokens: maxOutputTokens,
|
|
6220
|
+
temperature,
|
|
6221
|
+
top_p: topP,
|
|
6222
|
+
frequency_penalty: frequencyPenalty,
|
|
6223
|
+
presence_penalty: presencePenalty,
|
|
6224
|
+
seed,
|
|
6225
|
+
stop: stopSequences,
|
|
6226
|
+
response_format: responseFormat,
|
|
6227
|
+
top_k: topK,
|
|
6228
|
+
// messages:
|
|
6229
|
+
messages: convertToOpenRouterChatMessages(prompt),
|
|
6230
|
+
// OpenRouter specific settings:
|
|
6231
|
+
include_reasoning: this.settings.includeReasoning,
|
|
6232
|
+
reasoning: this.settings.reasoning,
|
|
6233
|
+
usage: this.settings.usage,
|
|
6234
|
+
// Web search settings:
|
|
6235
|
+
plugins: this.settings.plugins,
|
|
6236
|
+
web_search_options: this.settings.web_search_options,
|
|
6237
|
+
// Provider routing settings:
|
|
6238
|
+
provider: this.settings.provider
|
|
6239
|
+
}, this.config.extraBody), this.settings.extraBody);
|
|
6240
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
6241
|
+
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
6242
|
+
response_format: {
|
|
6243
|
+
type: "json_schema",
|
|
6244
|
+
json_schema: __spreadValues({
|
|
6245
|
+
schema: responseFormat.schema,
|
|
6246
|
+
strict: true,
|
|
6247
|
+
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
6248
|
+
}, responseFormat.description && {
|
|
6249
|
+
description: responseFormat.description
|
|
6250
|
+
})
|
|
6251
|
+
}
|
|
6252
|
+
});
|
|
6253
|
+
}
|
|
6254
|
+
if (tools && tools.length > 0) {
|
|
6255
|
+
const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
|
|
6256
|
+
type: "function",
|
|
6257
|
+
function: {
|
|
6258
|
+
name: tool.name,
|
|
6259
|
+
description: tool.description,
|
|
6260
|
+
parameters: tool.inputSchema
|
|
6261
|
+
}
|
|
6262
|
+
}));
|
|
6263
|
+
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
6264
|
+
tools: mappedTools,
|
|
6265
|
+
tool_choice: toolChoice ? getChatCompletionToolChoice(toolChoice) : void 0
|
|
6266
|
+
});
|
|
6267
|
+
}
|
|
6268
|
+
return baseArgs;
|
|
6269
|
+
}
|
|
6270
|
+
async doGenerate(options) {
|
|
6271
|
+
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;
|
|
6272
|
+
const providerOptions = options.providerOptions || {};
|
|
6273
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
6274
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
6275
|
+
const { value: responseValue, responseHeaders } = await postJsonToApi4({
|
|
6276
|
+
url: this.config.url({
|
|
6277
|
+
path: "/chat/completions",
|
|
6278
|
+
modelId: this.modelId
|
|
6279
|
+
}),
|
|
6280
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
6281
|
+
body: args,
|
|
6282
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
6283
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
6284
|
+
OpenRouterNonStreamChatCompletionResponseSchema
|
|
6285
|
+
),
|
|
6286
|
+
abortSignal: options.abortSignal,
|
|
6287
|
+
fetch: this.config.fetch
|
|
6288
|
+
});
|
|
6289
|
+
if ("error" in responseValue) {
|
|
6290
|
+
const errorData = responseValue.error;
|
|
6291
|
+
throw new APICallError2({
|
|
6292
|
+
message: errorData.message,
|
|
6293
|
+
url: this.config.url({
|
|
6294
|
+
path: "/chat/completions",
|
|
6295
|
+
modelId: this.modelId
|
|
6296
|
+
}),
|
|
6297
|
+
requestBodyValues: args,
|
|
6298
|
+
statusCode: 200,
|
|
6299
|
+
responseHeaders,
|
|
6300
|
+
data: errorData
|
|
6301
|
+
});
|
|
6302
|
+
}
|
|
6303
|
+
const response = responseValue;
|
|
6304
|
+
const choice = response.choices[0];
|
|
6305
|
+
if (!choice) {
|
|
6306
|
+
throw new NoContentGeneratedError({
|
|
6307
|
+
message: "No choice in response"
|
|
6308
|
+
});
|
|
6309
|
+
}
|
|
6310
|
+
const usageInfo = response.usage ? {
|
|
6311
|
+
inputTokens: (_a15 = response.usage.prompt_tokens) != null ? _a15 : 0,
|
|
6312
|
+
outputTokens: (_b = response.usage.completion_tokens) != null ? _b : 0,
|
|
6313
|
+
totalTokens: ((_c = response.usage.prompt_tokens) != null ? _c : 0) + ((_d = response.usage.completion_tokens) != null ? _d : 0),
|
|
6314
|
+
reasoningTokens: (_f = (_e = response.usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0,
|
|
6315
|
+
cachedInputTokens: (_h = (_g = response.usage.prompt_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : 0
|
|
6316
|
+
} : {
|
|
6317
|
+
inputTokens: 0,
|
|
6318
|
+
outputTokens: 0,
|
|
6319
|
+
totalTokens: 0,
|
|
6320
|
+
reasoningTokens: 0,
|
|
6321
|
+
cachedInputTokens: 0
|
|
6322
|
+
};
|
|
6323
|
+
const reasoningDetails = (_i = choice.message.reasoning_details) != null ? _i : [];
|
|
6324
|
+
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
6325
|
+
switch (detail.type) {
|
|
6326
|
+
case "reasoning.text": {
|
|
6327
|
+
if (detail.text) {
|
|
6328
|
+
return {
|
|
6329
|
+
type: "reasoning",
|
|
6330
|
+
text: detail.text
|
|
6331
|
+
};
|
|
6332
|
+
}
|
|
6333
|
+
break;
|
|
6334
|
+
}
|
|
6335
|
+
case "reasoning.summary": {
|
|
6336
|
+
if (detail.summary) {
|
|
6337
|
+
return {
|
|
6338
|
+
type: "reasoning",
|
|
6339
|
+
text: detail.summary
|
|
6340
|
+
};
|
|
6341
|
+
}
|
|
6342
|
+
break;
|
|
6343
|
+
}
|
|
6344
|
+
case "reasoning.encrypted": {
|
|
6345
|
+
if (detail.data) {
|
|
6346
|
+
return {
|
|
6347
|
+
type: "reasoning",
|
|
6348
|
+
text: "[REDACTED]"
|
|
6349
|
+
};
|
|
6350
|
+
}
|
|
6351
|
+
break;
|
|
6352
|
+
}
|
|
6353
|
+
}
|
|
6354
|
+
return null;
|
|
6355
|
+
}).filter((p) => p !== null) : choice.message.reasoning ? [
|
|
6356
|
+
{
|
|
6357
|
+
type: "reasoning",
|
|
6358
|
+
text: choice.message.reasoning
|
|
6359
|
+
}
|
|
6360
|
+
] : [];
|
|
6361
|
+
const content = [];
|
|
6362
|
+
content.push(...reasoning);
|
|
6363
|
+
if (choice.message.content) {
|
|
6364
|
+
content.push({
|
|
6365
|
+
type: "text",
|
|
6366
|
+
text: choice.message.content
|
|
6367
|
+
});
|
|
6368
|
+
}
|
|
6369
|
+
if (choice.message.tool_calls) {
|
|
6370
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
6371
|
+
content.push({
|
|
6372
|
+
type: "tool-call",
|
|
6373
|
+
toolCallId: (_j = toolCall.id) != null ? _j : generateId4(),
|
|
6374
|
+
toolName: toolCall.function.name,
|
|
6375
|
+
input: toolCall.function.arguments
|
|
6376
|
+
});
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6379
|
+
if (choice.message.images) {
|
|
6380
|
+
for (const image of choice.message.images) {
|
|
6381
|
+
content.push({
|
|
6382
|
+
type: "file",
|
|
6383
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
6384
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
6385
|
+
});
|
|
6386
|
+
}
|
|
6387
|
+
}
|
|
6388
|
+
if (choice.message.annotations) {
|
|
6389
|
+
for (const annotation of choice.message.annotations) {
|
|
6390
|
+
if (annotation.type === "url_citation") {
|
|
6391
|
+
content.push({
|
|
6392
|
+
type: "source",
|
|
6393
|
+
sourceType: "url",
|
|
6394
|
+
id: annotation.url_citation.url,
|
|
6395
|
+
url: annotation.url_citation.url,
|
|
6396
|
+
title: annotation.url_citation.title,
|
|
6397
|
+
providerMetadata: {
|
|
6398
|
+
openrouter: {
|
|
6399
|
+
content: annotation.url_citation.content || ""
|
|
6400
|
+
}
|
|
6401
|
+
}
|
|
6402
|
+
});
|
|
6403
|
+
}
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
6406
|
+
return {
|
|
6407
|
+
content,
|
|
6408
|
+
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
6409
|
+
usage: usageInfo,
|
|
6410
|
+
warnings: [],
|
|
6411
|
+
providerMetadata: {
|
|
6412
|
+
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
6413
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
6414
|
+
reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
|
|
6415
|
+
usage: {
|
|
6416
|
+
promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
|
|
6417
|
+
completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
|
|
6418
|
+
totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
|
|
6419
|
+
cost: (_p = response.usage) == null ? void 0 : _p.cost,
|
|
6420
|
+
promptTokensDetails: {
|
|
6421
|
+
cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
|
|
6422
|
+
},
|
|
6423
|
+
completionTokensDetails: {
|
|
6424
|
+
reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
|
|
6425
|
+
},
|
|
6426
|
+
costDetails: {
|
|
6427
|
+
upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
|
|
6428
|
+
}
|
|
6429
|
+
}
|
|
6430
|
+
})
|
|
6431
|
+
},
|
|
6432
|
+
request: { body: args },
|
|
6433
|
+
response: {
|
|
6434
|
+
id: response.id,
|
|
6435
|
+
modelId: response.model,
|
|
6436
|
+
headers: responseHeaders
|
|
6437
|
+
}
|
|
6438
|
+
};
|
|
6439
|
+
}
|
|
6440
|
+
async doStream(options) {
|
|
6441
|
+
var _a15;
|
|
6442
|
+
const providerOptions = options.providerOptions || {};
|
|
6443
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
6444
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
6445
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
6446
|
+
url: this.config.url({
|
|
6447
|
+
path: "/chat/completions",
|
|
6448
|
+
modelId: this.modelId
|
|
6449
|
+
}),
|
|
6450
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
6451
|
+
body: __spreadProps(__spreadValues({}, args), {
|
|
6452
|
+
stream: true,
|
|
6453
|
+
// only include stream_options when in strict compatibility mode:
|
|
6454
|
+
stream_options: this.config.compatibility === "strict" ? __spreadValues({
|
|
6455
|
+
include_usage: true
|
|
6456
|
+
}, ((_a15 = this.settings.usage) == null ? void 0 : _a15.include) ? { include_usage: true } : {}) : void 0
|
|
6457
|
+
}),
|
|
6458
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
6459
|
+
successfulResponseHandler: createEventSourceResponseHandler4(
|
|
6460
|
+
OpenRouterStreamChatCompletionChunkSchema
|
|
6461
|
+
),
|
|
6462
|
+
abortSignal: options.abortSignal,
|
|
6463
|
+
fetch: this.config.fetch
|
|
6464
|
+
});
|
|
6465
|
+
const toolCalls = [];
|
|
6466
|
+
let finishReason = "other";
|
|
6467
|
+
const usage = {
|
|
6468
|
+
inputTokens: Number.NaN,
|
|
6469
|
+
outputTokens: Number.NaN,
|
|
6470
|
+
totalTokens: Number.NaN,
|
|
6471
|
+
reasoningTokens: Number.NaN,
|
|
6472
|
+
cachedInputTokens: Number.NaN
|
|
6473
|
+
};
|
|
6474
|
+
const openrouterUsage = {};
|
|
6475
|
+
const accumulatedReasoningDetails = [];
|
|
6476
|
+
let textStarted = false;
|
|
6477
|
+
let reasoningStarted = false;
|
|
6478
|
+
let textId;
|
|
6479
|
+
let reasoningId;
|
|
6480
|
+
let openrouterResponseId;
|
|
6481
|
+
let provider;
|
|
6482
|
+
return {
|
|
6483
|
+
stream: response.pipeThrough(
|
|
6484
|
+
new TransformStream({
|
|
6485
|
+
transform(chunk, controller) {
|
|
6486
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
6487
|
+
if (!chunk.success) {
|
|
6488
|
+
finishReason = "error";
|
|
6489
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
6490
|
+
return;
|
|
6491
|
+
}
|
|
6492
|
+
const value = chunk.value;
|
|
6493
|
+
if ("error" in value) {
|
|
6494
|
+
finishReason = "error";
|
|
6495
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
6496
|
+
return;
|
|
6497
|
+
}
|
|
6498
|
+
if (value.provider) {
|
|
6499
|
+
provider = value.provider;
|
|
6500
|
+
}
|
|
6501
|
+
if (value.id) {
|
|
6502
|
+
openrouterResponseId = value.id;
|
|
6503
|
+
controller.enqueue({
|
|
6504
|
+
type: "response-metadata",
|
|
6505
|
+
id: value.id
|
|
6506
|
+
});
|
|
6507
|
+
}
|
|
6508
|
+
if (value.model) {
|
|
6509
|
+
controller.enqueue({
|
|
6510
|
+
type: "response-metadata",
|
|
6511
|
+
modelId: value.model
|
|
6512
|
+
});
|
|
6513
|
+
}
|
|
6514
|
+
if (value.usage != null) {
|
|
6515
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
6516
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
6517
|
+
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
6518
|
+
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
6519
|
+
if (value.usage.prompt_tokens_details) {
|
|
6520
|
+
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
6521
|
+
usage.cachedInputTokens = cachedInputTokens;
|
|
6522
|
+
openrouterUsage.promptTokensDetails = {
|
|
6523
|
+
cachedTokens: cachedInputTokens
|
|
6524
|
+
};
|
|
6525
|
+
}
|
|
6526
|
+
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
6527
|
+
if (value.usage.completion_tokens_details) {
|
|
6528
|
+
const reasoningTokens = (_b = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b : 0;
|
|
6529
|
+
usage.reasoningTokens = reasoningTokens;
|
|
6530
|
+
openrouterUsage.completionTokensDetails = {
|
|
6531
|
+
reasoningTokens
|
|
6532
|
+
};
|
|
6533
|
+
}
|
|
6534
|
+
openrouterUsage.cost = value.usage.cost;
|
|
6535
|
+
openrouterUsage.totalTokens = value.usage.total_tokens;
|
|
6536
|
+
}
|
|
6537
|
+
const choice = value.choices[0];
|
|
6538
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
6539
|
+
finishReason = mapOpenRouterFinishReason(choice.finish_reason);
|
|
6540
|
+
}
|
|
6541
|
+
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
6542
|
+
return;
|
|
6543
|
+
}
|
|
6544
|
+
const delta = choice.delta;
|
|
6545
|
+
const emitReasoningChunk = (chunkText) => {
|
|
6546
|
+
if (!reasoningStarted) {
|
|
6547
|
+
reasoningId = openrouterResponseId || generateId4();
|
|
6548
|
+
controller.enqueue({
|
|
6549
|
+
type: "reasoning-start",
|
|
6550
|
+
id: reasoningId
|
|
6551
|
+
});
|
|
6552
|
+
reasoningStarted = true;
|
|
6553
|
+
}
|
|
6554
|
+
controller.enqueue({
|
|
6555
|
+
type: "reasoning-delta",
|
|
6556
|
+
delta: chunkText,
|
|
6557
|
+
id: reasoningId || generateId4()
|
|
6558
|
+
});
|
|
6559
|
+
};
|
|
6560
|
+
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
6561
|
+
accumulatedReasoningDetails.push(...delta.reasoning_details);
|
|
6562
|
+
for (const detail of delta.reasoning_details) {
|
|
6563
|
+
switch (detail.type) {
|
|
6564
|
+
case "reasoning.text": {
|
|
6565
|
+
if (detail.text) {
|
|
6566
|
+
emitReasoningChunk(detail.text);
|
|
6567
|
+
}
|
|
6568
|
+
break;
|
|
6569
|
+
}
|
|
6570
|
+
case "reasoning.encrypted": {
|
|
6571
|
+
if (detail.data) {
|
|
6572
|
+
emitReasoningChunk("[REDACTED]");
|
|
6573
|
+
}
|
|
6574
|
+
break;
|
|
6575
|
+
}
|
|
6576
|
+
case "reasoning.summary": {
|
|
6577
|
+
if (detail.summary) {
|
|
6578
|
+
emitReasoningChunk(detail.summary);
|
|
6579
|
+
}
|
|
6580
|
+
break;
|
|
6581
|
+
}
|
|
6582
|
+
}
|
|
6583
|
+
}
|
|
6584
|
+
} else if (delta.reasoning) {
|
|
6585
|
+
emitReasoningChunk(delta.reasoning);
|
|
6586
|
+
}
|
|
6587
|
+
if (delta.content) {
|
|
6588
|
+
if (reasoningStarted && !textStarted) {
|
|
6589
|
+
controller.enqueue({
|
|
6590
|
+
type: "reasoning-end",
|
|
6591
|
+
id: reasoningId || generateId4()
|
|
6592
|
+
});
|
|
6593
|
+
reasoningStarted = false;
|
|
6594
|
+
}
|
|
6595
|
+
if (!textStarted) {
|
|
6596
|
+
textId = openrouterResponseId || generateId4();
|
|
6597
|
+
controller.enqueue({
|
|
6598
|
+
type: "text-start",
|
|
6599
|
+
id: textId
|
|
6600
|
+
});
|
|
6601
|
+
textStarted = true;
|
|
6602
|
+
}
|
|
6603
|
+
controller.enqueue({
|
|
6604
|
+
type: "text-delta",
|
|
6605
|
+
delta: delta.content,
|
|
6606
|
+
id: textId || generateId4()
|
|
6607
|
+
});
|
|
6608
|
+
}
|
|
6609
|
+
if (delta.annotations) {
|
|
6610
|
+
for (const annotation of delta.annotations) {
|
|
6611
|
+
if (annotation.type === "url_citation") {
|
|
6612
|
+
controller.enqueue({
|
|
6613
|
+
type: "source",
|
|
6614
|
+
sourceType: "url",
|
|
6615
|
+
id: annotation.url_citation.url,
|
|
6616
|
+
url: annotation.url_citation.url,
|
|
6617
|
+
title: annotation.url_citation.title,
|
|
6618
|
+
providerMetadata: {
|
|
6619
|
+
openrouter: {
|
|
6620
|
+
content: annotation.url_citation.content || ""
|
|
6621
|
+
}
|
|
6622
|
+
}
|
|
6623
|
+
});
|
|
6624
|
+
}
|
|
6625
|
+
}
|
|
6626
|
+
}
|
|
6627
|
+
if (delta.tool_calls != null) {
|
|
6628
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
6629
|
+
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
6630
|
+
if (toolCalls[index] == null) {
|
|
6631
|
+
if (toolCallDelta.type !== "function") {
|
|
6632
|
+
throw new InvalidResponseDataError2({
|
|
6633
|
+
data: toolCallDelta,
|
|
6634
|
+
message: `Expected 'function' type.`
|
|
6635
|
+
});
|
|
6636
|
+
}
|
|
6637
|
+
if (toolCallDelta.id == null) {
|
|
6638
|
+
throw new InvalidResponseDataError2({
|
|
6639
|
+
data: toolCallDelta,
|
|
6640
|
+
message: `Expected 'id' to be a string.`
|
|
6641
|
+
});
|
|
6642
|
+
}
|
|
6643
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
6644
|
+
throw new InvalidResponseDataError2({
|
|
6645
|
+
data: toolCallDelta,
|
|
6646
|
+
message: `Expected 'function.name' to be a string.`
|
|
6647
|
+
});
|
|
6648
|
+
}
|
|
6649
|
+
toolCalls[index] = {
|
|
6650
|
+
id: toolCallDelta.id,
|
|
6651
|
+
type: "function",
|
|
6652
|
+
function: {
|
|
6653
|
+
name: toolCallDelta.function.name,
|
|
6654
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
6655
|
+
},
|
|
6656
|
+
inputStarted: false,
|
|
6657
|
+
sent: false
|
|
6658
|
+
};
|
|
6659
|
+
const toolCall2 = toolCalls[index];
|
|
6660
|
+
if (toolCall2 == null) {
|
|
6661
|
+
throw new InvalidResponseDataError2({
|
|
6662
|
+
data: { index, toolCallsLength: toolCalls.length },
|
|
6663
|
+
message: `Tool call at index ${index} is missing after creation.`
|
|
6664
|
+
});
|
|
6665
|
+
}
|
|
6666
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson2(toolCall2.function.arguments)) {
|
|
6667
|
+
toolCall2.inputStarted = true;
|
|
6668
|
+
controller.enqueue({
|
|
6669
|
+
type: "tool-input-start",
|
|
6670
|
+
id: toolCall2.id,
|
|
6671
|
+
toolName: toolCall2.function.name
|
|
6672
|
+
});
|
|
6673
|
+
controller.enqueue({
|
|
6674
|
+
type: "tool-input-delta",
|
|
6675
|
+
id: toolCall2.id,
|
|
6676
|
+
delta: toolCall2.function.arguments
|
|
6677
|
+
});
|
|
6678
|
+
controller.enqueue({
|
|
6679
|
+
type: "tool-input-end",
|
|
6680
|
+
id: toolCall2.id
|
|
6681
|
+
});
|
|
6682
|
+
controller.enqueue({
|
|
6683
|
+
type: "tool-call",
|
|
6684
|
+
toolCallId: toolCall2.id,
|
|
6685
|
+
toolName: toolCall2.function.name,
|
|
6686
|
+
input: toolCall2.function.arguments
|
|
6687
|
+
});
|
|
6688
|
+
toolCall2.sent = true;
|
|
6689
|
+
}
|
|
6690
|
+
continue;
|
|
6691
|
+
}
|
|
6692
|
+
const toolCall = toolCalls[index];
|
|
6693
|
+
if (toolCall == null) {
|
|
6694
|
+
throw new InvalidResponseDataError2({
|
|
6695
|
+
data: {
|
|
6696
|
+
index,
|
|
6697
|
+
toolCallsLength: toolCalls.length,
|
|
6698
|
+
toolCallDelta
|
|
6699
|
+
},
|
|
6700
|
+
message: `Tool call at index ${index} is missing during merge.`
|
|
6701
|
+
});
|
|
6702
|
+
}
|
|
6703
|
+
if (!toolCall.inputStarted) {
|
|
6704
|
+
toolCall.inputStarted = true;
|
|
6705
|
+
controller.enqueue({
|
|
6706
|
+
type: "tool-input-start",
|
|
6707
|
+
id: toolCall.id,
|
|
6708
|
+
toolName: toolCall.function.name
|
|
6709
|
+
});
|
|
6710
|
+
}
|
|
6711
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
6712
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
6713
|
+
}
|
|
6714
|
+
controller.enqueue({
|
|
6715
|
+
type: "tool-input-delta",
|
|
6716
|
+
id: toolCall.id,
|
|
6717
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
6718
|
+
});
|
|
6719
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson2(toolCall.function.arguments)) {
|
|
6720
|
+
controller.enqueue({
|
|
6721
|
+
type: "tool-call",
|
|
6722
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId4(),
|
|
6723
|
+
toolName: toolCall.function.name,
|
|
6724
|
+
input: toolCall.function.arguments
|
|
6725
|
+
});
|
|
6726
|
+
toolCall.sent = true;
|
|
6727
|
+
}
|
|
6728
|
+
}
|
|
6729
|
+
}
|
|
6730
|
+
if (delta.images != null) {
|
|
6731
|
+
for (const image of delta.images) {
|
|
6732
|
+
controller.enqueue({
|
|
6733
|
+
type: "file",
|
|
6734
|
+
mediaType: getMediaType(image.image_url.url, "image/jpeg"),
|
|
6735
|
+
data: getBase64FromDataUrl(image.image_url.url)
|
|
6736
|
+
});
|
|
6737
|
+
}
|
|
6738
|
+
}
|
|
6739
|
+
},
|
|
6740
|
+
flush(controller) {
|
|
6741
|
+
var _a16;
|
|
6742
|
+
if (finishReason === "tool-calls") {
|
|
6743
|
+
for (const toolCall of toolCalls) {
|
|
6744
|
+
if (toolCall && !toolCall.sent) {
|
|
6745
|
+
controller.enqueue({
|
|
6746
|
+
type: "tool-call",
|
|
6747
|
+
toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId4(),
|
|
6748
|
+
toolName: toolCall.function.name,
|
|
6749
|
+
// Coerce invalid arguments to an empty JSON object
|
|
6750
|
+
input: isParsableJson2(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
6751
|
+
});
|
|
6752
|
+
toolCall.sent = true;
|
|
6753
|
+
}
|
|
6754
|
+
}
|
|
6755
|
+
}
|
|
6756
|
+
if (reasoningStarted) {
|
|
6757
|
+
controller.enqueue({
|
|
6758
|
+
type: "reasoning-end",
|
|
6759
|
+
id: reasoningId || generateId4()
|
|
6760
|
+
});
|
|
6761
|
+
}
|
|
6762
|
+
if (textStarted) {
|
|
6763
|
+
controller.enqueue({
|
|
6764
|
+
type: "text-end",
|
|
6765
|
+
id: textId || generateId4()
|
|
6766
|
+
});
|
|
6767
|
+
}
|
|
6768
|
+
const openrouterMetadata = {
|
|
6769
|
+
usage: openrouterUsage
|
|
6770
|
+
};
|
|
6771
|
+
if (provider !== void 0) {
|
|
6772
|
+
openrouterMetadata.provider = provider;
|
|
6773
|
+
}
|
|
6774
|
+
if (accumulatedReasoningDetails.length > 0) {
|
|
6775
|
+
openrouterMetadata.reasoning_details = accumulatedReasoningDetails;
|
|
6776
|
+
}
|
|
6777
|
+
controller.enqueue({
|
|
6778
|
+
type: "finish",
|
|
6779
|
+
finishReason,
|
|
6780
|
+
usage,
|
|
6781
|
+
providerMetadata: {
|
|
6782
|
+
openrouter: openrouterMetadata
|
|
6783
|
+
}
|
|
6784
|
+
});
|
|
6785
|
+
}
|
|
6786
|
+
})
|
|
6787
|
+
),
|
|
6788
|
+
warnings: [],
|
|
6789
|
+
request: { body: args },
|
|
6790
|
+
response: { headers: responseHeaders }
|
|
6791
|
+
};
|
|
6792
|
+
}
|
|
6793
|
+
};
|
|
6794
|
+
function convertToOpenRouterCompletionPrompt({
|
|
6795
|
+
prompt,
|
|
6796
|
+
inputFormat,
|
|
6797
|
+
user = "user",
|
|
6798
|
+
assistant = "assistant"
|
|
6799
|
+
}) {
|
|
6800
|
+
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") {
|
|
6801
|
+
return { prompt: prompt[0].content[0].text };
|
|
6802
|
+
}
|
|
6803
|
+
let text = "";
|
|
6804
|
+
if (prompt[0] && prompt[0].role === "system") {
|
|
6805
|
+
text += `${prompt[0].content}
|
|
6806
|
+
|
|
6807
|
+
`;
|
|
6808
|
+
prompt = prompt.slice(1);
|
|
6809
|
+
}
|
|
6810
|
+
for (const { role, content } of prompt) {
|
|
6811
|
+
switch (role) {
|
|
6812
|
+
case "system": {
|
|
6813
|
+
throw new InvalidPromptError({
|
|
6814
|
+
message: `Unexpected system message in prompt: ${content}`,
|
|
6815
|
+
prompt
|
|
6816
|
+
});
|
|
6817
|
+
}
|
|
6818
|
+
case "user": {
|
|
6819
|
+
const userMessage = content.map((part) => {
|
|
6820
|
+
switch (part.type) {
|
|
6821
|
+
case "text": {
|
|
6822
|
+
return part.text;
|
|
6823
|
+
}
|
|
6824
|
+
case "file": {
|
|
6825
|
+
throw new UnsupportedFunctionalityError2({
|
|
6826
|
+
functionality: "file attachments"
|
|
6827
|
+
});
|
|
6828
|
+
}
|
|
6829
|
+
default: {
|
|
6830
|
+
return "";
|
|
6831
|
+
}
|
|
6832
|
+
}
|
|
6833
|
+
}).join("");
|
|
6834
|
+
text += `${user}:
|
|
6835
|
+
${userMessage}
|
|
6836
|
+
|
|
6837
|
+
`;
|
|
6838
|
+
break;
|
|
6839
|
+
}
|
|
6840
|
+
case "assistant": {
|
|
6841
|
+
const assistantMessage = content.map(
|
|
6842
|
+
(part) => {
|
|
6843
|
+
switch (part.type) {
|
|
6844
|
+
case "text": {
|
|
6845
|
+
return part.text;
|
|
6846
|
+
}
|
|
6847
|
+
case "tool-call": {
|
|
6848
|
+
throw new UnsupportedFunctionalityError2({
|
|
6849
|
+
functionality: "tool-call messages"
|
|
6850
|
+
});
|
|
6851
|
+
}
|
|
6852
|
+
case "tool-result": {
|
|
6853
|
+
throw new UnsupportedFunctionalityError2({
|
|
6854
|
+
functionality: "tool-result messages"
|
|
6855
|
+
});
|
|
6856
|
+
}
|
|
6857
|
+
case "reasoning": {
|
|
6858
|
+
throw new UnsupportedFunctionalityError2({
|
|
6859
|
+
functionality: "reasoning messages"
|
|
6860
|
+
});
|
|
6861
|
+
}
|
|
6862
|
+
case "file": {
|
|
6863
|
+
throw new UnsupportedFunctionalityError2({
|
|
6864
|
+
functionality: "file attachments"
|
|
6865
|
+
});
|
|
6866
|
+
}
|
|
6867
|
+
default: {
|
|
6868
|
+
return "";
|
|
6869
|
+
}
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
).join("");
|
|
6873
|
+
text += `${assistant}:
|
|
6874
|
+
${assistantMessage}
|
|
6875
|
+
|
|
6876
|
+
`;
|
|
6877
|
+
break;
|
|
6878
|
+
}
|
|
6879
|
+
case "tool": {
|
|
6880
|
+
throw new UnsupportedFunctionalityError2({
|
|
6881
|
+
functionality: "tool messages"
|
|
6882
|
+
});
|
|
6883
|
+
}
|
|
6884
|
+
}
|
|
6885
|
+
}
|
|
6886
|
+
text += `${assistant}:
|
|
6887
|
+
`;
|
|
6888
|
+
return {
|
|
6889
|
+
prompt: text
|
|
6890
|
+
};
|
|
6891
|
+
}
|
|
6892
|
+
var OpenRouterCompletionChunkSchema = z.union([
|
|
6893
|
+
z.object({
|
|
6894
|
+
id: z.string().optional(),
|
|
6895
|
+
model: z.string().optional(),
|
|
6896
|
+
choices: z.array(
|
|
6897
|
+
z.object({
|
|
6898
|
+
text: z.string(),
|
|
6899
|
+
reasoning: z.string().nullish().optional(),
|
|
6900
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
6901
|
+
finish_reason: z.string().nullish(),
|
|
6902
|
+
index: z.number().nullish(),
|
|
6903
|
+
logprobs: z.object({
|
|
6904
|
+
tokens: z.array(z.string()),
|
|
6905
|
+
token_logprobs: z.array(z.number()),
|
|
6906
|
+
top_logprobs: z.array(z.record(z.string(), z.number())).nullable()
|
|
6907
|
+
}).passthrough().nullable().optional()
|
|
6908
|
+
}).passthrough()
|
|
6909
|
+
),
|
|
6910
|
+
usage: z.object({
|
|
6911
|
+
prompt_tokens: z.number(),
|
|
6912
|
+
prompt_tokens_details: z.object({
|
|
6913
|
+
cached_tokens: z.number()
|
|
6914
|
+
}).passthrough().nullish(),
|
|
6915
|
+
completion_tokens: z.number(),
|
|
6916
|
+
completion_tokens_details: z.object({
|
|
6917
|
+
reasoning_tokens: z.number()
|
|
6918
|
+
}).passthrough().nullish(),
|
|
6919
|
+
total_tokens: z.number(),
|
|
6920
|
+
cost: z.number().optional()
|
|
6921
|
+
}).passthrough().nullish()
|
|
6922
|
+
}).passthrough(),
|
|
6923
|
+
OpenRouterErrorResponseSchema
|
|
6924
|
+
]);
|
|
6925
|
+
var OpenRouterCompletionLanguageModel = class {
|
|
6926
|
+
constructor(modelId, settings, config) {
|
|
6927
|
+
this.specificationVersion = "v2";
|
|
6928
|
+
this.provider = "openrouter";
|
|
6929
|
+
this.supportedUrls = {
|
|
6930
|
+
"image/*": [
|
|
6931
|
+
/^data:image\/[a-zA-Z]+;base64,/,
|
|
6932
|
+
/^https?:\/\/.+\.(jpg|jpeg|png|gif|webp)$/i
|
|
6933
|
+
],
|
|
6934
|
+
"text/*": [/^data:text\//, /^https?:\/\/.+$/],
|
|
6935
|
+
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
6936
|
+
};
|
|
6937
|
+
this.defaultObjectGenerationMode = void 0;
|
|
6938
|
+
this.modelId = modelId;
|
|
6939
|
+
this.settings = settings;
|
|
6940
|
+
this.config = config;
|
|
6941
|
+
}
|
|
6942
|
+
getArgs({
|
|
6943
|
+
prompt,
|
|
6944
|
+
maxOutputTokens,
|
|
6945
|
+
temperature,
|
|
6946
|
+
topP,
|
|
6947
|
+
frequencyPenalty,
|
|
6948
|
+
presencePenalty,
|
|
6949
|
+
seed,
|
|
6950
|
+
responseFormat,
|
|
6951
|
+
topK,
|
|
6952
|
+
stopSequences,
|
|
6953
|
+
tools,
|
|
6954
|
+
toolChoice
|
|
6955
|
+
}) {
|
|
6956
|
+
const { prompt: completionPrompt } = convertToOpenRouterCompletionPrompt({
|
|
6957
|
+
prompt,
|
|
6958
|
+
inputFormat: "prompt"
|
|
6959
|
+
});
|
|
6960
|
+
if (tools == null ? void 0 : tools.length) {
|
|
6961
|
+
throw new UnsupportedFunctionalityError2({
|
|
6962
|
+
functionality: "tools"
|
|
6963
|
+
});
|
|
6964
|
+
}
|
|
6965
|
+
if (toolChoice) {
|
|
6966
|
+
throw new UnsupportedFunctionalityError2({
|
|
6967
|
+
functionality: "toolChoice"
|
|
6968
|
+
});
|
|
6969
|
+
}
|
|
6970
|
+
return __spreadValues(__spreadValues({
|
|
6971
|
+
// model id:
|
|
6972
|
+
model: this.modelId,
|
|
6973
|
+
models: this.settings.models,
|
|
6974
|
+
// model specific settings:
|
|
6975
|
+
logit_bias: this.settings.logitBias,
|
|
6976
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
6977
|
+
suffix: this.settings.suffix,
|
|
6978
|
+
user: this.settings.user,
|
|
6979
|
+
// standardized settings:
|
|
6980
|
+
max_tokens: maxOutputTokens,
|
|
6981
|
+
temperature,
|
|
6982
|
+
top_p: topP,
|
|
6983
|
+
frequency_penalty: frequencyPenalty,
|
|
6984
|
+
presence_penalty: presencePenalty,
|
|
6985
|
+
seed,
|
|
6986
|
+
stop: stopSequences,
|
|
6987
|
+
response_format: responseFormat,
|
|
6988
|
+
top_k: topK,
|
|
6989
|
+
// prompt:
|
|
6990
|
+
prompt: completionPrompt,
|
|
6991
|
+
// OpenRouter specific settings:
|
|
6992
|
+
include_reasoning: this.settings.includeReasoning,
|
|
6993
|
+
reasoning: this.settings.reasoning
|
|
6994
|
+
}, this.config.extraBody), this.settings.extraBody);
|
|
6995
|
+
}
|
|
6996
|
+
async doGenerate(options) {
|
|
6997
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
6998
|
+
const providerOptions = options.providerOptions || {};
|
|
6999
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
7000
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
7001
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
7002
|
+
url: this.config.url({
|
|
7003
|
+
path: "/completions",
|
|
7004
|
+
modelId: this.modelId
|
|
7005
|
+
}),
|
|
7006
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
7007
|
+
body: args,
|
|
7008
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
7009
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
7010
|
+
OpenRouterCompletionChunkSchema
|
|
7011
|
+
),
|
|
7012
|
+
abortSignal: options.abortSignal,
|
|
7013
|
+
fetch: this.config.fetch
|
|
7014
|
+
});
|
|
7015
|
+
if ("error" in response) {
|
|
7016
|
+
const errorData = response.error;
|
|
7017
|
+
throw new APICallError2({
|
|
7018
|
+
message: errorData.message,
|
|
7019
|
+
url: this.config.url({
|
|
7020
|
+
path: "/completions",
|
|
7021
|
+
modelId: this.modelId
|
|
7022
|
+
}),
|
|
7023
|
+
requestBodyValues: args,
|
|
7024
|
+
statusCode: 200,
|
|
7025
|
+
responseHeaders,
|
|
7026
|
+
data: errorData
|
|
7027
|
+
});
|
|
7028
|
+
}
|
|
7029
|
+
const choice = response.choices[0];
|
|
7030
|
+
if (!choice) {
|
|
7031
|
+
throw new NoContentGeneratedError({
|
|
7032
|
+
message: "No choice in OpenRouter completion response"
|
|
7033
|
+
});
|
|
7034
|
+
}
|
|
7035
|
+
return {
|
|
7036
|
+
content: [
|
|
7037
|
+
{
|
|
7038
|
+
type: "text",
|
|
7039
|
+
text: (_a15 = choice.text) != null ? _a15 : ""
|
|
7040
|
+
}
|
|
7041
|
+
],
|
|
7042
|
+
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
7043
|
+
usage: {
|
|
7044
|
+
inputTokens: (_c = (_b = response.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : 0,
|
|
7045
|
+
outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
|
|
7046
|
+
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),
|
|
7047
|
+
reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
|
|
7048
|
+
cachedInputTokens: (_o = (_n = (_m = response.usage) == null ? void 0 : _m.prompt_tokens_details) == null ? void 0 : _n.cached_tokens) != null ? _o : 0
|
|
7049
|
+
},
|
|
7050
|
+
warnings: [],
|
|
7051
|
+
response: {
|
|
7052
|
+
headers: responseHeaders
|
|
7053
|
+
}
|
|
7054
|
+
};
|
|
7055
|
+
}
|
|
7056
|
+
async doStream(options) {
|
|
7057
|
+
const providerOptions = options.providerOptions || {};
|
|
7058
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
7059
|
+
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
7060
|
+
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
7061
|
+
url: this.config.url({
|
|
7062
|
+
path: "/completions",
|
|
7063
|
+
modelId: this.modelId
|
|
7064
|
+
}),
|
|
7065
|
+
headers: combineHeaders4(this.config.headers(), options.headers),
|
|
7066
|
+
body: __spreadProps(__spreadValues({}, args), {
|
|
7067
|
+
stream: true,
|
|
7068
|
+
// only include stream_options when in strict compatibility mode:
|
|
7069
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
7070
|
+
}),
|
|
7071
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
7072
|
+
successfulResponseHandler: createEventSourceResponseHandler4(
|
|
7073
|
+
OpenRouterCompletionChunkSchema
|
|
7074
|
+
),
|
|
7075
|
+
abortSignal: options.abortSignal,
|
|
7076
|
+
fetch: this.config.fetch
|
|
7077
|
+
});
|
|
7078
|
+
let finishReason = "other";
|
|
7079
|
+
const usage = {
|
|
7080
|
+
inputTokens: Number.NaN,
|
|
7081
|
+
outputTokens: Number.NaN,
|
|
7082
|
+
totalTokens: Number.NaN,
|
|
7083
|
+
reasoningTokens: Number.NaN,
|
|
7084
|
+
cachedInputTokens: Number.NaN
|
|
7085
|
+
};
|
|
7086
|
+
const openrouterUsage = {};
|
|
7087
|
+
return {
|
|
7088
|
+
stream: response.pipeThrough(
|
|
7089
|
+
new TransformStream({
|
|
7090
|
+
transform(chunk, controller) {
|
|
7091
|
+
var _a15, _b;
|
|
7092
|
+
if (!chunk.success) {
|
|
7093
|
+
finishReason = "error";
|
|
7094
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
7095
|
+
return;
|
|
7096
|
+
}
|
|
7097
|
+
const value = chunk.value;
|
|
7098
|
+
if ("error" in value) {
|
|
7099
|
+
finishReason = "error";
|
|
7100
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
7101
|
+
return;
|
|
7102
|
+
}
|
|
7103
|
+
if (value.usage != null) {
|
|
7104
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
7105
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
7106
|
+
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
7107
|
+
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
7108
|
+
if (value.usage.prompt_tokens_details) {
|
|
7109
|
+
const cachedInputTokens = (_a15 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a15 : 0;
|
|
7110
|
+
usage.cachedInputTokens = cachedInputTokens;
|
|
7111
|
+
openrouterUsage.promptTokensDetails = {
|
|
7112
|
+
cachedTokens: cachedInputTokens
|
|
7113
|
+
};
|
|
7114
|
+
}
|
|
7115
|
+
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
7116
|
+
if (value.usage.completion_tokens_details) {
|
|
7117
|
+
const reasoningTokens = (_b = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b : 0;
|
|
7118
|
+
usage.reasoningTokens = reasoningTokens;
|
|
7119
|
+
openrouterUsage.completionTokensDetails = {
|
|
7120
|
+
reasoningTokens
|
|
7121
|
+
};
|
|
7122
|
+
}
|
|
7123
|
+
openrouterUsage.cost = value.usage.cost;
|
|
7124
|
+
openrouterUsage.totalTokens = value.usage.total_tokens;
|
|
7125
|
+
}
|
|
7126
|
+
const choice = value.choices[0];
|
|
7127
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
7128
|
+
finishReason = mapOpenRouterFinishReason(choice.finish_reason);
|
|
7129
|
+
}
|
|
7130
|
+
if ((choice == null ? void 0 : choice.text) != null) {
|
|
7131
|
+
controller.enqueue({
|
|
7132
|
+
type: "text-delta",
|
|
7133
|
+
delta: choice.text,
|
|
7134
|
+
id: generateId4()
|
|
7135
|
+
});
|
|
7136
|
+
}
|
|
7137
|
+
},
|
|
7138
|
+
flush(controller) {
|
|
7139
|
+
controller.enqueue({
|
|
7140
|
+
type: "finish",
|
|
7141
|
+
finishReason,
|
|
7142
|
+
usage,
|
|
7143
|
+
providerMetadata: {
|
|
7144
|
+
openrouter: {
|
|
7145
|
+
usage: openrouterUsage
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
});
|
|
7149
|
+
}
|
|
7150
|
+
})
|
|
7151
|
+
),
|
|
7152
|
+
response: {
|
|
7153
|
+
headers: responseHeaders
|
|
7154
|
+
}
|
|
7155
|
+
};
|
|
7156
|
+
}
|
|
7157
|
+
};
|
|
7158
|
+
function removeUndefinedEntries22(record) {
|
|
7159
|
+
return Object.fromEntries(
|
|
7160
|
+
Object.entries(record).filter(([, value]) => value !== null)
|
|
7161
|
+
);
|
|
7162
|
+
}
|
|
7163
|
+
function withUserAgentSuffix3(headers, ...userAgentSuffixParts) {
|
|
7164
|
+
const cleanedHeaders = removeUndefinedEntries22(
|
|
7165
|
+
headers != null ? headers : {}
|
|
7166
|
+
);
|
|
7167
|
+
const currentUserAgentHeader = cleanedHeaders["user-agent"] || "";
|
|
7168
|
+
const newUserAgent = [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ");
|
|
7169
|
+
return __spreadProps(__spreadValues({}, cleanedHeaders), {
|
|
7170
|
+
"user-agent": newUserAgent
|
|
7171
|
+
});
|
|
7172
|
+
}
|
|
7173
|
+
var VERSION5 = "1.2.3";
|
|
7174
|
+
function createOpenRouter(options = {}) {
|
|
7175
|
+
var _a15, _b, _c;
|
|
7176
|
+
const baseURL = (_b = withoutTrailingSlash4((_a15 = options.baseURL) != null ? _a15 : options.baseUrl)) != null ? _b : "https://openrouter.ai/api/v1";
|
|
7177
|
+
const compatibility = (_c = options.compatibility) != null ? _c : "compatible";
|
|
7178
|
+
const getHeaders = () => withUserAgentSuffix3(
|
|
7179
|
+
__spreadValues({
|
|
7180
|
+
Authorization: `Bearer ${loadApiKey4({
|
|
7181
|
+
apiKey: options.apiKey,
|
|
7182
|
+
environmentVariableName: "OPENROUTER_API_KEY",
|
|
7183
|
+
description: "OpenRouter"
|
|
7184
|
+
})}`
|
|
7185
|
+
}, options.headers),
|
|
7186
|
+
`ai-sdk/openrouter/${VERSION5}`
|
|
7187
|
+
);
|
|
7188
|
+
const createChatModel = (modelId, settings = {}) => new OpenRouterChatLanguageModel(modelId, settings, {
|
|
7189
|
+
provider: "openrouter.chat",
|
|
7190
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
7191
|
+
headers: getHeaders,
|
|
7192
|
+
compatibility,
|
|
7193
|
+
fetch: options.fetch,
|
|
7194
|
+
extraBody: options.extraBody
|
|
7195
|
+
});
|
|
7196
|
+
const createCompletionModel = (modelId, settings = {}) => new OpenRouterCompletionLanguageModel(modelId, settings, {
|
|
7197
|
+
provider: "openrouter.completion",
|
|
7198
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
7199
|
+
headers: getHeaders,
|
|
7200
|
+
compatibility,
|
|
7201
|
+
fetch: options.fetch,
|
|
7202
|
+
extraBody: options.extraBody
|
|
7203
|
+
});
|
|
7204
|
+
const createLanguageModel = (modelId, settings) => {
|
|
7205
|
+
if (new.target) {
|
|
7206
|
+
throw new Error(
|
|
7207
|
+
"The OpenRouter model function cannot be called with the new keyword."
|
|
7208
|
+
);
|
|
7209
|
+
}
|
|
7210
|
+
if (modelId === "openai/gpt-3.5-turbo-instruct") {
|
|
7211
|
+
return createCompletionModel(
|
|
7212
|
+
modelId,
|
|
7213
|
+
settings
|
|
7214
|
+
);
|
|
7215
|
+
}
|
|
7216
|
+
return createChatModel(modelId, settings);
|
|
7217
|
+
};
|
|
7218
|
+
const provider = (modelId, settings) => createLanguageModel(modelId, settings);
|
|
7219
|
+
provider.languageModel = createLanguageModel;
|
|
7220
|
+
provider.chat = createChatModel;
|
|
7221
|
+
provider.completion = createCompletionModel;
|
|
7222
|
+
return provider;
|
|
7223
|
+
}
|
|
7224
|
+
createOpenRouter({
|
|
7225
|
+
compatibility: "strict"
|
|
7226
|
+
// strict for OpenRouter API
|
|
7227
|
+
});
|
|
4776
7228
|
|
|
4777
7229
|
// src/llm/model/gateway-resolver.ts
|
|
4778
7230
|
function parseModelRouterId(routerId, gatewayPrefix) {
|
|
@@ -4955,5 +7407,5 @@ var ModelsDevGateway = class extends MastraModelGateway {
|
|
|
4955
7407
|
};
|
|
4956
7408
|
|
|
4957
7409
|
export { ModelsDevGateway, parseModelRouterId };
|
|
4958
|
-
//# sourceMappingURL=chunk-
|
|
4959
|
-
//# sourceMappingURL=chunk-
|
|
7410
|
+
//# sourceMappingURL=chunk-VZJOEGQA.js.map
|
|
7411
|
+
//# sourceMappingURL=chunk-VZJOEGQA.js.map
|