instavm 0.16.0 → 0.17.0
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/README.md +86 -9
- package/dist/InstaVM-DjkmUcaP.d.mts +1393 -0
- package/dist/InstaVM-DjkmUcaP.d.ts +1393 -0
- package/dist/_instavmToolsCore-34H4iqVZ.d.mts +26 -0
- package/dist/_instavmToolsCore-BuaJyxXB.d.ts +26 -0
- package/dist/cli.js +5821 -2296
- package/dist/cli.js.map +1 -1
- package/dist/index.d.mts +12 -919
- package/dist/index.d.ts +12 -919
- package/dist/index.js +1464 -140
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1449 -135
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/azure-openai.d.mts +18 -0
- package/dist/integrations/azure-openai.d.ts +18 -0
- package/dist/integrations/azure-openai.js +332 -0
- package/dist/integrations/azure-openai.js.map +1 -0
- package/dist/integrations/azure-openai.mjs +299 -0
- package/dist/integrations/azure-openai.mjs.map +1 -0
- package/dist/integrations/langchain.d.mts +7 -0
- package/dist/integrations/langchain.d.ts +7 -0
- package/dist/integrations/langchain.js +364 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/integrations/langchain.mjs +327 -0
- package/dist/integrations/langchain.mjs.map +1 -0
- package/dist/integrations/llamaindex.d.mts +11 -0
- package/dist/integrations/llamaindex.d.ts +11 -0
- package/dist/integrations/llamaindex.js +415 -0
- package/dist/integrations/llamaindex.js.map +1 -0
- package/dist/integrations/llamaindex.mjs +378 -0
- package/dist/integrations/llamaindex.mjs.map +1 -0
- package/dist/integrations/ollama.d.mts +35 -0
- package/dist/integrations/ollama.d.ts +35 -0
- package/dist/integrations/ollama.js +421 -0
- package/dist/integrations/ollama.js.map +1 -0
- package/dist/integrations/ollama.mjs +391 -0
- package/dist/integrations/ollama.mjs.map +1 -0
- package/dist/integrations/openai.d.mts +19 -0
- package/dist/integrations/openai.d.ts +19 -0
- package/dist/integrations/openai.js +302 -0
- package/dist/integrations/openai.js.map +1 -0
- package/dist/integrations/openai.mjs +272 -0
- package/dist/integrations/openai.mjs.map +1 -0
- package/package.json +44 -3
- package/dist/integrations/openai/index.d.mts +0 -16
- package/dist/integrations/openai/index.d.ts +0 -16
- package/dist/integrations/openai/index.js +0 -38
- package/dist/integrations/openai/index.js.map +0 -1
- package/dist/integrations/openai/index.mjs +0 -12
- package/dist/integrations/openai/index.mjs.map +0 -1
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// src/integrations/_instavmToolsCore.ts
|
|
2
|
+
function getInstavmOpenAITools() {
|
|
3
|
+
return INSTAVM_OPENAI_TOOLS;
|
|
4
|
+
}
|
|
5
|
+
var INSTAVM_OPENAI_TOOLS = [
|
|
6
|
+
{
|
|
7
|
+
type: "function",
|
|
8
|
+
function: {
|
|
9
|
+
name: "create_browser_session",
|
|
10
|
+
description: "Create a new browser session for web automation",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
width: { type: "integer", description: "Browser width", default: 1920 },
|
|
15
|
+
height: { type: "integer", description: "Browser height", default: 1080 }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "function",
|
|
22
|
+
function: {
|
|
23
|
+
name: "navigate_to_url",
|
|
24
|
+
description: "Navigate browser to URL",
|
|
25
|
+
parameters: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: { url: { type: "string", description: "URL to navigate to" } },
|
|
28
|
+
required: ["url"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "function",
|
|
34
|
+
function: {
|
|
35
|
+
name: "extract_page_content",
|
|
36
|
+
description: "Extract text content from page",
|
|
37
|
+
parameters: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
selector: { type: "string", description: "CSS selector", default: "body" },
|
|
41
|
+
max_length: { type: "integer", description: "Max content length", default: 1e4 }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "function",
|
|
48
|
+
function: {
|
|
49
|
+
name: "extract_elements",
|
|
50
|
+
description: "Extract elements using CSS selector",
|
|
51
|
+
parameters: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
selector: { type: "string", description: "CSS selector" },
|
|
55
|
+
attributes: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: { type: "string" },
|
|
58
|
+
description: "Attributes to extract",
|
|
59
|
+
default: ["text"]
|
|
60
|
+
},
|
|
61
|
+
max_results: { type: "integer", description: "Max results", default: 10 }
|
|
62
|
+
},
|
|
63
|
+
required: ["selector"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "function",
|
|
69
|
+
function: {
|
|
70
|
+
name: "click_element",
|
|
71
|
+
description: "Click a page element",
|
|
72
|
+
parameters: {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: {
|
|
75
|
+
selector: { type: "string", description: "CSS selector" },
|
|
76
|
+
timeout: { type: "integer", description: "Timeout ms", default: 1e4 }
|
|
77
|
+
},
|
|
78
|
+
required: ["selector"]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "function",
|
|
84
|
+
function: {
|
|
85
|
+
name: "take_screenshot",
|
|
86
|
+
description: "Take page screenshot",
|
|
87
|
+
parameters: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
full_page: { type: "boolean", description: "Full page capture", default: true }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: "function",
|
|
97
|
+
function: {
|
|
98
|
+
name: "execute_python_code",
|
|
99
|
+
description: "Execute Python code. Use !command for bash (e.g., !pip install pandas)",
|
|
100
|
+
parameters: {
|
|
101
|
+
type: "object",
|
|
102
|
+
properties: { code: { type: "string", description: "Python/bash code to execute" } },
|
|
103
|
+
required: ["code"]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "function",
|
|
109
|
+
function: {
|
|
110
|
+
name: "scroll_page",
|
|
111
|
+
description: "Scroll page",
|
|
112
|
+
parameters: {
|
|
113
|
+
type: "object",
|
|
114
|
+
properties: {
|
|
115
|
+
x: { type: "integer", default: 0 },
|
|
116
|
+
y: { type: "integer", default: 500 }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "function",
|
|
123
|
+
function: {
|
|
124
|
+
name: "wait_for_element",
|
|
125
|
+
description: "Wait for element to appear",
|
|
126
|
+
parameters: {
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: {
|
|
129
|
+
selector: { type: "string", description: "CSS selector" },
|
|
130
|
+
timeout: { type: "integer", default: 1e4 }
|
|
131
|
+
},
|
|
132
|
+
required: ["selector"]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
];
|
|
137
|
+
function serializeExecution(result) {
|
|
138
|
+
return {
|
|
139
|
+
stdout: result.stdout,
|
|
140
|
+
stderr: result.stderr,
|
|
141
|
+
success: result.success,
|
|
142
|
+
executionTime: result.executionTime,
|
|
143
|
+
cpuTime: result.cpuTime,
|
|
144
|
+
sessionId: result.sessionId,
|
|
145
|
+
error: result.error
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function parseArgs(raw) {
|
|
149
|
+
if (!raw || !raw.trim()) return {};
|
|
150
|
+
try {
|
|
151
|
+
const v = JSON.parse(raw);
|
|
152
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
153
|
+
} catch {
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function executeInstavmToolCall(instavm, toolCall, browserSession) {
|
|
158
|
+
const functionName = toolCall.function.name;
|
|
159
|
+
const arguments_ = parseArgs(toolCall.function.arguments);
|
|
160
|
+
try {
|
|
161
|
+
if (functionName === "create_browser_session") {
|
|
162
|
+
const width = Number(arguments_.width ?? 1920);
|
|
163
|
+
const height = Number(arguments_.height ?? 1080);
|
|
164
|
+
const session = await instavm.browser.createSession({ viewportWidth: width, viewportHeight: height });
|
|
165
|
+
return {
|
|
166
|
+
success: true,
|
|
167
|
+
session_id: session.sessionId,
|
|
168
|
+
session,
|
|
169
|
+
message: `Created browser session ${session.sessionId}`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (functionName === "navigate_to_url") {
|
|
173
|
+
if (!browserSession) {
|
|
174
|
+
return { success: false, error: "No browser session. Create one first." };
|
|
175
|
+
}
|
|
176
|
+
const url = String(arguments_.url ?? "");
|
|
177
|
+
const result = await browserSession.navigate(url);
|
|
178
|
+
return { success: true, message: `Navigated to ${url}`, result };
|
|
179
|
+
}
|
|
180
|
+
if (functionName === "extract_page_content") {
|
|
181
|
+
if (!browserSession) {
|
|
182
|
+
return { success: false, error: "No browser session active" };
|
|
183
|
+
}
|
|
184
|
+
const selector = String(arguments_.selector ?? "body");
|
|
185
|
+
const maxLength = Number(arguments_.max_length ?? 1e4);
|
|
186
|
+
const elements = await browserSession.extractElements(selector, ["text"]);
|
|
187
|
+
if (elements?.length) {
|
|
188
|
+
const first = elements[0];
|
|
189
|
+
const text = String(first.text ?? first.content ?? "").slice(0, maxLength);
|
|
190
|
+
return { success: true, content: text, length: text.length };
|
|
191
|
+
}
|
|
192
|
+
return { success: false, error: "No content found" };
|
|
193
|
+
}
|
|
194
|
+
if (functionName === "extract_elements") {
|
|
195
|
+
if (!browserSession) {
|
|
196
|
+
return { success: false, error: "No browser session active" };
|
|
197
|
+
}
|
|
198
|
+
const selector = String(arguments_.selector ?? "");
|
|
199
|
+
const attributes = arguments_.attributes ?? ["text"];
|
|
200
|
+
const maxResults = Number(arguments_.max_results ?? 10);
|
|
201
|
+
const elements = await browserSession.extractElements(selector, attributes);
|
|
202
|
+
const list = Array.isArray(elements) ? elements : [];
|
|
203
|
+
return { success: true, elements: list.slice(0, maxResults), count: list.length };
|
|
204
|
+
}
|
|
205
|
+
if (functionName === "click_element") {
|
|
206
|
+
if (!browserSession) {
|
|
207
|
+
return { success: false, error: "No browser session active" };
|
|
208
|
+
}
|
|
209
|
+
const selector = String(arguments_.selector ?? "");
|
|
210
|
+
const timeout = Number(arguments_.timeout ?? 1e4);
|
|
211
|
+
await browserSession.click(selector, { timeout });
|
|
212
|
+
return { success: true, message: `Clicked ${selector}` };
|
|
213
|
+
}
|
|
214
|
+
if (functionName === "take_screenshot") {
|
|
215
|
+
if (!browserSession) {
|
|
216
|
+
return { success: false, error: "No browser session active" };
|
|
217
|
+
}
|
|
218
|
+
const fullPage = arguments_.full_page !== false;
|
|
219
|
+
const screenshot = await browserSession.screenshot({ fullPage });
|
|
220
|
+
return { success: true, screenshot_length: screenshot.length, screenshot };
|
|
221
|
+
}
|
|
222
|
+
if (functionName === "execute_python_code") {
|
|
223
|
+
const code = String(arguments_.code ?? "");
|
|
224
|
+
const result = await instavm.execute(code, { language: "python" });
|
|
225
|
+
return { success: true, output: serializeExecution(result) };
|
|
226
|
+
}
|
|
227
|
+
if (functionName === "scroll_page") {
|
|
228
|
+
if (!browserSession) {
|
|
229
|
+
return { success: false, error: "No browser session active" };
|
|
230
|
+
}
|
|
231
|
+
const x = Number(arguments_.x ?? 0);
|
|
232
|
+
const y = Number(arguments_.y ?? 500);
|
|
233
|
+
await browserSession.scroll({ x, y });
|
|
234
|
+
return { success: true, message: `Scrolled to (${x}, ${y})` };
|
|
235
|
+
}
|
|
236
|
+
if (functionName === "wait_for_element") {
|
|
237
|
+
if (!browserSession) {
|
|
238
|
+
return { success: false, error: "No browser session active" };
|
|
239
|
+
}
|
|
240
|
+
const selector = String(arguments_.selector ?? "");
|
|
241
|
+
const timeout = Number(arguments_.timeout ?? 1e4);
|
|
242
|
+
const result = await browserSession.waitFor("visible", selector, timeout);
|
|
243
|
+
return { success: true, message: `Element ${selector} visible`, result };
|
|
244
|
+
}
|
|
245
|
+
return { success: false, error: `Unknown function: ${functionName}` };
|
|
246
|
+
} catch (e) {
|
|
247
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
248
|
+
return { success: false, error: `Function ${functionName} failed: ${msg}` };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
var INSTAVM_OLLAMA_TOOLS = INSTAVM_OPENAI_TOOLS.filter(
|
|
252
|
+
(t) => ["create_browser_session", "navigate_to_url", "extract_page_content", "extract_elements", "execute_python_code", "take_screenshot"].includes(
|
|
253
|
+
t.function.name
|
|
254
|
+
)
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// src/integrations/azure-openai/index.ts
|
|
258
|
+
function getAzureTools() {
|
|
259
|
+
return getInstavmOpenAITools();
|
|
260
|
+
}
|
|
261
|
+
var getOpenAITools = getAzureTools;
|
|
262
|
+
async function executeAzureTool(instavm, toolCall, browserSession) {
|
|
263
|
+
return executeInstavmToolCall(instavm, toolCall, browserSession);
|
|
264
|
+
}
|
|
265
|
+
var executeTool = executeAzureTool;
|
|
266
|
+
var executeToolCall = executeAzureTool;
|
|
267
|
+
function getSystemPrompt() {
|
|
268
|
+
return `
|
|
269
|
+
You are a web automation assistant with access to browser and code execution tools.
|
|
270
|
+
|
|
271
|
+
Available capabilities:
|
|
272
|
+
- create_browser_session: Start browser automation
|
|
273
|
+
- navigate_to_url: Go to any website
|
|
274
|
+
- extract_page_content: Get page text content
|
|
275
|
+
- extract_elements: Get specific elements by CSS selector
|
|
276
|
+
- click_element: Click page elements
|
|
277
|
+
- take_screenshot: Capture page images
|
|
278
|
+
- execute_python_code: Run Python/bash code (use !pip install for packages)
|
|
279
|
+
- scroll_page: Scroll to coordinates
|
|
280
|
+
- wait_for_element: Wait for elements to load
|
|
281
|
+
|
|
282
|
+
Tips:
|
|
283
|
+
- Always create browser session before navigation
|
|
284
|
+
- Install packages with !pip install before importing
|
|
285
|
+
- Use screenshots when text extraction isn't enough
|
|
286
|
+
- Be systematic and handle errors gracefully
|
|
287
|
+
`.trim();
|
|
288
|
+
}
|
|
289
|
+
var getAzureSystemPrompt = getSystemPrompt;
|
|
290
|
+
export {
|
|
291
|
+
executeAzureTool,
|
|
292
|
+
executeTool,
|
|
293
|
+
executeToolCall,
|
|
294
|
+
getAzureSystemPrompt,
|
|
295
|
+
getAzureTools,
|
|
296
|
+
getOpenAITools,
|
|
297
|
+
getSystemPrompt
|
|
298
|
+
};
|
|
299
|
+
//# sourceMappingURL=azure-openai.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/_instavmToolsCore.ts","../../src/integrations/azure-openai/index.ts"],"sourcesContent":["import type { InstaVM } from '../client/InstaVM';\nimport type { BrowserSession } from '../client/BrowserSession';\nimport type { ExecutionResult } from '../types/execution';\n\n/** OpenAI / Azure / Ollama–compatible function tool schema. */\nexport type InstaVMOpenAITool = {\n type: 'function';\n function: {\n name: string;\n description: string;\n parameters: Record<string, unknown>;\n };\n};\n\nexport function getInstavmOpenAITools(): InstaVMOpenAITool[] {\n return INSTAVM_OPENAI_TOOLS;\n}\n\nconst INSTAVM_OPENAI_TOOLS: InstaVMOpenAITool[] = [\n {\n type: 'function',\n function: {\n name: 'create_browser_session',\n description: 'Create a new browser session for web automation',\n parameters: {\n type: 'object',\n properties: {\n width: { type: 'integer', description: 'Browser width', default: 1920 },\n height: { type: 'integer', description: 'Browser height', default: 1080 },\n },\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'navigate_to_url',\n description: 'Navigate browser to URL',\n parameters: {\n type: 'object',\n properties: { url: { type: 'string', description: 'URL to navigate to' } },\n required: ['url'],\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'extract_page_content',\n description: 'Extract text content from page',\n parameters: {\n type: 'object',\n properties: {\n selector: { type: 'string', description: 'CSS selector', default: 'body' },\n max_length: { type: 'integer', description: 'Max content length', default: 10000 },\n },\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'extract_elements',\n description: 'Extract elements using CSS selector',\n parameters: {\n type: 'object',\n properties: {\n selector: { type: 'string', description: 'CSS selector' },\n attributes: {\n type: 'array',\n items: { type: 'string' },\n description: 'Attributes to extract',\n default: ['text'],\n },\n max_results: { type: 'integer', description: 'Max results', default: 10 },\n },\n required: ['selector'],\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'click_element',\n description: 'Click a page element',\n parameters: {\n type: 'object',\n properties: {\n selector: { type: 'string', description: 'CSS selector' },\n timeout: { type: 'integer', description: 'Timeout ms', default: 10000 },\n },\n required: ['selector'],\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'take_screenshot',\n description: 'Take page screenshot',\n parameters: {\n type: 'object',\n properties: {\n full_page: { type: 'boolean', description: 'Full page capture', default: true },\n },\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'execute_python_code',\n description: 'Execute Python code. Use !command for bash (e.g., !pip install pandas)',\n parameters: {\n type: 'object',\n properties: { code: { type: 'string', description: 'Python/bash code to execute' } },\n required: ['code'],\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'scroll_page',\n description: 'Scroll page',\n parameters: {\n type: 'object',\n properties: {\n x: { type: 'integer', default: 0 },\n y: { type: 'integer', default: 500 },\n },\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'wait_for_element',\n description: 'Wait for element to appear',\n parameters: {\n type: 'object',\n properties: {\n selector: { type: 'string', description: 'CSS selector' },\n timeout: { type: 'integer', default: 10000 },\n },\n required: ['selector'],\n },\n },\n },\n];\n\nfunction serializeExecution(result: ExecutionResult): Record<string, unknown> {\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n success: result.success,\n executionTime: result.executionTime,\n cpuTime: result.cpuTime,\n sessionId: result.sessionId,\n error: result.error,\n };\n}\n\nexport type ToolCallLike = {\n function: {\n name: string;\n arguments: string;\n };\n};\n\nfunction parseArgs(raw: string): Record<string, unknown> {\n if (!raw || !raw.trim()) return {};\n try {\n const v = JSON.parse(raw) as unknown;\n return v && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : {};\n } catch {\n return {};\n }\n}\n\n/**\n * Execute a single OpenAI-style tool call (parity with Python `execute_tool`).\n * Returns a dict; when a new browser session is created, `session` holds the `BrowserSession` instance.\n */\nexport async function executeInstavmToolCall(\n instavm: InstaVM,\n toolCall: ToolCallLike,\n browserSession?: BrowserSession | null,\n): Promise<Record<string, unknown> & { session?: BrowserSession }> {\n const functionName = toolCall.function.name;\n const arguments_ = parseArgs(toolCall.function.arguments);\n\n try {\n if (functionName === 'create_browser_session') {\n const width = Number(arguments_.width ?? 1920);\n const height = Number(arguments_.height ?? 1080);\n const session = await instavm.browser.createSession({ viewportWidth: width, viewportHeight: height });\n return {\n success: true,\n session_id: session.sessionId,\n session,\n message: `Created browser session ${session.sessionId}`,\n };\n }\n\n if (functionName === 'navigate_to_url') {\n if (!browserSession) {\n return { success: false, error: 'No browser session. Create one first.' };\n }\n const url = String(arguments_.url ?? '');\n const result = await browserSession.navigate(url);\n return { success: true, message: `Navigated to ${url}`, result };\n }\n\n if (functionName === 'extract_page_content') {\n if (!browserSession) {\n return { success: false, error: 'No browser session active' };\n }\n const selector = String(arguments_.selector ?? 'body');\n const maxLength = Number(arguments_.max_length ?? 10000);\n const elements = await browserSession.extractElements(selector, ['text']);\n if (elements?.length) {\n const first = elements[0] as Record<string, unknown>;\n const text = String(first.text ?? first.content ?? '').slice(0, maxLength);\n return { success: true, content: text, length: text.length };\n }\n return { success: false, error: 'No content found' };\n }\n\n if (functionName === 'extract_elements') {\n if (!browserSession) {\n return { success: false, error: 'No browser session active' };\n }\n const selector = String(arguments_.selector ?? '');\n const attributes = (arguments_.attributes as string[] | undefined) ?? ['text'];\n const maxResults = Number(arguments_.max_results ?? 10);\n const elements = await browserSession.extractElements(selector, attributes);\n const list = Array.isArray(elements) ? elements : [];\n return { success: true, elements: list.slice(0, maxResults), count: list.length };\n }\n\n if (functionName === 'click_element') {\n if (!browserSession) {\n return { success: false, error: 'No browser session active' };\n }\n const selector = String(arguments_.selector ?? '');\n const timeout = Number(arguments_.timeout ?? 10000);\n await browserSession.click(selector, { timeout });\n return { success: true, message: `Clicked ${selector}` };\n }\n\n if (functionName === 'take_screenshot') {\n if (!browserSession) {\n return { success: false, error: 'No browser session active' };\n }\n const fullPage = arguments_.full_page !== false;\n const screenshot = await browserSession.screenshot({ fullPage });\n return { success: true, screenshot_length: screenshot.length, screenshot };\n }\n\n if (functionName === 'execute_python_code') {\n const code = String(arguments_.code ?? '');\n const result = await instavm.execute(code, { language: 'python' });\n return { success: true, output: serializeExecution(result) };\n }\n\n if (functionName === 'scroll_page') {\n if (!browserSession) {\n return { success: false, error: 'No browser session active' };\n }\n const x = Number(arguments_.x ?? 0);\n const y = Number(arguments_.y ?? 500);\n await browserSession.scroll({ x, y });\n return { success: true, message: `Scrolled to (${x}, ${y})` };\n }\n\n if (functionName === 'wait_for_element') {\n if (!browserSession) {\n return { success: false, error: 'No browser session active' };\n }\n const selector = String(arguments_.selector ?? '');\n const timeout = Number(arguments_.timeout ?? 10000);\n const result = await browserSession.waitFor('visible', selector, timeout);\n return { success: true, message: `Element ${selector} visible`, result };\n }\n\n return { success: false, error: `Unknown function: ${functionName}` };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n return { success: false, error: `Function ${functionName} failed: ${msg}` };\n }\n}\n\n/** Subset of tools used by Ollama example in Python SDK. */\nexport const INSTAVM_OLLAMA_TOOLS: InstaVMOpenAITool[] = INSTAVM_OPENAI_TOOLS.filter((t) =>\n ['create_browser_session', 'navigate_to_url', 'extract_page_content', 'extract_elements', 'execute_python_code', 'take_screenshot'].includes(\n t.function.name,\n ),\n);\n\nexport async function executeOllamaStyleTool(\n instavm: InstaVM,\n functionName: string,\n arguments_: Record<string, unknown>,\n browserSession?: BrowserSession | null,\n): Promise<Record<string, unknown> & { session?: BrowserSession }> {\n return executeInstavmToolCall(\n instavm,\n { function: { name: functionName, arguments: JSON.stringify(arguments_ || {}) } },\n browserSession,\n );\n}\n","import type { InstaVM } from '../../client/InstaVM';\nimport type { BrowserSession } from '../../client/BrowserSession';\nimport {\n executeInstavmToolCall,\n getInstavmOpenAITools,\n type InstaVMOpenAITool,\n type ToolCallLike,\n} from '../_instavmToolsCore';\n\nexport type { InstaVMOpenAITool };\n\n/** Same schema as OpenAI tools (Azure uses the same JSON). */\nexport function getAzureTools(): InstaVMOpenAITool[] {\n return getInstavmOpenAITools();\n}\n\nexport const getOpenAITools = getAzureTools;\n\nexport async function executeAzureTool(\n instavm: InstaVM,\n toolCall: ToolCallLike,\n browserSession?: BrowserSession | null,\n) {\n return executeInstavmToolCall(instavm, toolCall, browserSession);\n}\n\nexport const executeTool = executeAzureTool;\nexport const executeToolCall = executeAzureTool;\n\n/** Optimized system prompt (parity with Python `get_system_prompt`). */\nexport function getSystemPrompt(): string {\n return `\nYou are a web automation assistant with access to browser and code execution tools.\n\nAvailable capabilities:\n- create_browser_session: Start browser automation\n- navigate_to_url: Go to any website\n- extract_page_content: Get page text content\n- extract_elements: Get specific elements by CSS selector\n- click_element: Click page elements\n- take_screenshot: Capture page images\n- execute_python_code: Run Python/bash code (use !pip install for packages)\n- scroll_page: Scroll to coordinates\n- wait_for_element: Wait for elements to load\n\nTips:\n- Always create browser session before navigation\n- Install packages with !pip install before importing\n- Use screenshots when text extraction isn't enough\n- Be systematic and handle errors gracefully\n`.trim();\n}\n\nexport const getAzureSystemPrompt = getSystemPrompt;\n"],"mappings":";AAcO,SAAS,wBAA6C;AAC3D,SAAO;AACT;AAEA,IAAM,uBAA4C;AAAA,EAChD;AAAA,IACE,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,QACV,MAAM;AAAA,QACN,YAAY;AAAA,UACV,OAAO,EAAE,MAAM,WAAW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