ai 3.0.18 → 3.0.20
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/anthropic/dist/index.d.mts +66 -34
- package/anthropic/dist/index.d.ts +66 -34
- package/anthropic/dist/index.js +98 -94
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +98 -94
- package/anthropic/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +119 -45
- package/dist/index.d.ts +119 -45
- package/dist/index.js +83 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -153
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +65 -31
- package/google/dist/index.d.ts +65 -31
- package/google/dist/index.js +47 -43
- package/google/dist/index.js.map +1 -1
- package/google/dist/index.mjs +47 -43
- package/google/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +65 -31
- package/mistral/dist/index.d.ts +65 -31
- package/mistral/dist/index.js +6 -21
- package/mistral/dist/index.js.map +1 -1
- package/mistral/dist/index.mjs +6 -21
- package/mistral/dist/index.mjs.map +1 -1
- package/openai/dist/index.d.mts +65 -31
- package/openai/dist/index.d.ts +65 -31
- package/openai/dist/index.js +9 -29
- package/openai/dist/index.js.map +1 -1
- package/openai/dist/index.mjs +9 -29
- package/openai/dist/index.mjs.map +1 -1
- package/package.json +5 -3
- package/react/dist/index.d.mts +8 -4
- package/react/dist/index.d.ts +12 -6
- package/react/dist/index.js +23 -105
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +22 -105
- package/react/dist/index.mjs.map +1 -1
- package/react/dist/index.server.d.mts +4 -2
- package/react/dist/index.server.d.ts +4 -2
- package/react/dist/index.server.js.map +1 -1
- package/react/dist/index.server.mjs.map +1 -1
- package/rsc/dist/rsc-server.mjs +6 -16
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/solid/dist/index.js +19 -104
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +19 -104
- package/solid/dist/index.mjs.map +1 -1
- package/spec/dist/index.d.mts +112 -40
- package/spec/dist/index.d.ts +112 -40
- package/spec/dist/index.js +71 -13
- package/spec/dist/index.js.map +1 -1
- package/spec/dist/index.mjs +69 -13
- package/spec/dist/index.mjs.map +1 -1
- package/svelte/dist/index.js +19 -104
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +19 -104
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.js +19 -104
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +19 -104
- package/vue/dist/index.mjs.map +1 -1
@@ -1,4 +1,24 @@
|
|
1
|
-
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
2
|
+
|
3
|
+
/**
|
4
|
+
A tool has a name, a description, and a set of parameters.
|
5
|
+
|
6
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
7
|
+
map the user-facing tool definitions to this format.
|
8
|
+
*/
|
9
|
+
type LanguageModelV1FunctionTool = {
|
10
|
+
/**
|
11
|
+
The type of the tool. Only functions for now, but this gives us room to
|
12
|
+
add more specific tool types in the future and use a discriminated union.
|
13
|
+
*/
|
14
|
+
type: 'function';
|
15
|
+
/**
|
16
|
+
The name of the tool. Unique within this model call.
|
17
|
+
*/
|
18
|
+
name: string;
|
19
|
+
description?: string;
|
20
|
+
parameters: JSONSchema7;
|
21
|
+
};
|
2
22
|
|
3
23
|
type LanguageModelV1CallSettings = {
|
4
24
|
/**
|
@@ -55,33 +75,13 @@ type LanguageModelV1CallSettings = {
|
|
55
75
|
};
|
56
76
|
|
57
77
|
/**
|
58
|
-
|
59
|
-
*
|
60
|
-
* Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
61
|
-
* map the user-facing tool definitions to this format.
|
62
|
-
*/
|
63
|
-
type LanguageModelV1FunctionTool = {
|
64
|
-
/**
|
65
|
-
* The type of the tool. Only functions for now, but this gives us room to
|
66
|
-
* add more specific tool types in the future and use a discriminated union.
|
67
|
-
*/
|
68
|
-
type: 'function';
|
69
|
-
/**
|
70
|
-
* The name of the tool. Unique within this model call.
|
71
|
-
*/
|
72
|
-
name: string;
|
73
|
-
description?: string;
|
74
|
-
parameters: JsonSchema;
|
75
|
-
};
|
78
|
+
A prompt is a list of messages.
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
*
|
83
|
-
* Note: This is not a user-facing prompt. The AI SDK methods will map the
|
84
|
-
* user-facing prompt types such as chat or instruction prompts to this format.
|
80
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
81
|
+
tool calls. The validation happens at runtime.
|
82
|
+
|
83
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
84
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
85
85
|
*/
|
86
86
|
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
87
87
|
type LanguageModelV1Message = {
|
@@ -97,35 +97,69 @@ type LanguageModelV1Message = {
|
|
97
97
|
role: 'tool';
|
98
98
|
content: Array<LanguageModelV1ToolResultPart>;
|
99
99
|
};
|
100
|
+
/**
|
101
|
+
Text content part of a prompt. It contains a string of text.
|
102
|
+
*/
|
100
103
|
interface LanguageModelV1TextPart {
|
101
104
|
type: 'text';
|
102
105
|
/**
|
103
|
-
|
106
|
+
The text content.
|
104
107
|
*/
|
105
108
|
text: string;
|
106
109
|
}
|
110
|
+
/**
|
111
|
+
Image content part of a prompt. It contains an image.
|
112
|
+
*/
|
107
113
|
interface LanguageModelV1ImagePart {
|
108
114
|
type: 'image';
|
109
115
|
/**
|
110
|
-
|
116
|
+
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
111
117
|
*/
|
112
118
|
image: Uint8Array | URL;
|
113
119
|
/**
|
114
|
-
|
120
|
+
Optional mime type of the image.
|
115
121
|
*/
|
116
122
|
mimeType?: string;
|
117
123
|
}
|
124
|
+
/**
|
125
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
126
|
+
*/
|
118
127
|
interface LanguageModelV1ToolCallPart {
|
119
128
|
type: 'tool-call';
|
129
|
+
/**
|
130
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
131
|
+
*/
|
120
132
|
toolCallId: string;
|
133
|
+
/**
|
134
|
+
Name of the tool that is being called.
|
135
|
+
*/
|
121
136
|
toolName: string;
|
137
|
+
/**
|
138
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
139
|
+
*/
|
122
140
|
args: unknown;
|
123
141
|
}
|
142
|
+
/**
|
143
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
144
|
+
*/
|
124
145
|
interface LanguageModelV1ToolResultPart {
|
125
146
|
type: 'tool-result';
|
147
|
+
/**
|
148
|
+
ID of the tool call that this result is associated with.
|
149
|
+
*/
|
126
150
|
toolCallId: string;
|
151
|
+
/**
|
152
|
+
Name of the tool that generated this result.
|
153
|
+
*/
|
127
154
|
toolName: string;
|
155
|
+
/**
|
156
|
+
Result of the tool call. This is a JSON-serializable object.
|
157
|
+
*/
|
128
158
|
result: unknown;
|
159
|
+
/**
|
160
|
+
Optional flag if the result is an error or an error message.
|
161
|
+
*/
|
162
|
+
isError?: boolean;
|
129
163
|
}
|
130
164
|
|
131
165
|
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
@@ -151,7 +185,7 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
|
151
185
|
type: 'object-json';
|
152
186
|
} | {
|
153
187
|
type: 'object-grammar';
|
154
|
-
schema:
|
188
|
+
schema: JSONSchema7;
|
155
189
|
} | {
|
156
190
|
type: 'object-tool';
|
157
191
|
tool: LanguageModelV1FunctionTool;
|
@@ -333,11 +367,10 @@ type AnthropicMessagesConfig = {
|
|
333
367
|
provider: string;
|
334
368
|
baseUrl: string;
|
335
369
|
headers: () => Record<string, string | undefined>;
|
336
|
-
generateId: () => string;
|
337
370
|
};
|
338
371
|
declare class AnthropicMessagesLanguageModel implements LanguageModelV1 {
|
339
372
|
readonly specificationVersion = "v1";
|
340
|
-
readonly defaultObjectGenerationMode = "
|
373
|
+
readonly defaultObjectGenerationMode = "tool";
|
341
374
|
readonly modelId: AnthropicMessagesModelId;
|
342
375
|
readonly settings: AnthropicMessagesSettings;
|
343
376
|
private readonly config;
|
@@ -354,7 +387,6 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV1 {
|
|
354
387
|
declare class Anthropic {
|
355
388
|
readonly baseUrl?: string;
|
356
389
|
readonly apiKey?: string;
|
357
|
-
private readonly generateId;
|
358
390
|
constructor(options?: {
|
359
391
|
baseUrl?: string;
|
360
392
|
apiKey?: string;
|
@@ -1,4 +1,24 @@
|
|
1
|
-
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
2
|
+
|
3
|
+
/**
|
4
|
+
A tool has a name, a description, and a set of parameters.
|
5
|
+
|
6
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
7
|
+
map the user-facing tool definitions to this format.
|
8
|
+
*/
|
9
|
+
type LanguageModelV1FunctionTool = {
|
10
|
+
/**
|
11
|
+
The type of the tool. Only functions for now, but this gives us room to
|
12
|
+
add more specific tool types in the future and use a discriminated union.
|
13
|
+
*/
|
14
|
+
type: 'function';
|
15
|
+
/**
|
16
|
+
The name of the tool. Unique within this model call.
|
17
|
+
*/
|
18
|
+
name: string;
|
19
|
+
description?: string;
|
20
|
+
parameters: JSONSchema7;
|
21
|
+
};
|
2
22
|
|
3
23
|
type LanguageModelV1CallSettings = {
|
4
24
|
/**
|
@@ -55,33 +75,13 @@ type LanguageModelV1CallSettings = {
|
|
55
75
|
};
|
56
76
|
|
57
77
|
/**
|
58
|
-
|
59
|
-
*
|
60
|
-
* Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
61
|
-
* map the user-facing tool definitions to this format.
|
62
|
-
*/
|
63
|
-
type LanguageModelV1FunctionTool = {
|
64
|
-
/**
|
65
|
-
* The type of the tool. Only functions for now, but this gives us room to
|
66
|
-
* add more specific tool types in the future and use a discriminated union.
|
67
|
-
*/
|
68
|
-
type: 'function';
|
69
|
-
/**
|
70
|
-
* The name of the tool. Unique within this model call.
|
71
|
-
*/
|
72
|
-
name: string;
|
73
|
-
description?: string;
|
74
|
-
parameters: JsonSchema;
|
75
|
-
};
|
78
|
+
A prompt is a list of messages.
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
*
|
83
|
-
* Note: This is not a user-facing prompt. The AI SDK methods will map the
|
84
|
-
* user-facing prompt types such as chat or instruction prompts to this format.
|
80
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
81
|
+
tool calls. The validation happens at runtime.
|
82
|
+
|
83
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
84
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
85
85
|
*/
|
86
86
|
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
87
87
|
type LanguageModelV1Message = {
|
@@ -97,35 +97,69 @@ type LanguageModelV1Message = {
|
|
97
97
|
role: 'tool';
|
98
98
|
content: Array<LanguageModelV1ToolResultPart>;
|
99
99
|
};
|
100
|
+
/**
|
101
|
+
Text content part of a prompt. It contains a string of text.
|
102
|
+
*/
|
100
103
|
interface LanguageModelV1TextPart {
|
101
104
|
type: 'text';
|
102
105
|
/**
|
103
|
-
|
106
|
+
The text content.
|
104
107
|
*/
|
105
108
|
text: string;
|
106
109
|
}
|
110
|
+
/**
|
111
|
+
Image content part of a prompt. It contains an image.
|
112
|
+
*/
|
107
113
|
interface LanguageModelV1ImagePart {
|
108
114
|
type: 'image';
|
109
115
|
/**
|
110
|
-
|
116
|
+
Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
111
117
|
*/
|
112
118
|
image: Uint8Array | URL;
|
113
119
|
/**
|
114
|
-
|
120
|
+
Optional mime type of the image.
|
115
121
|
*/
|
116
122
|
mimeType?: string;
|
117
123
|
}
|
124
|
+
/**
|
125
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
126
|
+
*/
|
118
127
|
interface LanguageModelV1ToolCallPart {
|
119
128
|
type: 'tool-call';
|
129
|
+
/**
|
130
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
131
|
+
*/
|
120
132
|
toolCallId: string;
|
133
|
+
/**
|
134
|
+
Name of the tool that is being called.
|
135
|
+
*/
|
121
136
|
toolName: string;
|
137
|
+
/**
|
138
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
139
|
+
*/
|
122
140
|
args: unknown;
|
123
141
|
}
|
142
|
+
/**
|
143
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
144
|
+
*/
|
124
145
|
interface LanguageModelV1ToolResultPart {
|
125
146
|
type: 'tool-result';
|
147
|
+
/**
|
148
|
+
ID of the tool call that this result is associated with.
|
149
|
+
*/
|
126
150
|
toolCallId: string;
|
151
|
+
/**
|
152
|
+
Name of the tool that generated this result.
|
153
|
+
*/
|
127
154
|
toolName: string;
|
155
|
+
/**
|
156
|
+
Result of the tool call. This is a JSON-serializable object.
|
157
|
+
*/
|
128
158
|
result: unknown;
|
159
|
+
/**
|
160
|
+
Optional flag if the result is an error or an error message.
|
161
|
+
*/
|
162
|
+
isError?: boolean;
|
129
163
|
}
|
130
164
|
|
131
165
|
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
@@ -151,7 +185,7 @@ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
|
151
185
|
type: 'object-json';
|
152
186
|
} | {
|
153
187
|
type: 'object-grammar';
|
154
|
-
schema:
|
188
|
+
schema: JSONSchema7;
|
155
189
|
} | {
|
156
190
|
type: 'object-tool';
|
157
191
|
tool: LanguageModelV1FunctionTool;
|
@@ -333,11 +367,10 @@ type AnthropicMessagesConfig = {
|
|
333
367
|
provider: string;
|
334
368
|
baseUrl: string;
|
335
369
|
headers: () => Record<string, string | undefined>;
|
336
|
-
generateId: () => string;
|
337
370
|
};
|
338
371
|
declare class AnthropicMessagesLanguageModel implements LanguageModelV1 {
|
339
372
|
readonly specificationVersion = "v1";
|
340
|
-
readonly defaultObjectGenerationMode = "
|
373
|
+
readonly defaultObjectGenerationMode = "tool";
|
341
374
|
readonly modelId: AnthropicMessagesModelId;
|
342
375
|
readonly settings: AnthropicMessagesSettings;
|
343
376
|
private readonly config;
|
@@ -354,7 +387,6 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV1 {
|
|
354
387
|
declare class Anthropic {
|
355
388
|
readonly baseUrl?: string;
|
356
389
|
readonly apiKey?: string;
|
357
|
-
private readonly generateId;
|
358
390
|
constructor(options?: {
|
359
391
|
baseUrl?: string;
|
360
392
|
apiKey?: string;
|
package/anthropic/dist/index.js
CHANGED
@@ -79,13 +79,6 @@ var APICallError = class extends Error {
|
|
79
79
|
}
|
80
80
|
};
|
81
81
|
|
82
|
-
// spec/util/generate-id.ts
|
83
|
-
var import_non_secure = require("nanoid/non-secure");
|
84
|
-
var generateId = (0, import_non_secure.customAlphabet)(
|
85
|
-
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
86
|
-
7
|
87
|
-
);
|
88
|
-
|
89
82
|
// spec/util/get-error-message.ts
|
90
83
|
function getErrorMessage(error) {
|
91
84
|
if (error == null) {
|
@@ -499,26 +492,19 @@ function convertUint8ArrayToBase64(array) {
|
|
499
492
|
|
500
493
|
// spec/errors/unsupported-functionality-error.ts
|
501
494
|
var UnsupportedFunctionalityError = class extends Error {
|
502
|
-
constructor({
|
503
|
-
|
504
|
-
functionality
|
505
|
-
}) {
|
506
|
-
super(
|
507
|
-
`'${functionality}' functionality not supported by the '${provider}' provider.`
|
508
|
-
);
|
495
|
+
constructor({ functionality }) {
|
496
|
+
super(`'${functionality}' functionality not supported.`);
|
509
497
|
this.name = "AI_UnsupportedFunctionalityError";
|
510
|
-
this.provider = provider;
|
511
498
|
this.functionality = functionality;
|
512
499
|
}
|
513
500
|
static isUnsupportedFunctionalityError(error) {
|
514
|
-
return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.
|
501
|
+
return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.functionality === "string";
|
515
502
|
}
|
516
503
|
toJSON() {
|
517
504
|
return {
|
518
505
|
name: this.name,
|
519
506
|
message: this.message,
|
520
507
|
stack: this.stack,
|
521
|
-
provider: this.provider,
|
522
508
|
functionality: this.functionality
|
523
509
|
};
|
524
510
|
}
|
@@ -541,24 +527,8 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
541
527
|
errorToMessage: (data) => data.error.message
|
542
528
|
});
|
543
529
|
|
544
|
-
// anthropic/map-anthropic-finish-reason.ts
|
545
|
-
function mapAnthropicFinishReason(finishReason) {
|
546
|
-
switch (finishReason) {
|
547
|
-
case "end_turn":
|
548
|
-
case "stop_sequence":
|
549
|
-
return "stop";
|
550
|
-
case "max_tokens":
|
551
|
-
return "length";
|
552
|
-
default:
|
553
|
-
return "other";
|
554
|
-
}
|
555
|
-
}
|
556
|
-
|
557
530
|
// anthropic/convert-to-anthropic-messages-prompt.ts
|
558
|
-
function convertToAnthropicMessagesPrompt({
|
559
|
-
prompt,
|
560
|
-
provider
|
561
|
-
}) {
|
531
|
+
function convertToAnthropicMessagesPrompt(prompt) {
|
562
532
|
let system;
|
563
533
|
const messages = [];
|
564
534
|
for (const { role, content } of prompt) {
|
@@ -579,7 +549,6 @@ function convertToAnthropicMessagesPrompt({
|
|
579
549
|
case "image": {
|
580
550
|
if (part.image instanceof URL) {
|
581
551
|
throw new UnsupportedFunctionalityError({
|
582
|
-
provider,
|
583
552
|
functionality: "URL image parts"
|
584
553
|
});
|
585
554
|
} else {
|
@@ -599,36 +568,37 @@ function convertToAnthropicMessagesPrompt({
|
|
599
568
|
break;
|
600
569
|
}
|
601
570
|
case "assistant": {
|
602
|
-
let text = "";
|
603
|
-
for (const part of content) {
|
604
|
-
switch (part.type) {
|
605
|
-
case "text": {
|
606
|
-
text += part.text;
|
607
|
-
break;
|
608
|
-
}
|
609
|
-
case "tool-call": {
|
610
|
-
throw new UnsupportedFunctionalityError({
|
611
|
-
provider,
|
612
|
-
functionality: "tool-call-part"
|
613
|
-
});
|
614
|
-
}
|
615
|
-
default: {
|
616
|
-
const _exhaustiveCheck = part;
|
617
|
-
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
618
|
-
}
|
619
|
-
}
|
620
|
-
}
|
621
571
|
messages.push({
|
622
572
|
role: "assistant",
|
623
|
-
content:
|
573
|
+
content: content.map((part) => {
|
574
|
+
switch (part.type) {
|
575
|
+
case "text": {
|
576
|
+
return { type: "text", text: part.text };
|
577
|
+
}
|
578
|
+
case "tool-call": {
|
579
|
+
return {
|
580
|
+
type: "tool_use",
|
581
|
+
id: part.toolCallId,
|
582
|
+
name: part.toolName,
|
583
|
+
input: part.args
|
584
|
+
};
|
585
|
+
}
|
586
|
+
}
|
587
|
+
})
|
624
588
|
});
|
625
589
|
break;
|
626
590
|
}
|
627
591
|
case "tool": {
|
628
|
-
|
629
|
-
|
630
|
-
|
592
|
+
messages.push({
|
593
|
+
role: "user",
|
594
|
+
content: content.map((part) => ({
|
595
|
+
type: "tool_result",
|
596
|
+
tool_use_id: part.toolCallId,
|
597
|
+
content: JSON.stringify(part.result),
|
598
|
+
is_error: part.isError
|
599
|
+
}))
|
631
600
|
});
|
601
|
+
break;
|
632
602
|
}
|
633
603
|
default: {
|
634
604
|
const _exhaustiveCheck = role;
|
@@ -642,11 +612,26 @@ function convertToAnthropicMessagesPrompt({
|
|
642
612
|
};
|
643
613
|
}
|
644
614
|
|
615
|
+
// anthropic/map-anthropic-stop-reason.ts
|
616
|
+
function mapAnthropicStopReason(finishReason) {
|
617
|
+
switch (finishReason) {
|
618
|
+
case "end_turn":
|
619
|
+
case "stop_sequence":
|
620
|
+
return "stop";
|
621
|
+
case "tool_use":
|
622
|
+
return "tool-calls";
|
623
|
+
case "max_tokens":
|
624
|
+
return "length";
|
625
|
+
default:
|
626
|
+
return "other";
|
627
|
+
}
|
628
|
+
}
|
629
|
+
|
645
630
|
// anthropic/anthropic-messages-language-model.ts
|
646
631
|
var AnthropicMessagesLanguageModel = class {
|
647
632
|
constructor(modelId, settings, config) {
|
648
633
|
this.specificationVersion = "v1";
|
649
|
-
this.defaultObjectGenerationMode = "
|
634
|
+
this.defaultObjectGenerationMode = "tool";
|
650
635
|
this.modelId = modelId;
|
651
636
|
this.settings = settings;
|
652
637
|
this.config = config;
|
@@ -685,10 +670,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
685
670
|
setting: "seed"
|
686
671
|
});
|
687
672
|
}
|
688
|
-
const messagesPrompt = convertToAnthropicMessagesPrompt(
|
689
|
-
provider: this.provider,
|
690
|
-
prompt
|
691
|
-
});
|
673
|
+
const messagesPrompt = convertToAnthropicMessagesPrompt(prompt);
|
692
674
|
const baseArgs = {
|
693
675
|
// model id:
|
694
676
|
model: this.modelId,
|
@@ -711,40 +693,38 @@ var AnthropicMessagesLanguageModel = class {
|
|
711
693
|
args: {
|
712
694
|
...baseArgs,
|
713
695
|
tools: tools == null ? void 0 : tools.map((tool) => ({
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
description: tool.description,
|
718
|
-
parameters: tool.parameters
|
719
|
-
}
|
696
|
+
name: tool.name,
|
697
|
+
description: tool.description,
|
698
|
+
input_schema: tool.parameters
|
720
699
|
}))
|
721
700
|
},
|
722
701
|
warnings
|
723
702
|
};
|
724
703
|
}
|
725
704
|
case "object-json": {
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
response_format: { type: "json_object" }
|
730
|
-
},
|
731
|
-
warnings
|
732
|
-
};
|
705
|
+
throw new UnsupportedFunctionalityError({
|
706
|
+
functionality: "json-mode object generation"
|
707
|
+
});
|
733
708
|
}
|
734
709
|
case "object-tool": {
|
710
|
+
const { name, description, parameters } = mode.tool;
|
711
|
+
baseArgs.messages[baseArgs.messages.length - 1].content.push({
|
712
|
+
type: "text",
|
713
|
+
text: `
|
714
|
+
|
715
|
+
Use the '${name}' tool.`
|
716
|
+
});
|
735
717
|
return {
|
736
718
|
args: {
|
737
719
|
...baseArgs,
|
738
|
-
|
739
|
-
tools: [{ type: "function", function: mode.tool }]
|
720
|
+
tools: [{ name, description, input_schema: parameters }]
|
740
721
|
},
|
741
722
|
warnings
|
742
723
|
};
|
743
724
|
}
|
744
725
|
case "object-grammar": {
|
745
726
|
throw new UnsupportedFunctionalityError({
|
746
|
-
functionality: "
|
747
|
-
provider: this.provider
|
727
|
+
functionality: "grammar-mode object generation"
|
748
728
|
});
|
749
729
|
}
|
750
730
|
default: {
|
@@ -766,9 +746,30 @@ var AnthropicMessagesLanguageModel = class {
|
|
766
746
|
abortSignal: options.abortSignal
|
767
747
|
});
|
768
748
|
const { messages: rawPrompt, ...rawSettings } = args;
|
749
|
+
let text = "";
|
750
|
+
for (const content of response.content) {
|
751
|
+
if (content.type === "text") {
|
752
|
+
text += content.text;
|
753
|
+
}
|
754
|
+
}
|
755
|
+
let toolCalls = void 0;
|
756
|
+
if (response.content.some((content) => content.type === "tool_use")) {
|
757
|
+
toolCalls = [];
|
758
|
+
for (const content of response.content) {
|
759
|
+
if (content.type === "tool_use") {
|
760
|
+
toolCalls.push({
|
761
|
+
toolCallType: "function",
|
762
|
+
toolCallId: content.id,
|
763
|
+
toolName: content.name,
|
764
|
+
args: JSON.stringify(content.input)
|
765
|
+
});
|
766
|
+
}
|
767
|
+
}
|
768
|
+
}
|
769
769
|
return {
|
770
|
-
text
|
771
|
-
|
770
|
+
text,
|
771
|
+
toolCalls,
|
772
|
+
finishReason: mapAnthropicStopReason(response.stop_reason),
|
772
773
|
usage: {
|
773
774
|
promptTokens: response.usage.input_tokens,
|
774
775
|
completionTokens: response.usage.output_tokens
|
@@ -798,7 +799,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
798
799
|
promptTokens: Number.NaN,
|
799
800
|
completionTokens: Number.NaN
|
800
801
|
};
|
801
|
-
const generateId2 = this.config.generateId;
|
802
802
|
return {
|
803
803
|
stream: response.pipeThrough(
|
804
804
|
new TransformStream({
|
@@ -828,9 +828,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
828
828
|
}
|
829
829
|
case "message_delta": {
|
830
830
|
usage.completionTokens = value.usage.output_tokens;
|
831
|
-
finishReason =
|
832
|
-
value.delta.stop_reason
|
833
|
-
);
|
831
|
+
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
834
832
|
return;
|
835
833
|
}
|
836
834
|
case "message_stop": {
|
@@ -853,10 +851,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
853
851
|
var anthropicMessagesResponseSchema = import_zod2.z.object({
|
854
852
|
type: import_zod2.z.literal("message"),
|
855
853
|
content: import_zod2.z.array(
|
856
|
-
import_zod2.z.
|
857
|
-
|
858
|
-
|
859
|
-
|
854
|
+
import_zod2.z.discriminatedUnion("type", [
|
855
|
+
import_zod2.z.object({
|
856
|
+
type: import_zod2.z.literal("text"),
|
857
|
+
text: import_zod2.z.string()
|
858
|
+
}),
|
859
|
+
import_zod2.z.object({
|
860
|
+
type: import_zod2.z.literal("tool_use"),
|
861
|
+
id: import_zod2.z.string(),
|
862
|
+
name: import_zod2.z.string(),
|
863
|
+
input: import_zod2.z.unknown()
|
864
|
+
})
|
865
|
+
])
|
860
866
|
),
|
861
867
|
stop_reason: import_zod2.z.string().optional().nullable(),
|
862
868
|
usage: import_zod2.z.object({
|
@@ -910,10 +916,8 @@ var anthropicMessagesChunkSchema = import_zod2.z.discriminatedUnion("type", [
|
|
910
916
|
// anthropic/anthropic-facade.ts
|
911
917
|
var Anthropic = class {
|
912
918
|
constructor(options = {}) {
|
913
|
-
var _a;
|
914
919
|
this.baseUrl = options.baseUrl;
|
915
920
|
this.apiKey = options.apiKey;
|
916
|
-
this.generateId = (_a = options.generateId) != null ? _a : generateId;
|
917
921
|
}
|
918
922
|
get baseConfig() {
|
919
923
|
var _a;
|
@@ -921,6 +925,7 @@ var Anthropic = class {
|
|
921
925
|
baseUrl: (_a = this.baseUrl) != null ? _a : "https://api.anthropic.com/v1",
|
922
926
|
headers: () => ({
|
923
927
|
"anthropic-version": "2023-06-01",
|
928
|
+
"anthropic-beta": "tools-2024-04-04",
|
924
929
|
"x-api-key": loadApiKey({
|
925
930
|
apiKey: this.apiKey,
|
926
931
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
@@ -932,8 +937,7 @@ var Anthropic = class {
|
|
932
937
|
messages(modelId, settings = {}) {
|
933
938
|
return new AnthropicMessagesLanguageModel(modelId, settings, {
|
934
939
|
provider: "anthropic.messages",
|
935
|
-
...this.baseConfig
|
936
|
-
generateId: this.generateId
|
940
|
+
...this.baseConfig
|
937
941
|
});
|
938
942
|
}
|
939
943
|
};
|