@different-ai/opencode-browser 4.0.5 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/plugin.js +168 -85
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -12354,6 +12354,7 @@ function getPackageVersion() {
12354
12354
  cachedVersion = "unknown";
12355
12355
  return cachedVersion;
12356
12356
  }
12357
+ var { schema } = tool;
12357
12358
  var BASE_DIR = join(homedir(), ".opencode-browser");
12358
12359
  var SOCKET_PATH = join(BASE_DIR, "broker.sock");
12359
12360
  mkdirSync(BASE_DIR, { recursive: true });
@@ -12467,91 +12468,173 @@ function toolResultText(data, fallback) {
12467
12468
  return JSON.stringify(data.content);
12468
12469
  return fallback;
12469
12470
  }
12470
- var plugin = {
12471
- name: "opencode-browser",
12472
- tools: [
12473
- tool("browser_debug", "Debug plugin loading and connection status.", {}, async () => {
12474
- console.log("[opencode-browser] browser_debug called", { sessionId, pid: process.pid });
12475
- return JSON.stringify({
12476
- loaded: true,
12477
- sessionId,
12478
- pid: process.pid,
12479
- pluginVersion: getPackageVersion(),
12480
- tools: plugin.tools.map((t) => ({ name: t.name, description: t.description })),
12481
- timestamp: new Date().toISOString()
12482
- });
12483
- }),
12484
- tool("browser_version", "Return the installed @different-ai/opencode-browser plugin version.", {}, async () => {
12485
- return JSON.stringify({
12486
- name: "@different-ai/opencode-browser",
12487
- version: getPackageVersion(),
12488
- sessionId,
12489
- pid: process.pid
12490
- });
12491
- }),
12492
- tool("browser_status", "Check broker/native-host connection status and current tab claims.", {}, async () => {
12493
- const data = await brokerRequest("status", {});
12494
- return JSON.stringify(data);
12495
- }),
12496
- tool("browser_get_tabs", "List all open browser tabs", {}, async () => {
12497
- const data = await brokerRequest("tool", { tool: "get_tabs", args: {} });
12498
- return toolResultText(data, "ok");
12499
- }),
12500
- tool("browser_navigate", "Navigate to a URL in the browser", { url: { type: "string" }, tabId: { type: "number", optional: true } }, async ({ url: url2, tabId }) => {
12501
- const data = await brokerRequest("tool", { tool: "navigate", args: { url: url2, tabId } });
12502
- return toolResultText(data, `Navigated to ${url2}`);
12503
- }),
12504
- tool("browser_click", "Click an element on the page using a CSS selector", { selector: { type: "string" }, tabId: { type: "number", optional: true } }, async ({ selector, tabId }) => {
12505
- const data = await brokerRequest("tool", { tool: "click", args: { selector, tabId } });
12506
- return toolResultText(data, `Clicked ${selector}`);
12507
- }),
12508
- tool("browser_type", "Type text into an input element", {
12509
- selector: { type: "string" },
12510
- text: { type: "string" },
12511
- clear: { type: "boolean", optional: true },
12512
- tabId: { type: "number", optional: true }
12513
- }, async ({ selector, text, clear, tabId }) => {
12514
- const data = await brokerRequest("tool", { tool: "type", args: { selector, text, clear, tabId } });
12515
- return toolResultText(data, `Typed "${text}" into ${selector}`);
12516
- }),
12517
- tool("browser_screenshot", "Take a screenshot of the current page. Returns base64 image data URL.", { tabId: { type: "number", optional: true } }, async ({ tabId }) => {
12518
- const data = await brokerRequest("tool", { tool: "screenshot", args: { tabId } });
12519
- return toolResultText(data, "Screenshot failed");
12520
- }),
12521
- tool("browser_snapshot", "Get an accessibility tree snapshot of the page.", { tabId: { type: "number", optional: true } }, async ({ tabId }) => {
12522
- const data = await brokerRequest("tool", { tool: "snapshot", args: { tabId } });
12523
- return toolResultText(data, "Snapshot failed");
12524
- }),
12525
- tool("browser_scroll", "Scroll the page or scroll an element into view", {
12526
- selector: { type: "string", optional: true },
12527
- x: { type: "number", optional: true },
12528
- y: { type: "number", optional: true },
12529
- tabId: { type: "number", optional: true }
12530
- }, async ({ selector, x, y, tabId }) => {
12531
- const data = await brokerRequest("tool", { tool: "scroll", args: { selector, x, y, tabId } });
12532
- return toolResultText(data, "Scrolled");
12533
- }),
12534
- tool("browser_wait", "Wait for a specified duration", { ms: { type: "number", optional: true }, tabId: { type: "number", optional: true } }, async ({ ms, tabId }) => {
12535
- const data = await brokerRequest("tool", { tool: "wait", args: { ms, tabId } });
12536
- return toolResultText(data, "Waited");
12537
- }),
12538
- tool("browser_execute", "Execute JavaScript code in the page context and return the result.", { code: { type: "string" }, tabId: { type: "number", optional: true } }, async ({ code, tabId }) => {
12539
- const data = await brokerRequest("tool", { tool: "execute_script", args: { code, tabId } });
12540
- return toolResultText(data, "Execute failed");
12541
- }),
12542
- tool("browser_claim_tab", "Claim a tab for this OpenCode session (per-tab ownership).", { tabId: { type: "number" }, force: { type: "boolean", optional: true } }, async ({ tabId, force }) => {
12543
- const data = await brokerRequest("claim_tab", { tabId, force });
12544
- return JSON.stringify(data);
12545
- }),
12546
- tool("browser_release_tab", "Release a previously claimed tab.", { tabId: { type: "number" } }, async ({ tabId }) => {
12547
- const data = await brokerRequest("release_tab", { tabId });
12548
- return JSON.stringify(data);
12549
- }),
12550
- tool("browser_list_claims", "List current tab ownership claims.", {}, async () => {
12551
- const data = await brokerRequest("list_claims", {});
12552
- return JSON.stringify(data);
12553
- })
12554
- ]
12471
+ var plugin = async (ctx) => {
12472
+ console.log("[opencode-browser] Plugin loading...", { pid: process.pid });
12473
+ return {
12474
+ tool: {
12475
+ browser_debug: tool({
12476
+ description: "Debug plugin loading and connection status.",
12477
+ args: {},
12478
+ async execute(args, ctx2) {
12479
+ console.log("[opencode-browser] browser_debug called", { sessionId, pid: process.pid });
12480
+ return JSON.stringify({
12481
+ loaded: true,
12482
+ sessionId,
12483
+ pid: process.pid,
12484
+ pluginVersion: getPackageVersion(),
12485
+ timestamp: new Date().toISOString()
12486
+ });
12487
+ }
12488
+ }),
12489
+ browser_version: tool({
12490
+ description: "Return the installed @different-ai/opencode-browser plugin version.",
12491
+ args: {},
12492
+ async execute(args, ctx2) {
12493
+ return JSON.stringify({
12494
+ name: "@different-ai/opencode-browser",
12495
+ version: getPackageVersion(),
12496
+ sessionId,
12497
+ pid: process.pid
12498
+ });
12499
+ }
12500
+ }),
12501
+ browser_status: tool({
12502
+ description: "Check broker/native-host connection status and current tab claims.",
12503
+ args: {},
12504
+ async execute(args, ctx2) {
12505
+ const data = await brokerRequest("status", {});
12506
+ return JSON.stringify(data);
12507
+ }
12508
+ }),
12509
+ browser_get_tabs: tool({
12510
+ description: "List all open browser tabs",
12511
+ args: {},
12512
+ async execute(args, ctx2) {
12513
+ const data = await brokerRequest("tool", { tool: "get_tabs", args: {} });
12514
+ return toolResultText(data, "ok");
12515
+ }
12516
+ }),
12517
+ browser_navigate: tool({
12518
+ description: "Navigate to a URL in the browser",
12519
+ args: {
12520
+ url: schema.string(),
12521
+ tabId: schema.number().optional()
12522
+ },
12523
+ async execute({ url: url2, tabId }, ctx2) {
12524
+ const data = await brokerRequest("tool", { tool: "navigate", args: { url: url2, tabId } });
12525
+ return toolResultText(data, `Navigated to ${url2}`);
12526
+ }
12527
+ }),
12528
+ browser_click: tool({
12529
+ description: "Click an element on the page using a CSS selector",
12530
+ args: {
12531
+ selector: schema.string(),
12532
+ tabId: schema.number().optional()
12533
+ },
12534
+ async execute({ selector, tabId }, ctx2) {
12535
+ const data = await brokerRequest("tool", { tool: "click", args: { selector, tabId } });
12536
+ return toolResultText(data, `Clicked ${selector}`);
12537
+ }
12538
+ }),
12539
+ browser_type: tool({
12540
+ description: "Type text into an input element",
12541
+ args: {
12542
+ selector: schema.string(),
12543
+ text: schema.string(),
12544
+ clear: schema.boolean().optional(),
12545
+ tabId: schema.number().optional()
12546
+ },
12547
+ async execute({ selector, text, clear, tabId }, ctx2) {
12548
+ const data = await brokerRequest("tool", { tool: "type", args: { selector, text, clear, tabId } });
12549
+ return toolResultText(data, `Typed "${text}" into ${selector}`);
12550
+ }
12551
+ }),
12552
+ browser_screenshot: tool({
12553
+ description: "Take a screenshot of the current page. Returns base64 image data URL.",
12554
+ args: {
12555
+ tabId: schema.number().optional()
12556
+ },
12557
+ async execute({ tabId }, ctx2) {
12558
+ const data = await brokerRequest("tool", { tool: "screenshot", args: { tabId } });
12559
+ return toolResultText(data, "Screenshot failed");
12560
+ }
12561
+ }),
12562
+ browser_snapshot: tool({
12563
+ description: "Get an accessibility tree snapshot of the page.",
12564
+ args: {
12565
+ tabId: schema.number().optional()
12566
+ },
12567
+ async execute({ tabId }, ctx2) {
12568
+ const data = await brokerRequest("tool", { tool: "snapshot", args: { tabId } });
12569
+ return toolResultText(data, "Snapshot failed");
12570
+ }
12571
+ }),
12572
+ browser_scroll: tool({
12573
+ description: "Scroll the page or scroll an element into view",
12574
+ args: {
12575
+ selector: schema.string().optional(),
12576
+ x: schema.number().optional(),
12577
+ y: schema.number().optional(),
12578
+ tabId: schema.number().optional()
12579
+ },
12580
+ async execute({ selector, x, y, tabId }, ctx2) {
12581
+ const data = await brokerRequest("tool", { tool: "scroll", args: { selector, x, y, tabId } });
12582
+ return toolResultText(data, "Scrolled");
12583
+ }
12584
+ }),
12585
+ browser_wait: tool({
12586
+ description: "Wait for a specified duration",
12587
+ args: {
12588
+ ms: schema.number().optional(),
12589
+ tabId: schema.number().optional()
12590
+ },
12591
+ async execute({ ms, tabId }, ctx2) {
12592
+ const data = await brokerRequest("tool", { tool: "wait", args: { ms, tabId } });
12593
+ return toolResultText(data, "Waited");
12594
+ }
12595
+ }),
12596
+ browser_execute: tool({
12597
+ description: "Execute JavaScript code in the page context and return the result.",
12598
+ args: {
12599
+ code: schema.string(),
12600
+ tabId: schema.number().optional()
12601
+ },
12602
+ async execute({ code, tabId }, ctx2) {
12603
+ const data = await brokerRequest("tool", { tool: "execute_script", args: { code, tabId } });
12604
+ return toolResultText(data, "Execute failed");
12605
+ }
12606
+ }),
12607
+ browser_claim_tab: tool({
12608
+ description: "Claim a tab for this OpenCode session (per-tab ownership).",
12609
+ args: {
12610
+ tabId: schema.number(),
12611
+ force: schema.boolean().optional()
12612
+ },
12613
+ async execute({ tabId, force }, ctx2) {
12614
+ const data = await brokerRequest("claim_tab", { tabId, force });
12615
+ return JSON.stringify(data);
12616
+ }
12617
+ }),
12618
+ browser_release_tab: tool({
12619
+ description: "Release a previously claimed tab.",
12620
+ args: {
12621
+ tabId: schema.number()
12622
+ },
12623
+ async execute({ tabId }, ctx2) {
12624
+ const data = await brokerRequest("release_tab", { tabId });
12625
+ return JSON.stringify(data);
12626
+ }
12627
+ }),
12628
+ browser_list_claims: tool({
12629
+ description: "List current tab ownership claims.",
12630
+ args: {},
12631
+ async execute(args, ctx2) {
12632
+ const data = await brokerRequest("list_claims", {});
12633
+ return JSON.stringify(data);
12634
+ }
12635
+ })
12636
+ }
12637
+ };
12555
12638
  };
12556
12639
  var plugin_default = plugin;
12557
12640
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@different-ai/opencode-browser",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "Browser automation plugin for OpenCode (native messaging + per-tab ownership).",
5
5
  "type": "module",
6
6
  "bin": {