@songsid/agend 2.3.2-beta.4 → 2.3.2-beta.6

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.
Files changed (197) hide show
  1. package/THIRD_PARTY_NOTICES.md +40 -0
  2. package/dist/antigravity-usage-scan.d.ts +58 -0
  3. package/dist/antigravity-usage-scan.js +257 -0
  4. package/dist/antigravity-usage-scan.js.map +1 -0
  5. package/dist/antigravity-usage-worker.d.ts +1 -0
  6. package/dist/antigravity-usage-worker.js +10 -0
  7. package/dist/antigravity-usage-worker.js.map +1 -0
  8. package/dist/backend/kiro-identity.d.ts +45 -0
  9. package/dist/backend/kiro-identity.js +74 -0
  10. package/dist/backend/kiro-identity.js.map +1 -1
  11. package/dist/backend/kiro.d.ts +15 -0
  12. package/dist/backend/kiro.js +42 -5
  13. package/dist/backend/kiro.js.map +1 -1
  14. package/dist/backend/types.d.ts +6 -0
  15. package/dist/backend/types.js.map +1 -1
  16. package/dist/backend-signin-guide.d.ts +1 -0
  17. package/dist/backend-signin-guide.js +9 -0
  18. package/dist/backend-signin-guide.js.map +1 -0
  19. package/dist/backend-signin-pending.d.ts +10 -0
  20. package/dist/backend-signin-pending.js +44 -0
  21. package/dist/backend-signin-pending.js.map +1 -0
  22. package/dist/browser-backend-signins.d.ts +56 -0
  23. package/dist/browser-backend-signins.js +189 -0
  24. package/dist/browser-backend-signins.js.map +1 -0
  25. package/dist/cache-ledger.d.ts +38 -2
  26. package/dist/cache-ledger.js +133 -8
  27. package/dist/cache-ledger.js.map +1 -1
  28. package/dist/cache-prices.d.ts +2 -1
  29. package/dist/cache-prices.js +5 -2
  30. package/dist/cache-prices.js.map +1 -1
  31. package/dist/cache-service.d.ts +68 -0
  32. package/dist/cache-service.js +355 -13
  33. package/dist/cache-service.js.map +1 -1
  34. package/dist/channel/adapters/discord.d.ts +11 -0
  35. package/dist/channel/adapters/discord.js +50 -8
  36. package/dist/channel/adapters/discord.js.map +1 -1
  37. package/dist/channel/mcp-tools.js +3 -1
  38. package/dist/channel/mcp-tools.js.map +1 -1
  39. package/dist/cli.js +21 -2
  40. package/dist/cli.js.map +1 -1
  41. package/dist/config-validator.js +25 -3
  42. package/dist/config-validator.js.map +1 -1
  43. package/dist/config.d.ts +19 -0
  44. package/dist/config.js +25 -0
  45. package/dist/config.js.map +1 -1
  46. package/dist/cpu-quota.d.ts +23 -0
  47. package/dist/cpu-quota.js +86 -0
  48. package/dist/cpu-quota.js.map +1 -0
  49. package/dist/daemon.js +6 -3
  50. package/dist/daemon.js.map +1 -1
  51. package/dist/fleet-manager.d.ts +56 -5
  52. package/dist/fleet-manager.js +387 -144
  53. package/dist/fleet-manager.js.map +1 -1
  54. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +5 -2
  55. package/dist/general-knowledge/skills/kiro-engine-migration/SKILL.md +14 -1
  56. package/dist/general-knowledge/skills/web-dashboard/SKILL.canvas-worker-off.md +20 -4
  57. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +20 -4
  58. package/dist/instance-lifecycle.d.ts +9 -0
  59. package/dist/instance-lifecycle.js +27 -1
  60. package/dist/instance-lifecycle.js.map +1 -1
  61. package/dist/kiro-db-reader.d.ts +5 -0
  62. package/dist/kiro-db-reader.js +18 -0
  63. package/dist/kiro-db-reader.js.map +1 -1
  64. package/dist/kiro-engine-status.d.ts +2 -0
  65. package/dist/kiro-engine-status.js +9 -0
  66. package/dist/kiro-engine-status.js.map +1 -1
  67. package/dist/kiro-migrate.d.ts +49 -0
  68. package/dist/kiro-migrate.js +105 -0
  69. package/dist/kiro-migrate.js.map +1 -0
  70. package/dist/kiro-transcript-lane.d.ts +2 -0
  71. package/dist/kiro-transcript-lane.js.map +1 -1
  72. package/dist/kiro-transcript-worker.js +1 -0
  73. package/dist/kiro-transcript-worker.js.map +1 -1
  74. package/dist/kiro-usage-run.d.ts +7 -0
  75. package/dist/kiro-usage-run.js +39 -0
  76. package/dist/kiro-usage-run.js.map +1 -0
  77. package/dist/kiro-usage-scan.d.ts +49 -0
  78. package/dist/kiro-usage-scan.js +223 -0
  79. package/dist/kiro-usage-scan.js.map +1 -0
  80. package/dist/kiro-usage-worker.d.ts +1 -0
  81. package/dist/kiro-usage-worker.js +10 -0
  82. package/dist/kiro-usage-worker.js.map +1 -0
  83. package/dist/kiro-usage.d.ts +58 -0
  84. package/dist/kiro-usage.js +310 -0
  85. package/dist/kiro-usage.js.map +1 -0
  86. package/dist/locale.js +78 -2
  87. package/dist/locale.js.map +1 -1
  88. package/dist/log-service.js +1 -1
  89. package/dist/log-service.js.map +1 -1
  90. package/dist/login-url.d.ts +4 -0
  91. package/dist/login-url.js +22 -0
  92. package/dist/login-url.js.map +1 -0
  93. package/dist/needs-you-hub.d.ts +2 -1
  94. package/dist/needs-you-hub.js +1 -1
  95. package/dist/needs-you-hub.js.map +1 -1
  96. package/dist/needs-you.d.ts +8 -2
  97. package/dist/needs-you.js +6 -0
  98. package/dist/needs-you.js.map +1 -1
  99. package/dist/notice-delivery.d.ts +7 -6
  100. package/dist/notice-delivery.js +16 -18
  101. package/dist/notice-delivery.js.map +1 -1
  102. package/dist/office-share-page.d.ts +13 -0
  103. package/dist/office-share-page.js +82 -0
  104. package/dist/office-share-page.js.map +1 -0
  105. package/dist/office-share-service.d.ts +89 -0
  106. package/dist/office-share-service.js +172 -0
  107. package/dist/office-share-service.js.map +1 -0
  108. package/dist/office-share.d.ts +228 -0
  109. package/dist/office-share.js +489 -0
  110. package/dist/office-share.js.map +1 -0
  111. package/dist/opencode-usage-scan.d.ts +28 -0
  112. package/dist/opencode-usage-scan.js +92 -0
  113. package/dist/opencode-usage-scan.js.map +1 -0
  114. package/dist/opencode-usage-worker.d.ts +1 -0
  115. package/dist/opencode-usage-worker.js +10 -0
  116. package/dist/opencode-usage-worker.js.map +1 -0
  117. package/dist/outbound-handlers.js +22 -2
  118. package/dist/outbound-handlers.js.map +1 -1
  119. package/dist/outbound-schemas.d.ts +4 -0
  120. package/dist/outbound-schemas.js +4 -0
  121. package/dist/outbound-schemas.js.map +1 -1
  122. package/dist/public-web-gateway.js +6 -0
  123. package/dist/public-web-gateway.js.map +1 -1
  124. package/dist/quickstart-api.js +13 -2
  125. package/dist/quickstart-api.js.map +1 -1
  126. package/dist/quickstart.js +2 -3
  127. package/dist/quickstart.js.map +1 -1
  128. package/dist/settings-api.js +1 -1
  129. package/dist/settings-api.js.map +1 -1
  130. package/dist/setup-form.d.ts +1 -1
  131. package/dist/setup-form.js +7 -1
  132. package/dist/setup-form.js.map +1 -1
  133. package/dist/setup-host.d.ts +9 -0
  134. package/dist/setup-host.js +125 -7
  135. package/dist/setup-host.js.map +1 -1
  136. package/dist/setup-signin-assets.d.ts +2 -0
  137. package/dist/setup-signin-assets.js +6 -0
  138. package/dist/setup-signin-assets.js.map +1 -0
  139. package/dist/setup-wizard.js +2 -2
  140. package/dist/setup-wizard.js.map +1 -1
  141. package/dist/structured-signin-transport.d.ts +8 -0
  142. package/dist/structured-signin-transport.js +79 -0
  143. package/dist/structured-signin-transport.js.map +1 -0
  144. package/dist/structured-signin.d.ts +131 -0
  145. package/dist/structured-signin.js +388 -0
  146. package/dist/structured-signin.js.map +1 -0
  147. package/dist/tool-permissions.js +2 -0
  148. package/dist/tool-permissions.js.map +1 -1
  149. package/dist/topic-commands.js +4 -1
  150. package/dist/topic-commands.js.map +1 -1
  151. package/dist/transcript-sources.d.ts +26 -2
  152. package/dist/transcript-sources.js +87 -40
  153. package/dist/transcript-sources.js.map +1 -1
  154. package/dist/types.d.ts +15 -5
  155. package/dist/ui/backend-signin.js +63 -10
  156. package/dist/ui/fleet-office-pack.js +7 -2
  157. package/dist/ui/fleet-office-skin.js +5 -4
  158. package/dist/ui/fleet-office-zones.js +17 -6
  159. package/dist/ui/fleet-office.js +20 -10
  160. package/dist/ui/fleet-usage.js +19 -15
  161. package/dist/ui/office-share-dialog.js +145 -0
  162. package/dist/ui/office-share-page.js +116 -0
  163. package/dist/ui/panel-log.js +2 -2
  164. package/dist/ui/panel-needs.js +4 -4
  165. package/dist/ui/panel-settings.js +12 -8
  166. package/dist/ui/settings-registry.js +2 -2
  167. package/dist/ui/settings-strings.js +6 -6
  168. package/dist/ui/shared/app-i18n.js +2 -2
  169. package/dist/ui/shared/app.css +29 -0
  170. package/dist/ui/structured-signin.js +115 -0
  171. package/dist/usage-report.d.ts +20 -0
  172. package/dist/usage-report.js +54 -17
  173. package/dist/usage-report.js.map +1 -1
  174. package/dist/usage-rollup.d.ts +9 -1
  175. package/dist/usage-rollup.js +20 -4
  176. package/dist/usage-rollup.js.map +1 -1
  177. package/dist/web-api.d.ts +15 -0
  178. package/dist/web-api.js +190 -0
  179. package/dist/web-api.js.map +1 -1
  180. package/dist/web-auth.js +1 -1
  181. package/dist/web-auth.js.map +1 -1
  182. package/dist/web-backend-login.d.ts +1 -7
  183. package/dist/web-backend-login.js +2 -24
  184. package/dist/web-backend-login.js.map +1 -1
  185. package/dist/web-office-skins.d.ts +2 -1
  186. package/dist/web-office-skins.js +2 -1
  187. package/dist/web-office-skins.js.map +1 -1
  188. package/dist/web-settings-patch.js +1 -1
  189. package/dist/web-settings-patch.js.map +1 -1
  190. package/dist/working-recovery.d.ts +2 -2
  191. package/dist/working-recovery.js +43 -8
  192. package/dist/working-recovery.js.map +1 -1
  193. package/dist/working-state-journal.d.ts +2 -0
  194. package/dist/working-state-journal.js +16 -1
  195. package/dist/working-state-journal.js.map +1 -1
  196. package/package.json +2 -1
  197. package/templates/windows-shortcuts.ps1 +7 -5
