@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,245 +0,0 @@
1
- import { z } from 'zod';
2
- import { tool } from '@langchain/core/tools';
3
- /**
4
- * Browser tool names - keep in sync with ranger-browser extension
5
- * These tools execute locally in the browser extension, NOT on the server
6
- */
7
- export const EBrowserTools = {
8
- CLICK: 'browser_click',
9
- TYPE: 'browser_type',
10
- NAVIGATE: 'browser_navigate',
11
- SCROLL: 'browser_scroll',
12
- EXTRACT: 'browser_extract',
13
- HOVER: 'browser_hover',
14
- WAIT: 'browser_wait',
15
- BACK: 'browser_back',
16
- SCREENSHOT: 'browser_screenshot',
17
- GET_PAGE_STATE: 'browser_get_page_state',
18
- KEYPRESS: 'browser_keypress',
19
- SWITCH_TAB: 'browser_switch_tab',
20
- };
21
- /**
22
- * Check if browser capability is available based on request headers or context
23
- * The browser extension sets these headers when connected:
24
- * - X-Illuma-Browser-Extension: true
25
- * - X-Illuma-Browser-Capable: true
26
- */
27
- export function hasBrowserCapability(req) {
28
- if (!req?.headers) {
29
- return false;
30
- }
31
- const browserExtension = req.headers['x-illuma-browser-extension'];
32
- const browserCapable = req.headers['x-illuma-browser-capable'];
33
- return browserExtension === 'true' || browserCapable === 'true';
34
- }
35
- // Tool schemas
36
- const BrowserClickSchema = z.object({
37
- index: z
38
- .number()
39
- .describe('The [index] of the element to click. Use fieldLabel to identify the correct element. For form fields, target <input> or <textarea> elements, NOT parent <div> containers.'),
40
- });
41
- const BrowserTypeSchema = z.object({
42
- index: z
43
- .number()
44
- .describe('The [index] of the INPUT element to type into. Target <input> or <textarea> elements. Check fieldLabel to identify the correct field.'),
45
- text: z.string().describe('The text to type into the element'),
46
- pressEnter: z
47
- .boolean()
48
- .optional()
49
- .describe('Whether to press Enter after typing (useful for search forms and submitting)'),
50
- });
51
- const BrowserNavigateSchema = z.object({
52
- url: z
53
- .string()
54
- .describe('The full URL to navigate to (must include https://)'),
55
- });
56
- const BrowserScrollSchema = z.object({
57
- direction: z
58
- .enum(['up', 'down', 'left', 'right'])
59
- .describe('Direction to scroll'),
60
- amount: z
61
- .number()
62
- .optional()
63
- .describe('Pixels to scroll (default: one viewport height)'),
64
- });
65
- const BrowserExtractSchema = z.object({
66
- query: z
67
- .string()
68
- .optional()
69
- .describe('Optional: specific content to extract from the page'),
70
- });
71
- const BrowserHoverSchema = z.object({
72
- index: z.number().describe('The index number of the element to hover over'),
73
- });
74
- const BrowserWaitSchema = z.object({
75
- duration: z
76
- .number()
77
- .optional()
78
- .describe('Milliseconds to wait (default: 1000)'),
79
- });
80
- const BrowserBackSchema = z.object({});
81
- const BrowserScreenshotSchema = z.object({});
82
- const BrowserGetPageStateSchema = z.object({});
83
- const BrowserKeypressSchema = z.object({
84
- keys: z
85
- .string()
86
- .describe('Keyboard keys to press. Use "+" to combine modifiers (e.g., "Control+Enter", "Control+a", "Escape", "Tab", "Enter"). Common shortcuts: Control+Enter (submit forms/send), Escape (close dialogs), Tab (next field).'),
87
- });
88
- const BrowserSwitchTabSchema = z.object({
89
- tabId: z
90
- .number()
91
- .describe('The tab ID to switch to. Use the tab IDs shown in the tabs list from page state.'),
92
- });
93
- /**
94
- * Format browser action result for LLM consumption
95
- */
96
- function formatResultForLLM(result, action) {
97
- const parts = [];
98
- // Include error info but DON'T discard page state — the extension often sends
99
- // success=false with valid page state (URL, elementList) that the LLM needs
100
- if (!result.success && result.error) {
101
- parts.push(`**Note:** Action "${action}" reported: ${result.error}`);
102
- }
103
- if (result.url != null && result.url !== '') {
104
- parts.push(`**Current URL:** ${result.url}`);
105
- }
106
- if (result.title != null && result.title !== '') {
107
- parts.push(`**Page Title:** ${result.title}`);
108
- }
109
- if (result.elementList != null && result.elementList !== '') {
110
- parts.push(`\n**Interactive Elements** (for typing: target <input> elements with fieldLabel, NOT parent <div> containers):\n${result.elementList}`);
111
- }
112
- if (result.screenshot != null && result.screenshot !== '') {
113
- parts.push('\n[Screenshot captured and displayed to user]');
114
- }
115
- if (parts.length === 0) {
116
- if (!result.success) {
117
- return `Browser action "${action}" failed: ${result.error || 'Unknown error'}`;
118
- }
119
- return `Browser action "${action}" completed successfully.`;
120
- }
121
- return parts.join('\n');
122
- }
123
- /**
124
- * Create browser tools with optional callback for waiting on results
125
- *
126
- * When waitForResult callback is provided:
127
- * 1. Tool returns marker that triggers extension
128
- * 2. Tool then awaits callback to get actual results
129
- * 3. Returns real page state to LLM
130
- *
131
- * When no callback:
132
- * 1. Tool returns marker only (for non-server contexts)
133
- *
134
- * NOTE: These tools use TEXT-BASED element lists, NOT screenshots
135
- * Screenshots would be 100K+ tokens each - element lists are ~100 tokens
136
- */
137
- export function createBrowserTools(options) {
138
- const { waitForResult } = options || {};
139
- const tools = [];
140
- /**
141
- * Helper to create tool function that optionally waits for results
142
- * The toolCallId is extracted from the RunnableConfig passed by LangChain
143
- */
144
- const createToolFunction = (action) => {
145
- return async (args, config) => {
146
- const toolCallId = config?.toolCall?.id ??
147
- `tool_${Date.now()}_${Math.random().toString(36).slice(2)}`;
148
- // Create marker for extension
149
- const marker = {
150
- requiresBrowserExecution: true,
151
- action,
152
- args,
153
- toolCallId,
154
- };
155
- // If no callback, return marker immediately (extension handles via SSE interception)
156
- if (!waitForResult) {
157
- return JSON.stringify(marker);
158
- }
159
- // With callback: wait for actual results from extension
160
- // The marker is still returned initially via SSE, but we wait for the callback
161
- try {
162
- const result = await waitForResult(action, args, toolCallId);
163
- return formatResultForLLM(result, action);
164
- }
165
- catch (error) {
166
- const errorMessage = error instanceof Error ? error.message : String(error);
167
- return `Browser action "${action}" failed: ${errorMessage}`;
168
- }
169
- };
170
- };
171
- // browser_click
172
- tools.push(tool(createToolFunction('click'), {
173
- name: EBrowserTools.CLICK,
174
- description: 'Click element by [index]. Use fieldLabel attribute to identify correct element. For form fields, target <input> elements NOT parent <div> containers.',
175
- schema: BrowserClickSchema,
176
- }));
177
- // browser_type
178
- tools.push(tool(createToolFunction('type'), {
179
- name: EBrowserTools.TYPE,
180
- description: 'Type text into <input> element by [index]. CRITICAL: Always target <input> or <textarea> tags (NOT parent <div> containers). Use fieldLabel to identify correct field (e.g., fieldLabel="To recipients" for To field).',
181
- schema: BrowserTypeSchema,
182
- }));
183
- // browser_navigate
184
- tools.push(tool(createToolFunction('navigate'), {
185
- name: EBrowserTools.NAVIGATE,
186
- description: 'Navigate to URL (include https://). Returns new page element list.',
187
- schema: BrowserNavigateSchema,
188
- }));
189
- // browser_scroll
190
- tools.push(tool(createToolFunction('scroll'), {
191
- name: EBrowserTools.SCROLL,
192
- description: 'Scroll page (up/down/left/right). Returns updated element list.',
193
- schema: BrowserScrollSchema,
194
- }));
195
- // browser_extract
196
- tools.push(tool(createToolFunction('extract'), {
197
- name: EBrowserTools.EXTRACT,
198
- description: 'Extract page content. Returns URL, title, and element list.',
199
- schema: BrowserExtractSchema,
200
- }));
201
- // browser_hover
202
- tools.push(tool(createToolFunction('hover'), {
203
- name: EBrowserTools.HOVER,
204
- description: 'Hover element by [index] to reveal menus/tooltips. Returns updated element list.',
205
- schema: BrowserHoverSchema,
206
- }));
207
- // browser_wait
208
- tools.push(tool(createToolFunction('wait'), {
209
- name: EBrowserTools.WAIT,
210
- description: 'Wait for async content to load. Returns updated element list.',
211
- schema: BrowserWaitSchema,
212
- }));
213
- // browser_back
214
- tools.push(tool(createToolFunction('back'), {
215
- name: EBrowserTools.BACK,
216
- description: 'Go back in browser history. Returns previous page element list.',
217
- schema: BrowserBackSchema,
218
- }));
219
- // browser_screenshot
220
- tools.push(tool(createToolFunction('screenshot'), {
221
- name: EBrowserTools.SCREENSHOT,
222
- description: 'Capture screenshot. Displayed to user. Use get_page_state for automation.',
223
- schema: BrowserScreenshotSchema,
224
- }));
225
- // browser_get_page_state
226
- tools.push(tool(createToolFunction('get_page_state'), {
227
- name: EBrowserTools.GET_PAGE_STATE,
228
- description: 'Get page URL, title, and interactive elements with [index] for actions. Start here.',
229
- schema: BrowserGetPageStateSchema,
230
- }));
231
- // browser_keypress - for keyboard shortcuts
232
- tools.push(tool(createToolFunction('keypress'), {
233
- name: EBrowserTools.KEYPRESS,
234
- description: 'Send keyboard shortcut or key press. Use for: Control+Enter (send email/submit), Escape (close dialog/cancel), Tab (next field), Enter (confirm). The keys are sent to the currently focused element.',
235
- schema: BrowserKeypressSchema,
236
- }));
237
- // browser_switch_tab - for switching between tabs
238
- tools.push(tool(createToolFunction('switch_tab'), {
239
- name: EBrowserTools.SWITCH_TAB,
240
- description: 'Switch to a different browser tab by its ID. Tab IDs are shown in the page state. Use this to work with existing open tabs (e.g., use existing Gmail tab instead of opening a new one).',
241
- schema: BrowserSwitchTabSchema,
242
- }));
243
- return tools;
244
- }
245
- //# sourceMappingURL=BrowserTools.js.map
@@ -1,38 +0,0 @@
1
- import { Tool } from '@langchain/core/tools';
2
- import * as math from 'mathjs';
3
- export const CalculatorToolName = 'calculator';
4
- export const CalculatorToolDescription = 'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';
5
- export const CalculatorSchema = {
6
- type: 'object',
7
- properties: {
8
- input: {
9
- type: 'string',
10
- description: 'A valid mathematical expression to evaluate',
11
- },
12
- },
13
- required: ['input'],
14
- };
15
- export const CalculatorToolDefinition = {
16
- name: CalculatorToolName,
17
- description: CalculatorToolDescription,
18
- schema: CalculatorSchema,
19
- };
20
- export class Calculator extends Tool {
21
- static lc_name() {
22
- return 'Calculator';
23
- }
24
- get lc_namespace() {
25
- return [...super.lc_namespace, 'calculator'];
26
- }
27
- name = CalculatorToolName;
28
- async _call(input) {
29
- try {
30
- return math.evaluate(input).toString();
31
- }
32
- catch {
33
- return 'I don\'t know how to do that.';
34
- }
35
- }
36
- description = CalculatorToolDescription;
37
- }
38
- //# sourceMappingURL=Calculator.js.map
@@ -1,225 +0,0 @@
1
- import { Calculator } from './Calculator';
2
- describe('Calculator', () => {
3
- let calculator;
4
- beforeEach(() => {
5
- calculator = new Calculator();
6
- });
7
- describe('basic properties', () => {
8
- it('should have correct name', () => {
9
- expect(calculator.name).toBe('calculator');
10
- });
11
- it('should have correct description', () => {
12
- expect(calculator.description).toBe('Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.');
13
- });
14
- it('should have correct lc_name', () => {
15
- expect(Calculator.lc_name()).toBe('Calculator');
16
- });
17
- it('should have correct lc_namespace', () => {
18
- const namespace = calculator.lc_namespace;
19
- expect(namespace).toContain('calculator');
20
- });
21
- });
22
- describe('basic arithmetic operations', () => {
23
- it('should add two numbers', async () => {
24
- const result = await calculator._call('2 + 3');
25
- expect(result).toBe('5');
26
- });
27
- it('should subtract two numbers', async () => {
28
- const result = await calculator._call('10 - 4');
29
- expect(result).toBe('6');
30
- });
31
- it('should multiply two numbers', async () => {
32
- const result = await calculator._call('6 * 7');
33
- expect(result).toBe('42');
34
- });
35
- it('should divide two numbers', async () => {
36
- const result = await calculator._call('15 / 3');
37
- expect(result).toBe('5');
38
- });
39
- it('should handle modulo operation', async () => {
40
- const result = await calculator._call('17 % 5');
41
- expect(result).toBe('2');
42
- });
43
- it('should handle exponentiation', async () => {
44
- const result = await calculator._call('2 ^ 3');
45
- expect(result).toBe('8');
46
- });
47
- });
48
- describe('complex expressions', () => {
49
- it('should handle order of operations', async () => {
50
- const result = await calculator._call('2 + 3 * 4');
51
- expect(result).toBe('14');
52
- });
53
- it('should handle parentheses', async () => {
54
- const result = await calculator._call('(2 + 3) * 4');
55
- expect(result).toBe('20');
56
- });
57
- it('should handle nested parentheses', async () => {
58
- const result = await calculator._call('((2 + 3) * 4) / 5');
59
- expect(result).toBe('4');
60
- });
61
- it('should handle multiple operations', async () => {
62
- const result = await calculator._call('(10 + 5) * 2 - 8 / 4');
63
- expect(result).toBe('28');
64
- });
65
- });
66
- describe('decimal numbers', () => {
67
- it('should handle decimal addition', async () => {
68
- const result = await calculator._call('2.5 + 3.7');
69
- expect(result).toBe('6.2');
70
- });
71
- it('should handle decimal multiplication', async () => {
72
- const result = await calculator._call('2.5 * 4');
73
- expect(result).toBe('10');
74
- });
75
- it('should handle decimal division', async () => {
76
- const result = await calculator._call('7.5 / 2.5');
77
- expect(result).toBe('3');
78
- });
79
- });
80
- describe('negative numbers', () => {
81
- it('should handle negative numbers in addition', async () => {
82
- const result = await calculator._call('-5 + 3');
83
- expect(result).toBe('-2');
84
- });
85
- it('should handle negative numbers in subtraction', async () => {
86
- const result = await calculator._call('10 - (-5)');
87
- expect(result).toBe('15');
88
- });
89
- it('should handle negative numbers in multiplication', async () => {
90
- const result = await calculator._call('-4 * -3');
91
- expect(result).toBe('12');
92
- });
93
- it('should handle negative numbers in division', async () => {
94
- const result = await calculator._call('-12 / 4');
95
- expect(result).toBe('-3');
96
- });
97
- });
98
- describe('mathematical functions', () => {
99
- it('should handle square root', async () => {
100
- const result = await calculator._call('sqrt(16)');
101
- expect(result).toBe('4');
102
- });
103
- it('should handle absolute value', async () => {
104
- const result = await calculator._call('abs(-42)');
105
- expect(result).toBe('42');
106
- });
107
- it('should handle sine function', async () => {
108
- const result = await calculator._call('sin(0)');
109
- expect(result).toBe('0');
110
- });
111
- it('should handle cosine function', async () => {
112
- const result = await calculator._call('cos(0)');
113
- expect(result).toBe('1');
114
- });
115
- it('should handle logarithm', async () => {
116
- const result = await calculator._call('log(10)');
117
- expect(parseFloat(result)).toBeCloseTo(2.302585, 5);
118
- });
119
- it('should handle exponential', async () => {
120
- const result = await calculator._call('exp(0)');
121
- expect(result).toBe('1');
122
- });
123
- it('should handle floor function', async () => {
124
- const result = await calculator._call('floor(4.7)');
125
- expect(result).toBe('4');
126
- });
127
- it('should handle ceil function', async () => {
128
- const result = await calculator._call('ceil(4.3)');
129
- expect(result).toBe('5');
130
- });
131
- it('should handle round function', async () => {
132
- const result = await calculator._call('round(4.5)');
133
- expect(result).toBe('5');
134
- });
135
- });
136
- describe('constants', () => {
137
- it('should handle pi constant', async () => {
138
- const result = await calculator._call('pi');
139
- expect(parseFloat(result)).toBeCloseTo(3.14159, 5);
140
- });
141
- it('should handle e constant', async () => {
142
- const result = await calculator._call('e');
143
- expect(parseFloat(result)).toBeCloseTo(2.71828, 5);
144
- });
145
- it('should use pi in calculations', async () => {
146
- const result = await calculator._call('2 * pi');
147
- expect(parseFloat(result)).toBeCloseTo(6.28318, 4);
148
- });
149
- });
150
- describe('error handling', () => {
151
- it('should return error message for invalid expression', async () => {
152
- const result = await calculator._call('invalid expression');
153
- expect(result).toBe('I don\'t know how to do that.');
154
- });
155
- it('should handle division by zero', async () => {
156
- const result = await calculator._call('5 / 0');
157
- expect(result).toBe('Infinity');
158
- });
159
- it('should return error message for incomplete expression', async () => {
160
- const result = await calculator._call('5 +');
161
- expect(result).toBe('I don\'t know how to do that.');
162
- });
163
- it('should return error message for mismatched parentheses', async () => {
164
- const result = await calculator._call('(5 + 3');
165
- expect(result).toBe('I don\'t know how to do that.');
166
- });
167
- it('should return error message for empty input', async () => {
168
- const result = await calculator._call('');
169
- expect(result).toBe('I don\'t know how to do that.');
170
- });
171
- it('should return error message for only whitespace', async () => {
172
- const result = await calculator._call(' ');
173
- expect(result).toBe('I don\'t know how to do that.');
174
- });
175
- it('should return error message for undefined variable', async () => {
176
- const result = await calculator._call('x + 5');
177
- expect(result).toBe('I don\'t know how to do that.');
178
- });
179
- });
180
- describe('edge cases', () => {
181
- it('should handle very large numbers', async () => {
182
- const result = await calculator._call('999999999 * 999999999');
183
- expect(parseFloat(result)).toBeCloseTo(999999998000000000, -10);
184
- });
185
- it('should handle very small decimal numbers', async () => {
186
- const result = await calculator._call('0.0001 + 0.0002');
187
- expect(parseFloat(result)).toBeCloseTo(0.0003, 10);
188
- });
189
- it('should handle expressions with spaces', async () => {
190
- const result = await calculator._call(' 5 + 3 ');
191
- expect(result).toBe('8');
192
- });
193
- it('should handle zero in calculations', async () => {
194
- const result = await calculator._call('0 + 0');
195
- expect(result).toBe('0');
196
- });
197
- it('should handle power of zero', async () => {
198
- const result = await calculator._call('5 ^ 0');
199
- expect(result).toBe('1');
200
- });
201
- it('should handle zero to the power', async () => {
202
- const result = await calculator._call('0 ^ 5');
203
- expect(result).toBe('0');
204
- });
205
- });
206
- describe('complex real-world calculations', () => {
207
- it('should calculate area of circle', async () => {
208
- const result = await calculator._call('pi * 5^2');
209
- expect(parseFloat(result)).toBeCloseTo(78.53981, 4);
210
- });
211
- it('should calculate compound interest formula component', async () => {
212
- const result = await calculator._call('(1 + 0.05/12)^(12*5)');
213
- expect(parseFloat(result)).toBeCloseTo(1.28336, 4);
214
- });
215
- it('should calculate percentage', async () => {
216
- const result = await calculator._call('(25 / 200) * 100');
217
- expect(result).toBe('12.5');
218
- });
219
- it('should calculate average', async () => {
220
- const result = await calculator._call('(10 + 20 + 30 + 40 + 50) / 5');
221
- expect(result).toBe('30');
222
- });
223
- });
224
- });
225
- //# sourceMappingURL=Calculator.test.js.map