@langchain/anthropic 1.5.7 → 1.5.9

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  3. package/dist/chat_models.cjs +2 -1
  4. package/dist/chat_models.cjs.map +1 -1
  5. package/dist/chat_models.d.cts +2 -2
  6. package/dist/chat_models.d.cts.map +1 -1
  7. package/dist/chat_models.d.ts +2 -2
  8. package/dist/chat_models.d.ts.map +1 -1
  9. package/dist/chat_models.js +2 -1
  10. package/dist/chat_models.js.map +1 -1
  11. package/dist/output_parsers.cjs.map +1 -1
  12. package/dist/tools/bash.cjs.map +1 -1
  13. package/dist/tools/computer.cjs.map +1 -1
  14. package/dist/tools/memory.cjs.map +1 -1
  15. package/dist/tools/textEditor.cjs.map +1 -1
  16. package/dist/utils/content.cjs +52 -50
  17. package/dist/utils/content.cjs.map +1 -1
  18. package/dist/utils/content.js +52 -50
  19. package/dist/utils/content.js.map +1 -1
  20. package/dist/utils/errors.cjs.map +1 -1
  21. package/dist/utils/message_inputs.cjs +44 -40
  22. package/dist/utils/message_inputs.cjs.map +1 -1
  23. package/dist/utils/message_inputs.js +44 -40
  24. package/dist/utils/message_inputs.js.map +1 -1
  25. package/dist/utils/message_outputs.cjs +40 -35
  26. package/dist/utils/message_outputs.cjs.map +1 -1
  27. package/dist/utils/message_outputs.js +40 -35
  28. package/dist/utils/message_outputs.js.map +1 -1
  29. package/dist/utils/params.cjs +1 -0
  30. package/dist/utils/params.cjs.map +1 -1
  31. package/dist/utils/params.js +1 -0
  32. package/dist/utils/params.js.map +1 -1
  33. package/dist/utils/prompts.cjs +2 -1
  34. package/dist/utils/prompts.cjs.map +1 -1
  35. package/dist/utils/prompts.js +2 -1
  36. package/dist/utils/prompts.js.map +1 -1
  37. package/dist/utils/standard.cjs +11 -10
  38. package/dist/utils/standard.cjs.map +1 -1
  39. package/dist/utils/standard.js +11 -10
  40. package/dist/utils/standard.js.map +1 -1
  41. package/dist/utils/stream_events.cjs +6 -8
  42. package/dist/utils/stream_events.cjs.map +1 -1
  43. package/dist/utils/stream_events.js +6 -8
  44. package/dist/utils/stream_events.js.map +1 -1
  45. package/package.json +4 -4
@@ -90,56 +90,58 @@ const standardContentBlockConverter = {
90
90
  ..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
91
91
  };
