unbrowse 12.4.0 → 12.5.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.
Files changed (3) hide show
  1. package/README.md +6 -2
  2. package/dist/cli.js +137 -25
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,9 +22,13 @@ unbrowse resume <runId> origin=SIN # answer on the same run
22
22
  | `logins`, `logins remove <origin>` | Saved logins, masked. The CLI never takes a password |
23
23
  | `registry [query]`, `site <host>`, `openapi <host>` | Public compiled sites, a site's tools, its OpenAPI 3.1 document — no account |
24
24
  | `call <host> <tool> [JSON]` | Run one site tool (`--set k=v`, `--deadline MS`, `--select a,b`, `--idempotency-key K`, `--end-user ID`) |
25
- | `tools [query]`, `tool <name> [--key value…]` | Every tool of the hosted MCP from the shell: the cloud browser (`tool browse_open --url …`), `map`, replay, memory, your sites' tools |
25
+ | `browse open <url>`, `browse act <id> click e1`, `browse snapshot`, `browse finish`, `browse close` | The recorded cloud browser |
26
+ | `map <url>`, `sites [site]`, `forget <capability>`, `connect [app]`, `credits` | Site map, what your workspace knows per site, learned tools, app connections, credits |
27
+ | `credentials list`, `credentials request <origin>`, `credentials status <id>` | Saved logins, and a link for the person to save one you need |
28
+ | `replay list`, `replay search`, `replay get`, `replay timeline`, `replay ask` | Recorded sessions |
29
+ | `tools [query]`, `tool <name> [--key value…]` | Any tool by name, such as your learned site tools |
26
30
 
