friend-assistant 0.1.86 → 0.1.87

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.86",
4
- "builtAt": "2026-11-21T10:30:12.192Z"
3
+ "version": "0.1.87",
4
+ "builtAt": "2026-11-21T11:14:55.131Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -4853,7 +4853,7 @@ ${languageNote2}` : ""}`;
4853
4853
  // ../server/src/office/brief.ts
4854
4854
  var clip2 = (s, n2) => s.length > n2 ? `${s.slice(0, n2)}\u2026` : s;
4855
4855
  var SETTING = "You may change the Office settings with settings.set { office: { ... } } (the owner approves with their PIN). Lists such as projects replace the old list, so send every entry to keep.";
4856
- var HIRING = "Hiring: there is no fixed list of jobs. For each worker, decide the job that the work needs and call office.hire with a title (for example Backend engineer), instructions (a brief to a new colleague: what to build, which tools and conventions, what done looks like), capabilities (one line), the project, and manager (the name of the worker they report to; leave it out to have them report to you). Build a small team with clear reporting lines, for example a lead with a few specialists under them, and hire only who the work needs.";
4856
+ var HIRING = "Hiring: there is no fixed list of jobs. For each worker, decide the job that the work needs and call office.hire with a title (for example Backend engineer), instructions (a brief to a new colleague: what to build, which tools and conventions, what done looks like), capabilities (one line), the project, and manager (the name of the worker they report to; leave it out to have them report to you). Build a small team with clear reporting lines, for example a lead with a few specialists under them (hire the lead first, then each specialist with manager set to the lead's name), and hire only who the work needs.";
4857
4857
  var LEVEL = {
4858
4858
  low: "Autonomy is LOW: what a worker asks to do (a command, a file change) that is not on the owner's let-through list goes to the owner as a card. You do not answer it.",
4859
4859
  medium: "Autonomy is MEDIUM: the Office answers the ordinary requests of workers itself, and a dangerous one (deleting, installing, force-pushing) still goes to the owner with their PIN.",
@@ -4871,7 +4871,7 @@ function officeBrief(o) {
4871
4871
  o.projects.length ? `Projects: ${o.projects.map((p) => `${p.id} (${clip2(p.name, 40)}${p.goal ? `: ${clip2(p.goal, 120)}` : ""})`).join("; ")}.` : "There is no project yet: ask the owner which folder the work is in, or where to create one; create the folder if they say so (it asks them), then add it as a project."
4872
4872
  );
4873
4873
  lines.push(
4874
- "You run the plan: you are told when a worker finishes or is stuck. Keep going until the work is done: review the ticket, then give the next ticket to the right worker, so nobody sits idle while work remains. Workers hear each other only through you, so put what one produced into the next one's ticket, and pass a worker's report to its manager when the manager should review it. Tell the owner what happened in a sentence or two."
4874
+ "You run the plan: you are told when a worker finishes or is stuck. Keep going until the work is done: review the ticket, then give the next ticket to the right worker, so nobody sits idle while work remains. A worker who leads others hears its team's reports directly: give the lead the whole goal in one ticket and it splits the work, gives the tickets to its team itself and checks what comes back; you hear from the lead when its team is done (its closing report may arrive as a message ticket: then review the original ticket too). Do not give a lead's people their tickets yourself unless the lead is not needed. Workers with no lead hear each other only through you, so put what one produced into the next one's ticket. Tell the owner what happened in a sentence or two."
4875
4875
  );
4876
4876
  lines.push(
4877
4877
  "Skills and tools: a worker is better at its job when it has the right skills (ways of working) and tools. When you hire, call office.options to see which skills and connected tools exist and which the owner allows, and give each worker what fits its job with office.hire (skills, mcp) or later with office.equip: for a build, the planning, test-first and review skills if they are listed; a connected tool when the work needs it. Give only what helps; skills and tools are loaded for every ticket."
@@ -16915,6 +16915,17 @@ var APPROVE_SPEC = {
16915
16915
  description: "Ask Friend whether an action may run. Friend answers for its owner.",
16916
16916
  inputSchema: { type: "object", properties: { tool_name: { type: "string" }, input: { type: "object" }, tool_use_id: { type: "string" } }, required: ["tool_name", "input"] }
16917
16917
  };
16918
+ var ASSIGN_SPEC = {
16919
+ name: "assign",
16920
+ description: "Give a ticket to one of the people who report to you. Say what to do, where in the project, and what done looks like. Their report comes back to you as a message.",
16921
+ inputSchema: { type: "object", properties: { worker: { type: "string", description: "Their name" }, title: { type: "string" }, description: { type: "string" } }, required: ["worker", "title"] }
16922
+ };
16923
+ var TEAM_SPEC = {
16924
+ name: "team",
16925
+ description: "The people who report to you: their jobs, what they are good at, and what each is doing now.",
16926
+ inputSchema: { type: "object", properties: {} }
16927
+ };
16928
+ var REPORT_CHARS = 6e3;
16918
16929
  var clip9 = (s, n2) => s.length > n2 ? s.slice(0, n2) : s;
16919
16930
  function describeAction(tool, input) {
16920
16931
  if (typeof input.command === "string") return `run the shell command: ${input.command}`;
@@ -17043,7 +17054,7 @@ var Office = class {
17043
17054
  if (!this.cfg.enabled) return { ok: false, error: OFF };
17044
17055
  const worker = this.d.store.findWorker(a.worker);
17045
17056
  if (!worker) return { ok: false, error: this.noWorker(a.worker) };
17046
- const ticket = this.d.store.createTicket({ projectId: worker.projectId, title: clip9(a.title.trim(), 200), description: clip9(a.description ?? "", 4e3), requestId: currentRequest()?.requestId ?? null });
17057
+ const ticket = this.d.store.createTicket({ projectId: worker.projectId, title: clip9(a.title.trim(), 200), description: clip9(a.description ?? "", 4e3), requestId: currentRequest()?.requestId ?? null, assignedBy: a.by ?? null });
17047
17058
  this.d.store.patchTicket(ticket.id, { workerId: worker.id });
17048
17059
  this.d.audit.log("agent", "office.assign", { worker: worker.id, ticket: ticket.id });
17049
17060
  this.queue.push({ workerId: worker.id, ticketId: ticket.id });
@@ -17264,7 +17275,7 @@ var Office = class {
17264
17275
  this.d.store.patchWorker(worker.id, { status: "starting", ticketId: ticket.id, detail: "Starting", startedAt: Date.now() });
17265
17276
  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})` };
17266
17277
  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)));
17267
- run2.bridge.setTools([APPROVE_SPEC]);
17278
+ run2.bridge.setTools([APPROVE_SPEC, ...this.reportsOf(worker.id).length > 0 ? [ASSIGN_SPEC, TEAM_SPEC] : []]);
17268
17279
  this.runs.set(worker.id, run2);
17269
17280
  this.rec(run2, "worker.run", "started", worker.name, { ticket: ticket.id, title: clip9(ticket.title, 200) });
17270
17281
  this.changed();
@@ -17316,6 +17327,51 @@ var Office = class {
17316
17327
  };
17317
17328
  }
17318
17329
  /** Who the worker is, who it reports to, and what its job is: its standing brief. Workers made before jobs were kept with them fall back to their starter role. */
17330
+ /** What a lead is told about its team and its job as the lead. */
17331
+ leadBrief(w, boss) {
17332
+ const team = this.reportsOf(w.id);
17333
+ if (team.length === 0) return "";
17334
+ const people = team.map((r) => `${r.name} (${r.title || r.roleId}${r.capabilities ? `, ${r.capabilities}` : ""})`).join("; ");
17335
+ return `You lead ${team.length} ${team.length === 1 ? "person" : "people"}: ${people}. You are the lead, not the only worker: when you get a goal, split it into tickets and give each to the right person with your assign tool (the team tool shows who is free). Do not do their work yourself; do only what is no one's job. In each ticket say the goal, where in the project, and what done looks like. Then end your turn with a short note of who has what. Their reports come back to you as messages: check them, send anything wrong back with assign, and when everything is done write one report for ${boss ?? "Friend"}: what each person did, what you checked, and what is left.`;
17336
+ }
17337
+ /** The Office's own tools that a lead calls: giving a ticket to a team member, and looking at the team. */
17338
+ onTeamCall(run2, call) {
17339
+ const say2 = (text5, isError = false) => call.respond({ text: text5, ...isError ? { isError: true } : {} });
17340
+ const team = this.reportsOf(run2.workerId);
17341
+ if (run2.concluded) return say2("The worker was stopped.", true);
17342
+ if (team.length === 0) return say2("Nobody reports to you.", true);
17343
+ if (call.name === "team") {
17344
+ return say2(
17345
+ team.map((r3) => {
17346
+ const t = r3.ticketId !== null ? this.d.store.getTicket(r3.ticketId) : void 0;
17347
+ return `${r3.name} (${r3.title || r3.roleId}${r3.capabilities ? `, ${r3.capabilities}` : ""}): ${r3.status}${t ? `, working on ticket #${t.id} "${clip9(t.title, 80)}"` : ""}`;
17348
+ }).join("\n")
17349
+ );
17350
+ }
17351
+ const a = call.args ?? {};
17352
+ const ref2 = String(a.worker ?? "").trim().toLowerCase();
17353
+ const target = team.find((r3) => r3.id === ref2 || r3.name.toLowerCase() === ref2);
17354
+ if (!target) return say2(`${String(a.worker ?? "")} does not report to you. Your team: ${team.map((r3) => r3.name).join(", ")}.`, true);
17355
+ const title2 = typeof a.title === "string" ? a.title.trim() : "";
17356
+ if (!title2) return say2("Give the ticket a title.", true);
17357
+ const r = this.assign({ worker: target.id, title: title2, ...typeof a.description === "string" ? { description: a.description } : {}, by: run2.workerId });
17358
+ if (!r.ok) return say2(r.error, true);
17359
+ this.rec(run2, "ticket.assign", "done", target.name, { ticket: r.ticket.id, title: clip9(title2, 200) });
17360
+ return say2(`Ticket #${r.ticket.id} is ${r.queued ? "queued for" : "started by"} ${target.name}. Their report will come to you as a message.`);
17361
+ }
17362
+ /** The workers who report to this one. */
17363
+ reportsOf(workerId) {
17364
+ return this.d.store.listWorkers().filter((x) => x.managerId === workerId);
17365
+ }
17366
+ /** Tickets a lead gave out that are not finished. */
17367
+ outstanding(leadId) {
17368
+ return this.d.store.listTickets().filter((t) => t.assignedBy === leadId && (t.status === "todo" || t.status === "doing")).length;
17369
+ }
17370
+ /** Puts a team member's report in front of its lead: into its conversation if it is working, as a message ticket if it is idle. */
17371
+ deliver(leadId, text5) {
17372
+ const lead = this.d.store.getWorker(leadId);
17373
+ if (lead) this.say(lead.id, text5);
17374
+ }
17319
17375
  briefing(w) {
17320
17376
  const legacy = !w.title && !w.instructions ? this.cfg.roles.find((r) => r.id === w.roleId) : void 0;
17321
17377
  const title2 = w.title || legacy?.title || "worker";
@@ -17325,7 +17381,8 @@ var Office = class {
17325
17381
  `You report to ${boss ?? "Friend, the owner's assistant"}. When you are done or stuck, say so plainly in your final reply: that is how your manager hears from you.`,
17326
17382
  (w.instructions || legacy?.instructions || "").trim(),
17327
17383
  w.skills.length ? `You have skills installed (your Skill tool lists them). Before you start a kind of work, use the skill that fits it, and follow it.` : "",
17328
- w.mcp.length ? `You also have tools from connected servers: ${w.mcp.join(", ")}. Use them when the ticket needs them.` : ""
17384
+ w.mcp.length ? `You also have tools from connected servers: ${w.mcp.join(", ")}. Use them when the ticket needs them.` : "",
17385
+ this.leadBrief(w, boss)
17329
17386
  ].filter((s) => s !== "").join("\n\n");
17330
17387
  }
17331
17388
  prompt(ticket, project, note, fresh = false) {
@@ -17391,7 +17448,9 @@ Goal: ${project.goal}` : ""}`,
17391
17448
  }
17392
17449
  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 });
