@langchain/anthropic 1.5.11 → 1.5.13

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 (70) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/chat_models.cjs +24 -13
  3. package/dist/chat_models.cjs.map +1 -1
  4. package/dist/chat_models.d.cts +12 -8
  5. package/dist/chat_models.d.cts.map +1 -1
  6. package/dist/chat_models.d.ts +12 -8
  7. package/dist/chat_models.d.ts.map +1 -1
  8. package/dist/chat_models.js +25 -14
  9. package/dist/chat_models.js.map +1 -1
  10. package/dist/profiles.cjs +87 -36
  11. package/dist/profiles.cjs.map +1 -1
  12. package/dist/profiles.js +87 -36
  13. package/dist/profiles.js.map +1 -1
  14. package/dist/tools/bash.d.cts +2 -3
  15. package/dist/tools/bash.d.cts.map +1 -1
  16. package/dist/tools/bash.d.ts +2 -3
  17. package/dist/tools/bash.d.ts.map +1 -1
  18. package/dist/tools/codeExecution.d.cts +2 -3
  19. package/dist/tools/codeExecution.d.cts.map +1 -1
  20. package/dist/tools/codeExecution.d.ts +2 -3
  21. package/dist/tools/codeExecution.d.ts.map +1 -1
  22. package/dist/tools/computer.d.cts +5 -6
  23. package/dist/tools/computer.d.cts.map +1 -1
  24. package/dist/tools/computer.d.ts +5 -6
  25. package/dist/tools/computer.d.ts.map +1 -1
  26. package/dist/tools/index.d.cts +2 -2
  27. package/dist/tools/index.d.cts.map +1 -1
  28. package/dist/tools/index.d.ts +2 -2
  29. package/dist/tools/index.d.ts.map +1 -1
  30. package/dist/tools/mcpToolset.d.cts +4 -5
  31. package/dist/tools/mcpToolset.d.cts.map +1 -1
  32. package/dist/tools/mcpToolset.d.ts +4 -5
  33. package/dist/tools/mcpToolset.d.ts.map +1 -1
  34. package/dist/tools/memory.d.cts +1 -2
  35. package/dist/tools/memory.d.cts.map +1 -1
  36. package/dist/tools/memory.d.ts +1 -2
  37. package/dist/tools/memory.d.ts.map +1 -1
  38. package/dist/tools/textEditor.d.cts +2 -3
  39. package/dist/tools/textEditor.d.cts.map +1 -1
  40. package/dist/tools/textEditor.d.ts +2 -3
  41. package/dist/tools/textEditor.d.ts.map +1 -1
  42. package/dist/tools/toolSearch.d.cts +3 -4
  43. package/dist/tools/toolSearch.d.cts.map +1 -1
  44. package/dist/tools/toolSearch.d.ts +3 -4
  45. package/dist/tools/toolSearch.d.ts.map +1 -1
  46. package/dist/tools/types.d.cts +68 -69
  47. package/dist/tools/types.d.cts.map +1 -1
  48. package/dist/tools/types.d.ts +68 -69
  49. package/dist/tools/types.d.ts.map +1 -1
  50. package/dist/tools/webFetch.d.cts +2 -3
  51. package/dist/tools/webFetch.d.cts.map +1 -1
  52. package/dist/tools/webFetch.d.ts +2 -3
  53. package/dist/tools/webFetch.d.ts.map +1 -1
  54. package/dist/tools/webSearch.d.cts +2 -3
  55. package/dist/tools/webSearch.d.cts.map +1 -1
  56. package/dist/tools/webSearch.d.ts +2 -3
  57. package/dist/tools/webSearch.d.ts.map +1 -1
  58. package/dist/types.d.cts +27 -28
  59. package/dist/types.d.cts.map +1 -1
  60. package/dist/types.d.ts +27 -28
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/utils/message_inputs.cjs +47 -10
  63. package/dist/utils/message_inputs.cjs.map +1 -1
  64. package/dist/utils/message_inputs.js +47 -11
  65. package/dist/utils/message_inputs.js.map +1 -1
  66. package/dist/utils/prompts.d.cts +1 -2
  67. package/dist/utils/prompts.d.cts.map +1 -1
  68. package/dist/utils/prompts.d.ts +1 -2
  69. package/dist/utils/prompts.d.ts.map +1 -1
  70. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/tools/types.ts"],"mappings":";;;;;;;;cAUa,iCAA+B,EAAA;;;GAG1C,EAAA,KAAA;cAEW,mCAAiC,EAAA;;;;GAI5C,EAAA,KAAA;cAEW,uCAAqC,EAAA;;;;;GAKhD,EAAA,KAAA;cAEW,mCAAiC,EAAA;;;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;YAGG,uBAAuB,EAAE,aAAa;YAEtC,qBAAqB,EAAE,aAAa;YAEpC,oBAAoB,EAAE,aAAa;YAEnC,0BAA0B,EAAE,aAC/B;YAGG,wBAAwB,EAAE,aAAa;YAEvC,qBAAqB,EAAE,aAAa;YAEpC,qBAAqB,EAAE,aAAa;;;;;qBAQnC,kCAAgC,EAAA;;GAE3C,EAAA,KAAA;qBAEW,kCAAgC,EAAA;;GAE3C,EAAA,KAAA;qBAGW,2BAAyB,EAAA,mBAAA,EAAA;;;;GAGpC,EAAA,KAAA;YAGU,6BAA6B,EAAE,aAClC;YAEG,6BAA6B,EAAE,aAClC;YAEG,sBAAsB,EAAE,aAAa"}
@@ -4,7 +4,7 @@ import { ServerTool } from "@langchain/core/tools";
4
4
  /**
5
5
  * Options for the web fetch tool.
6
6
  */
