@morphllm/morphsdk 0.2.93 → 0.2.95
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/chunk-2AMEQAO2.js +46 -0
- package/dist/chunk-2AMEQAO2.js.map +1 -0
- package/dist/{chunk-EI4UKP24.js → chunk-2HMEZZKK.js} +2 -2
- package/dist/{chunk-EI4UKP24.js.map → chunk-2HMEZZKK.js.map} +1 -1
- package/dist/chunk-2VERUKO2.js +177 -0
- package/dist/chunk-2VERUKO2.js.map +1 -0
- package/dist/{chunk-VHOWYK66.js → chunk-43LQLGP6.js} +23 -33
- package/dist/chunk-43LQLGP6.js.map +1 -0
- package/dist/{chunk-LMUZ3NGC.js → chunk-73RV6EXR.js} +2 -2
- package/dist/{chunk-PBLPZ6AU.js → chunk-7D6TXC7X.js} +2 -2
- package/dist/{chunk-GU6DACME.js → chunk-O7LDZA52.js} +2 -2
- package/dist/{chunk-5QIWYEHJ.js → chunk-PE4KGDA6.js} +1 -8
- package/dist/chunk-PE4KGDA6.js.map +1 -0
- package/dist/{chunk-SQN4DUQS.js → chunk-Q6Y4R236.js} +26 -2
- package/dist/chunk-Q6Y4R236.js.map +1 -0
- package/dist/{chunk-PUGIOVSP.js → chunk-QAT5UVPX.js} +2 -2
- package/dist/{chunk-MIIJWDOQ.js → chunk-QJP62BXH.js} +166 -71
- package/dist/chunk-QJP62BXH.js.map +1 -0
- package/dist/{chunk-EYGBUH2R.js → chunk-R7IQWNSA.js} +8 -8
- package/dist/chunk-R7IQWNSA.js.map +1 -0
- package/dist/chunk-SI2CKRKJ.js +389 -0
- package/dist/chunk-SI2CKRKJ.js.map +1 -0
- package/dist/{chunk-4WLGDYWQ.js → chunk-TSENDJQI.js} +6 -6
- package/dist/chunk-TSENDJQI.js.map +1 -0
- package/dist/{chunk-IUG2FHNN.js → chunk-XH7P7HVT.js} +1 -8
- package/dist/chunk-XH7P7HVT.js.map +1 -0
- package/dist/{chunk-FNLNDMIX.js → chunk-YZ5NCWO2.js} +6 -6
- package/dist/chunk-YZ5NCWO2.js.map +1 -0
- package/dist/{chunk-IJ54DTJ3.js → chunk-ZYTAKEBW.js} +13 -13
- package/dist/client.cjs +770 -110
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +16 -13
- package/dist/index.cjs +770 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -13
- package/dist/tools/browser/anthropic.cjs +58 -23
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +7 -4
- package/dist/tools/browser/core.cjs +750 -70
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.d.ts +30 -24
- package/dist/tools/browser/core.js +5 -2
- package/dist/tools/browser/errors.cjs +208 -0
- package/dist/tools/browser/errors.cjs.map +1 -0
- package/dist/tools/browser/errors.d.ts +158 -0
- package/dist/tools/browser/errors.js +22 -0
- package/dist/tools/browser/errors.js.map +1 -0
- package/dist/tools/browser/index.cjs +783 -85
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.d.ts +5 -2
- package/dist/tools/browser/index.js +32 -9
- package/dist/tools/browser/index.js.map +1 -1
- package/dist/tools/browser/live.cjs +25 -1
- package/dist/tools/browser/live.cjs.map +1 -1
- package/dist/tools/browser/live.js +1 -1
- package/dist/tools/browser/openai.cjs +58 -23
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +7 -4
- package/dist/tools/browser/profiles/core.cjs +670 -0
- package/dist/tools/browser/profiles/core.cjs.map +1 -0
- package/dist/tools/browser/profiles/core.d.ts +187 -0
- package/dist/tools/browser/profiles/core.js +29 -0
- package/dist/tools/browser/profiles/core.js.map +1 -0
- package/dist/tools/browser/profiles/index.cjs +670 -0
- package/dist/tools/browser/profiles/index.cjs.map +1 -0
- package/dist/tools/browser/profiles/index.d.ts +4 -0
- package/dist/tools/browser/profiles/index.js +29 -0
- package/dist/tools/browser/profiles/index.js.map +1 -0
- package/dist/tools/browser/profiles/types.cjs +74 -0
- package/dist/tools/browser/profiles/types.cjs.map +1 -0
- package/dist/tools/browser/profiles/types.d.ts +195 -0
- package/dist/tools/browser/profiles/types.js +16 -0
- package/dist/tools/browser/profiles/types.js.map +1 -0
- package/dist/tools/browser/prompts.cjs +1 -1
- package/dist/tools/browser/prompts.cjs.map +1 -1
- package/dist/tools/browser/prompts.d.ts +1 -1
- package/dist/tools/browser/prompts.js +1 -1
- package/dist/tools/browser/types.cjs.map +1 -1
- package/dist/tools/browser/types.d.ts +55 -51
- package/dist/tools/browser/vercel.cjs +60 -25
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.d.ts +1 -1
- package/dist/tools/browser/vercel.js +7 -4
- package/dist/tools/fastapply/anthropic.cjs +0 -7
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +1 -1
- package/dist/tools/fastapply/index.cjs +0 -14
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +5 -5
- package/dist/tools/fastapply/openai.cjs +0 -7
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +1 -1
- package/dist/tools/index.cjs +0 -14
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +5 -5
- package/dist/tools/warp_grep/agent/runner.cjs +18 -98
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -3
- package/dist/tools/warp_grep/anthropic.cjs +18 -98
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +8 -9
- package/dist/tools/warp_grep/client.cjs +18 -98
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +5 -6
- package/dist/tools/warp_grep/gemini.cjs +18 -98
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +7 -8
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/harness.js +10 -10
- package/dist/tools/warp_grep/index.cjs +18 -98
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +8 -9
- package/dist/tools/warp_grep/openai.cjs +18 -98
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +8 -9
- package/dist/tools/warp_grep/vercel.cjs +18 -98
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +8 -9
- package/dist/{vercel-CsnNSdze.d.ts → vercel-CVF27qFK.d.ts} +10 -10
- package/package.json +7 -2
- package/dist/chunk-4WLGDYWQ.js.map +0 -1
- package/dist/chunk-5QIWYEHJ.js.map +0 -1
- package/dist/chunk-EYGBUH2R.js.map +0 -1
- package/dist/chunk-FNLNDMIX.js.map +0 -1
- package/dist/chunk-IUG2FHNN.js.map +0 -1
- package/dist/chunk-MIIJWDOQ.js.map +0 -1
- package/dist/chunk-SQN4DUQS.js.map +0 -1
- package/dist/chunk-VHOWYK66.js.map +0 -1
- /package/dist/{chunk-LMUZ3NGC.js.map → chunk-73RV6EXR.js.map} +0 -0
- /package/dist/{chunk-PBLPZ6AU.js.map → chunk-7D6TXC7X.js.map} +0 -0
- /package/dist/{chunk-GU6DACME.js.map → chunk-O7LDZA52.js.map} +0 -0
- /package/dist/{chunk-PUGIOVSP.js.map → chunk-QAT5UVPX.js.map} +0 -0
- /package/dist/{chunk-IJ54DTJ3.js.map → chunk-ZYTAKEBW.js.map} +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProfilesClient
|
|
3
|
+
} from "./chunk-SI2CKRKJ.js";
|
|
1
4
|
import {
|
|
2
5
|
buildEmbedCode,
|
|
3
6
|
buildLiveIframe,
|
|
4
7
|
buildLiveUrl,
|
|
5
8
|
resolvePreset
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-Q6Y4R236.js";
|
|
7
10
|
import {
|
|
8
11
|
fetchWithRetry,
|
|
9
12
|
withTimeout
|
|
@@ -18,11 +21,16 @@ var DEFAULT_CONFIG = {
|
|
|
18
21
|
};
|
|
19
22
|
var BrowserClient = class {
|
|
20
23
|
config;
|
|
24
|
+
/**
|
|
25
|
+
* Profile management - create and manage browser profiles for storing login state.
|
|
26
|
+
*/
|
|
27
|
+
profiles;
|
|
21
28
|
constructor(config = {}) {
|
|
22
29
|
this.config = {
|
|
23
30
|
...DEFAULT_CONFIG,
|
|
24
31
|
...config
|
|
25
32
|
};
|
|
33
|
+
this.profiles = new ProfilesClient(this.config);
|
|
26
34
|
}
|
|
27
35
|
/**
|
|
28
36
|
* Execute a browser automation task
|
|
@@ -45,19 +53,21 @@ var BrowserClient = class {
|
|
|
45
53
|
body: JSON.stringify({
|
|
46
54
|
task: input.task,
|
|
47
55
|
url: input.url,
|
|
48
|
-
max_steps: input.
|
|
56
|
+
max_steps: input.maxSteps ?? 10,
|
|
49
57
|
model: input.model ?? "morph-computer-use-v0",
|
|
50
|
-
viewport_width: input.
|
|
51
|
-
viewport_height: input.
|
|
52
|
-
external_id: input.
|
|
53
|
-
repo_id: input.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
viewport_width: input.viewportWidth ?? 1280,
|
|
59
|
+
viewport_height: input.viewportHeight ?? 720,
|
|
60
|
+
external_id: input.externalId,
|
|
61
|
+
repo_id: input.repoId,
|
|
62
|
+
repo_full_name: input.repoFullName,
|
|
63
|
+
commit_id: input.commitId,
|
|
64
|
+
record_video: input.recordVideo ?? false,
|
|
65
|
+
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
66
|
+
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
67
|
+
allow_resizing: input.allowResizing ?? false,
|
|
59
68
|
structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0,
|
|
60
|
-
auth: input.auth
|
|
69
|
+
auth: input.auth,
|
|
70
|
+
profile_id: input.profileId
|
|
61
71
|
})
|
|
62
72
|
});
|
|
63
73
|
if (!response.ok) {
|
|
@@ -65,9 +75,10 @@ var BrowserClient = class {
|
|
|
65
75
|
if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);
|
|
66
76
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
67
77
|
}
|
|
68
|
-
const result = await response.json();
|
|
78
|
+
const result = mapTaskResult(await response.json());
|
|
69
79
|
if (debug) {
|
|
70
|
-
|
|
80
|
+
const debugUrl = result.debugUrl;
|
|
81
|
+
console.log(`[Browser] \u2705 Task created: recordingId=${result.recordingId ?? "none"} debugUrl=${debugUrl ? "available" : "none"}`);
|
|
71
82
|
}
|
|
72
83
|
if ("schema" in input) {
|
|
73
84
|
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
@@ -122,15 +133,15 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
122
133
|
error: 'Task description is required. Example: "Go to example.com and click the login button"'
|
|
123
134
|
};
|
|
124
135
|
}
|
|
125
|
-
if (input.
|
|
136
|
+
if (input.maxSteps !== void 0 && (input.maxSteps < 1 || input.maxSteps > 50)) {
|
|
126
137
|
return {
|
|
127
138
|
success: false,
|
|
128
|
-
error: "
|
|
139
|
+
error: "maxSteps must be between 1 and 50. Use more steps for complex multi-page flows."
|
|
129
140
|
};
|
|
130
141
|
}
|
|
131
142
|
if (debug) {
|
|
132
|
-
console.log(`[Browser] Task: "${input.task.slice(0, 60)}..." url=${input.url || "none"} maxSteps=${input.
|
|
133
|
-
console.log(`[Browser] Recording: ${input.
|
|
143
|
+
console.log(`[Browser] Task: "${input.task.slice(0, 60)}..." url=${input.url || "none"} maxSteps=${input.maxSteps ?? 10}`);
|
|
144
|
+
console.log(`[Browser] Recording: ${input.recordVideo ? "yes" : "no"} | Calling ${apiUrl}/browser-task`);
|
|
134
145
|
}
|
|
135
146
|
const startTime = Date.now();
|
|
136
147
|
try {
|
|
@@ -144,19 +155,20 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
144
155
|
body: JSON.stringify({
|
|
145
156
|
task: input.task,
|
|
146
157
|
url: input.url,
|
|
147
|
-
max_steps: input.
|
|
158
|
+
max_steps: input.maxSteps ?? 10,
|
|
148
159
|
model: input.model ?? "morph-computer-use-v0",
|
|
149
|
-
viewport_width: input.
|
|
150
|
-
viewport_height: input.
|
|
151
|
-
external_id: input.
|
|
152
|
-
repo_id: input.
|
|
153
|
-
commit_id: input.
|
|
154
|
-
record_video: input.
|
|
155
|
-
video_width: input.
|
|
156
|
-
video_height: input.
|
|
157
|
-
allow_resizing: input.
|
|
158
|
-
structured_output: input.
|
|
159
|
-
auth: input.auth
|
|
160
|
+
viewport_width: input.viewportWidth ?? 1280,
|
|
161
|
+
viewport_height: input.viewportHeight ?? 720,
|
|
162
|
+
external_id: input.externalId,
|
|
163
|
+
repo_id: input.repoId,
|
|
164
|
+
commit_id: input.commitId,
|
|
165
|
+
record_video: input.recordVideo ?? false,
|
|
166
|
+
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
167
|
+
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
168
|
+
allow_resizing: input.allowResizing ?? false,
|
|
169
|
+
structured_output: input.structuredOutput,
|
|
170
|
+
auth: input.auth,
|
|
171
|
+
profile_id: input.profileId
|
|
160
172
|
})
|
|
161
173
|
},
|
|
162
174
|
config.retryConfig
|
|
@@ -164,17 +176,17 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
164
176
|
const response = await withTimeout(
|
|
165
177
|
fetchPromise,
|
|
166
178
|
timeout,
|
|
167
|
-
`Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing
|
|
179
|
+
`Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing maxSteps.`
|
|
168
180
|
);
|
|
169
181
|
if (!response.ok) {
|
|
170
182
|
const errorText = await response.text().catch(() => response.statusText);
|
|
171
183
|
if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);
|
|
172
184
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
173
185
|
}
|
|
174
|
-
const result = await response.json();
|
|
186
|
+
const result = mapTaskResult(await response.json());
|
|
175
187
|
const elapsed = Date.now() - startTime;
|
|
176
188
|
if (debug) {
|
|
177
|
-
console.log(`[Browser] \u2705 ${result.success ? "Success" : "Failed"} in ${elapsed}ms | steps=${result.
|
|
189
|
+
console.log(`[Browser] \u2705 ${result.success ? "Success" : "Failed"} in ${elapsed}ms | steps=${result.stepsTaken ?? 0} recordingId=${result.recordingId ?? "none"}`);
|
|
178
190
|
}
|
|
179
191
|
return result;
|
|
180
192
|
} catch (error) {
|
|
@@ -212,7 +224,7 @@ async function getRecording(recordingId, config = {}) {
|
|
|
212
224
|
if (debug) console.error(`[Browser] getRecording error: ${response.status} - ${errorText}`);
|
|
213
225
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
214
226
|
}
|
|
215
|
-
const data = await response.json();
|
|
227
|
+
const data = mapRecordingStatus(await response.json());
|
|
216
228
|
if (debug) console.log(`[Browser] Recording status: ${data.status}`);
|
|
217
229
|
return {
|
|
218
230
|
...data,
|
|
@@ -235,10 +247,10 @@ async function waitForRecording(recordingId, config = {}, options = {}) {
|
|
|
235
247
|
}
|
|
236
248
|
async function executeWithRecording(input, config = {}) {
|
|
237
249
|
const taskResult = await executeBrowserTask(input, config);
|
|
238
|
-
if (taskResult.
|
|
250
|
+
if (taskResult.recordingId) {
|
|
239
251
|
try {
|
|
240
252
|
const recording = await waitForRecording(
|
|
241
|
-
taskResult.
|
|
253
|
+
taskResult.recordingId,
|
|
242
254
|
config,
|
|
243
255
|
{ timeout: 6e4, pollInterval: 2e3 }
|
|
244
256
|
);
|
|
@@ -248,12 +260,12 @@ async function executeWithRecording(input, config = {}) {
|
|
|
248
260
|
};
|
|
249
261
|
} catch (error) {
|
|
250
262
|
const errorRecording = {
|
|
251
|
-
id: taskResult.
|
|
263
|
+
id: taskResult.recordingId,
|
|
252
264
|
status: "ERROR",
|
|
253
265
|
error: error instanceof Error ? error.message : String(error),
|
|
254
|
-
|
|
255
|
-
getWebp: (options) => getWebp(taskResult.
|
|
256
|
-
getErrors: () => getErrors(taskResult.
|
|
266
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
267
|
+
getWebp: (options) => getWebp(taskResult.recordingId, config, options),
|
|
268
|
+
getErrors: () => getErrors(taskResult.recordingId, config)
|
|
257
269
|
};
|
|
258
270
|
return {
|
|
259
271
|
...taskResult,
|
|
@@ -279,8 +291,8 @@ async function getErrors(recordingId, config = {}) {
|
|
|
279
291
|
if (debug) console.error(`[Browser] getErrors error: ${response.status} - ${errorText}`);
|
|
280
292
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
281
293
|
}
|
|
282
|
-
const errors = await response.json();
|
|
283
|
-
if (debug) console.log(`[Browser] Found ${errors.
|
|
294
|
+
const errors = mapErrorsResponse(await response.json());
|
|
295
|
+
if (debug) console.log(`[Browser] Found ${errors.totalErrors} errors`);
|
|
284
296
|
return errors;
|
|
285
297
|
}
|
|
286
298
|
function stringifyStructuredOutput(schema) {
|
|
@@ -313,6 +325,84 @@ function parseStructuredTaskOutput(result, schema) {
|
|
|
313
325
|
throw error;
|
|
314
326
|
}
|
|
315
327
|
}
|
|
328
|
+
function mapTaskResult(api) {
|
|
329
|
+
if (!api || typeof api !== "object") {
|
|
330
|
+
return api;
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
success: api.success,
|
|
334
|
+
result: api.result,
|
|
335
|
+
error: api.error,
|
|
336
|
+
stepsTaken: api.steps_taken,
|
|
337
|
+
executionTimeMs: api.execution_time_ms,
|
|
338
|
+
urls: api.urls,
|
|
339
|
+
actionNames: api.action_names,
|
|
340
|
+
errors: api.errors,
|
|
341
|
+
modelActions: api.model_actions,
|
|
342
|
+
isDone: api.is_done,
|
|
343
|
+
actionHistory: api.action_history,
|
|
344
|
+
actionResults: api.action_results,
|
|
345
|
+
hasErrors: api.has_errors,
|
|
346
|
+
numberOfSteps: api.number_of_steps,
|
|
347
|
+
judgement: api.judgement,
|
|
348
|
+
isValidated: api.is_validated,
|
|
349
|
+
replayId: api.replay_id,
|
|
350
|
+
replayUrl: api.replay_url,
|
|
351
|
+
recordingId: api.recording_id,
|
|
352
|
+
recordingStatus: api.recording_status,
|
|
353
|
+
taskId: api.task_id,
|
|
354
|
+
status: api.status,
|
|
355
|
+
output: api.output,
|
|
356
|
+
debugUrl: api.debug_url
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function mapRecordingStatus(api) {
|
|
360
|
+
return {
|
|
361
|
+
id: api.id,
|
|
362
|
+
status: api.status,
|
|
363
|
+
replayUrl: api.replay_url,
|
|
364
|
+
networkUrl: api.network_url,
|
|
365
|
+
consoleUrl: api.console_url,
|
|
366
|
+
videoUrl: api.video_url,
|
|
367
|
+
totalEvents: api.total_events,
|
|
368
|
+
fileSize: api.file_size,
|
|
369
|
+
duration: api.duration,
|
|
370
|
+
error: api.error,
|
|
371
|
+
createdAt: api.created_at
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function mapBrowserError(api) {
|
|
375
|
+
return {
|
|
376
|
+
type: api.type,
|
|
377
|
+
message: api.message,
|
|
378
|
+
url: api.url,
|
|
379
|
+
timestamp: api.timestamp,
|
|
380
|
+
screenshotUrl: api.screenshot_url,
|
|
381
|
+
capturedAt: api.captured_at,
|
|
382
|
+
status: api.status
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function mapErrorsResponse(api) {
|
|
386
|
+
return {
|
|
387
|
+
recordingId: api.recording_id,
|
|
388
|
+
totalErrors: api.total_errors,
|
|
389
|
+
errors: Array.isArray(api.errors) ? api.errors.map(mapBrowserError) : []
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function mapWebpResponse(api) {
|
|
393
|
+
return {
|
|
394
|
+
webpUrl: api.webp_url,
|
|
395
|
+
cached: api.cached,
|
|
396
|
+
width: api.width,
|
|
397
|
+
fps: api.fps,
|
|
398
|
+
maxDuration: api.max_duration,
|
|
399
|
+
fileSize: api.file_size,
|
|
400
|
+
maxSizeMb: api.max_size_mb,
|
|
401
|
+
budgetMet: api.budget_met,
|
|
402
|
+
qualityUsed: api.quality_used,
|
|
403
|
+
attempts: api.attempts
|
|
404
|
+
};
|
|
405
|
+
}
|
|
316
406
|
async function getTaskStatus(taskId, config) {
|
|
317
407
|
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
318
408
|
const debug = config.debug || false;
|
|
@@ -328,7 +418,7 @@ async function getTaskStatus(taskId, config) {
|
|
|
328
418
|
if (debug) console.error(`[Browser] getTaskStatus error: ${response.status} - ${errorText}`);
|
|
329
419
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
330
420
|
}
|
|
331
|
-
const result = await response.json();
|
|
421
|
+
const result = mapTaskResult(await response.json());
|
|
332
422
|
if (debug) console.log(`[Browser] Task status: ${result.status}`);
|
|
333
423
|
return result;
|
|
334
424
|
}
|
|
@@ -351,42 +441,44 @@ async function pollTaskUntilComplete(taskId, config, pollConfig = {}) {
|
|
|
351
441
|
throw new Error(`Task polling timeout after ${timeout}ms`);
|
|
352
442
|
}
|
|
353
443
|
function wrapTaskResponse(result, config) {
|
|
444
|
+
const debugUrl = result.debugUrl ?? "";
|
|
354
445
|
const wrapped = {
|
|
355
446
|
...result,
|
|
356
|
-
|
|
357
|
-
|
|
447
|
+
debugUrl,
|
|
448
|
+
taskId: result.taskId || "",
|
|
449
|
+
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
358
450
|
complete: async (pollConfig) => {
|
|
359
|
-
if (result.
|
|
360
|
-
return pollTaskUntilComplete(result.
|
|
451
|
+
if (result.taskId) {
|
|
452
|
+
return pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
361
453
|
}
|
|
362
|
-
if (result.
|
|
454
|
+
if (result.recordingId) {
|
|
363
455
|
const recording = await waitForRecording(
|
|
364
|
-
result.
|
|
456
|
+
result.recordingId,
|
|
365
457
|
config,
|
|
366
458
|
pollConfig
|
|
367
459
|
);
|
|
368
460
|
return {
|
|
369
461
|
...result,
|
|
370
|
-
|
|
462
|
+
recordingStatus: recording.status
|
|
371
463
|
};
|
|
372
464
|
}
|
|
373
|
-
throw new Error("Cannot poll completion: no
|
|
465
|
+
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
374
466
|
},
|
|
375
467
|
// Add Steel live session helpers - either functional or error-throwing
|
|
376
|
-
getLiveUrl:
|
|
468
|
+
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
377
469
|
throw new Error(
|
|
378
470
|
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
379
471
|
);
|
|
380
472
|
},
|
|
381
|
-
getLiveIframe:
|
|
473
|
+
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
382
474
|
const options = resolvePreset(optionsOrPreset);
|
|
383
|
-
return buildLiveIframe(
|
|
475
|
+
return buildLiveIframe(debugUrl, options);
|
|
384
476
|
} : () => {
|
|
385
477
|
throw new Error(
|
|
386
478
|
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
387
479
|
);
|
|
388
480
|
},
|
|
389
|
-
getEmbedCode:
|
|
481
|
+
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
390
482
|
throw new Error(
|
|
391
483
|
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
392
484
|
);
|
|
@@ -395,44 +487,46 @@ function wrapTaskResponse(result, config) {
|
|
|
395
487
|
return wrapped;
|
|
396
488
|
}
|
|
397
489
|
function wrapTaskResponseWithSchema(result, config, schema) {
|
|
490
|
+
const debugUrl = result.debugUrl ?? "";
|
|
398
491
|
const parsed = result.output ? parseStructuredTaskOutput(result, schema) : { ...result, parsed: null };
|
|
399
492
|
const wrapped = {
|
|
400
493
|
...parsed,
|
|
401
|
-
|
|
402
|
-
|
|
494
|
+
debugUrl,
|
|
495
|
+
taskId: result.taskId || "",
|
|
496
|
+
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
403
497
|
complete: async (pollConfig) => {
|
|
404
|
-
if (result.
|
|
405
|
-
const finalResult = await pollTaskUntilComplete(result.
|
|
498
|
+
if (result.taskId) {
|
|
499
|
+
const finalResult = await pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
406
500
|
return parseStructuredTaskOutput(finalResult, schema);
|
|
407
501
|
}
|
|
408
|
-
if (result.
|
|
502
|
+
if (result.recordingId) {
|
|
409
503
|
const recording = await waitForRecording(
|
|
410
|
-
result.
|
|
504
|
+
result.recordingId,
|
|
411
505
|
config,
|
|
412
506
|
pollConfig
|
|
413
507
|
);
|
|
414
508
|
return {
|
|
415
509
|
...parsed,
|
|
416
|
-
|
|
510
|
+
recordingStatus: recording.status
|
|
417
511
|
};
|
|
418
512
|
}
|
|
419
|
-
throw new Error("Cannot poll completion: no
|
|
513
|
+
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
420
514
|
},
|
|
421
515
|
// Add Steel live session helpers - either functional or error-throwing
|
|
422
|
-
getLiveUrl:
|
|
516
|
+
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
423
517
|
throw new Error(
|
|
424
518
|
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions. "
|
|
425
519
|
);
|
|
426
520
|
},
|
|
427
|
-
getLiveIframe:
|
|
521
|
+
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
428
522
|
const options = resolvePreset(optionsOrPreset);
|
|
429
|
-
return buildLiveIframe(
|
|
523
|
+
return buildLiveIframe(debugUrl, options);
|
|
430
524
|
} : () => {
|
|
431
525
|
throw new Error(
|
|
432
526
|
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
433
527
|
);
|
|
434
528
|
},
|
|
435
|
-
getEmbedCode:
|
|
529
|
+
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
436
530
|
throw new Error(
|
|
437
531
|
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
438
532
|
);
|
|
@@ -447,10 +541,11 @@ async function getWebp(recordingId, config = {}, options = {}) {
|
|
|
447
541
|
throw new Error("API key required for getWebp");
|
|
448
542
|
}
|
|
449
543
|
const params = new URLSearchParams();
|
|
450
|
-
if (options.
|
|
544
|
+
if (options.maxDuration !== void 0) params.set("max_duration", String(options.maxDuration));
|
|
451
545
|
if (options.fps !== void 0) params.set("fps", String(options.fps));
|
|
452
546
|
if (options.width !== void 0) params.set("width", String(options.width));
|
|
453
547
|
if (options.quality !== void 0) params.set("quality", String(options.quality));
|
|
548
|
+
if (options.maxSizeMb !== void 0) params.set("max_size_mb", String(options.maxSizeMb));
|
|
454
549
|
const url = `${apiUrl}/recordings/${recordingId}/webp${params.toString() ? "?" + params.toString() : ""}`;
|
|
455
550
|
if (debug) console.log(`[Browser] getWebp: ${url}`);
|
|
456
551
|
const response = await fetch(url, {
|
|
@@ -462,8 +557,8 @@ async function getWebp(recordingId, config = {}, options = {}) {
|
|
|
462
557
|
if (debug) console.error(`[Browser] getWebp error: ${response.status} - ${errorText}`);
|
|
463
558
|
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
464
559
|
}
|
|
465
|
-
const result = await response.json();
|
|
466
|
-
if (debug) console.log(`[Browser] WebP ready: ${result.
|
|
560
|
+
const result = mapWebpResponse(await response.json());
|
|
561
|
+
if (debug) console.log(`[Browser] WebP ready: ${result.webpUrl} (cached: ${result.cached})`);
|
|
467
562
|
return result;
|
|
468
563
|
}
|
|
469
564
|
async function checkHealth(config = {}) {
|
|
@@ -504,4 +599,4 @@ export {
|
|
|
504
599
|
getWebp,
|
|
505
600
|
checkHealth
|
|
506
601
|
};
|
|
507
|
-
//# sourceMappingURL=chunk-
|
|
602
|
+
//# sourceMappingURL=chunk-QJP62BXH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/browser/core.ts"],"sourcesContent":["/**\n * Core implementation for browser automation tasks\n */\n\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type {\n BrowserConfig,\n BrowserTaskInput,\n BrowserTaskInputWithSchema,\n BrowserTaskResult,\n BrowserTaskWithPromise,\n BrowserTaskWithPromiseAndSchema,\n RecordingStatus,\n RecordingWithMethods,\n ErrorsResponse,\n LiveSessionOptions,\n IframeOptions,\n WebpOptions,\n WebpResponse,\n} from './types.js';\nimport { buildLiveUrl, buildLiveIframe, buildEmbedCode, resolvePreset } from './live.js';\nimport { ProfilesClient } from './profiles/core.js';\n\nconst DEFAULT_CONFIG = {\n apiUrl: process.env.MORPH_ENVIRONMENT === 'DEV' \n ? 'http://localhost:8000'\n : 'https://browser.morphllm.com',\n timeout: 1000000, // 10 minutes for complex tasks\n debug: false,\n};\n\n/**\n * BrowserClient class for easier usage with instance configuration\n */\nexport class BrowserClient {\n private config: BrowserConfig;\n\n /**\n * Profile management - create and manage browser profiles for storing login state.\n */\n public profiles: ProfilesClient;\n\n constructor(config: BrowserConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...config,\n };\n this.profiles = new ProfilesClient(this.config);\n }\n\n /**\n * Execute a browser automation task\n */\n async execute(input: BrowserTaskInput): Promise<BrowserTaskResult> {\n return executeBrowserTask(input, this.config);\n }\n\n async createTask(input: BrowserTaskInput): Promise<BrowserTaskWithPromise>;\n async createTask<T>(input: BrowserTaskInputWithSchema<T>): Promise<BrowserTaskWithPromiseAndSchema<T>>;\n async createTask<T>(\n input: BrowserTaskInput | BrowserTaskInputWithSchema<T>\n ): Promise<BrowserTaskWithPromise | BrowserTaskWithPromiseAndSchema<T>> {\n const apiUrl = this.config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = this.config.debug || false;\n \n if (debug) {\n console.log(`[Browser] createTask: \"${input.task.slice(0, 60)}...\" url=${input.url || 'none'}`);\n console.log(`[Browser] Calling async endpoint: ${apiUrl}/browser-task/async`);\n }\n \n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (this.config.apiKey) headers['Authorization'] = `Bearer ${this.config.apiKey}`;\n \n // Call ASYNC endpoint for immediate return with live URL\n const response = await fetch(`${apiUrl}/browser-task/async`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n task: input.task,\n url: input.url,\n max_steps: input.maxSteps ?? 10,\n model: input.model ?? 'morph-computer-use-v0',\n viewport_width: input.viewportWidth ?? 1280,\n viewport_height: input.viewportHeight ?? 720,\n external_id: input.externalId,\n repo_id: input.repoId,\n repo_full_name: input.repoFullName,\n commit_id: input.commitId,\n record_video: input.recordVideo ?? false,\n video_width: input.videoWidth ?? input.viewportWidth ?? 1280,\n video_height: input.videoHeight ?? input.viewportHeight ?? 720,\n allow_resizing: input.allowResizing ?? false,\n structured_output: 'schema' in input ? stringifyStructuredOutput(input.schema) : undefined,\n auth: input.auth,\n profile_id: input.profileId,\n }),\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n \n const result = mapTaskResult(await response.json());\n \n if (debug) {\n const debugUrl = result.debugUrl;\n console.log(`[Browser] ✅ Task created: recordingId=${result.recordingId ?? 'none'} debugUrl=${debugUrl ? 'available' : 'none'}`);\n }\n \n if ('schema' in input) {\n return wrapTaskResponseWithSchema(result, this.config, input.schema);\n } else {\n return wrapTaskResponse(result, this.config);\n }\n }\n\n /**\n * Execute task with recording and wait for video to be ready\n */\n async executeWithRecording(\n input: BrowserTaskInput & { recordVideo: true }\n ): Promise<BrowserTaskResult & { recording?: RecordingWithMethods }> {\n return executeWithRecording(input, this.config);\n }\n\n /**\n * Get recording status and URLs\n */\n async getRecording(recordingId: string): Promise<RecordingWithMethods> {\n return getRecording(recordingId, this.config);\n }\n\n /**\n * Wait for recording to complete with automatic polling\n */\n async waitForRecording(\n recordingId: string,\n options?: { timeout?: number; pollInterval?: number }\n ): Promise<RecordingWithMethods> {\n return waitForRecording(recordingId, this.config, options);\n }\n\n /**\n * Get errors from recording with screenshots\n */\n async getErrors(recordingId: string): Promise<ErrorsResponse> {\n return getErrors(recordingId, this.config);\n }\n\n /**\n * Get animated WebP preview of recording\n */\n async getWebp(\n recordingId: string,\n options?: WebpOptions\n ): Promise<WebpResponse> {\n return getWebp(recordingId, this.config, options);\n }\n\n /**\n * Check if browser worker service is healthy\n */\n async checkHealth(): Promise<{\n ok: boolean;\n google_configured: boolean;\n database_configured: boolean;\n s3_configured: boolean;\n error?: string;\n }> {\n return checkHealth(this.config);\n }\n}\n\n/**\n * Execute a natural language browser automation task\n * \n * Returns the full task result including rich agent history data (urls, errors, \n * action_history, judgement, etc.). When using this as an agent tool, use the\n * formatResult() functions from the SDK adapters to return a concise summary.\n * \n * @param input - Task parameters\n * @param config - Optional configuration (apiKey, apiUrl to override default)\n * @returns Task result with success status, findings, and comprehensive execution history\n * \n * @example\n * ```typescript\n * const result = await executeBrowserTask(\n * {\n * task: \"Test checkout flow for buying a pineapple\",\n * url: \"https://3000-abc.e2b.dev\",\n * maxSteps: 20,\n * repoId: \"my-project\",\n * commitId: \"uuid-here\"\n * },\n * {\n * apiKey: process.env.MORPH_API_KEY,\n * // apiUrl: 'http://localhost:8001' // Override for local testing\n * }\n * );\n * \n * if (result.success) {\n * console.log('Task completed:', result.result);\n * console.log('URLs visited:', result.urls);\n * console.log('Actions taken:', result.actionNames);\n * console.log('Has errors:', result.hasErrors);\n * console.log('Replay:', result.replayUrl);\n * }\n * ```\n */\nexport async function executeBrowserTask(\n input: BrowserTaskInput,\n config: BrowserConfig = {}\n): Promise<BrowserTaskResult> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const timeout = config.timeout || DEFAULT_CONFIG.timeout;\n const debug = config.debug || false;\n\n if (!input.task || input.task.trim().length === 0) {\n return { \n success: false, \n error: 'Task description is required. Example: \"Go to example.com and click the login button\"' \n };\n }\n\n if (input.maxSteps !== undefined && (input.maxSteps < 1 || input.maxSteps > 50)) {\n return { \n success: false, \n error: 'maxSteps must be between 1 and 50. Use more steps for complex multi-page flows.'\n };\n }\n\n if (debug) {\n console.log(`[Browser] Task: \"${input.task.slice(0, 60)}...\" url=${input.url || 'none'} maxSteps=${input.maxSteps ?? 10}`);\n console.log(`[Browser] Recording: ${input.recordVideo ? 'yes' : 'no'} | Calling ${apiUrl}/browser-task`);\n }\n\n const startTime = Date.now();\n\n try {\n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (config.apiKey) headers['Authorization'] = `Bearer ${config.apiKey}`;\n\n const fetchPromise = fetchWithRetry(\n `${apiUrl}/browser-task`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify({\n task: input.task,\n url: input.url,\n max_steps: input.maxSteps ?? 10,\n model: input.model ?? 'morph-computer-use-v0',\n viewport_width: input.viewportWidth ?? 1280,\n viewport_height: input.viewportHeight ?? 720,\n external_id: input.externalId,\n repo_id: input.repoId,\n commit_id: input.commitId,\n record_video: input.recordVideo ?? false,\n video_width: input.videoWidth ?? input.viewportWidth ?? 1280,\n video_height: input.videoHeight ?? input.viewportHeight ?? 720,\n allow_resizing: input.allowResizing ?? false,\n structured_output: input.structuredOutput,\n auth: input.auth,\n profile_id: input.profileId,\n }),\n },\n config.retryConfig\n );\n\n const response = await withTimeout(\n fetchPromise,\n timeout,\n `Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing maxSteps.`\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const result: BrowserTaskResult = mapTaskResult(await response.json());\n const elapsed = Date.now() - startTime;\n \n if (debug) {\n console.log(`[Browser] ✅ ${result.success ? 'Success' : 'Failed'} in ${elapsed}ms | steps=${result.stepsTaken ?? 0} recordingId=${result.recordingId ?? 'none'}`);\n }\n\n return result;\n\n } catch (error) {\n if (error instanceof Error) {\n // Handle network errors\n if (error.message.includes('ECONNREFUSED') || error.message.includes('fetch failed')) {\n return {\n success: false,\n error: `Cannot connect to browser worker at ${apiUrl}. Ensure the service is running and accessible. For local dev, set MORPH_ENVIRONMENT=DEV.`,\n };\n }\n\n return {\n success: false,\n error: error.message,\n };\n }\n\n return {\n success: false,\n error: String(error),\n };\n }\n}\n\n/**\n * Get recording status and video URL\n * \n * @param recordingId - Recording UUID from BrowserTaskResult\n * @param config - Configuration with apiKey\n * @returns Recording with convenience methods (.getWebp(), .getErrors())\n * \n * @example\n * ```typescript\n * const recording = await getRecording('uuid-here', { apiKey: 'key' });\n * \n * // Get animated WebP\n * const { webpUrl } = await recording.getWebp({ width: 780 });\n * \n * // Get errors with screenshots\n * const { errors } = await recording.getErrors();\n * ```\n */\nexport async function getRecording(\n recordingId: string,\n config: BrowserConfig = {}\n): Promise<RecordingWithMethods> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (!config.apiKey) {\n throw new Error('API key required for getRecording');\n }\n\n if (debug) console.log(`[Browser] getRecording: ${recordingId}`);\n\n const response = await fetch(`${apiUrl}/recordings/${recordingId}`, {\n method: 'GET',\n headers: { 'Authorization': `Bearer ${config.apiKey}` },\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getRecording error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const data: RecordingStatus = mapRecordingStatus(await response.json());\n if (debug) console.log(`[Browser] Recording status: ${data.status}`);\n\n // Return recording with convenience methods\n return {\n ...data,\n getWebp: (options?: WebpOptions) => getWebp(recordingId, config, options),\n getErrors: () => getErrors(recordingId, config),\n };\n}\n\n/**\n * Wait for recording to complete with automatic polling\n * \n * @param recordingId - Recording UUID\n * @param config - Configuration with apiKey\n * @param options - Polling options\n * @returns Recording status when completed or errored\n * \n * @example\n * ```typescript\n * const result = await executeBrowserTask({ task: '...', recordVideo: true }, config);\n * if (result.recordingId) {\n * const recording = await waitForRecording(result.recordingId, config, {\n * timeout: 60000, // 1 minute\n * pollInterval: 2000 // Check every 2 seconds\n * });\n * console.log('Video URL:', recording.videoUrl);\n * }\n * ```\n */\nexport async function waitForRecording(\n recordingId: string,\n config: BrowserConfig = {},\n options: { timeout?: number; pollInterval?: number } = {}\n): Promise<RecordingWithMethods> {\n const timeout = options.timeout ?? 60000; // Default 1 minute\n const pollInterval = options.pollInterval ?? 2000; // Default 2 seconds\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n const status = await getRecording(recordingId, config);\n \n if (status.status === 'COMPLETED' || status.status === 'ERROR') {\n return status;\n }\n\n // Wait before next poll\n await new Promise(resolve => setTimeout(resolve, pollInterval));\n }\n\n throw new Error(`Recording timeout after ${timeout}ms - status still pending`);\n}\n\n/**\n * Execute task with recording and wait for video to be ready\n * \n * @param input - Task parameters with recordVideo=true\n * @param config - Configuration with apiKey\n * @returns Task result with ready video URL\n * \n * @example\n * ```typescript\n * const result = await executeWithRecording(\n * {\n * task: \"Test checkout flow\",\n * url: \"https://example.com\",\n * recordVideo: true,\n * repoId: \"my-project\"\n * },\n * { apiKey: process.env.MORPH_API_KEY }\n * );\n * \n * console.log('Task result:', result.result);\n * console.log('Video URL:', result.recording?.videoUrl);\n * ```\n */\nexport async function executeWithRecording(\n input: BrowserTaskInput & { recordVideo: true },\n config: BrowserConfig = {}\n): Promise<BrowserTaskResult & { recording?: RecordingWithMethods }> {\n // Execute task with recording\n const taskResult = await executeBrowserTask(input, config);\n\n // If recording was created, wait for it to complete\n if (taskResult.recordingId) {\n try {\n const recording = await waitForRecording(\n taskResult.recordingId,\n config,\n { timeout: 60000, pollInterval: 2000 }\n );\n return {\n ...taskResult,\n recording,\n };\n } catch (error) {\n // Return task result even if recording fails\n // Still attach convenience methods for consistent API\n const errorRecording: RecordingWithMethods = {\n id: taskResult.recordingId,\n status: 'ERROR',\n error: error instanceof Error ? error.message : String(error),\n createdAt: new Date().toISOString(),\n getWebp: (options?: WebpOptions) => getWebp(taskResult.recordingId!, config, options),\n getErrors: () => getErrors(taskResult.recordingId!, config),\n };\n return {\n ...taskResult,\n recording: errorRecording,\n };\n }\n }\n\n return taskResult;\n}\n\n/**\n * Get errors from recording with screenshots\n * \n * Screenshots are captured in real-time (500ms after error occurs) during the browser session.\n * \n * @param recordingId - Recording UUID from BrowserTaskResult\n * @param config - Configuration with apiKey\n * @returns Errors with real-time screenshots\n * \n * @example\n * ```typescript\n * const { errors, totalErrors } = await getErrors('uuid-here', { apiKey: 'key' });\n * \n * console.log(`Found ${totalErrors} errors`);\n * \n * errors.forEach(err => {\n * console.log(`[${err.type}] ${err.message}`);\n * if (err.url) console.log(` URL: ${err.url}`);\n * if (err.screenshotUrl) console.log(` Screenshot: ${err.screenshotUrl}`);\n * \n * // Download screenshot\n * if (err.screenshotUrl) {\n * const response = await fetch(err.screenshotUrl);\n * const screenshot = await response.arrayBuffer();\n * // Save or process screenshot\n * }\n * });\n * ```\n */\nexport async function getErrors(\n recordingId: string,\n config: BrowserConfig = {}\n): Promise<ErrorsResponse> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (!config.apiKey) {\n throw new Error('API key required for getErrors');\n }\n\n if (debug) console.log(`[Browser] getErrors: ${recordingId}`);\n\n const response = await fetch(`${apiUrl}/recordings/${recordingId}/errors`, {\n method: 'GET',\n headers: { 'Authorization': `Bearer ${config.apiKey}` },\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getErrors error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const errors = mapErrorsResponse(await response.json());\n if (debug) console.log(`[Browser] Found ${errors.totalErrors} errors`);\n\n return errors;\n}\n\n/**\n * Helper to serialize Zod schema for API\n */\nfunction stringifyStructuredOutput(schema: any): string {\n try {\n return JSON.stringify({\n type: 'object',\n description: 'Zod schema definition (Zod v3)',\n zodDef: schema._def,\n });\n } catch (error) {\n console.warn('[Browser] Failed to serialize Zod schema:', error);\n return JSON.stringify({\n type: 'object',\n description: 'Schema serialization failed',\n });\n }\n}\n\n/**\n * Parse and validate structured task output\n */\nfunction parseStructuredTaskOutput<T>(\n result: BrowserTaskResult,\n schema: any\n): BrowserTaskResult & { parsed: T | null } {\n if (!result.output) {\n return { ...result, parsed: null };\n }\n\n try {\n const parsed = JSON.parse(result.output);\n const validated = schema.parse(parsed) as T;\n return { ...result, parsed: validated };\n } catch (error) {\n if (error instanceof SyntaxError) {\n return { ...result, parsed: null };\n }\n throw error;\n }\n}\n\nfunction mapTaskResult(api: any): BrowserTaskResult {\n if (!api || typeof api !== 'object') {\n return api as BrowserTaskResult;\n }\n\n return {\n success: api.success,\n result: api.result,\n error: api.error,\n stepsTaken: api.steps_taken,\n executionTimeMs: api.execution_time_ms,\n urls: api.urls,\n actionNames: api.action_names,\n errors: api.errors,\n modelActions: api.model_actions,\n isDone: api.is_done,\n actionHistory: api.action_history,\n actionResults: api.action_results,\n hasErrors: api.has_errors,\n numberOfSteps: api.number_of_steps,\n judgement: api.judgement,\n isValidated: api.is_validated,\n replayId: api.replay_id,\n replayUrl: api.replay_url,\n recordingId: api.recording_id,\n recordingStatus: api.recording_status,\n taskId: api.task_id,\n status: api.status,\n output: api.output,\n debugUrl: api.debug_url,\n };\n}\n\nfunction mapRecordingStatus(api: any): RecordingStatus {\n return {\n id: api.id,\n status: api.status,\n replayUrl: api.replay_url,\n networkUrl: api.network_url,\n consoleUrl: api.console_url,\n videoUrl: api.video_url,\n totalEvents: api.total_events,\n fileSize: api.file_size,\n duration: api.duration,\n error: api.error,\n createdAt: api.created_at,\n };\n}\n\nfunction mapBrowserError(api: any): ErrorsResponse['errors'][number] {\n return {\n type: api.type,\n message: api.message,\n url: api.url,\n timestamp: api.timestamp,\n screenshotUrl: api.screenshot_url,\n capturedAt: api.captured_at,\n status: api.status,\n };\n}\n\nfunction mapErrorsResponse(api: any): ErrorsResponse {\n return {\n recordingId: api.recording_id,\n totalErrors: api.total_errors,\n errors: Array.isArray(api.errors) ? api.errors.map(mapBrowserError) : [],\n };\n}\n\nfunction mapWebpResponse(api: any): WebpResponse {\n return {\n webpUrl: api.webp_url,\n cached: api.cached,\n width: api.width,\n fps: api.fps,\n maxDuration: api.max_duration,\n fileSize: api.file_size,\n maxSizeMb: api.max_size_mb,\n budgetMet: api.budget_met,\n qualityUsed: api.quality_used,\n attempts: api.attempts,\n };\n}\n\n/**\n * Get current task status\n */\nasync function getTaskStatus(\n taskId: string,\n config: BrowserConfig\n): Promise<BrowserTaskResult> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (debug) console.log(`[Browser] getTaskStatus: ${taskId}`);\n\n const headers: Record<string, string> = {};\n if (config.apiKey) headers['Authorization'] = `Bearer ${config.apiKey}`;\n\n const response = await fetch(`${apiUrl}/tasks/${taskId}`, {\n method: 'GET',\n headers,\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getTaskStatus error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const result: BrowserTaskResult = mapTaskResult(await response.json());\n if (debug) console.log(`[Browser] Task status: ${result.status}`);\n\n return result;\n}\n\n/**\n * Generate live URL for watching task execution in real-time\n */\nfunction generateLiveUrl(taskId: string, config: BrowserConfig): string {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const baseUrl = apiUrl.replace('/api', '');\n return `${baseUrl}/tasks/${taskId}/live`;\n}\n\n/**\n * Poll task until completion\n */\nasync function pollTaskUntilComplete(\n taskId: string,\n config: BrowserConfig,\n pollConfig: { interval?: number; timeout?: number } = {}\n): Promise<BrowserTaskResult> {\n const interval = pollConfig.interval ?? 2000; // 2 seconds\n const timeout = pollConfig.timeout ?? 300000; // 5 minutes\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n const status = await getTaskStatus(taskId, config);\n \n if (status.status === 'completed' || status.status === 'failed') {\n return status;\n }\n\n await new Promise(resolve => setTimeout(resolve, interval));\n }\n\n throw new Error(`Task polling timeout after ${timeout}ms`);\n}\n\n/**\n * Wrap task response with convenience methods\n */\nfunction wrapTaskResponse(\n result: BrowserTaskResult,\n config: BrowserConfig\n): BrowserTaskWithPromise {\n const debugUrl = result.debugUrl ?? '';\n\n const wrapped: BrowserTaskWithPromise = {\n ...result,\n debugUrl,\n taskId: result.taskId || '',\n liveUrl: result.taskId\n ? generateLiveUrl(result.taskId, config)\n : debugUrl,\n complete: async (pollConfig?: { interval?: number; timeout?: number }) => {\n // If we have a taskId, poll task status endpoint\n if (result.taskId) {\n return pollTaskUntilComplete(result.taskId!, config, pollConfig);\n }\n // If we have a recordingId, poll recording status instead\n if (result.recordingId) {\n const recording = await waitForRecording(\n result.recordingId,\n config,\n pollConfig\n );\n // Return a result-like object (recording doesn't have full task result)\n return {\n ...result,\n recordingStatus: recording.status,\n } as BrowserTaskResult;\n }\n // No way to poll completion\n throw new Error('Cannot poll completion: no taskId or recordingId available');\n },\n // Add Steel live session helpers - either functional or error-throwing\n getLiveUrl: debugUrl\n ? (options?: LiveSessionOptions) => buildLiveUrl(debugUrl, options)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help.'\n );\n },\n getLiveIframe: debugUrl\n ? (optionsOrPreset?: string | IframeOptions) => {\n const options = resolvePreset(optionsOrPreset);\n return buildLiveIframe(debugUrl, options);\n }\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help.'\n );\n },\n getEmbedCode: debugUrl\n ? () => buildEmbedCode(debugUrl)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help.'\n );\n },\n };\n\n return wrapped;\n}\n\n/**\n * Wrap task response with schema validation\n */\nfunction wrapTaskResponseWithSchema<T>(\n result: BrowserTaskResult,\n config: BrowserConfig,\n schema: any\n): BrowserTaskWithPromiseAndSchema<T> {\n const debugUrl = result.debugUrl ?? '';\n const parsed = result.output\n ? parseStructuredTaskOutput<T>(result, schema)\n : { ...result, parsed: null };\n\n const wrapped: BrowserTaskWithPromiseAndSchema<T> = {\n ...parsed,\n debugUrl,\n taskId: result.taskId || '',\n liveUrl: result.taskId\n ? generateLiveUrl(result.taskId, config)\n : debugUrl,\n complete: async (pollConfig?: { interval?: number; timeout?: number }) => {\n // If we have a taskId, poll task status endpoint\n if (result.taskId) {\n const finalResult = await pollTaskUntilComplete(result.taskId!, config, pollConfig);\n return parseStructuredTaskOutput<T>(finalResult, schema);\n }\n // If we have a recordingId, poll recording status instead\n if (result.recordingId) {\n const recording = await waitForRecording(\n result.recordingId,\n config,\n pollConfig\n );\n // Return parsed result (recording doesn't have task output)\n return {\n ...parsed,\n recordingStatus: recording.status,\n };\n }\n // No way to poll completion\n throw new Error('Cannot poll completion: no taskId or recordingId available');\n },\n // Add Steel live session helpers - either functional or error-throwing\n getLiveUrl: debugUrl\n ? (options?: LiveSessionOptions) => buildLiveUrl(debugUrl, options)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. ' +\n 'Contact support@morphllm.com if you need help enabling live sessions. '\n );\n },\n getLiveIframe: debugUrl\n ? (optionsOrPreset?: string | IframeOptions) => {\n const options = resolvePreset(optionsOrPreset);\n return buildLiveIframe(debugUrl, options);\n }\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. ' +\n 'Contact support@morphllm.com if you need help enabling live sessions.'\n );\n },\n getEmbedCode: debugUrl\n ? () => buildEmbedCode(debugUrl)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. ' +\n 'Contact support@morphllm.com if you need help enabling live sessions.'\n );\n },\n };\n\n return wrapped;\n}\n\n/**\n * Get animated WebP preview of recording\n * \n * Converts the native video recording to an animated WebP. Results are cached in S3.\n * \n * @param recordingId - Recording UUID from BrowserTaskResult\n * @param config - Configuration with apiKey\n * @param options - WebP generation options\n * @returns WebP URL and metadata\n * \n * @example\n * ```typescript\n * const webp = await getWebp('uuid-here', { apiKey: 'key' }, {\n * width: 780,\n * fps: 10,\n * quality: 65,\n * maxDuration: 15\n * });\n * console.log('WebP URL:', webp.webpUrl);\n * console.log('From cache:', webp.cached);\n * ```\n */\nexport async function getWebp(\n recordingId: string,\n config: BrowserConfig = {},\n options: WebpOptions = {}\n): Promise<WebpResponse> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (!config.apiKey) {\n throw new Error('API key required for getWebp');\n }\n\n // Build query params\n const params = new URLSearchParams();\n if (options.maxDuration !== undefined) params.set('max_duration', String(options.maxDuration));\n if (options.fps !== undefined) params.set('fps', String(options.fps));\n if (options.width !== undefined) params.set('width', String(options.width));\n if (options.quality !== undefined) params.set('quality', String(options.quality));\n if (options.maxSizeMb !== undefined) params.set('max_size_mb', String(options.maxSizeMb));\n\n const url = `${apiUrl}/recordings/${recordingId}/webp${params.toString() ? '?' + params.toString() : ''}`;\n \n if (debug) console.log(`[Browser] getWebp: ${url}`);\n\n const response = await fetch(url, {\n method: 'GET',\n headers: { 'Authorization': `Bearer ${config.apiKey}` },\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getWebp error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const result = mapWebpResponse(await response.json());\n if (debug) console.log(`[Browser] WebP ready: ${result.webpUrl} (cached: ${result.cached})`);\n\n return result;\n}\n\n/**\n * Check if browser worker service is healthy\n * \n * @param config - Optional configuration\n * @returns Health status\n */\nexport async function checkHealth(config: BrowserConfig = {}): Promise<{\n ok: boolean;\n google_configured: boolean;\n database_configured: boolean;\n s3_configured: boolean;\n error?: string;\n}> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n\n try {\n const response = await fetch(`${apiUrl}/health`, {\n method: 'GET',\n headers: config.apiKey\n ? { 'Authorization': `Bearer ${config.apiKey}` }\n : {},\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n\n const data = await response.json();\n return {\n ok: true,\n google_configured: data.google_configured ?? false,\n database_configured: data.database_configured ?? false,\n s3_configured: data.s3_configured ?? false,\n };\n } catch (error) {\n return {\n ok: false,\n google_configured: false,\n database_configured: false,\n s3_configured: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,IAAM,iBAAiB;AAAA,EACrB,QAAQ,QAAQ,IAAI,sBAAsB,QACtC,0BACA;AAAA,EACJ,SAAS;AAAA;AAAA,EACT,OAAO;AACT;AAKO,IAAM,gBAAN,MAAoB;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKD;AAAA,EAEP,YAAY,SAAwB,CAAC,GAAG;AACtC,SAAK,SAAS;AAAA,MACZ,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AACA,SAAK,WAAW,IAAI,eAAe,KAAK,MAAM;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,OAAqD;AACjE,WAAO,mBAAmB,OAAO,KAAK,MAAM;AAAA,EAC9C;AAAA,EAIA,MAAM,WACJ,OACsE;AACtE,UAAM,SAAS,KAAK,OAAO,UAAU,eAAe;AACpD,UAAM,QAAQ,KAAK,OAAO,SAAS;AAEnC,QAAI,OAAO;AACT,cAAQ,IAAI,0BAA0B,MAAM,KAAK,MAAM,GAAG,EAAE,C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AAK,iBAAiB;AAAA,IACvC;AAAA,EACF,SAAS,OAAO;AACd,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,mBAAmB;AAAA,MACnB,qBAAqB;AAAA,MACrB,eAAe;AAAA,MACf,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,IAC9D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BROWSER_TOOL_DESCRIPTION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2HMEZZKK.js";
|
|
4
4
|
import {
|
|
5
5
|
executeBrowserTask
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QJP62BXH.js";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
9
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -20,24 +20,24 @@ function createBrowserTool(config) {
|
|
|
20
20
|
const schema = z.object({
|
|
21
21
|
task: z.string().describe('Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'),
|
|
22
22
|
url: z.string().optional().describe("Starting URL (e.g., https://3000-xyz.e2b.dev)"),
|
|
23
|
-
|
|
23
|
+
maxSteps: z.number().min(1).max(50).default(10).describe("Maximum number of browser actions to take"),
|
|
24
24
|
region: z.enum(["sfo", "lon"]).default("sfo").describe("Browserless region: sfo (US West) or lon (Europe)")
|
|
25
25
|
});
|
|
26
26
|
return createTool({
|
|
27
27
|
description: BROWSER_TOOL_DESCRIPTION,
|
|
28
28
|
inputSchema: schema,
|
|
29
29
|
execute: async (params) => {
|
|
30
|
-
const { task, url,
|
|
30
|
+
const { task, url, maxSteps, region } = params;
|
|
31
31
|
const result = await executeBrowserTask(
|
|
32
|
-
{ task, url,
|
|
32
|
+
{ task, url, maxSteps, region },
|
|
33
33
|
config
|
|
34
34
|
);
|
|
35
35
|
if (result.success) {
|
|
36
36
|
return {
|
|
37
37
|
success: true,
|
|
38
38
|
result: result.result,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
stepsTaken: result.stepsTaken,
|
|
40
|
+
executionTimeMs: result.executionTimeMs
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
return {
|
|
@@ -54,4 +54,4 @@ export {
|
|
|
54
54
|
browserTool,
|
|
55
55
|
vercel_exports
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-R7IQWNSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/browser/vercel.ts"],"sourcesContent":["/**\n * Vercel AI SDK adapter for browser automation tool\n */\n\nimport { tool as createTool } from 'ai';\nimport { z } from 'zod';\nimport { executeBrowserTask } from './core.js';\nimport type { BrowserConfig } from './types.js';\nimport { BROWSER_TOOL_DESCRIPTION } from './prompts.js';\n\n/**\n * Create Vercel AI SDK tool for browser automation\n * \n * @param config - Optional browser worker configuration\n * @returns Vercel AI SDK tool\n * \n * @example\n * ```typescript\n * import { generateText } from 'ai';\n * import { anthropic } from '@ai-sdk/anthropic';\n * import { createBrowserTool } from 'morphsdk/tools/browser/vercel';\n * \n * const browserTool = createBrowserTool({\n * apiUrl: 'https://browser-worker.example.com'\n * });\n * \n * const result = await generateText({\n * model: anthropic('claude-sonnet-4-5-20250929'),\n * tools: { browserTask: browserTool },\n * prompt: 'Test the checkout flow at https://3000-abc.e2b.dev',\n * maxSteps: 5\n * });\n * ```\n */\nexport function createBrowserTool(config?: BrowserConfig) {\n const schema = z.object({\n task: z.string().describe('Natural language description of what to do (e.g., \"Test checkout flow for buying a pineapple\")'),\n url: z.string().optional().describe('Starting URL (e.g., https://3000-xyz.e2b.dev)'),\n maxSteps: z.number().min(1).max(50).default(10).describe('Maximum number of browser actions to take'),\n region: z.enum(['sfo', 'lon']).default('sfo').describe('Browserless region: sfo (US West) or lon (Europe)'),\n });\n\n return createTool({\n description: BROWSER_TOOL_DESCRIPTION,\n inputSchema: schema,\n execute: async (params) => {\n const { task, url, maxSteps, region } = params;\n const result = await executeBrowserTask(\n { task, url, maxSteps, region },\n config\n );\n\n // Return minimal summary for agent context (to save tokens)\n // Full result with urls, errors, action_history, judgement, etc. is available\n // when calling executeBrowserTask() directly outside of agent tools\n if (result.success) {\n return {\n success: true,\n result: result.result,\n stepsTaken: result.stepsTaken,\n executionTimeMs: result.executionTimeMs,\n };\n }\n\n return {\n success: false,\n error: result.error,\n };\n },\n });\n}\n\n/**\n * Default browser tool for Vercel AI SDK\n */\nexport const browserTool = createBrowserTool();\n"],"mappings":";;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,SAAS,QAAQ,kBAAkB;AACnC,SAAS,SAAS;AA6BX,SAAS,kBAAkB,QAAwB;AACxD,QAAM,SAAS,EAAE,OAAO;AAAA,IACtB,MAAM,EAAE,OAAO,EAAE,SAAS,gGAAgG;AAAA,IAC1H,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,+CAA+C;AAAA,IACnF,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,SAAS,2CAA2C;AAAA,IACpG,QAAQ,EAAE,KAAK,CAAC,OAAO,KAAK,CAAC,EAAE,QAAQ,KAAK,EAAE,SAAS,mDAAmD;AAAA,EAC5G,CAAC;AAED,SAAO,WAAW;AAAA,IAChB,aAAa;AAAA,IACb,aAAa;AAAA,IACb,SAAS,OAAO,WAAW;AACzB,YAAM,EAAE,MAAM,KAAK,UAAU,OAAO,IAAI;AACxC,YAAM,SAAS,MAAM;AAAA,QACnB,EAAE,MAAM,KAAK,UAAU,OAAO;AAAA,QAC9B;AAAA,MACF;AAKA,UAAI,OAAO,SAAS;AAClB,eAAO;AAAA,UACL,SAAS;AAAA,UACT,QAAQ,OAAO;AAAA,UACf,YAAY,OAAO;AAAA,UACnB,iBAAiB,OAAO;AAAA,QAC1B;AAAA,MACF;AAEA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,OAAO;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKO,IAAM,cAAc,kBAAkB;","names":[]}
|