@@ -30,6 +30,10 @@
30
30
  // "door": [640, 700], optional: where someone new walks in from (default: bottom middle)
31
31
  // "waypoints": [{ "id": "hall", "x": 640, "y": 600 }, …], "edges": [["hall", "east"], …],
32
32
  // optional: the walkable graph (else people walk straight)
33
+ // "straight": true, optional (#2634): every walk goes across, then up or down — each
34
+ // diagonal leg an L, so the walkSide / walkDown / walkUp strips
35
+ // always fit (graph edges laid out across and up/down put the
36
+ // corners on the aisles); default false
33
37
  // "furniture": [ { "id": "rack", "sprite": STRIP, "x": 1020, "y": 140, "depth": 2,
34
38
  // "activeWhen": "crashed", "activeSprite": STRIP, "activeFor": "atlas", "loop": true, "label": "Rack",
35
39
  // "night": { "sprite": STRIP, "x": 300, "y": 420 },
@@ -190,12 +194,13 @@ function states(v, at) {
190
194
  export function checkSkinPack(x) {
191
195
  try {
192
196
  obj(x, "pack");
193
- keys(x, ["format", "id", "scale", "background", "foreground", "matte", "areas", "stateZones", "door", "waypoints", "edges", "furniture", "characters", "byInstance", "props", "bubbles", "room", "desk"], "pack");
197
+ keys(x, ["format", "id", "scale", "background", "foreground", "matte", "areas", "stateZones", "door", "waypoints", "edges", "straight", "furniture", "characters", "byInstance", "props", "bubbles", "room", "desk"], "pack");
194
198
  if (x.format !== 1) throw new Refused("format", "1");
195
199
  if (typeof x.id !== "string" || !ID.test(x.id)) throw new Refused("id", "1–40 letters, digits, _ or -");
196
200
  if (BUILT_IN.has(x.id)) throw new Refused("id", "a built-in skin's id");
197
201
  const scale = x.scale === undefined ? 2 : int(x.scale, 1, 8, "scale");
198
202
  if (x.matte !== undefined && !matteOk(x.matte)) throw new Refused("matte", "a colour as #rrggbb");
203
+ if (x.straight !== undefined && typeof x.straight !== "boolean") throw new Refused("straight", "true or false");
199
204
  const areas = {};
200
205
  const rawAreas = x.areas === undefined ? {} : obj(x.areas, "areas");
201
206
  if (Object.keys(rawAreas).length > LIMIT.areas) throw new Refused("areas", `at most ${LIMIT.areas}`);
@@ -291,7 +296,7 @@ export function checkSkinPack(x) {
291
296
  const opt = (v, at) => (v === undefined ? undefined : src(v, at));
292
297
  return { ok: true, pack: {
293
298
  format: 1, id: x.id, scale, background: opt(x.background, "background"), foreground: opt(x.foreground, "foreground"), matte: x.matte === undefined ? undefined : x.matte.toLowerCase(), areas, stateZones,
294
- door: x.door === undefined ? { x: LOGICAL.w / 2, y: LOGICAL.h - 10 } : point(x.door, "door"), waypoints, edges, furniture, characters, byInstance,
299
+ door: x.door === undefined ? { x: LOGICAL.w / 2, y: LOGICAL.h - 10 } : point(x.door, "door"), waypoints, edges, straight: x.straight === true, furniture, characters, byInstance,
295
300
  props: x.props === undefined ? {} : strips(x.props, PROPS, "props", scale), bubbles,
296
301
  room: { floor: opt(room.floor, "room.floor"), wall: opt(room.wall, "room.wall") }, desk: { back: opt(desk.back, "desk.back"), front: opt(desk.front, "desk.front"), lit: opt(desk.lit, "desk.lit") },
297
302
  } };
@@ -376,7 +376,7 @@ const STUDIO_FURNITURE = [
376
376
  ].sort((a, b) => a.depth - b.depth);
377
377
  /** The studio's pack: the same shape as a checked one (fleet-office-pack.js), furniture by `shape` instead of sprites. */
378
378
  export const STUDIO_PACK = {
379
- format: 1, id: "studio", scale: 1, areas: STUDIO_AREAS, door: { x: HALL_X, y: 704 }, furniture: STUDIO_FURNITURE, ...studioGraph(STUDIO_AREAS),
379
+ format: 1, id: "studio", scale: 1, areas: STUDIO_AREAS, door: { x: HALL_X, y: 704 }, furniture: STUDIO_FURNITURE, ...studioGraph(STUDIO_AREAS), straight: false,
380
380
  stateZones: { working: "desks", idle: "lounge", needs: "alert", crashed: "alert", stuck: "alert", paused: "nap", stopped: "nap", default: "lounge" },
381
381
  characters: {}, byInstance: {}, props: {}, bubbles: {},
382
382
  };
@@ -561,9 +561,10 @@ const defaultImage = (url) => new Promise((resolve) => {
561
561
  /**
562
562
  * An uploaded pack (GET /ui/office-skins/<id>?v=<sha>) as an OfficeSkin: its manifest checked (null when it is not a
563
563
  * pack: the page then draws a built-in style and says so), its pictures loaded from their content ids (one that does
564
- * not load is drawn by the built-in skin). Kept per id and sha, so a pack is fetched once.
564
+ * not load is drawn by the built-in skin). Kept per id and sha, so a pack is fetched once. `url`: where a picture's path
565
+ * is read (a share link's page reads its own address, #2636).
565
566
  */
566
- export function loadPackSkin(id, sha, { fetch: get = globalThis.fetch, image = defaultImage } = {}) {
567
+ export function loadPackSkin(id, sha, { fetch: get = globalThis.fetch, image = defaultImage, url = (p) => p } = {}) {
567
568
  const key = `${id}@${sha}`;
568
569
  if (loaded.has(key)) return loaded.get(key);
569
570
  const base = `/ui/office-skins/${encodeURIComponent(id)}`;
@@ -579,7 +580,7 @@ export function loadPackSkin(id, sha, { fetch: get = globalThis.fetch, image = d
579
580
  await Promise.all(packImages(c.pack).map(async (src) => {
580
581
  const fid = own(files, src);
581
582
  if (typeof fid !== "string" || !/^[0-9a-f]{32}$/.test(fid)) return;
582
- const im = await image(`${base}/img/${fid}.png`);
583
+ const im = await image(url(`${base}/img/${fid}.png`));
583
584
  if (im) images.set(src, im);
584
585
  }));
585
586
  return spriteSkin(c.pack, images);
@@ -74,8 +74,8 @@ export function assignSeats(pack, wants, prev = new Map()) {
74
74
 
75
75
  /**
76
76
  * The zones layout for `nodes` (buildOrgView's) on a pack: everyone but the missing at their seat. The same shape as
77
- * the desks layout (rooms → desks with a seat), in logical units, plus `mode: "zones"`, the pack's areas and graph, the
78
- * seats given (`seats`, the next call's `prev`), `crowd` and `over` (the areas over capacity).
77
+ * the desks layout (rooms → desks with a seat), in logical units, plus `mode: "zones"`, the pack's areas and graph (and
78
+ * its `straight`, #2634), the seats given (`seats`, the next call's `prev`), `crowd` and `over` (the areas over capacity).
79
79
  */
80
80
  export function zonesLayout(pack, nodes, prev = new Map(), { night = false } = {}) {
81
81
  // At night (#2568) the idle go to bed: the area asleep people go to while it has a free seat; the rest doze where they are.
@@ -89,7 +89,7 @@ export function zonesLayout(pack, nodes, prev = new Map(), { night = false } = {
89
89
  return { key: `zone/${n.name}`, node: n, x: s.x - 24, y: s.y - 52, w: 48, h: 66, seat: { x: s.x, y: s.y }, wp: null, area: s.area, slot: s.slot, night: sleepers.has(n.name) };
90
90
  });
91
91
  return { mode: "zones", rooms: [{ key: "\u0000zones", name: null, lobby: false, x: 0, y: 0, w: LOGICAL.w, h: LOGICAL.h, desks }], areas: pack.areas,
92
- waypoints: pack.waypoints || [], edges: pack.edges || [], door: pack.door, width: LOGICAL.w, height: LOGICAL.h, seats, crowd, over };
92
+ waypoints: pack.waypoints || [], edges: pack.edges || [], straight: pack.straight === true, door: pack.door, width: LOGICAL.w, height: LOGICAL.h, seats, crowd, over };
93
93
  }
94
94
 
95
95
  // ── Walking ──
@@ -108,6 +108,16 @@ export function headingAt(pts, t) {
108
108
  }
109
109
  return null;
110
110
  }
111
+ /**
112
+ * #2634: a polyline with each diagonal leg made an L — across first, then up or down — so a character set's three
113
+ * walking strips always fit; legs already across or up/down are kept, and no point repeats (no zero-length leg).
114
+ */
115
+ export function straighten(pts) {
116
+ const out = [];
117
+ const add = (x, y) => { const l = out[out.length - 1]; if (!l || l.x !== x || l.y !== y) out.push({ x, y }); };
118
+ for (const p of pts) { const l = out[out.length - 1]; if (l && l.x !== p.x && l.y !== p.y) add(p.x, l.y); add(p.x, p.y); }
119
+ return out;
120
+ }
111
121
  // ── Night (#2568) ──
112
122
 
113
123
  /** Bedtime on the viewer's clock: from FROM o'clock to TO o'clock the idle sleep (anyone with work still gets up for it). */
@@ -249,8 +259,8 @@ export function createMail({ max = MAIL.MAX } = {}) {
249
259
 
250
260
  /**
251
261
  * Where each character is. `sync(targets, now, graph, still)`: targets name → { x, y }; someone new is already there;
252
- * someone whose target moved walks from where they are now along the graph (routeVia) — or is there at once when
253
- * `still` (reduced motion); someone gone is forgotten. `at(name, now)` → { x, y, walking } and, while walking, `heading`: the
262
+ * someone whose target moved walks from where they are now along the graph (routeVia; each diagonal leg an L when the
263
+ * graph is `straight`, #2634) — or is there at once when `still` (reduced motion); someone gone is forgotten. `at(name, now)` → { x, y, walking } and, while walking, `heading`: the
254
264
  * current step's { dx, dy }, which picks a pack's walkDown / walkUp / walkSide strip; `moving(now)`.
255
265
  */
256
266
  export function createWalkers() {
@@ -269,7 +279,8 @@ export function createWalkers() {
269
279
  const w = by.get(name);
270
280
  if (!w || still) { if (!w || w.to.x !== to.x || w.to.y !== to.y) by.set(name, { pts: null, to }); continue; }
271
281
  if (w.to.x === to.x && w.to.y === to.y) continue;
272
- const here = posAt(w, now), pts = routeVia(graph, { x: here.x, y: here.y }, { x: to.x, y: to.y });
282
+ const here = posAt(w, now), via = routeVia(graph, { x: here.x, y: here.y }, { x: to.x, y: to.y });
283
+ const pts = graph.straight ? straighten(via) : via; // #2634: timed along the longer way
273
284
  by.set(name, { pts, start: now, ms: Math.max(1, pathLength(pts) / WALK.SPEED), to });
274
285
  }
275
286
  },
@@ -34,6 +34,8 @@
34
34
  // ("+N", in its corner, never over its name); there idle and asleep people say nothing, at most a few speak (calls
35
35
  // first, then work), no bubble covers a name tag, and the tags show on hover or focus only. "Hide paused and stopped"
36
36
  // (per browser) leaves the sleepers out.
37
+ // - Share… (#2636; an admin, on the dashboard reached directly or over the public link): a link anyone can open to watch an office live, read-only,
38
+ // until it ends (office-share-dialog.js; the page it opens is office-share-page.js).
37
39
  // - Edit layout (an admin, a stored office on a zones skin): fleet-office-layout.js, saved as the office's overrides.
38
40
  // An editing session (#2513 review) is bound to the office it opened on, that office's style (the pack's id and sha)
39
41
  // and the list and rev read then: a re-read of the offices meanwhile (the stream) changes the view, never the session,
@@ -67,6 +69,7 @@ import { actsOk, createOfficeStore } from "./fleet-office-store.js";
67
69
  import { POLL_MS } from "./fleet-traffic.js";
68
70
  import { OfficeEditor, officeForSave } from "./fleet-office-editor.js";
69
71
  import { LayoutEditor, handlesOf } from "./fleet-office-layout.js";
72
+ import { ShareButton } from "./office-share-dialog.js";
70
73
  import { applyOverrides } from "./fleet-office-pack.js";
71
74
  import { ALL_ID, LOBBY_TILE, OV, createCrossFlights, cropToRooms, fromTile, inTile, labelAt, lobbyNodes, overviewOk, tileAt, tileBox, tileLayout, visibleTiles } from "./fleet-office-overview.js";
72
75
  import { centreOn, gestureState, gestures, miniPoint, toScreen, toWorld, wheelFactor, zoomKey, zoomTo } from "./fleet-canvas-view.js";
@@ -422,15 +425,18 @@ function People({ nodes, pinned, onChange }) {
422
425
 
423
426
  /**
424
427
  * The view: `view` buildOrgView's answer; `traffic` the live items (null: Live is off); `q` the Find box's needle;
425
- * `lease` the tab's (its reads); `onOpen(name)` what a desk opens (the canvas's: the chat).
428
+ * `lease` the tab's (its reads); `onOpen(name)` what a desk opens (the canvas's: the chat; none: a desk opens nothing,
429
+ * as on a share link's page, #2636); `assetUrl(path)` where a skin pack's picture is read (the share's address);
430
+ * `opening` the office it opens on (the share's), instead of the one this browser chose last.
426
431
  */
427
- export function Office({ view, traffic, q = "", lease, onOpen }) {
432
+ export function Office({ view, traffic, q = "", lease, onOpen, assetUrl, opening }) {
428
433
  const store = useMemo(() => createOfficeStore(lease ? { fetch: (path, o) => lease.fetch(path, o) } : {}), [lease]);
429
434
  const [stored, setStored] = useState([]);
430
435
  const [storedRev, setStoredRev] = useState(null); // the rev the list was read at (a save sends it)
431
436
  const [canEdit, setCanEdit] = useState(false); // an admin session (never a guest or the public link)
437
+ const [canShare, setCanShare] = useState(false); // #2636: an admin session, here or over the public link
432
438
  const [editing, setEditing] = useState(false);
433
- const [choice, setChoice] = useState(() => store.choice());
439
+ const [choice, setChoice] = useState(() => opening ?? store.choice());
434
440
  const [filter, setFilter] = useState(() => store.filter());
435
441
  const [style, setStyle] = useState(() => store.skin());
436
442
  const [hideAsleep, setHideAsleep] = useState(() => store.hideAsleep());
@@ -517,13 +523,15 @@ export function Office({ view, traffic, q = "", lease, onOpen }) {
517
523
  return () => { if (off) off(); };
518
524
  }, [lease, store]);
519
525
  // Whether this page may edit the offices: an admin session (the host asks again on every save), never a guest page or
520
- // the public link (whose sessions the host refuses outright).
526
+ // the public link (whose sessions the host refuses outright). #2636 follow-up (the user's choice): Share… is an admin
527
+ // session's here or over the public link (the host asks again too); never a guest's or a read-only one's.
521
528
  useEffect(() => {
522
529
  const body = globalThis.document?.body;
523
- if (!body || body.dataset.tier === "guest" || body.dataset.publicLink === "1") return undefined;
530
+ if (!body || body.dataset.tier === "guest") return undefined;
531
+ const overLink = body.dataset.publicLink === "1";
524
532
  let live = true;
525
533
  const auth = globalThis.AgendAuth;
526
- if (auth && typeof auth.canWrite === "function") Promise.resolve(auth.canWrite()).then((v) => { if (live) setCanEdit(v === true); }, () => {});
534
+ if (auth && typeof auth.canWrite === "function") Promise.resolve(auth.canWrite()).then((v) => { if (live) { setCanEdit(v === true && !overLink); setCanShare(v === true); } }, () => {});
527
535
  return () => { live = false; };
528
536
  }, []);
529
537
  // The stage's width (the grid wraps at it), and the theme (the tokens the canvas reads).
@@ -574,7 +582,7 @@ export function Office({ view, traffic, q = "", lease, onOpen }) {
574
582
  if (!want.length) return undefined;
575
583
  let live = true;
576
584
  const get = lease ? (path, o) => lease.fetch(path, o) : undefined;
577
- for (const [k, pk] of want) loadPackSkin(pk.id, pk.sha, get ? { fetch: get } : {}).then((sk) => { if (live) setPackSkins((m) => new Map(m).set(k, sk)); });
585
+ for (const [k, pk] of want) loadPackSkin(pk.id, pk.sha, { ...(get ? { fetch: get } : {}), ...(assetUrl ? { url: assetUrl } : {}) }).then((sk) => { if (live) setPackSkins((m) => new Map(m).set(k, sk)); });
578
586
  return () => { live = false; };
579
587
  }, [neededKey]);
580
588
  const loading = !!packInfo && !packSkins.has(packKey);
@@ -877,7 +885,7 @@ export function Office({ view, traffic, q = "", lease, onOpen }) {
877
885
  return () => root.classList.remove("oo-immersive");
878
886
  }, [fs]);
879
887
  /** A desk opens its chat: out of fullscreen first (the chat is beside the view, or instead of it). */
880
- const open = (name) => { if (fsRef.current) exitFs(); onOpen(name); };
888
+ const open = (name) => { if (!onOpen) return; if (fsRef.current) exitFs(); onOpen(name); };
881
889
 
882
890
  // ── Drawing: the back and front layers are pictures of the scene at the view's resolution (remade when the office
883
891
  // or the zoom changes, never on a pan); each frame draws the matte, the layers, the people and the items in the air ──
@@ -1149,6 +1157,8 @@ export function Office({ view, traffic, q = "", lease, onOpen }) {
1149
1157
  ${canEdit && storedRev !== null ? html`<button type="button" class="btn btn-sm oo-edit" onClick=${() => { if (!overview) setEditing(true); }} disabled=${!!layout || overview}
1150
1158
  title=${overview ? to("overviewNoEdit") : undefined}>${t("orge.edit")}</button>` : null}
1151
1159
  ${canLayout ? html`<button type="button" class="btn btn-sm oo-layout" onClick=${openLayout}>${t("orgl.edit")}</button>` : null}
1160
+ ${canShare ? html`<${ShareButton} offices=${stored} current=${overview ? "all" : custom ? custom.id : null} disabled=${!!layout}
1161
+ get=${lease ? (path, o) => lease.fetch(path, o) : undefined} />` : null}
1152
1162
  </div>
1153
1163
  ${editing && !overview ? html`<${OfficeEditor} offices=${stored} rev=${storedRev} view=${view} store=${store} packs=${packs}
1154
1164
  ask=${ask} current=${() => shown.current} onSaved=${adopt} onClose=${() => setEditing(false)} />` : null}
@@ -1169,12 +1179,12 @@ export function Office({ view, traffic, q = "", lease, onOpen }) {
1169
1179
  <strong>${tipText.primary}</strong>${tipText.secondary ? html` <span class="muted mono">${tipText.secondary}</span>` : null}
1170
1180
  <div>${tipText.sub}</div><div class="muted">${caption(officePose(tipDesk.node.state), tipDesk.node.state)}</div>
1171
1181
  ${tipDesk.office ? html`<div class="muted oo-tip-office">${tipDesk.office}</div>` : null}
1172
- ${tipDesk.node.i && lastType.current === "touch" ? html`<div class="muted">${to("tapAgain")}</div>` : null}
1182
+ ${tipDesk.node.i && onOpen && lastType.current === "touch" ? html`<div class="muted">${to("tapAgain")}</div>` : null}
1173
1183
  </div>` : null}
1174
1184
  <ul class="oo-desks" aria-label=${to("desks")}>${people.map((d) => {
1175
1185
  const nt = nodeText(d.node), cap = caption(officePose(d.node.state), d.node.state), where = d.office ? ` · ${d.office}` : "";
1176
1186
  return html`<li key=${d.key}>${d.node.i
1177
- ? html`<button type="button" class="oo-desk" data-name=${d.node.name} data-key=${d.key} aria-label=${`${nt.full}${where} · ${cap}. ${t("orgc.openChat")}`}
1187
+ ? html`<button type="button" class="oo-desk" data-name=${d.node.name} data-key=${d.key} aria-label=${`${nt.full}${where} · ${cap}.${onOpen ? ` ${t("orgc.openChat")}` : ""}`}
1178
1188
  onFocus=${() => setTip(d.key)} onBlur=${() => setTip(null)} onClick=${() => open(d.node.name)}>${nt.primary}</button>`
1179
1189
  : html`<span class="oo-desk" data-name=${d.node.name} data-key=${d.key}>${nt.full}</span>`}</li>`;
1180
1190
  })}</ul>
@@ -15,14 +15,15 @@ register("fusage", {
15
15
  range: "Range", today: "Today", r7d: "7 days", month: "This month", all: "All", custom: "Custom", from: "From", to: "To", apply: "Apply",
16
16
  group: "Group by", g_instance: "Agent", g_backend: "Backend", g_model: "Model", g_profile: "Credential profile", g_team: "Team (as configured now)",
17
17
  csv: "Download CSV", basis: "API-equivalent at list price (checked {0}) — not money spent. Subscriptions are not billed per token.",
18
- amount: "API-equivalent", input: "Input", output: "Output", read: "Cache read", write: "Cache write", total: "Total tokens", requests: "Requests", messages: "Messages",
18
+ amount: "API-equivalent", input: "Input", output: "Output", reasoning: "Reasoning", read: "Cache read", write: "Cache write", total: "Total tokens", requests: "Requests", messages: "Messages",
19
19
  notPriced: "not priced", partial: "partial", noTeam: "(no team)", unknown: "unknown",
20
- f_cache_write_not_reported: "cache writes not reported (Codex) — an estimate", f_not_priced: "not priced: {0}", f_source_unknown: "read before backend and profile were recorded",
20
+ f_cache_write_not_reported: "cache writes not reported (Codex, Muse) — an estimate", f_not_priced: "not priced: {0}", f_source_unknown: "read before backend and profile were recorded",
21
+ f_estimated: "estimated from text size — Kiro records no token counts", f_includes_estimates: "includes estimates (Kiro)", f_cost_reported: "amount as the CLI reported it (no list price for this model)", estimatedPart: "of which estimated: {0}",
21
22
  scanning: "Scanning — totals may still grow.", updated: "Updated {0} · read every 10 min", since: "Collected since {0}", notYet: "Not collected yet",
22
23
  refresh: "Refresh",
23
24
  notMeasured: "Not measured", nm_credit_billed: "Kiro is credit-billed and records no tokens", nm_unsupported: "AgEnD can't read this CLI's usage yet", nm_no_data: "nothing read yet",
24
25
  shared: "shares its working directory with {0}; their transcripts can't be told apart",
25
- empty: "Nothing recorded yet", emptyHint: "Usage is read from Claude Code and Codex transcripts, from when the fleet started.",
26
+ empty: "Nothing recorded yet", emptyHint: "Usage is read from Claude Code, Codex, Grok, Muse, OpenCode and Antigravity, and estimated for Kiro, from when the fleet started.",
26
27
  blocked: "Not offered over the public link", blockedHint: "Usage is offered over the public link only when \"Usage report over the public link\" is on in Settings → Web dashboard — on the dashboard reached directly, on the computer running AgEnD.",
27
28
  openSettings: "Open Settings → Web dashboard on that computer",
28
29
  partialDays: "Daily detail from {0}: the earlier days in this range are too many rows to send. The rows and totals above cover the whole range; the trend, the heatmap and the CSV start at {0}.",
@@ -42,14 +43,15 @@ register("fusage", {
42
43
  range: "期間", today: "今天", r7d: "7 天", month: "本月", all: "全部", custom: "自訂", from: "從", to: "到", apply: "套用",
43
44
  group: "分組", g_instance: "Agent", g_backend: "Backend", g_model: "模型", g_profile: "憑證 profile", g_team: "Team(依目前設定)",
44
45
  csv: "下載 CSV", basis: "依牌價換算的 API 等值(查證日期 {0})——不是實際花費。訂閱方案不按 token 計費。",
45
- amount: "API 等值", input: "輸入", output: "輸出", read: "快取讀取", write: "快取寫入", total: "token 總計", requests: "請求數", messages: "訊息數",
46
+ amount: "API 等值", input: "輸入", output: "輸出", reasoning: "推理", read: "快取讀取", write: "快取寫入", total: "token 總計", requests: "請求數", messages: "訊息數",
46
47
  notPriced: "未定價", partial: "部分", noTeam: "(不屬於任何 team)", unknown: "未知",
47
- f_cache_write_not_reported: "未回報快取寫入(Codex)——是估算", f_not_priced: "未定價:{0}", f_source_unknown: "讀取時尚未記錄 backend 與 profile",
48
+ f_cache_write_not_reported: "未回報快取寫入(Codex、Muse)——是估算", f_not_priced: "未定價:{0}", f_source_unknown: "讀取時尚未記錄 backend 與 profile",
49
+ f_estimated: "依文字長度估算——Kiro 不記錄 token 數", f_includes_estimates: "含估算值(Kiro)", f_cost_reported: "金額為 CLI 自行回報(價目表沒有此模型)", estimatedPart: "其中估算:{0}",
48
50
  scanning: "掃描中——總數可能還會增加。", updated: "更新於 {0} · 每 10 分鐘讀取一次", since: "自 {0} 起收集", notYet: "尚未收集",
49
51
  refresh: "重新整理",
50
52
  notMeasured: "未量測", nm_credit_billed: "Kiro 以 credit 計費,不記錄 token", nm_unsupported: "AgEnD 目前還讀不到這個 CLI 的用量", nm_no_data: "尚未讀到任何資料",
51
53
  shared: "與 {0} 共用工作目錄,無法分辨各自的 transcript",
52
- empty: "還沒有任何紀錄", emptyHint: "用量從 Claude Code 與 Codex 的 transcript 讀取,自 fleet 啟動起計。",
54
+ empty: "還沒有任何紀錄", emptyHint: "用量從 Claude Code、Codex、Grok、Muse、OpenCode 與 Antigravity 讀取,Kiro 則為估算,自 fleet 啟動起計。",
53
55
  blocked: "公開連結上不提供", blockedHint: "只有在設定 → 網頁儀表板裡開啟「透過公開連結提供用量報告」時,公開連結才會提供用量;這個設定要在執行 AgEnD 的那台電腦上、直接開啟的儀表板裡變更。",
54
56
  openSettings: "在那台電腦上開啟設定 → 網頁儀表板",
55
57
  partialDays: "每日明細從 {0} 起:這段期間更早的日子資料列太多,無法一次送出。上方的各列與總計涵蓋整段期間;趨勢、熱度圖與 CSV 則從 {0} 開始。",
@@ -95,11 +97,11 @@ export function keyText(group, key) {
95
97
  const writes = (r) => (r.cacheWrite5m || 0) + (r.cacheWrite1h || 0) + (r.cacheWrite || 0);
96
98
  function flagText(f, r) {
97
99
  if (f === "not_priced") return tu("f_not_priced", (r.unpriced || []).join(", "));
98
- return ["cache_write_not_reported", "source_unknown"].includes(f) ? tu(`f_${f}`) : f;
100
+ return ["cache_write_not_reported", "source_unknown", "estimated", "includes_estimates", "cost_reported"].includes(f) ? tu(`f_${f}`) : f;
99
101
  }
100
102
 
101
103
  // ── CSV (design §4): the daily rows of this same answer; messages on their own rows (they are per agent, not per model).
102
- const CSV_COLUMNS = ["date", "zone", "instance", "backend", "model", "tier", "profile", "input", "output", "cache_read", "cache_write_5m", "cache_write_1h", "cache_write", "requests", "messages", "amount", "basis", "flags"];
104
+ const CSV_COLUMNS = ["date", "zone", "instance", "backend", "model", "tier", "profile", "input", "output", "reasoning", "cache_read", "cache_write_5m", "cache_write_1h", "cache_write", "requests", "messages", "amount", "basis", "flags", "estimated"];
103
105
  /** One CSV field: quoted when it must be, and never read as a formula by a spreadsheet (=, +, -, @, tab, CR first). */
104
106
  export function csvField(v) {
105
107
  let s = v === null || v === undefined ? "" : String(v);
@@ -109,11 +111,11 @@ export function csvField(v) {
109
111
  export function usageCsv(report) {
110
112
  const lines = [CSV_COLUMNS.join(",")];
111
113
  for (const d of report.daily || []) {
112
- lines.push([d.date, d.zone, d.instance, d.backend, d.model, d.tier, d.profile, d.input, d.output, d.cacheRead, d.cacheWrite5m, d.cacheWrite1h, d.cacheWrite,
113
- d.requests, "", d.amount === null ? "" : d.amount.toFixed(6), report.basis, (d.flags || []).join(" ")].map(csvField).join(","));
114
+ lines.push([d.date, d.zone, d.instance, d.backend, d.model, d.tier, d.profile, d.input, d.output, d.reasoning, d.cacheRead, d.cacheWrite5m, d.cacheWrite1h, d.cacheWrite,
115
+ d.requests, "", d.amount === null ? "" : d.amount.toFixed(6), report.basis, (d.flags || []).join(" "), d.estimated ? "yes" : "no"].map(csvField).join(","));
114
116
  }
115
117
  for (const m of report.messagesDaily || []) {
116
- lines.push([m.date, report.zone, m.instance, "", "", "", "", "", "", "", "", "", "", "", m.count, "", report.basis, ""].map(csvField).join(","));
118
+ lines.push([m.date, report.zone, m.instance, "", "", "", "", "", "", "", "", "", "", "", "", m.count, "", report.basis, "", ""].map(csvField).join(","));
117
119
  }
118
120
  return `${lines.join("\r\n")}\r\n`;
119
121
  }
@@ -151,7 +153,7 @@ export function levels(values) {
151
153
  return (v) => (!(v > 0) ? 0 : v <= cut[0] ? 1 : v <= cut[1] ? 2 : v <= cut[2] ? 3 : 4);
152
154
  }
153
155
 
154
- const tokensOf = (d) => d.input + d.output + d.cacheRead + d.cacheWrite5m + d.cacheWrite1h + d.cacheWrite;
156
+ const tokensOf = (d) => d.input + d.output + (d.reasoning || 0) + d.cacheRead + d.cacheWrite5m + d.cacheWrite1h + d.cacheWrite;
155
157
  /**
156
158
  * Each day of the answer: its tokens (whether it was used at all), the priced part of its amount, whether part of it is
157
159
  * not priced, and its parts by zone (a day folded before the fleet's timezone changed keeps its own zone, §5.3).
@@ -218,7 +220,7 @@ export function thinXLabels(n, slotPx, labelWidthPx) {
218
220
  /** The trend's series: the top `TOP` agents by the measure over the range, then "others"; one value per date. */
219
221
  export function trendSeries(report, dates) {
220
222
  const priced = report.totals && report.totals.amount !== null && report.totals.amount > 0;
221
- const measure = (d) => (priced ? d.amount || 0 : d.input + d.output + d.cacheRead + d.cacheWrite5m + d.cacheWrite1h + d.cacheWrite);
223
+ const measure = (d) => (priced ? d.amount || 0 : tokensOf(d));
222
224
  const byAgent = new Map();
223
225
  for (const d of report.daily || []) byAgent.set(d.instance, (byAgent.get(d.instance) || 0) + measure(d));
224
226
  const ranked = [...byAgent.entries()].filter(([, v]) => v > 0).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
@@ -327,6 +329,7 @@ function Row({ r, group, max, measure }) {
327
329
  <td data-label=${tu("amount")} class=${`num${r.amount === null ? " muted" : ""}`}>${amountText(r)}</td>
328
330
  <td data-label=${tu("input")} class="num">${tokens(r.input)}</td>
329
331
  <td data-label=${tu("output")} class="num">${tokens(r.output)}</td>
332
+ <td data-label=${tu("reasoning")} class="num">${r.reasoningReported === false ? "—" : tokens(r.reasoning || 0)}</td>
330
333
  <td data-label=${tu("read")} class="num">${tokens(r.cacheRead)}</td>
331
334
  <td data-label=${tu("write")} class="num">${r.flags.includes("cache_write_not_reported") && writes(r) === 0 ? "—" : tokens(writes(r))}</td>
332
335
  <td data-label=${tu("total")} class="num">${tokens(r.total)}</td>
@@ -379,13 +382,14 @@ export function UsageReport({ report, choice, setChoice, refresh, fetchedAt }) {
379
382
  ${report.scanning.active && (!report.scanning.caughtUp || report.scanning.pendingBytes > 0) ? html` <span class="us-scan" role="status">${tu("scanning")} <button type="button" class="btn btn-sm" onClick=${refresh}>${tu("refresh")}</button></span>` : null}</p>
380
383
  ${empty ? html`<${Empty} icon="chart" title=${tu("empty")} hint=${tu("emptyHint")} />` : html`
381
384
  <dl class="us-totals card">
382
- <div class="ch-metric"><dt>${tu("amount")}</dt><dd>${amountText(report.totals)}</dd></div>
385
+ <div class="ch-metric"><dt>${tu("amount")}</dt><dd>${amountText(report.totals)}${report.totals.estimated
386
+ ? html`<span class="us-est">${report.totals.amountEstimated !== null && report.totals.amountEstimated !== undefined ? tu("estimatedPart", money(report.totals.amountEstimated)) : tu("f_includes_estimates")}</span>` : null}</dd></div>
383
387
  <div class="ch-metric"><dt>${tu("total")}</dt><dd>${tokens(report.totals.total)}</dd></div>
384
388
  <div class="ch-metric"><dt>${tu("requests")}</dt><dd>${n(report.totals.requests)}</dd></div>
385
389
  <div class="ch-metric"><dt>${tu("messages")}</dt><dd>${report.totals.messages === null ? "—" : n(report.totals.messages)}</dd></div>
386
390
  </dl>
387
391
  ${rows.length ? html`<table class="us-table"><thead><tr><th scope="col">${tu(`g_${group}`)}</th><th scope="col" class="num">${tu("amount")}</th>
388
- <th scope="col" class="num">${tu("input")}</th><th scope="col" class="num">${tu("output")}</th><th scope="col" class="num">${tu("read")}</th><th scope="col" class="num">${tu("write")}</th>
392
+ <th scope="col" class="num">${tu("input")}</th><th scope="col" class="num">${tu("output")}</th><th scope="col" class="num">${tu("reasoning")}</th><th scope="col" class="num">${tu("read")}</th><th scope="col" class="num">${tu("write")}</th>
389
393
  <th scope="col" class="num">${tu("total")}</th><th scope="col" class="num">${tu("requests")}</th><th scope="col" class="num">${tu("messages")}</th></tr></thead>
390
394
  <tbody>${rows.map((r) => html`<${Row} key=${r.key} r=${r} group=${group} max=${max} measure=${measure} />`)}</tbody></table>`
391
395
  : html`<p class="note">${tu("noRows")}</p>`}
@@ -0,0 +1,145 @@
1
+ // #2636: Office share links on the dashboard — the Office's Share… dialog (make one: which office, how long, whether
2
+ // agents' own lines show; then its URL to copy) and the list of open ones (Settings → Access & security, and under the
3
+ // dialog's form): each with its office, when it ends, whether lines show and who made it, Revoke and Revoke all.
4
+ // GET / POST /ui/office-share, DELETE /ui/office-share/<id|all> (web-api.ts): an admin session on the dashboard reached
5
+ // directly only; the public link never offers these.
6
+ import { html, useEffect, useState } from "/assets/app-html.js";
7
+ import { t, register } from "/assets/app-i18n.js";
8
+ import { Dialog } from "/assets/ui-dialog.js";
9
+ import { toast } from "/assets/ui-toast.js";
10
+
11
+ register("oshare", {
12
+ en: {
13
+ share: "Share…", title: "Share the office", lead: "Anyone with the link can watch this office live — names and states, nothing else — until it ends. No sign-in.",
14
+ office: "Office", allOffices: "All offices", how: "For", text: "Include agents' own status lines", create: "Create link", creating: "Starting the link…",
15
+ made: "Anyone with this link can watch until {0}.", copy: "Copy link", copied: "Link copied", open: "Open links", none: "No share links are open.",
16
+ ends: "until {0}", withText: "with status lines", by: "by {0}", revoke: "Revoke", revokeAll: "Revoke all", close: "Close", failed: "The link could not be made.",
17
+ m15: "15 minutes", m30: "30 minutes", h1: "1 hour", h2: "2 hours", h4: "4 hours", h8: "8 hours", h24: "24 hours",
18
+ e_disabled: "Office share links are off on this fleet (web.office_share.enabled: false).", e_office: "That office no longer exists.",
19
+ e_duration: "That is longer than this fleet allows (web.office_share.max_hours).", e_too_many: "At most 10 share links can be open at once: revoke one first.",
20
+ e_rate: "Cloudflare is limiting new quick tunnels right now. Try again in a few minutes.", e_tunnel: "The share link's tunnel did not start ({0}). Try again later.",
21
+ cardTitle: "Office share links", cardHint: "Read-only links to the live Office view, made from Fleet → Org chart → Office → Share…. Each ends at its time; revoke one to end it now.",
22
+ },
23
+ "zh-TW": {
24
+ share: "分享…", title: "分享辦公室", lead: "拿到連結的人都能即時觀看這間辦公室(只有名稱與狀態),直到連結結束,不需要登入。",
25
+ office: "辦公室", allOffices: "所有辦公室", how: "時間", text: "包含 agent 自己的狀態文字", create: "建立連結", creating: "正在啟動連結…",
26
+ made: "拿到這個連結的人可以觀看到 {0}。", copy: "複製連結", copied: "已複製連結", open: "開啟中的連結", none: "目前沒有開啟中的分享連結。",
27
+ ends: "到 {0} 為止", withText: "含狀態文字", by: "由 {0} 建立", revoke: "撤銷", revokeAll: "全部撤銷", close: "關閉", failed: "無法建立連結。",
28
+ m15: "15 分鐘", m30: "30 分鐘", h1: "1 小時", h2: "2 小時", h4: "4 小時", h8: "8 小時", h24: "24 小時",
29
+ e_disabled: "這個 fleet 已關閉辦公室分享連結(web.office_share.enabled: false)。", e_office: "這間辦公室已不存在。",
30
+ e_duration: "超過這個 fleet 允許的時間(web.office_share.max_hours)。", e_too_many: "同時最多 10 個分享連結:先撤銷一個。",
31
+ e_rate: "Cloudflare 目前限制新的臨時通道,請過幾分鐘再試。", e_tunnel: "分享連結的通道沒有啟動({0}),請稍後再試。",
32
+ cardTitle: "辦公室分享連結", cardHint: "即時辦公室畫面的唯讀連結,可在 Fleet → 組織圖 → 辦公室 → 分享… 建立。每個連結到時間就結束;撤銷可立即結束。",
33
+ },
34
+ });
35
+ const to = (k, ...v) => t(`oshare.${k}`, ...v);
36
+ const DURATIONS = [["m15", 15], ["m30", 30], ["h1", 60], ["h2", 120], ["h4", 240], ["h8", 480], ["h24", 1440]];
37
+ const JSON_HEADERS = { "Content-Type": "application/json" };
38
+ const when = (ms) => { try { return new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }).format(new Date(ms)); } catch { return ""; } };
39
+
40
+ /** What a refusal says (the host's `error` and `reason`). */
41
+ export function refusalText(d) {
42
+ const e = d && d.error;
43
+ if (e === "tunnel") return d.reason === "rate-limited" ? to("e_rate") : to("e_tunnel", d.reason || "unknown");
44
+ return ["disabled", "office", "duration", "too_many"].includes(e) ? to(`e_${e}`) : to("failed");
45
+ }
46
+
47
+ /** The open shares, read (and re-read after a change): { enabled, shares } or null while unread / unavailable. */
48
+ export function useShares(get = globalThis.fetch, rev = 0) {
49
+ const [d, setD] = useState(null);
50
+ useEffect(() => {
51
+ let live = true;
52
+ get("/ui/office-share", { method: "GET", headers: JSON_HEADERS }).then((r) => (r.ok ? r.json() : null)).then((v) => { if (live) setD(v); }, () => { if (live) setD(null); });
53
+ return () => { live = false; };
54
+ }, [rev]);
55
+ return d;
56
+ }
57
+
58
+ /** The open shares with Revoke (and Revoke all); `names`: office id → name. */
59
+ export function ShareList({ shares, names = {}, get = globalThis.fetch, onChange }) {
60
+ const [busy, setBusy] = useState(false);
61
+ const revoke = async (id) => {
62
+ setBusy(true);
63
+ try { await get(`/ui/office-share/${id}`, { method: "DELETE", headers: JSON_HEADERS }); } catch { /* the list is read again */ }
64
+ setBusy(false);
65
+ onChange && onChange();
66
+ };
67
+ if (!shares || !shares.length) return html`<p class="muted os-none">${to("none")}</p>`;
68
+ return html`<div class="os-list">
69
+ <ul class="os-rows">${shares.map((s) => html`<li key=${s.id} class="os-row">
70
+ <span class="os-what"><strong>${s.office === "all" ? to("allOffices") : names[s.office] || s.office_name || s.office}</strong>
71
+ <span class="muted"> · ${to("ends", when(s.expiresAt))}${s.text ? ` · ${to("withText")}` : ""}</span></span>
72
+ <button type="button" class="btn btn-sm" disabled=${busy} onClick=${() => revoke(s.id)}>${to("revoke")}</button>
73
+ </li>`)}</ul>
74
+ ${shares.length > 1 ? html`<button type="button" class="btn btn-sm danger os-all" disabled=${busy} onClick=${() => revoke("all")}>${to("revokeAll")}</button>` : null}
75
+ </div>`;
76
+ }
77
+
78
+ /** Share…: make a link for one office (the one shown, by default) or all of them. `offices`: the stored ones. */
79
+ export function ShareDialog({ offices = [], current = null, get = globalThis.fetch, onClose }) {
80
+ const [office, setOffice] = useState(current && offices.some((o) => o.id === current) ? current : "all");
81
+ const [minutes, setMinutes] = useState(60);
82
+ const [text, setText] = useState(false);
83
+ const [busy, setBusy] = useState(false);
84
+ const [made, setMade] = useState(null);
85
+ const [error, setError] = useState("");
86
+ const [rev, setRev] = useState(0);
87
+ const list = useShares(get, rev);
88
+ const names = Object.fromEntries(offices.map((o) => [o.id, o.name]));
89
+ const create = async () => {
90
+ setBusy(true); setError("");
91
+ try {
92
+ const r = await get("/ui/office-share", { method: "POST", headers: JSON_HEADERS, body: JSON.stringify({ office, minutes, text }) });
93
+ const d = await r.json().catch(() => ({}));
94
+ if (r.ok && d && typeof d.url === "string") setMade(d); else setError(refusalText(d));
95
+ } catch { setError(to("failed")); }
96
+ setBusy(false);
97
+ setRev((n) => n + 1);
98
+ };
99
+ const copy = async () => { try { await navigator.clipboard.writeText(made.url); toast(to("copied")); } catch { /* the link is on screen to copy by hand */ } };
100
+ const actions = made ? html`<button type="button" class="btn" onClick=${onClose}>${to("close")}</button>`
101
+ : html`<button type="button" class="btn" onClick=${onClose} disabled=${busy}>${to("close")}</button>
102
+ <button type="button" class="btn btn-primary" onClick=${create} disabled=${busy}>${busy ? to("creating") : to("create")}</button>`;
103
+ return html`<${Dialog} title=${to("title")} onClose=${onClose} busy=${busy} actions=${actions} wide=${true}>
104
+ <div class="os">
105
+ <p class="muted">${to("lead")}</p>
106
+ ${made ? html`<div class="os-made">
107
+ <input class="input mono os-url" readonly value=${made.url} aria-label=${to("copy")} onFocus=${(e) => e.target.select && e.target.select()} />
108
+ <button type="button" class="btn btn-sm" onClick=${copy}>${to("copy")}</button>
109
+ <p class="note">${to("made", when(made.share.expiresAt))}</p>
110
+ </div>` : html`<div class="os-form">
111
+ <label class="field"><span>${to("office")}</span>
112
+ <select class="tb-select" value=${office} onChange=${(e) => setOffice(e.target.value)} disabled=${busy}>
113
+ ${offices.length > 1 || !offices.length ? html`<option value="all">${to("allOffices")}</option>` : null}
114
+ ${offices.map((o) => html`<option key=${o.id} value=${o.id}>${o.name}</option>`)}
115
+ </select></label>
116
+ <label class="field"><span>${to("how")}</span>
117
+ <select class="tb-select" value=${String(minutes)} onChange=${(e) => setMinutes(Number(e.target.value))} disabled=${busy}>
118
+ ${DURATIONS.map(([k, m]) => html`<option key=${k} value=${String(m)}>${to(k)}</option>`)}
119
+ </select></label>
120
+ <label class="check"><input type="checkbox" checked=${text} onChange=${(e) => setText(e.target.checked)} disabled=${busy} /> ${to("text")}</label>
121
+ ${error ? html`<p class="err os-err" role="alert">${error}</p>` : null}
122
+ </div>`}
123
+ <h3 class="os-head">${to("open")}</h3>
124
+ <${ShareList} shares=${list && list.shares} names=${names} get=${get} onChange=${() => setRev((n) => n + 1)} />
125
+ </div>
126
+ <//>`;
127
+ }
128
+
129
+ /** Settings → Access & security: the open share links, with Revoke (made from the Office's Share…). */
130
+ export function OfficeSharesCard({ get = globalThis.fetch }) {
131
+ const [rev, setRev] = useState(0);
132
+ const d = useShares(get, rev);
133
+ if (!d) return null; // not kept on this fleet, or not this session's to see
134
+ return html`<section class="card os-card"><h3>${to("cardTitle")}</h3>
135
+ <p class="note">${d.enabled === false ? to("e_disabled") : to("cardHint")}</p>
136
+ <${ShareList} shares=${d.shares} get=${get} onChange=${() => setRev((n) => n + 1)} />
137
+ </section>`;
138
+ }
139
+
140
+ /** The Office toolbar's Share… button (shown to an admin on the dashboard reached directly, when the fleet offers it). */
141
+ export function ShareButton({ offices, current, get, disabled = false }) {
142
+ const [open, setOpen] = useState(false);
143
+ return html`<button type="button" class="btn btn-sm oo-share" disabled=${disabled} onClick=${() => setOpen(true)}>${to("share")}</button>
144
+ ${open ? html`<${ShareDialog} offices=${offices} current=${current} get=${get} onClose=${() => setOpen(false)} />` : null}`;
145
+ }
@@ -0,0 +1,116 @@
1
+ // #2636: an Office share link's page (/o/<token> on the share tunnel, src/office-share.ts) — the live Office view for
2
+ // people outside the fleet, read-only, with no sign-in. The same Office as Fleet → Org chart → Office (fleet-office.js),
3
+ // fed by the share's own reads instead of the app shell's: its status and structure (/o/<t>/state, every POLL_MS while
4
+ // the page is shown), the offices, acts and skin packs (the Office's own reads, sent to the share's addresses by the
5
+ // lease's fetch). Nothing opens a chat, edits or writes; there is no other page. When the share ends (revoked, expired,
6
+ // its office deleted) its reads answer 404 and the page says so and stops.
7
+ import { html, render, useEffect, useMemo, useState } from "/assets/app-html.js";
8
+ import { appStore, useStore } from "/assets/app-store.js";
9
+ import { createLease } from "/assets/app-ctx.js";
10
+ import { t, register } from "/assets/app-i18n.js";
11
+ import { buildOrgView } from "./fleet-org.js";
12
+ import { createTrafficStore, POLL_MS } from "./fleet-traffic.js";
13
+ import { Office } from "./fleet-office.js";
14
+ import { ALL_ID } from "./fleet-office-overview.js";
15
+
16
+ register("share", {
17
+ en: { title: "Office", live: "Live view", ends: "until {0}", readOnly: "Read-only: names and states only.", ended: "This Office link has ended.", loading: "Loading the office…", offline: "Can't reach the office right now. Trying again…" },
18
+ "zh-TW": { title: "辦公室", live: "即時畫面", ends: "到 {0} 為止", readOnly: "唯讀:只顯示名稱與狀態。", ended: "這個辦公室連結已結束。", loading: "正在載入辦公室…", offline: "目前連不上辦公室,正在重試…" },
19
+ });
20
+ const to = (k, ...v) => t(`share.${k}`, ...v);
21
+
22
+ /** The share's own address: `/o/<token>` (the page's path). */
23
+ export function shareBase(pathname) {
24
+ const m = /^\/o\/([A-Za-z0-9_-]{43})\/?$/.exec(pathname || "");
25
+ return m ? `/o/${m[1]}` : null;
26
+ }
27
+
28
+ /** The Office's reads, at the share's addresses (anything else is not the share's to answer: refused here). */
29
+ export function shareUrl(base, path) {
30
+ const p = String(path);
31
+ if (p === "/ui/offices") return `${base}/offices`;
32
+ if (p === "/ui/office-acts") return `${base}/office-acts`;
33
+ if (p === "/ui/office-skins" || p.startsWith("/ui/office-skins/") || p.startsWith("/ui/office-skins?")) return `${base}${p.slice(3)}`;
34
+ return null;
35
+ }
36
+
37
+ /** A lease whose fetch reads the share's addresses (createLease's timers), refusing any other. */
38
+ export function shareLease(base, timers = globalThis) {
39
+ return createLease({
40
+ setTimeout: (...a) => timers.setTimeout(...a), clearTimeout: (h) => timers.clearTimeout(h),
41
+ setInterval: (...a) => timers.setInterval(...a), clearInterval: (h) => timers.clearInterval(h),
42
+ fetch: (path, opts) => {
43
+ const url = shareUrl(base, path);
44
+ return url ? timers.fetch(url, opts) : Promise.resolve(new Response("", { status: 404 }));
45
+ },
46
+ });
47
+ }
48
+
49
+ /** The share's /state into the app store's shape (the status frame's, as app-store.js takes it). */
50
+ export function appFromState(d) {
51
+ const instances = Array.isArray(d && d.instances) ? d.instances : [];
52
+ const exec = {}, awaiting = {};
53
+ for (const i of instances) {
54
+ exec[i.name] = (i.execution_state !== undefined ? i.execution_state : i.state) ?? null;
55
+ if (i.state === "awaiting_input") awaiting[i.name] = "";
56
+ }
57
+ return { ready: true, instances, exec, awaiting, needs: Array.isArray(d && d.needs) ? d.needs : [], connection: "polling" };
58
+ }
59
+
60
+ const clock = (ms) => {
61
+ try { return new Intl.DateTimeFormat(undefined, { hour: "2-digit", minute: "2-digit" }).format(new Date(ms)); } catch { return ""; }
62
+ };
63
+
64
+ export function SharePage({ base, timers = globalThis, pollMs = POLL_MS }) {
65
+ const lease = useMemo(() => shareLease(base, timers), [base]);
66
+ const traffic = useMemo(createTrafficStore, []);
67
+ const [state, setState] = useState({ phase: "loading" }); // loading | live | ended | offline
68
+ const [items, setItems] = useState([]);
69
+ useEffect(() => {
70
+ let stopped = false;
71
+ const read = async () => {
72
+ try {
73
+ const r = await timers.fetch(`${base}/state`, { method: "GET", headers: { Accept: "application/json" } });
74
+ if (stopped || !lease.current()) return;
75
+ if (r.status === 404) { stopped = true; setState({ phase: "ended" }); return; }
76
+ if (!r.ok) { setState((s) => (s.phase === "live" ? s : { phase: "offline" })); return; }
77
+ const d = await r.json();
78
+ if (stopped || !lease.current()) return;
79
+ appStore.set((s) => ({ ...s, ...appFromState(d) }));
80
+ if (d.traffic && traffic.load(d.traffic)) setItems(traffic.items());
81
+ setState({ phase: "live", org: d.org, office: typeof d.office === "string" ? d.office : null, ends: typeof d.ends === "number" ? d.ends : null });
82
+ } catch { if (!stopped) setState((s) => (s.phase === "live" ? s : { phase: "offline" })); }
83
+ };
84
+ void read();
85
+ const hs = [
86
+ lease.interval(() => { if (!stopped && !globalThis.document?.hidden) void read(); }, pollMs),
87
+ lease.interval(() => { if (traffic.sweep()) setItems(traffic.items()); }, 1000),
88
+ ];
89
+ return () => { stopped = true; for (const h of hs) lease.clear(h); };
90
+ }, [lease]);
91
+ useEffect(() => () => lease.dispose(), [lease]);
92
+ const app = useStore(appStore);
93
+ const view = useMemo(() => (state.phase === "live" ? buildOrgView(state.org, app) : null), [state, app.instances, app.needs]);
94
+ if (state.phase === "ended") return html`<main class="share-page share-ended"><p>${to("ended")}</p></main>`;
95
+ return html`<main class="share-page">
96
+ <header class="share-head">
97
+ <strong>${to("title")}</strong>
98
+ <span class="muted">${to("live")}${state.ends ? ` · ${to("ends", clock(state.ends))}` : ""}</span>
99
+ <span class="muted share-note">${to("readOnly")}</span>
100
+ </header>
101
+ ${state.phase === "offline" ? html`<p class="note share-note" role="status">${to("offline")}</p>` : null}
102
+ ${view ? html`<div class="share-stage"><${Office} view=${view} traffic=${items} lease=${lease} assetUrl=${(p) => shareUrl(base, p) || p}
103
+ opening=${state.office === "all" ? ALL_ID : state.office || undefined} /></div>`
104
+ : html`<p class="muted share-loading" role="status">${to("loading")}</p>`}
105
+ </main>`;
106
+ }
107
+
108
+ /** Mount on the page (the module's entry): the share's address from the path, else nothing to show. */
109
+ export function mount(root = globalThis.document?.getElementById("app")) {
110
+ const base = shareBase(globalThis.location?.pathname);
111
+ if (!root || !base) return;
112
+ globalThis.document.body.dataset.webTransport = "poll";
113
+ render(html`<${SharePage} base=${base} />`, root);
114
+ }
115
+
116
+ if (globalThis.document?.getElementById?.("app")?.dataset?.share === "1") mount();