@songsid/agend 2.4.0-beta.15 → 2.4.0-beta.16

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 (158) hide show
  1. package/dist/accounts-profiles.d.ts +1 -1
  2. package/dist/accounts-view.d.ts +3 -0
  3. package/dist/accounts-view.js.map +1 -1
  4. package/dist/auth-api.js +4 -0
  5. package/dist/auth-api.js.map +1 -1
  6. package/dist/backend/claude-code.d.ts +6 -1
  7. package/dist/backend/claude-code.js +63 -8
  8. package/dist/backend/claude-code.js.map +1 -1
  9. package/dist/backend/kiro.js +6 -1
  10. package/dist/backend/kiro.js.map +1 -1
  11. package/dist/backend/types.d.ts +2 -0
  12. package/dist/backend/types.js.map +1 -1
  13. package/dist/backend-command.d.ts +4 -2
  14. package/dist/backend-command.js +3 -0
  15. package/dist/backend-command.js.map +1 -1
  16. package/dist/browser-backend-signins.d.ts +1 -0
  17. package/dist/browser-backend-signins.js +3 -1
  18. package/dist/browser-backend-signins.js.map +1 -1
  19. package/dist/build-provenance.json +1 -1
  20. package/dist/classic-channel-manager.d.ts +1 -0
  21. package/dist/classic-channel-manager.js +4 -1
  22. package/dist/classic-channel-manager.js.map +1 -1
  23. package/dist/claude-credential-change.d.ts +22 -0
  24. package/dist/claude-credential-change.js +47 -0
  25. package/dist/claude-credential-change.js.map +1 -0
  26. package/dist/claude-credential-launch.d.ts +62 -0
  27. package/dist/claude-credential-launch.js +304 -0
  28. package/dist/claude-credential-launch.js.map +1 -0
  29. package/dist/claude-credential-runner.d.ts +1 -0
  30. package/dist/claude-credential-runner.js +56 -0
  31. package/dist/claude-credential-runner.js.map +1 -0
  32. package/dist/claude-credential-vault.d.ts +51 -0
  33. package/dist/claude-credential-vault.js +252 -0
  34. package/dist/claude-credential-vault.js.map +1 -0
  35. package/dist/claude-setup-token-transport.d.ts +9 -0
  36. package/dist/claude-setup-token-transport.js +82 -0
  37. package/dist/claude-setup-token-transport.js.map +1 -0
  38. package/dist/claude-setup-token.d.ts +51 -0
  39. package/dist/claude-setup-token.js +83 -0
  40. package/dist/claude-setup-token.js.map +1 -0
  41. package/dist/cli-audited.js +7 -6
  42. package/dist/cli-audited.js.map +1 -1
  43. package/dist/command-report.d.ts +11 -0
  44. package/dist/command-report.js +2 -0
  45. package/dist/command-report.js.map +1 -0
  46. package/dist/config-validator.js +9 -0
  47. package/dist/config-validator.js.map +1 -1
  48. package/dist/config.js +4 -2
  49. package/dist/config.js.map +1 -1
  50. package/dist/daemon.d.ts +5 -0
  51. package/dist/daemon.js +59 -3
  52. package/dist/daemon.js.map +1 -1
  53. package/dist/fleet-level-config.d.ts +1 -1
  54. package/dist/fleet-level-config.js +1 -0
  55. package/dist/fleet-level-config.js.map +1 -1
  56. package/dist/fleet-manager.d.ts +39 -2
  57. package/dist/fleet-manager.js +383 -19
  58. package/dist/fleet-manager.js.map +1 -1
  59. package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -1
  60. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +18 -5
  61. package/dist/host-monitoring-config.d.ts +14 -0
  62. package/dist/host-monitoring-config.js +31 -0
  63. package/dist/host-monitoring-config.js.map +1 -0
  64. package/dist/hub/group-policy/resources.d.ts +1 -1
  65. package/dist/instance-config-impact.js +1 -1
  66. package/dist/instance-config-impact.js.map +1 -1
  67. package/dist/instructions.js +1 -0
  68. package/dist/instructions.js.map +1 -1
  69. package/dist/locale.d.ts +2 -0
  70. package/dist/locale.js +13 -1
  71. package/dist/locale.js.map +1 -1
  72. package/dist/office-share-page.js +1 -1
  73. package/dist/office-share-page.js.map +1 -1
  74. package/dist/profile-signins.d.ts +1 -0
  75. package/dist/profile-signins.js +3 -1
  76. package/dist/profile-signins.js.map +1 -1
  77. package/dist/public-web-gateway.js +2 -0
  78. package/dist/public-web-gateway.js.map +1 -1
  79. package/dist/public-web-link.d.ts +21 -2
  80. package/dist/public-web-link.js +22 -2
  81. package/dist/public-web-link.js.map +1 -1
  82. package/dist/settings-api.d.ts +12 -0
  83. package/dist/settings-api.js +146 -7
  84. package/dist/settings-api.js.map +1 -1
  85. package/dist/settings-change.js +2 -0
  86. package/dist/settings-change.js.map +1 -1
  87. package/dist/settings-effect.js +13 -1
  88. package/dist/settings-effect.js.map +1 -1
  89. package/dist/topic-commands.d.ts +7 -1
  90. package/dist/topic-commands.js +98 -88
  91. package/dist/topic-commands.js.map +1 -1
  92. package/dist/types.d.ts +2 -0
  93. package/dist/ui/accounts-view.js +12 -6
  94. package/dist/ui/backend-signin.js +3 -1
  95. package/dist/ui/chat-commands.js +2 -0
  96. package/dist/ui/chat-popout-transport.js +49 -19
  97. package/dist/ui/chat-popout.js +15 -1
  98. package/dist/ui/chat-store.js +1 -1
  99. package/dist/ui/claude-credentials.js +112 -0
  100. package/dist/ui/claude-setup-token.js +36 -0
  101. package/dist/ui/contact-auth-client.js +7 -2
  102. package/dist/ui/contact-auth-strings.js +45 -14
  103. package/dist/ui/contact-authorizations.js +47 -26
  104. package/dist/ui/contact-needs.js +4 -4
  105. package/dist/ui/fleet-canvas.js +3 -2
  106. package/dist/ui/fleet-office-card.js +414 -41
  107. package/dist/ui/fleet-office-dialogue.js +3 -3
  108. package/dist/ui/fleet-office-pack.d.ts +67 -1
  109. package/dist/ui/fleet-office-pack.js +412 -18
  110. package/dist/ui/fleet-office-play.js +262 -3
  111. package/dist/ui/fleet-office-skin.js +67 -20
  112. package/dist/ui/fleet-office-zones.js +19 -1
  113. package/dist/ui/fleet-office.js +393 -47
  114. package/dist/ui/office-share-page.js +5 -1
  115. package/dist/ui/panel-chat.js +47 -3
  116. package/dist/ui/panel-fleet.js +1 -1
  117. package/dist/ui/panel-settings.js +2 -1
  118. package/dist/ui/preview-popout.js +134 -0
  119. package/dist/ui/reply-file-preview.js +1 -1
  120. package/dist/ui/settings-host-monitoring.js +51 -0
  121. package/dist/ui/settings-shared.js +3 -2
  122. package/dist/ui/shared/app.css +211 -27
  123. package/dist/ui/shared/app.js +7 -1
  124. package/dist/ui/shared/chat-strings.js +8 -2
  125. package/dist/ui/shared/info-tip.js +64 -0
  126. package/dist/ui/shared/office-dialogue.css +12 -0
  127. package/dist/ui/shared/preview-panel.js +44 -18
  128. package/dist/ui/shared/preview-popout.css +11 -0
  129. package/dist/ui/shared/theme.js +11 -1
  130. package/dist/ui/shared/usage-dialog.js +9 -34
  131. package/dist/ui/shared/view-strings.js +2 -0
  132. package/dist/usage/i18n-keys.d.ts +1 -1
  133. package/dist/usage/i18n-keys.js +1 -1
  134. package/dist/usage/i18n-keys.js.map +1 -1
  135. package/dist/usage/providers.d.ts +1 -0
  136. package/dist/usage/providers.js +14 -1
  137. package/dist/usage/providers.js.map +1 -1
  138. package/dist/usage/usage-api.js +5 -2
  139. package/dist/usage/usage-api.js.map +1 -1
  140. package/dist/web-api.d.ts +4 -1
  141. package/dist/web-api.js +29 -9
  142. package/dist/web-api.js.map +1 -1
  143. package/dist/web-claude-credentials.d.ts +31 -0
  144. package/dist/web-claude-credentials.js +138 -0
  145. package/dist/web-claude-credentials.js.map +1 -0
  146. package/dist/web-commands.d.ts +5 -2
  147. package/dist/web-commands.js +4 -2
  148. package/dist/web-commands.js.map +1 -1
  149. package/dist/web-office-skins.d.ts +7 -2
  150. package/dist/web-office-skins.js +42 -16
  151. package/dist/web-office-skins.js.map +1 -1
  152. package/dist/web-session.d.ts +20 -1
  153. package/dist/web-session.js +27 -0
  154. package/dist/web-session.js.map +1 -1
  155. package/dist/web-terminal.d.ts +4 -0
  156. package/dist/web-terminal.js +16 -1
  157. package/dist/web-terminal.js.map +1 -1
  158. package/package.json +1 -1
