@cortexkit/opencode-antigravity-auth 3.0.20 → 3.0.22
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/cli.js +354 -278
- package/dist/cli.js.map +3 -3
- package/dist/cli.meta.json +66 -21
- package/dist/index.js +841 -392
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +123 -28
- package/dist/server.js +860 -411
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/custody.js +25 -0
- package/dist/src/common-auth-embedded/claustrum/hub.js +20 -1
- package/dist/src/common-auth-embedded/claustrum/insula.js +6 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +2 -2
- package/dist/src/common-auth-embedded/fs/with-lock.js +37 -10
- package/dist/src/common-auth-embedded/quota/format.d.ts +9 -4
- package/dist/src/common-auth-embedded/quota/format.js +45 -26
- package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +86 -0
- package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +654 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.js +128 -0
- package/dist/src/common-auth-embedded/source-output.json +69 -29
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +2 -2
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +2 -0
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +1 -0
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +6 -0
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +89 -2
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +4 -0
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/shared/vault-routing-purpose.d.ts +12 -0
- package/dist/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-routing-purpose.js +18 -0
- package/dist/src/plugin/shared/vault-routing-purpose.js.map +1 -0
- package/dist/src/plugin/shared/vault-routing.d.ts +36 -0
- package/dist/src/plugin/shared/vault-routing.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-routing.js +213 -0
- package/dist/src/plugin/shared/vault-routing.js.map +1 -0
- package/dist/src/plugin/types.d.ts +1 -0
- package/dist/src/plugin/types.d.ts.map +1 -1
- package/dist/src/tui/quota-layout.d.ts +4 -58
- package/dist/src/tui/quota-layout.d.ts.map +1 -1
- package/dist/src/tui/quota-layout.js +4 -90
- package/dist/src/tui/quota-layout.js.map +1 -1
- package/dist/src/tui/sidebar-frame.d.ts +4 -34
- package/dist/src/tui/sidebar-frame.d.ts.map +1 -1
- package/dist/src/tui/sidebar-frame.js +93 -167
- package/dist/src/tui/sidebar-frame.js.map +1 -1
- package/dist/src/tui.js +2 -2
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +31 -17
- package/dist/tui-ga-build-map.json +32 -17
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +9 -4
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +6 -0
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts +12 -0
- package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/vault-routing.d.ts +36 -0
- package/dist/types/src/plugin/shared/vault-routing.d.ts.map +1 -0
- package/dist/types/src/plugin/types.d.ts +1 -0
- package/dist/types/src/plugin/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/custody.js +25 -0
- package/src/common-auth-embedded/claustrum/hub.js +20 -1
- package/src/common-auth-embedded/claustrum/insula.js +6 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +2 -2
- package/src/common-auth-embedded/fs/with-lock.js +37 -10
- package/src/common-auth-embedded/quota/format.d.ts +9 -4
- package/src/common-auth-embedded/quota/format.js +45 -26
- package/src/common-auth-embedded/quota-sidebar/index.d.ts +86 -0
- package/src/common-auth-embedded/quota-sidebar/index.tsx +654 -0
- package/src/common-auth-embedded/routing-accessor/index.d.ts +62 -0
- package/src/common-auth-embedded/routing-accessor/index.js +128 -0
- package/src/common-auth-embedded/source-output.json +69 -29
- package/src/tui-compiled/common-auth-embedded/quota/format.js +45 -26
- package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +683 -0
- package/src/tui-compiled/tui/quota-layout.js +5 -330
- package/src/tui-compiled/tui/sidebar-frame.js +243 -467
- package/src/tui-compiled/tui.js +2 -2
- package/src/tui-ga-compiled/host-ga.js +2 -2
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +45 -26
- package/src/tui-ga-compiled/shared/ced204104a639c9c-sidebar-frame.js +243 -467
- package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +5 -330
- package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +683 -0
- package/src/tui-ga-raw/host-ga.tsx +2 -2
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +45 -26
- package/src/tui-ga-raw/shared/ced204104a639c9c-sidebar-frame.tsx +214 -400
- package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +10 -301
- package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +654 -0
- package/src/tui-raw/common-auth-embedded/quota/format.js +45 -26
- package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +654 -0
- package/src/tui-raw/tui/quota-layout.tsx +10 -301
- package/src/tui-raw/tui/sidebar-frame.tsx +214 -400
- package/src/tui-raw/tui.tsx +2 -2
- package/src/tui.tsx +2 -2
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Optional THALAMUS routing for vault mode only. Account ids here are vault
|
|
2
|
+
// account ids; local pool rows are not known to the routing engine.
|
|
3
|
+
function isObject(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null;
|
|
5
|
+
}
|
|
6
|
+
function routingHandle(sessionId) {
|
|
7
|
+
// The bridge can load after the auth plugin, so never cache the accessor.
|
|
8
|
+
const routing = Reflect.get(globalThis, Symbol.for('cortexkit.routing'));
|
|
9
|
+
if (typeof routing !== 'function')
|
|
10
|
+
return undefined;
|
|
11
|
+
const handle = routing(sessionId);
|
|
12
|
+
return isObject(handle) ? handle : undefined;
|
|
13
|
+
}
|
|
14
|
+
function selectionFor(answer, candidates) {
|
|
15
|
+
if (!isObject(answer))
|
|
16
|
+
return undefined;
|
|
17
|
+
const accountId = answer.account_id;
|
|
18
|
+
const credentialId = answer.credential_id;
|
|
19
|
+
if (typeof accountId !== 'string')
|
|
20
|
+
return undefined;
|
|
21
|
+
if (credentialId !== undefined && typeof credentialId !== 'string') {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const candidate = candidates.find((route) => route.accountId === accountId &&
|
|
25
|
+
(credentialId === undefined || route.credentialId === credentialId));
|
|
26
|
+
if (!candidate)
|
|
27
|
+
return undefined;
|
|
28
|
+
const hold = answer.hold;
|
|
29
|
+
const retryAfterMs = isObject(hold) ? hold.retry_after_ms : undefined;
|
|
30
|
+
if (typeof retryAfterMs === 'number' &&
|
|
31
|
+
Number.isFinite(retryAfterMs) &&
|
|
32
|
+
retryAfterMs >= 0) {
|
|
33
|
+
return { candidate, hold: { retry_after_ms: retryAfterMs } };
|
|
34
|
+
}
|
|
35
|
+
return { candidate };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ask routing for an eligible vault route. Any failure or unfamiliar answer
|
|
39
|
+
* yields undefined so the plugin can keep its own choice. This does not admit
|
|
40
|
+
* routes: callers must exclude vault refusals and killswitch-blocked accounts.
|
|
41
|
+
*/
|
|
42
|
+
export async function askRouting(input) {
|
|
43
|
+
let timer;
|
|
44
|
+
try {
|
|
45
|
+
const handle = routingHandle(input.sessionId);
|
|
46
|
+
if (!handle)
|
|
47
|
+
return undefined;
|
|
48
|
+
const accountFor = handle.accountFor;
|
|
49
|
+
if (typeof accountFor !== 'function')
|
|
50
|
+
return undefined;
|
|
51
|
+
const requested = input.deadlineMs ?? 500;
|
|
52
|
+
const deadlineMs = Number.isNaN(requested)
|
|
53
|
+
? 500
|
|
54
|
+
: Math.min(2000, Math.max(1, requested));
|
|
55
|
+
const expired = new Promise((resolve) => {
|
|
56
|
+
timer = setTimeout(() => resolve(undefined), deadlineMs);
|
|
57
|
+
timer.unref();
|
|
58
|
+
});
|
|
59
|
+
const pending = accountFor.call(handle, { provider: input.provider, modelId: input.modelId }, { deadlineMs });
|
|
60
|
+
if (!isObject(pending) || typeof pending.then !== 'function')
|
|
61
|
+
return undefined;
|
|
62
|
+
const answer = await Promise.race([pending, expired]);
|
|
63
|
+
return selectionFor(answer, input.candidates);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// The process-global bridge is optional and must not break authentication.
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Report a vault request without waiting for routing. Only contract fields are
|
|
75
|
+
* sent, and all accessor failures are ignored. Headers must already be limited
|
|
76
|
+
* to rate-limit headers by the caller; values are not filtered or redacted here.
|
|
77
|
+
*/
|
|
78
|
+
export function reportRouting(input) {
|
|
79
|
+
try {
|
|
80
|
+
const handle = routingHandle(input.sessionId);
|
|
81
|
+
if (!handle)
|
|
82
|
+
return;
|
|
83
|
+
const report = handle.report;
|
|
84
|
+
if (typeof report !== 'function')
|
|
85
|
+
return;
|
|
86
|
+
const identity = {
|
|
87
|
+
account_id: input.accountId,
|
|
88
|
+
...(input.credentialId !== undefined
|
|
89
|
+
? { credential_id: input.credentialId }
|
|
90
|
+
: {}),
|
|
91
|
+
};
|
|
92
|
+
let payload;
|
|
93
|
+
switch (input.outcome) {
|
|
94
|
+
case 'served':
|
|
95
|
+
payload = { ...identity, outcome: 'served', headers: input.headers };
|
|
96
|
+
break;
|
|
97
|
+
case 'exhausted': {
|
|
98
|
+
const { window, pool } = input;
|
|
99
|
+
if (window !== '5h' && window !== '7d')
|
|
100
|
+
return;
|
|
101
|
+
// An undefined pool means the whole account, as an omitted one does.
|
|
102
|
+
if (pool !== undefined &&
|
|
103
|
+
(typeof pool !== 'string' || pool.length === 0 || pool.includes(':')))
|
|
104
|
+
return;
|
|
105
|
+
payload = {
|
|
106
|
+
...identity,
|
|
107
|
+
outcome: 'exhausted',
|
|
108
|
+
window,
|
|
109
|
+
...(pool ? { pool } : {}),
|
|
110
|
+
...(input.resetsAt !== undefined
|
|
111
|
+
? { resets_at: input.resetsAt }
|
|
112
|
+
: {}),
|
|
113
|
+
};
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// A broken bridge may return a rejected promise despite its void contract.
|
|
120
|
+
const pending = report.call(handle, payload);
|
|
121
|
+
if (isObject(pending) && typeof pending.then === 'function') {
|
|
122
|
+
void Promise.resolve(pending).catch(() => { });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Reporting must never change the result of an auth request.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"package": "@cortexkit/common-auth",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.0",
|
|
5
5
|
"artifactStatus": "published",
|
|
6
6
|
"publicRoots": {
|
|
7
7
|
"./rpc": {
|
|
@@ -59,17 +59,25 @@
|
|
|
59
59
|
"./opencode2": {
|
|
60
60
|
"types": "./dist/opencode2/index.d.ts",
|
|
61
61
|
"import": "./dist/opencode2/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./routing-accessor": {
|
|
64
|
+
"types": "./dist/routing-accessor/index.d.ts",
|
|
65
|
+
"import": "./dist/routing-accessor/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./quota-sidebar": {
|
|
68
|
+
"types": "./dist/quota-sidebar/index.d.ts",
|
|
69
|
+
"import": "./src/quota-sidebar/index.tsx"
|
|
62
70
|
}
|
|
63
71
|
},
|
|
64
|
-
"input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.
|
|
65
|
-
"tarballSha256": "
|
|
66
|
-
"sri": "sha512-
|
|
67
|
-
"canonicalFiles":
|
|
68
|
-
"canonicalBytes":
|
|
72
|
+
"input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.33.0.tgz",
|
|
73
|
+
"tarballSha256": "bba9f56f7fb353c9c712113722c7c9361f0e13e930c73f57314185b13032a24c",
|
|
74
|
+
"sri": "sha512-cbbyqXTK1TYQZNHb2xA/ueZGQsBvAX6H9hTlQcZZxM7SR/u7tsscyBAWw38ViXl1n/gwkqgsvs2Vbs6cZ0hOrw==",
|
|
75
|
+
"canonicalFiles": 199,
|
|
76
|
+
"canonicalBytes": 1277160,
|
|
69
77
|
"generator": {
|
|
70
78
|
"path": "packages/opencode/scripts/embed-common-auth.ts",
|
|
71
|
-
"version":
|
|
72
|
-
"sha256": "
|
|
79
|
+
"version": 4,
|
|
80
|
+
"sha256": "9f9ebaeb47c9c18874ed832504422c0791551627c34092885cb481c6fe23ef19"
|
|
73
81
|
},
|
|
74
82
|
"files": [
|
|
75
83
|
{
|
|
@@ -275,9 +283,9 @@
|
|
|
275
283
|
{
|
|
276
284
|
"source": "package/dist/claustrum/custody.js",
|
|
277
285
|
"output": "claustrum/custody.js",
|
|
278
|
-
"bytes":
|
|
279
|
-
"sourceSha256": "
|
|
280
|
-
"outputSha256": "
|
|
286
|
+
"bytes": 31616,
|
|
287
|
+
"sourceSha256": "5ed70e65b78a04ceec3b3430908f46c860ea768b779b6af0f925681fd786593d",
|
|
288
|
+
"outputSha256": "5ed70e65b78a04ceec3b3430908f46c860ea768b779b6af0f925681fd786593d",
|
|
281
289
|
"transform": "verbatim"
|
|
282
290
|
},
|
|
283
291
|
{
|
|
@@ -339,9 +347,9 @@
|
|
|
339
347
|
{
|
|
340
348
|
"source": "package/dist/claustrum/hub.js",
|
|
341
349
|
"output": "claustrum/hub.js",
|
|
342
|
-
"bytes":
|
|
343
|
-
"sourceSha256": "
|
|
344
|
-
"outputSha256": "
|
|
350
|
+
"bytes": 45993,
|
|
351
|
+
"sourceSha256": "e50ebf6bcf840f8a4229d219ecb20fc1422c74b5b3aa2034dff0b73852380b79",
|
|
352
|
+
"outputSha256": "e50ebf6bcf840f8a4229d219ecb20fc1422c74b5b3aa2034dff0b73852380b79",
|
|
345
353
|
"transform": "verbatim"
|
|
346
354
|
},
|
|
347
355
|
{
|
|
@@ -371,9 +379,9 @@
|
|
|
371
379
|
{
|
|
372
380
|
"source": "package/dist/claustrum/insula.js",
|
|
373
381
|
"output": "claustrum/insula.js",
|
|
374
|
-
"bytes":
|
|
375
|
-
"sourceSha256": "
|
|
376
|
-
"outputSha256": "
|
|
382
|
+
"bytes": 20137,
|
|
383
|
+
"sourceSha256": "e2a2625cdad490cf24aa0badf66c842becd806738f8b137ebcf2b01e296eb0d2",
|
|
384
|
+
"outputSha256": "e2a2625cdad490cf24aa0badf66c842becd806738f8b137ebcf2b01e296eb0d2",
|
|
377
385
|
"transform": "verbatim"
|
|
378
386
|
},
|
|
379
387
|
{
|
|
@@ -627,9 +635,9 @@
|
|
|
627
635
|
{
|
|
628
636
|
"source": "package/dist/fs/refresh-file-lock.js",
|
|
629
637
|
"output": "fs/refresh-file-lock.js",
|
|
630
|
-
"bytes":
|
|
631
|
-
"sourceSha256": "
|
|
632
|
-
"outputSha256": "
|
|
638
|
+
"bytes": 37831,
|
|
639
|
+
"sourceSha256": "e0fdcc7a45548f3c88ea49bbe000f6e4022fb9c219f0510aa934492adb72a505",
|
|
640
|
+
"outputSha256": "e0fdcc7a45548f3c88ea49bbe000f6e4022fb9c219f0510aa934492adb72a505",
|
|
633
641
|
"transform": "verbatim"
|
|
634
642
|
},
|
|
635
643
|
{
|
|
@@ -643,9 +651,9 @@
|
|
|
643
651
|
{
|
|
644
652
|
"source": "package/dist/fs/with-lock.js",
|
|
645
653
|
"output": "fs/with-lock.js",
|
|
646
|
-
"bytes":
|
|
647
|
-
"sourceSha256": "
|
|
648
|
-
"outputSha256": "
|
|
654
|
+
"bytes": 3003,
|
|
655
|
+
"sourceSha256": "690fb43c6a0eb6a02eac024b8b58caa39775a37d0064118dab879a0e5ac8c996",
|
|
656
|
+
"outputSha256": "690fb43c6a0eb6a02eac024b8b58caa39775a37d0064118dab879a0e5ac8c996",
|
|
649
657
|
"transform": "verbatim"
|
|
650
658
|
},
|
|
651
659
|
{
|
|
@@ -875,17 +883,17 @@
|
|
|
875
883
|
{
|
|
876
884
|
"source": "package/dist/quota/format.d.ts",
|
|
877
885
|
"output": "quota/format.d.ts",
|
|
878
|
-
"bytes":
|
|
879
|
-
"sourceSha256": "
|
|
880
|
-
"outputSha256": "
|
|
886
|
+
"bytes": 5816,
|
|
887
|
+
"sourceSha256": "1865f4a06b8bd06b3dda73b59a7becc3eb2d13036134c1a34b8b6dce12678f21",
|
|
888
|
+
"outputSha256": "1865f4a06b8bd06b3dda73b59a7becc3eb2d13036134c1a34b8b6dce12678f21",
|
|
881
889
|
"transform": "verbatim"
|
|
882
890
|
},
|
|
883
891
|
{
|
|
884
892
|
"source": "package/dist/quota/format.js",
|
|
885
893
|
"output": "quota/format.js",
|
|
886
|
-
"bytes":
|
|
887
|
-
"sourceSha256": "
|
|
888
|
-
"outputSha256": "
|
|
894
|
+
"bytes": 18881,
|
|
895
|
+
"sourceSha256": "ffd69317391a225fb8e75550c22ea401480626cde762c52e61001955952ee013",
|
|
896
|
+
"outputSha256": "ffd69317391a225fb8e75550c22ea401480626cde762c52e61001955952ee013",
|
|
889
897
|
"transform": "verbatim"
|
|
890
898
|
},
|
|
891
899
|
{
|
|
@@ -1631,6 +1639,38 @@
|
|
|
1631
1639
|
"sourceSha256": "454adc21f90c42f5caa2c6b8374c1a7532623a1b954fe06a030afbc9248c10fe",
|
|
1632
1640
|
"outputSha256": "454adc21f90c42f5caa2c6b8374c1a7532623a1b954fe06a030afbc9248c10fe",
|
|
1633
1641
|
"transform": "verbatim"
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
"source": "package/dist/quota-sidebar/index.d.ts",
|
|
1645
|
+
"output": "quota-sidebar/index.d.ts",
|
|
1646
|
+
"bytes": 2658,
|
|
1647
|
+
"sourceSha256": "a2f94067970c25ce042febadc87a1afdd5c43c75a5100fa8446a783a53ce2815",
|
|
1648
|
+
"outputSha256": "a2f94067970c25ce042febadc87a1afdd5c43c75a5100fa8446a783a53ce2815",
|
|
1649
|
+
"transform": "verbatim"
|
|
1650
|
+
},
|
|
1651
|
+
{
|
|
1652
|
+
"source": "package/src/quota-sidebar/index.tsx",
|
|
1653
|
+
"output": "quota-sidebar/index.tsx",
|
|
1654
|
+
"bytes": 19762,
|
|
1655
|
+
"sourceSha256": "f35e4fd7b218110756bd04357c5b8c4bbb64be5012aefc7d7a7c1ab303d483ae",
|
|
1656
|
+
"outputSha256": "f35e4fd7b218110756bd04357c5b8c4bbb64be5012aefc7d7a7c1ab303d483ae",
|
|
1657
|
+
"transform": "verbatim"
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
"source": "package/dist/routing-accessor/index.d.ts",
|
|
1661
|
+
"output": "routing-accessor/index.d.ts",
|
|
1662
|
+
"bytes": 2486,
|
|
1663
|
+
"sourceSha256": "8bc146aea3903fad91ece61f0022251e8a45086ac11afa86ce93ec7bb2c05436",
|
|
1664
|
+
"outputSha256": "8bc146aea3903fad91ece61f0022251e8a45086ac11afa86ce93ec7bb2c05436",
|
|
1665
|
+
"transform": "verbatim"
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
"source": "package/dist/routing-accessor/index.js",
|
|
1669
|
+
"output": "routing-accessor/index.js",
|
|
1670
|
+
"bytes": 4967,
|
|
1671
|
+
"sourceSha256": "ff1fb189de19874df1edf25a64425bad2ca23013a6e392ab3247138cdd57b240",
|
|
1672
|
+
"outputSha256": "ff1fb189de19874df1edf25a64425bad2ca23013a6e392ab3247138cdd57b240",
|
|
1673
|
+
"transform": "verbatim"
|
|
1634
1674
|
}
|
|
1635
1675
|
],
|
|
1636
1676
|
"transforms": [],
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
//
|
|
6
6
|
// The rules: a window is named by its length (`5h`, `7d`), or, for a window
|
|
7
7
|
// that binds only one model family, by the label the plugin stored it under.
|
|
8
|
-
// Every figure is "% left". A window the provider did not
|
|
9
|
-
// record or a retirement tombstone) is left out rather than
|
|
10
|
-
// reported". A reset is a short time from now (`resets 2h`).
|
|
11
|
-
// than fifteen minutes says how old it is (`checked 3h ago`).
|
|
8
|
+
// Every reported window figure is "% left". A window the provider did not
|
|
9
|
+
// report (an absence record or a retirement tombstone) is left out rather than
|
|
10
|
+
// written as "not reported". A reset is a short time from now (`resets 2h`).
|
|
11
|
+
// A reading older than fifteen minutes says how old it is (`checked 3h ago`).
|
|
12
12
|
//
|
|
13
13
|
// Like the rest of this module it reads no clock: `now` is a parameter.
|
|
14
14
|
import { ALL_SCOPE } from "./map.js";
|
|
@@ -97,12 +97,14 @@ function displayOrder(left, right) {
|
|
|
97
97
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Structured quota wording for layouts that need one row per window.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
100
|
+
* Structured quota wording for layouts that need one row per window.
|
|
101
|
+
* Windows without a dated percentage remain as explicit unknown parts. Limits
|
|
102
|
+
* marked absent (not reported) or retired (no longer tracked) remain omitted.
|
|
103
|
+
* Reported windows, future resets and the optional age keep the shared
|
|
104
|
+
* formatter's wording and order.
|
|
103
105
|
*/
|
|
104
106
|
export function quotaWindowParts(quota, options) {
|
|
105
|
-
const { windows, age } = scopedWindowParts(quota, options);
|
|
107
|
+
const { windows, age } = scopedWindowParts(quota, options, true);
|
|
106
108
|
const parts = windows.map(({ part }) => part);
|
|
107
109
|
return age === undefined ? { windows: parts } : { windows: parts, age };
|
|
108
110
|
}
|
|
@@ -125,34 +127,47 @@ function withShortNames(windows) {
|
|
|
125
127
|
}
|
|
126
128
|
return windows;
|
|
127
129
|
}
|
|
130
|
+
function hasWindowReading(limit) {
|
|
131
|
+
return (Number.isFinite(limit.remainingPercent) && Number.isFinite(limit.checkedAt));
|
|
132
|
+
}
|
|
128
133
|
/**
|
|
129
134
|
* `quotaWindowParts` with each window's scope kept beside it. The narrow form
|
|
130
135
|
* needs the scope to name and pick model-scoped windows; the public parts do
|
|
131
|
-
* not carry
|
|
136
|
+
* not carry the scope.
|
|
132
137
|
*/
|
|
133
|
-
function scopedWindowParts(quota, options) {
|
|
138
|
+
function scopedWindowParts(quota, options, includeUnknown = false) {
|
|
134
139
|
if (!quota)
|
|
135
140
|
return { windows: [] };
|
|
136
141
|
const { now } = options;
|
|
137
142
|
const readings = quota.limits
|
|
138
|
-
.filter((limit) => limit.kind === 'reading' &&
|
|
143
|
+
.filter((limit) => limit.kind === 'reading' && (includeUnknown || hasWindowReading(limit)))
|
|
139
144
|
.sort(displayOrder);
|
|
140
145
|
const windows = readings.map((limit) => {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
scope: limit.scope,
|
|
144
|
-
...(limit.windowMinutes === undefined
|
|
145
|
-
? {}
|
|
146
|
-
: { windowMinutes: limit.windowMinutes }),
|
|
147
|
-
part: {
|
|
146
|
+
const part = hasWindowReading(limit)
|
|
147
|
+
? {
|
|
148
148
|
kind: 'window',
|
|
149
|
+
reading: 'known',
|
|
149
150
|
name: quotaWindowName(limit),
|
|
150
151
|
short: '',
|
|
151
|
-
figure: percentLeft(limit.remainingPercent
|
|
152
|
-
remainingPercent,
|
|
152
|
+
figure: percentLeft(limit.remainingPercent),
|
|
153
|
+
remainingPercent: clampPercent(limit.remainingPercent),
|
|
153
154
|
checkedAt: limit.checkedAt,
|
|
154
155
|
...resetDetails(limit.resetsAt, limit.checkedAt, now),
|
|
155
|
-
}
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
kind: 'window',
|
|
159
|
+
reading: 'unknown',
|
|
160
|
+
name: quotaWindowName(limit),
|
|
161
|
+
short: '',
|
|
162
|
+
figure: 'no reading',
|
|
163
|
+
resetSinceReading: false,
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
scope: limit.scope,
|
|
167
|
+
...(limit.windowMinutes === undefined
|
|
168
|
+
? {}
|
|
169
|
+
: { windowMinutes: limit.windowMinutes }),
|
|
170
|
+
part,
|
|
156
171
|
};
|
|
157
172
|
});
|
|
158
173
|
const budget = quota.budget;
|
|
@@ -168,6 +183,7 @@ function scopedWindowParts(quota, options) {
|
|
|
168
183
|
spent: budget.reached,
|
|
169
184
|
part: {
|
|
170
185
|
kind: 'budget',
|
|
186
|
+
reading: 'known',
|
|
171
187
|
name: 'credits',
|
|
172
188
|
short: '',
|
|
173
189
|
figure,
|
|
@@ -180,8 +196,11 @@ function scopedWindowParts(quota, options) {
|
|
|
180
196
|
});
|
|
181
197
|
}
|
|
182
198
|
withShortNames(windows);
|
|
183
|
-
|
|
184
|
-
|
|
199
|
+
const readingTimes = windows.flatMap(({ part }) => part.reading === 'known' && part.checkedAt !== undefined
|
|
200
|
+
? [part.checkedAt]
|
|
201
|
+
: []);
|
|
202
|
+
if (readingTimes.length > 0) {
|
|
203
|
+
const age = now - Math.min(...readingTimes);
|
|
185
204
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
186
205
|
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
187
206
|
}
|
|
@@ -357,13 +376,13 @@ function narrowTextParts(quota, options) {
|
|
|
357
376
|
export function quotaTextParts(quota, options) {
|
|
358
377
|
if (options.form === 'narrow')
|
|
359
378
|
return narrowTextParts(quota, options);
|
|
360
|
-
const
|
|
379
|
+
const { windows, age } = scopedWindowParts(quota, options);
|
|
361
380
|
const full = (options.form ?? 'full') === 'full';
|
|
362
|
-
const text =
|
|
381
|
+
const text = windows.map(({ part }) => {
|
|
363
382
|
const reset = full && part.resetIn ? `, resets ${part.resetIn}` : '';
|
|
364
383
|
return `${part.kind === 'budget' ? '' : `${part.name} `}${part.figure}${reset}`;
|
|
365
384
|
});
|
|
366
|
-
return
|
|
385
|
+
return age === undefined ? text : [...text, age];
|
|
367
386
|
}
|
|
368
387
|
/**
|
|
369
388
|
* A row's quota as one line: `5h 58% left · 7d 90% left` in the compact
|