27
- The CLI is the REST client, and through `tool` it can call everything the remote MCP has. To give an agent host the MCP itself, see the [install guide](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/install.md).
31
+ The CLI matches the remote MCP: every MCP tool has a command ([table](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/cli.md#same-as-the-mcp)). To give an agent host the MCP itself, see the [install guide](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/install.md).
28
32
 
29
33
  Exit codes: 0 accepted/ok (check status and verified), 1 error, 2 input required, 3 sign-in or saved login needed, 4 not verified.
30
34
  Env: `UNBROWSE_API_KEY`, `UNBROWSE_BASE_URL`. Node 18.17+, no dependencies.
package/dist/cli.js CHANGED
@@ -26,7 +26,7 @@ var __esm = (fn, res, err) => () => {
26
26
  };
27
27
 
28
28
  // ../sdk/src/version.ts
29
- var SDK_VERSION = "12.4.0";
29
+ var SDK_VERSION = "12.5.0";
30
30
 
31
31
  // ../sdk/src/client.ts
32
32
  function apiBase(url) {
@@ -1553,6 +1553,28 @@ function filterTools(tools, query) {
1553
1553
  const byName = tools.filter((t) => matches(shortName(t.name)));
1554
1554
  return byName.length ? byName : tools.filter((t) => matches(`${shortName(t.name)} ${t.description ?? ""}`));
1555
1555
  }
1556
+ function findCommand(cmd, sub) {
1557
+ const all = MCP_COMMANDS.filter((c) => c.cmd === cmd);
1558
+ const command = all.find((c) => !c.sub || c.sub === sub);
1559
+ return command ? { command } : { usage: all.map((c) => `unbrowse ${c.usage}`).join(`
1560
+ `) };
1561
+ }
1562
+ function commandInput(c, words, flags, sets, coerce) {
1563
+ const out = {};
1564
+ c.args.forEach((name, i) => {
1565
+ const v = c.rest && i === c.args.length - 1 ? words.slice(i).join(" ") : words[i];
1566
+ if (v)
1567
+ out[name.replace(/\?$/, "")] = v;
1568
+ });
1569
+ for (const [k, v] of Object.entries(flags))
1570
+ if (!CLI_FLAGS.has(k))
1571
+ out[k.replace(/-([a-z])/g, (_, ch) => ch.toUpperCase())] = typeof v === "string" ? coerce(v) : v;
1572
+ Object.assign(out, sets);
1573
+ for (const k of c.lists ?? [])
1574
+ if (typeof out[k] === "string")
1575
+ out[k] = out[k].split(",").map((s) => s.trim()).filter(Boolean);
1576
+ return out;
1577
+ }
1556
1578
  function toolInput(t, json, flags, sets, coerce) {
1557
1579
  const props = new Set(Object.keys((t.inputSchema ?? {}).properties ?? {}));
1558
1580
  const key = (k) => props.has(k) ? k : k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
@@ -1585,9 +1607,46 @@ function resultCode(r, value) {
1585
1607
  const status = value?.status;
1586
1608
  return status === "input_required" ? 2 : 0;
1587
1609
  }
1588
- var CLI_FLAGS;
1610
+ var MCP_COMMANDS, CLI_FOR_TOOL, CLI_FLAGS;
1589
1611
  var init_mcp_tools = __esm(() => {
1590
1612
  init_mcp_proxy();
1613
+ MCP_COMMANDS = [
1614
+ { cmd: "map", tool: "unbrowse_map", args: ["url"], usage: "map <url> [--search TEXT] [--limit N]", does: "A site's URLs from its sitemaps and the page's links" },
1615
+ { cmd: "browse", sub: "open", tool: "unbrowse_browse_open", args: ["url"], usage: "browse open <url> [--task TEXT] [--country XX]", does: "Open a recorded cloud browser on a page; prints its text and @refs" },
1616
+ { cmd: "browse", sub: "snapshot", tool: "unbrowse_browse_snapshot", args: ["sessionId"], usage: "browse snapshot <sessionId> [--text-offset N]", does: "The page's current text and @refs" },
1617
+ { cmd: "browse", sub: "act", tool: "unbrowse_browse_act", args: ["sessionId", "action", "ref?", "value?"], rest: true, usage: "browse act <sessionId> <click|fill|select|check|press|wait|autofill> [ref] [value…] [--name N] [--vault FIELD] [--key K]", does: "One action on a @ref" },
1618
+ { cmd: "browse", sub: "finish", tool: "unbrowse_browse_finish", args: ["sessionId"], usage: "browse finish <sessionId> [--title T] [--goal G]", does: "End the session and learn the site's routes from it" },
1619
+ { cmd: "browse", sub: "close", tool: "unbrowse_browse_close", args: ["sessionId"], usage: "browse close <sessionId> [--discard]", does: "End the session (it still indexes unless --discard)" },
1620
+ { cmd: "sites", tool: "unbrowse_sites", args: ["site?"], usage: "sites [site]", does: "What your workspace knows about each site: access, saved login, session" },
1621
+ { cmd: "forget", tool: "unbrowse_forget", args: ["capability"], usage: "forget <capability>", does: "Delete one of your learned capabilities" },
1622
+ { cmd: "credentials", sub: "list", tool: "unbrowse_credentials_list", args: ["origin?"], usage: "credentials list [origin] [--query TEXT] [--limit N]", does: "Saved logins as masked hints, filtered by site" },
1623
+ { cmd: "credentials", sub: "request", tool: "unbrowse_credentials_request", args: ["origin"], lists: ["fields"], usage: "credentials request <origin> [--fields username,password,totp] [--reason TEXT]", does: "A one-time link for the person to save a login you need" },
1624
+ { cmd: "credentials", sub: "status", tool: "unbrowse_credentials_status", args: ["requestId"], usage: "credentials status <requestId> [--wait-seconds N]", does: "Whether that request was answered" },
1625
+ { cmd: "connect", tool: "unbrowse_connect", args: ["app?"], usage: "connect [app] [--url URL --name N] [--search TEXT] [--disconnect]", does: "Connect an app's own MCP server (Linear, Notion, GitHub…) so its tools run as you" },
1626
+ { cmd: "credits", tool: "unbrowse_credits", args: [], usage: "credits [--pack p10|p50|p200]", does: "Credits left; --pack gets a checkout link" },
1627
+ { cmd: "replay", sub: "list", tool: "unbrowse_replay_list", args: [], usage: "replay list [--site S] [--outcome O] [--has-error] [--from D] [--to D] [--limit N]", does: "Recorded sessions, newest first" },
1628
+ { cmd: "replay", sub: "search", tool: "unbrowse_replay_search", args: ["query"], rest: true, usage: "replay search <query…> [same filters]", does: "Search what happened in recorded sessions" },
1629
+ { cmd: "replay", sub: "get", tool: "unbrowse_replay_get", args: ["sid"], usage: "replay get <sid>", does: "One session's details, signals and summary" },
1630
+ { cmd: "replay", sub: "timeline", tool: "unbrowse_replay_timeline", args: ["sid"], lists: ["kinds"], usage: "replay timeline <sid> [--from MS] [--to MS] [--kinds a,b]", does: "A session as text, one line per event" },
1631
+ { cmd: "replay", sub: "ask", tool: "unbrowse_replay_ask", args: ["question"], rest: true, usage: "replay ask <question…> [same filters]", does: "Ask a question across recorded sessions" }
1632
+ ];
1633
+ CLI_FOR_TOOL = {
1634
+ unbrowse_discover: "discover",
1635
+ search: "discover",
1636
+ unbrowse_run: "run",
1637
+ unbrowse_inspect: "inspect",
1638
+ unbrowse_resume: "resume",
1639
+ unbrowse_cancel: "cancel",
1640
+ unbrowse_learn: "learn",
1641
+ unbrowse_scrape: "scrape",
1642
+ fetch: "scrape",
1643
+ unbrowse_usage: "usage",
1644
+ unbrowse_index: "index",
1645
+ unbrowse_index_status: "index status",
1646
+ unbrowse_import_mcps: "mcps import",
1647
+ unbrowse_local_mcps: "mcps",
1648
+ ...Object.fromEntries(MCP_COMMANDS.map((c) => [c.tool, c.sub ? `${c.cmd} ${c.sub}` : c.cmd]))
1649
+ };
1591
1650
  CLI_FLAGS = new Set(["json", "base-url", "account", "no-open", "input", "from-here", "help", "version"]);
1592
1651
  });
1593
1652
 
@@ -1928,7 +1987,7 @@ async function deviceLogin(baseUrl, opts) {
1928
1987
 
1929
1988
  // src/cli.ts
1930
1989
  init_src();
1931
- var VERSION = "12.4.0";
1990
+ var VERSION = "12.5.0";
1932
1991
  var DEFAULT_ORIGIN = "https://unbrowse.ai";
1933
1992
  var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse API
1934
1993
 
@@ -1980,9 +2039,33 @@ var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse A
1980
2039
  call <host> <tool> [JSON] Run one site tool with its inputs (or --set key=value…); prints the run
1981
2040
  [--deadline MS] [--select PATH,…] [--idempotency-key K] [--end-user ID]
1982
2041
 
1983
- tools [query | name] Every tool of the hosted MCP (cloud browser, map, replay, memory, your sites' tools…);
2042
+ map <url> A site's URLs from its sitemaps and links [--search TEXT] [--limit N]
2043
+ sites [site] What your workspace knows about each site: access, saved login, session
2044
+ forget <capability> Delete one of your learned capabilities
2045
+ connect [app] Connect an app's own MCP server (Linear, Notion, GitHub…) so its tools run as you
2046
+ [--url URL --name N] [--search TEXT] [--disconnect]
2047
+ credits [--pack p10|p50|p200] Credits left; --pack gets a checkout link
2048
+
2049
+ browse open <url> A recorded cloud browser on a page: its text and @refs [--task TEXT] [--country XX]
2050
+ browse snapshot <sessionId> The page now [--text-offset N]
2051
+ browse act <sessionId> <action> [ref] [value…]
2052
+ click | fill | select | check | press | wait | autofill [--name N] [--vault FIELD] [--key K]
2053
+ browse finish <sessionId> End it and learn the site's routes from what you did [--title T] [--goal G]
2054
+ browse close <sessionId> End it (still indexes unless --discard)
2055
+
2056
+ credentials list [origin] Saved logins, masked, for one site [--query TEXT]
2057
+ credentials request <origin> A one-time link for the person to save a login [--fields username,password,totp] [--reason TEXT]
2058
+ credentials status <requestId> Whether they did [--wait-seconds N]
2059
+
2060
+ replay list Recorded sessions [--site S] [--outcome O] [--has-error] [--from D] [--to D] [--limit N]
2061
+ replay search <query…> Search what happened in them (same filters)
2062
+ replay get <sid> One session: details, signals, summary
2063
+ replay timeline <sid> One session as text, a line per event [--kinds a,b]
2064
+ replay ask <question…> Ask across sessions (same filters)
2065
+
2066
+ tools [query | name] Every tool the hosted MCP lists you, your own learned and indexed site tools included;
1984
2067
  one name prints its description and inputs (--json: every schema)
1985
- tool <name> [JSON] Call one, the same as an agent over MCP: unbrowse tool browse_open --url https://…
2068
+ tool <name> [JSON] Call any of them by name, e.g. a learned one: unbrowse tool my__arxiv_org__get_cs_ai_recent --name cs.AI
1986
2069
  [--key value]… [--set key=value]… [--input JSON]
1987
2070
  the unbrowse_ prefix is optional; every --flag the CLI does not use is an input
1988
2071
  [--from-here] run sends its site requests from this machine, like \`unbrowse run\`
@@ -1998,8 +2081,8 @@ var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse A
1998
2081
  Options: --json (errors as JSON) · --base-url URL · --no-open · --account NAME
1999
2082
  Env: UNBROWSE_API_KEY, UNBROWSE_ACCOUNT, UNBROWSE_BASE_URL (default ${DEFAULT_ORIGIN}), UNBROWSE_EGRESS=server, UNBROWSE_MCP_URL, UNBROWSE_END_USER
2000
2083
  Exit: 0 ok · 1 error · 2 input required · 3 sign-in or login needed · 4 not verified`;
2001
- var BOOLEAN = new Set(["json", "help", "version", "no-open", "no-wait", "unattended", "from-here", "from-unbrowse", "all", "all-sites", "yes", "full", "events", "dry-run", "with-keys", "replace"]);
2002
- var NEEDS_ACCOUNT = new Set(["whoami", "usage", "discover", "run", "scrape", "index", "inspect", "resume", "cancel", "learn", "learned", "logins", "call", "cookies", "tools", "tool"]);
2084
+ var BOOLEAN = new Set(["json", "help", "version", "no-open", "no-wait", "unattended", "from-here", "from-unbrowse", "all", "all-sites", "yes", "full", "events", "dry-run", "with-keys", "replace", "discard", "disconnect", "has-error"]);
2085
+ var NEEDS_ACCOUNT = new Set(["whoami", "usage", "discover", "run", "scrape", "index", "inspect", "resume", "cancel", "learn", "learned", "logins", "call", "cookies", "tools", "tool", "map", "sites", "forget", "connect", "credits", "browse", "credentials", "replay"]);
2003
2086
  var SCRAPE_FORMATS = ["markdown", "html", "text", "links", "raw"];
2004
2087
  function parseArgs(argv) {
2005
2088
  const out = { _: [], flags: {}, sets: {} };
@@ -2504,6 +2587,15 @@ Your browser opens ${origin}; approve it and \`unbrowse ${cmd}\` carries on. (Sc
2504
2587
  return io.err("Outcome unknown: a change may have happened. Inspect before retrying."), 4;
2505
2588
  return io.err(`${run.status}${run.error ? `: ${run.error.code} — ${run.error.message}` : ""}`), 1;
2506
2589
  }
2590
+ case "map":
2591
+ case "sites":
2592
+ case "forget":
2593
+ case "connect":
2594
+ case "credits":
2595
+ case "browse":
2596
+ case "credentials":
2597
+ case "replay":
2598
+ return await mcpCommand(cmd, rest, args, io, origin, print, client);
2507
2599
  case "tools":
2508
2600
  case "tool":
2509
2601
  return await mcpTools(cmd, rest, args, io, origin, print, client);
@@ -2707,20 +2799,53 @@ ${unique(servers.filter((s) => !s.self)).length} to import: unbrowse mcps import
2707
2799
  }
2708
2800
  return rows.some((r) => r.status === "failed") ? 1 : 0;
2709
2801
  }
2710
- async function mcpTools(cmd, rest, args, io, origin, print, client) {
2711
- const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2802
+ async function mcpRpc(args, origin, client) {
2712
2803
  await Promise.resolve().then(() => init_mcp_proxy());
2713
2804
  await Promise.resolve().then(() => init_src());
2714
2805
  const url = process.env.UNBROWSE_MCP_URL ?? `${origin}/api/mcp`;
2715
2806
  const endUser = process.env.UNBROWSE_END_USER;
2716
2807
  const handle = createProxy(async () => new UnbrowseMcp({ url, apiKey: await tokenFor(origin, url) ?? "", endUser, client: `cli/${VERSION}` }), VERSION, args.flags["from-here"] ? { runLocal: localRun(client) } : {});
2717
2808
  let id = 0;
2718
- const rpc = async (method, params) => {
2809
+ return async (method, params) => {
2719
2810
  const res = await handle({ jsonrpc: "2.0", id: ++id, method, ...params ? { params } : {} });
2720
2811
  if (res.error)
2721
2812
  throw Object.assign(new Error(res.error.message), { status: res.error.data?.code === "unauthorized" || /unbrowse login/.test(res.error.message) ? 401 : undefined, code: res.error.data?.code });
2722
2813
  return res.result;
2723
2814
  };
2815
+ }
2816
+ async function printToolResult(result, io, print) {
2817
+ const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2818
+ const value = resultValue(result);
2819
+ const code = resultCode(result, value);
2820
+ if (code === 1)
2821
+ io.err(typeof value === "string" ? value : JSON.stringify(value, null, 2));
2822
+ else if (typeof value === "string")
2823
+ io.out(value);
2824
+ else
2825
+ print(value);
2826
+ if (code === 2) {
2827
+ const runId = value.runId;
2828
+ io.err(`Input required: ${runId ? `unbrowse resume ${runId} key=value…` : "answer the open requirements and call again"}`);
2829
+ }
2830
+ return code;
2831
+ }
2832
+ async function mcpCommand(cmd, rest, args, io, origin, print, client) {
2833
+ const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2834
+ const { command, usage } = findCommand(cmd, rest[0]);
2835
+ if (!command)
2836
+ throw new UsageError(`usage:
2837
+ ${usage}`);
2838
+ const words = command.sub ? rest.slice(1) : rest;
2839
+ const required = command.args.filter((a) => !a.endsWith("?")).length;
2840
+ if (words.length < required || words.length > command.args.length && !command.rest)
2841
+ throw new UsageError(`usage: unbrowse ${command.usage}`);
2842
+ const input = commandInput(command, words, args.flags, mapValues(args.sets), coerce);
2843
+ const rpc = await mcpRpc(args, origin, client);
2844
+ return printToolResult(await rpc("tools/call", { name: command.tool, arguments: input }), io, print);
2845
+ }
2846
+ async function mcpTools(cmd, rest, args, io, origin, print, client) {
2847
+ const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2848
+ const rpc = await mcpRpc(args, origin, client);
2724
2849
  const { tools } = await rpc("tools/list");
2725
2850
  if (cmd === "tools") {
2726
2851
  const query = rest.join(" ");
@@ -2754,20 +2879,7 @@ ${shown.length} tool(s). One in full: unbrowse tools <name> · call one: unbrows
2754
2879
  throw new UsageError(`no MCP tool named "${typed}".${near.length ? ` Did you mean: ${near.join(", ")}?` : ""} List them: unbrowse tools`);
2755
2880
  }
2756
2881
  const input = toolInput(tool, rest[1] ? rest.slice(1).join(" ") : typeof args.flags.input === "string" ? args.flags.input : undefined, args.flags, mapValues(args.sets), coerce);
2757
- const result = await rpc("tools/call", { name: tool.name, arguments: input });
2758
- const value = resultValue(result);
2759
- const code = resultCode(result, value);
2760
- if (code === 1)
2761
- io.err(typeof value === "string" ? value : JSON.stringify(value, null, 2));
2762
- else if (typeof value === "string")
2763
- io.out(value);
2764
- else
2765
- print(value);
2766
- if (code === 2) {
2767
- const runId = value.runId;
2768
- io.err(`Input required: ${runId ? `unbrowse resume ${runId} key=value…` : "answer it with unbrowse tool resume"}`);
2769
- }
2770
- return code;
2882
+ return printToolResult(await rpc("tools/call", { name: tool.name, arguments: input }), io, print);
2771
2883
  }
2772
2884
  function siteLoginRequired(body) {
2773
2885
  const err = body?.error;
@@ -2804,7 +2916,7 @@ function noCapabilityHint(view, args) {
2804
2916
  if (url) {
2805
2917
  lines.push(` Read the page now: unbrowse scrape ${url}`);
2806
2918
  lines.push(` Teach Unbrowse the site: unbrowse index ${url} (minutes; then run the task again)`);
2807
- lines.push(` Do it in a cloud browser: unbrowse tool browse_open --url ${url} (recorded, so it teaches the site too)`);
2919
+ lines.push(` Do it in a cloud browser: unbrowse browse open ${url} (recorded, so it teaches the site too)`);
2808
2920
  } else {
2809
2921
  lines.push(` Name the site: unbrowse run ${JSON.stringify(task || "<task>")} --url https://…`);
2810
2922
  lines.push(" Read any page now: unbrowse scrape https://…");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unbrowse",
3
- "version": "12.4.0",
3
+ "version": "12.5.0",
4
4
  "mcpName": "io.github.unbrowse-ai/unbrowse",
5
5
  "description": "Call websites as APIs: a thin CLI over the Unbrowse API.",
6
6
  "keywords": [