92
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}`);
93
+ } else if (block.source_type === "text") {
94
+ 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") {
108
+ if (mime_type === "application/pdf" || mime_type === "") return {
109
+ type: "document",
110
+ source: {
111
+ type: "base64",
112
+ data: block.data,
113
+ media_type: "application/pdf"
114
+ },
115
+ ..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
116
+ ..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
117
+ ..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
118
+ ..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
119
+ };
120
+ else if ([
121
+ "image/jpeg",
122
+ "image/png",
123
+ "image/gif",
124
+ "image/webp"
125
+ ].includes(mime_type)) return {
126
+ type: "document",
127
+ source: {
128
+ type: "content",
129
+ content: [{
130
+ type: "image",
131
+ source: {
132
+ type: "base64",
133
+ data: block.data,
134
+ media_type: mime_type
135
+ }
136
+ }]
137
+ },
138
+ ..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
139
+ ..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
140
+ ..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
141
+ ..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
142
+ };
143
+ else throw new Error(`Unsupported file mime type for file base64 source: ${block.mime_type}`);
144
+ } else throw new Error(`Unsupported file source type: ${block.source_type}`);
143
145
  }
144
146
  };
145
147
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"content.cjs","names":[],"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 _isAnthropicCompactionBlock(\n block: unknown\n): block is Anthropic.Beta.BetaCompactionBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"compaction\"\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 },\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 },\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,0BACd,OACgD;CAChD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,kCACd,OACwD;CACxD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OACkD;CAClD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,8BACd,OACoD;CACpD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OAC6C;CAC7C,IAAI,OAAO,UAAU,YA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EAAE,SAAS,MAAM,SAAU,QAAQ,IACnC,CAAC;GACL,GAAI,YAAY,MAAM,YAAY,CAAC,KAC/B,EAAE,OAAO,MAAM,SAAU,MAAM,IAC/B,CAAC;EACP;OAEA,MAAM,IAAI,MACR,sDAAsD,MAAM,WAC9D;OAGF,MAAM,IAAI,MAAM,iCAAiC,MAAM,aAAa;CAExE;AACF"}
1
+ {"version":3,"file":"content.cjs","names":["parseBase64DataUrl"],"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 _isAnthropicCompactionBlock(\n block: unknown\n): block is Anthropic.Beta.BetaCompactionBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"compaction\"\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 },\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 },\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,0BACd,OACgD;CAChD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,kCACd,OACwD;CACxD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OACkD;CAClD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,8BACd,OACoD;CACpD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OAC6C;CAC7C,IAAI,OAAO,UAAU,YAAY,SAAS,MACxC,OAAO;CAET,IAAI,EAAE,UAAU,UAAU,MAAM,SAAS,SACvC,OAA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AI,YAAY,MAAM,YAAY,CAAC,KAC/B,EAAE,OAAO,MAAM,SAAU,MAAM,IAC/B,CAAC;GACP;QAEA,MAAM,IAAI,MACR,sDAAsD,MAAM,WAC9D;EAEJ,OACE,MAAM,IAAI,MAAM,iCAAiC,MAAM,aAAa;CAExE;AACF"}
@@ -90,56 +90,58 @@ const standardContentBlockConverter = {
90
90
  ..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
91
91
  };
92
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}`);
93
+ } else if (block.source_type === "text") {
94
+ 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") {
108
+ if (mime_type === "application/pdf" || mime_type === "") return {
109
+ type: "document",
110
+ source: {
111
+ type: "base64",
112
+ data: block.data,
113
+ media_type: "application/pdf"
114
+ },
115
+ ..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
116
+ ..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
117
+ ..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
118
+ ..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
119
+ };
120
+ else if ([
121
+ "image/jpeg",
122
+ "image/png",
123
+ "image/gif",
124
+ "image/webp"
125
+ ].includes(mime_type)) return {
126
+ type: "document",
127
+ source: {
128
+ type: "content",
129
+ content: [{
130
+ type: "image",
131
+ source: {
132
+ type: "base64",
133
+ data: block.data,
134
+ media_type: mime_type
135
+ }
136
+ }]
137
+ },
138
+ ..."cache_control" in (block.metadata ?? {}) ? { cache_control: block.metadata.cache_control } : {},
139
+ ..."citations" in (block.metadata ?? {}) ? { citations: block.metadata.citations } : {},
140
+ ..."context" in (block.metadata ?? {}) ? { context: block.metadata.context } : {},
141
+ ..."title" in (block.metadata ?? {}) ? { title: block.metadata.title } : {}
142
+ };
143
+ else throw new Error(`Unsupported file mime type for file base64 source: ${block.mime_type}`);
144
+ } else throw new Error(`Unsupported file source type: ${block.source_type}`);
143
145
  }
144
146
  };
