friend-assistant 0.1.97 → 0.1.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -432,7 +432,7 @@ Besides the simple widgets, Every component of the Jarvis HUD library that is sa
432
432
 
433
433
  ## Windows PCs: the assistant uses a PC like a person
434
434
 
435
- Add as many Windows PCs as you want (Plugins, Windows PCs). The assistant can then look at the screen, click, type, open apps, wait for things, run commands, work with files, and drive a terminal such as Claude Code (open a project, resume an earlier session, answer its menus, give it instructions, check its status). Each PC runs a small agent that connects out to your Friend; **nothing of Friend is installed on it**.
435
+ Add as many Windows PCs as you want: install the **Windows PCs** plugin (Plugins, Available, Install, then Turn on), press **Configure** and **Add a PC**. The assistant can then look at the screen, click, type, open apps, wait for things, run commands, work with files, and drive a terminal such as Claude Code (open a project, resume an earlier session, answer its menus, give it instructions, check its status). Each PC runs a small agent that connects out to your Friend; **nothing of Friend is installed on it**.
436
436
 
437
437
  - **Add a PC:** one PowerShell line (or a small `.cmd` file) installs the official Node.js (its signature is checked) and the agent (its checksum is checked) into your own user folder, starts it at every logon, and opens a page to approve the PC with your PIN (device authorization with PKCE). No administrator rights, no unsigned program.
438
438
  - **Permissions per PC**, all off to start: control the screen, screenshots, commands and terminals, programs, registry, files (off, read, read and write, only inside listed folders).
package/dist/BUILD.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "friend-assistant",
3
- "version": "0.1.97",
4
- "builtAt": "2026-11-27T08:26:06.027Z"
3
+ "version": "0.1.99",
4
+ "builtAt": "2026-11-27T09:18:59.023Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -3374,6 +3374,10 @@ function sanitizeChrome(raw) {
3374
3374
  const r = raw && typeof raw === "object" ? raw : {};
3375
3375
  return { installed: r.installed === true || r.installed === void 0 && r.enabled === true, enabled: r.enabled === true, remote: r.remote === true };
3376
3376
  }
