@illuma-ai/agents 1.1.21 → 1.1.23

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 (244) 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 +105 -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/cjs/utils/llm.cjs.map +1 -1
  8. package/dist/esm/graphs/Graph.mjs +12 -1
  9. package/dist/esm/graphs/Graph.mjs.map +1 -1
  10. package/dist/esm/graphs/MultiAgentGraph.mjs +105 -1
  11. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  12. package/dist/esm/run.mjs +20 -9
  13. package/dist/esm/run.mjs.map +1 -1
  14. package/dist/esm/utils/llm.mjs.map +1 -1
  15. package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
  16. package/package.json +1 -1
  17. package/src/graphs/Graph.ts +13 -1
  18. package/src/graphs/MultiAgentGraph.ts +128 -1
  19. package/src/graphs/__tests__/multi-agent-delegate.test.ts +205 -0
  20. package/src/run.ts +20 -11
  21. package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
  22. package/src/utils/llm.ts +1 -0
  23. package/src/agents/AgentContext.js +0 -782
  24. package/src/agents/AgentContext.test.js +0 -421
  25. package/src/agents/__tests__/AgentContext.test.js +0 -678
  26. package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
  27. package/src/common/enum.js +0 -192
  28. package/src/common/index.js +0 -3
  29. package/src/events.js +0 -166
  30. package/src/graphs/Graph.js +0 -1857
  31. package/src/graphs/MultiAgentGraph.js +0 -1092
  32. package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
  33. package/src/graphs/__tests__/structured-output.test.js +0 -144
  34. package/src/graphs/contextManagement.e2e.test.js +0 -718
  35. package/src/graphs/contextManagement.test.js +0 -485
  36. package/src/graphs/handoffValidation.test.js +0 -276
  37. package/src/graphs/index.js +0 -3
  38. package/src/index.js +0 -28
  39. package/src/instrumentation.js +0 -21
  40. package/src/llm/anthropic/index.js +0 -319
  41. package/src/llm/anthropic/types.js +0 -46
  42. package/src/llm/anthropic/utils/message_inputs.js +0 -627
  43. package/src/llm/anthropic/utils/message_outputs.js +0 -290
  44. package/src/llm/anthropic/utils/output_parsers.js +0 -89
  45. package/src/llm/anthropic/utils/tools.js +0 -25
  46. package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
  47. package/src/llm/bedrock/index.js +0 -303
  48. package/src/llm/bedrock/types.js +0 -2
  49. package/src/llm/bedrock/utils/index.js +0 -6
  50. package/src/llm/bedrock/utils/message_inputs.js +0 -463
  51. package/src/llm/bedrock/utils/message_outputs.js +0 -269
  52. package/src/llm/fake.js +0 -92
  53. package/src/llm/google/index.js +0 -215
  54. package/src/llm/google/types.js +0 -12
  55. package/src/llm/google/utils/common.js +0 -670
  56. package/src/llm/google/utils/tools.js +0 -111
  57. package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
  58. package/src/llm/openai/index.js +0 -1033
  59. package/src/llm/openai/types.js +0 -2
  60. package/src/llm/openai/utils/index.js +0 -756
  61. package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
  62. package/src/llm/openrouter/index.js +0 -261
  63. package/src/llm/openrouter/reasoning.test.js +0 -181
  64. package/src/llm/providers.js +0 -36
  65. package/src/llm/text.js +0 -65
  66. package/src/llm/vertexai/index.js +0 -402
  67. package/src/messages/__tests__/tools.test.js +0 -392
  68. package/src/messages/cache.js +0 -404
  69. package/src/messages/cache.test.js +0 -1167
  70. package/src/messages/content.js +0 -48
  71. package/src/messages/content.test.js +0 -314
  72. package/src/messages/core.js +0 -359
  73. package/src/messages/ensureThinkingBlock.test.js +0 -997
  74. package/src/messages/format.js +0 -973
  75. package/src/messages/formatAgentMessages.test.js +0 -2278
  76. package/src/messages/formatAgentMessages.tools.test.js +0 -362
  77. package/src/messages/formatMessage.test.js +0 -608
  78. package/src/messages/ids.js +0 -18
  79. package/src/messages/index.js +0 -9
  80. package/src/messages/labelContentByAgent.test.js +0 -725
  81. package/src/messages/prune.js +0 -438
  82. package/src/messages/reducer.js +0 -60
  83. package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
  84. package/src/messages/summarize.js +0 -146
  85. package/src/messages/summarize.test.js +0 -332
  86. package/src/messages/tools.js +0 -90
  87. package/src/mockStream.js +0 -81
  88. package/src/prompts/collab.js +0 -7
  89. package/src/prompts/index.js +0 -3
  90. package/src/prompts/taskmanager.js +0 -58
  91. package/src/run.js +0 -427
  92. package/src/schemas/index.js +0 -3
  93. package/src/schemas/schema-preparation.test.js +0 -370
  94. package/src/schemas/validate.js +0 -314
  95. package/src/schemas/validate.test.js +0 -264
  96. package/src/scripts/abort.js +0 -127
  97. package/src/scripts/ant_web_search.js +0 -130
  98. package/src/scripts/ant_web_search_edge_case.js +0 -133
  99. package/src/scripts/ant_web_search_error_edge_case.js +0 -119
  100. package/src/scripts/args.js +0 -41
  101. package/src/scripts/bedrock-cache-debug.js +0 -186
  102. package/src/scripts/bedrock-content-aggregation-test.js +0 -195
  103. package/src/scripts/bedrock-merge-test.js +0 -80
  104. package/src/scripts/bedrock-parallel-tools-test.js +0 -150
  105. package/src/scripts/caching.js +0 -106
  106. package/src/scripts/cli.js +0 -152
  107. package/src/scripts/cli2.js +0 -119
  108. package/src/scripts/cli3.js +0 -163
  109. package/src/scripts/cli4.js +0 -165
  110. package/src/scripts/cli5.js +0 -165
  111. package/src/scripts/code_exec.js +0 -171
  112. package/src/scripts/code_exec_files.js +0 -180
  113. package/src/scripts/code_exec_multi_session.js +0 -185
  114. package/src/scripts/code_exec_ptc.js +0 -265
  115. package/src/scripts/code_exec_session.js +0 -217
  116. package/src/scripts/code_exec_simple.js +0 -120
  117. package/src/scripts/content.js +0 -111
  118. package/src/scripts/empty_input.js +0 -125
  119. package/src/scripts/handoff-test.js +0 -96
  120. package/src/scripts/image.js +0 -138
  121. package/src/scripts/memory.js +0 -83
  122. package/src/scripts/multi-agent-chain.js +0 -271
  123. package/src/scripts/multi-agent-conditional.js +0 -185
  124. package/src/scripts/multi-agent-document-review-chain.js +0 -171
  125. package/src/scripts/multi-agent-hybrid-flow.js +0 -264
  126. package/src/scripts/multi-agent-parallel-start.js +0 -214
  127. package/src/scripts/multi-agent-parallel.js +0 -346
  128. package/src/scripts/multi-agent-sequence.js +0 -184
  129. package/src/scripts/multi-agent-supervisor.js +0 -324
  130. package/src/scripts/multi-agent-test.js +0 -147
  131. package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
  132. package/src/scripts/parallel-full-metadata-test.js +0 -176
  133. package/src/scripts/parallel-tools-test.js +0 -256
  134. package/src/scripts/programmatic_exec.js +0 -277
  135. package/src/scripts/programmatic_exec_agent.js +0 -168
  136. package/src/scripts/search.js +0 -118
  137. package/src/scripts/sequential-full-metadata-test.js +0 -143
  138. package/src/scripts/simple.js +0 -174
  139. package/src/scripts/single-agent-metadata-test.js +0 -152
  140. package/src/scripts/stream.js +0 -113
  141. package/src/scripts/test-custom-prompt-key.js +0 -132
  142. package/src/scripts/test-handoff-input.js +0 -143
  143. package/src/scripts/test-handoff-preamble.js +0 -227
  144. package/src/scripts/test-handoff-steering.js +0 -353
  145. package/src/scripts/test-multi-agent-list-handoff.js +0 -318
  146. package/src/scripts/test-parallel-agent-labeling.js +0 -253
  147. package/src/scripts/test-parallel-handoffs.js +0 -229
  148. package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
  149. package/src/scripts/test-thinking-handoff.js +0 -132
  150. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
  151. package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
  152. package/src/scripts/test-tools-before-handoff.js +0 -187
  153. package/src/scripts/test_code_api.js +0 -263
  154. package/src/scripts/thinking-bedrock.js +0 -128
  155. package/src/scripts/thinking-vertexai.js +0 -130
  156. package/src/scripts/thinking.js +0 -134
  157. package/src/scripts/tool_search.js +0 -114
  158. package/src/scripts/tools.js +0 -125
  159. package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
  160. package/src/specs/agent-handoffs.test.js +0 -924
  161. package/src/specs/anthropic.simple.test.js +0 -287
  162. package/src/specs/azure.simple.test.js +0 -381
  163. package/src/specs/cache.simple.test.js +0 -282
  164. package/src/specs/custom-event-await.test.js +0 -148
  165. package/src/specs/deepseek.simple.test.js +0 -189
  166. package/src/specs/emergency-prune.test.js +0 -308
  167. package/src/specs/moonshot.simple.test.js +0 -237
  168. package/src/specs/observability.integration.test.js +0 -1337
  169. package/src/specs/openai.simple.test.js +0 -233
  170. package/src/specs/openrouter.simple.test.js +0 -202
  171. package/src/specs/prune.test.js +0 -733
  172. package/src/specs/reasoning.test.js +0 -144
  173. package/src/specs/spec.utils.js +0 -4
  174. package/src/specs/thinking-handoff.test.js +0 -486
  175. package/src/specs/thinking-prune.test.js +0 -600
  176. package/src/specs/token-distribution-edge-case.test.js +0 -246
  177. package/src/specs/token-memoization.test.js +0 -32
  178. package/src/specs/tokens.test.js +0 -49
  179. package/src/specs/tool-error.test.js +0 -139
  180. package/src/splitStream.js +0 -204
  181. package/src/splitStream.test.js +0 -504
  182. package/src/stream.js +0 -650
  183. package/src/stream.test.js +0 -225
  184. package/src/test/mockTools.js +0 -340
  185. package/src/tools/BrowserTools.js +0 -245
  186. package/src/tools/Calculator.js +0 -38
  187. package/src/tools/Calculator.test.js +0 -225
  188. package/src/tools/CodeExecutor.js +0 -233
  189. package/src/tools/ProgrammaticToolCalling.js +0 -602
  190. package/src/tools/StreamingToolCallBuffer.js +0 -179
  191. package/src/tools/ToolNode.js +0 -930
  192. package/src/tools/ToolSearch.js +0 -904
  193. package/src/tools/__tests__/BrowserTools.test.js +0 -306
  194. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
  195. package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
  196. package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
  197. package/src/tools/__tests__/ToolApproval.test.js +0 -675
  198. package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
  199. package/src/tools/__tests__/ToolNode.session.test.js +0 -319
  200. package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
  201. package/src/tools/__tests__/ToolSearch.test.js +0 -812
  202. package/src/tools/__tests__/handlers.test.js +0 -799
  203. package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
  204. package/src/tools/handlers.js +0 -306
  205. package/src/tools/schema.js +0 -25
  206. package/src/tools/search/anthropic.js +0 -34
  207. package/src/tools/search/content.js +0 -116
  208. package/src/tools/search/content.test.js +0 -133
  209. package/src/tools/search/firecrawl.js +0 -173
  210. package/src/tools/search/format.js +0 -198
  211. package/src/tools/search/highlights.js +0 -241
  212. package/src/tools/search/index.js +0 -3
  213. package/src/tools/search/jina-reranker.test.js +0 -106
  214. package/src/tools/search/rerankers.js +0 -165
  215. package/src/tools/search/schema.js +0 -102
  216. package/src/tools/search/search.js +0 -561
  217. package/src/tools/search/serper-scraper.js +0 -126
  218. package/src/tools/search/test.js +0 -129
  219. package/src/tools/search/tool.js +0 -453
  220. package/src/tools/search/types.js +0 -2
  221. package/src/tools/search/utils.js +0 -59
  222. package/src/types/graph.js +0 -24
  223. package/src/types/graph.test.js +0 -192
  224. package/src/types/index.js +0 -7
  225. package/src/types/llm.js +0 -2
  226. package/src/types/messages.js +0 -2
  227. package/src/types/run.js +0 -2
  228. package/src/types/stream.js +0 -2
  229. package/src/types/tools.js +0 -2
  230. package/src/utils/contextAnalytics.js +0 -79
  231. package/src/utils/contextAnalytics.test.js +0 -166
  232. package/src/utils/events.js +0 -26
  233. package/src/utils/graph.js +0 -11
  234. package/src/utils/handlers.js +0 -65
  235. package/src/utils/index.js +0 -10
  236. package/src/utils/llm.js +0 -21
  237. package/src/utils/llmConfig.js +0 -205
  238. package/src/utils/logging.js +0 -37
  239. package/src/utils/misc.js +0 -51
  240. package/src/utils/run.js +0 -69
  241. package/src/utils/schema.js +0 -21
  242. package/src/utils/title.js +0 -119
  243. package/src/utils/tokens.js +0 -92
  244. package/src/utils/toonFormat.js +0 -379
