opencode-quota-gui 1.3.1 → 1.3.2

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 (155) hide show
  1. package/README.md +16 -12
  2. package/dist/contracts/build-identity.js +1 -1
  3. package/dist/contracts/card-order.d.ts +2 -0
  4. package/dist/contracts/card-order.js +2 -2
  5. package/dist/contracts/card-visibility.d.ts +2 -1
  6. package/dist/contracts/card-visibility.js +2 -1
  7. package/dist/contracts/dashboard.d.ts +87 -5
  8. package/dist/contracts/dashboard.js +10 -0
  9. package/dist/contracts/dto-guards.d.ts +4 -0
  10. package/dist/contracts/dto-guards.js +29 -7
  11. package/dist/contracts/guards.js +3 -1
  12. package/dist/contracts/identity.d.ts +37 -5
  13. package/dist/contracts/identity.js +43 -0
  14. package/dist/contracts/provider-auto-resume.d.ts +9 -0
  15. package/dist/contracts/provider-auto-resume.js +24 -0
  16. package/dist/contracts/provider-failure.d.ts +22 -0
  17. package/dist/contracts/provider-failure.js +25 -1
  18. package/dist/contracts/row-order.d.ts +13 -0
  19. package/dist/contracts/row-order.js +34 -0
  20. package/dist/contracts/row-visibility.d.ts +53 -0
  21. package/dist/contracts/row-visibility.js +130 -0
  22. package/dist/data/modelsdev-pricing.min.json +1 -1
  23. package/dist/data/modelsdev-temporal.min.json +3 -634
  24. package/dist/gui/aggregation.d.ts +29 -1
  25. package/dist/gui/aggregation.js +157 -4
  26. package/dist/gui/analytics-bridge.d.ts +8 -9
  27. package/dist/gui/analytics-bridge.js +197 -54
  28. package/dist/gui/analytics-engine.d.ts +7 -15
  29. package/dist/gui/analytics-engine.js +246 -106
  30. package/dist/gui/analytics-model.d.ts +7 -0
  31. package/dist/gui/analytics-model.js +75 -9
  32. package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
  33. package/dist/gui/analytics-pricing-upkeep.js +23 -0
  34. package/dist/gui/analytics-protocol.d.ts +17 -7
  35. package/dist/gui/analytics-protocol.js +1 -0
  36. package/dist/gui/analytics-service.d.ts +10 -0
  37. package/dist/gui/analytics-service.js +30 -9
  38. package/dist/gui/analytics-state.d.ts +30 -5
  39. package/dist/gui/analytics-state.js +46 -7
  40. package/dist/gui/analytics-worker-runtime.d.ts +5 -0
  41. package/dist/gui/analytics-worker-runtime.js +9 -1
  42. package/dist/gui/analytics-worker.js +11 -0
  43. package/dist/gui/config.d.ts +2 -2
  44. package/dist/gui/config.js +46 -5
  45. package/dist/gui/identity.d.ts +6 -20
  46. package/dist/gui/identity.js +6 -54
  47. package/dist/gui/primary-quota-windows.js +55 -34
  48. package/dist/gui/provider-cards.d.ts +12 -8
  49. package/dist/gui/provider-cards.js +12 -53
  50. package/dist/gui/quota-notification-detector.d.ts +25 -2
  51. package/dist/gui/quota-notification-detector.js +60 -5
  52. package/dist/gui/quota-notification-observer.d.ts +1 -1
  53. package/dist/gui/quota-notification-observer.js +5 -1
  54. package/dist/gui/quota-observation.d.ts +4 -0
  55. package/dist/gui/quota-observation.js +18 -0
  56. package/dist/gui/rpc.js +3 -0
  57. package/dist/gui/server.js +6 -1
  58. package/dist/gui/snapshot-service.d.ts +3 -17
  59. package/dist/gui/snapshot-service.js +159 -9
  60. package/dist/gui/sources.js +84 -11
  61. package/dist/gui/temporal-status.d.ts +3 -2
  62. package/dist/gui/temporal-status.js +10 -6
  63. package/dist/gui-experimental.cjs +228 -228
  64. package/dist/lib/accounting-format.d.ts +8 -0
  65. package/dist/lib/accounting-format.js +12 -2
  66. package/dist/lib/anthropic-api-auth.d.ts +7 -0
  67. package/dist/lib/anthropic-api-auth.js +27 -0
  68. package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
  69. package/dist/lib/anthropic-api-rate-limits.js +92 -0
  70. package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
  71. package/dist/lib/anthropic-oauth-throttle.js +379 -0
  72. package/dist/lib/anthropic.d.ts +22 -4
  73. package/dist/lib/anthropic.js +498 -180
  74. package/dist/lib/cache-observer-ingestion.js +27 -0
  75. package/dist/lib/cache-observer.d.ts +3 -0
  76. package/dist/lib/cache-observer.js +9 -3
  77. package/dist/lib/cli-show.d.ts +5 -0
  78. package/dist/lib/cli-show.js +16 -5
  79. package/dist/lib/cli-status.js +3 -6
  80. package/dist/lib/config.d.ts +1 -1
  81. package/dist/lib/config.js +64 -2
  82. package/dist/lib/dashboard-visibility.d.ts +5 -0
  83. package/dist/lib/dashboard-visibility.js +11 -10
  84. package/dist/lib/display-sanitize.js +1 -0
  85. package/dist/lib/entries.d.ts +10 -1
  86. package/dist/lib/entries.js +4 -0
  87. package/dist/lib/grouped-entry-normalization.js +1 -1
  88. package/dist/lib/maintainer-announcements.js +2 -2
  89. package/dist/lib/modelsdev-pricing.d.ts +74 -2
  90. package/dist/lib/modelsdev-pricing.js +457 -63
  91. package/dist/lib/modelsdev-temporal.d.ts +6 -0
  92. package/dist/lib/modelsdev-temporal.js +16 -2
  93. package/dist/lib/opencode-config-providers.js +2 -2
  94. package/dist/lib/opencode-storage.d.ts +20 -0
  95. package/dist/lib/opencode-storage.js +89 -2
  96. package/dist/lib/opencode-version-core.d.ts +7 -0
  97. package/dist/lib/opencode-version-core.js +10 -0
  98. package/dist/lib/opencode-warming-refresh.d.ts +19 -0
  99. package/dist/lib/opencode-warming-refresh.js +95 -0
  100. package/dist/lib/provider-metadata.d.ts +11 -3
  101. package/dist/lib/provider-metadata.js +20 -2
  102. package/dist/lib/provider-registration.d.ts +342 -3
  103. package/dist/lib/provider-registration.js +409 -27
  104. package/dist/lib/quota-auto-resume.d.ts +74 -0
  105. package/dist/lib/quota-auto-resume.js +539 -0
  106. package/dist/lib/quota-command-format.js +22 -9
  107. package/dist/lib/quota-identity.d.ts +64 -0
  108. package/dist/lib/quota-identity.js +111 -0
  109. package/dist/lib/quota-providers.js +2 -2
  110. package/dist/lib/quota-render-data.js +2 -2
  111. package/dist/lib/quota-reset-notifications.js +11 -155
  112. package/dist/lib/quota-retry-wait.d.ts +106 -5
  113. package/dist/lib/quota-retry-wait.js +301 -34
  114. package/dist/lib/quota-runtime-context.js +1 -0
  115. package/dist/lib/quota-state-codec.d.ts +2 -0
  116. package/dist/lib/quota-state-codec.js +14 -1
  117. package/dist/lib/quota-state.d.ts +1 -1
  118. package/dist/lib/quota-state.js +60 -28
  119. package/dist/lib/quota-stats.d.ts +26 -0
  120. package/dist/lib/quota-stats.js +19 -1
  121. package/dist/lib/quota-surface-data.js +18 -3
  122. package/dist/lib/quota-telemetry.js +2 -2
  123. package/dist/lib/resolved-auth-identity.d.ts +19 -0
  124. package/dist/lib/resolved-auth-identity.js +44 -0
  125. package/dist/lib/state-file-lock.d.ts +26 -0
  126. package/dist/lib/state-file-lock.js +205 -0
  127. package/dist/lib/toast-format-grouped.js +7 -4
  128. package/dist/lib/tui-compact-format.js +29 -16
  129. package/dist/lib/types.d.ts +20 -0
  130. package/dist/lib/types.js +4 -1
  131. package/dist/plugin.js +67 -1
  132. package/dist/providers/alibaba-coding-plan.js +21 -3
  133. package/dist/providers/alibaba-token-plan.js +9 -5
  134. package/dist/providers/anthropic.d.ts +6 -2
  135. package/dist/providers/anthropic.js +123 -14
  136. package/dist/providers/chutes.js +2 -0
  137. package/dist/providers/claude-agent.js +24 -5
  138. package/dist/providers/copilot.js +5 -4
  139. package/dist/providers/glm-coding-plan-provider.js +30 -23
  140. package/dist/providers/ollama-cloud.js +10 -0
  141. package/dist/providers/openai.js +24 -23
  142. package/dist/providers/opencode-go.js +7 -6
  143. package/dist/providers/opencode-zen.js +1 -1
  144. package/dist/providers/result-helpers.d.ts +4 -2
  145. package/dist/providers/result-helpers.js +5 -1
  146. package/dist/providers/synthetic.js +4 -0
  147. package/dist/providers/xai.js +9 -8
  148. package/dist/rpc.d.ts +8 -0
  149. package/dist/rpc.js +15 -2
  150. package/dist/ui/assets/{index-BcueIm3Z.css → index-6_g1FHs-.css} +1 -1
  151. package/dist/ui/assets/index-sZnGUuML.js +10 -0
  152. package/dist/ui/assets/{popover-4bFSvRZ7.js → popover-C4ZLYe9E.js} +1 -1
  153. package/dist/ui/index.html +2 -2
  154. package/package.json +3 -3
  155. package/dist/ui/assets/index-C6qRSoh8.js +0 -10
