@langchain/core 1.1.44 → 1.1.46

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 (52) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/callbacks/base.d.cts.map +1 -1
  3. package/dist/callbacks/base.d.ts.map +1 -1
  4. package/dist/language_models/base.cjs +1 -1
  5. package/dist/language_models/base.js +1 -1
  6. package/dist/load/index.cjs +19 -0
  7. package/dist/load/index.cjs.map +1 -1
  8. package/dist/load/index.d.cts +4 -0
  9. package/dist/load/index.d.cts.map +1 -1
  10. package/dist/load/index.d.ts +4 -0
  11. package/dist/load/index.d.ts.map +1 -1
  12. package/dist/load/index.js +19 -0
  13. package/dist/load/index.js.map +1 -1
  14. package/dist/load/map_keys.cjs +13 -7
  15. package/dist/load/map_keys.cjs.map +1 -1
  16. package/dist/load/map_keys.d.cts.map +1 -1
  17. package/dist/load/map_keys.d.ts.map +1 -1
  18. package/dist/load/map_keys.js +11 -2
  19. package/dist/load/map_keys.js.map +1 -1
  20. package/dist/messages/base.cjs +10 -0
  21. package/dist/messages/base.cjs.map +1 -1
  22. package/dist/messages/base.d.cts.map +1 -1
  23. package/dist/messages/base.d.ts.map +1 -1
  24. package/dist/messages/base.js +10 -0
  25. package/dist/messages/base.js.map +1 -1
  26. package/dist/runnables/base.cjs +3 -0
  27. package/dist/runnables/base.cjs.map +1 -1
  28. package/dist/runnables/base.d.cts +43 -0
  29. package/dist/runnables/base.d.cts.map +1 -1
  30. package/dist/runnables/base.d.ts +43 -0
  31. package/dist/runnables/base.d.ts.map +1 -1
  32. package/dist/runnables/base.js +3 -0
  33. package/dist/runnables/base.js.map +1 -1
  34. package/dist/runnables/history.cjs +3 -0
  35. package/dist/runnables/history.cjs.map +1 -1
  36. package/dist/runnables/history.d.cts +3 -0
  37. package/dist/runnables/history.d.cts.map +1 -1
  38. package/dist/runnables/history.d.ts +3 -0
  39. package/dist/runnables/history.d.ts.map +1 -1
  40. package/dist/runnables/history.js +3 -0
  41. package/dist/runnables/history.js.map +1 -1
  42. package/dist/tracers/console.cjs +30 -4
  43. package/dist/tracers/console.cjs.map +1 -1
  44. package/dist/tracers/console.d.cts.map +1 -1
  45. package/dist/tracers/console.d.ts.map +1 -1
  46. package/dist/tracers/console.js +28 -1
  47. package/dist/tracers/console.js.map +1 -1
  48. package/dist/utils/env.cjs.map +1 -1
  49. package/dist/utils/env.d.cts.map +1 -1
  50. package/dist/utils/env.d.ts.map +1 -1
  51. package/dist/utils/env.js.map +1 -1
  52. package/package.json +1 -5
@@ -9,6 +9,9 @@ const require_passthrough = require("./passthrough.cjs");
9
9
  * Wraps a LCEL chain and manages history. It appends input messages
10
10
  * and chain outputs as history, and adds the current history messages to
11
11
  * the chain input.
12
+ *
13
+ * @deprecated Use LangGraph's built-in persistence instead.
14
+ *
12
15
  * @example
13
16
  * ```typescript
14
17
  * // pnpm install @langchain/anthropic @langchain/classic
@@ -1 +1 @@
1
- {"version":3,"file":"history.cjs","names":["RunnableBinding","RunnableLambda","RunnablePassthrough","isBaseMessage","HumanMessage","AIMessage"],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,IAAa,6BAAb,cAGUA,eAAAA,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyBC,eAAAA,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAeC,oBAAAA,oBAAoB,OAAO,GACvC,cAAc,cAChB,CAAC,CAAC,WAAW,EAAE,SAAS,iBAAiB,CAAC;EAG7C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,EAAE,CAAC,EAC7D,CAAC,CACH,CACA,WAAW,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B,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
1
+ {"version":3,"file":"history.cjs","names":["RunnableBinding","RunnableLambda","RunnablePassthrough","isBaseMessage","HumanMessage","AIMessage"],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n *\n * @deprecated Use LangGraph's built-in persistence instead.\n *\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,6BAAb,cAGUA,eAAAA,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyBC,eAAAA,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAeC,oBAAAA,oBAAoB,OAAO,GACvC,cAAc,cAChB,CAAC,CAAC,WAAW,EAAE,SAAS,iBAAiB,CAAC;EAG7C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,EAAE,CAAC,EAC7D,CAAC,CACH,CACA,WAAW,EAAE,SAAS,8BAA8B,CAAC;EAExD,MAAM,SAAS,OAAO,UAAU,EAAE;AAElC,QAAM;GACJ,GAAG;GACH;GACA;GACD,CAAC;AACF,OAAK,WAAW,OAAO;AACvB,OAAK,oBAAoB,OAAO;AAChC,OAAK,mBAAmB,OAAO;AAC/B,OAAK,oBAAoB,OAAO;AAChC,OAAK,qBAAqB,OAAO;;CAGnC,kBAEE,YACoB;EACpB,IAAI;AACJ,MACE,OAAO,eAAe,YACtB,CAAC,MAAM,QAAQ,WAAW,IAC1B,CAACC,aAAAA,cAAc,WAAW,EAC1B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K,uBAAuB,KAAA,EAC9B,QAAO,SAAS,OAAO,KAAK,kBAAkB,MAAM,CAAC;AAEvD,SAAO;;CAGT,MAAM,aAAa,KAAU,QAAuC;EAClE,MAAM,UAAU,OAAO,cAAc;EAGrC,IAAI;AAEJ,MAAI,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,QAAQ,IAAI,OAAO,GAAG,CAC3D,UAAS,IAAI,OAAO;MAEpB,UAAS,IAAI;EAEf,IAAI,gBAAgB,KAAK,kBAAkB,OAAO;AAGlD,MAAI,KAAK,uBAAuB,KAAA,GAAW;GACzC,MAAM,mBAAmB,MAAM,QAAQ,aAAa;AACpD,mBAAgB,cAAc,MAAM,iBAAiB,OAAO;;EAG9D,MAAM,cAAc,IAAI;AACxB,MAAI,CAAC,YACH,OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
@@ -18,6 +18,9 @@ interface RunnableWithMessageHistoryInputs<RunInput, RunOutput> extends Omit<Run
18
18
  * Wraps a LCEL chain and manages history. It appends input messages
19
19
  * and chain outputs as history, and adds the current history messages to
20
20
  * the chain input.
21
+ *
22
+ * @deprecated Use LangGraph's built-in persistence instead.
23
+ *
21
24
  * @example
22
25
  * ```typescript
23
26
  * // pnpm install @langchain/anthropic @langchain/classic
