@langchain/core 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/agents.d.cts +0 -2
  3. package/dist/agents.d.ts +0 -2
  4. package/dist/callbacks/base.d.cts +22 -60
  5. package/dist/callbacks/base.d.ts +22 -60
  6. package/dist/callbacks/dispatch/index.d.cts +1 -3
  7. package/dist/callbacks/dispatch/index.d.ts +1 -3
  8. package/dist/callbacks/dispatch/web.d.cts +1 -3
  9. package/dist/callbacks/dispatch/web.d.ts +1 -3
  10. package/dist/callbacks/manager.d.cts +2 -12
  11. package/dist/callbacks/manager.d.ts +2 -12
  12. package/dist/chat_history.cjs +1 -1
  13. package/dist/chat_history.d.cts +0 -1
  14. package/dist/chat_history.d.ts +0 -1
  15. package/dist/chat_history.js +1 -1
  16. package/dist/document_loaders/langsmith.d.cts +0 -3
  17. package/dist/document_loaders/langsmith.d.ts +0 -3
  18. package/dist/documents/document.d.cts +3 -12
  19. package/dist/documents/document.d.ts +3 -12
  20. package/dist/example_selectors/length_based.d.cts +1 -1
  21. package/dist/example_selectors/length_based.d.ts +1 -1
  22. package/dist/indexing/base.d.cts +0 -1
  23. package/dist/indexing/base.d.ts +0 -1
  24. package/dist/indexing/record_manager.d.cts +0 -1
  25. package/dist/indexing/record_manager.d.ts +0 -1
  26. package/dist/language_models/base.d.cts +8 -38
  27. package/dist/language_models/base.d.ts +8 -38
  28. package/dist/language_models/chat_models.cjs +1 -1
  29. package/dist/language_models/chat_models.d.cts +6 -33
  30. package/dist/language_models/chat_models.d.ts +6 -33
  31. package/dist/language_models/chat_models.js +1 -1
  32. package/dist/language_models/llms.d.cts +0 -6
  33. package/dist/language_models/llms.d.ts +0 -6
  34. package/dist/load/import_type.d.cts +0 -1
  35. package/dist/load/import_type.d.ts +0 -1
  36. package/dist/load/map_keys.cjs +4 -5
  37. package/dist/load/map_keys.cjs.map +1 -1
  38. package/dist/load/map_keys.d.cts +0 -1
  39. package/dist/load/map_keys.d.ts +0 -1
  40. package/dist/load/map_keys.js +3 -3
  41. package/dist/load/map_keys.js.map +1 -1
  42. package/dist/load/serializable.d.cts +0 -1
  43. package/dist/load/serializable.d.ts +0 -1
  44. package/dist/memory.d.cts +0 -3
  45. package/dist/memory.d.ts +0 -3
  46. package/dist/messages/ai.cjs +6 -48
  47. package/dist/messages/ai.cjs.map +1 -1
  48. package/dist/messages/ai.js +6 -48
  49. package/dist/messages/ai.js.map +1 -1
  50. package/dist/messages/base.cjs +3 -2
  51. package/dist/messages/base.cjs.map +1 -1
  52. package/dist/messages/base.d.cts +1 -13
  53. package/dist/messages/base.d.ts +1 -13
  54. package/dist/messages/base.js +3 -2
  55. package/dist/messages/base.js.map +1 -1
  56. package/dist/messages/content/data.d.cts +2 -7
  57. package/dist/messages/content/data.d.ts +2 -7
  58. package/dist/messages/content/index.d.cts +1 -4
  59. package/dist/messages/content/index.d.ts +1 -4
  60. package/dist/messages/content/multimodal.d.cts +0 -1
  61. package/dist/messages/content/multimodal.d.ts +0 -1
  62. package/dist/messages/content/tools.d.cts +0 -1
  63. package/dist/messages/content/tools.d.ts +0 -1
  64. package/dist/messages/index.cjs +4 -2
  65. package/dist/messages/index.d.cts +2 -2
  66. package/dist/messages/index.d.ts +2 -2
  67. package/dist/messages/index.js +5 -4
  68. package/dist/messages/tool.d.cts +2 -9
  69. package/dist/messages/tool.d.ts +2 -9
  70. package/dist/messages/transformers.cjs +2 -2
  71. package/dist/messages/transformers.d.cts +0 -3
  72. package/dist/messages/transformers.d.ts +0 -3
  73. package/dist/messages/transformers.js +2 -2
  74. package/dist/messages/utils.cjs +77 -4
  75. package/dist/messages/utils.cjs.map +1 -1
  76. package/dist/messages/utils.d.cts +35 -7
  77. package/dist/messages/utils.d.ts +35 -7
  78. package/dist/messages/utils.js +77 -5
  79. package/dist/messages/utils.js.map +1 -1
  80. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs +169 -0
  81. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs.map +1 -0
  82. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js +168 -0
  83. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js.map +1 -0
  84. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs +122 -0
  85. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs.map +1 -0
  86. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js +121 -0
  87. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js.map +1 -0
  88. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs +18 -0
  89. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs.map +1 -0
  90. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js +17 -0
  91. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js.map +1 -0
  92. package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs +27 -0
  93. package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs.map +1 -0
  94. package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js +26 -0
  95. package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js.map +1 -0
  96. package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs +141 -0
  97. package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs.map +1 -0
  98. package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js +141 -0
  99. package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js.map +1 -0
  100. package/dist/output_parsers/json.d.cts +1 -5
  101. package/dist/output_parsers/json.d.ts +1 -5
  102. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +2 -6
  103. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +2 -6
  104. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +10 -34
  105. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +10 -34
  106. package/dist/output_parsers/transform.d.cts +0 -1
  107. package/dist/output_parsers/transform.d.ts +0 -1
  108. package/dist/outputs.d.cts +0 -6
  109. package/dist/outputs.d.ts +0 -6
  110. package/dist/prompts/base.d.cts +2 -10
  111. package/dist/prompts/base.d.ts +2 -10
  112. package/dist/prompts/chat.cjs +2 -2
  113. package/dist/prompts/chat.d.cts +13 -51
  114. package/dist/prompts/chat.d.ts +13 -51
  115. package/dist/prompts/chat.js +2 -2
  116. package/dist/prompts/few_shot.d.cts +1 -5
  117. package/dist/prompts/few_shot.d.ts +1 -5
  118. package/dist/prompts/image.d.cts +2 -10
  119. package/dist/prompts/image.d.ts +2 -10
  120. package/dist/prompts/prompt.d.cts +4 -15
  121. package/dist/prompts/prompt.d.ts +4 -16
  122. package/dist/prompts/serde.d.cts +0 -1
  123. package/dist/prompts/serde.d.ts +0 -1
  124. package/dist/prompts/string.d.cts +1 -5
  125. package/dist/prompts/string.d.ts +1 -5
  126. package/dist/prompts/structured.d.cts +3 -16
  127. package/dist/prompts/structured.d.ts +3 -16
  128. package/dist/retrievers/document_compressors/index.d.cts +0 -1
  129. package/dist/retrievers/document_compressors/index.d.ts +0 -1
  130. package/dist/retrievers/index.d.cts +2 -6
  131. package/dist/retrievers/index.d.ts +2 -6
  132. package/dist/runnables/base.cjs +7 -7
  133. package/dist/runnables/base.cjs.map +1 -1
  134. package/dist/runnables/base.d.cts +12 -64
  135. package/dist/runnables/base.d.ts +12 -64
  136. package/dist/runnables/base.js +1 -1
  137. package/dist/runnables/branch.d.cts +0 -2
  138. package/dist/runnables/branch.d.ts +0 -2
  139. package/dist/runnables/config.d.cts +0 -1
  140. package/dist/runnables/config.d.ts +0 -1
  141. package/dist/runnables/graph.d.cts +1 -5
  142. package/dist/runnables/graph.d.ts +1 -5
  143. package/dist/runnables/graph_mermaid.cjs +2 -1
  144. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  145. package/dist/runnables/graph_mermaid.js +3 -1
  146. package/dist/runnables/graph_mermaid.js.map +1 -1
  147. package/dist/runnables/history.cjs +1 -1
  148. package/dist/runnables/history.d.cts +4 -12
  149. package/dist/runnables/history.d.ts +4 -12
  150. package/dist/runnables/history.js +1 -1
  151. package/dist/runnables/passthrough.d.cts +0 -2
  152. package/dist/runnables/passthrough.d.ts +0 -2
  153. package/dist/runnables/router.d.cts +0 -1
  154. package/dist/runnables/router.d.ts +0 -1
  155. package/dist/runnables/types.d.cts +2 -9
  156. package/dist/runnables/types.d.ts +2 -9
  157. package/dist/runnables/utils.cjs +5 -0
  158. package/dist/runnables/utils.cjs.map +1 -1
  159. package/dist/runnables/utils.js +5 -1
  160. package/dist/runnables/utils.js.map +1 -1
  161. package/dist/singletons/async_local_storage/context.d.cts +0 -2
  162. package/dist/singletons/async_local_storage/context.d.ts +0 -2
  163. package/dist/singletons/async_local_storage/globals.d.cts +0 -1
  164. package/dist/singletons/async_local_storage/globals.d.ts +0 -1
  165. package/dist/singletons/callbacks.cjs.map +1 -1
  166. package/dist/singletons/callbacks.js.map +1 -1
  167. package/dist/stores.d.cts +0 -1
  168. package/dist/stores.d.ts +0 -1
  169. package/dist/structured_query/utils.d.cts +1 -4
  170. package/dist/structured_query/utils.d.ts +1 -4
  171. package/dist/tools/index.d.cts +1 -6
  172. package/dist/tools/index.d.ts +1 -6
  173. package/dist/tools/types.d.cts +3 -13
  174. package/dist/tools/types.d.ts +3 -13
  175. package/dist/tracers/base.d.cts +1 -20
  176. package/dist/tracers/base.d.ts +1 -20
  177. package/dist/tracers/console.cjs +3 -3
  178. package/dist/tracers/console.cjs.map +1 -1
  179. package/dist/tracers/console.d.cts +0 -2
  180. package/dist/tracers/console.d.ts +0 -2
  181. package/dist/tracers/console.js +3 -3
  182. package/dist/tracers/console.js.map +1 -1
  183. package/dist/tracers/event_stream.d.cts +0 -4
  184. package/dist/tracers/event_stream.d.ts +0 -4
  185. package/dist/tracers/log_stream.d.cts +0 -6
  186. package/dist/tracers/log_stream.d.ts +0 -6
  187. package/dist/types/_internal.d.cts +0 -3
  188. package/dist/types/_internal.d.ts +0 -3
  189. package/dist/types/type-utils.d.cts +0 -2
  190. package/dist/types/type-utils.d.ts +0 -2
  191. package/dist/utils/async_caller.cjs +2 -7
  192. package/dist/utils/async_caller.cjs.map +1 -1
  193. package/dist/utils/async_caller.d.cts +0 -3
  194. package/dist/utils/async_caller.d.ts +0 -3
  195. package/dist/utils/async_caller.js +1 -6
  196. package/dist/utils/async_caller.js.map +1 -1
  197. package/dist/utils/env.d.cts +0 -4
  198. package/dist/utils/env.d.ts +0 -4
  199. package/dist/utils/event_source_parse.d.cts +1 -4
  200. package/dist/utils/event_source_parse.d.ts +1 -4
  201. package/dist/utils/function_calling.d.cts +1 -3
  202. package/dist/utils/function_calling.d.ts +1 -3
  203. package/dist/utils/json.d.cts +0 -1
  204. package/dist/utils/json.d.ts +0 -1
  205. package/dist/utils/stream.d.cts +1 -13
  206. package/dist/utils/stream.d.ts +1 -13
  207. package/dist/utils/testing/chat_models.d.cts +3 -11
  208. package/dist/utils/testing/chat_models.d.ts +3 -11
  209. package/dist/utils/testing/message_history.cjs +1 -1
  210. package/dist/utils/testing/message_history.js +1 -1
  211. package/dist/utils/testing/retrievers.d.cts +1 -3
  212. package/dist/utils/testing/retrievers.d.ts +1 -3
  213. package/dist/utils/testing/vectorstores.d.cts +0 -1
  214. package/dist/utils/testing/vectorstores.d.ts +0 -1
  215. package/dist/utils/types/index.cjs +4 -0
  216. package/dist/utils/types/index.d.cts +2 -4
  217. package/dist/utils/types/index.d.ts +2 -4
  218. package/dist/utils/types/index.js +4 -2
  219. package/dist/utils/types/zod.cjs +24 -0
  220. package/dist/utils/types/zod.cjs.map +1 -1
  221. package/dist/utils/types/zod.d.cts +4 -4
  222. package/dist/utils/types/zod.d.ts +4 -4
  223. package/dist/utils/types/zod.js +23 -1
  224. package/dist/utils/types/zod.js.map +1 -1
  225. package/dist/vectorstores.d.cts +5 -17
  226. package/dist/vectorstores.d.ts +5 -17
  227. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["fn: () => T","toolCall: ToolCall | Record<string, unknown>","x: unknown","params:\n | (BaseMessageFields & { type: string } & Record<string, unknown>)\n | SerializedConstructor","type: string","rest: BaseMessageFields & Record<string, unknown>","messageLike: BaseMessageLike","messages: BaseMessage[]","string_messages: string[]","role: string","message: StoredMessage | StoredMessageV1","message: StoredMessage","messages: StoredMessage[]","message: BaseMessage","aiChunkFields: AIMessageChunkFields"],"sources":["../../src/messages/utils.ts"],"sourcesContent":["import { addLangChainErrorFields } from \"../errors/index.js\";\nimport { SerializedConstructor } from \"../load/serializable.js\";\nimport { _isToolCall } from \"../tools/utils.js\";\nimport { AIMessage, AIMessageChunk, AIMessageChunkFields } from \"./ai.js\";\nimport {\n BaseMessageLike,\n BaseMessage,\n isBaseMessage,\n StoredMessage,\n StoredMessageV1,\n BaseMessageFields,\n _isMessageFieldWithRole,\n} from \"./base.js\";\nimport { ChatMessage, ChatMessageFields, ChatMessageChunk } from \"./chat.js\";\nimport {\n FunctionMessage,\n FunctionMessageChunk,\n FunctionMessageFields,\n} from \"./function.js\";\nimport { HumanMessage, HumanMessageChunk } from \"./human.js\";\nimport { RemoveMessage } from \"./modifier.js\";\nimport { SystemMessage, SystemMessageChunk } from \"./system.js\";\nimport { ToolCall, ToolMessage, ToolMessageFields } from \"./tool.js\";\n\nexport type $Expand<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\n\n/**\n * Extracts the explicitly declared keys from a type T.\n *\n * @template T - The type to extract keys from\n * @returns A union of keys that are not string, number, or symbol\n */\ntype $KnownKeys<T> = {\n [K in keyof T]: string extends K\n ? never\n : number extends K\n ? never\n : symbol extends K\n ? never\n : K;\n}[keyof T];\n\n/**\n * Detects if T has an index signature.\n *\n * @template T - The type to check for index signatures\n * @returns True if T has an index signature, false otherwise\n */\ntype $HasIndexSignature<T> = string extends keyof T\n ? true\n : number extends keyof T\n ? true\n : symbol extends keyof T\n ? true\n : false;\n\n/**\n * Detects if T has an index signature and no known keys.\n *\n * @template T - The type to check for index signatures and no known keys\n * @returns True if T has an index signature and no known keys, false otherwise\n */\ntype $OnlyIndexSignatures<T> = $HasIndexSignature<T> extends true\n ? [$KnownKeys<T>] extends [never]\n ? true\n : false\n : false;\n\n/**\n * Recursively merges two object types T and U, with U taking precedence over T.\n *\n * This utility type performs a deep merge of two object types:\n * - For keys that exist in both T and U:\n * - If both values are objects (Record<string, unknown>), recursively merge them\n * - Otherwise, U's value takes precedence\n * - For keys that exist only in T, use T's value\n * - For keys that exist only in U, use U's value\n *\n * @template T - The first object type to merge\n * @template U - The second object type to merge (takes precedence over T)\n *\n * @example\n * ```ts\n * type ObjectA = {\n * shared: { a: string; b: number };\n * onlyInA: boolean;\n * };\n *\n * type ObjectB = {\n * shared: { b: string; c: Date };\n * onlyInB: symbol;\n * };\n *\n * type Merged = $MergeObjects<ObjectA, ObjectB>;\n * // Result: {\n * // shared: { a: string; b: string; c: Date };\n * // onlyInA: boolean;\n * // onlyInB: symbol;\n * // }\n * ```\n */\nexport type $MergeObjects<T, U> =\n // If U is purely index-signature based, prefer U as a whole\n $OnlyIndexSignatures<U> extends true\n ? U\n : // If T is purely index-signature based, prefer U as a whole (prevents leaking broad index signatures)\n $OnlyIndexSignatures<T> extends true\n ? U\n : {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? T[K] extends Record<string, unknown>\n ? U[K] extends Record<string, unknown>\n ? $MergeObjects<T[K], U[K]>\n : U[K]\n : U[K]\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n };\n\n/**\n * Merges two discriminated unions A and B based on a discriminator key (defaults to \"type\").\n * For each possible value of the discriminator across both unions:\n * - If B has a member with that discriminator value, use B's member\n * - Otherwise use A's member with that discriminator value\n * This effectively merges the unions while giving B's members precedence over A's members.\n *\n * @template A - First discriminated union type that extends Record<Key, PropertyKey>\n * @template B - Second discriminated union type that extends Record<Key, PropertyKey>\n * @template Key - The discriminator key property, defaults to \"type\"\n */\nexport type $MergeDiscriminatedUnion<\n A extends Record<Key, PropertyKey>,\n B extends Record<Key, PropertyKey>,\n Key extends PropertyKey = \"type\"\n> = {\n // Create a mapped type over all possible discriminator values from both A and B\n [T in A[Key] | B[Key]]: [Extract<B, Record<Key, T>>] extends [never] // Check if B has a member with this discriminator value\n ? // If B doesn't have this discriminator value, use A's member\n Extract<A, Record<Key, T>>\n : // If B does have this discriminator value, merge A's and B's members (B takes precedence)\n [Extract<A, Record<Key, T>>] extends [never]\n ? Extract<B, Record<Key, T>>\n : $MergeObjects<Extract<A, Record<Key, T>>, Extract<B, Record<Key, T>>>;\n // Index into the mapped type with all possible discriminator values\n // This converts the mapped type back into a union\n}[A[Key] | B[Key]];\n\nexport type Constructor<T> = new (...args: unknown[]) => T;\n\n/**\n * Immediately-invoked function expression.\n *\n * @param fn - The function to execute\n * @returns The result of the function\n */\nexport const iife = <T>(fn: () => T) => fn();\n\nfunction _coerceToolCall(\n toolCall: ToolCall | Record<string, unknown>\n): ToolCall {\n if (_isToolCall(toolCall)) {\n return toolCall;\n } else if (\n typeof toolCall.id === \"string\" &&\n toolCall.type === \"function\" &&\n typeof toolCall.function === \"object\" &&\n toolCall.function !== null &&\n \"arguments\" in toolCall.function &&\n typeof toolCall.function.arguments === \"string\" &&\n \"name\" in toolCall.function &&\n typeof toolCall.function.name === \"string\"\n ) {\n // Handle OpenAI tool call format\n return {\n id: toolCall.id,\n args: JSON.parse(toolCall.function.arguments),\n name: toolCall.function.name,\n type: \"tool_call\",\n };\n } else {\n // TODO: Throw an error?\n return toolCall as unknown as ToolCall;\n }\n}\n\nfunction isSerializedConstructor(x: unknown): x is SerializedConstructor {\n return (\n typeof x === \"object\" &&\n x != null &&\n (x as SerializedConstructor).lc === 1 &&\n Array.isArray((x as SerializedConstructor).id) &&\n (x as SerializedConstructor).kwargs != null &&\n typeof (x as SerializedConstructor).kwargs === \"object\"\n );\n}\n\nfunction _constructMessageFromParams(\n params:\n | (BaseMessageFields & { type: string } & Record<string, unknown>)\n | SerializedConstructor\n) {\n let type: string;\n let rest: BaseMessageFields & Record<string, unknown>;\n // Support serialized messages\n if (isSerializedConstructor(params)) {\n const className = params.id.at(-1);\n if (className === \"HumanMessage\" || className === \"HumanMessageChunk\") {\n type = \"user\";\n } else if (className === \"AIMessage\" || className === \"AIMessageChunk\") {\n type = \"assistant\";\n } else if (\n className === \"SystemMessage\" ||\n className === \"SystemMessageChunk\"\n ) {\n type = \"system\";\n } else if (\n className === \"FunctionMessage\" ||\n className === \"FunctionMessageChunk\"\n ) {\n type = \"function\";\n } else if (\n className === \"ToolMessage\" ||\n className === \"ToolMessageChunk\"\n ) {\n type = \"tool\";\n } else {\n type = \"unknown\";\n }\n rest = params.kwargs as BaseMessageFields;\n } else {\n const { type: extractedType, ...otherParams } = params;\n type = extractedType;\n rest = otherParams;\n }\n if (type === \"human\" || type === \"user\") {\n return new HumanMessage(rest);\n } else if (type === \"ai\" || type === \"assistant\") {\n const { tool_calls: rawToolCalls, ...other } = rest;\n if (!Array.isArray(rawToolCalls)) {\n return new AIMessage(rest);\n }\n const tool_calls = rawToolCalls.map(_coerceToolCall);\n return new AIMessage({ ...other, tool_calls });\n } else if (type === \"system\") {\n return new SystemMessage(rest);\n } else if (type === \"developer\") {\n return new SystemMessage({\n ...rest,\n additional_kwargs: {\n ...rest.additional_kwargs,\n __openai_role__: \"developer\",\n },\n });\n } else if (type === \"tool\" && \"tool_call_id\" in rest) {\n return new ToolMessage({\n ...rest,\n content: rest.content,\n tool_call_id: rest.tool_call_id as string,\n name: rest.name,\n });\n } else if (type === \"remove\" && \"id\" in rest && typeof rest.id === \"string\") {\n return new RemoveMessage({ ...rest, id: rest.id });\n } else {\n const error = addLangChainErrorFields(\n new Error(\n `Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.\\n\\nReceived: ${JSON.stringify(\n params,\n null,\n 2\n )}`\n ),\n \"MESSAGE_COERCION_FAILURE\"\n );\n throw error;\n }\n}\n\nexport function coerceMessageLikeToMessage(\n messageLike: BaseMessageLike\n): BaseMessage {\n if (typeof messageLike === \"string\") {\n return new HumanMessage(messageLike);\n } else if (isBaseMessage(messageLike)) {\n return messageLike;\n }\n if (Array.isArray(messageLike)) {\n const [type, content] = messageLike;\n return _constructMessageFromParams({ type, content });\n } else if (_isMessageFieldWithRole(messageLike)) {\n const { role: type, ...rest } = messageLike;\n return _constructMessageFromParams({ ...rest, type });\n } else {\n return _constructMessageFromParams(messageLike);\n }\n}\n\n/**\n * This function is used by memory classes to get a string representation\n * of the chat message history, based on the message content and role.\n */\nexport function getBufferString(\n messages: BaseMessage[],\n humanPrefix = \"Human\",\n aiPrefix = \"AI\"\n): string {\n const string_messages: string[] = [];\n for (const m of messages) {\n let role: string;\n if (m._getType() === \"human\") {\n role = humanPrefix;\n } else if (m._getType() === \"ai\") {\n role = aiPrefix;\n } else if (m._getType() === \"system\") {\n role = \"System\";\n } else if (m._getType() === \"tool\") {\n role = \"Tool\";\n } else if (m._getType() === \"generic\") {\n role = (m as ChatMessage).role;\n } else {\n throw new Error(`Got unsupported message type: ${m._getType()}`);\n }\n const nameStr = m.name ? `${m.name}, ` : \"\";\n const readableContent =\n typeof m.content === \"string\"\n ? m.content\n : JSON.stringify(m.content, null, 2);\n string_messages.push(`${role}: ${nameStr}${readableContent}`);\n }\n return string_messages.join(\"\\n\");\n}\n\n/**\n * Maps messages from an older format (V1) to the current `StoredMessage`\n * format. If the message is already in the `StoredMessage` format, it is\n * returned as is. Otherwise, it transforms the V1 message into a\n * `StoredMessage`. This function is important for maintaining\n * compatibility with older message formats.\n */\nfunction mapV1MessageToStoredMessage(\n message: StoredMessage | StoredMessageV1\n): StoredMessage {\n // TODO: Remove this mapper when we deprecate the old message format.\n if ((message as StoredMessage).data !== undefined) {\n return message as StoredMessage;\n } else {\n const v1Message = message as StoredMessageV1;\n return {\n type: v1Message.type,\n data: {\n content: v1Message.text,\n role: v1Message.role,\n name: undefined,\n tool_call_id: undefined,\n },\n };\n }\n}\n\nexport function mapStoredMessageToChatMessage(message: StoredMessage) {\n const storedMessage = mapV1MessageToStoredMessage(message);\n switch (storedMessage.type) {\n case \"human\":\n return new HumanMessage(storedMessage.data);\n case \"ai\":\n return new AIMessage(storedMessage.data);\n case \"system\":\n return new SystemMessage(storedMessage.data);\n case \"function\":\n if (storedMessage.data.name === undefined) {\n throw new Error(\"Name must be defined for function messages\");\n }\n return new FunctionMessage(storedMessage.data as FunctionMessageFields);\n case \"tool\":\n if (storedMessage.data.tool_call_id === undefined) {\n throw new Error(\"Tool call ID must be defined for tool messages\");\n }\n return new ToolMessage(storedMessage.data as ToolMessageFields);\n case \"generic\": {\n if (storedMessage.data.role === undefined) {\n throw new Error(\"Role must be defined for chat messages\");\n }\n return new ChatMessage(storedMessage.data as ChatMessageFields);\n }\n default:\n throw new Error(`Got unexpected type: ${storedMessage.type}`);\n }\n}\n\n/**\n * Transforms an array of `StoredMessage` instances into an array of\n * `BaseMessage` instances. It uses the `mapV1MessageToStoredMessage`\n * function to ensure all messages are in the `StoredMessage` format, then\n * creates new instances of the appropriate `BaseMessage` subclass based\n * on the type of each message. This function is used to prepare stored\n * messages for use in a chat context.\n */\nexport function mapStoredMessagesToChatMessages(\n messages: StoredMessage[]\n): BaseMessage[] {\n return messages.map(mapStoredMessageToChatMessage);\n}\n\n/**\n * Transforms an array of `BaseMessage` instances into an array of\n * `StoredMessage` instances. It does this by calling the `toDict` method\n * on each `BaseMessage`, which returns a `StoredMessage`. This function\n * is used to prepare chat messages for storage.\n */\nexport function mapChatMessagesToStoredMessages(\n messages: BaseMessage[]\n): StoredMessage[] {\n return messages.map((message) => message.toDict());\n}\n\nexport function convertToChunk(message: BaseMessage) {\n const type = message._getType();\n if (type === \"human\") {\n return new HumanMessageChunk({ ...message });\n } else if (type === \"ai\") {\n let aiChunkFields: AIMessageChunkFields = {\n ...message,\n };\n if (\"tool_calls\" in aiChunkFields) {\n aiChunkFields = {\n ...aiChunkFields,\n tool_call_chunks: aiChunkFields.tool_calls?.map((tc) => ({\n ...tc,\n type: \"tool_call_chunk\",\n index: undefined,\n args: JSON.stringify(tc.args),\n })),\n };\n }\n return new AIMessageChunk({ ...aiChunkFields });\n } else if (type === \"system\") {\n return new SystemMessageChunk({ ...message });\n } else if (type === \"function\") {\n return new FunctionMessageChunk({ ...message });\n } else if (ChatMessage.isInstance(message)) {\n return new ChatMessageChunk({ ...message });\n } else {\n throw new Error(\"Unknown message type.\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8JA,MAAa,OAAO,CAAIA,OAAgB,IAAI;AAE5C,SAAS,gBACPC,UACU;AACV,KAAI,YAAY,SAAS,CACvB,QAAO;UAEP,OAAO,SAAS,OAAO,YACvB,SAAS,SAAS,cAClB,OAAO,SAAS,aAAa,YAC7B,SAAS,aAAa,QACtB,eAAe,SAAS,YACxB,OAAO,SAAS,SAAS,cAAc,YACvC,UAAU,SAAS,YACnB,OAAO,SAAS,SAAS,SAAS,SAGlC,QAAO;EACL,IAAI,SAAS;EACb,MAAM,KAAK,MAAM,SAAS,SAAS,UAAU;EAC7C,MAAM,SAAS,SAAS;EACxB,MAAM;CACP;KAGD,QAAO;AAEV;AAED,SAAS,wBAAwBC,GAAwC;AACvE,QACE,OAAO,MAAM,YACb,KAAK,QACJ,EAA4B,OAAO,KACpC,MAAM,QAAS,EAA4B,GAAG,IAC7C,EAA4B,UAAU,QACvC,OAAQ,EAA4B,WAAW;AAElD;AAED,SAAS,4BACPC,QAGA;CACA,IAAIC;CACJ,IAAIC;AAEJ,KAAI,wBAAwB,OAAO,EAAE;EAC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AI,iBAAiB,EAAE,GAAG,QAAS;KAE1C,OAAM,IAAI,MAAM;AAEnB"}
