@songsid/agend 2.4.0-beta.7 → 2.4.0-beta.8

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 (140) hide show
  1. package/dist/auth-api.js +1 -0
  2. package/dist/auth-api.js.map +1 -1
  3. package/dist/backend/antigravity.d.ts +9 -2
  4. package/dist/backend/antigravity.js +24 -6
  5. package/dist/backend/antigravity.js.map +1 -1
  6. package/dist/backend/cli-env-probe.js +1 -1
  7. package/dist/backend/cli-env-probe.js.map +1 -1
  8. package/dist/build-provenance.json +1 -1
  9. package/dist/daemon.d.ts +13 -0
  10. package/dist/daemon.js +64 -1
  11. package/dist/daemon.js.map +1 -1
  12. package/dist/dispatcher-liveness.d.ts +51 -1
  13. package/dist/dispatcher-liveness.js +92 -2
  14. package/dist/dispatcher-liveness.js.map +1 -1
  15. package/dist/fleet-manager.d.ts +55 -0
  16. package/dist/fleet-manager.js +232 -16
  17. package/dist/fleet-manager.js.map +1 -1
  18. package/dist/general-knowledge/skills/hub/SKILL.md +6 -0
  19. package/dist/hub/catalog.d.ts +6 -4
  20. package/dist/hub/catalog.js +14 -7
  21. package/dist/hub/catalog.js.map +1 -1
  22. package/dist/hub/group-policy/admin-impact.d.ts +32 -3
  23. package/dist/hub/group-policy/admin-impact.js +14 -2
  24. package/dist/hub/group-policy/admin-impact.js.map +1 -1
  25. package/dist/hub/group-policy/impact-inventory.d.ts +1 -1
  26. package/dist/hub/group-policy/impact-inventory.js.map +1 -1
  27. package/dist/hub/http/compose.js +70 -6
  28. package/dist/hub/http/compose.js.map +1 -1
  29. package/dist/hub/http/core.js +3 -0
  30. package/dist/hub/http/core.js.map +1 -1
  31. package/dist/hub/http/deps.d.ts +1 -0
  32. package/dist/hub/join/service.d.ts +1 -1
  33. package/dist/hub/join/service.js.map +1 -1
  34. package/dist/hub/mcp/auth-schema.d.ts +7 -0
  35. package/dist/hub/mcp/auth-schema.js +31 -0
  36. package/dist/hub/mcp/auth-schema.js.map +1 -0
  37. package/dist/hub/mcp/auth.d.ts +86 -0
  38. package/dist/hub/mcp/auth.js +364 -0
  39. package/dist/hub/mcp/auth.js.map +1 -0
  40. package/dist/hub/personal/owner-host.d.ts +64 -0
  41. package/dist/hub/personal/owner-host.js +190 -0
  42. package/dist/hub/personal/owner-host.js.map +1 -0
  43. package/dist/hub/personal/schema.d.ts +2 -0
  44. package/dist/hub/personal/schema.js +48 -0
  45. package/dist/hub/personal/schema.js.map +1 -0
  46. package/dist/hub/personal/types.d.ts +42 -0
  47. package/dist/hub/personal/types.js +2 -0
  48. package/dist/hub/personal/types.js.map +1 -0
  49. package/dist/hub/policy.js +2 -0
  50. package/dist/hub/policy.js.map +1 -1
  51. package/dist/hub/quota.js +3 -1
  52. package/dist/hub/quota.js.map +1 -1
  53. package/dist/hub/roles/admin-control.d.ts +29 -0
  54. package/dist/hub/roles/admin-control.js +134 -0
  55. package/dist/hub/roles/admin-control.js.map +1 -0
  56. package/dist/hub/roles/admin-types.d.ts +49 -0
  57. package/dist/hub/roles/admin-types.js +2 -0
  58. package/dist/hub/roles/admin-types.js.map +1 -0
  59. package/dist/hub/roles/resource-effects.d.ts +16 -0
  60. package/dist/hub/roles/resource-effects.js +62 -0
  61. package/dist/hub/roles/resource-effects.js.map +1 -0
  62. package/dist/hub/roles/writer.d.ts +6 -1
  63. package/dist/hub/roles/writer.js +10 -2
  64. package/dist/hub/roles/writer.js.map +1 -1
  65. package/dist/hub/rooms/agents.js +5 -2
  66. package/dist/hub/rooms/agents.js.map +1 -1
  67. package/dist/hub/rooms.d.ts +1 -1
  68. package/dist/hub/rooms.js +12 -8
  69. package/dist/hub/rooms.js.map +1 -1
  70. package/dist/hub/sessions.js +20 -2
  71. package/dist/hub/sessions.js.map +1 -1
  72. package/dist/hub/sharing.js +2 -2
  73. package/dist/hub/sharing.js.map +1 -1
  74. package/dist/hub/types.d.ts +15 -3
  75. package/dist/locale.js +3 -0
  76. package/dist/locale.js.map +1 -1
  77. package/dist/native-model-catalog.d.ts +15 -0
  78. package/dist/native-model-catalog.js +43 -3
  79. package/dist/native-model-catalog.js.map +1 -1
  80. package/dist/runtime-build-info.js +1 -0
  81. package/dist/runtime-build-info.js.map +1 -1
  82. package/dist/runtime-cli.js +31 -5
  83. package/dist/runtime-cli.js.map +1 -1
  84. package/dist/runtime-client-store.d.ts +5 -0
  85. package/dist/runtime-client-store.js +28 -0
  86. package/dist/runtime-client-store.js.map +1 -1
  87. package/dist/runtime-client.d.ts +4 -0
  88. package/dist/runtime-client.js +33 -10
  89. package/dist/runtime-client.js.map +1 -1
  90. package/dist/runtime-coordinator.d.ts +4 -2
  91. package/dist/runtime-coordinator.js +28 -6
  92. package/dist/runtime-coordinator.js.map +1 -1
  93. package/dist/runtime-install.d.ts +3 -0
  94. package/dist/runtime-install.js +7 -1
  95. package/dist/runtime-install.js.map +1 -1
  96. package/dist/runtime-personal-answer.d.ts +1 -0
  97. package/dist/runtime-personal-answer.js +2 -1
  98. package/dist/runtime-personal-answer.js.map +1 -1
  99. package/dist/runtime-personal-preflight.d.ts +5 -0
  100. package/dist/runtime-personal-preflight.js +57 -0
  101. package/dist/runtime-personal-preflight.js.map +1 -0
  102. package/dist/runtime-personal-profile.d.ts +3 -1
  103. package/dist/runtime-personal-profile.js +13 -4
  104. package/dist/runtime-personal-profile.js.map +1 -1
  105. package/dist/runtime-personal-protocol.d.ts +7 -0
  106. package/dist/runtime-personal-protocol.js +11 -0
  107. package/dist/runtime-personal-protocol.js.map +1 -0
  108. package/dist/runtime-personal-stage.d.ts +36 -0
  109. package/dist/runtime-personal-stage.js +163 -0
  110. package/dist/runtime-personal-stage.js.map +1 -0
  111. package/dist/runtime-protocol.d.ts +2 -0
  112. package/dist/ui/chat-store.js +39 -2
  113. package/dist/ui/hub-client.js +14 -0
  114. package/dist/ui/hub-roles-strings.js +15 -0
  115. package/dist/ui/hub-roles.js +48 -0
  116. package/dist/ui/hub-switcher.js +2 -2
  117. package/dist/ui/hub-this-hub.js +2 -2
  118. package/dist/ui/model-picker.js +4 -1
  119. package/dist/ui/panel-hub.js +15 -9
  120. package/dist/ui/panel-settings.js +2 -3
  121. package/dist/ui/settings-catalog.js +22 -0
  122. package/dist/ui/settings-hub-setup.js +2 -1
  123. package/dist/ui/settings-strings.js +2 -0
  124. package/dist/ui/shared/app-shell.js +19 -7
  125. package/dist/ui/shared/app-stream.js +3 -1
  126. package/dist/ui/shared/app.css +18 -8
  127. package/dist/ui/shared/hub-roles.css +27 -0
  128. package/dist/ui/shared/hub.css +11 -3
  129. package/dist/ui/shared/usage-dialog.js +67 -12
  130. package/dist/ui/shared/view-strings.js +8 -0
  131. package/dist/web-api.d.ts +4 -0
  132. package/dist/web-api.js +39 -23
  133. package/dist/web-api.js.map +1 -1
  134. package/dist/windows-cli-worker.d.ts +7 -0
  135. package/dist/windows-cli-worker.js +80 -14
  136. package/dist/windows-cli-worker.js.map +1 -1
  137. package/dist/windows-cli.d.ts +9 -1
  138. package/dist/windows-cli.js +43 -13
  139. package/dist/windows-cli.js.map +1 -1
  140. package/package.json +1 -1