@@ -1,200 +0,0 @@
1
- import { z } from 'zod';
2
- import { tool } from '@langchain/core/tools';
3
- import { AIMessage } from '@langchain/core/messages';
4
- import { describe, it, expect } from '@jest/globals';
5
- import { ToolNode } from '../ToolNode';
6
- import { StreamingToolCallBuffer } from '../StreamingToolCallBuffer';
7
- /**
8
- * Creates a mock content_tool that captures the args it receives.
9
- * Used to verify that truncated args are recovered from the streaming buffer.
10
- */
11
- function createMockContentTool(capturedArgs) {
12
- return tool(async (input) => {
13
- capturedArgs.push({ ...input });
14
- return `Wrote ${input.filename ?? 'file'}`;
15
- }, {
16
- name: 'content_tool',
17
- description: 'Read, write, and manage files',
18
- schema: z.object({
19
- action: z.string(),
20
- filename: z.string().optional(),
21
- content: z.string().optional(),
22
- }),
23
- });
24
- }
25
- function createAIMessageWithContentTool(callId, args) {
26
- return new AIMessage({
27
- content: '',
28
- tool_calls: [
29
- {
30
- id: callId,
31
- name: 'content_tool',
32
- args,
33
- },
34
- ],
35
- });
36
- }
37
- describe('ToolNode truncated arg recovery', () => {
38
- it('recovers missing content field from streaming buffer', async () => {
39
- const capturedArgs = [];
40
- const buffer = new StreamingToolCallBuffer();
41
- // Simulate streaming: buffer accumulated the full raw args
42
- buffer.append('tc_1', '{"action":"write","filename":"app.tsx","content":"function App() {\\n return <div>Hello</div>;\\n}"}');
43
- buffer.setToolName('tc_1', 'content_tool');
44
- const contentTool = createMockContentTool(capturedArgs);
45
- const toolNode = new ToolNode({
46
- tools: [contentTool],
47
- streamingToolCallBuffer: buffer,
48
- });
49
- // Simulate truncated args: parsePartialJson lost the content field
50
- const aiMsg = createAIMessageWithContentTool('tc_1', {
51
- action: 'write',
52
- filename: 'app.tsx',
53
- // content is MISSING — truncated by max_tokens
54
- });
55
- await toolNode.invoke({ messages: [aiMsg] });
56
- expect(capturedArgs).toHaveLength(1);
57
- expect(capturedArgs[0].action).toBe('write');
58
- expect(capturedArgs[0].filename).toBe('app.tsx');
59
- expect(capturedArgs[0].content).toBe('function App() {\n return <div>Hello</div>;\n}');
60
- });
61
- it('recovers completely empty args from streaming buffer', async () => {
62
- const capturedArgs = [];
63
- const buffer = new StreamingToolCallBuffer();
64
- // Buffer has full args, but parsePartialJson returned empty object
65
- buffer.append('tc_1', '{"action":"write","filename":"test.js","content":"const x = 1;"}');
66
- buffer.setToolName('tc_1', 'content_tool');
67
- const contentTool = createMockContentTool(capturedArgs);
68
- const toolNode = new ToolNode({
69
- tools: [contentTool],
70
- streamingToolCallBuffer: buffer,
71
- });
72
- // Empty args — JSON parsing aborted completely
73
- const aiMsg = createAIMessageWithContentTool('tc_1', {});
74
- await toolNode.invoke({ messages: [aiMsg] });
75
- expect(capturedArgs).toHaveLength(1);
76
- expect(capturedArgs[0].action).toBe('write');
77
- expect(capturedArgs[0].filename).toBe('test.js');
78
- expect(capturedArgs[0].content).toBe('const x = 1;');
79
- });
80
- it('does not modify args when buffer has no entry', async () => {
81
- const capturedArgs = [];
82
- const buffer = new StreamingToolCallBuffer();
83
- // No buffer entry for tc_1
84
- const contentTool = createMockContentTool(capturedArgs);
85
- const toolNode = new ToolNode({
86
- tools: [contentTool],
87
- streamingToolCallBuffer: buffer,
88
- });
89
- const aiMsg = createAIMessageWithContentTool('tc_1', {
90
- action: 'read',
91
- filename: 'test.js',
92
- });
93
- await toolNode.invoke({ messages: [aiMsg] });
94
- expect(capturedArgs).toHaveLength(1);
95
- expect(capturedArgs[0].action).toBe('read');
96
- expect(capturedArgs[0].filename).toBe('test.js');
97
- expect(capturedArgs[0].content).toBeUndefined();
98
- });
99
- it('does not overwrite existing parsed values', async () => {
100
- const capturedArgs = [];
101
- const buffer = new StreamingToolCallBuffer();
102
- // Buffer has different values than parsed
103
- buffer.append('tc_1', '{"action":"write","filename":"old.tsx","content":"old content"}');
104
- const contentTool = createMockContentTool(capturedArgs);
105
- const toolNode = new ToolNode({
106
- tools: [contentTool],
107
- streamingToolCallBuffer: buffer,
108
- });
109
- // Parsed args have action and filename already
110
- const aiMsg = createAIMessageWithContentTool('tc_1', {
111
- action: 'write',
112
- filename: 'new.tsx',
113
- // content is missing — should be recovered
114
- });
115
- await toolNode.invoke({ messages: [aiMsg] });
116
- expect(capturedArgs).toHaveLength(1);
117
- expect(capturedArgs[0].action).toBe('write');
118
- expect(capturedArgs[0].filename).toBe('new.tsx'); // Keeps parsed value, not buffer value
119
- expect(capturedArgs[0].content).toBe('old content'); // Recovered from buffer
120
- });
121
- it('clears buffer after recovery', async () => {
122
- const capturedArgs = [];
123
- const buffer = new StreamingToolCallBuffer();
124
- buffer.append('tc_1', '{"action":"write","content":"test"}');
125
- const contentTool = createMockContentTool(capturedArgs);
126
- const toolNode = new ToolNode({
127
- tools: [contentTool],
128
- streamingToolCallBuffer: buffer,
129
- });
130
- const aiMsg = createAIMessageWithContentTool('tc_1', { action: 'write' });
131
- await toolNode.invoke({ messages: [aiMsg] });
132
- // Buffer should be cleared after processing
133
- expect(buffer.has('tc_1')).toBe(false);
134
- });
135
- it('works with tools other than content_tool', async () => {
136
- const capturedArgs = [];
137
- const buffer = new StreamingToolCallBuffer();
138
- buffer.append('tc_1', '{"query":"SELECT * FROM users","database":"prod"}');
139
- buffer.setToolName('tc_1', 'sql_query');
140
- const sqlTool = tool(async (input) => {
141
- capturedArgs.push({ ...input });
142
- return 'Results: 42 rows';
143
- }, {
144
- name: 'sql_query',
145
- description: 'Execute SQL query',
146
- schema: z.object({
147
- query: z.string(),
148
- database: z.string().optional(),
149
- }),
150
- });
151
- const toolNode = new ToolNode({
152
- tools: [sqlTool],
153
- streamingToolCallBuffer: buffer,
154
- });
155
- // Truncated: only has query, missing database
156
- const aiMsg = new AIMessage({
157
- content: '',
158
- tool_calls: [
159
- { id: 'tc_1', name: 'sql_query', args: { query: 'SELECT * FROM users' } },
160
- ],
161
- });
162
- await toolNode.invoke({ messages: [aiMsg] });
163
- expect(capturedArgs).toHaveLength(1);
164
- expect(capturedArgs[0].query).toBe('SELECT * FROM users');
165
- expect(capturedArgs[0].database).toBe('prod');
166
- });
167
- it('recovers truncated content with newlines and special chars', async () => {
168
- const capturedArgs = [];
169
- const buffer = new StreamingToolCallBuffer();
170
- const largeContent = 'import React from \\"react\\";\\n\\n' +
171
- 'export default function Dashboard() {\\n' +
172
- ' const [count, setCount] = React.useState(0);\\n' +
173
- ' return (\\n' +
174
- ' <div className=\\"dashboard\\">\\n' +
175
- ' <h1>Dashboard</h1>\\n' +
176
- ' <button onClick={() => setCount(c => c + 1)}>\\n' +
177
- ' Count: {count}\\n' +
178
- ' </button>\\n' +
179
- ' </div>\\n' +
180
- ' );\\n' +
181
- '}';
182
- buffer.append('tc_1', `{"action":"write","filename":"Dashboard.tsx","content":"${largeContent}"}`);
183
- const contentTool = createMockContentTool(capturedArgs);
184
- const toolNode = new ToolNode({
185
- tools: [contentTool],
186
- streamingToolCallBuffer: buffer,
187
- });
188
- // content_tool with missing content
189
- const aiMsg = createAIMessageWithContentTool('tc_1', {
190
- action: 'write',
191
- filename: 'Dashboard.tsx',
192
- });
193
- await toolNode.invoke({ messages: [aiMsg] });
194
- expect(capturedArgs).toHaveLength(1);
195
- expect(capturedArgs[0].content).toContain('import React from "react"');
196
- expect(capturedArgs[0].content).toContain('export default function Dashboard()');
197
- expect(capturedArgs[0].content).toContain('Count: {count}');
198
- });
199
- });
200
- //# sourceMappingURL=ToolNode.recovery.test.js.map
@@ -1,319 +0,0 @@
1
- import { z } from 'zod';
2
- import { tool } from '@langchain/core/tools';
3
- import { AIMessage } from '@langchain/core/messages';
4
- import { describe, it, expect } from '@jest/globals';
5
- import { ToolNode } from '../ToolNode';
6
- import { Constants } from '@/common';
7
- /**
8
- * Creates a mock execute_code tool that captures the toolCall config it receives.
9
- * Returns a content_and_artifact response with configurable session/files.
10
- */
11
- function createMockCodeTool(options) {
12
- const { capturedConfigs, artifact } = options;
13
- const defaultArtifact = {
14
- session_id: 'new-session-123',
15
- files: [],
16
- };
17
- return tool(async (_input, config) => {
18
- capturedConfigs.push({ ...(config.toolCall ?? {}) });
19
- return ['stdout:\nhello world\n', artifact ?? defaultArtifact];
20
- }, {
21
- name: Constants.EXECUTE_CODE,
22
- description: 'Execute code in a sandbox',
23
- schema: z.object({ lang: z.string(), code: z.string() }),
24
- responseFormat: Constants.CONTENT_AND_ARTIFACT,
25
- });
26
- }
27
- function createAIMessageWithCodeCall(callId) {
28
- return new AIMessage({
29
- content: '',
30
- tool_calls: [
31
- {
32
- id: callId,
33
- name: Constants.EXECUTE_CODE,
34
- args: { lang: 'python', code: 'print("hello")' },
35
- },
36
- ],
37
- });
38
- }
39
- describe('ToolNode code execution session management', () => {
40
- describe('session injection via runTool (direct execution)', () => {
41
- it('injects session_id and _injected_files when session has files', async () => {
42
- const capturedConfigs = [];
43
- const sessions = new Map();
44
- sessions.set(Constants.EXECUTE_CODE, {
45
- session_id: 'prev-session-abc',
46
- files: [
47
- { id: 'file1', name: 'data.csv', session_id: 'prev-session-abc' },
48
- { id: 'file2', name: 'chart.png', session_id: 'prev-session-abc' },
49
- ],
50
- lastUpdated: Date.now(),
51
- });
52
- const mockTool = createMockCodeTool({ capturedConfigs });
53
- const toolNode = new ToolNode({ tools: [mockTool], sessions });
54
- const aiMsg = createAIMessageWithCodeCall('call_1');
55
- await toolNode.invoke({ messages: [aiMsg] });
56
- expect(capturedConfigs).toHaveLength(1);
57
- expect(capturedConfigs[0].session_id).toBe('prev-session-abc');
58
- expect(capturedConfigs[0]._injected_files).toEqual([
59
- { session_id: 'prev-session-abc', id: 'file1', name: 'data.csv' },
60
- { session_id: 'prev-session-abc', id: 'file2', name: 'chart.png' },
61
- ]);
62
- });
63
- it('injects session_id even when session has no tracked files', async () => {
64
- const capturedConfigs = [];
65
- const sessions = new Map();
66
- sessions.set(Constants.EXECUTE_CODE, {
67
- session_id: 'prev-session-no-files',
68
- files: [],
69
- lastUpdated: Date.now(),
70
- });
71
- const mockTool = createMockCodeTool({ capturedConfigs });
72
- const toolNode = new ToolNode({ tools: [mockTool], sessions });
73
- const aiMsg = createAIMessageWithCodeCall('call_2');
74
- await toolNode.invoke({ messages: [aiMsg] });
75
- expect(capturedConfigs).toHaveLength(1);
76
- expect(capturedConfigs[0].session_id).toBe('prev-session-no-files');
77
- expect(capturedConfigs[0]._injected_files).toBeUndefined();
78
- });
79
- it('does not inject session context when no session exists', async () => {
80
- const capturedConfigs = [];
81
- const sessions = new Map();
82
- const mockTool = createMockCodeTool({ capturedConfigs });
83
- const toolNode = new ToolNode({ tools: [mockTool], sessions });
84
- const aiMsg = createAIMessageWithCodeCall('call_3');
85
- await toolNode.invoke({ messages: [aiMsg] });
86
- expect(capturedConfigs).toHaveLength(1);
87
- expect(capturedConfigs[0].session_id).toBeUndefined();
88
- expect(capturedConfigs[0]._injected_files).toBeUndefined();
89
- });
90
- it('preserves per-file session_id for multi-session files', async () => {
91
- const capturedConfigs = [];
92
- const sessions = new Map();
93
- sessions.set(Constants.EXECUTE_CODE, {
94
- session_id: 'session-B',
95
- files: [
96
- { id: 'f1', name: 'old.csv', session_id: 'session-A' },
97
- { id: 'f2', name: 'new.png', session_id: 'session-B' },
98
- ],
99
- lastUpdated: Date.now(),
100
- });
101
- const mockTool = createMockCodeTool({ capturedConfigs });
102
- const toolNode = new ToolNode({ tools: [mockTool], sessions });
103
- const aiMsg = createAIMessageWithCodeCall('call_4');
104
- await toolNode.invoke({ messages: [aiMsg] });
105
- const files = capturedConfigs[0]._injected_files;
106
- expect(files[0].session_id).toBe('session-A');
107
- expect(files[1].session_id).toBe('session-B');
108
- });
109
- });
110
- describe('getCodeSessionContext (via dispatchToolEvents request building)', () => {
111
- it('builds session context with files for event-driven requests', () => {
112
- const sessions = new Map();
113
- sessions.set(Constants.EXECUTE_CODE, {
114
- session_id: 'evt-session',
115
- files: [{ id: 'ef1', name: 'out.parquet', session_id: 'evt-session' }],
116
- lastUpdated: Date.now(),
117
- });
118
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
119
- const toolNode = new ToolNode({
120
- tools: [mockTool],
121
- sessions,
122
- eventDrivenMode: true,
123
- });
124
- const context = toolNode.getCodeSessionContext();
125
- expect(context).toEqual({
126
- session_id: 'evt-session',
127
- files: [{ session_id: 'evt-session', id: 'ef1', name: 'out.parquet' }],
128
- });
129
- });
130
- it('builds session context without files when session has no tracked files', () => {
131
- const sessions = new Map();
132
- sessions.set(Constants.EXECUTE_CODE, {
133
- session_id: 'evt-session-empty',
134
- files: [],
135
- lastUpdated: Date.now(),
136
- });
137
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
138
- const toolNode = new ToolNode({
139
- tools: [mockTool],
140
- sessions,
141
- eventDrivenMode: true,
142
- });
143
- const context = toolNode.getCodeSessionContext();
144
- expect(context).toEqual({ session_id: 'evt-session-empty' });
145
- });
146
- it('returns undefined when no session exists', () => {
147
- const sessions = new Map();
148
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
149
- const toolNode = new ToolNode({
150
- tools: [mockTool],
151
- sessions,
152
- eventDrivenMode: true,
153
- });
154
- const context = toolNode.getCodeSessionContext();
155
- expect(context).toBeUndefined();
156
- });
157
- });
158
- describe('storeCodeSessionFromResults (session storage from artifacts)', () => {
159
- it('stores session with files from code execution results', () => {
160
- const sessions = new Map();
161
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
162
- const toolNode = new ToolNode({
163
- tools: [mockTool],
164
- sessions,
165
- eventDrivenMode: true,
166
- });
167
- const storeMethod = toolNode.storeCodeSessionFromResults.bind(toolNode);
168
- storeMethod([
169
- {
170
- toolCallId: 'tc1',
171
- content: 'output',
172
- artifact: {
173
- session_id: 'new-sess',
174
- files: [{ id: 'f1', name: 'result.csv' }],
175
- },
176
- status: 'success',
177
- },
178
- ], [{ id: 'tc1', name: Constants.EXECUTE_CODE, args: {} }]);
179
- const stored = sessions.get(Constants.EXECUTE_CODE);
180
- expect(stored).toBeDefined();
181
- expect(stored.session_id).toBe('new-sess');
182
- expect(stored.files).toHaveLength(1);
183
- expect(stored.files[0]).toEqual(expect.objectContaining({
184
- id: 'f1',
185
- name: 'result.csv',
186
- session_id: 'new-sess',
187
- }));
188
- });
189
- it('stores session_id even when Code API returns no files', () => {
190
- const sessions = new Map();
191
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
192
- const toolNode = new ToolNode({
193
- tools: [mockTool],
194
- sessions,
195
- eventDrivenMode: true,
196
- });
197
- const storeMethod = toolNode.storeCodeSessionFromResults.bind(toolNode);
198
- storeMethod([
199
- {
200
- toolCallId: 'tc2',
201
- content: 'stdout:\nSaved parquet\n',
202
- artifact: { session_id: 'parquet-session', files: [] },
203
- status: 'success',
204
- },
205
- ], [{ id: 'tc2', name: Constants.EXECUTE_CODE, args: {} }]);
206
- const stored = sessions.get(Constants.EXECUTE_CODE);
207
- expect(stored).toBeDefined();
208
- expect(stored.session_id).toBe('parquet-session');
209
- expect(stored.files).toEqual([]);
210
- });
211
- it('merges new files with existing session, replacing same-name files', () => {
212
- const sessions = new Map();
213
- sessions.set(Constants.EXECUTE_CODE, {
214
- session_id: 'old-sess',
215
- files: [
216
- { id: 'f1', name: 'data.csv', session_id: 'old-sess' },
217
- { id: 'f2', name: 'chart.png', session_id: 'old-sess' },
218
- ],
219
- lastUpdated: Date.now(),
220
- });
221
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
222
- const toolNode = new ToolNode({
223
- tools: [mockTool],
224
- sessions,
225
- eventDrivenMode: true,
226
- });
227
- const storeMethod = toolNode.storeCodeSessionFromResults.bind(toolNode);
228
- storeMethod([
229
- {
230
- toolCallId: 'tc3',
231
- content: 'output',
232
- artifact: {
233
- session_id: 'new-sess',
234
- files: [{ id: 'f3', name: 'chart.png' }],
235
- },
236
- status: 'success',
237
- },
238
- ], [{ id: 'tc3', name: Constants.EXECUTE_CODE, args: {} }]);
239
- const stored = sessions.get(Constants.EXECUTE_CODE);
240
- expect(stored.session_id).toBe('new-sess');
241
- expect(stored.files).toHaveLength(2);
242
- const csvFile = stored.files.find((f) => f.name === 'data.csv');
243
- expect(csvFile.session_id).toBe('old-sess');
244
- const chartFile = stored.files.find((f) => f.name === 'chart.png');
245
- expect(chartFile.id).toBe('f3');
246
- expect(chartFile.session_id).toBe('new-sess');
247
- });
248
- it('preserves existing files when new execution has no files', () => {
249
- const sessions = new Map();
250
- sessions.set(Constants.EXECUTE_CODE, {
251
- session_id: 'old-sess',
252
- files: [{ id: 'f1', name: 'data.csv', session_id: 'old-sess' }],
253
- lastUpdated: Date.now(),
254
- });
255
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
256
- const toolNode = new ToolNode({
257
- tools: [mockTool],
258
- sessions,
259
- eventDrivenMode: true,
260
- });
261
- const storeMethod = toolNode.storeCodeSessionFromResults.bind(toolNode);
262
- storeMethod([
263
- {
264
- toolCallId: 'tc4',
265
- content: 'stdout:\nno files generated\n',
266
- artifact: { session_id: 'new-sess', files: [] },
267
- status: 'success',
268
- },
269
- ], [{ id: 'tc4', name: Constants.EXECUTE_CODE, args: {} }]);
270
- const stored = sessions.get(Constants.EXECUTE_CODE);
271
- expect(stored.session_id).toBe('new-sess');
272
- expect(stored.files).toHaveLength(1);
273
- expect(stored.files[0].name).toBe('data.csv');
274
- });
275
- it('ignores non-code-execution tool results', () => {
276
- const sessions = new Map();
277
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
278
- const toolNode = new ToolNode({
279
- tools: [mockTool],
280
- sessions,
281
- eventDrivenMode: true,
282
- });
283
- const storeMethod = toolNode.storeCodeSessionFromResults.bind(toolNode);
284
- storeMethod([
285
- {
286
- toolCallId: 'tc5',
287
- content: 'search results',
288
- artifact: { session_id: 'should-not-store' },
289
- status: 'success',
290
- },
291
- ], [{ id: 'tc5', name: 'web_search', args: {} }]);
292
- expect(sessions.has(Constants.EXECUTE_CODE)).toBe(false);
293
- });
294
- it('ignores error results', () => {
295
- const sessions = new Map();
296
- const mockTool = createMockCodeTool({ capturedConfigs: [] });
297
- const toolNode = new ToolNode({
298
- tools: [mockTool],
299
- sessions,
300
- eventDrivenMode: true,
301
- });
302
- const storeMethod = toolNode.storeCodeSessionFromResults.bind(toolNode);
303
- storeMethod([
304
- {
305
- toolCallId: 'tc6',
306
- content: '',
307
- artifact: {
308
- session_id: 'error-session',
309
- files: [{ id: 'f1', name: 'x' }],
310
- },
311
- status: 'error',
312
- errorMessage: 'execution failed',
313
- },
314
- ], [{ id: 'tc6', name: Constants.EXECUTE_CODE, args: {} }]);
315
- expect(sessions.has(Constants.EXECUTE_CODE)).toBe(false);
316
- });
317
- });
318
- });
319
- //# sourceMappingURL=ToolNode.session.test.js.map
@@ -1,125 +0,0 @@
1
- // src/tools/__tests__/ToolSearch.integration.test.ts
2
- /**
3
- * Integration tests for Tool Search Regex.
4
- * These tests hit the LIVE Code API and verify end-to-end search functionality.
5
- *
6
- * Run with: npm test -- ToolSearch.integration.test.ts
7
- *
8
- * Requires CODE_EXECUTOR_API_KEY environment variable.
9
- * Tests are skipped when the API key is not available.
10
- */
11
- import { config as dotenvConfig } from 'dotenv';
12
- dotenvConfig();
13
- import { describe, it, expect, beforeAll } from '@jest/globals';
14
- import { createToolSearch } from '../ToolSearch';
15
- import { createToolSearchToolRegistry } from '@/test/mockTools';
16
- const apiKey = process.env.CODE_EXECUTOR_API_KEY;
17
- const shouldSkip = apiKey == null || apiKey === '';
18
- const describeIfApiKey = shouldSkip ? describe.skip : describe;
19
- describeIfApiKey('ToolSearch - Live API Integration', () => {
20
- let searchTool;
21
- const toolRegistry = createToolSearchToolRegistry();
22
- beforeAll(() => {
23
- searchTool = createToolSearch({ apiKey: apiKey, toolRegistry });
24
- });
25
- it('searches for expense-related tools', async () => {
26
- const output = await searchTool.invoke({ query: 'expense' });
27
- expect(typeof output).toBe('string');
28
- expect(output).toContain('Found');
29
- expect(output).toContain('matching tools');
30
- expect(output).toContain('get_expenses');
31
- expect(output).toContain('calculate_expense_totals');
32
- expect(output).toContain('score: 0.95');
33
- }, 10000);
34
- it('searches for weather tools with OR pattern', async () => {
35
- const output = await searchTool.invoke({ query: 'weather|forecast' });
36
- expect(output).toContain('Found');
37
- expect(output).toContain('get_weather');
38
- expect(output).toContain('get_forecast');
39
- }, 10000);
40
- it('performs case-insensitive search', async () => {
41
- const output = await searchTool.invoke({ query: 'EMAIL' });
42
- expect(output).toContain('send_email');
43
- }, 10000);
44
- it('searches descriptions only', async () => {
45
- const output = await searchTool.invoke({
46
- query: 'database',
47
- fields: ['description'],
48
- });
49
- expect(output).toContain('Found');
50
- expect(output).toContain('Matched in: description');
51
- expect(output).toContain('run_database_query');
52
- }, 10000);
53
- it('searches parameter names', async () => {
54
- const output = await searchTool.invoke({
55
- query: 'query',
56
- fields: ['parameters'],
57
- });
58
- expect(output).toContain('Found');
59
- expect(output).toContain('Matched in: parameters');
60
- }, 10000);
61
- it('limits results to specified count', async () => {
62
- const output = await searchTool.invoke({
63
- query: 'get',
64
- max_results: 2,
65
- });
66
- expect(output).toContain('Found 2 matching tools');
67
- const toolMatches = output.match(/- \w+ \(score:/g);
68
- expect(toolMatches?.length).toBe(2);
69
- }, 10000);
70
- it('returns no matches for nonsense pattern', async () => {
71
- const output = await searchTool.invoke({
72
- query: 'xyznonexistent999',
73
- });
74
- expect(output).toContain('No tools matched');
75
- expect(output).toContain('Total tools searched:');
76
- }, 10000);
77
- it('uses regex character classes', async () => {
78
- const output = await searchTool.invoke({ query: 'get_[a-z]+' });
79
- expect(output).toContain('Found');
80
- expect(output).toContain('matching tools');
81
- }, 10000);
82
- it('sanitizes dangerous patterns with warning', async () => {
83
- const output = await searchTool.invoke({ query: '(a+)+' });
84
- expect(output).toContain('Note: The provided pattern was converted to a literal search for safety');
85
- // After sanitization, pattern is shown in the output
86
- expect(output).toContain('Total tools searched:');
87
- expect(output).toContain('No tools matched');
88
- }, 10000);
89
- it('searches across all fields', async () => {
90
- const output = await searchTool.invoke({
91
- query: 'text',
92
- fields: ['name', 'description', 'parameters'],
93
- });
94
- expect(output).toContain('Found');
95
- expect(output).toContain('translate_text');
96
- }, 10000);
97
- it('handles complex regex patterns', async () => {
98
- const output = await searchTool.invoke({
99
- query: '^(get|create)_.*',
100
- });
101
- expect(output).toContain('Found');
102
- expect(output).toContain('matching tools');
103
- }, 10000);
104
- it('prioritizes name matches over description matches', async () => {
105
- const output = await searchTool.invoke({ query: 'generate' });
106
- expect(output).toContain('generate_report');
107
- expect(output).toContain('score:');
108
- const lines = output.split('\n');
109
- const generateLine = lines.find((l) => l.includes('generate_report'));
110
- expect(generateLine).toContain('score: 0.95'); // Name match = 0.95
111
- }, 10000);
112
- it('finds tools by partial name match', async () => {
113
- const output = await searchTool.invoke({ query: 'budget' });
114
- expect(output).toContain('create_budget');
115
- }, 10000);
116
- it('handles very specific patterns', async () => {
117
- const output = await searchTool.invoke({
118
- query: 'send_email',
119
- });
120
- expect(output).toContain('Found');
121
- expect(output).toContain('send_email');
122
- expect(output).toContain('score: 0.95');
123
- }, 10000);
124
- });
125
- //# sourceMappingURL=ToolSearch.integration.test.js.map