friend-assistant 0.1.114 → 0.1.115

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/BUILD.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "friend-assistant",
3
- "version": "0.1.114",
4
- "builtAt": "2026-11-28T10:35:02.208Z"
3
+ "version": "0.1.115",
4
+ "builtAt": "2026-11-28T11:06:01.736Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -1310,10 +1310,10 @@ var MEETING_TOOL_DEFS = [
1310
1310
  def3("meeting.people", "Who is in the meeting you are in now, and who is speaking this moment, by the names the meeting shows.", z8.object({ id: id.optional() }), "T1", true),
1311
1311
  def3(
1312
1312
  "meeting.present",
1313
- "Share the screen of the meeting you are in to show something: slides you write yourself (slides: title and short lines each, three to eight slides), or a picture or film from a file on this PC (file: .png .jpg .gif .webp .mp4 .webm). The meeting sees a stage of its own, never the real screen. With slide next or back it turns the slides; with stop it stops sharing. Only when the owner asked for it.",
1313
+ "Share the screen of the meeting you are in to show something: slides you write yourself (slides: title and short lines each, three to eight slides; give each slide a say, two to four spoken sentences, and you talk through the slides aloud, turning to the next slide when you finish each one, so what is shown and what is said stay together), or a picture or film from a file on this PC (file: .png .jpg .gif .webp .mp4 .webm). The meeting sees a stage of its own, never the real screen. With slide next or back it turns the slides; with stop it stops sharing. Only when the owner asked for it.",
1314
1314
  z8.object({
1315
1315
  id: id.optional(),
1316
- slides: z8.array(z8.object({ title: z8.string().min(1).max(120), lines: z8.array(z8.string().min(1).max(200)).max(8).optional() })).min(1).max(20).optional(),
1316
+ slides: z8.array(z8.object({ title: z8.string().min(1).max(120), lines: z8.array(z8.string().min(1).max(200)).max(8).optional(), say: z8.string().min(1).max(400).optional() })).min(1).max(20).optional(),
1317
1317
  file: z8.string().min(1).max(500).optional(),
1318
1318
  slide: z8.enum(["next", "back"]).optional(),
1319
1319
  stop: z8.boolean().optional()
@@ -4852,7 +4852,7 @@ ${msgs.slice(-last).map((m) => `${m.sender}: ${m.text}`).join("\n")}` : "Nobody
4852
4852
  if (a.slide) return await service.flip(id3, a.slide === "next" ? 1 : -1) ? ok(`Turned to the ${a.slide} slide.`) : bad("No slides are being shown.");
4853
4853
  const slides = a.slides;
4854
4854
  if (slides?.length) {
4855
- const r = await service.present(id3, { kind: "slides", slides: slides.map((s) => ({ title: s.title, ...s.lines ? { lines: s.lines } : {} })) });
4855
+ const r = await service.present(id3, { kind: "slides", slides: slides.map((s) => ({ title: s.title, ...s.lines ? { lines: s.lines } : {}, ...s.say ? { say: s.say } : {} })) });
4856
4856
  return r.ok ? ok(r.message) : bad(r.message);
4857
4857
  }
4858
4858
  if (typeof a.file === "string") {
@@ -24284,7 +24284,7 @@ import { join as join31 } from "node:path";
24284
24284
  // ../server/src/meetings/domKit.ts
24285
24285
  var HELPERS = `
24286
24286
  const txt = (e) => ((e && (e.innerText || e.textContent)) || "").replace(/\\s+/g, " ").trim();
24287
- const vis = (e) => !!(e && (e.offsetWidth || e.offsetHeight || e.getClientRects().length));
24287
+ const vis = (e) => { if (!e || !(e.offsetWidth || e.offsetHeight || e.getClientRects().length)) return false; const r = e.getBoundingClientRect(); return r.right > 0 && r.bottom > 0 && r.left < innerWidth && getComputedStyle(e).visibility !== "hidden"; };
24288
24288
  const all = (sel) => Array.from(document.querySelectorAll(sel)).filter(vis);
24289
24289
  const label = (e) => (e.getAttribute("aria-label") || "") + " " + txt(e);
24290
24290
  const CLICKABLE = "button, [role=button], a, [role=menuitem], [role=menuitemcheckbox], [role=menuitemradio], [role=option]";
@@ -24316,11 +24316,15 @@ var camTo = (on) => `(() => { ${HELPERS}
24316
24316
  if (OFF.test(label(btn)) === ${on}) btn.click();
24317
24317
  return true;
24318
24318
  })()`;
24319
- var SEND_CHAT = (boxSel, sendSel) => `(() => { ${HELPERS}
24319
+ var SEND_CHAT = (boxSel, sendSel) => `(async () => { ${HELPERS}
24320
24320
  const box = all(${JSON.stringify(boxSel)})[0];
24321
24321
  if (!box || !((box.value !== undefined ? box.value : txt(box)) || "").trim()) return true;
24322
24322
  const send = all(${JSON.stringify(sendSel)})[0] || byText(/^\\s*send\\b/i, "button, [role=button]");
24323
24323
  if (!send) return false;
24324
+ // a plain click is what works in Teams (a real mouse press on its send button does nothing); if the box is not empty after it, the mouse is tried
24325
+ send.click();
24326
+ await new Promise((r) => setTimeout(r, 700));
24327
+ if (!((box.value !== undefined ? box.value : txt(box)) || "").trim()) return true;
24324
24328
  const b = send.getBoundingClientRect();
24325
24329
  return { x: b.x + b.width / 2, y: b.y + b.height / 2 };
24326
24330
  })()`;
@@ -24423,7 +24427,20 @@ var CAPTIONS = `(() => { ${HELPERS}
24423
24427
  });
24424
24428
  return { on: true, items };
24425
24429
  })()`;
24426
- var OPEN_MORE = `(() => { ${HELPERS} const b = document.querySelector('[data-tid="more-button"], #callingButtons-showMoreBtn, [id*="showMoreBtn"]') || byText(/^\\s*more( actions)?\\b/i, "button, [role=button]"); if (!b) return false; const r = b.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; })()`;
24430
+ var CAPTION_QUICK = `(async () => { ${HELPERS}
24431
+ const item = () => { const i = document.getElementById("closed-captions-button"); return i && vis(i) ? i : null; };
24432
+ let i = item();
24433
+ if (!i) {
24434
+ const b = document.querySelector('[data-tid="more-button"], #callingButtons-showMoreBtn, [id*="showMoreBtn"]');
24435
+ if (!b) return false;
24436
+ b.click();
24437
+ for (let k = 0; k < 8 && !(i = item()); k++) await new Promise((r) => setTimeout(r, 150));
24438
+ }
24439
+ if (!i) return false;
24440
+ if (i.getAttribute("aria-checked") !== "true") i.click();
24441
+ return true;
24442
+ })()`;
24443
+ var OPEN_MORE = `(async () => { ${HELPERS} const menuUp = () => vis(document.getElementById("closed-captions-button")) || !!byText(/language and speech|^\\s*captions\\b/i, "[role=menuitem], [role=menuitemcheckbox]"); if (menuUp()) return true; const b = document.querySelector('[data-tid="more-button"], #callingButtons-showMoreBtn, [id*="showMoreBtn"]') || byText(/^\\s*more( actions)?\\b/i, "button, [role=button]"); if (!b) return false; b.click(); await new Promise((r) => setTimeout(r, 700)); if (menuUp()) return true; const r = b.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; })()`;
24427
24444
  var CLICK_CAPTIONS_ITEM = `(() => { ${HELPERS} const b = document.getElementById("closed-captions-button") || byText(/^\\s*captions\\b/i, "[role=menuitem], [role=menuitemcheckbox]"); if (!b) return false; if (b.getAttribute("aria-checked") !== "true") b.click(); return true; })()`;
24428
24445
  var CLICK_LANGUAGE = `(() => { ${HELPERS} const b = byText(/language and speech/i); if (!b) return false; b.click(); return true; })()`;
24429
24446
  var CLICK_CAPTIONS = `(() => { ${HELPERS} const b = byText(/turn on live captions|show live captions|live captions/i); if (!b) return false; b.click(); return true; })()`;
@@ -24432,7 +24449,7 @@ var FOCUS_CHAT = `(() => { ${HELPERS}
24432
24449
  const box = () => all('[data-tid="ckeditor"], div[role="textbox"][contenteditable="true"], [data-tid="chat-message-input"] [contenteditable="true"]')[0];
24433
24450
  let b = box();
24434
24451
  if (!b) { const open = document.querySelector('[data-tid="chat-button"], #chat-button') || byText(/^\\s*chat\\b/i, "button, [role=button]"); if (open) open.click(); }
24435
- return new Promise((done) => setTimeout(() => { b = box(); if (!b) return done(false); b.focus(); done(true); }, 700));
24452
+ return new Promise((done) => setTimeout(() => { b = box(); if (!b) return done(false); b.focus(); done(true); }, 1200));
24436
24453
  })()`;
24437
24454
  var HANG_UP = `(() => { ${HELPERS} const b = document.querySelector('[data-tid="hangup-button"], #hangup-button') || byText(/^\\s*(leave|hang up)\\b/i, "button, [role=button]"); if (!b) return false; b.click(); return true; })()`;
24438
24455
  var READ_CHAT = `(() => { ${HELPERS}
@@ -24459,7 +24476,22 @@ var PEOPLE = `(() => { ${HELPERS}
24459
24476
  const TILE = '[data-tid*="video-tile"], [data-tid*="participant-tile"], [data-tid="calling-participant-stream"], [data-tid*="stream-container"], [data-cid*="tile"], [role="listitem"][aria-label]';
24460
24477
  const names = [];
24461
24478
  const speaking = [];
24462
- for (const el of all(TILE)) {
24479
+ // Teams today: a tile is an element with data-stream-type whose data-tid is the person's name; its ring changes its class while they speak
24480
+ // (the class names are hashes that change with every Teams build, so the idle look is learned: the one seen most often)
24481
+ const R = (window.__friendRing = window.__friendRing || {});
24482
+ for (const t of Array.from(document.querySelectorAll("[data-stream-type]"))) {
24483
+ const name = (t.getAttribute("data-tid") || "").replace(/\\s*\\((guest|external|unverified)[^)]*\\)/i, "").trim();
24484
+ if (!name || name.length > 60) continue;
24485
+ if (!names.includes(name)) names.push(name);
24486
+ const o = t.querySelector('[data-tid="voice-level-stream-outline"]');
24487
+ if (!o) continue;
24488
+ const sig = String(o.className);
24489
+ const r = (R[name] = R[name] || {});
24490
+ r[sig] = (r[sig] || 0) + 1;
24491
+ const sigs = Object.keys(r).sort((a, b) => r[b] - r[a]);
24492
+ if (sigs.length > 1 && sig !== sigs[0]) speaking.push(name);
24493
+ }
24494
+ if (!names.length) for (const el of all(TILE)) {
24463
24495
  const n = el.querySelector('[data-tid*="display-name"], [data-tid*="participant-name"], [data-tid*="name"]');
24464
24496
  let name = n ? txt(n) : (el.getAttribute("aria-label") || "").split(",")[0].trim();
24465
24497
  name = name.replace(/\\s*\\((guest|external|unverified)[^)]*\\)/i, "").trim();
@@ -24470,8 +24502,8 @@ var PEOPLE = `(() => { ${HELPERS}
24470
24502
  }
24471
24503
  return { names, speaking };
24472
24504
  })()`;
24473
- var CLICK_SHARE = `(() => { ${HELPERS} const b = document.querySelector('[data-tid="share-button"], #share-button') || byText(/^\\s*(share|present)\\b/i, "button, [role=button]"); if (!b) return false; const r = b.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; })()`;
24474
- var CLICK_SCREEN = `(() => { ${HELPERS} const b = byText(/^\\s*(screen|entire screen|share (the )?screen|present (the )?screen)\\b/i, "button, [role=button], [role=menuitem], [role=option], [data-tid*="screen"]") || document.querySelector('[data-tid*="share-screen"], [data-tid*="screen-share"]'); if (!b) return false; const r = b.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; })()`;
24505
+ var CLICK_SHARE = `(() => { ${HELPERS} const b = document.querySelector('#screenshare-button, [data-tid="screenshare-button"], [data-tid="share-button"], #share-button') || byText(/^\\s*(share|present)\\b/i, "button, [role=button]"); if (!b || !vis(b)) return false; if (!/stop (sharing|presenting)/i.test(label(b))) b.click(); return true; })()`;
24506
+ var CLICK_SCREEN = `(() => { ${HELPERS} const b = byText(/^\\s*(screen|entire screen|share (the )?screen|present (the )?screen)\\b/i, "button, [role=button], [role=menuitem], [role=option], [data-tid*="screen"]") || document.querySelector('[data-tid*="share-screen"], [data-tid*="screen-share"]'); if (!b) return false; b.click(); return true; })()`;
24475
24507
  var STOP_SHARE = `(() => { ${HELPERS} const b = document.querySelector('[data-tid="stop-sharing-button"], [data-tid="unshare-button"]') || byText(/stop (presenting|sharing)/i, "button, [role=button]"); if (!b) return false; b.click(); return true; })()`;
24476
24508
  var TEAMS = {
24477
24509
  readChat: READ_CHAT,
@@ -24480,6 +24512,7 @@ var TEAMS = {
24480
24512
  stopShare: STOP_SHARE,
24481
24513
  advance: ADVANCE,
24482
24514
  captions: CAPTIONS,
24515
+ captionQuick: CAPTION_QUICK,
24483
24516
  captionSteps: [OPEN_MORE, CLICK_CAPTIONS_ITEM, CLICK_LANGUAGE, CLICK_CAPTIONS, CLICK_CONFIRM],
24484
24517
  // Ctrl+Shift+U switches live captions on or off in Teams
24485
24518
  shortcut: { key: "U", code: "KeyU", vk: 85, modifiers: 10 },
@@ -24883,6 +24916,14 @@ var ChromeMeetingPage = class {
24883
24916
  await sleep2(800);
24884
24917
  return;
24885
24918
  }
24919
+ if (this.dom.captionQuick) {
24920
+ if (await this.run(this.dom.captionQuick).catch(() => false)) {
24921
+ await sleep2(900);
24922
+ const confirm = this.dom.captionSteps.at(-1);
24923
+ if (confirm) await this.run(confirm).catch(() => false);
24924
+ return;
24925
+ }
24926
+ }
24886
24927
  for (const [i, step] of this.dom.captionSteps.entries()) {
24887
24928
  const found = await this.run(step).catch(() => false);
24888
24929
  if (!found && i === 0) return;
@@ -24916,7 +24957,7 @@ var ChromeMeetingPage = class {
24916
24957
  async appears(text5) {
24917
24958
  const snippet = text5.replace(/\s+/g, " ").trim().slice(0, 40);
24918
24959
  const look2 = `(document.body.innerText || "").replace(/\\s+/g, " ").includes(${JSON.stringify(snippet)})`;
24919
- for (let i = 0; i < 4; i++) {
24960
+ for (let i = 0; i < 7; i++) {
24920
24961
  if (await this.run(look2).catch(() => false)) return true;
24921
24962
  if (i === 1) await this.run(this.dom.focusChat).catch(() => false);
24922
24963
  await sleep2(500);
@@ -25069,11 +25110,12 @@ var MeetingSession = class {
25069
25110
  return this.d.page.chat(text5.slice(0, 600)).catch(() => false);
25070
25111
  }
25071
25112
  /** Says it aloud in a computer voice, after the room has gone quiet; at most once every 20 seconds. */
25072
- async speak(text5) {
25113
+ async speak(text5, o = {}) {
25073
25114
  const d = this.d;
25115
+ if (!o.narration) this.narrateToken++;
25074
25116
  if (this.status !== "live") return { ok: false, message: "It is not in the meeting." };
25075
25117
  if (!d.speech || !d.page.speak || !d.page.mic) return { ok: false, message: "Speaking aloud is not switched on here." };
25076
- if (this.now() - this.lastSpoke < 6e3) return { ok: false, message: "It spoke a moment ago: wait a few seconds between spoken answers." };
25118
+ if (!o.narration && this.now() - this.lastSpoke < 6e3) return { ok: false, message: "It spoke a moment ago: wait a few seconds between spoken answers." };
25077
25119
  this.lastSpoke = this.now();
25078
25120
  const t02 = Date.now();
25079
25121
  const quietFor = () => d.hearing && this.audioMode ? Date.now() - d.hearing.lastVoiceAt : this.now() - this.lastHeard;
@@ -25262,7 +25304,28 @@ var MeetingSession = class {
25262
25304
  async present(c) {
25263
25305
  if (this.status !== "live") return { ok: false, message: "It is not in the meeting." };
25264
25306
  if (!this.d.page.present) return { ok: false, message: "This meeting page cannot share a screen." };
25265
- return this.d.page.present(c);
25307
+ this.narrateToken++;
25308
+ const r = await this.d.page.present(c);
25309
+ if (!r.ok || c.kind !== "slides" || !c.slides.some((s) => s.say)) return r;
25310
+ if (!this.d.speech || !this.d.page.speak) return { ok: true, message: `${r.message} Speaking aloud is not switched on, so the slides are shown without talking.` };
25311
+ void this.narrate(c.slides.map((s) => s.say));
25312
+ return { ok: true, message: `${r.message} It is talking through the ${c.slides.length} slides, turning to the next when each is told. Anyone who speaks to it stops the talk.` };
25313
+ }
25314
+ narrateToken = 0;
25315
+ /** Says what goes with each slide, and turns to the next slide when it has been said, so what is shown and what is heard stay together. */
25316
+ async narrate(says) {
25317
+ const token2 = ++this.narrateToken;
25318
+ const going = () => token2 === this.narrateToken && this.status === "live";
25319
+ for (let i = 0; i < says.length && going(); i++) {
25320
+ const say2 = says[i];
25321
+ if (say2) {
25322
+ const r = await this.speak(say2, { narration: true });
25323
+ if (!r.ok) return;
25324
+ } else await this.sleep(4e3);
25325
+ if (!going()) return;
25326
+ await this.sleep(500);
25327
+ if (i < says.length - 1) await this.d.page.flip?.(1).catch(() => false);
25328
+ }
25266
25329
  }
25267
25330
  /** The chat as it is on the screen now. */
25268
25331
  async chatNow() {
@@ -25276,6 +25339,7 @@ var MeetingSession = class {
25276
25339
  return await this.d.page.flip?.(by).catch(() => false) === true;
25277
25340
  }
25278
25341
  async stopPresenting() {
25342
+ this.narrateToken++;
25279
25343
  return await this.d.page.stopPresenting?.().catch(() => false) === true;
25280
25344
  }
25281
25345
  take(lines) {
@@ -29879,7 +29943,7 @@ function currentSelf() {
29879
29943
  // ../server/src/system/npm.ts
29880
29944
  import { spawn as spawn11 } from "node:child_process";
29881
29945
  var PACKAGE = "friend-assistant";
29882
- var runningVersion = () => true ? "0.1.114" : "development";
29946
+ var runningVersion = () => true ? "0.1.115" : "development";
29883
29947
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
29884
29948
  try {
29885
29949
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -35904,7 +35968,7 @@ import { appendFileSync } from "node:fs";
35904
35968
  import { join as join44 } from "node:path";
35905
35969
  var PACKAGE2 = "friend-assistant";
35906
35970
  var real2 = {
35907
- current: () => true ? "0.1.114" : "development",
35971
+ current: () => true ? "0.1.115" : "development",
35908
35972
  latest: () => new Promise((resolve13) => {
35909
35973
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
35910
35974
  let out = "";
@@ -36222,7 +36286,7 @@ async function run2(argv, io2) {
36222
36286
  case "version":
36223
36287
  case "--version":
36224
36288
  case "-v":
36225
- io2.out(true ? "0.1.114" : "development");
36289
+ io2.out(true ? "0.1.115" : "development");
36226
36290
  return 0;
36227
36291
  case "lan":
36228
36292
  return await lanCommand(rest, io2);
@@ -27526,10 +27526,10 @@ var MEETING_TOOL_DEFS = [
27526
27526
  def3("meeting.people", "Who is in the meeting you are in now, and who is speaking this moment, by the names the meeting shows.", external_exports.object({ id: id.optional() }), "T1", true),
27527
27527
  def3(
27528
27528
  "meeting.present",
27529
- "Share the screen of the meeting you are in to show something: slides you write yourself (slides: title and short lines each, three to eight slides), or a picture or film from a file on this PC (file: .png .jpg .gif .webp .mp4 .webm). The meeting sees a stage of its own, never the real screen. With slide next or back it turns the slides; with stop it stops sharing. Only when the owner asked for it.",
27529
+ "Share the screen of the meeting you are in to show something: slides you write yourself (slides: title and short lines each, three to eight slides; give each slide a say, two to four spoken sentences, and you talk through the slides aloud, turning to the next slide when you finish each one, so what is shown and what is said stay together), or a picture or film from a file on this PC (file: .png .jpg .gif .webp .mp4 .webm). The meeting sees a stage of its own, never the real screen. With slide next or back it turns the slides; with stop it stops sharing. Only when the owner asked for it.",
27530
27530
  external_exports.object({
27531
27531
  id: id.optional(),
27532
- slides: external_exports.array(external_exports.object({ title: external_exports.string().min(1).max(120), lines: external_exports.array(external_exports.string().min(1).max(200)).max(8).optional() })).min(1).max(20).optional(),
27532
+ slides: external_exports.array(external_exports.object({ title: external_exports.string().min(1).max(120), lines: external_exports.array(external_exports.string().min(1).max(200)).max(8).optional(), say: external_exports.string().min(1).max(400).optional() })).min(1).max(20).optional(),
27533
27533
  file: external_exports.string().min(1).max(500).optional(),
27534
27534
  slide: external_exports.enum(["next", "back"]).optional(),
27535
27535
  stop: external_exports.boolean().optional()
@@ -31053,7 +31053,7 @@ Write-Output ('changed: ' + ($did -join ','))`;
31053
31053
  }
31054
31054
 
31055
31055
  // ../pc-agent/src/main.ts
31056
- var VERSION = "0.1.114";
31056
+ var VERSION = "0.1.115";
31057
31057
  var TASK2 = "Friend PC Agent";
31058
31058
  function parse3(argv) {
31059
31059
  const out = {};
@@ -1 +1 @@
1
- 0a59770e748049257a9c671ea67fb1f3403a73e991ea54639269a3c1a8aa255b
1
+ 4edf7d25c832d7e8b82f549240523fed1254cbdee266886691f95f4ff539205d
@@ -1 +1 @@
1
- import{a as e,s as t,t as n,u as r}from"./index-B2UuujIL.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-1psO1lab.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-CKKwdWc2.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-BqX3s-j7.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};