@langchain/core 1.1.16 → 1.1.17
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.
- package/CHANGELOG.md +6 -0
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/index.d.cts.map +1 -1
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/tracers/event_stream.cjs +17 -0
- package/dist/tracers/event_stream.cjs.map +1 -1
- package/dist/tracers/event_stream.d.cts +5 -0
- package/dist/tracers/event_stream.d.cts.map +1 -1
- package/dist/tracers/event_stream.d.ts +5 -0
- package/dist/tracers/event_stream.d.ts.map +1 -1
- package/dist/tracers/event_stream.js +17 -0
- package/dist/tracers/event_stream.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @langchain/core
|
|
2
2
|
|
|
3
|
+
## 1.1.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#9842](https://github.com/langchain-ai/langchainjs/pull/9842) [`05a9733`](https://github.com/langchain-ai/langchainjs/commit/05a9733448a10764c0bfd070af859c33e623b998) Thanks [@encodedz](https://github.com/encodedz)! - Adding `on_tool_error` event into EventStreamCallbackHandler
|
|
8
|
+
|
|
3
9
|
## 1.1.16
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/agents.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","names":["AgentAction","Record","AgentFinish","AgentStep"],"sources":["../src/agents.d.ts"],"sourcesContent":["export type AgentAction = {\n tool: string;\n toolInput: string | Record<string, any>;\n log: string;\n};\nexport type AgentFinish = {\n returnValues: Record<string, any>;\n log: string;\n};\nexport type AgentStep = {\n action: AgentAction;\n observation: string;\n};\n//# sourceMappingURL=agents.d.ts.map"],"mappings":";KAAYA,WAAAA;EAAAA,IAAAA,EAAAA,MAAAA;EAKAE,SAAAA,EAAAA,MAAW,GAHCD,
|
|
1
|
+
{"version":3,"file":"agents.d.ts","names":["AgentAction","Record","AgentFinish","AgentStep"],"sources":["../src/agents.d.ts"],"sourcesContent":["export type AgentAction = {\n tool: string;\n toolInput: string | Record<string, any>;\n log: string;\n};\nexport type AgentFinish = {\n returnValues: Record<string, any>;\n log: string;\n};\nexport type AgentStep = {\n action: AgentAction;\n observation: string;\n};\n//# sourceMappingURL=agents.d.ts.map"],"mappings":";KAAYA,WAAAA;EAAAA,IAAAA,EAAAA,MAAAA;EAKAE,SAAAA,EAAAA,MAAW,GAHCD,MAGD,CACLA,MAAM,EAAA,GAAA,CAAA;EAGZE,GAAAA,EAAAA,MAAAA;;KAJAD,WAAAA;gBACMD;;;KAGNE,SAAAA;UACAH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["___messages_ai_js0","___messages_chat_js0","___messages_function_js0","___messages_human_js0","___messages_system_js0","___messages_tool_js0","HashKeyEncoder","Generation","StoredGeneration","defaultHashKeyEncoder","deserializeStoredGeneration","
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["___messages_ai_js0","___messages_chat_js0","___messages_function_js0","___messages_human_js0","___messages_system_js0","___messages_tool_js0","HashKeyEncoder","Generation","StoredGeneration","defaultHashKeyEncoder","deserializeStoredGeneration","___messages_message_js2","MessageToolSet","MessageStructure","AIMessage","ChatMessage","FunctionMessage","HumanMessage","SystemMessage","ToolMessage","serializeGeneration","BaseCache","T","Promise","InMemoryCache","Map"],"sources":["../../src/caches/index.d.ts"],"sourcesContent":["import { type HashKeyEncoder } from \"../utils/hash.js\";\nimport type { Generation } from \"../outputs.js\";\nimport { type StoredGeneration } from \"../messages/base.js\";\nexport declare const defaultHashKeyEncoder: HashKeyEncoder;\nexport declare function deserializeStoredGeneration(storedGeneration: StoredGeneration): {\n text: string;\n message: import(\"../messages/ai.js\").AIMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>> | import(\"../messages/chat.js\").ChatMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>> | import(\"../messages/function.js\").FunctionMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>> | import(\"../messages/human.js\").HumanMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>> | import(\"../messages/system.js\").SystemMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>> | import(\"../messages/tool.js\").ToolMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>>;\n} | {\n message?: undefined;\n text: string;\n};\nexport declare function serializeGeneration(generation: Generation): StoredGeneration;\n/**\n * Base class for all caches. All caches should extend this class.\n */\nexport declare abstract class BaseCache<T = Generation[]> {\n protected keyEncoder: HashKeyEncoder;\n /**\n * Sets a custom key encoder function for the cache.\n * This function should take a prompt and an LLM key and return a string\n * that will be used as the cache key.\n * @param keyEncoderFn The custom key encoder function.\n */\n makeDefaultKeyEncoder(keyEncoderFn: HashKeyEncoder): void;\n abstract lookup(prompt: string, llmKey: string): Promise<T | null>;\n abstract update(prompt: string, llmKey: string, value: T): Promise<void>;\n}\n/**\n * A cache for storing LLM generations that stores data in memory.\n */\nexport declare class InMemoryCache<T = Generation[]> extends BaseCache<T> {\n private cache;\n constructor(map?: Map<string, T>);\n /**\n * Retrieves data from the cache using a prompt and an LLM key. If the\n * data is not found, it returns null.\n * @param prompt The prompt used to find the data.\n * @param llmKey The LLM key used to find the data.\n * @returns The data corresponding to the prompt and LLM key, or null if not found.\n */\n lookup(prompt: string, llmKey: string): Promise<T | null>;\n /**\n * Updates the cache with new data using a prompt and an LLM key.\n * @param prompt The prompt used to store the data.\n * @param llmKey The LLM key used to store the data.\n * @param value The data to be stored.\n */\n update(prompt: string, llmKey: string, value: T): Promise<void>;\n /**\n * Returns a global instance of InMemoryCache using a predefined global\n * map as the initial cache.\n * @returns A global instance of InMemoryCache.\n */\n static global(): InMemoryCache;\n}\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;;cAGqBS,uBAAuBH;iBACpBI,2BAAAA,mBAA8CF;;;;;;;iBAO9CY,mBAAAA,aAAgCb,aAAaC;AARrE;AACA;;uBAW8Ba,cAAcd;wBAClBD;;;;;;;sCAOcA;mDACaiB,QAAQD;yDACFA,IAAIC;;;;;cAK1CC,kBAAkBjB,sBAAsBc,UAAUC;;oBAEjDG,YAAYH;EA1B8uB;AAKhxB;AAIA;;;;;EASqDC,MAAAA,CAAAA,MAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAgBTA,OAhBSA,CAgBDD,CAhBCC,GAAAA,IAAAA,CAAAA;EACMD;;AAAW;AAKtE;;;EAEkCA,MAAAA,CAAAA,MAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAAAA,KAAAA,EAegBA,CAfhBA,CAAAA,EAeoBC,OAfpBD,CAAAA,IAAAA,CAAAA;EAAZG;;;;;EAqBDD,OAAAA,MAAAA,CAAAA,CAAAA,EAAAA,aAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.cts","names":["ChainValues","BaseMessage","AgentAction","AgentFinish","ChatGenerationChunk","GenerationChunk","LLMResult","Serializable","Serialized","SerializedNotImplemented","SerializedFields","DocumentInterface","Error","BaseCallbackHandlerInput","NewTokenIndices","HandleLLMNewTokenCallbackFields","BaseCallbackHandlerMethodsClass","Record","Promise","CallbackHandlerMethods","CallbackHandlerPrefersStreaming","callbackHandlerPrefersStreaming","BaseCallbackHandler","___messages_message_js11","MessageToolSet","MessageStructure","MessageType","isBaseCallbackHandler"],"sources":["../../src/callbacks/base.d.ts"],"sourcesContent":["import type { ChainValues } from \"../utils/types/index.js\";\nimport type { BaseMessage } from \"../messages/base.js\";\nimport type { AgentAction, AgentFinish } from \"../agents.js\";\nimport type { ChatGenerationChunk, GenerationChunk, LLMResult } from \"../outputs.js\";\nimport { Serializable, Serialized, SerializedNotImplemented } from \"../load/serializable.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport type { DocumentInterface } from \"../documents/document.js\";\ntype Error = any;\n/**\n * Interface for the input parameters of the BaseCallbackHandler class. It\n * allows to specify which types of events should be ignored by the\n * callback handler.\n */\nexport interface BaseCallbackHandlerInput {\n ignoreLLM?: boolean;\n ignoreChain?: boolean;\n ignoreAgent?: boolean;\n ignoreRetriever?: boolean;\n ignoreCustomEvent?: boolean;\n _awaitHandler?: boolean;\n raiseError?: boolean;\n}\n/**\n * Interface for the indices of a new token produced by an LLM or Chat\n * Model in streaming mode.\n */\nexport interface NewTokenIndices {\n prompt: number;\n completion: number;\n}\nexport type HandleLLMNewTokenCallbackFields = {\n chunk?: GenerationChunk | ChatGenerationChunk;\n};\n/**\n * Abstract class that provides a set of optional methods that can be\n * overridden in derived classes to handle various events during the\n * execution of a LangChain application.\n */\ndeclare abstract class BaseCallbackHandlerMethodsClass {\n /**\n * Called at the start of an LLM or Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;\n /**\n * Called when an LLM/ChatModel in `streaming` mode produces a new token\n */\n handleLLMNewToken?(token: string, \n /**\n * idx.prompt is the index of the prompt that produced the token\n * (if there are multiple prompts)\n * idx.completion is the index of the completion that produced the token\n * (if multiple completions per prompt are requested)\n */\n idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<any> | any;\n /**\n * Called if an LLM/ChatModel run encounters an error\n */\n handleLLMError?(err: Error, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): Promise<any> | any;\n /**\n * Called at the end of an LLM/ChatModel run, with the output and the run ID.\n */\n handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): Promise<any> | any;\n /**\n * Called at the start of a Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;\n /**\n * Called at the start of a Chain run, with the chain name and inputs\n * and the run ID.\n */\n handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, runType?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string, parentRunId?: string, extra?: Record<string, unknown>): Promise<any> | any;\n /**\n * Called if a Chain run encounters an error\n */\n handleChainError?(err: Error, runId: string, parentRunId?: string, tags?: string[], kwargs?: {\n inputs?: Record<string, unknown>;\n }): Promise<any> | any;\n /**\n * Called at the end of a Chain run, with the outputs and the run ID.\n */\n handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {\n inputs?: Record<string, unknown>;\n }): Promise<any> | any;\n /**\n * Called at the start of a Tool run, with the tool name and input\n * and the run ID.\n */\n handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;\n /**\n * Called if a Tool run encounters an error\n */\n handleToolError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n /**\n * Called at the end of a Tool run, with the tool output and the run ID.\n */\n handleToolEnd?(output: any, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;\n /**\n * Called when an agent is about to execute an action,\n * with the action and the run ID.\n */\n handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;\n /**\n * Called when an agent finishes execution, before it exits.\n * with the final output and the run ID.\n */\n handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;\n handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): Promise<any> | any;\n handleRetrieverEnd?(documents: DocumentInterface[], runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n handleRetrieverError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): Promise<any> | any;\n}\n/**\n * Base interface for callbacks. All methods are optional. If a method is not\n * implemented, it will be ignored. If a method is implemented, it will be\n * called at the appropriate time. All methods are called with the run ID of\n * the LLM/ChatModel/Chain that is running, which is generated by the\n * CallbackManager.\n *\n * @interface\n */\nexport type CallbackHandlerMethods = BaseCallbackHandlerMethodsClass;\n/**\n * Interface for handlers that can indicate a preference for streaming responses.\n * When implemented, this allows the handler to signal whether it prefers to receive\n * streaming responses from language models rather than complete responses.\n */\nexport interface CallbackHandlerPrefersStreaming {\n readonly lc_prefer_streaming: boolean;\n}\nexport declare function callbackHandlerPrefersStreaming(x: BaseCallbackHandler): unknown;\n/**\n * Abstract base class for creating callback handlers in the LangChain\n * framework. It provides a set of optional methods that can be overridden\n * in derived classes to handle various events during the execution of a\n * LangChain application.\n */\nexport declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass implements BaseCallbackHandlerInput, Serializable {\n lc_serializable: boolean;\n get lc_namespace(): [\"langchain_core\", \"callbacks\", string];\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_attributes(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[] | undefined;\n /**\n * The name of the serializable. Override to provide an alias or\n * to preserve the serialized module name in minified environments.\n *\n * Implemented as a static method to support loading logic.\n */\n static lc_name(): string;\n /**\n * The final serialized identifier for the module.\n */\n get lc_id(): string[];\n lc_kwargs: SerializedFields;\n abstract name: string;\n ignoreLLM: boolean;\n ignoreChain: boolean;\n ignoreAgent: boolean;\n ignoreRetriever: boolean;\n ignoreCustomEvent: boolean;\n raiseError: boolean;\n awaitHandlers: boolean;\n constructor(input?: BaseCallbackHandlerInput);\n copy(): BaseCallbackHandler;\n toJSON(): Serialized;\n toJSONNotImplemented(): SerializedNotImplemented;\n static fromMethods(methods: CallbackHandlerMethods): {\n name: string;\n /**\n * Called at the start of an LLM or Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;\n /**\n * Called when an LLM/ChatModel in `streaming` mode produces a new token\n */\n handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, fields?: HandleLLMNewTokenCallbackFields | undefined): any;\n /**\n * Called if an LLM/ChatModel run encounters an error\n */\n handleLLMError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, extraParams?: Record<string, unknown> | undefined): any;\n /**\n * Called at the end of an LLM/ChatModel run, with the output and the run ID.\n */\n handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, extraParams?: Record<string, unknown> | undefined): any;\n /**\n * Called at the start of a Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleChatModelStart?(llm: Serialized, messages: BaseMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>, import(\"../messages/message.js\").MessageType>[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;\n /**\n * Called at the start of a Chain run, with the chain name and inputs\n * and the run ID.\n */\n handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, runType?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined, parentRunId?: string | undefined, extra?: Record<string, unknown> | undefined): any;\n /**\n * Called if a Chain run encounters an error\n */\n handleChainError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {\n inputs?: Record<string, unknown> | undefined;\n } | undefined): any;\n /**\n * Called at the end of a Chain run, with the outputs and the run ID.\n */\n handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {\n inputs?: Record<string, unknown> | undefined;\n } | undefined): any;\n /**\n * Called at the start of a Tool run, with the tool name and input\n * and the run ID.\n */\n handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;\n /**\n * Called if a Tool run encounters an error\n */\n handleToolError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n /**\n * Called at the end of a Tool run, with the tool output and the run ID.\n */\n handleToolEnd?(output: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n handleText?(text: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;\n /**\n * Called when an agent is about to execute an action,\n * with the action and the run ID.\n */\n handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;\n /**\n * Called when an agent finishes execution, before it exits.\n * with the final output and the run ID.\n */\n handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;\n handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;\n handleRetrieverEnd?(documents: DocumentInterface<Record<string, any>>[], runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n handleRetrieverError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[] | undefined, metadata?: Record<string, any> | undefined): any;\n lc_serializable: boolean;\n get lc_namespace(): [\"langchain_core\", \"callbacks\", string];\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_attributes(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[] | undefined;\n /**\n * The final serialized identifier for the module.\n */\n get lc_id(): string[];\n lc_kwargs: SerializedFields;\n ignoreLLM: boolean;\n ignoreChain: boolean;\n ignoreAgent: boolean;\n ignoreRetriever: boolean;\n ignoreCustomEvent: boolean;\n raiseError: boolean;\n awaitHandlers: boolean;\n copy(): BaseCallbackHandler;\n toJSON(): Serialized;\n toJSONNotImplemented(): SerializedNotImplemented;\n };\n}\nexport declare const isBaseCallbackHandler: (x: unknown) => boolean;\nexport {};\n//# sourceMappingURL=base.d.ts.map"],"mappings":";;;;;;;;;;KAOKY,KAAAA;;;AAD6D;AAOlE;AAaA;AAIYG,UAjBKF,wBAAAA,CAiB0B;EAQpBG,SAAAA,CAAAA,EAAAA,OAAAA;EAKER,WAAAA,CAAAA,EAAAA,OAAAA;EAAkFS,WAAAA,CAAAA,EAAAA,OAAAA;EAAqDA,eAAAA,CAAAA,EAAAA,OAAAA;EAA4CC,iBAAAA,CAAAA,EAAAA,OAAAA;EAWnMJ,aAAAA,CAAAA,EAAAA,OAAAA;EAAgFC,UAAAA,CAAAA,EAAAA,OAAAA;;;;;;AAQgBE,UApCxFH,eAAAA,CAoCwFG;EAA0BC,MAAAA,EAAAA,MAAAA;EAKpGV,UAAAA,EAAAA,MAAAA;;AAA0FS,KArC7GF,+BAAAA,GAqC6GE;EAAqDA,KAAAA,CAAAA,EApClKZ,eAoCkKY,GApChJb,mBAoCgJa;CAA4CC;;;;;;uBA7BnMF,+BAAAA,CAsCIJ;EACVK;;;;EAOTC,cAAAA,CAAAA,CAAAA,GAAAA,EAzCiBV,UAyCjBU,EAAAA,OAAAA,EAAAA,MAAAA,EAAAA,EAAAA,KAAAA,EAAAA,MAAAA,EAAAA,WAAAA,CAAAA,EAAAA,MAAAA,EAAAA,WAAAA,CAAAA,EAzCmGD,MAyC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base.d.cts","names":["ChainValues","BaseMessage","AgentAction","AgentFinish","ChatGenerationChunk","GenerationChunk","LLMResult","Serializable","Serialized","SerializedNotImplemented","SerializedFields","DocumentInterface","Error","BaseCallbackHandlerInput","NewTokenIndices","HandleLLMNewTokenCallbackFields","BaseCallbackHandlerMethodsClass","Record","Promise","CallbackHandlerMethods","CallbackHandlerPrefersStreaming","callbackHandlerPrefersStreaming","BaseCallbackHandler","___messages_message_js0","MessageToolSet","MessageStructure","MessageType","isBaseCallbackHandler"],"sources":["../../src/callbacks/base.d.ts"],"sourcesContent":["import type { ChainValues } from \"../utils/types/index.js\";\nimport type { BaseMessage } from \"../messages/base.js\";\nimport type { AgentAction, AgentFinish } from \"../agents.js\";\nimport type { ChatGenerationChunk, GenerationChunk, LLMResult } from \"../outputs.js\";\nimport { Serializable, Serialized, SerializedNotImplemented } from \"../load/serializable.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport type { DocumentInterface } from \"../documents/document.js\";\ntype Error = any;\n/**\n * Interface for the input parameters of the BaseCallbackHandler class. It\n * allows to specify which types of events should be ignored by the\n * callback handler.\n */\nexport interface BaseCallbackHandlerInput {\n ignoreLLM?: boolean;\n ignoreChain?: boolean;\n ignoreAgent?: boolean;\n ignoreRetriever?: boolean;\n ignoreCustomEvent?: boolean;\n _awaitHandler?: boolean;\n raiseError?: boolean;\n}\n/**\n * Interface for the indices of a new token produced by an LLM or Chat\n * Model in streaming mode.\n */\nexport interface NewTokenIndices {\n prompt: number;\n completion: number;\n}\nexport type HandleLLMNewTokenCallbackFields = {\n chunk?: GenerationChunk | ChatGenerationChunk;\n};\n/**\n * Abstract class that provides a set of optional methods that can be\n * overridden in derived classes to handle various events during the\n * execution of a LangChain application.\n */\ndeclare abstract class BaseCallbackHandlerMethodsClass {\n /**\n * Called at the start of an LLM or Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;\n /**\n * Called when an LLM/ChatModel in `streaming` mode produces a new token\n */\n handleLLMNewToken?(token: string, \n /**\n * idx.prompt is the index of the prompt that produced the token\n * (if there are multiple prompts)\n * idx.completion is the index of the completion that produced the token\n * (if multiple completions per prompt are requested)\n */\n idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<any> | any;\n /**\n * Called if an LLM/ChatModel run encounters an error\n */\n handleLLMError?(err: Error, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): Promise<any> | any;\n /**\n * Called at the end of an LLM/ChatModel run, with the output and the run ID.\n */\n handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): Promise<any> | any;\n /**\n * Called at the start of a Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;\n /**\n * Called at the start of a Chain run, with the chain name and inputs\n * and the run ID.\n */\n handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, runType?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string, parentRunId?: string, extra?: Record<string, unknown>): Promise<any> | any;\n /**\n * Called if a Chain run encounters an error\n */\n handleChainError?(err: Error, runId: string, parentRunId?: string, tags?: string[], kwargs?: {\n inputs?: Record<string, unknown>;\n }): Promise<any> | any;\n /**\n * Called at the end of a Chain run, with the outputs and the run ID.\n */\n handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {\n inputs?: Record<string, unknown>;\n }): Promise<any> | any;\n /**\n * Called at the start of a Tool run, with the tool name and input\n * and the run ID.\n */\n handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;\n /**\n * Called if a Tool run encounters an error\n */\n handleToolError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n /**\n * Called at the end of a Tool run, with the tool output and the run ID.\n */\n handleToolEnd?(output: any, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;\n /**\n * Called when an agent is about to execute an action,\n * with the action and the run ID.\n */\n handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;\n /**\n * Called when an agent finishes execution, before it exits.\n * with the final output and the run ID.\n */\n handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;\n handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): Promise<any> | any;\n handleRetrieverEnd?(documents: DocumentInterface[], runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n handleRetrieverError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;\n handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): Promise<any> | any;\n}\n/**\n * Base interface for callbacks. All methods are optional. If a method is not\n * implemented, it will be ignored. If a method is implemented, it will be\n * called at the appropriate time. All methods are called with the run ID of\n * the LLM/ChatModel/Chain that is running, which is generated by the\n * CallbackManager.\n *\n * @interface\n */\nexport type CallbackHandlerMethods = BaseCallbackHandlerMethodsClass;\n/**\n * Interface for handlers that can indicate a preference for streaming responses.\n * When implemented, this allows the handler to signal whether it prefers to receive\n * streaming responses from language models rather than complete responses.\n */\nexport interface CallbackHandlerPrefersStreaming {\n readonly lc_prefer_streaming: boolean;\n}\nexport declare function callbackHandlerPrefersStreaming(x: BaseCallbackHandler): unknown;\n/**\n * Abstract base class for creating callback handlers in the LangChain\n * framework. It provides a set of optional methods that can be overridden\n * in derived classes to handle various events during the execution of a\n * LangChain application.\n */\nexport declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass implements BaseCallbackHandlerInput, Serializable {\n lc_serializable: boolean;\n get lc_namespace(): [\"langchain_core\", \"callbacks\", string];\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_attributes(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[] | undefined;\n /**\n * The name of the serializable. Override to provide an alias or\n * to preserve the serialized module name in minified environments.\n *\n * Implemented as a static method to support loading logic.\n */\n static lc_name(): string;\n /**\n * The final serialized identifier for the module.\n */\n get lc_id(): string[];\n lc_kwargs: SerializedFields;\n abstract name: string;\n ignoreLLM: boolean;\n ignoreChain: boolean;\n ignoreAgent: boolean;\n ignoreRetriever: boolean;\n ignoreCustomEvent: boolean;\n raiseError: boolean;\n awaitHandlers: boolean;\n constructor(input?: BaseCallbackHandlerInput);\n copy(): BaseCallbackHandler;\n toJSON(): Serialized;\n toJSONNotImplemented(): SerializedNotImplemented;\n static fromMethods(methods: CallbackHandlerMethods): {\n name: string;\n /**\n * Called at the start of an LLM or Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;\n /**\n * Called when an LLM/ChatModel in `streaming` mode produces a new token\n */\n handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, fields?: HandleLLMNewTokenCallbackFields | undefined): any;\n /**\n * Called if an LLM/ChatModel run encounters an error\n */\n handleLLMError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, extraParams?: Record<string, unknown> | undefined): any;\n /**\n * Called at the end of an LLM/ChatModel run, with the output and the run ID.\n */\n handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, extraParams?: Record<string, unknown> | undefined): any;\n /**\n * Called at the start of a Chat Model run, with the prompt(s)\n * and the run ID.\n */\n handleChatModelStart?(llm: Serialized, messages: BaseMessage<import(\"../messages/message.js\").MessageStructure<import(\"../messages/message.js\").MessageToolSet>, import(\"../messages/message.js\").MessageType>[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;\n /**\n * Called at the start of a Chain run, with the chain name and inputs\n * and the run ID.\n */\n handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, runType?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined, parentRunId?: string | undefined, extra?: Record<string, unknown> | undefined): any;\n /**\n * Called if a Chain run encounters an error\n */\n handleChainError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {\n inputs?: Record<string, unknown> | undefined;\n } | undefined): any;\n /**\n * Called at the end of a Chain run, with the outputs and the run ID.\n */\n handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {\n inputs?: Record<string, unknown> | undefined;\n } | undefined): any;\n /**\n * Called at the start of a Tool run, with the tool name and input\n * and the run ID.\n */\n handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runName?: string | undefined): any;\n /**\n * Called if a Tool run encounters an error\n */\n handleToolError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n /**\n * Called at the end of a Tool run, with the tool output and the run ID.\n */\n handleToolEnd?(output: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n handleText?(text: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;\n /**\n * Called when an agent is about to execute an action,\n * with the action and the run ID.\n */\n handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;\n /**\n * Called when an agent finishes execution, before it exits.\n * with the final output and the run ID.\n */\n handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;\n handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;\n handleRetrieverEnd?(documents: DocumentInterface<Record<string, any>>[], runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n handleRetrieverError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;\n handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[] | undefined, metadata?: Record<string, any> | undefined): any;\n lc_serializable: boolean;\n get lc_namespace(): [\"langchain_core\", \"callbacks\", string];\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n get lc_attributes(): {\n [key: string]: string;\n } | undefined;\n get lc_aliases(): {\n [key: string]: string;\n } | undefined;\n get lc_serializable_keys(): string[] | undefined;\n /**\n * The final serialized identifier for the module.\n */\n get lc_id(): string[];\n lc_kwargs: SerializedFields;\n ignoreLLM: boolean;\n ignoreChain: boolean;\n ignoreAgent: boolean;\n ignoreRetriever: boolean;\n ignoreCustomEvent: boolean;\n raiseError: boolean;\n awaitHandlers: boolean;\n copy(): BaseCallbackHandler;\n toJSON(): Serialized;\n toJSONNotImplemented(): SerializedNotImplemented;\n };\n}\nexport declare const isBaseCallbackHandler: (x: unknown) => boolean;\nexport {};\n//# sourceMappingURL=base.d.ts.map"],"mappings":";;;;;;;;;;KAOKY,KAAAA;;;AAD6D;AAOlE;AAaA;AAIYG,UAjBKF,wBAAAA,CAiB0B;EAQpBG,SAAAA,CAAAA,EAAAA,OAAAA;EAKER,WAAAA,CAAAA,EAAAA,OAAAA;EAAkFS,WAAAA,CAAAA,EAAAA,OAAAA;EAAqDA,eAAAA,CAAAA,EAAAA,OAAAA;EAA4CC,iBAAAA,CAAAA,EAAAA,OAAAA;EAWnMJ,aAAAA,CAAAA,E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;;;sBASSG;UACZS;YACEd;0BACcC;8BACIU;;;;;;yBAMHX,8FAA8FS,6EAA6EA;;;;2CAIzJH,wGAAwGC;;;;0HAIzBE;;;;0BAIhGX,uGAAuGW;;;;;+BAKlGT,sBAAsBP,+HAAkOgB,6EAA6EA;;;;;6BAKvUT,oBAAoBR,kGAAkGiB,6GAA6GA;;;;;eAK/OA;;;;;6BAKYjB;eACZiB;;;;;;2BAMUT,oHAAoHS;;;;;;;;;oHAS3BC;;;;;+BAKrFhB,mGAAmGgB;;;;;4BAKtGf,mGAAmGe;qCAC1FV,oHAAoHS;mCACtHN,kBAAkBM;;4GAEuDA;;;;;;;;;;;;;;;;;eAiB7FP;;;;;;;;YAQHY;cACEd;4BACcC;;;cAGXkB"}
|
|
@@ -303,6 +303,23 @@ var EventStreamCallbackHandler = class extends require_tracers_base.BaseTracer {
|
|
|
303
303
|
metadata: runInfo.metadata
|
|
304
304
|
}, runInfo);
|
|
305
305
|
}
|
|
306
|
+
async onToolError(run) {
|
|
307
|
+
const runInfo = this.runInfoMap.get(run.id);
|
|
308
|
+
this.runInfoMap.delete(run.id);
|
|
309
|
+
if (runInfo === void 0) throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);
|
|
310
|
+
if (runInfo.inputs === void 0) throw new Error(`onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`);
|
|
311
|
+
await this.sendEndEvent({
|
|
312
|
+
event: "on_tool_error",
|
|
313
|
+
data: {
|
|
314
|
+
input: runInfo.inputs,
|
|
315
|
+
error: run.error
|
|
316
|
+
},
|
|
317
|
+
run_id: run.id,
|
|
318
|
+
name: runInfo.name,
|
|
319
|
+
tags: runInfo.tags,
|
|
320
|
+
metadata: runInfo.metadata
|
|
321
|
+
}, runInfo);
|
|
322
|
+
}
|
|
306
323
|
async onRetrieverStart(run) {
|
|
307
324
|
const runName = assignName(run);
|
|
308
325
|
const runType = "retriever";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event_stream.cjs","names":["handler: BaseCallbackHandler","BaseTracer","fields?: EventStreamCallbackHandlerInput","IterableReadableStream","_run: Run","run: RunInfo","runId: string","outputStream: AsyncGenerator<T>","eventType: string","data: unknown","GenerationChunk","tappedPromiseResolver: (() => void) | undefined","event: StreamEvent","payload: StreamEvent","run: Run","token: string","kwargs?: { chunk: any }","AIMessageChunk","eventName: string","generations: ChatGeneration[][] | Generation[][] | undefined","output: BaseMessage | Record<string, any> | undefined","runInfo: RunInfo","eventData: StreamEventData","data: StreamEventData","data: any"],"sources":["../../src/tracers/event_stream.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport {\n BaseCallbackHandler,\n BaseCallbackHandlerInput,\n CallbackHandlerPrefersStreaming,\n} from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { AIMessageChunk } from \"../messages/ai.js\";\nimport { ChatGeneration, Generation, GenerationChunk } from \"../outputs.js\";\nimport { BaseMessage } from \"../messages/base.js\";\n\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input?: any;\n\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n output?: any;\n\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chunk?: any;\n};\n\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\n\ntype RunInfo = {\n name: string;\n tags: string[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n runType: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputs?: Record<string, any>;\n};\n\nexport interface EventStreamCallbackHandlerInput\n extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\n\nfunction assignName({\n name,\n serialized,\n}: {\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n serialized?: Record<string, any>;\n}): string {\n if (name !== undefined) {\n return name;\n }\n if (serialized?.name !== undefined) {\n return serialized.name;\n } else if (serialized?.id !== undefined && Array.isArray(serialized?.id)) {\n return serialized.id[serialized.id.length - 1];\n }\n return \"Unnamed\";\n}\n\nexport const isStreamEventsHandler = (\n handler: BaseCallbackHandler\n): handler is EventStreamCallbackHandler =>\n handler.name === \"event_stream_tracer\";\n\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport class EventStreamCallbackHandler\n extends BaseTracer\n implements CallbackHandlerPrefersStreaming\n{\n protected autoClose = true;\n\n protected includeNames?: string[];\n\n protected includeTypes?: string[];\n\n protected includeTags?: string[];\n\n protected excludeNames?: string[];\n\n protected excludeTypes?: string[];\n\n protected excludeTags?: string[];\n\n private runInfoMap: Map<string, RunInfo> = new Map();\n\n private tappedPromises: Map<string, Promise<void>> = new Map();\n\n protected transformStream: TransformStream;\n\n public writer: WritableStreamDefaultWriter;\n\n public receiveStream: IterableReadableStream<StreamEvent>;\n\n private readableStreamClosed = false;\n\n name = \"event_stream_tracer\";\n\n lc_prefer_streaming = true;\n\n constructor(fields?: EventStreamCallbackHandlerInput) {\n super({ _awaitHandler: true, ...fields });\n this.autoClose = fields?.autoClose ?? true;\n this.includeNames = fields?.includeNames;\n this.includeTypes = fields?.includeTypes;\n this.includeTags = fields?.includeTags;\n this.excludeNames = fields?.excludeNames;\n this.excludeTypes = fields?.excludeTypes;\n this.excludeTags = fields?.excludeTags;\n this.transformStream = new TransformStream({\n flush: () => {\n this.readableStreamClosed = true;\n },\n });\n this.writer = this.transformStream.writable.getWriter();\n this.receiveStream = IterableReadableStream.fromReadableStream(\n this.transformStream.readable\n );\n }\n\n [Symbol.asyncIterator]() {\n return this.receiveStream;\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // This is a legacy method only called once for an entire run tree\n // and is therefore not useful here\n }\n\n _includeRun(run: RunInfo): boolean {\n const runTags = run.tags ?? [];\n let include =\n this.includeNames === undefined &&\n this.includeTags === undefined &&\n this.includeTypes === undefined;\n if (this.includeNames !== undefined) {\n include = include || this.includeNames.includes(run.name);\n }\n if (this.includeTypes !== undefined) {\n include = include || this.includeTypes.includes(run.runType);\n }\n if (this.includeTags !== undefined) {\n include =\n include ||\n runTags.find((tag) => this.includeTags?.includes(tag)) !== undefined;\n }\n if (this.excludeNames !== undefined) {\n include = include && !this.excludeNames.includes(run.name);\n }\n if (this.excludeTypes !== undefined) {\n include = include && !this.excludeTypes.includes(run.runType);\n }\n if (this.excludeTags !== undefined) {\n include =\n include && runTags.every((tag) => !this.excludeTags?.includes(tag));\n }\n return include;\n }\n\n async *tapOutputIterable<T>(\n runId: string,\n outputStream: AsyncGenerator<T>\n ): AsyncGenerator<T> {\n const firstChunk = await outputStream.next();\n if (firstChunk.done) {\n return;\n }\n const runInfo = this.runInfoMap.get(runId);\n // Run has finished, don't issue any stream events.\n // An example of this is for runnables that use the default\n // implementation of .stream(), which delegates to .invoke()\n // and calls .onChainEnd() before passing it to the iterator.\n if (runInfo === undefined) {\n yield firstChunk.value;\n return;\n }\n // Match format from handlers below\n function _formatOutputChunk(eventType: string, data: unknown) {\n if (eventType === \"llm\" && typeof data === \"string\") {\n return new GenerationChunk({ text: data });\n }\n return data;\n }\n let tappedPromise = this.tappedPromises.get(runId);\n // if we are the first to tap, issue stream events\n if (tappedPromise === undefined) {\n let tappedPromiseResolver: (() => void) | undefined;\n tappedPromise = new Promise((resolve) => {\n tappedPromiseResolver = resolve;\n });\n this.tappedPromises.set(runId, tappedPromise);\n try {\n const event: StreamEvent = {\n event: `on_${runInfo.runType}_stream`,\n run_id: runId,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data: {},\n };\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, firstChunk.value),\n },\n },\n runInfo\n );\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n // Don't yield tool and retriever stream events\n if (runInfo.runType !== \"tool\" && runInfo.runType !== \"retriever\") {\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, chunk),\n },\n },\n runInfo\n );\n }\n yield chunk;\n }\n } finally {\n tappedPromiseResolver?.();\n // Don't delete from the promises map to keep track of which runs have been tapped.\n }\n } else {\n // otherwise just pass through\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n yield chunk;\n }\n }\n }\n\n async send(payload: StreamEvent, run: RunInfo) {\n if (this.readableStreamClosed) return;\n if (this._includeRun(run)) {\n await this.writer.write(payload);\n }\n }\n\n async sendEndEvent(payload: StreamEvent, run: RunInfo) {\n const tappedPromise = this.tappedPromises.get(payload.run_id);\n if (tappedPromise !== undefined) {\n // eslint-disable-next-line no-void\n void tappedPromise.then(() => {\n // eslint-disable-next-line no-void\n void this.send(payload, run);\n });\n } else {\n await this.send(payload, run);\n }\n }\n\n async onLLMStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.inputs.messages !== undefined ? \"chat_model\" : \"llm\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: run.inputs,\n };\n this.runInfoMap.set(run.id, runInfo);\n const eventName = `on_${runType}_start`;\n await this.send(\n {\n event: eventName,\n data: {\n input: run.inputs,\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onLLMNewToken(\n run: Run,\n token: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n kwargs?: { chunk: any }\n ): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n let chunk;\n let eventName;\n if (runInfo === undefined) {\n throw new Error(`onLLMNewToken: Run ID ${run.id} not found in run map.`);\n }\n // Top-level streaming events are covered by tapOutputIterable\n if (this.runInfoMap.size === 1) {\n return;\n }\n if (runInfo.runType === \"chat_model\") {\n eventName = \"on_chat_model_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new AIMessageChunk({ content: token, id: `run-${run.id}` });\n } else {\n chunk = kwargs.chunk.message;\n }\n } else if (runInfo.runType === \"llm\") {\n eventName = \"on_llm_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new GenerationChunk({ text: token });\n } else {\n chunk = kwargs.chunk;\n }\n } else {\n throw new Error(`Unexpected run type ${runInfo.runType}`);\n }\n await this.send(\n {\n event: eventName,\n data: {\n chunk,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onLLMEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n let eventName: string;\n if (runInfo === undefined) {\n throw new Error(`onLLMEnd: Run ID ${run.id} not found in run map.`);\n }\n const generations: ChatGeneration[][] | Generation[][] | undefined =\n run.outputs?.generations;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let output: BaseMessage | Record<string, any> | undefined;\n if (runInfo.runType === \"chat_model\") {\n for (const generation of generations ?? []) {\n if (output !== undefined) {\n break;\n }\n output = (generation[0] as ChatGeneration | undefined)?.message;\n }\n eventName = \"on_chat_model_end\";\n } else if (runInfo.runType === \"llm\") {\n output = {\n generations: generations?.map((generation) => {\n return generation.map((chunk) => {\n return {\n text: chunk.text,\n generationInfo: chunk.generationInfo,\n };\n });\n }),\n llmOutput: run.outputs?.llmOutput ?? {},\n };\n eventName = \"on_llm_end\";\n } else {\n throw new Error(`onLLMEnd: Unexpected run type: ${runInfo.runType}`);\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onChainStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.run_type ?? \"chain\";\n const runInfo: RunInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: run.run_type,\n };\n let eventData: StreamEventData = {};\n // Workaround Runnable core code not sending input when transform streaming.\n if (run.inputs.input === \"\" && Object.keys(run.inputs).length === 1) {\n eventData = {};\n runInfo.inputs = {};\n } else if (run.inputs.input !== undefined) {\n eventData.input = run.inputs.input;\n runInfo.inputs = run.inputs.input;\n } else {\n eventData.input = run.inputs;\n runInfo.inputs = run.inputs;\n }\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: `on_${runType}_start`,\n data: eventData,\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onChainEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onChainEnd: Run ID ${run.id} not found in run map.`);\n }\n const eventName = `on_${run.run_type}_end`;\n const inputs = run.inputs ?? runInfo.inputs ?? {};\n const outputs = run.outputs?.output ?? run.outputs;\n const data: StreamEventData = {\n output: outputs,\n input: inputs,\n };\n if (inputs.input && Object.keys(inputs).length === 1) {\n data.input = inputs.input;\n runInfo.inputs = inputs.input;\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data,\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: \"tool\",\n inputs: run.inputs ?? {},\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_tool_start\",\n data: {\n input: run.inputs ?? {},\n },\n name: runName,\n run_id: run.id,\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);\n }\n if (runInfo.inputs === undefined) {\n throw new Error(\n `onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`\n );\n }\n const output =\n run.outputs?.output === undefined ? run.outputs : run.outputs.output;\n await this.sendEndEvent(\n {\n event: \"on_tool_end\",\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onRetrieverStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = \"retriever\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: {\n query: run.inputs.query,\n },\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_retriever_start\",\n data: {\n input: {\n query: run.inputs.query,\n },\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onRetrieverEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onRetrieverEnd: Run ID ${run.id} not found in run map.`);\n }\n await this.sendEndEvent(\n {\n event: \"on_retriever_end\",\n data: {\n output: run.outputs?.documents ?? run.outputs,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async handleCustomEvent(eventName: string, data: any, runId: string) {\n const runInfo = this.runInfoMap.get(runId);\n if (runInfo === undefined) {\n throw new Error(\n `handleCustomEvent: Run ID ${runId} not found in run map.`\n );\n }\n await this.send(\n {\n event: \"on_custom_event\",\n run_id: runId,\n name: eventName,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data,\n },\n runInfo\n );\n }\n\n async finish() {\n const pendingPromises = [...this.tappedPromises.values()];\n // eslint-disable-next-line no-void\n void Promise.all(pendingPromises).finally(() => {\n // eslint-disable-next-line no-void\n void this.writer.close();\n });\n }\n}\n"],"mappings":";;;;;;AAqHA,SAAS,WAAW,EAClB,M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AM,kBAAkBI,WAAmBM,MAAWlB,OAAe;EACnE,MAAM,UAAU,KAAK,WAAW,IAAI,MAAM;AAC1C,MAAI,YAAY,OACd,OAAM,IAAI,MACR,CAAC,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;EAG9D,MAAM,KAAK,KACT;GACE,OAAO;GACP,QAAQ;GACR,MAAM;GACN,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB;EACD,GACD,QACD;CACF;CAED,MAAM,SAAS;EACb,MAAM,kBAAkB,CAAC,GAAG,KAAK,eAAe,QAAQ,AAAC;EAEpD,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,MAAM;GAEzC,KAAK,OAAO,OAAO;EACzB,EAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"event_stream.cjs","names":["handler: BaseCallbackHandler","BaseTracer","fields?: EventStreamCallbackHandlerInput","IterableReadableStream","_run: Run","run: RunInfo","runId: string","outputStream: AsyncGenerator<T>","eventType: string","data: unknown","GenerationChunk","tappedPromiseResolver: (() => void) | undefined","event: StreamEvent","payload: StreamEvent","run: Run","token: string","kwargs?: { chunk: any }","AIMessageChunk","eventName: string","generations: ChatGeneration[][] | Generation[][] | undefined","output: BaseMessage | Record<string, any> | undefined","runInfo: RunInfo","eventData: StreamEventData","data: StreamEventData","data: any"],"sources":["../../src/tracers/event_stream.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport {\n BaseCallbackHandler,\n BaseCallbackHandlerInput,\n CallbackHandlerPrefersStreaming,\n} from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { AIMessageChunk } from \"../messages/ai.js\";\nimport { ChatGeneration, Generation, GenerationChunk } from \"../outputs.js\";\nimport { BaseMessage } from \"../messages/base.js\";\n\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input?: any;\n\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n output?: any;\n\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chunk?: any;\n\n /**\n * Error message if the runnable that generated the event failed.\n * This field will only be present if the runnable failed.\n */\n error?: string;\n};\n\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\n\ntype RunInfo = {\n name: string;\n tags: string[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n runType: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputs?: Record<string, any>;\n};\n\nexport interface EventStreamCallbackHandlerInput\n extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\n\nfunction assignName({\n name,\n serialized,\n}: {\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n serialized?: Record<string, any>;\n}): string {\n if (name !== undefined) {\n return name;\n }\n if (serialized?.name !== undefined) {\n return serialized.name;\n } else if (serialized?.id !== undefined && Array.isArray(serialized?.id)) {\n return serialized.id[serialized.id.length - 1];\n }\n return \"Unnamed\";\n}\n\nexport const isStreamEventsHandler = (\n handler: BaseCallbackHandler\n): handler is EventStreamCallbackHandler =>\n handler.name === \"event_stream_tracer\";\n\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport class EventStreamCallbackHandler\n extends BaseTracer\n implements CallbackHandlerPrefersStreaming\n{\n protected autoClose = true;\n\n protected includeNames?: string[];\n\n protected includeTypes?: string[];\n\n protected includeTags?: string[];\n\n protected excludeNames?: string[];\n\n protected excludeTypes?: string[];\n\n protected excludeTags?: string[];\n\n private runInfoMap: Map<string, RunInfo> = new Map();\n\n private tappedPromises: Map<string, Promise<void>> = new Map();\n\n protected transformStream: TransformStream;\n\n public writer: WritableStreamDefaultWriter;\n\n public receiveStream: IterableReadableStream<StreamEvent>;\n\n private readableStreamClosed = false;\n\n name = \"event_stream_tracer\";\n\n lc_prefer_streaming = true;\n\n constructor(fields?: EventStreamCallbackHandlerInput) {\n super({ _awaitHandler: true, ...fields });\n this.autoClose = fields?.autoClose ?? true;\n this.includeNames = fields?.includeNames;\n this.includeTypes = fields?.includeTypes;\n this.includeTags = fields?.includeTags;\n this.excludeNames = fields?.excludeNames;\n this.excludeTypes = fields?.excludeTypes;\n this.excludeTags = fields?.excludeTags;\n this.transformStream = new TransformStream({\n flush: () => {\n this.readableStreamClosed = true;\n },\n });\n this.writer = this.transformStream.writable.getWriter();\n this.receiveStream = IterableReadableStream.fromReadableStream(\n this.transformStream.readable\n );\n }\n\n [Symbol.asyncIterator]() {\n return this.receiveStream;\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // This is a legacy method only called once for an entire run tree\n // and is therefore not useful here\n }\n\n _includeRun(run: RunInfo): boolean {\n const runTags = run.tags ?? [];\n let include =\n this.includeNames === undefined &&\n this.includeTags === undefined &&\n this.includeTypes === undefined;\n if (this.includeNames !== undefined) {\n include = include || this.includeNames.includes(run.name);\n }\n if (this.includeTypes !== undefined) {\n include = include || this.includeTypes.includes(run.runType);\n }\n if (this.includeTags !== undefined) {\n include =\n include ||\n runTags.find((tag) => this.includeTags?.includes(tag)) !== undefined;\n }\n if (this.excludeNames !== undefined) {\n include = include && !this.excludeNames.includes(run.name);\n }\n if (this.excludeTypes !== undefined) {\n include = include && !this.excludeTypes.includes(run.runType);\n }\n if (this.excludeTags !== undefined) {\n include =\n include && runTags.every((tag) => !this.excludeTags?.includes(tag));\n }\n return include;\n }\n\n async *tapOutputIterable<T>(\n runId: string,\n outputStream: AsyncGenerator<T>\n ): AsyncGenerator<T> {\n const firstChunk = await outputStream.next();\n if (firstChunk.done) {\n return;\n }\n const runInfo = this.runInfoMap.get(runId);\n // Run has finished, don't issue any stream events.\n // An example of this is for runnables that use the default\n // implementation of .stream(), which delegates to .invoke()\n // and calls .onChainEnd() before passing it to the iterator.\n if (runInfo === undefined) {\n yield firstChunk.value;\n return;\n }\n // Match format from handlers below\n function _formatOutputChunk(eventType: string, data: unknown) {\n if (eventType === \"llm\" && typeof data === \"string\") {\n return new GenerationChunk({ text: data });\n }\n return data;\n }\n let tappedPromise = this.tappedPromises.get(runId);\n // if we are the first to tap, issue stream events\n if (tappedPromise === undefined) {\n let tappedPromiseResolver: (() => void) | undefined;\n tappedPromise = new Promise((resolve) => {\n tappedPromiseResolver = resolve;\n });\n this.tappedPromises.set(runId, tappedPromise);\n try {\n const event: StreamEvent = {\n event: `on_${runInfo.runType}_stream`,\n run_id: runId,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data: {},\n };\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, firstChunk.value),\n },\n },\n runInfo\n );\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n // Don't yield tool and retriever stream events\n if (runInfo.runType !== \"tool\" && runInfo.runType !== \"retriever\") {\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, chunk),\n },\n },\n runInfo\n );\n }\n yield chunk;\n }\n } finally {\n tappedPromiseResolver?.();\n // Don't delete from the promises map to keep track of which runs have been tapped.\n }\n } else {\n // otherwise just pass through\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n yield chunk;\n }\n }\n }\n\n async send(payload: StreamEvent, run: RunInfo) {\n if (this.readableStreamClosed) return;\n if (this._includeRun(run)) {\n await this.writer.write(payload);\n }\n }\n\n async sendEndEvent(payload: StreamEvent, run: RunInfo) {\n const tappedPromise = this.tappedPromises.get(payload.run_id);\n if (tappedPromise !== undefined) {\n // eslint-disable-next-line no-void\n void tappedPromise.then(() => {\n // eslint-disable-next-line no-void\n void this.send(payload, run);\n });\n } else {\n await this.send(payload, run);\n }\n }\n\n async onLLMStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.inputs.messages !== undefined ? \"chat_model\" : \"llm\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: run.inputs,\n };\n this.runInfoMap.set(run.id, runInfo);\n const eventName = `on_${runType}_start`;\n await this.send(\n {\n event: eventName,\n data: {\n input: run.inputs,\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onLLMNewToken(\n run: Run,\n token: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n kwargs?: { chunk: any }\n ): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n let chunk;\n let eventName;\n if (runInfo === undefined) {\n throw new Error(`onLLMNewToken: Run ID ${run.id} not found in run map.`);\n }\n // Top-level streaming events are covered by tapOutputIterable\n if (this.runInfoMap.size === 1) {\n return;\n }\n if (runInfo.runType === \"chat_model\") {\n eventName = \"on_chat_model_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new AIMessageChunk({ content: token, id: `run-${run.id}` });\n } else {\n chunk = kwargs.chunk.message;\n }\n } else if (runInfo.runType === \"llm\") {\n eventName = \"on_llm_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new GenerationChunk({ text: token });\n } else {\n chunk = kwargs.chunk;\n }\n } else {\n throw new Error(`Unexpected run type ${runInfo.runType}`);\n }\n await this.send(\n {\n event: eventName,\n data: {\n chunk,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onLLMEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n let eventName: string;\n if (runInfo === undefined) {\n throw new Error(`onLLMEnd: Run ID ${run.id} not found in run map.`);\n }\n const generations: ChatGeneration[][] | Generation[][] | undefined =\n run.outputs?.generations;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let output: BaseMessage | Record<string, any> | undefined;\n if (runInfo.runType === \"chat_model\") {\n for (const generation of generations ?? []) {\n if (output !== undefined) {\n break;\n }\n output = (generation[0] as ChatGeneration | undefined)?.message;\n }\n eventName = \"on_chat_model_end\";\n } else if (runInfo.runType === \"llm\") {\n output = {\n generations: generations?.map((generation) => {\n return generation.map((chunk) => {\n return {\n text: chunk.text,\n generationInfo: chunk.generationInfo,\n };\n });\n }),\n llmOutput: run.outputs?.llmOutput ?? {},\n };\n eventName = \"on_llm_end\";\n } else {\n throw new Error(`onLLMEnd: Unexpected run type: ${runInfo.runType}`);\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onChainStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.run_type ?? \"chain\";\n const runInfo: RunInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: run.run_type,\n };\n let eventData: StreamEventData = {};\n // Workaround Runnable core code not sending input when transform streaming.\n if (run.inputs.input === \"\" && Object.keys(run.inputs).length === 1) {\n eventData = {};\n runInfo.inputs = {};\n } else if (run.inputs.input !== undefined) {\n eventData.input = run.inputs.input;\n runInfo.inputs = run.inputs.input;\n } else {\n eventData.input = run.inputs;\n runInfo.inputs = run.inputs;\n }\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: `on_${runType}_start`,\n data: eventData,\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onChainEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onChainEnd: Run ID ${run.id} not found in run map.`);\n }\n const eventName = `on_${run.run_type}_end`;\n const inputs = run.inputs ?? runInfo.inputs ?? {};\n const outputs = run.outputs?.output ?? run.outputs;\n const data: StreamEventData = {\n output: outputs,\n input: inputs,\n };\n if (inputs.input && Object.keys(inputs).length === 1) {\n data.input = inputs.input;\n runInfo.inputs = inputs.input;\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data,\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: \"tool\",\n inputs: run.inputs ?? {},\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_tool_start\",\n data: {\n input: run.inputs ?? {},\n },\n name: runName,\n run_id: run.id,\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);\n }\n if (runInfo.inputs === undefined) {\n throw new Error(\n `onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`\n );\n }\n const output =\n run.outputs?.output === undefined ? run.outputs : run.outputs.output;\n await this.sendEndEvent(\n {\n event: \"on_tool_end\",\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onToolError(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);\n }\n if (runInfo.inputs === undefined) {\n throw new Error(\n `onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`\n );\n }\n\n await this.sendEndEvent(\n {\n event: \"on_tool_error\",\n data: {\n input: runInfo.inputs,\n error: run.error,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onRetrieverStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = \"retriever\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: {\n query: run.inputs.query,\n },\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_retriever_start\",\n data: {\n input: {\n query: run.inputs.query,\n },\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onRetrieverEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onRetrieverEnd: Run ID ${run.id} not found in run map.`);\n }\n await this.sendEndEvent(\n {\n event: \"on_retriever_end\",\n data: {\n output: run.outputs?.documents ?? run.outputs,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async handleCustomEvent(eventName: string, data: any, runId: string) {\n const runInfo = this.runInfoMap.get(runId);\n if (runInfo === undefined) {\n throw new Error(\n `handleCustomEvent: Run ID ${runId} not found in run map.`\n );\n }\n await this.send(\n {\n event: \"on_custom_event\",\n run_id: runId,\n name: eventName,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data,\n },\n runInfo\n );\n }\n\n async finish() {\n const pendingPromises = [...this.tappedPromises.values()];\n // eslint-disable-next-line no-void\n void Promise.all(pendingPromises).finally(() => {\n // eslint-disable-next-line no-void\n void this.writer.close();\n });\n }\n}\n"],"mappings":";;;;;;AA2HA,SAAS,WAAW,EAClB,MACA,YAKD,EAAU;AACT,KAAI,SAAS,OACX,QAAO;AAET,KAAI,YAAY,SAAS,OACvB,QAAO,WAAW;UACT,YAAY,OAAO,UAAa,MAAM,QAAQ,YAAY,GAAG,CACtE,QAAO,WAAW,GAAG,WAAW,GAAG,SAAS;AAE9C,QAAO;AACR;AAED,MAAa,wBAAwB,CACnCA,YAEA,QAAQ,SAAS;;;;;;;AAQnB,IAAa,6BAAb,cACUC,gCAEV;CACE,AAAU,YAAY;CAEtB,AAAU;CAEV,AAAU;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Q,IAAI,SAAS,aAAa,IAAI;IACtC,OAAO,QAAQ;GAChB;GACD,QAAQ,IAAI;GACZ,MAAM,QAAQ;GACd,MAAM,QAAQ;GACd,UAAU,QAAQ;EACnB,GACD,QACD;CACF;CAGD,MAAM,kBAAkBI,WAAmBM,MAAWlB,OAAe;EACnE,MAAM,UAAU,KAAK,WAAW,IAAI,MAAM;AAC1C,MAAI,YAAY,OACd,OAAM,IAAI,MACR,CAAC,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;EAG9D,MAAM,KAAK,KACT;GACE,OAAO;GACP,QAAQ;GACR,MAAM;GACN,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB;EACD,GACD,QACD;CACF;CAED,MAAM,SAAS;EACb,MAAM,kBAAkB,CAAC,GAAG,KAAK,eAAe,QAAQ,AAAC;EAEpD,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,MAAM;GAEzC,KAAK,OAAO,OAAO;EACzB,EAAC;CACH;AACF"}
|
|
@@ -29,6 +29,11 @@ type StreamEventData = {
|
|
|
29
29
|
* in the output of the runnable that generated the event.
|
|
30
30
|
*/
|
|
31
31
|
chunk?: any;
|
|
32
|
+
/**
|
|
33
|
+
* Error message if the runnable that generated the event failed.
|
|
34
|
+
* This field will only be present if the runnable failed.
|
|
35
|
+
*/
|
|
36
|
+
error?: string;
|
|
32
37
|
};
|
|
33
38
|
/**
|
|
34
39
|
* A streaming event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event_stream.d.cts","names":["BaseTracer","Run","BaseCallbackHandler","BaseCallbackHandlerInput","CallbackHandlerPrefersStreaming","IterableReadableStream","StreamEventData","StreamEvent","Record","RunInfo","EventStreamCallbackHandlerInput","isStreamEventsHandler","EventStreamCallbackHandler","T","TransformStream","WritableStreamDefaultWriter","Symbol","asyncIterator","Promise","AsyncGenerator"],"sources":["../../src/tracers/event_stream.d.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport { BaseCallbackHandler, BaseCallbackHandlerInput, CallbackHandlerPrefersStreaming } from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n input?: any;\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n output?: any;\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n chunk?: any;\n};\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\ntype RunInfo = {\n name: string;\n tags: string[];\n metadata: Record<string, any>;\n runType: string;\n inputs?: Record<string, any>;\n};\nexport interface EventStreamCallbackHandlerInput extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\nexport declare const isStreamEventsHandler: (handler: BaseCallbackHandler) => handler is EventStreamCallbackHandler;\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport declare class EventStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {\n protected autoClose: boolean;\n protected includeNames?: string[];\n protected includeTypes?: string[];\n protected includeTags?: string[];\n protected excludeNames?: string[];\n protected excludeTypes?: string[];\n protected excludeTags?: string[];\n private runInfoMap;\n private tappedPromises;\n protected transformStream: TransformStream;\n writer: WritableStreamDefaultWriter;\n receiveStream: IterableReadableStream<StreamEvent>;\n private readableStreamClosed;\n name: string;\n lc_prefer_streaming: boolean;\n constructor(fields?: EventStreamCallbackHandlerInput);\n [Symbol.asyncIterator](): IterableReadableStream<StreamEvent>;\n protected persistRun(_run: Run): Promise<void>;\n _includeRun(run: RunInfo): boolean;\n tapOutputIterable<T>(runId: string, outputStream: AsyncGenerator<T>): AsyncGenerator<T>;\n send(payload: StreamEvent, run: RunInfo): Promise<void>;\n sendEndEvent(payload: StreamEvent, run: RunInfo): Promise<void>;\n onLLMStart(run: Run): Promise<void>;\n onLLMNewToken(run: Run, token: string, kwargs?: {\n chunk: any;\n }): Promise<void>;\n onLLMEnd(run: Run): Promise<void>;\n onChainStart(run: Run): Promise<void>;\n onChainEnd(run: Run): Promise<void>;\n onToolStart(run: Run): Promise<void>;\n onToolEnd(run: Run): Promise<void>;\n onRetrieverStart(run: Run): Promise<void>;\n onRetrieverEnd(run: Run): Promise<void>;\n handleCustomEvent(eventName: string, data: any, runId: string): Promise<void>;\n finish(): Promise<void>;\n}\nexport {};\n//# sourceMappingURL=event_stream.d.ts.map"],"mappings":";;;;AAMA;
|
|
1
|
+
{"version":3,"file":"event_stream.d.cts","names":["BaseTracer","Run","BaseCallbackHandler","BaseCallbackHandlerInput","CallbackHandlerPrefersStreaming","IterableReadableStream","StreamEventData","StreamEvent","Record","RunInfo","EventStreamCallbackHandlerInput","isStreamEventsHandler","EventStreamCallbackHandler","T","TransformStream","WritableStreamDefaultWriter","Symbol","asyncIterator","Promise","AsyncGenerator"],"sources":["../../src/tracers/event_stream.d.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport { BaseCallbackHandler, BaseCallbackHandlerInput, CallbackHandlerPrefersStreaming } from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n input?: any;\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n output?: any;\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n chunk?: any;\n /**\n * Error message if the runnable that generated the event failed.\n * This field will only be present if the runnable failed.\n */\n error?: string;\n};\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\ntype RunInfo = {\n name: string;\n tags: string[];\n metadata: Record<string, any>;\n runType: string;\n inputs?: Record<string, any>;\n};\nexport interface EventStreamCallbackHandlerInput extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\nexport declare const isStreamEventsHandler: (handler: BaseCallbackHandler) => handler is EventStreamCallbackHandler;\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport declare class EventStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {\n protected autoClose: boolean;\n protected includeNames?: string[];\n protected includeTypes?: string[];\n protected includeTags?: string[];\n protected excludeNames?: string[];\n protected excludeTypes?: string[];\n protected excludeTags?: string[];\n private runInfoMap;\n private tappedPromises;\n protected transformStream: TransformStream;\n writer: WritableStreamDefaultWriter;\n receiveStream: IterableReadableStream<StreamEvent>;\n private readableStreamClosed;\n name: string;\n lc_prefer_streaming: boolean;\n constructor(fields?: EventStreamCallbackHandlerInput);\n [Symbol.asyncIterator](): IterableReadableStream<StreamEvent>;\n protected persistRun(_run: Run): Promise<void>;\n _includeRun(run: RunInfo): boolean;\n tapOutputIterable<T>(runId: string, outputStream: AsyncGenerator<T>): AsyncGenerator<T>;\n send(payload: StreamEvent, run: RunInfo): Promise<void>;\n sendEndEvent(payload: StreamEvent, run: RunInfo): Promise<void>;\n onLLMStart(run: Run): Promise<void>;\n onLLMNewToken(run: Run, token: string, kwargs?: {\n chunk: any;\n }): Promise<void>;\n onLLMEnd(run: Run): Promise<void>;\n onChainStart(run: Run): Promise<void>;\n onChainEnd(run: Run): Promise<void>;\n onToolStart(run: Run): Promise<void>;\n onToolEnd(run: Run): Promise<void>;\n onToolError(run: Run): Promise<void>;\n onRetrieverStart(run: Run): Promise<void>;\n onRetrieverEnd(run: Run): Promise<void>;\n handleCustomEvent(eventName: string, data: any, runId: string): Promise<void>;\n finish(): Promise<void>;\n}\nexport {};\n//# sourceMappingURL=event_stream.d.ts.map"],"mappings":";;;;AAMA;AAmCA;AAmDA;KAtFYM,eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmCAC,WAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoCEC;;;;;;QAMJF;;UASOI,+BAAAA,SAAwCP"}
|
|
@@ -30,6 +30,11 @@ type StreamEventData = {
|
|
|
30
30
|
* in the output of the runnable that generated the event.
|
|
31
31
|
*/
|
|
32
32
|
chunk?: any;
|
|
33
|
+
/**
|
|
34
|
+
* Error message if the runnable that generated the event failed.
|
|
35
|
+
* This field will only be present if the runnable failed.
|
|
36
|
+
*/
|
|
37
|
+
error?: string;
|
|
33
38
|
};
|
|
34
39
|
/**
|
|
35
40
|
* A streaming event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event_stream.d.ts","names":["BaseTracer","Run","BaseCallbackHandler","BaseCallbackHandlerInput","CallbackHandlerPrefersStreaming","IterableReadableStream","StreamEventData","StreamEvent","Record","RunInfo","EventStreamCallbackHandlerInput","isStreamEventsHandler","EventStreamCallbackHandler","T","TransformStream","WritableStreamDefaultWriter","Symbol","asyncIterator","Promise","AsyncGenerator"],"sources":["../../src/tracers/event_stream.d.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport { BaseCallbackHandler, BaseCallbackHandlerInput, CallbackHandlerPrefersStreaming } from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n input?: any;\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n output?: any;\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n chunk?: any;\n};\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\ntype RunInfo = {\n name: string;\n tags: string[];\n metadata: Record<string, any>;\n runType: string;\n inputs?: Record<string, any>;\n};\nexport interface EventStreamCallbackHandlerInput extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\nexport declare const isStreamEventsHandler: (handler: BaseCallbackHandler) => handler is EventStreamCallbackHandler;\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport declare class EventStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {\n protected autoClose: boolean;\n protected includeNames?: string[];\n protected includeTypes?: string[];\n protected includeTags?: string[];\n protected excludeNames?: string[];\n protected excludeTypes?: string[];\n protected excludeTags?: string[];\n private runInfoMap;\n private tappedPromises;\n protected transformStream: TransformStream;\n writer: WritableStreamDefaultWriter;\n receiveStream: IterableReadableStream<StreamEvent>;\n private readableStreamClosed;\n name: string;\n lc_prefer_streaming: boolean;\n constructor(fields?: EventStreamCallbackHandlerInput);\n [Symbol.asyncIterator](): IterableReadableStream<StreamEvent>;\n protected persistRun(_run: Run): Promise<void>;\n _includeRun(run: RunInfo): boolean;\n tapOutputIterable<T>(runId: string, outputStream: AsyncGenerator<T>): AsyncGenerator<T>;\n send(payload: StreamEvent, run: RunInfo): Promise<void>;\n sendEndEvent(payload: StreamEvent, run: RunInfo): Promise<void>;\n onLLMStart(run: Run): Promise<void>;\n onLLMNewToken(run: Run, token: string, kwargs?: {\n chunk: any;\n }): Promise<void>;\n onLLMEnd(run: Run): Promise<void>;\n onChainStart(run: Run): Promise<void>;\n onChainEnd(run: Run): Promise<void>;\n onToolStart(run: Run): Promise<void>;\n onToolEnd(run: Run): Promise<void>;\n onRetrieverStart(run: Run): Promise<void>;\n onRetrieverEnd(run: Run): Promise<void>;\n handleCustomEvent(eventName: string, data: any, runId: string): Promise<void>;\n finish(): Promise<void>;\n}\nexport {};\n//# sourceMappingURL=event_stream.d.ts.map"],"mappings":";;;;;;AAMA;
|
|
1
|
+
{"version":3,"file":"event_stream.d.ts","names":["BaseTracer","Run","BaseCallbackHandler","BaseCallbackHandlerInput","CallbackHandlerPrefersStreaming","IterableReadableStream","StreamEventData","StreamEvent","Record","RunInfo","EventStreamCallbackHandlerInput","isStreamEventsHandler","EventStreamCallbackHandler","T","TransformStream","WritableStreamDefaultWriter","Symbol","asyncIterator","Promise","AsyncGenerator"],"sources":["../../src/tracers/event_stream.d.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport { BaseCallbackHandler, BaseCallbackHandlerInput, CallbackHandlerPrefersStreaming } from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n input?: any;\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n output?: any;\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n chunk?: any;\n /**\n * Error message if the runnable that generated the event failed.\n * This field will only be present if the runnable failed.\n */\n error?: string;\n};\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\ntype RunInfo = {\n name: string;\n tags: string[];\n metadata: Record<string, any>;\n runType: string;\n inputs?: Record<string, any>;\n};\nexport interface EventStreamCallbackHandlerInput extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\nexport declare const isStreamEventsHandler: (handler: BaseCallbackHandler) => handler is EventStreamCallbackHandler;\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport declare class EventStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {\n protected autoClose: boolean;\n protected includeNames?: string[];\n protected includeTypes?: string[];\n protected includeTags?: string[];\n protected excludeNames?: string[];\n protected excludeTypes?: string[];\n protected excludeTags?: string[];\n private runInfoMap;\n private tappedPromises;\n protected transformStream: TransformStream;\n writer: WritableStreamDefaultWriter;\n receiveStream: IterableReadableStream<StreamEvent>;\n private readableStreamClosed;\n name: string;\n lc_prefer_streaming: boolean;\n constructor(fields?: EventStreamCallbackHandlerInput);\n [Symbol.asyncIterator](): IterableReadableStream<StreamEvent>;\n protected persistRun(_run: Run): Promise<void>;\n _includeRun(run: RunInfo): boolean;\n tapOutputIterable<T>(runId: string, outputStream: AsyncGenerator<T>): AsyncGenerator<T>;\n send(payload: StreamEvent, run: RunInfo): Promise<void>;\n sendEndEvent(payload: StreamEvent, run: RunInfo): Promise<void>;\n onLLMStart(run: Run): Promise<void>;\n onLLMNewToken(run: Run, token: string, kwargs?: {\n chunk: any;\n }): Promise<void>;\n onLLMEnd(run: Run): Promise<void>;\n onChainStart(run: Run): Promise<void>;\n onChainEnd(run: Run): Promise<void>;\n onToolStart(run: Run): Promise<void>;\n onToolEnd(run: Run): Promise<void>;\n onToolError(run: Run): Promise<void>;\n onRetrieverStart(run: Run): Promise<void>;\n onRetrieverEnd(run: Run): Promise<void>;\n handleCustomEvent(eventName: string, data: any, runId: string): Promise<void>;\n finish(): Promise<void>;\n}\nexport {};\n//# sourceMappingURL=event_stream.d.ts.map"],"mappings":";;;;;;AAMA;AAmCA;AAmDiBU,KAtFLJ,eAAAA,GAsFKI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAnDLH,WAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoCEC;;;;;;QAMJF;;UASOI,+BAAAA,SAAwCP"}
|
|
@@ -303,6 +303,23 @@ var EventStreamCallbackHandler = class extends BaseTracer {
|
|
|
303
303
|
metadata: runInfo.metadata
|
|
304
304
|
}, runInfo);
|
|
305
305
|
}
|
|
306
|
+
async onToolError(run) {
|
|
307
|
+
const runInfo = this.runInfoMap.get(run.id);
|
|
308
|
+
this.runInfoMap.delete(run.id);
|
|
309
|
+
if (runInfo === void 0) throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);
|
|
310
|
+
if (runInfo.inputs === void 0) throw new Error(`onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`);
|
|
311
|
+
await this.sendEndEvent({
|
|
312
|
+
event: "on_tool_error",
|
|
313
|
+
data: {
|
|
314
|
+
input: runInfo.inputs,
|
|
315
|
+
error: run.error
|
|
316
|
+
},
|
|
317
|
+
run_id: run.id,
|
|
318
|
+
name: runInfo.name,
|
|
319
|
+
tags: runInfo.tags,
|
|
320
|
+
metadata: runInfo.metadata
|
|
321
|
+
}, runInfo);
|
|
322
|
+
}
|
|
306
323
|
async onRetrieverStart(run) {
|
|
307
324
|
const runName = assignName(run);
|
|
308
325
|
const runType = "retriever";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event_stream.js","names":["handler: BaseCallbackHandler","fields?: EventStreamCallbackHandlerInput","_run: Run","run: RunInfo","runId: string","outputStream: AsyncGenerator<T>","eventType: string","data: unknown","tappedPromiseResolver: (() => void) | undefined","event: StreamEvent","payload: StreamEvent","run: Run","token: string","kwargs?: { chunk: any }","eventName: string","generations: ChatGeneration[][] | Generation[][] | undefined","output: BaseMessage | Record<string, any> | undefined","runInfo: RunInfo","eventData: StreamEventData","data: StreamEventData","data: any"],"sources":["../../src/tracers/event_stream.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport {\n BaseCallbackHandler,\n BaseCallbackHandlerInput,\n CallbackHandlerPrefersStreaming,\n} from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { AIMessageChunk } from \"../messages/ai.js\";\nimport { ChatGeneration, Generation, GenerationChunk } from \"../outputs.js\";\nimport { BaseMessage } from \"../messages/base.js\";\n\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input?: any;\n\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n output?: any;\n\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chunk?: any;\n};\n\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\n\ntype RunInfo = {\n name: string;\n tags: string[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n runType: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputs?: Record<string, any>;\n};\n\nexport interface EventStreamCallbackHandlerInput\n extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\n\nfunction assignName({\n name,\n serialized,\n}: {\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n serialized?: Record<string, any>;\n}): string {\n if (name !== undefined) {\n return name;\n }\n if (serialized?.name !== undefined) {\n return serialized.name;\n } else if (serialized?.id !== undefined && Array.isArray(serialized?.id)) {\n return serialized.id[serialized.id.length - 1];\n }\n return \"Unnamed\";\n}\n\nexport const isStreamEventsHandler = (\n handler: BaseCallbackHandler\n): handler is EventStreamCallbackHandler =>\n handler.name === \"event_stream_tracer\";\n\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport class EventStreamCallbackHandler\n extends BaseTracer\n implements CallbackHandlerPrefersStreaming\n{\n protected autoClose = true;\n\n protected includeNames?: string[];\n\n protected includeTypes?: string[];\n\n protected includeTags?: string[];\n\n protected excludeNames?: string[];\n\n protected excludeTypes?: string[];\n\n protected excludeTags?: string[];\n\n private runInfoMap: Map<string, RunInfo> = new Map();\n\n private tappedPromises: Map<string, Promise<void>> = new Map();\n\n protected transformStream: TransformStream;\n\n public writer: WritableStreamDefaultWriter;\n\n public receiveStream: IterableReadableStream<StreamEvent>;\n\n private readableStreamClosed = false;\n\n name = \"event_stream_tracer\";\n\n lc_prefer_streaming = true;\n\n constructor(fields?: EventStreamCallbackHandlerInput) {\n super({ _awaitHandler: true, ...fields });\n this.autoClose = fields?.autoClose ?? true;\n this.includeNames = fields?.includeNames;\n this.includeTypes = fields?.includeTypes;\n this.includeTags = fields?.includeTags;\n this.excludeNames = fields?.excludeNames;\n this.excludeTypes = fields?.excludeTypes;\n this.excludeTags = fields?.excludeTags;\n this.transformStream = new TransformStream({\n flush: () => {\n this.readableStreamClosed = true;\n },\n });\n this.writer = this.transformStream.writable.getWriter();\n this.receiveStream = IterableReadableStream.fromReadableStream(\n this.transformStream.readable\n );\n }\n\n [Symbol.asyncIterator]() {\n return this.receiveStream;\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // This is a legacy method only called once for an entire run tree\n // and is therefore not useful here\n }\n\n _includeRun(run: RunInfo): boolean {\n const runTags = run.tags ?? [];\n let include =\n this.includeNames === undefined &&\n this.includeTags === undefined &&\n this.includeTypes === undefined;\n if (this.includeNames !== undefined) {\n include = include || this.includeNames.includes(run.name);\n }\n if (this.includeTypes !== undefined) {\n include = include || this.includeTypes.includes(run.runType);\n }\n if (this.includeTags !== undefined) {\n include =\n include ||\n runTags.find((tag) => this.includeTags?.includes(tag)) !== undefined;\n }\n if (this.excludeNames !== undefined) {\n include = include && !this.excludeNames.includes(run.name);\n }\n if (this.excludeTypes !== undefined) {\n include = include && !this.excludeTypes.includes(run.runType);\n }\n if (this.excludeTags !== undefined) {\n include =\n include && runTags.every((tag) => !this.excludeTags?.includes(tag));\n }\n return include;\n }\n\n async *tapOutputIterable<T>(\n runId: string,\n outputStream: AsyncGenerator<T>\n ): AsyncGenerator<T> {\n const firstChunk = await outputStream.next();\n if (firstChunk.done) {\n return;\n }\n const runInfo = this.runInfoMap.get(runId);\n // Run has finished, don't issue any stream events.\n // An example of this is for runnables that use the default\n // implementation of .stream(), which delegates to .invoke()\n // and calls .onChainEnd() before passing it to the iterator.\n if (runInfo === undefined) {\n yield firstChunk.value;\n return;\n }\n // Match format from handlers below\n function _formatOutputChunk(eventType: string, data: unknown) {\n if (eventType === \"llm\" && typeof data === \"string\") {\n return new GenerationChunk({ text: data });\n }\n return data;\n }\n let tappedPromise = this.tappedPromises.get(runId);\n // if we are the first to tap, issue stream events\n if (tappedPromise === undefined) {\n let tappedPromiseResolver: (() => void) | undefined;\n tappedPromise = new Promise((resolve) => {\n tappedPromiseResolver = resolve;\n });\n this.tappedPromises.set(runId, tappedPromise);\n try {\n const event: StreamEvent = {\n event: `on_${runInfo.runType}_stream`,\n run_id: runId,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data: {},\n };\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, firstChunk.value),\n },\n },\n runInfo\n );\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n // Don't yield tool and retriever stream events\n if (runInfo.runType !== \"tool\" && runInfo.runType !== \"retriever\") {\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, chunk),\n },\n },\n runInfo\n );\n }\n yield chunk;\n }\n } finally {\n tappedPromiseResolver?.();\n // Don't delete from the promises map to keep track of which runs have been tapped.\n }\n } else {\n // otherwise just pass through\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n yield chunk;\n }\n }\n }\n\n async send(payload: StreamEvent, run: RunInfo) {\n if (this.readableStreamClosed) return;\n if (this._includeRun(run)) {\n await this.writer.write(payload);\n }\n }\n\n async sendEndEvent(payload: StreamEvent, run: RunInfo) {\n const tappedPromise = this.tappedPromises.get(payload.run_id);\n if (tappedPromise !== undefined) {\n // eslint-disable-next-line no-void\n void tappedPromise.then(() => {\n // eslint-disable-next-line no-void\n void this.send(payload, run);\n });\n } else {\n await this.send(payload, run);\n }\n }\n\n async onLLMStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.inputs.messages !== undefined ? \"chat_model\" : \"llm\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: run.inputs,\n };\n this.runInfoMap.set(run.id, runInfo);\n const eventName = `on_${runType}_start`;\n await this.send(\n {\n event: eventName,\n data: {\n input: run.inputs,\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onLLMNewToken(\n run: Run,\n token: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n kwargs?: { chunk: any }\n ): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n let chunk;\n let eventName;\n if (runInfo === undefined) {\n throw new Error(`onLLMNewToken: Run ID ${run.id} not found in run map.`);\n }\n // Top-level streaming events are covered by tapOutputIterable\n if (this.runInfoMap.size === 1) {\n return;\n }\n if (runInfo.runType === \"chat_model\") {\n eventName = \"on_chat_model_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new AIMessageChunk({ content: token, id: `run-${run.id}` });\n } else {\n chunk = kwargs.chunk.message;\n }\n } else if (runInfo.runType === \"llm\") {\n eventName = \"on_llm_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new GenerationChunk({ text: token });\n } else {\n chunk = kwargs.chunk;\n }\n } else {\n throw new Error(`Unexpected run type ${runInfo.runType}`);\n }\n await this.send(\n {\n event: eventName,\n data: {\n chunk,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onLLMEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n let eventName: string;\n if (runInfo === undefined) {\n throw new Error(`onLLMEnd: Run ID ${run.id} not found in run map.`);\n }\n const generations: ChatGeneration[][] | Generation[][] | undefined =\n run.outputs?.generations;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let output: BaseMessage | Record<string, any> | undefined;\n if (runInfo.runType === \"chat_model\") {\n for (const generation of generations ?? []) {\n if (output !== undefined) {\n break;\n }\n output = (generation[0] as ChatGeneration | undefined)?.message;\n }\n eventName = \"on_chat_model_end\";\n } else if (runInfo.runType === \"llm\") {\n output = {\n generations: generations?.map((generation) => {\n return generation.map((chunk) => {\n return {\n text: chunk.text,\n generationInfo: chunk.generationInfo,\n };\n });\n }),\n llmOutput: run.outputs?.llmOutput ?? {},\n };\n eventName = \"on_llm_end\";\n } else {\n throw new Error(`onLLMEnd: Unexpected run type: ${runInfo.runType}`);\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onChainStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.run_type ?? \"chain\";\n const runInfo: RunInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: run.run_type,\n };\n let eventData: StreamEventData = {};\n // Workaround Runnable core code not sending input when transform streaming.\n if (run.inputs.input === \"\" && Object.keys(run.inputs).length === 1) {\n eventData = {};\n runInfo.inputs = {};\n } else if (run.inputs.input !== undefined) {\n eventData.input = run.inputs.input;\n runInfo.inputs = run.inputs.input;\n } else {\n eventData.input = run.inputs;\n runInfo.inputs = run.inputs;\n }\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: `on_${runType}_start`,\n data: eventData,\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onChainEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onChainEnd: Run ID ${run.id} not found in run map.`);\n }\n const eventName = `on_${run.run_type}_end`;\n const inputs = run.inputs ?? runInfo.inputs ?? {};\n const outputs = run.outputs?.output ?? run.outputs;\n const data: StreamEventData = {\n output: outputs,\n input: inputs,\n };\n if (inputs.input && Object.keys(inputs).length === 1) {\n data.input = inputs.input;\n runInfo.inputs = inputs.input;\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data,\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: \"tool\",\n inputs: run.inputs ?? {},\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_tool_start\",\n data: {\n input: run.inputs ?? {},\n },\n name: runName,\n run_id: run.id,\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);\n }\n if (runInfo.inputs === undefined) {\n throw new Error(\n `onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`\n );\n }\n const output =\n run.outputs?.output === undefined ? run.outputs : run.outputs.output;\n await this.sendEndEvent(\n {\n event: \"on_tool_end\",\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onRetrieverStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = \"retriever\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: {\n query: run.inputs.query,\n },\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_retriever_start\",\n data: {\n input: {\n query: run.inputs.query,\n },\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onRetrieverEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onRetrieverEnd: Run ID ${run.id} not found in run map.`);\n }\n await this.sendEndEvent(\n {\n event: \"on_retriever_end\",\n data: {\n output: run.outputs?.documents ?? run.outputs,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async handleCustomEvent(eventName: string, data: any, runId: string) {\n const runInfo = this.runInfoMap.get(runId);\n if (runInfo === undefined) {\n throw new Error(\n `handleCustomEvent: Run ID ${runId} not found in run map.`\n );\n }\n await this.send(\n {\n event: \"on_custom_event\",\n run_id: runId,\n name: eventName,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data,\n },\n runInfo\n );\n }\n\n async finish() {\n const pendingPromises = [...this.tappedPromises.values()];\n // eslint-disable-next-line no-void\n void Promise.all(pendingPromises).finally(() => {\n // eslint-disable-next-line no-void\n void this.writer.close();\n });\n }\n}\n"],"mappings":";;;;;;AAqHA,SAAS,WAAW,EAClB,MACA,YAKD,EAAU;AACT,KAAI,SAAS,OACX,QAAO;AAET,KAAI,YAAY,SAAS,OACvB,QAAO,WAAW;UACT,YAAY,OAAO,UAAa,MAAM,QAAQ,YAAY,GAAG,CACtE,QAAO,WAAW,GAAG,WAAW,GAAG,SAAS;AAE9C,QAAO;AACR;AAED,MAAa,wBAAwB,CACnCA,YAEA,QAAQ,SAAS;;;;;;;AAQnB,IAAa,6BAAb,cACU,WAEV;CACE,AAAU,YAAY;CAEtB,AAAU;CAEV,AAAU;CAEV,AAAU;CAEV,AAAU;CAEV,AAAU;CAEV,AAAU;CAEV,AAAQ,6BAAmC,IAAI;CAE/C,AAAQ,iCAA6C,IAAI;CAEzD,AAAU;CAEV,AAAO;CAEP,AAAO;CAEP,AAAQ,uBAAuB;CAE/B,OAAO;CAEP,sBAAsB;CAEtB,YAAYC,QAA0C;EACpD,MAAM;GAAE,eAAe;GAAM,GAAG;EAAQ,EAAC;EACzC,KAAK,YAAY,QAAQ,aAAa;EACtC,KAAK,eAAe,QAAQ;EAC5B,KAAK,eAAe,QAAQ;EAC5B,KAAK,cAAc,QAAQ;EAC3B,KAAK,eAAe,QAAQ;EAC5B,KAAK,eAAe,QAAQ;EAC5B,KAAK,cAAc,QAAQ;EAC3B,KAAK,kBAAkB,IAAI,gBAAgB,EACzC,OAAO,MAAM;GACX,KAAK,uBAAuB;EAC7B,EACF;EACD,KAAK,SAAS,KAAK,gBAAgB,SAAS,WAAW;EACvD,KAAK,gBAAgB,uBAAuB,mBAC1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MAAI,YAAY,OACd,OAAM,IAAI,MAAM,CAAC,uBAAuB,EAAE,IAAI,GAAG,sBAAsB,CAAC;EAE1E,MAAM,KAAK,aACT;GACE,OAAO;GACP,MAAM;IACJ,QAAQ,IAAI,SAAS,aAAa,IAAI;IACtC,OAAO,QAAQ;GAChB;GACD,QAAQ,IAAI;GACZ,MAAM,QAAQ;GACd,MAAM,QAAQ;GACd,UAAU,QAAQ;EACnB,GACD,QACD;CACF;CAGD,MAAM,kBAAkBG,WAAmBM,MAAWhB,OAAe;EACnE,MAAM,UAAU,KAAK,WAAW,IAAI,MAAM;AAC1C,MAAI,YAAY,OACd,OAAM,IAAI,MACR,CAAC,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;EAG9D,MAAM,KAAK,KACT;GACE,OAAO;GACP,QAAQ;GACR,MAAM;GACN,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB;EACD,GACD,QACD;CACF;CAED,MAAM,SAAS;EACb,MAAM,kBAAkB,CAAC,GAAG,KAAK,eAAe,QAAQ,AAAC;EAEpD,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,MAAM;GAEzC,KAAK,OAAO,OAAO;EACzB,EAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"event_stream.js","names":["handler: BaseCallbackHandler","fields?: EventStreamCallbackHandlerInput","_run: Run","run: RunInfo","runId: string","outputStream: AsyncGenerator<T>","eventType: string","data: unknown","tappedPromiseResolver: (() => void) | undefined","event: StreamEvent","payload: StreamEvent","run: Run","token: string","kwargs?: { chunk: any }","eventName: string","generations: ChatGeneration[][] | Generation[][] | undefined","output: BaseMessage | Record<string, any> | undefined","runInfo: RunInfo","eventData: StreamEventData","data: StreamEventData","data: any"],"sources":["../../src/tracers/event_stream.ts"],"sourcesContent":["import { BaseTracer, type Run } from \"./base.js\";\nimport {\n BaseCallbackHandler,\n BaseCallbackHandlerInput,\n CallbackHandlerPrefersStreaming,\n} from \"../callbacks/base.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { AIMessageChunk } from \"../messages/ai.js\";\nimport { ChatGeneration, Generation, GenerationChunk } from \"../outputs.js\";\nimport { BaseMessage } from \"../messages/base.js\";\n\n/**\n * Data associated with a StreamEvent.\n */\nexport type StreamEventData = {\n /**\n * The input passed to the runnable that generated the event.\n * Inputs will sometimes be available at the *START* of the runnable, and\n * sometimes at the *END* of the runnable.\n * If a runnable is able to stream its inputs, then its input by definition\n * won't be known until the *END* of the runnable when it has finished streaming\n * its inputs.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input?: any;\n\n /**\n * The output of the runnable that generated the event.\n * Outputs will only be available at the *END* of the runnable.\n * For most runnables, this field can be inferred from the `chunk` field,\n * though there might be some exceptions for special cased runnables (e.g., like\n * chat models), which may return more information.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n output?: any;\n\n /**\n * A streaming chunk from the output that generated the event.\n * chunks support addition in general, and adding them up should result\n * in the output of the runnable that generated the event.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n chunk?: any;\n\n /**\n * Error message if the runnable that generated the event failed.\n * This field will only be present if the runnable failed.\n */\n error?: string;\n};\n\n/**\n * A streaming event.\n *\n * Schema of a streaming event which is produced from the streamEvents method.\n */\nexport type StreamEvent = {\n /**\n * Event names are of the format: on_[runnable_type]_(start|stream|end).\n *\n * Runnable types are one of:\n * - llm - used by non chat models\n * - chat_model - used by chat models\n * - prompt -- e.g., ChatPromptTemplate\n * - tool -- LangChain tools\n * - chain - most Runnables are of this type\n *\n * Further, the events are categorized as one of:\n * - start - when the runnable starts\n * - stream - when the runnable is streaming\n * - end - when the runnable ends\n *\n * start, stream and end are associated with slightly different `data` payload.\n *\n * Please see the documentation for `EventData` for more details.\n */\n event: string;\n /** The name of the runnable that generated the event. */\n name: string;\n /**\n * An randomly generated ID to keep track of the execution of the given runnable.\n *\n * Each child runnable that gets invoked as part of the execution of a parent runnable\n * is assigned its own unique ID.\n */\n run_id: string;\n /**\n * Tags associated with the runnable that generated this event.\n * Tags are always inherited from parent runnables.\n */\n tags?: string[];\n /** Metadata associated with the runnable that generated this event. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n /**\n * Event data.\n *\n * The contents of the event data depend on the event type.\n */\n data: StreamEventData;\n};\n\ntype RunInfo = {\n name: string;\n tags: string[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n runType: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputs?: Record<string, any>;\n};\n\nexport interface EventStreamCallbackHandlerInput\n extends BaseCallbackHandlerInput {\n autoClose?: boolean;\n includeNames?: string[];\n includeTypes?: string[];\n includeTags?: string[];\n excludeNames?: string[];\n excludeTypes?: string[];\n excludeTags?: string[];\n}\n\nfunction assignName({\n name,\n serialized,\n}: {\n name?: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n serialized?: Record<string, any>;\n}): string {\n if (name !== undefined) {\n return name;\n }\n if (serialized?.name !== undefined) {\n return serialized.name;\n } else if (serialized?.id !== undefined && Array.isArray(serialized?.id)) {\n return serialized.id[serialized.id.length - 1];\n }\n return \"Unnamed\";\n}\n\nexport const isStreamEventsHandler = (\n handler: BaseCallbackHandler\n): handler is EventStreamCallbackHandler =>\n handler.name === \"event_stream_tracer\";\n\n/**\n * Class that extends the `BaseTracer` class from the\n * `langchain.callbacks.tracers.base` module. It represents a callback\n * handler that logs the execution of runs and emits `RunLog` instances to a\n * `RunLogStream`.\n */\nexport class EventStreamCallbackHandler\n extends BaseTracer\n implements CallbackHandlerPrefersStreaming\n{\n protected autoClose = true;\n\n protected includeNames?: string[];\n\n protected includeTypes?: string[];\n\n protected includeTags?: string[];\n\n protected excludeNames?: string[];\n\n protected excludeTypes?: string[];\n\n protected excludeTags?: string[];\n\n private runInfoMap: Map<string, RunInfo> = new Map();\n\n private tappedPromises: Map<string, Promise<void>> = new Map();\n\n protected transformStream: TransformStream;\n\n public writer: WritableStreamDefaultWriter;\n\n public receiveStream: IterableReadableStream<StreamEvent>;\n\n private readableStreamClosed = false;\n\n name = \"event_stream_tracer\";\n\n lc_prefer_streaming = true;\n\n constructor(fields?: EventStreamCallbackHandlerInput) {\n super({ _awaitHandler: true, ...fields });\n this.autoClose = fields?.autoClose ?? true;\n this.includeNames = fields?.includeNames;\n this.includeTypes = fields?.includeTypes;\n this.includeTags = fields?.includeTags;\n this.excludeNames = fields?.excludeNames;\n this.excludeTypes = fields?.excludeTypes;\n this.excludeTags = fields?.excludeTags;\n this.transformStream = new TransformStream({\n flush: () => {\n this.readableStreamClosed = true;\n },\n });\n this.writer = this.transformStream.writable.getWriter();\n this.receiveStream = IterableReadableStream.fromReadableStream(\n this.transformStream.readable\n );\n }\n\n [Symbol.asyncIterator]() {\n return this.receiveStream;\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // This is a legacy method only called once for an entire run tree\n // and is therefore not useful here\n }\n\n _includeRun(run: RunInfo): boolean {\n const runTags = run.tags ?? [];\n let include =\n this.includeNames === undefined &&\n this.includeTags === undefined &&\n this.includeTypes === undefined;\n if (this.includeNames !== undefined) {\n include = include || this.includeNames.includes(run.name);\n }\n if (this.includeTypes !== undefined) {\n include = include || this.includeTypes.includes(run.runType);\n }\n if (this.includeTags !== undefined) {\n include =\n include ||\n runTags.find((tag) => this.includeTags?.includes(tag)) !== undefined;\n }\n if (this.excludeNames !== undefined) {\n include = include && !this.excludeNames.includes(run.name);\n }\n if (this.excludeTypes !== undefined) {\n include = include && !this.excludeTypes.includes(run.runType);\n }\n if (this.excludeTags !== undefined) {\n include =\n include && runTags.every((tag) => !this.excludeTags?.includes(tag));\n }\n return include;\n }\n\n async *tapOutputIterable<T>(\n runId: string,\n outputStream: AsyncGenerator<T>\n ): AsyncGenerator<T> {\n const firstChunk = await outputStream.next();\n if (firstChunk.done) {\n return;\n }\n const runInfo = this.runInfoMap.get(runId);\n // Run has finished, don't issue any stream events.\n // An example of this is for runnables that use the default\n // implementation of .stream(), which delegates to .invoke()\n // and calls .onChainEnd() before passing it to the iterator.\n if (runInfo === undefined) {\n yield firstChunk.value;\n return;\n }\n // Match format from handlers below\n function _formatOutputChunk(eventType: string, data: unknown) {\n if (eventType === \"llm\" && typeof data === \"string\") {\n return new GenerationChunk({ text: data });\n }\n return data;\n }\n let tappedPromise = this.tappedPromises.get(runId);\n // if we are the first to tap, issue stream events\n if (tappedPromise === undefined) {\n let tappedPromiseResolver: (() => void) | undefined;\n tappedPromise = new Promise((resolve) => {\n tappedPromiseResolver = resolve;\n });\n this.tappedPromises.set(runId, tappedPromise);\n try {\n const event: StreamEvent = {\n event: `on_${runInfo.runType}_stream`,\n run_id: runId,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data: {},\n };\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, firstChunk.value),\n },\n },\n runInfo\n );\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n // Don't yield tool and retriever stream events\n if (runInfo.runType !== \"tool\" && runInfo.runType !== \"retriever\") {\n await this.send(\n {\n ...event,\n data: {\n chunk: _formatOutputChunk(runInfo.runType, chunk),\n },\n },\n runInfo\n );\n }\n yield chunk;\n }\n } finally {\n tappedPromiseResolver?.();\n // Don't delete from the promises map to keep track of which runs have been tapped.\n }\n } else {\n // otherwise just pass through\n yield firstChunk.value;\n for await (const chunk of outputStream) {\n yield chunk;\n }\n }\n }\n\n async send(payload: StreamEvent, run: RunInfo) {\n if (this.readableStreamClosed) return;\n if (this._includeRun(run)) {\n await this.writer.write(payload);\n }\n }\n\n async sendEndEvent(payload: StreamEvent, run: RunInfo) {\n const tappedPromise = this.tappedPromises.get(payload.run_id);\n if (tappedPromise !== undefined) {\n // eslint-disable-next-line no-void\n void tappedPromise.then(() => {\n // eslint-disable-next-line no-void\n void this.send(payload, run);\n });\n } else {\n await this.send(payload, run);\n }\n }\n\n async onLLMStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.inputs.messages !== undefined ? \"chat_model\" : \"llm\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: run.inputs,\n };\n this.runInfoMap.set(run.id, runInfo);\n const eventName = `on_${runType}_start`;\n await this.send(\n {\n event: eventName,\n data: {\n input: run.inputs,\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onLLMNewToken(\n run: Run,\n token: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n kwargs?: { chunk: any }\n ): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n let chunk;\n let eventName;\n if (runInfo === undefined) {\n throw new Error(`onLLMNewToken: Run ID ${run.id} not found in run map.`);\n }\n // Top-level streaming events are covered by tapOutputIterable\n if (this.runInfoMap.size === 1) {\n return;\n }\n if (runInfo.runType === \"chat_model\") {\n eventName = \"on_chat_model_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new AIMessageChunk({ content: token, id: `run-${run.id}` });\n } else {\n chunk = kwargs.chunk.message;\n }\n } else if (runInfo.runType === \"llm\") {\n eventName = \"on_llm_stream\";\n if (kwargs?.chunk === undefined) {\n chunk = new GenerationChunk({ text: token });\n } else {\n chunk = kwargs.chunk;\n }\n } else {\n throw new Error(`Unexpected run type ${runInfo.runType}`);\n }\n await this.send(\n {\n event: eventName,\n data: {\n chunk,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onLLMEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n let eventName: string;\n if (runInfo === undefined) {\n throw new Error(`onLLMEnd: Run ID ${run.id} not found in run map.`);\n }\n const generations: ChatGeneration[][] | Generation[][] | undefined =\n run.outputs?.generations;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let output: BaseMessage | Record<string, any> | undefined;\n if (runInfo.runType === \"chat_model\") {\n for (const generation of generations ?? []) {\n if (output !== undefined) {\n break;\n }\n output = (generation[0] as ChatGeneration | undefined)?.message;\n }\n eventName = \"on_chat_model_end\";\n } else if (runInfo.runType === \"llm\") {\n output = {\n generations: generations?.map((generation) => {\n return generation.map((chunk) => {\n return {\n text: chunk.text,\n generationInfo: chunk.generationInfo,\n };\n });\n }),\n llmOutput: run.outputs?.llmOutput ?? {},\n };\n eventName = \"on_llm_end\";\n } else {\n throw new Error(`onLLMEnd: Unexpected run type: ${runInfo.runType}`);\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onChainStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = run.run_type ?? \"chain\";\n const runInfo: RunInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: run.run_type,\n };\n let eventData: StreamEventData = {};\n // Workaround Runnable core code not sending input when transform streaming.\n if (run.inputs.input === \"\" && Object.keys(run.inputs).length === 1) {\n eventData = {};\n runInfo.inputs = {};\n } else if (run.inputs.input !== undefined) {\n eventData.input = run.inputs.input;\n runInfo.inputs = run.inputs.input;\n } else {\n eventData.input = run.inputs;\n runInfo.inputs = run.inputs;\n }\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: `on_${runType}_start`,\n data: eventData,\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onChainEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onChainEnd: Run ID ${run.id} not found in run map.`);\n }\n const eventName = `on_${run.run_type}_end`;\n const inputs = run.inputs ?? runInfo.inputs ?? {};\n const outputs = run.outputs?.output ?? run.outputs;\n const data: StreamEventData = {\n output: outputs,\n input: inputs,\n };\n if (inputs.input && Object.keys(inputs).length === 1) {\n data.input = inputs.input;\n runInfo.inputs = inputs.input;\n }\n await this.sendEndEvent(\n {\n event: eventName,\n data,\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType: \"tool\",\n inputs: run.inputs ?? {},\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_tool_start\",\n data: {\n input: run.inputs ?? {},\n },\n name: runName,\n run_id: run.id,\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onToolEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);\n }\n if (runInfo.inputs === undefined) {\n throw new Error(\n `onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`\n );\n }\n const output =\n run.outputs?.output === undefined ? run.outputs : run.outputs.output;\n await this.sendEndEvent(\n {\n event: \"on_tool_end\",\n data: {\n output,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onToolError(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onToolEnd: Run ID ${run.id} not found in run map.`);\n }\n if (runInfo.inputs === undefined) {\n throw new Error(\n `onToolEnd: Run ID ${run.id} is a tool call, and is expected to have traced inputs.`\n );\n }\n\n await this.sendEndEvent(\n {\n event: \"on_tool_error\",\n data: {\n input: runInfo.inputs,\n error: run.error,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n async onRetrieverStart(run: Run): Promise<void> {\n const runName = assignName(run);\n const runType = \"retriever\";\n const runInfo = {\n tags: run.tags ?? [],\n metadata: run.extra?.metadata ?? {},\n name: runName,\n runType,\n inputs: {\n query: run.inputs.query,\n },\n };\n this.runInfoMap.set(run.id, runInfo);\n await this.send(\n {\n event: \"on_retriever_start\",\n data: {\n input: {\n query: run.inputs.query,\n },\n },\n name: runName,\n tags: run.tags ?? [],\n run_id: run.id,\n metadata: run.extra?.metadata ?? {},\n },\n runInfo\n );\n }\n\n async onRetrieverEnd(run: Run): Promise<void> {\n const runInfo = this.runInfoMap.get(run.id);\n this.runInfoMap.delete(run.id);\n if (runInfo === undefined) {\n throw new Error(`onRetrieverEnd: Run ID ${run.id} not found in run map.`);\n }\n await this.sendEndEvent(\n {\n event: \"on_retriever_end\",\n data: {\n output: run.outputs?.documents ?? run.outputs,\n input: runInfo.inputs,\n },\n run_id: run.id,\n name: runInfo.name,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n },\n runInfo\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async handleCustomEvent(eventName: string, data: any, runId: string) {\n const runInfo = this.runInfoMap.get(runId);\n if (runInfo === undefined) {\n throw new Error(\n `handleCustomEvent: Run ID ${runId} not found in run map.`\n );\n }\n await this.send(\n {\n event: \"on_custom_event\",\n run_id: runId,\n name: eventName,\n tags: runInfo.tags,\n metadata: runInfo.metadata,\n data,\n },\n runInfo\n );\n }\n\n async finish() {\n const pendingPromises = [...this.tappedPromises.values()];\n // eslint-disable-next-line no-void\n void Promise.all(pendingPromises).finally(() => {\n // eslint-disable-next-line no-void\n void this.writer.close();\n });\n }\n}\n"],"mappings":";;;;;;AA2HA,SAAS,WAAW,EAClB,MACA,YAKD,EAAU;AACT,KAAI,SAAS,OACX,QAAO;AAET,KAAI,YAAY,SAAS,OACvB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