ai 3.0.21 → 3.0.23

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.
Files changed (57) hide show
  1. package/dist/index.d.mts +42 -1
  2. package/dist/index.d.ts +42 -1
  3. package/dist/index.js +104 -177
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +65 -138
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +4 -33
  8. package/react/dist/index.d.mts +6 -2
  9. package/react/dist/index.d.ts +6 -2
  10. package/react/dist/index.js +107 -24
  11. package/react/dist/index.js.map +1 -1
  12. package/react/dist/index.mjs +107 -24
  13. package/react/dist/index.mjs.map +1 -1
  14. package/rsc/dist/rsc-server.mjs +3 -3
  15. package/rsc/dist/rsc-server.mjs.map +1 -1
  16. package/solid/dist/index.d.mts +6 -2
  17. package/solid/dist/index.d.ts +6 -2
  18. package/solid/dist/index.js +105 -23
  19. package/solid/dist/index.js.map +1 -1
  20. package/solid/dist/index.mjs +105 -23
  21. package/solid/dist/index.mjs.map +1 -1
  22. package/svelte/dist/index.d.mts +6 -2
  23. package/svelte/dist/index.d.ts +6 -2
  24. package/svelte/dist/index.js +107 -24
  25. package/svelte/dist/index.js.map +1 -1
  26. package/svelte/dist/index.mjs +107 -24
  27. package/svelte/dist/index.mjs.map +1 -1
  28. package/vue/dist/index.d.mts +6 -2
  29. package/vue/dist/index.d.ts +6 -2
  30. package/vue/dist/index.js +105 -23
  31. package/vue/dist/index.js.map +1 -1
  32. package/vue/dist/index.mjs +105 -23
  33. package/vue/dist/index.mjs.map +1 -1
  34. package/anthropic/dist/index.d.mts +0 -51
  35. package/anthropic/dist/index.d.ts +0 -51
  36. package/anthropic/dist/index.js +0 -792
  37. package/anthropic/dist/index.js.map +0 -1
  38. package/anthropic/dist/index.mjs +0 -760
  39. package/anthropic/dist/index.mjs.map +0 -1
  40. package/google/dist/index.d.mts +0 -47
  41. package/google/dist/index.d.ts +0 -47
  42. package/google/dist/index.js +0 -796
  43. package/google/dist/index.js.map +0 -1
  44. package/google/dist/index.mjs +0 -764
  45. package/google/dist/index.mjs.map +0 -1
  46. package/mistral/dist/index.d.mts +0 -52
  47. package/mistral/dist/index.d.ts +0 -52
  48. package/mistral/dist/index.js +0 -763
  49. package/mistral/dist/index.js.map +0 -1
  50. package/mistral/dist/index.mjs +0 -731
  51. package/mistral/dist/index.mjs.map +0 -1
  52. package/openai/dist/index.d.mts +0 -116
  53. package/openai/dist/index.d.ts +0 -116
  54. package/openai/dist/index.js +0 -1143
  55. package/openai/dist/index.js.map +0 -1
  56. package/openai/dist/index.mjs +0 -1115
  57. package/openai/dist/index.mjs.map +0 -1