@@ -1 +1 @@
1
- {"version":3,"file":"history.d.cts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;KAoBK,yBAAA,OAEA,IAAA,EAAM,KAAA,UAEP,OAAA,CAAQ,sBAAA,GAAyB,0BAAA,IACjC,sBAAA,GACA,0BAAA;AAAA,UAEa,gCAAA,8BAGP,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,SAAA;EAC3C,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAC7B,iBAAA,EAAmB,yBAAA;EACnB,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,MAAA,GAAS,cAAA;AAAA;;;;;;;;;;;;;;;;AATX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA;;;;;;;;;;;;;;cAAa,0BAAA,8BAGH,eAAA,CAAgB,QAAA,EAAU,SAAA;EAClC,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAE7B,gBAAA;EAEA,iBAAA;EAEA,kBAAA;EAEA,iBAAA,EAAmB,yBAAA;EAEnB,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,QAAA,EAAU,SAAA;EAkC/D,iBAAA,CAEE,UAAA,WAAqB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACvD,KAAA,CAAM,WAAA;EAwCT,kBAAA,CAEE,WAAA,WAAsB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACxD,KAAA,CAAM,WAAA;EA2CH,aAAA,CAEJ,KAAA,OACA,MAAA,GAAS,cAAA,GACR,OAAA,CAAQ,WAAA;EASL,YAAA,CAAa,GAAA,EAAK,GAAA,EAAK,MAAA,EAAQ,cAAA,GAAiB,OAAA;EAiChD,YAAA,CAAA,GAAgB,OAAA,EAAS,KAAA,CAAM,cAAA,gBAA2B,OAAA,CAA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@ interface RunnableWithMessageHistoryInputs<RunInput, RunOutput> extends Omit<Run
18
18
  * Wraps a LCEL chain and manages history. It appends input messages
19
19
  * and chain outputs as history, and adds the current history messages to
20
20
  * the chain input.
21
+ *
22
+ * @deprecated Use LangGraph's built-in persistence instead.
23
+ *
21
24
  * @example
22
25
  * ```typescript
23
26
  * // pnpm install @langchain/anthropic @langchain/classic
@@ -1 +1 @@
1
- {"version":3,"file":"history.d.ts","names":[],"sources":["../../src/runnables/history.ts"],"mappings":";;;;;;;KAoBK,yBAAA,OAEA,IAAA,EAAM,KAAA,UAEP,OAAA,CAAQ,sBAAA,GAAyB,0BAAA,IACjC,sBAAA,GACA,0BAAA;AAAA,UAEa,gCAAA,8BAGP,IAAA,CAAK,mBAAA,CAAoB,QAAA,EAAU,SAAA;EAC3C,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAC7B,iBAAA,EAAmB,yBAAA;EACnB,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,MAAA,GAAS,cAAA;AAAA;;;;;;;;;;;;;;;;AATX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA;;;;;;;;;;;;;;cAAa,0BAAA,8BAGH,eAAA,CAAgB,QAAA,EAAU,SAAA;EAClC,QAAA,EAAU,QAAA,CAAS,QAAA,EAAU,SAAA;EAE7B,gBAAA;EAEA,iBAAA;EAEA,kBAAA;EAEA,iBAAA,EAAmB,yBAAA;EAEnB,WAAA,CAAY,MAAA,EAAQ,gCAAA,CAAiC,QAAA,EAAU,SAAA;EAkC/D,iBAAA,CAEE,UAAA,WAAqB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACvD,KAAA,CAAM,WAAA;EAwCT,kBAAA,CAEE,WAAA,WAAsB,WAAA,GAAc,KAAA,CAAM,WAAA,IAAe,MAAA,gBACxD,KAAA,CAAM,WAAA;EA2CH,aAAA,CAEJ,KAAA,OACA,MAAA,GAAS,cAAA,GACR,OAAA,CAAQ,WAAA;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A,GAAiB,OAAA;EAiChD,YAAA,CAAA,GAAgB,OAAA,EAAS,KAAA,CAAM,cAAA,gBAA2B,OAAA,CAAA,OAAA,CAAA,cAAA,CAAA,MAAA;AAAA"}
@@ -9,6 +9,9 @@ import { RunnablePassthrough } from "./passthrough.js";
9
9
  * Wraps a LCEL chain and manages history. It appends input messages
10
10
  * and chain outputs as history, and adds the current history messages to
11
11
  * the chain input.
12
+ *
13
+ * @deprecated Use LangGraph's built-in persistence instead.
14
+ *
12
15
  * @example
13
16
  * ```typescript
14
17
  * // pnpm install @langchain/anthropic @langchain/classic
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","names":[],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,IAAa,6BAAb,cAGU,gBAAqC;CAC7C;CAEA;CAEA;CAEA;CAEA;CAEA,YAAY,QAA+D;EACzE,IAAI,eAAyB,eAAe,MAAM,OAAO,YACvD,KAAK,cAAc,OAAO,WAAW,EAAE,CAAC,CACzC,CAAC,WAAW,EAAE,SAAS,eAAe,CAAC;EAExC,MAAM,cAAc,OAAO,sBAAsB,OAAO;AACxD,MAAI,YACF,gBAAe,oBAAoB,OAAO,GACvC,cAAc,cAChB,CAAC,CAAC,WAAW,EAAE,SAAS,iBAAiB,CAAC;EAG7C,MAAM,QAAQ,aACX,KACC,OAAO,SAAS,cAAc,EAC5B,QAAQ,KAAK,WAAW,KAAK,aAAa,KAAK,UAAU,EAAE,CAAC,EAC7D,CAAC,CACH,CACA,WAAW,EAAE,SAAS,8BAA8B,CAAC;EAExD,MAAM,SAAS,OAAO,UAAU,EAAE;AAElC,QAAM;GACJ,GAAG;GACH;GACA;GACD,CAAC;AACF,OAAK,WAAW,OAAO;AACvB,OAAK,oBAAoB,OAAO;AAChC,OAAK,mBAAmB,OAAO;AAC/B,OAAK,oBAAoB,OAAO;AAChC,OAAK,qBAAqB,OAAO;;CAGnC,kBAEE,YACoB;EACpB,IAAI;AACJ,MACE,OAAO,eAAe,YACtB,CAAC,MAA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AI,KAAK,uBAAuB,KAAA,EAC9B,QAAO,SAAS,OAAO,KAAK,kBAAkB,MAAM,CAAC;AAEvD,SAAO;;CAGT,MAAM,aAAa,KAAU,QAAuC;EAClE,MAAM,UAAU,OAAO,cAAc;EAGrC,IAAI;AAEJ,MAAI,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,QAAQ,IAAI,OAAO,GAAG,CAC3D,UAAS,IAAI,OAAO;MAEpB,UAAS,IAAI;EAEf,IAAI,gBAAgB,KAAK,kBAAkB,OAAO;AAGlD,MAAI,KAAK,uBAAuB,KAAA,GAAW;GACzC,MAAM,mBAAmB,MAAM,QAAQ,aAAa;AACpD,mBAAgB,cAAc,MAAM,iBAAiB,OAAO;;EAG9D,MAAM,cAAc,IAAI;AACxB,MAAI,CAAC,YACH,OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
1
+ {"version":3,"file":"history.js","names":[],"sources":["../../src/runnables/history.ts"],"sourcesContent":["import {\n BaseChatMessageHistory,\n BaseListChatMessageHistory,\n} from \"../chat_history.js\";\nimport {\n AIMessage,\n BaseMessage,\n HumanMessage,\n isBaseMessage,\n} from \"../messages/index.js\";\nimport { Run } from \"../tracers/base.js\";\nimport {\n Runnable,\n RunnableBinding,\n type RunnableBindingArgs,\n RunnableLambda,\n} from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { RunnablePassthrough } from \"./passthrough.js\";\n\ntype GetSessionHistoryCallable = (\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Array<any>\n) =>\n | Promise<BaseChatMessageHistory | BaseListChatMessageHistory>\n | BaseChatMessageHistory\n | BaseListChatMessageHistory;\n\nexport interface RunnableWithMessageHistoryInputs<\n RunInput,\n RunOutput,\n> extends Omit<RunnableBindingArgs<RunInput, RunOutput>, \"bound\" | \"config\"> {\n runnable: Runnable<RunInput, RunOutput>;\n getMessageHistory: GetSessionHistoryCallable;\n inputMessagesKey?: string;\n outputMessagesKey?: string;\n historyMessagesKey?: string;\n config?: RunnableConfig;\n}\n\n/**\n * Wraps a LCEL chain and manages history. It appends input messages\n * and chain outputs as history, and adds the current history messages to\n * the chain input.\n *\n * @deprecated Use LangGraph's built-in persistence instead.\n *\n * @example\n * ```typescript\n * // pnpm install @langchain/anthropic @langchain/classic\n *\n * import {\n * ChatPromptTemplate,\n * MessagesPlaceholder,\n * } from \"@langchain/core/prompts\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatMessageHistory } from \"@langchain/classic/stores/message/in_memory\";\n *\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\"system\", \"You're an assistant who's good at {ability}\"],\n * new MessagesPlaceholder(\"history\"),\n * [\"human\", \"{question}\"],\n * ]);\n *\n * const chain = prompt.pipe(new ChatAnthropic({}));\n *\n * const chainWithHistory = new RunnableWithMessageHistory({\n * runnable: chain,\n * getMessageHistory: (sessionId) =>\n * new UpstashRedisChatMessageHistory({\n * sessionId,\n * config: {\n * url: process.env.UPSTASH_REDIS_REST_URL!,\n * token: process.env.UPSTASH_REDIS_REST_TOKEN!,\n * },\n * }),\n * inputMessagesKey: \"question\",\n * historyMessagesKey: \"history\",\n * });\n *\n * const result = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What does cosine mean?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n *\n * const result2 = await chainWithHistory.invoke(\n * {\n * ability: \"math\",\n * question: \"What's its inverse?\",\n * },\n * {\n * configurable: {\n * sessionId: \"some_string_identifying_a_user\",\n * },\n * }\n * );\n * ```\n */\nexport class RunnableWithMessageHistory<\n RunInput,\n RunOutput,\n> extends RunnableBinding<RunInput, RunOutput> {\n runnable: Runnable<RunInput, RunOutput>;\n\n inputMessagesKey?: string;\n\n outputMessagesKey?: string;\n\n historyMessagesKey?: string;\n\n getMessageHistory: GetSessionHistoryCallable;\n\n constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {\n let historyChain: Runnable = RunnableLambda.from((input, options) =>\n this._enterHistory(input, options ?? {})\n ).withConfig({ runName: \"loadHistory\" });\n\n const messagesKey = fields.historyMessagesKey ?? fields.inputMessagesKey;\n if (messagesKey) {\n historyChain = RunnablePassthrough.assign({\n [messagesKey]: historyChain,\n }).withConfig({ runName: \"insertHistory\" });\n }\n\n const bound = historyChain\n .pipe(\n fields.runnable.withListeners({\n onEnd: (run, config) => this._exitHistory(run, config ?? {}),\n })\n )\n .withConfig({ runName: \"RunnableWithMessageHistory\" });\n\n const config = fields.config ?? {};\n\n super({\n ...fields,\n config,\n bound,\n });\n this.runnable = fields.runnable;\n this.getMessageHistory = fields.getMessageHistory;\n this.inputMessagesKey = fields.inputMessagesKey;\n this.outputMessagesKey = fields.outputMessagesKey;\n this.historyMessagesKey = fields.historyMessagesKey;\n }\n\n _getInputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n inputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedInputValue;\n if (\n typeof inputValue === \"object\" &&\n !Array.isArray(inputValue) &&\n !isBaseMessage(inputValue)\n ) {\n let key;\n if (this.inputMessagesKey) {\n key = this.inputMessagesKey;\n } else if (Object.keys(inputValue).length === 1) {\n key = Object.keys(inputValue)[0];\n } else {\n key = \"input\";\n }\n if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {\n parsedInputValue = inputValue[key][0];\n } else {\n parsedInputValue = inputValue[key];\n }\n } else {\n parsedInputValue = inputValue;\n }\n if (typeof parsedInputValue === \"string\") {\n return [new HumanMessage(parsedInputValue)];\n } else if (Array.isArray(parsedInputValue)) {\n return parsedInputValue;\n } else if (isBaseMessage(parsedInputValue)) {\n return [parsedInputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages.\\nGot ${JSON.stringify(\n parsedInputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n _getOutputMessages(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n outputValue: string | BaseMessage | Array<BaseMessage> | Record<string, any>\n ): Array<BaseMessage> {\n let parsedOutputValue;\n if (\n !Array.isArray(outputValue) &&\n !isBaseMessage(outputValue) &&\n typeof outputValue !== \"string\"\n ) {\n let key;\n if (this.outputMessagesKey !== undefined) {\n key = this.outputMessagesKey;\n } else if (Object.keys(outputValue).length === 1) {\n key = Object.keys(outputValue)[0];\n } else {\n key = \"output\";\n }\n // If you are wrapping a chat model directly\n // The output is actually this weird generations object\n if (outputValue.generations !== undefined) {\n parsedOutputValue = outputValue.generations[0][0].message;\n } else {\n parsedOutputValue = outputValue[key];\n }\n } else {\n parsedOutputValue = outputValue;\n }\n\n if (typeof parsedOutputValue === \"string\") {\n return [new AIMessage(parsedOutputValue)];\n } else if (Array.isArray(parsedOutputValue)) {\n return parsedOutputValue;\n } else if (isBaseMessage(parsedOutputValue)) {\n return [parsedOutputValue];\n } else {\n throw new Error(\n `Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(\n parsedOutputValue,\n null,\n 2\n )}`\n );\n }\n }\n\n async _enterHistory(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n input: any,\n kwargs?: RunnableConfig\n ): Promise<BaseMessage[]> {\n const history = kwargs?.configurable?.messageHistory;\n const messages = await history.getMessages();\n if (this.historyMessagesKey === undefined) {\n return messages.concat(this._getInputMessages(input));\n }\n return messages;\n }\n\n async _exitHistory(run: Run, config: RunnableConfig): Promise<void> {\n const history = config.configurable?.messageHistory;\n\n // Get input messages\n let inputs;\n // Chat model inputs are nested arrays\n if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {\n inputs = run.inputs[0];\n } else {\n inputs = run.inputs;\n }\n let inputMessages = this._getInputMessages(inputs);\n // If historic messages were prepended to the input messages, remove them to\n // avoid adding duplicate messages to history.\n if (this.historyMessagesKey === undefined) {\n const existingMessages = await history.getMessages();\n inputMessages = inputMessages.slice(existingMessages.length);\n }\n // Get output messages\n const outputValue = run.outputs;\n if (!outputValue) {\n throw new Error(\n `Output values from 'Run' undefined. Run: ${JSON.stringify(\n run,\n null,\n 2\n )}`\n );\n }\n const outputMessages = this._getOutputMessages(outputValue);\n await history.addMessages([...inputMessages, ...outputMessages]);\n }\n\n async _mergeConfig(...configs: Array<RunnableConfig | undefined>) {\n const config = await super._mergeConfig(...configs);\n // Extract sessionId\n if (!config.configurable || !config.configurable.sessionId) {\n const exampleInput = {\n [this.inputMessagesKey ?? \"input\"]: \"foo\",\n };\n const exampleConfig = { configurable: { sessionId: \"123\" } };\n throw new Error(\n `sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\\n` +\n `eg. chain.invoke(${JSON.stringify(exampleInput)}, ${JSON.stringify(\n exampleConfig\n )})`\n );\n }\n // attach messageHistory\n const { sessionId } = config.configurable;\n config.configurable.messageHistory =\n await this.getMessageHistory(sessionId);\n return config;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,6BAAb,cAGU,gBAAqC;CAC7C;CAEA;CAEA;CAEA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OAAM,IAAI,MACR,4CAA4C,KAAK,UAC/C,KACA,MACA,EACD,GACF;EAEH,MAAM,iBAAiB,KAAK,mBAAmB,YAAY;AAC3D,QAAM,QAAQ,YAAY,CAAC,GAAG,eAAe,GAAG,eAAe,CAAC;;CAGlE,MAAM,aAAa,GAAG,SAA4C;EAChE,MAAM,SAAS,MAAM,MAAM,aAAa,GAAG,QAAQ;AAEnD,MAAI,CAAC,OAAO,gBAAgB,CAAC,OAAO,aAAa,WAAW;GAC1D,MAAM,eAAe,GAClB,KAAK,oBAAoB,UAAU,OACrC;AAED,SAAM,IAAI,MACR,gHACsB,KAAK,UAAU,aAAa,CAAC,IAAI,KAAK,UAHxC,EAAE,cAAc,EAAE,WAAW,OAAO,EAAE,CAKvD,CAAC,GACL;;EAGH,MAAM,EAAE,cAAc,OAAO;AAC7B,SAAO,aAAa,iBAClB,MAAM,KAAK,kBAAkB,UAAU;AACzC,SAAO"}
@@ -1,10 +1,36 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
3
  const require_tracers_base = require("./base.cjs");
4
- let ansi_styles = require("ansi-styles");
5
- ansi_styles = require_runtime.__toESM(ansi_styles, 1);
6
4
  //#region src/tracers/console.ts
7
5
  var console_exports = /* @__PURE__ */ require_runtime.__exportAll({ ConsoleCallbackHandler: () => ConsoleCallbackHandler });
6
+ const styles = {
7
+ bold: {
8
+ open: "\x1B[1m",
9
+ close: "\x1B[22m"
10
+ },
11
+ color: {
12
+ grey: {
13
+ open: "\x1B[90m",
14
+ close: "\x1B[39m"
15
+ },
16
+ green: {
17
+ open: "\x1B[32m",
18
+ close: "\x1B[39m"
19
+ },
20
+ cyan: {
21
+ open: "\x1B[36m",
22
+ close: "\x1B[39m"
23
+ },
24
+ red: {
25
+ open: "\x1B[31m",
26
+ close: "\x1B[39m"
27
+ },
28
+ blue: {
29
+ open: "\x1B[34m",
30
+ close: "\x1B[39m"
31
+ }
32
+ }
33
+ };
8
34
  function wrap(style, text) {
9
35
  return `${style.open}${text}${style.close}`;
10
36
  }
@@ -26,7 +52,7 @@ function elapsed(run) {
26
52
  if (elapsed < 1e3) return `${elapsed}ms`;
27
53
  return `${(elapsed / 1e3).toFixed(2)}s`;
28
54
  }
29
- const { color } = ansi_styles.default;
55
+ const { color } = styles;
30
56
  /**
31
57
  * A tracer that logs all events to the console. It extends from the
32
58
  * `BaseTracer` class and overrides its methods to provide custom logging
@@ -79,7 +105,7 @@ var ConsoleCallbackHandler = class extends require_tracers_base.BaseTracer {
79
105
  getBreadcrumbs(run) {
80
106
  const string = [...this.getParents(run).reverse(), run].map((parent, i, arr) => {
81
107
  const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;
82
- return i === arr.length - 1 ? wrap(ansi_styles.default.bold, name) : name;
108
+ return i === arr.length - 1 ? wrap(styles.bold, name) : name;
83
109
  }).join(" > ");
84
110
  return wrap(color.grey, string);
85
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"console.cjs","names":["styles","BaseTracer"],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import type { CSPair } from \"ansi-styles\";\nimport styles from \"ansi-styles\";\nimport { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;;;AAIA,SAAS,KAAK,OAAe,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM;;AAGtC,SAAS,iBAAiB,KAAc,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;SAC7B;AACN,SAAO;;;AAIX,SAAS,gBAAgB,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,KAAA,EAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;;AAGlD,SAAS,QAAQ,KAAkB;AACjC,KAAI,CAAC,IAAI,SAAU,QAAO;CAC1B,MAAM,UAAU,IAAI,WAAW,IAAI;AACnC,KAAI,UAAU,IACZ,QAAO,GAAG,QAAQ;AAEpB,QAAO,IAAI,UAAU,KAAM,QAAQ,EAAE,CAAC;;AAGxC,MAAM,EAAE,UAAUA,YAAAA;;;;;;;;;;;;;;;;AAiBlB,IAAa,yBAAb,cAA4CC,qBAAAA,WAAW;CACrD,OAAO;;;;;;;CAQP,WAAqB,MAAW;AAC9B,SAAO,QAAQ,SAAS;;;;;;;CAU1B,WAAW,KAAU;EACnB,MAAM,UAAiB,EAAE;EACzB,IAAI,aAAa;AACjB,SAAO,WAAW,eAAe;GAC/B,MAAM,SAAS,KAAK,OAAO,IAAI,WAAW,cAAc;AACxD,OAAI,QAAQ;AACV,YAAQ,KAAK,OAAO;AACpB,iBAAa;SAEb;;AAGJ,SAAO;;;;;;;;CAST,eAAe,KAAU;EAEvB,MAAM,SAAS,CAAC,GADA,KAAK,WAAW,IAAI,CAAC,SAAS,EAClB,IAAI,CAC7B,KAAK,QAAQ,G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C,sCAAsC,iBACtC,IAAI,OACJ,UACD,GACF;;;;;;;CAQH,cAAc,KAAU;EACtB,MAAM,WAAW;EACjB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KACD,MAAM,MACN,iBACD,CAAC,IAAI,OAAO,2BAA2B,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,GACF"}
1
+ {"version":3,"file":"console.cjs","names":["BaseTracer"],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\ninterface CSPair {\n open: string;\n close: string;\n}\n\nconst styles: {\n bold: CSPair;\n color: Record<\"grey\" | \"green\" | \"cyan\" | \"red\" | \"blue\", CSPair>;\n} = {\n bold: { open: \"\\u001b[1m\", close: \"\\u001b[22m\" },\n color: {\n grey: { open: \"\\u001b[90m\", close: \"\\u001b[39m\" },\n green: { open: \"\\u001b[32m\", close: \"\\u001b[39m\" },\n cyan: { open: \"\\u001b[36m\", close: \"\\u001b[39m\" },\n red: { open: \"\\u001b[31m\", close: \"\\u001b[39m\" },\n blue: { open: \"\\u001b[34m\", close: \"\\u001b[39m\" },\n },\n};\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;AAOA,MAAM,SAGF;CACF,MAAM;EAAE,MAAM;EAAa,OAAO;EAAc;CAChD,OAAO;EACL,MAAM;GAAE,MAAM;GAAc,OAAO;GAAc;EACjD,OAAO;GAAE,MAAM;GAAc,OAAO;GAAc;EAClD,MAAM;GAAE,MAAM;GAAc,OAAO;GAAc;EACjD,KAAK;GAAE,MAAM;GAAc,OAAO;GAAc;EAChD,MAAM;GAAE,MAAM;GAAc,OAAO;GAAc;EAClD;CACF;AAED,SAAS,KAAK,OAAe,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM;;AAGtC,SAAS,iBAAiB,KAAc,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;SAC7B;AACN,SAAO;;;AAIX,SAAS,gBAAgB,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,KAAA,EAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;;AAGlD,SAAS,QAAQ,KAAkB;AACjC,KAAI,CAAC,IAAI,SAAU,QAAO;CAC1B,MAAM,UAAU,IAAI,WAAW,IAAI;AACnC,KAAI,UAAU,IACZ,QAAO,GAAG,QAAQ;AAEpB,QAAO,IAAI,UAAU,KAAM,QAAQ,EAAE,CAAC;;AAGxC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;AAiBlB,IAAa,yBAAb,cAA4CA,qBAAAA,WAAW;CACrD,OAAO;;;;;;;CAQP,WAAqB,MAAW;AAC9B,SAAO,QAAQ,SAAS;;;;;;;CAU1B,WAAW,KAAU;EACnB,MAAM,UAAiB,EAAE;EACzB,IAAI,aAAa;AACjB,SAAO,WAAW,eAAe;GA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AA,EAAK,GAAA;;;;;;EAiBjB,gBAAA,CAAiB,GAAA,EAAK,GAAA;;;;;;EAkBtB,cAAA,CAAe,GAAA,EAAK,GAAA;;;;;;EAiBpB,gBAAA,CAAiB,GAAA,EAAK,GAAA;;;;;;EAiBtB,aAAA,CAAc,GAAA,EAAK,GAAA;AAAA"}
1
+ {"version":3,"file":"console.d.cts","names":[],"sources":["../../src/tracers/console.ts"],"mappings":";;;;;AAuEA;;;;;;;;;;;;;cAAa,sBAAA,SAA+B,UAAA;EAC1C,IAAA;EAoLe;;;;;;EAAA,UA5KL,UAAA,CAAW,IAAA,EAAM,GAAA,GAAG,OAAA;EATsB;;;;;EAoBpD,UAAA,CAAW,GAAA,EAAK,GAAA,GAAG,GAAA;EAXE;;;;;;EAgCrB,cAAA,CAAe,GAAA,EAAK,GAAA;EAAA;;;;;EAkBpB,YAAA,CAAa,GAAA,EAAK,GAAA;EAkBF;;;;;EAAhB,UAAA,CAAW,GAAA,EAAK,GAAA;EAkCA;;;;;EAjBhB,YAAA,CAAa,GAAA,EAAK,GAAA;EAwDF;;;;;EAvChB,UAAA,CAAW,GAAA,EAAK,GAAA;EAsED;;;;;EAhDf,QAAA,CAAS,GAAA,EAAK,GAAA;EAkFQ;;;;;EAjEtB,UAAA,CAAW,GAAA,EAAK,GAAA;EAoGM;;;;;EAtFtB,WAAA,CAAY,GAAA,EAAK,GAAA;EAuGK;;;;;EAtFtB,SAAA,CAAU,GAAA,EAAK,GAAA;;;;;;EAiBf,WAAA,CAAY,GAAA,EAAK,GAAA;;;;;;EAiBjB,gBAAA,CAAiB,GAAA,EAAK,GAAA;;;;;;EAkBtB,cAAA,CAAe,GAAA,EAAK,GAAA;;;;;;EAiBpB,gBAAA,CAAiB,GAAA,EAAK,GAAA;;;;;;EAiBtB,aAAA,CAAc,GAAA,EAAK,GAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"console.d.ts","names":[],"sources":["../../src/tracers/console.ts"],"mappings":";;;;;AAsDA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;;;;;EAAhB,UAAA,CAAW,GAAA,EAAK,GAAA;EAkCA;;;;;EAjBhB,YAAA,CAAa,GAAA,EAAK,GAAA;EAwDF;;;;;EAvChB,UAAA,CAAW,GAAA,EAAK,GAAA;EAsED;;;;;EAhDf,QAAA,CAAS,GAAA,EAAK,GAAA;EAkFQ;;;;;EAjEtB,UAAA,CAAW,GAAA,EAAK,GAAA;EAoGM;;;;;EAtFtB,WAAA,CAAY,GAAA,EAAK,GAAA;EAuGK;;;;;EAtFtB,SAAA,CAAU,GAAA,EAAK,GAAA;;;;;;EAiBf,WAAA,CAAY,GAAA,EAAK,GAAA;;;;;;EAiBjB,gBAAA,CAAiB,GAAA,EAAK,GAAA;;;;;;EAkBtB,cAAA,CAAe,GAAA,EAAK,GAAA;;;;;;EAiBpB,gBAAA,CAAiB,GAAA,EAAK,GAAA;;;;;;EAiBtB,aAAA,CAAc,GAAA,EAAK,GAAA;AAAA"}
@@ -1,8 +1,35 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { BaseTracer } from "./base.js";
3
- import styles from "ansi-styles";
4
3
  //#region src/tracers/console.ts
5
4
  var console_exports = /* @__PURE__ */ __exportAll({ ConsoleCallbackHandler: () => ConsoleCallbackHandler });
5
+ const styles = {
6
+ bold: {
7
+ open: "\x1B[1m",
8
+ close: "\x1B[22m"
9
+ },
10
+ color: {
11
+ grey: {
12
+ open: "\x1B[90m",
13
+ close: "\x1B[39m"
14
+ },
15
+ green: {
16
+ open: "\x1B[32m",
17
+ close: "\x1B[39m"
18
+ },
19
+ cyan: {
20
+ open: "\x1B[36m",
21
+ close: "\x1B[39m"
22
+ },
23
+ red: {
24
+ open: "\x1B[31m",
25
+ close: "\x1B[39m"
26
+ },
27
+ blue: {
28
+ open: "\x1B[34m",
29
+ close: "\x1B[39m"
30
+ }
31
+ }
32
+ };
6
33
  function wrap(style, text) {
7
34
  return `${style.open}${text}${style.close}`;
8
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"console.js","names":[],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import type { CSPair } from \"ansi-styles\";\nimport styles from \"ansi-styles\";\nimport { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;;AAIA,SAAS,KAAK,OAAe,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM;;AAGtC,SAAS,iBAAiB,KAAc,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;SAC7B;AACN,SAAO;;;AAIX,SAAS,gBAAgB,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MAAM;AAGrB,KAAI,UAAU,QAAQ,UAAU,KAAA,EAC9B,QAAO;AAGT,QAAO,iBAAiB,OAAO,MAAM,UAAU,CAAC;;AAGlD,SAAS,QAAQ,KAAkB;AACjC,KAAI,CAAC,IAAI,SAAU,QAAO;CAC1B,MAAM,UAAU,IAAI,WAAW,IAAI;AACnC,KAAI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D,IACD,CAAC,iCAAiC,iBACjC,IAAI,OACJ,UACD,GACF;;;;;;;CAQH,iBAAiB,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KACD,MAAM,OACN,oBACD,CAAC,IAAI,OAAO,uCAAuC,iBAClD,IAAI,QACJ,WACD,GACF;;;;;;;CAQH,eAAe,KAAU;EACvB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KAAK,MAAM,MAAM,kBAAkB,CAAC,IAAI,OAAO,KAAK,QACrD,IACD,CAAC,uCAAuC,iBACvC,IAAI,SACJ,YACD,GACF;;;;;;;CAQH,iBAAiB,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KAAK,MAAM,KAAK,oBAAoB,CAAC,IAAI,OAAO,KAAK,QACtD,IACD,CAAC,sCAAsC,iBACtC,IAAI,OACJ,UACD,GACF;;;;;;;CAQH,cAAc,KAAU;EACtB,MAAM,WAAW;EACjB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KACD,MAAM,MACN,iBACD,CAAC,IAAI,OAAO,2BAA2B,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,GACF"}
1
+ {"version":3,"file":"console.js","names":[],"sources":["../../src/tracers/console.ts"],"sourcesContent":["import { BaseTracer, type AgentRun, type Run } from \"./base.js\";\n\ninterface CSPair {\n open: string;\n close: string;\n}\n\nconst styles: {\n bold: CSPair;\n color: Record<\"grey\" | \"green\" | \"cyan\" | \"red\" | \"blue\", CSPair>;\n} = {\n bold: { open: \"\\u001b[1m\", close: \"\\u001b[22m\" },\n color: {\n grey: { open: \"\\u001b[90m\", close: \"\\u001b[39m\" },\n green: { open: \"\\u001b[32m\", close: \"\\u001b[39m\" },\n cyan: { open: \"\\u001b[36m\", close: \"\\u001b[39m\" },\n red: { open: \"\\u001b[31m\", close: \"\\u001b[39m\" },\n blue: { open: \"\\u001b[34m\", close: \"\\u001b[39m\" },\n },\n};\n\nfunction wrap(style: CSPair, text: string) {\n return `${style.open}${text}${style.close}`;\n}\n\nfunction tryJsonStringify(obj: unknown, fallback: string) {\n try {\n return JSON.stringify(obj, null, 2);\n } catch {\n return fallback;\n }\n}\n\nfunction formatKVMapItem(value: unknown) {\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (value === null || value === undefined) {\n return value;\n }\n\n return tryJsonStringify(value, value.toString());\n}\n\nfunction elapsed(run: Run): string {\n if (!run.end_time) return \"\";\n const elapsed = run.end_time - run.start_time;\n if (elapsed < 1000) {\n return `${elapsed}ms`;\n }\n return `${(elapsed / 1000).toFixed(2)}s`;\n}\n\nconst { color } = styles;\n\n/**\n * A tracer that logs all events to the console. It extends from the\n * `BaseTracer` class and overrides its methods to provide custom logging\n * functionality.\n * @example\n * ```typescript\n *\n * const llm = new ChatAnthropic({\n * temperature: 0,\n * tags: [\"example\", \"callbacks\", \"constructor\"],\n * callbacks: [new ConsoleCallbackHandler()],\n * });\n *\n * ```\n */\nexport class ConsoleCallbackHandler extends BaseTracer {\n name = \"console_callback_handler\" as const;\n\n /**\n * Method used to persist the run. In this case, it simply returns a\n * resolved promise as there's no persistence logic.\n * @param _run The run to persist.\n * @returns A resolved promise.\n */\n protected persistRun(_run: Run) {\n return Promise.resolve();\n }\n\n // utility methods\n\n /**\n * Method used to get all the parent runs of a given run.\n * @param run The run whose parents are to be retrieved.\n * @returns An array of parent runs.\n */\n getParents(run: Run) {\n const parents: Run[] = [];\n let currentRun = run;\n while (currentRun.parent_run_id) {\n const parent = this.runMap.get(currentRun.parent_run_id);\n if (parent) {\n parents.push(parent);\n currentRun = parent;\n } else {\n break;\n }\n }\n return parents;\n }\n\n /**\n * Method used to get a string representation of the run's lineage, which\n * is used in logging.\n * @param run The run whose lineage is to be retrieved.\n * @returns A string representation of the run's lineage.\n */\n getBreadcrumbs(run: Run) {\n const parents = this.getParents(run).reverse();\n const string = [...parents, run]\n .map((parent, i, arr) => {\n const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;\n return i === arr.length - 1 ? wrap(styles.bold, name) : name;\n })\n .join(\" > \");\n return wrap(color.grey, string);\n }\n\n // logging methods\n\n /**\n * Method used to log the start of a chain run.\n * @param run The chain run that has started.\n * @returns void\n */\n onChainStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[chain/start]\"\n )} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a chain run.\n * @param run The chain run that has ended.\n * @returns void\n */\n onChainEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[chain/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Chain run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a chain run.\n * @param run The chain run that has errored.\n * @returns void\n */\n onChainError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[chain/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Chain run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of an LLM run.\n * @param run The LLM run that has started.\n * @returns void\n */\n onLLMStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n const inputs =\n \"prompts\" in run.inputs\n ? { prompts: (run.inputs.prompts as string[]).map((p) => p.trim()) }\n : run.inputs;\n console.log(\n `${wrap(\n color.green,\n \"[llm/start]\"\n )} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(\n inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of an LLM run.\n * @param run The LLM run that has ended.\n * @returns void\n */\n onLLMEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[llm/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting LLM run with output: ${tryJsonStringify(\n run.outputs,\n \"[response]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of an LLM run.\n * @param run The LLM run that has errored.\n * @returns void\n */\n onLLMError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[llm/error]\")} [${crumbs}] [${elapsed(\n run\n )}] LLM run errored with error: ${tryJsonStringify(run.error, \"[error]\")}`\n );\n }\n\n /**\n * Method used to log the start of a tool run.\n * @param run The tool run that has started.\n * @returns void\n */\n onToolStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[tool/start]\"\n )} [${crumbs}] Entering Tool run with input: \"${formatKVMapItem(\n run.inputs.input\n )}\"`\n );\n }\n\n /**\n * Method used to log the end of a tool run.\n * @param run The tool run that has ended.\n * @returns void\n */\n onToolEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n\n console.log(\n `${wrap(color.cyan, \"[tool/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Tool run with output: \"${formatKVMapItem(\n run.outputs?.output\n )}\"`\n );\n }\n\n /**\n * Method used to log any errors of a tool run.\n * @param run The tool run that has errored.\n * @returns void\n */\n onToolError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[tool/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Tool run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the start of a retriever run.\n * @param run The retriever run that has started.\n * @returns void\n */\n onRetrieverStart(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.green,\n \"[retriever/start]\"\n )} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(\n run.inputs,\n \"[inputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log the end of a retriever run.\n * @param run The retriever run that has ended.\n * @returns void\n */\n onRetrieverEnd(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.cyan, \"[retriever/end]\")} [${crumbs}] [${elapsed(\n run\n )}] Exiting Retriever run with output: ${tryJsonStringify(\n run.outputs,\n \"[outputs]\"\n )}`\n );\n }\n\n /**\n * Method used to log any errors of a retriever run.\n * @param run The retriever run that has errored.\n * @returns void\n */\n onRetrieverError(run: Run) {\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(color.red, \"[retriever/error]\")} [${crumbs}] [${elapsed(\n run\n )}] Retriever run errored with error: ${tryJsonStringify(\n run.error,\n \"[error]\"\n )}`\n );\n }\n\n /**\n * Method used to log the action selected by the agent.\n * @param run The run in which the agent action occurred.\n * @returns void\n */\n onAgentAction(run: Run) {\n const agentRun = run as AgentRun;\n const crumbs = this.getBreadcrumbs(run);\n console.log(\n `${wrap(\n color.blue,\n \"[agent/action]\"\n )} [${crumbs}] Agent selected action: ${tryJsonStringify(\n agentRun.actions[agentRun.actions.length - 1],\n \"[action]\"\n )}`\n );\n }\n}\n"],"mappings":";;;;AAOA,MAAM,SAGF;CACF,MAAM;EAAE,MAAM;EAAa,OAAO;EAAc;CAChD,OAAO;EACL,MAAM;GAAE,MAAM;GAAc,OAAO;GAAc;EACjD,OAAO;GAAE,MAAM;GAAc,OAAO;GAAc;EAClD,MAAM;GAAE,MAAM;GAAc,OAAO;GAAc;EACjD,KAAK;GAAE,MAAM;GAAc,OAAO;GAAc;EAChD,MAAM;GAAE,MAAM;GAAc,OAAO;GAAc;EAClD;CACF;AAED,SAAS,KAAK,OAAe,MAAc;AACzC,QAAO,GAAG,MAAM,OAAO,OAAO,MAAM;;AAGtC,SAAS,iBAAiB,KAAc,UAAkB;AACxD,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,MAAM,EAAE;SAC7B;AACN,SAAO;;;AAIX,SAAS,gBAAgB,OAAgB;AACvC,KAAI,OAAO,UAAU,SACnB,QAAO,MAAM,MA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AI,OAAO,KAAK,QAChD,IACD,CAAC,mCAAmC,gBACnC,IAAI,SAAS,OACd,CAAC,GACH;;;;;;;CAQH,YAAY,KAAU;EACpB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KAAK,MAAM,KAAK,eAAe,CAAC,IAAI,OAAO,KAAK,QACjD,IACD,CAAC,iCAAiC,iBACjC,IAAI,OACJ,UACD,GACF;;;;;;;CAQH,iBAAiB,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KACD,MAAM,OACN,oBACD,CAAC,IAAI,OAAO,uCAAuC,iBAClD,IAAI,QACJ,WACD,GACF;;;;;;;CAQH,eAAe,KAAU;EACvB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KAAK,MAAM,MAAM,kBAAkB,CAAC,IAAI,OAAO,KAAK,QACrD,IACD,CAAC,uCAAuC,iBACvC,IAAI,SACJ,YACD,GACF;;;;;;;CAQH,iBAAiB,KAAU;EACzB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KAAK,MAAM,KAAK,oBAAoB,CAAC,IAAI,OAAO,KAAK,QACtD,IACD,CAAC,sCAAsC,iBACtC,IAAI,OACJ,UACD,GACF;;;;;;;CAQH,cAAc,KAAU;EACtB,MAAM,WAAW;EACjB,MAAM,SAAS,KAAK,eAAe,IAAI;AACvC,UAAQ,IACN,GAAG,KACD,MAAM,MACN,iBACD,CAAC,IAAI,OAAO,2BAA2B,iBACtC,SAAS,QAAQ,SAAS,QAAQ,SAAS,IAC3C,WACD,GACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CACjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
1
+ {"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n // @ts-expect-error Conflicts with langsmith's ambient Deno declaration\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n // @ts-expect-error Langsmith's Deno declaration is missing `env`\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CAEjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.cts","names":[],"sources":["../../src/utils/env.ts"],"mappings":";QACQ,MAAA;EAAA,MACA,IAAA;IAEA,OAAA;MACE,IAAA;IAAA;IAEF,GAAA;MACE,GAAA,GAAM,IAAA;IAAA;EAAA;AAAA;AAAA,cAMH,SAAA;AAAA,cAGA,WAAA;AAAA,cAKA,OAAA;AAAA,cAMA,MAAA;AAAA,cAGA,MAAA;AAAA,cAMA,MAAA;AAAA,KAmBD,kBAAA;EACV,OAAA;EACA,cAAA;EACA,OAAA;EACA,cAAA;AAAA;AAAA,iBAKc,qBAAA,CAAA,GAAyB,kBAAA;AAAA,iBAYzB,sBAAA,CAAuB,IAAA"}
1
+ {"version":3,"file":"env.d.cts","names":[],"sources":["../../src/utils/env.ts"],"mappings":";QACQ,MAAA;EAAA,MAEA,IAAA;IAEA,OAAA;MACE,IAAA;IAAA;IAEF,GAAA;MACE,GAAA,GAAM,IAAA;IAAA;EAAA;AAAA;AAAA,cAMH,SAAA;AAAA,cAGA,WAAA;AAAA,cAKA,OAAA;AAAA,cAMA,MAAA;AAAA,cAGA,MAAA;AAAA,cAMA,MAAA;AAAA,KAmBD,kBAAA;EACV,OAAA;EACA,cAAA;EACA,OAAA;EACA,cAAA;AAAA;AAAA,iBAKc,qBAAA,CAAA,GAAyB,kBAAA;AAAA,iBAYzB,sBAAA,CAAuB,IAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","names":[],"sources":["../../src/utils/env.ts"],"mappings":";QACQ,MAAA;EAAA,MACA,IAAA;IAEA,OAAA;MACE,IAAA;IAAA;IAEF,GAAA;MACE,GAAA,GAAM,IAAA;IAAA;EAAA;AAAA;AAAA,cAMH,SAAA;AAAA,cAGA,WAAA;AAAA,cAKA,OAAA;AAAA,cAMA,MAAA;AAAA,cAGA,MAAA;AAAA,cAMA,MAAA;AAAA,KAmBD,kBAAA;EACV,OAAA;EACA,cAAA;EACA,OAAA;EACA,cAAA;AAAA;AAAA,iBAKc,qBAAA,CAAA,GAAyB,kBAAA;AAAA,iBAYzB,sBAAA,CAAuB,IAAA"}
1
+ {"version":3,"file":"env.d.ts","names":[],"sources":["../../src/utils/env.ts"],"mappings":";QACQ,MAAA;EAAA,MAEA,IAAA;IAEA,OAAA;MACE,IAAA;IAAA;IAEF,GAAA;MACE,GAAA,GAAM,IAAA;IAAA;EAAA;AAAA;AAAA,cAMH,SAAA;AAAA,cAGA,WAAA;AAAA,cAKA,OAAA;AAAA,cAMA,MAAA;AAAA,cAGA,MAAA;AAAA,cAMA,MAAA;AAAA,KAmBD,kBAAA;EACV,OAAA;EACA,cAAA;EACA,OAAA;EACA,cAAA;AAAA;AAAA,iBAKc,qBAAA,CAAA,GAAyB,kBAAA;AAAA,iBAYzB,sBAAA,CAAuB,IAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CACjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
1
+ {"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["// Inlined from https://github.com/flexdinesh/browser-or-node\ndeclare global {\n // @ts-expect-error Conflicts with langsmith's ambient Deno declaration\n const Deno:\n | {\n version: {\n deno: string;\n };\n env: {\n get: (name: string) => string | undefined;\n };\n }\n | undefined;\n}\n\nexport const isBrowser = () =>\n typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\nexport const isWebWorker = () =>\n typeof globalThis === \"object\" &&\n globalThis.constructor &&\n globalThis.constructor.name === \"DedicatedWorkerGlobalScope\";\n\nexport const isJsDom = () =>\n (typeof window !== \"undefined\" && window.name === \"nodejs\") ||\n (typeof navigator !== \"undefined\" && navigator.userAgent.includes(\"jsdom\"));\n\n// Supabase Edge Function provides a `Deno` global object\n// without `version` property\nexport const isDeno = () => typeof Deno !== \"undefined\";\n\n// Mark not-as-node if in Supabase Edge Function\nexport const isNode = () =>\n typeof process !== \"undefined\" &&\n typeof process.versions !== \"undefined\" &&\n typeof process.versions.node !== \"undefined\" &&\n !isDeno();\n\nexport const getEnv = () => {\n let env: string;\n if (isBrowser()) {\n env = \"browser\";\n } else if (isNode()) {\n env = \"node\";\n } else if (isWebWorker()) {\n env = \"webworker\";\n } else if (isJsDom()) {\n env = \"jsdom\";\n } else if (isDeno()) {\n env = \"deno\";\n } else {\n env = \"other\";\n }\n\n return env;\n};\n\nexport type RuntimeEnvironment = {\n library: string;\n libraryVersion?: string;\n runtime: string;\n runtimeVersion?: string;\n};\n\nlet runtimeEnvironment: RuntimeEnvironment | undefined;\n\nexport function getRuntimeEnvironment(): RuntimeEnvironment {\n if (runtimeEnvironment === undefined) {\n const env = getEnv();\n\n runtimeEnvironment = {\n library: \"langchain-js\",\n runtime: env,\n };\n }\n return runtimeEnvironment;\n}\n\nexport function getEnvironmentVariable(name: string): string | undefined {\n // Certain Deno setups will throw an error if you try to access environment variables\n // https://github.com/langchain-ai/langchainjs/issues/1412\n try {\n if (typeof process !== \"undefined\") {\n // oxlint-disable-next-line no-process-env\n return process.env?.[name];\n } else if (isDeno()) {\n // @ts-expect-error Langsmith's Deno declaration is missing `env`\n return Deno?.env.get(name);\n } else {\n return undefined;\n }\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,kBACX,OAAO,WAAW,eAAe,OAAO,OAAO,aAAa;AAE9D,MAAa,oBACX,OAAO,eAAe,YACtB,WAAW,eACX,WAAW,YAAY,SAAS;AAElC,MAAa,gBACV,OAAO,WAAW,eAAe,OAAO,SAAS,YACjD,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,QAAQ;AAI5E,MAAa,eAAe,OAAO,SAAS;AAG5C,MAAa,eACX,OAAO,YAAY,eACnB,OAAO,QAAQ,aAAa,eAC5B,OAAO,QAAQ,SAAS,SAAS,eACjC,CAAC,QAAQ;AAEX,MAAa,eAAe;CAC1B,IAAI;AACJ,KAAI,WAAW,CACb,OAAM;UACG,QAAQ,CACjB,OAAM;UACG,aAAa,CACtB,OAAM;UACG,SAAS,CAClB,OAAM;UACG,QAAQ,CACjB,OAAM;KAEN,OAAM;AAGR,QAAO;;AAUT,IAAI;AAEJ,SAAgB,wBAA4C;AAC1D,KAAI,uBAAuB,KAAA,EAGzB,sBAAqB;EACnB,SAAS;EACT,SAJU,QAAQ;EAKnB;AAEH,QAAO;;AAGT,SAAgB,uBAAuB,MAAkC;AAGvE,KAAI;AACF,MAAI,OAAO,YAAY,YAErB,QAAO,QAAQ,MAAM;WACZ,QAAQ,CAEjB,QAAO,MAAM,IAAI,IAAI,KAAK;MAE1B;SAEI;AACN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "1.1.44",
3
+ "version": "1.1.46",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -18,9 +18,6 @@
18
18
  "dependencies": {
19
19
  "@cfworker/json-schema": "^4.0.2",
20
20
  "@standard-schema/spec": "^1.1.0",
21
- "ansi-styles": "^5.0.0",
22
- "camelcase": "6",
23
- "decamelize": "1.2.0",
24
21
  "js-tiktoken": "^1.0.12",
25
22
  "langsmith": ">=0.5.0 <1.0.0",
26
23
  "mustache": "^4.2.0",
@@ -28,7 +25,6 @@
28
25
  "zod": "^3.25.76 || ^4"
29
26
  },
30
27
  "devDependencies": {
31
- "@types/decamelize": "^1.2.0",
32
28
  "@types/mustache": "^4",
33
29
  "@types/node": "^25.5.0",
34
30
  "@types/uuid": "^10.0.0",