opencode-quota-gui 1.3.0 → 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.
- package/README.md +34 -20
- package/dist/bin/opencode-quota-gui.js +0 -0
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/card-order.d.ts +2 -0
- package/dist/contracts/card-order.js +2 -2
- package/dist/contracts/card-visibility.d.ts +2 -1
- package/dist/contracts/card-visibility.js +2 -1
- package/dist/contracts/dashboard.d.ts +95 -6
- package/dist/contracts/dashboard.js +10 -0
- package/dist/contracts/dto-guards.d.ts +4 -0
- package/dist/contracts/dto-guards.js +31 -7
- package/dist/contracts/guards.js +3 -1
- package/dist/contracts/identity.d.ts +37 -5
- package/dist/contracts/identity.js +43 -0
- package/dist/contracts/openai-quota.d.ts +3 -0
- package/dist/contracts/openai-quota.js +3 -0
- package/dist/contracts/provider-auto-resume.d.ts +9 -0
- package/dist/contracts/provider-auto-resume.js +24 -0
- package/dist/contracts/provider-failure.d.ts +22 -0
- package/dist/contracts/provider-failure.js +25 -1
- package/dist/contracts/row-order.d.ts +13 -0
- package/dist/contracts/row-order.js +34 -0
- package/dist/contracts/row-visibility.d.ts +53 -0
- package/dist/contracts/row-visibility.js +130 -0
- package/dist/data/modelsdev-pricing.min.json +1 -1
- package/dist/data/modelsdev-temporal.min.json +60 -634
- package/dist/gui/aggregation.d.ts +29 -1
- package/dist/gui/aggregation.js +157 -4
- package/dist/gui/analytics-bridge.d.ts +8 -9
- package/dist/gui/analytics-bridge.js +197 -54
- package/dist/gui/analytics-engine.d.ts +7 -15
- package/dist/gui/analytics-engine.js +246 -106
- package/dist/gui/analytics-model.d.ts +7 -0
- package/dist/gui/analytics-model.js +75 -9
- package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
- package/dist/gui/analytics-pricing-upkeep.js +23 -0
- package/dist/gui/analytics-protocol.d.ts +17 -7
- package/dist/gui/analytics-protocol.js +1 -0
- package/dist/gui/analytics-service.d.ts +10 -0
- package/dist/gui/analytics-service.js +30 -9
- package/dist/gui/analytics-state.d.ts +30 -5
- package/dist/gui/analytics-state.js +46 -7
- package/dist/gui/analytics-worker-runtime.d.ts +5 -0
- package/dist/gui/analytics-worker-runtime.js +9 -1
- package/dist/gui/analytics-worker.js +11 -0
- package/dist/gui/config.d.ts +3 -3
- package/dist/gui/config.js +77 -7
- package/dist/gui/identity.d.ts +6 -20
- package/dist/gui/identity.js +6 -54
- package/dist/gui/lifecycle.d.ts +5 -3
- package/dist/gui/lifecycle.js +3 -3
- package/dist/gui/primary-quota-windows.js +67 -44
- package/dist/gui/provider-cards.d.ts +20 -8
- package/dist/gui/provider-cards.js +42 -55
- package/dist/gui/quota-notification-detector.d.ts +29 -6
- package/dist/gui/quota-notification-detector.js +136 -47
- package/dist/gui/quota-notification-observer.d.ts +3 -4
- package/dist/gui/quota-notification-observer.js +73 -20
- package/dist/gui/quota-observation.d.ts +4 -0
- package/dist/gui/quota-observation.js +18 -0
- package/dist/gui/rpc.d.ts +2 -0
- package/dist/gui/rpc.js +14 -3
- package/dist/gui/server.js +17 -3
- package/dist/gui/snapshot-service.d.ts +3 -15
- package/dist/gui/snapshot-service.js +281 -23
- package/dist/gui/sources.js +179 -64
- package/dist/gui/temporal-status.d.ts +3 -2
- package/dist/gui/temporal-status.js +10 -6
- package/dist/gui-experimental.cjs +230 -225
- package/dist/lib/accounting-format.d.ts +8 -0
- package/dist/lib/accounting-format.js +20 -2
- package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
- package/dist/lib/alibaba-coding-plan-cli.js +539 -0
- package/dist/lib/anthropic-api-auth.d.ts +7 -0
- package/dist/lib/anthropic-api-auth.js +27 -0
- package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
- package/dist/lib/anthropic-api-rate-limits.js +92 -0
- package/dist/lib/anthropic-auth.d.ts +2 -3
- package/dist/lib/anthropic-auth.js +2 -3
- package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
- package/dist/lib/anthropic-oauth-throttle.js +379 -0
- package/dist/lib/anthropic.d.ts +68 -14
- package/dist/lib/anthropic.js +1016 -363
- package/dist/lib/api-key-retry-after.d.ts +7 -0
- package/dist/lib/api-key-retry-after.js +62 -0
- package/dist/lib/atomic-json.d.ts +2 -0
- package/dist/lib/atomic-json.js +1 -0
- package/dist/lib/cache-observer-ingestion.d.ts +90 -0
- package/dist/lib/cache-observer-ingestion.js +1008 -0
- package/dist/lib/cache-observer.d.ts +141 -0
- package/dist/lib/cache-observer.js +323 -0
- package/dist/lib/canonical-config-lock.d.ts +9 -0
- package/dist/lib/canonical-config-lock.js +36 -0
- package/dist/lib/chutes.js +62 -51
- package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
- package/dist/lib/claude-agent-transcript-ttl.js +154 -0
- package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
- package/dist/lib/claude-agent-ttl-tracker.js +152 -0
- package/dist/lib/cli-show.d.ts +5 -0
- package/dist/lib/cli-show.js +21 -8
- package/dist/lib/cli-status.js +3 -6
- package/dist/lib/config-write-target.d.ts +1 -1
- package/dist/lib/config-write-target.js +5 -2
- package/dist/lib/config.d.ts +2 -1
- package/dist/lib/config.js +257 -4
- package/dist/lib/copilot.js +171 -86
- package/dist/lib/dashboard-visibility.d.ts +5 -0
- package/dist/lib/dashboard-visibility.js +11 -10
- package/dist/lib/dashboard-web-policy.d.ts +4 -4
- package/dist/lib/dashboard-web-policy.js +2 -2
- package/dist/lib/deepseek.js +25 -13
- package/dist/lib/display-sanitize.js +2 -0
- package/dist/lib/entries.d.ts +33 -1
- package/dist/lib/entries.js +6 -0
- package/dist/lib/glm-coding-plan.js +98 -74
- package/dist/lib/google-agy.js +90 -12
- package/dist/lib/google-gemini-cli.js +84 -11
- package/dist/lib/grouped-entry-normalization.js +1 -1
- package/dist/lib/http.d.ts +4 -0
- package/dist/lib/http.js +16 -2
- package/dist/lib/init-installer.js +5 -3
- package/dist/lib/kilo.js +37 -18
- package/dist/lib/kimi.js +35 -18
- package/dist/lib/maintainer-announcements.js +2 -2
- package/dist/lib/mimo.d.ts +2 -0
- package/dist/lib/mimo.js +36 -0
- package/dist/lib/modelsdev-pricing.d.ts +74 -2
- package/dist/lib/modelsdev-pricing.js +457 -63
- package/dist/lib/modelsdev-temporal.d.ts +6 -0
- package/dist/lib/modelsdev-temporal.js +16 -2
- package/dist/lib/nanogpt.d.ts +1 -0
- package/dist/lib/nanogpt.js +26 -3
- package/dist/lib/ollama-cloud.d.ts +1 -1
- package/dist/lib/ollama-cloud.js +48 -35
- package/dist/lib/openai.js +84 -38
- package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
- package/dist/lib/opencode-auth-sqlite.js +2 -2
- package/dist/lib/opencode-config-editor.d.ts +1 -0
- package/dist/lib/opencode-config-editor.js +6 -1
- package/dist/lib/opencode-config-providers.js +2 -2
- package/dist/lib/opencode-go.js +29 -2
- package/dist/lib/opencode-storage.d.ts +20 -0
- package/dist/lib/opencode-storage.js +89 -2
- package/dist/lib/opencode-version-core.d.ts +30 -0
- package/dist/lib/opencode-version-core.js +59 -0
- package/dist/lib/opencode-version.d.ts +2 -22
- package/dist/lib/opencode-version.js +4 -48
- package/dist/lib/opencode-warming-refresh.d.ts +19 -0
- package/dist/lib/opencode-warming-refresh.js +95 -0
- package/dist/lib/opencode-zen.d.ts +3 -0
- package/dist/lib/opencode-zen.js +71 -5
- package/dist/lib/provider-add.js +5 -2
- package/dist/lib/provider-metadata.d.ts +11 -3
- package/dist/lib/provider-metadata.js +20 -2
- package/dist/lib/provider-registration.d.ts +358 -9
- package/dist/lib/provider-registration.js +423 -30
- package/dist/lib/quota-auto-resume.d.ts +74 -0
- package/dist/lib/quota-auto-resume.js +539 -0
- package/dist/lib/quota-command-format.js +23 -10
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.js +25 -0
- package/dist/lib/quota-identity.d.ts +64 -0
- package/dist/lib/quota-identity.js +111 -0
- package/dist/lib/quota-providers-remote.d.ts +2 -1
- package/dist/lib/quota-providers-remote.js +59 -3
- package/dist/lib/quota-providers.d.ts +1 -1
- package/dist/lib/quota-providers.js +14 -37
- package/dist/lib/quota-render-data.d.ts +6 -0
- package/dist/lib/quota-render-data.js +45 -19
- package/dist/lib/quota-reset-notifications.js +11 -155
- package/dist/lib/quota-retry-wait.d.ts +106 -5
- package/dist/lib/quota-retry-wait.js +301 -34
- package/dist/lib/quota-runtime-context.js +1 -0
- package/dist/lib/quota-state-codec.d.ts +2 -0
- package/dist/lib/quota-state-codec.js +31 -2
- package/dist/lib/quota-state.d.ts +8 -2
- package/dist/lib/quota-state.js +253 -47
- package/dist/lib/quota-stats.d.ts +26 -0
- package/dist/lib/quota-stats.js +40 -1
- package/dist/lib/quota-status.js +3 -51
- package/dist/lib/quota-surface-data.js +18 -3
- package/dist/lib/quota-telemetry.js +2 -2
- package/dist/lib/resolved-auth-identity.d.ts +19 -0
- package/dist/lib/resolved-auth-identity.js +44 -0
- package/dist/lib/scoped-update.d.ts +1 -1
- package/dist/lib/state-file-lock.d.ts +26 -0
- package/dist/lib/state-file-lock.js +205 -0
- package/dist/lib/synthetic.js +65 -54
- package/dist/lib/toast-format-grouped.js +7 -4
- package/dist/lib/tui-compact-format.js +29 -16
- package/dist/lib/types.d.ts +51 -1
- package/dist/lib/types.js +17 -1
- package/dist/lib/xai.js +48 -22
- package/dist/plugin.js +328 -14
- package/dist/provider-logos/NOTICE.md +1 -1
- package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
- package/dist/providers/alibaba-coding-plan.js +125 -104
- package/dist/providers/alibaba-token-plan.js +9 -5
- package/dist/providers/anthropic.d.ts +16 -3
- package/dist/providers/anthropic.js +172 -220
- package/dist/providers/cache-policies.d.ts +11 -4
- package/dist/providers/cache-policies.js +19 -13
- package/dist/providers/chutes.js +2 -0
- package/dist/providers/claude-agent.d.ts +19 -0
- package/dist/providers/claude-agent.js +215 -0
- package/dist/providers/copilot.js +7 -4
- package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
- package/dist/providers/glm-coding-plan-provider.js +30 -23
- package/dist/providers/google-account-format.js +1 -0
- package/dist/providers/google-agy.d.ts +6 -5
- package/dist/providers/google-agy.js +43 -15
- package/dist/providers/google-gemini-cli.js +1 -0
- package/dist/providers/kilo.js +1 -0
- package/dist/providers/kimi-code.js +2 -0
- package/dist/providers/mimo.js +1 -0
- package/dist/providers/nanogpt.js +1 -0
- package/dist/providers/ollama-cloud.js +10 -0
- package/dist/providers/openai.js +24 -23
- package/dist/providers/opencode-go.js +10 -6
- package/dist/providers/opencode-zen.js +3 -1
- package/dist/providers/openrouter.js +1 -0
- package/dist/providers/quota-providers.js +16 -5
- package/dist/providers/registry.js +2 -0
- package/dist/providers/result-helpers.d.ts +6 -2
- package/dist/providers/result-helpers.js +7 -1
- package/dist/providers/synthetic.js +4 -0
- package/dist/providers/xai.js +9 -8
- package/dist/rpc.d.ts +129 -8
- package/dist/rpc.js +219 -14
- package/dist/ui/assets/{index-cDd9jUVY.css → index-6_g1FHs-.css} +1 -1
- package/dist/ui/assets/index-sZnGUuML.js +10 -0
- package/dist/ui/assets/{popover-BGkgv9s0.js → popover-C4ZLYe9E.js} +1 -1
- package/dist/ui/assets/providers/claude-agent.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +45 -46
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
- package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
- package/dist/ui/assets/index-DLHeXYff.js +0 -9
package/dist/rpc.js
CHANGED
|
@@ -110,6 +110,8 @@ export const QuotaRpc = {
|
|
|
110
110
|
};
|
|
111
111
|
export const DASHBOARD_RPC_ID = "opencode-quota-gui.dashboard";
|
|
112
112
|
const MAX_RESOURCE_ID_LENGTH = 256;
|
|
113
|
+
/** Bounded relayed session titles; display layers truncate further. */
|
|
114
|
+
const SESSION_METADATA_TITLE_MAX_LENGTH = 200;
|
|
113
115
|
const NO_INPUT = schema((value) => value === undefined || (isObject(value) && Object.keys(value).length === 0)
|
|
114
116
|
? null
|
|
115
117
|
: "input must be an empty object", () => ({}));
|
|
@@ -173,9 +175,8 @@ function checkRange(value) {
|
|
|
173
175
|
return isRangeKey(value.range) ? null : "range must be one of 24h, 7d, 30d, lifetime";
|
|
174
176
|
}
|
|
175
177
|
/**
|
|
176
|
-
* The explicit typed dashboard RPC.
|
|
177
|
-
* operation (plus
|
|
178
|
-
* no generic dispatch/call method.
|
|
178
|
+
* The explicit typed dashboard RPC. Methods map to a dashboard data-source or
|
|
179
|
+
* user settings-store operation (plus `watch`); there is no generic dispatch.
|
|
179
180
|
*/
|
|
180
181
|
export const DashboardRpc = {
|
|
181
182
|
id: DASHBOARD_RPC_ID,
|
|
@@ -184,19 +185,29 @@ export const DashboardRpc = {
|
|
|
184
185
|
schema: eventSchema((value) => {
|
|
185
186
|
if (!isObject(value))
|
|
186
187
|
return "event must be an object";
|
|
187
|
-
if (!hasOnlyKeys(value, ["topic", "at", "scope"])) {
|
|
188
|
-
return "event must contain only topic, at and
|
|
188
|
+
if (!hasOnlyKeys(value, ["topic", "at", "scope", "cacheObserverEvent"])) {
|
|
189
|
+
return "event must contain only topic, at, scope and cacheObserverEvent";
|
|
190
|
+
}
|
|
191
|
+
if (!Number.isFinite(value.at))
|
|
192
|
+
return "at must be a finite number";
|
|
193
|
+
if (value.topic === "cache.observer") {
|
|
194
|
+
if (value.scope !== undefined)
|
|
195
|
+
return "cache observer events cannot have a scope";
|
|
196
|
+
return isDashboardRpcCacheObserverEvent(value.cacheObserverEvent)
|
|
197
|
+
? null
|
|
198
|
+
: "cache.observer topic requires a valid cache observer payload";
|
|
189
199
|
}
|
|
190
200
|
if (value.topic !== "quota.changed" &&
|
|
191
201
|
value.topic !== "sessions.changed" &&
|
|
192
202
|
value.topic !== "settings.changed") {
|
|
193
203
|
return "topic must be a dashboard event topic";
|
|
194
204
|
}
|
|
195
|
-
if (!Number.isFinite(value.at))
|
|
196
|
-
return "at must be a finite number";
|
|
197
205
|
if (value.scope !== undefined && value.scope !== "visibility") {
|
|
198
206
|
return "scope must be visibility";
|
|
199
207
|
}
|
|
208
|
+
if (value.cacheObserverEvent !== undefined) {
|
|
209
|
+
return "cache observer payload requires the cache.observer topic";
|
|
210
|
+
}
|
|
200
211
|
return null;
|
|
201
212
|
}),
|
|
202
213
|
},
|
|
@@ -231,14 +242,24 @@ export const DashboardRpc = {
|
|
|
231
242
|
errors: DASHBOARD_RPC_ERRORS,
|
|
232
243
|
},
|
|
233
244
|
quota: {
|
|
234
|
-
input:
|
|
245
|
+
input: schema((value) => {
|
|
246
|
+
if (value === undefined)
|
|
247
|
+
return null;
|
|
248
|
+
if (!isObject(value) || !hasOnlyKeys(value, ["refresh"]))
|
|
249
|
+
return "input must be an empty object";
|
|
250
|
+
return value.refresh === undefined || typeof value.refresh === "boolean"
|
|
251
|
+
? null
|
|
252
|
+
: "refresh must be boolean";
|
|
253
|
+
}, (value) => (value === undefined ? {} : value)),
|
|
235
254
|
output: output(isQuotaSnapshot),
|
|
236
255
|
errors: DASHBOARD_RPC_ERRORS,
|
|
237
256
|
},
|
|
238
257
|
home: {
|
|
239
258
|
input: schema((value) => {
|
|
240
|
-
if (!isObject(value) ||
|
|
241
|
-
|
|
259
|
+
if (!isObject(value) ||
|
|
260
|
+
!hasOnlyKeys(value, ["range", "background"]) ||
|
|
261
|
+
(value.background !== undefined && typeof value.background !== "boolean")) {
|
|
262
|
+
return "input must contain range and optional boolean background";
|
|
242
263
|
}
|
|
243
264
|
return checkRange(value);
|
|
244
265
|
}),
|
|
@@ -352,12 +373,16 @@ export const DashboardRpc = {
|
|
|
352
373
|
},
|
|
353
374
|
watch: {
|
|
354
375
|
input: schema((value) => {
|
|
355
|
-
if (!isObject(value) || !
|
|
356
|
-
return "input must contain only scope";
|
|
376
|
+
if (!isObject(value) || !hasOnlyKeys(value, ["scope", "attemptNonce"])) {
|
|
377
|
+
return "input must contain only scope and attemptNonce";
|
|
357
378
|
}
|
|
358
|
-
|
|
379
|
+
if (value.scope !== "quota" && value.scope !== "analytics") {
|
|
380
|
+
return "scope must be quota or analytics";
|
|
381
|
+
}
|
|
382
|
+
return value.attemptNonce === undefined ||
|
|
383
|
+
(typeof value.attemptNonce === "string" && isValidResourceId(value.attemptNonce))
|
|
359
384
|
? null
|
|
360
|
-
: "
|
|
385
|
+
: "attemptNonce must be a non-empty safe string";
|
|
361
386
|
}),
|
|
362
387
|
output: schema((value) => isObject(value) && typeof value.active === "boolean" ? null : "output must report active"),
|
|
363
388
|
errors: DASHBOARD_RPC_ERRORS,
|
|
@@ -387,4 +412,184 @@ export function isDashboardRpcQuotaNotificationData(value) {
|
|
|
387
412
|
return false;
|
|
388
413
|
return value.description === undefined || isSafeNotificationText(value.description, 1024);
|
|
389
414
|
}
|
|
415
|
+
/** Strict runtime validation for the narrow, content-free cache observer event DTO. */
|
|
416
|
+
export function isDashboardRpcCacheObserverEvent(value) {
|
|
417
|
+
if (!isObject(value) || typeof value.type !== "string")
|
|
418
|
+
return false;
|
|
419
|
+
if (value.type === "source.status") {
|
|
420
|
+
return (hasExactKeys(value, ["type", "created", "data"]) &&
|
|
421
|
+
Number.isFinite(value.created) &&
|
|
422
|
+
isObject(value.data) &&
|
|
423
|
+
hasOnlyKeys(value.data, ["state", "attemptNonce", "sourceBinding"]) &&
|
|
424
|
+
(value.data.state === "unverified" ||
|
|
425
|
+
value.data.state === "observed" ||
|
|
426
|
+
value.data.state === "unavailable" ||
|
|
427
|
+
value.data.state === "stopped") &&
|
|
428
|
+
(value.data.attemptNonce === undefined ||
|
|
429
|
+
(typeof value.data.attemptNonce === "string" &&
|
|
430
|
+
isValidResourceId(value.data.attemptNonce))) &&
|
|
431
|
+
(value.data.sourceBinding === undefined ||
|
|
432
|
+
(typeof value.data.sourceBinding === "string" &&
|
|
433
|
+
isValidResourceId(value.data.sourceBinding))));
|
|
434
|
+
}
|
|
435
|
+
if (value.type === "session.step.started") {
|
|
436
|
+
if (!hasExactKeys(value, ["type", "created", "data"]) ||
|
|
437
|
+
!Number.isFinite(value.created) ||
|
|
438
|
+
!isObject(value.data) ||
|
|
439
|
+
!hasOnlyKeys(value.data, [
|
|
440
|
+
"sessionID",
|
|
441
|
+
"assistantMessageID",
|
|
442
|
+
"model",
|
|
443
|
+
"started",
|
|
444
|
+
"connectionMethod",
|
|
445
|
+
]) ||
|
|
446
|
+
(value.data.connectionMethod !== undefined &&
|
|
447
|
+
value.data.connectionMethod !== "oauth" &&
|
|
448
|
+
value.data.connectionMethod !== "key" &&
|
|
449
|
+
value.data.connectionMethod !== "external") ||
|
|
450
|
+
typeof value.data.sessionID !== "string" ||
|
|
451
|
+
!isValidResourceId(value.data.sessionID) ||
|
|
452
|
+
typeof value.data.assistantMessageID !== "string" ||
|
|
453
|
+
!isValidResourceId(value.data.assistantMessageID) ||
|
|
454
|
+
!isObject(value.data.model) ||
|
|
455
|
+
!hasOnlyKeys(value.data.model, ["providerID", "id", "variant"]) ||
|
|
456
|
+
typeof value.data.model.providerID !== "string" ||
|
|
457
|
+
!isValidResourceId(value.data.model.providerID) ||
|
|
458
|
+
typeof value.data.model.id !== "string" ||
|
|
459
|
+
!isValidResourceId(value.data.model.id) ||
|
|
460
|
+
(value.data.model.variant !== undefined &&
|
|
461
|
+
(typeof value.data.model.variant !== "string" ||
|
|
462
|
+
!isValidResourceId(value.data.model.variant))) ||
|
|
463
|
+
(value.data.started !== undefined &&
|
|
464
|
+
(typeof value.data.started !== "number" ||
|
|
465
|
+
!Number.isFinite(value.data.started) ||
|
|
466
|
+
value.data.started < 0))) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
if (value.type === "session.step.ended") {
|
|
472
|
+
if (!hasExactKeys(value, ["type", "created", "data"]) || !isObject(value.data))
|
|
473
|
+
return false;
|
|
474
|
+
if (!Number.isFinite(value.created) ||
|
|
475
|
+
!hasExactKeys(value.data, ["sessionID", "assistantMessageID", "tokens"]) ||
|
|
476
|
+
typeof value.data.sessionID !== "string" ||
|
|
477
|
+
!isValidResourceId(value.data.sessionID) ||
|
|
478
|
+
typeof value.data.assistantMessageID !== "string" ||
|
|
479
|
+
!isValidResourceId(value.data.assistantMessageID) ||
|
|
480
|
+
!isObject(value.data.tokens) ||
|
|
481
|
+
!hasOnlyKeys(value.data.tokens, ["input", "cache"])) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
const tokens = value.data.tokens;
|
|
485
|
+
if (tokens.input !== undefined &&
|
|
486
|
+
(!Number.isFinite(tokens.input) || tokens.input < 0)) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
if (tokens.cache === undefined)
|
|
490
|
+
return true;
|
|
491
|
+
if (!isObject(tokens.cache) || !hasOnlyKeys(tokens.cache, ["read", "write"]))
|
|
492
|
+
return false;
|
|
493
|
+
return [tokens.cache.read, tokens.cache.write].every((count) => count === undefined || (Number.isFinite(count) && count >= 0));
|
|
494
|
+
}
|
|
495
|
+
if (value.type === "session.cache.warming") {
|
|
496
|
+
return (hasExactKeys(value, ["type", "data"]) &&
|
|
497
|
+
isObject(value.data) &&
|
|
498
|
+
hasExactKeys(value.data, ["sessionID", "dispatchMs", "evidence"]) &&
|
|
499
|
+
typeof value.data.sessionID === "string" &&
|
|
500
|
+
isValidResourceId(value.data.sessionID) &&
|
|
501
|
+
typeof value.data.dispatchMs === "number" &&
|
|
502
|
+
Number.isFinite(value.data.dispatchMs) &&
|
|
503
|
+
value.data.dispatchMs >= 0 &&
|
|
504
|
+
value.data.evidence === "warming-inferred");
|
|
505
|
+
}
|
|
506
|
+
if (value.type === "session.cache.ttl") {
|
|
507
|
+
return (hasExactKeys(value, ["type", "created", "data"]) &&
|
|
508
|
+
Number.isFinite(value.created) &&
|
|
509
|
+
isObject(value.data) &&
|
|
510
|
+
hasExactKeys(value.data, ["sessionID", "assistantMessageID", "ttlMs"]) &&
|
|
511
|
+
typeof value.data.sessionID === "string" &&
|
|
512
|
+
isValidResourceId(value.data.sessionID) &&
|
|
513
|
+
typeof value.data.assistantMessageID === "string" &&
|
|
514
|
+
isValidResourceId(value.data.assistantMessageID) &&
|
|
515
|
+
value.data.ttlMs === 3_600_000);
|
|
516
|
+
}
|
|
517
|
+
if (value.type === "session.created") {
|
|
518
|
+
return (hasExactKeys(value, ["type", "data"]) &&
|
|
519
|
+
isObject(value.data) &&
|
|
520
|
+
hasExactKeys(value.data, ["sessionID", "parentID"]) &&
|
|
521
|
+
typeof value.data.sessionID === "string" &&
|
|
522
|
+
isValidResourceId(value.data.sessionID) &&
|
|
523
|
+
typeof value.data.parentID === "string" &&
|
|
524
|
+
isValidResourceId(value.data.parentID));
|
|
525
|
+
}
|
|
526
|
+
if (value.type === "session.forked") {
|
|
527
|
+
return (hasExactKeys(value, ["type", "data"]) &&
|
|
528
|
+
isObject(value.data) &&
|
|
529
|
+
hasOnlyKeys(value.data, ["sessionID", "parentID"]) &&
|
|
530
|
+
typeof value.data.sessionID === "string" &&
|
|
531
|
+
isValidResourceId(value.data.sessionID) &&
|
|
532
|
+
(value.data.parentID === undefined ||
|
|
533
|
+
(typeof value.data.parentID === "string" && isValidResourceId(value.data.parentID))));
|
|
534
|
+
}
|
|
535
|
+
if (value.type === "session.status") {
|
|
536
|
+
return (hasExactKeys(value, ["type", "created", "data"]) &&
|
|
537
|
+
Number.isFinite(value.created) &&
|
|
538
|
+
isObject(value.data) &&
|
|
539
|
+
hasExactKeys(value.data, ["sessionID", "state"]) &&
|
|
540
|
+
typeof value.data.sessionID === "string" &&
|
|
541
|
+
isValidResourceId(value.data.sessionID) &&
|
|
542
|
+
(value.data.state === "busy" || value.data.state === "idle"));
|
|
543
|
+
}
|
|
544
|
+
if (value.type === "session.metadata") {
|
|
545
|
+
if (!hasExactKeys(value, ["type", "created", "data"]) ||
|
|
546
|
+
!Number.isFinite(value.created) ||
|
|
547
|
+
!isObject(value.data) ||
|
|
548
|
+
!hasOnlyKeys(value.data, ["sessionID", "title", "agent", "model"])) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
if (typeof value.data.sessionID !== "string" || !isValidResourceId(value.data.sessionID)) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
if (value.data.title !== undefined &&
|
|
555
|
+
!isSafeNotificationText(value.data.title, SESSION_METADATA_TITLE_MAX_LENGTH)) {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
if (value.data.agent !== undefined &&
|
|
559
|
+
(typeof value.data.agent !== "string" || !isValidResourceId(value.data.agent))) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
if (value.data.model !== undefined) {
|
|
563
|
+
const model = value.data.model;
|
|
564
|
+
if (!isObject(model) ||
|
|
565
|
+
!hasOnlyKeys(model, ["providerID", "id", "variant"]) ||
|
|
566
|
+
typeof model.providerID !== "string" ||
|
|
567
|
+
!isValidResourceId(model.providerID) ||
|
|
568
|
+
typeof model.id !== "string" ||
|
|
569
|
+
!isValidResourceId(model.id) ||
|
|
570
|
+
(model.variant !== undefined &&
|
|
571
|
+
(typeof model.variant !== "string" || !isValidResourceId(model.variant)))) {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
if (value.type !== "session.compaction.ended" && value.type !== "session.deleted")
|
|
578
|
+
return false;
|
|
579
|
+
return (hasExactKeys(value, ["type", "data"]) &&
|
|
580
|
+
isObject(value.data) &&
|
|
581
|
+
hasExactKeys(value.data, ["sessionID"]) &&
|
|
582
|
+
typeof value.data.sessionID === "string" &&
|
|
583
|
+
isValidResourceId(value.data.sessionID));
|
|
584
|
+
}
|
|
585
|
+
/** Strict guard for cache observer DTOs wrapped in the existing invalidation event envelope. */
|
|
586
|
+
export function isDashboardRpcCacheObserverEventData(value) {
|
|
587
|
+
return (isObject(value) &&
|
|
588
|
+
hasExactKeys(value, ["topic", "at", "cacheObserverEvent"]) &&
|
|
589
|
+
value.topic === "cache.observer" &&
|
|
590
|
+
typeof value.at === "number" &&
|
|
591
|
+
Number.isFinite(value.at) &&
|
|
592
|
+
value.at >= 0 &&
|
|
593
|
+
isDashboardRpcCacheObserverEvent(value.cacheObserverEvent));
|
|
594
|
+
}
|
|
390
595
|
//# sourceMappingURL=rpc.js.map
|