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