@@ -1,763 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // mistral/index.ts
31
- var mistral_exports = {};
32
- __export(mistral_exports, {
33
- Mistral: () => Mistral,
34
- mistral: () => mistral
35
- });
36
- module.exports = __toCommonJS(mistral_exports);
37
-
38
- // spec/util/generate-id.ts
39
- var import_non_secure = require("nanoid/non-secure");
40
- var generateId = (0, import_non_secure.customAlphabet)(
41
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
42
- 7
43
- );
44
-
45
- // spec/util/load-api-key.ts
46
- var import_provider = require("@ai-sdk/provider");
47
- function loadApiKey({
48
- apiKey,
49
- environmentVariableName,
50
- apiKeyParameterName = "apiKey",
51
- description
52
- }) {
53
- if (typeof apiKey === "string") {
54
- return apiKey;
55
- }
56
- if (apiKey != null) {
57
- throw new import_provider.LoadAPIKeyError({
58
- message: `${description} API key must be a string.`
59
- });
60
- }
61
- if (typeof process === "undefined") {
62
- throw new import_provider.LoadAPIKeyError({
63
- message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
64
- });
65
- }
66
- apiKey = process.env[environmentVariableName];
67
- if (apiKey == null) {
68
- throw new import_provider.LoadAPIKeyError({
69
- message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
70
- });
71
- }
72
- if (typeof apiKey !== "string") {
73
- throw new import_provider.LoadAPIKeyError({
74
- message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
75
- });
76
- }
77
- return apiKey;
78
- }
79
-
80
- // spec/util/parse-json.ts
81
- var import_provider3 = require("@ai-sdk/provider");
82
- var import_secure_json_parse = __toESM(require("secure-json-parse"));
83
-
84
- // spec/util/validate-types.ts
85
- var import_provider2 = require("@ai-sdk/provider");
86
- function validateTypes({
87
- value,
88
- schema
89
- }) {
90
- try {
91
- return schema.parse(value);
92
- } catch (error) {
93
- throw new import_provider2.TypeValidationError({ value, cause: error });
94
- }
95
- }
96
- function safeValidateTypes({
97
- value,
98
- schema
99
- }) {
100
- try {
101
- const validationResult = schema.safeParse(value);
102
- if (validationResult.success) {
103
- return {
104
- success: true,
105
- value: validationResult.data
106
- };
107
- }
108
- return {
109
- success: false,
110
- error: new import_provider2.TypeValidationError({
111
- value,
112
- cause: validationResult.error
113
- })
114
- };
115
- } catch (error) {
116
- return {
117
- success: false,
118
- error: import_provider2.TypeValidationError.isTypeValidationError(error) ? error : new import_provider2.TypeValidationError({ value, cause: error })
119
- };
120
- }
121
- }
122
-
123
- // spec/util/parse-json.ts
124
- function parseJSON({
125
- text,
126
- schema
127
- }) {
128
- try {
129
- const value = import_secure_json_parse.default.parse(text);
130
- if (schema == null) {
131
- return value;
132
- }
133
- return validateTypes({ value, schema });
134
- } catch (error) {
135
- if (import_provider3.JSONParseError.isJSONParseError(error) || import_provider3.TypeValidationError.isTypeValidationError(error)) {
136
- throw error;
137
- }
138
- throw new import_provider3.JSONParseError({ text, cause: error });
139
- }
140
- }
141
- function safeParseJSON({
142
- text,
143
- schema
144
- }) {
145
- try {
146
- const value = import_secure_json_parse.default.parse(text);
147
- if (schema == null) {
148
- return {
149
- success: true,
150
- value
151
- };
152
- }
153
- return safeValidateTypes({ value, schema });
154
- } catch (error) {
155
- return {
156
- success: false,
157
- error: import_provider3.JSONParseError.isJSONParseError(error) ? error : new import_provider3.JSONParseError({ text, cause: error })
158
- };
159
- }
160
- }
161
-
162
- // spec/util/post-to-api.ts
163
- var import_provider4 = require("@ai-sdk/provider");
164
- var postJsonToApi = async ({
165
- url,
166
- headers,
167
- body,
168
- failedResponseHandler,
169
- successfulResponseHandler,
170
- abortSignal
171
- }) => postToApi({
172
- url,
173
- headers: {
174
- ...headers,
175
- "Content-Type": "application/json"
176
- },
177
- body: {
178
- content: JSON.stringify(body),
179
- values: body
180
- },
181
- failedResponseHandler,
182
- successfulResponseHandler,
183
- abortSignal
184
- });
185
- var postToApi = async ({
186
- url,
187
- headers = {},
188
- body,
189
- successfulResponseHandler,
190
- failedResponseHandler,
191
- abortSignal
192
- }) => {
193
- try {
194
- const definedHeaders = Object.fromEntries(
195
- Object.entries(headers).filter(([_key, value]) => value != null)
196
- );
197
- const response = await fetch(url, {
198
- method: "POST",
199
- headers: definedHeaders,
200
- body: body.content,
201
- signal: abortSignal
202
- });
203
- if (!response.ok) {
204
- try {
205
- throw await failedResponseHandler({
206
- response,
207
- url,
208
- requestBodyValues: body.values
209
- });
210
- } catch (error) {
211
- if (error instanceof Error) {
212
- if (error.name === "AbortError" || import_provider4.APICallError.isAPICallError(error)) {
213
- throw error;
214
- }
215
- }
216
- throw new import_provider4.APICallError({
217
- message: "Failed to process error response",
218
- cause: error,
219
- statusCode: response.status,
220
- url,
221
- requestBodyValues: body.values
222
- });
223
- }
224
- }
225
- try {
226
- return await successfulResponseHandler({
227
- response,
228
- url,
229
- requestBodyValues: body.values
230
- });
231
- } catch (error) {
232
- if (error instanceof Error) {
233
- if (error.name === "AbortError" || import_provider4.APICallError.isAPICallError(error)) {
234
- throw error;
235
- }
236
- }
237
- throw new import_provider4.APICallError({
238
- message: "Failed to process successful response",
239
- cause: error,
240
- statusCode: response.status,
241
- url,
242
- requestBodyValues: body.values
243
- });
244
- }
245
- } catch (error) {
246
- if (error instanceof Error) {
247
- if (error.name === "AbortError") {
248
- throw error;
249
- }
250
- }
251
- if (error instanceof TypeError && error.message === "fetch failed") {
252
- const cause = error.cause;
253
- if (cause != null) {
254
- throw new import_provider4.APICallError({
255
- message: `Cannot connect to API: ${cause.message}`,
256
- cause,
257
- url,
258
- requestBodyValues: body.values,
259
- isRetryable: true
260
- // retry when network error
261
- });
262
- }
263
- }
264
- throw error;
265
- }
266
- };
267
-
268
- // spec/util/response-handler.ts
269
- var import_provider5 = require("@ai-sdk/provider");
270
- var import_stream = require("eventsource-parser/stream");
271
- var createJsonErrorResponseHandler = ({
272
- errorSchema,
273
- errorToMessage,
274
- isRetryable
275
- }) => async ({ response, url, requestBodyValues }) => {
276
- const responseBody = await response.text();
277
- if (responseBody.trim() === "") {
278
- return new import_provider5.APICallError({
279
- message: response.statusText,
280
- url,
281
- requestBodyValues,
282
- statusCode: response.status,
283
- responseBody,
284
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
285
- });
286
- }
287
- try {
288
- const parsedError = parseJSON({
289
- text: responseBody,
290
- schema: errorSchema
291
- });
292
- return new import_provider5.APICallError({
293
- message: errorToMessage(parsedError),
294
- url,
295
- requestBodyValues,
296
- statusCode: response.status,
297
- responseBody,
298
- data: parsedError,
299
- isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
300
- });
301
- } catch (parseError) {
302
- return new import_provider5.APICallError({
303
- message: response.statusText,
304
- url,
305
- requestBodyValues,
306
- statusCode: response.status,
307
- responseBody,
308
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
309
- });
310
- }
311
- };
312
- var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
313
- if (response.body == null) {
314
- throw new import_provider5.NoResponseBodyError();
315
- }
316
- return response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream()).pipeThrough(
317
- new TransformStream({
318
- transform({ data }, controller) {
319
- if (data === "[DONE]") {
320
- return;
321
- }
322
- controller.enqueue(
323
- safeParseJSON({
324
- text: data,
325
- schema: chunkSchema
326
- })
327
- );
328
- }
329
- })
330
- );
331
- };
332
- var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
333
- const responseBody = await response.text();
334
- const parsedResult = safeParseJSON({
335
- text: responseBody,
336
- schema: responseSchema
337
- });
338
- if (!parsedResult.success) {
339
- throw new import_provider5.APICallError({
340
- message: "Invalid JSON response",
341
- cause: parsedResult.error,
342
- statusCode: response.status,
343
- responseBody,
344
- url,
345
- requestBodyValues
346
- });
347
- }
348
- return parsedResult.value;
349
- };
350
-
351
- // mistral/mistral-chat-language-model.ts
352
- var import_provider7 = require("@ai-sdk/provider");
353
- var import_zod2 = require("zod");
354
-
355
- // mistral/convert-to-mistral-chat-messages.ts
356
- var import_provider6 = require("@ai-sdk/provider");
357
- function convertToMistralChatMessages(prompt) {
358
- const messages = [];
359
- for (const { role, content } of prompt) {
360
- switch (role) {
361
- case "system": {
362
- messages.push({ role: "system", content });
363
- break;
364
- }
365
- case "user": {
366
- messages.push({
367
- role: "user",
368
- content: content.map((part) => {
369
- switch (part.type) {
370
- case "text": {
371
- return part.text;
372
- }
373
- case "image": {
374
- throw new import_provider6.UnsupportedFunctionalityError({
375
- functionality: "image-part"
376
- });
377
- }
378
- }
379
- }).join("")
380
- });
381
- break;
382
- }
383
- case "assistant": {
384
- let text = "";
385
- const toolCalls = [];
386
- for (const part of content) {
387
- switch (part.type) {
388
- case "text": {
389
- text += part.text;
390
- break;
391
- }
392
- case "tool-call": {
393
- toolCalls.push({
394
- id: part.toolCallId,
395
- type: "function",
396
- function: {
397
- name: part.toolName,
398
- arguments: JSON.stringify(part.args)
399
- }
400
- });
401
- break;
402
- }
403
- default: {
404
- const _exhaustiveCheck = part;
405
- throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
406
- }
407
- }
408
- }
409
- messages.push({
410
- role: "assistant",
411
- content: text,
412
- tool_calls: toolCalls.length > 0 ? toolCalls.map(({ function: { name, arguments: args } }) => ({
413
- id: "null",
414
- type: "function",
415
- function: { name, arguments: args }
416
- })) : void 0
417
- });
418
- break;
419
- }
420
- case "tool": {
421
- for (const toolResponse of content) {
422
- messages.push({
423
- role: "tool",
424
- name: toolResponse.toolName,
425
- content: JSON.stringify(toolResponse.result)
426
- });
427
- }
428
- break;
429
- }
430
- default: {
431
- const _exhaustiveCheck = role;
432
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
433
- }
434
- }
435
- }
436
- return messages;
437
- }
438
-
439
- // mistral/map-mistral-finish-reason.ts
440
- function mapMistralFinishReason(finishReason) {
441
- switch (finishReason) {
442
- case "stop":
443
- return "stop";
444
- case "length":
445
- case "model_length":
446
- return "length";
447
- case "tool_calls":
448
- return "tool-calls";
449
- default:
450
- return "other";
451
- }
452
- }
453
-
454
- // mistral/mistral-error.ts
455
- var import_zod = require("zod");
456
- var mistralErrorDataSchema = import_zod.z.object({
457
- object: import_zod.z.literal("error"),
458
- message: import_zod.z.string(),
459
- type: import_zod.z.string(),
460
- param: import_zod.z.string().nullable(),
461
- code: import_zod.z.string().nullable()
462
- });
463
- var mistralFailedResponseHandler = createJsonErrorResponseHandler({
464
- errorSchema: mistralErrorDataSchema,
465
- errorToMessage: (data) => data.message
466
- });
467
-
468
- // mistral/mistral-chat-language-model.ts
469
- var MistralChatLanguageModel = class {
470
- constructor(modelId, settings, config) {
471
- this.specificationVersion = "v1";
472
- this.defaultObjectGenerationMode = "json";
473
- this.modelId = modelId;
474
- this.settings = settings;
475
- this.config = config;
476
- }
477
- get provider() {
478
- return this.config.provider;
479
- }
480
- getArgs({
481
- mode,
482
- prompt,
483
- maxTokens,
484
- temperature,
485
- topP,
486
- frequencyPenalty,
487
- presencePenalty,
488
- seed
489
- }) {
490
- var _a;
491
- const type = mode.type;
492
- const warnings = [];
493
- if (frequencyPenalty != null) {
494
- warnings.push({
495
- type: "unsupported-setting",
496
- setting: "frequencyPenalty"
497
- });
498
- }
499
- if (presencePenalty != null) {
500
- warnings.push({
501
- type: "unsupported-setting",
502
- setting: "presencePenalty"
503
- });
504
- }
505
- const baseArgs = {
506
- // model id:
507
- model: this.modelId,
508
- // model specific settings:
509
- safe_prompt: this.settings.safePrompt,
510
- // standardized settings:
511
- max_tokens: maxTokens,
512
- temperature,
513
- // uses 0..1 scale
514
- top_p: topP,
515
- random_seed: seed,
516
- // messages:
517
- messages: convertToMistralChatMessages(prompt)
518
- };
519
- switch (type) {
520
- case "regular": {
521
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
522
- return {
523
- args: {
524
- ...baseArgs,
525
- tools: tools == null ? void 0 : tools.map((tool) => ({
526
- type: "function",
527
- function: {
528
- name: tool.name,
529
- description: tool.description,
530
- parameters: tool.parameters
531
- }
532
- }))
533
- },
534
- warnings
535
- };
536
- }
537
- case "object-json": {
538
- return {
539
- args: {
540
- ...baseArgs,
541
- response_format: { type: "json_object" }
542
- },
543
- warnings
544
- };
545
- }
546
- case "object-tool": {
547
- return {
548
- args: {
549
- ...baseArgs,
550
- tool_choice: "any",
551
- tools: [{ type: "function", function: mode.tool }]
552
- },
553
- warnings
554
- };
555
- }
556
- case "object-grammar": {
557
- throw new import_provider7.UnsupportedFunctionalityError({
558
- functionality: "object-grammar mode"
559
- });
560
- }
561
- default: {
562
- const _exhaustiveCheck = type;
563
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
564
- }
565
- }
566
- }
567
- async doGenerate(options) {
568
- var _a, _b;
569
- const { args, warnings } = this.getArgs(options);
570
- const response = await postJsonToApi({
571
- url: `${this.config.baseUrl}/chat/completions`,
572
- headers: this.config.headers(),
573
- body: args,
574
- failedResponseHandler: mistralFailedResponseHandler,
575
- successfulResponseHandler: createJsonResponseHandler(
576
- mistralChatResponseSchema
577
- ),
578
- abortSignal: options.abortSignal
579
- });
580
- const { messages: rawPrompt, ...rawSettings } = args;
581
- const choice = response.choices[0];
582
- return {
583
- text: (_a = choice.message.content) != null ? _a : void 0,
584
- toolCalls: (_b = choice.message.tool_calls) == null ? void 0 : _b.map((toolCall) => ({
585
- toolCallType: "function",
586
- toolCallId: this.config.generateId(),
587
- toolName: toolCall.function.name,
588
- args: toolCall.function.arguments
589
- })),
590
- finishReason: mapMistralFinishReason(choice.finish_reason),
591
- usage: {
592
- promptTokens: response.usage.prompt_tokens,
593
- completionTokens: response.usage.completion_tokens
594
- },
595
- rawCall: { rawPrompt, rawSettings },
596
- warnings
597
- };
598
- }
599
- async doStream(options) {
600
- const { args, warnings } = this.getArgs(options);
601
- const response = await postJsonToApi({
602
- url: `${this.config.baseUrl}/chat/completions`,
603
- headers: this.config.headers(),
604
- body: {
605
- ...args,
606
- stream: true
607
- },
608
- failedResponseHandler: mistralFailedResponseHandler,
609
- successfulResponseHandler: createEventSourceResponseHandler(
610
- mistralChatChunkSchema
611
- ),
612
- abortSignal: options.abortSignal
613
- });
614
- const { messages: rawPrompt, ...rawSettings } = args;
615
- let finishReason = "other";
616
- let usage = {
617
- promptTokens: Number.NaN,
618
- completionTokens: Number.NaN
619
- };
620
- const generateId2 = this.config.generateId;
621
- return {
622
- stream: response.pipeThrough(
623
- new TransformStream({
624
- transform(chunk, controller) {
625
- if (!chunk.success) {
626
- controller.enqueue({ type: "error", error: chunk.error });
627
- return;
628
- }
629
- const value = chunk.value;
630
- if (value.usage != null) {
631
- usage = {
632
- promptTokens: value.usage.prompt_tokens,
633
- completionTokens: value.usage.completion_tokens
634
- };
635
- }
636
- const choice = value.choices[0];
637
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
638
- finishReason = mapMistralFinishReason(choice.finish_reason);
639
- }
640
- if ((choice == null ? void 0 : choice.delta) == null) {
641
- return;
642
- }
643
- const delta = choice.delta;
644
- if (delta.content != null) {
645
- controller.enqueue({
646
- type: "text-delta",
647
- textDelta: delta.content
648
- });
649
- }
650
- if (delta.tool_calls != null) {
651
- for (const toolCall of delta.tool_calls) {
652
- const toolCallId = generateId2();
653
- controller.enqueue({
654
- type: "tool-call-delta",
655
- toolCallType: "function",
656
- toolCallId,
657
- toolName: toolCall.function.name,
658
- argsTextDelta: toolCall.function.arguments
659
- });
660
- controller.enqueue({
661
- type: "tool-call",
662
- toolCallType: "function",
663
- toolCallId,
664
- toolName: toolCall.function.name,
665
- args: toolCall.function.arguments
666
- });
667
- }
668
- }
669
- },
670
- flush(controller) {
671
- controller.enqueue({ type: "finish", finishReason, usage });
672
- }
673
- })
674
- ),
675
- rawCall: { rawPrompt, rawSettings },
676
- warnings
677
- };
678
- }
679
- };
680
- var mistralChatResponseSchema = import_zod2.z.object({
681
- choices: import_zod2.z.array(
682
- import_zod2.z.object({
683
- message: import_zod2.z.object({
684
- role: import_zod2.z.literal("assistant"),
685
- content: import_zod2.z.string().nullable(),
686
- tool_calls: import_zod2.z.array(
687
- import_zod2.z.object({
688
- function: import_zod2.z.object({
689
- name: import_zod2.z.string(),
690
- arguments: import_zod2.z.string()
691
- })
692
- })
693
- ).optional().nullable()
694
- }),
695
- index: import_zod2.z.number(),
696
- finish_reason: import_zod2.z.string().optional().nullable()
697
- })
698
- ),
699
- object: import_zod2.z.literal("chat.completion"),
700
- usage: import_zod2.z.object({
701
- prompt_tokens: import_zod2.z.number(),
702
- completion_tokens: import_zod2.z.number()
703
- })
704
- });
705
- var mistralChatChunkSchema = import_zod2.z.object({
706
- object: import_zod2.z.literal("chat.completion.chunk"),
707
- choices: import_zod2.z.array(
708
- import_zod2.z.object({
709
- delta: import_zod2.z.object({
710
- role: import_zod2.z.enum(["assistant"]).optional(),
711
- content: import_zod2.z.string().nullable().optional(),
712
- tool_calls: import_zod2.z.array(
713
- import_zod2.z.object({
714
- function: import_zod2.z.object({ name: import_zod2.z.string(), arguments: import_zod2.z.string() })
715
- })
716
- ).optional().nullable()
717
- }),
718
- finish_reason: import_zod2.z.string().nullable().optional(),
719
- index: import_zod2.z.number()
720
- })
721
- ),
722
- usage: import_zod2.z.object({
723
- prompt_tokens: import_zod2.z.number(),
724
- completion_tokens: import_zod2.z.number()
725
- }).optional().nullable()
726
- });
727
-
728
- // mistral/mistral-facade.ts
729
- var Mistral = class {
730
- constructor(options = {}) {
731
- var _a;
732
- this.baseUrl = options.baseUrl;
733
- this.apiKey = options.apiKey;
734
- this.generateId = (_a = options.generateId) != null ? _a : generateId;
735
- }
736
- get baseConfig() {
737
- var _a;
738
- return {
739
- baseUrl: (_a = this.baseUrl) != null ? _a : "https://api.mistral.ai/v1",
740
- headers: () => ({
741
- Authorization: `Bearer ${loadApiKey({
742
- apiKey: this.apiKey,
743
- environmentVariableName: "MISTRAL_API_KEY",
744
- description: "Mistral"
745
- })}`
746
- })
747
- };
748
- }
749
- chat(modelId, settings = {}) {
750
- return new MistralChatLanguageModel(modelId, settings, {
751
- provider: "mistral.chat",
752
- ...this.baseConfig,
753
- generateId: this.generateId
754
- });
755
- }
756
- };
757
- var mistral = new Mistral();
758
- // Annotate the CommonJS export names for ESM import in node:
759
- 0 && (module.exports = {
760
- Mistral,
761
- mistral
762
- });
763
- //# sourceMappingURL=index.js.map