@mastra/core 1.1.0 → 1.2.0-alpha.0
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 +74 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +8 -8
- package/dist/agent/index.js +1 -1
- package/dist/{chunk-RYVRCT7Z.cjs → chunk-22EV7GMK.cjs} +55 -19
- package/dist/chunk-22EV7GMK.cjs.map +1 -0
- package/dist/chunk-2QXNHEDL.js +8 -0
- package/dist/chunk-2QXNHEDL.js.map +1 -0
- package/dist/{chunk-OSIE5L6N.js → chunk-66BWIF4S.js} +7 -7
- package/dist/{chunk-OSIE5L6N.js.map → chunk-66BWIF4S.js.map} +1 -1
- package/dist/{chunk-IDDFKLI7.js → chunk-AC63Y6KP.js} +865 -1471
- package/dist/chunk-AC63Y6KP.js.map +1 -0
- package/dist/{chunk-4QJBNJI4.cjs → chunk-BLXWTBLL.cjs} +168 -168
- package/dist/{chunk-4QJBNJI4.cjs.map → chunk-BLXWTBLL.cjs.map} +1 -1
- package/dist/{chunk-KPIJA2R5.js → chunk-CILDTRXD.js} +2 -2
- package/dist/{chunk-KPIJA2R5.js.map → chunk-CILDTRXD.js.map} +1 -1
- package/dist/{chunk-OW7H7G5N.js → chunk-DWD5DB6W.js} +4 -4
- package/dist/{chunk-OW7H7G5N.js.map → chunk-DWD5DB6W.js.map} +1 -1
- package/dist/{chunk-MGOFRL36.cjs → chunk-EYUXOOSQ.cjs} +106 -39
- package/dist/chunk-EYUXOOSQ.cjs.map +1 -0
- package/dist/{chunk-FVVQY6UU.js → chunk-FAJYC6PA.js} +375 -23
- package/dist/chunk-FAJYC6PA.js.map +1 -0
- package/dist/{chunk-YQMDMIP6.js → chunk-FYMM4PKR.js} +1337 -312
- package/dist/chunk-FYMM4PKR.js.map +1 -0
- package/dist/{chunk-FAM74XPO.js → chunk-G6E3QNJC.js} +3741 -2912
- package/dist/chunk-G6E3QNJC.js.map +1 -0
- package/dist/{chunk-YSFYUEEG.cjs → chunk-I6PWV32C.cjs} +42 -10
- package/dist/chunk-I6PWV32C.cjs.map +1 -0
- package/dist/{chunk-VNGQXHUE.cjs → chunk-MCI7M6AT.cjs} +7 -7
- package/dist/{chunk-VNGQXHUE.cjs.map → chunk-MCI7M6AT.cjs.map} +1 -1
- package/dist/{chunk-4KQEQ4NM.js → chunk-NS33UC72.js} +55 -20
- package/dist/chunk-NS33UC72.js.map +1 -0
- package/dist/{chunk-4PERRFZD.cjs → chunk-OAOMKZXU.cjs} +1378 -353
- package/dist/chunk-OAOMKZXU.cjs.map +1 -0
- package/dist/{chunk-4ACKGMN2.cjs → chunk-ODNSWEMV.cjs} +7 -7
- package/dist/{chunk-4ACKGMN2.cjs.map → chunk-ODNSWEMV.cjs.map} +1 -1
- package/dist/{chunk-H4C5NORS.js → chunk-OQPAOUDS.js} +36 -5
- package/dist/chunk-OQPAOUDS.js.map +1 -0
- package/dist/{chunk-VAJRNUEF.js → chunk-SPVI7HCP.js} +76 -76
- package/dist/chunk-SPVI7HCP.js.map +1 -0
- package/dist/{chunk-ENLG644T.cjs → chunk-STNSGW7W.cjs} +1514 -2120
- package/dist/chunk-STNSGW7W.cjs.map +1 -0
- package/dist/{chunk-FZZI2V2T.js → chunk-USHB3SPM.js} +4 -4
- package/dist/{chunk-FZZI2V2T.js.map → chunk-USHB3SPM.js.map} +1 -1
- package/dist/{chunk-4NGQR4ML.cjs → chunk-UZL4H5P2.cjs} +5092 -4247
- package/dist/chunk-UZL4H5P2.cjs.map +1 -0
- package/dist/{chunk-DOVI2C5F.cjs → chunk-VZXYBFCX.cjs} +8 -8
- package/dist/{chunk-DOVI2C5F.cjs.map → chunk-VZXYBFCX.cjs.map} +1 -1
- package/dist/{chunk-4FUG3CNY.js → chunk-W3AQUG66.js} +3 -3
- package/dist/{chunk-4FUG3CNY.js.map → chunk-W3AQUG66.js.map} +1 -1
- package/dist/{chunk-SLMSUZBA.cjs → chunk-W57QS6F6.cjs} +400 -46
- package/dist/chunk-W57QS6F6.cjs.map +1 -0
- package/dist/{chunk-BG6DCMO2.js → chunk-XS2MED4Y.js} +105 -38
- package/dist/chunk-XS2MED4Y.js.map +1 -0
- package/dist/{chunk-HR67B4UM.cjs → chunk-XVHK5IAO.cjs} +15 -15
- package/dist/{chunk-HR67B4UM.cjs.map → chunk-XVHK5IAO.cjs.map} +1 -1
- package/dist/{chunk-RIPKI7ON.cjs → chunk-Y2SVKUOQ.cjs} +2 -2
- package/dist/{chunk-RIPKI7ON.cjs.map → chunk-Y2SVKUOQ.cjs.map} +1 -1
- package/dist/{chunk-LJOQ7WYC.cjs → chunk-ZCBG4ZQT.cjs} +4 -2
- package/dist/chunk-ZCBG4ZQT.cjs.map +1 -0
- package/dist/docs/README.md +2 -2
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/SOURCE_MAP.json +280 -270
- package/dist/docs/agents/01-overview.md +6 -2
- package/dist/docs/agents/02-using-tools.md +1 -0
- package/dist/docs/agents/06-processors.md +87 -1
- package/dist/docs/evals/01-overview.md +5 -5
- package/dist/docs/mcp/01-overview.md +2 -2
- package/dist/docs/observability/01-overview.md +1 -1
- package/dist/docs/observability/03-overview.md +3 -3
- package/dist/docs/processors/01-reference.md +100 -1
- package/dist/docs/rag/01-overview.md +1 -1
- package/dist/docs/rag/03-vector-databases.md +10 -1
- package/dist/docs/server/04-request-context.md +168 -0
- package/dist/docs/tools-mcp/01-mcp-overview.md +2 -2
- package/dist/docs/voice/01-overview.md +1 -1
- package/dist/docs/workflows/01-overview.md +9 -5
- package/dist/docs/workspace/01-overview.md +38 -31
- package/dist/docs/workspace/02-filesystem.md +9 -11
- package/dist/docs/workspace/03-sandbox.md +8 -10
- package/dist/docs/workspace/04-skills.md +24 -25
- package/dist/docs/workspace/05-search.md +34 -31
- package/dist/docs/workspace/06-reference.md +24 -149
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +15 -15
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +44 -15
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +11 -11
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +6 -0
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/models-dev-2HBSVUOS.js +3 -0
- package/dist/{models-dev-B2ESSYRH.js.map → models-dev-2HBSVUOS.js.map} +1 -1
- package/dist/models-dev-SOIECXXQ.cjs +12 -0
- package/dist/{models-dev-IQ54YHQ4.cjs.map → models-dev-SOIECXXQ.cjs.map} +1 -1
- package/dist/netlify-SSWMYSAX.js +3 -0
- package/dist/{netlify-KPCOQ52P.js.map → netlify-SSWMYSAX.js.map} +1 -1
- package/dist/netlify-TXZZCT6N.cjs +12 -0
- package/dist/{netlify-D6LNGTDH.cjs.map → netlify-TXZZCT6N.cjs.map} +1 -1
- package/dist/processors/index.cjs +44 -40
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/index.d.ts +1 -0
- package/dist/processors/processors/index.d.ts.map +1 -1
- package/dist/processors/processors/tool-search.d.ts +176 -0
- package/dist/processors/processors/tool-search.d.ts.map +1 -0
- package/dist/provider-registry-K5L4DHRK.js +3 -0
- package/dist/{provider-registry-B3CGX3OF.js.map → provider-registry-K5L4DHRK.js.map} +1 -1
- package/dist/provider-registry-ML2VWWLB.cjs +40 -0
- package/dist/{provider-registry-CHV3DFFA.cjs.map → provider-registry-ML2VWWLB.cjs.map} +1 -1
- package/dist/provider-registry.json +101 -34
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/constants.cjs +16 -16
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +101 -101
- package/dist/storage/index.js +2 -2
- package/dist/storage/types.d.ts +4 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
- package/dist/stream/index.cjs +8 -8
- package/dist/stream/index.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +7 -7
- package/dist/vector/index.js +1 -1
- package/dist/workflows/constants.cjs +7 -3
- package/dist/workflows/constants.d.ts +1 -0
- package/dist/workflows/constants.d.ts.map +1 -1
- package/dist/workflows/constants.js +1 -1
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/execution-engine.d.ts +8 -1
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/helpers.d.ts +68 -0
- package/dist/workflows/evented/helpers.d.ts.map +1 -0
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts +9 -17
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/types.d.ts +29 -0
- package/dist/workflows/evented/types.d.ts.map +1 -0
- package/dist/workflows/evented/workflow-event-processor/index.d.ts +12 -3
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts +2 -2
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/sleep.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts.map +1 -1
- package/dist/workflows/evented/workflow.d.ts +54 -3
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/index.cjs +28 -24
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/utils.d.ts +27 -0
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/dist/workspace/filesystem/local-filesystem.d.ts +3 -0
- package/dist/workspace/filesystem/local-filesystem.d.ts.map +1 -1
- package/dist/workspace/index.cjs +32 -32
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/lifecycle.d.ts +2 -0
- package/dist/workspace/lifecycle.d.ts.map +1 -1
- package/dist/workspace/sandbox/local-sandbox.d.ts +1 -2
- package/dist/workspace/sandbox/local-sandbox.d.ts.map +1 -1
- package/dist/workspace/sandbox/sandbox.d.ts +0 -2
- package/dist/workspace/sandbox/sandbox.d.ts.map +1 -1
- package/dist/workspace/search/bm25.d.ts +2 -0
- package/dist/workspace/search/bm25.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/llm/model/provider-types.generated.d.ts +44 -15
- package/dist/chunk-4KQEQ4NM.js.map +0 -1
- package/dist/chunk-4NGQR4ML.cjs.map +0 -1
- package/dist/chunk-4PERRFZD.cjs.map +0 -1
- package/dist/chunk-BG6DCMO2.js.map +0 -1
- package/dist/chunk-ENLG644T.cjs.map +0 -1
- package/dist/chunk-FAM74XPO.js.map +0 -1
- package/dist/chunk-FVVQY6UU.js.map +0 -1
- package/dist/chunk-H4C5NORS.js.map +0 -1
- package/dist/chunk-IDDFKLI7.js.map +0 -1
- package/dist/chunk-LJOQ7WYC.cjs.map +0 -1
- package/dist/chunk-MGOFRL36.cjs.map +0 -1
- package/dist/chunk-RYVRCT7Z.cjs.map +0 -1
- package/dist/chunk-SLMSUZBA.cjs.map +0 -1
- package/dist/chunk-VAJRNUEF.js.map +0 -1
- package/dist/chunk-YEQB4VUA.js +0 -7
- package/dist/chunk-YEQB4VUA.js.map +0 -1
- package/dist/chunk-YQMDMIP6.js.map +0 -1
- package/dist/chunk-YSFYUEEG.cjs.map +0 -1
- package/dist/models-dev-B2ESSYRH.js +0 -3
- package/dist/models-dev-IQ54YHQ4.cjs +0 -12
- package/dist/netlify-D6LNGTDH.cjs +0 -12
- package/dist/netlify-KPCOQ52P.js +0 -3
- package/dist/provider-registry-B3CGX3OF.js +0 -3
- package/dist/provider-registry-CHV3DFFA.cjs +0 -40
|
@@ -1,827 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
1
|
+
import { createJsonErrorResponseHandler2, withoutTrailingSlash, InvalidArgumentError, withoutTrailingSlash2, withUserAgentSuffix, generateId2, withUserAgentSuffix2, createJsonErrorResponseHandler, parseProviderOptions, postJsonToApi, createJsonResponseHandler, combineHeaders, generateId, createEventSourceResponseHandler, InvalidResponseDataError, isParsableJson, loadApiKey, InvalidResponseDataError2, parseProviderOptions2, injectJsonInstructionIntoMessages, postJsonToApi2, createJsonResponseHandler2, combineHeaders2, createEventSourceResponseHandler2, loadApiKey2, UnsupportedFunctionalityError, convertToBase64, APICallError, UnsupportedFunctionalityError2, LoadAPIKeyError, convertToBase642, JSONParseError, TypeValidationError, EmptyResponseBodyError, EventSourceParserStream, NoSuchModelError, NoSuchModelError2, MastraModelGateway, createAnthropic, createOpenAI, createGoogleGenerativeAI, createOpenAICompatible, TooManyEmbeddingValuesForCallError, TooManyEmbeddingValuesForCallError2, InvalidPromptError } from './chunk-G6E3QNJC.js';
|
|
2
|
+
import * as z42 from 'zod/v4';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
5
5
|
|
|
6
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider@2.0.1/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
7
|
-
var marker = "vercel.ai.error";
|
|
8
|
-
var symbol = Symbol.for(marker);
|
|
9
|
-
var _a;
|
|
10
|
-
var _b;
|
|
11
|
-
var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
12
|
-
/**
|
|
13
|
-
* Creates an AI SDK Error.
|
|
14
|
-
*
|
|
15
|
-
* @param {Object} params - The parameters for creating the error.
|
|
16
|
-
* @param {string} params.name - The name of the error.
|
|
17
|
-
* @param {string} params.message - The error message.
|
|
18
|
-
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
19
|
-
*/
|
|
20
|
-
constructor({
|
|
21
|
-
name: name142,
|
|
22
|
-
message,
|
|
23
|
-
cause
|
|
24
|
-
}) {
|
|
25
|
-
super(message);
|
|
26
|
-
this[_a] = true;
|
|
27
|
-
this.name = name142;
|
|
28
|
-
this.cause = cause;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Checks if the given error is an AI SDK Error.
|
|
32
|
-
* @param {unknown} error - The error to check.
|
|
33
|
-
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
34
|
-
*/
|
|
35
|
-
static isInstance(error) {
|
|
36
|
-
return _AISDKError.hasMarker(error, marker);
|
|
37
|
-
}
|
|
38
|
-
static hasMarker(error, marker152) {
|
|
39
|
-
const markerSymbol = Symbol.for(marker152);
|
|
40
|
-
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var name = "AI_APICallError";
|
|
44
|
-
var marker2 = `vercel.ai.error.${name}`;
|
|
45
|
-
var symbol2 = Symbol.for(marker2);
|
|
46
|
-
var _a2;
|
|
47
|
-
var _b2;
|
|
48
|
-
var APICallError2 = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
|
|
49
|
-
constructor({
|
|
50
|
-
message,
|
|
51
|
-
url,
|
|
52
|
-
requestBodyValues,
|
|
53
|
-
statusCode,
|
|
54
|
-
responseHeaders,
|
|
55
|
-
responseBody,
|
|
56
|
-
cause,
|
|
57
|
-
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
|
58
|
-
statusCode === 409 || // conflict
|
|
59
|
-
statusCode === 429 || // too many requests
|
|
60
|
-
statusCode >= 500),
|
|
61
|
-
// server error
|
|
62
|
-
data
|
|
63
|
-
}) {
|
|
64
|
-
super({ name, message, cause });
|
|
65
|
-
this[_a2] = true;
|
|
66
|
-
this.url = url;
|
|
67
|
-
this.requestBodyValues = requestBodyValues;
|
|
68
|
-
this.statusCode = statusCode;
|
|
69
|
-
this.responseHeaders = responseHeaders;
|
|
70
|
-
this.responseBody = responseBody;
|
|
71
|
-
this.isRetryable = isRetryable;
|
|
72
|
-
this.data = data;
|
|
73
|
-
}
|
|
74
|
-
static isInstance(error) {
|
|
75
|
-
return AISDKError.hasMarker(error, marker2);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var name2 = "AI_EmptyResponseBodyError";
|
|
79
|
-
var marker3 = `vercel.ai.error.${name2}`;
|
|
80
|
-
var symbol3 = Symbol.for(marker3);
|
|
81
|
-
var _a3;
|
|
82
|
-
var _b3;
|
|
83
|
-
var EmptyResponseBodyError2 = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
|
|
84
|
-
// used in isInstance
|
|
85
|
-
constructor({ message = "Empty response body" } = {}) {
|
|
86
|
-
super({ name: name2, message });
|
|
87
|
-
this[_a3] = true;
|
|
88
|
-
}
|
|
89
|
-
static isInstance(error) {
|
|
90
|
-
return AISDKError.hasMarker(error, marker3);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
function getErrorMessage(error) {
|
|
94
|
-
if (error == null) {
|
|
95
|
-
return "unknown error";
|
|
96
|
-
}
|
|
97
|
-
if (typeof error === "string") {
|
|
98
|
-
return error;
|
|
99
|
-
}
|
|
100
|
-
if (error instanceof Error) {
|
|
101
|
-
return error.message;
|
|
102
|
-
}
|
|
103
|
-
return JSON.stringify(error);
|
|
104
|
-
}
|
|
105
|
-
var name3 = "AI_InvalidArgumentError";
|
|
106
|
-
var marker4 = `vercel.ai.error.${name3}`;
|
|
107
|
-
var symbol4 = Symbol.for(marker4);
|
|
108
|
-
var _a4;
|
|
109
|
-
var _b4;
|
|
110
|
-
var InvalidArgumentError2 = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
|
|
111
|
-
constructor({
|
|
112
|
-
message,
|
|
113
|
-
cause,
|
|
114
|
-
argument
|
|
115
|
-
}) {
|
|
116
|
-
super({ name: name3, message, cause });
|
|
117
|
-
this[_a4] = true;
|
|
118
|
-
this.argument = argument;
|
|
119
|
-
}
|
|
120
|
-
static isInstance(error) {
|
|
121
|
-
return AISDKError.hasMarker(error, marker4);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var name4 = "AI_InvalidPromptError";
|
|
125
|
-
var marker5 = `vercel.ai.error.${name4}`;
|
|
126
|
-
var symbol5 = Symbol.for(marker5);
|
|
127
|
-
var _a5;
|
|
128
|
-
var _b5;
|
|
129
|
-
var InvalidPromptError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
|
|
130
|
-
constructor({
|
|
131
|
-
prompt,
|
|
132
|
-
message,
|
|
133
|
-
cause
|
|
134
|
-
}) {
|
|
135
|
-
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
136
|
-
this[_a5] = true;
|
|
137
|
-
this.prompt = prompt;
|
|
138
|
-
}
|
|
139
|
-
static isInstance(error) {
|
|
140
|
-
return AISDKError.hasMarker(error, marker5);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var name5 = "AI_InvalidResponseDataError";
|
|
144
|
-
var marker6 = `vercel.ai.error.${name5}`;
|
|
145
|
-
var symbol6 = Symbol.for(marker6);
|
|
146
|
-
var _a6;
|
|
147
|
-
var _b6;
|
|
148
|
-
var InvalidResponseDataError2 = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
|
|
149
|
-
constructor({
|
|
150
|
-
data,
|
|
151
|
-
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
152
|
-
}) {
|
|
153
|
-
super({ name: name5, message });
|
|
154
|
-
this[_a6] = true;
|
|
155
|
-
this.data = data;
|
|
156
|
-
}
|
|
157
|
-
static isInstance(error) {
|
|
158
|
-
return AISDKError.hasMarker(error, marker6);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
var name6 = "AI_JSONParseError";
|
|
162
|
-
var marker7 = `vercel.ai.error.${name6}`;
|
|
163
|
-
var symbol7 = Symbol.for(marker7);
|
|
164
|
-
var _a7;
|
|
165
|
-
var _b7;
|
|
166
|
-
var JSONParseError2 = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
|
|
167
|
-
constructor({ text, cause }) {
|
|
168
|
-
super({
|
|
169
|
-
name: name6,
|
|
170
|
-
message: `JSON parsing failed: Text: ${text}.
|
|
171
|
-
Error message: ${getErrorMessage(cause)}`,
|
|
172
|
-
cause
|
|
173
|
-
});
|
|
174
|
-
this[_a7] = true;
|
|
175
|
-
this.text = text;
|
|
176
|
-
}
|
|
177
|
-
static isInstance(error) {
|
|
178
|
-
return AISDKError.hasMarker(error, marker7);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
var name7 = "AI_LoadAPIKeyError";
|
|
182
|
-
var marker8 = `vercel.ai.error.${name7}`;
|
|
183
|
-
var symbol8 = Symbol.for(marker8);
|
|
184
|
-
var _a8;
|
|
185
|
-
var _b8;
|
|
186
|
-
var LoadAPIKeyError2 = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
|
|
187
|
-
// used in isInstance
|
|
188
|
-
constructor({ message }) {
|
|
189
|
-
super({ name: name7, message });
|
|
190
|
-
this[_a8] = true;
|
|
191
|
-
}
|
|
192
|
-
static isInstance(error) {
|
|
193
|
-
return AISDKError.hasMarker(error, marker8);
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
var name10 = "AI_NoSuchModelError";
|
|
197
|
-
var marker11 = `vercel.ai.error.${name10}`;
|
|
198
|
-
var symbol11 = Symbol.for(marker11);
|
|
199
|
-
var _a11;
|
|
200
|
-
var _b11;
|
|
201
|
-
var NoSuchModelError2 = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
|
|
202
|
-
constructor({
|
|
203
|
-
errorName = name10,
|
|
204
|
-
modelId,
|
|
205
|
-
modelType,
|
|
206
|
-
message = `No such ${modelType}: ${modelId}`
|
|
207
|
-
}) {
|
|
208
|
-
super({ name: errorName, message });
|
|
209
|
-
this[_a11] = true;
|
|
210
|
-
this.modelId = modelId;
|
|
211
|
-
this.modelType = modelType;
|
|
212
|
-
}
|
|
213
|
-
static isInstance(error) {
|
|
214
|
-
return AISDKError.hasMarker(error, marker11);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
218
|
-
var marker12 = `vercel.ai.error.${name11}`;
|
|
219
|
-
var symbol12 = Symbol.for(marker12);
|
|
220
|
-
var _a12;
|
|
221
|
-
var _b12;
|
|
222
|
-
var TooManyEmbeddingValuesForCallError2 = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
223
|
-
constructor(options) {
|
|
224
|
-
super({
|
|
225
|
-
name: name11,
|
|
226
|
-
message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
|
|
227
|
-
});
|
|
228
|
-
this[_a12] = true;
|
|
229
|
-
this.provider = options.provider;
|
|
230
|
-
this.modelId = options.modelId;
|
|
231
|
-
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
232
|
-
this.values = options.values;
|
|
233
|
-
}
|
|
234
|
-
static isInstance(error) {
|
|
235
|
-
return AISDKError.hasMarker(error, marker12);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
var name12 = "AI_TypeValidationError";
|
|
239
|
-
var marker13 = `vercel.ai.error.${name12}`;
|
|
240
|
-
var symbol13 = Symbol.for(marker13);
|
|
241
|
-
var _a13;
|
|
242
|
-
var _b13;
|
|
243
|
-
var TypeValidationError2 = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
244
|
-
constructor({ value, cause }) {
|
|
245
|
-
super({
|
|
246
|
-
name: name12,
|
|
247
|
-
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
|
248
|
-
Error message: ${getErrorMessage(cause)}`,
|
|
249
|
-
cause
|
|
250
|
-
});
|
|
251
|
-
this[_a13] = true;
|
|
252
|
-
this.value = value;
|
|
253
|
-
}
|
|
254
|
-
static isInstance(error) {
|
|
255
|
-
return AISDKError.hasMarker(error, marker13);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Wraps an error into a TypeValidationError.
|
|
259
|
-
* If the cause is already a TypeValidationError with the same value, it returns the cause.
|
|
260
|
-
* Otherwise, it creates a new TypeValidationError.
|
|
261
|
-
*
|
|
262
|
-
* @param {Object} params - The parameters for wrapping the error.
|
|
263
|
-
* @param {unknown} params.value - The value that failed validation.
|
|
264
|
-
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
265
|
-
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
266
|
-
*/
|
|
267
|
-
static wrap({
|
|
268
|
-
value,
|
|
269
|
-
cause
|
|
270
|
-
}) {
|
|
271
|
-
return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({ value, cause });
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
var name13 = "AI_UnsupportedFunctionalityError";
|
|
275
|
-
var marker14 = `vercel.ai.error.${name13}`;
|
|
276
|
-
var symbol14 = Symbol.for(marker14);
|
|
277
|
-
var _a14;
|
|
278
|
-
var _b14;
|
|
279
|
-
var UnsupportedFunctionalityError2 = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
280
|
-
constructor({
|
|
281
|
-
functionality,
|
|
282
|
-
message = `'${functionality}' functionality not supported.`
|
|
283
|
-
}) {
|
|
284
|
-
super({ name: name13, message });
|
|
285
|
-
this[_a14] = true;
|
|
286
|
-
this.functionality = functionality;
|
|
287
|
-
}
|
|
288
|
-
static isInstance(error) {
|
|
289
|
-
return AISDKError.hasMarker(error, marker14);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
function combineHeaders2(...headers) {
|
|
293
|
-
return headers.reduce(
|
|
294
|
-
(combinedHeaders, currentHeaders) => ({
|
|
295
|
-
...combinedHeaders,
|
|
296
|
-
...currentHeaders != null ? currentHeaders : {}
|
|
297
|
-
}),
|
|
298
|
-
{}
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
function extractResponseHeaders(response) {
|
|
302
|
-
return Object.fromEntries([...response.headers]);
|
|
303
|
-
}
|
|
304
|
-
var createIdGenerator = ({
|
|
305
|
-
prefix,
|
|
306
|
-
size = 16,
|
|
307
|
-
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
308
|
-
separator = "-"
|
|
309
|
-
} = {}) => {
|
|
310
|
-
const generator = () => {
|
|
311
|
-
const alphabetLength = alphabet.length;
|
|
312
|
-
const chars = new Array(size);
|
|
313
|
-
for (let i = 0; i < size; i++) {
|
|
314
|
-
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
315
|
-
}
|
|
316
|
-
return chars.join("");
|
|
317
|
-
};
|
|
318
|
-
if (prefix == null) {
|
|
319
|
-
return generator;
|
|
320
|
-
}
|
|
321
|
-
if (alphabet.includes(separator)) {
|
|
322
|
-
throw new InvalidArgumentError2({
|
|
323
|
-
argument: "separator",
|
|
324
|
-
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
return () => `${prefix}${separator}${generator()}`;
|
|
328
|
-
};
|
|
329
|
-
var generateId2 = createIdGenerator();
|
|
330
|
-
function isAbortError(error) {
|
|
331
|
-
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
332
|
-
error.name === "TimeoutError");
|
|
333
|
-
}
|
|
334
|
-
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
335
|
-
function handleFetchError({
|
|
336
|
-
error,
|
|
337
|
-
url,
|
|
338
|
-
requestBodyValues
|
|
339
|
-
}) {
|
|
340
|
-
if (isAbortError(error)) {
|
|
341
|
-
return error;
|
|
342
|
-
}
|
|
343
|
-
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
344
|
-
const cause = error.cause;
|
|
345
|
-
if (cause != null) {
|
|
346
|
-
return new APICallError2({
|
|
347
|
-
message: `Cannot connect to API: ${cause.message}`,
|
|
348
|
-
cause,
|
|
349
|
-
url,
|
|
350
|
-
requestBodyValues,
|
|
351
|
-
isRetryable: true
|
|
352
|
-
// retry when network error
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return error;
|
|
357
|
-
}
|
|
358
|
-
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
359
|
-
var _a16, _b15, _c;
|
|
360
|
-
if (globalThisAny.window) {
|
|
361
|
-
return `runtime/browser`;
|
|
362
|
-
}
|
|
363
|
-
if ((_a16 = globalThisAny.navigator) == null ? void 0 : _a16.userAgent) {
|
|
364
|
-
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
365
|
-
}
|
|
366
|
-
if ((_c = (_b15 = globalThisAny.process) == null ? void 0 : _b15.versions) == null ? void 0 : _c.node) {
|
|
367
|
-
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
368
|
-
}
|
|
369
|
-
if (globalThisAny.EdgeRuntime) {
|
|
370
|
-
return `runtime/vercel-edge`;
|
|
371
|
-
}
|
|
372
|
-
return "runtime/unknown";
|
|
373
|
-
}
|
|
374
|
-
function normalizeHeaders(headers) {
|
|
375
|
-
if (headers == null) {
|
|
376
|
-
return {};
|
|
377
|
-
}
|
|
378
|
-
const normalized = {};
|
|
379
|
-
if (headers instanceof Headers) {
|
|
380
|
-
headers.forEach((value, key) => {
|
|
381
|
-
normalized[key.toLowerCase()] = value;
|
|
382
|
-
});
|
|
383
|
-
} else {
|
|
384
|
-
if (!Array.isArray(headers)) {
|
|
385
|
-
headers = Object.entries(headers);
|
|
386
|
-
}
|
|
387
|
-
for (const [key, value] of headers) {
|
|
388
|
-
if (value != null) {
|
|
389
|
-
normalized[key.toLowerCase()] = value;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return normalized;
|
|
394
|
-
}
|
|
395
|
-
function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
396
|
-
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
397
|
-
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
398
|
-
normalizedHeaders.set(
|
|
399
|
-
"user-agent",
|
|
400
|
-
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
401
|
-
);
|
|
402
|
-
return Object.fromEntries(normalizedHeaders.entries());
|
|
403
|
-
}
|
|
404
|
-
var VERSION = "3.0.20" ;
|
|
405
|
-
function loadApiKey2({
|
|
406
|
-
apiKey,
|
|
407
|
-
environmentVariableName,
|
|
408
|
-
apiKeyParameterName = "apiKey",
|
|
409
|
-
description
|
|
410
|
-
}) {
|
|
411
|
-
if (typeof apiKey === "string") {
|
|
412
|
-
return apiKey;
|
|
413
|
-
}
|
|
414
|
-
if (apiKey != null) {
|
|
415
|
-
throw new LoadAPIKeyError2({
|
|
416
|
-
message: `${description} API key must be a string.`
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
if (typeof process === "undefined") {
|
|
420
|
-
throw new LoadAPIKeyError2({
|
|
421
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
apiKey = process.env[environmentVariableName];
|
|
425
|
-
if (apiKey == null) {
|
|
426
|
-
throw new LoadAPIKeyError2({
|
|
427
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
if (typeof apiKey !== "string") {
|
|
431
|
-
throw new LoadAPIKeyError2({
|
|
432
|
-
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
return apiKey;
|
|
436
|
-
}
|
|
437
|
-
var suspectProtoRx = /"__proto__"\s*:/;
|
|
438
|
-
var suspectConstructorRx = /"constructor"\s*:/;
|
|
439
|
-
function _parse(text) {
|
|
440
|
-
const obj = JSON.parse(text);
|
|
441
|
-
if (obj === null || typeof obj !== "object") {
|
|
442
|
-
return obj;
|
|
443
|
-
}
|
|
444
|
-
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
445
|
-
return obj;
|
|
446
|
-
}
|
|
447
|
-
return filter(obj);
|
|
448
|
-
}
|
|
449
|
-
function filter(obj) {
|
|
450
|
-
let next = [obj];
|
|
451
|
-
while (next.length) {
|
|
452
|
-
const nodes = next;
|
|
453
|
-
next = [];
|
|
454
|
-
for (const node of nodes) {
|
|
455
|
-
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
456
|
-
throw new SyntaxError("Object contains forbidden prototype property");
|
|
457
|
-
}
|
|
458
|
-
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
459
|
-
throw new SyntaxError("Object contains forbidden prototype property");
|
|
460
|
-
}
|
|
461
|
-
for (const key in node) {
|
|
462
|
-
const value = node[key];
|
|
463
|
-
if (value && typeof value === "object") {
|
|
464
|
-
next.push(value);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return obj;
|
|
470
|
-
}
|
|
471
|
-
function secureJsonParse(text) {
|
|
472
|
-
const { stackTraceLimit } = Error;
|
|
473
|
-
try {
|
|
474
|
-
Error.stackTraceLimit = 0;
|
|
475
|
-
} catch (e) {
|
|
476
|
-
return _parse(text);
|
|
477
|
-
}
|
|
478
|
-
try {
|
|
479
|
-
return _parse(text);
|
|
480
|
-
} finally {
|
|
481
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
485
|
-
function validator(validate) {
|
|
486
|
-
return { [validatorSymbol]: true, validate };
|
|
487
|
-
}
|
|
488
|
-
function isValidator(value) {
|
|
489
|
-
return typeof value === "object" && value !== null && validatorSymbol in value && value[validatorSymbol] === true && "validate" in value;
|
|
490
|
-
}
|
|
491
|
-
function asValidator(value) {
|
|
492
|
-
return isValidator(value) ? value : typeof value === "function" ? value() : standardSchemaValidator(value);
|
|
493
|
-
}
|
|
494
|
-
function standardSchemaValidator(standardSchema) {
|
|
495
|
-
return validator(async (value) => {
|
|
496
|
-
const result = await standardSchema["~standard"].validate(value);
|
|
497
|
-
return result.issues == null ? { success: true, value: result.value } : {
|
|
498
|
-
success: false,
|
|
499
|
-
error: new TypeValidationError2({
|
|
500
|
-
value,
|
|
501
|
-
cause: result.issues
|
|
502
|
-
})
|
|
503
|
-
};
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
async function validateTypes({
|
|
507
|
-
value,
|
|
508
|
-
schema
|
|
509
|
-
}) {
|
|
510
|
-
const result = await safeValidateTypes({ value, schema });
|
|
511
|
-
if (!result.success) {
|
|
512
|
-
throw TypeValidationError2.wrap({ value, cause: result.error });
|
|
513
|
-
}
|
|
514
|
-
return result.value;
|
|
515
|
-
}
|
|
516
|
-
async function safeValidateTypes({
|
|
517
|
-
value,
|
|
518
|
-
schema
|
|
519
|
-
}) {
|
|
520
|
-
const validator22 = asValidator(schema);
|
|
521
|
-
try {
|
|
522
|
-
if (validator22.validate == null) {
|
|
523
|
-
return { success: true, value, rawValue: value };
|
|
524
|
-
}
|
|
525
|
-
const result = await validator22.validate(value);
|
|
526
|
-
if (result.success) {
|
|
527
|
-
return { success: true, value: result.value, rawValue: value };
|
|
528
|
-
}
|
|
529
|
-
return {
|
|
530
|
-
success: false,
|
|
531
|
-
error: TypeValidationError2.wrap({ value, cause: result.error }),
|
|
532
|
-
rawValue: value
|
|
533
|
-
};
|
|
534
|
-
} catch (error) {
|
|
535
|
-
return {
|
|
536
|
-
success: false,
|
|
537
|
-
error: TypeValidationError2.wrap({ value, cause: error }),
|
|
538
|
-
rawValue: value
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
async function parseJSON({
|
|
543
|
-
text,
|
|
544
|
-
schema
|
|
545
|
-
}) {
|
|
546
|
-
try {
|
|
547
|
-
const value = secureJsonParse(text);
|
|
548
|
-
if (schema == null) {
|
|
549
|
-
return value;
|
|
550
|
-
}
|
|
551
|
-
return validateTypes({ value, schema });
|
|
552
|
-
} catch (error) {
|
|
553
|
-
if (JSONParseError2.isInstance(error) || TypeValidationError2.isInstance(error)) {
|
|
554
|
-
throw error;
|
|
555
|
-
}
|
|
556
|
-
throw new JSONParseError2({ text, cause: error });
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
async function safeParseJSON({
|
|
560
|
-
text,
|
|
561
|
-
schema
|
|
562
|
-
}) {
|
|
563
|
-
try {
|
|
564
|
-
const value = secureJsonParse(text);
|
|
565
|
-
if (schema == null) {
|
|
566
|
-
return { success: true, value, rawValue: value };
|
|
567
|
-
}
|
|
568
|
-
return await safeValidateTypes({ value, schema });
|
|
569
|
-
} catch (error) {
|
|
570
|
-
return {
|
|
571
|
-
success: false,
|
|
572
|
-
error: JSONParseError2.isInstance(error) ? error : new JSONParseError2({ text, cause: error }),
|
|
573
|
-
rawValue: void 0
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
function isParsableJson(input) {
|
|
578
|
-
try {
|
|
579
|
-
secureJsonParse(input);
|
|
580
|
-
return true;
|
|
581
|
-
} catch (e) {
|
|
582
|
-
return false;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
function parseJsonEventStream({
|
|
586
|
-
stream,
|
|
587
|
-
schema
|
|
588
|
-
}) {
|
|
589
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
590
|
-
new TransformStream({
|
|
591
|
-
async transform({ data }, controller) {
|
|
592
|
-
if (data === "[DONE]") {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
controller.enqueue(await safeParseJSON({ text: data, schema }));
|
|
596
|
-
}
|
|
597
|
-
})
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
async function parseProviderOptions2({
|
|
601
|
-
provider,
|
|
602
|
-
providerOptions,
|
|
603
|
-
schema
|
|
604
|
-
}) {
|
|
605
|
-
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
|
|
606
|
-
return void 0;
|
|
607
|
-
}
|
|
608
|
-
const parsedProviderOptions = await safeValidateTypes({
|
|
609
|
-
value: providerOptions[provider],
|
|
610
|
-
schema
|
|
611
|
-
});
|
|
612
|
-
if (!parsedProviderOptions.success) {
|
|
613
|
-
throw new InvalidArgumentError2({
|
|
614
|
-
argument: "providerOptions",
|
|
615
|
-
message: `invalid ${provider} provider options`,
|
|
616
|
-
cause: parsedProviderOptions.error
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
return parsedProviderOptions.value;
|
|
620
|
-
}
|
|
621
|
-
var getOriginalFetch2 = () => globalThis.fetch;
|
|
622
|
-
var postJsonToApi2 = async ({
|
|
623
|
-
url,
|
|
624
|
-
headers,
|
|
625
|
-
body,
|
|
626
|
-
failedResponseHandler,
|
|
627
|
-
successfulResponseHandler,
|
|
628
|
-
abortSignal,
|
|
629
|
-
fetch: fetch2
|
|
630
|
-
}) => postToApi({
|
|
631
|
-
url,
|
|
632
|
-
headers: {
|
|
633
|
-
"Content-Type": "application/json",
|
|
634
|
-
...headers
|
|
635
|
-
},
|
|
636
|
-
body: {
|
|
637
|
-
content: JSON.stringify(body),
|
|
638
|
-
values: body
|
|
639
|
-
},
|
|
640
|
-
failedResponseHandler,
|
|
641
|
-
successfulResponseHandler,
|
|
642
|
-
abortSignal,
|
|
643
|
-
fetch: fetch2
|
|
644
|
-
});
|
|
645
|
-
var postToApi = async ({
|
|
646
|
-
url,
|
|
647
|
-
headers = {},
|
|
648
|
-
body,
|
|
649
|
-
successfulResponseHandler,
|
|
650
|
-
failedResponseHandler,
|
|
651
|
-
abortSignal,
|
|
652
|
-
fetch: fetch2 = getOriginalFetch2()
|
|
653
|
-
}) => {
|
|
654
|
-
try {
|
|
655
|
-
const response = await fetch2(url, {
|
|
656
|
-
method: "POST",
|
|
657
|
-
headers: withUserAgentSuffix2(
|
|
658
|
-
headers,
|
|
659
|
-
`ai-sdk/provider-utils/${VERSION}`,
|
|
660
|
-
getRuntimeEnvironmentUserAgent()
|
|
661
|
-
),
|
|
662
|
-
body: body.content,
|
|
663
|
-
signal: abortSignal
|
|
664
|
-
});
|
|
665
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
666
|
-
if (!response.ok) {
|
|
667
|
-
let errorInformation;
|
|
668
|
-
try {
|
|
669
|
-
errorInformation = await failedResponseHandler({
|
|
670
|
-
response,
|
|
671
|
-
url,
|
|
672
|
-
requestBodyValues: body.values
|
|
673
|
-
});
|
|
674
|
-
} catch (error) {
|
|
675
|
-
if (isAbortError(error) || APICallError2.isInstance(error)) {
|
|
676
|
-
throw error;
|
|
677
|
-
}
|
|
678
|
-
throw new APICallError2({
|
|
679
|
-
message: "Failed to process error response",
|
|
680
|
-
cause: error,
|
|
681
|
-
statusCode: response.status,
|
|
682
|
-
url,
|
|
683
|
-
responseHeaders,
|
|
684
|
-
requestBodyValues: body.values
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
throw errorInformation.value;
|
|
688
|
-
}
|
|
689
|
-
try {
|
|
690
|
-
return await successfulResponseHandler({
|
|
691
|
-
response,
|
|
692
|
-
url,
|
|
693
|
-
requestBodyValues: body.values
|
|
694
|
-
});
|
|
695
|
-
} catch (error) {
|
|
696
|
-
if (error instanceof Error) {
|
|
697
|
-
if (isAbortError(error) || APICallError2.isInstance(error)) {
|
|
698
|
-
throw error;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
throw new APICallError2({
|
|
702
|
-
message: "Failed to process successful response",
|
|
703
|
-
cause: error,
|
|
704
|
-
statusCode: response.status,
|
|
705
|
-
url,
|
|
706
|
-
responseHeaders,
|
|
707
|
-
requestBodyValues: body.values
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
} catch (error) {
|
|
711
|
-
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
var createJsonErrorResponseHandler2 = ({
|
|
715
|
-
errorSchema,
|
|
716
|
-
errorToMessage: errorToMessage2,
|
|
717
|
-
isRetryable
|
|
718
|
-
}) => async ({ response, url, requestBodyValues }) => {
|
|
719
|
-
const responseBody = await response.text();
|
|
720
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
721
|
-
if (responseBody.trim() === "") {
|
|
722
|
-
return {
|
|
723
|
-
responseHeaders,
|
|
724
|
-
value: new APICallError2({
|
|
725
|
-
message: response.statusText,
|
|
726
|
-
url,
|
|
727
|
-
requestBodyValues,
|
|
728
|
-
statusCode: response.status,
|
|
729
|
-
responseHeaders,
|
|
730
|
-
responseBody,
|
|
731
|
-
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
732
|
-
})
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
try {
|
|
736
|
-
const parsedError = await parseJSON({
|
|
737
|
-
text: responseBody,
|
|
738
|
-
schema: errorSchema
|
|
739
|
-
});
|
|
740
|
-
return {
|
|
741
|
-
responseHeaders,
|
|
742
|
-
value: new APICallError2({
|
|
743
|
-
message: errorToMessage2(parsedError),
|
|
744
|
-
url,
|
|
745
|
-
requestBodyValues,
|
|
746
|
-
statusCode: response.status,
|
|
747
|
-
responseHeaders,
|
|
748
|
-
responseBody,
|
|
749
|
-
data: parsedError,
|
|
750
|
-
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
751
|
-
})
|
|
752
|
-
};
|
|
753
|
-
} catch (parseError) {
|
|
754
|
-
return {
|
|
755
|
-
responseHeaders,
|
|
756
|
-
value: new APICallError2({
|
|
757
|
-
message: response.statusText,
|
|
758
|
-
url,
|
|
759
|
-
requestBodyValues,
|
|
760
|
-
statusCode: response.status,
|
|
761
|
-
responseHeaders,
|
|
762
|
-
responseBody,
|
|
763
|
-
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
764
|
-
})
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
var createEventSourceResponseHandler2 = (chunkSchema) => async ({ response }) => {
|
|
769
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
770
|
-
if (response.body == null) {
|
|
771
|
-
throw new EmptyResponseBodyError2({});
|
|
772
|
-
}
|
|
773
|
-
return {
|
|
774
|
-
responseHeaders,
|
|
775
|
-
value: parseJsonEventStream({
|
|
776
|
-
stream: response.body,
|
|
777
|
-
schema: chunkSchema
|
|
778
|
-
})
|
|
779
|
-
};
|
|
780
|
-
};
|
|
781
|
-
var createJsonResponseHandler2 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
782
|
-
const responseBody = await response.text();
|
|
783
|
-
const parsedResult = await safeParseJSON({
|
|
784
|
-
text: responseBody,
|
|
785
|
-
schema: responseSchema
|
|
786
|
-
});
|
|
787
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
788
|
-
if (!parsedResult.success) {
|
|
789
|
-
throw new APICallError2({
|
|
790
|
-
message: "Invalid JSON response",
|
|
791
|
-
cause: parsedResult.error,
|
|
792
|
-
statusCode: response.status,
|
|
793
|
-
responseHeaders,
|
|
794
|
-
responseBody,
|
|
795
|
-
url,
|
|
796
|
-
requestBodyValues
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
return {
|
|
800
|
-
responseHeaders,
|
|
801
|
-
value: parsedResult.value,
|
|
802
|
-
rawValue: parsedResult.rawValue
|
|
803
|
-
};
|
|
804
|
-
};
|
|
805
|
-
new Set(
|
|
806
|
-
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
807
|
-
);
|
|
808
|
-
var { btoa} = globalThis;
|
|
809
|
-
function convertUint8ArrayToBase64(array) {
|
|
810
|
-
let latin1string = "";
|
|
811
|
-
for (let i = 0; i < array.length; i++) {
|
|
812
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
813
|
-
}
|
|
814
|
-
return btoa(latin1string);
|
|
815
|
-
}
|
|
816
|
-
function convertToBase642(value) {
|
|
817
|
-
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
818
|
-
}
|
|
819
|
-
function withoutTrailingSlash2(url) {
|
|
820
|
-
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
821
|
-
}
|
|
822
6
|
function getOpenAIMetadata(message) {
|
|
823
|
-
var
|
|
824
|
-
return (
|
|
7
|
+
var _a15, _b;
|
|
8
|
+
return (_b = (_a15 = message == null ? void 0 : message.providerOptions) == null ? void 0 : _a15.openaiCompatible) != null ? _b : {};
|
|
825
9
|
}
|
|
826
10
|
function convertToOpenAICompatibleChatMessages(prompt) {
|
|
827
11
|
const messages = [];
|
|
@@ -855,12 +39,12 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
855
39
|
return {
|
|
856
40
|
type: "image_url",
|
|
857
41
|
image_url: {
|
|
858
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
42
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
859
43
|
},
|
|
860
44
|
...partMetadata
|
|
861
45
|
};
|
|
862
46
|
} else {
|
|
863
|
-
throw new
|
|
47
|
+
throw new UnsupportedFunctionalityError({
|
|
864
48
|
functionality: `file part media type ${part.mediaType}`
|
|
865
49
|
});
|
|
866
50
|
}
|
|
@@ -1036,7 +220,7 @@ function prepareTools({
|
|
|
1036
220
|
};
|
|
1037
221
|
default: {
|
|
1038
222
|
const _exhaustiveCheck = type;
|
|
1039
|
-
throw new
|
|
223
|
+
throw new UnsupportedFunctionalityError({
|
|
1040
224
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1041
225
|
});
|
|
1042
226
|
}
|
|
@@ -1046,15 +230,15 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1046
230
|
// type inferred via constructor
|
|
1047
231
|
constructor(modelId, config) {
|
|
1048
232
|
this.specificationVersion = "v2";
|
|
1049
|
-
var
|
|
233
|
+
var _a15, _b;
|
|
1050
234
|
this.modelId = modelId;
|
|
1051
235
|
this.config = config;
|
|
1052
|
-
const errorStructure = (
|
|
236
|
+
const errorStructure = (_a15 = config.errorStructure) != null ? _a15 : defaultOpenAICompatibleErrorStructure;
|
|
1053
237
|
this.chunkSchema = createOpenAICompatibleChatChunkSchema(
|
|
1054
238
|
errorStructure.errorSchema
|
|
1055
239
|
);
|
|
1056
|
-
this.failedResponseHandler =
|
|
1057
|
-
this.supportsStructuredOutputs = (
|
|
240
|
+
this.failedResponseHandler = createJsonErrorResponseHandler(errorStructure);
|
|
241
|
+
this.supportsStructuredOutputs = (_b = config.supportsStructuredOutputs) != null ? _b : false;
|
|
1058
242
|
}
|
|
1059
243
|
get provider() {
|
|
1060
244
|
return this.config.provider;
|
|
@@ -1063,8 +247,8 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1063
247
|
return this.config.provider.split(".")[0].trim();
|
|
1064
248
|
}
|
|
1065
249
|
get supportedUrls() {
|
|
1066
|
-
var
|
|
1067
|
-
return (_c = (
|
|
250
|
+
var _a15, _b, _c;
|
|
251
|
+
return (_c = (_b = (_a15 = this.config).supportedUrls) == null ? void 0 : _b.call(_a15)) != null ? _c : {};
|
|
1068
252
|
}
|
|
1069
253
|
async getArgs({
|
|
1070
254
|
prompt,
|
|
@@ -1081,19 +265,19 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1081
265
|
toolChoice,
|
|
1082
266
|
tools
|
|
1083
267
|
}) {
|
|
1084
|
-
var
|
|
268
|
+
var _a15, _b, _c, _d;
|
|
1085
269
|
const warnings = [];
|
|
1086
270
|
const compatibleOptions = Object.assign(
|
|
1087
|
-
(
|
|
271
|
+
(_a15 = await parseProviderOptions({
|
|
1088
272
|
provider: "openai-compatible",
|
|
1089
273
|
providerOptions,
|
|
1090
274
|
schema: openaiCompatibleProviderOptions
|
|
1091
|
-
})) != null ?
|
|
1092
|
-
(
|
|
275
|
+
})) != null ? _a15 : {},
|
|
276
|
+
(_b = await parseProviderOptions({
|
|
1093
277
|
provider: this.providerOptionsName,
|
|
1094
278
|
providerOptions,
|
|
1095
279
|
schema: openaiCompatibleProviderOptions
|
|
1096
|
-
})) != null ?
|
|
280
|
+
})) != null ? _b : {}
|
|
1097
281
|
);
|
|
1098
282
|
if (topK != null) {
|
|
1099
283
|
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
@@ -1154,22 +338,22 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1154
338
|
};
|
|
1155
339
|
}
|
|
1156
340
|
async doGenerate(options) {
|
|
1157
|
-
var
|
|
341
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1158
342
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
1159
343
|
const body = JSON.stringify(args);
|
|
1160
344
|
const {
|
|
1161
345
|
responseHeaders,
|
|
1162
346
|
value: responseBody,
|
|
1163
347
|
rawValue: rawResponse
|
|
1164
|
-
} = await
|
|
348
|
+
} = await postJsonToApi({
|
|
1165
349
|
url: this.config.url({
|
|
1166
350
|
path: "/chat/completions",
|
|
1167
351
|
modelId: this.modelId
|
|
1168
352
|
}),
|
|
1169
|
-
headers:
|
|
353
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1170
354
|
body: args,
|
|
1171
355
|
failedResponseHandler: this.failedResponseHandler,
|
|
1172
|
-
successfulResponseHandler:
|
|
356
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1173
357
|
OpenAICompatibleChatResponseSchema
|
|
1174
358
|
),
|
|
1175
359
|
abortSignal: options.abortSignal,
|
|
@@ -1181,7 +365,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1181
365
|
if (text != null && text.length > 0) {
|
|
1182
366
|
content.push({ type: "text", text });
|
|
1183
367
|
}
|
|
1184
|
-
const reasoning = (
|
|
368
|
+
const reasoning = (_a15 = choice.message.reasoning_content) != null ? _a15 : choice.message.reasoning;
|
|
1185
369
|
if (reasoning != null && reasoning.length > 0) {
|
|
1186
370
|
content.push({
|
|
1187
371
|
type: "reasoning",
|
|
@@ -1192,7 +376,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1192
376
|
for (const toolCall of choice.message.tool_calls) {
|
|
1193
377
|
content.push({
|
|
1194
378
|
type: "tool-call",
|
|
1195
|
-
toolCallId: (
|
|
379
|
+
toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
|
|
1196
380
|
toolName: toolCall.function.name,
|
|
1197
381
|
input: toolCall.function.arguments
|
|
1198
382
|
});
|
|
@@ -1232,7 +416,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1232
416
|
};
|
|
1233
417
|
}
|
|
1234
418
|
async doStream(options) {
|
|
1235
|
-
var
|
|
419
|
+
var _a15;
|
|
1236
420
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
1237
421
|
const body = {
|
|
1238
422
|
...args,
|
|
@@ -1240,16 +424,16 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1240
424
|
// only include stream_options when in strict compatibility mode:
|
|
1241
425
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
1242
426
|
};
|
|
1243
|
-
const metadataExtractor = (
|
|
1244
|
-
const { responseHeaders, value: response } = await
|
|
427
|
+
const metadataExtractor = (_a15 = this.config.metadataExtractor) == null ? void 0 : _a15.createStreamExtractor();
|
|
428
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1245
429
|
url: this.config.url({
|
|
1246
430
|
path: "/chat/completions",
|
|
1247
431
|
modelId: this.modelId
|
|
1248
432
|
}),
|
|
1249
|
-
headers:
|
|
433
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1250
434
|
body,
|
|
1251
435
|
failedResponseHandler: this.failedResponseHandler,
|
|
1252
|
-
successfulResponseHandler:
|
|
436
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
1253
437
|
this.chunkSchema
|
|
1254
438
|
),
|
|
1255
439
|
abortSignal: options.abortSignal,
|
|
@@ -1282,7 +466,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1282
466
|
},
|
|
1283
467
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
|
1284
468
|
transform(chunk, controller) {
|
|
1285
|
-
var
|
|
469
|
+
var _a22, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1286
470
|
if (options.includeRawChunks) {
|
|
1287
471
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1288
472
|
}
|
|
@@ -1339,7 +523,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1339
523
|
return;
|
|
1340
524
|
}
|
|
1341
525
|
const delta = choice.delta;
|
|
1342
|
-
const reasoningContent = (
|
|
526
|
+
const reasoningContent = (_a22 = delta.reasoning_content) != null ? _a22 : delta.reasoning;
|
|
1343
527
|
if (reasoningContent) {
|
|
1344
528
|
if (!isActiveReasoning) {
|
|
1345
529
|
controller.enqueue({
|
|
@@ -1370,13 +554,13 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1370
554
|
const index = toolCallDelta.index;
|
|
1371
555
|
if (toolCalls[index] == null) {
|
|
1372
556
|
if (toolCallDelta.id == null) {
|
|
1373
|
-
throw new
|
|
557
|
+
throw new InvalidResponseDataError({
|
|
1374
558
|
data: toolCallDelta,
|
|
1375
559
|
message: `Expected 'id' to be a string.`
|
|
1376
560
|
});
|
|
1377
561
|
}
|
|
1378
|
-
if (((
|
|
1379
|
-
throw new
|
|
562
|
+
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
|
563
|
+
throw new InvalidResponseDataError({
|
|
1380
564
|
data: toolCallDelta,
|
|
1381
565
|
message: `Expected 'function.name' to be a string.`
|
|
1382
566
|
});
|
|
@@ -1411,7 +595,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1411
595
|
});
|
|
1412
596
|
controller.enqueue({
|
|
1413
597
|
type: "tool-call",
|
|
1414
|
-
toolCallId: (_f = toolCall2.id) != null ? _f :
|
|
598
|
+
toolCallId: (_f = toolCall2.id) != null ? _f : generateId(),
|
|
1415
599
|
toolName: toolCall2.function.name,
|
|
1416
600
|
input: toolCall2.function.arguments
|
|
1417
601
|
});
|
|
@@ -1439,7 +623,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1439
623
|
});
|
|
1440
624
|
controller.enqueue({
|
|
1441
625
|
type: "tool-call",
|
|
1442
|
-
toolCallId: (_m = toolCall.id) != null ? _m :
|
|
626
|
+
toolCallId: (_m = toolCall.id) != null ? _m : generateId(),
|
|
1443
627
|
toolName: toolCall.function.name,
|
|
1444
628
|
input: toolCall.function.arguments
|
|
1445
629
|
});
|
|
@@ -1449,7 +633,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1449
633
|
}
|
|
1450
634
|
},
|
|
1451
635
|
flush(controller) {
|
|
1452
|
-
var
|
|
636
|
+
var _a22, _b, _c, _d, _e, _f;
|
|
1453
637
|
if (isActiveReasoning) {
|
|
1454
638
|
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
1455
639
|
}
|
|
@@ -1465,7 +649,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1465
649
|
});
|
|
1466
650
|
controller.enqueue({
|
|
1467
651
|
type: "tool-call",
|
|
1468
|
-
toolCallId: (
|
|
652
|
+
toolCallId: (_a22 = toolCall.id) != null ? _a22 : generateId(),
|
|
1469
653
|
toolName: toolCall.function.name,
|
|
1470
654
|
input: toolCall.function.arguments
|
|
1471
655
|
});
|
|
@@ -1484,7 +668,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
1484
668
|
type: "finish",
|
|
1485
669
|
finishReason,
|
|
1486
670
|
usage: {
|
|
1487
|
-
inputTokens: (
|
|
671
|
+
inputTokens: (_b = usage.promptTokens) != null ? _b : void 0,
|
|
1488
672
|
outputTokens: (_c = usage.completionTokens) != null ? _c : void 0,
|
|
1489
673
|
totalTokens: (_d = usage.totalTokens) != null ? _d : void 0,
|
|
1490
674
|
reasoningTokens: (_e = usage.completionTokensDetails.reasoningTokens) != null ? _e : void 0,
|
|
@@ -1612,7 +796,7 @@ ${userMessage}
|
|
|
1612
796
|
return part.text;
|
|
1613
797
|
}
|
|
1614
798
|
case "tool-call": {
|
|
1615
|
-
throw new
|
|
799
|
+
throw new UnsupportedFunctionalityError({
|
|
1616
800
|
functionality: "tool-call messages"
|
|
1617
801
|
});
|
|
1618
802
|
}
|
|
@@ -1625,7 +809,7 @@ ${assistantMessage}
|
|
|
1625
809
|
break;
|
|
1626
810
|
}
|
|
1627
811
|
case "tool": {
|
|
1628
|
-
throw new
|
|
812
|
+
throw new UnsupportedFunctionalityError({
|
|
1629
813
|
functionality: "tool messages"
|
|
1630
814
|
});
|
|
1631
815
|
}
|
|
@@ -1695,14 +879,14 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1695
879
|
// type inferred via constructor
|
|
1696
880
|
constructor(modelId, config) {
|
|
1697
881
|
this.specificationVersion = "v2";
|
|
1698
|
-
var
|
|
882
|
+
var _a15;
|
|
1699
883
|
this.modelId = modelId;
|
|
1700
884
|
this.config = config;
|
|
1701
|
-
const errorStructure = (
|
|
885
|
+
const errorStructure = (_a15 = config.errorStructure) != null ? _a15 : defaultOpenAICompatibleErrorStructure;
|
|
1702
886
|
this.chunkSchema = createOpenAICompatibleCompletionChunkSchema(
|
|
1703
887
|
errorStructure.errorSchema
|
|
1704
888
|
);
|
|
1705
|
-
this.failedResponseHandler =
|
|
889
|
+
this.failedResponseHandler = createJsonErrorResponseHandler(errorStructure);
|
|
1706
890
|
}
|
|
1707
891
|
get provider() {
|
|
1708
892
|
return this.config.provider;
|
|
@@ -1711,8 +895,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1711
895
|
return this.config.provider.split(".")[0].trim();
|
|
1712
896
|
}
|
|
1713
897
|
get supportedUrls() {
|
|
1714
|
-
var
|
|
1715
|
-
return (_c = (
|
|
898
|
+
var _a15, _b, _c;
|
|
899
|
+
return (_c = (_b = (_a15 = this.config).supportedUrls) == null ? void 0 : _b.call(_a15)) != null ? _c : {};
|
|
1716
900
|
}
|
|
1717
901
|
async getArgs({
|
|
1718
902
|
prompt,
|
|
@@ -1729,13 +913,13 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1729
913
|
tools,
|
|
1730
914
|
toolChoice
|
|
1731
915
|
}) {
|
|
1732
|
-
var
|
|
916
|
+
var _a15;
|
|
1733
917
|
const warnings = [];
|
|
1734
|
-
const completionOptions = (
|
|
918
|
+
const completionOptions = (_a15 = await parseProviderOptions({
|
|
1735
919
|
provider: this.providerOptionsName,
|
|
1736
920
|
providerOptions,
|
|
1737
921
|
schema: openaiCompatibleCompletionProviderOptions
|
|
1738
|
-
})) != null ?
|
|
922
|
+
})) != null ? _a15 : {};
|
|
1739
923
|
if (topK != null) {
|
|
1740
924
|
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1741
925
|
}
|
|
@@ -1780,21 +964,21 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1780
964
|
};
|
|
1781
965
|
}
|
|
1782
966
|
async doGenerate(options) {
|
|
1783
|
-
var
|
|
967
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1784
968
|
const { args, warnings } = await this.getArgs(options);
|
|
1785
969
|
const {
|
|
1786
970
|
responseHeaders,
|
|
1787
971
|
value: response,
|
|
1788
972
|
rawValue: rawResponse
|
|
1789
|
-
} = await
|
|
973
|
+
} = await postJsonToApi({
|
|
1790
974
|
url: this.config.url({
|
|
1791
975
|
path: "/completions",
|
|
1792
976
|
modelId: this.modelId
|
|
1793
977
|
}),
|
|
1794
|
-
headers:
|
|
978
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1795
979
|
body: args,
|
|
1796
980
|
failedResponseHandler: this.failedResponseHandler,
|
|
1797
|
-
successfulResponseHandler:
|
|
981
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
1798
982
|
openaiCompatibleCompletionResponseSchema
|
|
1799
983
|
),
|
|
1800
984
|
abortSignal: options.abortSignal,
|
|
@@ -1808,7 +992,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1808
992
|
return {
|
|
1809
993
|
content,
|
|
1810
994
|
usage: {
|
|
1811
|
-
inputTokens: (
|
|
995
|
+
inputTokens: (_b = (_a15 = response.usage) == null ? void 0 : _a15.prompt_tokens) != null ? _b : void 0,
|
|
1812
996
|
outputTokens: (_d = (_c = response.usage) == null ? void 0 : _c.completion_tokens) != null ? _d : void 0,
|
|
1813
997
|
totalTokens: (_f = (_e = response.usage) == null ? void 0 : _e.total_tokens) != null ? _f : void 0
|
|
1814
998
|
},
|
|
@@ -1830,15 +1014,15 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1830
1014
|
// only include stream_options when in strict compatibility mode:
|
|
1831
1015
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
1832
1016
|
};
|
|
1833
|
-
const { responseHeaders, value: response } = await
|
|
1017
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1834
1018
|
url: this.config.url({
|
|
1835
1019
|
path: "/completions",
|
|
1836
1020
|
modelId: this.modelId
|
|
1837
1021
|
}),
|
|
1838
|
-
headers:
|
|
1022
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1839
1023
|
body,
|
|
1840
1024
|
failedResponseHandler: this.failedResponseHandler,
|
|
1841
|
-
successfulResponseHandler:
|
|
1025
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
1842
1026
|
this.chunkSchema
|
|
1843
1027
|
),
|
|
1844
1028
|
abortSignal: options.abortSignal,
|
|
@@ -1858,7 +1042,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1858
1042
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1859
1043
|
},
|
|
1860
1044
|
transform(chunk, controller) {
|
|
1861
|
-
var
|
|
1045
|
+
var _a15, _b, _c;
|
|
1862
1046
|
if (options.includeRawChunks) {
|
|
1863
1047
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1864
1048
|
}
|
|
@@ -1885,8 +1069,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
|
|
|
1885
1069
|
});
|
|
1886
1070
|
}
|
|
1887
1071
|
if (value.usage != null) {
|
|
1888
|
-
usage.inputTokens = (
|
|
1889
|
-
usage.outputTokens = (
|
|
1072
|
+
usage.inputTokens = (_a15 = value.usage.prompt_tokens) != null ? _a15 : void 0;
|
|
1073
|
+
usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
|
|
1890
1074
|
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
|
|
1891
1075
|
}
|
|
1892
1076
|
const choice = value.choices[0];
|
|
@@ -1975,12 +1159,12 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1975
1159
|
return this.config.provider;
|
|
1976
1160
|
}
|
|
1977
1161
|
get maxEmbeddingsPerCall() {
|
|
1978
|
-
var
|
|
1979
|
-
return (
|
|
1162
|
+
var _a15;
|
|
1163
|
+
return (_a15 = this.config.maxEmbeddingsPerCall) != null ? _a15 : 2048;
|
|
1980
1164
|
}
|
|
1981
1165
|
get supportsParallelCalls() {
|
|
1982
|
-
var
|
|
1983
|
-
return (
|
|
1166
|
+
var _a15;
|
|
1167
|
+
return (_a15 = this.config.supportsParallelCalls) != null ? _a15 : true;
|
|
1984
1168
|
}
|
|
1985
1169
|
get providerOptionsName() {
|
|
1986
1170
|
return this.config.provider.split(".")[0].trim();
|
|
@@ -1991,21 +1175,21 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
1991
1175
|
abortSignal,
|
|
1992
1176
|
providerOptions
|
|
1993
1177
|
}) {
|
|
1994
|
-
var
|
|
1178
|
+
var _a15, _b, _c;
|
|
1995
1179
|
const compatibleOptions = Object.assign(
|
|
1996
|
-
(
|
|
1180
|
+
(_a15 = await parseProviderOptions({
|
|
1997
1181
|
provider: "openai-compatible",
|
|
1998
1182
|
providerOptions,
|
|
1999
1183
|
schema: openaiCompatibleEmbeddingProviderOptions
|
|
2000
|
-
})) != null ?
|
|
2001
|
-
(
|
|
1184
|
+
})) != null ? _a15 : {},
|
|
1185
|
+
(_b = await parseProviderOptions({
|
|
2002
1186
|
provider: this.providerOptionsName,
|
|
2003
1187
|
providerOptions,
|
|
2004
1188
|
schema: openaiCompatibleEmbeddingProviderOptions
|
|
2005
|
-
})) != null ?
|
|
1189
|
+
})) != null ? _b : {}
|
|
2006
1190
|
);
|
|
2007
1191
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
2008
|
-
throw new
|
|
1192
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
2009
1193
|
provider: this.provider,
|
|
2010
1194
|
modelId: this.modelId,
|
|
2011
1195
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -2016,12 +1200,12 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
2016
1200
|
responseHeaders,
|
|
2017
1201
|
value: response,
|
|
2018
1202
|
rawValue
|
|
2019
|
-
} = await
|
|
1203
|
+
} = await postJsonToApi({
|
|
2020
1204
|
url: this.config.url({
|
|
2021
1205
|
path: "/embeddings",
|
|
2022
1206
|
modelId: this.modelId
|
|
2023
1207
|
}),
|
|
2024
|
-
headers:
|
|
1208
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
2025
1209
|
body: {
|
|
2026
1210
|
model: this.modelId,
|
|
2027
1211
|
input: values,
|
|
@@ -2029,10 +1213,10 @@ var OpenAICompatibleEmbeddingModel = class {
|
|
|
2029
1213
|
dimensions: compatibleOptions.dimensions,
|
|
2030
1214
|
user: compatibleOptions.user
|
|
2031
1215
|
},
|
|
2032
|
-
failedResponseHandler:
|
|
1216
|
+
failedResponseHandler: createJsonErrorResponseHandler(
|
|
2033
1217
|
(_c = this.config.errorStructure) != null ? _c : defaultOpenAICompatibleErrorStructure
|
|
2034
1218
|
),
|
|
2035
|
-
successfulResponseHandler:
|
|
1219
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
2036
1220
|
openaiTextEmbeddingResponseSchema
|
|
2037
1221
|
),
|
|
2038
1222
|
abortSignal,
|
|
@@ -2054,7 +1238,7 @@ var openaiTextEmbeddingResponseSchema = z.object({
|
|
|
2054
1238
|
z.object({
|
|
2055
1239
|
data: z.array(z.object({ b64_json: z.string() }))
|
|
2056
1240
|
});
|
|
2057
|
-
var
|
|
1241
|
+
var VERSION = "1.0.35" ;
|
|
2058
1242
|
var cerebrasErrorSchema = z.object({
|
|
2059
1243
|
message: z.string(),
|
|
2060
1244
|
type: z.string(),
|
|
@@ -2066,20 +1250,20 @@ var cerebrasErrorStructure = {
|
|
|
2066
1250
|
errorToMessage: (data) => data.message
|
|
2067
1251
|
};
|
|
2068
1252
|
function createCerebras(options = {}) {
|
|
2069
|
-
var
|
|
2070
|
-
const baseURL =
|
|
2071
|
-
(
|
|
1253
|
+
var _a15;
|
|
1254
|
+
const baseURL = withoutTrailingSlash(
|
|
1255
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.cerebras.ai/v1"
|
|
2072
1256
|
);
|
|
2073
|
-
const getHeaders = () =>
|
|
1257
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
2074
1258
|
{
|
|
2075
|
-
Authorization: `Bearer ${
|
|
1259
|
+
Authorization: `Bearer ${loadApiKey({
|
|
2076
1260
|
apiKey: options.apiKey,
|
|
2077
1261
|
environmentVariableName: "CEREBRAS_API_KEY",
|
|
2078
1262
|
description: "Cerebras API key"
|
|
2079
1263
|
})}`,
|
|
2080
1264
|
...options.headers
|
|
2081
1265
|
},
|
|
2082
|
-
`ai-sdk/cerebras/${
|
|
1266
|
+
`ai-sdk/cerebras/${VERSION}`
|
|
2083
1267
|
);
|
|
2084
1268
|
const createLanguageModel = (modelId) => {
|
|
2085
1269
|
return new OpenAICompatibleChatLanguageModel(modelId, {
|
|
@@ -2095,10 +1279,10 @@ function createCerebras(options = {}) {
|
|
|
2095
1279
|
provider.languageModel = createLanguageModel;
|
|
2096
1280
|
provider.chat = createLanguageModel;
|
|
2097
1281
|
provider.textEmbeddingModel = (modelId) => {
|
|
2098
|
-
throw new
|
|
1282
|
+
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
2099
1283
|
};
|
|
2100
1284
|
provider.imageModel = (modelId) => {
|
|
2101
|
-
throw new
|
|
1285
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
2102
1286
|
};
|
|
2103
1287
|
return provider;
|
|
2104
1288
|
}
|
|
@@ -2123,13 +1307,13 @@ var DeepInfraImageModel = class {
|
|
|
2123
1307
|
headers,
|
|
2124
1308
|
abortSignal
|
|
2125
1309
|
}) {
|
|
2126
|
-
var
|
|
1310
|
+
var _a15, _b, _c, _d;
|
|
2127
1311
|
const warnings = [];
|
|
2128
1312
|
const splitSize = size == null ? void 0 : size.split("x");
|
|
2129
|
-
const currentDate = (_c = (
|
|
2130
|
-
const { value: response, responseHeaders } = await
|
|
1313
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1314
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
2131
1315
|
url: `${this.config.baseURL}/${this.modelId}`,
|
|
2132
|
-
headers:
|
|
1316
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
2133
1317
|
body: {
|
|
2134
1318
|
prompt,
|
|
2135
1319
|
num_images: n,
|
|
@@ -2138,11 +1322,11 @@ var DeepInfraImageModel = class {
|
|
|
2138
1322
|
...seed != null && { seed },
|
|
2139
1323
|
...(_d = providerOptions.deepinfra) != null ? _d : {}
|
|
2140
1324
|
},
|
|
2141
|
-
failedResponseHandler:
|
|
1325
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
2142
1326
|
errorSchema: deepInfraErrorSchema,
|
|
2143
1327
|
errorToMessage: (error) => error.detail.error
|
|
2144
1328
|
}),
|
|
2145
|
-
successfulResponseHandler:
|
|
1329
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
2146
1330
|
deepInfraImageResponseSchema
|
|
2147
1331
|
),
|
|
2148
1332
|
abortSignal,
|
|
@@ -2169,22 +1353,22 @@ var deepInfraErrorSchema = z.object({
|
|
|
2169
1353
|
var deepInfraImageResponseSchema = z.object({
|
|
2170
1354
|
images: z.array(z.string())
|
|
2171
1355
|
});
|
|
2172
|
-
var
|
|
1356
|
+
var VERSION2 = "1.0.32" ;
|
|
2173
1357
|
function createDeepInfra(options = {}) {
|
|
2174
|
-
var
|
|
2175
|
-
const baseURL =
|
|
2176
|
-
(
|
|
1358
|
+
var _a15;
|
|
1359
|
+
const baseURL = withoutTrailingSlash(
|
|
1360
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.deepinfra.com/v1"
|
|
2177
1361
|
);
|
|
2178
|
-
const getHeaders = () =>
|
|
1362
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
2179
1363
|
{
|
|
2180
|
-
Authorization: `Bearer ${
|
|
1364
|
+
Authorization: `Bearer ${loadApiKey({
|
|
2181
1365
|
apiKey: options.apiKey,
|
|
2182
1366
|
environmentVariableName: "DEEPINFRA_API_KEY",
|
|
2183
1367
|
description: "DeepInfra's API key"
|
|
2184
1368
|
})}`,
|
|
2185
1369
|
...options.headers
|
|
2186
1370
|
},
|
|
2187
|
-
`ai-sdk/deepinfra/${
|
|
1371
|
+
`ai-sdk/deepinfra/${VERSION2}`
|
|
2188
1372
|
);
|
|
2189
1373
|
const getCommonModelConfig = (modelType) => ({
|
|
2190
1374
|
provider: `deepinfra.${modelType}`,
|
|
@@ -2229,10 +1413,10 @@ function combineHeaders3(...headers) {
|
|
|
2229
1413
|
{}
|
|
2230
1414
|
);
|
|
2231
1415
|
}
|
|
2232
|
-
function
|
|
1416
|
+
function extractResponseHeaders(response) {
|
|
2233
1417
|
return Object.fromEntries([...response.headers]);
|
|
2234
1418
|
}
|
|
2235
|
-
var
|
|
1419
|
+
var createIdGenerator = ({
|
|
2236
1420
|
prefix,
|
|
2237
1421
|
size = 16,
|
|
2238
1422
|
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
@@ -2257,21 +1441,21 @@ var createIdGenerator2 = ({
|
|
|
2257
1441
|
}
|
|
2258
1442
|
return () => `${prefix}${separator}${generator()}`;
|
|
2259
1443
|
};
|
|
2260
|
-
var generateId3 =
|
|
2261
|
-
function
|
|
1444
|
+
var generateId3 = createIdGenerator();
|
|
1445
|
+
function isAbortError(error) {
|
|
2262
1446
|
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
2263
1447
|
error.name === "TimeoutError");
|
|
2264
1448
|
}
|
|
2265
|
-
var
|
|
2266
|
-
function
|
|
1449
|
+
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
1450
|
+
function handleFetchError({
|
|
2267
1451
|
error,
|
|
2268
1452
|
url,
|
|
2269
1453
|
requestBodyValues
|
|
2270
1454
|
}) {
|
|
2271
|
-
if (
|
|
1455
|
+
if (isAbortError(error)) {
|
|
2272
1456
|
return error;
|
|
2273
1457
|
}
|
|
2274
|
-
if (error instanceof TypeError &&
|
|
1458
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
2275
1459
|
const cause = error.cause;
|
|
2276
1460
|
if (cause != null) {
|
|
2277
1461
|
return new APICallError({
|
|
@@ -2286,15 +1470,15 @@ function handleFetchError2({
|
|
|
2286
1470
|
}
|
|
2287
1471
|
return error;
|
|
2288
1472
|
}
|
|
2289
|
-
function
|
|
2290
|
-
var
|
|
1473
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
1474
|
+
var _a15, _b, _c;
|
|
2291
1475
|
if (globalThisAny.window) {
|
|
2292
1476
|
return `runtime/browser`;
|
|
2293
1477
|
}
|
|
2294
|
-
if ((
|
|
1478
|
+
if ((_a15 = globalThisAny.navigator) == null ? void 0 : _a15.userAgent) {
|
|
2295
1479
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
2296
1480
|
}
|
|
2297
|
-
if ((_c = (
|
|
1481
|
+
if ((_c = (_b = globalThisAny.process) == null ? void 0 : _b.versions) == null ? void 0 : _c.node) {
|
|
2298
1482
|
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
2299
1483
|
}
|
|
2300
1484
|
if (globalThisAny.EdgeRuntime) {
|
|
@@ -2302,7 +1486,7 @@ function getRuntimeEnvironmentUserAgent2(globalThisAny = globalThis) {
|
|
|
2302
1486
|
}
|
|
2303
1487
|
return "runtime/unknown";
|
|
2304
1488
|
}
|
|
2305
|
-
function
|
|
1489
|
+
function normalizeHeaders(headers) {
|
|
2306
1490
|
if (headers == null) {
|
|
2307
1491
|
return {};
|
|
2308
1492
|
}
|
|
@@ -2324,7 +1508,7 @@ function normalizeHeaders2(headers) {
|
|
|
2324
1508
|
return normalized;
|
|
2325
1509
|
}
|
|
2326
1510
|
function withUserAgentSuffix3(headers, ...userAgentSuffixParts) {
|
|
2327
|
-
const normalizedHeaders = new Headers(
|
|
1511
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
2328
1512
|
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
2329
1513
|
normalizedHeaders.set(
|
|
2330
1514
|
"user-agent",
|
|
@@ -2332,7 +1516,7 @@ function withUserAgentSuffix3(headers, ...userAgentSuffixParts) {
|
|
|
2332
1516
|
);
|
|
2333
1517
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
2334
1518
|
}
|
|
2335
|
-
var
|
|
1519
|
+
var VERSION3 = "3.0.18" ;
|
|
2336
1520
|
function loadApiKey3({
|
|
2337
1521
|
apiKey,
|
|
2338
1522
|
environmentVariableName,
|
|
@@ -2365,19 +1549,19 @@ function loadApiKey3({
|
|
|
2365
1549
|
}
|
|
2366
1550
|
return apiKey;
|
|
2367
1551
|
}
|
|
2368
|
-
var
|
|
2369
|
-
var
|
|
2370
|
-
function
|
|
1552
|
+
var suspectProtoRx = /"__proto__"\s*:/;
|
|
1553
|
+
var suspectConstructorRx = /"constructor"\s*:/;
|
|
1554
|
+
function _parse(text) {
|
|
2371
1555
|
const obj = JSON.parse(text);
|
|
2372
1556
|
if (obj === null || typeof obj !== "object") {
|
|
2373
1557
|
return obj;
|
|
2374
1558
|
}
|
|
2375
|
-
if (
|
|
1559
|
+
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
2376
1560
|
return obj;
|
|
2377
1561
|
}
|
|
2378
|
-
return
|
|
1562
|
+
return filter(obj);
|
|
2379
1563
|
}
|
|
2380
|
-
function
|
|
1564
|
+
function filter(obj) {
|
|
2381
1565
|
let next = [obj];
|
|
2382
1566
|
while (next.length) {
|
|
2383
1567
|
const nodes = next;
|
|
@@ -2399,31 +1583,31 @@ function filter2(obj) {
|
|
|
2399
1583
|
}
|
|
2400
1584
|
return obj;
|
|
2401
1585
|
}
|
|
2402
|
-
function
|
|
1586
|
+
function secureJsonParse(text) {
|
|
2403
1587
|
const { stackTraceLimit } = Error;
|
|
2404
1588
|
try {
|
|
2405
1589
|
Error.stackTraceLimit = 0;
|
|
2406
1590
|
} catch (e) {
|
|
2407
|
-
return
|
|
1591
|
+
return _parse(text);
|
|
2408
1592
|
}
|
|
2409
1593
|
try {
|
|
2410
|
-
return
|
|
1594
|
+
return _parse(text);
|
|
2411
1595
|
} finally {
|
|
2412
1596
|
Error.stackTraceLimit = stackTraceLimit;
|
|
2413
1597
|
}
|
|
2414
1598
|
}
|
|
2415
|
-
var
|
|
2416
|
-
function
|
|
2417
|
-
return { [
|
|
1599
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
1600
|
+
function validator(validate) {
|
|
1601
|
+
return { [validatorSymbol]: true, validate };
|
|
2418
1602
|
}
|
|
2419
|
-
function
|
|
2420
|
-
return typeof value === "object" && value !== null &&
|
|
1603
|
+
function isValidator(value) {
|
|
1604
|
+
return typeof value === "object" && value !== null && validatorSymbol in value && value[validatorSymbol] === true && "validate" in value;
|
|
2421
1605
|
}
|
|
2422
|
-
function
|
|
2423
|
-
return
|
|
1606
|
+
function asValidator(value) {
|
|
1607
|
+
return isValidator(value) ? value : typeof value === "function" ? value() : standardSchemaValidator(value);
|
|
2424
1608
|
}
|
|
2425
|
-
function
|
|
2426
|
-
return
|
|
1609
|
+
function standardSchemaValidator(standardSchema) {
|
|
1610
|
+
return validator(async (value) => {
|
|
2427
1611
|
const result = await standardSchema["~standard"].validate(value);
|
|
2428
1612
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
2429
1613
|
success: false,
|
|
@@ -2434,21 +1618,21 @@ function standardSchemaValidator2(standardSchema) {
|
|
|
2434
1618
|
};
|
|
2435
1619
|
});
|
|
2436
1620
|
}
|
|
2437
|
-
async function
|
|
1621
|
+
async function validateTypes({
|
|
2438
1622
|
value,
|
|
2439
1623
|
schema
|
|
2440
1624
|
}) {
|
|
2441
|
-
const result = await
|
|
1625
|
+
const result = await safeValidateTypes({ value, schema });
|
|
2442
1626
|
if (!result.success) {
|
|
2443
1627
|
throw TypeValidationError.wrap({ value, cause: result.error });
|
|
2444
1628
|
}
|
|
2445
1629
|
return result.value;
|
|
2446
1630
|
}
|
|
2447
|
-
async function
|
|
1631
|
+
async function safeValidateTypes({
|
|
2448
1632
|
value,
|
|
2449
1633
|
schema
|
|
2450
1634
|
}) {
|
|
2451
|
-
const validator22 =
|
|
1635
|
+
const validator22 = asValidator(schema);
|
|
2452
1636
|
try {
|
|
2453
1637
|
if (validator22.validate == null) {
|
|
2454
1638
|
return { success: true, value, rawValue: value };
|
|
@@ -2470,16 +1654,16 @@ async function safeValidateTypes2({
|
|
|
2470
1654
|
};
|
|
2471
1655
|
}
|
|
2472
1656
|
}
|
|
2473
|
-
async function
|
|
1657
|
+
async function parseJSON({
|
|
2474
1658
|
text,
|
|
2475
1659
|
schema
|
|
2476
1660
|
}) {
|
|
2477
1661
|
try {
|
|
2478
|
-
const value =
|
|
1662
|
+
const value = secureJsonParse(text);
|
|
2479
1663
|
if (schema == null) {
|
|
2480
1664
|
return value;
|
|
2481
1665
|
}
|
|
2482
|
-
return
|
|
1666
|
+
return validateTypes({ value, schema });
|
|
2483
1667
|
} catch (error) {
|
|
2484
1668
|
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
|
|
2485
1669
|
throw error;
|
|
@@ -2487,16 +1671,16 @@ async function parseJSON2({
|
|
|
2487
1671
|
throw new JSONParseError({ text, cause: error });
|
|
2488
1672
|
}
|
|
2489
1673
|
}
|
|
2490
|
-
async function
|
|
1674
|
+
async function safeParseJSON({
|
|
2491
1675
|
text,
|
|
2492
1676
|
schema
|
|
2493
1677
|
}) {
|
|
2494
1678
|
try {
|
|
2495
|
-
const value =
|
|
1679
|
+
const value = secureJsonParse(text);
|
|
2496
1680
|
if (schema == null) {
|
|
2497
1681
|
return { success: true, value, rawValue: value };
|
|
2498
1682
|
}
|
|
2499
|
-
return await
|
|
1683
|
+
return await safeValidateTypes({ value, schema });
|
|
2500
1684
|
} catch (error) {
|
|
2501
1685
|
return {
|
|
2502
1686
|
success: false,
|
|
@@ -2507,13 +1691,13 @@ async function safeParseJSON2({
|
|
|
2507
1691
|
}
|
|
2508
1692
|
function isParsableJson2(input) {
|
|
2509
1693
|
try {
|
|
2510
|
-
|
|
1694
|
+
secureJsonParse(input);
|
|
2511
1695
|
return true;
|
|
2512
1696
|
} catch (e) {
|
|
2513
1697
|
return false;
|
|
2514
1698
|
}
|
|
2515
1699
|
}
|
|
2516
|
-
function
|
|
1700
|
+
function parseJsonEventStream({
|
|
2517
1701
|
stream,
|
|
2518
1702
|
schema
|
|
2519
1703
|
}) {
|
|
@@ -2523,7 +1707,7 @@ function parseJsonEventStream2({
|
|
|
2523
1707
|
if (data === "[DONE]") {
|
|
2524
1708
|
return;
|
|
2525
1709
|
}
|
|
2526
|
-
controller.enqueue(await
|
|
1710
|
+
controller.enqueue(await safeParseJSON({ text: data, schema }));
|
|
2527
1711
|
}
|
|
2528
1712
|
})
|
|
2529
1713
|
);
|
|
@@ -2536,7 +1720,7 @@ async function parseProviderOptions3({
|
|
|
2536
1720
|
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
|
|
2537
1721
|
return void 0;
|
|
2538
1722
|
}
|
|
2539
|
-
const parsedProviderOptions = await
|
|
1723
|
+
const parsedProviderOptions = await safeValidateTypes({
|
|
2540
1724
|
value: providerOptions[provider],
|
|
2541
1725
|
schema
|
|
2542
1726
|
});
|
|
@@ -2549,7 +1733,7 @@ async function parseProviderOptions3({
|
|
|
2549
1733
|
}
|
|
2550
1734
|
return parsedProviderOptions.value;
|
|
2551
1735
|
}
|
|
2552
|
-
var
|
|
1736
|
+
var getOriginalFetch2 = () => globalThis.fetch;
|
|
2553
1737
|
var postJsonToApi3 = async ({
|
|
2554
1738
|
url,
|
|
2555
1739
|
headers,
|
|
@@ -2558,7 +1742,7 @@ var postJsonToApi3 = async ({
|
|
|
2558
1742
|
successfulResponseHandler,
|
|
2559
1743
|
abortSignal,
|
|
2560
1744
|
fetch: fetch2
|
|
2561
|
-
}) =>
|
|
1745
|
+
}) => postToApi({
|
|
2562
1746
|
url,
|
|
2563
1747
|
headers: {
|
|
2564
1748
|
"Content-Type": "application/json",
|
|
@@ -2573,27 +1757,27 @@ var postJsonToApi3 = async ({
|
|
|
2573
1757
|
abortSignal,
|
|
2574
1758
|
fetch: fetch2
|
|
2575
1759
|
});
|
|
2576
|
-
var
|
|
1760
|
+
var postToApi = async ({
|
|
2577
1761
|
url,
|
|
2578
1762
|
headers = {},
|
|
2579
1763
|
body,
|
|
2580
1764
|
successfulResponseHandler,
|
|
2581
1765
|
failedResponseHandler,
|
|
2582
1766
|
abortSignal,
|
|
2583
|
-
fetch: fetch2 =
|
|
1767
|
+
fetch: fetch2 = getOriginalFetch2()
|
|
2584
1768
|
}) => {
|
|
2585
1769
|
try {
|
|
2586
1770
|
const response = await fetch2(url, {
|
|
2587
1771
|
method: "POST",
|
|
2588
1772
|
headers: withUserAgentSuffix3(
|
|
2589
1773
|
headers,
|
|
2590
|
-
`ai-sdk/provider-utils/${
|
|
2591
|
-
|
|
1774
|
+
`ai-sdk/provider-utils/${VERSION3}`,
|
|
1775
|
+
getRuntimeEnvironmentUserAgent()
|
|
2592
1776
|
),
|
|
2593
1777
|
body: body.content,
|
|
2594
1778
|
signal: abortSignal
|
|
2595
1779
|
});
|
|
2596
|
-
const responseHeaders =
|
|
1780
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2597
1781
|
if (!response.ok) {
|
|
2598
1782
|
let errorInformation;
|
|
2599
1783
|
try {
|
|
@@ -2603,7 +1787,7 @@ var postToApi2 = async ({
|
|
|
2603
1787
|
requestBodyValues: body.values
|
|
2604
1788
|
});
|
|
2605
1789
|
} catch (error) {
|
|
2606
|
-
if (
|
|
1790
|
+
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
2607
1791
|
throw error;
|
|
2608
1792
|
}
|
|
2609
1793
|
throw new APICallError({
|
|
@@ -2625,7 +1809,7 @@ var postToApi2 = async ({
|
|
|
2625
1809
|
});
|
|
2626
1810
|
} catch (error) {
|
|
2627
1811
|
if (error instanceof Error) {
|
|
2628
|
-
if (
|
|
1812
|
+
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
2629
1813
|
throw error;
|
|
2630
1814
|
}
|
|
2631
1815
|
}
|
|
@@ -2639,7 +1823,7 @@ var postToApi2 = async ({
|
|
|
2639
1823
|
});
|
|
2640
1824
|
}
|
|
2641
1825
|
} catch (error) {
|
|
2642
|
-
throw
|
|
1826
|
+
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
2643
1827
|
}
|
|
2644
1828
|
};
|
|
2645
1829
|
var createJsonErrorResponseHandler3 = ({
|
|
@@ -2648,7 +1832,7 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
2648
1832
|
isRetryable
|
|
2649
1833
|
}) => async ({ response, url, requestBodyValues }) => {
|
|
2650
1834
|
const responseBody = await response.text();
|
|
2651
|
-
const responseHeaders =
|
|
1835
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2652
1836
|
if (responseBody.trim() === "") {
|
|
2653
1837
|
return {
|
|
2654
1838
|
responseHeaders,
|
|
@@ -2664,7 +1848,7 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
2664
1848
|
};
|
|
2665
1849
|
}
|
|
2666
1850
|
try {
|
|
2667
|
-
const parsedError = await
|
|
1851
|
+
const parsedError = await parseJSON({
|
|
2668
1852
|
text: responseBody,
|
|
2669
1853
|
schema: errorSchema
|
|
2670
1854
|
});
|
|
@@ -2697,13 +1881,13 @@ var createJsonErrorResponseHandler3 = ({
|
|
|
2697
1881
|
}
|
|
2698
1882
|
};
|
|
2699
1883
|
var createEventSourceResponseHandler3 = (chunkSchema) => async ({ response }) => {
|
|
2700
|
-
const responseHeaders =
|
|
1884
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2701
1885
|
if (response.body == null) {
|
|
2702
1886
|
throw new EmptyResponseBodyError({});
|
|
2703
1887
|
}
|
|
2704
1888
|
return {
|
|
2705
1889
|
responseHeaders,
|
|
2706
|
-
value:
|
|
1890
|
+
value: parseJsonEventStream({
|
|
2707
1891
|
stream: response.body,
|
|
2708
1892
|
schema: chunkSchema
|
|
2709
1893
|
})
|
|
@@ -2711,11 +1895,11 @@ var createEventSourceResponseHandler3 = (chunkSchema) => async ({ response }) =>
|
|
|
2711
1895
|
};
|
|
2712
1896
|
var createJsonResponseHandler3 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
2713
1897
|
const responseBody = await response.text();
|
|
2714
|
-
const parsedResult = await
|
|
1898
|
+
const parsedResult = await safeParseJSON({
|
|
2715
1899
|
text: responseBody,
|
|
2716
1900
|
schema: responseSchema
|
|
2717
1901
|
});
|
|
2718
|
-
const responseHeaders =
|
|
1902
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2719
1903
|
if (!parsedResult.success) {
|
|
2720
1904
|
throw new APICallError({
|
|
2721
1905
|
message: "Invalid JSON response",
|
|
@@ -2775,11 +1959,11 @@ function parseAnyDef() {
|
|
|
2775
1959
|
return {};
|
|
2776
1960
|
}
|
|
2777
1961
|
function parseArrayDef(def, refs) {
|
|
2778
|
-
var
|
|
1962
|
+
var _a15, _b, _c;
|
|
2779
1963
|
const res = {
|
|
2780
1964
|
type: "array"
|
|
2781
1965
|
};
|
|
2782
|
-
if (((
|
|
1966
|
+
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) {
|
|
2783
1967
|
res.items = parseDef(def.type._def, {
|
|
2784
1968
|
...refs,
|
|
2785
1969
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -3124,13 +2308,13 @@ function parseStringDef(def, refs) {
|
|
|
3124
2308
|
function escapeLiteralCheckValue(literal, refs) {
|
|
3125
2309
|
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
3126
2310
|
}
|
|
3127
|
-
var
|
|
2311
|
+
var ALPHA_NUMERIC = new Set(
|
|
3128
2312
|
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
3129
2313
|
);
|
|
3130
2314
|
function escapeNonAlphaNumeric(source) {
|
|
3131
2315
|
let result = "";
|
|
3132
2316
|
for (let i = 0; i < source.length; i++) {
|
|
3133
|
-
if (!
|
|
2317
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
3134
2318
|
result += "\\";
|
|
3135
2319
|
}
|
|
3136
2320
|
result += source[i];
|
|
@@ -3138,8 +2322,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
3138
2322
|
return result;
|
|
3139
2323
|
}
|
|
3140
2324
|
function addFormat(schema, value, message, refs) {
|
|
3141
|
-
var
|
|
3142
|
-
if (schema.format || ((
|
|
2325
|
+
var _a15;
|
|
2326
|
+
if (schema.format || ((_a15 = schema.anyOf) == null ? void 0 : _a15.some((x) => x.format))) {
|
|
3143
2327
|
if (!schema.anyOf) {
|
|
3144
2328
|
schema.anyOf = [];
|
|
3145
2329
|
}
|
|
@@ -3158,8 +2342,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
3158
2342
|
}
|
|
3159
2343
|
}
|
|
3160
2344
|
function addPattern(schema, regex, message, refs) {
|
|
3161
|
-
var
|
|
3162
|
-
if (schema.pattern || ((
|
|
2345
|
+
var _a15;
|
|
2346
|
+
if (schema.pattern || ((_a15 = schema.allOf) == null ? void 0 : _a15.some((x) => x.pattern))) {
|
|
3163
2347
|
if (!schema.allOf) {
|
|
3164
2348
|
schema.allOf = [];
|
|
3165
2349
|
}
|
|
@@ -3178,7 +2362,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
3178
2362
|
}
|
|
3179
2363
|
}
|
|
3180
2364
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
3181
|
-
var
|
|
2365
|
+
var _a15;
|
|
3182
2366
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
3183
2367
|
return regex.source;
|
|
3184
2368
|
}
|
|
@@ -3208,7 +2392,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
3208
2392
|
pattern += source[i];
|
|
3209
2393
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
3210
2394
|
inCharRange = false;
|
|
3211
|
-
} else if (source[i + 1] === "-" && ((
|
|
2395
|
+
} else if (source[i + 1] === "-" && ((_a15 = source[i + 2]) == null ? void 0 : _a15.match(/[a-z]/))) {
|
|
3212
2396
|
pattern += source[i];
|
|
3213
2397
|
inCharRange = true;
|
|
3214
2398
|
} else {
|
|
@@ -3250,15 +2434,15 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
3250
2434
|
return pattern;
|
|
3251
2435
|
}
|
|
3252
2436
|
function parseRecordDef(def, refs) {
|
|
3253
|
-
var
|
|
2437
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
3254
2438
|
const schema = {
|
|
3255
2439
|
type: "object",
|
|
3256
|
-
additionalProperties: (
|
|
2440
|
+
additionalProperties: (_a15 = parseDef(def.valueType._def, {
|
|
3257
2441
|
...refs,
|
|
3258
2442
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
3259
|
-
})) != null ?
|
|
2443
|
+
})) != null ? _a15 : refs.allowedAdditionalProperties
|
|
3260
2444
|
};
|
|
3261
|
-
if (((
|
|
2445
|
+
if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
3262
2446
|
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
3263
2447
|
return {
|
|
3264
2448
|
...schema,
|
|
@@ -3513,8 +2697,8 @@ function safeIsOptional(schema) {
|
|
|
3513
2697
|
}
|
|
3514
2698
|
}
|
|
3515
2699
|
var parseOptionalDef = (def, refs) => {
|
|
3516
|
-
var
|
|
3517
|
-
if (refs.currentPath.toString() === ((
|
|
2700
|
+
var _a15;
|
|
2701
|
+
if (refs.currentPath.toString() === ((_a15 = refs.propertyPath) == null ? void 0 : _a15.toString())) {
|
|
3518
2702
|
return parseDef(def.innerType._def, refs);
|
|
3519
2703
|
}
|
|
3520
2704
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -3684,10 +2868,10 @@ var selectParser = (def, typeName, refs) => {
|
|
|
3684
2868
|
}
|
|
3685
2869
|
};
|
|
3686
2870
|
function parseDef(def, refs, forceResolution = false) {
|
|
3687
|
-
var
|
|
2871
|
+
var _a15;
|
|
3688
2872
|
const seenItem = refs.seen.get(def);
|
|
3689
2873
|
if (refs.override) {
|
|
3690
|
-
const overrideResult = (
|
|
2874
|
+
const overrideResult = (_a15 = refs.override) == null ? void 0 : _a15.call(
|
|
3691
2875
|
refs,
|
|
3692
2876
|
def,
|
|
3693
2877
|
refs,
|
|
@@ -3753,11 +2937,11 @@ var getRefs = (options) => {
|
|
|
3753
2937
|
currentPath,
|
|
3754
2938
|
propertyPath: void 0,
|
|
3755
2939
|
seen: new Map(
|
|
3756
|
-
Object.entries(_options.definitions).map(([
|
|
2940
|
+
Object.entries(_options.definitions).map(([name14, def]) => [
|
|
3757
2941
|
def._def,
|
|
3758
2942
|
{
|
|
3759
2943
|
def: def._def,
|
|
3760
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
2944
|
+
path: [..._options.basePath, _options.definitionPath, name14],
|
|
3761
2945
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
3762
2946
|
jsonSchema: void 0
|
|
3763
2947
|
}
|
|
@@ -3766,50 +2950,50 @@ var getRefs = (options) => {
|
|
|
3766
2950
|
};
|
|
3767
2951
|
};
|
|
3768
2952
|
var zodToJsonSchema = (schema, options) => {
|
|
3769
|
-
var
|
|
2953
|
+
var _a15;
|
|
3770
2954
|
const refs = getRefs(options);
|
|
3771
2955
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
3772
|
-
(acc, [
|
|
3773
|
-
var
|
|
2956
|
+
(acc, [name22, schema2]) => {
|
|
2957
|
+
var _a22;
|
|
3774
2958
|
return {
|
|
3775
2959
|
...acc,
|
|
3776
|
-
[
|
|
2960
|
+
[name22]: (_a22 = parseDef(
|
|
3777
2961
|
schema2._def,
|
|
3778
2962
|
{
|
|
3779
2963
|
...refs,
|
|
3780
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2964
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
3781
2965
|
},
|
|
3782
2966
|
true
|
|
3783
|
-
)) != null ?
|
|
2967
|
+
)) != null ? _a22 : parseAnyDef()
|
|
3784
2968
|
};
|
|
3785
2969
|
},
|
|
3786
2970
|
{}
|
|
3787
2971
|
) : void 0;
|
|
3788
|
-
const
|
|
3789
|
-
const main = (
|
|
2972
|
+
const name14 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2973
|
+
const main = (_a15 = parseDef(
|
|
3790
2974
|
schema._def,
|
|
3791
|
-
|
|
2975
|
+
name14 === void 0 ? refs : {
|
|
3792
2976
|
...refs,
|
|
3793
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2977
|
+
currentPath: [...refs.basePath, refs.definitionPath, name14]
|
|
3794
2978
|
},
|
|
3795
2979
|
false
|
|
3796
|
-
)) != null ?
|
|
2980
|
+
)) != null ? _a15 : parseAnyDef();
|
|
3797
2981
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
3798
2982
|
if (title !== void 0) {
|
|
3799
2983
|
main.title = title;
|
|
3800
2984
|
}
|
|
3801
|
-
const combined =
|
|
2985
|
+
const combined = name14 === void 0 ? definitions ? {
|
|
3802
2986
|
...main,
|
|
3803
2987
|
[refs.definitionPath]: definitions
|
|
3804
2988
|
} : main : {
|
|
3805
2989
|
$ref: [
|
|
3806
2990
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
3807
2991
|
refs.definitionPath,
|
|
3808
|
-
|
|
2992
|
+
name14
|
|
3809
2993
|
].join("/"),
|
|
3810
2994
|
[refs.definitionPath]: {
|
|
3811
2995
|
...definitions,
|
|
3812
|
-
[
|
|
2996
|
+
[name14]: main
|
|
3813
2997
|
}
|
|
3814
2998
|
};
|
|
3815
2999
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -3817,8 +3001,8 @@ var zodToJsonSchema = (schema, options) => {
|
|
|
3817
3001
|
};
|
|
3818
3002
|
var zod_to_json_schema_default = zodToJsonSchema;
|
|
3819
3003
|
function zod3Schema(zodSchema2, options) {
|
|
3820
|
-
var
|
|
3821
|
-
const useReferences = (
|
|
3004
|
+
var _a15;
|
|
3005
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
3822
3006
|
return jsonSchema(
|
|
3823
3007
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
3824
3008
|
() => zod_to_json_schema_default(zodSchema2, {
|
|
@@ -3833,18 +3017,18 @@ function zod3Schema(zodSchema2, options) {
|
|
|
3833
3017
|
);
|
|
3834
3018
|
}
|
|
3835
3019
|
function zod4Schema(zodSchema2, options) {
|
|
3836
|
-
var
|
|
3837
|
-
const useReferences = (
|
|
3020
|
+
var _a15;
|
|
3021
|
+
const useReferences = (_a15 = void 0 ) != null ? _a15 : false;
|
|
3838
3022
|
return jsonSchema(
|
|
3839
3023
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
3840
|
-
() =>
|
|
3024
|
+
() => z42.toJSONSchema(zodSchema2, {
|
|
3841
3025
|
target: "draft-7",
|
|
3842
3026
|
io: "output",
|
|
3843
3027
|
reused: useReferences ? "ref" : "inline"
|
|
3844
3028
|
}),
|
|
3845
3029
|
{
|
|
3846
3030
|
validate: async (value) => {
|
|
3847
|
-
const result = await
|
|
3031
|
+
const result = await z42.safeParseAsync(zodSchema2, value);
|
|
3848
3032
|
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
3849
3033
|
}
|
|
3850
3034
|
}
|
|
@@ -3877,7 +3061,7 @@ function jsonSchema(jsonSchema2, {
|
|
|
3877
3061
|
[schemaSymbol]: true,
|
|
3878
3062
|
_type: void 0,
|
|
3879
3063
|
// should never be used directly
|
|
3880
|
-
[
|
|
3064
|
+
[validatorSymbol]: true,
|
|
3881
3065
|
get jsonSchema() {
|
|
3882
3066
|
if (typeof jsonSchema2 === "function") {
|
|
3883
3067
|
jsonSchema2 = jsonSchema2();
|
|
@@ -4149,7 +3333,7 @@ function prepareTools2({
|
|
|
4149
3333
|
};
|
|
4150
3334
|
default: {
|
|
4151
3335
|
const _exhaustiveCheck = type;
|
|
4152
|
-
throw new
|
|
3336
|
+
throw new UnsupportedFunctionalityError2({
|
|
4153
3337
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
4154
3338
|
});
|
|
4155
3339
|
}
|
|
@@ -4214,12 +3398,12 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4214
3398
|
toolChoice,
|
|
4215
3399
|
seed
|
|
4216
3400
|
}) {
|
|
4217
|
-
var
|
|
4218
|
-
const deepseekOptions = (
|
|
3401
|
+
var _a15, _b;
|
|
3402
|
+
const deepseekOptions = (_a15 = await parseProviderOptions3({
|
|
4219
3403
|
provider: this.providerOptionsName,
|
|
4220
3404
|
providerOptions,
|
|
4221
3405
|
schema: deepseekChatOptions
|
|
4222
|
-
})) != null ?
|
|
3406
|
+
})) != null ? _a15 : {};
|
|
4223
3407
|
const { messages, warnings } = convertToDeepSeekChatMessages({
|
|
4224
3408
|
prompt,
|
|
4225
3409
|
responseFormat
|
|
@@ -4251,13 +3435,13 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4251
3435
|
messages,
|
|
4252
3436
|
tools: deepseekTools,
|
|
4253
3437
|
tool_choice: deepseekToolChoices,
|
|
4254
|
-
thinking: ((
|
|
3438
|
+
thinking: ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : void 0
|
|
4255
3439
|
},
|
|
4256
3440
|
warnings: [...warnings, ...toolWarnings]
|
|
4257
3441
|
};
|
|
4258
3442
|
}
|
|
4259
3443
|
async doGenerate(options) {
|
|
4260
|
-
var
|
|
3444
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
4261
3445
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
4262
3446
|
const {
|
|
4263
3447
|
responseHeaders,
|
|
@@ -4290,7 +3474,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4290
3474
|
for (const toolCall of choice.message.tool_calls) {
|
|
4291
3475
|
content.push({
|
|
4292
3476
|
type: "tool-call",
|
|
4293
|
-
toolCallId: (
|
|
3477
|
+
toolCallId: (_a15 = toolCall.id) != null ? _a15 : generateId3(),
|
|
4294
3478
|
toolName: toolCall.function.name,
|
|
4295
3479
|
input: toolCall.function.arguments
|
|
4296
3480
|
});
|
|
@@ -4304,7 +3488,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4304
3488
|
content,
|
|
4305
3489
|
finishReason: mapDeepSeekFinishReason(choice.finish_reason),
|
|
4306
3490
|
usage: {
|
|
4307
|
-
inputTokens: (_c = (
|
|
3491
|
+
inputTokens: (_c = (_b = responseBody.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
|
|
4308
3492
|
outputTokens: (_e = (_d = responseBody.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : void 0,
|
|
4309
3493
|
totalTokens: (_g = (_f = responseBody.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0,
|
|
4310
3494
|
reasoningTokens: (_j = (_i = (_h = responseBody.usage) == null ? void 0 : _h.completion_tokens_details) == null ? void 0 : _i.reasoning_tokens) != null ? _j : void 0,
|
|
@@ -4360,7 +3544,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4360
3544
|
controller.enqueue({ type: "stream-start", warnings });
|
|
4361
3545
|
},
|
|
4362
3546
|
transform(chunk, controller) {
|
|
4363
|
-
var
|
|
3547
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
4364
3548
|
if (options.includeRawChunks) {
|
|
4365
3549
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4366
3550
|
}
|
|
@@ -4438,13 +3622,13 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4438
3622
|
const index = toolCallDelta.index;
|
|
4439
3623
|
if (toolCalls[index] == null) {
|
|
4440
3624
|
if (toolCallDelta.id == null) {
|
|
4441
|
-
throw new
|
|
3625
|
+
throw new InvalidResponseDataError2({
|
|
4442
3626
|
data: toolCallDelta,
|
|
4443
3627
|
message: `Expected 'id' to be a string.`
|
|
4444
3628
|
});
|
|
4445
3629
|
}
|
|
4446
|
-
if (((
|
|
4447
|
-
throw new
|
|
3630
|
+
if (((_a15 = toolCallDelta.function) == null ? void 0 : _a15.name) == null) {
|
|
3631
|
+
throw new InvalidResponseDataError2({
|
|
4448
3632
|
data: toolCallDelta,
|
|
4449
3633
|
message: `Expected 'function.name' to be a string.`
|
|
4450
3634
|
});
|
|
@@ -4459,7 +3643,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4459
3643
|
type: "function",
|
|
4460
3644
|
function: {
|
|
4461
3645
|
name: toolCallDelta.function.name,
|
|
4462
|
-
arguments: (
|
|
3646
|
+
arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
|
|
4463
3647
|
},
|
|
4464
3648
|
hasFinished: false
|
|
4465
3649
|
};
|
|
@@ -4517,7 +3701,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4517
3701
|
}
|
|
4518
3702
|
},
|
|
4519
3703
|
flush(controller) {
|
|
4520
|
-
var
|
|
3704
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4521
3705
|
if (isActiveReasoning) {
|
|
4522
3706
|
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
4523
3707
|
}
|
|
@@ -4533,7 +3717,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4533
3717
|
});
|
|
4534
3718
|
controller.enqueue({
|
|
4535
3719
|
type: "tool-call",
|
|
4536
|
-
toolCallId: (
|
|
3720
|
+
toolCallId: (_a15 = toolCall.id) != null ? _a15 : generateId3(),
|
|
4537
3721
|
toolName: toolCall.function.name,
|
|
4538
3722
|
input: toolCall.function.arguments
|
|
4539
3723
|
});
|
|
@@ -4542,7 +3726,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4542
3726
|
type: "finish",
|
|
4543
3727
|
finishReason,
|
|
4544
3728
|
usage: {
|
|
4545
|
-
inputTokens: (
|
|
3729
|
+
inputTokens: (_b = usage == null ? void 0 : usage.prompt_tokens) != null ? _b : void 0,
|
|
4546
3730
|
outputTokens: (_c = usage == null ? void 0 : usage.completion_tokens) != null ? _c : void 0,
|
|
4547
3731
|
totalTokens: (_d = usage == null ? void 0 : usage.total_tokens) != null ? _d : void 0,
|
|
4548
3732
|
reasoningTokens: (_f = (_e = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : void 0,
|
|
@@ -4563,11 +3747,11 @@ var DeepSeekChatLanguageModel = class {
|
|
|
4563
3747
|
};
|
|
4564
3748
|
}
|
|
4565
3749
|
};
|
|
4566
|
-
var
|
|
3750
|
+
var VERSION4 = "1.0.31" ;
|
|
4567
3751
|
function createDeepSeek(options = {}) {
|
|
4568
|
-
var
|
|
3752
|
+
var _a15;
|
|
4569
3753
|
const baseURL = withoutTrailingSlash3(
|
|
4570
|
-
(
|
|
3754
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.deepseek.com"
|
|
4571
3755
|
);
|
|
4572
3756
|
const getHeaders = () => withUserAgentSuffix3(
|
|
4573
3757
|
{
|
|
@@ -4578,7 +3762,7 @@ function createDeepSeek(options = {}) {
|
|
|
4578
3762
|
})}`,
|
|
4579
3763
|
...options.headers
|
|
4580
3764
|
},
|
|
4581
|
-
`ai-sdk/deepseek/${
|
|
3765
|
+
`ai-sdk/deepseek/${VERSION4}`
|
|
4582
3766
|
);
|
|
4583
3767
|
const createLanguageModel = (modelId) => {
|
|
4584
3768
|
return new DeepSeekChatLanguageModel(modelId, {
|
|
@@ -4592,10 +3776,10 @@ function createDeepSeek(options = {}) {
|
|
|
4592
3776
|
provider.languageModel = createLanguageModel;
|
|
4593
3777
|
provider.chat = createLanguageModel;
|
|
4594
3778
|
provider.textEmbeddingModel = (modelId) => {
|
|
4595
|
-
throw new
|
|
3779
|
+
throw new NoSuchModelError2({ modelId, modelType: "textEmbeddingModel" });
|
|
4596
3780
|
};
|
|
4597
3781
|
provider.imageModel = (modelId) => {
|
|
4598
|
-
throw new
|
|
3782
|
+
throw new NoSuchModelError2({ modelId, modelType: "imageModel" });
|
|
4599
3783
|
};
|
|
4600
3784
|
return provider;
|
|
4601
3785
|
}
|
|
@@ -4623,7 +3807,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
4623
3807
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
4624
3808
|
return {
|
|
4625
3809
|
type: "image_url",
|
|
4626
|
-
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
3810
|
+
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
4627
3811
|
};
|
|
4628
3812
|
} else if (part.mediaType === "application/pdf") {
|
|
4629
3813
|
return {
|
|
@@ -4631,7 +3815,7 @@ function convertToMistralChatMessages(prompt) {
|
|
|
4631
3815
|
document_url: part.data.toString()
|
|
4632
3816
|
};
|
|
4633
3817
|
} else {
|
|
4634
|
-
throw new
|
|
3818
|
+
throw new UnsupportedFunctionalityError2({
|
|
4635
3819
|
functionality: "Only images and PDF file parts are supported"
|
|
4636
3820
|
});
|
|
4637
3821
|
}
|
|
@@ -4772,7 +3956,7 @@ var mistralErrorDataSchema = z.object({
|
|
|
4772
3956
|
param: z.string().nullable(),
|
|
4773
3957
|
code: z.string().nullable()
|
|
4774
3958
|
});
|
|
4775
|
-
var mistralFailedResponseHandler =
|
|
3959
|
+
var mistralFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
4776
3960
|
errorSchema: mistralErrorDataSchema,
|
|
4777
3961
|
errorToMessage: (data) => data.message
|
|
4778
3962
|
});
|
|
@@ -4822,7 +4006,7 @@ function prepareTools3({
|
|
|
4822
4006
|
};
|
|
4823
4007
|
default: {
|
|
4824
4008
|
const _exhaustiveCheck = type;
|
|
4825
|
-
throw new
|
|
4009
|
+
throw new UnsupportedFunctionalityError2({
|
|
4826
4010
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
4827
4011
|
});
|
|
4828
4012
|
}
|
|
@@ -4834,10 +4018,10 @@ var MistralChatLanguageModel = class {
|
|
|
4834
4018
|
this.supportedUrls = {
|
|
4835
4019
|
"application/pdf": [/^https:\/\/.*$/]
|
|
4836
4020
|
};
|
|
4837
|
-
var
|
|
4021
|
+
var _a15;
|
|
4838
4022
|
this.modelId = modelId;
|
|
4839
4023
|
this.config = config;
|
|
4840
|
-
this.generateId = (
|
|
4024
|
+
this.generateId = (_a15 = config.generateId) != null ? _a15 : generateId2;
|
|
4841
4025
|
}
|
|
4842
4026
|
get provider() {
|
|
4843
4027
|
return this.config.provider;
|
|
@@ -4857,13 +4041,13 @@ var MistralChatLanguageModel = class {
|
|
|
4857
4041
|
tools,
|
|
4858
4042
|
toolChoice
|
|
4859
4043
|
}) {
|
|
4860
|
-
var
|
|
4044
|
+
var _a15, _b, _c, _d;
|
|
4861
4045
|
const warnings = [];
|
|
4862
|
-
const options = (
|
|
4046
|
+
const options = (_a15 = await parseProviderOptions2({
|
|
4863
4047
|
provider: "mistral",
|
|
4864
4048
|
providerOptions,
|
|
4865
4049
|
schema: mistralLanguageModelOptions
|
|
4866
|
-
})) != null ?
|
|
4050
|
+
})) != null ? _a15 : {};
|
|
4867
4051
|
if (topK != null) {
|
|
4868
4052
|
warnings.push({
|
|
4869
4053
|
type: "unsupported-setting",
|
|
@@ -4888,7 +4072,7 @@ var MistralChatLanguageModel = class {
|
|
|
4888
4072
|
setting: "stopSequences"
|
|
4889
4073
|
});
|
|
4890
4074
|
}
|
|
4891
|
-
const structuredOutputs = (
|
|
4075
|
+
const structuredOutputs = (_b = options.structuredOutputs) != null ? _b : true;
|
|
4892
4076
|
const strictJsonSchema = (_c = options.strictJsonSchema) != null ? _c : false;
|
|
4893
4077
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && !(responseFormat == null ? void 0 : responseFormat.schema)) {
|
|
4894
4078
|
prompt = injectJsonInstructionIntoMessages({
|
|
@@ -4946,12 +4130,12 @@ var MistralChatLanguageModel = class {
|
|
|
4946
4130
|
responseHeaders,
|
|
4947
4131
|
value: response,
|
|
4948
4132
|
rawValue: rawResponse
|
|
4949
|
-
} = await
|
|
4133
|
+
} = await postJsonToApi2({
|
|
4950
4134
|
url: `${this.config.baseURL}/chat/completions`,
|
|
4951
|
-
headers:
|
|
4135
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
4952
4136
|
body,
|
|
4953
4137
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
4954
|
-
successfulResponseHandler:
|
|
4138
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
4955
4139
|
mistralChatResponseSchema
|
|
4956
4140
|
),
|
|
4957
4141
|
abortSignal: options.abortSignal,
|
|
@@ -5008,12 +4192,12 @@ var MistralChatLanguageModel = class {
|
|
|
5008
4192
|
async doStream(options) {
|
|
5009
4193
|
const { args, warnings } = await this.getArgs(options);
|
|
5010
4194
|
const body = { ...args, stream: true };
|
|
5011
|
-
const { responseHeaders, value: response } = await
|
|
4195
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
5012
4196
|
url: `${this.config.baseURL}/chat/completions`,
|
|
5013
|
-
headers:
|
|
4197
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
5014
4198
|
body,
|
|
5015
4199
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
5016
|
-
successfulResponseHandler:
|
|
4200
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
5017
4201
|
mistralChatChunkSchema
|
|
5018
4202
|
),
|
|
5019
4203
|
abortSignal: options.abortSignal,
|
|
@@ -5286,7 +4470,7 @@ var MistralEmbeddingModel = class {
|
|
|
5286
4470
|
headers
|
|
5287
4471
|
}) {
|
|
5288
4472
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
5289
|
-
throw new
|
|
4473
|
+
throw new TooManyEmbeddingValuesForCallError2({
|
|
5290
4474
|
provider: this.provider,
|
|
5291
4475
|
modelId: this.modelId,
|
|
5292
4476
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -5297,16 +4481,16 @@ var MistralEmbeddingModel = class {
|
|
|
5297
4481
|
responseHeaders,
|
|
5298
4482
|
value: response,
|
|
5299
4483
|
rawValue
|
|
5300
|
-
} = await
|
|
4484
|
+
} = await postJsonToApi2({
|
|
5301
4485
|
url: `${this.config.baseURL}/embeddings`,
|
|
5302
|
-
headers:
|
|
4486
|
+
headers: combineHeaders2(this.config.headers(), headers),
|
|
5303
4487
|
body: {
|
|
5304
4488
|
model: this.modelId,
|
|
5305
4489
|
input: values,
|
|
5306
4490
|
encoding_format: "float"
|
|
5307
4491
|
},
|
|
5308
4492
|
failedResponseHandler: mistralFailedResponseHandler,
|
|
5309
|
-
successfulResponseHandler:
|
|
4493
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
5310
4494
|
MistralTextEmbeddingResponseSchema
|
|
5311
4495
|
),
|
|
5312
4496
|
abortSignal,
|
|
@@ -5323,20 +4507,20 @@ var MistralTextEmbeddingResponseSchema = z.object({
|
|
|
5323
4507
|
data: z.array(z.object({ embedding: z.array(z.number()) })),
|
|
5324
4508
|
usage: z.object({ prompt_tokens: z.number() }).nullish()
|
|
5325
4509
|
});
|
|
5326
|
-
var
|
|
4510
|
+
var VERSION5 = "2.0.24" ;
|
|
5327
4511
|
function createMistral(options = {}) {
|
|
5328
|
-
var
|
|
5329
|
-
const baseURL = (
|
|
5330
|
-
const getHeaders = () =>
|
|
4512
|
+
var _a15;
|
|
4513
|
+
const baseURL = (_a15 = withoutTrailingSlash2(options.baseURL)) != null ? _a15 : "https://api.mistral.ai/v1";
|
|
4514
|
+
const getHeaders = () => withUserAgentSuffix2(
|
|
5331
4515
|
{
|
|
5332
|
-
Authorization: `Bearer ${
|
|
4516
|
+
Authorization: `Bearer ${loadApiKey2({
|
|
5333
4517
|
apiKey: options.apiKey,
|
|
5334
4518
|
environmentVariableName: "MISTRAL_API_KEY",
|
|
5335
4519
|
description: "Mistral"
|
|
5336
4520
|
})}`,
|
|
5337
4521
|
...options.headers
|
|
5338
4522
|
},
|
|
5339
|
-
`ai-sdk/mistral/${
|
|
4523
|
+
`ai-sdk/mistral/${VERSION5}`
|
|
5340
4524
|
);
|
|
5341
4525
|
const createChatModel = (modelId) => new MistralChatLanguageModel(modelId, {
|
|
5342
4526
|
provider: "mistral.chat",
|
|
@@ -5365,7 +4549,7 @@ function createMistral(options = {}) {
|
|
|
5365
4549
|
provider.textEmbedding = createEmbeddingModel;
|
|
5366
4550
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
5367
4551
|
provider.imageModel = (modelId) => {
|
|
5368
|
-
throw new
|
|
4552
|
+
throw new NoSuchModelError2({ modelId, modelType: "imageModel" });
|
|
5369
4553
|
};
|
|
5370
4554
|
return provider;
|
|
5371
4555
|
}
|
|
@@ -5384,10 +4568,10 @@ function combineHeaders4(...headers) {
|
|
|
5384
4568
|
{}
|
|
5385
4569
|
);
|
|
5386
4570
|
}
|
|
5387
|
-
function
|
|
4571
|
+
function extractResponseHeaders2(response) {
|
|
5388
4572
|
return Object.fromEntries([...response.headers]);
|
|
5389
4573
|
}
|
|
5390
|
-
var
|
|
4574
|
+
var createIdGenerator2 = ({
|
|
5391
4575
|
prefix,
|
|
5392
4576
|
size = 16,
|
|
5393
4577
|
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
@@ -5412,21 +4596,21 @@ var createIdGenerator3 = ({
|
|
|
5412
4596
|
}
|
|
5413
4597
|
return () => `${prefix}${separator}${generator()}`;
|
|
5414
4598
|
};
|
|
5415
|
-
var generateId4 =
|
|
5416
|
-
function
|
|
4599
|
+
var generateId4 = createIdGenerator2();
|
|
4600
|
+
function isAbortError2(error) {
|
|
5417
4601
|
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
5418
4602
|
error.name === "TimeoutError");
|
|
5419
4603
|
}
|
|
5420
|
-
var
|
|
5421
|
-
function
|
|
4604
|
+
var FETCH_FAILED_ERROR_MESSAGES2 = ["fetch failed", "failed to fetch"];
|
|
4605
|
+
function handleFetchError2({
|
|
5422
4606
|
error,
|
|
5423
4607
|
url,
|
|
5424
4608
|
requestBodyValues
|
|
5425
4609
|
}) {
|
|
5426
|
-
if (
|
|
4610
|
+
if (isAbortError2(error)) {
|
|
5427
4611
|
return error;
|
|
5428
4612
|
}
|
|
5429
|
-
if (error instanceof TypeError &&
|
|
4613
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES2.includes(error.message.toLowerCase())) {
|
|
5430
4614
|
const cause = error.cause;
|
|
5431
4615
|
if (cause != null) {
|
|
5432
4616
|
return new APICallError({
|
|
@@ -5478,19 +4662,19 @@ function loadApiKey4({
|
|
|
5478
4662
|
}
|
|
5479
4663
|
return apiKey;
|
|
5480
4664
|
}
|
|
5481
|
-
var
|
|
5482
|
-
var
|
|
5483
|
-
function
|
|
4665
|
+
var suspectProtoRx2 = /"__proto__"\s*:/;
|
|
4666
|
+
var suspectConstructorRx2 = /"constructor"\s*:/;
|
|
4667
|
+
function _parse2(text) {
|
|
5484
4668
|
const obj = JSON.parse(text);
|
|
5485
4669
|
if (obj === null || typeof obj !== "object") {
|
|
5486
4670
|
return obj;
|
|
5487
4671
|
}
|
|
5488
|
-
if (
|
|
4672
|
+
if (suspectProtoRx2.test(text) === false && suspectConstructorRx2.test(text) === false) {
|
|
5489
4673
|
return obj;
|
|
5490
4674
|
}
|
|
5491
|
-
return
|
|
4675
|
+
return filter2(obj);
|
|
5492
4676
|
}
|
|
5493
|
-
function
|
|
4677
|
+
function filter2(obj) {
|
|
5494
4678
|
let next = [obj];
|
|
5495
4679
|
while (next.length) {
|
|
5496
4680
|
const nodes = next;
|
|
@@ -5512,27 +4696,27 @@ function filter3(obj) {
|
|
|
5512
4696
|
}
|
|
5513
4697
|
return obj;
|
|
5514
4698
|
}
|
|
5515
|
-
function
|
|
4699
|
+
function secureJsonParse2(text) {
|
|
5516
4700
|
const { stackTraceLimit } = Error;
|
|
5517
4701
|
Error.stackTraceLimit = 0;
|
|
5518
4702
|
try {
|
|
5519
|
-
return
|
|
4703
|
+
return _parse2(text);
|
|
5520
4704
|
} finally {
|
|
5521
4705
|
Error.stackTraceLimit = stackTraceLimit;
|
|
5522
4706
|
}
|
|
5523
4707
|
}
|
|
5524
|
-
var
|
|
5525
|
-
function
|
|
5526
|
-
return { [
|
|
4708
|
+
var validatorSymbol2 = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
4709
|
+
function validator2(validate) {
|
|
4710
|
+
return { [validatorSymbol2]: true, validate };
|
|
5527
4711
|
}
|
|
5528
|
-
function
|
|
5529
|
-
return typeof value === "object" && value !== null &&
|
|
4712
|
+
function isValidator2(value) {
|
|
4713
|
+
return typeof value === "object" && value !== null && validatorSymbol2 in value && value[validatorSymbol2] === true && "validate" in value;
|
|
5530
4714
|
}
|
|
5531
|
-
function
|
|
5532
|
-
return
|
|
4715
|
+
function asValidator2(value) {
|
|
4716
|
+
return isValidator2(value) ? value : standardSchemaValidator2(value);
|
|
5533
4717
|
}
|
|
5534
|
-
function
|
|
5535
|
-
return
|
|
4718
|
+
function standardSchemaValidator2(standardSchema) {
|
|
4719
|
+
return validator2(async (value) => {
|
|
5536
4720
|
const result = await standardSchema["~standard"].validate(value);
|
|
5537
4721
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
5538
4722
|
success: false,
|
|
@@ -5543,21 +4727,21 @@ function standardSchemaValidator3(standardSchema) {
|
|
|
5543
4727
|
};
|
|
5544
4728
|
});
|
|
5545
4729
|
}
|
|
5546
|
-
async function
|
|
4730
|
+
async function validateTypes2({
|
|
5547
4731
|
value,
|
|
5548
4732
|
schema
|
|
5549
4733
|
}) {
|
|
5550
|
-
const result = await
|
|
4734
|
+
const result = await safeValidateTypes2({ value, schema });
|
|
5551
4735
|
if (!result.success) {
|
|
5552
4736
|
throw TypeValidationError.wrap({ value, cause: result.error });
|
|
5553
4737
|
}
|
|
5554
4738
|
return result.value;
|
|
5555
4739
|
}
|
|
5556
|
-
async function
|
|
4740
|
+
async function safeValidateTypes2({
|
|
5557
4741
|
value,
|
|
5558
4742
|
schema
|
|
5559
4743
|
}) {
|
|
5560
|
-
const validator22 =
|
|
4744
|
+
const validator22 = asValidator2(schema);
|
|
5561
4745
|
try {
|
|
5562
4746
|
if (validator22.validate == null) {
|
|
5563
4747
|
return { success: true, value, rawValue: value };
|
|
@@ -5579,16 +4763,16 @@ async function safeValidateTypes3({
|
|
|
5579
4763
|
};
|
|
5580
4764
|
}
|
|
5581
4765
|
}
|
|
5582
|
-
async function
|
|
4766
|
+
async function parseJSON2({
|
|
5583
4767
|
text,
|
|
5584
4768
|
schema
|
|
5585
4769
|
}) {
|
|
5586
4770
|
try {
|
|
5587
|
-
const value =
|
|
4771
|
+
const value = secureJsonParse2(text);
|
|
5588
4772
|
if (schema == null) {
|
|
5589
4773
|
return value;
|
|
5590
4774
|
}
|
|
5591
|
-
return
|
|
4775
|
+
return validateTypes2({ value, schema });
|
|
5592
4776
|
} catch (error) {
|
|
5593
4777
|
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
|
|
5594
4778
|
throw error;
|
|
@@ -5596,16 +4780,16 @@ async function parseJSON3({
|
|
|
5596
4780
|
throw new JSONParseError({ text, cause: error });
|
|
5597
4781
|
}
|
|
5598
4782
|
}
|
|
5599
|
-
async function
|
|
4783
|
+
async function safeParseJSON2({
|
|
5600
4784
|
text,
|
|
5601
4785
|
schema
|
|
5602
4786
|
}) {
|
|
5603
4787
|
try {
|
|
5604
|
-
const value =
|
|
4788
|
+
const value = secureJsonParse2(text);
|
|
5605
4789
|
if (schema == null) {
|
|
5606
4790
|
return { success: true, value, rawValue: value };
|
|
5607
4791
|
}
|
|
5608
|
-
return await
|
|
4792
|
+
return await safeValidateTypes2({ value, schema });
|
|
5609
4793
|
} catch (error) {
|
|
5610
4794
|
return {
|
|
5611
4795
|
success: false,
|
|
@@ -5614,7 +4798,7 @@ async function safeParseJSON3({
|
|
|
5614
4798
|
};
|
|
5615
4799
|
}
|
|
5616
4800
|
}
|
|
5617
|
-
function
|
|
4801
|
+
function parseJsonEventStream2({
|
|
5618
4802
|
stream,
|
|
5619
4803
|
schema
|
|
5620
4804
|
}) {
|
|
@@ -5624,12 +4808,12 @@ function parseJsonEventStream3({
|
|
|
5624
4808
|
if (data === "[DONE]") {
|
|
5625
4809
|
return;
|
|
5626
4810
|
}
|
|
5627
|
-
controller.enqueue(await
|
|
4811
|
+
controller.enqueue(await safeParseJSON2({ text: data, schema }));
|
|
5628
4812
|
}
|
|
5629
4813
|
})
|
|
5630
4814
|
);
|
|
5631
4815
|
}
|
|
5632
|
-
var
|
|
4816
|
+
var getOriginalFetch22 = () => globalThis.fetch;
|
|
5633
4817
|
var postJsonToApi4 = async ({
|
|
5634
4818
|
url,
|
|
5635
4819
|
headers,
|
|
@@ -5638,7 +4822,7 @@ var postJsonToApi4 = async ({
|
|
|
5638
4822
|
successfulResponseHandler,
|
|
5639
4823
|
abortSignal,
|
|
5640
4824
|
fetch: fetch2
|
|
5641
|
-
}) =>
|
|
4825
|
+
}) => postToApi2({
|
|
5642
4826
|
url,
|
|
5643
4827
|
headers: {
|
|
5644
4828
|
"Content-Type": "application/json",
|
|
@@ -5653,14 +4837,14 @@ var postJsonToApi4 = async ({
|
|
|
5653
4837
|
abortSignal,
|
|
5654
4838
|
fetch: fetch2
|
|
5655
4839
|
});
|
|
5656
|
-
var
|
|
4840
|
+
var postToApi2 = async ({
|
|
5657
4841
|
url,
|
|
5658
4842
|
headers = {},
|
|
5659
4843
|
body,
|
|
5660
4844
|
successfulResponseHandler,
|
|
5661
4845
|
failedResponseHandler,
|
|
5662
4846
|
abortSignal,
|
|
5663
|
-
fetch: fetch2 =
|
|
4847
|
+
fetch: fetch2 = getOriginalFetch22()
|
|
5664
4848
|
}) => {
|
|
5665
4849
|
try {
|
|
5666
4850
|
const response = await fetch2(url, {
|
|
@@ -5669,7 +4853,7 @@ var postToApi3 = async ({
|
|
|
5669
4853
|
body: body.content,
|
|
5670
4854
|
signal: abortSignal
|
|
5671
4855
|
});
|
|
5672
|
-
const responseHeaders =
|
|
4856
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
5673
4857
|
if (!response.ok) {
|
|
5674
4858
|
let errorInformation;
|
|
5675
4859
|
try {
|
|
@@ -5679,7 +4863,7 @@ var postToApi3 = async ({
|
|
|
5679
4863
|
requestBodyValues: body.values
|
|
5680
4864
|
});
|
|
5681
4865
|
} catch (error) {
|
|
5682
|
-
if (
|
|
4866
|
+
if (isAbortError2(error) || APICallError.isInstance(error)) {
|
|
5683
4867
|
throw error;
|
|
5684
4868
|
}
|
|
5685
4869
|
throw new APICallError({
|
|
@@ -5701,7 +4885,7 @@ var postToApi3 = async ({
|
|
|
5701
4885
|
});
|
|
5702
4886
|
} catch (error) {
|
|
5703
4887
|
if (error instanceof Error) {
|
|
5704
|
-
if (
|
|
4888
|
+
if (isAbortError2(error) || APICallError.isInstance(error)) {
|
|
5705
4889
|
throw error;
|
|
5706
4890
|
}
|
|
5707
4891
|
}
|
|
@@ -5715,7 +4899,7 @@ var postToApi3 = async ({
|
|
|
5715
4899
|
});
|
|
5716
4900
|
}
|
|
5717
4901
|
} catch (error) {
|
|
5718
|
-
throw
|
|
4902
|
+
throw handleFetchError2({ error, url, requestBodyValues: body.values });
|
|
5719
4903
|
}
|
|
5720
4904
|
};
|
|
5721
4905
|
var createJsonErrorResponseHandler4 = ({
|
|
@@ -5724,7 +4908,7 @@ var createJsonErrorResponseHandler4 = ({
|
|
|
5724
4908
|
isRetryable
|
|
5725
4909
|
}) => async ({ response, url, requestBodyValues }) => {
|
|
5726
4910
|
const responseBody = await response.text();
|
|
5727
|
-
const responseHeaders =
|
|
4911
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
5728
4912
|
if (responseBody.trim() === "") {
|
|
5729
4913
|
return {
|
|
5730
4914
|
responseHeaders,
|
|
@@ -5740,7 +4924,7 @@ var createJsonErrorResponseHandler4 = ({
|
|
|
5740
4924
|
};
|
|
5741
4925
|
}
|
|
5742
4926
|
try {
|
|
5743
|
-
const parsedError = await
|
|
4927
|
+
const parsedError = await parseJSON2({
|
|
5744
4928
|
text: responseBody,
|
|
5745
4929
|
schema: errorSchema
|
|
5746
4930
|
});
|
|
@@ -5773,13 +4957,13 @@ var createJsonErrorResponseHandler4 = ({
|
|
|
5773
4957
|
}
|
|
5774
4958
|
};
|
|
5775
4959
|
var createEventSourceResponseHandler4 = (chunkSchema) => async ({ response }) => {
|
|
5776
|
-
const responseHeaders =
|
|
4960
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
5777
4961
|
if (response.body == null) {
|
|
5778
4962
|
throw new EmptyResponseBodyError({});
|
|
5779
4963
|
}
|
|
5780
4964
|
return {
|
|
5781
4965
|
responseHeaders,
|
|
5782
|
-
value:
|
|
4966
|
+
value: parseJsonEventStream2({
|
|
5783
4967
|
stream: response.body,
|
|
5784
4968
|
schema: chunkSchema
|
|
5785
4969
|
})
|
|
@@ -5787,11 +4971,11 @@ var createEventSourceResponseHandler4 = (chunkSchema) => async ({ response }) =>
|
|
|
5787
4971
|
};
|
|
5788
4972
|
var createJsonResponseHandler4 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
5789
4973
|
const responseBody = await response.text();
|
|
5790
|
-
const parsedResult = await
|
|
4974
|
+
const parsedResult = await safeParseJSON2({
|
|
5791
4975
|
text: responseBody,
|
|
5792
4976
|
schema: responseSchema
|
|
5793
4977
|
});
|
|
5794
|
-
const responseHeaders =
|
|
4978
|
+
const responseHeaders = extractResponseHeaders2(response);
|
|
5795
4979
|
if (!parsedResult.success) {
|
|
5796
4980
|
throw new APICallError({
|
|
5797
4981
|
message: "Invalid JSON response",
|
|
@@ -5809,13 +4993,13 @@ var createJsonResponseHandler4 = (responseSchema) => async ({ response, url, req
|
|
|
5809
4993
|
rawValue: parsedResult.rawValue
|
|
5810
4994
|
};
|
|
5811
4995
|
};
|
|
5812
|
-
var { btoa:
|
|
5813
|
-
function
|
|
4996
|
+
var { btoa: btoa2} = globalThis;
|
|
4997
|
+
function convertUint8ArrayToBase64(array) {
|
|
5814
4998
|
let latin1string = "";
|
|
5815
4999
|
for (let i = 0; i < array.length; i++) {
|
|
5816
5000
|
latin1string += String.fromCodePoint(array[i]);
|
|
5817
5001
|
}
|
|
5818
|
-
return
|
|
5002
|
+
return btoa2(latin1string);
|
|
5819
5003
|
}
|
|
5820
5004
|
function withoutTrailingSlash4(url) {
|
|
5821
5005
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
@@ -5834,7 +5018,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
5834
5018
|
(part) => part.type === "file" && part.mediaType.startsWith("image/")
|
|
5835
5019
|
);
|
|
5836
5020
|
const messageContent = content.map((part) => {
|
|
5837
|
-
var
|
|
5021
|
+
var _a15;
|
|
5838
5022
|
switch (part.type) {
|
|
5839
5023
|
case "text": {
|
|
5840
5024
|
return {
|
|
@@ -5851,7 +5035,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
5851
5035
|
} : {
|
|
5852
5036
|
type: "image_url",
|
|
5853
5037
|
image_url: {
|
|
5854
|
-
url: `data:${(
|
|
5038
|
+
url: `data:${(_a15 = part.mediaType) != null ? _a15 : "image/jpeg"};base64,${typeof part.data === "string" ? part.data : convertUint8ArrayToBase64(part.data)}`
|
|
5855
5039
|
}
|
|
5856
5040
|
};
|
|
5857
5041
|
}
|
|
@@ -5864,7 +5048,7 @@ function convertToPerplexityMessages(prompt) {
|
|
|
5864
5048
|
break;
|
|
5865
5049
|
}
|
|
5866
5050
|
case "tool": {
|
|
5867
|
-
throw new
|
|
5051
|
+
throw new UnsupportedFunctionalityError2({
|
|
5868
5052
|
functionality: "Tool messages"
|
|
5869
5053
|
});
|
|
5870
5054
|
}
|
|
@@ -5908,7 +5092,7 @@ var PerplexityLanguageModel = class {
|
|
|
5908
5092
|
seed,
|
|
5909
5093
|
providerOptions
|
|
5910
5094
|
}) {
|
|
5911
|
-
var
|
|
5095
|
+
var _a15;
|
|
5912
5096
|
const warnings = [];
|
|
5913
5097
|
if (topK != null) {
|
|
5914
5098
|
warnings.push({
|
|
@@ -5945,7 +5129,7 @@ var PerplexityLanguageModel = class {
|
|
|
5945
5129
|
json_schema: { schema: responseFormat.schema }
|
|
5946
5130
|
} : void 0,
|
|
5947
5131
|
// provider extensions
|
|
5948
|
-
...(
|
|
5132
|
+
...(_a15 = providerOptions == null ? void 0 : providerOptions.perplexity) != null ? _a15 : {},
|
|
5949
5133
|
// messages:
|
|
5950
5134
|
messages: convertToPerplexityMessages(prompt)
|
|
5951
5135
|
},
|
|
@@ -5953,7 +5137,7 @@ var PerplexityLanguageModel = class {
|
|
|
5953
5137
|
};
|
|
5954
5138
|
}
|
|
5955
5139
|
async doGenerate(options) {
|
|
5956
|
-
var
|
|
5140
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
5957
5141
|
const { args: body, warnings } = this.getArgs(options);
|
|
5958
5142
|
const {
|
|
5959
5143
|
responseHeaders,
|
|
@@ -5993,8 +5177,8 @@ var PerplexityLanguageModel = class {
|
|
|
5993
5177
|
content,
|
|
5994
5178
|
finishReason: mapPerplexityFinishReason(choice.finish_reason),
|
|
5995
5179
|
usage: {
|
|
5996
|
-
inputTokens: (
|
|
5997
|
-
outputTokens: (
|
|
5180
|
+
inputTokens: (_a15 = response.usage) == null ? void 0 : _a15.prompt_tokens,
|
|
5181
|
+
outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
|
|
5998
5182
|
totalTokens: (_d = (_c = response.usage) == null ? void 0 : _c.total_tokens) != null ? _d : void 0
|
|
5999
5183
|
},
|
|
6000
5184
|
request: { body },
|
|
@@ -6062,7 +5246,7 @@ var PerplexityLanguageModel = class {
|
|
|
6062
5246
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6063
5247
|
},
|
|
6064
5248
|
transform(chunk, controller) {
|
|
6065
|
-
var
|
|
5249
|
+
var _a15, _b, _c;
|
|
6066
5250
|
if (options.includeRawChunks) {
|
|
6067
5251
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6068
5252
|
}
|
|
@@ -6076,7 +5260,7 @@ var PerplexityLanguageModel = class {
|
|
|
6076
5260
|
type: "response-metadata",
|
|
6077
5261
|
...getResponseMetadata5(value)
|
|
6078
5262
|
});
|
|
6079
|
-
(
|
|
5263
|
+
(_a15 = value.citations) == null ? void 0 : _a15.forEach((url) => {
|
|
6080
5264
|
controller.enqueue({
|
|
6081
5265
|
type: "source",
|
|
6082
5266
|
sourceType: "url",
|
|
@@ -6090,7 +5274,7 @@ var PerplexityLanguageModel = class {
|
|
|
6090
5274
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
6091
5275
|
usage.outputTokens = value.usage.completion_tokens;
|
|
6092
5276
|
providerMetadata.perplexity.usage = {
|
|
6093
|
-
citationTokens: (
|
|
5277
|
+
citationTokens: (_b = value.usage.citation_tokens) != null ? _b : null,
|
|
6094
5278
|
numSearchQueries: (_c = value.usage.num_search_queries) != null ? _c : null
|
|
6095
5279
|
};
|
|
6096
5280
|
}
|
|
@@ -6207,8 +5391,8 @@ var perplexityErrorSchema = z.object({
|
|
|
6207
5391
|
})
|
|
6208
5392
|
});
|
|
6209
5393
|
var errorToMessage = (data) => {
|
|
6210
|
-
var
|
|
6211
|
-
return (
|
|
5394
|
+
var _a15, _b;
|
|
5395
|
+
return (_b = (_a15 = data.error.message) != null ? _a15 : data.error.type) != null ? _b : "unknown error";
|
|
6212
5396
|
};
|
|
6213
5397
|
function createPerplexity(options = {}) {
|
|
6214
5398
|
const getHeaders = () => ({
|
|
@@ -6220,10 +5404,10 @@ function createPerplexity(options = {}) {
|
|
|
6220
5404
|
...options.headers
|
|
6221
5405
|
});
|
|
6222
5406
|
const createLanguageModel = (modelId) => {
|
|
6223
|
-
var
|
|
5407
|
+
var _a15;
|
|
6224
5408
|
return new PerplexityLanguageModel(modelId, {
|
|
6225
5409
|
baseURL: withoutTrailingSlash4(
|
|
6226
|
-
(
|
|
5410
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.perplexity.ai"
|
|
6227
5411
|
),
|
|
6228
5412
|
headers: getHeaders,
|
|
6229
5413
|
generateId: generateId4,
|
|
@@ -6233,10 +5417,10 @@ function createPerplexity(options = {}) {
|
|
|
6233
5417
|
const provider = (modelId) => createLanguageModel(modelId);
|
|
6234
5418
|
provider.languageModel = createLanguageModel;
|
|
6235
5419
|
provider.textEmbeddingModel = (modelId) => {
|
|
6236
|
-
throw new
|
|
5420
|
+
throw new NoSuchModelError2({ modelId, modelType: "textEmbeddingModel" });
|
|
6237
5421
|
};
|
|
6238
5422
|
provider.imageModel = (modelId) => {
|
|
6239
|
-
throw new
|
|
5423
|
+
throw new NoSuchModelError2({ modelId, modelType: "imageModel" });
|
|
6240
5424
|
};
|
|
6241
5425
|
return provider;
|
|
6242
5426
|
}
|
|
@@ -6246,7 +5430,261 @@ var TogetherAIImageModel = class {
|
|
|
6246
5430
|
this.modelId = modelId;
|
|
6247
5431
|
this.config = config;
|
|
6248
5432
|
this.specificationVersion = "v2";
|
|
6249
|
-
this.maxImagesPerCall = 1;
|
|
5433
|
+
this.maxImagesPerCall = 1;
|
|
5434
|
+
}
|
|
5435
|
+
get provider() {
|
|
5436
|
+
return this.config.provider;
|
|
5437
|
+
}
|
|
5438
|
+
async doGenerate({
|
|
5439
|
+
prompt,
|
|
5440
|
+
n,
|
|
5441
|
+
size,
|
|
5442
|
+
seed,
|
|
5443
|
+
providerOptions,
|
|
5444
|
+
headers,
|
|
5445
|
+
abortSignal
|
|
5446
|
+
}) {
|
|
5447
|
+
var _a15, _b, _c, _d;
|
|
5448
|
+
const warnings = [];
|
|
5449
|
+
if (size != null) {
|
|
5450
|
+
warnings.push({
|
|
5451
|
+
type: "unsupported-setting",
|
|
5452
|
+
setting: "aspectRatio",
|
|
5453
|
+
details: "This model does not support the `aspectRatio` option. Use `size` instead."
|
|
5454
|
+
});
|
|
5455
|
+
}
|
|
5456
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
5457
|
+
const splitSize = size == null ? void 0 : size.split("x");
|
|
5458
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
5459
|
+
url: `${this.config.baseURL}/images/generations`,
|
|
5460
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
5461
|
+
body: {
|
|
5462
|
+
model: this.modelId,
|
|
5463
|
+
prompt,
|
|
5464
|
+
seed,
|
|
5465
|
+
...n > 1 ? { n } : {},
|
|
5466
|
+
...splitSize && {
|
|
5467
|
+
width: parseInt(splitSize[0]),
|
|
5468
|
+
height: parseInt(splitSize[1])
|
|
5469
|
+
},
|
|
5470
|
+
response_format: "base64",
|
|
5471
|
+
...(_d = providerOptions.togetherai) != null ? _d : {}
|
|
5472
|
+
},
|
|
5473
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
5474
|
+
errorSchema: togetheraiErrorSchema,
|
|
5475
|
+
errorToMessage: (data) => data.error.message
|
|
5476
|
+
}),
|
|
5477
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
5478
|
+
togetheraiImageResponseSchema
|
|
5479
|
+
),
|
|
5480
|
+
abortSignal,
|
|
5481
|
+
fetch: this.config.fetch
|
|
5482
|
+
});
|
|
5483
|
+
return {
|
|
5484
|
+
images: response.data.map((item) => item.b64_json),
|
|
5485
|
+
warnings,
|
|
5486
|
+
response: {
|
|
5487
|
+
timestamp: currentDate,
|
|
5488
|
+
modelId: this.modelId,
|
|
5489
|
+
headers: responseHeaders
|
|
5490
|
+
}
|
|
5491
|
+
};
|
|
5492
|
+
}
|
|
5493
|
+
};
|
|
5494
|
+
var togetheraiImageResponseSchema = z.object({
|
|
5495
|
+
data: z.array(
|
|
5496
|
+
z.object({
|
|
5497
|
+
b64_json: z.string()
|
|
5498
|
+
})
|
|
5499
|
+
)
|
|
5500
|
+
});
|
|
5501
|
+
var togetheraiErrorSchema = z.object({
|
|
5502
|
+
error: z.object({
|
|
5503
|
+
message: z.string()
|
|
5504
|
+
})
|
|
5505
|
+
});
|
|
5506
|
+
var VERSION6 = "1.0.33" ;
|
|
5507
|
+
function createTogetherAI(options = {}) {
|
|
5508
|
+
var _a15;
|
|
5509
|
+
const baseURL = withoutTrailingSlash(
|
|
5510
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.together.xyz/v1/"
|
|
5511
|
+
);
|
|
5512
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
5513
|
+
{
|
|
5514
|
+
Authorization: `Bearer ${loadApiKey({
|
|
5515
|
+
apiKey: options.apiKey,
|
|
5516
|
+
environmentVariableName: "TOGETHER_AI_API_KEY",
|
|
5517
|
+
description: "TogetherAI"
|
|
5518
|
+
})}`,
|
|
5519
|
+
...options.headers
|
|
5520
|
+
},
|
|
5521
|
+
`ai-sdk/togetherai/${VERSION6}`
|
|
5522
|
+
);
|
|
5523
|
+
const getCommonModelConfig = (modelType) => ({
|
|
5524
|
+
provider: `togetherai.${modelType}`,
|
|
5525
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
5526
|
+
headers: getHeaders,
|
|
5527
|
+
fetch: options.fetch
|
|
5528
|
+
});
|
|
5529
|
+
const createChatModel = (modelId) => {
|
|
5530
|
+
return new OpenAICompatibleChatLanguageModel(
|
|
5531
|
+
modelId,
|
|
5532
|
+
getCommonModelConfig("chat")
|
|
5533
|
+
);
|
|
5534
|
+
};
|
|
5535
|
+
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(
|
|
5536
|
+
modelId,
|
|
5537
|
+
getCommonModelConfig("completion")
|
|
5538
|
+
);
|
|
5539
|
+
const createTextEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(
|
|
5540
|
+
modelId,
|
|
5541
|
+
getCommonModelConfig("embedding")
|
|
5542
|
+
);
|
|
5543
|
+
const createImageModel = (modelId) => new TogetherAIImageModel(modelId, {
|
|
5544
|
+
...getCommonModelConfig("image"),
|
|
5545
|
+
baseURL: baseURL != null ? baseURL : "https://api.together.xyz/v1/"
|
|
5546
|
+
});
|
|
5547
|
+
const provider = (modelId) => createChatModel(modelId);
|
|
5548
|
+
provider.completionModel = createCompletionModel;
|
|
5549
|
+
provider.languageModel = createChatModel;
|
|
5550
|
+
provider.chatModel = createChatModel;
|
|
5551
|
+
provider.textEmbeddingModel = createTextEmbeddingModel;
|
|
5552
|
+
provider.image = createImageModel;
|
|
5553
|
+
provider.imageModel = createImageModel;
|
|
5554
|
+
return provider;
|
|
5555
|
+
}
|
|
5556
|
+
createTogetherAI();
|
|
5557
|
+
z.object({
|
|
5558
|
+
/**
|
|
5559
|
+
* A unique identifier representing your end-user, which can help the provider to
|
|
5560
|
+
* monitor and detect abuse.
|
|
5561
|
+
*/
|
|
5562
|
+
user: z.string().optional(),
|
|
5563
|
+
/**
|
|
5564
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
5565
|
+
*/
|
|
5566
|
+
reasoningEffort: z.string().optional(),
|
|
5567
|
+
/**
|
|
5568
|
+
* Controls the verbosity of the generated text. Defaults to `medium`.
|
|
5569
|
+
*/
|
|
5570
|
+
textVerbosity: z.string().optional()
|
|
5571
|
+
});
|
|
5572
|
+
var openaiCompatibleErrorDataSchema2 = z.object({
|
|
5573
|
+
error: z.object({
|
|
5574
|
+
message: z.string(),
|
|
5575
|
+
// The additional information below is handled loosely to support
|
|
5576
|
+
// OpenAI-compatible providers that have slightly different error
|
|
5577
|
+
// responses:
|
|
5578
|
+
type: z.string().nullish(),
|
|
5579
|
+
param: z.any().nullish(),
|
|
5580
|
+
code: z.union([z.string(), z.number()]).nullish()
|
|
5581
|
+
})
|
|
5582
|
+
});
|
|
5583
|
+
var defaultOpenAICompatibleErrorStructure2 = {
|
|
5584
|
+
errorSchema: openaiCompatibleErrorDataSchema2,
|
|
5585
|
+
errorToMessage: (data) => data.error.message
|
|
5586
|
+
};
|
|
5587
|
+
var openaiCompatibleTokenUsageSchema2 = z.object({
|
|
5588
|
+
prompt_tokens: z.number().nullish(),
|
|
5589
|
+
completion_tokens: z.number().nullish(),
|
|
5590
|
+
total_tokens: z.number().nullish(),
|
|
5591
|
+
prompt_tokens_details: z.object({
|
|
5592
|
+
cached_tokens: z.number().nullish()
|
|
5593
|
+
}).nullish(),
|
|
5594
|
+
completion_tokens_details: z.object({
|
|
5595
|
+
reasoning_tokens: z.number().nullish(),
|
|
5596
|
+
accepted_prediction_tokens: z.number().nullish(),
|
|
5597
|
+
rejected_prediction_tokens: z.number().nullish()
|
|
5598
|
+
}).nullish()
|
|
5599
|
+
}).nullish();
|
|
5600
|
+
z.object({
|
|
5601
|
+
id: z.string().nullish(),
|
|
5602
|
+
created: z.number().nullish(),
|
|
5603
|
+
model: z.string().nullish(),
|
|
5604
|
+
choices: z.array(
|
|
5605
|
+
z.object({
|
|
5606
|
+
message: z.object({
|
|
5607
|
+
role: z.literal("assistant").nullish(),
|
|
5608
|
+
content: z.string().nullish(),
|
|
5609
|
+
reasoning_content: z.string().nullish(),
|
|
5610
|
+
reasoning: z.string().nullish(),
|
|
5611
|
+
tool_calls: z.array(
|
|
5612
|
+
z.object({
|
|
5613
|
+
id: z.string().nullish(),
|
|
5614
|
+
function: z.object({
|
|
5615
|
+
name: z.string(),
|
|
5616
|
+
arguments: z.string()
|
|
5617
|
+
})
|
|
5618
|
+
})
|
|
5619
|
+
).nullish()
|
|
5620
|
+
}),
|
|
5621
|
+
finish_reason: z.string().nullish()
|
|
5622
|
+
})
|
|
5623
|
+
),
|
|
5624
|
+
usage: openaiCompatibleTokenUsageSchema2
|
|
5625
|
+
});
|
|
5626
|
+
z.object({
|
|
5627
|
+
/**
|
|
5628
|
+
* Echo back the prompt in addition to the completion.
|
|
5629
|
+
*/
|
|
5630
|
+
echo: z.boolean().optional(),
|
|
5631
|
+
/**
|
|
5632
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
5633
|
+
*
|
|
5634
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
5635
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
5636
|
+
*/
|
|
5637
|
+
logitBias: z.record(z.string(), z.number()).optional(),
|
|
5638
|
+
/**
|
|
5639
|
+
* The suffix that comes after a completion of inserted text.
|
|
5640
|
+
*/
|
|
5641
|
+
suffix: z.string().optional(),
|
|
5642
|
+
/**
|
|
5643
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
5644
|
+
* monitor and detect abuse.
|
|
5645
|
+
*/
|
|
5646
|
+
user: z.string().optional()
|
|
5647
|
+
});
|
|
5648
|
+
var usageSchema2 = z.object({
|
|
5649
|
+
prompt_tokens: z.number(),
|
|
5650
|
+
completion_tokens: z.number(),
|
|
5651
|
+
total_tokens: z.number()
|
|
5652
|
+
});
|
|
5653
|
+
z.object({
|
|
5654
|
+
id: z.string().nullish(),
|
|
5655
|
+
created: z.number().nullish(),
|
|
5656
|
+
model: z.string().nullish(),
|
|
5657
|
+
choices: z.array(
|
|
5658
|
+
z.object({
|
|
5659
|
+
text: z.string(),
|
|
5660
|
+
finish_reason: z.string()
|
|
5661
|
+
})
|
|
5662
|
+
),
|
|
5663
|
+
usage: usageSchema2.nullish()
|
|
5664
|
+
});
|
|
5665
|
+
z.object({
|
|
5666
|
+
/**
|
|
5667
|
+
* The number of dimensions the resulting output embeddings should have.
|
|
5668
|
+
* Only supported in text-embedding-3 and later models.
|
|
5669
|
+
*/
|
|
5670
|
+
dimensions: z.number().optional(),
|
|
5671
|
+
/**
|
|
5672
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
5673
|
+
* monitor and detect abuse.
|
|
5674
|
+
*/
|
|
5675
|
+
user: z.string().optional()
|
|
5676
|
+
});
|
|
5677
|
+
z.object({
|
|
5678
|
+
data: z.array(z.object({ embedding: z.array(z.number()) })),
|
|
5679
|
+
usage: z.object({ prompt_tokens: z.number() }).nullish(),
|
|
5680
|
+
providerMetadata: z.record(z.string(), z.record(z.string(), z.any())).optional()
|
|
5681
|
+
});
|
|
5682
|
+
var OpenAICompatibleImageModel = class {
|
|
5683
|
+
constructor(modelId, config) {
|
|
5684
|
+
this.modelId = modelId;
|
|
5685
|
+
this.config = config;
|
|
5686
|
+
this.specificationVersion = "v2";
|
|
5687
|
+
this.maxImagesPerCall = 10;
|
|
6250
5688
|
}
|
|
6251
5689
|
get provider() {
|
|
6252
5690
|
return this.config.provider;
|
|
@@ -6255,43 +5693,44 @@ var TogetherAIImageModel = class {
|
|
|
6255
5693
|
prompt,
|
|
6256
5694
|
n,
|
|
6257
5695
|
size,
|
|
5696
|
+
aspectRatio,
|
|
6258
5697
|
seed,
|
|
6259
5698
|
providerOptions,
|
|
6260
5699
|
headers,
|
|
6261
5700
|
abortSignal
|
|
6262
5701
|
}) {
|
|
6263
|
-
var
|
|
5702
|
+
var _a15, _b, _c, _d, _e;
|
|
6264
5703
|
const warnings = [];
|
|
6265
|
-
if (
|
|
5704
|
+
if (aspectRatio != null) {
|
|
6266
5705
|
warnings.push({
|
|
6267
5706
|
type: "unsupported-setting",
|
|
6268
5707
|
setting: "aspectRatio",
|
|
6269
|
-
details: "This model does not support
|
|
5708
|
+
details: "This model does not support aspect ratio. Use `size` instead."
|
|
6270
5709
|
});
|
|
6271
5710
|
}
|
|
6272
|
-
|
|
6273
|
-
|
|
5711
|
+
if (seed != null) {
|
|
5712
|
+
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
5713
|
+
}
|
|
5714
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
6274
5715
|
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
6275
|
-
url:
|
|
5716
|
+
url: this.config.url({
|
|
5717
|
+
path: "/images/generations",
|
|
5718
|
+
modelId: this.modelId
|
|
5719
|
+
}),
|
|
6276
5720
|
headers: combineHeaders2(this.config.headers(), headers),
|
|
6277
5721
|
body: {
|
|
6278
5722
|
model: this.modelId,
|
|
6279
5723
|
prompt,
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
...
|
|
6283
|
-
|
|
6284
|
-
height: parseInt(splitSize[1])
|
|
6285
|
-
},
|
|
6286
|
-
response_format: "base64",
|
|
6287
|
-
...(_d = providerOptions.togetherai) != null ? _d : {}
|
|
5724
|
+
n,
|
|
5725
|
+
size,
|
|
5726
|
+
...(_d = providerOptions.openai) != null ? _d : {},
|
|
5727
|
+
response_format: "b64_json"
|
|
6288
5728
|
},
|
|
6289
|
-
failedResponseHandler: createJsonErrorResponseHandler2(
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
}),
|
|
5729
|
+
failedResponseHandler: createJsonErrorResponseHandler2(
|
|
5730
|
+
(_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure2
|
|
5731
|
+
),
|
|
6293
5732
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
6294
|
-
|
|
5733
|
+
openaiCompatibleImageResponseSchema2
|
|
6295
5734
|
),
|
|
6296
5735
|
abortSignal,
|
|
6297
5736
|
fetch: this.config.fetch
|
|
@@ -6307,69 +5746,9 @@ var TogetherAIImageModel = class {
|
|
|
6307
5746
|
};
|
|
6308
5747
|
}
|
|
6309
5748
|
};
|
|
6310
|
-
var
|
|
6311
|
-
data: z.array(
|
|
6312
|
-
z.object({
|
|
6313
|
-
b64_json: z.string()
|
|
6314
|
-
})
|
|
6315
|
-
)
|
|
6316
|
-
});
|
|
6317
|
-
var togetheraiErrorSchema = z.object({
|
|
6318
|
-
error: z.object({
|
|
6319
|
-
message: z.string()
|
|
6320
|
-
})
|
|
5749
|
+
var openaiCompatibleImageResponseSchema2 = z.object({
|
|
5750
|
+
data: z.array(z.object({ b64_json: z.string() }))
|
|
6321
5751
|
});
|
|
6322
|
-
var VERSION7 = "1.0.33" ;
|
|
6323
|
-
function createTogetherAI(options = {}) {
|
|
6324
|
-
var _a16;
|
|
6325
|
-
const baseURL = withoutTrailingSlash2(
|
|
6326
|
-
(_a16 = options.baseURL) != null ? _a16 : "https://api.together.xyz/v1/"
|
|
6327
|
-
);
|
|
6328
|
-
const getHeaders = () => withUserAgentSuffix2(
|
|
6329
|
-
{
|
|
6330
|
-
Authorization: `Bearer ${loadApiKey2({
|
|
6331
|
-
apiKey: options.apiKey,
|
|
6332
|
-
environmentVariableName: "TOGETHER_AI_API_KEY",
|
|
6333
|
-
description: "TogetherAI"
|
|
6334
|
-
})}`,
|
|
6335
|
-
...options.headers
|
|
6336
|
-
},
|
|
6337
|
-
`ai-sdk/togetherai/${VERSION7}`
|
|
6338
|
-
);
|
|
6339
|
-
const getCommonModelConfig = (modelType) => ({
|
|
6340
|
-
provider: `togetherai.${modelType}`,
|
|
6341
|
-
url: ({ path }) => `${baseURL}${path}`,
|
|
6342
|
-
headers: getHeaders,
|
|
6343
|
-
fetch: options.fetch
|
|
6344
|
-
});
|
|
6345
|
-
const createChatModel = (modelId) => {
|
|
6346
|
-
return new OpenAICompatibleChatLanguageModel(
|
|
6347
|
-
modelId,
|
|
6348
|
-
getCommonModelConfig("chat")
|
|
6349
|
-
);
|
|
6350
|
-
};
|
|
6351
|
-
const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(
|
|
6352
|
-
modelId,
|
|
6353
|
-
getCommonModelConfig("completion")
|
|
6354
|
-
);
|
|
6355
|
-
const createTextEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(
|
|
6356
|
-
modelId,
|
|
6357
|
-
getCommonModelConfig("embedding")
|
|
6358
|
-
);
|
|
6359
|
-
const createImageModel = (modelId) => new TogetherAIImageModel(modelId, {
|
|
6360
|
-
...getCommonModelConfig("image"),
|
|
6361
|
-
baseURL: baseURL != null ? baseURL : "https://api.together.xyz/v1/"
|
|
6362
|
-
});
|
|
6363
|
-
const provider = (modelId) => createChatModel(modelId);
|
|
6364
|
-
provider.completionModel = createCompletionModel;
|
|
6365
|
-
provider.languageModel = createChatModel;
|
|
6366
|
-
provider.chatModel = createChatModel;
|
|
6367
|
-
provider.textEmbeddingModel = createTextEmbeddingModel;
|
|
6368
|
-
provider.image = createImageModel;
|
|
6369
|
-
provider.imageModel = createImageModel;
|
|
6370
|
-
return provider;
|
|
6371
|
-
}
|
|
6372
|
-
createTogetherAI();
|
|
6373
5752
|
function convertToXaiChatMessages(prompt) {
|
|
6374
5753
|
const messages = [];
|
|
6375
5754
|
const warnings = [];
|
|
@@ -6397,11 +5776,11 @@ function convertToXaiChatMessages(prompt) {
|
|
|
6397
5776
|
return {
|
|
6398
5777
|
type: "image_url",
|
|
6399
5778
|
image_url: {
|
|
6400
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${
|
|
5779
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
6401
5780
|
}
|
|
6402
5781
|
};
|
|
6403
5782
|
} else {
|
|
6404
|
-
throw new
|
|
5783
|
+
throw new UnsupportedFunctionalityError2({
|
|
6405
5784
|
functionality: `file part media type ${part.mediaType}`
|
|
6406
5785
|
});
|
|
6407
5786
|
}
|
|
@@ -6582,7 +5961,7 @@ var xaiErrorDataSchema = z.object({
|
|
|
6582
5961
|
code: z.union([z.string(), z.number()]).nullish()
|
|
6583
5962
|
})
|
|
6584
5963
|
});
|
|
6585
|
-
var xaiFailedResponseHandler =
|
|
5964
|
+
var xaiFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
6586
5965
|
errorSchema: xaiErrorDataSchema,
|
|
6587
5966
|
errorToMessage: (data) => data.error.message
|
|
6588
5967
|
});
|
|
@@ -6631,7 +6010,7 @@ function prepareTools4({
|
|
|
6631
6010
|
};
|
|
6632
6011
|
default: {
|
|
6633
6012
|
const _exhaustiveCheck = type;
|
|
6634
|
-
throw new
|
|
6013
|
+
throw new UnsupportedFunctionalityError2({
|
|
6635
6014
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
6636
6015
|
});
|
|
6637
6016
|
}
|
|
@@ -6664,13 +6043,13 @@ var XaiChatLanguageModel = class {
|
|
|
6664
6043
|
tools,
|
|
6665
6044
|
toolChoice
|
|
6666
6045
|
}) {
|
|
6667
|
-
var
|
|
6046
|
+
var _a15, _b, _c;
|
|
6668
6047
|
const warnings = [];
|
|
6669
|
-
const options = (
|
|
6048
|
+
const options = (_a15 = await parseProviderOptions2({
|
|
6670
6049
|
provider: "xai",
|
|
6671
6050
|
providerOptions,
|
|
6672
6051
|
schema: xaiProviderOptions
|
|
6673
|
-
})) != null ?
|
|
6052
|
+
})) != null ? _a15 : {};
|
|
6674
6053
|
if (topK != null) {
|
|
6675
6054
|
warnings.push({
|
|
6676
6055
|
type: "unsupported-setting",
|
|
@@ -6721,7 +6100,7 @@ var XaiChatLanguageModel = class {
|
|
|
6721
6100
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
6722
6101
|
type: "json_schema",
|
|
6723
6102
|
json_schema: {
|
|
6724
|
-
name: (
|
|
6103
|
+
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
6725
6104
|
schema: responseFormat.schema,
|
|
6726
6105
|
strict: true
|
|
6727
6106
|
}
|
|
@@ -6734,7 +6113,7 @@ var XaiChatLanguageModel = class {
|
|
|
6734
6113
|
to_date: options.searchParameters.toDate,
|
|
6735
6114
|
max_search_results: options.searchParameters.maxSearchResults,
|
|
6736
6115
|
sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => {
|
|
6737
|
-
var
|
|
6116
|
+
var _a22;
|
|
6738
6117
|
return {
|
|
6739
6118
|
type: source.type,
|
|
6740
6119
|
...source.type === "web" && {
|
|
@@ -6745,7 +6124,7 @@ var XaiChatLanguageModel = class {
|
|
|
6745
6124
|
},
|
|
6746
6125
|
...source.type === "x" && {
|
|
6747
6126
|
excluded_x_handles: source.excludedXHandles,
|
|
6748
|
-
included_x_handles: (
|
|
6127
|
+
included_x_handles: (_a22 = source.includedXHandles) != null ? _a22 : source.xHandles,
|
|
6749
6128
|
post_favorite_count: source.postFavoriteCount,
|
|
6750
6129
|
post_view_count: source.postViewCount
|
|
6751
6130
|
},
|
|
@@ -6772,18 +6151,18 @@ var XaiChatLanguageModel = class {
|
|
|
6772
6151
|
};
|
|
6773
6152
|
}
|
|
6774
6153
|
async doGenerate(options) {
|
|
6775
|
-
var
|
|
6154
|
+
var _a15, _b, _c;
|
|
6776
6155
|
const { args: body, warnings } = await this.getArgs(options);
|
|
6777
6156
|
const {
|
|
6778
6157
|
responseHeaders,
|
|
6779
6158
|
value: response,
|
|
6780
6159
|
rawValue: rawResponse
|
|
6781
|
-
} = await
|
|
6782
|
-
url: `${(
|
|
6783
|
-
headers:
|
|
6160
|
+
} = await postJsonToApi2({
|
|
6161
|
+
url: `${(_a15 = this.config.baseURL) != null ? _a15 : "https://api.x.ai/v1"}/chat/completions`,
|
|
6162
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
6784
6163
|
body,
|
|
6785
6164
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
6786
|
-
successfulResponseHandler:
|
|
6165
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
6787
6166
|
xaiChatResponseSchema
|
|
6788
6167
|
),
|
|
6789
6168
|
abortSignal: options.abortSignal,
|
|
@@ -6834,7 +6213,7 @@ var XaiChatLanguageModel = class {
|
|
|
6834
6213
|
inputTokens: response.usage.prompt_tokens,
|
|
6835
6214
|
outputTokens: response.usage.completion_tokens,
|
|
6836
6215
|
totalTokens: response.usage.total_tokens,
|
|
6837
|
-
reasoningTokens: (_c = (
|
|
6216
|
+
reasoningTokens: (_c = (_b = response.usage.completion_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null ? _c : void 0
|
|
6838
6217
|
},
|
|
6839
6218
|
request: { body },
|
|
6840
6219
|
response: {
|
|
@@ -6846,7 +6225,7 @@ var XaiChatLanguageModel = class {
|
|
|
6846
6225
|
};
|
|
6847
6226
|
}
|
|
6848
6227
|
async doStream(options) {
|
|
6849
|
-
var
|
|
6228
|
+
var _a15;
|
|
6850
6229
|
const { args, warnings } = await this.getArgs(options);
|
|
6851
6230
|
const body = {
|
|
6852
6231
|
...args,
|
|
@@ -6855,12 +6234,12 @@ var XaiChatLanguageModel = class {
|
|
|
6855
6234
|
include_usage: true
|
|
6856
6235
|
}
|
|
6857
6236
|
};
|
|
6858
|
-
const { responseHeaders, value: response } = await
|
|
6859
|
-
url: `${(
|
|
6860
|
-
headers:
|
|
6237
|
+
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
6238
|
+
url: `${(_a15 = this.config.baseURL) != null ? _a15 : "https://api.x.ai/v1"}/chat/completions`,
|
|
6239
|
+
headers: combineHeaders2(this.config.headers(), options.headers),
|
|
6861
6240
|
body,
|
|
6862
6241
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
6863
|
-
successfulResponseHandler:
|
|
6242
|
+
successfulResponseHandler: createEventSourceResponseHandler2(xaiChatChunkSchema),
|
|
6864
6243
|
abortSignal: options.abortSignal,
|
|
6865
6244
|
fetch: this.config.fetch
|
|
6866
6245
|
});
|
|
@@ -6881,7 +6260,7 @@ var XaiChatLanguageModel = class {
|
|
|
6881
6260
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6882
6261
|
},
|
|
6883
6262
|
transform(chunk, controller) {
|
|
6884
|
-
var
|
|
6263
|
+
var _a22, _b;
|
|
6885
6264
|
if (options.includeRawChunks) {
|
|
6886
6265
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6887
6266
|
}
|
|
@@ -6911,7 +6290,7 @@ var XaiChatLanguageModel = class {
|
|
|
6911
6290
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
6912
6291
|
usage.outputTokens = value.usage.completion_tokens;
|
|
6913
6292
|
usage.totalTokens = value.usage.total_tokens;
|
|
6914
|
-
usage.reasoningTokens = (
|
|
6293
|
+
usage.reasoningTokens = (_b = (_a22 = value.usage.completion_tokens_details) == null ? void 0 : _a22.reasoning_tokens) != null ? _b : void 0;
|
|
6915
6294
|
}
|
|
6916
6295
|
const choice = value.choices[0];
|
|
6917
6296
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -7068,33 +6447,33 @@ var xaiChatChunkSchema = z.object({
|
|
|
7068
6447
|
usage: xaiUsageSchema.nullish(),
|
|
7069
6448
|
citations: z.array(z.string().url()).nullish()
|
|
7070
6449
|
});
|
|
7071
|
-
var
|
|
6450
|
+
var VERSION7 = "2.0.33" ;
|
|
7072
6451
|
var xaiErrorStructure = {
|
|
7073
6452
|
errorSchema: xaiErrorDataSchema,
|
|
7074
6453
|
errorToMessage: (data) => data.error.message
|
|
7075
6454
|
};
|
|
7076
6455
|
function createXai(options = {}) {
|
|
7077
|
-
var
|
|
7078
|
-
const baseURL =
|
|
7079
|
-
(
|
|
6456
|
+
var _a15;
|
|
6457
|
+
const baseURL = withoutTrailingSlash2(
|
|
6458
|
+
(_a15 = options.baseURL) != null ? _a15 : "https://api.x.ai/v1"
|
|
7080
6459
|
);
|
|
7081
|
-
const getHeaders = () =>
|
|
6460
|
+
const getHeaders = () => withUserAgentSuffix2(
|
|
7082
6461
|
{
|
|
7083
|
-
Authorization: `Bearer ${
|
|
6462
|
+
Authorization: `Bearer ${loadApiKey2({
|
|
7084
6463
|
apiKey: options.apiKey,
|
|
7085
6464
|
environmentVariableName: "XAI_API_KEY",
|
|
7086
6465
|
description: "xAI API key"
|
|
7087
6466
|
})}`,
|
|
7088
6467
|
...options.headers
|
|
7089
6468
|
},
|
|
7090
|
-
`ai-sdk/xai/${
|
|
6469
|
+
`ai-sdk/xai/${VERSION7}`
|
|
7091
6470
|
);
|
|
7092
6471
|
const createLanguageModel = (modelId) => {
|
|
7093
6472
|
return new XaiChatLanguageModel(modelId, {
|
|
7094
6473
|
provider: "xai.chat",
|
|
7095
6474
|
baseURL,
|
|
7096
6475
|
headers: getHeaders,
|
|
7097
|
-
generateId,
|
|
6476
|
+
generateId: generateId2,
|
|
7098
6477
|
fetch: options.fetch
|
|
7099
6478
|
});
|
|
7100
6479
|
};
|
|
@@ -7111,7 +6490,7 @@ function createXai(options = {}) {
|
|
|
7111
6490
|
provider.languageModel = createLanguageModel;
|
|
7112
6491
|
provider.chat = createLanguageModel;
|
|
7113
6492
|
provider.textEmbeddingModel = (modelId) => {
|
|
7114
|
-
throw new
|
|
6493
|
+
throw new NoSuchModelError2({ modelId, modelType: "textEmbeddingModel" });
|
|
7115
6494
|
};
|
|
7116
6495
|
provider.imageModel = createImageModel;
|
|
7117
6496
|
provider.image = createImageModel;
|
|
@@ -7137,10 +6516,10 @@ var __spreadValues = (a, b) => {
|
|
|
7137
6516
|
return a;
|
|
7138
6517
|
};
|
|
7139
6518
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7140
|
-
var
|
|
7141
|
-
var
|
|
7142
|
-
var
|
|
7143
|
-
var
|
|
6519
|
+
var marker = "vercel.ai.error";
|
|
6520
|
+
var symbol = Symbol.for(marker);
|
|
6521
|
+
var _a;
|
|
6522
|
+
var _AISDKError = class _AISDKError2 extends Error {
|
|
7144
6523
|
/**
|
|
7145
6524
|
* Creates an AI SDK Error.
|
|
7146
6525
|
*
|
|
@@ -7150,13 +6529,13 @@ var _AISDKError2 = class _AISDKError22 extends Error {
|
|
|
7150
6529
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
7151
6530
|
*/
|
|
7152
6531
|
constructor({
|
|
7153
|
-
name:
|
|
6532
|
+
name: name14,
|
|
7154
6533
|
message,
|
|
7155
6534
|
cause
|
|
7156
6535
|
}) {
|
|
7157
6536
|
super(message);
|
|
7158
|
-
this[
|
|
7159
|
-
this.name =
|
|
6537
|
+
this[_a] = true;
|
|
6538
|
+
this.name = name14;
|
|
7160
6539
|
this.cause = cause;
|
|
7161
6540
|
}
|
|
7162
6541
|
/**
|
|
@@ -7165,20 +6544,20 @@ var _AISDKError2 = class _AISDKError22 extends Error {
|
|
|
7165
6544
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
7166
6545
|
*/
|
|
7167
6546
|
static isInstance(error) {
|
|
7168
|
-
return
|
|
6547
|
+
return _AISDKError2.hasMarker(error, marker);
|
|
7169
6548
|
}
|
|
7170
|
-
static hasMarker(error,
|
|
7171
|
-
const markerSymbol = Symbol.for(
|
|
6549
|
+
static hasMarker(error, marker15) {
|
|
6550
|
+
const markerSymbol = Symbol.for(marker15);
|
|
7172
6551
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
7173
6552
|
}
|
|
7174
6553
|
};
|
|
7175
|
-
|
|
7176
|
-
var
|
|
7177
|
-
var
|
|
7178
|
-
var
|
|
7179
|
-
var
|
|
7180
|
-
var
|
|
7181
|
-
var
|
|
6554
|
+
_a = symbol;
|
|
6555
|
+
var AISDKError = _AISDKError;
|
|
6556
|
+
var name = "AI_APICallError";
|
|
6557
|
+
var marker2 = `vercel.ai.error.${name}`;
|
|
6558
|
+
var symbol2 = Symbol.for(marker2);
|
|
6559
|
+
var _a2;
|
|
6560
|
+
var APICallError2 = class extends AISDKError {
|
|
7182
6561
|
constructor({
|
|
7183
6562
|
message,
|
|
7184
6563
|
url,
|
|
@@ -7194,8 +6573,8 @@ var APICallError3 = class extends AISDKError2 {
|
|
|
7194
6573
|
// server error
|
|
7195
6574
|
data
|
|
7196
6575
|
}) {
|
|
7197
|
-
super({ name
|
|
7198
|
-
this[
|
|
6576
|
+
super({ name, message, cause });
|
|
6577
|
+
this[_a2] = true;
|
|
7199
6578
|
this.url = url;
|
|
7200
6579
|
this.requestBodyValues = requestBodyValues;
|
|
7201
6580
|
this.statusCode = statusCode;
|
|
@@ -7205,26 +6584,26 @@ var APICallError3 = class extends AISDKError2 {
|
|
|
7205
6584
|
this.data = data;
|
|
7206
6585
|
}
|
|
7207
6586
|
static isInstance(error) {
|
|
7208
|
-
return
|
|
6587
|
+
return AISDKError.hasMarker(error, marker2);
|
|
7209
6588
|
}
|
|
7210
6589
|
};
|
|
7211
|
-
|
|
7212
|
-
var
|
|
7213
|
-
var
|
|
7214
|
-
var
|
|
7215
|
-
var
|
|
7216
|
-
var
|
|
6590
|
+
_a2 = symbol2;
|
|
6591
|
+
var name2 = "AI_EmptyResponseBodyError";
|
|
6592
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
6593
|
+
var symbol3 = Symbol.for(marker3);
|
|
6594
|
+
var _a3;
|
|
6595
|
+
var EmptyResponseBodyError2 = class extends AISDKError {
|
|
7217
6596
|
// used in isInstance
|
|
7218
6597
|
constructor({ message = "Empty response body" } = {}) {
|
|
7219
|
-
super({ name:
|
|
7220
|
-
this[
|
|
6598
|
+
super({ name: name2, message });
|
|
6599
|
+
this[_a3] = true;
|
|
7221
6600
|
}
|
|
7222
6601
|
static isInstance(error) {
|
|
7223
|
-
return
|
|
6602
|
+
return AISDKError.hasMarker(error, marker3);
|
|
7224
6603
|
}
|
|
7225
6604
|
};
|
|
7226
|
-
|
|
7227
|
-
function
|
|
6605
|
+
_a3 = symbol3;
|
|
6606
|
+
function getErrorMessage(error) {
|
|
7228
6607
|
if (error == null) {
|
|
7229
6608
|
return "unknown error";
|
|
7230
6609
|
}
|
|
@@ -7236,131 +6615,131 @@ function getErrorMessage2(error) {
|
|
|
7236
6615
|
}
|
|
7237
6616
|
return JSON.stringify(error);
|
|
7238
6617
|
}
|
|
7239
|
-
var
|
|
7240
|
-
var
|
|
7241
|
-
var
|
|
7242
|
-
var
|
|
7243
|
-
var
|
|
6618
|
+
var name3 = "AI_InvalidArgumentError";
|
|
6619
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
|
6620
|
+
var symbol4 = Symbol.for(marker4);
|
|
6621
|
+
var _a4;
|
|
6622
|
+
var InvalidArgumentError2 = class extends AISDKError {
|
|
7244
6623
|
constructor({
|
|
7245
6624
|
message,
|
|
7246
6625
|
cause,
|
|
7247
6626
|
argument
|
|
7248
6627
|
}) {
|
|
7249
|
-
super({ name:
|
|
7250
|
-
this[
|
|
6628
|
+
super({ name: name3, message, cause });
|
|
6629
|
+
this[_a4] = true;
|
|
7251
6630
|
this.argument = argument;
|
|
7252
6631
|
}
|
|
7253
6632
|
static isInstance(error) {
|
|
7254
|
-
return
|
|
6633
|
+
return AISDKError.hasMarker(error, marker4);
|
|
7255
6634
|
}
|
|
7256
6635
|
};
|
|
7257
|
-
|
|
7258
|
-
var
|
|
7259
|
-
var
|
|
7260
|
-
var
|
|
7261
|
-
var
|
|
7262
|
-
var InvalidPromptError2 = class extends
|
|
6636
|
+
_a4 = symbol4;
|
|
6637
|
+
var name4 = "AI_InvalidPromptError";
|
|
6638
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
|
6639
|
+
var symbol5 = Symbol.for(marker5);
|
|
6640
|
+
var _a5;
|
|
6641
|
+
var InvalidPromptError2 = class extends AISDKError {
|
|
7263
6642
|
constructor({
|
|
7264
6643
|
prompt,
|
|
7265
6644
|
message,
|
|
7266
6645
|
cause
|
|
7267
6646
|
}) {
|
|
7268
|
-
super({ name:
|
|
7269
|
-
this[
|
|
6647
|
+
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
6648
|
+
this[_a5] = true;
|
|
7270
6649
|
this.prompt = prompt;
|
|
7271
6650
|
}
|
|
7272
6651
|
static isInstance(error) {
|
|
7273
|
-
return
|
|
6652
|
+
return AISDKError.hasMarker(error, marker5);
|
|
7274
6653
|
}
|
|
7275
6654
|
};
|
|
7276
|
-
|
|
7277
|
-
var
|
|
7278
|
-
var
|
|
7279
|
-
var
|
|
7280
|
-
var
|
|
7281
|
-
var InvalidResponseDataError3 = class extends
|
|
6655
|
+
_a5 = symbol5;
|
|
6656
|
+
var name5 = "AI_InvalidResponseDataError";
|
|
6657
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
|
6658
|
+
var symbol6 = Symbol.for(marker6);
|
|
6659
|
+
var _a6;
|
|
6660
|
+
var InvalidResponseDataError3 = class extends AISDKError {
|
|
7282
6661
|
constructor({
|
|
7283
6662
|
data,
|
|
7284
6663
|
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
7285
6664
|
}) {
|
|
7286
|
-
super({ name:
|
|
7287
|
-
this[
|
|
6665
|
+
super({ name: name5, message });
|
|
6666
|
+
this[_a6] = true;
|
|
7288
6667
|
this.data = data;
|
|
7289
6668
|
}
|
|
7290
6669
|
static isInstance(error) {
|
|
7291
|
-
return
|
|
6670
|
+
return AISDKError.hasMarker(error, marker6);
|
|
7292
6671
|
}
|
|
7293
6672
|
};
|
|
7294
|
-
|
|
7295
|
-
var
|
|
7296
|
-
var
|
|
7297
|
-
var
|
|
7298
|
-
var
|
|
7299
|
-
var
|
|
6673
|
+
_a6 = symbol6;
|
|
6674
|
+
var name6 = "AI_JSONParseError";
|
|
6675
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
|
6676
|
+
var symbol7 = Symbol.for(marker7);
|
|
6677
|
+
var _a7;
|
|
6678
|
+
var JSONParseError2 = class extends AISDKError {
|
|
7300
6679
|
constructor({ text, cause }) {
|
|
7301
6680
|
super({
|
|
7302
|
-
name:
|
|
6681
|
+
name: name6,
|
|
7303
6682
|
message: `JSON parsing failed: Text: ${text}.
|
|
7304
|
-
Error message: ${
|
|
6683
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
7305
6684
|
cause
|
|
7306
6685
|
});
|
|
7307
|
-
this[
|
|
6686
|
+
this[_a7] = true;
|
|
7308
6687
|
this.text = text;
|
|
7309
6688
|
}
|
|
7310
6689
|
static isInstance(error) {
|
|
7311
|
-
return
|
|
6690
|
+
return AISDKError.hasMarker(error, marker7);
|
|
7312
6691
|
}
|
|
7313
6692
|
};
|
|
7314
|
-
|
|
7315
|
-
var
|
|
7316
|
-
var
|
|
7317
|
-
var
|
|
7318
|
-
var
|
|
7319
|
-
var
|
|
6693
|
+
_a7 = symbol7;
|
|
6694
|
+
var name7 = "AI_LoadAPIKeyError";
|
|
6695
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
|
6696
|
+
var symbol8 = Symbol.for(marker8);
|
|
6697
|
+
var _a8;
|
|
6698
|
+
var LoadAPIKeyError2 = class extends AISDKError {
|
|
7320
6699
|
// used in isInstance
|
|
7321
6700
|
constructor({ message }) {
|
|
7322
|
-
super({ name:
|
|
7323
|
-
this[
|
|
6701
|
+
super({ name: name7, message });
|
|
6702
|
+
this[_a8] = true;
|
|
7324
6703
|
}
|
|
7325
6704
|
static isInstance(error) {
|
|
7326
|
-
return
|
|
6705
|
+
return AISDKError.hasMarker(error, marker8);
|
|
7327
6706
|
}
|
|
7328
6707
|
};
|
|
7329
|
-
|
|
7330
|
-
var
|
|
7331
|
-
var
|
|
7332
|
-
var
|
|
7333
|
-
var
|
|
7334
|
-
var
|
|
6708
|
+
_a8 = symbol8;
|
|
6709
|
+
var name9 = "AI_NoContentGeneratedError";
|
|
6710
|
+
var marker10 = `vercel.ai.error.${name9}`;
|
|
6711
|
+
var symbol10 = Symbol.for(marker10);
|
|
6712
|
+
var _a10;
|
|
6713
|
+
var NoContentGeneratedError = class extends AISDKError {
|
|
7335
6714
|
// used in isInstance
|
|
7336
6715
|
constructor({
|
|
7337
6716
|
message = "No content generated."
|
|
7338
6717
|
} = {}) {
|
|
7339
|
-
super({ name:
|
|
7340
|
-
this[
|
|
6718
|
+
super({ name: name9, message });
|
|
6719
|
+
this[_a10] = true;
|
|
7341
6720
|
}
|
|
7342
6721
|
static isInstance(error) {
|
|
7343
|
-
return
|
|
6722
|
+
return AISDKError.hasMarker(error, marker10);
|
|
7344
6723
|
}
|
|
7345
6724
|
};
|
|
7346
|
-
|
|
7347
|
-
var
|
|
7348
|
-
var
|
|
7349
|
-
var
|
|
7350
|
-
var
|
|
7351
|
-
var
|
|
6725
|
+
_a10 = symbol10;
|
|
6726
|
+
var name12 = "AI_TypeValidationError";
|
|
6727
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
6728
|
+
var symbol13 = Symbol.for(marker13);
|
|
6729
|
+
var _a13;
|
|
6730
|
+
var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
|
|
7352
6731
|
constructor({ value, cause }) {
|
|
7353
6732
|
super({
|
|
7354
|
-
name:
|
|
6733
|
+
name: name12,
|
|
7355
6734
|
message: `Type validation failed: Value: ${JSON.stringify(value)}.
|
|
7356
|
-
Error message: ${
|
|
6735
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
7357
6736
|
cause
|
|
7358
6737
|
});
|
|
7359
|
-
this[
|
|
6738
|
+
this[_a13] = true;
|
|
7360
6739
|
this.value = value;
|
|
7361
6740
|
}
|
|
7362
6741
|
static isInstance(error) {
|
|
7363
|
-
return
|
|
6742
|
+
return AISDKError.hasMarker(error, marker13);
|
|
7364
6743
|
}
|
|
7365
6744
|
/**
|
|
7366
6745
|
* Wraps an error into a TypeValidationError.
|
|
@@ -7376,29 +6755,29 @@ Error message: ${getErrorMessage2(cause)}`,
|
|
|
7376
6755
|
value,
|
|
7377
6756
|
cause
|
|
7378
6757
|
}) {
|
|
7379
|
-
return
|
|
6758
|
+
return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
|
|
7380
6759
|
}
|
|
7381
6760
|
};
|
|
7382
|
-
|
|
7383
|
-
var
|
|
7384
|
-
var
|
|
7385
|
-
var
|
|
7386
|
-
var
|
|
7387
|
-
var
|
|
7388
|
-
var UnsupportedFunctionalityError3 = class extends
|
|
6761
|
+
_a13 = symbol13;
|
|
6762
|
+
var TypeValidationError2 = _TypeValidationError;
|
|
6763
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
6764
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
6765
|
+
var symbol14 = Symbol.for(marker14);
|
|
6766
|
+
var _a14;
|
|
6767
|
+
var UnsupportedFunctionalityError3 = class extends AISDKError {
|
|
7389
6768
|
constructor({
|
|
7390
6769
|
functionality,
|
|
7391
6770
|
message = `'${functionality}' functionality not supported.`
|
|
7392
6771
|
}) {
|
|
7393
|
-
super({ name:
|
|
7394
|
-
this[
|
|
6772
|
+
super({ name: name13, message });
|
|
6773
|
+
this[_a14] = true;
|
|
7395
6774
|
this.functionality = functionality;
|
|
7396
6775
|
}
|
|
7397
6776
|
static isInstance(error) {
|
|
7398
|
-
return
|
|
6777
|
+
return AISDKError.hasMarker(error, marker14);
|
|
7399
6778
|
}
|
|
7400
6779
|
};
|
|
7401
|
-
|
|
6780
|
+
_a14 = symbol14;
|
|
7402
6781
|
var ParseError = class extends Error {
|
|
7403
6782
|
constructor(message, options) {
|
|
7404
6783
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
@@ -7529,10 +6908,10 @@ function combineHeaders5(...headers) {
|
|
|
7529
6908
|
{}
|
|
7530
6909
|
);
|
|
7531
6910
|
}
|
|
7532
|
-
function
|
|
6911
|
+
function extractResponseHeaders3(response) {
|
|
7533
6912
|
return Object.fromEntries([...response.headers]);
|
|
7534
6913
|
}
|
|
7535
|
-
var
|
|
6914
|
+
var createIdGenerator3 = ({
|
|
7536
6915
|
prefix,
|
|
7537
6916
|
size = 16,
|
|
7538
6917
|
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
@@ -7550,31 +6929,31 @@ var createIdGenerator4 = ({
|
|
|
7550
6929
|
return generator;
|
|
7551
6930
|
}
|
|
7552
6931
|
if (alphabet.includes(separator)) {
|
|
7553
|
-
throw new
|
|
6932
|
+
throw new InvalidArgumentError2({
|
|
7554
6933
|
argument: "separator",
|
|
7555
6934
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
7556
6935
|
});
|
|
7557
6936
|
}
|
|
7558
6937
|
return () => `${prefix}${separator}${generator()}`;
|
|
7559
6938
|
};
|
|
7560
|
-
var generateId5 =
|
|
7561
|
-
function
|
|
6939
|
+
var generateId5 = createIdGenerator3();
|
|
6940
|
+
function isAbortError3(error) {
|
|
7562
6941
|
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
7563
6942
|
error.name === "TimeoutError");
|
|
7564
6943
|
}
|
|
7565
|
-
var
|
|
7566
|
-
function
|
|
6944
|
+
var FETCH_FAILED_ERROR_MESSAGES3 = ["fetch failed", "failed to fetch"];
|
|
6945
|
+
function handleFetchError3({
|
|
7567
6946
|
error,
|
|
7568
6947
|
url,
|
|
7569
6948
|
requestBodyValues
|
|
7570
6949
|
}) {
|
|
7571
|
-
if (
|
|
6950
|
+
if (isAbortError3(error)) {
|
|
7572
6951
|
return error;
|
|
7573
6952
|
}
|
|
7574
|
-
if (error instanceof TypeError &&
|
|
6953
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES3.includes(error.message.toLowerCase())) {
|
|
7575
6954
|
const cause = error.cause;
|
|
7576
6955
|
if (cause != null) {
|
|
7577
|
-
return new
|
|
6956
|
+
return new APICallError2({
|
|
7578
6957
|
message: `Cannot connect to API: ${cause.message}`,
|
|
7579
6958
|
cause,
|
|
7580
6959
|
url,
|
|
@@ -7601,41 +6980,41 @@ function loadApiKey5({
|
|
|
7601
6980
|
return apiKey;
|
|
7602
6981
|
}
|
|
7603
6982
|
if (apiKey != null) {
|
|
7604
|
-
throw new
|
|
6983
|
+
throw new LoadAPIKeyError2({
|
|
7605
6984
|
message: `${description} API key must be a string.`
|
|
7606
6985
|
});
|
|
7607
6986
|
}
|
|
7608
6987
|
if (typeof process === "undefined") {
|
|
7609
|
-
throw new
|
|
6988
|
+
throw new LoadAPIKeyError2({
|
|
7610
6989
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
7611
6990
|
});
|
|
7612
6991
|
}
|
|
7613
6992
|
apiKey = process.env[environmentVariableName];
|
|
7614
6993
|
if (apiKey == null) {
|
|
7615
|
-
throw new
|
|
6994
|
+
throw new LoadAPIKeyError2({
|
|
7616
6995
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
7617
6996
|
});
|
|
7618
6997
|
}
|
|
7619
6998
|
if (typeof apiKey !== "string") {
|
|
7620
|
-
throw new
|
|
6999
|
+
throw new LoadAPIKeyError2({
|
|
7621
7000
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
7622
7001
|
});
|
|
7623
7002
|
}
|
|
7624
7003
|
return apiKey;
|
|
7625
7004
|
}
|
|
7626
|
-
var
|
|
7627
|
-
var
|
|
7628
|
-
function
|
|
7005
|
+
var suspectProtoRx3 = /"__proto__"\s*:/;
|
|
7006
|
+
var suspectConstructorRx3 = /"constructor"\s*:/;
|
|
7007
|
+
function _parse3(text) {
|
|
7629
7008
|
const obj = JSON.parse(text);
|
|
7630
7009
|
if (obj === null || typeof obj !== "object") {
|
|
7631
7010
|
return obj;
|
|
7632
7011
|
}
|
|
7633
|
-
if (
|
|
7012
|
+
if (suspectProtoRx3.test(text) === false && suspectConstructorRx3.test(text) === false) {
|
|
7634
7013
|
return obj;
|
|
7635
7014
|
}
|
|
7636
|
-
return
|
|
7015
|
+
return filter3(obj);
|
|
7637
7016
|
}
|
|
7638
|
-
function
|
|
7017
|
+
function filter3(obj) {
|
|
7639
7018
|
let next = [obj];
|
|
7640
7019
|
while (next.length) {
|
|
7641
7020
|
const nodes = next;
|
|
@@ -7657,52 +7036,52 @@ function filter4(obj) {
|
|
|
7657
7036
|
}
|
|
7658
7037
|
return obj;
|
|
7659
7038
|
}
|
|
7660
|
-
function
|
|
7039
|
+
function secureJsonParse3(text) {
|
|
7661
7040
|
const { stackTraceLimit } = Error;
|
|
7662
7041
|
Error.stackTraceLimit = 0;
|
|
7663
7042
|
try {
|
|
7664
|
-
return
|
|
7043
|
+
return _parse3(text);
|
|
7665
7044
|
} finally {
|
|
7666
7045
|
Error.stackTraceLimit = stackTraceLimit;
|
|
7667
7046
|
}
|
|
7668
7047
|
}
|
|
7669
|
-
var
|
|
7670
|
-
function
|
|
7671
|
-
return { [
|
|
7048
|
+
var validatorSymbol3 = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
7049
|
+
function validator3(validate) {
|
|
7050
|
+
return { [validatorSymbol3]: true, validate };
|
|
7672
7051
|
}
|
|
7673
|
-
function
|
|
7674
|
-
return typeof value === "object" && value !== null &&
|
|
7052
|
+
function isValidator3(value) {
|
|
7053
|
+
return typeof value === "object" && value !== null && validatorSymbol3 in value && value[validatorSymbol3] === true && "validate" in value;
|
|
7675
7054
|
}
|
|
7676
|
-
function
|
|
7677
|
-
return
|
|
7055
|
+
function asValidator3(value) {
|
|
7056
|
+
return isValidator3(value) ? value : standardSchemaValidator3(value);
|
|
7678
7057
|
}
|
|
7679
|
-
function
|
|
7680
|
-
return
|
|
7058
|
+
function standardSchemaValidator3(standardSchema) {
|
|
7059
|
+
return validator3(async (value) => {
|
|
7681
7060
|
const result = await standardSchema["~standard"].validate(value);
|
|
7682
7061
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
7683
7062
|
success: false,
|
|
7684
|
-
error: new
|
|
7063
|
+
error: new TypeValidationError2({
|
|
7685
7064
|
value,
|
|
7686
7065
|
cause: result.issues
|
|
7687
7066
|
})
|
|
7688
7067
|
};
|
|
7689
7068
|
});
|
|
7690
7069
|
}
|
|
7691
|
-
async function
|
|
7070
|
+
async function validateTypes3({
|
|
7692
7071
|
value,
|
|
7693
7072
|
schema
|
|
7694
7073
|
}) {
|
|
7695
|
-
const result = await
|
|
7074
|
+
const result = await safeValidateTypes3({ value, schema });
|
|
7696
7075
|
if (!result.success) {
|
|
7697
|
-
throw
|
|
7076
|
+
throw TypeValidationError2.wrap({ value, cause: result.error });
|
|
7698
7077
|
}
|
|
7699
7078
|
return result.value;
|
|
7700
7079
|
}
|
|
7701
|
-
async function
|
|
7080
|
+
async function safeValidateTypes3({
|
|
7702
7081
|
value,
|
|
7703
7082
|
schema
|
|
7704
7083
|
}) {
|
|
7705
|
-
const validator22 =
|
|
7084
|
+
const validator22 = asValidator3(schema);
|
|
7706
7085
|
try {
|
|
7707
7086
|
if (validator22.validate == null) {
|
|
7708
7087
|
return { success: true, value, rawValue: value };
|
|
@@ -7713,61 +7092,61 @@ async function safeValidateTypes4({
|
|
|
7713
7092
|
}
|
|
7714
7093
|
return {
|
|
7715
7094
|
success: false,
|
|
7716
|
-
error:
|
|
7095
|
+
error: TypeValidationError2.wrap({ value, cause: result.error }),
|
|
7717
7096
|
rawValue: value
|
|
7718
7097
|
};
|
|
7719
7098
|
} catch (error) {
|
|
7720
7099
|
return {
|
|
7721
7100
|
success: false,
|
|
7722
|
-
error:
|
|
7101
|
+
error: TypeValidationError2.wrap({ value, cause: error }),
|
|
7723
7102
|
rawValue: value
|
|
7724
7103
|
};
|
|
7725
7104
|
}
|
|
7726
7105
|
}
|
|
7727
|
-
async function
|
|
7106
|
+
async function parseJSON3({
|
|
7728
7107
|
text,
|
|
7729
7108
|
schema
|
|
7730
7109
|
}) {
|
|
7731
7110
|
try {
|
|
7732
|
-
const value =
|
|
7111
|
+
const value = secureJsonParse3(text);
|
|
7733
7112
|
if (schema == null) {
|
|
7734
7113
|
return value;
|
|
7735
7114
|
}
|
|
7736
|
-
return
|
|
7115
|
+
return validateTypes3({ value, schema });
|
|
7737
7116
|
} catch (error) {
|
|
7738
|
-
if (
|
|
7117
|
+
if (JSONParseError2.isInstance(error) || TypeValidationError2.isInstance(error)) {
|
|
7739
7118
|
throw error;
|
|
7740
7119
|
}
|
|
7741
|
-
throw new
|
|
7120
|
+
throw new JSONParseError2({ text, cause: error });
|
|
7742
7121
|
}
|
|
7743
7122
|
}
|
|
7744
|
-
async function
|
|
7123
|
+
async function safeParseJSON3({
|
|
7745
7124
|
text,
|
|
7746
7125
|
schema
|
|
7747
7126
|
}) {
|
|
7748
7127
|
try {
|
|
7749
|
-
const value =
|
|
7128
|
+
const value = secureJsonParse3(text);
|
|
7750
7129
|
if (schema == null) {
|
|
7751
7130
|
return { success: true, value, rawValue: value };
|
|
7752
7131
|
}
|
|
7753
|
-
return await
|
|
7132
|
+
return await safeValidateTypes3({ value, schema });
|
|
7754
7133
|
} catch (error) {
|
|
7755
7134
|
return {
|
|
7756
7135
|
success: false,
|
|
7757
|
-
error:
|
|
7136
|
+
error: JSONParseError2.isInstance(error) ? error : new JSONParseError2({ text, cause: error }),
|
|
7758
7137
|
rawValue: void 0
|
|
7759
7138
|
};
|
|
7760
7139
|
}
|
|
7761
7140
|
}
|
|
7762
7141
|
function isParsableJson3(input) {
|
|
7763
7142
|
try {
|
|
7764
|
-
|
|
7143
|
+
secureJsonParse3(input);
|
|
7765
7144
|
return true;
|
|
7766
7145
|
} catch (e) {
|
|
7767
7146
|
return false;
|
|
7768
7147
|
}
|
|
7769
7148
|
}
|
|
7770
|
-
function
|
|
7149
|
+
function parseJsonEventStream3({
|
|
7771
7150
|
stream,
|
|
7772
7151
|
schema
|
|
7773
7152
|
}) {
|
|
@@ -7777,12 +7156,12 @@ function parseJsonEventStream4({
|
|
|
7777
7156
|
if (data === "[DONE]") {
|
|
7778
7157
|
return;
|
|
7779
7158
|
}
|
|
7780
|
-
controller.enqueue(await
|
|
7159
|
+
controller.enqueue(await safeParseJSON3({ text: data, schema }));
|
|
7781
7160
|
}
|
|
7782
7161
|
})
|
|
7783
7162
|
);
|
|
7784
7163
|
}
|
|
7785
|
-
var
|
|
7164
|
+
var getOriginalFetch23 = () => globalThis.fetch;
|
|
7786
7165
|
var postJsonToApi5 = async ({
|
|
7787
7166
|
url,
|
|
7788
7167
|
headers,
|
|
@@ -7791,7 +7170,7 @@ var postJsonToApi5 = async ({
|
|
|
7791
7170
|
successfulResponseHandler,
|
|
7792
7171
|
abortSignal,
|
|
7793
7172
|
fetch: fetch2
|
|
7794
|
-
}) =>
|
|
7173
|
+
}) => postToApi3({
|
|
7795
7174
|
url,
|
|
7796
7175
|
headers: __spreadValues({
|
|
7797
7176
|
"Content-Type": "application/json"
|
|
@@ -7805,14 +7184,14 @@ var postJsonToApi5 = async ({
|
|
|
7805
7184
|
abortSignal,
|
|
7806
7185
|
fetch: fetch2
|
|
7807
7186
|
});
|
|
7808
|
-
var
|
|
7187
|
+
var postToApi3 = async ({
|
|
7809
7188
|
url,
|
|
7810
7189
|
headers = {},
|
|
7811
7190
|
body,
|
|
7812
7191
|
successfulResponseHandler,
|
|
7813
7192
|
failedResponseHandler,
|
|
7814
7193
|
abortSignal,
|
|
7815
|
-
fetch: fetch2 =
|
|
7194
|
+
fetch: fetch2 = getOriginalFetch23()
|
|
7816
7195
|
}) => {
|
|
7817
7196
|
try {
|
|
7818
7197
|
const response = await fetch2(url, {
|
|
@@ -7821,7 +7200,7 @@ var postToApi4 = async ({
|
|
|
7821
7200
|
body: body.content,
|
|
7822
7201
|
signal: abortSignal
|
|
7823
7202
|
});
|
|
7824
|
-
const responseHeaders =
|
|
7203
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
7825
7204
|
if (!response.ok) {
|
|
7826
7205
|
let errorInformation;
|
|
7827
7206
|
try {
|
|
@@ -7831,10 +7210,10 @@ var postToApi4 = async ({
|
|
|
7831
7210
|
requestBodyValues: body.values
|
|
7832
7211
|
});
|
|
7833
7212
|
} catch (error) {
|
|
7834
|
-
if (
|
|
7213
|
+
if (isAbortError3(error) || APICallError2.isInstance(error)) {
|
|
7835
7214
|
throw error;
|
|
7836
7215
|
}
|
|
7837
|
-
throw new
|
|
7216
|
+
throw new APICallError2({
|
|
7838
7217
|
message: "Failed to process error response",
|
|
7839
7218
|
cause: error,
|
|
7840
7219
|
statusCode: response.status,
|
|
@@ -7853,11 +7232,11 @@ var postToApi4 = async ({
|
|
|
7853
7232
|
});
|
|
7854
7233
|
} catch (error) {
|
|
7855
7234
|
if (error instanceof Error) {
|
|
7856
|
-
if (
|
|
7235
|
+
if (isAbortError3(error) || APICallError2.isInstance(error)) {
|
|
7857
7236
|
throw error;
|
|
7858
7237
|
}
|
|
7859
7238
|
}
|
|
7860
|
-
throw new
|
|
7239
|
+
throw new APICallError2({
|
|
7861
7240
|
message: "Failed to process successful response",
|
|
7862
7241
|
cause: error,
|
|
7863
7242
|
statusCode: response.status,
|
|
@@ -7867,7 +7246,7 @@ var postToApi4 = async ({
|
|
|
7867
7246
|
});
|
|
7868
7247
|
}
|
|
7869
7248
|
} catch (error) {
|
|
7870
|
-
throw
|
|
7249
|
+
throw handleFetchError3({ error, url, requestBodyValues: body.values });
|
|
7871
7250
|
}
|
|
7872
7251
|
};
|
|
7873
7252
|
var createJsonErrorResponseHandler5 = ({
|
|
@@ -7876,11 +7255,11 @@ var createJsonErrorResponseHandler5 = ({
|
|
|
7876
7255
|
isRetryable
|
|
7877
7256
|
}) => async ({ response, url, requestBodyValues }) => {
|
|
7878
7257
|
const responseBody = await response.text();
|
|
7879
|
-
const responseHeaders =
|
|
7258
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
7880
7259
|
if (responseBody.trim() === "") {
|
|
7881
7260
|
return {
|
|
7882
7261
|
responseHeaders,
|
|
7883
|
-
value: new
|
|
7262
|
+
value: new APICallError2({
|
|
7884
7263
|
message: response.statusText,
|
|
7885
7264
|
url,
|
|
7886
7265
|
requestBodyValues,
|
|
@@ -7892,13 +7271,13 @@ var createJsonErrorResponseHandler5 = ({
|
|
|
7892
7271
|
};
|
|
7893
7272
|
}
|
|
7894
7273
|
try {
|
|
7895
|
-
const parsedError = await
|
|
7274
|
+
const parsedError = await parseJSON3({
|
|
7896
7275
|
text: responseBody,
|
|
7897
7276
|
schema: errorSchema
|
|
7898
7277
|
});
|
|
7899
7278
|
return {
|
|
7900
7279
|
responseHeaders,
|
|
7901
|
-
value: new
|
|
7280
|
+
value: new APICallError2({
|
|
7902
7281
|
message: errorToMessage2(parsedError),
|
|
7903
7282
|
url,
|
|
7904
7283
|
requestBodyValues,
|
|
@@ -7912,7 +7291,7 @@ var createJsonErrorResponseHandler5 = ({
|
|
|
7912
7291
|
} catch (parseError) {
|
|
7913
7292
|
return {
|
|
7914
7293
|
responseHeaders,
|
|
7915
|
-
value: new
|
|
7294
|
+
value: new APICallError2({
|
|
7916
7295
|
message: response.statusText,
|
|
7917
7296
|
url,
|
|
7918
7297
|
requestBodyValues,
|
|
@@ -7925,13 +7304,13 @@ var createJsonErrorResponseHandler5 = ({
|
|
|
7925
7304
|
}
|
|
7926
7305
|
};
|
|
7927
7306
|
var createEventSourceResponseHandler5 = (chunkSchema) => async ({ response }) => {
|
|
7928
|
-
const responseHeaders =
|
|
7307
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
7929
7308
|
if (response.body == null) {
|
|
7930
|
-
throw new
|
|
7309
|
+
throw new EmptyResponseBodyError2({});
|
|
7931
7310
|
}
|
|
7932
7311
|
return {
|
|
7933
7312
|
responseHeaders,
|
|
7934
|
-
value:
|
|
7313
|
+
value: parseJsonEventStream3({
|
|
7935
7314
|
stream: response.body,
|
|
7936
7315
|
schema: chunkSchema
|
|
7937
7316
|
})
|
|
@@ -7939,13 +7318,13 @@ var createEventSourceResponseHandler5 = (chunkSchema) => async ({ response }) =>
|
|
|
7939
7318
|
};
|
|
7940
7319
|
var createJsonResponseHandler5 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
7941
7320
|
const responseBody = await response.text();
|
|
7942
|
-
const parsedResult = await
|
|
7321
|
+
const parsedResult = await safeParseJSON3({
|
|
7943
7322
|
text: responseBody,
|
|
7944
7323
|
schema: responseSchema
|
|
7945
7324
|
});
|
|
7946
|
-
const responseHeaders =
|
|
7325
|
+
const responseHeaders = extractResponseHeaders3(response);
|
|
7947
7326
|
if (!parsedResult.success) {
|
|
7948
|
-
throw new
|
|
7327
|
+
throw new APICallError2({
|
|
7949
7328
|
message: "Invalid JSON response",
|
|
7950
7329
|
cause: parsedResult.error,
|
|
7951
7330
|
statusCode: response.status,
|
|
@@ -7961,13 +7340,13 @@ var createJsonResponseHandler5 = (responseSchema) => async ({ response, url, req
|
|
|
7961
7340
|
rawValue: parsedResult.rawValue
|
|
7962
7341
|
};
|
|
7963
7342
|
};
|
|
7964
|
-
var { btoa:
|
|
7965
|
-
function
|
|
7343
|
+
var { btoa: btoa3} = globalThis;
|
|
7344
|
+
function convertUint8ArrayToBase642(array) {
|
|
7966
7345
|
let latin1string = "";
|
|
7967
7346
|
for (let i = 0; i < array.length; i++) {
|
|
7968
7347
|
latin1string += String.fromCodePoint(array[i]);
|
|
7969
7348
|
}
|
|
7970
|
-
return
|
|
7349
|
+
return btoa3(latin1string);
|
|
7971
7350
|
}
|
|
7972
7351
|
function withoutTrailingSlash5(url) {
|
|
7973
7352
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
@@ -8105,10 +7484,10 @@ function getFileUrl({
|
|
|
8105
7484
|
part,
|
|
8106
7485
|
defaultMediaType
|
|
8107
7486
|
}) {
|
|
8108
|
-
var
|
|
7487
|
+
var _a15, _b;
|
|
8109
7488
|
if (part.data instanceof Uint8Array) {
|
|
8110
|
-
const base64 =
|
|
8111
|
-
return `data:${(
|
|
7489
|
+
const base64 = convertUint8ArrayToBase642(part.data);
|
|
7490
|
+
return `data:${(_a15 = part.mediaType) != null ? _a15 : defaultMediaType};base64,${base64}`;
|
|
8112
7491
|
}
|
|
8113
7492
|
const stringUrl = part.data.toString();
|
|
8114
7493
|
if (isUrl({
|
|
@@ -8117,25 +7496,25 @@ function getFileUrl({
|
|
|
8117
7496
|
})) {
|
|
8118
7497
|
return stringUrl;
|
|
8119
7498
|
}
|
|
8120
|
-
return stringUrl.startsWith("data:") ? stringUrl : `data:${(
|
|
7499
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b = part.mediaType) != null ? _b : defaultMediaType};base64,${stringUrl}`;
|
|
8121
7500
|
}
|
|
8122
7501
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
8123
|
-
var
|
|
7502
|
+
var _a15;
|
|
8124
7503
|
const match = dataUrl.match(/^data:([^;]+)/);
|
|
8125
|
-
return match ? (
|
|
7504
|
+
return match ? (_a15 = match[1]) != null ? _a15 : defaultMediaType : defaultMediaType;
|
|
8126
7505
|
}
|
|
8127
7506
|
function getBase64FromDataUrl(dataUrl) {
|
|
8128
7507
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
8129
7508
|
return match ? match[1] : dataUrl;
|
|
8130
7509
|
}
|
|
8131
7510
|
function getCacheControl(providerMetadata) {
|
|
8132
|
-
var
|
|
7511
|
+
var _a15, _b, _c;
|
|
8133
7512
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
8134
7513
|
const openrouter2 = providerMetadata == null ? void 0 : providerMetadata.openrouter;
|
|
8135
|
-
return (_c = (
|
|
7514
|
+
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;
|
|
8136
7515
|
}
|
|
8137
7516
|
function convertToOpenRouterChatMessages(prompt) {
|
|
8138
|
-
var
|
|
7517
|
+
var _a15, _b, _c, _d, _e;
|
|
8139
7518
|
const messages = [];
|
|
8140
7519
|
for (const { role, content, providerOptions } of prompt) {
|
|
8141
7520
|
switch (role) {
|
|
@@ -8148,8 +7527,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
8148
7527
|
break;
|
|
8149
7528
|
}
|
|
8150
7529
|
case "user": {
|
|
8151
|
-
if (content.length === 1 && ((
|
|
8152
|
-
const cacheControl = (
|
|
7530
|
+
if (content.length === 1 && ((_a15 = content[0]) == null ? void 0 : _a15.type) === "text") {
|
|
7531
|
+
const cacheControl = (_b = getCacheControl(providerOptions)) != null ? _b : getCacheControl(content[0].providerOptions);
|
|
8153
7532
|
const contentWithCacheControl = cacheControl ? [
|
|
8154
7533
|
{
|
|
8155
7534
|
type: "text",
|
|
@@ -8166,7 +7545,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
8166
7545
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
8167
7546
|
const contentParts = content.map(
|
|
8168
7547
|
(part) => {
|
|
8169
|
-
var _a16,
|
|
7548
|
+
var _a16, _b2, _c2, _d2, _e2, _f;
|
|
8170
7549
|
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
8171
7550
|
switch (part.type) {
|
|
8172
7551
|
case "text":
|
|
@@ -8177,7 +7556,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
8177
7556
|
cache_control: cacheControl
|
|
8178
7557
|
};
|
|
8179
7558
|
case "file": {
|
|
8180
|
-
if ((
|
|
7559
|
+
if ((_b2 = part.mediaType) == null ? void 0 : _b2.startsWith("image/")) {
|
|
8181
7560
|
const url = getFileUrl({
|
|
8182
7561
|
part,
|
|
8183
7562
|
defaultMediaType: "image/jpeg"
|
|
@@ -8318,7 +7697,7 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
8318
7697
|
};
|
|
8319
7698
|
}
|
|
8320
7699
|
default: {
|
|
8321
|
-
throw new
|
|
7700
|
+
throw new InvalidArgumentError2({
|
|
8322
7701
|
argument: "toolChoice",
|
|
8323
7702
|
message: `Invalid tool choice type: ${JSON.stringify(toolChoice)}`
|
|
8324
7703
|
});
|
|
@@ -8550,7 +7929,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8550
7929
|
tools,
|
|
8551
7930
|
toolChoice
|
|
8552
7931
|
}) {
|
|
8553
|
-
var
|
|
7932
|
+
var _a15;
|
|
8554
7933
|
const baseArgs = __spreadValues(__spreadValues({
|
|
8555
7934
|
// model id:
|
|
8556
7935
|
model: this.modelId,
|
|
@@ -8590,7 +7969,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8590
7969
|
json_schema: __spreadValues({
|
|
8591
7970
|
schema: responseFormat.schema,
|
|
8592
7971
|
strict: true,
|
|
8593
|
-
name: (
|
|
7972
|
+
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
8594
7973
|
}, responseFormat.description && {
|
|
8595
7974
|
description: responseFormat.description
|
|
8596
7975
|
})
|
|
@@ -8614,7 +7993,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8614
7993
|
return baseArgs;
|
|
8615
7994
|
}
|
|
8616
7995
|
async doGenerate(options) {
|
|
8617
|
-
var
|
|
7996
|
+
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;
|
|
8618
7997
|
const providerOptions = options.providerOptions || {};
|
|
8619
7998
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
8620
7999
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -8634,7 +8013,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8634
8013
|
});
|
|
8635
8014
|
if ("error" in responseValue) {
|
|
8636
8015
|
const errorData = responseValue.error;
|
|
8637
|
-
throw new
|
|
8016
|
+
throw new APICallError2({
|
|
8638
8017
|
message: errorData.message,
|
|
8639
8018
|
url: this.config.url({
|
|
8640
8019
|
path: "/chat/completions",
|
|
@@ -8649,13 +8028,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8649
8028
|
const response = responseValue;
|
|
8650
8029
|
const choice = response.choices[0];
|
|
8651
8030
|
if (!choice) {
|
|
8652
|
-
throw new
|
|
8031
|
+
throw new NoContentGeneratedError({
|
|
8653
8032
|
message: "No choice in response"
|
|
8654
8033
|
});
|
|
8655
8034
|
}
|
|
8656
8035
|
const usageInfo = response.usage ? {
|
|
8657
|
-
inputTokens: (
|
|
8658
|
-
outputTokens: (
|
|
8036
|
+
inputTokens: (_a15 = response.usage.prompt_tokens) != null ? _a15 : 0,
|
|
8037
|
+
outputTokens: (_b = response.usage.completion_tokens) != null ? _b : 0,
|
|
8659
8038
|
totalTokens: ((_c = response.usage.prompt_tokens) != null ? _c : 0) + ((_d = response.usage.completion_tokens) != null ? _d : 0),
|
|
8660
8039
|
reasoningTokens: (_f = (_e = response.usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0,
|
|
8661
8040
|
cachedInputTokens: (_h = (_g = response.usage.prompt_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : 0
|
|
@@ -8784,7 +8163,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8784
8163
|
};
|
|
8785
8164
|
}
|
|
8786
8165
|
async doStream(options) {
|
|
8787
|
-
var
|
|
8166
|
+
var _a15;
|
|
8788
8167
|
const providerOptions = options.providerOptions || {};
|
|
8789
8168
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
8790
8169
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -8799,7 +8178,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8799
8178
|
// only include stream_options when in strict compatibility mode:
|
|
8800
8179
|
stream_options: this.config.compatibility === "strict" ? __spreadValues({
|
|
8801
8180
|
include_usage: true
|
|
8802
|
-
}, ((
|
|
8181
|
+
}, ((_a15 = this.settings.usage) == null ? void 0 : _a15.include) ? { include_usage: true } : {}) : void 0
|
|
8803
8182
|
}),
|
|
8804
8183
|
failedResponseHandler: openrouterFailedResponseHandler,
|
|
8805
8184
|
successfulResponseHandler: createEventSourceResponseHandler5(
|
|
@@ -8829,7 +8208,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8829
8208
|
stream: response.pipeThrough(
|
|
8830
8209
|
new TransformStream({
|
|
8831
8210
|
transform(chunk, controller) {
|
|
8832
|
-
var _a16,
|
|
8211
|
+
var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
8833
8212
|
if (!chunk.success) {
|
|
8834
8213
|
finishReason = "error";
|
|
8835
8214
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -8871,7 +8250,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
8871
8250
|
}
|
|
8872
8251
|
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
8873
8252
|
if (value.usage.completion_tokens_details) {
|
|
8874
|
-
const reasoningTokens = (
|
|
8253
|
+
const reasoningTokens = (_b = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b : 0;
|
|
8875
8254
|
usage.reasoningTokens = reasoningTokens;
|
|
8876
8255
|
openrouterUsage.completionTokensDetails = {
|
|
8877
8256
|
reasoningTokens
|
|
@@ -9340,7 +8719,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9340
8719
|
}, this.config.extraBody), this.settings.extraBody);
|
|
9341
8720
|
}
|
|
9342
8721
|
async doGenerate(options) {
|
|
9343
|
-
var
|
|
8722
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
9344
8723
|
const providerOptions = options.providerOptions || {};
|
|
9345
8724
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
9346
8725
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -9360,7 +8739,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9360
8739
|
});
|
|
9361
8740
|
if ("error" in response) {
|
|
9362
8741
|
const errorData = response.error;
|
|
9363
|
-
throw new
|
|
8742
|
+
throw new APICallError2({
|
|
9364
8743
|
message: errorData.message,
|
|
9365
8744
|
url: this.config.url({
|
|
9366
8745
|
path: "/completions",
|
|
@@ -9374,7 +8753,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9374
8753
|
}
|
|
9375
8754
|
const choice = response.choices[0];
|
|
9376
8755
|
if (!choice) {
|
|
9377
|
-
throw new
|
|
8756
|
+
throw new NoContentGeneratedError({
|
|
9378
8757
|
message: "No choice in OpenRouter completion response"
|
|
9379
8758
|
});
|
|
9380
8759
|
}
|
|
@@ -9382,12 +8761,12 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9382
8761
|
content: [
|
|
9383
8762
|
{
|
|
9384
8763
|
type: "text",
|
|
9385
|
-
text: (
|
|
8764
|
+
text: (_a15 = choice.text) != null ? _a15 : ""
|
|
9386
8765
|
}
|
|
9387
8766
|
],
|
|
9388
8767
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
9389
8768
|
usage: {
|
|
9390
|
-
inputTokens: (_c = (
|
|
8769
|
+
inputTokens: (_c = (_b = response.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : 0,
|
|
9391
8770
|
outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
|
|
9392
8771
|
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),
|
|
9393
8772
|
reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
|
|
@@ -9434,7 +8813,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9434
8813
|
stream: response.pipeThrough(
|
|
9435
8814
|
new TransformStream({
|
|
9436
8815
|
transform(chunk, controller) {
|
|
9437
|
-
var
|
|
8816
|
+
var _a15, _b;
|
|
9438
8817
|
if (!chunk.success) {
|
|
9439
8818
|
finishReason = "error";
|
|
9440
8819
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -9452,7 +8831,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9452
8831
|
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
9453
8832
|
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
9454
8833
|
if (value.usage.prompt_tokens_details) {
|
|
9455
|
-
const cachedInputTokens = (
|
|
8834
|
+
const cachedInputTokens = (_a15 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a15 : 0;
|
|
9456
8835
|
usage.cachedInputTokens = cachedInputTokens;
|
|
9457
8836
|
openrouterUsage.promptTokensDetails = {
|
|
9458
8837
|
cachedTokens: cachedInputTokens
|
|
@@ -9460,7 +8839,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
9460
8839
|
}
|
|
9461
8840
|
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
9462
8841
|
if (value.usage.completion_tokens_details) {
|
|
9463
|
-
const reasoningTokens = (
|
|
8842
|
+
const reasoningTokens = (_b = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b : 0;
|
|
9464
8843
|
usage.reasoningTokens = reasoningTokens;
|
|
9465
8844
|
openrouterUsage.completionTokensDetails = {
|
|
9466
8845
|
reasoningTokens
|
|
@@ -9516,10 +8895,10 @@ function withUserAgentSuffix4(headers, ...userAgentSuffixParts) {
|
|
|
9516
8895
|
"user-agent": newUserAgent
|
|
9517
8896
|
});
|
|
9518
8897
|
}
|
|
9519
|
-
var
|
|
8898
|
+
var VERSION8 = "1.2.3";
|
|
9520
8899
|
function createOpenRouter(options = {}) {
|
|
9521
|
-
var
|
|
9522
|
-
const baseURL = (
|
|
8900
|
+
var _a15, _b, _c;
|
|
8901
|
+
const baseURL = (_b = withoutTrailingSlash5((_a15 = options.baseURL) != null ? _a15 : options.baseUrl)) != null ? _b : "https://openrouter.ai/api/v1";
|
|
9523
8902
|
const compatibility = (_c = options.compatibility) != null ? _c : "compatible";
|
|
9524
8903
|
const getHeaders = () => withUserAgentSuffix4(
|
|
9525
8904
|
__spreadValues({
|
|
@@ -9529,7 +8908,7 @@ function createOpenRouter(options = {}) {
|
|
|
9529
8908
|
description: "OpenRouter"
|
|
9530
8909
|
})}`
|
|
9531
8910
|
}, options.headers),
|
|
9532
|
-
`ai-sdk/openrouter/${
|
|
8911
|
+
`ai-sdk/openrouter/${VERSION8}`
|
|
9533
8912
|
);
|
|
9534
8913
|
const createChatModel = (modelId, settings = {}) => new OpenRouterChatLanguageModel(modelId, settings, {
|
|
9535
8914
|
provider: "openrouter.chat",
|
|
@@ -9633,6 +9012,16 @@ var OPENAI_COMPATIBLE_OVERRIDES = {
|
|
|
9633
9012
|
vercel: {
|
|
9634
9013
|
url: "https://ai-gateway.vercel.sh/v1",
|
|
9635
9014
|
apiKeyEnvVar: "AI_GATEWAY_API_KEY"
|
|
9015
|
+
},
|
|
9016
|
+
// moonshotai uses Anthropic-compatible API, not OpenAI-compatible
|
|
9017
|
+
moonshotai: {
|
|
9018
|
+
url: "https://api.moonshot.ai/anthropic/v1",
|
|
9019
|
+
npm: "@ai-sdk/anthropic"
|
|
9020
|
+
},
|
|
9021
|
+
// moonshotai-cn (China version) also uses Anthropic-compatible API
|
|
9022
|
+
"moonshotai-cn": {
|
|
9023
|
+
url: "https://api.moonshot.cn/anthropic/v1",
|
|
9024
|
+
npm: "@ai-sdk/anthropic"
|
|
9636
9025
|
}
|
|
9637
9026
|
};
|
|
9638
9027
|
var ModelsDevGateway = class extends MastraModelGateway {
|
|
@@ -9745,6 +9134,11 @@ var ModelsDevGateway = class extends MastraModelGateway {
|
|
|
9745
9134
|
return createTogetherAI({ apiKey })(modelId);
|
|
9746
9135
|
case "deepinfra":
|
|
9747
9136
|
return createDeepInfra({ apiKey })(modelId);
|
|
9137
|
+
case "moonshotai":
|
|
9138
|
+
case "moonshotai-cn": {
|
|
9139
|
+
if (!baseURL) throw new Error(`No API URL found for ${providerId}/${modelId}`);
|
|
9140
|
+
return createAnthropic({ apiKey, baseURL })(modelId);
|
|
9141
|
+
}
|
|
9748
9142
|
default: {
|
|
9749
9143
|
const config = this.providerConfigs[providerId];
|
|
9750
9144
|
const npm = config?.npm;
|
|
@@ -9774,5 +9168,5 @@ var ModelsDevGateway = class extends MastraModelGateway {
|
|
|
9774
9168
|
};
|
|
9775
9169
|
|
|
9776
9170
|
export { ModelsDevGateway, parseModelRouterId };
|
|
9777
|
-
//# sourceMappingURL=chunk-
|
|
9778
|
-
//# sourceMappingURL=chunk-
|
|
9171
|
+
//# sourceMappingURL=chunk-AC63Y6KP.js.map
|
|
9172
|
+
//# sourceMappingURL=chunk-AC63Y6KP.js.map
|