@@ -67,7 +67,8 @@ const SNAPSHOT_KEYS = new Set([
67
67
  "jurisdictions",
68
68
  "providers",
69
69
  ]);
70
- const POLICY_KEYS = new Set(["status", "source", "overrides", "multipliers", "reason"]);
70
+ const POLICY_KEYS = new Set(["status", "source", "base", "overrides", "multipliers", "reason"]);
71
+ const BASE_RATE_KEYS = new Set(TEMPORAL_RATE_KEYS);
71
72
  const CALENDAR_KEYS = new Set(["timeZone", "source", "published", "intervals", "makeupWorkdays"]);
72
73
  const INTERVAL_KEYS = new Set(["id", "localStart", "localEnd", "startMs", "endMs"]);
73
74
  const OVERRIDE_KEYS = new Set(["id", "field", "when", "rates"]);
@@ -282,6 +283,18 @@ function parseRates(raw, field, path) {
282
283
  fail(`${path} must set at least one rate`);
283
284
  return rates;
284
285
  }
286
+ function parseBaseRates(raw, path) {
287
+ const object = asObject(raw, path);
288
+ assertKeys(object, BASE_RATE_KEYS, path);
289
+ const rates = {};
290
+ for (const key of TEMPORAL_RATE_KEYS) {
291
+ if (hasOwn(object, key))
292
+ rates[key] = asRate(object[key], `${path}.${key}`);
293
+ }
294
+ if (Object.keys(rates).length === 0)
295
+ fail(`${path} must set at least one rate`);
296
+ return rates;
297
+ }
285
298
  function parseMultiplierFactor(raw, path) {
286
299
  if (typeof raw === "number") {
287
300
  return asRate(raw, path);
@@ -310,6 +323,7 @@ function parsePolicyEntry(raw, providerId, modelId, path) {
310
323
  }
311
324
  if (status !== "supported")
312
325
  fail(`${path}.status is not supported`);
326
+ const base = hasOwn(object, "base") ? parseBaseRates(object.base, `${path}.base`) : undefined;
313
327
  const rawOverrides = asArray(object.overrides, `${path}.overrides`);
314
328
  const rawMultipliers = asArray(object.multipliers, `${path}.multipliers`);
315
329
  if (rawOverrides.length === 0 && rawMultipliers.length === 0) {
@@ -348,7 +362,7 @@ function parsePolicyEntry(raw, providerId, modelId, path) {
348
362
  factor: parseMultiplierFactor(multiplier.factor, `${multiplierPath}.factor`),
349
363
  };
350
364
  });
351
- return { status: "supported", source, overrides, multipliers };
365
+ return { status: "supported", source, ...(base ? { base } : {}), overrides, multipliers };
352
366
  }