@@ -89,7 +89,11 @@ function blobImage(blob) {
89
89
  return new Promise((resolve) => {
90
90
  if (typeof Image !== "function") { resolve(null); return; }
91
91
  const src = URL.createObjectURL(blob), im = new Image();
92
- im.onload = () => { URL.revokeObjectURL(src); resolve(im); };
92
+ const finish = () => { URL.revokeObjectURL(src); resolve(im); };
93
+ im.onload = () => {
94
+ if (typeof im.decode === "function") im.decode().then(finish, finish);
95
+ else finish();
96
+ };
93
97
  im.onerror = () => { URL.revokeObjectURL(src); resolve(null); };
94
98
  im.src = src;
95
99
  });
@@ -385,10 +385,11 @@ export function boot({ stream, boot: bootData, deps = {} }) {
385
385
  clearReply: (instance) => store.clearReply(instance),
386
386
  addToDraft: (instance, line) => { feedbackInstance = instance; recordEdit(composerField(instance)); store.addToDraft(instance, line); },
387
387
  focus: (instance = feedbackInstance) => {
388
+ import("./preview-popout.js").then(m => m.leavePreviewWindow()).catch(() => {});
388
389
  const el = composerField(instance); if (!el) return;
389
390
  el.focus();
390
391
  // After the render that shows the line: the caret at its end.
391
- setTimeout(() => { if (composerField(instance) !== el) return; try { const n = el.value.length; el.setSelectionRange(n, n); } catch { /* not a text field */ } }, 0);
392
+ setTimeout(() => { if (composerField(instance) !== el) return; el.focus(); try { const n = el.value.length; el.setSelectionRange(n, n); } catch { /* not a text field */ } }, 0);
392
393
  },
393
394
  });
