@langchain/anthropic 0.3.31 → 1.0.0-alpha.2
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/README.md +8 -8
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/chat_models.cjs +781 -1012
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +620 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +227 -211
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +775 -1003
- package/dist/chat_models.js.map +1 -0
- package/dist/index.cjs +6 -20
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -2
- package/dist/output_parsers.cjs +65 -104
- package/dist/output_parsers.cjs.map +1 -0
- package/dist/output_parsers.js +64 -100
- package/dist/output_parsers.js.map +1 -0
- package/dist/types.d.cts +33 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +30 -32
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/content.cjs +151 -0
- package/dist/utils/content.cjs.map +1 -0
- package/dist/utils/content.js +146 -0
- package/dist/utils/content.js.map +1 -0
- package/dist/utils/errors.cjs +16 -27
- package/dist/utils/errors.cjs.map +1 -0
- package/dist/utils/errors.js +17 -25
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.cjs +7 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/message_inputs.cjs +223 -534
- package/dist/utils/message_inputs.cjs.map +1 -0
- package/dist/utils/message_inputs.js +224 -532
- package/dist/utils/message_inputs.js.map +1 -0
- package/dist/utils/message_outputs.cjs +186 -250
- package/dist/utils/message_outputs.cjs.map +1 -0
- package/dist/utils/message_outputs.js +185 -247
- package/dist/utils/message_outputs.js.map +1 -0
- package/dist/utils/prompts.cjs +46 -45
- package/dist/utils/prompts.cjs.map +1 -0
- package/dist/utils/prompts.d.cts +45 -0
- package/dist/utils/prompts.d.cts.map +1 -0
- package/dist/utils/prompts.d.ts +8 -2
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +46 -42
- package/dist/utils/prompts.js.map +1 -0
- package/dist/utils/standard.cjs +285 -0
- package/dist/utils/standard.cjs.map +1 -0
- package/dist/utils/standard.js +285 -0
- package/dist/utils/standard.js.map +1 -0
- package/dist/utils/tools.cjs +15 -30
- package/dist/utils/tools.cjs.map +1 -0
- package/dist/utils/tools.js +15 -28
- package/dist/utils/tools.js.map +1 -0
- package/package.json +45 -71
- package/dist/experimental/index.cjs +0 -17
- package/dist/experimental/index.d.ts +0 -1
- package/dist/experimental/index.js +0 -1
- package/dist/experimental/tool_calling.cjs +0 -318
- package/dist/experimental/tool_calling.d.ts +0 -57
- package/dist/experimental/tool_calling.js +0 -314
- package/dist/experimental/utils/tool_calling.cjs +0 -106
- package/dist/experimental/utils/tool_calling.d.ts +0 -10
- package/dist/experimental/utils/tool_calling.js +0 -101
- package/dist/load/import_constants.cjs +0 -5
- package/dist/load/import_constants.d.ts +0 -1
- package/dist/load/import_constants.js +0 -2
- package/dist/load/import_map.cjs +0 -39
- package/dist/load/import_map.d.ts +0 -2
- package/dist/load/import_map.js +0 -3
- package/dist/load/import_type.cjs +0 -3
- package/dist/load/import_type.d.ts +0 -5
- package/dist/load/import_type.js +0 -2
- package/dist/load/index.cjs +0 -63
- package/dist/load/index.d.ts +0 -14
- package/dist/load/index.js +0 -25
- package/dist/load/map_keys.cjs +0 -2
- package/dist/load/map_keys.d.ts +0 -3
- package/dist/load/map_keys.js +0 -1
- package/dist/load/serializable.cjs +0 -17
- package/dist/load/serializable.d.ts +0 -1
- package/dist/load/serializable.js +0 -1
- package/dist/output_parsers.d.ts +0 -22
- package/dist/types.cjs +0 -48
- package/dist/types.js +0 -45
- package/dist/utils/errors.d.ts +0 -3
- package/dist/utils/message_inputs.d.ts +0 -14
- package/dist/utils/message_outputs.d.ts +0 -14
- package/dist/utils/tools.d.ts +0 -3
- package/experimental.cjs +0 -1
- package/experimental.d.cts +0 -1
- package/experimental.d.ts +0 -1
- package/experimental.js +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { iife } from "./index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/standard.ts
|
|
4
|
+
function _isStandardAnnotation(annotation) {
|
|
5
|
+
return typeof annotation === "object" && annotation !== null && "type" in annotation && annotation.type === "citation";
|
|
6
|
+
}
|
|
7
|
+
function _formatStandardCitations(annotations) {
|
|
8
|
+
function* iterateAnnotations() {
|
|
9
|
+
for (const annotation of annotations) if (_isStandardAnnotation(annotation)) {
|
|
10
|
+
if (annotation.source === "char") yield {
|
|
11
|
+
type: "char_location",
|
|
12
|
+
file_id: annotation.url ?? "",
|
|
13
|
+
start_char_index: annotation.startIndex ?? 0,
|
|
14
|
+
end_char_index: annotation.endIndex ?? 0,
|
|
15
|
+
document_title: annotation.title ?? null,
|
|
16
|
+
document_index: 0,
|
|
17
|
+
cited_text: annotation.citedText ?? ""
|
|
18
|
+
};
|
|
19
|
+
else if (annotation.source === "page") yield {
|
|
20
|
+
type: "page_location",
|
|
21
|
+
file_id: annotation.url ?? "",
|
|
22
|
+
start_page_number: annotation.startIndex ?? 0,
|
|
23
|
+
end_page_number: annotation.endIndex ?? 0,
|
|
24
|
+
document_title: annotation.title ?? null,
|
|
25
|
+
document_index: 0,
|
|
26
|
+
cited_text: annotation.citedText ?? ""
|
|
27
|
+
};
|
|
28
|
+
else if (annotation.source === "block") yield {
|
|
29
|
+
type: "content_block_location",
|
|
30
|
+
file_id: annotation.url ?? "",
|
|
31
|
+
start_block_index: annotation.startIndex ?? 0,
|
|
32
|
+
end_block_index: annotation.endIndex ?? 0,
|
|
33
|
+
document_title: annotation.title ?? null,
|
|
34
|
+
document_index: 0,
|
|
35
|
+
cited_text: annotation.citedText ?? ""
|
|
36
|
+
};
|
|
37
|
+
else if (annotation.source === "url") yield {
|
|
38
|
+
type: "web_search_result_location",
|
|
39
|
+
url: annotation.url ?? "",
|
|
40
|
+
title: annotation.title ?? null,
|
|
41
|
+
encrypted_index: String(annotation.startIndex ?? 0),
|
|
42
|
+
cited_text: annotation.citedText ?? ""
|
|
43
|
+
};
|
|
44
|
+
else if (annotation.source === "search") yield {
|
|
45
|
+
type: "search_result_location",
|
|
46
|
+
title: annotation.title ?? null,
|
|
47
|
+
start_block_index: annotation.startIndex ?? 0,
|
|
48
|
+
end_block_index: annotation.endIndex ?? 0,
|
|
49
|
+
search_result_index: 0,
|
|
50
|
+
source: annotation.source ?? "",
|
|
51
|
+
cited_text: annotation.citedText ?? ""
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Array.from(iterateAnnotations());
|
|
56
|
+
}
|
|
57
|
+
function _formatBase64Data(data) {
|
|
58
|
+
if (typeof data === "string") return data;
|
|
59
|
+
else return _encodeUint8Array(data);
|
|
60
|
+
}
|
|
61
|
+
function _encodeUint8Array(data) {
|
|
62
|
+
const output = [];
|
|
63
|
+
for (let i = 0, { length } = data; i < length; i++) output.push(String.fromCharCode(data[i]));
|
|
64
|
+
return btoa(output.join(""));
|
|
65
|
+
}
|
|
66
|
+
function _normalizeMimeType(mimeType) {
|
|
67
|
+
return (mimeType ?? "").split(";")[0].toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
function _extractMetadataValue(metadata, key) {
|
|
70
|
+
if (metadata !== void 0 && metadata !== null && typeof metadata === "object" && key in metadata) return metadata[key];
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
function _applyDocumentMetadata(block, metadata) {
|
|
74
|
+
const cacheControl = _extractMetadataValue(metadata, "cache_control");
|
|
75
|
+
if (cacheControl !== void 0) block.cache_control = cacheControl;
|
|
76
|
+
const citations = _extractMetadataValue(metadata, "citations");
|
|
77
|
+
if (citations !== void 0) block.citations = citations;
|
|
78
|
+
const context = _extractMetadataValue(metadata, "context");
|
|
79
|
+
if (context !== void 0) block.context = context;
|
|
80
|
+
const title = _extractMetadataValue(metadata, "title");
|
|
81
|
+
if (title !== void 0) block.title = title;
|
|
82
|
+
return block;
|
|
83
|
+
}
|
|
84
|
+
function _applyImageMetadata(block, metadata) {
|
|
85
|
+
const cacheControl = _extractMetadataValue(metadata, "cache_control");
|
|
86
|
+
if (cacheControl !== void 0) block.cache_control = cacheControl;
|
|
87
|
+
return block;
|
|
88
|
+
}
|
|
89
|
+
function _hasAllowedImageMimeType(mimeType) {
|
|
90
|
+
const ALLOWED_IMAGE_MIME_TYPES = new Set([
|
|
91
|
+
"image/jpeg",
|
|
92
|
+
"image/png",
|
|
93
|
+
"image/gif",
|
|
94
|
+
"image/webp"
|
|
95
|
+
]);
|
|
96
|
+
return ALLOWED_IMAGE_MIME_TYPES.has(mimeType);
|
|
97
|
+
}
|
|
98
|
+
function _formatStandardContent(message) {
|
|
99
|
+
const result = [];
|
|
100
|
+
const responseMetadata = message.response_metadata;
|
|
101
|
+
const isAnthropicMessage = "model_provider" in responseMetadata && responseMetadata?.model_provider === "anthropic";
|
|
102
|
+
for (const block of message.contentBlocks) if (block.type === "text") if (block.annotations) result.push({
|
|
103
|
+
type: "text",
|
|
104
|
+
text: block.text,
|
|
105
|
+
citations: _formatStandardCitations(block.annotations)
|
|
106
|
+
});
|
|
107
|
+
else result.push({
|
|
108
|
+
type: "text",
|
|
109
|
+
text: block.text
|
|
110
|
+
});
|
|
111
|
+
else if (block.type === "tool_call") result.push({
|
|
112
|
+
type: "tool_use",
|
|
113
|
+
id: block.id ?? "",
|
|
114
|
+
name: block.name,
|
|
115
|
+
input: block.args
|
|
116
|
+
});
|
|
117
|
+
else if (block.type === "tool_call_chunk") {
|
|
118
|
+
const input = iife(() => {
|
|
119
|
+
if (typeof block.args !== "string") return block.args;
|
|
120
|
+
try {
|
|
121
|
+
return JSON.parse(block.args);
|
|
122
|
+
} catch {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
result.push({
|
|
127
|
+
type: "tool_use",
|
|
128
|
+
id: block.id ?? "",
|
|
129
|
+
name: block.name ?? "",
|
|
130
|
+
input
|
|
131
|
+
});
|
|
132
|
+
} else if (block.type === "reasoning" && isAnthropicMessage) result.push({
|
|
133
|
+
type: "thinking",
|
|
134
|
+
thinking: block.reasoning,
|
|
135
|
+
signature: String(block.signature)
|
|
136
|
+
});
|
|
137
|
+
else if (block.type === "server_tool_call" && isAnthropicMessage) {
|
|
138
|
+
if (block.name === "web_search") result.push({
|
|
139
|
+
type: "server_tool_use",
|
|
140
|
+
name: block.name,
|
|
141
|
+
id: block.id ?? "",
|
|
142
|
+
input: block.args
|
|
143
|
+
});
|
|
144
|
+
else if (block.name === "code_execution") result.push({
|
|
145
|
+
type: "server_tool_use",
|
|
146
|
+
name: block.name,
|
|
147
|
+
id: block.id ?? "",
|
|
148
|
+
input: block.args
|
|
149
|
+
});
|
|
150
|
+
} else if (block.type === "server_tool_call_result" && isAnthropicMessage) {
|
|
151
|
+
if (block.name === "web_search" && Array.isArray(block.output.urls)) {
|
|
152
|
+
const content = block.output.urls.map((url) => ({
|
|
153
|
+
type: "web_search_result",
|
|
154
|
+
title: "",
|
|
155
|
+
encrypted_content: "",
|
|
156
|
+
url
|
|
157
|
+
}));
|
|
158
|
+
result.push({
|
|
159
|
+
type: "web_search_tool_result",
|
|
160
|
+
tool_use_id: block.toolCallId ?? "",
|
|
161
|
+
content
|
|
162
|
+
});
|
|
163
|
+
} else if (block.name === "code_execution") result.push({
|
|
164
|
+
type: "code_execution_tool_result",
|
|
165
|
+
tool_use_id: block.toolCallId ?? "",
|
|
166
|
+
content: block.output
|
|
167
|
+
});
|
|
168
|
+
else if (block.name === "mcp_tool_result") result.push({
|
|
169
|
+
type: "mcp_tool_result",
|
|
170
|
+
tool_use_id: block.toolCallId ?? "",
|
|
171
|
+
content: block.output
|
|
172
|
+
});
|
|
173
|
+
} else if (block.type === "audio") throw new Error("Anthropic does not support audio content blocks.");
|
|
174
|
+
else if (block.type === "file") {
|
|
175
|
+
const metadata = block.metadata;
|
|
176
|
+
if (block.fileId) {
|
|
177
|
+
result.push(_applyDocumentMetadata({
|
|
178
|
+
type: "document",
|
|
179
|
+
source: {
|
|
180
|
+
type: "file",
|
|
181
|
+
file_id: block.fileId
|
|
182
|
+
}
|
|
183
|
+
}, metadata));
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (block.url) {
|
|
187
|
+
const mimeType = _normalizeMimeType(block.mimeType);
|
|
188
|
+
if (mimeType === "application/pdf" || mimeType === "") {
|
|
189
|
+
result.push(_applyDocumentMetadata({
|
|
190
|
+
type: "document",
|
|
191
|
+
source: {
|
|
192
|
+
type: "url",
|
|
193
|
+
url: block.url
|
|
194
|
+
}
|
|
195
|
+
}, metadata));
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (block.data) {
|
|
200
|
+
const mimeType = _normalizeMimeType(block.mimeType);
|
|
201
|
+
if (mimeType === "" || mimeType === "application/pdf") result.push(_applyDocumentMetadata({
|
|
202
|
+
type: "document",
|
|
203
|
+
source: {
|
|
204
|
+
type: "base64",
|
|
205
|
+
data: _formatBase64Data(block.data),
|
|
206
|
+
media_type: "application/pdf"
|
|
207
|
+
}
|
|
208
|
+
}, metadata));
|
|
209
|
+
else if (mimeType === "text/plain") result.push(_applyDocumentMetadata({
|
|
210
|
+
type: "document",
|
|
211
|
+
source: {
|
|
212
|
+
type: "text",
|
|
213
|
+
data: _formatBase64Data(block.data),
|
|
214
|
+
media_type: "text/plain"
|
|
215
|
+
}
|
|
216
|
+
}, metadata));
|
|
217
|
+
else if (_hasAllowedImageMimeType(mimeType)) result.push(_applyDocumentMetadata({
|
|
218
|
+
type: "document",
|
|
219
|
+
source: {
|
|
220
|
+
type: "content",
|
|
221
|
+
content: [{
|
|
222
|
+
type: "image",
|
|
223
|
+
source: {
|
|
224
|
+
type: "base64",
|
|
225
|
+
data: _formatBase64Data(block.data),
|
|
226
|
+
media_type: mimeType
|
|
227
|
+
}
|
|
228
|
+
}]
|
|
229
|
+
}
|
|
230
|
+
}, metadata));
|
|
231
|
+
else throw new Error(`Unsupported file mime type for Anthropic base64 source: ${mimeType}`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
throw new Error("File content block must include a fileId, url, or data property.");
|
|
235
|
+
} else if (block.type === "image") {
|
|
236
|
+
const metadata = block.metadata;
|
|
237
|
+
if (block.fileId) {
|
|
238
|
+
result.push(_applyImageMetadata({
|
|
239
|
+
type: "image",
|
|
240
|
+
source: {
|
|
241
|
+
type: "file",
|
|
242
|
+
file_id: block.fileId
|
|
243
|
+
}
|
|
244
|
+
}, metadata));
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (block.url) {
|
|
248
|
+
result.push(_applyImageMetadata({
|
|
249
|
+
type: "image",
|
|
250
|
+
source: {
|
|
251
|
+
type: "url",
|
|
252
|
+
url: block.url
|
|
253
|
+
}
|
|
254
|
+
}, metadata));
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (block.data) {
|
|
258
|
+
const mimeType = _normalizeMimeType(block.mimeType) || "image/png";
|
|
259
|
+
if (_hasAllowedImageMimeType(mimeType)) result.push(_applyImageMetadata({
|
|
260
|
+
type: "image",
|
|
261
|
+
source: {
|
|
262
|
+
type: "base64",
|
|
263
|
+
data: _formatBase64Data(block.data),
|
|
264
|
+
media_type: mimeType
|
|
265
|
+
}
|
|
266
|
+
}, metadata));
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
throw new Error("Image content block must include a fileId, url, or data property.");
|
|
270
|
+
} else if (block.type === "video") {} else if (block.type === "text-plain") {
|
|
271
|
+
if (block.data) result.push(_applyDocumentMetadata({
|
|
272
|
+
type: "document",
|
|
273
|
+
source: {
|
|
274
|
+
type: "text",
|
|
275
|
+
data: _formatBase64Data(block.data),
|
|
276
|
+
media_type: "text/plain"
|
|
277
|
+
}
|
|
278
|
+
}, block.metadata));
|
|
279
|
+
} else if (block.type === "non_standard" && isAnthropicMessage) result.push(block.value);
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
//#endregion
|
|
284
|
+
export { _formatStandardContent };
|
|
285
|
+
//# sourceMappingURL=standard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard.js","names":["annotation: unknown","annotations: ContentBlock.Citation[]","data: string | Uint8Array","data: Uint8Array","mimeType?: string | null","metadata: unknown","key: string","block: Anthropic.Beta.BetaRequestDocumentBlock","block: Anthropic.Beta.BetaImageBlockParam","mimeType: string","message: BaseMessage","result: Anthropic.Beta.BetaContentBlockParam[]"],"sources":["../../src/utils/standard.ts"],"sourcesContent":["import type Anthropic from \"@anthropic-ai/sdk\";\nimport type {\n BaseMessage,\n ContentBlock,\n ResponseMetadata,\n} from \"@langchain/core/messages\";\nimport { iife } from \"./index.js\";\n\nfunction _isStandardAnnotation(\n annotation: unknown\n): annotation is ContentBlock.Citation {\n return (\n typeof annotation === \"object\" &&\n annotation !== null &&\n \"type\" in annotation &&\n annotation.type === \"citation\"\n );\n}\n\nfunction _formatStandardCitations(\n annotations: ContentBlock.Citation[]\n): Anthropic.Beta.BetaTextCitation[] {\n function* iterateAnnotations() {\n for (const annotation of annotations) {\n if (_isStandardAnnotation(annotation)) {\n if (annotation.source === \"char\") {\n yield {\n type: \"char_location\" as const,\n file_id: annotation.url ?? \"\",\n start_char_index: annotation.startIndex ?? 0,\n end_char_index: annotation.endIndex ?? 0,\n document_title: annotation.title ?? null,\n document_index: 0,\n cited_text: annotation.citedText ?? \"\",\n };\n } else if (annotation.source === \"page\") {\n yield {\n type: \"page_location\" as const,\n file_id: annotation.url ?? \"\",\n start_page_number: annotation.startIndex ?? 0,\n end_page_number: annotation.endIndex ?? 0,\n document_title: annotation.title ?? null,\n document_index: 0,\n cited_text: annotation.citedText ?? \"\",\n };\n } else if (annotation.source === \"block\") {\n yield {\n type: \"content_block_location\" as const,\n file_id: annotation.url ?? \"\",\n start_block_index: annotation.startIndex ?? 0,\n end_block_index: annotation.endIndex ?? 0,\n document_title: annotation.title ?? null,\n document_index: 0,\n cited_text: annotation.citedText ?? \"\",\n };\n } else if (annotation.source === \"url\") {\n yield {\n type: \"web_search_result_location\" as const,\n url: annotation.url ?? \"\",\n title: annotation.title ?? null,\n encrypted_index: String(annotation.startIndex ?? 0),\n cited_text: annotation.citedText ?? \"\",\n };\n } else if (annotation.source === \"search\") {\n yield {\n type: \"search_result_location\" as const,\n title: annotation.title ?? null,\n start_block_index: annotation.startIndex ?? 0,\n end_block_index: annotation.endIndex ?? 0,\n search_result_index: 0,\n source: annotation.source ?? \"\",\n cited_text: annotation.citedText ?? \"\",\n };\n }\n }\n }\n }\n return Array.from(iterateAnnotations());\n}\n\nfunction _formatBase64Data(data: string | Uint8Array): string {\n if (typeof data === \"string\") return data;\n else return _encodeUint8Array(data);\n}\n\nfunction _encodeUint8Array(data: Uint8Array): string {\n const output = [];\n for (let i = 0, { length } = data; i < length; i++) {\n output.push(String.fromCharCode(data[i]));\n }\n return btoa(output.join(\"\"));\n}\n\nfunction _normalizeMimeType(mimeType?: string | null): string {\n return (mimeType ?? \"\").split(\";\")[0].toLowerCase();\n}\n\nfunction _extractMetadataValue<T>(\n metadata: unknown,\n key: string\n): T | undefined {\n if (\n metadata !== undefined &&\n metadata !== null &&\n typeof metadata === \"object\" &&\n key in metadata\n ) {\n return (metadata as Record<string, unknown>)[key] as T;\n }\n return undefined;\n}\n\nfunction _applyDocumentMetadata(\n block: Anthropic.Beta.BetaRequestDocumentBlock,\n metadata: unknown\n): Anthropic.Beta.BetaRequestDocumentBlock {\n const cacheControl =\n _extractMetadataValue<Anthropic.Beta.BetaCacheControlEphemeral | null>(\n metadata,\n \"cache_control\"\n );\n if (cacheControl !== undefined) {\n block.cache_control = cacheControl;\n }\n const citations =\n _extractMetadataValue<Anthropic.Beta.BetaCitationsConfigParam | null>(\n metadata,\n \"citations\"\n );\n if (citations !== undefined) {\n block.citations = citations;\n }\n const context = _extractMetadataValue<string | null>(metadata, \"context\");\n if (context !== undefined) {\n block.context = context;\n }\n const title = _extractMetadataValue<string | null>(metadata, \"title\");\n if (title !== undefined) {\n block.title = title;\n }\n return block;\n}\n\nfunction _applyImageMetadata(\n block: Anthropic.Beta.BetaImageBlockParam,\n metadata: unknown\n): Anthropic.Beta.BetaImageBlockParam {\n const cacheControl =\n _extractMetadataValue<Anthropic.Beta.BetaCacheControlEphemeral | null>(\n metadata,\n \"cache_control\"\n );\n if (cacheControl !== undefined) {\n block.cache_control = cacheControl;\n }\n return block;\n}\n\nfunction _hasAllowedImageMimeType(\n mimeType: string\n): mimeType is \"image/jpeg\" | \"image/png\" | \"image/gif\" | \"image/webp\" {\n const ALLOWED_IMAGE_MIME_TYPES = new Set([\n \"image/jpeg\",\n \"image/png\",\n \"image/gif\",\n \"image/webp\",\n ]);\n return ALLOWED_IMAGE_MIME_TYPES.has(mimeType);\n}\n\nexport function _formatStandardContent(\n message: BaseMessage\n): Anthropic.Beta.BetaContentBlockParam[] {\n const result: Anthropic.Beta.BetaContentBlockParam[] = [];\n const responseMetadata = message.response_metadata as ResponseMetadata;\n const isAnthropicMessage =\n \"model_provider\" in responseMetadata &&\n responseMetadata?.model_provider === \"anthropic\";\n for (const block of message.contentBlocks) {\n if (block.type === \"text\") {\n if (block.annotations) {\n result.push({\n type: \"text\",\n text: block.text,\n citations: _formatStandardCitations(\n block.annotations as ContentBlock.Citation[]\n ),\n });\n } else {\n result.push({\n type: \"text\",\n text: block.text,\n });\n }\n } else if (block.type === \"tool_call\") {\n result.push({\n type: \"tool_use\",\n id: block.id ?? \"\",\n name: block.name,\n input: block.args,\n });\n } else if (block.type === \"tool_call_chunk\") {\n const input = iife(() => {\n if (typeof block.args !== \"string\") {\n return block.args;\n }\n try {\n return JSON.parse(block.args);\n } catch {\n return {};\n }\n });\n result.push({\n type: \"tool_use\",\n id: block.id ?? \"\",\n name: block.name ?? \"\",\n input,\n });\n } else if (block.type === \"reasoning\" && isAnthropicMessage) {\n result.push({\n type: \"thinking\",\n thinking: block.reasoning,\n signature: String(block.signature),\n });\n } else if (block.type === \"server_tool_call\" && isAnthropicMessage) {\n if (block.name === \"web_search\") {\n result.push({\n type: \"server_tool_use\",\n name: block.name,\n id: block.id ?? \"\",\n input: block.args,\n });\n } else if (block.name === \"code_execution\") {\n result.push({\n type: \"server_tool_use\",\n name: block.name,\n id: block.id ?? \"\",\n input: block.args,\n });\n }\n } else if (block.type === \"server_tool_call_result\" && isAnthropicMessage) {\n if (block.name === \"web_search\" && Array.isArray(block.output.urls)) {\n const content = block.output.urls.map((url) => ({\n type: \"web_search_result\" as const,\n title: \"\",\n encrypted_content: \"\",\n url,\n }));\n result.push({\n type: \"web_search_tool_result\",\n tool_use_id: block.toolCallId ?? \"\",\n content,\n });\n } else if (block.name === \"code_execution\") {\n result.push({\n type: \"code_execution_tool_result\",\n tool_use_id: block.toolCallId ?? \"\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n content: block.output as any,\n });\n } else if (block.name === \"mcp_tool_result\") {\n result.push({\n type: \"mcp_tool_result\",\n tool_use_id: block.toolCallId ?? \"\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n content: block.output as any,\n });\n }\n } else if (block.type === \"audio\") {\n throw new Error(\"Anthropic does not support audio content blocks.\");\n } else if (block.type === \"file\") {\n const metadata = block.metadata;\n if (block.fileId) {\n result.push(\n _applyDocumentMetadata(\n {\n type: \"document\",\n source: {\n type: \"file\",\n file_id: block.fileId,\n },\n },\n metadata\n )\n );\n continue;\n }\n if (block.url) {\n const mimeType = _normalizeMimeType(block.mimeType);\n if (mimeType === \"application/pdf\" || mimeType === \"\") {\n result.push(\n _applyDocumentMetadata(\n {\n type: \"document\",\n source: {\n type: \"url\",\n url: block.url,\n },\n },\n metadata\n )\n );\n continue;\n }\n }\n if (block.data) {\n const mimeType = _normalizeMimeType(block.mimeType);\n if (mimeType === \"\" || mimeType === \"application/pdf\") {\n result.push(\n _applyDocumentMetadata(\n {\n type: \"document\",\n source: {\n type: \"base64\",\n data: _formatBase64Data(block.data),\n media_type: \"application/pdf\",\n },\n },\n metadata\n )\n );\n } else if (mimeType === \"text/plain\") {\n result.push(\n _applyDocumentMetadata(\n {\n type: \"document\",\n source: {\n type: \"text\",\n data: _formatBase64Data(block.data),\n media_type: \"text/plain\",\n },\n },\n metadata\n )\n );\n } else {\n if (_hasAllowedImageMimeType(mimeType)) {\n result.push(\n _applyDocumentMetadata(\n {\n type: \"document\",\n source: {\n type: \"content\",\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n data: _formatBase64Data(block.data),\n media_type: mimeType,\n },\n },\n ],\n },\n },\n metadata\n )\n );\n } else {\n throw new Error(\n `Unsupported file mime type for Anthropic base64 source: ${mimeType}`\n );\n }\n }\n continue;\n }\n throw new Error(\n \"File content block must include a fileId, url, or data property.\"\n );\n } else if (block.type === \"image\") {\n const metadata = block.metadata;\n if (block.fileId) {\n result.push(\n _applyImageMetadata(\n {\n type: \"image\",\n source: {\n type: \"file\",\n file_id: block.fileId,\n },\n },\n metadata\n )\n );\n continue;\n }\n if (block.url) {\n result.push(\n _applyImageMetadata(\n {\n type: \"image\",\n source: {\n type: \"url\",\n url: block.url,\n },\n },\n metadata\n )\n );\n continue;\n }\n if (block.data) {\n const mimeType = _normalizeMimeType(block.mimeType) || \"image/png\";\n if (_hasAllowedImageMimeType(mimeType)) {\n result.push(\n _applyImageMetadata(\n {\n type: \"image\",\n source: {\n type: \"base64\",\n data: _formatBase64Data(block.data),\n media_type: mimeType,\n },\n },\n metadata\n )\n );\n }\n continue;\n }\n throw new Error(\n \"Image content block must include a fileId, url, or data property.\"\n );\n } else if (block.type === \"video\") {\n // no-op\n } else if (block.type === \"text-plain\") {\n if (block.data) {\n result.push(\n _applyDocumentMetadata(\n {\n type: \"document\",\n source: {\n type: \"text\",\n data: _formatBase64Data(block.data),\n media_type: \"text/plain\",\n },\n },\n block.metadata\n )\n );\n }\n } else if (block.type === \"non_standard\" && isAnthropicMessage) {\n result.push(block.value as Anthropic.Beta.BetaContentBlockParam);\n }\n }\n return result;\n}\n"],"mappings":";;;AAQA,SAAS,sBACPA,YACqC;AACrC,QACE,OAAO,eAAe,YACtB,eAAe,QACf,UAAU,cACV,WAAW,SAAS;AAEvB;AAED,SAAS,yBACPC,aACmC;CACnC,UAAU,qBAAqB;AAC7B,OAAK,MAAM,cAAc,YACvB,KAAI,sBAAsB,WAAW,EACnC;OAAI,WAAW,WAAW,QACxB,MAAM;IACJ,MAAM;IACN,SAAS,WAAW,OAAO;IAC3B,kBAAkB,WAAW,cAAc;IAC3C,gBAAgB,WAAW,YAAY;IACvC,gBAAgB,WAAW,SAAS;IACpC,gBAAgB;IAChB,YAAY,WAAW,aAAa;GACrC;YACQ,WAAW,WAAW,QAC/B,MAAM;IACJ,MAAM;IACN,SAAS,WAAW,OAAO;IAC3B,mBAAmB,WAAW,cAAc;IAC5C,iBAAiB,WAAW,YAAY;IACxC,gBAAgB,WAAW,SAAS;IACpC,gBAAgB;IAChB,YAAY,WAAW,aAAa;GACrC;YACQ,WAAW,WAAW,SAC/B,MAAM;IACJ,MAAM;IACN,SAAS,WAAW,OAAO;IAC3B,mBAAmB,WAAW,cAAc;IAC5C,iBAAiB,WAAW,YAAY;IACxC,gBAAgB,WAAW,SAAS;IACpC,gBAAgB;IAChB,YAAY,WAAW,aAAa;GACrC;YACQ,WAAW,WAAW,OAC/B,MAAM;IACJ,MAAM;IACN,KAAK,WAAW,OAAO;IACvB,OAAO,WAAW,SAAS;IAC3B,iBAAiB,OAAO,WAAW,cAAc,EAAE;IACnD,YAAY,WAAW,aAAa;GACrC;YACQ,WAAW,WAAW,UAC/B,MAAM;IACJ,MAAM;IACN,OAAO,WAAW,SAAS;IAC3B,mBAAmB,WAAW,cAAc;IAC5C,iBAAiB,WAAW,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,KACL,uBACE;IACE,MAAM;IACN,QAAQ;KACN,MAAM;KACN,SAAS,CACP;MACE,MAAM;MACN,QAAQ;OACN,MAAM;OACN,MAAM,kBAAkB,MAAM,KAAK;OACnC,YAAY;MACb;KACF,CACF;IACF;GACF,GACD,SACD,CACF;OAED,OAAM,IAAI,MACR,CAAC,wDAAwD,EAAE,UAAU;AAI3E;EACD;AACD,QAAM,IAAI,MACR;CAEH,WAAU,MAAM,SAAS,SAAS;EACjC,MAAM,WAAW,MAAM;AACvB,MAAI,MAAM,QAAQ;GAChB,OAAO,KACL,oBACE;IACE,MAAM;IACN,QAAQ;KACN,MAAM;KACN,SAAS,MAAM;IAChB;GACF,GACD,SACD,CACF;AACD;EACD;AACD,MAAI,MAAM,KAAK;GACb,OAAO,KACL,oBACE;IACE,MAAM;IACN,QAAQ;KACN,MAAM;KACN,KAAK,MAAM;IACZ;GACF,GACD,SACD,CACF;AACD;EACD;AACD,MAAI,MAAM,MAAM;GACd,MAAM,WAAW,mBAAmB,MAAM,SAAS,IAAI;AACvD,OAAI,yBAAyB,SAAS,EACpC,OAAO,KACL,oBACE;IACE,MAAM;IACN,QAAQ;KACN,MAAM;KACN,MAAM,kBAAkB,MAAM,KAAK;KACnC,YAAY;IACb;GACF,GACD,SACD,CACF;AAEH;EACD;AACD,QAAM,IAAI,MACR;CAEH,WAAU,MAAM,SAAS,SAAS,CAElC,WAAU,MAAM,SAAS,cACxB;MAAI,MAAM,MACR,OAAO,KACL,uBACE;GACE,MAAM;GACN,QAAQ;IACN,MAAM;IACN,MAAM,kBAAkB,MAAM,KAAK;IACnC,YAAY;GACb;EACF,GACD,MAAM,SACP,CACF;CACF,WACQ,MAAM,SAAS,kBAAkB,oBAC1C,OAAO,KAAK,MAAM,MAA8C;AAGpE,QAAO;AACR"}
|
package/dist/utils/tools.cjs
CHANGED
|
@@ -1,32 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.handleToolChoice = handleToolChoice;
|
|
1
|
+
|
|
2
|
+
//#region src/utils/tools.ts
|
|
4
3
|
function handleToolChoice(toolChoice) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
type: "auto",
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
else if (toolChoice === "none") {
|
|
19
|
-
return {
|
|
20
|
-
type: "none",
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
else if (typeof toolChoice === "string") {
|
|
24
|
-
return {
|
|
25
|
-
type: "tool",
|
|
26
|
-
name: toolChoice,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return toolChoice;
|
|
31
|
-
}
|
|
4
|
+
if (!toolChoice) return void 0;
|
|
5
|
+
else if (toolChoice === "any") return { type: "any" };
|
|
6
|
+
else if (toolChoice === "auto") return { type: "auto" };
|
|
7
|
+
else if (toolChoice === "none") return { type: "none" };
|
|
8
|
+
else if (typeof toolChoice === "string") return {
|
|
9
|
+
type: "tool",
|
|
10
|
+
name: toolChoice
|
|
11
|
+
};
|
|
12
|
+
else return toolChoice;
|
|
32
13
|
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.handleToolChoice = handleToolChoice;
|
|
17
|
+
//# sourceMappingURL=tools.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.cjs","names":["toolChoice?: AnthropicToolChoice"],"sources":["../../src/utils/tools.ts"],"sourcesContent":["import type { Anthropic } from \"@anthropic-ai/sdk\";\nimport { AnthropicToolChoice } from \"../types.js\";\n\nexport function handleToolChoice(\n toolChoice?: AnthropicToolChoice\n):\n | Anthropic.Messages.ToolChoiceAuto\n | Anthropic.Messages.ToolChoiceAny\n | Anthropic.Messages.ToolChoiceTool\n | Anthropic.Messages.ToolChoiceNone\n | undefined {\n if (!toolChoice) {\n return undefined;\n } else if (toolChoice === \"any\") {\n return {\n type: \"any\",\n };\n } else if (toolChoice === \"auto\") {\n return {\n type: \"auto\",\n };\n } else if (toolChoice === \"none\") {\n return {\n type: \"none\",\n };\n } else if (typeof toolChoice === \"string\") {\n return {\n type: \"tool\",\n name: toolChoice,\n };\n } else {\n return toolChoice;\n }\n}\n"],"mappings":";;AAGA,SAAgB,iBACdA,YAMY;AACZ,KAAI,CAAC,WACH,QAAO;UACE,eAAe,MACxB,QAAO,EACL,MAAM,MACP;UACQ,eAAe,OACxB,QAAO,EACL,MAAM,OACP;UACQ,eAAe,OACxB,QAAO,EACL,MAAM,OACP;UACQ,OAAO,eAAe,SAC/B,QAAO;EACL,MAAM;EACN,MAAM;CACP;KAED,QAAO;AAEV"}
|
package/dist/utils/tools.js
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type: "auto",
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
else if (toolChoice === "none") {
|
|
16
|
-
return {
|
|
17
|
-
type: "none",
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
else if (typeof toolChoice === "string") {
|
|
21
|
-
return {
|
|
22
|
-
type: "tool",
|
|
23
|
-
name: toolChoice,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return toolChoice;
|
|
28
|
-
}
|
|
1
|
+
//#region src/utils/tools.ts
|
|
2
|
+
function handleToolChoice(toolChoice) {
|
|
3
|
+
if (!toolChoice) return void 0;
|
|
4
|
+
else if (toolChoice === "any") return { type: "any" };
|
|
5
|
+
else if (toolChoice === "auto") return { type: "auto" };
|
|
6
|
+
else if (toolChoice === "none") return { type: "none" };
|
|
7
|
+
else if (typeof toolChoice === "string") return {
|
|
8
|
+
type: "tool",
|
|
9
|
+
name: toolChoice
|
|
10
|
+
};
|
|
11
|
+
else return toolChoice;
|
|
29
12
|
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { handleToolChoice };
|
|
16
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","names":["toolChoice?: AnthropicToolChoice"],"sources":["../../src/utils/tools.ts"],"sourcesContent":["import type { Anthropic } from \"@anthropic-ai/sdk\";\nimport { AnthropicToolChoice } from \"../types.js\";\n\nexport function handleToolChoice(\n toolChoice?: AnthropicToolChoice\n):\n | Anthropic.Messages.ToolChoiceAuto\n | Anthropic.Messages.ToolChoiceAny\n | Anthropic.Messages.ToolChoiceTool\n | Anthropic.Messages.ToolChoiceNone\n | undefined {\n if (!toolChoice) {\n return undefined;\n } else if (toolChoice === \"any\") {\n return {\n type: \"any\",\n };\n } else if (toolChoice === \"auto\") {\n return {\n type: \"auto\",\n };\n } else if (toolChoice === \"none\") {\n return {\n type: \"none\",\n };\n } else if (typeof toolChoice === \"string\") {\n return {\n type: \"tool\",\n name: toolChoice,\n };\n } else {\n return toolChoice;\n }\n}\n"],"mappings":";AAGA,SAAgB,iBACdA,YAMY;AACZ,KAAI,CAAC,WACH,QAAO;UACE,eAAe,MACxB,QAAO,EACL,MAAM,MACP;UACQ,eAAe,OACxB,QAAO,EACL,MAAM,OACP;UACQ,eAAe,OACxB,QAAO,EACL,MAAM,OACP;UACQ,OAAO,eAAe,SAC/B,QAAO;EACL,MAAM;EACN,MAAM;CACP;KAED,QAAO;AAEV"}
|
package/package.json
CHANGED
|
@@ -1,70 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Anthropic integrations for LangChain.js",
|
|
5
|
+
"author": "LangChain",
|
|
6
|
+
"license": "MIT",
|
|
5
7
|
"type": "module",
|
|
6
8
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
9
|
+
"node": ">=20"
|
|
8
10
|
},
|
|
9
|
-
"main": "./index.js",
|
|
10
|
-
"types": "./index.d.ts",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git@github.com:langchain-ai/langchainjs.git"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-anthropic/",
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "yarn turbo:command build:internal --filter=@langchain/anthropic",
|
|
18
|
-
"build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking --gen-maps",
|
|
19
|
-
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
20
|
-
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
21
|
-
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
22
|
-
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
|
|
23
|
-
"clean": "rm -rf .turbo dist/",
|
|
24
|
-
"prepack": "yarn build",
|
|
25
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
|
|
26
|
-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
27
|
-
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
28
|
-
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
29
|
-
"test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
30
|
-
"test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
31
|
-
"test:standard": "yarn test:standard:unit && yarn test:standard:int",
|
|
32
|
-
"format": "prettier --config .prettierrc --write \"src\"",
|
|
33
|
-
"format:check": "prettier --config .prettierrc --check \"src\""
|
|
34
|
-
},
|
|
35
|
-
"author": "LangChain",
|
|
36
|
-
"license": "MIT",
|
|
37
16
|
"dependencies": {
|
|
38
|
-
"@anthropic-ai/sdk": "^0.65.0"
|
|
39
|
-
"fast-xml-parser": "^4.4.1"
|
|
17
|
+
"@anthropic-ai/sdk": "^0.65.0"
|
|
40
18
|
},
|
|
41
19
|
"peerDependencies": {
|
|
42
|
-
"@langchain/core": "
|
|
20
|
+
"@langchain/core": "^1.0.0-alpha.6"
|
|
43
21
|
},
|
|
44
22
|
"devDependencies": {
|
|
45
23
|
"@anthropic-ai/vertex-sdk": "^0.11.5",
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"@langchain/standard-tests": "0.0.0",
|
|
50
|
-
"@swc/core": "^1.3.90",
|
|
51
|
-
"@swc/jest": "^0.2.29",
|
|
24
|
+
"@tsconfig/recommended": "^1.0.10",
|
|
25
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
26
|
+
"dotenv": "^17.2.1",
|
|
52
27
|
"dpdm": "^3.14.0",
|
|
53
|
-
"eslint": "^
|
|
54
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
55
|
-
"eslint-config-prettier": "^8.6.0",
|
|
56
|
-
"eslint-plugin-import": "^2.27.5",
|
|
57
|
-
"eslint-plugin-jest": "^27.6.0",
|
|
58
|
-
"eslint-plugin-no-instanceof": "^1.0.1",
|
|
59
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
60
|
-
"jest": "^29.5.0",
|
|
61
|
-
"jest-environment-node": "^29.6.4",
|
|
28
|
+
"eslint": "^9.34.0",
|
|
62
29
|
"prettier": "^2.8.3",
|
|
63
|
-
"release-it": "^
|
|
30
|
+
"release-it": "^19.0.4",
|
|
31
|
+
"release-it-pnpm": "^4.6.6",
|
|
64
32
|
"rimraf": "^5.0.1",
|
|
65
|
-
"ts-jest": "^29.1.0",
|
|
66
33
|
"typescript": "~5.8.3",
|
|
67
|
-
"
|
|
34
|
+
"vitest": "^3.2.4",
|
|
35
|
+
"zod": "3.25.76",
|
|
36
|
+
"@langchain/standard-tests": "0.0.0",
|
|
37
|
+
"@langchain/eslint": "0.1.0",
|
|
38
|
+
"@langchain/core": "1.0.0-alpha.6"
|
|
68
39
|
},
|
|
69
40
|
"publishConfig": {
|
|
70
41
|
"access": "public"
|
|
@@ -83,36 +54,39 @@
|
|
|
83
54
|
"embeddings",
|
|
84
55
|
"vectorstores"
|
|
85
56
|
],
|
|
57
|
+
"main": "./dist/index.js",
|
|
58
|
+
"types": "./dist/index.d.ts",
|
|
86
59
|
"exports": {
|
|
87
60
|
".": {
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"default": "./index.d.ts"
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/index.d.ts",
|
|
63
|
+
"default": "./dist/index.js"
|
|
92
64
|
},
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"./experimental": {
|
|
97
|
-
"types": {
|
|
98
|
-
"import": "./experimental.d.ts",
|
|
99
|
-
"require": "./experimental.d.cts",
|
|
100
|
-
"default": "./experimental.d.ts"
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/index.d.cts",
|
|
67
|
+
"default": "./dist/index.cjs"
|
|
101
68
|
},
|
|
102
|
-
"
|
|
103
|
-
"require": "./experimental.cjs"
|
|
69
|
+
"input": "./src/index.ts"
|
|
104
70
|
},
|
|
105
71
|
"./package.json": "./package.json"
|
|
106
72
|
},
|
|
107
73
|
"files": [
|
|
108
|
-
"dist/"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
|
|
118
|
-
|
|
74
|
+
"dist/"
|
|
75
|
+
],
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "pnpm --filter @langchain/build compile @langchain/anthropic",
|
|
78
|
+
"lint:eslint": "eslint --cache src/",
|
|
79
|
+
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
80
|
+
"lint": "pnpm lint:eslint && pnpm lint:dpdm",
|
|
81
|
+
"lint:fix": "pnpm lint:eslint --fix && pnpm lint:dpdm",
|
|
82
|
+
"clean": "rm -rf .turbo dist/",
|
|
83
|
+
"test": "vitest run",
|
|
84
|
+
"test:watch": "vitest",
|
|
85
|
+
"test:int": "vitest run --mode int",
|
|
86
|
+
"test:standard:unit": "vitest run --mode standard-unit",
|
|
87
|
+
"test:standard:int": "vitest run --mode standard-int",
|
|
88
|
+
"test:standard": "pnpm test:standard:unit && pnpm test:standard:int",
|
|
89
|
+
"format": "prettier --config .prettierrc --write \"src\"",
|
|
90
|
+
"format:check": "prettier --config .prettierrc --check \"src\""
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./tool_calling.cjs"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./tool_calling.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./tool_calling.js";
|