@langchain/anthropic 0.3.21 → 0.3.23

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.
@@ -7,7 +7,7 @@ const outputs_1 = require("@langchain/core/outputs");
7
7
  const env_1 = require("@langchain/core/utils/env");
8
8
  const chat_models_1 = require("@langchain/core/language_models/chat_models");
9
9
  const base_1 = require("@langchain/core/language_models/base");
10
- const zod_to_json_schema_1 = require("zod-to-json-schema");
10
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
11
11
  const runnables_1 = require("@langchain/core/runnables");
12
12
  const types_1 = require("@langchain/core/utils/types");
13
13
  const function_calling_1 = require("@langchain/core/utils/function_calling");
@@ -43,6 +43,16 @@ function _thinkingInParams(params) {
43
43
  function isAnthropicTool(tool) {
44
44
  return "input_schema" in tool;
45
45
  }
46
+ function isBuiltinTool(tool) {
47
+ const builtinTools = ["web_search"];
48
+ return (typeof tool === "object" &&
49
+ tool !== null &&
50
+ "type" in tool &&
51
+ "name" in tool &&
52
+ typeof tool.type === "string" &&
53
+ typeof tool.name === "string" &&
54
+ builtinTools.includes(tool.name));
55
+ }
46
56
  function extractToken(chunk) {
47
57
  if (typeof chunk.content === "string") {
48
58
  return chunk.content;
@@ -626,6 +636,9 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
626
636
  return undefined;
627
637
  }
628
638
  return tools.map((tool) => {
639
+ if (isBuiltinTool(tool)) {
640
+ return tool;
641
+ }
629
642
  if (isAnthropicTool(tool)) {
630
643
  return tool;
631
644
  }
@@ -641,8 +654,8 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
641
654
  return {
642
655
  name: tool.name,
643
656
  description: tool.description,
644
- input_schema: ((0, types_1.isZodSchema)(tool.schema)
645
- ? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema)
657
+ input_schema: ((0, types_1.isInteropZodSchema)(tool.schema)
658
+ ? (0, json_schema_1.toJsonSchema)(tool.schema)
646
659
  : tool.schema),
647
660
  };
648
661
  }
@@ -879,8 +892,8 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
879
892
  let functionName = name ?? "extract";
880
893
  let outputParser;
881
894
  let tools;
882
- if ((0, types_1.isZodSchema)(schema)) {
883
- const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
895
+ if ((0, types_1.isInteropZodSchema)(schema)) {
896
+ const jsonSchema = (0, json_schema_1.toJsonSchema)(schema);
884
897
  tools = [
885
898
  {
886
899
  name: functionName,
@@ -926,6 +939,10 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
926
939
  console.warn(thinkingAdmonition);
927
940
  llm = this.withConfig({
928
941
  tools,
942
+ ls_structured_output_format: {
943
+ kwargs: { method: "functionCalling" },
944
+ schema: (0, json_schema_1.toJsonSchema)(schema),
945
+ },
929
946
  });
930
947
  const raiseIfNoToolCalls = (message) => {
931
948
  if (!message.tool_calls || message.tool_calls.length === 0) {
@@ -942,6 +959,10 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
942
959
  type: "tool",
943
960
  name: functionName,
944
961
  },
962
+ ls_structured_output_format: {
963
+ kwargs: { method: "functionCalling" },
964
+ schema: (0, json_schema_1.toJsonSchema)(schema),
965
+ },
945
966
  });
946
967
  }
947
968
  if (!includeRaw) {
@@ -6,7 +6,7 @@ import { ChatGenerationChunk, type ChatResult } from "@langchain/core/outputs";
6
6
  import { BaseChatModel, BaseChatModelCallOptions, LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
7
7
  import { type StructuredOutputMethodOptions, type BaseLanguageModelInput } from "@langchain/core/language_models/base";
8
8
  import { Runnable } from "@langchain/core/runnables";
9
- import { z } from "zod";
9
+ import { InteropZodType } from "@langchain/core/utils/types";
10
10
  import { AnthropicMessageCreateParams, AnthropicMessageStreamEvent, AnthropicRequestOptions, AnthropicStreamingMessageCreateParams, AnthropicThinkingConfigParam, AnthropicToolChoice, ChatAnthropicToolType } from "./types.js";
11
11
  export interface ChatAnthropicCallOptions extends BaseChatModelCallOptions, Pick<AnthropicInput, "streamUsage"> {
12
12
  tools?: ChatAnthropicToolType[];
@@ -21,6 +21,10 @@ export interface ChatAnthropicCallOptions extends BaseChatModelCallOptions, Pick
21
21
  */
22
22
  headers?: Record<string, string>;
23
23
  }
24
+ /**
25
+ * @see https://docs.anthropic.com/claude/docs/models-overview
26
+ */
27
+ export type AnthropicMessagesModelId = Anthropic.Model | (string & NonNullable<unknown>);
24
28
  /**
25
29
  * Input to AnthropicChat class.
26
30
  */
@@ -66,9 +70,9 @@ export interface AnthropicInput {
66
70
  /** Anthropic API URL */
67
71
  anthropicApiUrl?: string;
68
72
  /** @deprecated Use "model" instead */
69
- modelName?: string;
73
+ modelName?: AnthropicMessagesModelId;
70
74
  /** Model name to use */
71
- model?: string;
75
+ model?: AnthropicMessagesModelId;
72
76
  /** Overridable Anthropic ClientOptions */
73
77
  clientOptions?: ClientOptions;
74
78
  /** Holds any additional parameters that are valid to pass to {@link
@@ -511,7 +515,7 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
511
515
  * @param {ChatAnthropicCallOptions["tools"]} tools The tools to format
512
516
  * @returns {AnthropicTool[] | undefined} The formatted tools, or undefined if none are passed.
513
517
  */
514
- formatStructuredToolToAnthropic(tools: ChatAnthropicCallOptions["tools"]): Anthropic.Messages.Tool[] | undefined;
518
+ formatStructuredToolToAnthropic(tools: ChatAnthropicCallOptions["tools"]): Anthropic.Messages.ToolUnion[] | undefined;
515
519
  bindTools(tools: ChatAnthropicToolType[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, CallOptions>;
516
520
  /**
517
521
  * Get the parameters used to invoke the model
@@ -519,16 +523,17 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
519
523
  invocationParams(options?: this["ParsedCallOptions"]): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages"> & Kwargs;
520
524
  /** @ignore */
521
525
  _identifyingParams(): {
522
- system?: string | Anthropic.Messages.TextBlockParam[] | undefined;
526
+ system?: (string | Array<Anthropic.Messages.TextBlockParam>) | undefined;
523
527
  thinking?: Anthropic.Messages.ThinkingConfigParam | undefined;
524
528
  metadata?: Anthropic.Messages.Metadata | undefined;
525
529
  model: Anthropic.Messages.Model;
526
530
  max_tokens: number;
527
- tools?: Anthropic.Messages.ToolUnion[] | undefined;
531
+ tools?: Array<Anthropic.Messages.ToolUnion> | undefined;
528
532
  tool_choice?: Anthropic.Messages.ToolChoice | undefined;
529
533
  temperature?: number | undefined;
530
534
  stream?: boolean | undefined;
531
- stop_sequences?: string[] | undefined;
535
+ service_tier?: "auto" | "standard_only" | undefined;
536
+ stop_sequences?: Array<string> | undefined;
532
537
  top_k?: number | undefined;
533
538
  top_p?: number | undefined;
534
539
  model_name: string;
@@ -537,16 +542,17 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
537
542
  * Get the identifying parameters for the model
538
543
  */
539
544
  identifyingParams(): {
540
- system?: string | Anthropic.Messages.TextBlockParam[] | undefined;
545
+ system?: (string | Array<Anthropic.Messages.TextBlockParam>) | undefined;
541
546
  thinking?: Anthropic.Messages.ThinkingConfigParam | undefined;
542
547
  metadata?: Anthropic.Messages.Metadata | undefined;
543
548
  model: Anthropic.Messages.Model;
544
549
  max_tokens: number;
545
- tools?: Anthropic.Messages.ToolUnion[] | undefined;
550
+ tools?: Array<Anthropic.Messages.ToolUnion> | undefined;
546
551
  tool_choice?: Anthropic.Messages.ToolChoice | undefined;
547
552
  temperature?: number | undefined;
548
553
  stream?: boolean | undefined;
549
- stop_sequences?: string[] | undefined;
554
+ service_tier?: "auto" | "standard_only" | undefined;
555
+ stop_sequences?: Array<string> | undefined;
550
556
  top_k?: number | undefined;
551
557
  top_p?: number | undefined;
552
558
  model_name: string;
@@ -558,7 +564,7 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
558
564
  llmOutput: {
559
565
  id: string;
560
566
  model: Anthropic.Messages.Model;
561
- stop_reason: "tool_use" | "stop_sequence" | "end_turn" | "max_tokens" | null;
567
+ stop_reason: Anthropic.Messages.StopReason | null;
562
568
  stop_sequence: string | null;
563
569
  usage: Anthropic.Messages.Usage;
564
570
  };
@@ -575,8 +581,8 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
575
581
  /** @ignore */
576
582
  protected completionWithRetry(request: AnthropicMessageCreateParams & Kwargs, options: AnthropicRequestOptions): Promise<Anthropic.Message>;
577
583
  _llmType(): string;
578
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
579
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
584
+ withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
585
+ withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
580
586
  raw: BaseMessage;
581
587
  parsed: RunOutput;
582
588
  }>;
@@ -4,9 +4,9 @@ import { ChatGenerationChunk } from "@langchain/core/outputs";
4
4
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
5
5
  import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
6
6
  import { isOpenAITool, } from "@langchain/core/language_models/base";
7
- import { zodToJsonSchema } from "zod-to-json-schema";
7
+ import { toJsonSchema } from "@langchain/core/utils/json_schema";
8
8
  import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnables";
9
- import { isZodSchema } from "@langchain/core/utils/types";
9
+ import { isInteropZodSchema, } from "@langchain/core/utils/types";
10
10
  import { isLangChainTool } from "@langchain/core/utils/function_calling";
11
11
  import { AnthropicToolsOutputParser } from "./output_parsers.js";
12
12
  import { handleToolChoice } from "./utils/tools.js";
@@ -40,6 +40,16 @@ function _thinkingInParams(params) {
40
40
  function isAnthropicTool(tool) {
41
41
  return "input_schema" in tool;
42
42
  }
43
+ function isBuiltinTool(tool) {
44
+ const builtinTools = ["web_search"];
45
+ return (typeof tool === "object" &&
46
+ tool !== null &&
47
+ "type" in tool &&
48
+ "name" in tool &&
49
+ typeof tool.type === "string" &&
50
+ typeof tool.name === "string" &&
51
+ builtinTools.includes(tool.name));
52
+ }
43
53
  function extractToken(chunk) {
44
54
  if (typeof chunk.content === "string") {
45
55
  return chunk.content;
@@ -623,6 +633,9 @@ export class ChatAnthropicMessages extends BaseChatModel {
623
633
  return undefined;
624
634
  }
625
635
  return tools.map((tool) => {
636
+ if (isBuiltinTool(tool)) {
637
+ return tool;
638
+ }
626
639
  if (isAnthropicTool(tool)) {
627
640
  return tool;
628
641
  }
@@ -638,8 +651,8 @@ export class ChatAnthropicMessages extends BaseChatModel {
638
651
  return {
639
652
  name: tool.name,
640
653
  description: tool.description,
641
- input_schema: (isZodSchema(tool.schema)
642
- ? zodToJsonSchema(tool.schema)
654
+ input_schema: (isInteropZodSchema(tool.schema)
655
+ ? toJsonSchema(tool.schema)
643
656
  : tool.schema),
644
657
  };
645
658
  }
@@ -876,8 +889,8 @@ export class ChatAnthropicMessages extends BaseChatModel {
876
889
  let functionName = name ?? "extract";
877
890
  let outputParser;
878
891
  let tools;
879
- if (isZodSchema(schema)) {
880
- const jsonSchema = zodToJsonSchema(schema);
892
+ if (isInteropZodSchema(schema)) {
893
+ const jsonSchema = toJsonSchema(schema);
881
894
  tools = [
882
895
  {
883
896
  name: functionName,
@@ -923,6 +936,10 @@ export class ChatAnthropicMessages extends BaseChatModel {
923
936
  console.warn(thinkingAdmonition);
924
937
  llm = this.withConfig({
925
938
  tools,
939
+ ls_structured_output_format: {
940
+ kwargs: { method: "functionCalling" },
941
+ schema: toJsonSchema(schema),
942
+ },
926
943
  });
927
944
  const raiseIfNoToolCalls = (message) => {
928
945
  if (!message.tool_calls || message.tool_calls.length === 0) {
@@ -939,6 +956,10 @@ export class ChatAnthropicMessages extends BaseChatModel {
939
956
  type: "tool",
940
957
  name: functionName,
941
958
  },
959
+ ls_structured_output_format: {
960
+ kwargs: { method: "functionCalling" },
961
+ schema: toJsonSchema(schema),
962
+ },
942
963
  });
943
964
  }
944
965
  if (!includeRaw) {
@@ -6,7 +6,8 @@ const messages_1 = require("@langchain/core/messages");
6
6
  const chat_models_1 = require("@langchain/core/language_models/chat_models");
7
7
  const runnables_1 = require("@langchain/core/runnables");
8
8
  const openai_tools_1 = require("@langchain/core/output_parsers/openai_tools");
9
- const zod_to_json_schema_1 = require("zod-to-json-schema");
9
+ const json_schema_1 = require("@langchain/core/utils/json_schema");
10
+ const types_1 = require("@langchain/core/utils/types");
10
11
  const chat_models_js_1 = require("../chat_models.cjs");
11
12
  const tool_calling_js_1 = require("./utils/tool_calling.cjs");
12
13
  /**
@@ -226,8 +227,8 @@ class ChatAnthropicTools extends chat_models_1.BaseChatModel {
226
227
  let functionName = name ?? "extract";
227
228
  let outputParser;
228
229
  let tools;
229
- if (isZodSchema(schema)) {
230
- const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
230
+ if ((0, types_1.isInteropZodSchema)(schema)) {
231
+ const jsonSchema = (0, json_schema_1.toJsonSchema)(schema);
231
232
  tools = [
232
233
  {
233
234
  type: "function",
@@ -307,12 +308,6 @@ class ChatAnthropicTools extends chat_models_1.BaseChatModel {
307
308
  }
308
309
  }
309
310
  exports.ChatAnthropicTools = ChatAnthropicTools;
310
- function isZodSchema(
311
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
312
- input) {
313
- // Check for a characteristic method of Zod schemas
314
- return typeof input?.parse === "function";
315
- }
316
311
  function isStructuredOutputMethodParams(x
317
312
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
318
313
  ) {
@@ -5,7 +5,7 @@ import { CallbackManagerForLLMRun, Callbacks } from "@langchain/core/callbacks/m
5
5
  import { BasePromptTemplate } from "@langchain/core/prompts";
6
6
  import type { BaseLanguageModelCallOptions, BaseLanguageModelInput, StructuredOutputMethodParams, StructuredOutputMethodOptions, ToolDefinition } from "@langchain/core/language_models/base";
7
7
  import { Runnable } from "@langchain/core/runnables";
8
- import { z } from "zod";
8
+ import { InteropZodType } from "@langchain/core/utils/types";
9
9
  import { type AnthropicInput } from "../chat_models.js";
10
10
  export interface ChatAnthropicToolsCallOptions extends BaseLanguageModelCallOptions {
11
11
  tools?: ToolDefinition[];
@@ -45,10 +45,10 @@ export declare class ChatAnthropicTools extends BaseChatModel<ChatAnthropicTools
45
45
  generate(messages: BaseMessageLike[][], parsedOptions?: ChatAnthropicToolsCallOptions, callbacks?: Callbacks): Promise<LLMResult>;
46
46
  _generate(_messages: BaseMessage[], _options: this["ParsedCallOptions"], _runManager?: CallbackManagerForLLMRun | undefined): Promise<ChatResult>;
47
47
  _llmType(): string;
48
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: StructuredOutputMethodParams<RunOutput, false> | z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false> & {
48
+ withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false> & {
49
49
  force?: boolean;
50
50
  }): Runnable<BaseLanguageModelInput, RunOutput>;
51
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: StructuredOutputMethodParams<RunOutput, true> | z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true> & {
51
+ withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true> & {
52
52
  force?: boolean;
53
53
  }): Runnable<BaseLanguageModelInput, {
54
54
  raw: BaseMessage;
@@ -3,7 +3,8 @@ import { AIMessage, SystemMessage, coerceMessageLikeToMessage, } from "@langchai
3
3
  import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
4
4
  import { RunnablePassthrough, RunnableSequence, } from "@langchain/core/runnables";
5
5
  import { JsonOutputKeyToolsParser } from "@langchain/core/output_parsers/openai_tools";
6
- import { zodToJsonSchema } from "zod-to-json-schema";
6
+ import { toJsonSchema, } from "@langchain/core/utils/json_schema";
7
+ import { isInteropZodSchema, } from "@langchain/core/utils/types";
7
8
  import { ChatAnthropic } from "../chat_models.js";
8
9
  import { DEFAULT_TOOL_SYSTEM_PROMPT, formatAsXMLRepresentation, fixArrayXMLParameters, } from "./utils/tool_calling.js";
9
10
  /**
@@ -223,8 +224,8 @@ export class ChatAnthropicTools extends BaseChatModel {
223
224
  let functionName = name ?? "extract";
224
225
  let outputParser;
225
226
  let tools;
226
- if (isZodSchema(schema)) {
227
- const jsonSchema = zodToJsonSchema(schema);
227
+ if (isInteropZodSchema(schema)) {
228
+ const jsonSchema = toJsonSchema(schema);
228
229
  tools = [
229
230
  {
230
231
  type: "function",
@@ -303,12 +304,6 @@ export class ChatAnthropicTools extends BaseChatModel {
303
304
  });
304
305
  }
305
306
  }
306
- function isZodSchema(
307
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
- input) {
309
- // Check for a characteristic method of Zod schemas
310
- return typeof input?.parse === "function";
311
- }
312
307
  function isStructuredOutputMethodParams(x
313
308
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
314
309
  ) {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixArrayXMLParameters = exports.formatAsXMLRepresentation = exports.DEFAULT_TOOL_SYSTEM_PROMPT = void 0;
3
+ exports.DEFAULT_TOOL_SYSTEM_PROMPT = void 0;
4
+ exports.formatAsXMLRepresentation = formatAsXMLRepresentation;
5
+ exports.fixArrayXMLParameters = fixArrayXMLParameters;
4
6
  const fast_xml_parser_1 = require("fast-xml-parser");
5
7
  const prompts_1 = require("@langchain/core/prompts");
6
8
  exports.DEFAULT_TOOL_SYSTEM_PROMPT =
@@ -51,7 +53,6 @@ ${parameterXml}
51
53
  </parameters>
52
54
  </tool_description>`;
53
55
  }
54
- exports.formatAsXMLRepresentation = formatAsXMLRepresentation;
55
56
  function fixArrayXMLParameters(schema,
56
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
58
  xmlParameters
@@ -103,4 +104,3 @@ xmlParameters
103
104
  }
104
105
  return fixedParameters;
105
106
  }
106
- exports.fixArrayXMLParameters = fixArrayXMLParameters;
@@ -1,4 +1,4 @@
1
- import { JsonSchema7ObjectType } from "zod-to-json-schema";
1
+ import { type JsonSchema7ObjectType } from "@langchain/core/utils/json_schema";
2
2
  import { PromptTemplate } from "@langchain/core/prompts";
3
3
  import { ToolDefinition } from "@langchain/core/language_models/base";
4
4
  export declare const DEFAULT_TOOL_SYSTEM_PROMPT: PromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"In this environment you have access to a set of tools you can use to answer the user's question.\n\nYou may call them like this:\n<function_calls>\n<invoke>\n<tool_name>$TOOL_NAME</tool_name>\n<parameters>\n<$PARAMETER_NAME>$PARAMETER_VALUE</$PARAMETER_NAME>\n...\n</parameters>\n</invoke>\n</function_calls>\n\nHere are the tools available:\n{tools}\n\nIf the schema above contains a property typed as an enum, you must only return values matching an allowed value for that enum.">, any>;
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
26
36
  Object.defineProperty(exports, "__esModule", { value: true });
27
37
  exports.experimental = exports.index = void 0;
28
38
  exports.index = __importStar(require("../index.cjs"));
@@ -15,15 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.load = exports.importMap = exports.optionalImportEntrypoints = void 0;
36
+ exports.importMap = exports.optionalImportEntrypoints = void 0;
37
+ exports.load = load;
27
38
  const load_1 = require("@langchain/core/load");
28
39
  const importMap = __importStar(require("./import_map.cjs"));
29
40
  exports.importMap = importMap;
@@ -50,4 +61,3 @@ optionalImportsMap = {}) {
50
61
  importMap,
51
62
  });
52
63
  }
53
- exports.load = load;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractToolCalls = exports.AnthropicToolsOutputParser = void 0;
3
+ exports.AnthropicToolsOutputParser = void 0;
4
+ exports.extractToolCalls = extractToolCalls;
4
5
  const output_parsers_1 = require("@langchain/core/output_parsers");
6
+ const types_1 = require("@langchain/core/utils/types");
5
7
  class AnthropicToolsOutputParser extends output_parsers_1.BaseLLMOutputParser {
6
8
  static lc_name() {
7
9
  return "AnthropicToolsOutputParser";
@@ -61,12 +63,12 @@ class AnthropicToolsOutputParser extends output_parsers_1.BaseLLMOutputParser {
61
63
  if (this.zodSchema === undefined) {
62
64
  return parsedResult;
63
65
  }
64
- const zodParsedResult = await this.zodSchema.safeParseAsync(parsedResult);
66
+ const zodParsedResult = await (0, types_1.interopSafeParseAsync)(this.zodSchema, parsedResult);
65
67
  if (zodParsedResult.success) {
66
68
  return zodParsedResult.data;
67
69
  }
68
70
  else {
69
- throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.errors)}`, JSON.stringify(parsedResult, null, 2));
71
+ throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, JSON.stringify(parsedResult, null, 2));
70
72
  }
71
73
  }
72
74
  async parseResult(generations) {
@@ -99,7 +101,16 @@ function extractToolCalls(content) {
99
101
  type: "tool_call",
100
102
  });
101
103
  }
104
+ else if (block.type === "server_tool_use" &&
105
+ block.name === "web_search") {
106
+ // Handle Anthropic built-in web search tool
107
+ toolCalls.push({
108
+ name: block.name,
109
+ args: block.input,
110
+ id: block.id,
111
+ type: "tool_call",
112
+ });
113
+ }
102
114
  }
103
115
  return toolCalls;
104
116
  }
105
- exports.extractToolCalls = extractToolCalls;
@@ -1,9 +1,9 @@
1
- import { z } from "zod";
2
1
  import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
3
- import { JsonOutputKeyToolsParserParams } from "@langchain/core/output_parsers/openai_tools";
2
+ import { JsonOutputKeyToolsParserParamsInterop } from "@langchain/core/output_parsers/openai_tools";
4
3
  import { ChatGeneration } from "@langchain/core/outputs";
5
4
  import { ToolCall } from "@langchain/core/messages/tool";
6
- interface AnthropicToolsOutputParserParams<T extends Record<string, any>> extends JsonOutputKeyToolsParserParams<T> {
5
+ import { InteropZodType } from "@langchain/core/utils/types";
6
+ interface AnthropicToolsOutputParserParams<T extends Record<string, any>> extends JsonOutputKeyToolsParserParamsInterop<T> {
7
7
  }
8
8
  export declare class AnthropicToolsOutputParser<T extends Record<string, any> = Record<string, any>> extends BaseLLMOutputParser<T> {
9
9
  static lc_name(): string;
@@ -13,7 +13,7 @@ export declare class AnthropicToolsOutputParser<T extends Record<string, any> =
13
13
  keyName: string;
14
14
  /** Whether to return only the first tool call. */
15
15
  returnSingle: boolean;
16
- zodSchema?: z.ZodType<T>;
16
+ zodSchema?: InteropZodType<T>;
17
17
  constructor(params: AnthropicToolsOutputParserParams<T>);
18
18
  protected _validateResult(result: unknown): Promise<T>;
19
19
  parseResult(generations: ChatGeneration[]): Promise<T>;
@@ -1,4 +1,5 @@
1
1
  import { BaseLLMOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
2
+ import { interopSafeParseAsync, } from "@langchain/core/utils/types";
2
3
  export class AnthropicToolsOutputParser extends BaseLLMOutputParser {
3
4
  static lc_name() {
4
5
  return "AnthropicToolsOutputParser";
@@ -58,12 +59,12 @@ export class AnthropicToolsOutputParser extends BaseLLMOutputParser {
58
59
  if (this.zodSchema === undefined) {
59
60
  return parsedResult;
60
61
  }
61
- const zodParsedResult = await this.zodSchema.safeParseAsync(parsedResult);
62
+ const zodParsedResult = await interopSafeParseAsync(this.zodSchema, parsedResult);
62
63
  if (zodParsedResult.success) {
63
64
  return zodParsedResult.data;
64
65
  }
65
66
  else {
66
- throw new OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.errors)}`, JSON.stringify(parsedResult, null, 2));
67
+ throw new OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, JSON.stringify(parsedResult, null, 2));
67
68
  }
68
69
  }
69
70
  async parseResult(generations) {
@@ -95,6 +96,16 @@ export function extractToolCalls(content) {
95
96
  type: "tool_call",
96
97
  });
97
98
  }
99
+ else if (block.type === "server_tool_use" &&
100
+ block.name === "web_search") {
101
+ // Handle Anthropic built-in web search tool
102
+ toolCalls.push({
103
+ name: block.name,
104
+ args: block.input,
105
+ id: block.id,
106
+ type: "tool_call",
107
+ });
108
+ }
98
109
  }
99
110
  return toolCalls;
100
111
  }
package/dist/types.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAnthropicImageBlockParam = void 0;
3
+ exports.isAnthropicImageBlockParam = isAnthropicImageBlockParam;
4
4
  function isAnthropicImageBlockParam(block) {
5
5
  if (block == null) {
6
6
  return false;
@@ -46,4 +46,3 @@ function isAnthropicImageBlockParam(block) {
46
46
  }
47
47
  return false;
48
48
  }
49
- exports.isAnthropicImageBlockParam = isAnthropicImageBlockParam;
package/dist/types.d.ts CHANGED
@@ -25,4 +25,9 @@ export type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockPa
25
25
  export type AnthropicDocumentBlockParam = Anthropic.Messages.DocumentBlockParam;
26
26
  export type AnthropicThinkingBlockParam = Anthropic.Messages.ThinkingBlockParam;
27
27
  export type AnthropicRedactedThinkingBlockParam = Anthropic.Messages.RedactedThinkingBlockParam;
28
+ export type AnthropicServerToolUseBlockParam = Anthropic.Messages.ServerToolUseBlockParam;
29
+ export type AnthropicWebSearchToolResultBlockParam = Anthropic.Messages.WebSearchToolResultBlockParam;
30
+ export type AnthropicWebSearchResultBlockParam = Anthropic.Messages.WebSearchResultBlockParam;
31
+ export type AnthropicContentBlock = AnthropicTextBlockParam | AnthropicImageBlockParam | AnthropicToolUseBlockParam | AnthropicToolResultBlockParam | AnthropicDocumentBlockParam | AnthropicThinkingBlockParam | AnthropicRedactedThinkingBlockParam | AnthropicServerToolUseBlockParam | AnthropicWebSearchToolResultBlockParam | AnthropicWebSearchResultBlockParam;
28
32
  export declare function isAnthropicImageBlockParam(block: unknown): block is AnthropicImageBlockParam;
33
+ export type AnthropicBuiltInToolUnion = Exclude<Anthropic.Messages.ToolUnion, Anthropic.Messages.Tool>;
@@ -2,13 +2,13 @@
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  /* eslint-disable no-param-reassign */
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.wrapAnthropicClientError = exports.addLangChainErrorFields = void 0;
5
+ exports.addLangChainErrorFields = addLangChainErrorFields;
6
+ exports.wrapAnthropicClientError = wrapAnthropicClientError;
6
7
  function addLangChainErrorFields(error, lc_error_code) {
7
8
  error.lc_error_code = lc_error_code;
8
9
  error.message = `${error.message}\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/${lc_error_code}/\n`;
9
10
  return error;
10
11
  }
11
- exports.addLangChainErrorFields = addLangChainErrorFields;
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
  function wrapAnthropicClientError(e) {
14
14
  let error;
@@ -29,4 +29,3 @@ function wrapAnthropicClientError(e) {
29
29
  }
30
30
  return error;
31
31
  }
32
- exports.wrapAnthropicClientError = wrapAnthropicClientError;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._convertMessagesToAnthropicPayload = exports._convertLangChainToolCallToAnthropic = void 0;
3
+ exports._convertLangChainToolCallToAnthropic = _convertLangChainToolCallToAnthropic;
4
+ exports._convertMessagesToAnthropicPayload = _convertMessagesToAnthropicPayload;
4
5
  /**
5
6
  * This util file contains functions for converting LangChain messages to Anthropic messages.
6
7
  */
@@ -101,7 +102,6 @@ function _convertLangChainToolCallToAnthropic(toolCall) {
101
102
  input: toolCall.args,
102
103
  };
103
104
  }
104
- exports._convertLangChainToolCallToAnthropic = _convertLangChainToolCallToAnthropic;
105
105
  const standardContentBlockConverter = {
106
106
  providerName: "anthropic",
107
107
  fromStandardTextBlock(block) {
@@ -285,7 +285,14 @@ const standardContentBlockConverter = {
285
285
  },
286
286
  };
287
287
  function _formatContent(content) {
288
- const toolTypes = ["tool_use", "tool_result", "input_json_delta"];
288
+ const toolTypes = [
289
+ "tool_use",
290
+ "tool_result",
291
+ "input_json_delta",
292
+ "server_tool_use",
293
+ "web_search_tool_result",
294
+ "web_search_result",
295
+ ];
289
296
  const textTypes = ["text", "text_delta"];
290
297
  if (typeof content === "string") {
291
298
  return content;
@@ -305,7 +312,7 @@ function _formatContent(content) {
305
312
  source = _formatImage(contentPart.image_url.url);
306
313
  }
307
314
  return {
308
- type: "image",
315
+ type: "image", // Explicitly setting the type as "image"
309
316
  source,
310
317
  ...(cacheControl ? { cache_control: cacheControl } : {}),
311
318
  };
@@ -322,7 +329,7 @@ function _formatContent(content) {
322
329
  }
323
330
  else if (contentPart.type === "thinking") {
324
331
  const block = {
325
- type: "thinking",
332
+ type: "thinking", // Explicitly setting the type as "thinking"
326
333
  thinking: contentPart.thinking,
327
334
  signature: contentPart.signature,
328
335
  ...(cacheControl ? { cache_control: cacheControl } : {}),
@@ -331,7 +338,7 @@ function _formatContent(content) {
331
338
  }
332
339
  else if (contentPart.type === "redacted_thinking") {
333
340
  const block = {
334
- type: "redacted_thinking",
341
+ type: "redacted_thinking", // Explicitly setting the type as "redacted_thinking"
335
342
  data: contentPart.data,
336
343
  ...(cacheControl ? { cache_control: cacheControl } : {}),
337
344
  };
@@ -341,9 +348,12 @@ function _formatContent(content) {
341
348
  "text" in contentPart) {
342
349
  // Assuming contentPart is of type MessageContentText here
343
350
  return {
344
- type: "text",
351
+ type: "text", // Explicitly setting the type as "text"
345
352
  text: contentPart.text,
346
353
  ...(cacheControl ? { cache_control: cacheControl } : {}),
354
+ ...("citations" in contentPart && contentPart.citations
355
+ ? { citations: contentPart.citations }
356
+ : {}),
347
357
  };
348
358
  }
349
359
  else if (toolTypes.find((t) => t === contentPart.type)) {
@@ -433,7 +443,8 @@ function _convertMessagesToAnthropicPayload(messages) {
433
443
  else {
434
444
  const { content } = message;
435
445
  const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) => content.find((contentPart) => (contentPart.type === "tool_use" ||
436
- contentPart.type === "input_json_delta") &&
446
+ contentPart.type === "input_json_delta" ||
447
+ contentPart.type === "server_tool_use") &&
437
448
  contentPart.id === toolCall.id));
438
449
  if (hasMismatchedToolCalls) {
439
450
  console.warn(`The "tool_calls" field on a message is only respected if content is a string.`);
@@ -456,7 +467,6 @@ function _convertMessagesToAnthropicPayload(messages) {
456
467
  system,
457
468
  };
458
469
  }
459
- exports._convertMessagesToAnthropicPayload = _convertMessagesToAnthropicPayload;
460
470
  function mergeMessages(messages) {
461
471
  if (!messages || messages.length <= 1) {
462
472
  return messages;
@@ -281,7 +281,14 @@ const standardContentBlockConverter = {
281
281
  },
282
282
  };
283
283
  function _formatContent(content) {
284
- const toolTypes = ["tool_use", "tool_result", "input_json_delta"];
284
+ const toolTypes = [
285
+ "tool_use",
286
+ "tool_result",
287
+ "input_json_delta",
288
+ "server_tool_use",
289
+ "web_search_tool_result",
290
+ "web_search_result",
291
+ ];
285
292
  const textTypes = ["text", "text_delta"];
286
293
  if (typeof content === "string") {
287
294
  return content;
@@ -301,7 +308,7 @@ function _formatContent(content) {
301
308
  source = _formatImage(contentPart.image_url.url);
302
309
  }
303
310
  return {
304
- type: "image",
311
+ type: "image", // Explicitly setting the type as "image"
305
312
  source,
306
313
  ...(cacheControl ? { cache_control: cacheControl } : {}),
307
314
  };
@@ -318,7 +325,7 @@ function _formatContent(content) {
318
325
  }
319
326
  else if (contentPart.type === "thinking") {
320
327
  const block = {
321
- type: "thinking",
328
+ type: "thinking", // Explicitly setting the type as "thinking"
322
329
  thinking: contentPart.thinking,
323
330
  signature: contentPart.signature,
324
331
  ...(cacheControl ? { cache_control: cacheControl } : {}),
@@ -327,7 +334,7 @@ function _formatContent(content) {
327
334
  }
328
335
  else if (contentPart.type === "redacted_thinking") {
329
336
  const block = {
330
- type: "redacted_thinking",
337
+ type: "redacted_thinking", // Explicitly setting the type as "redacted_thinking"
331
338
  data: contentPart.data,
332
339
  ...(cacheControl ? { cache_control: cacheControl } : {}),
333
340
  };
@@ -337,9 +344,12 @@ function _formatContent(content) {
337
344
  "text" in contentPart) {
338
345
  // Assuming contentPart is of type MessageContentText here
339
346
  return {
340
- type: "text",
347
+ type: "text", // Explicitly setting the type as "text"
341
348
  text: contentPart.text,
342
349
  ...(cacheControl ? { cache_control: cacheControl } : {}),
350
+ ...("citations" in contentPart && contentPart.citations
351
+ ? { citations: contentPart.citations }
352
+ : {}),
343
353
  };
344
354
  }
345
355
  else if (toolTypes.find((t) => t === contentPart.type)) {
@@ -429,7 +439,8 @@ export function _convertMessagesToAnthropicPayload(messages) {
429
439
  else {
430
440
  const { content } = message;
431
441
  const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) => content.find((contentPart) => (contentPart.type === "tool_use" ||
432
- contentPart.type === "input_json_delta") &&
442
+ contentPart.type === "input_json_delta" ||
443
+ contentPart.type === "server_tool_use") &&
433
444
  contentPart.id === toolCall.id));
434
445
  if (hasMismatchedToolCalls) {
435
446
  console.warn(`The "tool_calls" field on a message is only respected if content is a string.`);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.anthropicResponseToChatMessages = exports._makeMessageChunkFromAnthropicEvent = void 0;
3
+ exports._makeMessageChunkFromAnthropicEvent = _makeMessageChunkFromAnthropicEvent;
4
+ exports.anthropicResponseToChatMessages = anthropicResponseToChatMessages;
4
5
  const messages_1 = require("@langchain/core/messages");
5
6
  const output_parsers_js_1 = require("../output_parsers.cjs");
6
7
  function _makeMessageChunkFromAnthropicEvent(data, fields) {
@@ -60,7 +61,12 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
60
61
  };
61
62
  }
62
63
  else if (data.type === "content_block_start" &&
63
- ["tool_use", "document"].includes(data.content_block.type)) {
64
+ [
65
+ "tool_use",
66
+ "document",
67
+ "server_tool_use",
68
+ "web_search_tool_result",
69
+ ].includes(data.content_block.type)) {
64
70
  const contentBlock = data.content_block;
65
71
  let toolCallChunks;
66
72
  if (contentBlock.type === "tool_use") {
@@ -73,6 +79,17 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
73
79
  },
74
80
  ];
75
81
  }
82
+ else if (contentBlock.type === "server_tool_use") {
83
+ // Handle anthropic built-in server tool use (like web search)
84
+ toolCallChunks = [
85
+ {
86
+ id: contentBlock.id,
87
+ index: data.index,
88
+ name: contentBlock.name,
89
+ args: "",
90
+ },
91
+ ];
92
+ }
76
93
  else {
77
94
  toolCallChunks = [];
78
95
  }
@@ -84,7 +101,10 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
84
101
  {
85
102
  index: data.index,
86
103
  ...data.content_block,
87
- input: "",
104
+ input: contentBlock.type === "server_tool_use" ||
105
+ contentBlock.type === "tool_use"
106
+ ? ""
107
+ : undefined,
88
108
  },
89
109
  ],
90
110
  additional_kwargs: {},
@@ -193,7 +213,6 @@ function _makeMessageChunkFromAnthropicEvent(data, fields) {
193
213
  }
194
214
  return null;
195
215
  }
196
- exports._makeMessageChunkFromAnthropicEvent = _makeMessageChunkFromAnthropicEvent;
197
216
  function anthropicResponseToChatMessages(messages, additionalKwargs) {
198
217
  const usage = additionalKwargs.usage;
199
218
  const usageMetadata = usage != null
@@ -240,4 +259,3 @@ function anthropicResponseToChatMessages(messages, additionalKwargs) {
240
259
  return generations;
241
260
  }
242
261
  }
243
- exports.anthropicResponseToChatMessages = anthropicResponseToChatMessages;
@@ -57,7 +57,12 @@ export function _makeMessageChunkFromAnthropicEvent(data, fields) {
57
57
  };
58
58
  }
59
59
  else if (data.type === "content_block_start" &&
60
- ["tool_use", "document"].includes(data.content_block.type)) {
60
+ [
61
+ "tool_use",
62
+ "document",
63
+ "server_tool_use",
64
+ "web_search_tool_result",
65
+ ].includes(data.content_block.type)) {
61
66
  const contentBlock = data.content_block;
62
67
  let toolCallChunks;
63
68
  if (contentBlock.type === "tool_use") {
@@ -70,6 +75,17 @@ export function _makeMessageChunkFromAnthropicEvent(data, fields) {
70
75
  },
71
76
  ];
72
77
  }
78
+ else if (contentBlock.type === "server_tool_use") {
79
+ // Handle anthropic built-in server tool use (like web search)
80
+ toolCallChunks = [
81
+ {
82
+ id: contentBlock.id,
83
+ index: data.index,
84
+ name: contentBlock.name,
85
+ args: "",
86
+ },
87
+ ];
88
+ }
73
89
  else {
74
90
  toolCallChunks = [];
75
91
  }
@@ -81,7 +97,10 @@ export function _makeMessageChunkFromAnthropicEvent(data, fields) {
81
97
  {
82
98
  index: data.index,
83
99
  ...data.content_block,
84
- input: "",
100
+ input: contentBlock.type === "server_tool_use" ||
101
+ contentBlock.type === "tool_use"
102
+ ? ""
103
+ : undefined,
85
104
  },
86
105
  ],
87
106
  additional_kwargs: {},
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertPromptToAnthropic = void 0;
3
+ exports.convertPromptToAnthropic = convertPromptToAnthropic;
4
4
  const message_inputs_js_1 = require("./message_inputs.cjs");
5
5
  /**
6
6
  * Convert a formatted LangChain prompt (e.g. pulled from the hub) into
@@ -46,4 +46,3 @@ function convertPromptToAnthropic(formattedPrompt) {
46
46
  }
47
47
  return anthropicBody;
48
48
  }
49
- exports.convertPromptToAnthropic = convertPromptToAnthropic;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleToolChoice = void 0;
3
+ exports.handleToolChoice = handleToolChoice;
4
4
  function handleToolChoice(toolChoice) {
5
5
  if (!toolChoice) {
6
6
  return undefined;
@@ -25,4 +25,3 @@ function handleToolChoice(toolChoice) {
25
25
  return toolChoice;
26
26
  }
27
27
  }
28
- exports.handleToolChoice = handleToolChoice;
@@ -1,3 +1,3 @@
1
- import type { MessageCreateParams } from "@anthropic-ai/sdk/resources/index.mjs";
1
+ import type { Anthropic } from "@anthropic-ai/sdk";
2
2
  import { AnthropicToolChoice } from "../types.js";
3
- export declare function handleToolChoice(toolChoice?: AnthropicToolChoice): MessageCreateParams.ToolChoiceAuto | MessageCreateParams.ToolChoiceAny | MessageCreateParams.ToolChoiceTool | undefined;
3
+ export declare function handleToolChoice(toolChoice?: AnthropicToolChoice): Anthropic.Messages.ToolChoiceAuto | Anthropic.Messages.ToolChoiceAny | Anthropic.Messages.ToolChoiceTool | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/anthropic",
3
- "version": "0.3.21",
3
+ "version": "0.3.23",
4
4
  "description": "Anthropic integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -17,7 +17,7 @@
17
17
  "build": "yarn turbo:command build:internal --filter=@langchain/anthropic",
18
18
  "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking --gen-maps",
19
19
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
20
- "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
20
+ "lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
21
21
  "lint": "yarn lint:eslint && yarn lint:dpdm",
22
22
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
23
23
  "clean": "rm -rf .turbo dist/",
@@ -35,13 +35,11 @@
35
35
  "author": "LangChain",
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@anthropic-ai/sdk": "^0.39.0",
39
- "fast-xml-parser": "^4.4.1",
40
- "zod": "^3.22.4",
41
- "zod-to-json-schema": "^3.22.4"
38
+ "@anthropic-ai/sdk": "^0.52.0",
39
+ "fast-xml-parser": "^4.4.1"
42
40
  },
43
41
  "peerDependencies": {
44
- "@langchain/core": ">=0.3.48 <0.4.0"
42
+ "@langchain/core": ">=0.3.58 <0.4.0"
45
43
  },
46
44
  "devDependencies": {
47
45
  "@anthropic-ai/vertex-sdk": "^0.4.1",
@@ -51,7 +49,7 @@
51
49
  "@langchain/standard-tests": "0.0.0",
52
50
  "@swc/core": "^1.3.90",
53
51
  "@swc/jest": "^0.2.29",
54
- "dpdm": "^3.12.0",
52
+ "dpdm": "^3.14.0",
55
53
  "eslint": "^8.33.0",
56
54
  "eslint-config-airbnb-base": "^15.0.0",
57
55
  "eslint-config-prettier": "^8.6.0",
@@ -65,7 +63,8 @@
65
63
  "release-it": "^18.1.2",
66
64
  "rimraf": "^5.0.1",
67
65
  "ts-jest": "^29.1.0",
68
- "typescript": "~5.1.6"
66
+ "typescript": "~5.8.3",
67
+ "zod": "^3.25.32"
69
68
  },
70
69
  "publishConfig": {
71
70
  "access": "public"