145
147
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","names":[],"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 _isAnthropicCompactionBlock(\n block: unknown\n): block is Anthropic.Beta.BetaCompactionBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"compaction\"\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 },\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 },\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,0BACd,OACgD;CAChD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,kCACd,OACwD;CACxD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OACkD;CAClD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,8BACd,OACoD;CACpD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OAC6C;CAC7C,IAAI,OAAO,UAAU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M,SAAU,QAAQ,IACnC,CAAC;GACL,GAAI,YAAY,MAAM,YAAY,CAAC,KAC/B,EAAE,OAAO,MAAM,SAAU,MAAM,IAC/B,CAAC;EACP;OAEA,MAAM,IAAI,MACR,sDAAsD,MAAM,WAC9D;OAGF,MAAM,IAAI,MAAM,iCAAiC,MAAM,aAAa;CAExE;AACF"}
1
+ {"version":3,"file":"content.js","names":[],"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 _isAnthropicCompactionBlock(\n block: unknown\n): block is Anthropic.Beta.BetaCompactionBlockParam {\n return (\n typeof block === \"object\" &&\n block !== null &&\n \"type\" in block &&\n block.type === \"compaction\"\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 },\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 },\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,0BACd,OACgD;CAChD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,kCACd,OACwD;CACxD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OACkD;CAClD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,8BACd,OACoD;CACpD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEnB;AAEA,SAAgB,4BACd,OAC6C;CAC7C,IAAI,OAAO,UAAU,YAAY,SAAS,MACxC,OAAO;CAET,IAAI,EAAE,UAAU,UAAU,MAAM,SAAS,SACvC,OAAO;CAGT,IACE,EAAE,YAAY,UACd,O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AAU,MAAM,IAC/B,CAAC;GACP;QAEA,MAAM,IAAI,MACR,sDAAsD,MAAM,WAC9D;EAEJ,OACE,MAAM,IAAI,MAAM,iCAAiC,MAAM,aAAa;CAExE;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":["ContextOverflowError"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\n/* oxlint-disable no-param-reassign */\n\nimport { ContextOverflowError, stampRetryable } from \"@langchain/core/errors\";\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"CONTEXT_OVERFLOW\"\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://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n return error;\n}\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrapAnthropicClientError(e: any) {\n let error;\n if (\n e.status === 400 &&\n typeof e.message === \"string\" &&\n e.message.includes(\"prompt is too long\")\n ) {\n // ContextOverflowError marks itself non-retryable at construction.\n error = addLangChainErrorFields(\n ContextOverflowError.fromError(e),\n \"CONTEXT_OVERFLOW\"\n );\n } else if (e.status === 400 && e.message.includes(\"tool\")) {\n error = stampRetryable(\n addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\"),\n false\n );\n } else if (e.status === 401) {\n error = stampRetryable(\n addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\"),\n false\n );\n } else if (e.status === 404) {\n error = stampRetryable(\n addLangChainErrorFields(e, \"MODEL_NOT_FOUND\"),\n false\n );\n } else if (e.status === 429) {\n // AsyncCaller runs after this and re-marks false if it's quota exhaustion.\n error = stampRetryable(\n addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\"),\n true\n );\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;AAiBA,SAAgB,wBACd,OACA,eACA;CACA,MAAe,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,sFAAsF,cAAc;CACrI,OAAO;AACT;AAGA,SAAgB,yBAAyB,GAAQ;CAC/C,IAAI;CACJ,IACE,EAAE,WAAW,OACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,oBAAoB,GAGvC,QAAQ,wBACNA,uBAAAA,qBAAqB,UAAU,CAAC,GAChC,kBACF;MACK,IAAI,EAAE,WAAW,OAAO,EAAE,QAAQ,SAAS,MAAM,GACtD,SAAA,GAAA,uBAAA,eAAA,CACE,wBAAwB,GAAG,sBAAsB,GACjD,KACF;MACK,IAAI,EAAE,WAAW,KACtB,SAAA,GAAA,uBAAA,eAAA,CACE,wBAAwB,GAAG,sBAAsB,GACjD,KACF;MACK,IAAI,EAAE,WAAW,KACtB,SAAA,GAAA,uBAAA,eAAA,CACE,wBAAwB,GAAG,iBAAiB,GAC5C,KACF;MACK,IAAI,EAAE,WAAW,KAEtB,SAAA,GAAA,uBAAA,eAAA,CACE,wBAAwB,GAAG,kBAAkB,GAC7C,IACF;MAEA,QAAQ;CAEV,OAAO;AACT"}
1
+ {"version":3,"file":"errors.cjs","names":["ContextOverflowError","stampRetryable"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\n/* oxlint-disable no-param-reassign */\n\nimport { ContextOverflowError, stampRetryable } from \"@langchain/core/errors\";\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n | \"CONTEXT_OVERFLOW\"\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://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n return error;\n}\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrapAnthropicClientError(e: any) {\n let error;\n if (\n e.status === 400 &&\n typeof e.message === \"string\" &&\n e.message.includes(\"prompt is too long\")\n ) {\n // ContextOverflowError marks itself non-retryable at construction.\n error = addLangChainErrorFields(\n ContextOverflowError.fromError(e),\n \"CONTEXT_OVERFLOW\"\n );\n } else if (e.status === 400 && e.message.includes(\"tool\")) {\n error = stampRetryable(\n addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\"),\n false\n );\n } else if (e.status === 401) {\n error = stampRetryable(\n addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\"),\n false\n );\n } else if (e.status === 404) {\n error = stampRetryable(\n addLangChainErrorFields(e, \"MODEL_NOT_FOUND\"),\n false\n );\n } else if (e.status === 429) {\n // AsyncCaller runs after this and re-marks false if it's quota exhaustion.\n error = stampRetryable(\n addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\"),\n true\n );\n } else {\n error = e;\n }\n return error;\n}\n"],"mappings":";;AAiBA,SAAgB,wBACd,OACA,eACA;CACA,MAAe,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,sFAAsF,cAAc;CACrI,OAAO;AACT;AAGA,SAAgB,yBAAyB,GAAQ;CAC/C,IAAI;CACJ,IACE,EAAE,WAAW,OACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,oBAAoB,GAGvC,QAAQ,wBACNA,uBAAAA,qBAAqB,UAAU,CAAC,GAChC,kBACF;MACK,IAAI,EAAE,WAAW,OAAO,EAAE,QAAQ,SAAS,MAAM,GACtD,SAAA,GAAQC,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,sBAAsB,GACjD,KACF;MACK,IAAI,EAAE,WAAW,KACtB,SAAA,GAAQA,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,sBAAsB,GACjD,KACF;MACK,IAAI,EAAE,WAAW,KACtB,SAAA,GAAQA,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,iBAAiB,GAC5C,KACF;MACK,IAAI,EAAE,WAAW,KAEtB,SAAA,GAAQA,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,kBAAkB,GAC7C,IACF;MAEA,QAAQ;CAEV,OAAO;AACT"}
@@ -31,24 +31,25 @@ function _formatImage(imageUrl) {
31
31
  }
32
32
  function _ensureMessageContents(messages) {
33
33
  const updatedMsgs = [];
34
- for (const message of messages) if (message._getType() === "tool") if (typeof message.content === "string") {
35
- const previousMessage = updatedMsgs[updatedMsgs.length - 1];
36
- if (previousMessage?._getType() === "human" && Array.isArray(previousMessage.content) && "type" in previousMessage.content[0] && previousMessage.content[0].type === "tool_result") previousMessage.content.push({
34
+ for (const message of messages) if (message._getType() === "tool") {
35
+ if (typeof message.content === "string") {
36
+ const previousMessage = updatedMsgs[updatedMsgs.length - 1];
37
+ if (previousMessage?._getType() === "human" && Array.isArray(previousMessage.content) && "type" in previousMessage.content[0] && previousMessage.content[0].type === "tool_result") previousMessage.content.push({
38
+ type: "tool_result",
39
+ content: message.content,
40
+ tool_use_id: message.tool_call_id
41
+ });
42
+ else updatedMsgs.push(new _langchain_core_messages.HumanMessage({ content: [{
43
+ type: "tool_result",
44
+ content: message.content,
45
+ tool_use_id: message.tool_call_id
46
+ }] }));
47
+ } else updatedMsgs.push(new _langchain_core_messages.HumanMessage({ content: [{
37
48
  type: "tool_result",
38
- content: message.content,
39
- tool_use_id: message.tool_call_id
40
- });
41
- else updatedMsgs.push(new _langchain_core_messages.HumanMessage({ content: [{
42
- type: "tool_result",
43
- content: message.content,
49
+ ...message.content != null ? { content: _formatContent(message) } : {},
44
50
  tool_use_id: message.tool_call_id
45
51
  }] }));
46
- } else updatedMsgs.push(new _langchain_core_messages.HumanMessage({ content: [{
47
- type: "tool_result",
48
- ...message.content != null ? { content: _formatContent(message) } : {},
49
- tool_use_id: message.tool_call_id
50
- }] }));
51
- else updatedMsgs.push(message);
52
+ } else updatedMsgs.push(message);
52
53
  return updatedMsgs;
53
54
  }
54
55
  function _convertLangChainToolCallToAnthropic(toolCall) {
@@ -67,6 +68,7 @@ function* _formatContentBlocks(content, toolCalls) {
67
68
  "server_tool_use",
68
69
  "text_editor_code_execution_tool_result",
69
70
  "tool_result",
71
+ "tool_search_tool_result",
70
72
  "tool_search_tool_bm25_tool_result",
71
73
  "tool_search_tool_regex_tool_result",
72
74
  "tool_use",
@@ -211,31 +213,33 @@ function _convertMessagesToAnthropicPayload(messages) {
211
213
  role,
212
214
  content: require_standard._formatStandardContent(message)
213
215
  };
214
- if (_langchain_core_messages.AIMessage.isInstance(message) && !!message.tool_calls?.length) if (typeof message.content === "string") if (message.content === "") return {
215
- role,
216
- content: message.tool_calls.map(_convertLangChainToolCallToAnthropic)
217
- };
218
- else return {
219
- role,
220
- content: [{
221
- type: "text",
222
- text: message.content
223
- }, ...message.tool_calls.map(_convertLangChainToolCallToAnthropic)]
224
- };
225
- else {
226
- const { content } = message;
227
- const formattedContent = _formatContent(message, message.tool_calls);
228
- const formattedContentArr = Array.isArray(formattedContent) ? formattedContent : [{
229
- type: "text",
230
- text: formattedContent
231
- }];
232
- const missingToolCalls = message.tool_calls.filter((toolCall) => !content.find((contentPart) => (contentPart.type === "tool_use" || contentPart.type === "input_json_delta" || contentPart.type === "server_tool_use") && contentPart.id === toolCall.id));
233
- return {
234
- role,
235
- content: [...formattedContentArr, ...missingToolCalls.map(_convertLangChainToolCallToAnthropic)]
236
- };
237
- }
238
- else return {
216
+ if (_langchain_core_messages.AIMessage.isInstance(message) && !!message.tool_calls?.length) {
217
+ if (typeof message.content === "string") {
218
+ if (message.content === "") return {
219
+ role,
220
+ content: message.tool_calls.map(_convertLangChainToolCallToAnthropic)
221
+ };
222
+ else return {
223
+ role,
224
+ content: [{
225
+ type: "text",
226
+ text: message.content
227
+ }, ...message.tool_calls.map(_convertLangChainToolCallToAnthropic)]
228
+ };
229
+ } else {
230
+ const { content } = message;
231
+ const formattedContent = _formatContent(message, message.tool_calls);
232
+ const formattedContentArr = Array.isArray(formattedContent) ? formattedContent : [{
233
+ type: "text",
234
+ text: formattedContent
235
+ }];
236
+ const missingToolCalls = message.tool_calls.filter((toolCall) => !content.find((contentPart) => (contentPart.type === "tool_use" || contentPart.type === "input_json_delta" || contentPart.type === "server_tool_use") && contentPart.id === toolCall.id));
237
+ return {
238
+ role,
239
+ content: [...formattedContentArr, ...missingToolCalls.map(_convertLangChainToolCallToAnthropic)]
240
+ };
241
+ }
242
+ } else return {
239
243
  role,
240
244
  content: _formatContent(message, _langchain_core_messages.AIMessage.isInstance(message) ? message.tool_calls : void 0)
241
245
  };