friend-assistant 0.1.82 → 0.1.84

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.82",
4
- "builtAt": "2026-11-08T04:47:47.792Z"
3
+ "version": "0.1.84",
4
+ "builtAt": "2026-11-08T13:02:27.505Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -1717,6 +1717,13 @@ var TOOL_DEFS = [
1717
1717
  baseTier: "T1",
1718
1718
  target: "gateway"
1719
1719
  },
1720
+ {
1721
+ name: "office.close",
1722
+ description: "Close a ticket nobody needs to review any more (stale, replaced, or only a message that was answered). It is marked done with your reason. A ticket a worker is working on must be stopped first (office.stop).",
1723
+ input: z5.object({ ticket: z5.number().int(), reason: z5.string().min(1).max(300) }),
1724
+ baseTier: "T1",
1725
+ target: "gateway"
1726
+ },
1720
1727
  {
1721
1728
  name: "office.fire",
1722
1729
  description: "Remove a worker from the Office when it is no longer needed. It is stopped, the workers who reported to it now report to its manager, and its finished tickets stay. The owner is asked.",
@@ -2004,6 +2011,8 @@ ${visible(String(t.code ?? ""))}`);
2004
2011
  return `${a.accept ? "Accept" : "Send back"} ticket #${visible(String(a.ticket ?? ""))}`;
2005
2012
  case "office.action":
2006
2013
  return `Worker ${visible(String(a.worker ?? ""))} wants to ${visible(String(a.summary ?? ""))}`;
2014
+ case "office.close":
2015
+ return `Close ticket #${visible(String(a.ticket ?? ""))}`;
2007
2016
  case "office.fire":
2008
2017
  return `Remove the worker ${visible(String(a.worker ?? ""))} from the Office`;
2009
2018
  case "office.stop":
@@ -4328,6 +4337,14 @@ var StageState = class {
4328
4337
  return [...this.panels];
4329
4338
  }
4330
4339
  };