17393
17450
  run2.answered++;
17394
- const message = isMessage(this.d.store.getTicket(run2.ticketId));
17451
+ const own = this.d.store.getTicket(run2.ticketId);
17452
+ const message = isMessage(own);
17453
+ const delegated = !!own?.assignedBy;
17395
17454
  if (ev.ok && !message && !run2.nudged && run2.proc && run2.answered >= run2.sent && run2.report.length < MIN_REPORT_CHARS) {
17396
17455
  run2.nudged = true;
17397
17456
  run2.sent++;
@@ -17403,7 +17462,7 @@ Goal: ${project.goal}` : ""}`,
17403
17462
  const worker = this.d.store.getWorker(run2.workerId);
17404
17463
  const over = this.budgetReason(worker);
17405
17464
  if (over) this.conclude(run2, { worker: "stopped", ticket: "blocked", feed: { kind: "error", text: over } });
17406
- else this.conclude(run2, { worker: "idle", ticket: ev.ok ? message ? "done" : "review" : "blocked", ...ev.ok && message ? { reply: true } : {} });
17465
+ else this.conclude(run2, { worker: "idle", ticket: ev.ok ? message || delegated ? "done" : "review" : "blocked", ...ev.ok && message ? { reply: true } : {} });
17407
17466
  }