394
395
  // #1604: the preview opt-in and Tour live in Settings → This device now (and on each preview card's menu).
@@ -446,6 +447,7 @@ export function ChatPanel({ route, navKey }) {
446
447
  const app = useStore(appStore);
447
448
  const name = route.instance;
448
449
  const inst = name ? app.instances.find(i => i.name === name) : null;
450
+
449
451
  useEffect(() => {
450
452
  if (store.show) {
451
453
  if (!name || !inst) return;
@@ -501,6 +503,16 @@ function useResolvedMode(lease) {
501
503
  }
502
504
 
503
505
  function ChatView({ name, inst, lease, navKey, exec, awaiting }) {
506
+ const [previewPopout, setPreviewPopout] = useState(null);
507
+ useEffect(() => {
508
+ let alive = true, owner = null; setPreviewPopout(null);
509
+ if (!name || !inst) return;
510
+ import("./preview-popout.js").then(m => m.createPreviewPopout(name)).then(value => {
511
+ if (!alive) { value?.close(); return; } owner = value;
512
+ if (owner) setPreviewPopout(() => spec => owner.open(spec));
513
+ }).catch(() => {});
514
+ return () => { alive = false; owner?.close(); };
515
+ }, [name, !!inst]);
504
516
  const pane = paneContext.usePane?.(), paneNow = useRef(pane); paneNow.current = pane;
505
517
  const bindings = useRef({ input: { current: null }, box: { current: null }, composing: false }).current;
506
518
  const ids = pane ? Object.fromEntries(["msgIn", "attachBtn", "stopBtn", "sendBtn", "cmdPalette"].map(key => [key, `pane-${pane.id}-${key}`])) : {};
@@ -657,7 +669,7 @@ function ChatView({ name, inst, lease, navKey, exec, awaiting }) {
657
669
  <${ChatAmbient} name=${name} surface=${effectSurface} part="front" />
658
670
  </div>
659
671
  <${PreviewPanel} name=${name} split=${split} msgs=${() => store.state.msgs[name] || []} subscribe=${(fn) => store.subscribe(fn)}
660
- keyOf=${msgKey} reveal=${(k) => thread.current && thread.current.reveal(k)} download=${downloadHtml} allow=${(commit) => setPreviewOptIn(true, commit)} />
672
+ popout=${previewPopout} keyOf=${msgKey} reveal=${(k) => { const owner = thread.current; import("./preview-popout.js").then(m => m.leavePreviewWindow(), () => {}).then(() => { if (lease.current() && thread.current === owner) owner?.reveal(k); }); }} download=${downloadHtml} allow=${(commit) => setPreviewOptIn(true, commit)} />
661
673
  </div>
662
674
  <${LightboxHost} owner=${view} />
663
675
  ${attachmentsSupported ? html`<div data-trust="drop" class="drop-overlay" aria-hidden="true"><div class="drop-card"><${Icon} name="attach" size=${32} /><span>${t("chat.dropHere")}</span></div></div>` : null}
@@ -996,6 +1008,38 @@ function openBackendSignIn(backend) {
996
1008
  import("./backend-signin.js").then((m) => m.openSignIn({ backend }), () => toast(t("app.loadFailed"), false));
997
1009
  }
998
1010
 
1011
+ /** Reports contain plain strings; HTM escapes every title, header, cell and note. */
1012
+ function CommandReport({ report, command }) {
1013
+ const [filter, setFilter] = useState("");
1014
+ const [expanded, setExpanded] = useState(false);
1015
+ const trigger = useRef(null);
1016
+ const wasExpanded = useRef(false);
1017
+ // The inline trigger is recreated when the modal closes; restore focus after its ref is mounted.
1018
+ useLayoutEffect(() => {
1019
+ if (wasExpanded.current && !expanded) trigger.current?.focus({ preventScroll: true });
1020
+ wasExpanded.current = expanded;
1021
+ }, [expanded]);
1022
+ const query = filter.trim().toLocaleLowerCase();
1023
+ const rows = command === "status" && query
1024
+ ? report.rows.filter(row => row.some(value => value.toLocaleLowerCase().includes(query))) : report.rows;
1025
+ const view = html`<section class=${`cmd-report cmd-report-${command}${expanded ? " cmd-report-expanded" : ""}`} aria-label=${report.title}>
1026
+ ${expanded ? null : html`<h3>${report.title}</h3>`}
1027
+ <div class="cmd-report-tools">
1028
+ ${command === "status" ? html`<label class="field"><span class="sr-only">${t("chat.cmdReportFilter")}</span>
1029
+ <input type="search" aria-label=${t("chat.cmdReportFilter")} placeholder=${t("chat.cmdReportFilter")}
1030
+ value=${filter} onInput=${e => setFilter(e.target.value)} /></label>` : null}
1031
+ ${expanded ? null : html`<button type="button" class="btn btn-sm btn-ghost" ref=${trigger} data-report-expand onClick=${() => setExpanded(true)}>${t("chat.cmdReportOpen")}</button>`}
1032
+ </div>
1033
+ ${command === "status" ? html`<p class="note cmd-report-count">${query ? t("chat.cmdReportMatches", rows.length, report.rows.length) : t("chat.cmdReportCount", report.rows.length)}${report.notes[0] ? " · " + report.notes[0] : ""}</p>` : null}
1034
+ <div class="cmd-report-body" tabIndex="0" aria-label=${report.title}>
1035
+ ${rows.length ? html`<table class=${command === "status" ? "us-table" : "cmd-metrics"}><thead><tr>${report.columns.map(label => html`<th scope="col">${label}</th>`)}</tr></thead>
1036
+ <tbody>${rows.map(row => html`<tr>${row.map((value, i) => html`<td data-label=${report.columns[i]}>${value}</td>`)}</tr>`)}</tbody></table>` : query ? html`<p class="note">${t("chat.cmdReportEmpty")}</p>` : null}
1037
+ ${(command === "status" ? report.notes.slice(1) : report.notes).map(note => html`<p class="note">${note}</p>`)}
1038
+ </div>
1039
+ </section>`;
1040
+ return expanded ? html`<div class="cmd-report-modal"><${Dialog} title=${report.title} wide onClose=${() => setExpanded(false)}>${view}</${Dialog}></div>` : view;
1041
+ }
1042
+
999
1043
  /** #1269: what the last chat command answered — its text, why it was refused, or a list to choose from. */
1000
1044
  // M-3166 PR 3: the model menu's words (kept beside their caller: a retained chat dictionary has no such words).
1001
1045
  register("modelMenu", {
@@ -1144,7 +1188,7 @@ function CommandCard({ name, lease }) {
1144
1188
  ${c.busy ? html`<span class="wait">${t("chat.cmdRunning", c.command)}</span>` : html`<button type="button" class="icon-btn" title=${t("chat.cmdDismiss")}
1145
1189
  aria-label=${t("chat.cmdDismiss")} onClick=${() => store.dismissCommand(name)}><${Icon} name="close" size=${14} /></button>`}</div></div>
1146
1190
  ${c.error ? html`<p class="cmd-text">${c.error}</p>` : null}
1147
- ${c.text ? html`<pre class="cmd-text">${c.text}</pre>` : null}
1191
+ ${c.report ? html`<${CommandReport} report=${c.report} command=${c.command} />` : c.text ? html`<pre class="cmd-text">${c.text}</pre>` : null}
1148
1192
  ${c.compact ? html`<p class="cmd-text cmd-phase">${c.compact === "running" ? t("chat.compactRunning")
1149
1193
  : c.compact === "done" ? t("chat.compactDone") : c.compact === "timeout" ? t("chat.compactTimeout", "10")
1150
1194
  : c.compact === "lost" ? t("chat.compactLost") : c.compact === "not_compacted" ? t("chat.compactNotCompacted") : t("chat.compactUnknown")}</p>` : null}
@@ -241,7 +241,7 @@ export function FleetPanel({ route, navKey }) {
241
241
  tabs; the title, search, docs and text size give way: app.css), then the page's own tools. */ ""}
242
242
  <${PanelHeader} title=${t("fleet.title")} sub=${sub} nav=${wide ? tabs("fleet-tabs") : phone ? tabs("seg fleet-phone-tabs") : null}><${DocsLink} /><${HeaderTools} navKey=${navKey} /></${PanelHeader}>
243
243
  ${wide || phone ? null : tabs("seg")}
244
- <div data-trust="panel-content" class="panel-body"><div class=${`col${tab === "tasks" || tab === "org" || tab === "cache" || tab === "usage" ? " col-wide" : ""}`}><${Body} lease=${lease} /></div></div>
244
+ <div data-trust="panel-content" class="panel-body"><div class=${`col${tab === "tasks" || tab === "org" || tab === "cache" || tab === "usage" || tab === "authorizations" ? " col-wide" : ""}`}><${Body} lease=${lease} /></div></div>
245
245
  </div>`;
246
246
  }
247
247
 
@@ -1,3 +1,4 @@
1
+ import { HostMonitoringSettings } from "./settings-host-monitoring.js";
1
2
  import { SettingsBuildVersion } from "./settings-build-version.js";
2
3
  // #1408 step 3: the Settings panel (/settings[/<section>]) — agents, connections, ClassicBot rooms, general defaults,
3
4
  // the developer YAML. Behind the session gate (/ui/js/), loaded the first time it is opened.
@@ -436,7 +437,7 @@ export function SettingsPanel({ route, navKey }) {
436
437
  : section === "agents" ? html`<${YamlLock} staged=${staged}><${Agents} ctx=${ctx} search=${search} clearSearch=${() => setSearch("")} openDialog=${toDialog} /></${YamlLock}>${SETTINGS_SECTIONS.includes("accounts") ? html`<p class="note s-agents-accounts-link">${layoutText("agentsAccountsNote")} <a href=${settingsPath("accounts")}>${layoutText("agentsAccountsLink")}<span aria-hidden="true">→</span></a></p>` : accountsCard()}`
437
438
  : section === "accounts" ? accountsCard()
438
439
  : section === "agent-defaults" ? html`<${GeneralLocation} /><${YamlLock} staged=${staged}><${General} key=${formKey} ctx=${ctx} part="fleet" />${!SETTINGS_SECTIONS.includes("notifications") ? html`<${QuotaNoticeSettings} key=${`quota:${formKey}`} ctx=${ctx} />` : null}</${YamlLock}>`
439
- : section === "notifications" ? html`<${YamlLock} staged=${staged}><${QuotaNoticeSettings} key=${formKey} ctx=${ctx} /></${YamlLock}>`
440
+ : section === "notifications" ? html`<${YamlLock} staged=${staged}><${HostMonitoringSettings} key=${`monitoring:${formKey}`} ctx=${ctx} /><${QuotaNoticeSettings} key=${formKey} ctx=${ctx} /></${YamlLock}>`
440
441
  : section === "chat" ? html`<${SettingsConnector} /><${YamlLock} staged=${staged}><${Bots} ctx=${ctx} search=${search} openDialog=${toDialog} /></${YamlLock}>
441
442
  <${WebSection} key=${formKey} ctx=${ctx} staged=${staged} part="chat" />
442
443
  <div id="classicbot" class="s-anchor s-classic-area"><section class="card s-chat-classic"><h2 class="s-ap-group">ClassicBot</h2><${Classic} ctx=${ctx} search=${search} openDialog=${toDialog} /></section>
@@ -0,0 +1,134 @@
1
+ // M-3438: presentation only. Each new window authenticates and reads its own history.
2
+ // Only a bounded locator crosses the existing exact-window protocol; never HTML, credentials or permissions.
3
+ import { appStore } from "/assets/app-store.js";
4
+ import { assetUrl } from "/assets/asset-url.js";
5
+ import { Shell, shellStore } from "/assets/app-shell.js";
6
+ import { isSafeInstanceName } from "/assets/app-route.js";
7
+ import { register, t } from "/assets/app-i18n.js";
8
+ import { toast } from "/assets/ui-toast.js";
9
+ import { loadHtmlAttachment } from "/assets/html-attachment.js";
10
+ import * as Panel from "/assets/preview-panel.js";
11
+ import * as Transport from "./chat-popout-transport.js";
12
+
13
+ register("previewPopout", {
14
+ en: { open: "Pop out preview", blocked: "Your browser blocked the window. Allow pop-ups for this site, then try again. The original preview is unchanged.",
15
+ retained: "The preview could not be opened in the new window. The original preview has been kept.", busy: "A preview window is already opening." },
16
+ "zh-TW": { open: "彈出預覽視窗", blocked: "瀏覽器封鎖了新視窗。請允許這個網站開啟彈出視窗,再試一次。原本的預覽不變。",
17
+ retained: "無法在新視窗開啟預覽,已保留原本的預覽。", busy: "正在開啟預覽視窗。" },
18
+ });
19
+ register("chat", { en: { pvPopout: "Pop out preview" }, "zh-TW": { pvPopout: "彈出預覽視窗" } });
20
+ const notify = reason => toast(t("previewPopout." + reason), false);
21
+ const safeKey = value => typeof value === "string" && value.length <= 256 && /^[a-zA-Z0-9_-]+-[0-9]+$/.test(value);
22
+ export function validPreviewLocator(value) {
23
+ if (!value || typeof value !== "object" || Array.isArray(value) || !safeKey(value.msgKey)) return false;
24
+ const keys = Object.keys(value).sort().join(",");
25
+ return keys === "msgKey,n" ? Number.isInteger(value.n) && value.n >= 0 && value.n < 1000
26
+ : keys === "attachmentId,msgKey" && typeof value.attachmentId === "string" && /^[a-f0-9]{32}$/.test(value.attachmentId);
27
+ }
28
+ export function previewLocator(open) {
29
+ if (!open || open.kind !== "html" || !isSafeInstanceName(open.instance)) return null;
30
+ const locator = open.att ? { msgKey: open.msgKey, attachmentId: open.att.id } : { msgKey: open.msgKey, n: open.n };
31
+ return validPreviewLocator(locator) ? locator : null;
32
+ }
33
+ export function previewSpecFromHistory(name, locator, messages) {
34
+ if (!isSafeInstanceName(name) || !validPreviewLocator(locator)) return null;
35
+ const row = (Array.isArray(messages) ? messages : []).find(x =>
36
+ x.instance === name && x.role === "agent" && x.boot + "-" + x.id === locator.msgKey);
37
+ if (!row) return null;
38
+ const common = { instance: name, msgKey: locator.msgKey, sender: row.sender, ts: row.ts };
39
+ if (Object.hasOwn(locator, "n")) {
40
+ const fence = globalThis.AgendChatRender.htmlFences(row.text)[locator.n];
41
+ return fence?.terminated ? { ...common, key: locator.msgKey + ":f" + locator.n, n: locator.n, code: fence.code } : null;
42
+ }
43
+ const att = (row.attachments || []).find(a => a.id === locator.attachmentId && globalThis.AgendChatRender.isHtmlAttachment(a));
44
+ return att ? { ...common, key: locator.msgKey + ":a" + att.id, att: { id: att.id, name: att.name, size: att.size }, code: null } : null;
45
+ }
46
+ export async function readPreviewSpec(chat, name, locator, current) {
47
+ if (!validPreviewLocator(locator) || !current()) return null;
48
+ await chat.store.findQuoted(name, locator.msgKey); // Existing endpoint, archive limits and audience checks.
49
+ if (!current()) return null;
50
+ let spec = previewSpecFromHistory(name, locator, chat.store.state.msgs[name]);
51
+ if (spec?.att) {
52
+ // Read through the existing same-origin attachment loader. Launch still has its own size/opt-in gate.
53
+ const read = await loadHtmlAttachment(spec.att, undefined, { anyway: true });
54
+ if (!current() || !read.ok) return null;
55
+ spec = { ...spec, code: read.code };
56
+ }
57
+ return current() ? spec : null;
58
+ }
59
+
60
+ let styles;
61
+ function loadStyles() {
62
+ return styles ??= new Promise(resolve => {
63
+ const link = document.createElement("link"); link.rel = "stylesheet"; link.href = assetUrl("/assets/preview-popout.css");
64
+ link.onload = () => resolve(true); link.onerror = () => resolve(false); document.head.appendChild(link);
65
+ });
66
+ }
67
+ const supported = () => Shell.popoutVersion === 1 && typeof Panel.previewHostReady === "function"
68
+ && typeof Transport.createPreviewPopoutTransport === "function" && typeof Transport.receivePreviewPopout === "function";
69
+ const requested = win => new URL(win.location.href).searchParams.get("presentation") === "preview";
70
+ const auth = () => globalThis.AgendAuth;
71
+ const visible = name => appStore.get().ready && appStore.get().instances.some(x => x.name === name) && !auth()?.sessionEnded?.();
72
+ let leavePresentation = null;
73
+ export function leavePreviewWindow() { leavePresentation?.(); }
74
+
75
+ /** Prepared before offering the control, so window.open remains in its actual click stack. */
76
+ export async function createPreviewPopout(name, win = window) {
77
+ if (!supported() || !isSafeInstanceName(name) || requested(win)) return null;
78
+ const [css, scope] = await Promise.all([loadStyles(), auth()?.sessionHandle?.()]);
79
+ if (!css || !scope || !visible(name)) return null;
80
+ let alive = true;
81
+ const transport = Transport.createPreviewPopoutTransport({ win, scope, notify });
82
+ const off = auth()?.onSessionEnd?.(() => { alive = false; transport.close(); });
83
+ return {
84
+ open(open) {
85
+ const payload = previewLocator(open);
86
+ const current = () => alive && visible(name) && open.instance === name && Panel.panelStore.get().open === open;
87
+ if (!payload || !current()) return false;
88
+ return transport.open({ name, payload, current, complete() {
89
+ if (!current()) return false; Panel.closePanel(); return true;
90
+ } });
91
+ },
92
+ close() { alive = false; transport.close(); if (typeof off === "function") off(); },
93
+ };
94
+ }
95
+
96
+ export async function installPreviewWindow({ nav, chat, win = window }) {
97
+ const stamp = nav.navStore.get(), route = stamp.route, name = route?.instance;
98
+ if (!supported() || !requested(win) || route?.panel !== "chat" || !isSafeInstanceName(name) || !win.opener) return null;
99
+ const [css, scope] = await Promise.all([loadStyles(), auth()?.sessionHandle?.()]);
100
+ if (!css || !scope) return null;
101
+ let alive = true, showing = false;
102
+ const current = () => alive && nav.navStore.get() === stamp && !auth()?.sessionEnded?.();
103
+ const leave = () => {
104
+ if (!showing) return; showing = false;
105
+ delete document.documentElement.dataset.previewWindow;
106
+ shellStore.set({ popout: false, popoutHeader: null });
107
+ const url = new URL(win.location.href); url.searchParams.delete("presentation");
108
+ win.history.replaceState(win.history.state, "", url.pathname + url.search + url.hash);
109
+ };
110
+ const stop = Transport.receivePreviewPopout({
111
+ win, name, scope, notify, current,
112
+ ready: () => current() && visible(name) && Panel.previewHostReady(name),
113
+ accept: async (locator, withinDeadline) => {
114
+ const fresh = () => current() && withinDeadline();
115
+ const spec = await readPreviewSpec(chat, name, locator, fresh);
116
+ if (!spec || !fresh()) return false;
117
+ showing = true; leavePresentation = leave;
118
+ document.documentElement.dataset.previewWindow = "1";
119
+ shellStore.set({ popout: true, popoutHeader: null, drawer: false });
120
+ Panel.openPanel(spec, { run: true }); // The explicit pop-out click; existing availability/opt-in/size gates still own launch.
121
+ return true;
122
+ },
123
+ });
124
+ const panelOff = Panel.panelStore.subscribe(s => { if (showing && !s.open) leave(); });
125
+ const navOff = nav.navStore.subscribe(() => { if (nav.navStore.get() !== stamp) close(); });
126
+ let authOff = null;
127
+ authOff = auth()?.onSessionEnd?.(() => { Panel.closePanel(); close(); });
128
+ function close() {
129
+ if (!alive) return; alive = false; stop(); leave(); panelOff(); navOff();
130
+ if (leavePresentation === leave) leavePresentation = null;
131
+ if (typeof authOff === "function") authOff();
132
+ }
133
+ return { close };
134
+ }
@@ -51,7 +51,7 @@ export function ReplyFilePanel({ open, panel, fs, enterFs, leaveFs, onKey, close
51
51
  return html`<aside data-trust="preview" class=${`pv-panel ws-panel reply-file-panel${fs ? ` pv-fs pv-fs-${fs}` : ""}`} ref=${panel} aria-label=${t("replyPreview.title")} onKeyDown=${onKey}>
52
52
  <div class="pv-panel-head">
53
53
  <div class="pv-panel-title"><strong>${t("replyPreview.title")}</strong><span class="pv-source">${open.instance}</span></div>
54
- <button type="button" class="icon-btn only-wide" aria-label=${t(fs ? "chat.pvFsExit" : "chat.pvFs")} onClick=${() => fs ? leaveFs() : enterFs()}><${Icon} name=${fs ? "fullscreenexit" : "fullscreen"} size=${16} /></button>
54
+ <button type="button" class="icon-btn pv-panel-fs" aria-label=${t(fs ? "chat.pvFsExit" : "chat.pvFs")} onClick=${() => fs ? leaveFs() : enterFs()}><${Icon} name=${fs ? "fullscreenexit" : "fullscreen"} size=${16} /></button>
55
55
  <button type="button" class="icon-btn pv-panel-close" aria-label=${t("chat.pvClose")} onClick=${close}><${Icon} name="close" size=${18} /></button>
56
56
  </div>
57
57
  <div class="pv-note ws-readonly">${t("replyPreview.readonly")}</div>
@@ -0,0 +1,51 @@
1
+ import { html, useEffect } from '/assets/app-html.js';
2
+ import { register, t } from '/assets/app-i18n.js';
3
+ import { confirmDialog } from '/assets/ui-confirm.js';
4
+ import { useDraft, syncStage } from './settings-draft.js';
5
+ register('hostMonitoring', {
6
+ en: { title:'Host monitoring', enabled:'Monitor this computer', agents:'Include agent footprint',
7
+ hint:'When on, samples every 30–60 seconds; estimated 2–4 MiB RAM and 1–4 MiB of local writes per hour.',
8
+ agentHint:'Optional process snapshot every minute; for 32 agents, an estimated extra 2–8 MiB RAM and 1–4 MiB of writes per hour.',
9
+ off:'Off by default. While off, there is no monitoring collector, timer or history file.',
10
+ agentUnavailable:'Agent footprint is not available in this version of AgEnD.',
11
+ stopTitle:'Turn off host monitoring?', stopBody:'This stops monitoring and its alerts, and removes the recorded host history. Turning it on again starts a new history.', stop:'Turn off', },
12
+ 'zh-TW': { title:'主機監測', enabled:'監測這台電腦', agents:'包含 Agent 資源用量',
13
+ hint:'開啟後每 30–60 秒取樣;估計使用 2–4 MiB 記憶體,每小時本機寫入 1–4 MiB。',
14
+ agentHint:'選用:每分鐘讀取行程資料;32 個 Agent 估計另用 2–8 MiB 記憶體,每小時寫入 1–4 MiB。',
15
+ off:'預設關閉。關閉時沒有監測收集器、計時器或歷史檔案。',
16
+ agentUnavailable:'這個 AgEnD 版本尚未提供 Agent 資源用量。',
17
+ stopTitle:'關閉主機監測?', stopBody:'這會停止監測與通知,並移除已記錄的主機歷史。重新開啟時會建立新的歷史。', stop:'關閉', },
18
+ });
19
+ const copy = k => t(`hostMonitoring.${k}`);
20
+ export function HostMonitoringSettings({ ctx }) {
21
+ const available = ctx.schema?.host_monitoring === true;
22
+ useEffect(() => { if (!available) syncStage(ctx, 'host-monitoring', null); }, [available]);
23
+ // Keep the dormant controls out of Settings until a real collector is wired.
24
+ // A separate child keeps hook order stable across capability transitions.
25
+ return available ? html`<${AvailableHostMonitoringSettings} ctx=${ctx} />` : null;
26
+ }
27
+ function AvailableHostMonitoringSettings({ ctx }) {
28
+ const base = { enabled:ctx.fleet.monitoring?.enabled === true, agent_footprint:ctx.fleet.monitoring?.agent_footprint === true };
29
+ const [form, setForm] = useDraft(ctx, 'host-monitoring', () => base);
30
+ const agentsAvailable = ctx.schema?.host_monitoring_agents === true;
31
+ useEffect(() => {
32
+ const changed = form.enabled !== base.enabled || form.agent_footprint !== base.agent_footprint;
33
+ syncStage(ctx, 'host-monitoring', changed ? {label:copy('title'), impact:'now', request:{method:'PUT',url:'/api/settings/fleet/monitoring',body:{enabled:form.enabled,agent_footprint:form.agent_footprint}}} : null);
34
+ }, [form]);
35
+ const setEnabled = async (checked, control) => {
36
+ if (!checked && form.enabled && !(await confirmDialog({title:copy('stopTitle'),message:copy('stopBody'),confirmLabel:copy('stop'),danger:true}))) {
37
+ // The browser toggled its native property before the asynchronous question.
38
+ // Cancel leaves the draft unchanged, so restore the displayed value too.
39
+ control.checked = form.enabled;
40
+ return;
41
+ }
42
+ setForm(f=>({...f,enabled:checked}));
43
+ };
44
+ const row = (id,key,hint,disabled,change) => html`<div class="s-setting-row"><div class="s-setting-copy"><label for=${id}>${copy(key)}</label><p class="note" id=${`${id}-hint`}>${copy(hint)}</p></div>
45
+ <input class="s-ui-toggle" type="checkbox" role="switch" id=${id} checked=${form[key === 'agents' ? 'agent_footprint':'enabled']} disabled=${disabled} aria-describedby=${`${id}-hint`} onChange=${e=>change(e.target.checked, e.target)} /></div>`;
46
+ return html`<section class="card s-group" id="host-monitoring"><h3>${copy('title')}</h3>
47
+ ${row('hostMonitoringEnabled','enabled','hint',false,setEnabled)}
48
+ ${row('hostMonitoringAgents','agents','agentHint',!agentsAvailable || !form.enabled,checked=>setForm(f=>({...f,agent_footprint:checked})))}
49
+ ${!agentsAvailable ? html`<p class="note">${copy('agentUnavailable')}</p>` : null}
50
+ <p class="note">${copy('off')}</p></section>`;
51
+ }
@@ -10,6 +10,7 @@
10
10
  import { html, useEffect, useRef, useState } from "/assets/app-html.js";
11
11
  import { t } from "/assets/app-i18n.js";
12
12
  import { settingsPath } from "/assets/app-route.js";
13
+ import { InfoTip as SharedInfoTip } from "/assets/info-tip.js";
13
14
  import "./settings-strings.js";
14
15
  import "./settings-shared-strings.js"; // the words this page added: a tab that already ran an older settings-strings.js has none of them (#3087)
15
16
  import {
@@ -225,9 +226,9 @@ export function Tip({ text, cls = "", ariaLabel, children }) {
225
226
  onClick=${(e) => { e.stopPropagation(); if (pinned) hide(); else { show(); setPinned(true); } }}>${children}</button>
226
227
  <span id=${idRef.current} ref=${body} class=${`s-tipbody${at && at.above ? " above" : ""}`} role="tooltip" hidden=${!at}>${text}</span></span>`;
227
228
  }
228
- /** The ⓘ beside a label: what the field is for, when it matters, what its default means. */
229
+ /** The ⓘ beside a label: what the field is for, when it matters, what its default means. M-3443: the shared info icon. */
229
230
  export function InfoTip({ text, name }) {
230
- return html`<${Tip} text=${text} cls="s-i" ariaLabel=${tn("tipLabel", name)}>i</${Tip}>`;
231
+ return html`<${SharedInfoTip} text=${text} label=${tn("tipLabel", name)} cls="s-i" />`;
231
232
  }
232
233
  /**
233
234
  * "6/7 in use · artist custom" at a field's right: how many agents use this page's value; hover lists the ones that set their own.