@langchain/anthropic 0.3.25 → 1.0.0-alpha.1
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 +772 -989
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +615 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +222 -199
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +766 -980
- 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 +32 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +29 -31
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/content.cjs +153 -0
- package/dist/utils/content.cjs.map +1 -0
- package/dist/utils/content.js +148 -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 +218 -535
- package/dist/utils/message_inputs.cjs.map +1 -0
- package/dist/utils/message_inputs.js +219 -533
- package/dist/utils/message_inputs.js.map +1 -0
- package/dist/utils/message_outputs.cjs +185 -246
- package/dist/utils/message_outputs.cjs.map +1 -0
- package/dist/utils/message_outputs.js +184 -243
- 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 +127 -0
- package/dist/utils/standard.cjs.map +1 -0
- package/dist/utils/standard.js +127 -0
- package/dist/utils/standard.js.map +1 -0
- package/dist/utils/tools.cjs +14 -25
- package/dist/utils/tools.cjs.map +1 -0
- package/dist/utils/tools.js +14 -23
- package/dist/utils/tools.js.map +1 -0
- package/package.json +30 -53
- 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
package/dist/types.d.ts
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
2
|
import { BindToolsInput } from "@langchain/core/language_models/chat_models";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
|
|
15
|
-
export type AnthropicRequestOptions = Anthropic.RequestOptions;
|
|
16
|
-
export type AnthropicToolChoice = {
|
|
17
|
-
type: "tool";
|
|
18
|
-
name: string;
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
|
|
6
|
+
type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;
|
|
7
|
+
type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;
|
|
8
|
+
type AnthropicThinkingConfigParam = Anthropic.ThinkingConfigParam;
|
|
9
|
+
type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
|
|
10
|
+
type AnthropicRequestOptions = Anthropic.RequestOptions;
|
|
11
|
+
type AnthropicToolChoice = {
|
|
12
|
+
type: "tool";
|
|
13
|
+
name: string;
|
|
19
14
|
} | "any" | "auto" | "none" | string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
type ChatAnthropicToolType = Anthropic.Messages.Tool | BindToolsInput;
|
|
16
|
+
type AnthropicTextBlockParam = Anthropic.Messages.TextBlockParam;
|
|
17
|
+
type AnthropicImageBlockParam = Anthropic.Messages.ImageBlockParam;
|
|
18
|
+
type AnthropicToolUseBlockParam = Anthropic.Messages.ToolUseBlockParam;
|
|
19
|
+
type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockParam;
|
|
20
|
+
type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;
|
|
21
|
+
type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;
|
|
22
|
+
type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThinkingBlockParam;
|
|
23
|
+
type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;
|
|
24
|
+
type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;
|
|
25
|
+
type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;
|
|
26
|
+
// TODO(hntrl): beta blocks should be separated
|
|
27
|
+
type AnthropicSearchResultBlockParam = Anthropic.Beta.BetaSearchResultBlockParam;
|
|
28
|
+
// Union of all possible content block types including server tool use
|
|
29
|
+
type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { AnthropicMessageCreateParams, AnthropicMessageStreamEvent, AnthropicRequestOptions, AnthropicStreamingMessageCreateParams, AnthropicThinkingConfigParam, AnthropicToolChoice, ChatAnthropicContentBlock, ChatAnthropicToolType };
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["Anthropic","BindToolsInput","AnthropicToolResponse","Record","AnthropicMessageParam","MessageParam","AnthropicMessageResponse","ContentBlock","AnthropicMessageCreateParams","MessageCreateParamsNonStreaming","AnthropicStreamingMessageCreateParams","MessageCreateParamsStreaming","AnthropicThinkingConfigParam","ThinkingConfigParam","AnthropicMessageStreamEvent","MessageStreamEvent","AnthropicRequestOptions","RequestOptions","AnthropicToolChoice","ChatAnthropicToolType","Messages","Tool","AnthropicTextBlockParam","TextBlockParam","AnthropicImageBlockParam","ImageBlockParam","AnthropicToolUseBlockParam","ToolUseBlockParam","AnthropicToolResultBlockParam","ToolResultBlockParam","AnthropicDocumentBlockParam","DocumentBlockParam","AnthropicThinkingBlockParam","ThinkingBlockParam","AnthropicRedactedThinkingBlockParam","RedactedThinkingBlockParam","AnthropicServerToolUseBlockParam","ServerToolUseBlockParam","AnthropicWebSearchToolResultBlockParam","WebSearchToolResultBlockParam","AnthropicWebSearchResultBlockParam","WebSearchResultBlockParam","AnthropicSearchResultBlockParam","Beta","BetaSearchResultBlockParam","ChatAnthropicContentBlock","isAnthropicImageBlockParam","AnthropicBuiltInToolUnion","ToolUnion","Exclude"],"sources":["../src/types.d.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { BindToolsInput } from \"@langchain/core/language_models/chat_models\";\nexport type AnthropicToolResponse = {\n type: \"tool_use\";\n id: string;\n name: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: Record<string, any>;\n};\nexport type AnthropicMessageParam = Anthropic.MessageParam;\nexport type AnthropicMessageResponse = Anthropic.ContentBlock | AnthropicToolResponse;\nexport type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;\nexport type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;\nexport type AnthropicThinkingConfigParam = Anthropic.ThinkingConfigParam;\nexport type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;\nexport type AnthropicRequestOptions = Anthropic.RequestOptions;\nexport type AnthropicToolChoice = {\n type: \"tool\";\n name: string;\n} | \"any\" | \"auto\" | \"none\" | string;\nexport type ChatAnthropicToolType = Anthropic.Messages.Tool | BindToolsInput;\nexport type AnthropicTextBlockParam = Anthropic.Messages.TextBlockParam;\nexport type AnthropicImageBlockParam = Anthropic.Messages.ImageBlockParam;\nexport type AnthropicToolUseBlockParam = Anthropic.Messages.ToolUseBlockParam;\nexport type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockParam;\nexport type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;\nexport type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;\nexport type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThinkingBlockParam;\nexport type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;\nexport type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;\nexport type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;\n// TODO(hntrl): beta blocks should be separated\nexport type AnthropicSearchResultBlockParam = Anthropic.Beta.BetaSearchResultBlockParam;\n// Union of all possible content block types including server tool use\nexport type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam;\nexport declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;\n// Type for built-in tools only (excludes custom Tool type)\nexport type AnthropicBuiltInToolUnion = Exclude<Anthropic.Messages.ToolUnion, Anthropic.Messages.Tool>;\n"],"mappings":";;;;;AAoBiC,KATrBQ,4BAAAA,GAA+BR,SAAAA,CAAUS,+BASpB;AAAGT,KARxBU,qCAAAA,GAAwC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KAA1MW,yBAAAA,GAA4BvB,uBAA8KY,GAApJV,wBAAoJU,GAAzHR,0BAAyHQ,GAA5FN,6BAA4FM,GAA5DJ,2BAA4DI,GAA9BF,2BAA8BE,GAAAA,mCAAAA,GAAsCE,gCAAtCF,GAAyEI,sCAAzEJ,GAAkHM,kCAAlHN,GAAuJQ,+BAAvJR"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
|
|
3
|
+
|
|
4
|
+
//#region src/utils/content.ts
|
|
5
|
+
function _isAnthropicThinkingBlock(block) {
|
|
6
|
+
return typeof block === "object" && block !== null && "type" in block && block.type === "thinking";
|
|
7
|
+
}
|
|
8
|
+
function _isAnthropicRedactedThinkingBlock(block) {
|
|
9
|
+
return typeof block === "object" && block !== null && "type" in block && block.type === "redacted_thinking";
|
|
10
|
+
}
|
|
11
|
+
function _isAnthropicSearchResultBlock(block) {
|
|
12
|
+
return typeof block === "object" && block !== null && "type" in block && block.type === "search_result";
|
|
13
|
+
}
|
|
14
|
+
function _isAnthropicImageBlockParam(block) {
|
|
15
|
+
if (typeof block !== "object" || block == null) return false;
|
|
16
|
+
if (!("type" in block) || block.type !== "image") return false;
|
|
17
|
+
if (!("source" in block) || typeof block.source !== "object" || block.source == null) return false;
|
|
18
|
+
if (!("type" in block.source)) return false;
|
|
19
|
+
if (block.source.type === "base64") {
|
|
20
|
+
if (!("media_type" in block.source)) return false;
|
|
21
|
+
if (typeof block.source.media_type !== "string") return false;
|
|
22
|
+
if (!("data" in block.source)) return false;
|
|
23
|
+
if (typeof block.source.data !== "string") return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (block.source.type === "url") {
|
|
27
|
+
if (!("url" in block.source)) return false;
|
|
28
|
+
if (typeof block.source.url !== "string") return false;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const standardContentBlockConverter = {
|
|
34
|
+
providerName: "anthropic",
|
|
35
|
+
fromStandardTextBlock(block) {
|
|
36
|
+
return {
|
|
37
|
+
type: "text",
|
|
38
|
+
text: block.text,
|
|
39
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
40
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
fromStandardImageBlock(block) {
|
|
44
|
+
if (block.source_type === "url") {
|
|
45
|
+
const data = (0, __langchain_core_messages.parseBase64DataUrl)({
|
|
46
|
+
dataUrl: block.url,
|
|
47
|
+
asTypedArray: false
|
|
48
|
+
});
|
|
49
|
+
if (data) return {
|
|
50
|
+
type: "image",
|
|
51
|
+
source: {
|
|
52
|
+
type: "base64",
|
|
53
|
+
data: data.data,
|
|
54
|
+
media_type: data.mime_type
|
|
55
|
+
},
|
|
56
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
57
|
+
};
|
|
58
|
+
else return {
|
|
59
|
+
type: "image",
|
|
60
|
+
source: {
|
|
61
|
+
type: "url",
|
|
62
|
+
url: block.url,
|
|
63
|
+
media_type: block.mime_type ?? ""
|
|
64
|
+
},
|
|
65
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
66
|
+
};
|
|
67
|
+
} else if (block.source_type === "base64") return {
|
|
68
|
+
type: "image",
|
|
69
|
+
source: {
|
|
70
|
+
type: "base64",
|
|
71
|
+
data: block.data,
|
|
72
|
+
media_type: block.mime_type ?? ""
|
|
73
|
+
},
|
|
74
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
75
|
+
};
|
|
76
|
+
else throw new Error(`Unsupported image source type: ${block.source_type}`);
|
|
77
|
+
},
|
|
78
|
+
fromStandardFileBlock(block) {
|
|
79
|
+
const mime_type = (block.mime_type ?? "").split(";")[0];
|
|
80
|
+
if (block.source_type === "url") {
|
|
81
|
+
if (mime_type === "application/pdf" || mime_type === "") return {
|
|
82
|
+
type: "document",
|
|
83
|
+
source: {
|
|
84
|
+
type: "url",
|
|
85
|
+
url: block.url,
|
|
86
|
+
media_type: block.mime_type ?? ""
|
|
87
|
+
},
|
|
88
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
89
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
90
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
91
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
92
|
+
};
|
|
93
|
+
throw new Error(`Unsupported file mime type for file url source: ${block.mime_type}`);
|
|
94
|
+
} else if (block.source_type === "text") if (mime_type === "text/plain" || mime_type === "") return {
|
|
95
|
+
type: "document",
|
|
96
|
+
source: {
|
|
97
|
+
type: "text",
|
|
98
|
+
data: block.text,
|
|
99
|
+
media_type: block.mime_type ?? ""
|
|
100
|
+
},
|
|
101
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
102
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
103
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
104
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
105
|
+
};
|
|
106
|
+
else throw new Error(`Unsupported file mime type for file text source: ${block.mime_type}`);
|
|
107
|
+
else if (block.source_type === "base64") if (mime_type === "application/pdf" || mime_type === "") return {
|
|
108
|
+
type: "document",
|
|
109
|
+
source: {
|
|
110
|
+
type: "base64",
|
|
111
|
+
data: block.data,
|
|
112
|
+
media_type: "application/pdf"
|
|
113
|
+
},
|
|
114
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
115
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
116
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
117
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
118
|
+
};
|
|
119
|
+
else if ([
|
|
120
|
+
"image/jpeg",
|
|
121
|
+
"image/png",
|
|
122
|
+
"image/gif",
|
|
123
|
+
"image/webp"
|
|
124
|
+
].includes(mime_type)) return {
|
|
125
|
+
type: "document",
|
|
126
|
+
source: {
|
|
127
|
+
type: "content",
|
|
128
|
+
content: [{
|
|
129
|
+
type: "image",
|
|
130
|
+
source: {
|
|
131
|
+
type: "base64",
|
|
132
|
+
data: block.data,
|
|
133
|
+
media_type: mime_type
|
|
134
|
+
}
|
|
135
|
+
}]
|
|
136
|
+
},
|
|
137
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
138
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
139
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
140
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
141
|
+
};
|
|
142
|
+
else throw new Error(`Unsupported file mime type for file base64 source: ${block.mime_type}`);
|
|
143
|
+
else throw new Error(`Unsupported file source type: ${block.source_type}`);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
exports._isAnthropicImageBlockParam = _isAnthropicImageBlockParam;
|
|
149
|
+
exports._isAnthropicRedactedThinkingBlock = _isAnthropicRedactedThinkingBlock;
|
|
150
|
+
exports._isAnthropicSearchResultBlock = _isAnthropicSearchResultBlock;
|
|
151
|
+
exports._isAnthropicThinkingBlock = _isAnthropicThinkingBlock;
|
|
152
|
+
exports.standardContentBlockConverter = standardContentBlockConverter;
|
|
153
|
+
//# sourceMappingURL=content.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.cjs","names":["block: unknown","standardContentBlockConverter: StandardContentBlockConverter<{\n text: Anthropic.Messages.TextBlockParam;\n image: Anthropic.Messages.ImageBlockParam;\n file: Anthropic.Messages.DocumentBlockParam;\n}>"],"sources":["../../src/utils/content.ts"],"sourcesContent":["import type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n parseBase64DataUrl,\n type StandardContentBlockConverter,\n} from \"@langchain/core/messages\";\n\nexport function _isAnthropicThinkingBlock(\n block: unknown\n): block is Anthropic.Messages.ThinkingBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"thinking\"\n );\n}\n\nexport function _isAnthropicRedactedThinkingBlock(\n block: unknown\n): block is Anthropic.Messages.RedactedThinkingBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"redacted_thinking\"\n );\n}\n\nexport function _isAnthropicSearchResultBlock(\n block: unknown\n): block is Anthropic.Beta.BetaSearchResultBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"search_result\"\n );\n}\n\nexport function _isAnthropicImageBlockParam(\n block: unknown\n): block is Anthropic.Messages.ImageBlockParam {\n if (typeof block !== \"object\" || block == null) {\n return false;\n }\n if (!(\"type\" in block) || block.type !== \"image\") {\n return false;\n }\n\n if (\n !(\"source\" in block) ||\n typeof block.source !== \"object\" ||\n block.source == null\n ) {\n return false;\n }\n\n if (!(\"type\" in block.source)) {\n return false;\n }\n\n if (block.source.type === \"base64\") {\n if (!(\"media_type\" in block.source)) {\n return false;\n }\n\n if (typeof block.source.media_type !== \"string\") {\n return false;\n }\n\n if (!(\"data\" in block.source)) {\n return false;\n }\n\n if (typeof block.source.data !== \"string\") {\n return false;\n }\n\n return true;\n }\n\n if (block.source.type === \"url\") {\n if (!(\"url\" in block.source)) {\n return false;\n }\n\n if (typeof block.source.url !== \"string\") {\n return false;\n }\n\n return true;\n }\n\n return false;\n}\n\nexport const standardContentBlockConverter: StandardContentBlockConverter<{\n text: Anthropic.Messages.TextBlockParam;\n image: Anthropic.Messages.ImageBlockParam;\n file: Anthropic.Messages.DocumentBlockParam;\n}> = {\n providerName: \"anthropic\",\n\n fromStandardTextBlock(block): Anthropic.Messages.TextBlockParam {\n return {\n type: \"text\",\n text: block.text,\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n },\n\n fromStandardImageBlock(block): Anthropic.Messages.ImageBlockParam {\n if (block.source_type === \"url\") {\n const data = parseBase64DataUrl({\n dataUrl: block.url,\n asTypedArray: false,\n });\n if (data) {\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n data: data.data,\n media_type: data.mime_type,\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.ImageBlockParam;\n } else {\n return {\n type: \"image\",\n source: {\n type: \"url\",\n url: block.url,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else {\n if (block.source_type === \"base64\") {\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.ImageBlockParam;\n } else {\n throw new Error(`Unsupported image source type: ${block.source_type}`);\n }\n }\n },\n\n fromStandardFileBlock(block): Anthropic.Messages.DocumentBlockParam {\n const mime_type = (block.mime_type ?? \"\").split(\";\")[0];\n\n if (block.source_type === \"url\") {\n if (mime_type === \"application/pdf\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"url\",\n url: block.url,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n throw new Error(\n `Unsupported file mime type for file url source: ${block.mime_type}`\n );\n } else if (block.source_type === \"text\") {\n if (mime_type === \"text/plain\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"text\",\n data: block.text,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else {\n throw new Error(\n `Unsupported file mime type for file text source: ${block.mime_type}`\n );\n }\n } else if (block.source_type === \"base64\") {\n if (mime_type === \"application/pdf\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: \"application/pdf\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (\n [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(\n mime_type\n )\n ) {\n return {\n type: \"document\",\n source: {\n type: \"content\",\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: mime_type as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n },\n },\n ],\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else {\n throw new Error(\n `Unsupported file mime type for file base64 source: ${block.mime_type}`\n );\n }\n } else {\n throw new Error(`Unsupported file source type: ${block.source_type}`);\n }\n },\n};\n"],"mappings":";;;;AAMA,SAAgB,0BACdA,OACgD;AAChD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAElB;AAED,SAAgB,kCACdA,OACwD;AACxD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAElB;AAED,SAAgB,8BACdA,OACoD;AACpD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAElB;AAED,SAAgB,4BACdA,OAC6C;AAC7C,KAAI,OAAO,UAAU,YAAY,SAAS,KACxC,QAAO;AAET,KAAI,EAAE,UAAU,UAAU,MAAM,SAAS,QACvC,QAAO;AAGT,KACE,EAAE,YAAY,UACd,OAAO,MAAM,WAAW,YACxB,MAAM,UAAU,KAEhB,QAAO;AAGT,KAAI,EAAE,UAAU,MAAM,QACpB,QAAO;AAGT,KAAI,MAAM,OAAO,SAAS,UAAU;AAClC,MAAI,EAAE,gBAAgB,MAAM,QAC1B,QAAO;AAGT,MAAI,OAAO,MAAM,OAAO,eAAe,SACrC,QAAO;AAGT,MAAI,EAAE,UAAU,M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,gBAAgB,SAC/B,KAAI,cAAc,qBAAqB,cAAc,GACnD,QAAO;GACL,MAAM;GACN,QAAQ;IACN,MAAM;IACN,MAAM,MAAM;IACZ,YAAY;GACb;GACD,GAAI,oBAAoB,MAAM,YAAY,CAAE,KACxC,EAAE,eAAe,MAAM,SAAU,cAAe,IAChD,CAAE;GACN,GAAI,gBAAgB,MAAM,YAAY,CAAE,KACpC,EAAE,WAAW,MAAM,SAAU,UAAW,IACxC,CAAE;GACN,GAAI,cAAc,MAAM,YAAY,CAAE,KAClC,EAAE,SAAS,MAAM,SAAU,QAAS,IACpC,CAAE;GACN,GAAI,YAAY,MAAM,YAAY,CAAE,KAChC,EAAE,OAAO,MAAM,SAAU,MAAO,IAChC,CAAE;EACP;WAED;GAAC;GAAc;GAAa;GAAa;EAAa,EAAC,SACrD,UACD,CAED,QAAO;GACL,MAAM;GACN,QAAQ;IACN,MAAM;IACN,SAAS,CACP;KACE,MAAM;KACN,QAAQ;MACN,MAAM;MACN,MAAM,MAAM;MACZ,YAAY;KAKb;IACF,CACF;GACF;GACD,GAAI,oBAAoB,MAAM,YAAY,CAAE,KACxC,EAAE,eAAe,MAAM,SAAU,cAAe,IAChD,CAAE;GACN,GAAI,gBAAgB,MAAM,YAAY,CAAE,KACpC,EAAE,WAAW,MAAM,SAAU,UAAW,IACxC,CAAE;GACN,GAAI,cAAc,MAAM,YAAY,CAAE,KAClC,EAAE,SAAS,MAAM,SAAU,QAAS,IACpC,CAAE;GACN,GAAI,YAAY,MAAM,YAAY,CAAE,KAChC,EAAE,OAAO,MAAM,SAAU,MAAO,IAChC,CAAE;EACP;MAED,OAAM,IAAI,MACR,CAAC,mDAAmD,EAAE,MAAM,WAAW;MAI3E,OAAM,IAAI,MAAM,CAAC,8BAA8B,EAAE,MAAM,aAAa;CAEvE;AACF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { parseBase64DataUrl } from "@langchain/core/messages";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/content.ts
|
|
4
|
+
function _isAnthropicThinkingBlock(block) {
|
|
5
|
+
return typeof block === "object" && block !== null && "type" in block && block.type === "thinking";
|
|
6
|
+
}
|
|
7
|
+
function _isAnthropicRedactedThinkingBlock(block) {
|
|
8
|
+
return typeof block === "object" && block !== null && "type" in block && block.type === "redacted_thinking";
|
|
9
|
+
}
|
|
10
|
+
function _isAnthropicSearchResultBlock(block) {
|
|
11
|
+
return typeof block === "object" && block !== null && "type" in block && block.type === "search_result";
|
|
12
|
+
}
|
|
13
|
+
function _isAnthropicImageBlockParam(block) {
|
|
14
|
+
if (typeof block !== "object" || block == null) return false;
|
|
15
|
+
if (!("type" in block) || block.type !== "image") return false;
|
|
16
|
+
if (!("source" in block) || typeof block.source !== "object" || block.source == null) return false;
|
|
17
|
+
if (!("type" in block.source)) return false;
|
|
18
|
+
if (block.source.type === "base64") {
|
|
19
|
+
if (!("media_type" in block.source)) return false;
|
|
20
|
+
if (typeof block.source.media_type !== "string") return false;
|
|
21
|
+
if (!("data" in block.source)) return false;
|
|
22
|
+
if (typeof block.source.data !== "string") return false;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (block.source.type === "url") {
|
|
26
|
+
if (!("url" in block.source)) return false;
|
|
27
|
+
if (typeof block.source.url !== "string") return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const standardContentBlockConverter = {
|
|
33
|
+
providerName: "anthropic",
|
|
34
|
+
fromStandardTextBlock(block) {
|
|
35
|
+
return {
|
|
36
|
+
type: "text",
|
|
37
|
+
text: block.text,
|
|
38
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
39
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
fromStandardImageBlock(block) {
|
|
43
|
+
if (block.source_type === "url") {
|
|
44
|
+
const data = parseBase64DataUrl({
|
|
45
|
+
dataUrl: block.url,
|
|
46
|
+
asTypedArray: false
|
|
47
|
+
});
|
|
48
|
+
if (data) return {
|
|
49
|
+
type: "image",
|
|
50
|
+
source: {
|
|
51
|
+
type: "base64",
|
|
52
|
+
data: data.data,
|
|
53
|
+
media_type: data.mime_type
|
|
54
|
+
},
|
|
55
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
56
|
+
};
|
|
57
|
+
else return {
|
|
58
|
+
type: "image",
|
|
59
|
+
source: {
|
|
60
|
+
type: "url",
|
|
61
|
+
url: block.url,
|
|
62
|
+
media_type: block.mime_type ?? ""
|
|
63
|
+
},
|
|
64
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
65
|
+
};
|
|
66
|
+
} else if (block.source_type === "base64") return {
|
|
67
|
+
type: "image",
|
|
68
|
+
source: {
|
|
69
|
+
type: "base64",
|
|
70
|
+
data: block.data,
|
|
71
|
+
media_type: block.mime_type ?? ""
|
|
72
|
+
},
|
|
73
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {}
|
|
74
|
+
};
|
|
75
|
+
else throw new Error(`Unsupported image source type: ${block.source_type}`);
|
|
76
|
+
},
|
|
77
|
+
fromStandardFileBlock(block) {
|
|
78
|
+
const mime_type = (block.mime_type ?? "").split(";")[0];
|
|
79
|
+
if (block.source_type === "url") {
|
|
80
|
+
if (mime_type === "application/pdf" || mime_type === "") return {
|
|
81
|
+
type: "document",
|
|
82
|
+
source: {
|
|
83
|
+
type: "url",
|
|
84
|
+
url: block.url,
|
|
85
|
+
media_type: block.mime_type ?? ""
|
|
86
|
+
},
|
|
87
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
88
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
89
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
90
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
91
|
+
};
|
|
92
|
+
throw new Error(`Unsupported file mime type for file url source: ${block.mime_type}`);
|
|
93
|
+
} else if (block.source_type === "text") if (mime_type === "text/plain" || mime_type === "") return {
|
|
94
|
+
type: "document",
|
|
95
|
+
source: {
|
|
96
|
+
type: "text",
|
|
97
|
+
data: block.text,
|
|
98
|
+
media_type: block.mime_type ?? ""
|
|
99
|
+
},
|
|
100
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
101
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
102
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
103
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
104
|
+
};
|
|
105
|
+
else throw new Error(`Unsupported file mime type for file text source: ${block.mime_type}`);
|
|
106
|
+
else if (block.source_type === "base64") if (mime_type === "application/pdf" || mime_type === "") return {
|
|
107
|
+
type: "document",
|
|
108
|
+
source: {
|
|
109
|
+
type: "base64",
|
|
110
|
+
data: block.data,
|
|
111
|
+
media_type: "application/pdf"
|
|
112
|
+
},
|
|
113
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
114
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
115
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
116
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
117
|
+
};
|
|
118
|
+
else if ([
|
|
119
|
+
"image/jpeg",
|
|
120
|
+
"image/png",
|
|
121
|
+
"image/gif",
|
|
122
|
+
"image/webp"
|
|
123
|
+
].includes(mime_type)) return {
|
|
124
|
+
type: "document",
|
|
125
|
+
source: {
|
|
126
|
+
type: "content",
|
|
127
|
+
content: [{
|
|
128
|
+
type: "image",
|
|
129
|
+
source: {
|
|
130
|
+
type: "base64",
|
|
131
|
+
data: block.data,
|
|
132
|
+
media_type: mime_type
|
|
133
|
+
}
|
|
134
|
+
}]
|
|
135
|
+
},
|
|
136
|
+
..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
|
|
137
|
+
..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
|
|
138
|
+
..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
|
|
139
|
+
..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
|
|
140
|
+
};
|
|
141
|
+
else throw new Error(`Unsupported file mime type for file base64 source: ${block.mime_type}`);
|
|
142
|
+
else throw new Error(`Unsupported file source type: ${block.source_type}`);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
export { _isAnthropicImageBlockParam, _isAnthropicRedactedThinkingBlock, _isAnthropicSearchResultBlock, _isAnthropicThinkingBlock, standardContentBlockConverter };
|
|
148
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","names":["block: unknown","standardContentBlockConverter: StandardContentBlockConverter<{\n text: Anthropic.Messages.TextBlockParam;\n image: Anthropic.Messages.ImageBlockParam;\n file: Anthropic.Messages.DocumentBlockParam;\n}>"],"sources":["../../src/utils/content.ts"],"sourcesContent":["import type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n parseBase64DataUrl,\n type StandardContentBlockConverter,\n} from \"@langchain/core/messages\";\n\nexport function _isAnthropicThinkingBlock(\n block: unknown\n): block is Anthropic.Messages.ThinkingBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"thinking\"\n );\n}\n\nexport function _isAnthropicRedactedThinkingBlock(\n block: unknown\n): block is Anthropic.Messages.RedactedThinkingBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"redacted_thinking\"\n );\n}\n\nexport function _isAnthropicSearchResultBlock(\n block: unknown\n): block is Anthropic.Beta.BetaSearchResultBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"search_result\"\n );\n}\n\nexport function _isAnthropicImageBlockParam(\n block: unknown\n): block is Anthropic.Messages.ImageBlockParam {\n if (typeof block !== \"object\" || block == null) {\n return false;\n }\n if (!(\"type\" in block) || block.type !== \"image\") {\n return false;\n }\n\n if (\n !(\"source\" in block) ||\n typeof block.source !== \"object\" ||\n block.source == null\n ) {\n return false;\n }\n\n if (!(\"type\" in block.source)) {\n return false;\n }\n\n if (block.source.type === \"base64\") {\n if (!(\"media_type\" in block.source)) {\n return false;\n }\n\n if (typeof block.source.media_type !== \"string\") {\n return false;\n }\n\n if (!(\"data\" in block.source)) {\n return false;\n }\n\n if (typeof block.source.data !== \"string\") {\n return false;\n }\n\n return true;\n }\n\n if (block.source.type === \"url\") {\n if (!(\"url\" in block.source)) {\n return false;\n }\n\n if (typeof block.source.url !== \"string\") {\n return false;\n }\n\n return true;\n }\n\n return false;\n}\n\nexport const standardContentBlockConverter: StandardContentBlockConverter<{\n text: Anthropic.Messages.TextBlockParam;\n image: Anthropic.Messages.ImageBlockParam;\n file: Anthropic.Messages.DocumentBlockParam;\n}> = {\n providerName: \"anthropic\",\n\n fromStandardTextBlock(block): Anthropic.Messages.TextBlockParam {\n return {\n type: \"text\",\n text: block.text,\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n },\n\n fromStandardImageBlock(block): Anthropic.Messages.ImageBlockParam {\n if (block.source_type === \"url\") {\n const data = parseBase64DataUrl({\n dataUrl: block.url,\n asTypedArray: false,\n });\n if (data) {\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n data: data.data,\n media_type: data.mime_type,\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.ImageBlockParam;\n } else {\n return {\n type: \"image\",\n source: {\n type: \"url\",\n url: block.url,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else {\n if (block.source_type === \"base64\") {\n return {\n type: \"image\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n } as Anthropic.Messages.ImageBlockParam;\n } else {\n throw new Error(`Unsupported image source type: ${block.source_type}`);\n }\n }\n },\n\n fromStandardFileBlock(block): Anthropic.Messages.DocumentBlockParam {\n const mime_type = (block.mime_type ?? \"\").split(\";\")[0];\n\n if (block.source_type === \"url\") {\n if (mime_type === \"application/pdf\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"url\",\n url: block.url,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n throw new Error(\n `Unsupported file mime type for file url source: ${block.mime_type}`\n );\n } else if (block.source_type === \"text\") {\n if (mime_type === \"text/plain\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"text\",\n data: block.text,\n media_type: block.mime_type ?? \"\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else {\n throw new Error(\n `Unsupported file mime type for file text source: ${block.mime_type}`\n );\n }\n } else if (block.source_type === \"base64\") {\n if (mime_type === \"application/pdf\" || mime_type === \"\") {\n return {\n type: \"document\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: \"application/pdf\",\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (\n [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(\n mime_type\n )\n ) {\n return {\n type: \"document\",\n source: {\n type: \"content\",\n content: [\n {\n type: \"image\",\n source: {\n type: \"base64\",\n data: block.data,\n media_type: mime_type as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n },\n },\n ],\n },\n ...(\"cache_control\" in (block.metadata ?? {})\n ? { cache_control: block.metadata!.cache_control }\n : {}),\n ...(\"citations\" in (block.metadata ?? {})\n ? { citations: block.metadata!.citations }\n : {}),\n ...(\"context\" in (block.metadata ?? {})\n ? { context: block.metadata!.context }\n : {}),\n ...(\"title\" in (block.metadata ?? {})\n ? { title: block.metadata!.title }\n : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else {\n throw new Error(\n `Unsupported file mime type for file base64 source: ${block.mime_type}`\n );\n }\n } else {\n throw new Error(`Unsupported file source type: ${block.source_type}`);\n }\n },\n};\n"],"mappings":";;;AAMA,SAAgB,0BACdA,OACgD;A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AS,CACP;KACE,MAAM;KACN,QAAQ;MACN,MAAM;MACN,MAAM,MAAM;MACZ,YAAY;KAKb;IACF,CACF;GACF;GACD,GAAI,oBAAoB,MAAM,YAAY,CAAE,KACxC,EAAE,eAAe,MAAM,SAAU,cAAe,IAChD,CAAE;GACN,GAAI,gBAAgB,MAAM,YAAY,CAAE,KACpC,EAAE,WAAW,MAAM,SAAU,UAAW,IACxC,CAAE;GACN,GAAI,cAAc,MAAM,YAAY,CAAE,KAClC,EAAE,SAAS,MAAM,SAAU,QAAS,IACpC,CAAE;GACN,GAAI,YAAY,MAAM,YAAY,CAAE,KAChC,EAAE,OAAO,MAAM,SAAU,MAAO,IAChC,CAAE;EACP;MAED,OAAM,IAAI,MACR,CAAC,mDAAmD,EAAE,MAAM,WAAW;MAI3E,OAAM,IAAI,MAAM,CAAC,8BAA8B,EAAE,MAAM,aAAa;CAEvE;AACF"}
|
package/dist/utils/errors.cjs
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-param-reassign */
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.addLangChainErrorFields = addLangChainErrorFields;
|
|
6
|
-
exports.wrapAnthropicClientError = wrapAnthropicClientError;
|
|
1
|
+
|
|
2
|
+
//#region src/utils/errors.ts
|
|
7
3
|
function addLangChainErrorFields(error, lc_error_code) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
error.lc_error_code = lc_error_code;
|
|
5
|
+
error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
|
|
6
|
+
return error;
|
|
11
7
|
}
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
8
|
function wrapAnthropicClientError(e) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
else if (e.status === 404) {
|
|
22
|
-
error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
|
|
23
|
-
}
|
|
24
|
-
else if (e.status === 429) {
|
|
25
|
-
error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
error = e;
|
|
29
|
-
}
|
|
30
|
-
return error;
|
|
9
|
+
let error;
|
|
10
|
+
if (e.status === 400 && e.message.includes("tool")) error = addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
|
|
11
|
+
else if (e.status === 401) error = addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
|
|
12
|
+
else if (e.status === 404) error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
|
|
13
|
+
else if (e.status === 429) error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
|
|
14
|
+
else error = e;
|
|
15
|
+
return error;
|
|
31
16
|
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.wrapAnthropicClientError = wrapAnthropicClientError;
|
|
20
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":["error: any","lc_error_code: LangChainErrorCodes","e: any"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable no-param-reassign */\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"INVALID_PROMPT_INPUT\"\n | \"INVALID_TOOL_RESULTS\"\n | \"MESSAGE_COERCION_FAILURE\"\n | \"MODEL_AUTHENTICATION\"\n | \"MODEL_NOT_FOUND\"\n | \"MODEL_RATE_LIMIT\"\n | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n error: any,\n lc_error_code: LangChainErrorCodes\n) {\n (error as any).lc_error_code = lc_error_code;\n error.message = `${error.message}\\n\\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\\n`;\n return error;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrapAnthropicClientError(e: any) {\n let error;\n if (e.status === 400 && e.message.includes(\"tool\")) {\n error = addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\");\n } else if (e.status === 401) {\n error = addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\");\n } else if (e.status === 404) {\n error = addLangChainErrorFields(e, \"MODEL_NOT_FOUND\");\n } else if (e.status === 429) {\n error = addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\");\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;AAcA,SAAgB,wBACdA,OACAC,eACA;CACC,MAAc,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,8EAA8E,EAAE,cAAc,GAAG,CAAC;AACnI,QAAO;AACR;AAGD,SAAgB,yBAAyBC,GAAQ;CAC/C,IAAI;AACJ,KAAI,EAAE,WAAW,OAAO,EAAE,QAAQ,SAAS,OAAO,EAChD,QAAQ,wBAAwB,GAAG,uBAAuB;UACjD,EAAE,WAAW,KACtB,QAAQ,wBAAwB,GAAG,uBAAuB;UACjD,EAAE,WAAW,KACtB,QAAQ,wBAAwB,GAAG,kBAAkB;UAC5C,EAAE,WAAW,KACtB,QAAQ,wBAAwB,GAAG,mBAAmB;MAEtD,QAAQ;AAEV,QAAO;AACR"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return error;
|
|
1
|
+
//#region src/utils/errors.ts
|
|
2
|
+
function addLangChainErrorFields(error, lc_error_code) {
|
|
3
|
+
error.lc_error_code = lc_error_code;
|
|
4
|
+
error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
|
|
5
|
+
return error;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
else if (e.status === 404) {
|
|
18
|
-
error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
|
|
19
|
-
}
|
|
20
|
-
else if (e.status === 429) {
|
|
21
|
-
error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
error = e;
|
|
25
|
-
}
|
|
26
|
-
return error;
|
|
7
|
+
function wrapAnthropicClientError(e) {
|
|
8
|
+
let error;
|
|
9
|
+
if (e.status === 400 && e.message.includes("tool")) error = addLangChainErrorFields(e, "INVALID_TOOL_RESULTS");
|
|
10
|
+
else if (e.status === 401) error = addLangChainErrorFields(e, "MODEL_AUTHENTICATION");
|
|
11
|
+
else if (e.status === 404) error = addLangChainErrorFields(e, "MODEL_NOT_FOUND");
|
|
12
|
+
else if (e.status === 429) error = addLangChainErrorFields(e, "MODEL_RATE_LIMIT");
|
|
13
|
+
else error = e;
|
|
14
|
+
return error;
|
|
27
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { wrapAnthropicClientError };
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":["error: any","lc_error_code: LangChainErrorCodes","e: any"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable no-param-reassign */\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"INVALID_PROMPT_INPUT\"\n | \"INVALID_TOOL_RESULTS\"\n | \"MESSAGE_COERCION_FAILURE\"\n | \"MODEL_AUTHENTICATION\"\n | \"MODEL_NOT_FOUND\"\n | \"MODEL_RATE_LIMIT\"\n | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n error: any,\n lc_error_code: LangChainErrorCodes\n) {\n (error as any).lc_error_code = lc_error_code;\n error.message = `${error.message}\\n\\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\\n`;\n return error;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrapAnthropicClientError(e: any) {\n let error;\n if (e.status === 400 && e.message.includes(\"tool\")) {\n error = addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\");\n } else if (e.status === 401) {\n error = addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\");\n } else if (e.status === 404) {\n error = addLangChainErrorFields(e, \"MODEL_NOT_FOUND\");\n } else if (e.status === 429) {\n error = addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\");\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";AAcA,SAAgB,wBACdA,OACAC,eACA;CACC,MAAc,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,8EAA8E,EAAE,cAAc,GAAG,CAAC;AACnI,QAAO;AACR;AAGD,SAAgB,yBAAyBC,GAAQ;CAC/C,IAAI;AACJ,KAAI,EAAE,WAAW,OAAO,EAAE,QAAQ,SAAS,OAAO,EAChD,QAAQ,wBAAwB,GAAG,uBAAuB;UACjD,EAAE,WAAW,KACtB,QAAQ,wBAAwB,GAAG,uBAAuB;UACjD,EAAE,WAAW,KACtB,QAAQ,wBAAwB,GAAG,kBAAkB;UAC5C,EAAE,WAAW,KACtB,QAAQ,wBAAwB,GAAG,mBAAmB;MAEtD,QAAQ;AAEV,QAAO;AACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["fn: () => T"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export const iife = <T>(fn: () => T) => fn();\n\nexport const safeParseJson = <T>(json: string): T | object => {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n};\n"],"mappings":";;AAAA,MAAa,OAAO,CAAIA,OAAgB,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["fn: () => T"],"sources":["../../src/utils/index.ts"],"sourcesContent":["export const iife = <T>(fn: () => T) => fn();\n\nexport const safeParseJson = <T>(json: string): T | object => {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n};\n"],"mappings":";AAAA,MAAa,OAAO,CAAIA,OAAgB,IAAI"}
|