4340
+ function composeSummary(r) {
4341
+ const where = r.show.map((o) => `${o.id} (${o.docked ? "chip" : o.layer === "overlay" ? "note" : o.role ?? "card"})`);
4342
+ const parts = [`Shown: ${where.join(", ")}.`];
4343
+ if (r.dock.length) parts.push(`Put away as chips: ${r.dock.join(", ")}.`);
4344
+ if (r.hide.length) parts.push(`Removed: ${r.hide.join(", ")}.`);
4345
+ parts.push(...r.notes);
4346
+ return parts;
4347
+ }
4331
4348
  function runStageTool(name, args, stage, emit) {
4332
4349
  if (name === "stage.guide") {
4333
4350
  const topic = args?.topic;
@@ -4341,13 +4358,7 @@ function runStageTool(name, args, stage, emit) {
4341
4358
  const done = stage.compose(items, mode ?? "replace");
4342
4359
  if (!done.ok) return { ok: false, error: done.error };
4343
4360
  for (const command2 of done.commands) emit({ type: "stage", command: command2 });
4344
- const r = done.result;
4345
- const where = r.show.map((o) => `${o.id} (${o.docked ? "chip" : o.layer === "overlay" ? "note" : o.role ?? "card"})`);
4346
- const parts = [`Shown: ${where.join(", ")}.`];
4347
- if (r.dock.length) parts.push(`Put away as chips: ${r.dock.join(", ")}.`);
4348
- if (r.hide.length) parts.push(`Removed: ${r.hide.join(", ")}.`);
4349
- parts.push(...r.notes);
4350
- return { ok: true, output: `ok. ${parts.join(" ")}`, truncated: false };
4361
+ return { ok: true, output: `ok. ${composeSummary(done.result).join(" ")}`, truncated: false };
4351
4362
  }
4352
4363
  const def = TOOL_DEFS.find((t) => t.name === name && t.target === "gateway");
4353
4364
  if (!def) return { ok: false, error: `Unknown stage tool: ${name}` };
@@ -4369,6 +4380,13 @@ function runStageTool(name, args, stage, emit) {
4369
4380
  }
4370
4381
  if (command.cmd === "show" && command.object.layer === "overlay" && !command.object.pinned) {
4371
4382
  command = { cmd: "show", object: { ...command.object, placement: "center" } };
4383
+ } else if (command.cmd === "show" && stage.snapshot().objects.some((o) => o.role !== void 0) && !command.object.pinned) {
4384
+ const o = command.object;
4385
+ const role = stage.snapshot().objects.find((x) => x.id === o.id)?.role ?? "beside";
4386
+ const done = stage.compose([{ id: o.id, type: o.type, props: o.props, role, ...o.label ? { label: o.label } : {}, ...o.ttl !== void 0 ? { ttl: o.ttl } : {} }], "add");
4387
+ if (!done.ok) return { ok: false, error: done.error };
4388
+ for (const c of done.commands) emit({ type: "stage", command: c });
4389
+ return { ok: true, output: `ok. This screen is laid out by screen.compose, so "${o.id}" was placed for you as ${role} and the place you gave was not used. To change the layout call screen.compose again. ${composeSummary(done.result).join(" ")}`, truncated: false };
4372
4390
  } else if (command.cmd === "show") {
4373
4391
  const placed = placeObject(command.object, stage.snapshot().objects, stage.openPanels(), stage.screenInfo());
4374
4392
  command = { cmd: "show", object: placed.object };
@@ -4809,7 +4827,7 @@ var LEVEL = {
4809
4827
  };
4810
4828
  function officeBrief(o) {
4811
4829
  if (!o.enabled) return `The Office (hired workers) is off. If the owner wants workers, turn it on with settings.set { office: { enabled: true } } (the owner approves with their PIN), then set up a project.`;
4812
- const lines = ["The Office: you can hire workers (separate Claude sessions) to do work in the owner's project folders (office.hire, office.assign, office.say, office.review, office.report (read a worker's whole report), office.fire (remove a worker who is no longer needed), office.stop, office.status)."];
4830
+ const lines = ["The Office: you can hire workers (separate Claude sessions) to do work in the owner's project folders (office.hire, office.assign, office.say, office.review, office.report (read a worker's whole report), office.close (close a stale or answered ticket with a reason), office.fire (remove a worker who is no longer needed), office.stop, office.status)."];
4813
4831
  lines.push(HIRING);
4814
4832
  if (o.roles.length) lines.push(`Starter roles you may use instead of describing a job yourself: ${o.roles.map((r) => `${r.id} (${clip2(r.title, 40)})`).join(", ")}.`);
4815
4833
  lines.push(
@@ -4876,6 +4894,10 @@ ${body.slice(0, 2e4)}
4876
4894
  const r = office.review(Number(args.ticket), args.accept === true, args.note ? String(args.note) : void 0);
4877
4895
  return r.ok ? ok(args.accept === true ? "Accepted." : "Sent back.") : fail(r.error ?? "Could not review the ticket.");
4878
4896
  }
4897
+ case "office.close": {
4898
+ const r = office.close(Number(args.ticket), String(args.reason ?? ""));
4899
+ return r.ok ? ok(`Ticket #${Number(args.ticket)} is closed.`) : fail(r.error ?? "Could not close the ticket.");
4900
+ }
4879
4901
  case "office.fire": {
4880
4902
  const r = office.fire(String(args.worker), "agent");
4881
4903
  return r.ok ? ok(`${r.name} was removed from the Office.`) : fail(r.error);
@@ -5453,7 +5475,8 @@ ${r.text}` };
5453
5475
  if (call.name === "shell.run") tier = classifyShell(String(args.command), d.config.destructivePatterns);
5454
5476
  const p = pathArg(call.name, args);
5455
5477
  const unpointed = call.name === "web.read" && typeof args.url === "string" && !this.seenUrls.has(normalUrl(args.url)) || call.name === "plugins.fetch" && !this.namedRepo(String(args.url ?? ""));
5456
- const insideRoots = (p === void 0 ? true : lexicalInsideRoots(p, d.config.roots)) && !unpointed;
5478
+ const officeRoots = def.readOnly && d.config.office.enabled ? d.config.office.projects.flatMap((pr) => [pr.folder, ...pr.extraFolders]) : [];
5479
+ const insideRoots = (p === void 0 ? true : lexicalInsideRoots(p, [...d.config.roots, ...officeRoots])) && !unpointed;
5457
5480
  const protectedPath = p !== void 0 && lexicalInsideRoots(p, [d.config.dataDir]);
5458
5481
  let decision = d.policy.decide({ tool: call.name, baseTier: tier, args, trust: ctx.trust, insideRoots, protectedPath });
5459
5482
  if (decision === "ask" && d.eyeGate && LOOK_TOOLS.has(call.name)) {
@@ -16549,6 +16572,24 @@ function touchesProtected(p) {
16549
16572
  const parts = p.toLowerCase().split(/[\\/]+/).filter(Boolean);
16550
16573
  return parts.some((s) => PROTECTED_DIRS.has(s)) || parts.at(-1) === ".mcp.json";
16551
16574
  }
16575
+ var READ_ONLY_COMMANDS = /* @__PURE__ */ new Set(["ls", "dir", "pwd", "cat", "type", "head", "tail", "wc", "grep", "rg", "tree", "stat", "file", "du", "which", "where", "whoami", "date", "get-childitem", "get-content", "get-location", "select-string", "get-item", "test-path", "ffprobe"]);
16576
+ var READ_ONLY_GIT = /* @__PURE__ */ new Set(["status", "log", "diff", "show", "ls-files", "rev-parse", "blame"]);
16577
+ var RUNS_OR_WRITES = /^(--pre|--output|--ext-diff|--exec|-exec|-delete|-o$|-out|-c$)/i;
16578
+ function readOnlyShell(command, folders) {
16579
+ if (!isSimpleCommand(command.trim())) return false;
16580
+ const words = command.trim().split(/\s+/);
16581
+ const first3 = (words[0] ?? "").replace(/\.exe$/i, "").toLowerCase();
16582
+ const rest = words.slice(1).map((w) => w.replace(/^["']|["']$/g, ""));
16583
+ if (first3 === "git") {
16584
+ if (!READ_ONLY_GIT.has((rest[0] ?? "").toLowerCase())) return false;
16585
+ } else if (!READ_ONLY_COMMANDS.has(first3)) return false;
16586
+ for (const w of rest) {
16587
+ if (RUNS_OR_WRITES.test(w)) return false;
16588
+ if (/^[~%]/.test(w) || /(^|[\\/])\.\.([\\/]|$)/.test(w)) return false;
16589
+ if (/^([a-zA-Z]:|[\\/])/.test(w) && (!plainAbsolute(w) || !lexicalInsideRoots(w, folders))) return false;
16590
+ }
16591
+ return true;
16592
+ }
16552
16593
  function decideAction(call, ctx) {
16553
16594
  const input = call.input && typeof call.input === "object" ? call.input : {};
16554
16595
  for (const field of PATH_FIELDS) {
@@ -16567,6 +16608,7 @@ function decideAction(call, ctx) {
16567
16608
  }
16568
16609
  }
16569
16610
  }
16611
+ if (command !== null && readOnlyShell(command, ctx.folders)) return { verdict: "allow" };
16570
16612
  const danger = command !== null && classifyShell(command, ctx.shellPatterns) === "T3";
16571
16613
  if (ctx.policy.allowTools.includes(call.tool) && !danger) return { verdict: "allow" };
16572
16614
  return { verdict: "ask", danger };
@@ -16710,6 +16752,9 @@ var OFF = "The Office is switched off in Settings.";
16710
16752
  var STATE_EVERY_MS = 200;
16711
16753
  var DETAIL_CHARS = 80;
16712
16754
  var FEED_CHARS = 200;
16755
+ var MIN_REPORT_CHARS = 40;
16756
+ var FULLER_REPORT = "Your report was too short for your manager to check. Reply again with what you did, which files you changed or made, and what you checked.";
16757
+ var isMessage = (t) => !!t && t.title.startsWith("Message: ");
16713
16758
  var APPROVE_SPEC = {
16714
16759
  name: "approve",
16715
16760
  description: "Ask Friend whether an action may run. Friend answers for its owner.",
@@ -16826,6 +16871,7 @@ var Office = class {
16826
16871
  review(ticketId, accept, note) {
16827
16872
  const t = this.d.store.getTicket(ticketId);
16828
16873
  if (!t) return { ok: false, error: `There is no ticket #${ticketId}.` };
16874
+ if (t.status === "done" && accept) return { ok: true };
16829
16875
  if (t.status !== "review") return { ok: false, error: `Ticket #${ticketId} is not waiting for review (it is ${t.status}).` };
16830
16876
  this.d.audit.log("agent", "office.review", { ticket: ticketId, accept });
16831
16877
  if (accept) {
@@ -16838,6 +16884,22 @@ var Office = class {
16838
16884
  this.changed();
16839
16885
  return { ok: true };
16840
16886
  }
16887
+ /** Closes a ticket nobody needs to review (stale, replaced, a message): done, with the reason kept in its report. */
16888
+ close(ticketId, reason) {
16889
+ const t = this.d.store.getTicket(ticketId);
16890
+ if (!t) return { ok: false, error: `There is no ticket #${ticketId}.` };
16891
+ if (t.status === "done") return { ok: true };
16892
+ if (t.status === "doing") return { ok: false, error: `Ticket #${ticketId} is being worked on. Stop the worker first (office.stop), then close it.` };
16893
+ const why = reason.trim().slice(0, 300);
16894
+ if (!why) return { ok: false, error: "Give a reason for closing the ticket." };
16895
+ this.queue = this.queue.filter((e) => e.ticketId !== ticketId);
16896
+ this.d.store.patchTicket(ticketId, { status: "done", report: `${t.report ? `${t.report}
16897
+
16898
+ ` : ""}Closed: ${why}` });
16899
+ this.d.audit.log("agent", "office.close", { ticket: ticketId, reason: why });
16900
+ this.changed();
16901
+ return { ok: true };
16902
+ }
16841
16903
  /** Stops one worker, or every worker when none is named. */
16842
16904
  stop(workerRef, by = "agent") {
16843
16905
  let targets;
@@ -16979,7 +17041,7 @@ var Office = class {
16979
17041
  }
16980
17042
  this.d.store.patchTicket(ticket.id, { status: "doing", workerId: worker.id });
16981
17043
  this.d.store.patchWorker(worker.id, { status: "starting", ticketId: ticket.id, detail: "Starting", startedAt: Date.now() });
16982
- const run2 = { workerId: worker.id, ticketId: ticket.id, proc: null, bridge: null, startTimer: null, spoke: false, pending: 0, concluded: false, report: "", sent: 1, answered: 0, requestId: newRequestId("run"), parentRequestId: ticket.requestId, label: `${worker.name} (${worker.id})` };
17044
+ const run2 = { workerId: worker.id, ticketId: ticket.id, proc: null, bridge: null, startTimer: null, spoke: false, pending: 0, concluded: false, report: "", sent: 1, answered: 0, nudged: false, requestId: newRequestId("run"), parentRequestId: ticket.requestId, label: `${worker.name} (${worker.id})` };
16983
17045
  run2.bridge = this.makeBridge((call) => void runWithRequest({ prefix: "run", requestId: run2.requestId, parentId: run2.parentRequestId, actorKind: "worker", actorId: `${worker.name} (${worker.id})` }, () => this.onCall(run2, call)));
16984
17046
  run2.bridge.setTools([APPROVE_SPEC]);
16985
17047
  this.runs.set(worker.id, run2);
@@ -17079,11 +17141,19 @@ Goal: ${project.goal}` : ""}`,
17079
17141
  this.d.store.patchTicket(run2.ticketId, { report: ev.text.trim() || run2.report });
17080
17142
  this.rec(run2, "ticket.report", ev.ok ? "done" : "failed", `#${run2.ticketId}`, { ticket: run2.ticketId, report: ev.text.trim() || run2.report, turns: ev.turns, tokens: ev.input + ev.output });
17081
17143
  run2.answered++;
17144
+ const message = isMessage(this.d.store.getTicket(run2.ticketId));
17145
+ if (ev.ok && !message && !run2.nudged && run2.proc && run2.answered >= run2.sent && run2.report.length < MIN_REPORT_CHARS) {
17146
+ run2.nudged = true;
17147
+ run2.sent++;
17148
+ run2.proc.send(FULLER_REPORT);
17149
+ this.feed(run2.workerId, "text", "Asked for a fuller report.");
17150
+ return;
17151
+ }
17082
17152
  if (run2.answered < run2.sent && ev.ok) return;
17083
17153
  const worker = this.d.store.getWorker(run2.workerId);
17084
17154
  const over = this.budgetReason(worker);
17085
17155
  if (over) this.conclude(run2, { worker: "stopped", ticket: "blocked", feed: { kind: "error", text: over } });
17086
- else this.conclude(run2, { worker: "idle", ticket: ev.ok ? "review" : "blocked" });
17156
+ else this.conclude(run2, { worker: "idle", ticket: ev.ok ? message ? "done" : "review" : "blocked", ...ev.ok && message ? { reply: true } : {} });
17087
17157
  }
17088
17158
  onExit(run2, x) {
17089
17159
  if (run2.concluded) return;
@@ -17109,10 +17179,10 @@ Goal: ${project.goal}` : ""}`,
17109
17179
  }
17110
17180
  void run2.bridge.stop().catch(() => {
17111
17181
  });
17112
- if ((o.ticket === "review" || o.ticket === "blocked") && this.cfg.notifyFriend && !this.down) {
17182
+ if ((o.ticket === "review" || o.ticket === "blocked" || o.reply) && this.cfg.notifyFriend && !this.down) {
17113
17183
  const ticket = this.d.store.getTicket(run2.ticketId);
17114
17184
  const worker = this.d.store.getWorker(run2.workerId);
17115
- if (ticket && worker) this.d.notify?.({ worker: worker.name, jobTitle: worker.title, manager: worker.managerId ? this.d.store.getWorker(worker.managerId)?.name ?? null : null, ticketId: ticket.id, title: ticket.title, status: o.ticket, report: run2.report || o.feed?.text || "" });
17185
+ if (ticket && worker) this.d.notify?.({ worker: worker.name, jobTitle: worker.title, manager: worker.managerId ? this.d.store.getWorker(worker.managerId)?.name ?? null : null, ticketId: ticket.id, title: ticket.title, status: o.ticket === "blocked" ? "blocked" : "review", report: run2.report || o.feed?.text || "" });
17116
17186
  }
17117
17187
  this.changed();
17118
17188
  this.pump();
@@ -22221,7 +22291,7 @@ function currentSelf() {
22221
22291
  // ../server/src/system/npm.ts
22222
22292
  import { spawn as spawn10 } from "node:child_process";
22223
22293
  var PACKAGE = "friend-assistant";
22224
- var runningVersion = () => true ? "0.1.82" : "development";
22294
+ var runningVersion = () => true ? "0.1.84" : "development";
22225
22295
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
22226
22296
  try {
22227
22297
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -27600,7 +27670,7 @@ import { appendFileSync } from "node:fs";
27600
27670
  import { join as join39 } from "node:path";
27601
27671
  var PACKAGE2 = "friend-assistant";
27602
27672
  var real2 = {
27603
- current: () => true ? "0.1.82" : "development",
27673
+ current: () => true ? "0.1.84" : "development",
27604
27674
  latest: () => new Promise((resolve13) => {
27605
27675
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
27606
27676
  let out = "";
@@ -27918,7 +27988,7 @@ async function run(argv, io2) {
27918
27988
  case "version":
27919
27989
  case "--version":
27920
27990
  case "-v":
27921
- io2.out(true ? "0.1.82" : "development");
27991
+ io2.out(true ? "0.1.84" : "development");
27922
27992
  return 0;
27923
27993
  case "lan":
27924
27994
  return await lanCommand(rest, io2);
@@ -1 +1 @@
1
- import{i as e,l as t,o as n,t as r}from"./index-Cs0cYyfP.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-CdoaKiS6.js";var c=t(n(),1),l=350,u=174,d=.25,f=2.5,p=96;function m(e){let t=r(e),n=e=>Math.round(e.y/134),i=e=>({x:n(e)===0?0:260+(n(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{i as e,l as t,o as n,t as r}from"./index-Cr-p_FMH.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-Dx5ynYrM.js";var c=t(n(),1),l=350,u=174,d=.25,f=2.5,p=96;function m(e){let t=r(e),n=e=>Math.round(e.y/134),i=e=>({x:n(e)===0?0:260+(n(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};