@elyracode/browser-tools 0.9.55 → 0.9.57

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.57] - 2026-11-10
4
+
5
+ ### Fixed
6
+
7
+ - Tool failures were returned as normal results (`isError` on the return value is ignored) and the model saw them as successes; they now throw so the result is marked as an error
8
+
9
+ ## [0.9.56] - 2026-11-01
10
+
3
11
  ## [0.9.55] - 2026-10-21
4
12
 
5
13
  ## [0.9.54] - 2026-10-14
@@ -173,10 +173,6 @@ function ok(text: string) {
173
173
  return { content: [{ type: "text" as const, text }], details: {} };
174
174
  }
175
175
 
176
- function err(text: string) {
177
- return { content: [{ type: "text" as const, text }], details: {}, isError: true as const };
178
- }
179
-
180
176
  interface Target {
181
177
  role?: string;
182
178
  name?: string;
@@ -223,11 +219,11 @@ export default function (elyra: ExtensionAPI): void {
223
219
  }),
224
220
  execute: async (_id, params) => {
225
221
  const result = await ensurePage();
226
- if ("error" in result) return err(result.error);
222
+ if ("error" in result) throw new Error(result.error);
227
223
  try {
228
224
  await result.page.goto(params.url, { waitUntil: params.wait_until ?? "load", timeout: 30_000 });
229
225
  } catch (error) {
230
- return err(`Navigation failed: ${error instanceof Error ? error.message : String(error)}`);
226
+ throw new Error(`Navigation failed: ${error instanceof Error ? error.message : String(error)}`);
231
227
  }
232
228
  const title = await result.page.title();
233
229
  const snapshot = await snapshotOf(result.page);
@@ -243,21 +239,25 @@ export default function (elyra: ExtensionAPI): void {
243
239
  "Re-read the current page as an accessibility snapshot without navigating - use after the page " +
244
240
  "changed on its own (SPA updates, timers) or to scope into part of a large page with a css selector.",
245
241
  parameters: Type.Object({
246
- css: Type.Optional(Type.String({ description: "Scope the snapshot to this selector (e.g. 'main', '#results')" })),
242
+ css: Type.Optional(
243
+ Type.String({ description: "Scope the snapshot to this selector (e.g. 'main', '#results')" }),
244
+ ),
247
245
  }),
248
246
  execute: async (_id, params) => {
249
- if (!page) return err("No page is open. Use browser_navigate first.");
247
+ if (!page) throw new Error("No page is open. Use browser_navigate first.");
250
248
  try {
251
249
  if (params.css) {
252
250
  const scoped = await page.locator(params.css).first().ariaSnapshot();
253
251
  const clipped =
254
- scoped.length > SNAPSHOT_MAX_CHARS ? `${scoped.slice(0, SNAPSHOT_MAX_CHARS)}\n... (truncated)` : scoped;
252
+ scoped.length > SNAPSHOT_MAX_CHARS
253
+ ? `${scoped.slice(0, SNAPSHOT_MAX_CHARS)}\n... (truncated)`
254
+ : scoped;
255
255
  return ok(`${clipped || "(empty)"}\n\n${drainConsole()}`);
256
256
  }
257
257
  const snapshot = await snapshotOf(page);
258
258
  return ok(`URL: ${page.url()}\n\n${snapshot}\n\n${drainConsole()}`);
259
259
  } catch (error) {
260
- return err(`Snapshot failed: ${error instanceof Error ? error.message : String(error)}`);
260
+ throw new Error(`Snapshot failed: ${error instanceof Error ? error.message : String(error)}`);
261
261
  }
262
262
  },
263
263
  });
@@ -286,12 +286,22 @@ export default function (elyra: ExtensionAPI): void {
286
286
  label: Type.Optional(Type.String({ description: "Form field label" })),
287
287
  text: Type.Optional(Type.String({ description: "Visible text (links, buttons)" })),
288
288
  css: Type.Optional(Type.String({ description: "CSS selector (escape hatch)" })),
289
- value: Type.Optional(Type.String({ description: "For fill/select: the value. For press: the key (e.g. 'Enter')" })),
289
+ value: Type.Optional(
290
+ Type.String({ description: "For fill/select: the value. For press: the key (e.g. 'Enter')" }),
291
+ ),
290
292
  }),
