@adelie/server 0.6.6 → 0.6.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.
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-GO6G445C.js";
9
9
  import {
10
10
  TICKET_SLUG_PATTERN
11
- } from "./chunk-2NN3GRLL.js";
11
+ } from "./chunk-OYLSIVS7.js";
12
12
  import {
13
13
  MachinesRepo
14
14
  } from "./chunk-HMTT2PX4.js";
@@ -3828,7 +3828,7 @@ import { DEFAULT_PROJECT_ID as DEFAULT_PROJECT_ID3, DEFAULT_PROJECT_NAME as DEFA
3828
3828
 
3829
3829
  // src/ifaces.json
3830
3830
  var ifaces_default = {
3831
- hash: "24e6dab61d3570cd29ae2b879e85ab58aec3a69473bce064ed4291e6e924c3ce",
3831
+ hash: "d8d20ea5e3d2ed0efa41124541a9f94d5b894d7eb1e85d0f829977783976fb0c",
3832
3832
  ifaces: {
3833
3833
  "@adelie/server#Access": {
3834
3834
  name: "Access",
@@ -16653,6 +16653,14 @@ var ifaces_default = {
16653
16653
  }
16654
16654
  }
16655
16655
  },
16656
+ liveSessions: {
16657
+ params: [],
16658
+ returns: {
16659
+ data: {
16660
+ $ref: "typescript#Array<{ sessionId: string; projectId: string; agentId: string; status: SessionStatus; }>"
16661
+ }
16662
+ }
16663
+ },
16656
16664
  pendingApprovalCount: {
16657
16665
  params: [
16658
16666
  {
@@ -19937,6 +19945,27 @@ var ifaces_default = {
19937
19945
  }
19938
19946
  }
19939
19947
  },
19948
+ sessionDays: {
19949
+ params: [
19950
+ {
19951
+ data: "string"
19952
+ },
19953
+ {
19954
+ data: [
19955
+ {
19956
+ "days?": "number"
19957
+ },
19958
+ "|",
19959
+ "undefined"
19960
+ ]
19961
+ }
19962
+ ],
19963
+ returns: {
19964
+ data: {
19965
+ $ref: "typescript#Array<UsageSessionDay>"
19966
+ }
19967
+ }
19968
+ },
19940
19969
  queryErrors: {
19941
19970
  params: [
19942
19971
  {
@@ -20257,6 +20286,27 @@ var ifaces_default = {
20257
20286
  }
20258
20287
  }
20259
20288
  },
20289
+ sessionDayByModel: {
20290
+ params: [
20291
+ {
20292
+ data: "string"
20293
+ },
20294
+ {
20295
+ data: [
20296
+ {
20297
+ $ref: "@adelie/server#UsageFilter"
20298
+ },
20299
+ "|",
20300
+ "undefined"
20301
+ ]
20302
+ }
20303
+ ],
20304
+ returns: {
20305
+ data: {
20306
+ $ref: "typescript#Array<UsageSessionDaySums>"
20307
+ }
20308
+ }
20309
+ },
20260
20310
  seriesByModel: {
20261
20311
  params: [
20262
20312
  {
@@ -20500,6 +20550,27 @@ var ifaces_default = {
20500
20550
  }
20501
20551
  }
20502
20552
  },
20553
+ sessionDays: {
20554
+ params: [
20555
+ {
20556
+ data: "string"
20557
+ },
20558
+ {
20559
+ data: [
20560
+ {
20561
+ "days?": "number"
20562
+ },
20563
+ "|",
20564
+ "undefined"
20565
+ ]
20566
+ }
20567
+ ],
20568
+ returns: {
20569
+ data: {
20570
+ $ref: "typescript#Array<UsageSessionDay>"
20571
+ }
20572
+ }
20573
+ },
20503
20574
  lifetimeCost: {
20504
20575
  params: [
20505
20576
  {
@@ -20649,6 +20720,27 @@ var ifaces_default = {
20649
20720
  }
20650
20721
  }
20651
20722
  },
20723
+ sessionDayByModel: {
20724
+ params: [
20725
+ {
20726
+ data: "string"
20727
+ },
20728
+ {
20729
+ data: [
20730
+ {
20731
+ $ref: "@adelie/server#UsageFilter"
20732
+ },
20733
+ "|",
20734
+ "undefined"
20735
+ ]
20736
+ }
20737
+ ],
20738
+ returns: {
20739
+ data: {
20740
+ $ref: "typescript#Array<UsageSessionDaySums>"
20741
+ }
20742
+ }
20743
+ },
20652
20744
  agentSeries: {
20653
20745
  params: [
20654
20746
  {
@@ -25000,7 +25092,7 @@ var ifaces_default = {
25000
25092
  },
25001
25093
  "@adelie/server#ScheduleStatus": "'done'|'expired'|'active'|'missed'|'invalid'|'disabled'",
25002
25094
  "@adelie/server#SemanticIdKind": "'agent'|'org'|'channel'|'project'|'benchmark'",
25003
- "@adelie/server#SemanticIdSuggestReason": "'no_default_model'|'model_failed'|'unusable_answer'|'no_ascii'",
25095
+ "@adelie/server#SemanticIdSuggestReason": "'no_free_model'|'model_failed'|'unusable_answer'|'no_ascii'",
25004
25096
  "@adelie/server#SemanticIdSuggestRequest": {
25005
25097
  name: "string",
25006
25098
  kind: {
@@ -26125,6 +26217,45 @@ var ifaces_default = {
26125
26217
  completed: "number",
26126
26218
  denominator: "number"
26127
26219
  },
26220
+ "@adelie/server#UsageSessionDay": {
26221
+ date: "string",
26222
+ cacheRead: "number",
26223
+ cacheWrite: "number",
26224
+ output: "number",
26225
+ total: "number",
26226
+ requests: "number",
26227
+ cost: "null|number",
26228
+ hasUncosted: "boolean",
26229
+ sessions: {
26230
+ $ref: "typescript#Array<UsageSessionDayRow>"
26231
+ }
26232
+ },
26233
+ "@adelie/server#UsageSessionDayRow": {
26234
+ sessionId: "string",
26235
+ agentId: "string",
26236
+ "title?": "string",
26237
+ cacheRead: "number",
26238
+ cacheWrite: "number",
26239
+ output: "number",
26240
+ total: "number",
26241
+ requests: "number",
26242
+ cost: "null|number",
26243
+ hasUncosted: "boolean"
26244
+ },
26245
+ "@adelie/server#UsageSessionDaySums": {
26246
+ date: "string",
26247
+ sessionId: "string",
26248
+ agentId: "string",
26249
+ provider: "string",
26250
+ modelId: "string",
26251
+ cacheRead: "number",
26252
+ cacheWrite: "number",
26253
+ output: "number",
26254
+ total: "number",
26255
+ requests: "number",
26256
+ cost: "null|number",
26257
+ uncosted: "number"
26258
+ },
26128
26259
  "@adelie/server#UsageTrendPointInTrace": {
26129
26260
  ts: "string",
26130
26261
  requestTotal: "number",
@@ -27038,6 +27169,24 @@ var ifaces_default = {
27038
27169
  },
27039
27170
  "[]"
27040
27171
  ],
27172
+ "typescript#Array<UsageSessionDay>": [
27173
+ {
27174
+ $ref: "@adelie/server#UsageSessionDay"
27175
+ },
27176
+ "[]"
27177
+ ],
27178
+ "typescript#Array<UsageSessionDayRow>": [
27179
+ {
27180
+ $ref: "@adelie/server#UsageSessionDayRow"
27181
+ },
27182
+ "[]"
27183
+ ],
27184
+ "typescript#Array<UsageSessionDaySums>": [
27185
+ {
27186
+ $ref: "@adelie/server#UsageSessionDaySums"
27187
+ },
27188
+ "[]"
27189
+ ],
27041
27190
  "typescript#Array<UsageTrendPointInTrace>": [
27042
27191
  {
27043
27192
  $ref: "@adelie/server#UsageTrendPointInTrace"
@@ -27244,6 +27393,17 @@ var ifaces_default = {
27244
27393
  },
27245
27394
  "[]"
27246
27395
  ],
27396
+ "typescript#Array<{ sessionId: string; projectId: string; agentId: string; status: SessionStatus; }>": [
27397
+ {
27398
+ sessionId: "string",
27399
+ projectId: "string",
27400
+ agentId: "string",
27401
+ status: {
27402
+ $ref: "@adelie/server#SessionStatus"
27403
+ }
27404
+ },
27405
+ "[]"
27406
+ ],
27247
27407
  "typescript#Array<{ ticketId: string; sessionId: string; agentId: string; }>": [
27248
27408
  {
27249
27409
  ticketId: "string",
@@ -28687,6 +28847,10 @@ var ifaces_default = {
28687
28847
  access: {
28688
28848
  iface: "@adelie/server#Access",
28689
28849
  from: "ProjectsModule"
28850
+ },
28851
+ errors: {
28852
+ iface: "@adelie/server#Errors",
28853
+ from: "ObservabilityModule"
28690
28854
  }
28691
28855
  },
28692
28856
  provides: {
@@ -30630,6 +30794,12 @@ var ifaces_default = {
30630
30794
  auth: "user",
30631
30795
  order: 255
30632
30796
  },
30797
+ {
30798
+ id: "session-api.sessions-running",
30799
+ prefix: "/api/projects/:projectId/sessions/running",
30800
+ auth: "user",
30801
+ order: 256
30802
+ },
30633
30803
  {
30634
30804
  id: "session-api.usage",
30635
30805
  prefix: "/api/projects/:projectId/usage",
@@ -33241,12 +33411,14 @@ var LIST_MODELS_TIMEOUT_MS = 2e4;
33241
33411
  var SPEED_PROBE_PROMPT = "Count from 1 to 50 as a comma-separated list, and nothing else. Do not think or explain.\n<think></think>";
33242
33412
  var UTILITY_COMPLETION_BUDGET = 300;
33243
33413
  var UTILITY_COMPLETION_TIMEOUT_MS = 15e3;
33414
+ var UTILITY_COMPLETION_ATTEMPTS = 4;
33415
+ var UTILITY_COMPLETION_WALK_BUDGET_MS = 3e4;
33244
33416
  var MAX_FAILURE_DETAIL = 300;
33245
33417
  function outcomeDetail(outcome) {
33246
33418
  const detail = outcome.errorMessage ? outcome.errorMessage : outcome.status;
33247
33419
  return String(detail).slice(0, MAX_FAILURE_DETAIL);
33248
33420
  }
33249
- function utilityCompletionConfig(modelId, entry) {
33421
+ function utilityCompletionConfig(modelId, entry, requestTimeoutMs = UTILITY_COMPLETION_TIMEOUT_MS) {
33250
33422
  const clientType = canonicalClientType(optStr(entry.client_type));
33251
33423
  const credential = resolveModelCredential({
33252
33424
  provider: optStr(entry.provider) ?? "",
@@ -33262,9 +33434,26 @@ function utilityCompletionConfig(modelId, entry) {
33262
33434
  tools: [],
33263
33435
  thinkingLevel: "none",
33264
33436
  maxTokens: metaMaxTokens(UTILITY_COMPLETION_BUDGET, optNum(entry.max_tokens)),
33265
- requestTimeoutMs: UTILITY_COMPLETION_TIMEOUT_MS
33437
+ requestTimeoutMs
33266
33438
  };
33267
33439
  }
33440
+ function freeModelEntries(raw) {
33441
+ const out = [];
33442
+ const seen = /* @__PURE__ */ new Set();
33443
+ for (const entry of asArray(raw.models)) {
33444
+ const provider = optStr(entry.provider);
33445
+ const modelId = optStr(entry.model_id);
33446
+ if (provider === void 0 || modelId === void 0) continue;
33447
+ const pricing = pricingDtoOf(entry.pricing);
33448
+ if (pricing === void 0) continue;
33449
+ if (pricing.cacheRead !== 0 || pricing.cacheWrite !== 0 || pricing.output !== 0) continue;
33450
+ const key2 = `${provider}\0${modelId}`;
33451
+ if (seen.has(key2)) continue;
33452
+ seen.add(key2);
33453
+ out.push({ provider, modelId, entry });
33454
+ }
33455
+ return out;
33456
+ }
33268
33457
  async function collectUtilityCompletion(stream) {
33269
33458
  let text2 = "";
33270
33459
  for (; ; ) {
@@ -33702,15 +33891,21 @@ var ProjectConfigService = class {
33702
33891
  }
33703
33892
  }
33704
33893
  /**
33705
- * One short completion on the Project's **default** model, for utility asks that belong to
33706
- * no Session — today the English identifier a display name is translated into. Everything
33707
- * comes from the stored default entry (credential, base URL, pinned protocol), and the
33708
- * answer is the model's plain text. Nothing throws: no default model, no entry for it, a
33709
- * construction that throws on a missing credential, a refusal, a timeout, or an answer with
33710
- * no text all come back as `{ ok: false }` carrying the reason, which the caller records so
33711
- * the errors panel can say why the ask produced nothing. Callers must still have a result
33712
- * that works without it. The request is not metered — it carries no Session to attribute
33713
- * it to.
33894
+ * One short completion on a **free** model of the Project, for utility asks that belong to
33895
+ * no Session — today the English identifier a display name is translated into. A free model
33896
+ * is walked first, and several of them: free endpoints are throttled, delisted and retired
33897
+ * routinely, one dead endpoint says nothing about the next, and the ask must not cost
33898
+ * anything, so the Project's default model is deliberately not among the candidates. What
33899
+ * the caller gets when none of them answers is the reason, and its own fallback.
33900
+ *
33901
+ * The walk is bounded twice over: at most `UTILITY_COMPLETION_ATTEMPTS` requests are sent,
33902
+ * and together they get `UTILITY_COMPLETION_WALK_BUDGET_MS`. A candidate that cannot be built
33903
+ * at all — no credential, no routable id — costs neither an attempt nor a wait, so a config
33904
+ * full of unusable free rows does not eat the budget of the ones that work. Nothing throws:
33905
+ * no free entry, an entry with no credential, a refusal, a timeout, or an answer with no text
33906
+ * all come back as `{ ok: false }` carrying the reason, which the caller records so the
33907
+ * errors panel can say why the ask produced nothing. Callers must still have a result that
33908
+ * works without it. The request is not metered — it carries no Session to attribute it to.
33714
33909
  *
33715
33910
  * Thinking is off and the budget is the shared meta budget, for the same reason core's own
33716
33911
  * out-of-band requests set them that way: a reasoning model spends thinking out of
@@ -33719,33 +33914,51 @@ var ProjectConfigService = class {
33719
33914
  */
33720
33915
  async completeOnce(projectId, prompt) {
33721
33916
  const raw = await this.readRaw(projectId);
33722
- const ref = optRef(raw.default_model);
33723
- if (ref === void 0) {
33724
- return { ok: false, cause: "no_model", error: "the Project names no default model" };
33725
- }
33726
- const entry = asArray(raw.models).find((m) => entryMatches(m, ref.provider, ref.model_id));
33727
- if (entry === void 0) {
33728
- return {
33729
- ok: false,
33730
- cause: "no_model",
33731
- error: `the default model ${ref.provider}/${ref.model_id} has no entry in the Project config`
33732
- };
33733
- }
33734
- try {
33735
- const llm = new GenerativeModel({
33736
- ...utilityCompletionConfig(ref.model_id, entry),
33737
- ...this.requestApiKeyResolver(projectId, ref.provider, ref.model_id)
33738
- });
33739
- return await collectUtilityCompletion(
33917
+ const candidates = freeModelEntries(raw);
33918
+ const deadline = Date.now() + UTILITY_COMPLETION_WALK_BUDGET_MS;
33919
+ let failure;
33920
+ let sent = 0;
33921
+ for (const candidate of candidates) {
33922
+ if (sent >= UTILITY_COMPLETION_ATTEMPTS) break;
33923
+ const remaining = deadline - Date.now();
33924
+ if (remaining < 1e3) break;
33925
+ let llm;
33926
+ try {
33927
+ llm = new GenerativeModel({
33928
+ ...utilityCompletionConfig(
33929
+ candidate.modelId,
33930
+ candidate.entry,
33931
+ Math.min(UTILITY_COMPLETION_TIMEOUT_MS, remaining)
33932
+ ),
33933
+ ...this.requestApiKeyResolver(projectId, candidate.provider, candidate.modelId)
33934
+ });
33935
+ } catch (err) {
33936
+ failure = {
33937
+ ok: false,
33938
+ cause: "failed",
33939
+ error: (err instanceof Error ? err.message : String(err)).slice(0, MAX_FAILURE_DETAIL)
33940
+ };
33941
+ continue;
33942
+ }
33943
+ sent += 1;
33944
+ const res = await collectUtilityCompletion(
33740
33945
  llm.streamGenerate({ newMessages: [userText(prompt)] })
33741
33946
  );
33742
- } catch (err) {
33947
+ if (res.ok) return res;
33948
+ failure = res;
33949
+ }
33950
+ if (sent === 0) {
33743
33951
  return {
33744
33952
  ok: false,
33745
- cause: "failed",
33746
- error: (err instanceof Error ? err.message : String(err)).slice(0, MAX_FAILURE_DETAIL)
33953
+ cause: "no_model",
33954
+ error: failure?.error ?? "the Project has no free ($0-priced) model that can be run"
33747
33955
  };
33748
33956
  }
33957
+ return {
33958
+ ok: false,
33959
+ cause: "failed",
33960
+ error: failure?.error ?? "every free model of the Project gave no answer"
33961
+ };
33749
33962
  }
33750
33963
  async testModel(projectId, req) {
33751
33964
  const raw = await this.readRaw(projectId);
@@ -36897,6 +37110,25 @@ var SessionManager = class {
36897
37110
  statusOf(sessionId) {
36898
37111
  return this.entries.get(sessionId)?.status ?? "idle";
36899
37112
  }
37113
+ /**
37114
+ * Every Session this process holds in a live state — running or compacting — across all
37115
+ * Projects and Agents. `statusOf` answers one id at a time, and a Session nobody is looking
37116
+ * at has no row in any client's list; the account menu's "what is running right now" asks
37117
+ * the whole table instead, which is a walk over the entries this process already keeps.
37118
+ */
37119
+ liveSessions() {
37120
+ const out = [];
37121
+ for (const e of this.entries.values()) {
37122
+ if (e.status === "idle") continue;
37123
+ out.push({
37124
+ sessionId: e.sessionId,
37125
+ projectId: e.projectId,
37126
+ agentId: e.agentId,
37127
+ status: e.status
37128
+ });
37129
+ }
37130
+ return out;
37131
+ }
36900
37132
  pendingApprovalCount(sessionId) {
36901
37133
  return this.entries.get(sessionId)?.approvals.size ?? 0;
36902
37134
  }
@@ -46500,6 +46732,25 @@ var UsageRepo = class {
46500
46732
  ).all(params);
46501
46733
  return rows.map((r) => ({ key: r.key, ...toSums(r) }));
46502
46734
  }
46735
+ /**
46736
+ * Per-(calendar day, Session, Agent) x paired reference sums: the day-by-day
46737
+ * "which conversations spent the Tokens" view. Same filter and same `date`
46738
+ * column as `groupsByModel`, so a total here adds up to the cost center's.
46739
+ */
46740
+ sessionDayByModel(projectId, f = {}) {
46741
+ const { where, params } = this.conds(projectId, f);
46742
+ const rows = this.db.prepare(
46743
+ `SELECT date, session_id, agent_id, provider, model_id, ${SUM_COLUMNS}
46744
+ FROM usage_records WHERE ${where}
46745
+ GROUP BY date, session_id, agent_id, provider, model_id`
46746
+ ).all(params);
46747
+ return rows.map((r) => ({
46748
+ date: r.date,
46749
+ sessionId: r.session_id,
46750
+ agentId: r.agent_id,
46751
+ ...toSums(r)
46752
+ }));
46753
+ }
46503
46754
  /**
46504
46755
  * Time-series sums (bucket key x paired reference breakdown) with per-bucket
46505
46756
  * success-rate counts riding along: powers the cost center's time-series charts
@@ -48075,6 +48326,86 @@ var UsageService = class {
48075
48326
  }))
48076
48327
  };
48077
48328
  }
48329
+ /**
48330
+ * Usage by calendar day, each day split by Session — the account menu's "会话运行记录":
48331
+ * which conversations spent the Tokens, day by day. One grouped scan over the last `days`
48332
+ * calendar days (today included), folded here into days and Sessions; both levels sum the
48333
+ * same rows, so a day's figure is the sum of its Sessions' and the window's is the sum of
48334
+ * the days'.
48335
+ *
48336
+ * Days with no records are left out rather than drawn as zeros — a day nobody used the app
48337
+ * is not a row worth reading — but today is always answered, at zero when nothing has run,
48338
+ * because "今天花了多少" is the one figure the list is opened for. Within a day, Sessions
48339
+ * are ordered by Token total, descending.
48340
+ */
48341
+ sessionDays(projectId, opts = {}) {
48342
+ const days = Math.min(Math.max(opts.days ?? 7, 1), 90);
48343
+ const now = this.clock.now();
48344
+ const today = formatLocalDate(now);
48345
+ const rows = this.usage.sessionDayByModel(projectId, {
48346
+ from: localDateMinusDays(now, days - 1),
48347
+ to: today
48348
+ });
48349
+ const byDate = /* @__PURE__ */ new Map();
48350
+ for (const r of rows) {
48351
+ let day = byDate.get(r.date);
48352
+ if (!day) {
48353
+ day = {
48354
+ date: r.date,
48355
+ cacheRead: 0,
48356
+ cacheWrite: 0,
48357
+ output: 0,
48358
+ total: 0,
48359
+ requests: 0,
48360
+ cost: null,
48361
+ hasUncosted: false,
48362
+ sessions: []
48363
+ };
48364
+ byDate.set(r.date, day);
48365
+ }
48366
+ let session = day.sessions.find((s) => s.sessionId === r.sessionId);
48367
+ if (!session) {
48368
+ session = {
48369
+ sessionId: r.sessionId,
48370
+ agentId: r.agentId,
48371
+ cacheRead: 0,
48372
+ cacheWrite: 0,
48373
+ output: 0,
48374
+ total: 0,
48375
+ requests: 0,
48376
+ cost: null,
48377
+ hasUncosted: false
48378
+ };
48379
+ day.sessions.push(session);
48380
+ }
48381
+ for (const target of [day, session]) {
48382
+ target.cacheRead += r.cacheRead;
48383
+ target.cacheWrite += r.cacheWrite;
48384
+ target.output += r.output;
48385
+ target.total += r.total;
48386
+ target.requests += r.requests;
48387
+ if (r.cost !== null) target.cost = (target.cost ?? 0) + r.cost;
48388
+ if (r.uncosted > 0) target.hasUncosted = true;
48389
+ }
48390
+ }
48391
+ const out = [...byDate.values()];
48392
+ for (const day of out) day.sessions.sort((a, b) => b.total - a.total);
48393
+ out.sort((a, b) => b.date.localeCompare(a.date));
48394
+ if (!byDate.has(today)) {
48395
+ out.unshift({
48396
+ date: today,
48397
+ cacheRead: 0,
48398
+ cacheWrite: 0,
48399
+ output: 0,
48400
+ total: 0,
48401
+ requests: 0,
48402
+ cost: null,
48403
+ hasUncosted: false,
48404
+ sessions: []
48405
+ });
48406
+ }
48407
+ return out;
48408
+ }
48078
48409
  /**
48079
48410
  * The Project's lifetime cost — one unfiltered grouped scan, the same one `modelTotals` runs,
48080
48411
  * summing the costs fixed when the rows were written. Its consumer is a per-account figure
@@ -58746,6 +59077,27 @@ function usageRoutes(deps) {
58746
59077
  deps.access.requireProjectAccess(c.var.user.userId, projectId);
58747
59078
  return c.json(deps.usageService.modelTotals(projectId));
58748
59079
  });
59080
+ app.get("/session-days", (c) => {
59081
+ const projectId = requireValidId(c, "projectId");
59082
+ deps.access.requireProjectAccess(c.var.user.userId, projectId);
59083
+ const raw = c.req.query("days");
59084
+ const parsed = raw === void 0 || raw === "" ? 7 : /^\d{1,3}$/.test(raw) ? Number(raw) : NaN;
59085
+ if (!Number.isInteger(parsed) || parsed < 1 || parsed > 90) {
59086
+ throw badRequest("days must be a whole number between 1 and 90.");
59087
+ }
59088
+ const titles = /* @__PURE__ */ new Map();
59089
+ const days = deps.usageService.sessionDays(projectId, { days: parsed }).map((day) => ({
59090
+ ...day,
59091
+ sessions: day.sessions.map((row) => {
59092
+ if (!titles.has(row.sessionId)) {
59093
+ titles.set(row.sessionId, deps.sessionsRepo.findById(row.sessionId)?.title ?? void 0);
59094
+ }
59095
+ const title = titles.get(row.sessionId);
59096
+ return { ...row, ...title !== void 0 ? { title } : {} };
59097
+ })
59098
+ }));
59099
+ return c.json({ days });
59100
+ });
58749
59101
  app.get("/errors", (c) => {
58750
59102
  const projectId = requireValidId(c, "projectId");
58751
59103
  deps.access.requireProjectAccess(c.var.user.userId, projectId);
@@ -59706,6 +60058,22 @@ function agentSessionsRoutes(deps) {
59706
60058
  });
59707
60059
  return app;
59708
60060
  }
60061
+ function runningSessionsRoutes(deps) {
60062
+ const app = new Hono22();
60063
+ app.get("/", async (c) => {
60064
+ const projectId = requireValidId(c, "projectId");
60065
+ deps.access.requireProjectAccess(c.var.user.userId, projectId);
60066
+ const live = deps.manager.liveSessions().filter((e) => e.projectId === projectId).sort((a, b) => a.status === b.status ? 0 : a.status === "running" ? -1 : 1);
60067
+ const sessions2 = [];
60068
+ for (const entry of live) {
60069
+ const row = deps.sessionsRepo.findById(entry.sessionId);
60070
+ if (!row) continue;
60071
+ sessions2.push(await deps.sessionService.toInfo(row, await deps.sessionService.hasTrace(row)));
60072
+ }
60073
+ return c.json({ sessions: sessions2 });
60074
+ });
60075
+ return app;
60076
+ }
59709
60077
  function sessionsRoutes(deps) {
59710
60078
  const app = new Hono22();
59711
60079
  const resolveSession = (c) => {
@@ -60419,7 +60787,7 @@ function sessionsRoutes(deps) {
60419
60787
  });
60420
60788
  return app;
60421
60789
  }
60422
- var _sessionsRoutes_dec, _workspaceFilesRoutes_dec, _usageRoutes_dec, _sessionsBatchRoutes_dec, _agentSessionsRoutes_dec, _vaultRoutes_dec, _agentConfigRoutes_dec, _agentDeletionsRoutes_dec, _agentsRoutes_dec, _commandPolicyRoutes_dec, _chatDefaultsRoutes_dec, _modelScopeAuthRoutes_dec, _platformAuthRoutes_dec, _modelOauthRoutes_dec, _modelsRoutes_dec, _modelOauthCallbackRoutes_dec, _agentApi_dec2, _auth_dec5, _liveStreams_dec3, _usage_dec5, _errorsRepo_dec, _sources_dec4, _sessionsRepo_dec3, _settings_dec4, _previewTokens_dec, _desktop_dec2, _fileReveal_dec, _workspaceFiles_dec2, _traces_dec, _traceIndex_dec3, _modelScopeAuth_dec2, _platformAuth_dec, _modelOAuth_dec, _projectConfig_dec11, _projectEvents_dec2, _access_dec3, _schedulesRepo_dec, _messaging_dec2, _agents_dec3, _userVault_dec, _agentConfig_dec3, _sessionService_dec2, _machines_dec, _manager_dec3, _channels_dec8, _config_dec8, _SessionApiRoutes_decorators, _init110;
60790
+ var _sessionsRoutes_dec, _workspaceFilesRoutes_dec, _usageRoutes_dec, _runningSessionsRoutes_dec, _sessionsBatchRoutes_dec, _agentSessionsRoutes_dec, _vaultRoutes_dec, _agentConfigRoutes_dec, _agentDeletionsRoutes_dec, _agentsRoutes_dec, _commandPolicyRoutes_dec, _chatDefaultsRoutes_dec, _modelScopeAuthRoutes_dec, _platformAuthRoutes_dec, _modelOauthRoutes_dec, _modelsRoutes_dec, _modelOauthCallbackRoutes_dec, _agentApi_dec2, _auth_dec5, _liveStreams_dec3, _usage_dec5, _errorsRepo_dec, _sources_dec4, _sessionsRepo_dec3, _settings_dec4, _previewTokens_dec, _desktop_dec2, _fileReveal_dec, _workspaceFiles_dec2, _traces_dec, _traceIndex_dec3, _modelScopeAuth_dec2, _platformAuth_dec, _modelOAuth_dec, _projectConfig_dec11, _projectEvents_dec2, _access_dec3, _schedulesRepo_dec, _messaging_dec2, _agents_dec3, _userVault_dec, _agentConfig_dec3, _sessionService_dec2, _machines_dec, _manager_dec3, _channels_dec8, _config_dec8, _SessionApiRoutes_decorators, _init110;
60423
60791
  _SessionApiRoutes_decorators = [Component50({
60424
60792
  contributes: {
60425
60793
  "HttpModule.routes": [
@@ -60501,6 +60869,12 @@ _SessionApiRoutes_decorators = [Component50({
60501
60869
  auth: "user",
60502
60870
  order: 255
60503
60871
  },
60872
+ {
60873
+ id: "session-api.sessions-running",
60874
+ prefix: "/api/projects/:projectId/sessions/running",
60875
+ auth: "user",
60876
+ order: 256
60877
+ },
60504
60878
  {
60505
60879
  id: "session-api.usage",
60506
60880
  prefix: "/api/projects/:projectId/usage",
@@ -60521,7 +60895,7 @@ _SessionApiRoutes_decorators = [Component50({
60521
60895
  }
60522
60896
  ]
60523
60897
  }
60524
- })], _config_dec8 = [Use50()], _channels_dec8 = [Use50()], _manager_dec3 = [Use50()], _machines_dec = [Use50()], _sessionService_dec2 = [Use50()], _agentConfig_dec3 = [Use50()], _userVault_dec = [Use50()], _agents_dec3 = [Use50()], _messaging_dec2 = [Use50()], _schedulesRepo_dec = [Use50()], _access_dec3 = [Use50()], _projectEvents_dec2 = [Use50()], _projectConfig_dec11 = [Use50()], _modelOAuth_dec = [Use50()], _platformAuth_dec = [Use50()], _modelScopeAuth_dec2 = [Use50()], _traceIndex_dec3 = [Use50()], _traces_dec = [Use50()], _workspaceFiles_dec2 = [Use50()], _fileReveal_dec = [Use50()], _desktop_dec2 = [Use50()], _previewTokens_dec = [Use50()], _settings_dec4 = [Use50()], _sessionsRepo_dec3 = [Use50()], _sources_dec4 = [Use50()], _errorsRepo_dec = [Use50()], _usage_dec5 = [Use50()], _liveStreams_dec3 = [Use50()], _auth_dec5 = [Use50()], _agentApi_dec2 = [Use50()], _modelOauthCallbackRoutes_dec = [Bind11("session-api.model-oauth-callback")], _modelsRoutes_dec = [Bind11("session-api.models")], _modelOauthRoutes_dec = [Bind11("session-api.model-oauth")], _platformAuthRoutes_dec = [Bind11("session-api.platform-auth")], _modelScopeAuthRoutes_dec = [Bind11("session-api.modelscope-auth")], _chatDefaultsRoutes_dec = [Bind11("session-api.chat-defaults")], _commandPolicyRoutes_dec = [Bind11("session-api.command-policy")], _agentsRoutes_dec = [Bind11("session-api.agents")], _agentDeletionsRoutes_dec = [Bind11("session-api.agent-deletions")], _agentConfigRoutes_dec = [Bind11("session-api.agent-config")], _vaultRoutes_dec = [Bind11("session-api.vault")], _agentSessionsRoutes_dec = [Bind11("session-api.agent-sessions")], _sessionsBatchRoutes_dec = [Bind11("session-api.sessions-batch")], _usageRoutes_dec = [Bind11("session-api.usage")], _workspaceFilesRoutes_dec = [Bind11("session-api.workspace-files")], _sessionsRoutes_dec = [Bind11("session-api.sessions")];
60898
+ })], _config_dec8 = [Use50()], _channels_dec8 = [Use50()], _manager_dec3 = [Use50()], _machines_dec = [Use50()], _sessionService_dec2 = [Use50()], _agentConfig_dec3 = [Use50()], _userVault_dec = [Use50()], _agents_dec3 = [Use50()], _messaging_dec2 = [Use50()], _schedulesRepo_dec = [Use50()], _access_dec3 = [Use50()], _projectEvents_dec2 = [Use50()], _projectConfig_dec11 = [Use50()], _modelOAuth_dec = [Use50()], _platformAuth_dec = [Use50()], _modelScopeAuth_dec2 = [Use50()], _traceIndex_dec3 = [Use50()], _traces_dec = [Use50()], _workspaceFiles_dec2 = [Use50()], _fileReveal_dec = [Use50()], _desktop_dec2 = [Use50()], _previewTokens_dec = [Use50()], _settings_dec4 = [Use50()], _sessionsRepo_dec3 = [Use50()], _sources_dec4 = [Use50()], _errorsRepo_dec = [Use50()], _usage_dec5 = [Use50()], _liveStreams_dec3 = [Use50()], _auth_dec5 = [Use50()], _agentApi_dec2 = [Use50()], _modelOauthCallbackRoutes_dec = [Bind11("session-api.model-oauth-callback")], _modelsRoutes_dec = [Bind11("session-api.models")], _modelOauthRoutes_dec = [Bind11("session-api.model-oauth")], _platformAuthRoutes_dec = [Bind11("session-api.platform-auth")], _modelScopeAuthRoutes_dec = [Bind11("session-api.modelscope-auth")], _chatDefaultsRoutes_dec = [Bind11("session-api.chat-defaults")], _commandPolicyRoutes_dec = [Bind11("session-api.command-policy")], _agentsRoutes_dec = [Bind11("session-api.agents")], _agentDeletionsRoutes_dec = [Bind11("session-api.agent-deletions")], _agentConfigRoutes_dec = [Bind11("session-api.agent-config")], _vaultRoutes_dec = [Bind11("session-api.vault")], _agentSessionsRoutes_dec = [Bind11("session-api.agent-sessions")], _sessionsBatchRoutes_dec = [Bind11("session-api.sessions-batch")], _runningSessionsRoutes_dec = [Bind11("session-api.sessions-running")], _usageRoutes_dec = [Bind11("session-api.usage")], _workspaceFilesRoutes_dec = [Bind11("session-api.workspace-files")], _sessionsRoutes_dec = [Bind11("session-api.sessions")];
60525
60899
  var SessionApiRoutes = class {
60526
60900
  constructor() {
60527
60901
  __publicField(this, "config", __runInitializers(_init110, 8, this)), __runInitializers(_init110, 11, this);
@@ -60567,9 +60941,10 @@ var SessionApiRoutes = class {
60567
60941
  __publicField(this, "vaultRoutes", __runInitializers(_init110, 168, this)), __runInitializers(_init110, 171, this);
60568
60942
  __publicField(this, "agentSessionsRoutes", __runInitializers(_init110, 172, this)), __runInitializers(_init110, 175, this);
60569
60943
  __publicField(this, "sessionsBatchRoutes", __runInitializers(_init110, 176, this)), __runInitializers(_init110, 179, this);
60570
- __publicField(this, "usageRoutes", __runInitializers(_init110, 180, this)), __runInitializers(_init110, 183, this);
60571
- __publicField(this, "workspaceFilesRoutes", __runInitializers(_init110, 184, this)), __runInitializers(_init110, 187, this);
60572
- __publicField(this, "sessionsRoutes", __runInitializers(_init110, 188, this)), __runInitializers(_init110, 191, this);
60944
+ __publicField(this, "runningSessionsRoutes", __runInitializers(_init110, 180, this)), __runInitializers(_init110, 183, this);
60945
+ __publicField(this, "usageRoutes", __runInitializers(_init110, 184, this)), __runInitializers(_init110, 187, this);
60946
+ __publicField(this, "workspaceFilesRoutes", __runInitializers(_init110, 188, this)), __runInitializers(_init110, 191, this);
60947
+ __publicField(this, "sessionsRoutes", __runInitializers(_init110, 192, this)), __runInitializers(_init110, 195, this);
60573
60948
  }
60574
60949
  setup() {
60575
60950
  const manager = this.manager;
@@ -60659,7 +61034,8 @@ var SessionApiRoutes = class {
60659
61034
  });
60660
61035
  this.agentSessionsRoutes = agentSessionsRoutes(sessionsDeps);
60661
61036
  this.sessionsBatchRoutes = sessionsBatchRoutes(sessionsDeps);
60662
- this.usageRoutes = usageRoutes({ access, usageService: this.usage });
61037
+ this.runningSessionsRoutes = runningSessionsRoutes(sessionsDeps);
61038
+ this.usageRoutes = usageRoutes({ access, usageService: this.usage, sessionsRepo });
60663
61039
  this.workspaceFilesRoutes = workspaceFilesRoutes({
60664
61040
  access,
60665
61041
  workspaceFiles: this.workspaceFiles,
@@ -60713,6 +61089,7 @@ __decorateElement(_init110, 5, "agentConfigRoutes", _agentConfigRoutes_dec, Sess
60713
61089
  __decorateElement(_init110, 5, "vaultRoutes", _vaultRoutes_dec, SessionApiRoutes);
60714
61090
  __decorateElement(_init110, 5, "agentSessionsRoutes", _agentSessionsRoutes_dec, SessionApiRoutes);
60715
61091
  __decorateElement(_init110, 5, "sessionsBatchRoutes", _sessionsBatchRoutes_dec, SessionApiRoutes);
61092
+ __decorateElement(_init110, 5, "runningSessionsRoutes", _runningSessionsRoutes_dec, SessionApiRoutes);
60716
61093
  __decorateElement(_init110, 5, "usageRoutes", _usageRoutes_dec, SessionApiRoutes);
60717
61094
  __decorateElement(_init110, 5, "workspaceFilesRoutes", _workspaceFilesRoutes_dec, SessionApiRoutes);
60718
61095
  __decorateElement(_init110, 5, "sessionsRoutes", _sessionsRoutes_dec, SessionApiRoutes);
@@ -64462,6 +64839,9 @@ function currentRemoteLayout(env = process.env) {
64462
64839
  var KEEP_HELD_MS = 6e4;
64463
64840
  var REHOLD_BACKOFF_MIN_MS = 6e4;
64464
64841
  var REHOLD_BACKOFF_MAX_MS = 15 * 6e4;
64842
+ function machinesErrorRecord(err, code2, projectId) {
64843
+ return { source: "process", err, code: code2, ctx: projectId === void 0 ? void 0 : { projectId } };
64844
+ }
64465
64845
  var LOCAL_MACHINE_ID = "local";
64466
64846
  var CONCURRENCY = 5;
64467
64847
  var SESSION_REUSE_MS = 50 * 6e4;
@@ -64490,6 +64870,8 @@ var MachinesService = class {
64490
64870
  upgrade: upgradeRemote,
64491
64871
  loadConfig: (projectId) => loadProjectConfig(dataRoot, projectId),
64492
64872
  now: () => /* @__PURE__ */ new Date(),
64873
+ recordError: () => {
64874
+ },
64493
64875
  ...effects
64494
64876
  };
64495
64877
  }
@@ -64534,6 +64916,13 @@ var MachinesService = class {
64534
64916
  #jobs = /* @__PURE__ */ new Map();
64535
64917
  /** The standing intent: while this App lives, machines recorded as held are re-held when found dropped. */
64536
64918
  #keepHeld = null;
64919
+ /**
64920
+ * Whether this generation has been retired. start() reaches out over the network before it
64921
+ * settles, so a hot push's stop() can land while it is still awaiting: the generation must
64922
+ * then install nothing — a timer on a retired generation would read a database that is
64923
+ * already closed, once a minute, until the process ends.
64924
+ */
64925
+ #stopped = false;
64537
64926
  /** Per machine, when the next re-hold may be tried (epoch ms) and how many tries have failed in a row. */
64538
64927
  #reholdNotBefore = /* @__PURE__ */ new Map();
64539
64928
  #reholdFailures = /* @__PURE__ */ new Map();
@@ -65201,19 +65590,43 @@ var MachinesService = class {
65201
65590
  * slow to answer must not hold up the App that serves everything else.
65202
65591
  */
65203
65592
  async start() {
65593
+ if (this.#stopped) return;
65204
65594
  await this.syncOutOfDate();
65595
+ if (this.#stopped) return;
65205
65596
  await this.autoConnect();
65206
- if (this.#keepHeld === null) {
65207
- this.#keepHeld = setInterval(() => void this.autoConnect(), KEEP_HELD_MS);
65597
+ if (!this.#stopped && this.#keepHeld === null) {
65598
+ this.#keepHeld = setInterval(() => void this.#keepHeldTick(), KEEP_HELD_MS);
65208
65599
  this.#keepHeld.unref?.();
65209
65600
  }
65210
65601
  }
65602
+ /**
65603
+ * One attempt of the standing intent, from the timer.
65604
+ *
65605
+ * The boot path in platform.ts is fire-and-forget too, but it has somewhere to put a
65606
+ * rejection (its own `.catch`); a timer callback has nobody to throw to, so a rejection here
65607
+ * would escape to the process as an unhandled rejection — which is what used to happen once a
65608
+ * minute whenever a sweep failed. It is recorded instead, under the same source and code as
65609
+ * that boot path: one machine failing to come back is one class in the error centre, and one
65610
+ * rule there silences both occasions.
65611
+ *
65612
+ * The guard first: a stop() landing between the tick and this call retires the generation,
65613
+ * and reading a closed database to tell its error table about it helps nobody.
65614
+ */
65615
+ async #keepHeldTick() {
65616
+ if (this.#stopped) return;
65617
+ try {
65618
+ await this.autoConnect();
65619
+ } catch (err) {
65620
+ if (!this.#stopped) this.#effects.recordError(err, "machines_reconnect_failed");
65621
+ }
65622
+ }
65211
65623
  /**
65212
65624
  * Closes every connection THIS generation opened — the platform's dispose effect on a hot
65213
65625
  * push. The record of which were held stays, so the successor's start() brings each back.
65214
65626
  * Nothing here closes by a remembered pid: the child handles are this generation's own.
65215
65627
  */
65216
65628
  stop() {
65629
+ this.#stopped = true;
65217
65630
  if (this.#keepHeld !== null) clearInterval(this.#keepHeld);
65218
65631
  this.#keepHeld = null;
65219
65632
  closeAllConnections();
@@ -65508,27 +65921,31 @@ var MachinesService = class {
65508
65921
  * interface member is a contract change a pushed platform pays for.
65509
65922
  */
65510
65923
  async syncModelsEverywhere(projectId) {
65511
- const connected = this.list(projectId).filter(
65512
- (m) => !m.local && m.installed !== null && m.connection !== null
65513
- );
65514
- await Promise.all(
65515
- connected.map(async (machine) => {
65516
- const address = machine.id;
65517
- const port = this.#liveSession(address) === null ? null : this.repo.get(address)?.remotePort ?? null;
65518
- if (port === null) return;
65519
- try {
65520
- await this.#syncCoalesced(address, this.#targetOf(machine.alias), port, () => [
65521
- projectId
65522
- ]);
65523
- } catch {
65524
- }
65525
- })
65526
- );
65924
+ try {
65925
+ const connected = this.list(projectId).filter(
65926
+ (m) => !m.local && m.installed !== null && m.connection !== null
65927
+ );
65928
+ await Promise.all(
65929
+ connected.map(async (machine) => {
65930
+ const address = machine.id;
65931
+ const port = this.#liveSession(address) === null ? null : this.repo.get(address)?.remotePort ?? null;
65932
+ if (port === null) return;
65933
+ try {
65934
+ await this.#syncCoalesced(address, this.#targetOf(machine.alias), port, () => [
65935
+ projectId
65936
+ ]);
65937
+ } catch {
65938
+ }
65939
+ })
65940
+ );
65941
+ } catch (err) {
65942
+ this.#effects.recordError(err, "fleet_sync_failed", projectId);
65943
+ }
65527
65944
  }
65528
65945
  };
65529
65946
  var Machines = class extends Interface23() {
65530
65947
  };
65531
- var _serverProxyRoutes_dec, _routes_dec6, _machines_dec2, _access_dec7, _hmr_dec3, _db_dec16, _paths_dec16, _MachinesModule_decorators, _init116;
65948
+ var _serverProxyRoutes_dec, _routes_dec6, _machines_dec2, _errors_dec7, _access_dec7, _hmr_dec3, _db_dec16, _paths_dec16, _MachinesModule_decorators, _init116;
65532
65949
  _MachinesModule_decorators = [Module16({
65533
65950
  contributes: {
65534
65951
  "HttpModule.routes": [
@@ -65548,16 +65965,17 @@ _MachinesModule_decorators = [Module16({
65548
65965
  }
65549
65966
  ]
65550
65967
  }
65551
- })], _paths_dec16 = [Use56()], _db_dec16 = [Use56()], _hmr_dec3 = [Use56()], _access_dec7 = [Use56()], _machines_dec2 = [Provide16()], _routes_dec6 = [Bind16("MachinesModule.routes")], _serverProxyRoutes_dec = [Bind16("MachinesModule.server-proxy")];
65968
+ })], _paths_dec16 = [Use56()], _db_dec16 = [Use56()], _hmr_dec3 = [Use56()], _access_dec7 = [Use56()], _errors_dec7 = [Use56()], _machines_dec2 = [Provide16()], _routes_dec6 = [Bind16("MachinesModule.routes")], _serverProxyRoutes_dec = [Bind16("MachinesModule.server-proxy")];
65552
65969
  var MachinesModule = class {
65553
65970
  constructor() {
65554
65971
  __publicField(this, "paths", __runInitializers(_init116, 8, this)), __runInitializers(_init116, 11, this);
65555
65972
  __publicField(this, "db", __runInitializers(_init116, 12, this)), __runInitializers(_init116, 15, this);
65556
65973
  __publicField(this, "hmr", __runInitializers(_init116, 16, this)), __runInitializers(_init116, 19, this);
65557
65974
  __publicField(this, "access", __runInitializers(_init116, 20, this)), __runInitializers(_init116, 23, this);
65558
- __publicField(this, "machines", __runInitializers(_init116, 24, this)), __runInitializers(_init116, 27, this);
65559
- __publicField(this, "routes", __runInitializers(_init116, 28, this)), __runInitializers(_init116, 31, this);
65560
- __publicField(this, "serverProxyRoutes", __runInitializers(_init116, 32, this)), __runInitializers(_init116, 35, this);
65975
+ __publicField(this, "errors", __runInitializers(_init116, 24, this)), __runInitializers(_init116, 27, this);
65976
+ __publicField(this, "machines", __runInitializers(_init116, 28, this)), __runInitializers(_init116, 31, this);
65977
+ __publicField(this, "routes", __runInitializers(_init116, 32, this)), __runInitializers(_init116, 35, this);
65978
+ __publicField(this, "serverProxyRoutes", __runInitializers(_init116, 36, this)), __runInitializers(_init116, 39, this);
65561
65979
  }
65562
65980
  setup({ effect }) {
65563
65981
  const repo = new MachinesRepo(this.db);
@@ -65565,7 +65983,13 @@ var MachinesModule = class {
65565
65983
  this.paths.root,
65566
65984
  repo.ownId(),
65567
65985
  repo,
65568
- {},
65986
+ {
65987
+ // The standing-intent timer's failures have no caller to throw to; they go to the error
65988
+ // centre under the same source and code the boot path uses for the same failure
65989
+ // (platform.ts), so one machine that will not come back is one silenceable class. The
65990
+ // code is the port's, not this wiring's: the fleet push files its own class the same way.
65991
+ recordError: (err, code2, projectId) => this.errors.record(machinesErrorRecord(err, code2, projectId))
65992
+ },
65569
65993
  () => this.hmr.assetsDir()
65570
65994
  );
65571
65995
  this.machines = machines;
@@ -65579,6 +66003,7 @@ __decorateElement(_init116, 5, "paths", _paths_dec16, MachinesModule);
65579
66003
  __decorateElement(_init116, 5, "db", _db_dec16, MachinesModule);
65580
66004
  __decorateElement(_init116, 5, "hmr", _hmr_dec3, MachinesModule);
65581
66005
  __decorateElement(_init116, 5, "access", _access_dec7, MachinesModule);
66006
+ __decorateElement(_init116, 5, "errors", _errors_dec7, MachinesModule);
65582
66007
  __decorateElement(_init116, 5, "machines", _machines_dec2, MachinesModule);
65583
66008
  __decorateElement(_init116, 5, "routes", _routes_dec6, MachinesModule);
65584
66009
  __decorateElement(_init116, 5, "serverProxyRoutes", _serverProxyRoutes_dec, MachinesModule);
@@ -67439,7 +67864,7 @@ async function modelSemanticId(deps, complete, projectId, input, avoid) {
67439
67864
  const res = await complete(projectId, prompt);
67440
67865
  if (!res.ok) {
67441
67866
  record(res.error);
67442
- return { reason: res.cause === "no_model" ? "no_default_model" : "model_failed" };
67867
+ return { reason: res.cause === "no_model" ? "no_free_model" : "model_failed" };
67443
67868
  }
67444
67869
  const id = sanitizeSuggestedId(res.text, input.rule, avoid);
67445
67870
  if (id !== null) return { id };
@@ -70801,8 +71226,8 @@ var OrgService = class extends Interface25() {
70801
71226
  };
70802
71227
  var OrgScheduler = class extends Interface25() {
70803
71228
  };
70804
- var _orgScheduler_dec, _orgService_dec, _messagingRepo_dec3, _settings_dec6, _errors_dec7, _usage_dec6, _projectConfig_dec13, _agentsRepo_dec, _agentConfig_dec6, _agentService_dec, _sessionCreator_dec2, _runner_dec3, _sessionsRepo_dec4, _members_dec4, _projects_dec7, _cache_dec, _log_dec4, _clock_dec12, _channels_dec9, _config_dec11, _OrganizationModule_decorators, _init117;
70805
- _OrganizationModule_decorators = [Module17()], _config_dec11 = [Use57()], _channels_dec9 = [Use57()], _clock_dec12 = [Use57()], _log_dec4 = [Use57()], _cache_dec = [Use57()], _projects_dec7 = [Use57()], _members_dec4 = [Use57()], _sessionsRepo_dec4 = [Use57()], _runner_dec3 = [Use57()], _sessionCreator_dec2 = [Use57()], _agentService_dec = [Use57()], _agentConfig_dec6 = [Use57()], _agentsRepo_dec = [Use57()], _projectConfig_dec13 = [Use57()], _usage_dec6 = [Use57()], _errors_dec7 = [Use57()], _settings_dec6 = [Use57()], _messagingRepo_dec3 = [Use57()], _orgService_dec = [Provide17()], _orgScheduler_dec = [Provide17()];
71229
+ var _orgScheduler_dec, _orgService_dec, _messagingRepo_dec3, _settings_dec6, _errors_dec8, _usage_dec6, _projectConfig_dec13, _agentsRepo_dec, _agentConfig_dec6, _agentService_dec, _sessionCreator_dec2, _runner_dec3, _sessionsRepo_dec4, _members_dec4, _projects_dec7, _cache_dec, _log_dec4, _clock_dec12, _channels_dec9, _config_dec11, _OrganizationModule_decorators, _init117;
71230
+ _OrganizationModule_decorators = [Module17()], _config_dec11 = [Use57()], _channels_dec9 = [Use57()], _clock_dec12 = [Use57()], _log_dec4 = [Use57()], _cache_dec = [Use57()], _projects_dec7 = [Use57()], _members_dec4 = [Use57()], _sessionsRepo_dec4 = [Use57()], _runner_dec3 = [Use57()], _sessionCreator_dec2 = [Use57()], _agentService_dec = [Use57()], _agentConfig_dec6 = [Use57()], _agentsRepo_dec = [Use57()], _projectConfig_dec13 = [Use57()], _usage_dec6 = [Use57()], _errors_dec8 = [Use57()], _settings_dec6 = [Use57()], _messagingRepo_dec3 = [Use57()], _orgService_dec = [Provide17()], _orgScheduler_dec = [Provide17()];
70806
71231
  var OrganizationModule = class {
70807
71232
  constructor() {
70808
71233
  __publicField(this, "config", __runInitializers(_init117, 8, this)), __runInitializers(_init117, 11, this);
@@ -70909,7 +71334,7 @@ __decorateElement(_init117, 5, "agentConfig", _agentConfig_dec6, OrganizationMod
70909
71334
  __decorateElement(_init117, 5, "agentsRepo", _agentsRepo_dec, OrganizationModule);
70910
71335
  __decorateElement(_init117, 5, "projectConfig", _projectConfig_dec13, OrganizationModule);
70911
71336
  __decorateElement(_init117, 5, "usage", _usage_dec6, OrganizationModule);
70912
- __decorateElement(_init117, 5, "errors", _errors_dec7, OrganizationModule);
71337
+ __decorateElement(_init117, 5, "errors", _errors_dec8, OrganizationModule);
70913
71338
  __decorateElement(_init117, 5, "settings", _settings_dec6, OrganizationModule);
70914
71339
  __decorateElement(_init117, 5, "messagingRepo", _messagingRepo_dec3, OrganizationModule);
70915
71340
  __decorateElement(_init117, 5, "orgService", _orgService_dec, OrganizationModule);
@@ -76182,7 +76607,7 @@ function suggestIdRoutes(deps) {
76182
76607
  });
76183
76608
  return app;
76184
76609
  }
76185
- var _routes_dec24, _log_dec5, _errors_dec8, _settings_dec11, _orgService_dec3, _benchmarks_dec2, _agents_dec4, _projectConfig_dec15, _projects_dec8, _access_dec10, _SuggestIdRoutes_decorators, _init140;
76610
+ var _routes_dec24, _log_dec5, _errors_dec9, _settings_dec11, _orgService_dec3, _benchmarks_dec2, _agents_dec4, _projectConfig_dec15, _projects_dec8, _access_dec10, _SuggestIdRoutes_decorators, _init140;
76186
76611
  _SuggestIdRoutes_decorators = [Component70({
76187
76612
  contributes: {
76188
76613
  "HttpModule.routes": [
@@ -76194,7 +76619,7 @@ _SuggestIdRoutes_decorators = [Component70({
76194
76619
  }
76195
76620
  ]
76196
76621
  }
76197
- })], _access_dec10 = [Use72()], _projects_dec8 = [Use72()], _projectConfig_dec15 = [Use72()], _agents_dec4 = [Use72()], _benchmarks_dec2 = [Use72()], _orgService_dec3 = [Use72()], _settings_dec11 = [Use72()], _errors_dec8 = [Use72()], _log_dec5 = [Use72()], _routes_dec24 = [Bind30("SuggestIdRoutes.routes")];
76622
+ })], _access_dec10 = [Use72()], _projects_dec8 = [Use72()], _projectConfig_dec15 = [Use72()], _agents_dec4 = [Use72()], _benchmarks_dec2 = [Use72()], _orgService_dec3 = [Use72()], _settings_dec11 = [Use72()], _errors_dec9 = [Use72()], _log_dec5 = [Use72()], _routes_dec24 = [Bind30("SuggestIdRoutes.routes")];
76198
76623
  var SuggestIdRoutes = class {
76199
76624
  constructor() {
76200
76625
  __publicField(this, "access", __runInitializers(_init140, 8, this)), __runInitializers(_init140, 11, this);
@@ -76238,7 +76663,7 @@ __decorateElement(_init140, 5, "agents", _agents_dec4, SuggestIdRoutes);
76238
76663
  __decorateElement(_init140, 5, "benchmarks", _benchmarks_dec2, SuggestIdRoutes);
76239
76664
  __decorateElement(_init140, 5, "orgService", _orgService_dec3, SuggestIdRoutes);
76240
76665
  __decorateElement(_init140, 5, "settings", _settings_dec11, SuggestIdRoutes);
76241
- __decorateElement(_init140, 5, "errors", _errors_dec8, SuggestIdRoutes);
76666
+ __decorateElement(_init140, 5, "errors", _errors_dec9, SuggestIdRoutes);
76242
76667
  __decorateElement(_init140, 5, "log", _log_dec5, SuggestIdRoutes);
76243
76668
  __decorateElement(_init140, 5, "routes", _routes_dec24, SuggestIdRoutes);
76244
76669
  SuggestIdRoutes = __decorateElement(_init140, 0, "SuggestIdRoutes", _SuggestIdRoutes_decorators, SuggestIdRoutes);
@@ -77906,8 +78331,8 @@ var Http = class {
77906
78331
  _init184 = __decoratorStart(null);
77907
78332
  Http = __decorateElement(_init184, 0, "Http", _Http_decorators, Http);
77908
78333
  __runInitializers(_init184, 1, Http);
77909
- var _http_dec3, _access_dec12, _settings_dec12, _errors_dec9, _auth_dec10, _log_dec7, _config_dec21, _HttpModule_decorators, _init185;
77910
- _HttpModule_decorators = [Module19()], _config_dec21 = [Use76()], _log_dec7 = [Use76()], _auth_dec10 = [Use76()], _errors_dec9 = [Use76()], _settings_dec12 = [Use76()], _access_dec12 = [Use76()], _http_dec3 = [Provide19()];
78334
+ var _http_dec3, _access_dec12, _settings_dec12, _errors_dec10, _auth_dec10, _log_dec7, _config_dec21, _HttpModule_decorators, _init185;
78335
+ _HttpModule_decorators = [Module19()], _config_dec21 = [Use76()], _log_dec7 = [Use76()], _auth_dec10 = [Use76()], _errors_dec10 = [Use76()], _settings_dec12 = [Use76()], _access_dec12 = [Use76()], _http_dec3 = [Provide19()];
77911
78336
  var HttpModule = class {
77912
78337
  constructor() {
77913
78338
  __publicField(this, "config", __runInitializers(_init185, 8, this)), __runInitializers(_init185, 11, this);
@@ -77982,7 +78407,7 @@ _init185 = __decoratorStart(null);
77982
78407
  __decorateElement(_init185, 5, "config", _config_dec21, HttpModule);
77983
78408
  __decorateElement(_init185, 5, "log", _log_dec7, HttpModule);
77984
78409
  __decorateElement(_init185, 5, "auth", _auth_dec10, HttpModule);
77985
- __decorateElement(_init185, 5, "errors", _errors_dec9, HttpModule);
78410
+ __decorateElement(_init185, 5, "errors", _errors_dec10, HttpModule);
77986
78411
  __decorateElement(_init185, 5, "settings", _settings_dec12, HttpModule);
77987
78412
  __decorateElement(_init185, 5, "access", _access_dec12, HttpModule);
77988
78413
  __decorateElement(_init185, 5, "http", _http_dec3, HttpModule);
@@ -83389,7 +83814,7 @@ function agentApiTryRoutes(deps) {
83389
83814
  }
83390
83815
 
83391
83816
  // src/amsp/module.ts
83392
- var _tryRoutes_dec, _routes_dec27, _access_dec13, _clock_dec14, _errors_dec10, _log_dec9, _agentConfig_dec8, _channels_dec13, _sessionService_dec3, _manager_dec5, _sessions_dec7, _agentApi_dec4, _settings_dec13, _AmspRoutes_decorators, _init194;
83817
+ var _tryRoutes_dec, _routes_dec27, _access_dec13, _clock_dec14, _errors_dec11, _log_dec9, _agentConfig_dec8, _channels_dec13, _sessionService_dec3, _manager_dec5, _sessions_dec7, _agentApi_dec4, _settings_dec13, _AmspRoutes_decorators, _init194;
83393
83818
  _AmspRoutes_decorators = [Component75({
83394
83819
  contributes: {
83395
83820
  "HttpModule.routes": [
@@ -83402,7 +83827,7 @@ _AmspRoutes_decorators = [Component75({
83402
83827
  }
83403
83828
  ]
83404
83829
  }
83405
- })], _settings_dec13 = [Use79()], _agentApi_dec4 = [Use79()], _sessions_dec7 = [Use79()], _manager_dec5 = [Use79()], _sessionService_dec3 = [Use79()], _channels_dec13 = [Use79()], _agentConfig_dec8 = [Use79()], _log_dec9 = [Use79()], _errors_dec10 = [Use79()], _clock_dec14 = [Use79()], _access_dec13 = [Use79()], _routes_dec27 = [Bind35("AmspRoutes.routes")], _tryRoutes_dec = [Bind35("AmspRoutes.try")];
83830
+ })], _settings_dec13 = [Use79()], _agentApi_dec4 = [Use79()], _sessions_dec7 = [Use79()], _manager_dec5 = [Use79()], _sessionService_dec3 = [Use79()], _channels_dec13 = [Use79()], _agentConfig_dec8 = [Use79()], _log_dec9 = [Use79()], _errors_dec11 = [Use79()], _clock_dec14 = [Use79()], _access_dec13 = [Use79()], _routes_dec27 = [Bind35("AmspRoutes.routes")], _tryRoutes_dec = [Bind35("AmspRoutes.try")];
83406
83831
  var AmspRoutes = class {
83407
83832
  constructor() {
83408
83833
  __publicField(this, "settings", __runInitializers(_init194, 8, this)), __runInitializers(_init194, 11, this);
@@ -83446,7 +83871,7 @@ __decorateElement(_init194, 5, "sessionService", _sessionService_dec3, AmspRoute
83446
83871
  __decorateElement(_init194, 5, "channels", _channels_dec13, AmspRoutes);
83447
83872
  __decorateElement(_init194, 5, "agentConfig", _agentConfig_dec8, AmspRoutes);
83448
83873
  __decorateElement(_init194, 5, "log", _log_dec9, AmspRoutes);
83449
- __decorateElement(_init194, 5, "errors", _errors_dec10, AmspRoutes);
83874
+ __decorateElement(_init194, 5, "errors", _errors_dec11, AmspRoutes);
83450
83875
  __decorateElement(_init194, 5, "clock", _clock_dec14, AmspRoutes);
83451
83876
  __decorateElement(_init194, 5, "access", _access_dec13, AmspRoutes);
83452
83877
  __decorateElement(_init194, 5, "routes", _routes_dec27, AmspRoutes);
@@ -83465,8 +83890,8 @@ AgentApiModule = __decorateElement(_init195, 0, "AgentApiModule", _AgentApiModul
83465
83890
  __runInitializers(_init195, 1, AgentApiModule);
83466
83891
 
83467
83892
  // src/platform.ts
83468
- var _agents_dec6, _usage_dec7, _projectConfig_dec16, _errors_dec11, _machines_dec5, _sessionService_dec4, _orgScheduler_dec2, _scheduler_dec2, _Startup_decorators, _init196;
83469
- _Startup_decorators = [Component76()], _scheduler_dec2 = [Use80()], _orgScheduler_dec2 = [Use80()], _sessionService_dec4 = [Use80()], _machines_dec5 = [Use80()], _errors_dec11 = [Use80()], _projectConfig_dec16 = [Use80()], _usage_dec7 = [Use80()], _agents_dec6 = [Use80()];
83893
+ var _agents_dec6, _usage_dec7, _projectConfig_dec16, _errors_dec12, _machines_dec5, _sessionService_dec4, _orgScheduler_dec2, _scheduler_dec2, _Startup_decorators, _init196;
83894
+ _Startup_decorators = [Component76()], _scheduler_dec2 = [Use80()], _orgScheduler_dec2 = [Use80()], _sessionService_dec4 = [Use80()], _machines_dec5 = [Use80()], _errors_dec12 = [Use80()], _projectConfig_dec16 = [Use80()], _usage_dec7 = [Use80()], _agents_dec6 = [Use80()];
83470
83895
  var Startup = class {
83471
83896
  constructor() {
83472
83897
  __publicField(this, "scheduler", __runInitializers(_init196, 8, this)), __runInitializers(_init196, 11, this);
@@ -83503,7 +83928,7 @@ __decorateElement(_init196, 5, "scheduler", _scheduler_dec2, Startup);
83503
83928
  __decorateElement(_init196, 5, "orgScheduler", _orgScheduler_dec2, Startup);
83504
83929
  __decorateElement(_init196, 5, "sessionService", _sessionService_dec4, Startup);
83505
83930
  __decorateElement(_init196, 5, "machines", _machines_dec5, Startup);
83506
- __decorateElement(_init196, 5, "errors", _errors_dec11, Startup);
83931
+ __decorateElement(_init196, 5, "errors", _errors_dec12, Startup);
83507
83932
  __decorateElement(_init196, 5, "projectConfig", _projectConfig_dec16, Startup);
83508
83933
  __decorateElement(_init196, 5, "usage", _usage_dec7, Startup);
83509
83934
  __decorateElement(_init196, 5, "agents", _agents_dec6, Startup);