@ai-sdk/anthropic 1.0.3 → 1.0.4
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 +6 -0
- package/dist/index.js +16 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +227 -0
- package/internal/dist/index.d.ts +227 -0
- package/internal/dist/index.js +916 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +900 -0
- package/internal/dist/index.mjs.map +1 -0
- package/package.json +9 -2
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { LanguageModelV1 } from '@ai-sdk/provider';
|
|
2
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-5-sonnet-latest' | 'claude-3-5-sonnet-20241022' | 'claude-3-5-sonnet-20240620' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-opus-latest' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | (string & {});
|
|
6
|
+
interface AnthropicMessagesSettings {
|
|
7
|
+
/**
|
|
8
|
+
Enable Anthropic cache control (beta feature). This will add the beta header and
|
|
9
|
+
allow you to use provider-specific cacheControl metadata.
|
|
10
|
+
*/
|
|
11
|
+
cacheControl?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type AnthropicMessagesConfig = {
|
|
15
|
+
provider: string;
|
|
16
|
+
baseURL: string;
|
|
17
|
+
headers: Resolvable<Record<string, string | undefined>>;
|
|
18
|
+
fetch?: FetchFunction;
|
|
19
|
+
buildRequestUrl?: (baseURL: string, isStreaming: boolean) => string;
|
|
20
|
+
transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
|
|
21
|
+
};
|
|
22
|
+
declare class AnthropicMessagesLanguageModel implements LanguageModelV1 {
|
|
23
|
+
readonly specificationVersion = "v1";
|
|
24
|
+
readonly defaultObjectGenerationMode = "tool";
|
|
25
|
+
readonly supportsImageUrls = false;
|
|
26
|
+
readonly modelId: AnthropicMessagesModelId;
|
|
27
|
+
readonly settings: AnthropicMessagesSettings;
|
|
28
|
+
private readonly config;
|
|
29
|
+
constructor(modelId: AnthropicMessagesModelId, settings: AnthropicMessagesSettings, config: AnthropicMessagesConfig);
|
|
30
|
+
get provider(): string;
|
|
31
|
+
private getArgs;
|
|
32
|
+
private getHeaders;
|
|
33
|
+
private buildRequestUrl;
|
|
34
|
+
private transformRequestBody;
|
|
35
|
+
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
|
36
|
+
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type ExecuteFunction<PARAMETERS, RESULT> = undefined | ((args: PARAMETERS, options: {
|
|
40
|
+
abortSignal?: AbortSignal;
|
|
41
|
+
}) => Promise<RESULT>);
|
|
42
|
+
type ToolResultContent = Array<{
|
|
43
|
+
type: 'text';
|
|
44
|
+
text: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'image';
|
|
47
|
+
data: string;
|
|
48
|
+
mimeType?: string;
|
|
49
|
+
}>;
|
|
50
|
+
declare const Bash20241022Parameters: z.ZodObject<{
|
|
51
|
+
command: z.ZodString;
|
|
52
|
+
restart: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
command: string;
|
|
55
|
+
restart?: boolean | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
command: string;
|
|
58
|
+
restart?: boolean | undefined;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
62
|
+
*
|
|
63
|
+
* Image results are supported.
|
|
64
|
+
*
|
|
65
|
+
* @param execute - The function to execute the tool. Optional.
|
|
66
|
+
*/
|
|
67
|
+
declare function bashTool_20241022<RESULT>(options?: {
|
|
68
|
+
execute?: ExecuteFunction<{
|
|
69
|
+
/**
|
|
70
|
+
* The bash command to run. Required unless the tool is being restarted.
|
|
71
|
+
*/
|
|
72
|
+
command: string;
|
|
73
|
+
/**
|
|
74
|
+
* Specifying true will restart this tool. Otherwise, leave this unspecified.
|
|
75
|
+
*/
|
|
76
|
+
restart?: boolean;
|
|
77
|
+
}, RESULT>;
|
|
78
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
|
79
|
+
}): {
|
|
80
|
+
type: 'provider-defined';
|
|
81
|
+
id: 'anthropic.bash_20241022';
|
|
82
|
+
args: {};
|
|
83
|
+
parameters: typeof Bash20241022Parameters;
|
|
84
|
+
execute: ExecuteFunction<z.infer<typeof Bash20241022Parameters>, RESULT>;
|
|
85
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
|
86
|
+
};
|
|
87
|
+
declare const TextEditor20241022Parameters: z.ZodObject<{
|
|
88
|
+
command: z.ZodEnum<["view", "create", "str_replace", "insert", "undo_edit"]>;
|
|
89
|
+
path: z.ZodString;
|
|
90
|
+
file_text: z.ZodOptional<z.ZodString>;
|
|
91
|
+
insert_line: z.ZodOptional<z.ZodNumber>;
|
|
92
|
+
new_str: z.ZodOptional<z.ZodString>;
|
|
93
|
+
old_str: z.ZodOptional<z.ZodString>;
|
|
94
|
+
view_range: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
path: string;
|
|
97
|
+
command: "view" | "create" | "str_replace" | "insert" | "undo_edit";
|
|
98
|
+
file_text?: string | undefined;
|
|
99
|
+
insert_line?: number | undefined;
|
|
100
|
+
new_str?: string | undefined;
|
|
101
|
+
old_str?: string | undefined;
|
|
102
|
+
view_range?: number[] | undefined;
|
|
103
|
+
}, {
|
|
104
|
+
path: string;
|
|
105
|
+
command: "view" | "create" | "str_replace" | "insert" | "undo_edit";
|
|
106
|
+
file_text?: string | undefined;
|
|
107
|
+
insert_line?: number | undefined;
|
|
108
|
+
new_str?: string | undefined;
|
|
109
|
+
old_str?: string | undefined;
|
|
110
|
+
view_range?: number[] | undefined;
|
|
111
|
+
}>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
114
|
+
*
|
|
115
|
+
* Image results are supported.
|
|
116
|
+
*
|
|
117
|
+
* @param execute - The function to execute the tool. Optional.
|
|
118
|
+
*/
|
|
119
|
+
declare function textEditorTool_20241022<RESULT>(options?: {
|
|
120
|
+
execute?: ExecuteFunction<{
|
|
121
|
+
/**
|
|
122
|
+
* The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.
|
|
123
|
+
*/
|
|
124
|
+
command: 'view' | 'create' | 'str_replace' | 'insert' | 'undo_edit';
|
|
125
|
+
/**
|
|
126
|
+
* Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`.
|
|
127
|
+
*/
|
|
128
|
+
path: string;
|
|
129
|
+
/**
|
|
130
|
+
* Required parameter of `create` command, with the content of the file to be created.
|
|
131
|
+
*/
|
|
132
|
+
file_text?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.
|
|
135
|
+
*/
|
|
136
|
+
insert_line?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.
|
|
139
|
+
*/
|
|
140
|
+
new_str?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Required parameter of `str_replace` command containing the string in `path` to replace.
|
|
143
|
+
*/
|
|
144
|
+
old_str?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.
|
|
147
|
+
*/
|
|
148
|
+
view_range?: number[];
|
|
149
|
+
}, RESULT>;
|
|
150
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
|
151
|
+
}): {
|
|
152
|
+
type: 'provider-defined';
|
|
153
|
+
id: 'anthropic.text_editor_20241022';
|
|
154
|
+
args: {};
|
|
155
|
+
parameters: typeof TextEditor20241022Parameters;
|
|
156
|
+
execute: ExecuteFunction<z.infer<typeof TextEditor20241022Parameters>, RESULT>;
|
|
157
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
|
158
|
+
};
|
|
159
|
+
declare const Computer20241022Parameters: z.ZodObject<{
|
|
160
|
+
action: z.ZodEnum<["key", "type", "mouse_move", "left_click", "left_click_drag", "right_click", "middle_click", "double_click", "screenshot", "cursor_position"]>;
|
|
161
|
+
coordinate: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
162
|
+
text: z.ZodOptional<z.ZodString>;
|
|
163
|
+
}, "strip", z.ZodTypeAny, {
|
|
164
|
+
action: "type" | "key" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position";
|
|
165
|
+
text?: string | undefined;
|
|
166
|
+
coordinate?: number[] | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
action: "type" | "key" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position";
|
|
169
|
+
text?: string | undefined;
|
|
170
|
+
coordinate?: number[] | undefined;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
174
|
+
*
|
|
175
|
+
* Image results are supported.
|
|
176
|
+
*
|
|
177
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
178
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
179
|
+
* @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
|
|
180
|
+
* @param execute - The function to execute the tool. Optional.
|
|
181
|
+
*/
|
|
182
|
+
declare function computerTool_20241022<RESULT>(options: {
|
|
183
|
+
displayWidthPx: number;
|
|
184
|
+
displayHeightPx: number;
|
|
185
|
+
displayNumber?: number;
|
|
186
|
+
execute?: ExecuteFunction<{
|
|
187
|
+
/**
|
|
188
|
+
* The action to perform. The available actions are:
|
|
189
|
+
* - `key`: Press a key or key-combination on the keyboard.
|
|
190
|
+
* - This supports xdotool's `key` syntax.
|
|
191
|
+
* - Examples: "a", "Return", "alt+Tab", "ctrl+s", "Up", "KP_0" (for the numpad 0 key).
|
|
192
|
+
* - `type`: Type a string of text on the keyboard.
|
|
193
|
+
* - `cursor_position`: Get the current (x, y) pixel coordinate of the cursor on the screen.
|
|
194
|
+
* - `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.
|
|
195
|
+
* - `left_click`: Click the left mouse button.
|
|
196
|
+
* - `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.
|
|
197
|
+
* - `right_click`: Click the right mouse button.
|
|
198
|
+
* - `middle_click`: Click the middle mouse button.
|
|
199
|
+
* - `double_click`: Double-click the left mouse button.
|
|
200
|
+
* - `screenshot`: Take a screenshot of the screen.
|
|
201
|
+
*/
|
|
202
|
+
action: 'key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'screenshot' | 'cursor_position';
|
|
203
|
+
/**
|
|
204
|
+
* (x, y): The x (pixels from the left edge) and y (pixels from the top edge) coordinates to move the mouse to. Required only by `action=mouse_move` and `action=left_click_drag`.
|
|
205
|
+
*/
|
|
206
|
+
coordinate?: number[];
|
|
207
|
+
/**
|
|
208
|
+
* Required only by `action=type` and `action=key`.
|
|
209
|
+
*/
|
|
210
|
+
text?: string;
|
|
211
|
+
}, RESULT>;
|
|
212
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
|
213
|
+
}): {
|
|
214
|
+
type: 'provider-defined';
|
|
215
|
+
id: 'anthropic.computer_20241022';
|
|
216
|
+
args: {};
|
|
217
|
+
parameters: typeof Computer20241022Parameters;
|
|
218
|
+
execute: ExecuteFunction<z.infer<typeof Computer20241022Parameters>, RESULT>;
|
|
219
|
+
experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
|
|
220
|
+
};
|
|
221
|
+
declare const anthropicTools: {
|
|
222
|
+
bash_20241022: typeof bashTool_20241022;
|
|
223
|
+
textEditor_20241022: typeof textEditorTool_20241022;
|
|
224
|
+
computer_20241022: typeof computerTool_20241022;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, type AnthropicMessagesSettings, anthropicTools };
|