353
367
  function parseHolidayCalendar(raw, path) {
354
368
  const object = asObject(raw, path);
@@ -3,7 +3,7 @@ import { dedupeNonEmptyStrings, extractPluginSpecsFromParsedConfig, extractProvi
3
3
  import { applyConfigDocumentEdit, ConfigDocumentError, parseConfigDocument, planConfigDocumentEdit, } from "./opencode-config-editor.js";
4
4
  import { buildOpenCodeConfigCandidates, readOpenCodeConfigCandidate, selectFirstExistingOpenCodeConfigCandidate, } from "./opencode-config-read.js";
5
5
  import { getOpencodeRuntimeDirs } from "./opencode-runtime-paths.js";
6
- import { getQuotaProviderRuntimeIds, getQuotaProviderShape, normalizeQuotaProviderId, } from "./provider-metadata.js";
6
+ import { getQuotaProviderRegistration, getQuotaProviderRuntimeIds, normalizeQuotaProviderId, } from "./provider-metadata.js";
7
7
  function isRecord(value) {
8
8
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
9
9
  }
@@ -88,7 +88,7 @@ export async function reconcileDetectedProvidersInGlobalConfig(options) {
88
88
  const detectedProviderIds = dedupeNonEmptyStrings(options.detectedProviderIds
89
89
  .map((providerId) => normalizeQuotaProviderId(providerId))
90
90
  .filter((providerId) => {
91
- const shape = getQuotaProviderShape(providerId);
91
+ const shape = getQuotaProviderRegistration(providerId);
92
92
  return Boolean(shape && shape.id !== "quota-providers");
93
93
  }));
94
94
  const globalConfigDir = getOpencodeRuntimeDirs().configDir;
@@ -127,6 +127,14 @@ export interface OpenCodeRawAssistantRow {
127
127
  providerID?: string;
128
128
  modelID?: string;
129
129
  agent?: string;
130
+ /** Reasoning effort as stored (`model.variant`); absent when not recorded. */
131
+ variant?: string;
132
+ /**
133
+ * The stored message had no numeric cache counter. `tokens.cacheRead/Write`
134
+ * still read 0 for accounting, but the 0 is unknown, not an observed zero.
135
+ */
136
+ cacheReadMissing?: true;
137
+ cacheWriteMissing?: true;
130
138
  }
131
139
  /**
132
140
  * True when a completed assistant row carries at least one non-zero additive
@@ -152,6 +160,7 @@ export interface OpenCodeCompactionMarker {
152
160
  messageId: string;
153
161
  }
154
162
  export interface ReadCompletedAssistantRowsParams {
163
+ createdSinceMs?: number;
155
164
  completedSinceMs?: number;
156
165
  completedUntilMs?: number;
157
166
  /**
@@ -185,6 +194,11 @@ export interface OpenCodeMessageRevision {
185
194
  updatedAtMs: number | null;
186
195
  /** Positive parsed `$.time.completed`; null when unfinished or unavailable. */
187
196
  completedAtMs: number | null;
197
+ /**
198
+ * Assistant `$.parentID`: the user message this reply answers, when the
199
+ * stored JSON records it. Absent on user rows and on schemas without JSON.
200
+ */
201
+ parentID?: string;
188
202
  }
189
203
  export interface OpenCodeMessageRevisionSnapshot {
190
204
  /** false when `session_message` is absent or unreadable. */
@@ -287,6 +301,12 @@ export interface OpenCodeStorageSnapshot {
287
301
  readonly dbPath: string;
288
302
  /** Identity captured for the transaction that backs every reader below. */
289
303
  readonly identity: OpenCodeSourceIdentity;
304
+ /**
305
+ * Cheap source-change evidence captured before this snapshot's transaction
306
+ * began; `null` when the filesystem could not be inspected. See
307
+ * `readOpenCodeSourceChangeSignature`.
308
+ */
309
+ readonly changeSignature?: string | null;
290
310
  readAllSessionsIndex(): Record<string, OpenCodeSessionInfo>;
291
311
  readProjectsIndex(): Record<string, OpenCodeProjectInfo>;
292
312
  readCompletedAssistantRows(params?: ReadCompletedAssistantRowsParams): OpenCodeRawAssistantRow[];
@@ -107,6 +107,7 @@ const PROJECTED_MESSAGE_COLUMNS = [
107
107
  `${guardedJsonScalar("$.cost")} AS cost`,
108
108
  `${guardedJsonScalar("$.time.completed")} AS time_completed`,
109
109
  `${guardedJsonScalar("$.agent")} AS agent`,
110
+ `${guardedJsonScalar("$.model.variant")} AS variant`,
110
111
  ].join(", ");
111
112
  const ASSISTANT_FILTER = `type = 'assistant'`;
112
113
  function buildMessageQuery(params) {
@@ -203,6 +204,10 @@ function buildCompletedAssistantQuery(params, includeUpdatedAt = false) {
203
204
  `${completedExpression} > 0`,
204
205
  ];
205
206
  const args = [];
207
+ if (typeof params.createdSinceMs === "number") {
208
+ where.push("time_created >= ?");
209
+ args.push(params.createdSinceMs);
210
+ }
206
211
  if (typeof params.completedSinceMs === "number") {
207
212
  where.push(`${completedExpression} >= ?`);
208
213
  args.push(params.completedSinceMs);
@@ -594,6 +599,7 @@ function mapRawCompletedAssistantRow(row) {
594
599
  const completed = completedAt(message);
595
600
  if (completed === null)
596
601
  return null;
602
+ const variant = normalizeString(row.variant);
597
603
  return {
598
604
  sessionID: message.sessionID,
599
605
  messageID: message.id,
@@ -610,6 +616,9 @@ function mapRawCompletedAssistantRow(row) {
610
616
  providerID: message.providerID,
611
617
  modelID: message.modelID,
612
618
  agent: message.agent,
619
+ ...(variant === undefined ? {} : { variant }),
620
+ ...(normalizeNumber(row.tokens_cache_read) === undefined ? { cacheReadMissing: true } : {}),
621
+ ...(normalizeNumber(row.tokens_cache_write) === undefined ? { cacheWriteMissing: true } : {}),
613
622
  };
614
623
  }
615
624
  /**
@@ -637,6 +646,7 @@ function readCompletedAssistantRowsFrom(conn, params) {
637
646
  return [];
638
647
  const hasUpdatedAt = columns.has("time_updated");
639
648
  const reservedArgs = countDefined([
649
+ params.createdSinceMs,
640
650
  params.completedSinceMs,
641
651
  params.completedUntilMs,
642
652
  params.completedAtTimes,
@@ -658,6 +668,7 @@ function readCompletedAssistantRowsFrom(conn, params) {
658
668
  }
659
669
  else {
660
670
  const queries = scopedIdQueries(scope.ids, maxIdsPerQuery, (clause) => buildCompletedAssistantQuery({
671
+ createdSinceMs: params.createdSinceMs,
661
672
  completedSinceMs: params.completedSinceMs,
662
673
  completedUntilMs: params.completedUntilMs,
663
674
  completedAtTimes: params.completedAtTimes,
@@ -871,6 +882,7 @@ function readMessageRevisionsFrom(conn, params) {
871
882
  completedAtAvailable
872
883
  ? `${guardedJsonScalar("$.time.completed")} AS completed`
873
884
  : "NULL AS completed",
885
+ completedAtAvailable ? `${guardedJsonScalar("$.parentID")} AS parent_id` : "NULL AS parent_id",
874
886
  ].join(", ");
875
887
  const revisions = [];
876
888
  const updatedDelta = updatedAtAvailable && typeof params.updatedSinceMs === "number"
@@ -915,6 +927,7 @@ function readMessageRevisionsFrom(conn, params) {
915
927
  const createdAt = normalizeNumber(row.time_created);
916
928
  const updatedAt = normalizeNumber(row.time_updated);
917
929
  const completed = normalizeNumber(row.completed);
930
+ const parentID = normalizeString(row.parent_id);
918
931
  revisions.push({
919
932
  messageID: row.id,
920
933
  sessionID: row.session_id,
@@ -922,6 +935,7 @@ function readMessageRevisionsFrom(conn, params) {
922
935
  createdAtMs: createdAt ?? 0,
923
936
  updatedAtMs: updatedAt ?? null,
924
937
  completedAtMs: completed !== undefined && completed > 0 ? Math.trunc(completed) : null,
938
+ ...(parentID === undefined ? {} : { parentID }),
925
939
  });
926
940
  }
927
941
  };
@@ -1101,6 +1115,75 @@ function readSourceIdentityStat() {
1101
1115
  }
1102
1116
  return identity;
1103
1117
  }
1118
+ /**
1119
+ * Cheap, non-mutating evidence that the SQLite files changed since the last
1120
+ * completed analytics revision.
1121
+ *
1122
+ * The revision projection is a full scan because completion time lives in
1123
+ * message JSON. Before paying for it, the worker compares this signature with
1124
+ * the one persisted alongside the compact index. Any committed write appends to
1125
+ * the WAL (or changes the main file when a rollback journal is used), so the
1126
+ * size/mtime of `opencode.db` and `opencode.db-wal` plus the stable file
1127
+ * identity change for inserts, deletions, and in-place JSON updates. A
1128
+ * read-only connection's `PRAGMA data_version` is intentionally not used: it is
1129
+ * only comparable within one connection, and the storage snapshot opens a new
1130
+ * connection per refresh.
1131
+ *
1132
+ * The signature is captured before the snapshot transaction begins. Any write
1133
+ * counted here is therefore committed before `BEGIN`, so the same refresh can
1134
+ * persist this signature with data that already includes it. A write that lands
1135
+ * after the stat is caught by the next refresh because its file state differs.
1136
+ *
1137
+ * This is an optimization, not the correctness boundary: a same-size WAL or a
1138
+ * coarse filesystem timestamp can theoretically hide a commit, so the persisted
1139
+ * 7-day repair still re-reads the source periodically (and always overrides the
1140
+ * signature gate when due).
1141
+ */
1142
+ function readOpenCodeSourceChangeSignature() {
1143
+ const dbPath = getOpenCodeDbPath();
1144
+ if (dbPath === ":memory:")
1145
+ return null;
1146
+ let database;
1147
+ try {
1148
+ database = statSync(dbPath, { bigint: true });
1149
+ }
1150
+ catch {
1151
+ return null;
1152
+ }
1153
+ if (!database.isFile())
1154
+ return null;
1155
+ const dbMtime = typeof database.mtimeNs === "bigint" ? database.mtimeNs.toString() : String(database.mtimeMs);
1156
+ let wal = "absent";
1157
+ try {
1158
+ const walStat = statSync(`${dbPath}-wal`, { bigint: true });
1159
+ // Opening a WAL database read-only may create a zero-length `-wal`; it
1160
+ // holds no committed frames, so it must not look like a source change.
1161
+ if (walStat.isFile() && walStat.size > 0n) {
1162
+ const walMtime = typeof walStat.mtimeNs === "bigint" ? walStat.mtimeNs.toString() : String(walStat.mtimeMs);
1163
+ wal = `${walStat.size}:${walMtime}`;
1164
+ }
1165
+ }
1166
+ catch (error) {
1167
+ // Only "no WAL file" is conclusive (rollback journal). Any other stat
1168
+ // failure makes the evidence inconclusive, so return no signature and let
1169
+ // the caller scan.
1170
+ const code = typeof error === "object" && error !== null && "code" in error
1171
+ ? error.code
1172
+ : undefined;
1173
+ if (code !== "ENOENT" && code !== "ENOTDIR")
1174
+ return null;
1175
+ }
1176
+ return [
1177
+ "v1",
1178
+ dbPath,
1179
+ database.dev.toString(),
1180
+ database.ino.toString(),
1181
+ database.birthtimeNs.toString(),
1182
+ database.size.toString(),
1183
+ dbMtime,
1184
+ wal,
1185
+ ].join("|");
1186
+ }
1104
1187
  /**
1105
1188
  * Read the local source identity. `status: "ok"` means the file exists and the
1106
1189
  * schema was readable (including a successfully opened, empty database);
@@ -1128,10 +1211,11 @@ export async function readOpenCodeSourceIdentity() {
1128
1211
  conn.close();
1129
1212
  }
1130
1213
  }
1131
- function createStorageSnapshot(conn, identity) {
1214
+ function createStorageSnapshot(conn, identity, changeSignature) {
1132
1215
  return {
1133
1216
  dbPath: identity.dbPath,
1134
1217
  identity,
1218
+ changeSignature,
1135
1219
  readAllSessionsIndex: () => readAllSessionsIndexFrom(conn),
1136
1220
  readProjectsIndex: () => readProjectsIndexFrom(conn),
1137
1221
  readCompletedAssistantRows: (params = {}) => readCompletedAssistantRowsFrom(conn, params),
@@ -1183,6 +1267,9 @@ export async function withOpenCodeStorageSnapshot(read) {
1183
1267
  return { status: "missing" };
1184
1268
  if (statIdentity.status === "unreadable")
1185
1269
  return { status: "unreadable" };
1270
+ // Captured before `BEGIN`: every write counted by the signature is visible to
1271
+ // the transaction, so the refresh may persist it with data that includes it.
1272
+ const changeSignature = readOpenCodeSourceChangeSignature();
1186
1273
  let conn;
1187
1274
  try {
1188
1275
  conn = await openOpenCodeSqliteReadOnly(statIdentity.dbPath);
@@ -1210,7 +1297,7 @@ export async function withOpenCodeStorageSnapshot(read) {
1210
1297
  catch {
1211
1298
  return { status: "unreadable" };
1212
1299
  }
1213
- const value = await read(createStorageSnapshot(conn, identity));
1300
+ const value = await read(createStorageSnapshot(conn, identity, changeSignature));
1214
1301
  // Do not publish a generation if the path was replaced during the read;
1215
1302
  // the connection remains the old file while the path already points at a
1216
1303
  // different generation.
@@ -14,6 +14,13 @@ export declare function parseOpenCodeMajor(output: string): OpenCodeMajor | unde
14
14
  * unparseable versions are not assumed capable.
15
15
  */
16
16
  export declare function supportsNativeGui(version: string | OpenCodeVersion | undefined): boolean;
17
+ /**
18
+ * Whether the host renders the visible heading of a composer pill's custom
19
+ * `menu` popover itself. Hosts before 2.4.0 do (the popover body then starts
20
+ * below that heading); 2.4.0 moved the whole popover body, including any
21
+ * heading, to the plugin. Unknown versions are treated as the newer contract.
22
+ */
23
+ export declare function hostRendersComposerMenuHeading(version: string | OpenCodeVersion | undefined): boolean;
17
24
  /**
18
25
  * Whether the host predates the Native GUI and therefore keeps the compatibility
19
26
  * web dashboard on by default. Only a parseable version below 2.2.1 qualifies;
@@ -37,6 +37,16 @@ export function supportsNativeGui(version) {
37
37
  const parsed = typeof version === "string" ? parseOpenCodeVersion(version) : version;
38
38
  return parsed !== undefined && isAtLeast(parsed, 2, 2, 1);
39
39
  }
40
+ /**
41
+ * Whether the host renders the visible heading of a composer pill's custom
42
+ * `menu` popover itself. Hosts before 2.4.0 do (the popover body then starts
43
+ * below that heading); 2.4.0 moved the whole popover body, including any
44
+ * heading, to the plugin. Unknown versions are treated as the newer contract.
45
+ */
46
+ export function hostRendersComposerMenuHeading(version) {
47
+ const parsed = typeof version === "string" ? parseOpenCodeVersion(version) : version;
48
+ return parsed !== undefined && !isAtLeast(parsed, 2, 4, 0);
49
+ }
40
50
  /**
41
51
  * Whether the host predates the Native GUI and therefore keeps the compatibility
42
52
  * web dashboard on by default. Only a parseable version below 2.2.1 qualifies;
@@ -0,0 +1,19 @@
1
+ export interface WarmingRefresh {
2
+ sessionID: string;
3
+ dispatchMs: number;
4
+ evidence: "warming-inferred";
5
+ }
6
+ export declare class OpencodeWarmingRefreshTracker {
7
+ private readonly sessions;
8
+ private session;
9
+ onModelRequest(input: {
10
+ sessionID?: unknown;
11
+ kind?: unknown;
12
+ model?: unknown;
13
+ }, nowMs: number): void;
14
+ private onStep;
15
+ onStepStarted(event: unknown): void;
16
+ onStepEnded(event: unknown): void;
17
+ onUsageUpdated(event: unknown): WarmingRefresh | undefined;
18
+ }
19
+ //# sourceMappingURL=opencode-warming-refresh.d.ts.map
@@ -0,0 +1,95 @@
1
+ const MAX_TRACKED_SESSIONS = 256;
2
+ function text(value) {
3
+ return typeof value === "string" && value.length > 0 ? value : undefined;
4
+ }
5
+ function record(value) {
6
+ return typeof value === "object" && value !== null
7
+ ? value
8
+ : undefined;
9
+ }
10
+ function modelKey(value) {
11
+ const model = record(value);
12
+ const provider = text(model?.providerID);
13
+ const id = text(model?.id) ?? text(model?.modelID);
14
+ return provider !== undefined && id !== undefined ? JSON.stringify([provider, id]) : undefined;
15
+ }
16
+ export class OpencodeWarmingRefreshTracker {
17
+ sessions = new Map();
18
+ session(id) {
19
+ let state = this.sessions.get(id);
20
+ if (state === undefined) {
21
+ state = { requests: 0, generate: false, step: false, tainted: false };
22
+ this.sessions.set(id, state);
23
+ if (this.sessions.size > MAX_TRACKED_SESSIONS) {
24
+ const oldest = this.sessions.keys().next().value;
25
+ if (oldest !== undefined)
26
+ this.sessions.delete(oldest);
27
+ }
28
+ }
29
+ return state;
30
+ }
31
+ onModelRequest(input, nowMs) {
32
+ const request = record(input);
33
+ const id = text(request?.sessionID);
34
+ if (id === undefined)
35
+ return;
36
+ const state = this.session(id);
37
+ state.requests++;
38
+ if (request?.kind === "generate") {
39
+ state.generate = true;
40
+ const model = modelKey(request.model);
41
+ if (model !== undefined && Number.isFinite(nowMs))
42
+ state.candidate = { model, dispatchMs: nowMs };
43
+ }
44
+ }
45
+ onStep(event, started) {
46
+ const data = record(record(event)?.data);
47
+ const id = text(data?.sessionID);
48
+ if (id === undefined)
49
+ return;
50
+ const state = this.session(id);
51
+ state.step = true;
52
+ if (started)
53
+ state.model = modelKey(data?.model);
54
+ else
55
+ state.tainted = false;
56
+ }
57
+ onStepStarted(event) {
58
+ this.onStep(event, true);
59
+ }
60
+ onStepEnded(event) {
61
+ this.onStep(event, false);
62
+ }
63
+ onUsageUpdated(event) {
64
+ const data = record(record(event)?.data);
65
+ const id = text(data?.sessionID);
66
+ if (id === undefined)
67
+ return undefined;
68
+ const state = this.session(id);
69
+ const read = record(record(data?.tokens)?.cache)?.read;
70
+ const cacheRead = typeof read === "number" && Number.isFinite(read) ? read : undefined;
71
+ // Cumulative, source-less usage may under-detect refreshes and should rarely over-detect them.
72
+ const accepted = !state.tainted &&
73
+ !state.step &&
74
+ state.requests === 1 &&
75
+ state.generate &&
76
+ state.candidate !== undefined &&
77
+ state.model !== undefined &&
78
+ state.candidate.model === state.model &&
79
+ state.baseline !== undefined &&
80
+ cacheRead !== undefined &&
81
+ cacheRead > state.baseline;
82
+ const result = accepted && state.candidate !== undefined
83
+ ? { sessionID: id, dispatchMs: state.candidate.dispatchMs, evidence: "warming-inferred" }
84
+ : undefined;
85
+ if (!accepted && state.generate)
86
+ state.tainted = true;
87
+ state.baseline = cacheRead;
88
+ state.requests = 0;
89
+ state.generate = false;
90
+ state.candidate = undefined;
91
+ state.step = false;
92
+ return result;
93
+ }
94
+ }
95
+ //# sourceMappingURL=opencode-warming-refresh.js.map
@@ -1,5 +1,5 @@
1
- import { type CanonicalQuotaProviderId, type QuotaProviderAuthentication, type QuotaProviderAuthFallback, type QuotaProviderAutoSetup, type QuotaProviderQuotaSource } from "./provider-registration.js";
2
- export type { CanonicalQuotaProviderId, QuotaProviderAuthentication, QuotaProviderAuthFallback, QuotaProviderAutoSetup, QuotaProviderQuotaSource, } from "./provider-registration.js";
1
+ import { type CanonicalQuotaProviderId, type QuotaProviderAuthentication, type QuotaProviderAuthFallback, type QuotaProviderAutoResumeBinding, type QuotaProviderAutoSetup, type QuotaProviderOptionalVisibilityRow, type QuotaProviderQuotaSource } from "./provider-registration.js";
2
+ export type { CanonicalQuotaProviderId, QuotaProviderAuthentication, QuotaProviderAuthFallback, QuotaProviderAutoResumeBinding, QuotaProviderAutoSetup, QuotaProviderQuotaSource, } from "./provider-registration.js";
3
3
  export interface QuotaProviderShape {
4
4
  id: CanonicalQuotaProviderId;
5
5
  recommendedReplacementId?: CanonicalQuotaProviderId;
@@ -7,6 +7,8 @@ export interface QuotaProviderShape {
7
7
  authentication: QuotaProviderAuthentication;
8
8
  authFallbacks?: QuotaProviderAuthFallback[];
9
9
  quota: QuotaProviderQuotaSource;
10
+ autoResume?: QuotaProviderAutoResumeBinding;
11
+ optionalVisibilityRows?: readonly QuotaProviderOptionalVisibilityRow[];
10
12
  quickSetupAnchor?: string;
11
13
  notes?: string;
12
14
  }
@@ -24,7 +26,13 @@ export declare const QUOTA_PROVIDER_ID_SYNONYMS: Readonly<Record<string, string>
24
26
  export declare const QUOTA_PROVIDER_RUNTIME_IDS: QuotaProviderRuntimeIds;
25
27
  export declare const QUOTA_PROVIDER_SHAPES: readonly QuotaProviderShape[];
26
28
  export declare function normalizeQuotaProviderId(id: string): string;
27
- export declare function getQuotaProviderShape(id: string): QuotaProviderShape | undefined;
29
+ export declare function getQuotaProviderRegistration(id: string): QuotaProviderShape | undefined;
30
+ /** Display labels for providers that can supply one exact auto-resume binding kind. */
31
+ export declare function getAutoResumeProviderLabelsForBinding(binding: QuotaProviderAutoResumeBinding): readonly string[];
32
+ /** Display labels for every provider that can supply auto-resume evidence. */
33
+ export declare function getSupportedAutoResumeProviderLabels(): readonly string[];
34
+ /** Display labels for providers that can never supply auto-resume evidence. */
35
+ export declare function getUnsupportedAutoResumeProviderLabels(): readonly string[];
28
36
  export declare function getQuotaProviderDisplayLabel(id: string): string;
29
37
  export declare function getQuotaProviderRuntimeIds(id: string): readonly string[];
30
38
  export declare function getQuotaProviderIdsForRuntimeId(id: string): readonly CanonicalQuotaProviderId[];
@@ -63,18 +63,36 @@ export function normalizeQuotaProviderId(id) {
63
63
  const normalized = id.trim().toLowerCase();
64
64
  return QUOTA_PROVIDER_ID_SYNONYMS[normalized] ?? normalized;
65
65
  }
66
- export function getQuotaProviderShape(id) {
66
+ export function getQuotaProviderRegistration(id) {
67
67
  const normalized = normalizeQuotaProviderId(id);
68
68
  return isCanonicalQuotaProviderId(normalized)
69
69
  ? QUOTA_PROVIDER_CATALOG[normalized].shape
70
70
  : undefined;
71
71
  }
72
+ function autoResumeProviderLabels(predicate) {
73
+ return catalogKeys()
74
+ .filter((id) => id !== "quota-providers")
75
+ .filter((id) => predicate(QUOTA_PROVIDER_CATALOG[id].shape.autoResume))
76
+ .map((id) => QUOTA_PROVIDER_CATALOG[id].label);
77
+ }
78
+ /** Display labels for providers that can supply one exact auto-resume binding kind. */
79
+ export function getAutoResumeProviderLabelsForBinding(binding) {
80
+ return autoResumeProviderLabels((candidate) => candidate === binding);
81
+ }
82
+ /** Display labels for every provider that can supply auto-resume evidence. */
83
+ export function getSupportedAutoResumeProviderLabels() {
84
+ return autoResumeProviderLabels((binding) => binding !== undefined);
85
+ }
86
+ /** Display labels for providers that can never supply auto-resume evidence. */
87
+ export function getUnsupportedAutoResumeProviderLabels() {
88
+ return autoResumeProviderLabels((binding) => binding === undefined);
89
+ }
72
90
  export function getQuotaProviderDisplayLabel(id) {
73
91
  const normalized = normalizeQuotaProviderId(id);
74
92
  return QUOTA_PROVIDER_LABELS[normalized] ?? id;
75
93
  }
76
94
  export function getQuotaProviderRuntimeIds(id) {
77
- const shape = getQuotaProviderShape(id);
95
+ const shape = getQuotaProviderRegistration(id);
78
96
  if (!shape) {
79
97
  return [];
80
98
  }