7
- interface WebFetch20250910Options {
7
+ export interface WebFetch20250910Options {
8
8
  /**
9
9
  * Maximum number of times the tool can be used in the API request.
10
10
  */
@@ -88,7 +88,6 @@ interface WebFetch20250910Options {
88
88
  * );
89
89
  * ```
90
90
  */
91
- declare function webFetch_20250910(options?: WebFetch20250910Options): ServerTool;
91
+ export declare function webFetch_20250910(options?: WebFetch20250910Options): ServerTool;
92
92
  //#endregion
93
- export { WebFetch20250910Options, webFetch_20250910 };
94
93
  //# sourceMappingURL=webFetch.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webFetch.d.cts","names":[],"sources":["../../src/tools/webFetch.ts"],"mappings":";;;;;;UAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAe,YAAU,KAAK;;;;;EAK9B;IACE;;;;;;EAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuDc,kBACd,UAAU,0BACT"}
1
+ {"version":3,"file":"webFetch.d.cts","names":["Anthropic"],"sources":["../../src/tools/webFetch.ts"],"mappings":";;;;;;iBAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAeA,YAAU,KAAK;;;;;EAK9B;IACE;;;;;;EAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuDc,kBACd,UAAU,0BACT"}
@@ -4,7 +4,7 @@ import { ServerTool } from "@langchain/core/tools";
4
4
  /**
5
5
  * Options for the web fetch tool.
6
6
  */
7
- interface WebFetch20250910Options {
7
+ export interface WebFetch20250910Options {
8
8
  /**
9
9
  * Maximum number of times the tool can be used in the API request.
10
10
  */
@@ -88,7 +88,6 @@ interface WebFetch20250910Options {
88
88
  * );
89
89
  * ```
90
90
  */
91
- declare function webFetch_20250910(options?: WebFetch20250910Options): ServerTool;
91
+ export declare function webFetch_20250910(options?: WebFetch20250910Options): ServerTool;
92
92
  //#endregion
93
- export { WebFetch20250910Options, webFetch_20250910 };
94
93
  //# sourceMappingURL=webFetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webFetch.d.ts","names":[],"sources":["../../src/tools/webFetch.ts"],"mappings":";;;;;;UAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAe,YAAU,KAAK;;;;;EAK9B;IACE;;;;;;EAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuDc,kBACd,UAAU,0BACT"}
1
+ {"version":3,"file":"webFetch.d.ts","names":["Anthropic"],"sources":["../../src/tools/webFetch.ts"],"mappings":";;;;;;iBAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAeA,YAAU,KAAK;;;;;EAK9B;IACE;;;;;;EAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuDc,kBACd,UAAU,0BACT"}
@@ -4,7 +4,7 @@ import { ServerTool } from "@langchain/core/tools";
4
4
  /**
5
5
  * Options for the web search tool.
6
6
  */
7
- interface WebSearch20250305Options {
7
+ export interface WebSearch20250305Options {
8
8
  /**
9
9
  * Maximum number of times the tool can be used in the API request.
10
10
  */
@@ -76,7 +76,6 @@ interface WebSearch20250305Options {
76
76
  * });
77
77
  * ```
78
78
  */
79
- declare function webSearch_20250305(options?: WebSearch20250305Options): ServerTool;
79
+ export declare function webSearch_20250305(options?: WebSearch20250305Options): ServerTool;
80
80
  //#endregion
81
- export { WebSearch20250305Options, webSearch_20250305 };
82
81
  //# sourceMappingURL=webSearch.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webSearch.d.cts","names":[],"sources":["../../src/tools/webSearch.ts"],"mappings":";;;;;;UAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAe,YAAU,KAAK;;;;;EAK9B,eAAe,YAAU,KAAK,0BAA0B;;;;;EAKxD;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCc,mBACd,UAAU,2BACT"}
1
+ {"version":3,"file":"webSearch.d.cts","names":["Anthropic"],"sources":["../../src/tools/webSearch.ts"],"mappings":";;;;;;iBAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAeA,YAAU,KAAK;;;;;EAK9B,eAAeA,YAAU,KAAK,0BAA0B;;;;;EAKxD;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyCc,mBACd,UAAU,2BACT"}
@@ -4,7 +4,7 @@ import { ServerTool } from "@langchain/core/tools";
4
4
  /**
5
5
  * Options for the web search tool.
6
6
  */
7
- interface WebSearch20250305Options {
7
+ export interface WebSearch20250305Options {
8
8
  /**
9
9
  * Maximum number of times the tool can be used in the API request.
10
10
  */
@@ -76,7 +76,6 @@ interface WebSearch20250305Options {
76
76
  * });
77
77
  * ```
78
78
  */
79
- declare function webSearch_20250305(options?: WebSearch20250305Options): ServerTool;
79
+ export declare function webSearch_20250305(options?: WebSearch20250305Options): ServerTool;
80
80
  //#endregion
81
- export { WebSearch20250305Options, webSearch_20250305 };
82
81
  //# sourceMappingURL=webSearch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webSearch.d.ts","names":[],"sources":["../../src/tools/webSearch.ts"],"mappings":";;;;;;UAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAe,YAAU,KAAK;;;;;EAK9B,eAAe,YAAU,KAAK,0BAA0B;;;;;EAKxD;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCc,mBACd,UAAU,2BACT"}
1
+ {"version":3,"file":"webSearch.d.ts","names":["Anthropic"],"sources":["../../src/tools/webSearch.ts"],"mappings":";;;;;;iBAMiB;;;;EAIf;;;;;EAKA;;;;;EAKA;;;;EAIA,eAAeA,YAAU,KAAK;;;;;EAK9B,eAAeA,YAAU,KAAK,0BAA0B;;;;;EAKxD;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyCc,mBACd,UAAU,2BACT"}
package/dist/types.d.cts CHANGED
@@ -1,40 +1,39 @@
1
1
  import Anthropic$1 from "@anthropic-ai/sdk";
2
2
  import { BindToolsInput } from "@langchain/core/language_models/chat_models";
3
3
  //#region src/types.d.ts
4
- type AnthropicMessageCreateParams = Anthropic$1.MessageCreateParamsNonStreaming;
5
- type AnthropicStreamingMessageCreateParams = Anthropic$1.MessageCreateParamsStreaming;
6
- type AnthropicThinkingConfigParam = Anthropic$1.ThinkingConfigParam;
7
- type AnthropicContextManagementConfigParam = Anthropic$1.Beta.BetaContextManagementConfig;
8
- type AnthropicMessageStreamEvent = Anthropic$1.MessageStreamEvent;
9
- type AnthropicRequestOptions = Anthropic$1.RequestOptions;
10
- type AnthropicToolChoice = {
4
+ export type AnthropicMessageCreateParams = Anthropic$1.MessageCreateParamsNonStreaming;
5
+ export type AnthropicStreamingMessageCreateParams = Anthropic$1.MessageCreateParamsStreaming;
6
+ export type AnthropicThinkingConfigParam = Anthropic$1.ThinkingConfigParam;
7
+ export type AnthropicContextManagementConfigParam = Anthropic$1.Beta.BetaContextManagementConfig;
8
+ export type AnthropicMessageStreamEvent = Anthropic$1.MessageStreamEvent;
9
+ export type AnthropicRequestOptions = Anthropic$1.RequestOptions;
10
+ export type AnthropicToolChoice = {
11
11
  type: "tool";
12
12
  name: string;
13
13
  } | "any" | "auto" | "none" | string;
14
- type ChatAnthropicToolType = Anthropic$1.Messages.Tool | BindToolsInput;
15
- type ChatAnthropicOutputFormat = Anthropic$1.Messages.JSONOutputFormat;
16
- type AnthropicOutputConfig = Anthropic$1.Messages.OutputConfig;
17
- type AnthropicTextBlockParam = Anthropic$1.Messages.TextBlockParam;
18
- type AnthropicImageBlockParam = Anthropic$1.Messages.ImageBlockParam;
19
- type AnthropicToolUseBlockParam = Anthropic$1.Messages.ToolUseBlockParam;
20
- type AnthropicToolResultBlockParam = Anthropic$1.Messages.ToolResultBlockParam;
21
- type AnthropicDocumentBlockParam = Anthropic$1.Messages.DocumentBlockParam;
22
- type AnthropicThinkingBlockParam = Anthropic$1.Messages.ThinkingBlockParam;
23
- type AnthropicRedactedThinkingBlockParam = Anthropic$1.Messages.RedactedThinkingBlockParam;
24
- type AnthropicServerToolUseBlockParam = Anthropic$1.Messages.ServerToolUseBlockParam;
25
- type AnthropicWebSearchToolResultBlockParam = Anthropic$1.Messages.WebSearchToolResultBlockParam;
26
- type AnthropicWebSearchResultBlockParam = Anthropic$1.Messages.WebSearchResultBlockParam;
27
- type AnthropicSearchResultBlockParam = Anthropic$1.SearchResultBlockParam;
28
- type AnthropicContainerUploadBlockParam = Anthropic$1.Beta.BetaContainerUploadBlockParam;
29
- type AnthropicCompactionBlockParam = Anthropic$1.Beta.BetaCompactionBlockParam;
30
- type AnthropicMCPServerURLDefinition = Anthropic$1.Beta.Messages.BetaRequestMCPServerURLDefinition;
31
- type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam | AnthropicContainerUploadBlockParam | AnthropicCompactionBlockParam;
14
+ export type ChatAnthropicToolType = Anthropic$1.Messages.Tool | BindToolsInput;
15
+ export type ChatAnthropicOutputFormat = Anthropic$1.Messages.JSONOutputFormat;
16
+ export type AnthropicOutputConfig = Anthropic$1.Messages.OutputConfig;
17
+ export type AnthropicTextBlockParam = Anthropic$1.Messages.TextBlockParam;
18
+ export type AnthropicImageBlockParam = Anthropic$1.Messages.ImageBlockParam;
19
+ export type AnthropicToolUseBlockParam = Anthropic$1.Messages.ToolUseBlockParam;
20
+ export type AnthropicToolResultBlockParam = Anthropic$1.Messages.ToolResultBlockParam;
21
+ export type AnthropicDocumentBlockParam = Anthropic$1.Messages.DocumentBlockParam;
22
+ export type AnthropicThinkingBlockParam = Anthropic$1.Messages.ThinkingBlockParam;
23
+ export type AnthropicRedactedThinkingBlockParam = Anthropic$1.Messages.RedactedThinkingBlockParam;
24
+ export type AnthropicServerToolUseBlockParam = Anthropic$1.Messages.ServerToolUseBlockParam;
25
+ export type AnthropicWebSearchToolResultBlockParam = Anthropic$1.Messages.WebSearchToolResultBlockParam;
26
+ export type AnthropicWebSearchResultBlockParam = Anthropic$1.Messages.WebSearchResultBlockParam;
27
+ export type AnthropicSearchResultBlockParam = Anthropic$1.SearchResultBlockParam;
28
+ export type AnthropicContainerUploadBlockParam = Anthropic$1.Beta.BetaContainerUploadBlockParam;
29
+ export type AnthropicCompactionBlockParam = Anthropic$1.Beta.BetaCompactionBlockParam;
30
+ export type AnthropicMCPServerURLDefinition = Anthropic$1.Beta.Messages.BetaRequestMCPServerURLDefinition;
31
+ export type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam | AnthropicContainerUploadBlockParam | AnthropicCompactionBlockParam;
32
32
  /**
33
33
  * A type representing additional parameters that can be passed to the
34
34
  * Anthropic API.
35
35
  */
36
- type Kwargs = Record<string, any>;
37
- type AnthropicInvocationParams = Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages"> & Kwargs;
36
+ export type Kwargs = Record<string, any>;
37
+ export type AnthropicInvocationParams = Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages"> & Kwargs;
38
38
  //#endregion
39
- export { AnthropicCompactionBlockParam, AnthropicContainerUploadBlockParam, AnthropicContextManagementConfigParam, AnthropicDocumentBlockParam, AnthropicImageBlockParam, AnthropicInvocationParams, AnthropicMCPServerURLDefinition, AnthropicMessageCreateParams, AnthropicMessageStreamEvent, AnthropicOutputConfig, AnthropicRedactedThinkingBlockParam, AnthropicRequestOptions, AnthropicSearchResultBlockParam, AnthropicServerToolUseBlockParam, AnthropicStreamingMessageCreateParams, AnthropicTextBlockParam, AnthropicThinkingBlockParam, AnthropicThinkingConfigParam, AnthropicToolChoice, AnthropicToolResultBlockParam, AnthropicToolUseBlockParam, AnthropicWebSearchResultBlockParam, AnthropicWebSearchToolResultBlockParam, ChatAnthropicContentBlock, ChatAnthropicOutputFormat, ChatAnthropicToolType, Kwargs };
40
39
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAcY,+BACV,YAAU;KACA,wCACV,YAAU;KACA,+BAA+B,YAAU;KACzC,wCACV,YAAU,KAAK;KACL,8BAA8B,YAAU;KACxC,0BAA0B,YAAU;KACpC;EAEN;EACA;;KAMM,wBAAwB,YAAU,SAAS,OAAO;KAClD,4BAA4B,YAAU,SAAS;KAC/C,wBAAwB,YAAU,SAAS;KAE3C,0BAA0B,YAAU,SAAS;KAC7C,2BAA2B,YAAU,SAAS;KAC9C,6BAA6B,YAAU,SAAS;KAChD,gCACV,YAAU,SAAS;KACT,8BAA8B,YAAU,SAAS;KACjD,8BAA8B,YAAU,SAAS;KACjD,sCACV,YAAU,SAAS;KACT,mCACV,YAAU,SAAS;KACT,yCACV,YAAU,SAAS;KACT,qCACV,YAAU,SAAS;KACT,kCAAkC,YAAU;KAC5C,qCACV,YAAU,KAAK;KACL,gCACV,YAAU,KAAK;KACL,kCACV,YAAU,KAAK,SAAS;KAGd,4BACR,0BACA,2BACA,6BACA,gCACA,8BACA,8BACA,sCACA,mCACA,yCACA,qCACA,kCACA,qCACA;;;;;KAyEQ,SAAS;KAET,4BAA4B,KACtC,+BAA+B,qDAG/B"}
1
+ {"version":3,"file":"types.d.cts","names":["Anthropic"],"sources":["../src/types.ts"],"mappings":";;;YAcY,+BACVA,YAAU;YACA,wCACVA,YAAU;YACA,+BAA+BA,YAAU;YACzC,wCACVA,YAAU,KAAK;YACL,8BAA8BA,YAAU;YACxC,0BAA0BA,YAAU;YACpC;EAEN;EACA;;YAMM,wBAAwBA,YAAU,SAAS,OAAO;YAClD,4BAA4BA,YAAU,SAAS;YAC/C,wBAAwBA,YAAU,SAAS;YAE3C,0BAA0BA,YAAU,SAAS;YAC7C,2BAA2BA,YAAU,SAAS;YAC9C,6BAA6BA,YAAU,SAAS;YAChD,gCACVA,YAAU,SAAS;YACT,8BAA8BA,YAAU,SAAS;YACjD,8BAA8BA,YAAU,SAAS;YACjD,sCACVA,YAAU,SAAS;YACT,mCACVA,YAAU,SAAS;YACT,yCACVA,YAAU,SAAS;YACT,qCACVA,YAAU,SAAS;YACT,kCAAkCA,YAAU;YAC5C,qCACVA,YAAU,KAAK;YACL,gCACVA,YAAU,KAAK;YACL,kCACVA,YAAU,KAAK,SAAS;YAGd,4BACR,0BACA,2BACA,6BACA,gCACA,8BACA,8BACA,sCACA,mCACA,yCACA,qCACA,kCACA,qCACA;;;;;YAyEQ,SAAS;YAET,4BAA4B,KACtC,+BAA+B,qDAG/B"}
package/dist/types.d.ts CHANGED
@@ -1,40 +1,39 @@
1
1
  import Anthropic$1 from "@anthropic-ai/sdk";
2
2
  import { BindToolsInput } from "@langchain/core/language_models/chat_models";
3
3
  //#region src/types.d.ts
4
- type AnthropicMessageCreateParams = Anthropic$1.MessageCreateParamsNonStreaming;
5
- type AnthropicStreamingMessageCreateParams = Anthropic$1.MessageCreateParamsStreaming;
6
- type AnthropicThinkingConfigParam = Anthropic$1.ThinkingConfigParam;
7
- type AnthropicContextManagementConfigParam = Anthropic$1.Beta.BetaContextManagementConfig;
8
- type AnthropicMessageStreamEvent = Anthropic$1.MessageStreamEvent;
9
- type AnthropicRequestOptions = Anthropic$1.RequestOptions;
10
- type AnthropicToolChoice = {
4
+ export type AnthropicMessageCreateParams = Anthropic$1.MessageCreateParamsNonStreaming;
5
+ export type AnthropicStreamingMessageCreateParams = Anthropic$1.MessageCreateParamsStreaming;
6
+ export type AnthropicThinkingConfigParam = Anthropic$1.ThinkingConfigParam;
7
+ export type AnthropicContextManagementConfigParam = Anthropic$1.Beta.BetaContextManagementConfig;
8
+ export type AnthropicMessageStreamEvent = Anthropic$1.MessageStreamEvent;
9
+ export type AnthropicRequestOptions = Anthropic$1.RequestOptions;
10
+ export type AnthropicToolChoice = {
11
11
  type: "tool";
12
12
  name: string;
13
13
  } | "any" | "auto" | "none" | string;
14
- type ChatAnthropicToolType = Anthropic$1.Messages.Tool | BindToolsInput;
15
- type ChatAnthropicOutputFormat = Anthropic$1.Messages.JSONOutputFormat;
16
- type AnthropicOutputConfig = Anthropic$1.Messages.OutputConfig;
17
- type AnthropicTextBlockParam = Anthropic$1.Messages.TextBlockParam;
18
- type AnthropicImageBlockParam = Anthropic$1.Messages.ImageBlockParam;
19
- type AnthropicToolUseBlockParam = Anthropic$1.Messages.ToolUseBlockParam;
20
- type AnthropicToolResultBlockParam = Anthropic$1.Messages.ToolResultBlockParam;
21
- type AnthropicDocumentBlockParam = Anthropic$1.Messages.DocumentBlockParam;
22
- type AnthropicThinkingBlockParam = Anthropic$1.Messages.ThinkingBlockParam;
23
- type AnthropicRedactedThinkingBlockParam = Anthropic$1.Messages.RedactedThinkingBlockParam;
24
- type AnthropicServerToolUseBlockParam = Anthropic$1.Messages.ServerToolUseBlockParam;
25
- type AnthropicWebSearchToolResultBlockParam = Anthropic$1.Messages.WebSearchToolResultBlockParam;
26
- type AnthropicWebSearchResultBlockParam = Anthropic$1.Messages.WebSearchResultBlockParam;
27
- type AnthropicSearchResultBlockParam = Anthropic$1.SearchResultBlockParam;
28
- type AnthropicContainerUploadBlockParam = Anthropic$1.Beta.BetaContainerUploadBlockParam;
29
- type AnthropicCompactionBlockParam = Anthropic$1.Beta.BetaCompactionBlockParam;
30
- type AnthropicMCPServerURLDefinition = Anthropic$1.Beta.Messages.BetaRequestMCPServerURLDefinition;
31
- type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam | AnthropicContainerUploadBlockParam | AnthropicCompactionBlockParam;
14
+ export type ChatAnthropicToolType = Anthropic$1.Messages.Tool | BindToolsInput;
15
+ export type ChatAnthropicOutputFormat = Anthropic$1.Messages.JSONOutputFormat;
16
+ export type AnthropicOutputConfig = Anthropic$1.Messages.OutputConfig;
17
+ export type AnthropicTextBlockParam = Anthropic$1.Messages.TextBlockParam;
18
+ export type AnthropicImageBlockParam = Anthropic$1.Messages.ImageBlockParam;
19
+ export type AnthropicToolUseBlockParam = Anthropic$1.Messages.ToolUseBlockParam;
20
+ export type AnthropicToolResultBlockParam = Anthropic$1.Messages.ToolResultBlockParam;
21
+ export type AnthropicDocumentBlockParam = Anthropic$1.Messages.DocumentBlockParam;
22
+ export type AnthropicThinkingBlockParam = Anthropic$1.Messages.ThinkingBlockParam;
23
+ export type AnthropicRedactedThinkingBlockParam = Anthropic$1.Messages.RedactedThinkingBlockParam;
24
+ export type AnthropicServerToolUseBlockParam = Anthropic$1.Messages.ServerToolUseBlockParam;
25
+ export type AnthropicWebSearchToolResultBlockParam = Anthropic$1.Messages.WebSearchToolResultBlockParam;
26
+ export type AnthropicWebSearchResultBlockParam = Anthropic$1.Messages.WebSearchResultBlockParam;
27
+ export type AnthropicSearchResultBlockParam = Anthropic$1.SearchResultBlockParam;
28
+ export type AnthropicContainerUploadBlockParam = Anthropic$1.Beta.BetaContainerUploadBlockParam;
29
+ export type AnthropicCompactionBlockParam = Anthropic$1.Beta.BetaCompactionBlockParam;
30
+ export type AnthropicMCPServerURLDefinition = Anthropic$1.Beta.Messages.BetaRequestMCPServerURLDefinition;
31
+ export type ChatAnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam | AnthropicSearchResultBlockParam | AnthropicContainerUploadBlockParam | AnthropicCompactionBlockParam;
32
32
  /**
33
33
  * A type representing additional parameters that can be passed to the
34
34
  * Anthropic API.
35
35
  */
36
- type Kwargs = Record<string, any>;
37
- type AnthropicInvocationParams = Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages"> & Kwargs;
36
+ export type Kwargs = Record<string, any>;
37
+ export type AnthropicInvocationParams = Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages"> & Kwargs;
38
38
  //#endregion
39
- export { AnthropicCompactionBlockParam, AnthropicContainerUploadBlockParam, AnthropicContextManagementConfigParam, AnthropicDocumentBlockParam, AnthropicImageBlockParam, AnthropicInvocationParams, AnthropicMCPServerURLDefinition, AnthropicMessageCreateParams, AnthropicMessageStreamEvent, AnthropicOutputConfig, AnthropicRedactedThinkingBlockParam, AnthropicRequestOptions, AnthropicSearchResultBlockParam, AnthropicServerToolUseBlockParam, AnthropicStreamingMessageCreateParams, AnthropicTextBlockParam, AnthropicThinkingBlockParam, AnthropicThinkingConfigParam, AnthropicToolChoice, AnthropicToolResultBlockParam, AnthropicToolUseBlockParam, AnthropicWebSearchResultBlockParam, AnthropicWebSearchToolResultBlockParam, ChatAnthropicContentBlock, ChatAnthropicOutputFormat, ChatAnthropicToolType, Kwargs };
40
39
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;KAcY,+BACV,YAAU;KACA,wCACV,YAAU;KACA,+BAA+B,YAAU;KACzC,wCACV,YAAU,KAAK;KACL,8BAA8B,YAAU;KACxC,0BAA0B,YAAU;KACpC;EAEN;EACA;;KAMM,wBAAwB,YAAU,SAAS,OAAO;KAClD,4BAA4B,YAAU,SAAS;KAC/C,wBAAwB,YAAU,SAAS;KAE3C,0BAA0B,YAAU,SAAS;KAC7C,2BAA2B,YAAU,SAAS;KAC9C,6BAA6B,YAAU,SAAS;KAChD,gCACV,YAAU,SAAS;KACT,8BAA8B,YAAU,SAAS;KACjD,8BAA8B,YAAU,SAAS;KACjD,sCACV,YAAU,SAAS;KACT,mCACV,YAAU,SAAS;KACT,yCACV,YAAU,SAAS;KACT,qCACV,YAAU,SAAS;KACT,kCAAkC,YAAU;KAC5C,qCACV,YAAU,KAAK;KACL,gCACV,YAAU,KAAK;KACL,kCACV,YAAU,KAAK,SAAS;KAGd,4BACR,0BACA,2BACA,6BACA,gCACA,8BACA,8BACA,sCACA,mCACA,yCACA,qCACA,kCACA,qCACA;;;;;KAyEQ,SAAS;KAET,4BAA4B,KACtC,+BAA+B,qDAG/B"}
1
+ {"version":3,"file":"types.d.ts","names":["Anthropic"],"sources":["../src/types.ts"],"mappings":";;;YAcY,+BACVA,YAAU;YACA,wCACVA,YAAU;YACA,+BAA+BA,YAAU;YACzC,wCACVA,YAAU,KAAK;YACL,8BAA8BA,YAAU;YACxC,0BAA0BA,YAAU;YACpC;EAEN;EACA;;YAMM,wBAAwBA,YAAU,SAAS,OAAO;YAClD,4BAA4BA,YAAU,SAAS;YAC/C,wBAAwBA,YAAU,SAAS;YAE3C,0BAA0BA,YAAU,SAAS;YAC7C,2BAA2BA,YAAU,SAAS;YAC9C,6BAA6BA,YAAU,SAAS;YAChD,gCACVA,YAAU,SAAS;YACT,8BAA8BA,YAAU,SAAS;YACjD,8BAA8BA,YAAU,SAAS;YACjD,sCACVA,YAAU,SAAS;YACT,mCACVA,YAAU,SAAS;YACT,yCACVA,YAAU,SAAS;YACT,qCACVA,YAAU,SAAS;YACT,kCAAkCA,YAAU;YAC5C,qCACVA,YAAU,KAAK;YACL,gCACVA,YAAU,KAAK;YACL,kCACVA,YAAU,KAAK,SAAS;YAGd,4BACR,0BACA,2BACA,6BACA,gCACA,8BACA,8BACA,sCACA,mCACA,yCACA,qCACA,kCACA,qCACA;;;;;YAyEQ,SAAS;YAET,4BAA4B,KACtC,+BAA+B,qDAG/B"}
@@ -191,23 +191,41 @@ function _formatContent(message, toolCalls) {
191
191
  if (typeof content === "string") return content;
192
192
  else return Array.from(_formatContentBlocks(content, toolCalls));
193
193
  }
194
+ const TOOL_CHANGE_BLOCK_TYPES = ["tool_addition", "tool_removal"];
195
+ /**
196
+ * Returns the provider payload a block carries: the `value` of a
197
+ * `non_standard` wrapper, or the block itself.
198
+ */
199
+ function _unwrapNonStandard(block) {
200
+ if (block.type === "non_standard" && "value" in block && typeof block.value === "object" && block.value !== null) return block.value;
201
+ return block;
202
+ }
194
203
  /**
195
204
  * Normalizes the content of a system message for the wire.
196
205
  *
197
206
  * Shared by the hoisted top-level `system` field and by in-place
198
207
  * `role: "system"` entries, so both strip the same framework-internal fields.
208
+ *
209
+ * Blocks wrapped in core's `non_standard` escape hatch are unwrapped first, so
210
+ * a provider-native block behaves the same whichever way it was written.
199
211
  */
200
212
  function _formatSystemContent(content) {
201
213
  if (typeof content === "string") return content;
202
214
  if (!Array.isArray(content)) return [];
203
- return content.map((block) => {
204
- if (block.type !== "text" || typeof block.text !== "string") return block;
205
- return {
215
+ return content.flatMap((rawBlock) => {
216
+ if (typeof rawBlock !== "object" || rawBlock === null) return [{
217
+ type: "text",
218
+ text: String(rawBlock)
219
+ }];
220
+ const block = _unwrapNonStandard(rawBlock);
221
+ if (TOOL_CHANGE_BLOCK_TYPES.includes(block.type)) return [block];
222
+ if (block.type === "text" && typeof block.text === "string") return [{
206
223
  type: "text",
207
224
  text: block.text,
208
225
  ..."cache_control" in block && block.cache_control ? { cache_control: block.cache_control } : {},
209
226
  ..."citations" in block && block.citations ? { citations: block.citations } : {}
210
- };
227
+ }];
228
+ return [];
211
229
  });
212
230
  }
213
231
  /**
@@ -229,6 +247,7 @@ function _convertMessagesToAnthropicPayload(messages) {
229
247
  text: content
230
248
  }] : content;
231
249
  });
250
+ if (Array.isArray(system) && system.length === 0) system = void 0;
232
251
  return {
233
252
  messages: mergeMessages(mergedMessages.slice(leadingSystemCount).map((message) => {
234
253
  let role;
@@ -267,18 +286,35 @@ function _convertMessagesToAnthropicPayload(messages) {
267
286
  content: [...formattedContentArr, ...missingToolCalls.map(_convertLangChainToolCallToAnthropic)]
268
287
  };
269
288
  }
270
- } else if (role === "system") return {
271
- role,
272
- content: _formatSystemContent(message.content)
273
- };
274
- else return {
289
+ } else if (role === "system") {
290
+ const content = _formatSystemContent(message.content);
291
+ return Array.isArray(content) && content.length === 0 ? void 0 : {
292
+ role,
293
+ content
294
+ };
295
+ } else return {
275
296
  role,
276
297
  content: _formatContent(message, _langchain_core_messages.AIMessage.isInstance(message) ? message.tool_calls : void 0)
277
298
  };
278
- })),
299
+ }).filter((message) => message !== void 0)),
279
300
  system
280
301
  };
281
302
  }
303
+ /**
304
+ * Describes the tool changes in the system content of a converted payload:
305
+ * `"inline"` if any `tool_addition` block defines a tool by value,
306
+ * `"reference"` if tool changes only name tools declared elsewhere, or
307
+ * `undefined` if there are none. The provider requires a different beta for
308
+ * each.
309
+ *
310
+ * Reads the converted payload rather than the input messages, so a block that
311
+ * was dropped during conversion never enables a beta.
312
+ */
313
+ function _getToolChangeKind(payload) {
314
+ const toolChanges = [payload.system, ...payload.messages.filter((message) => message.role === "system").map((message) => message.content)].flatMap((content) => Array.isArray(content) ? content.filter((block) => TOOL_CHANGE_BLOCK_TYPES.includes(block.type)) : []);
315
+ if (toolChanges.some((block) => block.tool?.type === "tool_definition")) return "inline";
316
+ return toolChanges.length > 0 ? "reference" : void 0;
317
+ }
282
318
  function mergeMessages(messages) {
283
319
  if (!messages || messages.length <= 1) return messages;
284
320
  const result = [];
@@ -312,5 +348,6 @@ function mergeMessages(messages) {
312
348
  //#endregion
313
349
  exports._convertLangChainToolCallToAnthropic = _convertLangChainToolCallToAnthropic;
314
350
  exports._convertMessagesToAnthropicPayload = _convertMessagesToAnthropicPayload;
351
+ exports._getToolChangeKind = _getToolChangeKind;
315
352
 
316
353
  //# sourceMappingURL=message_inputs.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"message_inputs.cjs","names":["parseBase64DataUrl","HumanMessage","isDataContentBlock","convertToProviderContentBlock","standardContentBlockConverter","_isAnthropicImageBlockParam","_isAnthropicThinkingBlock","_isAnthropicRedactedThinkingBlock","_isAnthropicCompactionBlock","_isAnthropicSearchResultBlock","AIMessage","_formatStandardContent"],"sources":["../../src/utils/message_inputs.ts"],"sourcesContent":["/**\n * This util file contains functions for converting LangChain messages to Anthropic messages.\n */\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n type BaseMessage,\n HumanMessage,\n ToolMessage,\n MessageContentComplex,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n ContentBlock,\n AIMessage,\n} from \"@langchain/core/messages\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n AnthropicMessageCreateParams,\n AnthropicTextBlockParam,\n AnthropicThinkingBlockParam,\n AnthropicRedactedThinkingBlockParam,\n AnthropicSearchResultBlockParam,\n AnthropicToolResponse,\n AnthropicContainerUploadBlockParam,\n AnthropicCompactionBlockParam,\n} from \"../types.js\";\nimport {\n _isAnthropicImageBlockParam,\n _isAnthropicRedactedThinkingBlock,\n _isAnthropicSearchResultBlock,\n _isAnthropicThinkingBlock,\n _isAnthropicCompactionBlock,\n standardContentBlockConverter,\n} from \"./content.js\";\nimport { _formatStandardContent } from \"./standard.js\";\n\nfunction _formatImage(imageUrl: string) {\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\n if (parsed) {\n return {\n type: \"base64\",\n media_type: parsed.mime_type,\n data: parsed.data,\n };\n }\n let parsedUrl: URL;\n\n try {\n parsedUrl = new URL(imageUrl);\n } catch {\n throw new Error(\n [\n `Malformed image URL: ${JSON.stringify(\n imageUrl\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n }\n\n if (parsedUrl.protocol === \"http:\" || parsedUrl.protocol === \"https:\") {\n return {\n type: \"url\",\n url: imageUrl,\n };\n }\n\n throw new Error(\n [\n `Invalid image URL protocol: ${JSON.stringify(\n parsedUrl.protocol\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n}\n\nfunction _ensureMessageContents(messages: BaseMessage[]): BaseMessage[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs = [];\n for (const message of messages) {\n if (message._getType() === \"tool\") {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n (previousMessage.content as MessageContentComplex[]).push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n // rare case: message.content could be undefined\n ...(message.content != null\n ? { content: _formatContent(message) }\n : {}),\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(message);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n): AnthropicToolResponse {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction* _formatContentBlocks(\n content: ContentBlock[],\n toolCalls?: ToolCall[]\n): Generator<Anthropic.Beta.BetaContentBlockParam> {\n const toolTypes = [\n \"bash_code_execution_tool_result\",\n \"input_json_delta\",\n \"server_tool_use\",\n \"text_editor_code_execution_tool_result\",\n \"tool_result\",\n \"tool_search_tool_result\",\n \"tool_search_tool_bm25_tool_result\",\n \"tool_search_tool_regex_tool_result\",\n \"tool_use\",\n \"web_search_result\",\n \"web_search_tool_result\",\n ];\n const textTypes = [\"text\", \"text_delta\"];\n for (const contentPart of content) {\n if (isDataContentBlock(contentPart)) {\n yield convertToProviderContentBlock(\n contentPart,\n standardContentBlockConverter\n );\n }\n\n const cacheControl =\n \"cache_control\" in contentPart\n ? (contentPart.cache_control as Anthropic.Beta.BetaCacheControlEphemeral)\n : undefined;\n\n if (contentPart.type === \"image_url\") {\n let source;\n if (typeof contentPart.image_url === \"string\") {\n source = _formatImage(contentPart.image_url);\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n source = _formatImage(contentPart.image_url.url);\n }\n if (source) {\n yield {\n type: \"image\" as const, // Explicitly setting the type as \"image\"\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (_isAnthropicImageBlockParam(contentPart)) {\n yield contentPart;\n } else if (contentPart.type === \"image\") {\n // Handle new ContentBlock.Multimodal.Image format\n let source;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // URL-based image\n source = _formatImage(contentPart.url);\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // oxlint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // Base64-based image\n const mimeType =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n source = {\n type: \"base64\" as const,\n media_type: mimeType as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID-based image\n // Note: Anthropic supports file IDs for images that have been uploaded\n // to their servers via the Files API\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"image\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (contentPart.type === \"file\") {\n // Handle new ContentBlock.Multimodal.File format\n let source:\n | { type: \"url\"; url: string }\n | { type: \"base64\"; media_type: string; data: string }\n | { type: \"file\"; file_id: string }\n | undefined;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // File with URL\n source = {\n type: \"url\" as const,\n url: contentPart.url,\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // oxlint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // File with base64 data (string or Uint8Array)\n const media_type =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"application/pdf\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n\n source = {\n type: \"base64\" as const,\n media_type,\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID from Anthropic Files API\n // https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-3-files-api\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"document\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n } else if (contentPart.type === \"document\") {\n // PDF\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (_isAnthropicThinkingBlock(contentPart)) {\n const block: AnthropicThinkingBlockParam = {\n type: \"thinking\" as const, // Explicitly setting the type as \"thinking\"\n thinking: contentPart.thinking,\n signature: contentPart.signature,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicRedactedThinkingBlock(contentPart)) {\n const block: AnthropicRedactedThinkingBlockParam = {\n type: \"redacted_thinking\" as const, // Explicitly setting the type as \"redacted_thinking\"\n data: contentPart.data,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicCompactionBlock(contentPart)) {\n const block: AnthropicCompactionBlockParam = {\n type: \"compaction\" as const,\n content: contentPart.content,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicSearchResultBlock(contentPart)) {\n const block: AnthropicSearchResultBlockParam = {\n type: \"search_result\" as const, // Explicitly setting the type as \"search_result\"\n title: contentPart.title,\n source: contentPart.source,\n ...(\"cache_control\" in contentPart && contentPart.cache_control\n ? { cache_control: contentPart.cache_control }\n : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n content: contentPart.content,\n };\n yield block as Anthropic.Beta.BetaSearchResultBlockParam;\n } else if (\n textTypes.find((t) => t === contentPart.type) &&\n \"text\" in contentPart\n ) {\n // Assuming contentPart is of type MessageContentText here\n yield {\n type: \"text\" as const, // Explicitly setting the type as \"text\"\n text: contentPart.text,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n } else if (toolTypes.find((t) => t === contentPart.type)) {\n const contentPartCopy = { ...contentPart };\n\n if (contentPartCopy.type === \"input_json_delta\") {\n // `input_json_delta` type only represents yielding partial tool inputs\n // and is not a valid type for Anthropic messages.\n // These blocks appear in streaming responses and should be skipped\n // as their input data is already captured in tool_calls.\n continue;\n }\n\n if (\n contentPartCopy.type === \"tool_use\" &&\n typeof contentPartCopy.input === \"string\"\n ) {\n // First, try to get the input from the corresponding tool_call.\n // This is the most reliable source since tool_calls are properly\n // consolidated from tool_call_chunks during streaming.\n const matchingToolCall = toolCalls?.find(\n (tc) => tc.id === contentPartCopy.id\n );\n if (matchingToolCall) {\n contentPartCopy.input = matchingToolCall.args;\n } else {\n // Fallback: `tool_use` content part may be followed by `input_json_delta`\n // content parts which are chunks of a stringified JSON input,\n // so we need to collect them and merge their inputs.\n const inputDeltas = content.filter(\n (nestedContentPart) =>\n nestedContentPart.index === contentPartCopy.index &&\n nestedContentPart.type === \"input_json_delta\" &&\n typeof nestedContentPart.input === \"string\"\n );\n // If no `input_json_delta` parts are found, this line will just\n // return `contentPartCopy.input`, so no additional check is needed\n contentPartCopy.input = inputDeltas.reduce(\n (accumulator, nestedContentPart) =>\n accumulator + nestedContentPart.input,\n contentPartCopy.input\n );\n }\n }\n\n if (\"index\" in contentPartCopy) {\n // Anthropic does not support passing the index field here, so we remove it.\n delete contentPartCopy.index;\n }\n\n if (\"input\" in contentPartCopy) {\n // Anthropic tool use inputs should be valid objects, when applicable.\n if (typeof contentPartCopy.input === \"string\") {\n try {\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\n } catch {\n contentPartCopy.input = {};\n }\n }\n }\n // TODO: Fix when SDK types are fixed\n yield {\n ...contentPartCopy,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n } else if (contentPart.type === \"container_upload\") {\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as AnthropicContainerUploadBlockParam;\n }\n\n // Note that we are intentionally dropping any blocks that we don't\n // recognize. This is to allow for cross-compatibility between different\n // providers that may have different block types. Ie if we take a message\n // output from OpenAI and send it to Anthropic, we want to drop any blocks\n // that Anthropic doesn't understand.\n }\n}\n\nfunction _formatContent(message: BaseMessage, toolCalls?: ToolCall[]) {\n const { content } = message;\n\n if (typeof content === \"string\") {\n return content;\n } else {\n return Array.from(_formatContentBlocks(content, toolCalls));\n }\n}\n\n/**\n * Normalizes the content of a system message for the wire.\n *\n * Shared by the hoisted top-level `system` field and by in-place\n * `role: \"system\"` entries, so both strip the same framework-internal fields.\n */\nfunction _formatSystemContent(\n content: BaseMessage[\"content\"]\n): string | Anthropic.Messages.ContentBlockParam[] {\n if (typeof content === \"string\") {\n return content;\n }\n if (!Array.isArray(content)) {\n // rare case: message.content could be undefined\n return [];\n }\n return content.map((block) => {\n if (block.type !== \"text\" || typeof block.text !== \"string\") {\n return block as Anthropic.Messages.ContentBlockParam;\n }\n return {\n type: \"text\" as const,\n text: block.text,\n ...(\"cache_control\" in block && block.cache_control\n ? {\n cache_control:\n block.cache_control as AnthropicTextBlockParam[\"cache_control\"],\n }\n : {}),\n ...(\"citations\" in block && block.citations\n ? {\n citations: block.citations as AnthropicTextBlockParam[\"citations\"],\n }\n : {}),\n };\n });\n}\n\n/**\n * Formats messages as a prompt for the model.\n * Used in LangSmith, export is important here.\n * @param messages The base messages to format as a prompt.\n * @returns The formatted prompt.\n */\nexport function _convertMessagesToAnthropicPayload(\n messages: BaseMessage[]\n): AnthropicMessageCreateParams {\n const mergedMessages = _ensureMessageContents(messages);\n\n // The contiguous run of system messages starting at index 0 is hoisted into\n // the top-level `system` field. Every other system message keeps its\n // position and is sent as a `role: \"system\"` entry, which the provider\n // applies from that point in the conversation onwards. The run is identified\n // after tool-message folding, because that is the sequence the provider sees.\n let leadingSystemCount = 0;\n while (\n leadingSystemCount < mergedMessages.length &&\n mergedMessages[leadingSystemCount]._getType() === \"system\"\n ) {\n leadingSystemCount += 1;\n }\n\n let system: string | Anthropic.Messages.ContentBlockParam[] | undefined;\n if (leadingSystemCount === 1) {\n system = _formatSystemContent(mergedMessages[0].content);\n } else if (leadingSystemCount > 1) {\n system = mergedMessages.slice(0, leadingSystemCount).flatMap((message) => {\n const content = _formatSystemContent(message.content);\n return typeof content === \"string\"\n ? [{ type: \"text\" as const, text: content }]\n : content;\n });\n }\n\n const conversationMessages = mergedMessages.slice(leadingSystemCount);\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n role = \"system\" as const;\n } else {\n throw new Error(`Message type \"${message.type}\" is not supported.`);\n }\n if (\n AIMessage.isInstance(message) &&\n message.response_metadata?.output_version === \"v1\"\n ) {\n return {\n role,\n content: _formatStandardContent(message),\n };\n }\n if (AIMessage.isInstance(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const { content } = message;\n const formattedContent = _formatContent(message, message.tool_calls);\n const formattedContentArr = Array.isArray(formattedContent)\n ? formattedContent\n : [{ type: \"text\" as const, text: formattedContent }];\n const missingToolCalls = message.tool_calls.filter(\n (toolCall) =>\n !content.find(\n (contentPart) =>\n (contentPart.type === \"tool_use\" ||\n contentPart.type === \"input_json_delta\" ||\n contentPart.type === \"server_tool_use\") &&\n contentPart.id === toolCall.id\n )\n );\n return {\n role,\n content: [\n ...formattedContentArr,\n ...missingToolCalls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else if (role === \"system\") {\n return { role, content: _formatSystemContent(message.content) };\n } else {\n return {\n role,\n content: _formatContent(\n message,\n AIMessage.isInstance(message) ? message.tool_calls : undefined\n ),\n };\n }\n });\n return {\n messages: mergeMessages(\n formattedMessages as AnthropicMessageCreateParams[\"messages\"]\n ),\n system,\n } as AnthropicMessageCreateParams;\n}\n\nfunction mergeMessages(messages: AnthropicMessageCreateParams[\"messages\"]) {\n if (!messages || messages.length <= 1) {\n return messages;\n }\n\n const result: AnthropicMessageCreateParams[\"messages\"] = [];\n let currentMessage = messages[0];\n\n const normalizeContent = (\n content: string | Array<Anthropic.Messages.ContentBlockParam>\n ): Array<Anthropic.Messages.ContentBlockParam> => {\n if (typeof content === \"string\") {\n return [\n {\n type: \"text\",\n text: content,\n },\n ];\n }\n return content;\n };\n\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\n if (msg.role !== \"user\") return false;\n\n if (typeof msg.content === \"string\") {\n return false;\n }\n\n return (\n Array.isArray(msg.content) &&\n msg.content.every((item) => item.type === \"tool_result\")\n );\n };\n\n for (let i = 1; i < messages.length; i += 1) {\n const nextMessage = messages[i];\n\n if (\n isToolResultMessage(currentMessage) &&\n isToolResultMessage(nextMessage)\n ) {\n // Merge the messages by combining their content arrays\n currentMessage = {\n ...currentMessage,\n content: [\n ...normalizeContent(currentMessage.content),\n ...normalizeContent(nextMessage.content),\n ],\n };\n } else {\n result.push(currentMessage);\n currentMessage = nextMessage;\n }\n }\n\n result.push(currentMessage);\n return result;\n}\n"],"mappings":";;;;AAoCA,SAAS,aAAa,UAAkB;CACtC,MAAM,UAAA,GAASA,yBAAAA,mBAAAA,CAAmB,EAAE,SAAS,SAAS,CAAC;CACvD,IAAI,QACF,OAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,MAAM,OAAO;CACf;CAEF,IAAI;CAEJ,IAAI;EACF,YAAY,IAAI,IAAI,QAAQ;CAC9B,QAAQ;EACN,MAAM,IAAI,MACR;GACE,wBAAwB,KAAK,UAC3B,QACF,EAAE;GACF;GACA;EACF,CAAC,CAAC,KAAK,MAAM,CACf;CACF;CAEA,IAAI,UAAU,aAAa,WAAW,UAAU,aAAa,UAC3D,OAAO;EACL,MAAM;EACN,KAAK;CACP;CAGF,MAAM,IAAI,MACR;EACE,+BAA+B,KAAK,UAClC,UAAU,QACZ,EAAE;EACF;EACA;CACF,CAAC,CAAC,KAAK,MAAM,CACf;AACF;AAEA,SAAS,uBAAuB,UAAwC;CAEtE,MAAM,cAAc,CAAC;CACrB,KAAK,MAAM,WAAW,UACpB,IAAI,QAAQ,SAAS,MAAM,QAAQ;EACjC,IAAI,OAAO,QAAQ,YAAY,UAAU;GACvC,MAAM,kBAAkB,YAAY,YAAY,SAAS;GACzD,IACE,iBAAiB,SAAS,MAAM,WAChC,MAAM,QAAQ,gBAAgB,OAAO,KACrC,UAAU,gBAAgB,QAAQ,MAClC,gBAAgB,QAAQ,EAAE,CAAC,SAAS,eAGpC,gBAAiB,QAAoC,KAAK;IACxD,MAAM;IACN,SAAS,QAAQ;IACjB,aAAc,QAAwB;GACxC,CAAC;QAGD,YAAY,KACV,IAAIC,yB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K,cAAc;GAC1B,iBAAiB;EACnB;CACF;CAEA,OAAO,KAAK,cAAc;CAC1B,OAAO;AACT"}
1
+ {"version":3,"file":"message_inputs.cjs","names":["parseBase64DataUrl","HumanMessage","isDataContentBlock","convertToProviderContentBlock","standardContentBlockConverter","_isAnthropicImageBlockParam","_isAnthropicThinkingBlock","_isAnthropicRedactedThinkingBlock","_isAnthropicCompactionBlock","_isAnthropicSearchResultBlock","AIMessage","_formatStandardContent"],"sources":["../../src/utils/message_inputs.ts"],"sourcesContent":["/**\n * This util file contains functions for converting LangChain messages to Anthropic messages.\n */\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport {\n type BaseMessage,\n HumanMessage,\n ToolMessage,\n MessageContentComplex,\n isDataContentBlock,\n convertToProviderContentBlock,\n parseBase64DataUrl,\n ContentBlock,\n AIMessage,\n} from \"@langchain/core/messages\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n AnthropicMessageCreateParams,\n AnthropicTextBlockParam,\n AnthropicThinkingBlockParam,\n AnthropicRedactedThinkingBlockParam,\n AnthropicSearchResultBlockParam,\n AnthropicToolResponse,\n AnthropicContainerUploadBlockParam,\n AnthropicCompactionBlockParam,\n} from \"../types.js\";\nimport {\n _isAnthropicImageBlockParam,\n _isAnthropicRedactedThinkingBlock,\n _isAnthropicSearchResultBlock,\n _isAnthropicThinkingBlock,\n _isAnthropicCompactionBlock,\n standardContentBlockConverter,\n} from \"./content.js\";\nimport { _formatStandardContent } from \"./standard.js\";\n\nfunction _formatImage(imageUrl: string) {\n const parsed = parseBase64DataUrl({ dataUrl: imageUrl });\n if (parsed) {\n return {\n type: \"base64\",\n media_type: parsed.mime_type,\n data: parsed.data,\n };\n }\n let parsedUrl: URL;\n\n try {\n parsedUrl = new URL(imageUrl);\n } catch {\n throw new Error(\n [\n `Malformed image URL: ${JSON.stringify(\n imageUrl\n )}. Content blocks of type 'image_url' must be a valid http, https, or base64-encoded data URL.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n }\n\n if (parsedUrl.protocol === \"http:\" || parsedUrl.protocol === \"https:\") {\n return {\n type: \"url\",\n url: imageUrl,\n };\n }\n\n throw new Error(\n [\n `Invalid image URL protocol: ${JSON.stringify(\n parsedUrl.protocol\n )}. Anthropic only supports images as http, https, or base64-encoded data URLs on 'image_url' content blocks.`,\n \"Example: data:image/png;base64,/9j/4AAQSk...\",\n \"Example: https://example.com/image.jpg\",\n ].join(\"\\n\\n\")\n );\n}\n\nfunction _ensureMessageContents(messages: BaseMessage[]): BaseMessage[] {\n // Merge runs of human/tool messages into single human messages with content blocks.\n const updatedMsgs = [];\n for (const message of messages) {\n if (message._getType() === \"tool\") {\n if (typeof message.content === \"string\") {\n const previousMessage = updatedMsgs[updatedMsgs.length - 1];\n if (\n previousMessage?._getType() === \"human\" &&\n Array.isArray(previousMessage.content) &&\n \"type\" in previousMessage.content[0] &&\n previousMessage.content[0].type === \"tool_result\"\n ) {\n // If the previous message was a tool result, we merge this tool message into it.\n (previousMessage.content as MessageContentComplex[]).push({\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n });\n } else {\n // If not, we create a new human message with the tool result.\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n content: message.content,\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(\n new HumanMessage({\n content: [\n {\n type: \"tool_result\",\n // rare case: message.content could be undefined\n ...(message.content != null\n ? { content: _formatContent(message) }\n : {}),\n tool_use_id: (message as ToolMessage).tool_call_id,\n },\n ],\n })\n );\n }\n } else {\n updatedMsgs.push(message);\n }\n }\n return updatedMsgs;\n}\n\nexport function _convertLangChainToolCallToAnthropic(\n toolCall: ToolCall\n): AnthropicToolResponse {\n if (toolCall.id === undefined) {\n throw new Error(`Anthropic requires all tool calls to have an \"id\".`);\n }\n return {\n type: \"tool_use\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.args,\n };\n}\n\nfunction* _formatContentBlocks(\n content: ContentBlock[],\n toolCalls?: ToolCall[]\n): Generator<Anthropic.Beta.BetaContentBlockParam> {\n const toolTypes = [\n \"bash_code_execution_tool_result\",\n \"input_json_delta\",\n \"server_tool_use\",\n \"text_editor_code_execution_tool_result\",\n \"tool_result\",\n \"tool_search_tool_result\",\n \"tool_search_tool_bm25_tool_result\",\n \"tool_search_tool_regex_tool_result\",\n \"tool_use\",\n \"web_search_result\",\n \"web_search_tool_result\",\n ];\n const textTypes = [\"text\", \"text_delta\"];\n for (const contentPart of content) {\n if (isDataContentBlock(contentPart)) {\n yield convertToProviderContentBlock(\n contentPart,\n standardContentBlockConverter\n );\n }\n\n const cacheControl =\n \"cache_control\" in contentPart\n ? (contentPart.cache_control as Anthropic.Beta.BetaCacheControlEphemeral)\n : undefined;\n\n if (contentPart.type === \"image_url\") {\n let source;\n if (typeof contentPart.image_url === \"string\") {\n source = _formatImage(contentPart.image_url);\n } else if (\n typeof contentPart.image_url === \"object\" &&\n contentPart.image_url !== null &&\n \"url\" in contentPart.image_url &&\n typeof contentPart.image_url.url === \"string\"\n ) {\n source = _formatImage(contentPart.image_url.url);\n }\n if (source) {\n yield {\n type: \"image\" as const, // Explicitly setting the type as \"image\"\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (_isAnthropicImageBlockParam(contentPart)) {\n yield contentPart;\n } else if (contentPart.type === \"image\") {\n // Handle new ContentBlock.Multimodal.Image format\n let source;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // URL-based image\n source = _formatImage(contentPart.url);\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // oxlint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // Base64-based image\n const mimeType =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"image/jpeg\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n source = {\n type: \"base64\" as const,\n media_type: mimeType as\n | \"image/jpeg\"\n | \"image/png\"\n | \"image/gif\"\n | \"image/webp\",\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID-based image\n // Note: Anthropic supports file IDs for images that have been uploaded\n // to their servers via the Files API\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"image\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.ImageBlockParam;\n }\n } else if (contentPart.type === \"file\") {\n // Handle new ContentBlock.Multimodal.File format\n let source:\n | { type: \"url\"; url: string }\n | { type: \"base64\"; media_type: string; data: string }\n | { type: \"file\"; file_id: string }\n | undefined;\n\n if (\"url\" in contentPart && typeof contentPart.url === \"string\") {\n // File with URL\n source = {\n type: \"url\" as const,\n url: contentPart.url,\n };\n } else if (\n \"data\" in contentPart &&\n (typeof contentPart.data === \"string\" ||\n // oxlint-disable-next-line no-instanceof/no-instanceof\n contentPart.data instanceof Uint8Array)\n ) {\n // File with base64 data (string or Uint8Array)\n const media_type =\n \"mimeType\" in contentPart && typeof contentPart.mimeType === \"string\"\n ? contentPart.mimeType\n : \"application/pdf\";\n const data =\n typeof contentPart.data === \"string\"\n ? contentPart.data\n : Buffer.from(contentPart.data).toString(\"base64\");\n\n source = {\n type: \"base64\" as const,\n media_type,\n data,\n };\n } else if (\n \"fileId\" in contentPart &&\n typeof contentPart.fileId === \"string\"\n ) {\n // File ID from Anthropic Files API\n // https://platform.claude.com/docs/en/build-with-claude/pdf-support#option-3-files-api\n source = {\n type: \"file\" as const,\n file_id: contentPart.fileId,\n };\n }\n\n if (source) {\n yield {\n type: \"document\" as const,\n source,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n }\n } else if (contentPart.type === \"document\") {\n // PDF\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as Anthropic.Messages.DocumentBlockParam;\n } else if (_isAnthropicThinkingBlock(contentPart)) {\n const block: AnthropicThinkingBlockParam = {\n type: \"thinking\" as const, // Explicitly setting the type as \"thinking\"\n thinking: contentPart.thinking,\n signature: contentPart.signature,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicRedactedThinkingBlock(contentPart)) {\n const block: AnthropicRedactedThinkingBlockParam = {\n type: \"redacted_thinking\" as const, // Explicitly setting the type as \"redacted_thinking\"\n data: contentPart.data,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicCompactionBlock(contentPart)) {\n const block: AnthropicCompactionBlockParam = {\n type: \"compaction\" as const,\n content: contentPart.content,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n };\n yield block;\n } else if (_isAnthropicSearchResultBlock(contentPart)) {\n const block: AnthropicSearchResultBlockParam = {\n type: \"search_result\" as const, // Explicitly setting the type as \"search_result\"\n title: contentPart.title,\n source: contentPart.source,\n ...(\"cache_control\" in contentPart && contentPart.cache_control\n ? { cache_control: contentPart.cache_control }\n : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n content: contentPart.content,\n };\n yield block as Anthropic.Beta.BetaSearchResultBlockParam;\n } else if (\n textTypes.find((t) => t === contentPart.type) &&\n \"text\" in contentPart\n ) {\n // Assuming contentPart is of type MessageContentText here\n yield {\n type: \"text\" as const, // Explicitly setting the type as \"text\"\n text: contentPart.text,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n ...(\"citations\" in contentPart && contentPart.citations\n ? { citations: contentPart.citations }\n : {}),\n } as Anthropic.Messages.TextBlockParam;\n } else if (toolTypes.find((t) => t === contentPart.type)) {\n const contentPartCopy = { ...contentPart };\n\n if (contentPartCopy.type === \"input_json_delta\") {\n // `input_json_delta` type only represents yielding partial tool inputs\n // and is not a valid type for Anthropic messages.\n // These blocks appear in streaming responses and should be skipped\n // as their input data is already captured in tool_calls.\n continue;\n }\n\n if (\n contentPartCopy.type === \"tool_use\" &&\n typeof contentPartCopy.input === \"string\"\n ) {\n // First, try to get the input from the corresponding tool_call.\n // This is the most reliable source since tool_calls are properly\n // consolidated from tool_call_chunks during streaming.\n const matchingToolCall = toolCalls?.find(\n (tc) => tc.id === contentPartCopy.id\n );\n if (matchingToolCall) {\n contentPartCopy.input = matchingToolCall.args;\n } else {\n // Fallback: `tool_use` content part may be followed by `input_json_delta`\n // content parts which are chunks of a stringified JSON input,\n // so we need to collect them and merge their inputs.\n const inputDeltas = content.filter(\n (nestedContentPart) =>\n nestedContentPart.index === contentPartCopy.index &&\n nestedContentPart.type === \"input_json_delta\" &&\n typeof nestedContentPart.input === \"string\"\n );\n // If no `input_json_delta` parts are found, this line will just\n // return `contentPartCopy.input`, so no additional check is needed\n contentPartCopy.input = inputDeltas.reduce(\n (accumulator, nestedContentPart) =>\n accumulator + nestedContentPart.input,\n contentPartCopy.input\n );\n }\n }\n\n if (\"index\" in contentPartCopy) {\n // Anthropic does not support passing the index field here, so we remove it.\n delete contentPartCopy.index;\n }\n\n if (\"input\" in contentPartCopy) {\n // Anthropic tool use inputs should be valid objects, when applicable.\n if (typeof contentPartCopy.input === \"string\") {\n try {\n contentPartCopy.input = JSON.parse(contentPartCopy.input);\n } catch {\n contentPartCopy.input = {};\n }\n }\n }\n // TODO: Fix when SDK types are fixed\n yield {\n ...contentPartCopy,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n } else if (contentPart.type === \"container_upload\") {\n yield {\n ...contentPart,\n ...(cacheControl ? { cache_control: cacheControl } : {}),\n } as AnthropicContainerUploadBlockParam;\n }\n\n // Note that we are intentionally dropping any blocks that we don't\n // recognize. This is to allow for cross-compatibility between different\n // providers that may have different block types. Ie if we take a message\n // output from OpenAI and send it to Anthropic, we want to drop any blocks\n // that Anthropic doesn't understand.\n }\n}\n\nfunction _formatContent(message: BaseMessage, toolCalls?: ToolCall[]) {\n const { content } = message;\n\n if (typeof content === \"string\") {\n return content;\n } else {\n return Array.from(_formatContentBlocks(content, toolCalls));\n }\n}\n\ntype AnthropicToolChangeBlockParam =\n | Anthropic.Beta.BetaRequestToolAdditionBlock\n | Anthropic.Beta.BetaRequestToolRemovalBlock;\n\ntype AnthropicSystemContentBlockParam =\n | Anthropic.Messages.ContentBlockParam\n | AnthropicToolChangeBlockParam;\n\nconst TOOL_CHANGE_BLOCK_TYPES = [\"tool_addition\", \"tool_removal\"];\n\n/**\n * Returns the provider payload a block carries: the `value` of a\n * `non_standard` wrapper, or the block itself.\n */\nfunction _unwrapNonStandard(\n block: MessageContentComplex\n): MessageContentComplex {\n if (\n block.type === \"non_standard\" &&\n \"value\" in block &&\n typeof block.value === \"object\" &&\n block.value !== null\n ) {\n return block.value as MessageContentComplex;\n }\n return block;\n}\n\n/**\n * Normalizes the content of a system message for the wire.\n *\n * Shared by the hoisted top-level `system` field and by in-place\n * `role: \"system\"` entries, so both strip the same framework-internal fields.\n *\n * Blocks wrapped in core's `non_standard` escape hatch are unwrapped first, so\n * a provider-native block behaves the same whichever way it was written.\n */\nfunction _formatSystemContent(\n content: BaseMessage[\"content\"]\n): string | AnthropicSystemContentBlockParam[] {\n if (typeof content === \"string\") {\n return content;\n }\n if (!Array.isArray(content)) {\n // rare case: message.content could be undefined\n return [];\n }\n return content.flatMap((rawBlock): AnthropicSystemContentBlockParam[] => {\n if (typeof rawBlock !== \"object\" || rawBlock === null) {\n return [{ type: \"text\" as const, text: String(rawBlock) }];\n }\n const block = _unwrapNonStandard(rawBlock);\n if (TOOL_CHANGE_BLOCK_TYPES.includes(block.type as string)) {\n return [block as AnthropicToolChangeBlockParam];\n }\n if (block.type === \"text\" && typeof block.text === \"string\") {\n return [\n {\n type: \"text\" as const,\n text: block.text,\n ...(\"cache_control\" in block && block.cache_control\n ? {\n cache_control:\n block.cache_control as AnthropicTextBlockParam[\"cache_control\"],\n }\n : {}),\n ...(\"citations\" in block && block.citations\n ? {\n citations:\n block.citations as AnthropicTextBlockParam[\"citations\"],\n }\n : {}),\n },\n ];\n }\n // Anthropic accepts a closed set of system content blocks, and rejects\n // the whole request for anything else.\n // Consider warning about the dropped block once we have a proper logging solution\n return [];\n });\n}\n\n/**\n * Formats messages as a prompt for the model.\n * Used in LangSmith, export is important here.\n * @param messages The base messages to format as a prompt.\n * @returns The formatted prompt.\n */\nexport function _convertMessagesToAnthropicPayload(\n messages: BaseMessage[]\n): AnthropicMessageCreateParams {\n const mergedMessages = _ensureMessageContents(messages);\n\n // The contiguous run of system messages starting at index 0 is hoisted into\n // the top-level `system` field. Every other system message keeps its\n // position and is sent as a `role: \"system\"` entry, which the provider\n // applies from that point in the conversation onwards. The run is identified\n // after tool-message folding, because that is the sequence the provider sees.\n let leadingSystemCount = 0;\n while (\n leadingSystemCount < mergedMessages.length &&\n mergedMessages[leadingSystemCount]._getType() === \"system\"\n ) {\n leadingSystemCount += 1;\n }\n\n let system: string | AnthropicSystemContentBlockParam[] | undefined;\n if (leadingSystemCount === 1) {\n system = _formatSystemContent(mergedMessages[0].content);\n } else if (leadingSystemCount > 1) {\n system = mergedMessages.slice(0, leadingSystemCount).flatMap((message) => {\n const content = _formatSystemContent(message.content);\n return typeof content === \"string\"\n ? [{ type: \"text\" as const, text: content }]\n : content;\n });\n }\n // The provider rejects empty system content, so system content that narrowed\n // to nothing is omitted rather than sent.\n if (Array.isArray(system) && system.length === 0) {\n system = undefined;\n }\n\n const conversationMessages = mergedMessages.slice(leadingSystemCount);\n const formattedMessages = conversationMessages.map((message) => {\n let role;\n if (message._getType() === \"human\") {\n role = \"user\" as const;\n } else if (message._getType() === \"ai\") {\n role = \"assistant\" as const;\n } else if (message._getType() === \"tool\") {\n role = \"user\" as const;\n } else if (message._getType() === \"system\") {\n role = \"system\" as const;\n } else {\n throw new Error(`Message type \"${message.type}\" is not supported.`);\n }\n if (\n AIMessage.isInstance(message) &&\n message.response_metadata?.output_version === \"v1\"\n ) {\n return {\n role,\n content: _formatStandardContent(message),\n };\n }\n if (AIMessage.isInstance(message) && !!message.tool_calls?.length) {\n if (typeof message.content === \"string\") {\n if (message.content === \"\") {\n return {\n role,\n content: message.tool_calls.map(\n _convertLangChainToolCallToAnthropic\n ),\n };\n } else {\n return {\n role,\n content: [\n { type: \"text\", text: message.content },\n ...message.tool_calls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else {\n const { content } = message;\n const formattedContent = _formatContent(message, message.tool_calls);\n const formattedContentArr = Array.isArray(formattedContent)\n ? formattedContent\n : [{ type: \"text\" as const, text: formattedContent }];\n const missingToolCalls = message.tool_calls.filter(\n (toolCall) =>\n !content.find(\n (contentPart) =>\n (contentPart.type === \"tool_use\" ||\n contentPart.type === \"input_json_delta\" ||\n contentPart.type === \"server_tool_use\") &&\n contentPart.id === toolCall.id\n )\n );\n return {\n role,\n content: [\n ...formattedContentArr,\n ...missingToolCalls.map(_convertLangChainToolCallToAnthropic),\n ],\n };\n }\n } else if (role === \"system\") {\n const content = _formatSystemContent(message.content);\n return Array.isArray(content) && content.length === 0\n ? undefined\n : { role, content };\n } else {\n return {\n role,\n content: _formatContent(\n message,\n AIMessage.isInstance(message) ? message.tool_calls : undefined\n ),\n };\n }\n });\n return {\n messages: mergeMessages(\n formattedMessages.filter(\n (message) => message !== undefined\n ) as AnthropicMessageCreateParams[\"messages\"]\n ),\n system,\n } as AnthropicMessageCreateParams;\n}\n\n/**\n * Describes the tool changes in the system content of a converted payload:\n * `\"inline\"` if any `tool_addition` block defines a tool by value,\n * `\"reference\"` if tool changes only name tools declared elsewhere, or\n * `undefined` if there are none. The provider requires a different beta for\n * each.\n *\n * Reads the converted payload rather than the input messages, so a block that\n * was dropped during conversion never enables a beta.\n */\nexport function _getToolChangeKind(\n payload: AnthropicMessageCreateParams\n): \"inline\" | \"reference\" | undefined {\n const systemContents: unknown[] = [\n payload.system,\n ...payload.messages\n .filter((message) => message.role === \"system\")\n .map((message) => message.content),\n ];\n const toolChanges = systemContents.flatMap((content) =>\n Array.isArray(content)\n ? content.filter((block) => TOOL_CHANGE_BLOCK_TYPES.includes(block.type))\n : []\n );\n if (toolChanges.some((block) => block.tool?.type === \"tool_definition\")) {\n return \"inline\";\n }\n return toolChanges.length > 0 ? \"reference\" : undefined;\n}\n\nfunction mergeMessages(messages: AnthropicMessageCreateParams[\"messages\"]) {\n if (!messages || messages.length <= 1) {\n return messages;\n }\n\n const result: AnthropicMessageCreateParams[\"messages\"] = [];\n let currentMessage = messages[0];\n\n const normalizeContent = (\n content: string | Array<Anthropic.Messages.ContentBlockParam>\n ): Array<Anthropic.Messages.ContentBlockParam> => {\n if (typeof content === \"string\") {\n return [\n {\n type: \"text\",\n text: content,\n },\n ];\n }\n return content;\n };\n\n const isToolResultMessage = (msg: (typeof messages)[0]) => {\n if (msg.role !== \"user\") return false;\n\n if (typeof msg.content === \"string\") {\n return false;\n }\n\n return (\n Array.isArray(msg.content) &&\n msg.content.every((item) => item.type === \"tool_result\")\n );\n };\n\n for (let i = 1; i < messages.length; i += 1) {\n const nextMessage = messages[i];\n\n if (\n isToolResultMessage(currentMessage) &&\n isToolResultMessage(nextMessage)\n ) {\n // Merge the messages by combining their content arrays\n currentMessage = {\n ...currentMessage,\n content: [\n ...normalizeContent(currentMessage.content),\n ...normalizeContent(nextMessage.content),\n ],\n };\n } else {\n result.push(currentMessage);\n currentMessage = nextMessage;\n }\n }\n\n result.push(currentMessage);\n return result;\n}\n"],"mappings":";;;;AAoCA,SAAS,aAAa,UAAkB;CACtC,MAAM,UAAA,GAASA,yBAAAA,mBAAAA,CAAmB,EAAE,SAAS,SAAS,CAAC;CACvD,IAAI,QACF,OAAO;EACL,MAAM;EACN,YAAY,OAAO;EACnB,MAAM,OAAO;CACf;CAEF,IAAI;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