3377
+ function sanitizePcs(raw) {
3378
+ const r = raw && typeof raw === "object" ? raw : {};
3379
+ return { installed: r.installed === true || r.installed === void 0 && r.enabled === true, enabled: r.enabled === true };
3380
+ }
3377
3381
  function sanitizeAudius(raw) {
3378
3382
  const r = raw && typeof raw === "object" ? raw : {};
3379
3383
  return { installed: r.installed === true || r.installed === void 0 && r.enabled === true, enabled: r.enabled === true };
@@ -3848,6 +3852,7 @@ var defaults = (dataDir) => ({
3848
3852
  alexa: sanitizeAlexa({}),
3849
3853
  music: sanitizeMusic({}),
3850
3854
  chrome: sanitizeChrome({}),
3855
+ pcs: sanitizePcs({}),
3851
3856
  video: sanitizeVideo({}),
3852
3857
  browser: sanitizeBrowser({}),
3853
3858
  hud: sanitizeHud({}),
@@ -3932,6 +3937,7 @@ function loadConfig(dataDir = defaultDataDir()) {
3932
3937
  alexa: sanitizeAlexa(stored.alexa),
3933
3938
  music: sanitizeMusic(stored.music),
3934
3939
  chrome: sanitizeChrome(stored.chrome),
3940
+ pcs: sanitizePcs(stored.pcs),
3935
3941
  video: sanitizeVideo(stored.video),
3936
3942
  browser: sanitizeBrowser(stored.browser),
3937
3943
  hud: sanitizeHud(stored.hud),
@@ -7398,7 +7404,7 @@ function authorPlugin(plugins, scratchRoot, spec) {
7398
7404
  }
7399
7405
 
7400
7406
  // ../server/src/integrations.ts
7401
- var INTEGRATION_IDS = ["telegram", "twilio", "zerodha", "alexa", "spotify", "soundcloud", "audius", "browser", "tavily", "chrome", "video"];
7407
+ var INTEGRATION_IDS = ["telegram", "twilio", "zerodha", "alexa", "spotify", "soundcloud", "audius", "browser", "tavily", "chrome", "windows-pcs", "video"];
7402
7408
  var isIntegrationId = (id2) => typeof id2 === "string" && INTEGRATION_IDS.includes(id2);
7403
7409
  var META = {
7404
7410
  telegram: { name: "Telegram", description: "Talk to Friend from your phone through Telegram, and let it message people for you. Needs a free bot token from @BotFather." },
@@ -7408,6 +7414,7 @@ var META = {
7408
7414
  soundcloud: { name: "SoundCloud", description: "Play and search your own SoundCloud account from Friend: ask for a track or an artist. Sign-in is through SoundCloud's own page. Needs a free app of your own at soundcloud.com/you/apps (SoundCloud decides who gets one), and some tracks only play with the right SoundCloud plan." },
7409
7415
  audius: { name: "Audius", description: "Free music from Audius, an open music service: ask for a track or an artist. No account, no key and no payment: install it and switch it on. Mostly independent artists." },
7410
7416
  chrome: { name: "Chrome control", description: "Lets Friend open pages, read them, click and type in your own Chrome, through an extension. It comes with Friend: nothing else to install. Every action still asks for your approval, and while it is on, Friend can act as you on the sites it allows." },
7417
+ "windows-pcs": { name: "Windows PCs", description: "Lets Friend use your Windows PCs like a person: see the screen, click, type, open apps, run commands and work in a terminal such as Claude Code. Add as many PCs as you want. Each one runs a small agent that you install with one line (nothing of Friend is installed on it), and you choose what it may do. Anything that cannot be undone asks you first." },
7411
7418
  video: { name: "Web video", description: "Play videos from YouTube and almost any video site, on your Friend screen or in a window on this PC: ask for a video by name or give a link. Uses the free programs yt-dlp and ffmpeg (and mpv for a PC window), which you install once; nothing is downloaded to your disk." },
7412
7419
  tavily: { name: "Tavily search", description: 'Better web search for Friend: news and finance searches, "this week" filters and site filters, built for assistants. Needs your own Tavily API key (tavily.com has a free monthly allowance; check their current limits). The key stays on this PC and is never shown to the AI. Without it, or when switched off, Friend keeps its free search.' },
7413
7420
  browser: { name: "Safe browser", description: "Lets Friend open a public web page in a private Chrome of its own, to read pages that need scripts and to see how a page looks. It starts fresh each time with no cookies or logins, cannot open addresses on this PC or your network, and is deleted afterwards. It does not try to get past logins, paywalls or bot checks. Uses the Chrome or Edge already on this PC; nothing to download." },
@@ -7423,10 +7430,11 @@ var PUBLIC_SETTINGS = {
7423
7430
  audius: [],
7424
7431
  chrome: [],
7425
7432
  video: [],
7433
+ "windows-pcs": [],
7426
7434
  tavily: [],
7427
7435
  browser: []
7428
7436
  };
7429
- function integrationViews(config, hub, brokers, alexa, spotify, soundcloud, audius, chrome, video, browser) {
7437
+ function integrationViews(config, hub, brokers, alexa, spotify, soundcloud, audius, chrome, video, browser, pcs) {
7430
7438
  const status2 = hub.status();
7431
7439
  const t = config.channels.telegram;
7432
7440
  const w = config.channels.twilio;
@@ -7474,6 +7482,20 @@ function integrationViews(config, hub, brokers, alexa, spotify, soundcloud, audi
7474
7482
  if (chs.extension === "connected") return { state: "online", detail: "Connected to your Chrome. Every action still asks for your approval." };
7475
7483
  return { state: "online", detail: "Running. Check that the extension is switched on in Chrome (click its icon)." };
7476
7484
  };
7485
+ const pc2 = config.pcs ?? { installed: false, enabled: false };
7486
+ const pcn = pcs?.counts() ?? { total: 0, online: 0 };
7487
+ const pcSteps = [
7488
+ { text: "Switch the plugin on.", done: pc2.enabled },
7489
+ { text: "Press Configure, then Add a PC: copy the one line it shows into PowerShell on that PC.", done: pcn.total > 0 },
7490
+ { text: "Approve the PC on the page that opens there, and choose what it may do. It then stays connected by itself.", done: pcn.online > 0 }
7491
+ ];
7492
+ const pcState = () => {
7493
+ if (!pc2.installed) return { state: "not-installed", detail: "" };
7494
+ if (!pc2.enabled) return { state: "off", detail: "Switched off: the assistant cannot use your PCs." };
7495
+ if (pcn.total === 0) return { state: "needs-setup", detail: "No PC yet. Press Configure, then Add a PC." };
7496
+ if (pcn.online === 0) return { state: "connecting", detail: `${pcn.total} PC${pcn.total === 1 ? "" : "s"}, none online right now.` };
7497
+ return { state: "online", detail: `${pcn.online} of ${pcn.total} PC${pcn.total === 1 ? "" : "s"} online. Use a PC by asking Friend; a control session starts only with your approval.` };
7498
+ };
7477
7499
  const vd = config.video;
7478
7500
  const vs = video?.status();
7479
7501
  const vdMpvWindow = vd.output === "host" && !!vs?.mpv.found;
@@ -7629,6 +7651,7 @@ function integrationViews(config, hub, brokers, alexa, spotify, soundcloud, audi
7629
7651
  { id: "browser", ...META.browser, kind: "integration", installed: bw.installed, enabled: bw.enabled, ...bwState(), steps: bwSteps, settings: { chrome: bwFound ?? "", chromePath: bw.chromePath, timeoutSec: String(bw.timeoutSec), maxChars: String(bw.maxChars) }, secrets: {} },
7630
7652
  { id: "tavily", ...META.tavily, kind: "integration", installed: tv.installed, enabled: tv.enabled, ...tvState(), steps: tvSteps, settings: { depth: tv.depth, maxResults: String(tv.maxResults) }, secrets: { apiKey: tvKey } },
7631
7653
  { id: "chrome", ...META.chrome, kind: "integration", installed: ch.installed, enabled: ch.enabled, ...chState(), steps: chSteps, settings: chs?.extensionFolder ? { extensionFolder: chs.extensionFolder } : {}, secrets: {} },
7654
+ { id: "windows-pcs", ...META["windows-pcs"], kind: "integration", installed: pc2.installed, enabled: pc2.enabled, ...pcState(), steps: pcSteps, settings: {}, secrets: {} },
7632
7655
  { id: "video", ...META.video, kind: "integration", installed: vd.installed, enabled: vd.enabled, ...vdState(), steps: vdSteps, settings: {}, secrets: {} }
7633
7656
  ];
7634
7657
  }
@@ -7762,6 +7785,19 @@ function changeVideo(video, change) {
7762
7785
  video.enabled = change.enabled;
7763
7786
  return null;
7764
7787
  }
7788
+ function changePcs(pcs, change) {
7789
+ if ("install" in change) {
7790
+ pcs.installed = true;
7791
+ return null;
7792
+ }
7793
+ if ("remove" in change) {
7794
+ Object.assign(pcs, { installed: false, enabled: false });
7795
+ return null;
7796
+ }
7797
+ if (!pcs.installed) return `${META["windows-pcs"].name} is not installed yet.`;
7798
+ pcs.enabled = change.enabled;
7799
+ return null;
7800
+ }
7765
7801
  function changeChrome(chrome, change, helper) {
7766
7802
  if ("install" in change) {
7767
7803
  chrome.installed = true;
@@ -21796,6 +21832,7 @@ function createGateway(deps) {
21796
21832
  const session = token2 ? auth.resolveSession(token2) : null;
21797
21833
  if (!session) return reply.code(401).send({ error: "Unauthorized" });
21798
21834
  if (!pcWindow.allow(String(session.id))) return reply.code(429).header("retry-after", 10).send({ error: "Too many requests" });
21835
+ if (!config.pcs.installed) return reply.code(409).send({ error: "Windows PCs is not installed. Install it in Plugins first." });
21799
21836
  reply.header("cache-control", "no-store");
21800
21837
  }
21801
21838
  });
@@ -24940,6 +24977,11 @@ var PcStore = class {
24940
24977
  this.db.prepare("delete from pc_tokens where pc_id = ?").run(id2);
24941
24978
  return this.db.prepare("update pcs set revoked = 1 where id = ?").run(id2).changes > 0;
24942
24979
  }
24980
+ /** Lets a revoked PC sign in again (with a new enrollment). Its name and permissions stay as they were; its old tokens are already gone. */
24981
+ restore(id2) {
24982
+ this.db.prepare("delete from pc_tokens where pc_id = ?").run(id2);
24983
+ return this.db.prepare("update pcs set revoked = 0, status_json = '' where id = ?").run(id2).changes > 0;
24984
+ }
24943
24985
  remove(id2) {
24944
24986
  return this.db.prepare("delete from pcs where id = ?").run(id2).changes > 0;
24945
24987
  }
@@ -24992,9 +25034,10 @@ var PcService = class {
24992
25034
  async reissue(id2, pin, ip) {
24993
25035
  await this.pin(pin, ip);
24994
25036
  const pc2 = this.store.get(id2);
24995
- if (!pc2 || pc2.revoked) throw new HttpError(404, "There is no such PC.");
25037
+ if (!pc2) throw new HttpError(404, "There is no such PC.");
25038
+ if (pc2.revoked) this.store.restore(id2);
24996
25039
  const enrollmentId = this.store.newEnrollment(id2);
24997
- this.deps.audit.log("owner", "pc.reissued", { pc: pc2.name, ip });
25040
+ this.deps.audit.log("owner", pc2.revoked ? "pc.readded" : "pc.reissued", { pc: pc2.name, ip });
24998
25041
  return { enrollmentId };
24999
25042
  }
25000
25043
  start(input, ip) {
@@ -25328,6 +25371,7 @@ var PcTools = class {
25328
25371
  prepare(name, args) {
25329
25372
  const { hub, store: store2 } = this.deps;
25330
25373
  const a = args ?? {};
25374
+ if (this.deps.enabled && !this.deps.enabled()) return { error: "The Windows PCs plugin is not switched on. Ask the owner to install it and switch it on in Plugins (Windows PCs)." };
25331
25375
  if (name === "pc.list") return { pcName: "", tier: "T1", run: async () => ({ text: this.list(), isError: false }) };
25332
25376
  const which = hub.resolve(typeof a.pc === "string" ? a.pc : void 0);
25333
25377
  if ("ask" in which) return { error: which.ask };
@@ -26083,7 +26127,7 @@ function currentSelf() {
26083
26127
  // ../server/src/system/npm.ts
26084
26128
  import { spawn as spawn10 } from "node:child_process";
26085
26129
  var PACKAGE = "friend-assistant";
26086
- var runningVersion = () => true ? "0.1.97" : "development";
26130
+ var runningVersion = () => true ? "0.1.99" : "development";
26087
26131
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
26088
26132
  try {
26089
26133
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -27230,6 +27274,20 @@ async function createApp(opts) {
27230
27274
  saveConfig(saved);
27231
27275
  return null;
27232
27276
  };
27277
+ const pcCounts = {
27278
+ counts: () => {
27279
+ const all = pcService.store.list().filter((p) => !p.revoked);
27280
+ return { total: all.length, online: all.filter((p) => pcHub.isOnline(p.id)).length };
27281
+ }
27282
+ };
27283
+ const changePcsConfig = (fn) => {
27284
+ const saved = loadConfig(opts.dataDir);
27285
+ const err = fn(saved.pcs);
27286
+ if (err) return err;
27287
+ fn(config.pcs);
27288
+ saveConfig(saved);
27289
+ return null;
27290
+ };
27233
27291
  const changeChromeConfig = (fn) => {
27234
27292
  const saved = loadConfig(opts.dataDir);
27235
27293
  const err = fn(saved.chrome);
@@ -27259,6 +27317,7 @@ async function createApp(opts) {
27259
27317
  if (!err2 && "remove" in change) plugins.remove(TAVILY_SKILL);
27260
27318
  return err2;
27261
27319
  }
27320
+ if (id2 === "windows-pcs") return changePcsConfig((p) => changePcs(p, change));
27262
27321
  if (id2 === "video") {
27263
27322
  const err2 = changeVideoConfig((v) => changeVideo(v, change));
27264
27323
  if (!err2 && ("install" in change || "enabled" in change && change.enabled)) void videoHub.prepare().catch(() => {
@@ -27315,12 +27374,12 @@ async function createApp(opts) {
27315
27374
  }
27316
27375
  },
27317
27376
  integrations: {
27318
- views: () => integrationViews(config, channelHub, brokerHub, alexaHub, spotifyHub, scView, audiusHub, chromePlugin, videoHub, browserHub),
27377
+ views: () => integrationViews(config, channelHub, brokerHub, alexaHub, spotifyHub, scView, audiusHub, chromePlugin, videoHub, browserHub, pcCounts),
27319
27378
  install: (id2) => changeAny(id2, { install: true }),
27320
27379
  remove: (id2) => changeAny(id2, { remove: true }),
27321
27380
  configure: (id2, { enabled, settings }) => {
27322
- if (!(id2 === "zerodha" ? config.brokers.zerodha : id2 === "alexa" ? config.alexa : id2 === "spotify" ? config.music.spotify : id2 === "soundcloud" ? config.music.soundcloud : id2 === "audius" ? config.music.audius : id2 === "chrome" ? config.chrome : id2 === "video" ? config.video : id2 === "tavily" ? config.web.tavily : id2 === "browser" ? config.browser : config.channels[id2]).installed) return `${id2} is not installed yet. Install it first with plugins.install.`;
27323
- if (id2 !== "zerodha" && id2 !== "alexa" && id2 !== "spotify" && id2 !== "soundcloud" && id2 !== "audius" && id2 !== "chrome" && id2 !== "video" && id2 !== "tavily" && id2 !== "browser" && Object.keys(settings).length) {
27381
+ if (!(id2 === "zerodha" ? config.brokers.zerodha : id2 === "alexa" ? config.alexa : id2 === "spotify" ? config.music.spotify : id2 === "soundcloud" ? config.music.soundcloud : id2 === "audius" ? config.music.audius : id2 === "chrome" ? config.chrome : id2 === "windows-pcs" ? config.pcs : id2 === "video" ? config.video : id2 === "tavily" ? config.web.tavily : id2 === "browser" ? config.browser : config.channels[id2]).installed) return `${id2} is not installed yet. Install it first with plugins.install.`;
27382
+ if (id2 !== "zerodha" && id2 !== "alexa" && id2 !== "spotify" && id2 !== "soundcloud" && id2 !== "audius" && id2 !== "chrome" && id2 !== "windows-pcs" && id2 !== "video" && id2 !== "tavily" && id2 !== "browser" && Object.keys(settings).length) {
27324
27383
  try {
27325
27384
  commitSettings({ channels: { [id2]: settings } }, { actor: "agent" });
27326
27385
  } catch (e) {
@@ -27606,7 +27665,7 @@ First check the work: read the whole report (office.report) and, when it changed
27606
27665
  if (b && hello.agentSha256 && hello.agentSha256 !== b.sha256) pcHub.send(pcId, { type: "update", url: "/api/pc/agent.js", sha256: b.sha256 });
27607
27666
  }
27608
27667
  });
27609
- const pcTools = new PcTools({ hub: pcHub, store: pcService.store, audit, extraPatterns: () => [] });
27668
+ const pcTools = new PcTools({ hub: pcHub, store: pcService.store, audit, extraPatterns: () => [], enabled: () => config.pcs.installed && config.pcs.enabled });
27610
27669
  const deckStore = new DeckStore(db);
27611
27670
  const presenter = new Presenter({
27612
27671
  speak: (text5) => speaker ? speaker.say(text5, (m) => broadcast(m)) : Promise.resolve(),
@@ -27717,7 +27776,7 @@ First check the work: read the whole report (office.report) and, when it changed
27717
27776
  video: videoHub,
27718
27777
  office,
27719
27778
  attachments: { read: (id2, part) => readAttachment(attachments, id2, part) },
27720
- integrations: { summary: () => integrationSummary(integrationViews(config, channelHub, brokerHub, alexaHub, spotifyHub, scView, audiusHub, chromePlugin, videoHub, browserHub)) }
27779
+ integrations: { summary: () => integrationSummary(integrationViews(config, channelHub, brokerHub, alexaHub, spotifyHub, scView, audiusHub, chromePlugin, videoHub, browserHub, pcCounts)) }
27721
27780
  });
27722
27781
  const clients = /* @__PURE__ */ new Set();
27723
27782
  const broadcast = (m) => {
@@ -27968,7 +28027,7 @@ ${task.title}`) !== null,
27968
28027
  void chromePlugin.refresh();
27969
28028
  const installed = plugins.list();
27970
28029
  const have = new Set(installed.map((p) => p.id));
27971
- return { installed, catalog: listCatalog(catalogDir).map((c) => ({ ...c, installed: have.has(c.id) })), integrations: integrationViews(config, channelHub, brokerHub, alexaHub, spotifyHub, scView, audiusHub, chromePlugin, videoHub, browserHub) };
28030
+ return { installed, catalog: listCatalog(catalogDir).map((c) => ({ ...c, installed: have.has(c.id) })), integrations: integrationViews(config, channelHub, brokerHub, alexaHub, spotifyHub, scView, audiusHub, chromePlugin, videoHub, browserHub, pcCounts) };
27972
28031
  },
27973
28032
  install: async (id2, pin, ip) => {
27974
28033
  if (isIntegrationId(id2)) {
@@ -31865,7 +31924,7 @@ import { appendFileSync } from "node:fs";
31865
31924
  import { join as join42 } from "node:path";
31866
31925
  var PACKAGE2 = "friend-assistant";
31867
31926
  var real2 = {
31868
- current: () => true ? "0.1.97" : "development",
31927
+ current: () => true ? "0.1.99" : "development",
31869
31928
  latest: () => new Promise((resolve13) => {
31870
31929
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
31871
31930
  let out = "";
@@ -32183,7 +32242,7 @@ async function run(argv, io2) {
32183
32242
  case "version":
32184
32243
  case "--version":
32185
32244
  case "-v":
32186
- io2.out(true ? "0.1.97" : "development");
32245
+ io2.out(true ? "0.1.99" : "development");
32187
32246
  return 0;
32188
32247
  case "lan":
32189
32248
  return await lanCommand(rest, io2);
@@ -30830,7 +30830,7 @@ function toTask(r) {
30830
30830
  }
30831
30831
 
30832
30832
  // ../pc-agent/src/main.ts
30833
- var VERSION = "0.1.97";
30833
+ var VERSION = "0.1.99";
30834
30834
  var TASK = "Friend PC Agent";
30835
30835
  function parse3(argv) {
30836
30836
  const out = {};
@@ -1 +1 @@
1
- a10c8838f274200580cbc404adb1fd682ad02ed9b06ba4fee9ea95bdc4ce3c4b
1
+ 978db5cd168c12eefba4a2e184b05c25116c2ed2c7d8518983cd5c7f3ca273ce
@@ -1 +1 @@
1
- import{a as e,s as t,t as n,u as r}from"./index-WRsUpXK7.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-B58dux8c.js";var c=r(t(),1),l=350,u=174,d=.25,f=2.5,p=96;function m(e){let t=n(e),r=e=>Math.round(e.y/134),i=e=>({x:r(e)===0?0:260+(r(e)-1)*l,y:Math.round(e.x/216*u)}),a=t.nodes.map(e=>({id:e.id,worker:e.worker,w:e.worker?240:150,...i(e)})),o=new Map(a.map(e=>[e.id,e])),s=t.edges.map(e=>{let t=o.get(e.from),n=o.get(e.to);return{from:e.from,to:e.to,x1:t.x+t.w,y1:t.y+70,x2:n.x,y2:n.y+70}}),c=Math.min(...a.map(e=>e.y));for(let e of a)e.y-=c;for(let e of s)e.y1-=c,e.y2-=c;return{nodes:a,edges:s,width:Math.max(...a.map(e=>e.x+e.w)),height:Math.max(...a.map(e=>e.y))+140}}var h=e=>Math.min(f,Math.max(d,e));function g(e,t){let n=h(Math.min((t.width-56)/e.width,(t.height-56)/e.height,1.25));return{k:n,x:(t.width-e.width*n)/2,y:(t.height-e.height*n)/2}}function _(e,t,n){let r=h(e.k*n),i=r/e.k;return{k:r,x:t.x-(t.x-e.x)*i,y:t.y-(t.y-e.y)*i}}function v(e,t,n){let r=t.width*e.k,i=t.height*e.k,a=Math.min(p,r),o=Math.min(p,i);return{k:e.k,x:Math.min(n.width-a,Math.max(a-r,e.x)),y:Math.min(n.height-o,Math.max(o-i,e.y))}}var y=e(),b={starting:`green`,running:`green`,waiting:`amber`,idle:`cyan`,paused:`ghost`,stopped:`ghost`,failed:`red`},x={starting:`active`,running:`active`,waiting:`warning`,idle:`success`,paused:`warning`,stopped:`warning`,failed:`error`},S={starting:`running`,running:`running`,waiting:`waiting`,idle:`idle`,paused:`idle`,stopped:`idle`,failed:`failed`},C=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),w=1.25;function T({workers:e,name:t,onWorker:n}){let r=(0,c.useRef)(null),l=(0,c.useMemo)(()=>m(e),[e]),u=(0,c.useMemo)(()=>({width:l.width,height:l.height}),[l.width,l.height]),[d,f]=(0,c.useState)({width:640,height:420}),[p,h]=(0,c.useState)(()=>g(u,d)),T=(0,c.useRef)(!1),E=(0,c.useRef)(!1),D=(0,c.useRef)(null),O=new Map(e.map(e=>[e.id,e.status])),k=(0,c.useCallback)(e=>h(v(e,u,d)),[u,d]),A=(0,c.useCallback)(()=>{T.current=!1,h(g(u,d))},[u,d]);(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();t.width>40&&t.height>40&&f({width:Math.floor(t.width),height:Math.floor(t.height)})};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,c.useEffect)(()=>{T.current||h(g(u,d))},[u,d]),(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();T.current=!0,h(e=>v(_(e,{x:t.clientX-n.left,y:t.clientY-n.top},Math.exp(-t.deltaY*.0015)),u,d))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[u,d]);let j={x:d.width/2,y:d.height/2},M=e=>{T.current=!0,k(_(p,j,e))};return(0,y.jsxs)(`div`,{className:`ob-canvas-room`,ref:r,children:[(0,y.jsx)(`div`,{className:`ob-canvas-pan`,onPointerDown:e=>{e.button===0&&(E.current=!1,D.current={x:e.clientX,y:e.clientY,vx:p.x,vy:p.y,id:e.pointerId,far:!1})},onPointerMove:e=>{let t=D.current;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;!t.far&&Math.hypot(n,r)<5||(t.far||e.currentTarget.setPointerCapture?.(t.id),t.far=!0,E.current=!0,T.current=!0,k({k:p.k,x:t.vx+n,y:t.vy+r}))},onPointerUp:e=>{D.current=null,e.currentTarget.releasePointerCapture?.(e.pointerId)},onPointerCancel:()=>D.current=null,children:(0,y.jsxs)(`div`,{className:`ob-canvas-world`,style:{width:l.width,height:l.height,transform:`translate(${p.x}px, ${p.y}px) scale(${p.k})`},children:[(0,y.jsxs)(`svg`,{className:`ob-canvas-edges`,width:l.width,height:l.height,"aria-hidden":`true`,children:[(0,y.jsx)(`defs`,{children:(0,y.jsx)(`marker`,{id:`ob-arrow`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,y.jsx)(`path`,{d:`M0 0L10 5L0 10z`,className:`ob-arrow`})})}),l.edges.map(e=>{let t=O.get(e.to),n=(e.x1+e.x2)/2;return(0,y.jsx)(`path`,{d:`M${e.x1} ${e.y1}C${n} ${e.y1} ${n} ${e.y2} ${e.x2} ${e.y2}`,markerEnd:`url(#ob-arrow)`,"data-flow":t===`running`||t===`starting`?`on`:t===`waiting`?`wait`:`off`},`${e.from}>${e.to}`)})]}),l.nodes.map(e=>{let r=e.worker;if(!r)return(0,y.jsxs)(`div`,{className:`ob-cnode ob-cnode-root`,"data-node":`friend`,style:{left:e.x,top:e.y,width:e.w,height:140},children:[(0,y.jsx)(a,{size:92,color:`cyan`,label:t.toUpperCase(),animated:!0}),(0,y.jsx)(`small`,{children:`the assistant`})]},e.id);let c=r.budget&&r.budget>0?Math.min(100,100*r.tokens/r.budget):void 0;return(0,y.jsx)(`div`,{className:`ob-cnode`,role:`button`,tabIndex:0,"data-node":e.id,"data-status":S[r.status],"aria-label":`${r.name}, ${r.title}, ${r.detail||r.status}`,style:{left:e.x,top:e.y,width:240,height:140},onClick:()=>{E.current?E.current=!1:n(e.id)},onKeyDown:t=>(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.id)),children:(0,y.jsxs)(s,{cardStyle:`SideRail`,color:b[r.status],padding:`8px 12px`,header:(0,y.jsxs)(`div`,{className:`ob-cnode-head`,children:[(0,y.jsx)(`b`,{children:r.name}),(0,y.jsx)(i,{state:x[r.status],children:r.status.toUpperCase()})]}),children:[(0,y.jsx)(o,{label:`JOB`,value:r.title}),(0,y.jsx)(o,{label:`DOING`,value:r.detail||r.status}),(0,y.jsx)(o,{label:`TOKENS`,value:C(r.tokens),...c===void 0?{}:{barPercent:c}})]})},e.id)})]})}),(0,y.jsxs)(`div`,{className:`ob-canvas-tools`,role:`toolbar`,"aria-label":`View of the team`,children:[(0,y.jsx)(`button`,{type:`button`,"aria-label":`Zoom in`,onClick:()=>M(w),children:`+`}),(0,y.jsx)(`button`,{type:`button`,"aria-label":`Zoom out`,onClick:()=>M(1/w),children:`−`}),(0,y.jsx)(`button`,{type:`button`,"aria-label":`Fit the team`,onClick:A,children:`⤢`}),(0,y.jsxs)(`span`,{"aria-hidden":`true`,children:[Math.round(p.k*100),`%`]})]})]})}export{T as OrgCanvas};
1
+ import{a as e,s as t,t as n,u as r}from"./index-D8oZdcLi.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-DMmG6Vql.js";var c=r(t(),1),l=350,u=174,d=.25,f=2.5,p=96;function m(e){let t=n(e),r=e=>Math.round(e.y/134),i=e=>({x:r(e)===0?0:260+(r(e)-1)*l,y:Math.round(e.x/216*u)}),a=t.nodes.map(e=>({id:e.id,worker:e.worker,w:e.worker?240:150,...i(e)})),o=new Map(a.map(e=>[e.id,e])),s=t.edges.map(e=>{let t=o.get(e.from),n=o.get(e.to);return{from:e.from,to:e.to,x1:t.x+t.w,y1:t.y+70,x2:n.x,y2:n.y+70}}),c=Math.min(...a.map(e=>e.y));for(let e of a)e.y-=c;for(let e of s)e.y1-=c,e.y2-=c;return{nodes:a,edges:s,width:Math.max(...a.map(e=>e.x+e.w)),height:Math.max(...a.map(e=>e.y))+140}}var h=e=>Math.min(f,Math.max(d,e));function g(e,t){let n=h(Math.min((t.width-56)/e.width,(t.height-56)/e.height,1.25));return{k:n,x:(t.width-e.width*n)/2,y:(t.height-e.height*n)/2}}function _(e,t,n){let r=h(e.k*n),i=r/e.k;return{k:r,x:t.x-(t.x-e.x)*i,y:t.y-(t.y-e.y)*i}}function v(e,t,n){let r=t.width*e.k,i=t.height*e.k,a=Math.min(p,r),o=Math.min(p,i);return{k:e.k,x:Math.min(n.width-a,Math.max(a-r,e.x)),y:Math.min(n.height-o,Math.max(o-i,e.y))}}var y=e(),b={starting:`green`,running:`green`,waiting:`amber`,idle:`cyan`,paused:`ghost`,stopped:`ghost`,failed:`red`},x={starting:`active`,running:`active`,waiting:`warning`,idle:`success`,paused:`warning`,stopped:`warning`,failed:`error`},S={starting:`running`,running:`running`,waiting:`waiting`,idle:`idle`,paused:`idle`,stopped:`idle`,failed:`failed`},C=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e),w=1.25;function T({workers:e,name:t,onWorker:n}){let r=(0,c.useRef)(null),l=(0,c.useMemo)(()=>m(e),[e]),u=(0,c.useMemo)(()=>({width:l.width,height:l.height}),[l.width,l.height]),[d,f]=(0,c.useState)({width:640,height:420}),[p,h]=(0,c.useState)(()=>g(u,d)),T=(0,c.useRef)(!1),E=(0,c.useRef)(!1),D=(0,c.useRef)(null),O=new Map(e.map(e=>[e.id,e.status])),k=(0,c.useCallback)(e=>h(v(e,u,d)),[u,d]),A=(0,c.useCallback)(()=>{T.current=!1,h(g(u,d))},[u,d]);(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();t.width>40&&t.height>40&&f({width:Math.floor(t.width),height:Math.floor(t.height)})};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,c.useEffect)(()=>{T.current||h(g(u,d))},[u,d]),(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();T.current=!0,h(e=>v(_(e,{x:t.clientX-n.left,y:t.clientY-n.top},Math.exp(-t.deltaY*.0015)),u,d))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[u,d]);let j={x:d.width/2,y:d.height/2},M=e=>{T.current=!0,k(_(p,j,e))};return(0,y.jsxs)(`div`,{className:`ob-canvas-room`,ref:r,children:[(0,y.jsx)(`div`,{className:`ob-canvas-pan`,onPointerDown:e=>{e.button===0&&(E.current=!1,D.current={x:e.clientX,y:e.clientY,vx:p.x,vy:p.y,id:e.pointerId,far:!1})},onPointerMove:e=>{let t=D.current;if(!t)return;let n=e.clientX-t.x,r=e.clientY-t.y;!t.far&&Math.hypot(n,r)<5||(t.far||e.currentTarget.setPointerCapture?.(t.id),t.far=!0,E.current=!0,T.current=!0,k({k:p.k,x:t.vx+n,y:t.vy+r}))},onPointerUp:e=>{D.current=null,e.currentTarget.releasePointerCapture?.(e.pointerId)},onPointerCancel:()=>D.current=null,children:(0,y.jsxs)(`div`,{className:`ob-canvas-world`,style:{width:l.width,height:l.height,transform:`translate(${p.x}px, ${p.y}px) scale(${p.k})`},children:[(0,y.jsxs)(`svg`,{className:`ob-canvas-edges`,width:l.width,height:l.height,"aria-hidden":`true`,children:[(0,y.jsx)(`defs`,{children:(0,y.jsx)(`marker`,{id:`ob-arrow`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,y.jsx)(`path`,{d:`M0 0L10 5L0 10z`,className:`ob-arrow`})})}),l.edges.map(e=>{let t=O.get(e.to),n=(e.x1+e.x2)/2;return(0,y.jsx)(`path`,{d:`M${e.x1} ${e.y1}C${n} ${e.y1} ${n} ${e.y2} ${e.x2} ${e.y2}`,markerEnd:`url(#ob-arrow)`,"data-flow":t===`running`||t===`starting`?`on`:t===`waiting`?`wait`:`off`},`${e.from}>${e.to}`)})]}),l.nodes.map(e=>{let r=e.worker;if(!r)return(0,y.jsxs)(`div`,{className:`ob-cnode ob-cnode-root`,"data-node":`friend`,style:{left:e.x,top:e.y,width:e.w,height:140},children:[(0,y.jsx)(a,{size:92,color:`cyan`,label:t.toUpperCase(),animated:!0}),(0,y.jsx)(`small`,{children:`the assistant`})]},e.id);let c=r.budget&&r.budget>0?Math.min(100,100*r.tokens/r.budget):void 0;return(0,y.jsx)(`div`,{className:`ob-cnode`,role:`button`,tabIndex:0,"data-node":e.id,"data-status":S[r.status],"aria-label":`${r.name}, ${r.title}, ${r.detail||r.status}`,style:{left:e.x,top:e.y,width:240,height:140},onClick:()=>{E.current?E.current=!1:n(e.id)},onKeyDown:t=>(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.id)),children:(0,y.jsxs)(s,{cardStyle:`SideRail`,color:b[r.status],padding:`8px 12px`,header:(0,y.jsxs)(`div`,{className:`ob-cnode-head`,children:[(0,y.jsx)(`b`,{children:r.name}),(0,y.jsx)(i,{state:x[r.status],children:r.status.toUpperCase()})]}),children:[(0,y.jsx)(o,{label:`JOB`,value:r.title}),(0,y.jsx)(o,{label:`DOING`,value:r.detail||r.status}),(0,y.jsx)(o,{label:`TOKENS`,value:C(r.tokens),...c===void 0?{}:{barPercent:c}})]})},e.id)})]})}),(0,y.jsxs)(`div`,{className:`ob-canvas-tools`,role:`toolbar`,"aria-label":`View of the team`,children:[(0,y.jsx)(`button`,{type:`button`,"aria-label":`Zoom in`,onClick:()=>M(w),children:`+`}),(0,y.jsx)(`button`,{type:`button`,"aria-label":`Zoom out`,onClick:()=>M(1/w),children:`−`}),(0,y.jsx)(`button`,{type:`button`,"aria-label":`Fit the team`,onClick:A,children:`⤢`}),(0,y.jsxs)(`span`,{"aria-hidden":`true`,children:[Math.round(p.k*100),`%`]})]})]})}export{T as OrgCanvas};