@cortexkit/opencode-antigravity-auth 3.1.8 → 3.1.9
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 +111 -77
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +71 -32
- package/dist/index.js +5072 -4519
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +315 -256
- package/dist/server.js +1018 -395
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/fs/private-files.js +8 -3
- package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/opencode2/index.js +1 -1
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +6 -1
- package/dist/src/common-auth-embedded/opencode2/install.js +14 -4
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +10 -7
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +66 -16
- package/dist/src/common-auth-embedded/routing-accessor/index.js +123 -17
- package/dist/src/common-auth-embedded/source-output.json +35 -35
- package/dist/src/common-auth-embedded/store/mutate.js +34 -13
- package/dist/src/ga/server/index.d.ts +1 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +58 -19
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +102 -80
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +27 -13
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +21 -11
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +13 -5
- 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 +2 -2
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/opencode-retry-hints.d.ts +2 -0
- package/dist/src/plugin/shared/opencode-retry-hints.d.ts.map +1 -0
- package/dist/src/plugin/shared/opencode-retry-hints.js +22 -0
- package/dist/src/plugin/shared/opencode-retry-hints.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +2 -0
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +410 -112
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-routing-purpose.d.ts +6 -2
- package/dist/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-routing-purpose.js +13 -7
- package/dist/src/plugin/shared/vault-routing-purpose.js.map +1 -1
- package/dist/src/plugin/shared/vault-routing.d.ts +8 -1
- package/dist/src/plugin/shared/vault-routing.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-routing.js +12 -4
- package/dist/src/plugin/shared/vault-routing.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +1 -0
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +3 -3
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +6 -13
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +19 -16
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/tui-build-map.json +5 -5
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +6 -1
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +10 -7
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +66 -16
- package/dist/types/src/ga/server/index.d.ts +1 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- 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/opencode-retry-hints.d.ts +2 -0
- package/dist/types/src/plugin/shared/opencode-retry-hints.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +2 -0
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts +6 -2
- package/dist/types/src/plugin/shared/vault-routing-purpose.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-routing.d.ts +8 -1
- package/dist/types/src/plugin/shared/vault-routing.d.ts.map +1 -1
- package/dist/types/src/plugin/storage.d.ts +1 -0
- package/dist/types/src/plugin/storage.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +6 -13
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/fs/private-files.js +8 -3
- package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/src/common-auth-embedded/opencode2/index.js +1 -1
- package/src/common-auth-embedded/opencode2/install.d.ts +6 -1
- package/src/common-auth-embedded/opencode2/install.js +14 -4
- package/src/common-auth-embedded/opencode2/types.d.ts +10 -7
- package/src/common-auth-embedded/routing-accessor/index.d.ts +66 -16
- package/src/common-auth-embedded/routing-accessor/index.js +123 -17
- package/src/common-auth-embedded/source-output.json +35 -35
- package/src/common-auth-embedded/store/mutate.js +34 -13
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +8 -3
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +8 -3
|
@@ -13,11 +13,31 @@ export interface RoutingCandidate {
|
|
|
13
13
|
accountId: string;
|
|
14
14
|
credentialId: string;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
type ContinueExhaustion = {
|
|
17
|
+
/** Vault account id, not the plugin's route id. */
|
|
18
|
+
accountId: string;
|
|
19
|
+
credentialId: string;
|
|
20
|
+
/** When the limit or sign-in signal was observed, in Unix milliseconds. */
|
|
21
|
+
observedAtMs: number;
|
|
22
|
+
} & ({
|
|
23
|
+
limitWindow: 'five_hour' | 'seven_day';
|
|
24
|
+
/** Scoped quota group matching `^[a-z0-9._-]{1,64}$`. */
|
|
25
|
+
pool?: string;
|
|
26
|
+
/** Reset time in Unix milliseconds. */
|
|
27
|
+
resetsAtMs?: number;
|
|
28
|
+
/** Non-negative seconds until retry, rounded down. */
|
|
29
|
+
retryAfterS?: number;
|
|
30
|
+
} | {
|
|
31
|
+
limitWindow: 'signed_out';
|
|
32
|
+
pool?: never;
|
|
33
|
+
resetsAtMs?: never;
|
|
34
|
+
retryAfterS?: never;
|
|
35
|
+
});
|
|
36
|
+
export type AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate, Refusals extends boolean = false> = {
|
|
17
37
|
sessionId: string;
|
|
18
38
|
provider: string;
|
|
19
39
|
modelId: string;
|
|
20
|
-
/** Only routes
|
|
40
|
+
/** Only routes eligible under the vault and the user's configured rules. */
|
|
21
41
|
candidates: readonly Candidate[];
|
|
22
42
|
/** Defaults to 1500 ms, above routing's normal tail; clamped to 1–2000 ms. */
|
|
23
43
|
deadlineMs?: number;
|
|
@@ -33,7 +53,24 @@ export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCan
|
|
|
33
53
|
holdWaitMaxS?: number;
|
|
34
54
|
/** Plugin sticky choice's vault credential id; an eligible-account hint, not a pin. */
|
|
35
55
|
warmCredentialId?: string;
|
|
36
|
-
}
|
|
56
|
+
} & ({
|
|
57
|
+
mode?: never;
|
|
58
|
+
requestId?: never;
|
|
59
|
+
exhausted?: never;
|
|
60
|
+
} | {
|
|
61
|
+
/**
|
|
62
|
+
* Ask routing whether a run should move off its pinned account. Send to
|
|
63
|
+
* the selected account, or wait on it if the answer includes a hold.
|
|
64
|
+
* With `refusals: true`, a `{refused}` answer means keep the run paused
|
|
65
|
+
* on its account until the reset or, for `signed_out`, until the user
|
|
66
|
+
* signs in. Do not ask again while paused.
|
|
67
|
+
*/
|
|
68
|
+
mode: 'continue';
|
|
69
|
+
/** One id per question (e.g. a fresh UUID); reuse it only to retry that same question. */
|
|
70
|
+
requestId: string;
|
|
71
|
+
/** Required on a continue: a proved usage limit or a definite sign-in signal. */
|
|
72
|
+
exhausted: ContinueExhaustion;
|
|
73
|
+
});
|
|
37
74
|
export interface RoutingHold {
|
|
38
75
|
/** Uncapped advice from routing. The plugin must apply its own hold cap. */
|
|
39
76
|
retry_after_ms: number;
|
|
@@ -47,6 +84,7 @@ export type RoutingRefusal = {
|
|
|
47
84
|
refused: {
|
|
48
85
|
code: 'account_limit_exhausted' | 'account_selection_refused' | 'account_selection_final';
|
|
49
86
|
routingCode?: string;
|
|
87
|
+
reason?: string;
|
|
50
88
|
retryAfterSecs?: number;
|
|
51
89
|
resetsAtMs?: number;
|
|
52
90
|
};
|
|
@@ -110,7 +148,21 @@ export type ReportRoutingInput = (RoutingReportIdentity & ({
|
|
|
110
148
|
* as 403 or 429. Must match `^[a-z0-9._-]{1,64}$`.
|
|
111
149
|
*/
|
|
112
150
|
providerCode: string;
|
|
113
|
-
})) | {
|
|
151
|
+
})) | (RoutingReportIdentity & {
|
|
152
|
+
/**
|
|
153
|
+
* Report a 429 or similar response that isn't a proved quota limit. With
|
|
154
|
+
* no provider retry time, use the final attempt's receipt time + 5,000 ms.
|
|
155
|
+
* Routing blocks only new admissions on the account until `retryAtMs`.
|
|
156
|
+
* The session's pin stays: wait until `retryAtMs` and retry the run on
|
|
157
|
+
* the same account. For a proved quota limit, report `exhausted` and ask
|
|
158
|
+
* routing to continue with the exhausted window. Use `credential_refused`
|
|
159
|
+
* for an API key refused for any use.
|
|
160
|
+
*/
|
|
161
|
+
kind: 'transient_backoff';
|
|
162
|
+
/** Absolute retry time in Unix milliseconds. */
|
|
163
|
+
retryAtMs: number;
|
|
164
|
+
providerCode?: string;
|
|
165
|
+
}) | {
|
|
114
166
|
sessionId: string;
|
|
115
167
|
kind: 'turn_notes_supported';
|
|
116
168
|
model: string;
|
|
@@ -175,20 +227,18 @@ export declare function turnNotes(sessionId: string): readonly {
|
|
|
175
227
|
* Ask routing for an eligible vault route. Any failure or unfamiliar answer
|
|
176
228
|
* yields undefined so the plugin can keep its own choice. Opted-in routing
|
|
177
229
|
* refusals instead stop the request. This does not admit routes. Callers never
|
|
178
|
-
* pass an account the vault refused.
|
|
179
|
-
* user
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* floor, and don't add floors of the plugin's own that duplicate routing's
|
|
185
|
-
* reserves.
|
|
230
|
+
* pass an account the vault refused. Beyond that, a plugin may leave accounts
|
|
231
|
+
* out only under a user-configured eligibility rule, such as a killswitch floor
|
|
232
|
+
* the user turned on (the minimum share of a quota window an account must keep
|
|
233
|
+
* to be offered) or a per-model account list. Plugins ship no floors of
|
|
234
|
+
* their own by default. Routing's pick is final: never reject it under a local
|
|
235
|
+
* floor or choose another account afterwards.
|
|
186
236
|
*/
|
|
187
237
|
export declare function askRouting<Candidate extends RoutingCandidate, Refusals extends boolean = false>(input: AskRoutingInput<Candidate, Refusals>): Promise<RoutingSelection<Candidate> | (Refusals extends true ? RoutingRefusal : never) | undefined>;
|
|
188
238
|
/**
|
|
189
|
-
* Report a vault request, billing result, plugin wait or
|
|
190
|
-
* waiting for routing. Only contract fields are sent,
|
|
191
|
-
* are ignored. Headers must already be limited to
|
|
192
|
-
* caller; values are not filtered or redacted here.
|
|
239
|
+
* Report a vault request, account backoff, billing result, plugin wait or
|
|
240
|
+
* turn-note event without waiting for routing. Only contract fields are sent,
|
|
241
|
+
* and all accessor failures are ignored. Headers must already be limited to
|
|
242
|
+
* rate-limit headers by the caller; values are not filtered or redacted here.
|
|
193
243
|
*/
|
|
194
244
|
export declare function reportRouting(input: ReportRoutingInput): void;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* rows. Nothing is persisted here; plugins on routes the runner does not serve
|
|
5
5
|
* get no turn notes.
|
|
6
6
|
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
7
8
|
import { isCacheWarmStopReason, } from './cache-policy.js';
|
|
8
9
|
import { routingHandle } from './handle.js';
|
|
9
10
|
export { CACHE_WARM_STOP_REASONS, isCacheWarmStopReason, reportCacheTouch, reportCacheWarmStopped, sessionCachePolicy, sessionToolWait, } from './cache-policy.js';
|
|
@@ -22,6 +23,58 @@ function isObject(value) {
|
|
|
22
23
|
function isNonEmptyString(value) {
|
|
23
24
|
return typeof value === 'string' && value.length > 0;
|
|
24
25
|
}
|
|
26
|
+
function isBoundedControlFreeString(value, maxLength) {
|
|
27
|
+
return (isNonEmptyString(value) &&
|
|
28
|
+
value.length <= maxLength &&
|
|
29
|
+
!/\p{Cc}/u.test(value));
|
|
30
|
+
}
|
|
31
|
+
function isRoutingCode(value) {
|
|
32
|
+
return typeof value === 'string' && /^[a-z0-9._-]{1,64}$/.test(value);
|
|
33
|
+
}
|
|
34
|
+
function continueExhaustion(value) {
|
|
35
|
+
if (!isObject(value) || Array.isArray(value))
|
|
36
|
+
return undefined;
|
|
37
|
+
const { accountId, credentialId, limitWindow, observedAtMs } = value;
|
|
38
|
+
if (!isBoundedControlFreeString(accountId, 256) ||
|
|
39
|
+
!isBoundedControlFreeString(credentialId, 256) ||
|
|
40
|
+
typeof observedAtMs !== 'number' ||
|
|
41
|
+
!Number.isSafeInteger(observedAtMs) ||
|
|
42
|
+
observedAtMs <= 0 ||
|
|
43
|
+
(limitWindow !== 'five_hour' &&
|
|
44
|
+
limitWindow !== 'seven_day' &&
|
|
45
|
+
limitWindow !== 'signed_out'))
|
|
46
|
+
return undefined;
|
|
47
|
+
const exhausted = {
|
|
48
|
+
account: accountId,
|
|
49
|
+
credential_id: credentialId,
|
|
50
|
+
limit_window: limitWindow,
|
|
51
|
+
observed_at_ms: observedAtMs,
|
|
52
|
+
};
|
|
53
|
+
if (limitWindow === 'signed_out') {
|
|
54
|
+
if ('pool' in value || 'resetsAtMs' in value || 'retryAfterS' in value)
|
|
55
|
+
return undefined;
|
|
56
|
+
return exhausted;
|
|
57
|
+
}
|
|
58
|
+
const { pool, resetsAtMs, retryAfterS } = value;
|
|
59
|
+
if ((pool !== undefined && !isRoutingCode(pool)) ||
|
|
60
|
+
(resetsAtMs !== undefined &&
|
|
61
|
+
(typeof resetsAtMs !== 'number' ||
|
|
62
|
+
!Number.isSafeInteger(resetsAtMs) ||
|
|
63
|
+
resetsAtMs <= 0)) ||
|
|
64
|
+
(retryAfterS !== undefined &&
|
|
65
|
+
(typeof retryAfterS !== 'number' ||
|
|
66
|
+
!Number.isFinite(retryAfterS) ||
|
|
67
|
+
retryAfterS < 0)))
|
|
68
|
+
return undefined;
|
|
69
|
+
return {
|
|
70
|
+
...exhausted,
|
|
71
|
+
...(pool !== undefined ? { pool } : {}),
|
|
72
|
+
...(resetsAtMs !== undefined ? { resets_at_ms: resetsAtMs } : {}),
|
|
73
|
+
...(retryAfterS !== undefined
|
|
74
|
+
? { retry_after_s: Math.floor(retryAfterS) }
|
|
75
|
+
: {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
25
78
|
function billingCache(value) {
|
|
26
79
|
if (!isObject(value) || Array.isArray(value))
|
|
27
80
|
return;
|
|
@@ -123,6 +176,24 @@ export function turnNotes(sessionId) {
|
|
|
123
176
|
return [];
|
|
124
177
|
}
|
|
125
178
|
}
|
|
179
|
+
function candidateView(candidates) {
|
|
180
|
+
const accounts = [];
|
|
181
|
+
for (const { accountId, credentialId } of candidates) {
|
|
182
|
+
if (isNonEmptyString(accountId) &&
|
|
183
|
+
isBoundedControlFreeString(credentialId, 256)) {
|
|
184
|
+
accounts.push({ account_id: accountId, credential_id: credentialId });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (accounts.length === 0)
|
|
188
|
+
return undefined;
|
|
189
|
+
const lines = accounts
|
|
190
|
+
.map(({ account_id, credential_id }) => Buffer.from(`${account_id}\t${credential_id}\n`, 'utf8'))
|
|
191
|
+
.sort(Buffer.compare);
|
|
192
|
+
const hash = createHash('sha256');
|
|
193
|
+
for (const line of lines)
|
|
194
|
+
hash.update(line);
|
|
195
|
+
return { view_digest: hash.digest('hex'), accounts };
|
|
196
|
+
}
|
|
126
197
|
function selectionFor(answer, candidates) {
|
|
127
198
|
if (!isObject(answer))
|
|
128
199
|
return undefined;
|
|
@@ -156,11 +227,11 @@ function refusalFor(value) {
|
|
|
156
227
|
return undefined;
|
|
157
228
|
}
|
|
158
229
|
const refused = { code };
|
|
159
|
-
const routingCode = value
|
|
160
|
-
if (
|
|
161
|
-
/^[a-z0-9._-]{1,64}$/.test(routingCode)) {
|
|
230
|
+
const { routing_code: routingCode, reason } = value;
|
|
231
|
+
if (isRoutingCode(routingCode))
|
|
162
232
|
refused.routingCode = routingCode;
|
|
163
|
-
|
|
233
|
+
if (isRoutingCode(reason))
|
|
234
|
+
refused.reason = reason;
|
|
164
235
|
const retryAfterSecs = value.retry_after_secs;
|
|
165
236
|
if (typeof retryAfterSecs === 'number' &&
|
|
166
237
|
Number.isFinite(retryAfterSecs) &&
|
|
@@ -178,6 +249,21 @@ function refusalFor(value) {
|
|
|
178
249
|
export async function askRouting(input) {
|
|
179
250
|
let timer;
|
|
180
251
|
try {
|
|
252
|
+
const request = {
|
|
253
|
+
provider: input.provider,
|
|
254
|
+
modelId: input.modelId,
|
|
255
|
+
};
|
|
256
|
+
if (input.mode === 'continue') {
|
|
257
|
+
const { requestId } = input;
|
|
258
|
+
if (!isBoundedControlFreeString(requestId, 128))
|
|
259
|
+
return undefined;
|
|
260
|
+
const exhausted = continueExhaustion(input.exhausted);
|
|
261
|
+
if (!exhausted)
|
|
262
|
+
return undefined;
|
|
263
|
+
request.mode = 'continue';
|
|
264
|
+
request.request_id = requestId;
|
|
265
|
+
request.exhausted = exhausted;
|
|
266
|
+
}
|
|
181
267
|
const handle = routingHandle(input.sessionId);
|
|
182
268
|
if (!handle)
|
|
183
269
|
return undefined;
|
|
@@ -192,10 +278,6 @@ export async function askRouting(input) {
|
|
|
192
278
|
timer = setTimeout(() => resolve(undefined), deadlineMs);
|
|
193
279
|
timer.unref();
|
|
194
280
|
});
|
|
195
|
-
const request = {
|
|
196
|
-
provider: input.provider,
|
|
197
|
-
modelId: input.modelId,
|
|
198
|
-
};
|
|
199
281
|
const cap = input.holdWaitMaxS;
|
|
200
282
|
if (typeof cap === 'number' && Number.isFinite(cap)) {
|
|
201
283
|
request.hold_wait_max_s = Math.max(0, Math.floor(cap));
|
|
@@ -203,12 +285,13 @@ export async function askRouting(input) {
|
|
|
203
285
|
if (input.refusals === true)
|
|
204
286
|
request.refusals = true;
|
|
205
287
|
const warmCredentialId = input.warmCredentialId;
|
|
206
|
-
if (
|
|
207
|
-
warmCredentialId.length <= 256 &&
|
|
208
|
-
!/\p{Cc}/u.test(warmCredentialId) &&
|
|
288
|
+
if (isBoundedControlFreeString(warmCredentialId, 256) &&
|
|
209
289
|
input.candidates.some((candidate) => candidate.credentialId === warmCredentialId)) {
|
|
210
290
|
request.warm_credential = warmCredentialId;
|
|
211
291
|
}
|
|
292
|
+
const candidates = candidateView(input.candidates);
|
|
293
|
+
if (candidates)
|
|
294
|
+
request.candidates = candidates;
|
|
212
295
|
const pending = accountFor.call(handle, request, { deadlineMs });
|
|
213
296
|
if (!isObject(pending) || typeof pending.then !== 'function')
|
|
214
297
|
return undefined;
|
|
@@ -227,10 +310,10 @@ export async function askRouting(input) {
|
|
|
227
310
|
}
|
|
228
311
|
}
|
|
229
312
|
/**
|
|
230
|
-
* Report a vault request, billing result, plugin wait or
|
|
231
|
-
* waiting for routing. Only contract fields are sent,
|
|
232
|
-
* are ignored. Headers must already be limited to
|
|
233
|
-
* caller; values are not filtered or redacted here.
|
|
313
|
+
* Report a vault request, account backoff, billing result, plugin wait or
|
|
314
|
+
* turn-note event without waiting for routing. Only contract fields are sent,
|
|
315
|
+
* and all accessor failures are ignored. Headers must already be limited to
|
|
316
|
+
* rate-limit headers by the caller; values are not filtered or redacted here.
|
|
234
317
|
*/
|
|
235
318
|
export function reportRouting(input) {
|
|
236
319
|
try {
|
|
@@ -244,6 +327,30 @@ export function reportRouting(input) {
|
|
|
244
327
|
let payload;
|
|
245
328
|
if ('kind' in input) {
|
|
246
329
|
switch (input.kind) {
|
|
330
|
+
case 'transient_backoff': {
|
|
331
|
+
const { accountId, credentialId, retryAtMs, providerCode } = input;
|
|
332
|
+
if (!isNonEmptyString(sessionId) ||
|
|
333
|
+
!isNonEmptyString(accountId) ||
|
|
334
|
+
!Number.isSafeInteger(retryAtMs) ||
|
|
335
|
+
retryAtMs <= 0 ||
|
|
336
|
+
(credentialId !== undefined &&
|
|
337
|
+
!isBoundedControlFreeString(credentialId, 256)) ||
|
|
338
|
+
(providerCode !== undefined &&
|
|
339
|
+
!isBoundedControlFreeString(providerCode, 128)))
|
|
340
|
+
return;
|
|
341
|
+
payload = {
|
|
342
|
+
kind: 'transient_backoff',
|
|
343
|
+
account_id: accountId,
|
|
344
|
+
...(credentialId !== undefined
|
|
345
|
+
? { credential_id: credentialId }
|
|
346
|
+
: {}),
|
|
347
|
+
retry_at_ms: retryAtMs,
|
|
348
|
+
...(providerCode !== undefined
|
|
349
|
+
? { provider_code: providerCode }
|
|
350
|
+
: {}),
|
|
351
|
+
};
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
247
354
|
case 'wait': {
|
|
248
355
|
const { phase, waitId, reason, nextMs, attempt, message, outcome } = input;
|
|
249
356
|
if (!isNonEmptyString(sessionId) ||
|
|
@@ -406,8 +513,7 @@ export function reportRouting(input) {
|
|
|
406
513
|
if (window !== '5h' && window !== '7d')
|
|
407
514
|
return;
|
|
408
515
|
// An undefined pool means the whole account, as an omitted one does.
|
|
409
|
-
if (pool !== undefined &&
|
|
410
|
-
(typeof pool !== 'string' || !/^[a-z0-9._-]{1,64}$/.test(pool)))
|
|
516
|
+
if (pool !== undefined && !isRoutingCode(pool))
|
|
411
517
|
return;
|
|
412
518
|
payload = {
|
|
413
519
|
...identity,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"package": "@cortexkit/common-auth",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.55.0",
|
|
5
5
|
"artifactStatus": "published",
|
|
6
|
-
"archiveBytes":
|
|
6
|
+
"archiveBytes": 502568,
|
|
7
7
|
"publicRoots": {
|
|
8
8
|
"./rpc": {
|
|
9
9
|
"types": "./dist/rpc/index.d.ts",
|
|
@@ -74,16 +74,16 @@
|
|
|
74
74
|
"import": "./src/quota-sidebar/index.tsx"
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
-
"input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.
|
|
78
|
-
"tarballSha256": "
|
|
79
|
-
"sri": "sha512-
|
|
80
|
-
"shasum": "
|
|
77
|
+
"input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.55.0.tgz",
|
|
78
|
+
"tarballSha256": "b629e10e9a39c5b1e6dc7576c2d5814a23a5bbb2dad8d6c1ccddb759c14d200c",
|
|
79
|
+
"sri": "sha512-EScwmEDdxSdW/z+6n1v630bsTdAUSQYBuG4l16yziRqptG4MhjCAoH6aNelSy/I3hIJ2j6bV3IcqteoGWBLpSg==",
|
|
80
|
+
"shasum": "8a5d3a07ec72662120305388d051c0bdcee416f4",
|
|
81
81
|
"canonicalFiles": 257,
|
|
82
|
-
"canonicalBytes":
|
|
82
|
+
"canonicalBytes": 1522655,
|
|
83
83
|
"generator": {
|
|
84
84
|
"path": "packages/opencode/scripts/embed-common-auth.ts",
|
|
85
85
|
"version": 4,
|
|
86
|
-
"sha256": "
|
|
86
|
+
"sha256": "d4f9c099ec2dd6a53cd0b7a35e5571be94e24176c7e01347e4ea20b92eed13fd"
|
|
87
87
|
},
|
|
88
88
|
"files": [
|
|
89
89
|
{
|
|
@@ -681,9 +681,9 @@
|
|
|
681
681
|
{
|
|
682
682
|
"source": "package/dist/fs/private-files.js",
|
|
683
683
|
"output": "fs/private-files.js",
|
|
684
|
-
"bytes":
|
|
685
|
-
"sourceSha256": "
|
|
686
|
-
"outputSha256": "
|
|
684
|
+
"bytes": 15526,
|
|
685
|
+
"sourceSha256": "8456644c921d76d1946c9c04a6784308dfbc4c22be19d88d5b15bf629d5f4226",
|
|
686
|
+
"outputSha256": "8456644c921d76d1946c9c04a6784308dfbc4c22be19d88d5b15bf629d5f4226",
|
|
687
687
|
"transform": "verbatim"
|
|
688
688
|
},
|
|
689
689
|
{
|
|
@@ -897,33 +897,33 @@
|
|
|
897
897
|
{
|
|
898
898
|
"source": "package/dist/opencode2/index.d.ts",
|
|
899
899
|
"output": "opencode2/index.d.ts",
|
|
900
|
-
"bytes":
|
|
901
|
-
"sourceSha256": "
|
|
902
|
-
"outputSha256": "
|
|
900
|
+
"bytes": 1325,
|
|
901
|
+
"sourceSha256": "03baf6a3ea7b26545ec20a03588ac7f30830c84e15f4bbde51d268218ff3e284",
|
|
902
|
+
"outputSha256": "03baf6a3ea7b26545ec20a03588ac7f30830c84e15f4bbde51d268218ff3e284",
|
|
903
903
|
"transform": "verbatim"
|
|
904
904
|
},
|
|
905
905
|
{
|
|
906
906
|
"source": "package/dist/opencode2/index.js",
|
|
907
907
|
"output": "opencode2/index.js",
|
|
908
|
-
"bytes":
|
|
909
|
-
"sourceSha256": "
|
|
910
|
-
"outputSha256": "
|
|
908
|
+
"bytes": 485,
|
|
909
|
+
"sourceSha256": "0a68a5e9af890954e96172fd475ea20e6e137ad20feb0c5ad014d4ea33dfd198",
|
|
910
|
+
"outputSha256": "0a68a5e9af890954e96172fd475ea20e6e137ad20feb0c5ad014d4ea33dfd198",
|
|
911
911
|
"transform": "verbatim"
|
|
912
912
|
},
|
|
913
913
|
{
|
|
914
914
|
"source": "package/dist/opencode2/install.d.ts",
|
|
915
915
|
"output": "opencode2/install.d.ts",
|
|
916
|
-
"bytes":
|
|
917
|
-
"sourceSha256": "
|
|
918
|
-
"outputSha256": "
|
|
916
|
+
"bytes": 4212,
|
|
917
|
+
"sourceSha256": "edb14a4f60ef24c85b5e4f41f94b66b5594f38628c65145841fa4bcf1bf319f6",
|
|
918
|
+
"outputSha256": "edb14a4f60ef24c85b5e4f41f94b66b5594f38628c65145841fa4bcf1bf319f6",
|
|
919
919
|
"transform": "verbatim"
|
|
920
920
|
},
|
|
921
921
|
{
|
|
922
922
|
"source": "package/dist/opencode2/install.js",
|
|
923
923
|
"output": "opencode2/install.js",
|
|
924
|
-
"bytes":
|
|
925
|
-
"sourceSha256": "
|
|
926
|
-
"outputSha256": "
|
|
924
|
+
"bytes": 65592,
|
|
925
|
+
"sourceSha256": "fc98e6bd26a6835d118666b1f27fc0598dbe9f929d793b2fe619d3be7375b988",
|
|
926
|
+
"outputSha256": "fc98e6bd26a6835d118666b1f27fc0598dbe9f929d793b2fe619d3be7375b988",
|
|
927
927
|
"transform": "verbatim"
|
|
928
928
|
},
|
|
929
929
|
{
|
|
@@ -961,9 +961,9 @@
|
|
|
961
961
|
{
|
|
962
962
|
"source": "package/dist/opencode2/types.d.ts",
|
|
963
963
|
"output": "opencode2/types.d.ts",
|
|
964
|
-
"bytes":
|
|
965
|
-
"sourceSha256": "
|
|
966
|
-
"outputSha256": "
|
|
964
|
+
"bytes": 32971,
|
|
965
|
+
"sourceSha256": "955be769b8aacbc13f51d16a94639658424b3e02e29c2a252b4b872bfde9096f",
|
|
966
|
+
"outputSha256": "955be769b8aacbc13f51d16a94639658424b3e02e29c2a252b4b872bfde9096f",
|
|
967
967
|
"transform": "verbatim"
|
|
968
968
|
},
|
|
969
969
|
{
|
|
@@ -1857,9 +1857,9 @@
|
|
|
1857
1857
|
{
|
|
1858
1858
|
"source": "package/dist/store/mutate.js",
|
|
1859
1859
|
"output": "store/mutate.js",
|
|
1860
|
-
"bytes":
|
|
1861
|
-
"sourceSha256": "
|
|
1862
|
-
"outputSha256": "
|
|
1860
|
+
"bytes": 21075,
|
|
1861
|
+
"sourceSha256": "e2b69c850dface416ff3ebc54e2f57fd5c36b5346055b90195493cada75b6901",
|
|
1862
|
+
"outputSha256": "e2b69c850dface416ff3ebc54e2f57fd5c36b5346055b90195493cada75b6901",
|
|
1863
1863
|
"transform": "verbatim"
|
|
1864
1864
|
},
|
|
1865
1865
|
{
|
|
@@ -2129,17 +2129,17 @@
|
|
|
2129
2129
|
{
|
|
2130
2130
|
"source": "package/dist/routing-accessor/index.d.ts",
|
|
2131
2131
|
"output": "routing-accessor/index.d.ts",
|
|
2132
|
-
"bytes":
|
|
2133
|
-
"sourceSha256": "
|
|
2134
|
-
"outputSha256": "
|
|
2132
|
+
"bytes": 10161,
|
|
2133
|
+
"sourceSha256": "9a53d387aea7a3423225372bd8a61000838e1c7bb5818c93a32455f2037c315f",
|
|
2134
|
+
"outputSha256": "9a53d387aea7a3423225372bd8a61000838e1c7bb5818c93a32455f2037c315f",
|
|
2135
2135
|
"transform": "verbatim"
|
|
2136
2136
|
},
|
|
2137
2137
|
{
|
|
2138
2138
|
"source": "package/dist/routing-accessor/index.js",
|
|
2139
2139
|
"output": "routing-accessor/index.js",
|
|
2140
|
-
"bytes":
|
|
2141
|
-
"sourceSha256": "
|
|
2142
|
-
"outputSha256": "
|
|
2140
|
+
"bytes": 22848,
|
|
2141
|
+
"sourceSha256": "13f13701391958c2e1f52d614a78da8d276594a90ee54b4f6af33bf81b4ca669",
|
|
2142
|
+
"outputSha256": "13f13701391958c2e1f52d614a78da8d276594a90ee54b4f6af33bf81b4ca669",
|
|
2143
2143
|
"transform": "verbatim"
|
|
2144
2144
|
}
|
|
2145
2145
|
],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setTimeout as
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
2
|
import { AtomicSyncError, syncJsonFile, writeJsonAtomic, writeJsonAtomicTracked, } from '../fs/atomic-write.js';
|
|
3
|
-
import { readPrivateText, windowsPrivateFiles } from '../fs/private-files.js';
|
|
3
|
+
import { isWindowsSharingViolation, readPrivateText, windowsPrivateFiles, } from '../fs/private-files.js';
|
|
4
4
|
import { LockContentionError, LockOwnershipError } from '../fs/with-lock.js';
|
|
5
5
|
import { PoolOperationError, } from './errors.js';
|
|
6
6
|
import { callFailureHook } from './hooks.js';
|
|
@@ -8,14 +8,25 @@ import { LockStack, } from './refresh-lock.js';
|
|
|
8
8
|
import { assertNotReserved } from './reserved.js';
|
|
9
9
|
import { CREDENTIAL_STAMP_KEY, classifyConfig, classifyState, ensureEntries, entryIn, isRecord, LEGACY_STORE_VERSION, POOL_KEY, POOL_ROWS_KEY, POOL_SCHEMA_VERSION, retireEpochsIn, rosterOf, rosterRowIn, setEntryIn, } from './schema.js';
|
|
10
10
|
import { completeTornRows, loadRows } from './torn.js';
|
|
11
|
+
// About 1 s in total. A replace usually clears in milliseconds, but an
|
|
12
|
+
// OpenCode 2 turn ends if the first pool read of a request fails, and a
|
|
13
|
+
// scanner opening the new file can hold it longer.
|
|
14
|
+
const sharingRetryDelays = [5, 10, 20, 40, 80, 160, 320, 400];
|
|
11
15
|
async function readText(path) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
for (let attempt = 0;; attempt++) {
|
|
17
|
+
try {
|
|
18
|
+
return await readPrivateText(path, windowsPrivateFiles);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code === 'ENOENT')
|
|
22
|
+
return undefined;
|
|
23
|
+
const wait = sharingRetryDelays[attempt];
|
|
24
|
+
// An atomic replace can briefly block a Windows read. Permission
|
|
25
|
+
// refusals are not evidence of a replace and must still surface at once.
|
|
26
|
+
if (wait === undefined || !isWindowsSharingViolation(error))
|
|
27
|
+
throw error;
|
|
28
|
+
await delay(wait);
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
31
|
}
|
|
21
32
|
function parseFile(text) {
|
|
@@ -39,12 +50,22 @@ export async function readPoolConfig(path) {
|
|
|
39
50
|
*/
|
|
40
51
|
export async function readPool(ctx) {
|
|
41
52
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
let configText;
|
|
54
|
+
let stateText;
|
|
55
|
+
let checkedConfigText;
|
|
56
|
+
try {
|
|
57
|
+
configText = await readText(ctx.configPath);
|
|
58
|
+
stateText = await readText(ctx.statePath);
|
|
59
|
+
checkedConfigText = await readText(ctx.configPath);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (isWindowsSharingViolation(error))
|
|
63
|
+
break;
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
45
66
|
if (configText !== checkedConfigText) {
|
|
46
67
|
if (attempt < 2)
|
|
47
|
-
await
|
|
68
|
+
await delay(2 + Math.floor(Math.random() * 4));
|
|
48
69
|
continue;
|
|
49
70
|
}
|
|
50
71
|
const config = classifyConfig(parseFile(configText));
|
|
@@ -70,6 +70,10 @@ function loadBackend() {
|
|
|
70
70
|
});
|
|
71
71
|
return backend;
|
|
72
72
|
}
|
|
73
|
+
function isSharingIoError(detail) {
|
|
74
|
+
return (detail?.reason === 'io-error' &&
|
|
75
|
+
(detail.win32Code === 32 || detail.win32Code === 303));
|
|
76
|
+
}
|
|
73
77
|
export class PrivateFileError extends Error {
|
|
74
78
|
path;
|
|
75
79
|
stage;
|
|
@@ -88,7 +92,9 @@ export class PrivateFileError extends Error {
|
|
|
88
92
|
? // The reason stays on `.reason`: its word "unavailable" would make
|
|
89
93
|
// OpenCode 1 retry a plain error carrying this message.
|
|
90
94
|
`Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`
|
|
91
|
-
:
|
|
95
|
+
: isSharingIoError(detail)
|
|
96
|
+
? `Private file busy at ${stage}: ${path}. Another process was replacing or deleting this file at the same moment (Windows error ${detail.win32Code}).`
|
|
97
|
+
: `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
92
98
|
this.path = path;
|
|
93
99
|
this.stage = stage;
|
|
94
100
|
this.name = 'PrivateFileError';
|
|
@@ -101,8 +107,7 @@ export class PrivateFileError extends Error {
|
|
|
101
107
|
export function isWindowsSharingViolation(error) {
|
|
102
108
|
return (windowsPrivateFiles &&
|
|
103
109
|
error instanceof PrivateFileError &&
|
|
104
|
-
error
|
|
105
|
-
(error.win32Code === 32 || error.win32Code === 303));
|
|
110
|
+
isSharingIoError(error));
|
|
106
111
|
}
|
|
107
112
|
export async function privateOperation(path, stage, operation) {
|
|
108
113
|
try {
|
|
@@ -70,6 +70,10 @@ function loadBackend() {
|
|
|
70
70
|
});
|
|
71
71
|
return backend;
|
|
72
72
|
}
|
|
73
|
+
function isSharingIoError(detail) {
|
|
74
|
+
return (detail?.reason === 'io-error' &&
|
|
75
|
+
(detail.win32Code === 32 || detail.win32Code === 303));
|
|
76
|
+
}
|
|
73
77
|
export class PrivateFileError extends Error {
|
|
74
78
|
path;
|
|
75
79
|
stage;
|
|
@@ -88,7 +92,9 @@ export class PrivateFileError extends Error {
|
|
|
88
92
|
? // The reason stays on `.reason`: its word "unavailable" would make
|
|
89
93
|
// OpenCode 1 retry a plain error carrying this message.
|
|
90
94
|
`Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.`
|
|
91
|
-
:
|
|
95
|
+
: isSharingIoError(detail)
|
|
96
|
+
? `Private file busy at ${stage}: ${path}. Another process was replacing or deleting this file at the same moment (Windows error ${detail.win32Code}).`
|
|
97
|
+
: `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? 'io-error'}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
92
98
|
this.path = path;
|
|
93
99
|
this.stage = stage;
|
|
94
100
|
this.name = 'PrivateFileError';
|
|
@@ -101,8 +107,7 @@ export class PrivateFileError extends Error {
|
|
|
101
107
|
export function isWindowsSharingViolation(error) {
|
|
102
108
|
return (windowsPrivateFiles &&
|
|
103
109
|
error instanceof PrivateFileError &&
|
|
104
|
-
error
|
|
105
|
-
(error.win32Code === 32 || error.win32Code === 303));
|
|
110
|
+
isSharingIoError(error));
|
|
106
111
|
}
|
|
107
112
|
export async function privateOperation(path, stage, operation) {
|
|
108
113
|
try {
|