@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.
- package/dist/cjs/graphs/Graph.cjs +12 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +105 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/run.cjs +20 -9
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +12 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +105 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/run.mjs +20 -9
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +13 -1
- package/src/graphs/MultiAgentGraph.ts +128 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +205 -0
- package/src/run.ts +20 -11
- package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
- package/src/utils/llm.ts +1 -0
- package/src/agents/AgentContext.js +0 -782
- package/src/agents/AgentContext.test.js +0 -421
- package/src/agents/__tests__/AgentContext.test.js +0 -678
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
- package/src/common/enum.js +0 -192
- package/src/common/index.js +0 -3
- package/src/events.js +0 -166
- package/src/graphs/Graph.js +0 -1857
- package/src/graphs/MultiAgentGraph.js +0 -1092
- package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
- package/src/graphs/__tests__/structured-output.test.js +0 -144
- package/src/graphs/contextManagement.e2e.test.js +0 -718
- package/src/graphs/contextManagement.test.js +0 -485
- package/src/graphs/handoffValidation.test.js +0 -276
- package/src/graphs/index.js +0 -3
- package/src/index.js +0 -28
- package/src/instrumentation.js +0 -21
- package/src/llm/anthropic/index.js +0 -319
- package/src/llm/anthropic/types.js +0 -46
- package/src/llm/anthropic/utils/message_inputs.js +0 -627
- package/src/llm/anthropic/utils/message_outputs.js +0 -290
- package/src/llm/anthropic/utils/output_parsers.js +0 -89
- package/src/llm/anthropic/utils/tools.js +0 -25
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
- package/src/llm/bedrock/index.js +0 -303
- package/src/llm/bedrock/types.js +0 -2
- package/src/llm/bedrock/utils/index.js +0 -6
- package/src/llm/bedrock/utils/message_inputs.js +0 -463
- package/src/llm/bedrock/utils/message_outputs.js +0 -269
- package/src/llm/fake.js +0 -92
- package/src/llm/google/index.js +0 -215
- package/src/llm/google/types.js +0 -12
- package/src/llm/google/utils/common.js +0 -670
- package/src/llm/google/utils/tools.js +0 -111
- package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
- package/src/llm/openai/index.js +0 -1033
- package/src/llm/openai/types.js +0 -2
- package/src/llm/openai/utils/index.js +0 -756
- package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
- package/src/llm/openrouter/index.js +0 -261
- package/src/llm/openrouter/reasoning.test.js +0 -181
- package/src/llm/providers.js +0 -36
- package/src/llm/text.js +0 -65
- package/src/llm/vertexai/index.js +0 -402
- package/src/messages/__tests__/tools.test.js +0 -392
- package/src/messages/cache.js +0 -404
- package/src/messages/cache.test.js +0 -1167
- package/src/messages/content.js +0 -48
- package/src/messages/content.test.js +0 -314
- package/src/messages/core.js +0 -359
- package/src/messages/ensureThinkingBlock.test.js +0 -997
- package/src/messages/format.js +0 -973
- package/src/messages/formatAgentMessages.test.js +0 -2278
- package/src/messages/formatAgentMessages.tools.test.js +0 -362
- package/src/messages/formatMessage.test.js +0 -608
- package/src/messages/ids.js +0 -18
- package/src/messages/index.js +0 -9
- package/src/messages/labelContentByAgent.test.js +0 -725
- package/src/messages/prune.js +0 -438
- package/src/messages/reducer.js +0 -60
- package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
- package/src/messages/summarize.js +0 -146
- package/src/messages/summarize.test.js +0 -332
- package/src/messages/tools.js +0 -90
- package/src/mockStream.js +0 -81
- package/src/prompts/collab.js +0 -7
- package/src/prompts/index.js +0 -3
- package/src/prompts/taskmanager.js +0 -58
- package/src/run.js +0 -427
- package/src/schemas/index.js +0 -3
- package/src/schemas/schema-preparation.test.js +0 -370
- package/src/schemas/validate.js +0 -314
- package/src/schemas/validate.test.js +0 -264
- package/src/scripts/abort.js +0 -127
- package/src/scripts/ant_web_search.js +0 -130
- package/src/scripts/ant_web_search_edge_case.js +0 -133
- package/src/scripts/ant_web_search_error_edge_case.js +0 -119
- package/src/scripts/args.js +0 -41
- package/src/scripts/bedrock-cache-debug.js +0 -186
- package/src/scripts/bedrock-content-aggregation-test.js +0 -195
- package/src/scripts/bedrock-merge-test.js +0 -80
- package/src/scripts/bedrock-parallel-tools-test.js +0 -150
- package/src/scripts/caching.js +0 -106
- package/src/scripts/cli.js +0 -152
- package/src/scripts/cli2.js +0 -119
- package/src/scripts/cli3.js +0 -163
- package/src/scripts/cli4.js +0 -165
- package/src/scripts/cli5.js +0 -165
- package/src/scripts/code_exec.js +0 -171
- package/src/scripts/code_exec_files.js +0 -180
- package/src/scripts/code_exec_multi_session.js +0 -185
- package/src/scripts/code_exec_ptc.js +0 -265
- package/src/scripts/code_exec_session.js +0 -217
- package/src/scripts/code_exec_simple.js +0 -120
- package/src/scripts/content.js +0 -111
- package/src/scripts/empty_input.js +0 -125
- package/src/scripts/handoff-test.js +0 -96
- package/src/scripts/image.js +0 -138
- package/src/scripts/memory.js +0 -83
- package/src/scripts/multi-agent-chain.js +0 -271
- package/src/scripts/multi-agent-conditional.js +0 -185
- package/src/scripts/multi-agent-document-review-chain.js +0 -171
- package/src/scripts/multi-agent-hybrid-flow.js +0 -264
- package/src/scripts/multi-agent-parallel-start.js +0 -214
- package/src/scripts/multi-agent-parallel.js +0 -346
- package/src/scripts/multi-agent-sequence.js +0 -184
- package/src/scripts/multi-agent-supervisor.js +0 -324
- package/src/scripts/multi-agent-test.js +0 -147
- package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
- package/src/scripts/parallel-full-metadata-test.js +0 -176
- package/src/scripts/parallel-tools-test.js +0 -256
- package/src/scripts/programmatic_exec.js +0 -277
- package/src/scripts/programmatic_exec_agent.js +0 -168
- package/src/scripts/search.js +0 -118
- package/src/scripts/sequential-full-metadata-test.js +0 -143
- package/src/scripts/simple.js +0 -174
- package/src/scripts/single-agent-metadata-test.js +0 -152
- package/src/scripts/stream.js +0 -113
- package/src/scripts/test-custom-prompt-key.js +0 -132
- package/src/scripts/test-handoff-input.js +0 -143
- package/src/scripts/test-handoff-preamble.js +0 -227
- package/src/scripts/test-handoff-steering.js +0 -353
- package/src/scripts/test-multi-agent-list-handoff.js +0 -318
- package/src/scripts/test-parallel-agent-labeling.js +0 -253
- package/src/scripts/test-parallel-handoffs.js +0 -229
- package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
- package/src/scripts/test-thinking-handoff.js +0 -132
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
- package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
- package/src/scripts/test-tools-before-handoff.js +0 -187
- package/src/scripts/test_code_api.js +0 -263
- package/src/scripts/thinking-bedrock.js +0 -128
- package/src/scripts/thinking-vertexai.js +0 -130
- package/src/scripts/thinking.js +0 -134
- package/src/scripts/tool_search.js +0 -114
- package/src/scripts/tools.js +0 -125
- package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
- package/src/specs/agent-handoffs.test.js +0 -924
- package/src/specs/anthropic.simple.test.js +0 -287
- package/src/specs/azure.simple.test.js +0 -381
- package/src/specs/cache.simple.test.js +0 -282
- package/src/specs/custom-event-await.test.js +0 -148
- package/src/specs/deepseek.simple.test.js +0 -189
- package/src/specs/emergency-prune.test.js +0 -308
- package/src/specs/moonshot.simple.test.js +0 -237
- package/src/specs/observability.integration.test.js +0 -1337
- package/src/specs/openai.simple.test.js +0 -233
- package/src/specs/openrouter.simple.test.js +0 -202
- package/src/specs/prune.test.js +0 -733
- package/src/specs/reasoning.test.js +0 -144
- package/src/specs/spec.utils.js +0 -4
- package/src/specs/thinking-handoff.test.js +0 -486
- package/src/specs/thinking-prune.test.js +0 -600
- package/src/specs/token-distribution-edge-case.test.js +0 -246
- package/src/specs/token-memoization.test.js +0 -32
- package/src/specs/tokens.test.js +0 -49
- package/src/specs/tool-error.test.js +0 -139
- package/src/splitStream.js +0 -204
- package/src/splitStream.test.js +0 -504
- package/src/stream.js +0 -650
- package/src/stream.test.js +0 -225
- package/src/test/mockTools.js +0 -340
- package/src/tools/BrowserTools.js +0 -245
- package/src/tools/Calculator.js +0 -38
- package/src/tools/Calculator.test.js +0 -225
- package/src/tools/CodeExecutor.js +0 -233
- package/src/tools/ProgrammaticToolCalling.js +0 -602
- package/src/tools/StreamingToolCallBuffer.js +0 -179
- package/src/tools/ToolNode.js +0 -930
- package/src/tools/ToolSearch.js +0 -904
- package/src/tools/__tests__/BrowserTools.test.js +0 -306
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
- package/src/tools/__tests__/ToolApproval.test.js +0 -675
- package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
- package/src/tools/__tests__/ToolNode.session.test.js +0 -319
- package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
- package/src/tools/__tests__/ToolSearch.test.js +0 -812
- package/src/tools/__tests__/handlers.test.js +0 -799
- package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
- package/src/tools/handlers.js +0 -306
- package/src/tools/schema.js +0 -25
- package/src/tools/search/anthropic.js +0 -34
- package/src/tools/search/content.js +0 -116
- package/src/tools/search/content.test.js +0 -133
- package/src/tools/search/firecrawl.js +0 -173
- package/src/tools/search/format.js +0 -198
- package/src/tools/search/highlights.js +0 -241
- package/src/tools/search/index.js +0 -3
- package/src/tools/search/jina-reranker.test.js +0 -106
- package/src/tools/search/rerankers.js +0 -165
- package/src/tools/search/schema.js +0 -102
- package/src/tools/search/search.js +0 -561
- package/src/tools/search/serper-scraper.js +0 -126
- package/src/tools/search/test.js +0 -129
- package/src/tools/search/tool.js +0 -453
- package/src/tools/search/types.js +0 -2
- package/src/tools/search/utils.js +0 -59
- package/src/types/graph.js +0 -24
- package/src/types/graph.test.js +0 -192
- package/src/types/index.js +0 -7
- package/src/types/llm.js +0 -2
- package/src/types/messages.js +0 -2
- package/src/types/run.js +0 -2
- package/src/types/stream.js +0 -2
- package/src/types/tools.js +0 -2
- package/src/utils/contextAnalytics.js +0 -79
- package/src/utils/contextAnalytics.test.js +0 -166
- package/src/utils/events.js +0 -26
- package/src/utils/graph.js +0 -11
- package/src/utils/handlers.js +0 -65
- package/src/utils/index.js +0 -10
- package/src/utils/llm.js +0 -21
- package/src/utils/llmConfig.js +0 -205
- package/src/utils/logging.js +0 -37
- package/src/utils/misc.js +0 -51
- package/src/utils/run.js +0 -69
- package/src/utils/schema.js +0 -21
- package/src/utils/title.js +0 -119
- package/src/utils/tokens.js +0 -92
- 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
|