291
293
  execute: async (_id, params) => {
292
- if (!page) return err("No page is open. Use browser_navigate first.");
294
+ if (!page) throw new Error("No page is open. Use browser_navigate first.");
293
295
  const locator = resolveTarget(page, params);
294
- if (!locator) return err("No target given. Provide role(+name), label, text, or css.");
296
+ if (!locator) throw new Error("No target given. Provide role(+name), label, text, or css.");
297
+ if ((params.action === "fill" || params.action === "select") && params.value == null) {
298
+ throw new Error(`'${params.action}' needs a value.`);
299
+ }
300
+ if (params.action === "press" && !params.value) {
301
+ throw new Error("'press' needs a key in value (e.g. 'Enter').");
302
+ }
303
+ // Validated above for the actions that use it.
304
+ const value = params.value ?? "";
295
305
  const timeout = DEFAULT_ACTION_TIMEOUT;
296
306
  try {
297
307
  switch (params.action) {
@@ -299,16 +309,13 @@ export default function (elyra: ExtensionAPI): void {
299
309
  await locator.click({ timeout });
300
310
  break;
301
311
  case "fill":
302
- if (params.value == null) return err("'fill' needs a value.");
303
- await locator.fill(params.value, { timeout });
312
+ await locator.fill(value, { timeout });
304
313
  break;
305
314
  case "press":
306
- if (!params.value) return err("'press' needs a key in value (e.g. 'Enter').");
307
- await locator.press(params.value, { timeout });
315
+ await locator.press(value, { timeout });
308
316
  break;
309
317
  case "select":
310
- if (params.value == null) return err("'select' needs a value.");
311
- await locator.selectOption(params.value, { timeout });
318
+ await locator.selectOption(value, { timeout });
312
319
  break;
313
320
  case "check":
314
321
  await locator.check({ timeout });
@@ -322,7 +329,7 @@ export default function (elyra: ExtensionAPI): void {
322
329
  }
323
330
  } catch (error) {
324
331
  const message = error instanceof Error ? error.message.split("\n")[0] : String(error);
325
- return err(
332
+ throw new Error(
326
333
  `${params.action} on ${describeTarget(params)} failed: ${message} ` +
327
334
  "(take a browser_snapshot to see what the page actually offers)",
328
335
  );
@@ -354,7 +361,7 @@ export default function (elyra: ExtensionAPI): void {
354
361
  height: Type.Optional(Type.Number({ description: "Viewport height to set first" })),
355
362
  }),
356
363
  execute: async (_id, params) => {
357
- if (!page) return err("No page is open. Use browser_navigate first.");
364
+ if (!page) throw new Error("No page is open. Use browser_navigate first.");
358
365
  try {
359
366
  if (params.width && params.height) {
360
367
  await page.setViewportSize({ width: params.width, height: params.height });
@@ -380,7 +387,7 @@ export default function (elyra: ExtensionAPI): void {
380
387
  details: {},
381
388
  };
382
389
  } catch (error) {
383
- return err(`Screenshot failed: ${error instanceof Error ? error.message : String(error)}`);
390
+ throw new Error(`Screenshot failed: ${error instanceof Error ? error.message : String(error)}`);
384
391
  }
385
392
  },
386
393
  });
@@ -408,7 +415,7 @@ export default function (elyra: ExtensionAPI): void {
408
415
  if (result.code === 0) {
409
416
  return ok(`Playwright tests passed.\n\n${tail}`);
410
417
  }
411
- return err(`Playwright tests failed (exit ${result.code}).\n\n${tail}`);
418
+ throw new Error(`Playwright tests failed (exit ${result.code}).\n\n${tail}`);
412
419
  },
413
420
  });
414
421
 
@@ -434,7 +441,9 @@ export default function (elyra: ExtensionAPI): void {
434
441
  ctx.ui.notify("Usage: /browser <url> \u2014 e.g. /browser https://freddy.test", "error");
435
442
  return;
436
443
  }
437
- elyra.sendUserMessage(`Open ${url} with browser_navigate and describe what the page shows and whether the console is clean.`);
444
+ elyra.sendUserMessage(
445
+ `Open ${url} with browser_navigate and describe what the page shows and whether the console is clean.`,
446
+ );
438
447
  },
439
448
  });
440
449
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyracode/browser-tools",
3
- "version": "0.9.55",
3
+ "version": "0.9.57",
4
4
  "description": "Browser automation for Elyra via Playwright - the agent navigates, clicks, fills, and verifies behavior, with token-cheap accessibility snapshots and screenshots",
5
5
  "type": "module",
6
6
  "keywords": [