@illuma-ai/agents 1.1.21 → 1.1.22

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 (241) hide show
  1. package/dist/cjs/graphs/Graph.cjs +12 -1
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/graphs/MultiAgentGraph.cjs +85 -1
  4. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  5. package/dist/cjs/run.cjs +20 -9
  6. package/dist/cjs/run.cjs.map +1 -1
  7. package/dist/esm/graphs/Graph.mjs +12 -1
  8. package/dist/esm/graphs/Graph.mjs.map +1 -1
  9. package/dist/esm/graphs/MultiAgentGraph.mjs +85 -1
  10. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  11. package/dist/esm/run.mjs +20 -9
  12. package/dist/esm/run.mjs.map +1 -1
  13. package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
  14. package/package.json +1 -1
  15. package/src/graphs/Graph.ts +12 -1
  16. package/src/graphs/MultiAgentGraph.ts +105 -1
  17. package/src/graphs/__tests__/multi-agent-delegate.test.ts +191 -0
  18. package/src/run.ts +20 -11
  19. package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
  20. package/src/agents/AgentContext.js +0 -782
  21. package/src/agents/AgentContext.test.js +0 -421
  22. package/src/agents/__tests__/AgentContext.test.js +0 -678
  23. package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
  24. package/src/common/enum.js +0 -192
  25. package/src/common/index.js +0 -3
  26. package/src/events.js +0 -166
  27. package/src/graphs/Graph.js +0 -1857
  28. package/src/graphs/MultiAgentGraph.js +0 -1092
  29. package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
  30. package/src/graphs/__tests__/structured-output.test.js +0 -144
  31. package/src/graphs/contextManagement.e2e.test.js +0 -718
  32. package/src/graphs/contextManagement.test.js +0 -485
  33. package/src/graphs/handoffValidation.test.js +0 -276
  34. package/src/graphs/index.js +0 -3
  35. package/src/index.js +0 -28
  36. package/src/instrumentation.js +0 -21
  37. package/src/llm/anthropic/index.js +0 -319
  38. package/src/llm/anthropic/types.js +0 -46
  39. package/src/llm/anthropic/utils/message_inputs.js +0 -627
  40. package/src/llm/anthropic/utils/message_outputs.js +0 -290
  41. package/src/llm/anthropic/utils/output_parsers.js +0 -89
  42. package/src/llm/anthropic/utils/tools.js +0 -25
  43. package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
  44. package/src/llm/bedrock/index.js +0 -303
  45. package/src/llm/bedrock/types.js +0 -2
  46. package/src/llm/bedrock/utils/index.js +0 -6
  47. package/src/llm/bedrock/utils/message_inputs.js +0 -463
  48. package/src/llm/bedrock/utils/message_outputs.js +0 -269
  49. package/src/llm/fake.js +0 -92
  50. package/src/llm/google/index.js +0 -215
  51. package/src/llm/google/types.js +0 -12
  52. package/src/llm/google/utils/common.js +0 -670
  53. package/src/llm/google/utils/tools.js +0 -111
  54. package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
  55. package/src/llm/openai/index.js +0 -1033
  56. package/src/llm/openai/types.js +0 -2
  57. package/src/llm/openai/utils/index.js +0 -756
  58. package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
  59. package/src/llm/openrouter/index.js +0 -261
  60. package/src/llm/openrouter/reasoning.test.js +0 -181
  61. package/src/llm/providers.js +0 -36
  62. package/src/llm/text.js +0 -65
  63. package/src/llm/vertexai/index.js +0 -402
  64. package/src/messages/__tests__/tools.test.js +0 -392
  65. package/src/messages/cache.js +0 -404
  66. package/src/messages/cache.test.js +0 -1167
  67. package/src/messages/content.js +0 -48
  68. package/src/messages/content.test.js +0 -314
  69. package/src/messages/core.js +0 -359
  70. package/src/messages/ensureThinkingBlock.test.js +0 -997
  71. package/src/messages/format.js +0 -973
  72. package/src/messages/formatAgentMessages.test.js +0 -2278
  73. package/src/messages/formatAgentMessages.tools.test.js +0 -362
  74. package/src/messages/formatMessage.test.js +0 -608
  75. package/src/messages/ids.js +0 -18
  76. package/src/messages/index.js +0 -9
  77. package/src/messages/labelContentByAgent.test.js +0 -725
  78. package/src/messages/prune.js +0 -438
  79. package/src/messages/reducer.js +0 -60
  80. package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
  81. package/src/messages/summarize.js +0 -146
  82. package/src/messages/summarize.test.js +0 -332
  83. package/src/messages/tools.js +0 -90
  84. package/src/mockStream.js +0 -81
  85. package/src/prompts/collab.js +0 -7
  86. package/src/prompts/index.js +0 -3
  87. package/src/prompts/taskmanager.js +0 -58
  88. package/src/run.js +0 -427
  89. package/src/schemas/index.js +0 -3
  90. package/src/schemas/schema-preparation.test.js +0 -370
  91. package/src/schemas/validate.js +0 -314
  92. package/src/schemas/validate.test.js +0 -264
  93. package/src/scripts/abort.js +0 -127
  94. package/src/scripts/ant_web_search.js +0 -130
  95. package/src/scripts/ant_web_search_edge_case.js +0 -133
  96. package/src/scripts/ant_web_search_error_edge_case.js +0 -119
  97. package/src/scripts/args.js +0 -41
  98. package/src/scripts/bedrock-cache-debug.js +0 -186
  99. package/src/scripts/bedrock-content-aggregation-test.js +0 -195
  100. package/src/scripts/bedrock-merge-test.js +0 -80
  101. package/src/scripts/bedrock-parallel-tools-test.js +0 -150
  102. package/src/scripts/caching.js +0 -106
  103. package/src/scripts/cli.js +0 -152
  104. package/src/scripts/cli2.js +0 -119
  105. package/src/scripts/cli3.js +0 -163
  106. package/src/scripts/cli4.js +0 -165
  107. package/src/scripts/cli5.js +0 -165
  108. package/src/scripts/code_exec.js +0 -171
  109. package/src/scripts/code_exec_files.js +0 -180
  110. package/src/scripts/code_exec_multi_session.js +0 -185
  111. package/src/scripts/code_exec_ptc.js +0 -265
  112. package/src/scripts/code_exec_session.js +0 -217
  113. package/src/scripts/code_exec_simple.js +0 -120
  114. package/src/scripts/content.js +0 -111
  115. package/src/scripts/empty_input.js +0 -125
  116. package/src/scripts/handoff-test.js +0 -96
  117. package/src/scripts/image.js +0 -138
  118. package/src/scripts/memory.js +0 -83
  119. package/src/scripts/multi-agent-chain.js +0 -271
  120. package/src/scripts/multi-agent-conditional.js +0 -185
  121. package/src/scripts/multi-agent-document-review-chain.js +0 -171
  122. package/src/scripts/multi-agent-hybrid-flow.js +0 -264
  123. package/src/scripts/multi-agent-parallel-start.js +0 -214
  124. package/src/scripts/multi-agent-parallel.js +0 -346
  125. package/src/scripts/multi-agent-sequence.js +0 -184
  126. package/src/scripts/multi-agent-supervisor.js +0 -324
  127. package/src/scripts/multi-agent-test.js +0 -147
  128. package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
  129. package/src/scripts/parallel-full-metadata-test.js +0 -176
  130. package/src/scripts/parallel-tools-test.js +0 -256
  131. package/src/scripts/programmatic_exec.js +0 -277
  132. package/src/scripts/programmatic_exec_agent.js +0 -168
  133. package/src/scripts/search.js +0 -118
  134. package/src/scripts/sequential-full-metadata-test.js +0 -143
  135. package/src/scripts/simple.js +0 -174
  136. package/src/scripts/single-agent-metadata-test.js +0 -152
  137. package/src/scripts/stream.js +0 -113
  138. package/src/scripts/test-custom-prompt-key.js +0 -132
  139. package/src/scripts/test-handoff-input.js +0 -143
  140. package/src/scripts/test-handoff-preamble.js +0 -227
  141. package/src/scripts/test-handoff-steering.js +0 -353
  142. package/src/scripts/test-multi-agent-list-handoff.js +0 -318
  143. package/src/scripts/test-parallel-agent-labeling.js +0 -253
  144. package/src/scripts/test-parallel-handoffs.js +0 -229
  145. package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
  146. package/src/scripts/test-thinking-handoff.js +0 -132
  147. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
  148. package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
  149. package/src/scripts/test-tools-before-handoff.js +0 -187
  150. package/src/scripts/test_code_api.js +0 -263
  151. package/src/scripts/thinking-bedrock.js +0 -128
  152. package/src/scripts/thinking-vertexai.js +0 -130
  153. package/src/scripts/thinking.js +0 -134
  154. package/src/scripts/tool_search.js +0 -114
  155. package/src/scripts/tools.js +0 -125
  156. package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
  157. package/src/specs/agent-handoffs.test.js +0 -924
  158. package/src/specs/anthropic.simple.test.js +0 -287
  159. package/src/specs/azure.simple.test.js +0 -381
  160. package/src/specs/cache.simple.test.js +0 -282
  161. package/src/specs/custom-event-await.test.js +0 -148
  162. package/src/specs/deepseek.simple.test.js +0 -189
  163. package/src/specs/emergency-prune.test.js +0 -308
  164. package/src/specs/moonshot.simple.test.js +0 -237
  165. package/src/specs/observability.integration.test.js +0 -1337
  166. package/src/specs/openai.simple.test.js +0 -233
  167. package/src/specs/openrouter.simple.test.js +0 -202
  168. package/src/specs/prune.test.js +0 -733
  169. package/src/specs/reasoning.test.js +0 -144
  170. package/src/specs/spec.utils.js +0 -4
  171. package/src/specs/thinking-handoff.test.js +0 -486
  172. package/src/specs/thinking-prune.test.js +0 -600
  173. package/src/specs/token-distribution-edge-case.test.js +0 -246
  174. package/src/specs/token-memoization.test.js +0 -32
  175. package/src/specs/tokens.test.js +0 -49
  176. package/src/specs/tool-error.test.js +0 -139
  177. package/src/splitStream.js +0 -204
  178. package/src/splitStream.test.js +0 -504
  179. package/src/stream.js +0 -650
  180. package/src/stream.test.js +0 -225
  181. package/src/test/mockTools.js +0 -340
  182. package/src/tools/BrowserTools.js +0 -245
  183. package/src/tools/Calculator.js +0 -38
  184. package/src/tools/Calculator.test.js +0 -225
  185. package/src/tools/CodeExecutor.js +0 -233
  186. package/src/tools/ProgrammaticToolCalling.js +0 -602
  187. package/src/tools/StreamingToolCallBuffer.js +0 -179
  188. package/src/tools/ToolNode.js +0 -930
  189. package/src/tools/ToolSearch.js +0 -904
  190. package/src/tools/__tests__/BrowserTools.test.js +0 -306
  191. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
  192. package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
  193. package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
  194. package/src/tools/__tests__/ToolApproval.test.js +0 -675
  195. package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
  196. package/src/tools/__tests__/ToolNode.session.test.js +0 -319
  197. package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
  198. package/src/tools/__tests__/ToolSearch.test.js +0 -812
  199. package/src/tools/__tests__/handlers.test.js +0 -799
  200. package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
  201. package/src/tools/handlers.js +0 -306
  202. package/src/tools/schema.js +0 -25
  203. package/src/tools/search/anthropic.js +0 -34
  204. package/src/tools/search/content.js +0 -116
  205. package/src/tools/search/content.test.js +0 -133
  206. package/src/tools/search/firecrawl.js +0 -173
  207. package/src/tools/search/format.js +0 -198
  208. package/src/tools/search/highlights.js +0 -241
  209. package/src/tools/search/index.js +0 -3
  210. package/src/tools/search/jina-reranker.test.js +0 -106
  211. package/src/tools/search/rerankers.js +0 -165
  212. package/src/tools/search/schema.js +0 -102
  213. package/src/tools/search/search.js +0 -561
  214. package/src/tools/search/serper-scraper.js +0 -126
  215. package/src/tools/search/test.js +0 -129
  216. package/src/tools/search/tool.js +0 -453
  217. package/src/tools/search/types.js +0 -2
  218. package/src/tools/search/utils.js +0 -59
  219. package/src/types/graph.js +0 -24
  220. package/src/types/graph.test.js +0 -192
  221. package/src/types/index.js +0 -7
  222. package/src/types/llm.js +0 -2
  223. package/src/types/messages.js +0 -2
  224. package/src/types/run.js +0 -2
  225. package/src/types/stream.js +0 -2
  226. package/src/types/tools.js +0 -2
  227. package/src/utils/contextAnalytics.js +0 -79
  228. package/src/utils/contextAnalytics.test.js +0 -166
  229. package/src/utils/events.js +0 -26
  230. package/src/utils/graph.js +0 -11
  231. package/src/utils/handlers.js +0 -65
  232. package/src/utils/index.js +0 -10
  233. package/src/utils/llm.js +0 -21
  234. package/src/utils/llmConfig.js +0 -205
  235. package/src/utils/logging.js +0 -37
  236. package/src/utils/misc.js +0 -51
  237. package/src/utils/run.js +0 -69
  238. package/src/utils/schema.js +0 -21
  239. package/src/utils/title.js +0 -119
  240. package/src/utils/tokens.js +0 -92
  241. package/src/utils/toonFormat.js +0 -379
