friend-assistant 0.1.83 → 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.83",
4
- "builtAt": "2026-11-08T06:17:28.978Z"
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":
@@ -4818,7 +4827,7 @@ var LEVEL = {
4818
4827
  };
4819
4828
  function officeBrief(o) {
4820
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.`;
4821
- 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)."];
4822
4831
  lines.push(HIRING);
4823
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(", ")}.`);
4824
4833
  lines.push(
@@ -4885,6 +4894,10 @@ ${body.slice(0, 2e4)}
4885
4894
  const r = office.review(Number(args.ticket), args.accept === true, args.note ? String(args.note) : void 0);
4886
4895
  return r.ok ? ok(args.accept === true ? "Accepted." : "Sent back.") : fail(r.error ?? "Could not review the ticket.");
4887
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
+ }
4888
4901
  case "office.fire": {
4889
4902
  const r = office.fire(String(args.worker), "agent");
4890
4903
  return r.ok ? ok(`${r.name} was removed from the Office.`) : fail(r.error);
@@ -5462,7 +5475,8 @@ ${r.text}` };
5462
5475
  if (call.name === "shell.run") tier = classifyShell(String(args.command), d.config.destructivePatterns);
5463
5476
  const p = pathArg(call.name, args);
5464
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 ?? ""));
5465
- 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;
5466
5480
  const protectedPath = p !== void 0 && lexicalInsideRoots(p, [d.config.dataDir]);
5467
5481
  let decision = d.policy.decide({ tool: call.name, baseTier: tier, args, trust: ctx.trust, insideRoots, protectedPath });
5468
5482
  if (decision === "ask" && d.eyeGate && LOOK_TOOLS.has(call.name)) {
@@ -16558,6 +16572,24 @@ function touchesProtected(p) {
16558
16572
  const parts = p.toLowerCase().split(/[\\/]+/).filter(Boolean);
16559
16573
  return parts.some((s) => PROTECTED_DIRS.has(s)) || parts.at(-1) === ".mcp.json";
16560
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
+ }
16561
16593
  function decideAction(call, ctx) {
16562
16594
  const input = call.input && typeof call.input === "object" ? call.input : {};
16563
16595
  for (const field of PATH_FIELDS) {
@@ -16576,6 +16608,7 @@ function decideAction(call, ctx) {
16576
16608
  }
16577
16609
  }
16578
16610
  }
16611
+ if (command !== null && readOnlyShell(command, ctx.folders)) return { verdict: "allow" };
16579
16612
  const danger = command !== null && classifyShell(command, ctx.shellPatterns) === "T3";
16580
16613
  if (ctx.policy.allowTools.includes(call.tool) && !danger) return { verdict: "allow" };
16581
16614
  return { verdict: "ask", danger };
@@ -16719,6 +16752,9 @@ var OFF = "The Office is switched off in Settings.";
16719
16752
  var STATE_EVERY_MS = 200;
16720
16753
  var DETAIL_CHARS = 80;
16721
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: ");
16722
16758
  var APPROVE_SPEC = {
16723
16759
  name: "approve",
16724
16760
  description: "Ask Friend whether an action may run. Friend answers for its owner.",
@@ -16835,6 +16871,7 @@ var Office = class {
16835
16871
  review(ticketId, accept, note) {
16836
16872
  const t = this.d.store.getTicket(ticketId);
16837
16873
  if (!t) return { ok: false, error: `There is no ticket #${ticketId}.` };
16874
+ if (t.status === "done" && accept) return { ok: true };
16838
16875
  if (t.status !== "review") return { ok: false, error: `Ticket #${ticketId} is not waiting for review (it is ${t.status}).` };
16839
16876
  this.d.audit.log("agent", "office.review", { ticket: ticketId, accept });
16840
16877
  if (accept) {
@@ -16847,6 +16884,22 @@ var Office = class {
16847
16884
  this.changed();
16848
16885
  return { ok: true };
16849
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
+ }
16850
16903
  /** Stops one worker, or every worker when none is named. */
16851
16904
  stop(workerRef, by = "agent") {
16852
16905
  let targets;
@@ -16988,7 +17041,7 @@ var Office = class {
16988
17041
  }
16989
17042
  this.d.store.patchTicket(ticket.id, { status: "doing", workerId: worker.id });
16990
17043
  this.d.store.patchWorker(worker.id, { status: "starting", ticketId: ticket.id, detail: "Starting", startedAt: Date.now() });
16991
- 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})` };
16992
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)));
16993
17046
  run2.bridge.setTools([APPROVE_SPEC]);
16994
17047
  this.runs.set(worker.id, run2);
@@ -17088,11 +17141,19 @@ Goal: ${project.goal}` : ""}`,
17088
17141
  this.d.store.patchTicket(run2.ticketId, { report: ev.text.trim() || run2.report });
17089
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 });
17090
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
+ }
17091
17152
  if (run2.answered < run2.sent && ev.ok) return;
17092
17153
  const worker = this.d.store.getWorker(run2.workerId);
17093
17154
  const over = this.budgetReason(worker);
17094
17155
  if (over) this.conclude(run2, { worker: "stopped", ticket: "blocked", feed: { kind: "error", text: over } });
17095
- 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 } : {} });
17096
17157
  }
17097
17158
  onExit(run2, x) {
17098
17159
  if (run2.concluded) return;
@@ -17118,10 +17179,10 @@ Goal: ${project.goal}` : ""}`,
17118
17179
  }
17119
17180
  void run2.bridge.stop().catch(() => {
17120
17181
  });
17121
- 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) {
17122
17183
  const ticket = this.d.store.getTicket(run2.ticketId);
17123
17184
  const worker = this.d.store.getWorker(run2.workerId);
17124
- 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 || "" });
17125
17186
  }
17126
17187
  this.changed();
17127
17188
  this.pump();
@@ -22230,7 +22291,7 @@ function currentSelf() {
22230
22291
  // ../server/src/system/npm.ts
22231
22292
  import { spawn as spawn10 } from "node:child_process";
22232
22293
  var PACKAGE = "friend-assistant";
22233
- var runningVersion = () => true ? "0.1.83" : "development";
22294
+ var runningVersion = () => true ? "0.1.84" : "development";
22234
22295
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
22235
22296
  try {
22236
22297
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -27609,7 +27670,7 @@ import { appendFileSync } from "node:fs";
27609
27670
  import { join as join39 } from "node:path";
27610
27671
  var PACKAGE2 = "friend-assistant";
27611
27672
  var real2 = {
27612
- current: () => true ? "0.1.83" : "development",
27673
+ current: () => true ? "0.1.84" : "development",
27613
27674
  latest: () => new Promise((resolve13) => {
27614
27675
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
27615
27676
  let out = "";
@@ -27927,7 +27988,7 @@ async function run(argv, io2) {
27927
27988
  case "version":
27928
27989
  case "--version":
27929
27990
  case "-v":
27930
- io2.out(true ? "0.1.83" : "development");
27991
+ io2.out(true ? "0.1.84" : "development");
27931
27992
  return 0;
27932
27993
  case "lan":
27933
27994
  return await lanCommand(rest, io2);
@@ -1 +1 @@
1
- import{i as e,l as t,o as n,t as r}from"./index-BBjRJqRf.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-BVWkQCG6.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};