{"version":3,"file":"index.cjs","names":["BaseBedrockChat"],"sources":["../../../src/chat_models/bedrock/index.ts"],"sourcesContent":["import {\n  defaultProvider,\n  DefaultProviderInit,\n} from \"@aws-sdk/credential-provider-node\";\n\nimport type { BaseChatModelParams } from \"@langchain/core/language_models/chat_models\";\n\nimport { BaseBedrockInput } from \"../../utils/bedrock/index.js\";\nimport { BedrockChat as BaseBedrockChat } from \"./web.js\";\n\nexport interface BedrockChatFields\n  extends\n    Partial<BaseBedrockInput>,\n    BaseChatModelParams,\n    Partial<DefaultProviderInit> {}\n\n/**\n * AWS Bedrock chat model integration.\n *\n * Setup:\n * Install `@langchain/community` and set the following environment variables:\n *\n * ```bash\n * npm install @langchain/openai\n * export AWS_REGION=\"your-aws-region\"\n * export AWS_SECRET_ACCESS_KEY=\"your-aws-secret-access-key\"\n * export AWS_ACCESS_KEY_ID=\"your-aws-access-key-id\"\n * ```\n *\n * ## [Constructor args](/classes/langchain_community_chat_models_bedrock.BedrockChat.html#constructor)\n *\n * ## [Runtime args](/interfaces/langchain_community_chat_models_bedrock_web.BedrockChatCallOptions.html)\n *\n * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.\n * They can also be passed via `.withConfig`, or the second arg in `.bindTools`, like shown in the examples below:\n *\n * ```typescript\n * // When calling `.withConfig`, call options should be passed via the first argument\n * const llmWithArgsBound = llm.withConfig({\n *   stop: [\"\\n\"],\n *   tools: [...],\n * });\n *\n * // When calling `.bindTools`, call options should be passed via the second argument\n * const llmWithTools = llm.bindTools(\n *   [...],\n *   {\n *     stop: [\"stop on this token!\"],\n *   }\n * );\n * ```\n *\n * ## Examples\n *\n * <details open>\n * <summary><strong>Instantiate</strong></summary>\n *\n * ```typescript\n * import { BedrockChat } from '@langchain/community/chat_models/bedrock';\n *\n * const llm = new BedrockChat({\n *   region: process.env.BEDROCK_AWS_REGION,\n *   maxRetries: 0,\n *   model: \"anthropic.claude-sonnet-4-5-20250929-v1:0\",\n *   temperature: 0,\n *   maxTokens: undefined,\n *   // other params...\n * });\n *\n * // You can also pass credentials in explicitly:\n * const llmWithCredentials = new BedrockChat({\n *   region: process.env.BEDROCK_AWS_REGION,\n *   model: \"anthropic.claude-sonnet-4-5-20250929-v1:0\",\n *   credentials: {\n *     secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY!,\n *     accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID!,\n *   },\n * });\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Invoking</strong></summary>\n *\n * ```typescript\n * const messages = [\n *   {\n *     type: \"system\" as const,\n *     content: \"You are a helpful translator. Translate the user sentence to French.\",\n *   },\n *   {\n *     type: \"human\" as const,\n *     content: \"I love programming.\",\n *   },\n * ];\n * const result = await llm.invoke(messages);\n * console.log(result);\n * ```\n *\n * ```txt\n * AIMessage {\n *   \"content\": \"Here's the translation to French:\\n\\nJ'adore la programmation.\",\n *   \"additional_kwargs\": {\n *     \"id\": \"msg_bdrk_01HCZHa2mKbMZeTeHjLDd286\"\n *   },\n *   \"response_metadata\": {\n *     \"type\": \"message\",\n *     \"role\": \"assistant\",\n *     \"model\": \"claude-sonnet-4-5-20250929\",\n *     \"stop_reason\": \"end_turn\",\n *     \"stop_sequence\": null,\n *     \"usage\": {\n *       \"input_tokens\": 25,\n *       \"output_tokens\": 19\n *     }\n *   },\n *   \"tool_calls\": [],\n *   \"invalid_tool_calls\": []\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Streaming Chunks</strong></summary>\n *\n * ```typescript\n * for await (const chunk of await llm.stream(messages)) {\n *   console.log(chunk);\n * }\n * ```\n *\n * ```txt\n * AIMessageChunk {\n *   \"content\": \"\",\n *   \"additional_kwargs\": {\n *     \"id\": \"msg_bdrk_01RhFuGR9uJ2bj5GbdAma4y6\"\n *   },\n *   \"response_metadata\": {\n *     \"type\": \"message\",\n *     \"role\": \"assistant\",\n *     \"model\": \"claude-sonnet-4-5-20250929\",\n *     \"stop_reason\": null,\n *     \"stop_sequence\": null\n *   },\n * }\n * AIMessageChunk {\n *   \"content\": \"J\",\n * }\n * AIMessageChunk {\n *   \"content\": \"'adore la\",\n * }\n * AIMessageChunk {\n *   \"content\": \" programmation.\",\n * }\n * AIMessageChunk {\n *   \"content\": \"\",\n *   \"additional_kwargs\": {\n *     \"stop_reason\": \"end_turn\",\n *     \"stop_sequence\": null\n *   },\n * }\n * AIMessageChunk {\n *   \"content\": \"\",\n *   \"response_metadata\": {\n *     \"amazon-bedrock-invocationMetrics\": {\n *       \"inputTokenCount\": 25,\n *       \"outputTokenCount\": 11,\n *       \"invocationLatency\": 659,\n *       \"firstByteLatency\": 506\n *     }\n *   },\n *   \"usage_metadata\": {\n *     \"input_tokens\": 25,\n *     \"output_tokens\": 11,\n *     \"total_tokens\": 36\n *   }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Aggregate Streamed Chunks</strong></summary>\n *\n * ```typescript\n * import { AIMessageChunk } from '@langchain/core/messages';\n * import { concat } from '@langchain/core/utils/stream';\n *\n * const stream = await llm.stream(messages);\n * let full: AIMessageChunk | undefined;\n * for await (const chunk of stream) {\n *   full = !full ? chunk : concat(full, chunk);\n * }\n * console.log(full);\n * ```\n *\n * ```txt\n * AIMessageChunk {\n *   \"content\": \"J'adore la programmation.\",\n *   \"additional_kwargs\": {\n *     \"id\": \"msg_bdrk_017b6PuBybA51P5LZ9K6gZHm\",\n *     \"stop_reason\": \"end_turn\",\n *     \"stop_sequence\": null\n *   },\n *   \"response_metadata\": {\n *     \"type\": \"message\",\n *     \"role\": \"assistant\",\n *     \"model\": \"claude-sonnet-4-5-20250929\",\n *     \"stop_reason\": null,\n *     \"stop_sequence\": null,\n *     \"amazon-bedrock-invocationMetrics\": {\n *       \"inputTokenCount\": 25,\n *       \"outputTokenCount\": 11,\n *       \"invocationLatency\": 1181,\n *       \"firstByteLatency\": 1177\n *     }\n *   },\n *   \"usage_metadata\": {\n *     \"input_tokens\": 25,\n *     \"output_tokens\": 11,\n *     \"total_tokens\": 36\n *   }\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Bind tools</strong></summary>\n *\n * ```typescript\n * import { z } from 'zod';\n * import { AIMessage } from '@langchain/core/messages';\n *\n * const GetWeather = {\n *   name: \"GetWeather\",\n *   description: \"Get the current weather in a given location\",\n *   schema: z.object({\n *     location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n *   }),\n * }\n *\n * const GetPopulation = {\n *   name: \"GetPopulation\",\n *   description: \"Get the current population in a given location\",\n *   schema: z.object({\n *     location: z.string().describe(\"The city and state, e.g. San Francisco, CA\")\n *   }),\n * }\n *\n * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);\n * const aiMsg: AIMessage = await llmWithTools.invoke(\n *   \"Which city is hotter today and which is bigger: LA or NY?\"\n * );\n * console.log(aiMsg.tool_calls);\n * ```\n *\n * ```txt\n * [\n *   {\n *     name: 'GetWeather',\n *     args: { location: 'Los Angeles, CA' },\n *     id: 'toolu_bdrk_01R2daqwHR931r4baVNzbe38',\n *     type: 'tool_call'\n *   },\n *   {\n *     name: 'GetWeather',\n *     args: { location: 'New York, NY' },\n *     id: 'toolu_bdrk_01WDadwNc7PGqVZvCN7Dr7eD',\n *     type: 'tool_call'\n *   },\n *   {\n *     name: 'GetPopulation',\n *     args: { location: 'Los Angeles, CA' },\n *     id: 'toolu_bdrk_014b8zLkpAgpxrPfewKinJFc',\n *     type: 'tool_call'\n *   },\n *   {\n *     name: 'GetPopulation',\n *     args: { location: 'New York, NY' },\n *     id: 'toolu_bdrk_01Tt8K2MUP15kNuMDFCLEFKN',\n *     type: 'tool_call'\n *   }\n * ]\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Structured Output</strong></summary>\n *\n * ```typescript\n * const Joke = z.object({\n *   setup: z.string().describe(\"The setup of the joke\"),\n *   punchline: z.string().describe(\"The punchline to the joke\"),\n *   rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\")\n * }).describe('Joke to tell user.');\n *\n * const structuredLlm = llm.withStructuredOutput(Joke);\n * const jokeResult = await structuredLlm.invoke(\"Tell me a joke about cats\");\n * console.log(jokeResult);\n * ```\n *\n * ```txt\n * {\n *   setup: \"Why don't cats play poker in the jungle?\",\n *   punchline: 'Too many cheetahs!'\n * }\n * ```\n * </details>\n *\n * <br />\n *\n * <details>\n * <summary><strong>Response Metadata</strong></summary>\n *\n * ```typescript\n * const aiMsgForResponseMetadata = await llm.invoke(messages);\n * console.log(aiMsgForResponseMetadata.response_metadata);\n * ```\n *\n * ```txt\n * \"response_metadata\": {\n *   \"type\": \"message\",\n *   \"role\": \"assistant\",\n *   \"model\": \"claude-sonnet-4-5-20250929\",\n *   \"stop_reason\": \"end_turn\",\n *   \"stop_sequence\": null,\n *   \"usage\": {\n *     \"input_tokens\": 25,\n *     \"output_tokens\": 19\n *   }\n * }\n * ```\n * </details>\n */\nexport class BedrockChat extends BaseBedrockChat {\n  static lc_name() {\n    return \"BedrockChat\";\n  }\n\n  constructor(fields?: BedrockChatFields) {\n    const {\n      profile,\n      filepath,\n      configFilepath,\n      ignoreCache,\n      mfaCodeProvider,\n      roleAssumer,\n      roleArn,\n      webIdentityTokenFile,\n      roleAssumerWithWebIdentity,\n      ...rest\n    } = fields ?? {};\n    super({\n      ...rest,\n      credentials:\n        rest?.credentials ??\n        defaultProvider({\n          profile,\n          filepath,\n          configFilepath,\n          ignoreCache,\n          mfaCodeProvider,\n          roleAssumer,\n          roleArn,\n          webIdentityTokenFile,\n          roleAssumerWithWebIdentity,\n        }),\n    });\n  }\n}\n\nexport {\n  convertMessagesToPromptAnthropic,\n  convertMessagesToPrompt,\n} from \"./web.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuVA,IAAa,cAAb,cAAiCA,gCAAAA,YAAgB;CAC/C,OAAO,UAAU;AACf,SAAO;;CAGT,YAAY,QAA4B;EACtC,MAAM,EACJ,SACA,UACA,gBACA,aACA,iBACA,aACA,SACA,sBACA,4BACA,GAAG,SACD,UAAU,EAAE;AAChB,QAAM;GACJ,GAAG;GACH,aACE,MAAM,gBAAA,GAAA,kCAAA,iBACU;IACd;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;GACL,CAAC"}