17408
17467
  onExit(run2, x) {
17409
17468
  if (run2.concluded) return;
@@ -17421,6 +17480,13 @@ Goal: ${project.goal}` : ""}`,
17421
17480
  if (o.ticket) this.rec(run2, "ticket.status", o.ticket === "blocked" ? "failed" : "done", `#${run2.ticketId}`, { ticket: run2.ticketId, status: o.ticket });
17422
17481
  this.rec(run2, "worker.run", o.worker === "idle" ? "done" : o.worker === "stopped" ? "refused" : "failed", run2.label, { status: o.worker, ticketStatus: o.ticket, ...o.feed ? { reason: o.feed.text } : {} });
17423
17482
  if (o.feed) this.feed(run2.workerId, o.feed.kind, o.feed.text);
17483
+ const given = this.d.store.getTicket(run2.ticketId);
17484
+ const handedOver = !!given?.assignedBy && (o.ticket === "done" || o.ticket === "blocked");
17485
+ if (handedOver && !this.down) {
17486
+ const who = this.d.store.getWorker(run2.workerId)?.name ?? "a worker";
17487
+ this.deliver(given.assignedBy, `Report from ${who} on ticket #${given.id} "${clip9(given.title, 120)}" (${o.ticket === "done" ? "finished" : "could not finish"}):
17488
+ ${(run2.report || o.feed?.text || "").slice(0, REPORT_CHARS)}`);
17489
+ }
17424
17490
  this.d.approvals.denyWhere((r) => r.args?.workerId === run2.workerId, "The worker was stopped.");
17425
17491
  this.d.assistant?.cancelWorker(run2.workerId);
17426
17492
  try {
@@ -17431,7 +17497,8 @@ Goal: ${project.goal}` : ""}`,
17431
17497
  });
