@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,306 +0,0 @@
1
- import { describe, it, expect, beforeEach } from '@jest/globals';
2
- import { createBrowserTools, hasBrowserCapability, EBrowserTools, } from '../BrowserTools';
3
- describe('BrowserTools', () => {
4
- describe('EBrowserTools enum', () => {
5
- it('should have all expected browser tool names', () => {
6
- expect(EBrowserTools.CLICK).toBe('browser_click');
7
- expect(EBrowserTools.TYPE).toBe('browser_type');
8
- expect(EBrowserTools.NAVIGATE).toBe('browser_navigate');
9
- expect(EBrowserTools.SCROLL).toBe('browser_scroll');
10
- expect(EBrowserTools.EXTRACT).toBe('browser_extract');
11
- expect(EBrowserTools.HOVER).toBe('browser_hover');
12
- expect(EBrowserTools.WAIT).toBe('browser_wait');
13
- expect(EBrowserTools.BACK).toBe('browser_back');
14
- expect(EBrowserTools.SCREENSHOT).toBe('browser_screenshot');
15
- expect(EBrowserTools.GET_PAGE_STATE).toBe('browser_get_page_state');
16
- expect(EBrowserTools.KEYPRESS).toBe('browser_keypress');
17
- expect(EBrowserTools.SWITCH_TAB).toBe('browser_switch_tab');
18
- });
19
- it('should have exactly 12 browser tools', () => {
20
- expect(Object.keys(EBrowserTools).length).toBe(12);
21
- });
22
- });
23
- describe('hasBrowserCapability', () => {
24
- it('should return false when no request is provided', () => {
25
- expect(hasBrowserCapability()).toBe(false);
26
- expect(hasBrowserCapability(undefined)).toBe(false);
27
- });
28
- it('should return false when request has no headers', () => {
29
- expect(hasBrowserCapability({})).toBe(false);
30
- expect(hasBrowserCapability({ headers: undefined })).toBe(false);
31
- });
32
- it('should return true when X-Illuma-Browser-Extension header is true', () => {
33
- const req = {
34
- headers: {
35
- 'x-illuma-browser-extension': 'true',
36
- },
37
- };
38
- expect(hasBrowserCapability(req)).toBe(true);
39
- });
40
- it('should return true when X-Illuma-Browser-Capable header is true', () => {
41
- const req = {
42
- headers: {
43
- 'x-illuma-browser-capable': 'true',
44
- },
45
- };
46
- expect(hasBrowserCapability(req)).toBe(true);
47
- });
48
- it('should return false when browser headers are not true', () => {
49
- const req = {
50
- headers: {
51
- 'x-illuma-browser-extension': 'false',
52
- 'x-illuma-browser-capable': 'false',
53
- },
54
- };
55
- expect(hasBrowserCapability(req)).toBe(false);
56
- });
57
- it('should return false when browser headers are missing', () => {
58
- const req = {
59
- headers: {
60
- 'content-type': 'application/json',
61
- },
62
- };
63
- expect(hasBrowserCapability(req)).toBe(false);
64
- });
65
- });
66
- describe('createBrowserTools', () => {
67
- let tools;
68
- beforeEach(() => {
69
- tools = createBrowserTools();
70
- });
71
- it('should create exactly 12 browser tools', () => {
72
- expect(tools.length).toBe(12);
73
- });
74
- it('should create tools with correct names', () => {
75
- const toolNames = tools.map((t) => t.name);
76
- expect(toolNames).toContain('browser_click');
77
- expect(toolNames).toContain('browser_type');
78
- expect(toolNames).toContain('browser_navigate');
79
- expect(toolNames).toContain('browser_scroll');
80
- expect(toolNames).toContain('browser_extract');
81
- expect(toolNames).toContain('browser_hover');
82
- expect(toolNames).toContain('browser_wait');
83
- expect(toolNames).toContain('browser_back');
84
- expect(toolNames).toContain('browser_screenshot');
85
- expect(toolNames).toContain('browser_get_page_state');
86
- });
87
- it('should have descriptions for all tools', () => {
88
- for (const tool of tools) {
89
- expect(tool.description).toBeDefined();
90
- expect(tool.description.length).toBeGreaterThan(0);
91
- }
92
- });
93
- describe('browser_click tool', () => {
94
- it('should return requiresBrowserExecution marker', async () => {
95
- const clickTool = tools.find((t) => t.name === 'browser_click');
96
- expect(clickTool).toBeDefined();
97
- const result = await clickTool.invoke({ index: 5 });
98
- const parsed = JSON.parse(result);
99
- expect(parsed.requiresBrowserExecution).toBe(true);
100
- expect(parsed.action).toBe('click');
101
- expect(parsed.args).toEqual({ index: 5 });
102
- });
103
- });
104
- describe('browser_type tool', () => {
105
- it('should return requiresBrowserExecution marker with all args', async () => {
106
- const typeTool = tools.find((t) => t.name === 'browser_type');
107
- expect(typeTool).toBeDefined();
108
- const result = await typeTool.invoke({
109
- index: 3,
110
- text: 'Hello World',
111
- pressEnter: true,
112
- });
113
- const parsed = JSON.parse(result);
114
- expect(parsed.requiresBrowserExecution).toBe(true);
115
- expect(parsed.action).toBe('type');
116
- expect(parsed.args.index).toBe(3);
117
- expect(parsed.args.text).toBe('Hello World');
118
- expect(parsed.args.pressEnter).toBe(true);
119
- });
120
- });
121
- describe('browser_navigate tool', () => {
122
- it('should return requiresBrowserExecution marker with URL', async () => {
123
- const navigateTool = tools.find((t) => t.name === 'browser_navigate');
124
- expect(navigateTool).toBeDefined();
125
- const result = await navigateTool.invoke({
126
- url: 'https://example.com',
127
- });
128
- const parsed = JSON.parse(result);
129
- expect(parsed.requiresBrowserExecution).toBe(true);
130
- expect(parsed.action).toBe('navigate');
131
- expect(parsed.args.url).toBe('https://example.com');
132
- });
133
- });
134
- describe('browser_scroll tool', () => {
135
- it('should return requiresBrowserExecution marker with direction', async () => {
136
- const scrollTool = tools.find((t) => t.name === 'browser_scroll');
137
- expect(scrollTool).toBeDefined();
138
- const result = await scrollTool.invoke({
139
- direction: 'down',
140
- amount: 500,
141
- });
142
- const parsed = JSON.parse(result);
143
- expect(parsed.requiresBrowserExecution).toBe(true);
144
- expect(parsed.action).toBe('scroll');
145
- expect(parsed.args.direction).toBe('down');
146
- expect(parsed.args.amount).toBe(500);
147
- });
148
- });
149
- describe('browser_hover tool', () => {
150
- it('should return requiresBrowserExecution marker with index', async () => {
151
- const hoverTool = tools.find((t) => t.name === 'browser_hover');
152
- expect(hoverTool).toBeDefined();
153
- const result = await hoverTool.invoke({ index: 2 });
154
- const parsed = JSON.parse(result);
155
- expect(parsed.requiresBrowserExecution).toBe(true);
156
- expect(parsed.action).toBe('hover');
157
- expect(parsed.args.index).toBe(2);
158
- });
159
- });
160
- describe('browser_wait tool', () => {
161
- it('should return requiresBrowserExecution marker with duration', async () => {
162
- const waitTool = tools.find((t) => t.name === 'browser_wait');
163
- expect(waitTool).toBeDefined();
164
- const result = await waitTool.invoke({ duration: 2000 });
165
- const parsed = JSON.parse(result);
166
- expect(parsed.requiresBrowserExecution).toBe(true);
167
- expect(parsed.action).toBe('wait');
168
- expect(parsed.args.duration).toBe(2000);
169
- });
170
- });
171
- describe('browser_back tool', () => {
172
- it('should return requiresBrowserExecution marker', async () => {
173
- const backTool = tools.find((t) => t.name === 'browser_back');
174
- expect(backTool).toBeDefined();
175
- const result = await backTool.invoke({});
176
- const parsed = JSON.parse(result);
177
- expect(parsed.requiresBrowserExecution).toBe(true);
178
- expect(parsed.action).toBe('back');
179
- });
180
- });
181
- describe('browser_screenshot tool', () => {
182
- it('should return requiresBrowserExecution marker', async () => {
183
- const screenshotTool = tools.find((t) => t.name === 'browser_screenshot');
184
- expect(screenshotTool).toBeDefined();
185
- const result = await screenshotTool.invoke({});
186
- const parsed = JSON.parse(result);
187
- expect(parsed.requiresBrowserExecution).toBe(true);
188
- expect(parsed.action).toBe('screenshot');
189
- });
190
- });
191
- describe('browser_get_page_state tool', () => {
192
- it('should return requiresBrowserExecution marker', async () => {
193
- const pageStateTool = tools.find((t) => t.name === 'browser_get_page_state');
194
- expect(pageStateTool).toBeDefined();
195
- const result = await pageStateTool.invoke({});
196
- const parsed = JSON.parse(result);
197
- expect(parsed.requiresBrowserExecution).toBe(true);
198
- expect(parsed.action).toBe('get_page_state');
199
- });
200
- });
201
- describe('browser_extract tool', () => {
202
- it('should return requiresBrowserExecution marker', async () => {
203
- const extractTool = tools.find((t) => t.name === 'browser_extract');
204
- expect(extractTool).toBeDefined();
205
- const result = await extractTool.invoke({ query: 'main content' });
206
- const parsed = JSON.parse(result);
207
- expect(parsed.requiresBrowserExecution).toBe(true);
208
- expect(parsed.action).toBe('extract');
209
- expect(parsed.args.query).toBe('main content');
210
- });
211
- });
212
- describe('with waitForResult callback (formatResultForLLM)', () => {
213
- it('should format successful result with full page state', async () => {
214
- const mockCallback = async () => ({
215
- success: true,
216
- url: 'https://example.com/page',
217
- title: 'Example Page',
218
- elementList: '[0] <button> Click me\n[1] <input> fieldLabel="Search"',
219
- });
220
- const toolsWithCallback = createBrowserTools({
221
- waitForResult: mockCallback,
222
- });
223
- const extractTool = toolsWithCallback.find((t) => t.name === 'browser_extract');
224
- const result = await extractTool.invoke({});
225
- expect(result).toContain('**Current URL:** https://example.com/page');
226
- expect(result).toContain('**Page Title:** Example Page');
227
- expect(result).toContain('**Interactive Elements**');
228
- expect(result).toContain('[0] <button> Click me');
229
- });
230
- it('should include page state even when success is false', async () => {
231
- // Critical: extension often sends success=false with valid page state
232
- const mockCallback = async () => ({
233
- success: false,
234
- error: 'Element not found',
235
- url: 'https://example.com/form',
236
- title: 'Login Form',
237
- elementList: '[0] <input> fieldLabel="Username"\n[1] <input> fieldLabel="Password"',
238
- });
239
- const toolsWithCallback = createBrowserTools({
240
- waitForResult: mockCallback,
241
- });
242
- const clickTool = toolsWithCallback.find((t) => t.name === 'browser_click');
243
- const result = await clickTool.invoke({ index: 5 });
244
- // Should include the error note
245
- expect(result).toContain('**Note:**');
246
- expect(result).toContain('Element not found');
247
- // But also include page state — this is the critical fix
248
- expect(result).toContain('**Current URL:** https://example.com/form');
249
- expect(result).toContain('**Page Title:** Login Form');
250
- expect(result).toContain('**Interactive Elements**');
251
- expect(result).toContain('fieldLabel="Username"');
252
- });
253
- it('should return failure message when success=false and no page state', async () => {
254
- const mockCallback = async () => ({
255
- success: false,
256
- error: 'Timeout waiting for page',
257
- });
258
- const toolsWithCallback = createBrowserTools({
259
- waitForResult: mockCallback,
260
- });
261
- const navTool = toolsWithCallback.find((t) => t.name === 'browser_navigate');
262
- const result = await navTool.invoke({ url: 'https://example.com' });
263
- expect(result).toContain('**Note:**');
264
- expect(result).toContain('Timeout waiting for page');
265
- });
266
- it('should return success message when success=true and no other data', async () => {
267
- const mockCallback = async () => ({
268
- success: true,
269
- });
270
- const toolsWithCallback = createBrowserTools({
271
- waitForResult: mockCallback,
272
- });
273
- const waitTool = toolsWithCallback.find((t) => t.name === 'browser_wait');
274
- const result = await waitTool.invoke({});
275
- expect(result).toContain('completed successfully');
276
- });
277
- it('should handle screenshot result', async () => {
278
- const mockCallback = async () => ({
279
- success: true,
280
- url: 'https://example.com',
281
- screenshot: 'data:image/png;base64,iVBOR...',
282
- });
283
- const toolsWithCallback = createBrowserTools({
284
- waitForResult: mockCallback,
285
- });
286
- const ssTool = toolsWithCallback.find((t) => t.name === 'browser_screenshot');
287
- const result = await ssTool.invoke({});
288
- expect(result).toContain('[Screenshot captured and displayed to user]');
289
- expect(result).toContain('**Current URL:** https://example.com');
290
- });
291
- it('should handle callback error gracefully', async () => {
292
- const mockCallback = async () => {
293
- throw new Error('Extension disconnected');
294
- };
295
- const toolsWithCallback = createBrowserTools({
296
- waitForResult: mockCallback,
297
- });
298
- const clickTool = toolsWithCallback.find((t) => t.name === 'browser_click');
299
- const result = await clickTool.invoke({ index: 1 });
300
- expect(result).toContain('failed');
301
- expect(result).toContain('Extension disconnected');
302
- });
303
- });
304
- });
305
- });
306
- //# sourceMappingURL=BrowserTools.test.js.map
@@ -1,276 +0,0 @@
1
- // src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts
2
- /**
3
- * Integration tests for Programmatic Tool Calling.
4
- * These tests hit the LIVE Code API and verify end-to-end functionality.
5
- *
6
- * Run with: npm test -- ProgrammaticToolCalling.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 { createProgrammaticToolCallingTool } from '../ProgrammaticToolCalling';
15
- import { createGetTeamMembersTool, createGetExpensesTool, createGetWeatherTool, createCalculatorTool, createProgrammaticToolRegistry, } 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('ProgrammaticToolCalling - Live API Integration', () => {
20
- let ptcTool;
21
- let toolMap;
22
- let toolDefinitions;
23
- beforeAll(() => {
24
- const tools = [
25
- createGetTeamMembersTool(),
26
- createGetExpensesTool(),
27
- createGetWeatherTool(),
28
- createCalculatorTool(),
29
- ];
30
- toolMap = new Map(tools.map((t) => [t.name, t]));
31
- toolDefinitions = Array.from(createProgrammaticToolRegistry().values());
32
- ptcTool = createProgrammaticToolCallingTool({ apiKey: apiKey });
33
- });
34
- it('executes simple single tool call', async () => {
35
- const args = {
36
- code: `
37
- result = await get_weather(city="San Francisco")
38
- print(f"Temperature: {result['temperature']}°F")
39
- print(f"Condition: {result['condition']}")
40
- `,
41
- };
42
- const toolCall = {
43
- name: 'programmatic_code_execution',
44
- args,
45
- toolMap,
46
- toolDefs: toolDefinitions,
47
- };
48
- const output = await ptcTool.invoke(args, { toolCall });
49
- // When responseFormat is 'content_and_artifact', invoke() returns just the content
50
- // The artifact is available via other methods or when used in a graph
51
- expect(typeof output).toBe('string');
52
- expect(output).toContain('stdout:');
53
- expect(output).toContain('Temperature: 65°F');
54
- expect(output).toContain('Condition: Foggy');
55
- }, 10000);
56
- it('executes sequential tool calls in a loop', async () => {
57
- const args = {
58
- code: `
59
- team = await get_team_members()
60
- print(f"Team size: {len(team)}")
61
-
62
- total = 0
63
- for member in team:
64
- expenses = await get_expenses(user_id=member['id'])
65
- member_total = sum(e['amount'] for e in expenses)
66
- total += member_total
67
- print(f"{member['name']}: \${member_total:.2f}")
68
-
69
- print(f"Grand total: \${total:.2f}")
70
- `,
71
- };
72
- const toolCall = {
73
- name: 'programmatic_code_execution',
74
- args,
75
- toolMap,
76
- toolDefs: toolDefinitions,
77
- };
78
- const output = await ptcTool.invoke(args, { toolCall });
79
- expect(output).toContain('Team size: 3');
80
- expect(output).toContain('Alice:');
81
- expect(output).toContain('Bob:');
82
- expect(output).toContain('Charlie:');
83
- expect(output).toContain('Grand total:');
84
- }, 15000);
85
- it('executes parallel tool calls with asyncio.gather', async () => {
86
- const args = {
87
- code: `
88
- import asyncio
89
-
90
- cities = ["San Francisco", "New York", "London"]
91
- results = await asyncio.gather(*[
92
- get_weather(city=city)
93
- for city in cities
94
- ])
95
-
96
- for city, weather in zip(cities, results):
97
- print(f"{city}: {weather['temperature']}°F, {weather['condition']}")
98
- `,
99
- };
100
- const toolCall = {
101
- name: 'programmatic_code_execution',
102
- args,
103
- toolMap,
104
- toolDefs: toolDefinitions,
105
- };
106
- const output = await ptcTool.invoke(args, { toolCall });
107
- expect(output).toContain('San Francisco: 65°F, Foggy');
108
- expect(output).toContain('New York: 75°F, Sunny');
109
- expect(output).toContain('London: 55°F, Rainy');
110
- }, 10000);
111
- it('handles conditional logic', async () => {
112
- const args = {
113
- code: `
114
- team = await get_team_members()
115
- high_spenders = []
116
-
117
- for member in team:
118
- expenses = await get_expenses(user_id=member['id'])
119
- total = sum(e['amount'] for e in expenses)
120
- if total > 300:
121
- high_spenders.append((member['name'], total))
122
-
123
- if high_spenders:
124
- print("High spenders (over $300):")
125
- for name, amount in high_spenders:
126
- print(f" {name}: \${amount:.2f}")
127
- else:
128
- print("No high spenders found.")
129
- `,
130
- };
131
- const toolCall = {
132
- name: 'programmatic_code_execution',
133
- args,
134
- toolMap,
135
- toolDefs: toolDefinitions,
136
- };
137
- const output = await ptcTool.invoke(args, { toolCall });
138
- expect(output).toContain('High spenders');
139
- expect(output).toContain('Bob:');
140
- expect(output).toContain('Charlie:');
141
- }, 15000);
142
- it('handles early termination with break', async () => {
143
- const args = {
144
- code: `
145
- team = await get_team_members()
146
-
147
- for member in team:
148
- expenses = await get_expenses(user_id=member['id'])
149
- if any(e['category'] == 'equipment' for e in expenses):
150
- print(f"First member with equipment: {member['name']}")
151
- equipment_total = sum(e['amount'] for e in expenses if e['category'] == 'equipment')
152
- print(f"Equipment total: \${equipment_total:.2f}")
153
- break
154
- else:
155
- print("No equipment expenses found")
156
- `,
157
- };
158
- const toolCall = {
159
- name: 'programmatic_code_execution',
160
- args,
161
- toolMap,
162
- toolDefs: toolDefinitions,
163
- };
164
- const output = await ptcTool.invoke(args, { toolCall });
165
- expect(output).toContain('First member with equipment: Charlie');
166
- expect(output).toContain('Equipment total: $500.00');
167
- }, 15000);
168
- it('handles tool execution errors gracefully', async () => {
169
- const args = {
170
- code: `
171
- cities = ["San Francisco", "InvalidCity", "New York"]
172
-
173
- for city in cities:
174
- try:
175
- weather = await get_weather(city=city)
176
- print(f"{city}: {weather['temperature']}°F")
177
- except Exception as e:
178
- print(f"{city}: Error - {e}")
179
- `,
180
- };
181
- const toolCall = {
182
- name: 'programmatic_code_execution',
183
- args,
184
- toolMap,
185
- toolDefs: toolDefinitions,
186
- };
187
- const output = await ptcTool.invoke(args, { toolCall });
188
- expect(output).toContain('San Francisco: 65°F');
189
- expect(output).toContain('InvalidCity: Error');
190
- expect(output).toContain('New York: 75°F');
191
- }, 15000);
192
- it('uses calculator tool', async () => {
193
- const args = {
194
- code: `
195
- result1 = await calculator(expression="2 + 2 * 3")
196
- result2 = await calculator(expression="(10 + 5) / 3")
197
-
198
- print(f"2 + 2 * 3 = {result1['result']}")
199
- print(f"(10 + 5) / 3 = {result2['result']:.2f}")
200
- `,
201
- };
202
- const toolCall = {
203
- name: 'programmatic_code_execution',
204
- args,
205
- toolMap,
206
- toolDefs: toolDefinitions,
207
- };
208
- const output = await ptcTool.invoke(args, { toolCall });
209
- expect(output).toContain('2 + 2 * 3 = 8');
210
- expect(output).toContain('(10 + 5) / 3 = 5.00');
211
- }, 10000);
212
- it('mixes parallel and sequential execution', async () => {
213
- const args = {
214
- code: `
215
- import asyncio
216
-
217
- # Step 1: Get team (sequential)
218
- team = await get_team_members()
219
- print(f"Fetched {len(team)} team members")
220
-
221
- # Step 2: Get all expenses in parallel
222
- all_expenses = await asyncio.gather(*[
223
- get_expenses(user_id=member['id'])
224
- for member in team
225
- ])
226
-
227
- # Step 3: Process
228
- print("\\nExpense summary:")
229
- for member, expenses in zip(team, all_expenses):
230
- total = sum(e['amount'] for e in expenses)
231
- print(f" {member['name']}: \${total:.2f} ({len(expenses)} items)")
232
- `,
233
- };
234
- const toolCall = {
235
- name: 'programmatic_code_execution',
236
- args,
237
- toolMap,
238
- toolDefs: toolDefinitions,
239
- };
240
- const output = await ptcTool.invoke(args, { toolCall });
241
- expect(output).toContain('Fetched 3 team members');
242
- expect(output).toContain('Expense summary:');
243
- expect(output).toContain('Alice:');
244
- expect(output).toContain('Bob:');
245
- expect(output).toContain('Charlie:');
246
- expect(output).toContain('(2 items)');
247
- expect(output).toContain('(3 items)');
248
- }, 15000);
249
- it('uses only provided tool definitions (subset)', async () => {
250
- const weatherToolDef = toolDefinitions.find((t) => t.name === 'get_weather');
251
- const args = {
252
- code: `
253
- import asyncio
254
-
255
- sf, nyc = await asyncio.gather(
256
- get_weather(city="San Francisco"),
257
- get_weather(city="New York")
258
- )
259
-
260
- print(f"SF: {sf['temperature']}°F vs NYC: {nyc['temperature']}°F")
261
- difference = abs(sf['temperature'] - nyc['temperature'])
262
- print(f"Temperature difference: {difference}°F")
263
- `,
264
- };
265
- const toolCall = {
266
- name: 'programmatic_code_execution',
267
- args,
268
- toolMap,
269
- toolDefs: [weatherToolDef],
270
- };
271
- const output = await ptcTool.invoke(args, { toolCall });
272
- expect(output).toContain('SF: 65°F vs NYC: 75°F');
273
- expect(output).toContain('Temperature difference: 10°F');
274
- }, 10000);
275
- });
276
- //# sourceMappingURL=ProgrammaticToolCalling.integration.test.js.map