friend-assistant 0.1.80 → 0.1.81

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.80",
4
- "builtAt": "2026-11-08T03:26:58.321Z"
3
+ "version": "0.1.81",
4
+ "builtAt": "2026-11-08T04:26:08.870Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -382,6 +382,7 @@ var INSTRUMENT_RECTS = {
382
382
  var CONFLICT = 0.25;
383
383
  var MIN_FOCUS_W = 40;
384
384
  var MIN_TABLET_FOCUS_W = 30;
385
+ var MIN_SLOT_H = 16;
385
386
  var DESKTOP = {
386
387
  focus: [26, 16, 48, 52],
387
388
  big: [14, 15, 72, 60],
@@ -397,6 +398,17 @@ var clampChips = (n2) => Math.min(12, Math.max(1, Math.round(n2)));
397
398
  function zonesFor(screen, taken = { panels: [], instruments: [] }, maxChips) {
398
399
  const all = [...taken.panels, ...taken.instruments];
399
400
  const free = (r) => !all.some((t) => overlap(r, t) > CONFLICT);
401
+ const fitSlot = (r) => {
402
+ let h = r[3];
403
+ for (const t of all) {
404
+ const across = t[0] < r[0] + r[2] && t[0] + t[2] > r[0];
405
+ if (!across || t[1] >= r[1] + h || t[1] + t[3] <= r[1]) continue;
406
+ if (t[1] <= r[1]) return null;
407
+ h = Math.min(h, t[1] - 1 - r[1]);
408
+ }
409
+ return h >= MIN_SLOT_H ? [r[0], r[1], r[2], Math.round(h * 100) / 100] : null;
410
+ };
411
+ const fitted = (slots) => slots.map(fitSlot).filter((r) => r !== null);
400
412
  const kind = screen?.kind ?? "desktop";
401
413
  const chips = (byKind) => maxChips === void 0 ? byKind : clampChips(maxChips);
402
414
  if (kind === "phone") return { focus: PHONE.focus, focusBig: PHONE.big, beside: [], chipMax: chips(5), stack: true };
@@ -413,15 +425,16 @@ function zonesFor(screen, taken = { panels: [], instruments: [] }, maxChips) {
413
425
  const hi2 = Math.min(r[0] + r[2], right - 1);
414
426
  return hi2 - lo2 >= MIN_TABLET_FOCUS_W ? [Math.round(lo2 * 100) / 100, r[1], Math.round((hi2 - lo2) * 100) / 100, r[3]] : r;
415
427
  };
416
- return { focus: fit(TABLET.focus), focusBig: fit(TABLET.big), beside: TABLET.slots.filter(free), chipMax: chips(5), stack: false };
428
+ return { focus: fit(TABLET.focus), focusBig: fit(TABLET.big), beside: fitted(TABLET.slots), chipMax: chips(5), stack: false };
417
429
  }
418
- const beside = DESKTOP.slots.filter(free);
430
+ const beside = fitted(DESKTOP.slots);
431
+ const slotOpen = (i) => fitSlot(DESKTOP.slots[i]) !== null;
419
432
  const [fx, fy, fw, fh] = DESKTOP.focus;
420
433
  const band = all.filter((t) => t[1] < fy + fh && t[1] + t[3] > fy);
421
434
  const leftEdge = Math.max(-Infinity, ...band.filter((t) => t[0] + t[2] / 2 < 50).map((t) => t[0] + t[2]));
422
435
  const rightEdge = Math.min(Infinity, ...band.filter((t) => t[0] + t[2] / 2 >= 50).map((t) => t[0]));
423
- const leftOpen = free(DESKTOP.slots[1]);
424
- const rightOpen = free(DESKTOP.slots[0]) || free(DESKTOP.slots[2]);
436
+ const leftOpen = slotOpen(1);
437
+ const rightOpen = slotOpen(0) || slotOpen(2);
425
438
  let lo = Math.max(leftOpen ? fx : DESKTOP.big[0], leftEdge + 1);
426
439
  let hi = Math.min(rightOpen ? fx + fw : DESKTOP.big[0] + DESKTOP.big[2], rightEdge - 1);
427
440
  if (hi - lo < MIN_FOCUS_W) {
@@ -1553,7 +1566,7 @@ var TOOL_DEFS = [
1553
1566
  },
1554
1567
  {
1555
1568
  name: "stage.show",
1556
- description: `Show an object on the owner's screen. Give id, type, props, placement. Types and props: card {title?, text}; stat {label, value, unit?, delta?}; gauge {label, value 0-100, unit?}; list {title?, items}; table {title?, columns, rows}; code {title?, language?, code}; chart {title?, kind: line|bar|area, labels[], series:[{name, values[]}]}; timeline {title?, items:[{time, title, detail?}]}; graph {title?, nodes:[{id, label?}], edges:[{from, to, label?}]}; sandbox {title?, html} = a small page in an isolated frame with all HTML, CSS and JavaScript inline and no network: use it for animations, clocks, simulations, games and any visual the others cannot draw; colour it with var(--accent|ink|muted|ok|warn|bad|glass|edge|ui|mono) only. More (props in stage.guide): markdown, progress, checklist, kv, countdown, Jarvis components are types too (JStatCard, JGaugeChart, JTable, JCard, about forty more: see stage.guide) and look best: pick them first, image|video|pdf|gallery (src only from file.present); group {items:[{type, props}]} and tabs {tabs:[{title, type, props}]} put many objects in ONE: prefer them to many cards. placement: "auto" (default, tidy grid), center, left, right, top, bottom, or {x,y,w,h} as fractions 0..1. Optional ttl seconds, and layer "overlay" to float it over the screen for a short explanation. Call stage.guide for the manual. Example: {object:{id:"cpu",type:"gauge",props:{label:"CPU",value:42,unit:"%"},placement:"auto"}}`,
1569
+ description: 'Show ONE object at an exact place (several things: use screen.compose). Give id, type, props, placement. Types and props: card {title?, text}; stat {label, value, unit?, delta?}; gauge {label, value 0-100, unit?}; list {title?, items}; table {title?, columns, rows}; code {title?, language?, code}; chart {title?, kind: line|bar|area, labels[], series:[{name, values[]}]}; timeline {title?, items:[{time, title, detail?}]}; graph {title?, nodes:[{id, label?}], edges:[{from, to, label?}]}; sandbox {title?, html} = a small page in an isolated frame with all HTML, CSS and JavaScript inline and no network: use it for animations, clocks, simulations, games and any visual the others cannot draw; colour it with var(--accent|ink|muted|ok|warn|bad|glass|edge|ui|mono) only. More (props in stage.guide): markdown, progress, checklist, kv, countdown, Jarvis components are types too (JStatCard, JGaugeChart, JTable, JCard, about forty more: see stage.guide) and look best: pick them first, image|video|pdf|gallery (src only from file.present); group {items:[{type, props}]} and tabs {tabs:[{title, type, props}]} put many objects in ONE: prefer them to many cards. placement: "auto" (default, tidy grid), center, left, right, top, bottom, or {x,y,w,h} as fractions 0..1. Optional ttl seconds, and layer "overlay" to float it over the screen for a short explanation. Call stage.guide for the manual. Example: {object:{id:"cpu",type:"gauge",props:{label:"CPU",value:42,unit:"%"},placement:"auto"}}',
1557
1570
  input: z5.object({ object: StageObject }),
1558
1571
  baseTier: "T0",
1559
1572
  target: "gateway"
@@ -2643,24 +2656,29 @@ var WeatherService = class {
2643
2656
  }
2644
2657
  };
2645
2658
  function weatherScene(w) {
2646
- const show2 = (id2, type, props, placement = "auto") => ({
2647
- cmd: "show",
2648
- object: { id: id2, type, props, placement }
2649
- });
2650
2659
  return [
2651
- { cmd: "scene", mode: "multi" },
2652
- show2("weather-now", "stat", { label: w.place, value: String(Math.round(w.tempC)), unit: "\xB0C", delta: `${w.description}, feels like ${Math.round(w.feelsC)}\xB0C` }),
2653
- show2("weather-humidity", "gauge", { label: "Humidity", value: Math.round(w.humidity), unit: "%" }),
2654
- show2("weather-wind", "stat", { label: "Wind", value: String(Math.round(w.windKmh)), unit: "km/h" }),
2655
- show2("weather-hours", "chart", {
2656
- title: "Next 24 hours",
2657
- kind: "line",
2658
- labels: w.hours.map((h) => h.label),
2659
- series: [
2660
- { name: "Temperature \xB0C", values: w.hours.map((h) => Math.round(h.tempC * 10) / 10) },
2661
- { name: "Rain chance %", values: w.hours.map((h) => h.rainPct ?? 0) }
2662
- ]
2663
- })
2660
+ {
2661
+ id: "weather-hours",
2662
+ type: "chart",
2663
+ role: "focus",
2664
+ props: {
2665
+ title: "Next 24 hours",
2666
+ kind: "line",
2667
+ labels: w.hours.map((h) => h.label),
2668
+ series: [
2669
+ { name: "Temperature \xB0C", values: w.hours.map((h) => Math.round(h.tempC * 10) / 10) },
2670
+ { name: "Rain chance %", values: w.hours.map((h) => h.rainPct ?? 0) }
2671
+ ]
2672
+ }
2673
+ },
2674
+ {
2675
+ id: "weather-now",
2676
+ type: "stat",
2677
+ role: "beside",
2678
+ props: { label: w.place, value: String(Math.round(w.tempC)), unit: "\xB0C", delta: `${w.description}, feels like ${Math.round(w.feelsC)}\xB0C` }
2679
+ },
2680
+ { id: "weather-humidity", type: "gauge", role: "glance", props: { label: "Humidity", value: Math.round(w.humidity), unit: "%" } },
2681
+ { id: "weather-wind", type: "stat", role: "glance", props: { label: "Wind", value: String(Math.round(w.windKmh)), unit: "km/h" } }
2664
2682
  ];
2665
2683
  }
2666
2684
  function weatherSummary(w) {
@@ -3747,7 +3765,7 @@ function composeScreen(items, mode, st) {
3747
3765
  const gone = sides.splice(oldest === -1 ? sides.length - 1 : oldest, 1)[0];
3748
3766
  const id2 = gone.existing?.id ?? gone.item.id;
3749
3767
  const why = zones.stack ? "a phone shows one card at a time under the main thing" : `a ${kindOf(st.screen)} here has ${cap} place${cap === 1 ? "" : "s"} beside the main thing`;
3750
- notes.push(`"${id2}" was put away as a chip: ${why}.`);
3768
+ notes.push(`"${id2}" was put away as a chip: ${why}. The owner can tap its chip to bring it back; to see it now, make it the focus. Do not place it by hand with stage.show: that covers the screen's own instruments.`);
3751
3769
  squeezed.push(id2);
3752
3770
  if (gone.existing) {
3753
3771
  dock.push(id2);
@@ -3898,7 +3916,7 @@ var LAYOUT = `ARRANGING THE SCREEN
3898
3916
  - With stage.show, placement is explicit: one object "center"; two "left" and "right"; three to six "auto" with scene "multi"; one big thing scene "focus" and "center". "top" and "bottom" are wide banners. screen.compose does this for you for every screen size.
3899
3917
  - Never cover the voice presence (middle), captions (bottom), status line (bottom-left), clock (bottom-right) or the owner's pinned widgets. Pinned widgets belong to the owner: leave them, do not move them, do not hide them.
3900
3918
  - Update an object (same id) only when it is the same thing refreshed; a different topic is a new object, never reuse an old card for it. Clear the screen (stage.clear) whenever you need the room. At most 12 objects.
3901
- - Phone: everything stacks in one column, so show one focus and one card at most, prefer stat, gauge, progress, list, card; the rest are chips. Tablet: a focus and two beside. Desktop: a focus and three beside.
3919
+ - Phone: everything stacks in one column, so show one focus and one card at most, prefer stat, gauge, progress, list, card; the rest are chips. Tablet: a focus and two beside. Desktop: a focus and up to three beside (fewer when the screen's instruments or open panels take places; the zones: line says how many).
3902
3920
  - Lifetimes: what the owner asked to see stays until they dismiss it or you replace it. Passing information gets a ttl of 15 to 60 seconds.
3903
3921
  - When the task is done and the owner has what they need, take your temporary objects off the screen.`;
3904
3922
  var OVERLAY = `OVERLAY AND PRIORITY (what to do when the screen already has things on it)
@@ -4727,11 +4745,11 @@ Loyalty and safety
4727
4745
  - Prefer the smallest action that does the job. Say what you are about to do before running commands that change things.
4728
4746
 
4729
4747
  ${soulBlock(soul ?? DEFAULT_SOUL)}The screen
4730
- - The owner sees one full-screen stage and you control all of it. Only the voice presence and live captions are always there. The owner wants to SEE answers, not only hear them: whenever they ask for information, a status, numbers, a comparison, a schedule, a plan, progress or an explanation, put it on the screen with stage.show, then say one or two short sentences about it.
4731
- - Choose the picture that fits: gauge or stat for single numbers, chart for values over time, table or list for several items, timeline for schedules, graph for how things connect, card for a short note, and a sandbox page (an animated canvas, a clock, a countdown, a simulation, a small game) whenever no standard object can show it. The Jarvis HUD components are already part of Friend and available now, as object types like the others: JStatCard, JGaugeChart, JBarChart, JTable, JCard, JNodeGraph and about forty more (stage.guide lists every one with its props and size). They are the best looking, so choose one of them first for any card, number, chart, table, status or diagram, and use a basic widget only when no Jarvis component fits. Never tell the owner they are not there yet. Be creative and make it look good. Use placement "auto" for several objects, scene "multi" for dashboards and "focus" for one big thing, and match stage.mood and stage.presence to the topic.
4748
+ - The owner sees one full-screen stage and you control all of it. Only the voice presence and live captions are always there. The owner wants to SEE answers, not only hear them: whenever they ask for information, a status, numbers, a comparison, a schedule, a plan, progress or an explanation, show it on the screen with screen.compose (say what each thing is for: focus, beside, glance, note or alert; the screen picks the places for this device, its panels and its instruments), then say one or two short sentences about it. The first time you lay out a screen, read the screen-design skill with skill.use (plugin screen-design); after you compose, call stage.check once. If screen.compose put something away as a chip, leave it: never put it back by hand with stage.show, that covers the screen's own instruments.
4749
+ - Choose the picture that fits: gauge or stat for single numbers, chart for values over time, table or list for several items, timeline for schedules, graph for how things connect, card for a short note, and a sandbox page (an animated canvas, a clock, a countdown, a simulation, a small game) whenever no standard object can show it. The Jarvis HUD components are already part of Friend and available now, as object types like the others: JStatCard, JGaugeChart, JBarChart, JTable, JCard, JNodeGraph and about forty more (stage.guide lists every one with its props and size). They are the best looking, so choose one of them first for any card, number, chart, table, status or diagram, and use a basic widget only when no Jarvis component fits. Never tell the owner they are not there yet. Be creative and make it look good. Match stage.mood and stage.presence to the topic.
4732
4750
  - Act, do not announce. Never say you will do something ("I'll fetch...", "let me check...") without calling the tool in that same reply. After a tool returns data, show it on the screen.
4733
4751
  - Never invent numbers or facts to draw: get real data with a tool first, and put on the screen only what a tool returned or what the owner told you.
4734
- - For weather call weather.get (never curl, never an API key); for computer status call system.info. Both draw their own pictures on the screen, so afterwards just say a short summary.
4752
+ - For weather call weather.get (never curl, never an API key); for computer status call system.info. Both already put their pictures on the screen, so afterwards just say a short summary.
4735
4753
  - Voice presence styles: sphere (particle sphere, default), orb (glowing plasma orb) and ring (radial bars). Switch with stage.presence when it suits the mood. Use stage.mood to set the accent color and intensity.
4736
4754
  - Keep it tidy: replace what is no longer useful instead of piling things up (at most 12 objects), and use ttl for short-lived items. Spoken-style captions should be short and natural.
4737
4755
 
@@ -5594,7 +5612,7 @@ ${r.stderr}` : ""}`);
5594
5612
  const r = await d.weather.get(String(args.city));
5595
5613
  d.audit.log("agent", "tool.call", { tool: call.name, args: clipArgs(args), tier, ok: r.ok });
5596
5614
  if (!r.ok) return fail3(r.error);
5597
- this.showScene(weatherScene(r.weather), ctx.emit);
5615
+ this.composeScene(weatherScene(r.weather), ctx.emit);
5598
5616
  return { text: weatherSummary(r.weather), isError: false };
5599
5617
  }
5600
5618
  if (call.name === "skill.use") {
@@ -5822,6 +5840,14 @@ ${lines.join("\n")}`, isError: false };
5822
5840
  const cmd = { cmd: "widget", show: show2 };
5823
5841
  if (this.deps.stage.apply(cmd).ok) emit({ type: "stage", command: cmd });
5824
5842
  }
5843
+ /** A scene the server draws itself goes through the screen director like anything the model shows: places for this screen, nothing on top of an instrument. */
5844
+ composeScene(items, emit) {
5845
+ if (this.scenesThisTurn++ === 0) {
5846
+ const clear = { cmd: "clear", keepInstruments: true };
5847
+ if (this.deps.stage.apply(clear).ok) emit({ type: "stage", command: clear });
5848
+ }
5849
+ runStageTool("screen.compose", { items, mode: "replace" }, this.deps.stage, emit);
5850
+ }
5825
5851
  showScene(commands, emit) {
5826
5852
  const first3 = this.scenesThisTurn++ === 0;
5827
5853
  for (const cmd of first3 ? [{ cmd: "clear", keepInstruments: true }, ...commands] : commands) {
@@ -22195,7 +22221,7 @@ function currentSelf() {
22195
22221
  // ../server/src/system/npm.ts
22196
22222
  import { spawn as spawn10 } from "node:child_process";
22197
22223
  var PACKAGE = "friend-assistant";
22198
- var runningVersion = () => true ? "0.1.80" : "development";
22224
+ var runningVersion = () => true ? "0.1.81" : "development";
22199
22225
  async function npmLatest(fetchFn = fetch, timeoutMs = 1e4) {
22200
22226
  try {
22201
22227
  const res = await fetchFn(`https://registry.npmjs.org/${PACKAGE}/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
@@ -27574,7 +27600,7 @@ import { appendFileSync } from "node:fs";
27574
27600
  import { join as join39 } from "node:path";
27575
27601
  var PACKAGE2 = "friend-assistant";
27576
27602
  var real2 = {
27577
- current: () => true ? "0.1.80" : "development",
27603
+ current: () => true ? "0.1.81" : "development",
27578
27604
  latest: () => new Promise((resolve13) => {
27579
27605
  const child = crossSpawn5("npm", ["view", PACKAGE2, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
27580
27606
  let out = "";
@@ -27892,7 +27918,7 @@ async function run(argv, io2) {
27892
27918
  case "version":
27893
27919
  case "--version":
27894
27920
  case "-v":
27895
- io2.out(true ? "0.1.80" : "development");
27921
+ io2.out(true ? "0.1.81" : "development");
27896
27922
  return 0;
27897
27923
  case "lan":
27898
27924
  return await lanCommand(rest, io2);
@@ -27,6 +27,7 @@ You say what each thing is for. The system picks the place for this screen. You
27
27
  ## For each screen
28
28
 
29
29
  - **Desktop:** a focus in the middle, up to three cards beside it, chips along the top. Use `beside` for what really helps, not to fill space.
30
+ - **Beside places are small.** On a home screen with instruments they are short (a number, a few lines): put a chart or a long table as the `focus`, not beside. The `zones:` line of the screen description says how many places there are. If something was put away as a chip, leave it: do not put it back with `stage.show` and a box, that covers the screen's own instruments.
30
31
  - **Tablet:** a focus and up to two cards beside it. Keep text large and short.
31
32
  - **Phone:** one card at a time under the orb; everything else is a chip. Prefer a stat, a gauge or a short list over a wide chart or table. The request's `screen:` line says which one this is; if it changes (the owner turns the phone), the screen is laid out again by itself.
32
33
 
@@ -1 +1 @@
1
- import{i as e,l as t,o as n,t as r}from"./index-QAOoIk37.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-DmnSOb4G.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-DLkyeH9i.js";import{a as i,n as a,r as o,t as s}from"./jarvis-ui-DDzxKRuI.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};