@langchain/core 1.1.12 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/caches/index.d.cts.map +1 -1
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/messages/block_translators/deepseek.cjs +59 -0
- package/dist/messages/block_translators/deepseek.cjs.map +1 -0
- package/dist/messages/block_translators/deepseek.js +59 -0
- package/dist/messages/block_translators/deepseek.js.map +1 -0
- package/dist/messages/block_translators/google_genai.cjs +7 -0
- package/dist/messages/block_translators/google_genai.cjs.map +1 -1
- package/dist/messages/block_translators/google_genai.js +7 -0
- package/dist/messages/block_translators/google_genai.js.map +1 -1
- package/dist/messages/block_translators/google_vertexai.cjs +7 -0
- package/dist/messages/block_translators/google_vertexai.cjs.map +1 -1
- package/dist/messages/block_translators/google_vertexai.js +7 -0
- package/dist/messages/block_translators/google_vertexai.js.map +1 -1
- package/dist/messages/block_translators/groq.cjs +97 -0
- package/dist/messages/block_translators/groq.cjs.map +1 -0
- package/dist/messages/block_translators/groq.js +97 -0
- package/dist/messages/block_translators/groq.js.map +1 -0
- package/dist/messages/block_translators/index.cjs +9 -1
- package/dist/messages/block_translators/index.cjs.map +1 -1
- package/dist/messages/block_translators/index.js +9 -1
- package/dist/messages/block_translators/index.js.map +1 -1
- package/dist/messages/block_translators/ollama.cjs +59 -0
- package/dist/messages/block_translators/ollama.cjs.map +1 -0
- package/dist/messages/block_translators/ollama.js +59 -0
- package/dist/messages/block_translators/ollama.js.map +1 -0
- package/dist/messages/block_translators/xai.cjs +95 -0
- package/dist/messages/block_translators/xai.cjs.map +1 -0
- package/dist/messages/block_translators/xai.js +95 -0
- package/dist/messages/block_translators/xai.js.map +1 -0
- package/dist/output_parsers/json.cjs +10 -0
- package/dist/output_parsers/json.cjs.map +1 -1
- package/dist/output_parsers/json.d.cts +9 -0
- package/dist/output_parsers/json.d.cts.map +1 -1
- package/dist/output_parsers/json.d.ts +10 -1
- package/dist/output_parsers/json.d.ts.map +1 -1
- package/dist/output_parsers/json.js +10 -0
- package/dist/output_parsers/json.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +9 -2
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +9 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @langchain/core
|
|
2
2
|
|
|
3
|
+
## 1.1.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#9777](https://github.com/langchain-ai/langchainjs/pull/9777) [`3efe79c`](https://github.com/langchain-ai/langchainjs/commit/3efe79c62ff2ffe0ada562f7eecd85be074b649a) Thanks [@christian-bromann](https://github.com/christian-bromann)! - fix(core): properly elevate reasoning tokens
|
|
8
|
+
|
|
9
|
+
- [#9789](https://github.com/langchain-ai/langchainjs/pull/9789) [`b8561c1`](https://github.com/langchain-ai/langchainjs/commit/b8561c17556bdf7a3ff8d70bc307422642a9172e) Thanks [@hntrl](https://github.com/hntrl)! - source JsonOutputParser content from text accessor
|
|
10
|
+
|
|
3
11
|
## 1.1.12
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 🦜🍎️ @langchain/core
|
|
2
2
|
|
|
3
|
-
 [](https://opensource.org/licenses/MIT) [ [](https://opensource.org/licenses/MIT) [](https://x.com/langchain)
|
|
4
4
|
|
|
5
5
|
`@langchain/core` contains the core abstractions and schemas of LangChain.js, including base classes for language models,
|
|
6
6
|
chat models, vectorstores, retrievers, and runnables.
|
|
@@ -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,EA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;;;;;KAvJYU,sBAAAA,GAAyBH;;;;;;UAMpBI,+BAAAA;;;iBAGOC,+BAAAA,IAAmCC;;;;;;;uBAO7BA,mBAAAA,SAA4BN,+BAAAA,YAA2CH,0BAA0BN;;;;;;;;;;;;;;;;;;;;;;;;aAwBhHG;;;;;;;;;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"}
|
|
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_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,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,MAyCnGC,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA,CAAAA,EA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messages/block_translators/deepseek.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a DeepSeek AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from DeepSeek's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* both string content and the reasoning_content in additional_kwargs.
|
|
10
|
+
*
|
|
11
|
+
* @param message - The AI message containing DeepSeek-formatted content
|
|
12
|
+
* @returns Array of content blocks in v1 standard format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const message = new AIMessage({
|
|
17
|
+
* content: "The answer is 42",
|
|
18
|
+
* additional_kwargs: { reasoning_content: "Let me think about this..." }
|
|
19
|
+
* });
|
|
20
|
+
* const standardBlocks = convertToV1FromDeepSeekMessage(message);
|
|
21
|
+
* // Returns:
|
|
22
|
+
* // [
|
|
23
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
24
|
+
* // { type: "text", text: "The answer is 42" }
|
|
25
|
+
* // ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function convertToV1FromDeepSeekMessage(message) {
|
|
29
|
+
const blocks = [];
|
|
30
|
+
const reasoningContent = message.additional_kwargs?.reasoning_content;
|
|
31
|
+
if (require_utils._isString(reasoningContent) && reasoningContent.length > 0) blocks.push({
|
|
32
|
+
type: "reasoning",
|
|
33
|
+
reasoning: reasoningContent
|
|
34
|
+
});
|
|
35
|
+
if (typeof message.content === "string") {
|
|
36
|
+
if (message.content.length > 0) blocks.push({
|
|
37
|
+
type: "text",
|
|
38
|
+
text: message.content
|
|
39
|
+
});
|
|
40
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && require_utils._isString(block.text)) blocks.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: block.text
|
|
43
|
+
});
|
|
44
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
45
|
+
type: "tool_call",
|
|
46
|
+
id: toolCall.id,
|
|
47
|
+
name: toolCall.name,
|
|
48
|
+
args: toolCall.args
|
|
49
|
+
});
|
|
50
|
+
return blocks;
|
|
51
|
+
}
|
|
52
|
+
const ChatDeepSeekTranslator = {
|
|
53
|
+
translateContent: convertToV1FromDeepSeekMessage,
|
|
54
|
+
translateContentChunk: convertToV1FromDeepSeekMessage
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.ChatDeepSeekTranslator = ChatDeepSeekTranslator;
|
|
59
|
+
//# sourceMappingURL=deepseek.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","_isString","ChatDeepSeekTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/deepseek.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts a DeepSeek AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from DeepSeek's API format\n * and converts it to the standardized v1 content block format. It handles\n * both string content and the reasoning_content in additional_kwargs.\n *\n * @param message - The AI message containing DeepSeek-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromDeepSeekMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromDeepSeekMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Extract reasoning from additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatDeepSeekTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromDeepSeekMessage,\n translateContentChunk: convertToV1FromDeepSeekMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAIC,wBAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACVA,wBAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,yBAAyD;CACpE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { _isString } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/deepseek.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a DeepSeek AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from DeepSeek's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* both string content and the reasoning_content in additional_kwargs.
|
|
10
|
+
*
|
|
11
|
+
* @param message - The AI message containing DeepSeek-formatted content
|
|
12
|
+
* @returns Array of content blocks in v1 standard format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const message = new AIMessage({
|
|
17
|
+
* content: "The answer is 42",
|
|
18
|
+
* additional_kwargs: { reasoning_content: "Let me think about this..." }
|
|
19
|
+
* });
|
|
20
|
+
* const standardBlocks = convertToV1FromDeepSeekMessage(message);
|
|
21
|
+
* // Returns:
|
|
22
|
+
* // [
|
|
23
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
24
|
+
* // { type: "text", text: "The answer is 42" }
|
|
25
|
+
* // ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function convertToV1FromDeepSeekMessage(message) {
|
|
29
|
+
const blocks = [];
|
|
30
|
+
const reasoningContent = message.additional_kwargs?.reasoning_content;
|
|
31
|
+
if (_isString(reasoningContent) && reasoningContent.length > 0) blocks.push({
|
|
32
|
+
type: "reasoning",
|
|
33
|
+
reasoning: reasoningContent
|
|
34
|
+
});
|
|
35
|
+
if (typeof message.content === "string") {
|
|
36
|
+
if (message.content.length > 0) blocks.push({
|
|
37
|
+
type: "text",
|
|
38
|
+
text: message.content
|
|
39
|
+
});
|
|
40
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && _isString(block.text)) blocks.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: block.text
|
|
43
|
+
});
|
|
44
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
45
|
+
type: "tool_call",
|
|
46
|
+
id: toolCall.id,
|
|
47
|
+
name: toolCall.name,
|
|
48
|
+
args: toolCall.args
|
|
49
|
+
});
|
|
50
|
+
return blocks;
|
|
51
|
+
}
|
|
52
|
+
const ChatDeepSeekTranslator = {
|
|
53
|
+
translateContent: convertToV1FromDeepSeekMessage,
|
|
54
|
+
translateContentChunk: convertToV1FromDeepSeekMessage
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { ChatDeepSeekTranslator };
|
|
59
|
+
//# sourceMappingURL=deepseek.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek.js","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","ChatDeepSeekTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/deepseek.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts a DeepSeek AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from DeepSeek's API format\n * and converts it to the standardized v1 content block format. It handles\n * both string content and the reasoning_content in additional_kwargs.\n *\n * @param message - The AI message containing DeepSeek-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning_content: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromDeepSeekMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromDeepSeekMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Extract reasoning from additional_kwargs.reasoning_content\n const reasoningContent = message.additional_kwargs?.reasoning_content;\n if (_isString(reasoningContent) && reasoningContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: reasoningContent,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n if (message.content.length > 0) {\n blocks.push({\n type: \"text\",\n text: message.content,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n blocks.push({\n type: \"text\",\n text: block.text,\n });\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatDeepSeekTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromDeepSeekMessage,\n translateContentChunk: convertToV1FromDeepSeekMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,+BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,mBAAmB,QAAQ,mBAAmB;AACpD,KAAI,UAAU,iBAAiB,IAAI,iBAAiB,SAAS,GAC3D,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAC7B;MAAI,QAAQ,QAAQ,SAAS,GAC3B,OAAO,KAAK;GACV,MAAM;GACN,MAAM,QAAQ;EACf,EAAC;CACH,MAED,MAAK,MAAM,SAAS,QAAQ,QAC1B,KACE,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,UACf,UAAU,SACV,UAAU,MAAM,KAAK,EAErB,OAAO,KAAK;EACV,MAAM;EACN,MAAM,MAAM;CACb,EAAC;AAMR,MAAK,MAAM,YAAY,QAAQ,cAAc,CAAE,GAC7C,OAAO,KAAK;EACV,MAAM;EACN,IAAI,SAAS;EACb,MAAM,SAAS;EACf,MAAM,SAAS;CAChB,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,yBAAyD;CACpE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -14,6 +14,13 @@ function convertToV1FromChatGoogleMessage(message) {
|
|
|
14
14
|
text: block.text
|
|
15
15
|
};
|
|
16
16
|
continue;
|
|
17
|
+
} else if (require_utils._isContentBlock(block, "thinking") && require_utils._isString(block.thinking)) {
|
|
18
|
+
yield {
|
|
19
|
+
type: "reasoning",
|
|
20
|
+
reasoning: block.thinking,
|
|
21
|
+
...block.signature ? { signature: block.signature } : {}
|
|
22
|
+
};
|
|
23
|
+
continue;
|
|
17
24
|
} else if (require_utils._isContentBlock(block, "inlineData") && require_utils._isObject(block.inlineData) && require_utils._isString(block.inlineData.mimeType) && require_utils._isString(block.inlineData.data)) {
|
|
18
25
|
yield {
|
|
19
26
|
type: "file",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google_genai.cjs","names":["message: AIMessage","_isContentBlock","_isString","_isObject","ChatGoogleGenAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_genai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `libs/providers/langchain-google-genai/src/utils/common.ts:mapGenerateContentResultToChatResult\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n yield {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n continue;\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n yield {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n continue;\n } else if (_isContentBlock(block, \"functionResponse\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n yield {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n continue;\n } else if (_isContentBlock(block, \"executableCode\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleGenAITranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QAAQ,YAAY,WACvB,CAAC;GAAE,MAAM;GAAQ,MAAM,QAAQ;EAAS,CAAC,IACzC,QAAQ;AACd,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAIC,8BAAgB,OAAO,OAAO,IAAIC,wBAAU,MAAM,KAAK,EAAE;IAC3D,MAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;IAAM;AACxC;GACD,WACCD,8BAAgB,OAAO,aAAa,IACpCE,wBAAU,MAAM,WAAW,IAC3BD,wBAAU,MAAM,WAAW,SAAS,IACpCA,wBAAU,MAAM,WAAW,KAAK,EAChC;IACA,MAAM;KACJ,MAAM;KACN,UAAU,MAAM,WAAW;KAC3B,MAAM,MAAM,WAAW;IACxB;AACD;GACD,WACCD,8BAAgB,OAAO,eAAe,IACtCE,wBAAU,MAAM,aAAa,IAC7BD,wBAAU,MAAM,aAAa,KAAK,IAClCC,wBAAU,MAAM,aAAa,KAAK,EAClC;IACA,MAAM;KACJ,MAAM;KACN,IAAI,QAAQ;KACZ,MAAM,MAAM,aAAa;KACzB,MAAM,MAAM,aAAa;IAC1B;AACD;GACD,WAAUF,8BAAgB,OAAO,mBAAmB,EAAE;IACrD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD,WACCA,8BAAgB,OAAO,WAAW,IAClCE,wBAAU,MAAM,SAAS,IACzBD,wBAAU,MAAM,SAAS,SAAS,IAClCA,wBAAU,MAAM,SAAS,QAAQ,EACjC;IACA,MAAM;KACJ,MAAM;KACN,UAAU,MAAM,SAAS;KACzB,QAAQ,MAAM,SAAS;IACxB;AACD;GACD,WAAUD,8BAAgB,OAAO,iBAAiB,EAAE;IACnD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD,WAAUA,8BAAgB,OAAO,sBAAsB,EAAE;IACxD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaG,4BAA4D;CACvE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
1
|
+
{"version":3,"file":"google_genai.cjs","names":["message: AIMessage","_isContentBlock","_isString","_isObject","ChatGoogleGenAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_genai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `libs/providers/langchain-google-genai/src/utils/common.ts:mapGenerateContentResultToChatResult\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n // Handle Google's thinking blocks (converted from Gemini's thought property)\n yield {\n type: \"reasoning\",\n reasoning: block.thinking,\n ...(block.signature ? { signature: block.signature } : {}),\n };\n continue;\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n yield {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n continue;\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n yield {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n continue;\n } else if (_isContentBlock(block, \"functionResponse\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n yield {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n continue;\n } else if (_isContentBlock(block, \"executableCode\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleGenAITranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QAAQ,YAAY,WACvB,CAAC;GAAE,MAAM;GAAQ,MAAM,QAAQ;EAAS,CAAC,IACzC,QAAQ;AACd,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAIC,8BAAgB,OAAO,OAAO,IAAIC,wBAAU,MAAM,KAAK,EAAE;IAC3D,MAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;IAAM;AACxC;GACD,WACCD,8BAAgB,OAAO,WAAW,IAClCC,wBAAU,MAAM,SAAS,EACzB;IAEA,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;KACjB,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAW,IAAG,CAAE;IAC1D;AACD;GACD,WACCD,8BAAgB,OAAO,aAAa,IACpCE,wBAAU,MAAM,WAAW,IAC3BD,wBAAU,MAAM,WAAW,SAAS,IACpCA,wBAAU,MAAM,WAAW,KAAK,EAChC;IACA,MAAM;KACJ,MAAM;KACN,UAAU,MAAM,WAAW;KAC3B,MAAM,MAAM,WAAW;IACxB;AACD;GACD,WACCD,8BAAgB,OAAO,eAAe,IACtCE,wBAAU,MAAM,aAAa,IAC7BD,wBAAU,MAAM,aAAa,KAAK,IAClCC,wBAAU,MAAM,aAAa,KAAK,EAClC;IACA,MAAM;KACJ,MAAM;KACN,IAAI,QAAQ;KACZ,MAAM,MAAM,aAAa;KACzB,MAAM,MAAM,aAAa;IAC1B;AACD;GACD,WAAUF,8BAAgB,OAAO,mBAAmB,EAAE;IACrD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD,WACCA,8BAAgB,OAAO,WAAW,IAClCE,wBAAU,MAAM,SAAS,IACzBD,wBAAU,MAAM,SAAS,SAAS,IAClCA,wBAAU,MAAM,SAAS,QAAQ,EACjC;IACA,MAAM;KACJ,MAAM;KACN,UAAU,MAAM,SAAS;KACzB,QAAQ,MAAM,SAAS;IACxB;AACD;GACD,WAAUD,8BAAgB,OAAO,iBAAiB,EAAE;IACnD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD,WAAUA,8BAAgB,OAAO,sBAAsB,EAAE;IACxD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaG,4BAA4D;CACvE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -14,6 +14,13 @@ function convertToV1FromChatGoogleMessage(message) {
|
|
|
14
14
|
text: block.text
|
|
15
15
|
};
|
|
16
16
|
continue;
|
|
17
|
+
} else if (_isContentBlock(block, "thinking") && _isString(block.thinking)) {
|
|
18
|
+
yield {
|
|
19
|
+
type: "reasoning",
|
|
20
|
+
reasoning: block.thinking,
|
|
21
|
+
...block.signature ? { signature: block.signature } : {}
|
|
22
|
+
};
|
|
23
|
+
continue;
|
|
17
24
|
} else if (_isContentBlock(block, "inlineData") && _isObject(block.inlineData) && _isString(block.inlineData.mimeType) && _isString(block.inlineData.data)) {
|
|
18
25
|
yield {
|
|
19
26
|
type: "file",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google_genai.js","names":["message: AIMessage","ChatGoogleGenAITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_genai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `libs/providers/langchain-google-genai/src/utils/common.ts:mapGenerateContentResultToChatResult\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n yield {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n continue;\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n yield {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n continue;\n } else if (_isContentBlock(block, \"functionResponse\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n yield {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n continue;\n } else if (_isContentBlock(block, \"executableCode\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleGenAITranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QAAQ,YAAY,WACvB,CAAC;GAAE,MAAM;GAAQ,MAAM,QAAQ;EAAS,CAAC,IACzC,QAAQ;AACd,OAAK,MAAM,SAAS,SAAS;AAC3B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ITranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_genai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isContentBlock, _isObject, _isString } from \"./utils.js\";\n\nfunction convertToV1FromChatGoogleMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `libs/providers/langchain-google-genai/src/utils/common.ts:mapGenerateContentResultToChatResult\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n // Handle Google's thinking blocks (converted from Gemini's thought property)\n yield {\n type: \"reasoning\",\n reasoning: block.thinking,\n ...(block.signature ? { signature: block.signature } : {}),\n };\n continue;\n } else if (\n _isContentBlock(block, \"inlineData\") &&\n _isObject(block.inlineData) &&\n _isString(block.inlineData.mimeType) &&\n _isString(block.inlineData.data)\n ) {\n yield {\n type: \"file\",\n mimeType: block.inlineData.mimeType,\n data: block.inlineData.data,\n };\n continue;\n } else if (\n _isContentBlock(block, \"functionCall\") &&\n _isObject(block.functionCall) &&\n _isString(block.functionCall.name) &&\n _isObject(block.functionCall.args)\n ) {\n yield {\n type: \"tool_call\",\n id: message.id,\n name: block.functionCall.name,\n args: block.functionCall.args,\n };\n continue;\n } else if (_isContentBlock(block, \"functionResponse\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (\n _isContentBlock(block, \"fileData\") &&\n _isObject(block.fileData) &&\n _isString(block.fileData.mimeType) &&\n _isString(block.fileData.fileUri)\n ) {\n yield {\n type: \"file\",\n mimeType: block.fileData.mimeType,\n fileId: block.fileData.fileUri,\n };\n continue;\n } else if (_isContentBlock(block, \"executableCode\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n } else if (_isContentBlock(block, \"codeExecutionResult\")) {\n yield { type: \"non_standard\", value: block };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatGoogleGenAITranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatGoogleMessage,\n translateContentChunk: convertToV1FromChatGoogleMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QAAQ,YAAY,WACvB,CAAC;GAAE,MAAM;GAAQ,MAAM,QAAQ;EAAS,CAAC,IACzC,QAAQ;AACd,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAI,gBAAgB,OAAO,OAAO,IAAI,UAAU,MAAM,KAAK,EAAE;IAC3D,MAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;IAAM;AACxC;GACD,WACC,gBAAgB,OAAO,WAAW,IAClC,UAAU,MAAM,SAAS,EACzB;IAEA,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;KACjB,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAW,IAAG,CAAE;IAC1D;AACD;GACD,WACC,gBAAgB,OAAO,aAAa,IACpC,UAAU,MAAM,WAAW,IAC3B,UAAU,MAAM,WAAW,SAAS,IACpC,UAAU,MAAM,WAAW,KAAK,EAChC;IACA,MAAM;KACJ,MAAM;KACN,UAAU,MAAM,WAAW;KAC3B,MAAM,MAAM,WAAW;IACxB;AACD;GACD,WACC,gBAAgB,OAAO,eAAe,IACtC,UAAU,MAAM,aAAa,IAC7B,UAAU,MAAM,aAAa,KAAK,IAClC,UAAU,MAAM,aAAa,KAAK,EAClC;IACA,MAAM;KACJ,MAAM;KACN,IAAI,QAAQ;KACZ,MAAM,MAAM,aAAa;KACzB,MAAM,MAAM,aAAa;IAC1B;AACD;GACD,WAAU,gBAAgB,OAAO,mBAAmB,EAAE;IACrD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD,WACC,gBAAgB,OAAO,WAAW,IAClC,UAAU,MAAM,SAAS,IACzB,UAAU,MAAM,SAAS,SAAS,IAClC,UAAU,MAAM,SAAS,QAAQ,EACjC;IACA,MAAM;KACJ,MAAM;KACN,UAAU,MAAM,SAAS;KACzB,QAAQ,MAAM,SAAS;IACxB;AACD;GACD,WAAU,gBAAgB,OAAO,iBAAiB,EAAE;IACnD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD,WAAU,gBAAgB,OAAO,sBAAsB,EAAE;IACxD,MAAM;KAAE,MAAM;KAAgB,OAAO;IAAO;AAC5C;GACD;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,4BAA4D;CACvE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -24,6 +24,13 @@ function convertToV1FromChatVertexMessage(message) {
|
|
|
24
24
|
reasoning: block.reasoning
|
|
25
25
|
};
|
|
26
26
|
continue;
|
|
27
|
+
} else if (require_utils._isContentBlock(block, "thinking") && require_utils._isString(block.thinking)) {
|
|
28
|
+
yield {
|
|
29
|
+
type: "reasoning",
|
|
30
|
+
reasoning: block.thinking,
|
|
31
|
+
...block.signature ? { signature: block.signature } : {}
|
|
32
|
+
};
|
|
33
|
+
continue;
|
|
27
34
|
} else if (require_utils._isContentBlock(block, "text") && require_utils._isString(block.text)) {
|
|
28
35
|
yield {
|
|
29
36
|
type: "text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google_vertexai.cjs","names":["message: AIMessage","_isContentBlock","_isString","iife","_isArray","ChatVertexTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_vertexai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isArray, _isContentBlock, _isString, iife } from \"./utils.js\";\n\nfunction convertToV1FromChatVertexMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-google-common/src/utils/gemini.ts:partsToMessageContent`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"reasoning\") && _isString(block.reasoning)) {\n const signature = iife(() => {\n const reasoningIndex = content.indexOf(block);\n if (\n _isArray(message.additional_kwargs?.signatures) &&\n reasoningIndex >= 0\n ) {\n return message.additional_kwargs.signatures.at(reasoningIndex);\n }\n return undefined;\n });\n if (_isString(signature)) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n signature,\n };\n } else {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n };\n }\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"image_url\")) {\n if (_isString(block.image_url)) {\n if (block.image_url.startsWith(\"data:\")) {\n const dataUrlRegex = /^data:([^;]+);base64,(.+)$/;\n const match = block.image_url.match(dataUrlRegex);\n if (match) {\n yield { type: \"image\", data: match[2], mimeType: match[1] };\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n }\n continue;\n } else if (\n _isContentBlock(block, \"media\") &&\n _isString(block.mimeType) &&\n _isString(block.data)\n ) {\n yield { type: \"file\", mimeType: block.mimeType, data: block.data };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatVertexTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatVertexMessage,\n translateContentChunk: convertToV1FromChatVertexMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QA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M,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaG,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
1
|
+
{"version":3,"file":"google_vertexai.cjs","names":["message: AIMessage","_isContentBlock","_isString","iife","_isArray","ChatVertexTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_vertexai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isArray, _isContentBlock, _isString, iife } from \"./utils.js\";\n\nfunction convertToV1FromChatVertexMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-google-common/src/utils/gemini.ts:partsToMessageContent`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"reasoning\") && _isString(block.reasoning)) {\n const signature = iife(() => {\n const reasoningIndex = content.indexOf(block);\n if (\n _isArray(message.additional_kwargs?.signatures) &&\n reasoningIndex >= 0\n ) {\n return message.additional_kwargs.signatures.at(reasoningIndex);\n }\n return undefined;\n });\n if (_isString(signature)) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n signature,\n };\n } else {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n };\n }\n continue;\n } else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n // Handle thinking blocks (Anthropic-style format used in some Google models)\n yield {\n type: \"reasoning\",\n reasoning: block.thinking,\n ...(block.signature ? { signature: block.signature } : {}),\n };\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"image_url\")) {\n if (_isString(block.image_url)) {\n if (block.image_url.startsWith(\"data:\")) {\n const dataUrlRegex = /^data:([^;]+);base64,(.+)$/;\n const match = block.image_url.match(dataUrlRegex);\n if (match) {\n yield { type: \"image\", data: match[2], mimeType: match[1] };\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n }\n continue;\n } else if (\n _isContentBlock(block, \"media\") &&\n _isString(block.mimeType) &&\n _isString(block.data)\n ) {\n yield { type: \"file\", mimeType: block.mimeType, data: block.data };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatVertexTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatVertexMessage,\n translateContentChunk: convertToV1FromChatVertexMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QAAQ,YAAY,WACvB,CAAC;GAAE,MAAM;GAAQ,MAAM,QAAQ;EAAS,CAAC,IACzC,QAAQ;AACd,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAIC,8BAAgB,OAAO,YAAY,IAAIC,wBAAU,MAAM,UAAU,EAAE;IACrE,MAAM,YAAYC,mBAAK,MAAM;KAC3B,MAAM,iBAAiB,QAAQ,QAAQ,MAAM;AAC7C,SACEC,uBAAS,QAAQ,mBAAmB,WAAW,IAC/C,kBAAkB,EAElB,QAAO,QAAQ,kBAAkB,WAAW,GAAG,eAAe;AAEhE,YAAO;IACR,EAAC;AACF,QAAIF,wBAAU,UAAU,EACtB,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;KACjB;IACD;SAED,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;IAClB;AAEH;GACD,WACCD,8BAAgB,OAAO,WAAW,IAClCC,wBAAU,MAAM,SAAS,EACzB;IAEA,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;KACjB,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAW,IAAG,CAAE;IAC1D;AACD;GACD,WAAUD,8BAAgB,OAAO,OAAO,IAAIC,wBAAU,MAAM,KAAK,EAAE;IAClE,MAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;IAAM;AACxC;GACD,WAAUD,8BAAgB,OAAO,YAAY,EAAE;AAC9C,QAAIC,wBAAU,MAAM,UAAU,CAC5B,KAAI,MAAM,UAAU,WAAW,QAAQ,EAAE;KACvC,MAAM,eAAe;KACrB,MAAM,QAAQ,MAAM,UAAU,MAAM,aAAa;AACjD,SAAI,OACF,MAAM;MAAE,MAAM;MAAS,MAAM,MAAM;MAAI,UAAU,MAAM;KAAI;UAE3D,MAAM;MAAE,MAAM;MAAS,KAAK,MAAM;KAAW;IAEhD,OACC,MAAM;KAAE,MAAM;KAAS,KAAK,MAAM;IAAW;AAGjD;GACD,WACCD,8BAAgB,OAAO,QAAQ,IAC/BC,wBAAU,MAAM,SAAS,IACzBA,wBAAU,MAAM,KAAK,EACrB;IACA,MAAM;KAAE,MAAM;KAAQ,UAAU,MAAM;KAAU,MAAM,MAAM;IAAM;AAClE;GACD;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaG,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -24,6 +24,13 @@ function convertToV1FromChatVertexMessage(message) {
|
|
|
24
24
|
reasoning: block.reasoning
|
|
25
25
|
};
|
|
26
26
|
continue;
|
|
27
|
+
} else if (_isContentBlock(block, "thinking") && _isString(block.thinking)) {
|
|
28
|
+
yield {
|
|
29
|
+
type: "reasoning",
|
|
30
|
+
reasoning: block.thinking,
|
|
31
|
+
...block.signature ? { signature: block.signature } : {}
|
|
32
|
+
};
|
|
33
|
+
continue;
|
|
27
34
|
} else if (_isContentBlock(block, "text") && _isString(block.text)) {
|
|
28
35
|
yield {
|
|
29
36
|
type: "text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google_vertexai.js","names":["message: AIMessage","ChatVertexTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_vertexai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isArray, _isContentBlock, _isString, iife } from \"./utils.js\";\n\nfunction convertToV1FromChatVertexMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-google-common/src/utils/gemini.ts:partsToMessageContent`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"reasoning\") && _isString(block.reasoning)) {\n const signature = iife(() => {\n const reasoningIndex = content.indexOf(block);\n if (\n _isArray(message.additional_kwargs?.signatures) &&\n reasoningIndex >= 0\n ) {\n return message.additional_kwargs.signatures.at(reasoningIndex);\n }\n return undefined;\n });\n if (_isString(signature)) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n signature,\n };\n } else {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n };\n }\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"image_url\")) {\n if (_isString(block.image_url)) {\n if (block.image_url.startsWith(\"data:\")) {\n const dataUrlRegex = /^data:([^;]+);base64,(.+)$/;\n const match = block.image_url.match(dataUrlRegex);\n if (match) {\n yield { type: \"image\", data: match[2], mimeType: match[1] };\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n }\n continue;\n } else if (\n _isContentBlock(block, \"media\") &&\n _isString(block.mimeType) &&\n _isString(block.data)\n ) {\n yield { type: \"file\", mimeType: block.mimeType, data: block.data };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatVertexTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChat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MAAM;KAAU,MAAM,MAAM;IAAM;AAClE;GACD;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
1
|
+
{"version":3,"file":"google_vertexai.js","names":["message: AIMessage","ChatVertexTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/google_vertexai.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isArray, _isContentBlock, _isString, iife } from \"./utils.js\";\n\nfunction convertToV1FromChatVertexMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n // see `/libs/providers/langchain-google-common/src/utils/gemini.ts:partsToMessageContent`\n function* iterateContent(): Iterable<ContentBlock.Standard> {\n const content =\n typeof message.content === \"string\"\n ? [{ type: \"text\", text: message.content }]\n : message.content;\n for (const block of content) {\n if (_isContentBlock(block, \"reasoning\") && _isString(block.reasoning)) {\n const signature = iife(() => {\n const reasoningIndex = content.indexOf(block);\n if (\n _isArray(message.additional_kwargs?.signatures) &&\n reasoningIndex >= 0\n ) {\n return message.additional_kwargs.signatures.at(reasoningIndex);\n }\n return undefined;\n });\n if (_isString(signature)) {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n signature,\n };\n } else {\n yield {\n type: \"reasoning\",\n reasoning: block.reasoning,\n };\n }\n continue;\n } else if (\n _isContentBlock(block, \"thinking\") &&\n _isString(block.thinking)\n ) {\n // Handle thinking blocks (Anthropic-style format used in some Google models)\n yield {\n type: \"reasoning\",\n reasoning: block.thinking,\n ...(block.signature ? { signature: block.signature } : {}),\n };\n continue;\n } else if (_isContentBlock(block, \"text\") && _isString(block.text)) {\n yield { type: \"text\", text: block.text };\n continue;\n } else if (_isContentBlock(block, \"image_url\")) {\n if (_isString(block.image_url)) {\n if (block.image_url.startsWith(\"data:\")) {\n const dataUrlRegex = /^data:([^;]+);base64,(.+)$/;\n const match = block.image_url.match(dataUrlRegex);\n if (match) {\n yield { type: \"image\", data: match[2], mimeType: match[1] };\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n } else {\n yield { type: \"image\", url: block.image_url };\n }\n }\n continue;\n } else if (\n _isContentBlock(block, \"media\") &&\n _isString(block.mimeType) &&\n _isString(block.data)\n ) {\n yield { type: \"file\", mimeType: block.mimeType, data: block.data };\n continue;\n }\n yield { type: \"non_standard\", value: block };\n }\n }\n return Array.from(iterateContent());\n}\n\nexport const ChatVertexTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromChatVertexMessage,\n translateContentChunk: convertToV1FromChatVertexMessage,\n};\n"],"mappings":";;;AAKA,SAAS,iCACPA,SAC8B;CAE9B,UAAU,iBAAkD;EAC1D,MAAM,UACJ,OAAO,QAAQ,YAAY,WACvB,CAAC;GAAE,MAAM;GAAQ,MAAM,QAAQ;EAAS,CAAC,IACzC,QAAQ;AACd,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAI,gBAAgB,OAAO,YAAY,IAAI,UAAU,MAAM,UAAU,EAAE;IACrE,MAAM,YAAY,KAAK,MAAM;KAC3B,MAAM,iBAAiB,QAAQ,QAAQ,MAAM;AAC7C,SACE,SAAS,QAAQ,mBAAmB,WAAW,IAC/C,kBAAkB,EAElB,QAAO,QAAQ,kBAAkB,WAAW,GAAG,eAAe;AAEhE,YAAO;IACR,EAAC;AACF,QAAI,UAAU,UAAU,EACtB,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;KACjB;IACD;SAED,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;IAClB;AAEH;GACD,WACC,gBAAgB,OAAO,WAAW,IAClC,UAAU,MAAM,SAAS,EACzB;IAEA,MAAM;KACJ,MAAM;KACN,WAAW,MAAM;KACjB,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAW,IAAG,CAAE;IAC1D;AACD;GACD,WAAU,gBAAgB,OAAO,OAAO,IAAI,UAAU,MAAM,KAAK,EAAE;IAClE,MAAM;KAAE,MAAM;KAAQ,MAAM,MAAM;IAAM;AACxC;GACD,WAAU,gBAAgB,OAAO,YAAY,EAAE;AAC9C,QAAI,UAAU,MAAM,UAAU,CAC5B,KAAI,MAAM,UAAU,WAAW,QAAQ,EAAE;KACvC,MAAM,eAAe;KACrB,MAAM,QAAQ,MAAM,UAAU,MAAM,aAAa;AACjD,SAAI,OACF,MAAM;MAAE,MAAM;MAAS,MAAM,MAAM;MAAI,UAAU,MAAM;KAAI;UAE3D,MAAM;MAAE,MAAM;MAAS,KAAK,MAAM;KAAW;IAEhD,OACC,MAAM;KAAE,MAAM;KAAS,KAAK,MAAM;IAAW;AAGjD;GACD,WACC,gBAAgB,OAAO,QAAQ,IAC/B,UAAU,MAAM,SAAS,IACzB,UAAU,MAAM,KAAK,EACrB;IACA,MAAM;KAAE,MAAM;KAAQ,UAAU,MAAM;KAAU,MAAM,MAAM;IAAM;AAClE;GACD;GACD,MAAM;IAAE,MAAM;IAAgB,OAAO;GAAO;EAC7C;CACF;AACD,QAAO,MAAM,KAAK,gBAAgB,CAAC;AACpC;AAED,MAAaC,uBAAuD;CAClE,kBAAkB;CAClB,uBAAuB;AACxB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const require_utils = require('./utils.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/messages/block_translators/groq.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Groq AI message to an array of v1 standard content blocks.
|
|
6
|
+
*
|
|
7
|
+
* This function processes an AI message from Groq's API format
|
|
8
|
+
* and converts it to the standardized v1 content block format. It handles
|
|
9
|
+
* both parsed reasoning (in additional_kwargs.reasoning) and raw reasoning
|
|
10
|
+
* (in <think> tags within content).
|
|
11
|
+
*
|
|
12
|
+
* @param message - The AI message containing Groq-formatted content
|
|
13
|
+
* @returns Array of content blocks in v1 standard format
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Parsed format (reasoning_format="parsed")
|
|
18
|
+
* const message = new AIMessage({
|
|
19
|
+
* content: "The answer is 42",
|
|
20
|
+
* additional_kwargs: { reasoning: "Let me think about this..." }
|
|
21
|
+
* });
|
|
22
|
+
* const standardBlocks = convertToV1FromGroqMessage(message);
|
|
23
|
+
* // Returns:
|
|
24
|
+
* // [
|
|
25
|
+
* // { type: "reasoning", reasoning: "Let me think about this..." },
|
|
26
|
+
* // { type: "text", text: "The answer is 42" }
|
|
27
|
+
* // ]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Raw format (reasoning_format="raw")
|
|
33
|
+
* const message = new AIMessage({
|
|
34
|
+
* content: "<think>Let me think...</think>The answer is 42"
|
|
35
|
+
* });
|
|
36
|
+
* const standardBlocks = convertToV1FromGroqMessage(message);
|
|
37
|
+
* // Returns:
|
|
38
|
+
* // [
|
|
39
|
+
* // { type: "reasoning", reasoning: "Let me think..." },
|
|
40
|
+
* // { type: "text", text: "The answer is 42" }
|
|
41
|
+
* // ]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function convertToV1FromGroqMessage(message) {
|
|
45
|
+
const blocks = [];
|
|
46
|
+
const parsedReasoning = message.additional_kwargs?.reasoning;
|
|
47
|
+
if (require_utils._isString(parsedReasoning) && parsedReasoning.length > 0) blocks.push({
|
|
48
|
+
type: "reasoning",
|
|
49
|
+
reasoning: parsedReasoning
|
|
50
|
+
});
|
|
51
|
+
if (typeof message.content === "string") {
|
|
52
|
+
let textContent = message.content;
|
|
53
|
+
const thinkMatch = textContent.match(/<think>([\s\S]*?)<\/think>/);
|
|
54
|
+
if (thinkMatch) {
|
|
55
|
+
const thinkingContent = thinkMatch[1].trim();
|
|
56
|
+
if (thinkingContent.length > 0) blocks.push({
|
|
57
|
+
type: "reasoning",
|
|
58
|
+
reasoning: thinkingContent
|
|
59
|
+
});
|
|
60
|
+
textContent = textContent.replace(/<think>[\s\S]*?<\/think>/, "").trim();
|
|
61
|
+
}
|
|
62
|
+
if (textContent.length > 0) blocks.push({
|
|
63
|
+
type: "text",
|
|
64
|
+
text: textContent
|
|
65
|
+
});
|
|
66
|
+
} else for (const block of message.content) if (typeof block === "object" && "type" in block && block.type === "text" && "text" in block && require_utils._isString(block.text)) {
|
|
67
|
+
let textContent = block.text;
|
|
68
|
+
const thinkMatch = textContent.match(/<think>([\s\S]*?)<\/think>/);
|
|
69
|
+
if (thinkMatch) {
|
|
70
|
+
const thinkingContent = thinkMatch[1].trim();
|
|
71
|
+
if (thinkingContent.length > 0) blocks.push({
|
|
72
|
+
type: "reasoning",
|
|
73
|
+
reasoning: thinkingContent
|
|
74
|
+
});
|
|
75
|
+
textContent = textContent.replace(/<think>[\s\S]*?<\/think>/, "").trim();
|
|
76
|
+
}
|
|
77
|
+
if (textContent.length > 0) blocks.push({
|
|
78
|
+
type: "text",
|
|
79
|
+
text: textContent
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
for (const toolCall of message.tool_calls ?? []) blocks.push({
|
|
83
|
+
type: "tool_call",
|
|
84
|
+
id: toolCall.id,
|
|
85
|
+
name: toolCall.name,
|
|
86
|
+
args: toolCall.args
|
|
87
|
+
});
|
|
88
|
+
return blocks;
|
|
89
|
+
}
|
|
90
|
+
const ChatGroqTranslator = {
|
|
91
|
+
translateContent: convertToV1FromGroqMessage,
|
|
92
|
+
translateContentChunk: convertToV1FromGroqMessage
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
exports.ChatGroqTranslator = ChatGroqTranslator;
|
|
97
|
+
//# sourceMappingURL=groq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groq.cjs","names":["message: AIMessage","blocks: Array<ContentBlock.Standard>","_isString","ChatGroqTranslator: StandardContentBlockTranslator"],"sources":["../../../src/messages/block_translators/groq.ts"],"sourcesContent":["import { AIMessage } from \"../ai.js\";\nimport { ContentBlock } from \"../content/index.js\";\nimport type { StandardContentBlockTranslator } from \"./index.js\";\nimport { _isString } from \"./utils.js\";\n\n/**\n * Converts a Groq AI message to an array of v1 standard content blocks.\n *\n * This function processes an AI message from Groq's API format\n * and converts it to the standardized v1 content block format. It handles\n * both parsed reasoning (in additional_kwargs.reasoning) and raw reasoning\n * (in <think> tags within content).\n *\n * @param message - The AI message containing Groq-formatted content\n * @returns Array of content blocks in v1 standard format\n *\n * @example\n * ```typescript\n * // Parsed format (reasoning_format=\"parsed\")\n * const message = new AIMessage({\n * content: \"The answer is 42\",\n * additional_kwargs: { reasoning: \"Let me think about this...\" }\n * });\n * const standardBlocks = convertToV1FromGroqMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n *\n * @example\n * ```typescript\n * // Raw format (reasoning_format=\"raw\")\n * const message = new AIMessage({\n * content: \"<think>Let me think...</think>The answer is 42\"\n * });\n * const standardBlocks = convertToV1FromGroqMessage(message);\n * // Returns:\n * // [\n * // { type: \"reasoning\", reasoning: \"Let me think...\" },\n * // { type: \"text\", text: \"The answer is 42\" }\n * // ]\n * ```\n */\nexport function convertToV1FromGroqMessage(\n message: AIMessage\n): Array<ContentBlock.Standard> {\n const blocks: Array<ContentBlock.Standard> = [];\n\n // Check for parsed reasoning format in additional_kwargs.reasoning\n const parsedReasoning = message.additional_kwargs?.reasoning;\n if (_isString(parsedReasoning) && parsedReasoning.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: parsedReasoning,\n });\n }\n\n // Handle text content\n if (typeof message.content === \"string\") {\n let textContent = message.content;\n\n // Check for raw reasoning format with <think> tags\n const thinkMatch = textContent.match(/<think>([\\s\\S]*?)<\\/think>/);\n if (thinkMatch) {\n const thinkingContent = thinkMatch[1].trim();\n if (thinkingContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: thinkingContent,\n });\n }\n // Remove the think tags from the text content\n textContent = textContent.replace(/<think>[\\s\\S]*?<\\/think>/, \"\").trim();\n }\n\n if (textContent.length > 0) {\n blocks.push({\n type: \"text\",\n text: textContent,\n });\n }\n } else {\n for (const block of message.content) {\n if (\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n _isString(block.text)\n ) {\n let textContent = block.text;\n\n // Check for raw reasoning format with <think> tags\n const thinkMatch = textContent.match(/<think>([\\s\\S]*?)<\\/think>/);\n if (thinkMatch) {\n const thinkingContent = thinkMatch[1].trim();\n if (thinkingContent.length > 0) {\n blocks.push({\n type: \"reasoning\",\n reasoning: thinkingContent,\n });\n }\n textContent = textContent\n .replace(/<think>[\\s\\S]*?<\\/think>/, \"\")\n .trim();\n }\n\n if (textContent.length > 0) {\n blocks.push({\n type: \"text\",\n text: textContent,\n });\n }\n }\n }\n }\n\n // Add tool calls if present\n for (const toolCall of message.tool_calls ?? []) {\n blocks.push({\n type: \"tool_call\",\n id: toolCall.id,\n name: toolCall.name,\n args: toolCall.args,\n });\n }\n\n return blocks;\n}\n\nexport const ChatGroqTranslator: StandardContentBlockTranslator = {\n translateContent: convertToV1FromGroqMessage,\n translateContentChunk: convertToV1FromGroqMessage,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,2BACdA,SAC8B;CAC9B,MAAMC,SAAuC,CAAE;CAG/C,MAAM,kBAAkB,QAAQ,mBAAmB;AACnD,KAAIC,wBAAU,gBAAgB,IAAI,gBAAgB,SAAS,GACzD,OAAO,KAAK;EACV,MAAM;EACN,WAAW;CACZ,EAAC;AAIJ,KAAI,OAAO,QAAQ,YAAY,UAAU;EACvC,IAAI,cAAc,QAAQ;EAG1B,MAAM,aAAa,YAAY,MAAM,6BAA6B;AAClE,MAAI,YAAY;GACd,MAAM,kBAAkB,WAAW,GAAG,MA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