1
+ {"version":3,"file":"utils.js","names":["fn: () => T","toolCall: ToolCall | Record<string, unknown>","x: unknown","params:\n | (BaseMessageFields & { type: string } & Record<string, unknown>)\n | SerializedConstructor","type: string","rest: BaseMessageFields & Record<string, unknown>","messageLike: BaseMessageLike","messages: BaseMessage[]","string_messages: string[]","role: string","message: StoredMessage | StoredMessageV1","message: StoredMessage","messages: StoredMessage[]","message: BaseMessage","aiChunkFields: AIMessageChunkFields","chunks: ToolCallChunk[]","toolCalls: ToolCall[]","invalidToolCalls: InvalidToolCall[]","chunks","parsedArgs: Record<string, unknown> | null"],"sources":["../../src/messages/utils.ts"],"sourcesContent":["import { addLangChainErrorFields } from \"../errors/index.js\";\nimport { SerializedConstructor } from \"../load/serializable.js\";\nimport { _isToolCall } from \"../tools/utils.js\";\nimport { parsePartialJson } from \"../utils/json.js\";\nimport { AIMessage, AIMessageChunk, AIMessageChunkFields } from \"./ai.js\";\nimport {\n BaseMessageLike,\n BaseMessage,\n isBaseMessage,\n StoredMessage,\n StoredMessageV1,\n BaseMessageFields,\n _isMessageFieldWithRole,\n} from \"./base.js\";\nimport { ChatMessage, ChatMessageFields, ChatMessageChunk } from \"./chat.js\";\nimport {\n FunctionMessage,\n FunctionMessageChunk,\n FunctionMessageFields,\n} from \"./function.js\";\nimport { HumanMessage, HumanMessageChunk } from \"./human.js\";\nimport { RemoveMessage } from \"./modifier.js\";\nimport { SystemMessage, SystemMessageChunk } from \"./system.js\";\nimport {\n InvalidToolCall,\n ToolCall,\n ToolCallChunk,\n ToolMessage,\n ToolMessageFields,\n} from \"./tool.js\";\n\nexport type $Expand<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\n\n/**\n * Extracts the explicitly declared keys from a type T.\n *\n * @template T - The type to extract keys from\n * @returns A union of keys that are not string, number, or symbol\n */\ntype $KnownKeys<T> = {\n [K in keyof T]: string extends K\n ? never\n : number extends K\n ? never\n : symbol extends K\n ? never\n : K;\n}[keyof T];\n\n/**\n * Detects if T has an index signature.\n *\n * @template T - The type to check for index signatures\n * @returns True if T has an index signature, false otherwise\n */\ntype $HasIndexSignature<T> = string extends keyof T\n ? true\n : number extends keyof T\n ? true\n : symbol extends keyof T\n ? true\n : false;\n\n/**\n * Detects if T has an index signature and no known keys.\n *\n * @template T - The type to check for index signatures and no known keys\n * @returns True if T has an index signature and no known keys, false otherwise\n */\ntype $OnlyIndexSignatures<T> = $HasIndexSignature<T> extends true\n ? [$KnownKeys<T>] extends [never]\n ? true\n : false\n : false;\n\n/**\n * Recursively merges two object types T and U, with U taking precedence over T.\n *\n * This utility type performs a deep merge of two object types:\n * - For keys that exist in both T and U:\n * - If both values are objects (Record<string, unknown>), recursively merge them\n * - Otherwise, U's value takes precedence\n * - For keys that exist only in T, use T's value\n * - For keys that exist only in U, use U's value\n *\n * @template T - The first object type to merge\n * @template U - The second object type to merge (takes precedence over T)\n *\n * @example\n * ```ts\n * type ObjectA = {\n * shared: { a: string; b: number };\n * onlyInA: boolean;\n * };\n *\n * type ObjectB = {\n * shared: { b: string; c: Date };\n * onlyInB: symbol;\n * };\n *\n * type Merged = $MergeObjects<ObjectA, ObjectB>;\n * // Result: {\n * // shared: { a: string; b: string; c: Date };\n * // onlyInA: boolean;\n * // onlyInB: symbol;\n * // }\n * ```\n */\nexport type $MergeObjects<T, U> =\n // If U is purely index-signature based, prefer U as a whole\n $OnlyIndexSignatures<U> extends true\n ? U\n : // If T is purely index-signature based, prefer U as a whole (prevents leaking broad index signatures)\n $OnlyIndexSignatures<T> extends true\n ? U\n : {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? T[K] extends Record<string, unknown>\n ? U[K] extends Record<string, unknown>\n ? $MergeObjects<T[K], U[K]>\n : U[K]\n : U[K]\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n };\n\n/**\n * Merges two discriminated unions A and B based on a discriminator key (defaults to \"type\").\n * For each possible value of the discriminator across both unions:\n * - If B has a member with that discriminator value, use B's member\n * - Otherwise use A's member with that discriminator value\n * This effectively merges the unions while giving B's members precedence over A's members.\n *\n * @template A - First discriminated union type that extends Record<Key, PropertyKey>\n * @template B - Second discriminated union type that extends Record<Key, PropertyKey>\n * @template Key - The discriminator key property, defaults to \"type\"\n */\nexport type $MergeDiscriminatedUnion<\n A extends Record<Key, PropertyKey>,\n B extends Record<Key, PropertyKey>,\n Key extends PropertyKey = \"type\"\n> = {\n // Create a mapped type over all possible discriminator values from both A and B\n [T in A[Key] | B[Key]]: [Extract<B, Record<Key, T>>] extends [never] // Check if B has a member with this discriminator value\n ? // If B doesn't have this discriminator value, use A's member\n Extract<A, Record<Key, T>>\n : // If B does have this discriminator value, merge A's and B's members (B takes precedence)\n [Extract<A, Record<Key, T>>] extends [never]\n ? Extract<B, Record<Key, T>>\n : $MergeObjects<Extract<A, Record<Key, T>>, Extract<B, Record<Key, T>>>;\n // Index into the mapped type with all possible discriminator values\n // This converts the mapped type back into a union\n}[A[Key] | B[Key]];\n\nexport type Constructor<T> = new (...args: unknown[]) => T;\n\n/**\n * Immediately-invoked function expression.\n *\n * @param fn - The function to execute\n * @returns The result of the function\n */\nexport const iife = <T>(fn: () => T) => fn();\n\nfunction _coerceToolCall(\n toolCall: ToolCall | Record<string, unknown>\n): ToolCall {\n if (_isToolCall(toolCall)) {\n return toolCall;\n } else if (\n typeof toolCall.id === \"string\" &&\n toolCall.type === \"function\" &&\n typeof toolCall.function === \"object\" &&\n toolCall.function !== null &&\n \"arguments\" in toolCall.function &&\n typeof toolCall.function.arguments === \"string\" &&\n \"name\" in toolCall.function &&\n typeof toolCall.function.name === \"string\"\n ) {\n // Handle OpenAI tool call format\n return {\n id: toolCall.id,\n args: JSON.parse(toolCall.function.arguments),\n name: toolCall.function.name,\n type: \"tool_call\",\n };\n } else {\n // TODO: Throw an error?\n return toolCall as unknown as ToolCall;\n }\n}\n\nfunction isSerializedConstructor(x: unknown): x is SerializedConstructor {\n return (\n typeof x === \"object\" &&\n x != null &&\n (x as SerializedConstructor).lc === 1 &&\n Array.isArray((x as SerializedConstructor).id) &&\n (x as SerializedConstructor).kwargs != null &&\n typeof (x as SerializedConstructor).kwargs === \"object\"\n );\n}\n\nfunction _constructMessageFromParams(\n params:\n | (BaseMessageFields & { type: string } & Record<string, unknown>)\n | SerializedConstructor\n) {\n let type: string;\n let rest: BaseMessageFields & Record<string, unknown>;\n // Support serialized messages\n if (isSerializedConstructor(params)) {\n const className = params.id.at(-1);\n if (className === \"HumanMessage\" || className === \"HumanMessageChunk\") {\n type = \"user\";\n } else if (className === \"AIMessage\" || className === \"AIMessageChunk\") {\n type = \"assistant\";\n } else if (\n className === \"SystemMessage\" ||\n className === \"SystemMessageChunk\"\n ) {\n type = \"system\";\n } else if (\n className === \"FunctionMessage\" ||\n className === \"FunctionMessageChunk\"\n ) {\n type = \"function\";\n } else if (\n className === \"ToolMessage\" ||\n className === \"ToolMessageChunk\"\n ) {\n type = \"tool\";\n } else {\n type = \"unknown\";\n }\n rest = params.kwargs as BaseMessageFields;\n } else {\n const { type: extractedType, ...otherParams } = params;\n type = extractedType;\n rest = otherParams;\n }\n if (type === \"human\" || type === \"user\") {\n return new HumanMessage(rest);\n } else if (type === \"ai\" || type === \"assistant\") {\n const { tool_calls: rawToolCalls, ...other } = rest;\n if (!Array.isArray(rawToolCalls)) {\n return new AIMessage(rest);\n }\n const tool_calls = rawToolCalls.map(_coerceToolCall);\n return new AIMessage({ ...other, tool_calls });\n } else if (type === \"system\") {\n return new SystemMessage(rest);\n } else if (type === \"developer\") {\n return new SystemMessage({\n ...rest,\n additional_kwargs: {\n ...rest.additional_kwargs,\n __openai_role__: \"developer\",\n },\n });\n } else if (type === \"tool\" && \"tool_call_id\" in rest) {\n return new ToolMessage({\n ...rest,\n content: rest.content,\n tool_call_id: rest.tool_call_id as string,\n name: rest.name,\n });\n } else if (type === \"remove\" && \"id\" in rest && typeof rest.id === \"string\") {\n return new RemoveMessage({ ...rest, id: rest.id });\n } else {\n const error = addLangChainErrorFields(\n new Error(\n `Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.\\n\\nReceived: ${JSON.stringify(\n params,\n null,\n 2\n )}`\n ),\n \"MESSAGE_COERCION_FAILURE\"\n );\n throw error;\n }\n}\n\nexport function coerceMessageLikeToMessage(\n messageLike: BaseMessageLike\n): BaseMessage {\n if (typeof messageLike === \"string\") {\n return new HumanMessage(messageLike);\n } else if (isBaseMessage(messageLike)) {\n return messageLike;\n }\n if (Array.isArray(messageLike)) {\n const [type, content] = messageLike;\n return _constructMessageFromParams({ type, content });\n } else if (_isMessageFieldWithRole(messageLike)) {\n const { role: type, ...rest } = messageLike;\n return _constructMessageFromParams({ ...rest, type });\n } else {\n return _constructMessageFromParams(messageLike);\n }\n}\n\n/**\n * This function is used by memory classes to get a string representation\n * of the chat message history, based on the message content and role.\n */\nexport function getBufferString(\n messages: BaseMessage[],\n humanPrefix = \"Human\",\n aiPrefix = \"AI\"\n): string {\n const string_messages: string[] = [];\n for (const m of messages) {\n let role: string;\n if (m._getType() === \"human\") {\n role = humanPrefix;\n } else if (m._getType() === \"ai\") {\n role = aiPrefix;\n } else if (m._getType() === \"system\") {\n role = \"System\";\n } else if (m._getType() === \"tool\") {\n role = \"Tool\";\n } else if (m._getType() === \"generic\") {\n role = (m as ChatMessage).role;\n } else {\n throw new Error(`Got unsupported message type: ${m._getType()}`);\n }\n const nameStr = m.name ? `${m.name}, ` : \"\";\n const readableContent =\n typeof m.content === \"string\"\n ? m.content\n : JSON.stringify(m.content, null, 2);\n string_messages.push(`${role}: ${nameStr}${readableContent}`);\n }\n return string_messages.join(\"\\n\");\n}\n\n/**\n * Maps messages from an older format (V1) to the current `StoredMessage`\n * format. If the message is already in the `StoredMessage` format, it is\n * returned as is. Otherwise, it transforms the V1 message into a\n * `StoredMessage`. This function is important for maintaining\n * compatibility with older message formats.\n */\nfunction mapV1MessageToStoredMessage(\n message: StoredMessage | StoredMessageV1\n): StoredMessage {\n // TODO: Remove this mapper when we deprecate the old message format.\n if ((message as StoredMessage).data !== undefined) {\n return message as StoredMessage;\n } else {\n const v1Message = message as StoredMessageV1;\n return {\n type: v1Message.type,\n data: {\n content: v1Message.text,\n role: v1Message.role,\n name: undefined,\n tool_call_id: undefined,\n },\n };\n }\n}\n\nexport function mapStoredMessageToChatMessage(message: StoredMessage) {\n const storedMessage = mapV1MessageToStoredMessage(message);\n switch (storedMessage.type) {\n case \"human\":\n return new HumanMessage(storedMessage.data);\n case \"ai\":\n return new AIMessage(storedMessage.data);\n case \"system\":\n return new SystemMessage(storedMessage.data);\n case \"function\":\n if (storedMessage.data.name === undefined) {\n throw new Error(\"Name must be defined for function messages\");\n }\n return new FunctionMessage(storedMessage.data as FunctionMessageFields);\n case \"tool\":\n if (storedMessage.data.tool_call_id === undefined) {\n throw new Error(\"Tool call ID must be defined for tool messages\");\n }\n return new ToolMessage(storedMessage.data as ToolMessageFields);\n case \"generic\": {\n if (storedMessage.data.role === undefined) {\n throw new Error(\"Role must be defined for chat messages\");\n }\n return new ChatMessage(storedMessage.data as ChatMessageFields);\n }\n default:\n throw new Error(`Got unexpected type: ${storedMessage.type}`);\n }\n}\n\n/**\n * Transforms an array of `StoredMessage` instances into an array of\n * `BaseMessage` instances. It uses the `mapV1MessageToStoredMessage`\n * function to ensure all messages are in the `StoredMessage` format, then\n * creates new instances of the appropriate `BaseMessage` subclass based\n * on the type of each message. This function is used to prepare stored\n * messages for use in a chat context.\n */\nexport function mapStoredMessagesToChatMessages(\n messages: StoredMessage[]\n): BaseMessage[] {\n return messages.map(mapStoredMessageToChatMessage);\n}\n\n/**\n * Transforms an array of `BaseMessage` instances into an array of\n * `StoredMessage` instances. It does this by calling the `toDict` method\n * on each `BaseMessage`, which returns a `StoredMessage`. This function\n * is used to prepare chat messages for storage.\n */\nexport function mapChatMessagesToStoredMessages(\n messages: BaseMessage[]\n): StoredMessage[] {\n return messages.map((message) => message.toDict());\n}\n\nexport function convertToChunk(message: BaseMessage) {\n const type = message._getType();\n if (type === \"human\") {\n return new HumanMessageChunk({ ...message });\n } else if (type === \"ai\") {\n let aiChunkFields: AIMessageChunkFields = {\n ...message,\n };\n if (\"tool_calls\" in aiChunkFields) {\n aiChunkFields = {\n ...aiChunkFields,\n tool_call_chunks: aiChunkFields.tool_calls?.map((tc) => ({\n ...tc,\n type: \"tool_call_chunk\",\n index: undefined,\n args: JSON.stringify(tc.args),\n })),\n };\n }\n return new AIMessageChunk({ ...aiChunkFields });\n } else if (type === \"system\") {\n return new SystemMessageChunk({ ...message });\n } else if (type === \"function\") {\n return new FunctionMessageChunk({ ...message });\n } else if (ChatMessage.isInstance(message)) {\n return new ChatMessageChunk({ ...message });\n } else {\n throw new Error(\"Unknown message type.\");\n }\n}\n\n/**\n * Collapses an array of tool call chunks into complete tool calls.\n *\n * This function groups tool call chunks by their id and/or index, then attempts to\n * parse and validate the accumulated arguments for each group. Successfully parsed\n * tool calls are returned as valid `ToolCall` objects, while malformed ones are\n * returned as `InvalidToolCall` objects.\n *\n * @param chunks - An array of `ToolCallChunk` objects to collapse\n * @returns An object containing:\n * - `tool_call_chunks`: The original input chunks\n * - `tool_calls`: An array of successfully parsed and validated tool calls\n * - `invalid_tool_calls`: An array of tool calls that failed parsing or validation\n *\n * @remarks\n * Chunks are grouped using the following matching logic:\n * - If a chunk has both an id and index, it matches chunks with the same id and index\n * - If a chunk has only an id, it matches chunks with the same id\n * - If a chunk has only an index, it matches chunks with the same index\n *\n * For each group, the function:\n * 1. Concatenates all `args` strings from the chunks\n * 2. Attempts to parse the concatenated string as JSON\n * 3. Validates that the result is a non-null object with a valid id\n * 4. Creates either a `ToolCall` (if valid) or `InvalidToolCall` (if invalid)\n */\nexport function collapseToolCallChunks(chunks: ToolCallChunk[]): {\n tool_call_chunks: ToolCallChunk[];\n tool_calls: ToolCall[];\n invalid_tool_calls: InvalidToolCall[];\n} {\n const groupedToolCallChunks = chunks.reduce((acc, chunk) => {\n const matchedChunkIndex = acc.findIndex(([match]) => {\n // If chunk has an id and index, match if both are present\n if (\n \"id\" in chunk &&\n chunk.id &&\n \"index\" in chunk &&\n chunk.index !== undefined\n ) {\n return chunk.id === match.id && chunk.index === match.index;\n }\n // If chunk has an id, we match on id\n if (\"id\" in chunk && chunk.id) {\n return chunk.id === match.id;\n }\n // If chunk has an index, we match on index\n if (\"index\" in chunk && chunk.index !== undefined) {\n return chunk.index === match.index;\n }\n return false;\n });\n if (matchedChunkIndex !== -1) {\n acc[matchedChunkIndex].push(chunk);\n } else {\n acc.push([chunk]);\n }\n return acc;\n }, [] as ToolCallChunk[][]);\n\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const chunks of groupedToolCallChunks) {\n let parsedArgs: Record<string, unknown> | null = null;\n const name = chunks[0]?.name ?? \"\";\n const joinedArgs = chunks\n .map((c) => c.args || \"\")\n .join(\"\")\n .trim();\n const argsStr = joinedArgs.length ? joinedArgs : \"{}\";\n const id = chunks[0]?.id;\n try {\n parsedArgs = parsePartialJson(argsStr);\n if (\n !id ||\n parsedArgs === null ||\n typeof parsedArgs !== \"object\" ||\n Array.isArray(parsedArgs)\n ) {\n throw new Error(\"Malformed tool call chunk args.\");\n }\n toolCalls.push({\n name,\n args: parsedArgs,\n id,\n type: \"tool_call\",\n });\n } catch {\n invalidToolCalls.push({\n name,\n args: argsStr,\n id,\n error: \"Malformed args.\",\n type: \"invalid_tool_call\",\n });\n }\n }\n return {\n tool_call_chunks: chunks,\n tool_calls: toolCalls,\n invalid_tool_calls: invalidToolCalls,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqKA,MAAa,OAAO,CAAIA,OAAgB,IAAI;AAE5C,SAAS,gBACPC,UACU;AACV,KAAI,YAAY,SAAS,CACvB,QAAO;UAEP,OAAO,SAAS,OAAO,YACvB,SAAS,SAAS,cAClB,OAAO,SAAS,aAAa,YAC7B,SAAS,aAAa,QACtB,eAAe,SAAS,YACxB,OAAO,SA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aAAaA,SAChB,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,CACxB,KAAK,GAAG,CACR,MAAM;EACT,MAAM,UAAU,WAAW,SAAS,aAAa;EACjD,MAAM,KAAKA,SAAO,IAAI;AACtB,MAAI;GACF,aAAa,iBAAiB,QAAQ;AACtC,OACE,CAAC,MACD,eAAe,QACf,OAAO,eAAe,YACtB,MAAM,QAAQ,WAAW,CAEzB,OAAM,IAAI,MAAM;GAElB,UAAU,KAAK;IACb;IACA,MAAM;IACN;IACA,MAAM;GACP,EAAC;EACH,QAAO;GACN,iBAAiB,KAAK;IACpB;IACA,MAAM;IACN;IACA,OAAO;IACP,MAAM;GACP,EAAC;EACH;CACF;AACD,QAAO;EACL,kBAAkB;EAClB,YAAY;EACZ,oBAAoB;CACrB;AACF"}
@@ -0,0 +1,169 @@
1
+
2
+ //#region ../../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js
3
+ const ANSI_BACKGROUND_OFFSET = 10;
4
+ const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
5
+ const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
6
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
7
+ const styles = {
8
+ modifier: {
9
+ reset: [0, 0],
10
+ bold: [1, 22],
11
+ dim: [2, 22],
12
+ italic: [3, 23],
13
+ underline: [4, 24],
14
+ overline: [53, 55],
15
+ inverse: [7, 27],
16
+ hidden: [8, 28],
17
+ strikethrough: [9, 29]
18
+ },
19
+ color: {
20
+ black: [30, 39],
21
+ red: [31, 39],
22
+ green: [32, 39],
23
+ yellow: [33, 39],
24
+ blue: [34, 39],
25
+ magenta: [35, 39],
26
+ cyan: [36, 39],
27
+ white: [37, 39],
28
+ blackBright: [90, 39],
29
+ gray: [90, 39],
30
+ grey: [90, 39],
31
+ redBright: [91, 39],
32
+ greenBright: [92, 39],
33
+ yellowBright: [93, 39],
34
+ blueBright: [94, 39],
35
+ magentaBright: [95, 39],
36
+ cyanBright: [96, 39],
37
+ whiteBright: [97, 39]
38
+ },
39
+ bgColor: {
40
+ bgBlack: [40, 49],
41
+ bgRed: [41, 49],
42
+ bgGreen: [42, 49],
43
+ bgYellow: [43, 49],
44
+ bgBlue: [44, 49],
45
+ bgMagenta: [45, 49],
46
+ bgCyan: [46, 49],
47
+ bgWhite: [47, 49],
48
+ bgBlackBright: [100, 49],
49
+ bgGray: [100, 49],
50
+ bgGrey: [100, 49],
51
+ bgRedBright: [101, 49],
52
+ bgGreenBright: [102, 49],
53
+ bgYellowBright: [103, 49],
54
+ bgBlueBright: [104, 49],
55
+ bgMagentaBright: [105, 49],
56
+ bgCyanBright: [106, 49],
57
+ bgWhiteBright: [107, 49]
58
+ }
59
+ };
60
+ const modifierNames = Object.keys(styles.modifier);
61
+ const foregroundColorNames = Object.keys(styles.color);
62
+ const backgroundColorNames = Object.keys(styles.bgColor);
63
+ const colorNames = [...foregroundColorNames, ...backgroundColorNames];
64
+ function assembleStyles() {
65
+ const codes = /* @__PURE__ */ new Map();
66
+ for (const [groupName, group] of Object.entries(styles)) {
67
+ for (const [styleName, style] of Object.entries(group)) {
68
+ styles[styleName] = {
69
+ open: `\u001B[${style[0]}m`,
70
+ close: `\u001B[${style[1]}m`
71
+ };
72
+ group[styleName] = styles[styleName];
73
+ codes.set(style[0], style[1]);
74
+ }
75
+ Object.defineProperty(styles, groupName, {
76
+ value: group,
77
+ enumerable: false
78
+ });
79
+ }
80
+ Object.defineProperty(styles, "codes", {
81
+ value: codes,
82
+ enumerable: false
83
+ });
84
+ styles.color.close = "\x1B[39m";
85
+ styles.bgColor.close = "\x1B[49m";
86
+ styles.color.ansi = wrapAnsi16();
87
+ styles.color.ansi256 = wrapAnsi256();
88
+ styles.color.ansi16m = wrapAnsi16m();
89
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
90
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
91
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
92
+ Object.defineProperties(styles, {
93
+ rgbToAnsi256: {
94
+ value(red, green, blue) {
95
+ if (red === green && green === blue) {
96
+ if (red < 8) return 16;
97
+ if (red > 248) return 231;
98
+ return Math.round((red - 8) / 247 * 24) + 232;
99
+ }
100
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
101
+ },
102
+ enumerable: false
103
+ },
104
+ hexToRgb: {
105
+ value(hex) {
106
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
107
+ if (!matches) return [
108
+ 0,
109
+ 0,
110
+ 0
111
+ ];
112
+ let [colorString] = matches;
113
+ if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
114
+ const integer = Number.parseInt(colorString, 16);
115
+ return [
116
+ integer >> 16 & 255,
117
+ integer >> 8 & 255,
118
+ integer & 255
119
+ ];
120
+ },
121
+ enumerable: false
122
+ },
123
+ hexToAnsi256: {
124
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
125
+ enumerable: false
126
+ },
127
+ ansi256ToAnsi: {
128
+ value(code) {
129
+ if (code < 8) return 30 + code;
130
+ if (code < 16) return 90 + (code - 8);
131
+ let red;
132
+ let green;
133
+ let blue;
134
+ if (code >= 232) {
135
+ red = ((code - 232) * 10 + 8) / 255;
136
+ green = red;
137
+ blue = red;
138
+ } else {
139
+ code -= 16;
140
+ const remainder = code % 36;
141
+ red = Math.floor(code / 36) / 5;
142
+ green = Math.floor(remainder / 6) / 5;
143
+ blue = remainder % 6 / 5;
144
+ }
145
+ const value = Math.max(red, green, blue) * 2;
146
+ if (value === 0) return 30;
147
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
148
+ if (value === 2) result += 60;
149
+ return result;
150
+ },
151
+ enumerable: false
152
+ },
153
+ rgbToAnsi: {
154
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
155
+ enumerable: false
156
+ },
157
+ hexToAnsi: {
158
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
159
+ enumerable: false
160
+ }
161
+ });
162
+ return styles;
163
+ }
164
+ const ansiStyles = assembleStyles();
165
+ var ansi_styles_default = ansiStyles;
166
+
167
+ //#endregion
168
+ exports.default = ansi_styles_default;
169
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../../../../../../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js"],"sourcesContent":["const ANSI_BACKGROUND_OFFSET = 10;\n\nconst wrapAnsi16 = (offset = 0) => code => `\\u001B[${code + offset}m`;\n\nconst wrapAnsi256 = (offset = 0) => code => `\\u001B[${38 + offset};5;${code}m`;\n\nconst wrapAnsi16m = (offset = 0) => (red, green, blue) => `\\u001B[${38 + offset};2;${red};${green};${blue}m`;\n\nconst styles = {\n\tmodifier: {\n\t\treset: [0, 0],\n\t\t// 21 isn't widely supported and 22 does the same thing\n\t\tbold: [1, 22],\n\t\tdim: [2, 22],\n\t\titalic: [3, 23],\n\t\tunderline: [4, 24],\n\t\toverline: [53, 55],\n\t\tinverse: [7, 27],\n\t\thidden: [8, 28],\n\t\tstrikethrough: [9, 29],\n\t},\n\tcolor: {\n\t\tblack: [30, 39],\n\t\tred: [31, 39],\n\t\tgreen: [32, 39],\n\t\tyellow: [33, 39],\n\t\tblue: [34, 39],\n\t\tmagenta: [35, 39],\n\t\tcyan: [36, 39],\n\t\twhite: [37, 39],\n\n\t\t// Bright color\n\t\tblackBright: [90, 39],\n\t\tgray: [90, 39], // Alias of `blackBright`\n\t\tgrey: [90, 39], // Alias of `blackBright`\n\t\tredBright: [91, 39],\n\t\tgreenBright: [92, 39],\n\t\tyellowBright: [93, 39],\n\t\tblueBright: [94, 39],\n\t\tmagentaBright: [95, 39],\n\t\tcyanBright: [96, 39],\n\t\twhiteBright: [97, 39],\n\t},\n\tbgColor: {\n\t\tbgBlack: [40, 49],\n\t\tbgRed: [41, 49],\n\t\tbgGreen: [42, 49],\n\t\tbgYellow: [43, 49],\n\t\tbgBlue: [44, 49],\n\t\tbgMagenta: [45, 49],\n\t\tbgCyan: [46, 49],\n\t\tbgWhite: [47, 49],\n\n\t\t// Bright color\n\t\tbgBlackBright: [100, 49],\n\t\tbgGray: [100, 49], // Alias of `bgBlackBright`\n\t\tbgGrey: [100, 49], // Alias of `bgBlackBright`\n\t\tbgRedBright: [101, 49],\n\t\tbgGreenBright: [102, 49],\n\t\tbgYellowBright: [103, 49],\n\t\tbgBlueBright: [104, 49],\n\t\tbgMagentaBright: [105, 49],\n\t\tbgCyanBright: [106, 49],\n\t\tbgWhiteBright: [107, 49],\n\t},\n};\n\nexport const modifierNames = Object.keys(styles.modifier);\nexport const foregroundColorNames = Object.keys(styles.color);\nexport const backgroundColorNames = Object.keys(styles.bgColor);\nexport const colorNames = [...foregroundColorNames, ...backgroundColorNames];\n\nfunction assembleStyles() {\n\tconst codes = new Map();\n\n\tfor (const [groupName, group] of Object.entries(styles)) {\n\t\tfor (const [styleName, style] of Object.entries(group)) {\n\t\t\tstyles[styleName] = {\n\t\t\t\topen: `\\u001B[${style[0]}m`,\n\t\t\t\tclose: `\\u001B[${style[1]}m`,\n\t\t\t};\n\n\t\t\tgroup[styleName] = styles[styleName];\n\n\t\t\tcodes.set(style[0], style[1]);\n\t\t}\n\n\t\tObject.defineProperty(styles, groupName, {\n\t\t\tvalue: group,\n\t\t\tenumerable: false,\n\t\t});\n\t}\n\n\tObject.defineProperty(styles, 'codes', {\n\t\tvalue: codes,\n\t\tenumerable: false,\n\t});\n\n\tstyles.color.close = '\\u001B[39m';\n\tstyles.bgColor.close = '\\u001B[49m';\n\n\tstyles.color.ansi = wrapAnsi16();\n\tstyles.color.ansi256 = wrapAnsi256();\n\tstyles.color.ansi16m = wrapAnsi16m();\n\tstyles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);\n\n\t// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js\n\tObject.defineProperties(styles, {\n\t\trgbToAnsi256: {\n\t\t\tvalue(red, green, blue) {\n\t\t\t\t// We use the extended greyscale palette here, with the exception of\n\t\t\t\t// black and white. normal palette only has 4 greyscale shades.\n\t\t\t\tif (red === green && green === blue) {\n\t\t\t\t\tif (red < 8) {\n\t\t\t\t\t\treturn 16;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (red > 248) {\n\t\t\t\t\t\treturn 231;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn Math.round(((red - 8) / 247) * 24) + 232;\n\t\t\t\t}\n\n\t\t\t\treturn 16\n\t\t\t\t\t+ (36 * Math.round(red / 255 * 5))\n\t\t\t\t\t+ (6 * Math.round(green / 255 * 5))\n\t\t\t\t\t+ Math.round(blue / 255 * 5);\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToRgb: {\n\t\t\tvalue(hex) {\n\t\t\t\tconst matches = /[a-f\\d]{6}|[a-f\\d]{3}/i.exec(hex.toString(16));\n\t\t\t\tif (!matches) {\n\t\t\t\t\treturn [0, 0, 0];\n\t\t\t\t}\n\n\t\t\t\tlet [colorString] = matches;\n\n\t\t\t\tif (colorString.length === 3) {\n\t\t\t\t\tcolorString = [...colorString].map(character => character + character).join('');\n\t\t\t\t}\n\n\t\t\t\tconst integer = Number.parseInt(colorString, 16);\n\n\t\t\t\treturn [\n\t\t\t\t\t/* eslint-disable no-bitwise */\n\t\t\t\t\t(integer >> 16) & 0xFF,\n\t\t\t\t\t(integer >> 8) & 0xFF,\n\t\t\t\t\tinteger & 0xFF,\n\t\t\t\t\t/* eslint-enable no-bitwise */\n\t\t\t\t];\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi256: {\n\t\t\tvalue: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t\tansi256ToAnsi: {\n\t\t\tvalue(code) {\n\t\t\t\tif (code < 8) {\n\t\t\t\t\treturn 30 + code;\n\t\t\t\t}\n\n\t\t\t\tif (code < 16) {\n\t\t\t\t\treturn 90 + (code - 8);\n\t\t\t\t}\n\n\t\t\t\tlet red;\n\t\t\t\tlet green;\n\t\t\t\tlet blue;\n\n\t\t\t\tif (code >= 232) {\n\t\t\t\t\tred = (((code - 232) * 10) + 8) / 255;\n\t\t\t\t\tgreen = red;\n\t\t\t\t\tblue = red;\n\t\t\t\t} else {\n\t\t\t\t\tcode -= 16;\n\n\t\t\t\t\tconst remainder = code % 36;\n\n\t\t\t\t\tred = Math.floor(code / 36) / 5;\n\t\t\t\t\tgreen = Math.floor(remainder / 6) / 5;\n\t\t\t\t\tblue = (remainder % 6) / 5;\n\t\t\t\t}\n\n\t\t\t\tconst value = Math.max(red, green, blue) * 2;\n\n\t\t\t\tif (value === 0) {\n\t\t\t\t\treturn 30;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tlet result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));\n\n\t\t\t\tif (value === 2) {\n\t\t\t\t\tresult += 60;\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\trgbToAnsi: {\n\t\t\tvalue: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi: {\n\t\t\tvalue: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t});\n\n\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AO,SAAS,IAAI,CAAC;GAC1D,YAAY;EACZ;EACD,eAAe;GACd,MAAM,MAAM;AACX,QAAI,OAAO,EACV,QAAO,KAAK;AAGb,QAAI,OAAO,GACV,QAAO,MAAM,OAAO;IAGrB,IAAI;IACJ,IAAI;IACJ,IAAI;AAEJ,QAAI,QAAQ,KAAK;KAChB,QAAS,OAAO,OAAO,KAAM,KAAK;KAClC,QAAQ;KACR,OAAO;IACP,OAAM;KACN,QAAQ;KAER,MAAM,YAAY,OAAO;KAEzB,MAAM,KAAK,MAAM,OAAO,GAAG,GAAG;KAC9B,QAAQ,KAAK,MAAM,YAAY,EAAE,GAAG;KACpC,OAAQ,YAAY,IAAK;IACzB;IAED,MAAM,QAAQ,KAAK,IAAI,KAAK,OAAO,KAAK,GAAG;AAE3C,QAAI,UAAU,EACb,QAAO;IAIR,IAAI,SAAS,MAAO,KAAK,MAAM,KAAK,IAAI,IAAM,KAAK,MAAM,MAAM,IAAI,IAAK,KAAK,MAAM,IAAI;AAEvF,QAAI,UAAU,GACb,UAAU;AAGX,WAAO;GACP;GACD,YAAY;EACZ;EACD,WAAW;GACV,OAAO,CAAC,KAAK,OAAO,SAAS,OAAO,cAAc,OAAO,aAAa,KAAK,OAAO,KAAK,CAAC;GACxF,YAAY;EACZ;EACD,WAAW;GACV,OAAO,SAAO,OAAO,cAAc,OAAO,aAAa,IAAI,CAAC;GAC5D,YAAY;EACZ;CACD,EAAC;AAEF,QAAO;AACP;AAED,MAAM,aAAa,gBAAgB;AAEnC,0BAAe"}
@@ -0,0 +1,168 @@
1
+ //#region ../../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js
2
+ const ANSI_BACKGROUND_OFFSET = 10;
3
+ const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
4
+ const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
5
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
6
+ const styles = {
7
+ modifier: {
8
+ reset: [0, 0],
9
+ bold: [1, 22],
10
+ dim: [2, 22],
11
+ italic: [3, 23],
12
+ underline: [4, 24],
13
+ overline: [53, 55],
14
+ inverse: [7, 27],
15
+ hidden: [8, 28],
16
+ strikethrough: [9, 29]
17
+ },
18
+ color: {
19
+ black: [30, 39],
20
+ red: [31, 39],
21
+ green: [32, 39],
22
+ yellow: [33, 39],
23
+ blue: [34, 39],
24
+ magenta: [35, 39],
25
+ cyan: [36, 39],
26
+ white: [37, 39],
27
+ blackBright: [90, 39],
28
+ gray: [90, 39],
29
+ grey: [90, 39],
30
+ redBright: [91, 39],
31
+ greenBright: [92, 39],
32
+ yellowBright: [93, 39],
33
+ blueBright: [94, 39],
34
+ magentaBright: [95, 39],
35
+ cyanBright: [96, 39],
36
+ whiteBright: [97, 39]
37
+ },
38
+ bgColor: {
39
+ bgBlack: [40, 49],
40
+ bgRed: [41, 49],
41
+ bgGreen: [42, 49],
42
+ bgYellow: [43, 49],
43
+ bgBlue: [44, 49],
44
+ bgMagenta: [45, 49],
45
+ bgCyan: [46, 49],
46
+ bgWhite: [47, 49],
47
+ bgBlackBright: [100, 49],
48
+ bgGray: [100, 49],
49
+ bgGrey: [100, 49],
50
+ bgRedBright: [101, 49],
51
+ bgGreenBright: [102, 49],
52
+ bgYellowBright: [103, 49],
53
+ bgBlueBright: [104, 49],
54
+ bgMagentaBright: [105, 49],
55
+ bgCyanBright: [106, 49],
56
+ bgWhiteBright: [107, 49]
57
+ }
58
+ };
59
+ const modifierNames = Object.keys(styles.modifier);
60
+ const foregroundColorNames = Object.keys(styles.color);
61
+ const backgroundColorNames = Object.keys(styles.bgColor);
62
+ const colorNames = [...foregroundColorNames, ...backgroundColorNames];
63
+ function assembleStyles() {
64
+ const codes = /* @__PURE__ */ new Map();
65
+ for (const [groupName, group] of Object.entries(styles)) {
66
+ for (const [styleName, style] of Object.entries(group)) {
67
+ styles[styleName] = {
68
+ open: `\u001B[${style[0]}m`,
69
+ close: `\u001B[${style[1]}m`
70
+ };
71
+ group[styleName] = styles[styleName];
72
+ codes.set(style[0], style[1]);
73
+ }
74
+ Object.defineProperty(styles, groupName, {
75
+ value: group,
76
+ enumerable: false
77
+ });
78
+ }
79
+ Object.defineProperty(styles, "codes", {
80
+ value: codes,
81
+ enumerable: false
82
+ });
83
+ styles.color.close = "\x1B[39m";
84
+ styles.bgColor.close = "\x1B[49m";
85
+ styles.color.ansi = wrapAnsi16();
86
+ styles.color.ansi256 = wrapAnsi256();
87
+ styles.color.ansi16m = wrapAnsi16m();
88
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
89
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
90
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
91
+ Object.defineProperties(styles, {
92
+ rgbToAnsi256: {
93
+ value(red, green, blue) {
94
+ if (red === green && green === blue) {
95
+ if (red < 8) return 16;
96
+ if (red > 248) return 231;
97
+ return Math.round((red - 8) / 247 * 24) + 232;
98
+ }
99
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
100
+ },
101
+ enumerable: false
102
+ },
103
+ hexToRgb: {
104
+ value(hex) {
105
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
106
+ if (!matches) return [
107
+ 0,
108
+ 0,
109
+ 0
110
+ ];
111
+ let [colorString] = matches;
112
+ if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
113
+ const integer = Number.parseInt(colorString, 16);
114
+ return [
115
+ integer >> 16 & 255,
116
+ integer >> 8 & 255,
117
+ integer & 255
118
+ ];
119
+ },
120
+ enumerable: false
121
+ },
122
+ hexToAnsi256: {
123
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
124
+ enumerable: false
125
+ },
126
+ ansi256ToAnsi: {
127
+ value(code) {
128
+ if (code < 8) return 30 + code;
129
+ if (code < 16) return 90 + (code - 8);
130
+ let red;
131
+ let green;
132
+ let blue;
133
+ if (code >= 232) {
134
+ red = ((code - 232) * 10 + 8) / 255;
135
+ green = red;
136
+ blue = red;
137
+ } else {
138
+ code -= 16;
139
+ const remainder = code % 36;
140
+ red = Math.floor(code / 36) / 5;
141
+ green = Math.floor(remainder / 6) / 5;
142
+ blue = remainder % 6 / 5;
143
+ }
144
+ const value = Math.max(red, green, blue) * 2;
145
+ if (value === 0) return 30;
146
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
147
+ if (value === 2) result += 60;
148
+ return result;
149
+ },
150
+ enumerable: false
151
+ },
152
+ rgbToAnsi: {
153
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
154
+ enumerable: false
155
+ },
156
+ hexToAnsi: {
157
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
158
+ enumerable: false
159
+ }
160
+ });
161
+ return styles;
162
+ }
163
+ const ansiStyles = assembleStyles();
164
+ var ansi_styles_default = ansiStyles;
165
+
166
+ //#endregion
167
+ export { ansi_styles_default as default };
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js"],"sourcesContent":["const ANSI_BACKGROUND_OFFSET = 10;\n\nconst wrapAnsi16 = (offset = 0) => code => `\\u001B[${code + offset}m`;\n\nconst wrapAnsi256 = (offset = 0) => code => `\\u001B[${38 + offset};5;${code}m`;\n\nconst wrapAnsi16m = (offset = 0) => (red, green, blue) => `\\u001B[${38 + offset};2;${red};${green};${blue}m`;\n\nconst styles = {\n\tmodifier: {\n\t\treset: [0, 0],\n\t\t// 21 isn't widely supported and 22 does the same thing\n\t\tbold: [1, 22],\n\t\tdim: [2, 22],\n\t\titalic: [3, 23],\n\t\tunderline: [4, 24],\n\t\toverline: [53, 55],\n\t\tinverse: [7, 27],\n\t\thidden: [8, 28],\n\t\tstrikethrough: [9, 29],\n\t},\n\tcolor: {\n\t\tblack: [30, 39],\n\t\tred: [31, 39],\n\t\tgreen: [32, 39],\n\t\tyellow: [33, 39],\n\t\tblue: [34, 39],\n\t\tmagenta: [35, 39],\n\t\tcyan: [36, 39],\n\t\twhite: [37, 39],\n\n\t\t// Bright color\n\t\tblackBright: [90, 39],\n\t\tgray: [90, 39], // Alias of `blackBright`\n\t\tgrey: [90, 39], // Alias of `blackBright`\n\t\tredBright: [91, 39],\n\t\tgreenBright: [92, 39],\n\t\tyellowBright: [93, 39],\n\t\tblueBright: [94, 39],\n\t\tmagentaBright: [95, 39],\n\t\tcyanBright: [96, 39],\n\t\twhiteBright: [97, 39],\n\t},\n\tbgColor: {\n\t\tbgBlack: [40, 49],\n\t\tbgRed: [41, 49],\n\t\tbgGreen: [42, 49],\n\t\tbgYellow: [43, 49],\n\t\tbgBlue: [44, 49],\n\t\tbgMagenta: [45, 49],\n\t\tbgCyan: [46, 49],\n\t\tbgWhite: [47, 49],\n\n\t\t// Bright color\n\t\tbgBlackBright: [100, 49],\n\t\tbgGray: [100, 49], // Alias of `bgBlackBright`\n\t\tbgGrey: [100, 49], // Alias of `bgBlackBright`\n\t\tbgRedBright: [101, 49],\n\t\tbgGreenBright: [102, 49],\n\t\tbgYellowBright: [103, 49],\n\t\tbgBlueBright: [104, 49],\n\t\tbgMagentaBright: [105, 49],\n\t\tbgCyanBright: [106, 49],\n\t\tbgWhiteBright: [107, 49],\n\t},\n};\n\nexport const modifierNames = Object.keys(styles.modifier);\nexport const foregroundColorNames = Object.keys(styles.color);\nexport const backgroundColorNames = Object.keys(styles.bgColor);\nexport const colorNames = [...foregroundColorNames, ...backgroundColorNames];\n\nfunction assembleStyles() {\n\tconst codes = new Map();\n\n\tfor (const [groupName, group] of Object.entries(styles)) {\n\t\tfor (const [styleName, style] of Object.entries(group)) {\n\t\t\tstyles[styleName] = {\n\t\t\t\topen: `\\u001B[${style[0]}m`,\n\t\t\t\tclose: `\\u001B[${style[1]}m`,\n\t\t\t};\n\n\t\t\tgroup[styleName] = styles[styleName];\n\n\t\t\tcodes.set(style[0], style[1]);\n\t\t}\n\n\t\tObject.defineProperty(styles, groupName, {\n\t\t\tvalue: group,\n\t\t\tenumerable: false,\n\t\t});\n\t}\n\n\tObject.defineProperty(styles, 'codes', {\n\t\tvalue: codes,\n\t\tenumerable: false,\n\t});\n\n\tstyles.color.close = '\\u001B[39m';\n\tstyles.bgColor.close = '\\u001B[49m';\n\n\tstyles.color.ansi = wrapAnsi16();\n\tstyles.color.ansi256 = wrapAnsi256();\n\tstyles.color.ansi16m = wrapAnsi16m();\n\tstyles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);\n\tstyles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);\n\n\t// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js\n\tObject.defineProperties(styles, {\n\t\trgbToAnsi256: {\n\t\t\tvalue(red, green, blue) {\n\t\t\t\t// We use the extended greyscale palette here, with the exception of\n\t\t\t\t// black and white. normal palette only has 4 greyscale shades.\n\t\t\t\tif (red === green && green === blue) {\n\t\t\t\t\tif (red < 8) {\n\t\t\t\t\t\treturn 16;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (red > 248) {\n\t\t\t\t\t\treturn 231;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn Math.round(((red - 8) / 247) * 24) + 232;\n\t\t\t\t}\n\n\t\t\t\treturn 16\n\t\t\t\t\t+ (36 * Math.round(red / 255 * 5))\n\t\t\t\t\t+ (6 * Math.round(green / 255 * 5))\n\t\t\t\t\t+ Math.round(blue / 255 * 5);\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToRgb: {\n\t\t\tvalue(hex) {\n\t\t\t\tconst matches = /[a-f\\d]{6}|[a-f\\d]{3}/i.exec(hex.toString(16));\n\t\t\t\tif (!matches) {\n\t\t\t\t\treturn [0, 0, 0];\n\t\t\t\t}\n\n\t\t\t\tlet [colorString] = matches;\n\n\t\t\t\tif (colorString.length === 3) {\n\t\t\t\t\tcolorString = [...colorString].map(character => character + character).join('');\n\t\t\t\t}\n\n\t\t\t\tconst integer = Number.parseInt(colorString, 16);\n\n\t\t\t\treturn [\n\t\t\t\t\t/* eslint-disable no-bitwise */\n\t\t\t\t\t(integer >> 16) & 0xFF,\n\t\t\t\t\t(integer >> 8) & 0xFF,\n\t\t\t\t\tinteger & 0xFF,\n\t\t\t\t\t/* eslint-enable no-bitwise */\n\t\t\t\t];\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi256: {\n\t\t\tvalue: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t\tansi256ToAnsi: {\n\t\t\tvalue(code) {\n\t\t\t\tif (code < 8) {\n\t\t\t\t\treturn 30 + code;\n\t\t\t\t}\n\n\t\t\t\tif (code < 16) {\n\t\t\t\t\treturn 90 + (code - 8);\n\t\t\t\t}\n\n\t\t\t\tlet red;\n\t\t\t\tlet green;\n\t\t\t\tlet blue;\n\n\t\t\t\tif (code >= 232) {\n\t\t\t\t\tred = (((code - 232) * 10) + 8) / 255;\n\t\t\t\t\tgreen = red;\n\t\t\t\t\tblue = red;\n\t\t\t\t} else {\n\t\t\t\t\tcode -= 16;\n\n\t\t\t\t\tconst remainder = code % 36;\n\n\t\t\t\t\tred = Math.floor(code / 36) / 5;\n\t\t\t\t\tgreen = Math.floor(remainder / 6) / 5;\n\t\t\t\t\tblue = (remainder % 6) / 5;\n\t\t\t\t}\n\n\t\t\t\tconst value = Math.max(red, green, blue) * 2;\n\n\t\t\t\tif (value === 0) {\n\t\t\t\t\treturn 30;\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tlet result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));\n\n\t\t\t\tif (value === 2) {\n\t\t\t\t\tresult += 60;\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t},\n\t\trgbToAnsi: {\n\t\t\tvalue: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),\n\t\t\tenumerable: false,\n\t\t},\n\t\thexToAnsi: {\n\t\t\tvalue: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),\n\t\t\tenumerable: false,\n\t\t},\n\t});\n\n\treturn styles;\n}\n\nconst ansiStyles = assembleStyles();\n\nexport default ansiStyles;\n"],"x_google_ignoreList":[0],"mappings":";AAAA,MAAM,yBAAyB;AAE/B,MAAM,aAAa,CAAC,SAAS,MAAM,UAAQ,CAAC,OAAO,EAAE,OAAO,OAAO,CAAC,CAAC;AAErE,MAAM,cAAc,CAAC,SAAS,MAAM,UAAQ,CAAC,OAAO,EAAE,KAAK,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC;AAE9E,MAAM,cAAc,CAAC,SAAS,MAAM,CAAC,KAAK,OAAO,SAAS,CAAC,OAAO,EAAE,KAAK,OAAO,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;AAE5G,MAAM,SAAS;CACd,UAAU;EACT,OAAO,CAAC,GAAG,CAAE;EAEb,MAAM,CAAC,GAAG,EAAG;EACb,KAAK,CAAC,GAAG,EAAG;EACZ,QAAQ,CAAC,GAAG,EAAG;EACf,WAAW,CAAC,GAAG,EAAG;EAClB,UAAU,CAAC,IAAI,EAAG;EAClB,SAAS,CAAC,GAAG,EAAG;EAChB,QAAQ,CAAC,GAAG,EAAG;EACf,eAAe,CAAC,GAAG,EAAG;CACtB;CACD,OAAO;EACN,OAAO,CAAC,IAAI,EAAG;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EACD,WAAW;GACV,OAAO,SAAO,OAAO,cAAc,OAAO,aAAa,IAAI,CAAC;GAC5D,YAAY;EACZ;CACD,EAAC;AAEF,QAAO;AACP;AAED,MAAM,aAAa,gBAAgB;AAEnC,0BAAe"}
@@ -0,0 +1,122 @@
1
+
2
+ //#region ../../node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js
3
+ const UPPERCASE = /[\p{Lu}]/u;
4
+ const LOWERCASE = /[\p{Ll}]/u;
5
+ const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/u;
6
+ const SEPARATORS = /[_.\- ]+/;
7
+ const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
8
+ const LEADING_SEPARATORS = /* @__PURE__ */ new RegExp("^" + SEPARATORS.source);
9
+ const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
10
+ const NUMBERS_AND_IDENTIFIER = new RegExp(String.raw`\d+` + IDENTIFIER.source, "gu");
11
+ const preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase$1) => {
12
+ let isLastCharLower = false;
13
+ let isLastCharUpper = false;
14
+ let isLastLastCharUpper = false;
15
+ let isLastLastCharPreserved = false;
16
+ for (let index = 0; index < string.length; index++) {
17
+ const character = string[index];
18
+ isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
19
+ if (isLastCharLower && UPPERCASE.test(character)) {
20
+ string = string.slice(0, index) + "-" + string.slice(index);
21
+ isLastCharLower = false;
22
+ isLastLastCharUpper = isLastCharUpper;
23
+ isLastCharUpper = true;
24
+ index++;
25
+ } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase$1)) {
26
+ string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
27
+ isLastLastCharUpper = isLastCharUpper;
28
+ isLastCharUpper = false;
29
+ isLastCharLower = true;
30
+ } else {
31
+ isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
32
+ isLastLastCharUpper = isLastCharUpper;
33
+ isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
34
+ }
35
+ }
36
+ return string;
37
+ };
38
+ const preserveConsecutiveUppercase = (input, toLowerCase) => input.replace(LEADING_CAPITAL, (match) => toLowerCase(match));
39
+ const processWithCasePreservation = (input, toLowerCase, preserveConsecutiveUppercase$1) => {
40
+ let result = "";
41
+ let previousWasNumber = false;
42
+ let previousWasUppercase = false;
43
+ const characters = [...input];
44
+ for (let index = 0; index < characters.length; index++) {
45
+ const character = characters[index];
46
+ const isUpperCase = UPPERCASE.test(character);
47
+ const nextCharIsUpperCase = index + 1 < characters.length && UPPERCASE.test(characters[index + 1]);
48
+ if (previousWasNumber && /[\p{Alpha}]/u.test(character)) {
49
+ result += character;
50
+ previousWasNumber = false;
51
+ previousWasUppercase = isUpperCase;
52
+ } else if (preserveConsecutiveUppercase$1 && isUpperCase && (previousWasUppercase || nextCharIsUpperCase)) {
53
+ result += character;
54
+ previousWasUppercase = true;
55
+ } else if (/\d/.test(character)) {
56
+ result += character;
57
+ previousWasNumber = true;
58
+ previousWasUppercase = false;
59
+ } else if (SEPARATORS.test(character)) {
60
+ result += character;
61
+ previousWasUppercase = false;
62
+ } else {
63
+ result += toLowerCase(character);
64
+ previousWasNumber = false;
65
+ previousWasUppercase = false;
66
+ }
67
+ }
68
+ return result;
69
+ };
70
+ /**
71
+ Core post-processing:
72
+ - Collapses separators and uppercases the following identifier character.
73
+ - Optionally uppercases the identifier following a numeric sequence.
74
+
75
+ Two-pass strategy prevents conflicts:
76
+ 1. NUMBERS_AND_IDENTIFIER: handles digit-to-letter transitions
77
+ 2. SEPARATORS_AND_IDENTIFIER: handles separator-to-identifier transitions
78
+
79
+ Example: "b2b_registration" with capitalizeAfterNumber: true
80
+ - Pass 1: "2b" matches, next char is "_" (separator), so don't capitalize → "b2b_registration"
81
+ - Pass 2: "_r" matches, replace with "R" → "b2bRegistration"
82
+ */
83
+ const postProcess = (input, toUpperCase, { capitalizeAfterNumber }) => {
84
+ const transformNumericIdentifier = capitalizeAfterNumber ? (match, identifier, offset, string) => {
85
+ const nextCharacter = string.charAt(offset + match.length);
86
+ if (SEPARATORS.test(nextCharacter)) return match;
87
+ return identifier ? match.slice(0, -identifier.length) + toUpperCase(identifier) : match;
88
+ } : (match) => match;
89
+ return input.replaceAll(NUMBERS_AND_IDENTIFIER, transformNumericIdentifier).replaceAll(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));
90
+ };
91
+ function camelCase(input, options) {
92
+ if (!(typeof input === "string" || Array.isArray(input))) throw new TypeError("Expected the input to be `string | string[]`");
93
+ options = {
94
+ pascalCase: false,
95
+ preserveConsecutiveUppercase: false,
96
+ capitalizeAfterNumber: true,
97
+ ...options
98
+ };
99
+ if (Array.isArray(input)) input = input.map((element) => element.trim()).filter((element) => element.length > 0).join("-");
100
+ else input = input.trim();
101
+ if (input.length === 0) return "";
102
+ const leadingPrefix = input.match(/^[_$]*/)[0];
103
+ input = input.slice(leadingPrefix.length);
104
+ if (input.length === 0) return leadingPrefix;
105
+ const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
106
+ const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
107
+ if (input.length === 1) {
108
+ if (SEPARATORS.test(input)) return leadingPrefix;
109
+ return leadingPrefix + (options.pascalCase ? toUpperCase(input) : toLowerCase(input));
110
+ }
111
+ const hasUpperCase = input !== toLowerCase(input);
112
+ if (hasUpperCase) input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
113
+ input = input.replace(LEADING_SEPARATORS, "");
114
+ if (options.capitalizeAfterNumber) input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
115
+ else input = processWithCasePreservation(input, toLowerCase, options.preserveConsecutiveUppercase);
116
+ if (options.pascalCase && input.length > 0) input = toUpperCase(input[0]) + input.slice(1);
117
+ return leadingPrefix + postProcess(input, toUpperCase, options);
118
+ }
119
+
120
+ //#endregion
121
+ exports.camelCase = camelCase;
122
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["preserveConsecutiveUppercase"],"sources":["../../../../../../../../node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js"],"sourcesContent":["const UPPERCASE = /[\\p{Lu}]/u;\nconst LOWERCASE = /[\\p{Ll}]/u;\nconst LEADING_CAPITAL = /^[\\p{Lu}](?![\\p{Lu}])/u;\nconst SEPARATORS = /[_.\\- ]+/;\n\n// The |$ alternative allows matching at end-of-string, capturing empty string\n// This enables NUMBERS_AND_IDENTIFIER to match digits at string end (e.g., \"test123\")\nconst IDENTIFIER = /([\\p{Alpha}\\p{N}_]|$)/u;\n\nconst LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);\nconst SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');\nconst NUMBERS_AND_IDENTIFIER = new RegExp(String.raw`\\d+` + IDENTIFIER.source, 'gu');\n\nconst preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase) => {\n\tlet isLastCharLower = false;\n\tlet isLastCharUpper = false;\n\tlet isLastLastCharUpper = false;\n\tlet isLastLastCharPreserved = false;\n\n\tfor (let index = 0; index < string.length; index++) {\n\t\tconst character = string[index];\n\n\t\t// Was the character 3 positions back inserted as a separator?\n\t\t// Prevents excessive separators by checking if we recently inserted one\n\t\t// index - 3 accounts for: current character, inserted separator, previous character\n\t\t// Default true for early positions activates the preserveConsecutiveUppercase guard\n\t\tisLastLastCharPreserved = index > 2 ? string[index - 3] === '-' : true;\n\n\t\tif (isLastCharLower && UPPERCASE.test(character)) {\n\t\t\t// FooBar → Foo-Bar (insert separator before uppercase)\n\t\t\tstring = string.slice(0, index) + '-' + string.slice(index);\n\t\t\tisLastCharLower = false;\n\t\t\tisLastLastCharUpper = isLastCharUpper;\n\t\t\tisLastCharUpper = true;\n\t\t\tindex++;\n\t\t} else if (\n\t\t\tisLastCharUpper\n\t\t\t&& isLastLastCharUpper\n\t\t\t&& LOWERCASE.test(character)\n\t\t\t&& (!isLastLastCharPreserved || preserveConsecutiveUppercase)\n\t\t) {\n\t\t\t// FOOBar → FOO-Bar\n\t\t\tstring = string.slice(0, index - 1) + '-' + string.slice(index - 1);\n\t\t\tisLastLastCharUpper = isLastCharUpper;\n\t\t\tisLastCharUpper = false;\n\t\t\tisLastCharLower = true;\n\t\t} else {\n\t\t\tisLastCharLower\n\t\t\t\t= toLowerCase(character) === character\n\t\t\t\t\t&& toUpperCase(character) !== character;\n\t\t\tisLastLastCharUpper = isLastCharUpper;\n\t\t\tisLastCharUpper\n\t\t\t\t= toUpperCase(character) === character\n\t\t\t\t\t&& toLowerCase(character) !== character;\n\t\t}\n\t}\n\n\treturn string;\n};\n\nconst preserveConsecutiveUppercase = (input, toLowerCase) => input.replace(LEADING_CAPITAL, match => toLowerCase(match));\n\nconst processWithCasePreservation = (input, toLowerCase, preserveConsecutiveUppercase) => {\n\tlet result = '';\n\tlet previousWasNumber = false;\n\tlet previousWasUppercase = false;\n\n\t// Convert input to array for lookahead capability\n\tconst characters = [...input];\n\n\tfor (let index = 0; index < characters.length; index++) {\n\t\tconst character = characters[index];\n\t\tconst isUpperCase = UPPERCASE.test(character);\n\t\tconst nextCharIsUpperCase = index + 1 < characters.length && UPPERCASE.test(characters[index + 1]);\n\n\t\tif (previousWasNumber && /[\\p{Alpha}]/u.test(character)) {\n\t\t\t// Letter after number - preserve original case\n\t\t\tresult += character;\n\t\t\tpreviousWasNumber = false;\n\t\t\tpreviousWasUppercase = isUpperCase;\n\t\t} else if (preserveConsecutiveUppercase && isUpperCase && (previousWasUppercase || nextCharIsUpperCase)) {\n\t\t\t// Part of consecutive uppercase sequence when preserveConsecutiveUppercase is true - keep it\n\t\t\tresult += character;\n\t\t\tpreviousWasUppercase = true;\n\t\t} else if (/\\d/.test(character)) {\n\t\t\t// Number - keep as-is and track it\n\t\t\tresult += character;\n\t\t\tpreviousWasNumber = true;\n\t\t\tpreviousWasUppercase = false;\n\t\t} else if (SEPARATORS.test(character)) {\n\t\t\t// Separator - keep as-is and maintain previousWasNumber state\n\t\t\tresult += character;\n\t\t\tpreviousWasUppercase = false;\n\t\t} else {\n\t\t\t// Regular character - lowercase it\n\t\t\tresult += toLowerCase(character);\n\t\t\tpreviousWasNumber = false;\n\t\t\tpreviousWasUppercase = false;\n\t\t}\n\t}\n\n\treturn result;\n};\n\n/**\nCore post-processing:\n- Collapses separators and uppercases the following identifier character.\n- Optionally uppercases the identifier following a numeric sequence.\n\nTwo-pass strategy prevents conflicts:\n1. NUMBERS_AND_IDENTIFIER: handles digit-to-letter transitions\n2. SEPARATORS_AND_IDENTIFIER: handles separator-to-identifier transitions\n\nExample: \"b2b_registration\" with capitalizeAfterNumber: true\n- Pass 1: \"2b\" matches, next char is \"_\" (separator), so don't capitalize → \"b2b_registration\"\n- Pass 2: \"_r\" matches, replace with \"R\" → \"b2bRegistration\"\n*/\nconst postProcess = (input, toUpperCase, {capitalizeAfterNumber}) => {\n\tconst transformNumericIdentifier = capitalizeAfterNumber\n\t\t? (match, identifier, offset, string) => {\n\t\t\tconst nextCharacter = string.charAt(offset + match.length);\n\n\t\t\t// If the numeric+identifier run is immediately followed by a separator,\n\t\t\t// treat it as a continued token and do not force a new word.\n\t\t\tif (SEPARATORS.test(nextCharacter)) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Only uppercase the identifier part (not the digits) for efficiency\n\t\t\treturn identifier ? match.slice(0, -identifier.length) + toUpperCase(identifier) : match;\n\t\t}\n\t\t// When false: numbers do not create a word boundary.\n\t\t: match => match;\n\n\treturn input\n\t\t.replaceAll(NUMBERS_AND_IDENTIFIER, transformNumericIdentifier)\n\t\t.replaceAll(\n\t\t\tSEPARATORS_AND_IDENTIFIER,\n\t\t\t(_, identifier) => toUpperCase(identifier),\n\t\t);\n};\n\nexport default function camelCase(input, options) {\n\tif (!(typeof input === 'string' || Array.isArray(input))) {\n\t\tthrow new TypeError('Expected the input to be `string | string[]`');\n\t}\n\n\toptions = {\n\t\tpascalCase: false,\n\t\tpreserveConsecutiveUppercase: false,\n\t\tcapitalizeAfterNumber: true,\n\t\t...options,\n\t};\n\n\tif (Array.isArray(input)) {\n\t\tinput = input\n\t\t\t.map(element => element.trim())\n\t\t\t.filter(element => element.length > 0)\n\t\t\t.join('-');\n\t} else {\n\t\tinput = input.trim();\n\t}\n\n\tif (input.length === 0) {\n\t\treturn '';\n\t}\n\n\t// Preserve leading _ and $ as they have semantic meaning\n\tconst leadingPrefix = input.match(/^[_$]*/)[0];\n\tinput = input.slice(leadingPrefix.length);\n\n\tif (input.length === 0) {\n\t\treturn leadingPrefix;\n\t}\n\n\tconst toLowerCase = options.locale === false\n\t\t? string => string.toLowerCase()\n\t\t: string => string.toLocaleLowerCase(options.locale);\n\n\tconst toUpperCase = options.locale === false\n\t\t? string => string.toUpperCase()\n\t\t: string => string.toLocaleUpperCase(options.locale);\n\n\tif (input.length === 1) {\n\t\tif (SEPARATORS.test(input)) {\n\t\t\treturn leadingPrefix;\n\t\t}\n\n\t\treturn leadingPrefix + (options.pascalCase\n\t\t\t? toUpperCase(input)\n\t\t\t: toLowerCase(input));\n\t}\n\n\tconst hasUpperCase = input !== toLowerCase(input);\n\n\tif (hasUpperCase) {\n\t\tinput = preserveCamelCase(\n\t\t\tinput,\n\t\t\ttoLowerCase,\n\t\t\ttoUpperCase,\n\t\t\toptions.preserveConsecutiveUppercase,\n\t\t);\n\t}\n\n\t// Strip leading separators eagerly so they do not affect word detection\n\tinput = input.replace(LEADING_SEPARATORS, '');\n\n\t// Normalize base casing while preserving intended consecutive uppers\n\tif (options.capitalizeAfterNumber) {\n\t\t// Standard behavior - lowercase everything (or preserve consecutive uppercase)\n\t\tinput = options.preserveConsecutiveUppercase\n\t\t\t? preserveConsecutiveUppercase(input, toLowerCase)\n\t\t\t: toLowerCase(input);\n\t} else {\n\t\t// Preserve case after numbers (processWithCasePreservation handles preserveConsecutiveUppercase internally)\n\t\tinput = processWithCasePreservation(input, toLowerCase, options.preserveConsecutiveUppercase);\n\t}\n\n\tif (options.pascalCase && input.length > 0) {\n\t\tinput = toUpperCase(input[0]) + input.slice(1);\n\t}\n\n\treturn leadingPrefix + postProcess(input, toUpperCase, options);\n}\n"],"x_google_ignoreList":[0],"mappings":";;AAAA,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AACxB,MAAM,aAAa;AAInB,MAAM,aAAa;AAEnB,MAAM,qCAAqB,IAAI,OAAO,MAAM,WAAW;AACvD,MAAM,4BAA4B,IAAI,OAAO,WAAW,SAAS,WAAW,QAAQ;AACpF,MAAM,yBAAyB,IAAI,OAAO,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,QAAQ;AAE/E,MAAM,oBAAoB,CAAC,QAAQ,aAAa,aAAaA,mCAAiC;CAC7F,IAAI,kBAAkB;CACtB,IAAI,kBAAkB;CACtB,IAAI,sBAAsB;CAC1B,IAAI,0BAA0B;AAE9B,MAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;EACnD,MAAM,YAAY,OAAO;EAMzB,0BAA0B,QAAQ,IAAI,OAAO,QAAQ,OAAO,MAAM;AAElE,MAAI,mBAAmB,UAAU,KAAK,UAAU,EAAE;GAEjD,SAAS,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,OAAO,MAAM,MAAM;GAC3D,kBAAkB;GAClB,sBAAsB;GACtB,kBAAkB;GAClB;EACA,WACA,mBACG,uBACA,UAAU,KAAK,UAAU,KACxB,CAAC,2BAA2BA,iCAC/B;GAED,SAAS,OAAO,MAAM,GAAG,QAAQ,EAAE,GAAG,MAAM,OAAO,MAAM,QAAQ,EAAE;GACnE,sBAAsB;GACtB,kBAAkB;GAClB,kBAAkB;E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