17432
17498
  const held = this.ctx.get(run2.workerId);
17433
17499
  const pct3 = held !== void 0 && this.cfg.context.warnAt > 0 && held / this.cfg.context.window >= this.cfg.context.warnAt ? Math.round(held / this.cfg.context.window * 100) : null;
17434
- if ((o.ticket === "review" || o.ticket === "blocked" || o.reply) && this.cfg.notifyFriend && !this.down) {
17500
+ const teamBusy = o.ticket !== "blocked" && this.outstanding(run2.workerId) > 0;
17501
+ if ((o.ticket === "review" || o.ticket === "blocked" || o.reply) && this.cfg.notifyFriend && !this.down && !handedOver && !teamBusy) {
17435
17502
  const ticket = this.d.store.getTicket(run2.ticketId);
17436
17503
  const worker = this.d.store.getWorker(run2.workerId);
17437
17504
  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 || "", ...pct3 !== null ? { contextPct: pct3 } : {} });
@@ -17455,6 +17522,7 @@ Goal: ${project.goal}` : ""}`,
17455
17522
  // ---- the questions a worker asks ----
17456
17523
  async onCall(run2, call) {
17457
17524
  const answer = (v) => call.respond({ text: JSON.stringify(v) });
17525
+ if (call.name === "assign" || call.name === "team") return this.onTeamCall(run2, call);
17458
17526
  if (call.name !== "approve") return call.respond({ text: `Error: there is no tool ${call.name}.`, isError: true });
17459
17527
  const a = call.args ?? {};
17460
17528
  if (typeof a.tool_name !== "string" || !a.input || typeof a.input !== "object" || Array.isArray(a.input)) return answer({ behavior: "deny", message: "That question was not understood." });
@@ -17465,6 +17533,11 @@ Goal: ${project.goal}` : ""}`,
17465
17533
  const worker = this.d.store.getWorker(run2.workerId);
17466
17534
  const project = worker && this.cfg.projects.find((p) => p.id === worker.projectId);
17467
17535
  if (!worker || !project) return answer({ behavior: "deny", message: "The project of this worker no longer exists." });
17536
+ if (tool === "mcp__office__assign" || tool === "mcp__office__team") {
17537
+ if (this.reportsOf(worker.id).length === 0) return answer({ behavior: "deny", message: "Nobody reports to you." });
17538
+ this.d.audit.log("agent", "office.approval", { worker: worker.id, tool, verdict: "allow", by: "lead" });
17539
+ return answer({ behavior: "allow", updatedInput: input });
17540
+ }
17468
17541
  if (tool === "Skill" && worker.skills.length > 0) {
17469
17542
  this.d.audit.log("agent", "office.approval", { worker: worker.id, tool, verdict: "allow", by: "skills" });
17470
17543
  return answer({ behavior: "allow", updatedInput: input });
@@ -17604,7 +17677,7 @@ var idList = (s) => {
17604
17677
  }
17605
17678
  };
17606
17679
  var toWorker = (r) => ({ id: r.id, name: r.name, roleId: r.role_id, projectId: r.project_id, status: r.status, sessionId: r.session_id, ticketId: r.ticket_id, detail: r.detail, tokens: r.tokens, createdAt: r.created_at, startedAt: r.started_at, title: r.title, capabilities: r.capabilities, instructions: r.instructions, model: r.model, permission: r.permission, managerId: r.manager_id, skills: idList(r.skills), mcp: idList(r.mcp) });
17607
- var toTicket = (r) => ({ id: r.id, projectId: r.project_id, title: r.title, description: r.description, status: r.status, workerId: r.worker_id, report: r.report, requestId: r.request_id, createdAt: r.created_at, updatedAt: r.updated_at });
17680
+ var toTicket = (r) => ({ id: r.id, projectId: r.project_id, title: r.title, description: r.description, status: r.status, workerId: r.worker_id, report: r.report, requestId: r.request_id, assignedBy: r.assigned_by ?? null, createdAt: r.created_at, updatedAt: r.updated_at });
17608
17681
  var WORKER_COLUMNS = { status: "status", sessionId: "session_id", ticketId: "ticket_id", detail: "detail", startedAt: "started_at" };
17609
17682
  var TICKET_COLUMNS = { status: "status", workerId: "worker_id", report: "report" };
17610
17683
  var MAX_REPORT_CHARS = 2e4;
@@ -17653,7 +17726,7 @@ var OfficeStore = class {
17653
17726
  }
17654
17727
  createTicket(t) {
17655
17728
  const now = this.now();
17656
- const r = this.db.prepare("insert into office_tickets (project_id, title, description, request_id, created_at, updated_at) values (?, ?, ?, ?, ?, ?)").run(t.projectId, t.title, t.description, t.requestId ?? null, now, now);
17729
+ const r = this.db.prepare("insert into office_tickets (project_id, title, description, request_id, assigned_by, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?)").run(t.projectId, t.title, t.description, t.requestId ?? null, t.assignedBy ?? null, now, now);
17657
17730
  return this.getTicket(Number(r.lastInsertRowid));
17658
17731
  }
17659
17732
  getTicket(id2) {
@@ -18052,6 +18125,10 @@ create index person_faces_person on person_faces (person_id);`
18052
18125
  id: 19,
18053
18126
  sql: `alter table office_workers add column skills text not null default '[]';
18054
18127
  alter table office_workers add column mcp text not null default '[]';`
18128
+ },
18129
+ {
18130
+ id: 20,
18131
+ sql: `alter table office_tickets add column assigned_by text;`
18055
18132
  }
18056
18133
  ];
18057
18134
 
@@ -22576,7 +22653,7 @@ function currentSelf() {
22576
22653
  // ../server/src/system/npm.ts
22577
22654
  import { spawn as spawn10 } from "node:child_process";
22578
22655
  var PACKAGE = "friend-assistant";
22579
- var runningVersion = () => true ? "0.1.86" : "development";
22656
+ var runningVersion = () => true ? "0.1.87" : "development";
22580
22657
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
22581
22658
  try {
22582
22659
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -27966,7 +28043,7 @@ import { appendFileSync } from "node:fs";
27966
28043
  import { join as join40 } from "node:path";
27967
28044
  var PACKAGE2 = "friend-assistant";
27968
28045
  var real2 = {
27969
- current: () => true ? "0.1.86" : "development",
28046
+ current: () => true ? "0.1.87" : "development",
27970
28047
  latest: () => new Promise((resolve13) => {
27971
28048
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
27972
28049
  let out = "";
@@ -28284,7 +28361,7 @@ async function run(argv, io2) {
28284
28361
  case "version":
28285
28362
  case "--version":
28286
28363
  case "-v":
28287
- io2.out(true ? "0.1.86" : "development");
28364
+ io2.out(true ? "0.1.87" : "development");
28288
28365
  return 0;
28289
28366
  case "lan":
28290
28367
  return await lanCommand(rest, io2);
@@ -1 +1 @@
1
- import{i as e,l as t,o as n,t as r}from"./index-4Huw9zYx.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-EHVJAVdI.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-B5NSWZ8b.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-kkfaAmBP.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};