@@ -11,7 +11,7 @@ import { Dialog } from "./ui-dialog.js";
11
11
  import { ErrorState, Skeleton } from "./ui-states.js";
12
12
  import { Icon } from "./ui-icons.js";
13
13
  import "./view-strings.js";
14
- import { CompactMeter, resetClock, resetText, tn, usageClock, usageDuration, usageText } from "./usage-meter.js";
14
+ import { CompactMeter, level, resetClock, resetText, tn, usageClock, usageDuration, usageText, windowTag } from "./usage-meter.js";
15
15
  // What this file exported before the meter moved out of it (#3321), for what imports it from here.
16
16
  export { usageClock, windowTag, soonestReset } from "./usage-meter.js";
17
17
 
@@ -207,18 +207,20 @@ function rowNote(p) {
207
207
  * Numbers not current, a failed read or no login: one muted line in place of the bars, what is wrong as its tooltip.
208
208
  * Pressed, it opens its full card.
209
209
  */
210
- export function CompactRow({ p, onExpand }) {
210
+ export function CompactRow({ p, onExpand, one = false }) {
211
211
  const title = providerTitle(p), failed = p.status === "error" || p.status === "no-credentials";
212
212
  // Last known numbers (stale, e.g. an expired token) show as the others do (the user, 2026-10-23; the full card has since
213
213
  // #2386), with a small "cached at 07:47" on the name line; a window that reset since is left out (compactSlots).
214
- const pools = failed ? null : compactPools(p);
215
- const metrics = failed ? [] : pools ? pools.flatMap((x) => x.metrics) : compactMetrics(p);
214
+ // M-3241: `one` — its group shows one line per login: the binding window (the most used) beside the name.
215
+ const binding = one && !failed ? bindingMetric(p) : null;
216
+ const pools = failed || one ? null : compactPools(p);
217
+ const metrics = failed ? [] : one ? (binding ? [binding] : []) : pools ? pools.flatMap((x) => x.metrics) : compactMetrics(p);
216
218
  const note = rowNote(p), stale = p.stale ? staleNote(p) : null;
217
219
  const say = stale ? stale.mark : note || tn("usage.no_data");
218
220
  const detail = stale ? [stale.mark, stale.detail].filter(Boolean).join(" — ") : say;
219
221
  const name = title.profile || title.base;
220
222
  const models = !pools && metrics.some((m) => m.scope === "model");
221
- return html`<button type="button" class=${`u-crow${p.stale ? " is-stale" : ""}${pools ? " is-pooled" : ""}${models ? " has-models" : ""}`} aria-expanded="false" title=${`${p.name} — ${tn("usageExpand")}`} onClick=${onExpand}>
223
+ return html`<button type="button" class=${`u-crow${p.stale ? " is-stale" : ""}${pools ? " is-pooled" : ""}${models ? " has-models" : ""}${one ? " is-one" : ""}`} aria-expanded="false" title=${`${p.name} — ${tn("usageExpand")}`} onClick=${onExpand}>
222
224
  <span class="u-crow-head"><span class="u-crow-name">${name}</span>${p.noAgents ? html`<span class="note">${tn("usage.no_agents")}</span>` : null}
223
225
  ${p.plan ? html`<span class="pill u-plan" title=${p.plan}><span aria-hidden="true">${planBadge(p.plan)}</span><span class="sr-only">${p.plan}</span></span>` : null}
224
226
  ${stale && metrics.length ? html`<span class="u-crow-stale" title=${detail}>${p.cachedAt ? tn("usageCachedAt", { at: usageClock(p.cachedAt) }) : stale.mark}<span class="sr-only"> (${detail})</span></span>` : null}</span>
@@ -228,11 +230,63 @@ export function CompactRow({ p, onExpand }) {
228
230
  : html`<span class=${`u-crow-note${(stale || (p.status === "error" && !p.transient)) ? " is-alert" : ""}`} title=${detail}>${say}</span>`}
229
231
  </button>`;
230
232
  }
231
- /** A provider's logins: its name once (×N), in small capitals, then each login (or the full card of one opened). */
232
- export function CompactGroup({ group, line }) {
233
- return html`<section class="u-cgroup">
234
- <div class="u-cg-head"><span class="u-cg-name" title=${group.base}>${group.base}</span>${group.items.length > 1 ? html`<span class="u-cg-count">×${group.items.length}</span>` : null}</div>
235
- ${group.items.map(line)}
233
+ // ── M-3241 (the user): a provider of two or more logins folds — −/+ on its header cycles every window of each login →
234
+ // one line per login (its binding window: the most used) → the header alone, with the highest percent. Warning colours
235
+ // stay in each. This browser's choice (localStorage), per provider; another tab's follows. ──
236
+ const GROUP_MODE_KEY = "agend_usage_group_modes";
237
+ const GROUP_MODES = ["expanded", "compact", "collapsed"];
238
+ function readGroupModes() {
239
+ try { const o = JSON.parse(stored(GROUP_MODE_KEY) || "{}"); return o && typeof o === "object" && !Array.isArray(o) ? Object.fromEntries(Object.entries(o).filter(([, v]) => GROUP_MODES.includes(v))) : {}; }
240
+ catch { return {}; }
241
+ }
242
+ export const usageGroupStore = createStore({ modes: readGroupModes() });
243
+ export const groupMode = (base) => usageGroupStore.get().modes[base] || "expanded";
244
+ export function setGroupMode(base, mode) {
245
+ const modes = { ...usageGroupStore.get().modes };
246
+ if (mode === "expanded") delete modes[base]; else modes[base] = mode;
247
+ usageGroupStore.set({ modes });
248
+ store(GROUP_MODE_KEY, JSON.stringify(modes));
249
+ }
250
+ if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
251
+ window.addEventListener("storage", (e) => { if (!e || e.key === GROUP_MODE_KEY || e.key === null) usageGroupStore.set({ modes: readGroupModes() }); });
252
+ }
253
+ /** The window that binds a login: its most used percent window (any pool, any model), or null. */
254
+ export function bindingMetric(p) {
255
+ const pct = ((p && p.metrics) || []).filter((m) => m && m.type === "percent" && !m.resetPassed);
256
+ return pct.length ? pct.reduce((a, b) => ((b.used ?? 0) > (a.used ?? 0) ? b : a)) : null;
257
+ }
258
+ /**
259
+ * A group's most used window, and whose: the collapsed header's number. A failed login has none. A stale login's cached
260
+ * number (#4054 review) counts only when no current login has one, and is then muted and marked cached, as its row is.
261
+ */
262
+ function groupTop(group) {
263
+ let top = null, cached = null;
264
+ for (const { p } of group.items) {
265
+ const m = p.status === "error" || p.status === "no-credentials" ? null : bindingMetric(p);
266
+ if (!m) continue;
267
+ if (p.stale) { if (!cached || (m.used ?? 0) > (cached.m.used ?? 0)) cached = { m, p }; }
268
+ else if (!top || (m.used ?? 0) > (top.m.used ?? 0)) top = { m, p };
269
+ }
270
+ return top || cached;
271
+ }
272
+ /**
273
+ * A provider's logins: its name once (×N), in small capitals, then each login (or the full card of one opened). Two or
274
+ * more (M-3241): −/+ on the right cycles `mode` — every window, one line each, the header alone with the highest percent.
275
+ */
276
+ export function CompactGroup({ group, line, mode = "expanded", onCycle }) {
277
+ const many = group.items.length > 1 && typeof onCycle === "function";
278
+ const shown = many ? mode : "expanded";
279
+ const top = many && shown === "collapsed" ? groupTop(group) : null;
280
+ const pct = top ? Math.min(100, Math.max(0, top.m.used ?? 0)) : null;
281
+ const next = shown === "expanded" ? "usageGroupToOne" : shown === "compact" ? "usageGroupToHeader" : "usageGroupToAll";
282
+ const who = top ? `${providerTitle(top.p).profile || providerTitle(top.p).base} · ${top.m.scope === "model" ? modelTag(top.m) : windowTag(top.m)}` : "";
283
+ return html`<section class=${`u-cgroup${many ? ` is-${shown}` : ""}`} data-group=${group.base}>
284
+ <div class="u-cg-head"><span class="u-cg-name" title=${group.base}>${group.base}</span>${group.items.length > 1 ? html`<span class="u-cg-count">×${group.items.length}</span>` : null}
285
+ ${many ? html`<span class="u-cg-tools">
286
+ ${top ? html`<span class=${`u-cg-top u-cm-pct ${level(pct)}${top.p.stale ? " is-stale" : ""}`} title=${tn("usageGroupTop", { pct: pct.toFixed(0), who }) + (top.p.stale && top.p.cachedAt ? ` · ${tn("usageCachedAt", { at: usageClock(top.p.cachedAt) })}` : "")}>${pct.toFixed(0)}%<span class="sr-only"> (${who})</span></span>` : null}
287
+ <button type="button" class="icon-btn u-cg-toggle" aria-expanded=${shown === "collapsed" ? "false" : "true"} aria-label=${`${group.base}: ${tn(next)}`} title=${tn(next)}
288
+ onClick=${() => onCycle(GROUP_MODES[(GROUP_MODES.indexOf(shown) + 1) % GROUP_MODES.length])}><${Icon} name=${shown === "collapsed" ? "plus" : "minus"} size=${14} /></button></span>` : null}</div>
289
+ ${shown === "collapsed" ? null : group.items.map(line)}
236
290
  </section>`;
237
291
  }
238
292
 
@@ -250,6 +304,7 @@ export function UsageBody({ owner }) {
250
304
  const reads = useMemo(() => readStream(lease), [lease]);
251
305
  // Compact (one line per login): a line pressed opens its full card here, until folded or the mode changes.
252
306
  const { compact } = useStore(usageViewStore);
307
+ const { modes } = useStore(usageGroupStore); // M-3241
253
308
  const [expanded, setExpanded] = useState(() => new Set());
254
309
  useEffect(() => { setExpanded(new Set()); }, [compact]);
255
310
  const toggleOne = (id) => setExpanded((was) => { const next = new Set(was); if (next.has(id)) next.delete(id); else next.add(id); return next; });
@@ -317,8 +372,8 @@ export function UsageBody({ owner }) {
317
372
  ${!p.stale && p.hint ? html`<p class="note">${usageText(p.hint, p.hintI18n)}</p>` : !(p.metrics || []).length ? html`<p class="note">${tn("usage.no_data")}</p>` : null}`}
318
373
  </section>`;
319
374
  content = html`${!providers.length ? html`<p class="note">${tn("usage.empty_active")}</p>` : null}
320
- ${compact ? compactGroups(providers).map((g) => html`<${CompactGroup} key=${g.base} group=${g}
321
- line=${({ p, i }) => (expanded.has(key(p)) ? card(p, i) : html`<${CompactRow} key=${key(p)} p=${p} onExpand=${() => toggleOne(key(p))} />`)} />`)
375
+ ${compact ? compactGroups(providers).map((g) => html`<${CompactGroup} key=${g.base} group=${g} mode=${modes[g.base] || "expanded"} onCycle=${(m) => setGroupMode(g.base, m)}
376
+ line=${({ p, i }) => (expanded.has(key(p)) ? card(p, i) : html`<${CompactRow} key=${key(p)} p=${p} one=${(modes[g.base] || "expanded") === "compact" && g.items.length > 1} onExpand=${() => toggleOne(key(p))} />`)} />`)
322
377
  : providers.map((p, i) => card(p, i))}
323
378
  <div class="u-foot"><span class="note" title=${new Date(data.fetchedAt).toLocaleString()}>${failed ? html`${updatedAgo(data.fetchedAt)} · <span class="u-refresh-failed" role="status">${tn("usageRefreshFailed")}</span>` : data.refreshing ? html`<span class="u-refreshing">${tn("usageRefreshing")}</span>` : updatedAgo(data.fetchedAt)}</span>
324
379
  ${byAgent() ? html`<a class="btn btn-ghost btn-sm u-by-agent" href="/ui/fleet/usage" title=${tn("usageByAgentTitle")}>${tn("usageByAgent")}</a>` : null}
@@ -52,6 +52,10 @@ register("view", {
52
52
  "usageMoveDown": "Move down",
53
53
  "usageCompact": "Compact",
54
54
  "usageCompactTitle": "One line per login",
55
+ "usageGroupToOne": "One line per account",
56
+ "usageGroupToHeader": "Show only the header",
57
+ "usageGroupToAll": "Show every window",
58
+ "usageGroupTop": "Highest: {pct}% ({who})",
55
59
  "usageFull": "Full",
56
60
  "usageFullTitle": "The full card for each login",
57
61
  "usageExpand": "Show the full card",
@@ -333,6 +337,10 @@ register("view", {
333
337
  "usageMoveDown": "下移",
334
338
  "usageCompact": "精簡",
335
339
  "usageCompactTitle": "每個登入一行",
340
+ "usageGroupToOne": "每個帳號一行",
341
+ "usageGroupToHeader": "只顯示標題",
342
+ "usageGroupToAll": "顯示所有用量",
343
+ "usageGroupTop": "最高:{pct}%({who})",
336
344
  "usageFull": "完整",
337
345
  "usageFullTitle": "每個登入顯示完整卡片",
338
346
  "usageExpand": "顯示完整卡片",
package/dist/web-api.d.ts CHANGED
@@ -85,6 +85,10 @@ export interface WebApiContext {
85
85
  label: string;
86
86
  description?: string;
87
87
  }>>;
88
+ /** Discover an empty (or refresh a stale) model list once, bounded, before GET /ui/models answers; never throws. */
89
+ ensureModelCatalog?(backend: string, instance: string | null, selection?: {
90
+ profile?: string;
91
+ }): Promise<void>;
88
92
  refreshModelCatalogFor?(backend: string, instance: string | null, selection?: {
89
93
  profile?: string;
90
94
  }): Promise<{
package/dist/web-api.js CHANGED
@@ -377,6 +377,35 @@ function webCatalog(ctx, backend, instance, profile, plain) {
377
377
  const flat = plain ?? (profile !== null ? ctx.modelCatalogFor?.(backend, instance, { profile }) : ctx.modelCatalogFor?.(backend, instance)) ?? [];
378
378
  return shapeWebModelCatalog(backend, flat);
379
379
  }
380
+ /** GET /ui/models' answer: the cached catalog of this instance/account, else the CLI's own cache, else (claude) the documented ids. */
381
+ function answerModelCatalog(res, ctx, backend, instance, profile, canAnswer) {
382
+ const models = webCatalog(ctx, backend, instance, profile);
383
+ // claude with no account list — with or without a credential profile — is answered with the documentation's ids.
384
+ const answerCatalog = () => {
385
+ if (backend === "claude-code" && !models.length)
386
+ json(res, 200, { backend, models: documentedClaudeCatalog(ctx), source: "official-catalog" });
387
+ else
388
+ json(res, 200, { backend, models });
389
+ };
390
+ // The existing catalog belongs to this instance/account and always wins.
391
+ if (models.length || !ctx.cliModelCatalogFor || profile !== null) {
392
+ answerCatalog();
393
+ return;
394
+ }
395
+ void (async () => {
396
+ const cliModels = await ctx.cliModelCatalogFor?.(backend, instance) ?? [];
397
+ if (!canAnswer())
398
+ return;
399
+ const shaped = shapeWebModelCatalog(backend, cliModels);
400
+ if (shaped.length)
401
+ json(res, 200, { backend, models: shaped, source: "cli-cache" });
402
+ else
403
+ answerCatalog();
404
+ })().catch(() => {
405
+ if (canAnswer())
406
+ json(res, 503, { error: "CLI model cache unavailable" });
407
+ });
408
+ }
380
409
  /** claude's fallback when no account list is readable: the documentation's `claude-*` ids for the host's CLI version, unverified. */
381
410
  function documentedClaudeCatalog(ctx) {
382
411
  const version = ctx.backendAvailabilityRows?.().find(row => row.backend === "claude-code")?.version;
@@ -2858,33 +2887,20 @@ export function handleWebRequest(req, res, url, ctx) {
2858
2887
  }
2859
2888
  if (handleNativeModelCatalog(req, res, url, ctx))
2860
2889
  return true;
2861
- const models = webCatalog(ctx, backend, instance, profile);
2862
- // claude with no account list — with or without a credential profile — is answered with the documentation's ids.
2863
- const answerCatalog = () => {
2864
- if (backend === "claude-code" && !models.length)
2865
- json(res, 200, { backend, models: documentedClaudeCatalog(ctx), source: "official-catalog" });
2866
- else
2867
- json(res, 200, { backend, models });
2868
- };
2869
- // The existing catalog belongs to this instance/account and always wins.
2870
- if (models.length || !ctx.cliModelCatalogFor || profile !== null) {
2871
- answerCatalog();
2890
+ const canAnswer = () => !res.headersSent && !res.destroyed && !res.writableEnded && stillAuthorized(req, res, url, ctx);
2891
+ const answer = () => answerModelCatalog(res, ctx, backend, instance, profile, canAnswer);
2892
+ // An empty (or stale) list is discovered once, bounded, before the answer — the page shows its loading state
2893
+ // meanwhile — rather than answered as "no models" until someone presses Refresh. A cached fresh list is answered at once.
2894
+ if (!ctx.ensureModelCatalog) {
2895
+ answer();
2872
2896
  return true;
2873
2897
  }
2874
- const canAnswer = () => !res.headersSent && !res.destroyed && !res.writableEnded && stillAuthorized(req, res, url, ctx);
2875
2898
  void (async () => {
2876
- const cliModels = await ctx.cliModelCatalogFor?.(backend, instance) ?? [];
2877
- if (!canAnswer())
2878
- return;
2879
- const shaped = shapeWebModelCatalog(backend, cliModels);
2880
- if (shaped.length)
2881
- json(res, 200, { backend, models: shaped, source: "cli-cache" });
2882
- else
2883
- answerCatalog();
2884
- })().catch(() => {
2899
+ await ctx.ensureModelCatalog?.(backend, instance, profile !== null ? { profile } : undefined);
2885
2900
  if (canAnswer())
2886
- json(res, 503, { error: "CLI model cache unavailable" });
2887
- });
2901
+ answer();
2902
+ })().catch(() => { if (canAnswer())
2903
+ json(res, 503, { error: "model catalog unavailable" }); });
2888
2904
  return true;
2889
2905
  }
2890
2906
  // The effort levels Settings → Runtime & model's dropdown offers for an agent and a (not yet saved) model — the chat chip's list.