@langchain/core 1.0.0-alpha.6 → 1.0.0
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 +131 -0
- package/LICENSE +6 -6
- package/README.md +2 -23
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/manager.cjs +9 -64
- package/dist/callbacks/manager.cjs.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -23
- package/dist/callbacks/manager.d.cts.map +1 -1
- package/dist/callbacks/manager.d.ts +1 -23
- package/dist/callbacks/manager.d.ts.map +1 -1
- package/dist/callbacks/manager.js +10 -63
- package/dist/callbacks/manager.js.map +1 -1
- package/dist/chat_history.cjs +0 -4
- package/dist/chat_history.cjs.map +1 -1
- package/dist/chat_history.d.cts +1 -3
- package/dist/chat_history.d.cts.map +1 -1
- package/dist/chat_history.d.ts +1 -3
- package/dist/chat_history.d.ts.map +1 -1
- package/dist/chat_history.js +0 -4
- package/dist/chat_history.js.map +1 -1
- package/dist/document_loaders/base.cjs +1 -13
- package/dist/document_loaders/base.cjs.map +1 -1
- package/dist/document_loaders/base.d.cts +0 -9
- package/dist/document_loaders/base.d.cts.map +1 -1
- package/dist/document_loaders/base.d.ts +0 -9
- package/dist/document_loaders/base.d.ts.map +1 -1
- package/dist/document_loaders/base.js +1 -13
- package/dist/document_loaders/base.js.map +1 -1
- package/dist/document_loaders/langsmith.d.cts +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +0 -16
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +0 -16
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs +10 -83
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +21 -55
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +21 -55
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +11 -83
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.cjs +0 -56
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.d.cts +1 -43
- package/dist/language_models/llms.d.cts.map +1 -1
- package/dist/language_models/llms.d.ts +1 -43
- package/dist/language_models/llms.d.ts.map +1 -1
- package/dist/language_models/llms.js +0 -56
- package/dist/language_models/llms.js.map +1 -1
- package/dist/load/import_map.cjs +1 -7
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +1 -7
- package/dist/load/import_map.js.map +1 -1
- package/dist/messages/ai.cjs +4 -0
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +4 -0
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/block_translators/anthropic.cjs +191 -144
- package/dist/messages/block_translators/anthropic.cjs.map +1 -1
- package/dist/messages/block_translators/anthropic.js +191 -144
- package/dist/messages/block_translators/anthropic.js.map +1 -1
- package/dist/messages/block_translators/index.cjs +2 -2
- package/dist/messages/block_translators/index.cjs.map +1 -1
- package/dist/messages/block_translators/index.js +4 -4
- package/dist/messages/block_translators/index.js.map +1 -1
- package/dist/messages/block_translators/openai.cjs +78 -22
- package/dist/messages/block_translators/openai.cjs.map +1 -1
- package/dist/messages/block_translators/openai.js +78 -22
- package/dist/messages/block_translators/openai.js.map +1 -1
- package/dist/messages/content/tools.cjs +1 -5
- package/dist/messages/content/tools.cjs.map +1 -1
- package/dist/messages/content/tools.d.cts +1 -85
- package/dist/messages/content/tools.d.cts.map +1 -1
- package/dist/messages/content/tools.d.ts +1 -85
- package/dist/messages/content/tools.d.ts.map +1 -1
- package/dist/messages/content/tools.js +1 -5
- package/dist/messages/content/tools.js.map +1 -1
- package/dist/messages/metadata.cjs.map +1 -1
- package/dist/messages/metadata.d.cts +3 -0
- package/dist/messages/metadata.d.cts.map +1 -1
- package/dist/messages/metadata.d.ts +3 -0
- package/dist/messages/metadata.d.ts.map +1 -1
- package/dist/messages/metadata.js.map +1 -1
- package/dist/messages/tool.cjs +2 -0
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +2 -0
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +2 -0
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +2 -0
- package/dist/messages/tool.js.map +1 -1
- package/dist/output_parsers/json.cjs +5 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +2 -0
- package/dist/output_parsers/json.d.cts.map +1 -1
- package/dist/output_parsers/json.d.ts +2 -0
- package/dist/output_parsers/json.d.ts.map +1 -1
- package/dist/output_parsers/json.js +5 -0
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/prompts/base.cjs +0 -36
- package/dist/prompts/base.cjs.map +1 -1
- package/dist/prompts/base.d.cts +0 -16
- package/dist/prompts/base.d.cts.map +1 -1
- package/dist/prompts/base.d.ts +0 -16
- package/dist/prompts/base.d.ts.map +1 -1
- package/dist/prompts/base.js +0 -36
- package/dist/prompts/base.js.map +1 -1
- package/dist/prompts/chat.cjs +1 -5
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +1 -4
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +1 -4
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +1 -5
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/dict.d.cts +1 -1
- package/dist/prompts/dict.d.ts +1 -1
- package/dist/prompts/few_shot.d.cts +2 -2
- package/dist/prompts/few_shot.d.ts +2 -2
- package/dist/prompts/image.d.cts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/index.d.cts +2 -2
- package/dist/prompts/index.d.ts +2 -2
- package/dist/prompts/pipeline.d.cts +1 -1
- package/dist/prompts/pipeline.d.ts +1 -1
- package/dist/prompts/prompt.d.cts +2 -2
- package/dist/prompts/prompt.d.ts +2 -2
- package/dist/retrievers/index.cjs +3 -18
- package/dist/retrievers/index.cjs.map +1 -1
- package/dist/retrievers/index.d.cts +2 -27
- package/dist/retrievers/index.d.cts.map +1 -1
- package/dist/retrievers/index.d.ts +2 -27
- package/dist/retrievers/index.d.ts.map +1 -1
- package/dist/retrievers/index.js +3 -18
- package/dist/retrievers/index.js.map +1 -1
- package/dist/runnables/base.cjs +24 -63
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +10 -39
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +10 -39
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +24 -63
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/graph.cjs +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +2 -2
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs +1 -10
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +1 -10
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/history.cjs +1 -1
- package/dist/runnables/history.cjs.map +1 -1
- package/dist/runnables/history.d.cts +2 -2
- package/dist/runnables/history.d.cts.map +1 -1
- package/dist/runnables/history.d.ts +2 -2
- package/dist/runnables/history.d.ts.map +1 -1
- package/dist/runnables/history.js +1 -1
- package/dist/runnables/history.js.map +1 -1
- package/dist/stores.cjs.map +1 -1
- package/dist/stores.d.cts +3 -29
- package/dist/stores.d.cts.map +1 -1
- package/dist/stores.d.ts +3 -29
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js.map +1 -1
- package/dist/tools/index.cjs +12 -4
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +12 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +4 -0
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +4 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tracers/base.cjs +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.js +2 -2
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/log_stream.d.cts +1 -1
- package/dist/tracers/log_stream.d.ts +1 -1
- package/dist/tracers/tracer_langchain.cjs +1 -0
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.d.cts +2 -2
- package/dist/tracers/tracer_langchain.js +1 -0
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/utils/env.cjs +1 -9
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.d.cts +2 -6
- package/dist/utils/env.d.cts.map +1 -1
- package/dist/utils/env.d.ts +2 -6
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +2 -9
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/testing/message_history.cjs +1 -1
- package/dist/utils/testing/message_history.cjs.map +1 -1
- package/dist/utils/testing/message_history.d.cts +1 -1
- package/dist/utils/testing/message_history.d.cts.map +1 -1
- package/dist/utils/testing/message_history.d.ts +1 -1
- package/dist/utils/testing/message_history.d.ts.map +1 -1
- package/dist/utils/testing/message_history.js +1 -1
- package/dist/utils/testing/message_history.js.map +1 -1
- package/dist/utils/types/index.cjs +6 -0
- package/dist/utils/types/index.d.cts +2 -2
- package/dist/utils/types/index.d.ts +2 -2
- package/dist/utils/types/index.js +5 -2
- package/dist/utils/types/zod.cjs +23 -0
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.d.cts +11 -1
- package/dist/utils/types/zod.d.cts.map +1 -1
- package/dist/utils/types/zod.d.ts +11 -1
- package/dist/utils/types/zod.d.ts.map +1 -1
- package/dist/utils/types/zod.js +21 -1
- package/dist/utils/types/zod.js.map +1 -1
- package/package.json +121 -154
- package/dist/runnables/remote.cjs +0 -399
- package/dist/runnables/remote.cjs.map +0 -1
- package/dist/runnables/remote.d.cts +0 -73
- package/dist/runnables/remote.d.cts.map +0 -1
- package/dist/runnables/remote.d.ts +0 -73
- package/dist/runnables/remote.d.ts.map +0 -1
- package/dist/runnables/remote.js +0 -393
- package/dist/runnables/remote.js.map +0 -1
- package/dist/tracers/initialize.cjs +0 -46
- package/dist/tracers/initialize.cjs.map +0 -1
- package/dist/tracers/initialize.d.cts +0 -26
- package/dist/tracers/initialize.d.cts.map +0 -1
- package/dist/tracers/initialize.d.ts +0 -26
- package/dist/tracers/initialize.d.ts.map +0 -1
- package/dist/tracers/initialize.js +0 -39
- package/dist/tracers/initialize.js.map +0 -1
- package/dist/tracers/tracer_langchain_v1.cjs +0 -168
- package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
- package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
- package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
- package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
- package/dist/tracers/tracer_langchain_v1.js +0 -162
- package/dist/tracers/tracer_langchain_v1.js.map +0 -1
|
@@ -92,39 +92,40 @@ function convertAnthropicAnnotation(citation) {
|
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
94
|
function convertToV1FromAnthropicContentBlock(block) {
|
|
95
|
-
if (_isContentBlock(block, "document") && _isObject(block.source) && "type" in block.source)
|
|
96
|
-
type
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
type
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
type
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
type
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
else if (_isContentBlock(block, "image") && _isObject(block.source) && "type" in block.source)
|
|
115
|
-
type
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
type
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
type
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
95
|
+
if (_isContentBlock(block, "document") && _isObject(block.source) && "type" in block.source) {
|
|
96
|
+
if (block.source.type === "base64" && _isString(block.source.media_type) && _isString(block.source.data)) return {
|
|
97
|
+
type: "file",
|
|
98
|
+
mimeType: block.source.media_type,
|
|
99
|
+
data: block.source.data
|
|
100
|
+
};
|
|
101
|
+
else if (block.source.type === "url" && _isString(block.source.url)) return {
|
|
102
|
+
type: "file",
|
|
103
|
+
url: block.source.url
|
|
104
|
+
};
|
|
105
|
+
else if (block.source.type === "file" && _isString(block.source.file_id)) return {
|
|
106
|
+
type: "file",
|
|
107
|
+
fileId: block.source.file_id
|
|
108
|
+
};
|
|
109
|
+
else if (block.source.type === "text" && _isString(block.source.data)) return {
|
|
110
|
+
type: "file",
|
|
111
|
+
mimeType: String(block.source.media_type ?? "text/plain"),
|
|
112
|
+
data: block.source.data
|
|
113
|
+
};
|
|
114
|
+
} else if (_isContentBlock(block, "image") && _isObject(block.source) && "type" in block.source) {
|
|
115
|
+
if (block.source.type === "base64" && _isString(block.source.media_type) && _isString(block.source.data)) return {
|
|
116
|
+
type: "image",
|
|
117
|
+
mimeType: block.source.media_type,
|
|
118
|
+
data: block.source.data
|
|
119
|
+
};
|
|
120
|
+
else if (block.source.type === "url" && _isString(block.source.url)) return {
|
|
121
|
+
type: "image",
|
|
122
|
+
url: block.source.url
|
|
123
|
+
};
|
|
124
|
+
else if (block.source.type === "file" && _isString(block.source.file_id)) return {
|
|
125
|
+
type: "image",
|
|
126
|
+
fileId: block.source.file_id
|
|
127
|
+
};
|
|
128
|
+
}
|
|
128
129
|
return void 0;
|
|
129
130
|
}
|
|
130
131
|
/**
|
|
@@ -180,133 +181,179 @@ function convertToV1FromAnthropicMessage(message) {
|
|
|
180
181
|
type: "text",
|
|
181
182
|
text: message.content
|
|
182
183
|
}] : message.content;
|
|
183
|
-
for (const block of content)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
184
|
+
for (const block of content) {
|
|
185
|
+
if (_isContentBlock(block, "text") && _isString(block.text)) {
|
|
186
|
+
const { text, citations,...rest } = block;
|
|
187
|
+
if (_isArray(citations) && citations.length) {
|
|
188
|
+
const _citations = citations.reduce((acc, item) => {
|
|
189
|
+
const citation = convertAnthropicAnnotation(item);
|
|
190
|
+
if (citation) return [...acc, citation];
|
|
191
|
+
return acc;
|
|
192
|
+
}, []);
|
|
193
|
+
yield {
|
|
194
|
+
...rest,
|
|
195
|
+
type: "text",
|
|
196
|
+
text,
|
|
197
|
+
annotations: _citations
|
|
198
|
+
};
|
|
199
|
+
continue;
|
|
200
|
+
} else {
|
|
201
|
+
yield {
|
|
202
|
+
...rest,
|
|
203
|
+
type: "text",
|
|
204
|
+
text
|
|
205
|
+
};
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
} else if (_isContentBlock(block, "thinking") && _isString(block.thinking)) {
|
|
209
|
+
const { thinking, signature,...rest } = block;
|
|
210
|
+
yield {
|
|
211
|
+
...rest,
|
|
212
|
+
type: "reasoning",
|
|
213
|
+
reasoning: thinking,
|
|
214
|
+
signature
|
|
215
|
+
};
|
|
216
|
+
continue;
|
|
217
|
+
} else if (_isContentBlock(block, "redacted_thinking")) {
|
|
218
|
+
yield {
|
|
219
|
+
type: "non_standard",
|
|
220
|
+
value: block
|
|
221
|
+
};
|
|
222
|
+
continue;
|
|
223
|
+
} else if (_isContentBlock(block, "tool_use") && _isString(block.name) && _isString(block.id)) {
|
|
224
|
+
yield {
|
|
225
|
+
type: "tool_call",
|
|
226
|
+
id: block.id,
|
|
227
|
+
name: block.name,
|
|
228
|
+
args: block.input
|
|
229
|
+
};
|
|
230
|
+
continue;
|
|
231
|
+
} else if (_isContentBlock(block, "input_json_delta")) {
|
|
232
|
+
if (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {
|
|
233
|
+
const tool_call_chunk = message.tool_call_chunks[0];
|
|
234
|
+
yield {
|
|
235
|
+
type: "tool_call_chunk",
|
|
236
|
+
id: tool_call_chunk.id,
|
|
237
|
+
name: tool_call_chunk.name,
|
|
238
|
+
args: tool_call_chunk.args,
|
|
239
|
+
index: tool_call_chunk.index
|
|
240
|
+
};
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
} else if (_isContentBlock(block, "server_tool_use") && _isString(block.name) && _isString(block.id)) {
|
|
244
|
+
const { name, id } = block;
|
|
245
|
+
if (name === "web_search") {
|
|
246
|
+
const query = iife(() => {
|
|
247
|
+
if (typeof block.input === "string") return block.input;
|
|
248
|
+
else if (_isObject(block.input) && _isString(block.input.query)) return block.input.query;
|
|
249
|
+
else if (_isString(block.partial_json)) {
|
|
250
|
+
const json = safeParseJson(block.partial_json);
|
|
251
|
+
if (json?.query) return json.query;
|
|
252
|
+
}
|
|
253
|
+
return "";
|
|
254
|
+
});
|
|
255
|
+
yield {
|
|
256
|
+
id,
|
|
257
|
+
type: "server_tool_call",
|
|
258
|
+
name: "web_search",
|
|
259
|
+
args: { query }
|
|
260
|
+
};
|
|
261
|
+
continue;
|
|
262
|
+
} else if (block.name === "code_execution") {
|
|
263
|
+
const code = iife(() => {
|
|
264
|
+
if (typeof block.input === "string") return block.input;
|
|
265
|
+
else if (_isObject(block.input) && _isString(block.input.code)) return block.input.code;
|
|
266
|
+
else if (_isString(block.partial_json)) {
|
|
267
|
+
const json = safeParseJson(block.partial_json);
|
|
268
|
+
if (json?.code) return json.code;
|
|
269
|
+
}
|
|
270
|
+
return "";
|
|
271
|
+
});
|
|
272
|
+
yield {
|
|
273
|
+
id,
|
|
274
|
+
type: "server_tool_call",
|
|
275
|
+
name: "code_execution",
|
|
276
|
+
args: { code }
|
|
277
|
+
};
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
} else if (_isContentBlock(block, "web_search_tool_result") && _isString(block.tool_use_id) && _isArray(block.content)) {
|
|
281
|
+
const { content: content$1, tool_use_id } = block;
|
|
282
|
+
const urls = content$1.reduce((acc, content$2) => {
|
|
283
|
+
if (_isContentBlock(content$2, "web_search_result")) return [...acc, content$2.url];
|
|
189
284
|
return acc;
|
|
190
285
|
}, []);
|
|
191
286
|
yield {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
287
|
+
type: "server_tool_call_result",
|
|
288
|
+
name: "web_search",
|
|
289
|
+
toolCallId: tool_use_id,
|
|
290
|
+
status: "success",
|
|
291
|
+
output: { urls }
|
|
196
292
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
type: "text",
|
|
200
|
-
text
|
|
201
|
-
};
|
|
202
|
-
} else if (_isContentBlock(block, "thinking") && _isString(block.thinking)) {
|
|
203
|
-
const { thinking, signature,...rest } = block;
|
|
204
|
-
yield {
|
|
205
|
-
...rest,
|
|
206
|
-
type: "reasoning",
|
|
207
|
-
reasoning: thinking,
|
|
208
|
-
signature
|
|
209
|
-
};
|
|
210
|
-
} else if (_isContentBlock(block, "redacted_thinking")) continue;
|
|
211
|
-
else if (_isContentBlock(block, "tool_use") && _isString(block.name) && _isString(block.id)) yield {
|
|
212
|
-
type: "tool_call",
|
|
213
|
-
id: block.id,
|
|
214
|
-
name: block.name,
|
|
215
|
-
args: block.input
|
|
216
|
-
};
|
|
217
|
-
else if (_isContentBlock(block, "input_json_delta")) {
|
|
218
|
-
if (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {
|
|
219
|
-
const tool_call_chunk = message.tool_call_chunks[0];
|
|
293
|
+
continue;
|
|
294
|
+
} else if (_isContentBlock(block, "code_execution_tool_result") && _isString(block.tool_use_id) && _isObject(block.content)) {
|
|
220
295
|
yield {
|
|
221
|
-
type: "
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
296
|
+
type: "server_tool_call_result",
|
|
297
|
+
name: "code_execution",
|
|
298
|
+
toolCallId: block.tool_use_id,
|
|
299
|
+
status: "success",
|
|
300
|
+
output: block.content
|
|
226
301
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const { name, id } = block;
|
|
230
|
-
if (name === "web_search") {
|
|
231
|
-
const query = iife(() => {
|
|
232
|
-
if (typeof block.input === "string") return block.input;
|
|
233
|
-
else if (_isObject(block.input) && _isString(block.input.query)) return block.input.query;
|
|
234
|
-
else if (_isString(block.partial_json)) {
|
|
235
|
-
const json = safeParseJson(block.partial_json);
|
|
236
|
-
if (json?.query) return json.query;
|
|
237
|
-
}
|
|
238
|
-
return "";
|
|
239
|
-
});
|
|
302
|
+
continue;
|
|
303
|
+
} else if (_isContentBlock(block, "mcp_tool_use")) {
|
|
240
304
|
yield {
|
|
241
|
-
id,
|
|
242
|
-
type: "
|
|
243
|
-
|
|
305
|
+
id: block.id,
|
|
306
|
+
type: "server_tool_call",
|
|
307
|
+
name: "mcp_tool_use",
|
|
308
|
+
args: block.input
|
|
244
309
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (typeof block.input === "string") return block.input;
|
|
248
|
-
else if (_isObject(block.input) && _isString(block.input.code)) return block.input.code;
|
|
249
|
-
else if (_isString(block.partial_json)) {
|
|
250
|
-
const json = safeParseJson(block.partial_json);
|
|
251
|
-
if (json?.code) return json.code;
|
|
252
|
-
}
|
|
253
|
-
return "";
|
|
254
|
-
});
|
|
310
|
+
continue;
|
|
311
|
+
} else if (_isContentBlock(block, "mcp_tool_result") && _isString(block.tool_use_id) && _isObject(block.content)) {
|
|
255
312
|
yield {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
313
|
+
type: "server_tool_call_result",
|
|
314
|
+
name: "mcp_tool_use",
|
|
315
|
+
toolCallId: block.tool_use_id,
|
|
316
|
+
status: "success",
|
|
317
|
+
output: block.content
|
|
259
318
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
fileIds
|
|
288
|
-
}];
|
|
319
|
+
continue;
|
|
320
|
+
} else if (_isContentBlock(block, "container_upload")) {
|
|
321
|
+
yield {
|
|
322
|
+
type: "server_tool_call",
|
|
323
|
+
name: "container_upload",
|
|
324
|
+
args: block.input
|
|
325
|
+
};
|
|
326
|
+
continue;
|
|
327
|
+
} else if (_isContentBlock(block, "search_result")) {
|
|
328
|
+
yield {
|
|
329
|
+
id: block.id,
|
|
330
|
+
type: "non_standard",
|
|
331
|
+
value: block
|
|
332
|
+
};
|
|
333
|
+
continue;
|
|
334
|
+
} else if (_isContentBlock(block, "tool_result")) {
|
|
335
|
+
yield {
|
|
336
|
+
id: block.id,
|
|
337
|
+
type: "non_standard",
|
|
338
|
+
value: block
|
|
339
|
+
};
|
|
340
|
+
continue;
|
|
341
|
+
} else {
|
|
342
|
+
const stdBlock = convertToV1FromAnthropicContentBlock(block);
|
|
343
|
+
if (stdBlock) {
|
|
344
|
+
yield stdBlock;
|
|
345
|
+
continue;
|
|
289
346
|
}
|
|
290
|
-
|
|
291
|
-
});
|
|
347
|
+
}
|
|
292
348
|
yield {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
output
|
|
349
|
+
type: "non_standard",
|
|
350
|
+
value: block
|
|
296
351
|
};
|
|
297
|
-
} else if (block.type === "mcp_tool_use") continue;
|
|
298
|
-
else if (block.type === "mcp_tool_result") continue;
|
|
299
|
-
else if (block.type === "container_upload") continue;
|
|
300
|
-
else if (block.type === "search_result") continue;
|
|
301
|
-
else if (block.type === "tool_result") continue;
|
|
302
|
-
else {
|
|
303
|
-
const stdBlock = convertToV1FromAnthropicContentBlock(block);
|
|
304
|
-
if (stdBlock) yield stdBlock;
|
|
305
352
|
}
|
|
306
353
|
}
|
|
307
354
|
return Array.from(iterateContent());
|
|
308
355
|
}
|
|
309
|
-
const
|
|
356
|
+
const ChatAnthropicTranslator = {
|
|
310
357
|
translateContent: convertToV1FromAnthropicMessage,
|
|
311
358
|
translateContentChunk: convertToV1FromAnthropicMessage
|
|
312
359
|
};
|
|
@@ -315,5 +362,5 @@ function _isAIMessageChunk(message) {
|
|
|
315
362
|
}
|
|
316
363
|
|
|
317
364
|
//#endregion
|
|
318
|
-
export {
|
|
365
|
+
export { ChatAnthropicTranslator, convertToV1FromAnthropicInput };
|
|
319
366
|
//# sourceMappingURL=anthropic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","names":["citation: ContentBlock","block: ContentBlock","content: Array<ContentBlock>","message: AIMessage","content","anthropicTranslator: StandardContentBlockTranslator","message: unknown"],"sources":["../../../src/messages/block_translators/anthropic.ts"],"sourcesContent":["import type { StandardContentBlockTranslator } from \"./index.js\";\nimport type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { BaseMessage, BaseMessageChunk } from \"../base.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n safeParseJson,\n iife,\n} from \"./utils.js\";\n\nfunction convertAnthropicAnnotation(\n citation: ContentBlock\n): ContentBlock.Citation | undefined {\n if (\n citation.type === \"char_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_char_index) &&\n _isNumber(citation.end_char_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_char_index,\n end_char_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"char\",\n title: document_title ?? undefined,\n startIndex: start_char_index,\n endIndex: end_char_index,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"page_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_page_number) &&\n _isNumber(citation.end_page_number) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_page_number,\n end_page_number,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"page\",\n title: document_title ?? undefined,\n startIndex: start_page_number,\n endIndex: end_page_number,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"content_block_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_block_index) &&\n _isNumber(citation.end_block_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_block_index,\n end_block_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"block\",\n title: document_title ?? undefined,\n startIndex: start_block_index,\n endIndex: end_block_index,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"web_search_result_location\" &&\n _isString(citation.url) &&\n _isString(citation.title) &&\n _isString(citation.encrypted_index) &&\n _isString(citation.cited_text)\n ) {\n const { url, title, encrypted_index, cited_text, ...rest } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"url\",\n url,\n title,\n startIndex: Number(encrypted_index),\n endIndex: Number(encrypted_index),\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"search_result_location\" &&\n _isString(citation.source) &&\n _isString(citation.title) &&\n _isNumber(citation.start_block_index) &&\n _isNumber(citation.end_block_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n source,\n title,\n start_block_index,\n end_block_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"search\",\n url: source,\n title: title ?? undefined,\n startIndex: start_block_index,\n endIndex: end_block_index,\n citedText: cited_text,\n };\n }\n return undefined;\n}\n\n/**\n * Converts an Anthropic content block to a standard V1 content block.\n *\n * This function handles the conversion of Anthropic-specific content blocks\n * (document and image blocks) to the standardized V1 format. It supports\n * various source types including base64 data, URLs, file IDs, and text data.\n *\n * @param block - The Anthropic content block to convert\n * @returns A standard V1 content block if conversion is successful, undefined otherwise\n *\n * @example\n * ```typescript\n * const anthropicBlock = {\n * type: \"image\",\n * source: {\n * type: \"base64\",\n * media_type: \"image/png\",\n * data: \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==\"\n * }\n * };\n *\n * const standardBlock = convertToV1FromAnthropicContentBlock(anthropicBlock);\n * // Returns: { type: \"image\", mimeType: \"image/png\", data: \"...\" }\n * ```\n */\nexport function convertToV1FromAnthropicContentBlock(\n block: ContentBlock\n): ContentBlock.Standard | undefined {\n if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.source) &&\n \"type\" in block.source\n ) {\n if (\n block.source.type === \"base64\" &&\n _isString(block.source.media_type) &&\n _isString(block.source.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.source.media_type,\n data: block.source.data,\n };\n } else if (block.source.type === \"url\" && _isString(block.source.url)) {\n return {\n type: \"file\",\n url: block.source.url,\n };\n } else if (\n block.source.type === \"file\" &&\n _isString(block.source.file_id)\n ) {\n return {\n type: \"file\",\n fileId: block.source.file_id,\n };\n } else if (block.source.type === \"text\" && _isString(block.source.data)) {\n return {\n type: \"file\",\n mimeType: String(block.source.media_type ?? \"text/plain\"),\n data: block.source.data,\n };\n } else {\n return block as ContentBlock.Standard;\n }\n } else if (\n _isContentBlock(block, \"image\") &&\n _isObject(block.source) &&\n \"type\" in block.source\n ) {\n if (\n block.source.type === \"base64\" &&\n _isString(block.source.media_type) &&\n _isString(block.source.data)\n ) {\n return {\n type: \"image\",\n mimeType: block.source.media_type,\n data: block.source.data,\n };\n } else if (block.source.type === \"url\" && _isString(block.source.url)) {\n return {\n type: \"image\",\n url: block.source.url,\n };\n } else if (\n block.source.type === \"file\" &&\n _isString(block.source.file_id)\n ) {\n return {\n type: \"image\",\n fileId: block.source.file_id,\n };\n } else {\n return block as ContentBlock.Standard;\n }\n }\n return undefined;\n}\n\n/**\n * Converts an array of content blocks from Anthropic format to v1 standard format.\n *\n * This function processes each content block in the input array, attempting to convert\n * Anthropic-specific block formats (like image blocks with source objects, document blocks, etc.)\n * to the standardized v1 content block format. If a block cannot be converted, it is\n * passed through as-is with a type assertion to ContentBlock.Standard.\n *\n * @param content - Array of content blocks in Anthropic format to be converted\n * @returns Array of content blocks in v1 standard format\n */\nexport function convertToV1FromAnthropicInput(\n content: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n for (const block of content) {\n const stdBlock = convertToV1FromAnthropicContentBlock(block);\n if (stdBlock) {\n yield stdBlock;\n } else {\n yield block as ContentBlock.Standard;\n }\n }\n }\n return Array.from(iterateContent());\n}\n\ntype AnthropicCodeExecutionToolResult = {\n type: \"code_execution_tool_result\";\n tool_use_id: string;\n content:\n | {\n // BetaCodeExecutionToolResultError\n type: \"code_execution_tool_result_error\";\n error_code: string;\n }\n | {\n // BetaCodeExecutionResultBlock\n type: \"code_execution_result\";\n stderr: string;\n stdout: string;\n return_code: number;\n content: {\n // BetaCodeExecutionOutputBlock\n type: \"code_execution_output\";\n file_id: string;\n }[];\n };\n};\n\n/**\n * Converts an Anthropic AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing Anthropic-specific content blocks\n * and converts them to the standardized v1 content block format.\n *\n * @param message - The AI message containing Anthropic-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"thinking\", text: \"Let me think about this...\" },\n * { type: \"tool_use\", id: \"123\", name: \"calculator\", input: { a: 1, b: 2 } }\n * ]);\n *\n * const standardBlocks = convertToV1FromAnthropicMessage(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromAnthropicMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n // TextBlock\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n const { text, citations, ...rest } = block;\n if (_isArray(citations) && citations.length) {\n const _citations = citations.reduce<ContentBlock.Citation[]>(\n (acc, item) => {\n const citation = convertAnthropicAnnotation(item as ContentBlock);\n if (citation) {\n return [...acc, citation];\n }\n return acc;\n },\n []\n );\n yield {\n ...rest,\n type: \"text\",\n text,\n annotations: _citations,\n };\n } else {\n yield {\n ...rest,\n type: \"text\",\n text,\n };\n }\n }\n // ThinkingBlock\n else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n const { thinking, signature, ...rest } = block;\n yield {\n ...rest,\n type: \"reasoning\",\n reasoning: thinking,\n signature,\n };\n }\n // RedactedThinkingBlock\n else if (_isContentBlock(block, \"redacted_thinking\")) {\n continue;\n }\n // ToolUseBlock\n else if (\n _isContentBlock(block, \"tool_use\") &&\n _isString(block.name) &&\n _isString(block.id)\n ) {\n yield {\n type: \"tool_call\",\n id: block.id,\n name: block.name,\n args: block.input,\n };\n }\n // message chunks can have input_json_delta contents\n else if (_isContentBlock(block, \"input_json_delta\")) {\n if (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {\n const tool_call_chunk = message.tool_call_chunks[0];\n yield {\n type: \"tool_call_chunk\",\n id: tool_call_chunk.id,\n name: tool_call_chunk.name,\n args: tool_call_chunk.args,\n index: tool_call_chunk.index,\n };\n }\n // TODO: implement\n }\n // ServerToolUseBlock\n else if (\n _isContentBlock(block, \"server_tool_use\") &&\n _isString(block.name) &&\n _isString(block.id)\n ) {\n const { name, id } = block;\n if (name === \"web_search\") {\n const query = iife(() => {\n if (typeof block.input === \"string\") {\n return block.input;\n } else if (_isObject(block.input) && _isString(block.input.query)) {\n return block.input.query;\n } else if (_isString(block.partial_json)) {\n const json = safeParseJson<{ query?: string }>(\n block.partial_json\n );\n if (json?.query) {\n return json.query;\n }\n }\n return \"\";\n });\n yield {\n id,\n type: \"web_search_call\",\n query,\n };\n } else if (block.name === \"code_execution\") {\n const code = iife(() => {\n if (typeof block.input === \"string\") {\n return block.input;\n } else if (_isObject(block.input) && _isString(block.input.code)) {\n return block.input.code;\n } else if (_isString(block.partial_json)) {\n const json = safeParseJson<{ code?: string }>(block.partial_json);\n if (json?.code) {\n return json.code;\n }\n }\n return \"\";\n });\n yield {\n id,\n type: \"code_interpreter_call\",\n code,\n };\n }\n }\n // WebSearchToolResultBlock\n else if (\n _isContentBlock(block, \"web_search_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isArray(block.content)\n ) {\n const { content, tool_use_id } = block;\n const urls = content.reduce<string[]>((acc, content) => {\n if (_isContentBlock(content, \"web_search_result\")) {\n return [...acc, content.url as string];\n }\n return acc;\n }, []);\n yield {\n id: tool_use_id,\n type: \"web_search_result\",\n urls,\n };\n }\n // CodeExecutionToolResultBlock\n else if (\n _isContentBlock(block, \"code_execution_tool_result\") &&\n _isString(block.tool_use_id)\n ) {\n // We just make a type assertion here instead of deep checking every property\n // since `code_execution_tool_result` is an anthropic only block\n const { content, tool_use_id } =\n block as AnthropicCodeExecutionToolResult;\n const output = iife(() => {\n if (content.type === \"code_execution_tool_result_error\") {\n return [\n {\n type: \"code_interpreter_output\" as const,\n returnCode: 1,\n stderr: content.error_code,\n },\n ];\n }\n if (content.type === \"code_execution_result\") {\n const fileIds = Array.isArray(content.content)\n ? content.content\n .filter((content) => content.type === \"code_execution_output\")\n .map((content) => content.file_id)\n : [];\n return [\n {\n type: \"code_interpreter_output\" as const,\n returnCode: content.return_code ?? 0,\n stderr: content.stderr,\n stdout: content.stdout,\n fileIds,\n },\n ];\n }\n return [];\n });\n yield {\n id: tool_use_id,\n type: \"code_interpreter_result\",\n output,\n };\n }\n // MCPToolUseBlock\n else if (block.type === \"mcp_tool_use\") {\n continue;\n }\n // MCPToolResultBlock\n else if (block.type === \"mcp_tool_result\") {\n continue;\n }\n // ContainerUploadBlock\n else if (block.type === \"container_upload\") {\n continue;\n }\n // SearchResultBlockParam\n else if (block.type === \"search_result\") {\n continue;\n }\n // ToolResultBlockParam\n else if (block.type === \"tool_result\") {\n // TODO: Implement\n continue;\n } else {\n // For all other blocks, we try to convert them to a standard block\n const stdBlock = convertToV1FromAnthropicContentBlock(block);\n if (stdBlock) {\n yield stdBlock;\n } else {\n // TODO: non standard?\n }\n }\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const anthropicTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromAnthropicMessage,\n translateContentChunk: convertToV1FromAnthropicMessage,\n};\n\nfunction _isAIMessageChunk(message: unknown): message is AIMessageChunk {\n return (\n typeof (message as BaseMessage)?._getType === \"function\" &&\n typeof (message as BaseMessageChunk).concat === \"function\" &&\n (message as BaseMessageChunk)._getType() === \"ai\"\n );\n}\n"],"mappings":";;;AAcA,SAAS,2BACPA,UACmC;AACnC,KACE,SAAS,SAAS,mBAClB,UAAU,SAAS,eAAe,IAClC,UAAU,SAAS,iBAAiB,IACpC,UAAU,SAAS,eAAe,IAClC,UAAU,SAAS,WAAW,EAC9B;EACA,MAAM,EACJ,gBACA,kBACA,gBACA,WACA,GAAG,MACJ,GAAG;AACJ,SAAO;GACL,GAAG;GACH,MAAM;GACN,QAAQ;GACR,OAAO,kBAAkB;GACzB,YAAY;GACZ,UAAU;GACV,WAAW;EACZ;CACF;AACD,KACE,SAAS,SAAS,mBAClB,UAAU,SAAS,eAAe,IAClC,UAAU,SAAS,kBAAkB,IACrC,UAAU,SAAS,gBAAgB,IACnC,UAAU,SAAS,WAAW,EAC9B;EACA,MAAM,EACJ,gBACA,mBACA,iBACA,W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,EAC5B;GAGA,MAAM,EAAE,oBAAS,aAAa,GAC5B;GACF,MAAM,SAAS,KAAK,MAAM;AACxB,QAAIA,UAAQ,SAAS,mCACnB,QAAO,CACL;KACE,MAAM;KACN,YAAY;KACZ,QAAQA,UAAQ;IACjB,CACF;AAEH,QAAIA,UAAQ,SAAS,yBAAyB;KAC5C,MAAM,UAAU,MAAM,QAAQA,UAAQ,QAAQ,GAC1CA,UAAQ,QACL,OAAO,CAACA,cAAYA,UAAQ,SAAS,wBAAwB,CAC7D,IAAI,CAACA,cAAYA,UAAQ,QAAQ,GACpC,CAAE;AACN,YAAO,CACL;MACE,MAAM;MACN,YAAYA,UAAQ,eAAe;MACnC,QAAQA,UAAQ;MAChB,QAAQA,UAAQ;MAChB;KACD,CACF;IACF;AACD,WAAO,CAAE;GACV,EAAC;GACF,MAAM;IACJ,IAAI;IACJ,MAAM;IACN;GACD;EACF,WAEQ,MAAM,SAAS,eACtB;WAGO,MAAM,SAAS,kBACtB;WAGO,MAAM,SAAS,mBACtB;WAGO,MAAM,SAAS,gBACtB;WAGO,MAAM,SAAS,cAEtB;OACK;GAEL,MAAM,WAAW,qCAAqC,MAAM;AAC5D,OAAI,UACF,MAAM;EAIT;CAEJ;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,sBAAsD;CACjE,kBAAkB;CAClB,uBAAuB;AACxB;AAED,SAAS,kBAAkBC,SAA6C;AACtE,QACE,OAAQ,SAAyB,aAAa,cAC9C,OAAQ,QAA6B,WAAW,cAC/C,QAA6B,UAAU,KAAK;AAEhD"}
|
|
1
|
+
{"version":3,"file":"anthropic.js","names":["citation: ContentBlock","block: ContentBlock","content: Array<ContentBlock>","message: AIMessage","content","ChatAnthropicTranslator: StandardContentBlockTranslator","message: unknown"],"sources":["../../../src/messages/block_translators/anthropic.ts"],"sourcesContent":["import type { StandardContentBlockTranslator } from \"./index.js\";\nimport type { ContentBlock } from \"../content/index.js\";\nimport type { AIMessageChunk, AIMessage } from \"../ai.js\";\nimport type { BaseMessage, BaseMessageChunk } from \"../base.js\";\nimport {\n _isArray,\n _isContentBlock,\n _isNumber,\n _isObject,\n _isString,\n safeParseJson,\n iife,\n} from \"./utils.js\";\n\nfunction convertAnthropicAnnotation(\n citation: ContentBlock\n): ContentBlock.Citation | undefined {\n if (\n citation.type === \"char_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_char_index) &&\n _isNumber(citation.end_char_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_char_index,\n end_char_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"char\",\n title: document_title ?? undefined,\n startIndex: start_char_index,\n endIndex: end_char_index,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"page_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_page_number) &&\n _isNumber(citation.end_page_number) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_page_number,\n end_page_number,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"page\",\n title: document_title ?? undefined,\n startIndex: start_page_number,\n endIndex: end_page_number,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"content_block_location\" &&\n _isString(citation.document_title) &&\n _isNumber(citation.start_block_index) &&\n _isNumber(citation.end_block_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n document_title,\n start_block_index,\n end_block_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"block\",\n title: document_title ?? undefined,\n startIndex: start_block_index,\n endIndex: end_block_index,\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"web_search_result_location\" &&\n _isString(citation.url) &&\n _isString(citation.title) &&\n _isString(citation.encrypted_index) &&\n _isString(citation.cited_text)\n ) {\n const { url, title, encrypted_index, cited_text, ...rest } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"url\",\n url,\n title,\n startIndex: Number(encrypted_index),\n endIndex: Number(encrypted_index),\n citedText: cited_text,\n };\n }\n if (\n citation.type === \"search_result_location\" &&\n _isString(citation.source) &&\n _isString(citation.title) &&\n _isNumber(citation.start_block_index) &&\n _isNumber(citation.end_block_index) &&\n _isString(citation.cited_text)\n ) {\n const {\n source,\n title,\n start_block_index,\n end_block_index,\n cited_text,\n ...rest\n } = citation;\n return {\n ...rest,\n type: \"citation\",\n source: \"search\",\n url: source,\n title: title ?? undefined,\n startIndex: start_block_index,\n endIndex: end_block_index,\n citedText: cited_text,\n };\n }\n return undefined;\n}\n\n/**\n * Converts an Anthropic content block to a standard V1 content block.\n *\n * This function handles the conversion of Anthropic-specific content blocks\n * (document and image blocks) to the standardized V1 format. It supports\n * various source types including base64 data, URLs, file IDs, and text data.\n *\n * @param block - The Anthropic content block to convert\n * @returns A standard V1 content block if conversion is successful, undefined otherwise\n *\n * @example\n * ```typescript\n * const anthropicBlock = {\n * type: \"image\",\n * source: {\n * type: \"base64\",\n * media_type: \"image/png\",\n * data: \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==\"\n * }\n * };\n *\n * const standardBlock = convertToV1FromAnthropicContentBlock(anthropicBlock);\n * // Returns: { type: \"image\", mimeType: \"image/png\", data: \"...\" }\n * ```\n */\nexport function convertToV1FromAnthropicContentBlock(\n block: ContentBlock\n): ContentBlock.Standard | undefined {\n if (\n _isContentBlock(block, \"document\") &&\n _isObject(block.source) &&\n \"type\" in block.source\n ) {\n if (\n block.source.type === \"base64\" &&\n _isString(block.source.media_type) &&\n _isString(block.source.data)\n ) {\n return {\n type: \"file\",\n mimeType: block.source.media_type,\n data: block.source.data,\n };\n } else if (block.source.type === \"url\" && _isString(block.source.url)) {\n return {\n type: \"file\",\n url: block.source.url,\n };\n } else if (\n block.source.type === \"file\" &&\n _isString(block.source.file_id)\n ) {\n return {\n type: \"file\",\n fileId: block.source.file_id,\n };\n } else if (block.source.type === \"text\" && _isString(block.source.data)) {\n return {\n type: \"file\",\n mimeType: String(block.source.media_type ?? \"text/plain\"),\n data: block.source.data,\n };\n }\n } else if (\n _isContentBlock(block, \"image\") &&\n _isObject(block.source) &&\n \"type\" in block.source\n ) {\n if (\n block.source.type === \"base64\" &&\n _isString(block.source.media_type) &&\n _isString(block.source.data)\n ) {\n return {\n type: \"image\",\n mimeType: block.source.media_type,\n data: block.source.data,\n };\n } else if (block.source.type === \"url\" && _isString(block.source.url)) {\n return {\n type: \"image\",\n url: block.source.url,\n };\n } else if (\n block.source.type === \"file\" &&\n _isString(block.source.file_id)\n ) {\n return {\n type: \"image\",\n fileId: block.source.file_id,\n };\n }\n }\n return undefined;\n}\n\n/**\n * Converts an array of content blocks from Anthropic format to v1 standard format.\n *\n * This function processes each content block in the input array, attempting to convert\n * Anthropic-specific block formats (like image blocks with source objects, document blocks, etc.)\n * to the standardized v1 content block format. If a block cannot be converted, it is\n * passed through as-is with a type assertion to ContentBlock.Standard.\n *\n * @param content - Array of content blocks in Anthropic format to be converted\n * @returns Array of content blocks in v1 standard format\n */\nexport function convertToV1FromAnthropicInput(\n content: Array<ContentBlock>\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n for (const block of content) {\n const stdBlock = convertToV1FromAnthropicContentBlock(block);\n if (stdBlock) {\n yield stdBlock;\n } else {\n yield block as ContentBlock.Standard;\n }\n }\n }\n return Array.from(iterateContent());\n}\n\n/**\n * Converts an Anthropic AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message containing Anthropic-specific content blocks\n * and converts them to the standardized v1 content block format.\n *\n * @param message - The AI message containing Anthropic-formatted content blocks\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage([\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"thinking\", text: \"Let me think about this...\" },\n * { type: \"tool_use\", id: \"123\", name: \"calculator\", input: { a: 1, b: 2 } }\n * ]);\n *\n * const standardBlocks = convertToV1FromAnthropicMessage(message);\n * // Returns:\n * // [\n * // { type: \"text\", text: \"Hello world\" },\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }\n * // ]\n * ```\n */\nexport function convertToV1FromAnthropicMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n // TextBlock\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n const { text, citations, ...rest } = block;\n if (_isArray(citations) && citations.length) {\n const _citations = citations.reduce<ContentBlock.Citation[]>(\n (acc, item) => {\n const citation = convertAnthropicAnnotation(item as ContentBlock);\n if (citation) {\n return [...acc, citation];\n }\n return acc;\n },\n []\n );\n yield {\n ...rest,\n type: \"text\",\n text,\n annotations: _citations,\n };\n continue;\n } else {\n yield {\n ...rest,\n type: \"text\",\n text,\n };\n continue;\n }\n }\n // ThinkingBlock\n else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n const { thinking, signature, ...rest } = block;\n yield {\n ...rest,\n type: \"reasoning\",\n reasoning: thinking,\n signature,\n };\n continue;\n }\n // RedactedThinkingBlock\n else if (_isContentBlock(block, \"redacted_thinking\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n }\n // ToolUseBlock\n else if (\n _isContentBlock(block, \"tool_use\") &&\n _isString(block.name) &&\n _isString(block.id)\n ) {\n yield {\n type: \"tool_call\",\n id: block.id,\n name: block.name,\n args: block.input,\n };\n continue;\n }\n // message chunks can have input_json_delta contents\n else if (_isContentBlock(block, \"input_json_delta\")) {\n if (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {\n const tool_call_chunk = message.tool_call_chunks[0];\n yield {\n type: \"tool_call_chunk\",\n id: tool_call_chunk.id,\n name: tool_call_chunk.name,\n args: tool_call_chunk.args,\n index: tool_call_chunk.index,\n };\n continue;\n }\n }\n // ServerToolUseBlock\n else if (\n _isContentBlock(block, \"server_tool_use\") &&\n _isString(block.name) &&\n _isString(block.id)\n ) {\n const { name, id } = block;\n if (name === \"web_search\") {\n const query = iife(() => {\n if (typeof block.input === \"string\") {\n return block.input;\n } else if (_isObject(block.input) && _isString(block.input.query)) {\n return block.input.query;\n } else if (_isString(block.partial_json)) {\n const json = safeParseJson<{ query?: string }>(\n block.partial_json\n );\n if (json?.query) {\n return json.query;\n }\n }\n return \"\";\n });\n yield {\n id,\n type: \"server_tool_call\",\n name: \"web_search\",\n args: { query },\n };\n continue;\n } else if (block.name === \"code_execution\") {\n const code = iife(() => {\n if (typeof block.input === \"string\") {\n return block.input;\n } else if (_isObject(block.input) && _isString(block.input.code)) {\n return block.input.code;\n } else if (_isString(block.partial_json)) {\n const json = safeParseJson<{ code?: string }>(block.partial_json);\n if (json?.code) {\n return json.code;\n }\n }\n return \"\";\n });\n yield {\n id,\n type: \"server_tool_call\",\n name: \"code_execution\",\n args: { code },\n };\n continue;\n }\n }\n // WebSearchToolResultBlock\n else if (\n _isContentBlock(block, \"web_search_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isArray(block.content)\n ) {\n const { content, tool_use_id } = block;\n const urls = content.reduce<string[]>((acc, content) => {\n if (_isContentBlock(content, \"web_search_result\")) {\n return [...acc, content.url as string];\n }\n return acc;\n }, []);\n yield {\n type: \"server_tool_call_result\",\n name: \"web_search\",\n toolCallId: tool_use_id,\n status: \"success\",\n output: {\n urls,\n },\n };\n continue;\n }\n // CodeExecutionToolResultBlock\n else if (\n _isContentBlock(block, \"code_execution_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isObject(block.content)\n ) {\n yield {\n type: \"server_tool_call_result\",\n name: \"code_execution\",\n toolCallId: block.tool_use_id,\n status: \"success\",\n output: block.content,\n };\n continue;\n }\n // MCPToolUseBlock\n else if (_isContentBlock(block, \"mcp_tool_use\")) {\n yield {\n id: block.id,\n type: \"server_tool_call\",\n name: \"mcp_tool_use\",\n args: block.input,\n };\n continue;\n }\n // MCPToolResultBlock\n else if (\n _isContentBlock(block, \"mcp_tool_result\") &&\n _isString(block.tool_use_id) &&\n _isObject(block.content)\n ) {\n yield {\n type: \"server_tool_call_result\",\n name: \"mcp_tool_use\",\n toolCallId: block.tool_use_id,\n status: \"success\",\n output: block.content,\n };\n continue;\n }\n // ContainerUploadBlock\n else if (_isContentBlock(block, \"container_upload\")) {\n yield {\n type: \"server_tool_call\",\n name: \"container_upload\",\n args: block.input,\n };\n continue;\n }\n // SearchResultBlockParam\n else if (_isContentBlock(block, \"search_result\")) {\n yield { id: block.id, type: \"non_standard\", value: block };\n continue;\n }\n // ToolResultBlockParam\n else if (_isContentBlock(block, \"tool_result\")) {\n yield { id: block.id, type: \"non_standard\", value: block };\n continue;\n } else {\n // For all other blocks, we try to convert them to a standard block\n const stdBlock = convertToV1FromAnthropicContentBlock(block);\n if (stdBlock) {\n yield stdBlock;\n continue;\n }\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatAnthropicTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromAnthropicMessage,\n translateContentChunk: convertToV1FromAnthropicMessage,\n};\n\nfunction _isAIMessageChunk(message: unknown): message is AIMessageChunk {\n return (\n typeof (message as BaseMessage)?._getType === \"function\" &&\n typeof (message as BaseMessageChunk).concat === \"function\" &&\n (message as BaseMessageChunk)._getType() === \"ai\"\n );\n}\n"],"mappings":";;;AAcA,SAAS,2BACPA,UACmC;AACnC,KACE,SAAS,SAAS,mBAClB,UAAU,SAAS,eAAe,IAClC,UAAU,SAAS,iBAAiB,IACpC,UAAU,SAAS,eAAe,IAClC,UAAU,SAAS,WAAW,EAC9B;EACA,MAAM,EACJ,gBACA,kBACA,gBACA,WACA,GAAG,MACJ,GAAG;AACJ,SAAO;GACL,GAAG;GACH,MAAM;GACN,QAAQ;GACR,OAAO,kBAAkB;GACzB,YAAY;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;GACF;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,0BAA0D;CACrE,kBAAkB;CAClB,uBAAuB;AACxB;AAED,SAAS,kBAAkBC,SAA6C;AACtE,QACE,OAAQ,SAAyB,aAAa,cAC9C,OAAQ,QAA6B,WAAW,cAC/C,QAA6B,UAAU,KAAK;AAEhD"}
|
|
@@ -6,11 +6,11 @@ const require_google_vertexai = require('./google_vertexai.cjs');
|
|
|
6
6
|
|
|
7
7
|
//#region src/messages/block_translators/index.ts
|
|
8
8
|
globalThis.lc_block_translators_registry ??= new Map([
|
|
9
|
-
["anthropic", require_anthropic.
|
|
9
|
+
["anthropic", require_anthropic.ChatAnthropicTranslator],
|
|
10
10
|
["bedrock-converse", require_bedrock_converse.ChatBedrockConverseTranslator],
|
|
11
11
|
["google-genai", require_google_genai.ChatGoogleGenAITranslator],
|
|
12
12
|
["google-vertexai", require_google_vertexai.ChatVertexTranslator],
|
|
13
|
-
["openai", require_openai.
|
|
13
|
+
["openai", require_openai.ChatOpenAITranslator]
|
|
14
14
|
]);
|
|
15
15
|
function getTranslator(modelProvider) {
|
|
16
16
|
return globalThis.lc_block_translators_registry.get(modelProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ChatAnthropicTranslator","ChatBedrockConverseTranslator","ChatGoogleGenAITranslator","ChatVertexTranslator","ChatOpenAITranslator","modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport { ChatAnthropicTranslator } from \"./anthropic.js\";\nimport { ChatBedrockConverseTranslator } from \"./bedrock_converse.js\";\nimport { ChatGoogleGenAITranslator } from \"./google_genai.js\";\nimport { ChatVertexTranslator } from \"./google_vertexai.js\";\nimport { ChatOpenAITranslator } from \"./openai.js\";\n\nexport interface StandardContentBlockTranslator {\n translateContent(message: AIMessage): Array<ContentBlock.Standard>;\n translateContentChunk(chunk: AIMessageChunk): Array<ContentBlock.Standard>;\n}\n\ntype TranslatorRegistry = Map<string, StandardContentBlockTranslator>;\n\ndeclare global {\n var lc_block_translators_registry: TranslatorRegistry;\n}\n\nglobalThis.lc_block_translators_registry ??= new Map([\n [\"anthropic\", ChatAnthropicTranslator],\n [\"bedrock-converse\", ChatBedrockConverseTranslator],\n [\"google-genai\", ChatGoogleGenAITranslator],\n [\"google-vertexai\", ChatVertexTranslator],\n [\"openai\", ChatOpenAITranslator],\n]);\n\nexport function registerTranslator(\n modelProvider: string,\n translator: StandardContentBlockTranslator\n) {\n globalThis.lc_block_translators_registry.set(modelProvider, translator);\n}\n\nexport function getTranslator(\n modelProvider: string\n): StandardContentBlockTranslator | undefined {\n return globalThis.lc_block_translators_registry.get(modelProvider);\n}\n"],"mappings":";;;;;;;AAoBA,WAAW,kCAAkC,IAAI,IAAI;CACnD,CAAC,aAAaA,yCAAwB;CACtC,CAAC,oBAAoBC,sDAA8B;CACnD,CAAC,gBAAgBC,8CAA0B;CAC3C,CAAC,mBAAmBC,4CAAqB;CACzC,CAAC,UAAUC,mCAAqB;AACjC;AASD,SAAgB,cACdC,eAC4C;AAC5C,QAAO,WAAW,8BAA8B,IAAI,cAAc;AACnE"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ChatAnthropicTranslator } from "./anthropic.js";
|
|
2
|
+
import { ChatOpenAITranslator } from "./openai.js";
|
|
3
3
|
import { ChatBedrockConverseTranslator } from "./bedrock_converse.js";
|
|
4
4
|
import { ChatGoogleGenAITranslator } from "./google_genai.js";
|
|
5
5
|
import { ChatVertexTranslator } from "./google_vertexai.js";
|
|
6
6
|
|
|
7
7
|
//#region src/messages/block_translators/index.ts
|
|
8
8
|
globalThis.lc_block_translators_registry ??= new Map([
|
|
9
|
-
["anthropic",
|
|
9
|
+
["anthropic", ChatAnthropicTranslator],
|
|
10
10
|
["bedrock-converse", ChatBedrockConverseTranslator],
|
|
11
11
|
["google-genai", ChatGoogleGenAITranslator],
|
|
12
12
|
["google-vertexai", ChatVertexTranslator],
|
|
13
|
-
["openai",
|
|
13
|
+
["openai", ChatOpenAITranslator]
|
|
14
14
|
]);
|
|
15
15
|
function getTranslator(modelProvider) {
|
|
16
16
|
return globalThis.lc_block_translators_registry.get(modelProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["modelProvider: string"],"sources":["../../../src/messages/block_translators/index.ts"],"sourcesContent":["import type { AIMessage, AIMessageChunk } from \"../ai.js\";\nimport type { ContentBlock } from \"../content/index.js\";\n\nimport { ChatAnthropicTranslator } from \"./anthropic.js\";\nimport { ChatBedrockConverseTranslator } from \"./bedrock_converse.js\";\nimport { ChatGoogleGenAITranslator } from \"./google_genai.js\";\nimport { ChatVertexTranslator } from \"./google_vertexai.js\";\nimport { ChatOpenAITranslator } from \"./openai.js\";\n\nexport interface StandardContentBlockTranslator {\n translateContent(message: AIMessage): Array<ContentBlock.Standard>;\n translateContentChunk(chunk: AIMessageChunk): Array<ContentBlock.Standard>;\n}\n\ntype TranslatorRegistry = Map<string, StandardContentBlockTranslator>;\n\ndeclare global {\n var lc_block_translators_registry: TranslatorRegistry;\n}\n\nglobalThis.lc_block_translators_registry ??= new Map([\n [\"anthropic\", ChatAnthropicTranslator],\n [\"bedrock-converse\", ChatBedrockConverseTranslator],\n [\"google-genai\", ChatGoogleGenAITranslator],\n [\"google-vertexai\", ChatVertexTranslator],\n [\"openai\", ChatOpenAITranslator],\n]);\n\nexport function registerTranslator(\n modelProvider: string,\n translator: StandardContentBlockTranslator\n) {\n globalThis.lc_block_translators_registry.set(modelProvider, translator);\n}\n\nexport function getTranslator(\n modelProvider: string\n): StandardContentBlockTranslator | undefined {\n return globalThis.lc_block_translators_registry.get(modelProvider);\n}\n"],"mappings":";;;;;;;AAoBA,WAAW,kCAAkC,IAAI,IAAI;CACnD,CAAC,aAAa,uBAAwB;CACtC,CAAC,oBAAoB,6BAA8B;CACnD,CAAC,gBAAgB,yBAA0B;CAC3C,CAAC,mBAAmB,oBAAqB;CACzC,CAAC,UAAU,oBAAqB;AACjC;AASD,SAAgB,cACdA,eAC4C;AAC5C,QAAO,WAAW,8BAA8B,IAAI,cAAc;AACnE"}
|