@@ -1,205 +0,0 @@
1
- // src/utils/llmConfig.ts
2
- import { Providers } from '@/common';
3
- export const llmConfigs = {
4
- [Providers.OPENAI]: {
5
- provider: Providers.OPENAI,
6
- model: 'gpt-4.1',
7
- // temperature: 0.7,
8
- streaming: true,
9
- streamUsage: true,
10
- // disableStreaming: true,
11
- },
12
- anthropicLITELLM: {
13
- provider: Providers.OPENAI,
14
- streaming: true,
15
- streamUsage: false,
16
- apiKey: 'sk-1234',
17
- model: 'claude-sonnet-4',
18
- maxTokens: 8192,
19
- modelKwargs: {
20
- metadata: {
21
- user_id: 'some_user_id',
22
- },
23
- thinking: {
24
- type: 'enabled',
25
- budget_tokens: 2000,
26
- },
27
- },
28
- configuration: {
29
- baseURL: 'http://host.docker.internal:4000/v1',
30
- defaultHeaders: {
31
- 'anthropic-beta': 'prompt-caching-2024-07-31,context-1m-2025-08-07',
32
- },
33
- },
34
- // disableStreaming: true,
35
- },
36
- [Providers.XAI]: {
37
- provider: Providers.XAI,
38
- model: 'grok-2-latest',
39
- streaming: true,
40
- streamUsage: true,
41
- },
42
- alibaba: {
43
- provider: Providers.OPENAI,
44
- streaming: true,
45
- streamUsage: true,
46
- model: 'qwen-max',
47
- openAIApiKey: process.env.ALIBABA_API_KEY,
48
- configuration: {
49
- baseURL: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1',
50
- },
51
- },
52
- [Providers.OPENROUTER]: {
53
- provider: Providers.OPENROUTER,
54
- streaming: true,
55
- streamUsage: true,
56
- // model: 'anthropic/claude-sonnet-4',
57
- // model: 'moonshotai/kimi-k2-thinking',
58
- model: 'google/gemini-3-pro-preview',
59
- apiKey: process.env.OPENROUTER_API_KEY,
60
- configuration: {
61
- baseURL: process.env.OPENROUTER_BASE_URL,
62
- defaultHeaders: {
63
- 'HTTP-Referer': 'https://illuma.ai',
64
- 'X-Title': 'Illuma',
65
- },
66
- },
67
- reasoning: {
68
- max_tokens: 8000,
69
- },
70
- modelKwargs: {
71
- max_tokens: 10000,
72
- },
73
- },
74
- [Providers.AZURE]: {
75
- provider: Providers.AZURE,
76
- temperature: 0.7,
77
- streaming: true,
78
- streamUsage: true,
79
- azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
80
- azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE,
81
- azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT,
82
- azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
83
- model: process.env.AZURE_MODEL_NAME ?? 'gpt-4o',
84
- },
85
- ollama: {
86
- provider: Providers.OPENAI,
87
- model: 'gpt-oss:20b',
88
- streaming: true,
89
- streamUsage: true,
90
- configuration: {
91
- baseURL: 'http://localhost:11434/v1',
92
- },
93
- },
94
- lmstudio: {
95
- provider: Providers.OPENAI,
96
- model: 'gpt-oss-20b',
97
- streaming: true,
98
- streamUsage: true,
99
- configuration: {
100
- baseURL: 'http://192.168.254.183:1233/v1',
101
- },
102
- },
103
- zhipu: {
104
- provider: Providers.OPENAI,
105
- streaming: true,
106
- streamUsage: false,
107
- model: 'glm-4.5-air',
108
- apiKey: process.env.ZHIPU_API_KEY,
109
- configuration: {
110
- baseURL: 'https://open.bigmodel.cn/api/paas/v4',
111
- },
112
- },
113
- [Providers.DEEPSEEK]: {
114
- provider: Providers.DEEPSEEK,
115
- model: 'deepseek-reasoner',
116
- streaming: true,
117
- streamUsage: true,
118
- },
119
- [Providers.MOONSHOT]: {
120
- provider: Providers.MOONSHOT,
121
- model: 'kimi-k2.5',
122
- streaming: true,
123
- streamUsage: true,
124
- configuration: {
125
- apiKey: process.env.MOONSHOT_API_KEY,
126
- baseURL: 'https://api.moonshot.ai/v1',
127
- },
128
- },
129
- [Providers.ANTHROPIC]: {
130
- provider: Providers.ANTHROPIC,
131
- model: 'claude-sonnet-4-5',
132
- streaming: true,
133
- streamUsage: true,
134
- },
135
- // [Providers.MISTRALAI]: {
136
- // provider: Providers.MISTRALAI,
137
- // model: 'mistral-large-latest',
138
- // streaming: true,
139
- // streamUsage: true,
140
- // },
141
- [Providers.MISTRAL]: {
142
- provider: Providers.OPENAI,
143
- streaming: true,
144
- streamUsage: false,
145
- // model: 'codestral-latest',
146
- model: 'mistral-large-latest',
147
- openAIApiKey: process.env.MISTRAL_API_KEY,
148
- configuration: {
149
- baseURL: 'https://api.mistral.ai/v1',
150
- defaultHeaders: {},
151
- },
152
- },
153
- [Providers.VERTEXAI]: {
154
- provider: Providers.VERTEXAI,
155
- model: 'gemini-2.5-flash',
156
- // model: 'gemini-2.5-pro',
157
- streaming: true,
158
- streamUsage: true,
159
- keyFile: process.env.VERTEXAI_KEY_FILE,
160
- // maxRetries: 2,
161
- // location: 'global',
162
- // thinkingBudget: -1,
163
- // includeThoughts: true,
164
- },
165
- [Providers.GOOGLE]: {
166
- provider: Providers.GOOGLE,
167
- model: 'gemini-2.5-flash',
168
- streaming: true,
169
- streamUsage: true,
170
- },
171
- [Providers.BEDROCK]: {
172
- provider: Providers.BEDROCK,
173
- // model: 'anthropic.claude-3-sonnet-20240229-v1:0',
174
- // model: 'us.anthropic.claude-3-5-sonnet-20241022-v2:0',
175
- // model: 'us.amazon.nova-pro-v1:0',
176
- // model: 'us.anthropic.claude-sonnet-4-20250514-v1:0',
177
- model: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0',
178
- // additionalModelRequestFields: { thinking: { type: 'enabled', budget_tokens: 2000 } },
179
- region: process.env.BEDROCK_AWS_REGION,
180
- credentials: {
181
- accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID,
182
- secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY,
183
- },
184
- streaming: true,
185
- streamUsage: true,
186
- },
187
- perplexity: {
188
- provider: Providers.OPENAI,
189
- model: 'llama-3.1-sonar-small-128k-online',
190
- streaming: true,
191
- streamUsage: true,
192
- apiKey: process.env.PERPLEXITY_API_KEY,
193
- configuration: {
194
- baseURL: 'https://api.perplexity.ai/',
195
- },
196
- },
197
- };
198
- export function getLLMConfig(provider) {
199
- const config = llmConfigs[provider];
200
- if (config === undefined) {
201
- throw new Error(`Unsupported provider: ${provider}`);
202
- }
203
- return config;
204
- }
205
- //# sourceMappingURL=llmConfig.js.map
@@ -1,37 +0,0 @@
1
- // src/utils/logging.ts
2
- import fs from 'fs';
3
- import util from 'util';
4
- export function setupLogging(logFileName) {
5
- const logFile = fs.createWriteStream(logFileName, { flags: 'a' });
6
- const originalConsoleLog = console.log;
7
- const originalConsoleError = console.error;
8
- const originalStdoutWrite = process.stdout.write;
9
- const originalStderrWrite = process.stderr.write;
10
- console.log = function (...args) {
11
- logFile.write(util.format.apply(null, args) + ' ');
12
- originalConsoleLog.apply(console, args);
13
- };
14
- console.error = function (...args) {
15
- logFile.write(util.format.apply(null, args) + ' ');
16
- originalConsoleError.apply(console, args);
17
- };
18
- process.stdout.write = function (buffer, cb, fd) {
19
- if (typeof buffer === 'string') {
20
- logFile.write(buffer);
21
- }
22
- else {
23
- logFile.write(buffer.toString());
24
- }
25
- return originalStdoutWrite.call(process.stdout, buffer, cb, fd);
26
- };
27
- process.stderr.write = function (buffer, cb, fd) {
28
- if (typeof buffer === 'string') {
29
- logFile.write(buffer);
30
- }
31
- else {
32
- logFile.write(buffer.toString());
33
- }
34
- return originalStderrWrite.call(process.stderr, buffer, cb, fd);
35
- };
36
- }
37
- //# sourceMappingURL=logging.js.map
package/src/utils/misc.js DELETED
@@ -1,51 +0,0 @@
1
- export function isPresent(value) {
2
- return value != null && value !== '';
3
- }
4
- /**
5
- * Unescapes a c-escaped string
6
- * @param str The string to unescape
7
- * @returns The unescaped string
8
- */
9
- const unescapeString = (string) => string.replace(/\\(.)/g, (_, char) => {
10
- switch (char) {
11
- case 'n':
12
- return '\n';
13
- case 't':
14
- return '\t';
15
- case 'r':
16
- return '\r';
17
- case '"':
18
- return '"';
19
- case '\'':
20
- return '\'';
21
- case '\\':
22
- return '\\';
23
- default:
24
- return char;
25
- }
26
- });
27
- /**
28
- * Recursively unescapes all string values in an object
29
- * @param obj The object to unescape
30
- * @returns The unescaped object
31
- */
32
- export function unescapeObject(obj, key) {
33
- if (typeof obj === 'string') {
34
- let unescaped = unescapeString(obj);
35
- if (key === 'filePath' && unescaped.match(/^"(.+)"$/)) {
36
- unescaped = unescaped.substring(1, unescaped.length - 1);
37
- }
38
- return unescaped;
39
- }
40
- if (Array.isArray(obj)) {
41
- return obj.map((value) => unescapeObject(value, key === 'contextPaths' ? 'filePath' : ''));
42
- }
43
- if (typeof obj === 'object' && obj !== null) {
44
- return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
45
- key,
46
- unescapeObject(value, key),
47
- ]));
48
- }
49
- return obj;
50
- }
51
- //# sourceMappingURL=misc.js.map
package/src/utils/run.js DELETED
@@ -1,69 +0,0 @@
1
- import { mergeConfigs, patchConfig, Runnable, } from '@langchain/core/runnables';
2
- import { AsyncLocalStorageProviderSingleton } from '@langchain/core/singletons';
3
- /**
4
- * Delays the execution for a specified number of milliseconds.
5
- *
6
- * @param {number} ms - The number of milliseconds to delay.
7
- * @return {Promise<void>} A promise that resolves after the specified delay.
8
- */
9
- export function sleep(ms) {
10
- return new Promise((resolve) => setTimeout(resolve, ms));
11
- }
12
- export class RunnableCallable extends Runnable {
13
- lc_namespace = ['langgraph'];
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- func;
16
- tags;
17
- config;
18
- trace = true;
19
- recurse = true;
20
- constructor(fields) {
21
- super();
22
- this.name = fields.name ?? fields.func.name;
23
- this.func = fields.func;
24
- this.config = fields.tags ? { tags: fields.tags } : undefined;
25
- this.trace = fields.trace ?? this.trace;
26
- this.recurse = fields.recurse ?? this.recurse;
27
- }
28
- async _tracedInvoke(input, config, runManager) {
29
- return new Promise((resolve, reject) => {
30
- // Defensive check: ensure runManager has getChild method before calling
31
- const childCallbacks = typeof runManager?.getChild === 'function'
32
- ? runManager.getChild()
33
- : undefined;
34
- let childConfig = patchConfig(config, {
35
- callbacks: childCallbacks,
36
- });
37
- void AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
38
- try {
39
- const output = await this.func(input, childConfig);
40
- childConfig = null;
41
- resolve(output);
42
- }
43
- catch (e) {
44
- childConfig = null;
45
- reject(e);
46
- }
47
- });
48
- });
49
- }
50
- async invoke(
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- input, options
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- ) {
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- let returnValue;
57
- if (this.trace) {
58
- returnValue = await this._callWithConfig(this._tracedInvoke, input, mergeConfigs(this.config, options));
59
- }
60
- else {
61
- returnValue = await this.func(input, mergeConfigs(this.config, options));
62
- }
63
- if (Runnable.isRunnable(returnValue) && this.recurse) {
64
- return await returnValue.invoke(input, options);
65
- }
66
- return returnValue;
67
- }
68
- }
69
- //# sourceMappingURL=run.js.map
@@ -1,21 +0,0 @@
1
- // src/utils/schema.ts
2
- import { zodToJsonSchema } from 'zod-to-json-schema';
3
- /** Checks if a schema is a Zod schema by looking for the _def property */
4
- export function isZodSchema(schema) {
5
- return (schema != null && typeof schema === 'object' && '_def' in schema);
6
- }
7
- /**
8
- * Converts a schema to JSON schema format.
9
- * Handles both Zod schemas (converts) and JSON schemas (passthrough).
10
- */
11
- export function toJsonSchema(schema, name, description) {
12
- if (isZodSchema(schema)) {
13
- const zodSchema = schema;
14
- const described = description != null && description !== ''
15
- ? zodSchema.describe(description)
16
- : schema;
17
- return zodToJsonSchema(described, name ?? '');
18
- }
19
- return schema;
20
- }
21
- //# sourceMappingURL=schema.js.map
@@ -1,119 +0,0 @@
1
- import { ChatPromptTemplate } from '@langchain/core/prompts';
2
- import { RunnableLambda, RunnableSequence } from '@langchain/core/runnables';
3
- import { ContentTypes } from '@/common';
4
- const defaultTitlePrompt = `Analyze this conversation and provide:
5
- 1. The detected language of the conversation
6
- 2. A concise title in the detected language (5 words or less, no punctuation or quotation)
7
-
8
- {convo}`;
9
- const titleSchema = {
10
- type: 'object',
11
- properties: {
12
- title: {
13
- type: 'string',
14
- description: 'A concise title for the conversation in 5 words or less, without punctuation or quotation',
15
- },
16
- },
17
- required: ['title'],
18
- };
19
- const combinedSchema = {
20
- type: 'object',
21
- properties: {
22
- language: {
23
- type: 'string',
24
- description: 'The detected language of the conversation',
25
- },
26
- title: {
27
- type: 'string',
28
- description: 'A concise title for the conversation in 5 words or less, without punctuation or quotation',
29
- },
30
- },
31
- required: ['language', 'title'],
32
- };
33
- export const createTitleRunnable = async (model, _titlePrompt) => {
34
- // Disabled since this works fine
35
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36
- /* @ts-ignore */
37
- const titleLLM = model.withStructuredOutput(titleSchema);
38
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
- /* @ts-ignore */
40
- const combinedLLM = model.withStructuredOutput(combinedSchema);
41
- const titlePrompt = ChatPromptTemplate.fromTemplate(_titlePrompt ?? defaultTitlePrompt).withConfig({ runName: 'TitlePrompt' });
42
- const titleOnlyInnerChain = RunnableSequence.from([titlePrompt, titleLLM]);
43
- const combinedInnerChain = RunnableSequence.from([titlePrompt, combinedLLM]);
44
- /** Wrap titleOnlyChain in RunnableLambda to create parent span */
45
- const titleOnlyChain = new RunnableLambda({
46
- func: async (input, config) => {
47
- const result = await titleOnlyInnerChain.invoke(input, config);
48
- return result;
49
- },
50
- }).withConfig({ runName: 'TitleOnlyChain' });
51
- /** Wrap combinedChain in RunnableLambda to create parent span */
52
- const combinedChain = new RunnableLambda({
53
- func: async (input, config) => {
54
- const result = await combinedInnerChain.invoke(input, config);
55
- return result;
56
- },
57
- }).withConfig({ runName: 'TitleLanguageChain' });
58
- /** Runnable to add default values if needed */
59
- const addDefaults = new RunnableLambda({
60
- func: (result) => ({
61
- language: result?.language ?? 'English',
62
- title: result?.title ?? '',
63
- }),
64
- }).withConfig({ runName: 'AddDefaults' });
65
- const combinedChainInner = RunnableSequence.from([
66
- combinedChain,
67
- addDefaults,
68
- ]);
69
- /** Wrap combinedChainWithDefaults in RunnableLambda to create parent span */
70
- const combinedChainWithDefaults = new RunnableLambda({
71
- func: async (input, config) => {
72
- return await combinedChainInner.invoke(input, config);
73
- },
74
- }).withConfig({ runName: 'CombinedChainWithDefaults' });
75
- return new RunnableLambda({
76
- func: async (input, config) => {
77
- const invokeInput = { convo: input.convo };
78
- if (input.skipLanguage) {
79
- return (await titleOnlyChain.invoke(invokeInput, config));
80
- }
81
- return await combinedChainWithDefaults.invoke(invokeInput, config);
82
- },
83
- }).withConfig({ runName: 'TitleGenerator' });
84
- };
85
- const defaultCompletionPrompt = `Provide a concise, 5-word-or-less title for the conversation, using title case conventions. Only return the title itself.
86
-
87
- Conversation:
88
- {convo}`;
89
- export const createCompletionTitleRunnable = async (model, titlePrompt) => {
90
- const completionPrompt = ChatPromptTemplate.fromTemplate(titlePrompt ?? defaultCompletionPrompt).withConfig({ runName: 'CompletionTitlePrompt' });
91
- /** Runnable to extract content from model response */
92
- const extractContent = new RunnableLambda({
93
- func: (response) => {
94
- let content = '';
95
- if (typeof response.content === 'string') {
96
- content = response.content;
97
- }
98
- else if (Array.isArray(response.content)) {
99
- content = response.content
100
- .filter((part) => part.type === ContentTypes.TEXT)
101
- .map((part) => part.text)
102
- .join('');
103
- }
104
- return { title: content.trim() };
105
- },
106
- }).withConfig({ runName: 'ExtractTitle' });
107
- const innerChain = RunnableSequence.from([
108
- completionPrompt,
109
- model,
110
- extractContent,
111
- ]);
112
- /** Wrap in RunnableLambda to create a parent span for LangFuse */
113
- return new RunnableLambda({
114
- func: async (input, config) => {
115
- return await innerChain.invoke(input, config);
116
- },
117
- }).withConfig({ runName: 'CompletionTitleChain' });
118
- };
119
- //# sourceMappingURL=title.js.map
@@ -1,92 +0,0 @@
1
- import { Tokenizer } from 'ai-tokenizer';
2
- import { ContentTypes } from '@/common/enum';
3
- const tokenizers = {};
4
- async function getTokenizer(encoding = 'o200k_base') {
5
- const cached = tokenizers[encoding];
6
- if (cached) {
7
- return cached;
8
- }
9
- const data = encoding === 'claude'
10
- ? await import('ai-tokenizer/encoding/claude')
11
- : await import('ai-tokenizer/encoding/o200k_base');
12
- const instance = new Tokenizer(data);
13
- tokenizers[encoding] = instance;
14
- return instance;
15
- }
16
- export function encodingForModel(model) {
17
- if (model.toLowerCase().includes('claude')) {
18
- return 'claude';
19
- }
20
- return 'o200k_base';
21
- }
22
- export function getTokenCountForMessage(message, getTokenCount) {
23
- const tokensPerMessage = 3;
24
- const processValue = (value) => {
25
- if (Array.isArray(value)) {
26
- for (const item of value) {
27
- if (!item ||
28
- !item.type ||
29
- item.type === ContentTypes.ERROR ||
30
- item.type === ContentTypes.IMAGE_URL) {
31
- continue;
32
- }
33
- if (item.type === ContentTypes.TOOL_CALL && item.tool_call != null) {
34
- const toolName = item.tool_call?.name || '';
35
- if (toolName != null && toolName && typeof toolName === 'string') {
36
- numTokens += getTokenCount(toolName);
37
- }
38
- const args = item.tool_call?.args || '';
39
- if (args != null && args && typeof args === 'string') {
40
- numTokens += getTokenCount(args);
41
- }
42
- const output = item.tool_call?.output || '';
43
- if (output != null && output && typeof output === 'string') {
44
- numTokens += getTokenCount(output);
45
- }
46
- continue;
47
- }
48
- const nestedValue = item[item.type];
49
- if (!nestedValue) {
50
- continue;
51
- }
52
- processValue(nestedValue);
53
- }
54
- }
55
- else if (typeof value === 'string') {
56
- numTokens += getTokenCount(value);
57
- }
58
- else if (typeof value === 'number') {
59
- numTokens += getTokenCount(value.toString());
60
- }
61
- else if (typeof value === 'boolean') {
62
- numTokens += getTokenCount(value.toString());
63
- }
64
- };
65
- let numTokens = tokensPerMessage;
66
- processValue(message.content);
67
- return numTokens;
68
- }
69
- /**
70
- * Creates a token counter function using the specified encoding.
71
- * Lazily loads the encoding data on first use via dynamic import.
72
- */
73
- export const createTokenCounter = async (encoding = 'o200k_base') => {
74
- const tok = await getTokenizer(encoding);
75
- const countTokens = (text) => tok.count(text);
76
- return (message) => getTokenCountForMessage(message, countTokens);
77
- };
78
- /** Utility to manage the token encoder lifecycle explicitly. */
79
- export const TokenEncoderManager = {
80
- async initialize() {
81
- // No-op: ai-tokenizer is synchronously initialized from bundled data.
82
- },
83
- reset() {
84
- for (const key of Object.keys(tokenizers)) {
85
- delete tokenizers[key];
86
- }
87
- },
88
- isInitialized() {
89
- return Object.keys(tokenizers).length > 0;
90
- },
91
- };
92
- //# sourceMappingURL=tokens.js.map