@cortexkit/opencode-antigravity-auth 3.0.30 → 3.0.32
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 +104 -81
- package/dist/cli.js.map +3 -3
- package/dist/cli.meta.json +24 -19
- package/dist/index.js +171 -140
- package/dist/index.js.map +3 -3
- package/dist/index.meta.json +28 -23
- package/dist/server.js +171 -140
- package/dist/server.js.map +3 -3
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/dist/src/common-auth-embedded/claustrum/roster.js +32 -8
- package/dist/src/common-auth-embedded/fs/file-read-cache.js +10 -5
- package/dist/src/common-auth-embedded/limits/axes.d.ts +7 -1
- package/dist/src/common-auth-embedded/limits/decide.d.ts +5 -0
- package/dist/src/common-auth-embedded/limits/families.d.ts +4 -2
- package/dist/src/common-auth-embedded/limits/marker.d.ts +5 -0
- package/dist/src/common-auth-embedded/limits/request-history.d.ts +3 -1
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +2 -1
- package/dist/src/common-auth-embedded/opencode2/install.js +58 -9
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +19 -3
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +30 -5
- package/dist/src/common-auth-embedded/routing-accessor/index.js +121 -33
- package/dist/src/common-auth-embedded/setup/enroll.js +7 -1
- package/dist/src/common-auth-embedded/source-output.json +63 -63
- package/dist/src/common-auth-embedded/store/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/limits-namespace.d.ts +7 -1
- package/dist/src/common-auth-embedded/store/limits-namespace.js +19 -7
- package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/pool.js +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.js +0 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/account-access.js +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +3 -2
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +1 -1
- package/dist/src/plugin/shared/request-services.js +1 -1
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/dist/types/src/common-auth-embedded/limits/axes.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/limits/decide.d.ts +5 -0
- package/dist/types/src/common-auth-embedded/limits/families.d.ts +4 -2
- package/dist/types/src/common-auth-embedded/limits/marker.d.ts +5 -0
- package/dist/types/src/common-auth-embedded/limits/request-history.d.ts +3 -1
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +2 -1
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +19 -3
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +30 -5
- package/dist/types/src/common-auth-embedded/store/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/limits-namespace.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +1 -1
- package/package.json +3 -3
- package/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/src/common-auth-embedded/claustrum/roster.js +32 -8
- package/src/common-auth-embedded/fs/file-read-cache.js +10 -5
- package/src/common-auth-embedded/limits/axes.d.ts +7 -1
- package/src/common-auth-embedded/limits/decide.d.ts +5 -0
- package/src/common-auth-embedded/limits/families.d.ts +4 -2
- package/src/common-auth-embedded/limits/marker.d.ts +5 -0
- package/src/common-auth-embedded/limits/request-history.d.ts +3 -1
- package/src/common-auth-embedded/opencode2/install.d.ts +2 -1
- package/src/common-auth-embedded/opencode2/install.js +58 -9
- package/src/common-auth-embedded/opencode2/types.d.ts +19 -3
- package/src/common-auth-embedded/routing-accessor/index.d.ts +30 -5
- package/src/common-auth-embedded/routing-accessor/index.js +121 -33
- package/src/common-auth-embedded/setup/enroll.js +7 -1
- package/src/common-auth-embedded/source-output.json +63 -63
- package/src/common-auth-embedded/store/index.d.ts +1 -1
- package/src/common-auth-embedded/store/limits-namespace.d.ts +7 -1
- package/src/common-auth-embedded/store/limits-namespace.js +19 -7
- package/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/src/common-auth-embedded/store/pool.js +1 -1
|
@@ -120,6 +120,8 @@ export interface VaultRosterLockContext {
|
|
|
120
120
|
}
|
|
121
121
|
export interface MutateVaultRosterOptions {
|
|
122
122
|
signal?: AbortSignal;
|
|
123
|
+
/** Runs under the roster lock once published, even if a later step fails. Must not throw. */
|
|
124
|
+
onPublished?: () => void;
|
|
123
125
|
/**
|
|
124
126
|
* Runs when the new roster is fully staged on disk, immediately before the
|
|
125
127
|
* rename that publishes it, so a caller can confirm a lease of its own at
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { stat } from 'node:fs/promises';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
|
+
import { FileReadCache } from '../fs/file-read-cache.js';
|
|
4
5
|
import { acquireRefreshFileLock, LockContentionError, LockOwnershipError, lockPathFor, PrivateFileError, withLock, writeJsonAtomic, } from '../fs/index.js';
|
|
5
6
|
import { readPrivateText, windowsPrivateFiles } from '../fs/private-files.js';
|
|
6
7
|
import { decodeQuotaMap, isQuotaObservation, mergeQuotaObservation, } from '../quota/index.js';
|
|
@@ -333,7 +334,18 @@ function decodeRoster(value) {
|
|
|
333
334
|
export function decodedVaultRoster(roster) {
|
|
334
335
|
return decodeRoster(JSON.parse(JSON.stringify(roster)));
|
|
335
336
|
}
|
|
337
|
+
const rosterReadCache = new FileReadCache({
|
|
338
|
+
followSymlinks: true,
|
|
339
|
+
});
|
|
336
340
|
export async function readVaultRoster(path) {
|
|
341
|
+
// Windows permission, owner and ancestry checks must still run on every read.
|
|
342
|
+
if (windowsPrivateFiles)
|
|
343
|
+
return readFreshVaultRoster(path);
|
|
344
|
+
const roster = await rosterReadCache.read([path], ([resolvedPath = path]) => readFreshVaultRoster(resolvedPath));
|
|
345
|
+
// Callers edit rows and nested limits data; none may own the cached objects.
|
|
346
|
+
return structuredClone(roster);
|
|
347
|
+
}
|
|
348
|
+
async function readFreshVaultRoster(path) {
|
|
337
349
|
let text;
|
|
338
350
|
try {
|
|
339
351
|
text = await readPrivateText(path, windowsPrivateFiles);
|
|
@@ -366,7 +378,8 @@ const DISCOVERY_LEASE = { name: 'claustrum-roster', ttlMs: 30_000 };
|
|
|
366
378
|
*/
|
|
367
379
|
export async function mutateVaultRoster(path, change, options = {}) {
|
|
368
380
|
return withLock(path, { ...WRITE_LOCK, signal: options.signal }, async (lock) => {
|
|
369
|
-
|
|
381
|
+
// A read-modify-write always observes the file under its write lock.
|
|
382
|
+
const current = await readFreshVaultRoster(path);
|
|
370
383
|
const { next, result } = await change(current, {
|
|
371
384
|
assertOwned: () => lock.assertOwned(),
|
|
372
385
|
});
|
|
@@ -374,13 +387,24 @@ export async function mutateVaultRoster(path, change, options = {}) {
|
|
|
374
387
|
await lock.assertOwned();
|
|
375
388
|
// Staging the file takes several awaited steps; check both the caller's
|
|
376
389
|
// lease and this lock again at the last moment before the rename.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
390
|
+
try {
|
|
391
|
+
await writeJsonAtomic(path, next, {
|
|
392
|
+
beforeRename: async () => {
|
|
393
|
+
await options.beforePublish?.();
|
|
394
|
+
options.signal?.throwIfAborted();
|
|
395
|
+
await lock.assertOwned();
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
if (error &&
|
|
401
|
+
typeof error === 'object' &&
|
|
402
|
+
'published' in error &&
|
|
403
|
+
error.published === true)
|
|
404
|
+
options.onPublished?.();
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
options.onPublished?.();
|
|
384
408
|
}
|
|
385
409
|
return result;
|
|
386
410
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { lstat } from 'node:fs/promises';
|
|
1
|
+
import { lstat, stat } from 'node:fs/promises';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
async function identity(path) {
|
|
3
|
+
async function identity(path, followSymlinks) {
|
|
4
4
|
try {
|
|
5
|
-
|
|
6
|
-
//
|
|
5
|
+
// Match the reader: private readers reject links, while readFile follows
|
|
6
|
+
// them and needs the target's identity, not the link's identity.
|
|
7
|
+
const metadata = await (followSymlinks ? stat(path) : lstat(path));
|
|
7
8
|
return metadata.isFile() ? metadata : undefined;
|
|
8
9
|
}
|
|
9
10
|
catch (error) {
|
|
@@ -23,11 +24,15 @@ function sameIdentity(left, right) {
|
|
|
23
24
|
}
|
|
24
25
|
/** Process-local reads, capped at 64 path sets with one value per resolved set. */
|
|
25
26
|
export class FileReadCache {
|
|
27
|
+
#followSymlinks;
|
|
26
28
|
#entries = new Map();
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.#followSymlinks = options.followSymlinks ?? false;
|
|
31
|
+
}
|
|
27
32
|
async read(paths, read, validateHit) {
|
|
28
33
|
const resolvedPaths = paths.map((path) => resolve(path));
|
|
29
34
|
const key = JSON.stringify(resolvedPaths);
|
|
30
|
-
const probed = await Promise.all(resolvedPaths.map(identity));
|
|
35
|
+
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#followSymlinks)));
|
|
31
36
|
const identities = probed.every((entry) => entry !== undefined)
|
|
32
37
|
? probed
|
|
33
38
|
: undefined;
|
|
@@ -29,8 +29,10 @@ export interface LimitAxes {
|
|
|
29
29
|
readonly preference: 'same-account-first' | 'ready-alternative-first';
|
|
30
30
|
readonly jitter: 'session-sha256' | 'none';
|
|
31
31
|
};
|
|
32
|
-
/**
|
|
32
|
+
/** Legacy uncounted retention remains unbounded. */
|
|
33
33
|
readonly retainBound: 'none';
|
|
34
|
+
/** Opt-in turn/account budget when the caller supplies unconfirmedRetainCount. */
|
|
35
|
+
readonly unconfirmedRetainLimit?: number;
|
|
34
36
|
readonly poolWaiting: {
|
|
35
37
|
readonly kind: 'off';
|
|
36
38
|
} | {
|
|
@@ -56,6 +58,10 @@ export interface LimitAxes {
|
|
|
56
58
|
readonly terminalStatusHistory?: {
|
|
57
59
|
readonly minRetryMs: number;
|
|
58
60
|
readonly defaultRetryMs: number;
|
|
61
|
+
readonly paymentBalance?: {
|
|
62
|
+
readonly family: RefusalFamily;
|
|
63
|
+
readonly messageKey: string;
|
|
64
|
+
};
|
|
59
65
|
};
|
|
60
66
|
readonly refusals: Readonly<Record<RefusalReason, HostValues<RefusalPolicy>>>;
|
|
61
67
|
}
|
|
@@ -9,6 +9,7 @@ import type { WakeFacts } from './wake.js';
|
|
|
9
9
|
export interface TimedBlocker {
|
|
10
10
|
readonly kind: 'hard' | 'cooldown' | 'soft';
|
|
11
11
|
readonly until?: number;
|
|
12
|
+
readonly cause?: import('./marker.js').LimitMarkCause;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Admission includes the caller's minimum quota thresholds, access checks,
|
|
@@ -80,6 +81,8 @@ export interface PolicyFacts {
|
|
|
80
81
|
readonly retryMs?: number;
|
|
81
82
|
};
|
|
82
83
|
readonly retryHintsMs?: readonly number[];
|
|
84
|
+
/** Committed unconfirmed retains for the current session, turn and account. */
|
|
85
|
+
readonly unconfirmedRetainCount?: number;
|
|
83
86
|
readonly hold?: HoldFacts;
|
|
84
87
|
readonly wake?: WakeFacts;
|
|
85
88
|
readonly remainingRetries?: number;
|
|
@@ -110,6 +113,8 @@ export type LimitDecision = DecisionBase & ({
|
|
|
110
113
|
readonly action: 'retain';
|
|
111
114
|
readonly account: AccountKey;
|
|
112
115
|
readonly retryMs?: number;
|
|
116
|
+
/** Commit once when executing this retain, never when polling the decision. */
|
|
117
|
+
readonly incrementUnconfirmedRetain?: true;
|
|
113
118
|
/** Exhaustion windows waived for this dispatch only, never persisted. */
|
|
114
119
|
readonly liftedWindows?: readonly string[];
|
|
115
120
|
} | {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type LimitMessages } from './wording.js';
|
|
2
|
-
export type OpenCode1Family = 'openai-429' | 'claude-429' | 'json-412' | 'claustrum-429' | 'claude-econnreset';
|
|
2
|
+
export type OpenCode1Family = 'openai-429' | 'claude-429' | 'json-412' | 'claustrum-429' | 'claustrum-402' | 'claude-econnreset';
|
|
3
3
|
export type RefusalFamily = OpenCode1Family | 'pi-final';
|
|
4
4
|
export type HostRetry = 'leave' | 'veto';
|
|
5
5
|
export interface RefusalInput {
|
|
6
6
|
readonly family: RefusalFamily;
|
|
7
|
+
/** Local responses formatted for OpenCode 2 must not be replayed by the host. */
|
|
8
|
+
readonly host?: 'opencode1' | 'opencode2' | 'pi';
|
|
7
9
|
readonly messageKey: string;
|
|
8
10
|
readonly messages?: LimitMessages;
|
|
9
11
|
readonly parameters?: {
|
|
@@ -31,7 +33,7 @@ interface RefusalAttributes {
|
|
|
31
33
|
}
|
|
32
34
|
export interface HttpRefusal extends RefusalAttributes {
|
|
33
35
|
readonly kind: 'http';
|
|
34
|
-
readonly status: 412 | 429;
|
|
36
|
+
readonly status: 402 | 412 | 429;
|
|
35
37
|
readonly headers: Headers;
|
|
36
38
|
readonly body: string;
|
|
37
39
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Scope } from './scope.js';
|
|
2
2
|
import type { AccountKey, LimitKind, LimitSignal } from './signal.js';
|
|
3
3
|
export type MergeLaw = 'latest-evidence' | 'max-until' | 'overwrite';
|
|
4
|
+
export type LimitMarkCause = 'rate-limit' | 'payment-balance';
|
|
4
5
|
export interface LimitMark {
|
|
5
6
|
readonly scope: Scope;
|
|
6
7
|
readonly until: number;
|
|
7
8
|
readonly mergeLaw: MergeLaw;
|
|
9
|
+
readonly cause?: LimitMarkCause;
|
|
8
10
|
}
|
|
9
11
|
export interface FailureLadderAxes {
|
|
10
12
|
readonly kind: 'failure-ladder';
|
|
@@ -27,6 +29,9 @@ export type MarkerAxes = {
|
|
|
27
29
|
readonly kind: 'hint';
|
|
28
30
|
readonly mergeLaw: MergeLaw;
|
|
29
31
|
readonly defaultMs: number;
|
|
32
|
+
readonly defaultMsByKind?: Readonly<Partial<Record<LimitSignal['kind'], number>>>;
|
|
33
|
+
readonly causes?: readonly LimitMarkCause[];
|
|
34
|
+
readonly ignoredKinds?: readonly LimitSignal['kind'][];
|
|
30
35
|
readonly minimumMs: number;
|
|
31
36
|
readonly zero: 'accept' | 'skip';
|
|
32
37
|
/** Core absolute dates and host event-relative hints use different samples. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Scope } from './scope.js';
|
|
2
|
-
import type { AccountKey } from './signal.js';
|
|
2
|
+
import type { AccountKey, LimitKind } from './signal.js';
|
|
3
3
|
export declare function sameAccount(a: AccountKey, b: AccountKey): boolean;
|
|
4
4
|
export interface RequestExclusion {
|
|
5
5
|
readonly account: AccountKey;
|
|
@@ -17,6 +17,7 @@ export interface RequestHistory {
|
|
|
17
17
|
readonly originalUrl: string;
|
|
18
18
|
readonly requestStartedAt: number;
|
|
19
19
|
readonly saw429: boolean;
|
|
20
|
+
readonly sawPaymentBalance?: boolean;
|
|
20
21
|
readonly lastStatus?: number;
|
|
21
22
|
readonly tried: readonly RequestExclusion[];
|
|
22
23
|
readonly excludedForRequest: readonly RequestExclusion[];
|
|
@@ -38,6 +39,7 @@ export type RequestHistoryEvent = {
|
|
|
38
39
|
readonly account: AccountKey;
|
|
39
40
|
readonly scope: Scope;
|
|
40
41
|
readonly status?: number;
|
|
42
|
+
readonly kind?: LimitKind;
|
|
41
43
|
} | {
|
|
42
44
|
readonly type: 'retain';
|
|
43
45
|
readonly account: AccountKey;
|
|
@@ -30,7 +30,8 @@ export declare function applyHeaderEdits(target: Record<string, string>, edits:
|
|
|
30
30
|
* - `retry` asks the host to retry at once when an account was refused
|
|
31
31
|
* before any output and `chooseAccount` names another account for the
|
|
32
32
|
* next attempt, keeps the host's decision when the refused account was the
|
|
33
|
-
* last one that can serve
|
|
33
|
+
* last one that can serve. After output, only a witnessed HTTP read failure
|
|
34
|
+
* with adapter-approved same-account continuation can keep the host's retry.
|
|
34
35
|
*
|
|
35
36
|
* Attribution. A send belongs to the attempt named by the mark
|
|
36
37
|
* `model.request` left on it, so several attempts of one session and kind
|
|
@@ -101,7 +101,8 @@ function applyHeaderEditsTo(target, edits) {
|
|
|
101
101
|
* - `retry` asks the host to retry at once when an account was refused
|
|
102
102
|
* before any output and `chooseAccount` names another account for the
|
|
103
103
|
* next attempt, keeps the host's decision when the refused account was the
|
|
104
|
-
* last one that can serve
|
|
104
|
+
* last one that can serve. After output, only a witnessed HTTP read failure
|
|
105
|
+
* with adapter-approved same-account continuation can keep the host's retry.
|
|
105
106
|
*
|
|
106
107
|
* Attribution. A send belongs to the attempt named by the mark
|
|
107
108
|
* `model.request` left on it, so several attempts of one session and kind
|
|
@@ -471,6 +472,12 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
471
472
|
await inChoiceOrder(scope.sessionID, () => releaseSameAccount(sameAccount));
|
|
472
473
|
assertActive();
|
|
473
474
|
}
|
|
475
|
+
if (sameAccount?.continuation &&
|
|
476
|
+
(!sameRoute || mixed(scope.sessionID))) {
|
|
477
|
+
if (sameRoute)
|
|
478
|
+
await inChoiceOrder(scope.sessionID, () => releaseSameAccount(sameAccount));
|
|
479
|
+
throw noAccount(scope);
|
|
480
|
+
}
|
|
474
481
|
const choice = sameRoute
|
|
475
482
|
? sameAccount.accountId
|
|
476
483
|
: matches && wake === undefined
|
|
@@ -796,7 +803,11 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
796
803
|
error: describe(error),
|
|
797
804
|
})));
|
|
798
805
|
}
|
|
799
|
-
response = new Response(trackBody(body, (error) =>
|
|
806
|
+
response = new Response(trackBody(body, (error) => {
|
|
807
|
+
if (error?.reason === 'failed')
|
|
808
|
+
rec.httpReadFailed = true;
|
|
809
|
+
finish(rec, error);
|
|
810
|
+
}), {
|
|
800
811
|
status: original.status,
|
|
801
812
|
statusText: original.statusText,
|
|
802
813
|
headers: original.headers,
|
|
@@ -936,9 +947,38 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
936
947
|
const checkRetryActive = assertActive;
|
|
937
948
|
const retrySameAccount = adapter.retrySameAccount?.bind(adapter);
|
|
938
949
|
const handle = rec.attempt;
|
|
950
|
+
const afterOutput = rec.outputStarted;
|
|
951
|
+
if (afterOutput &&
|
|
952
|
+
rec.httpReadFailed &&
|
|
953
|
+
retrySameAccount &&
|
|
954
|
+
handle &&
|
|
955
|
+
!mixed(draft.sessionID)) {
|
|
956
|
+
if (!rec.limit) {
|
|
957
|
+
const signal = adapter.limitFromError?.(draft.error, handle);
|
|
958
|
+
if (signal)
|
|
959
|
+
noteLimit(rec, signal, 'error');
|
|
960
|
+
}
|
|
961
|
+
if (rec.ended)
|
|
962
|
+
await rec.ended;
|
|
963
|
+
if (rec.limit)
|
|
964
|
+
await rec.limit.delivered;
|
|
965
|
+
checkRetryActive();
|
|
966
|
+
}
|
|
967
|
+
// The host drops read-operation metadata from its retry error. Only
|
|
968
|
+
// our attributed body reader can prove a read failed; wording cannot.
|
|
969
|
+
const canContinue = () => rec.httpReadFailed === true &&
|
|
970
|
+
draft.error.type === 'provider.transport' &&
|
|
971
|
+
hostDecision.retry &&
|
|
972
|
+
hostRetryLimit - draft.attempt >= 1 &&
|
|
973
|
+
!rec.limit &&
|
|
974
|
+
!(rec.status !== undefined && rec.status >= 400) &&
|
|
975
|
+
!(draft.error.status !== undefined && draft.error.status >= 400) &&
|
|
976
|
+
!handle?.reboundFrom &&
|
|
977
|
+
!vetoed() &&
|
|
978
|
+
!mixed(draft.sessionID);
|
|
939
979
|
if (retrySameAccount &&
|
|
940
980
|
handle &&
|
|
941
|
-
!
|
|
981
|
+
(!afterOutput || canContinue()) &&
|
|
942
982
|
(!vetoed() || mixed(draft.sessionID)) &&
|
|
943
983
|
!rec.sameAccountRetry) {
|
|
944
984
|
if (rec.ended)
|
|
@@ -951,7 +991,8 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
951
991
|
const active = () => attempts.has(rec.id) &&
|
|
952
992
|
rec.accountId === accountId &&
|
|
953
993
|
pickForRetry(draft.sessionID) === rec &&
|
|
954
|
-
|
|
994
|
+
rec.outputStarted === afterOutput &&
|
|
995
|
+
(!afterOutput || canContinue()) &&
|
|
955
996
|
(!vetoed() || mixed(draft.sessionID)) &&
|
|
956
997
|
(!ownership ||
|
|
957
998
|
latestTransportOwned.get(draft.sessionID) === true);
|
|
@@ -964,6 +1005,9 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
964
1005
|
error: draft.error,
|
|
965
1006
|
attempt: draft.attempt,
|
|
966
1007
|
...(rec.limit ? { limit: rec.limit.signal } : {}),
|
|
1008
|
+
...(afterOutput
|
|
1009
|
+
? { continuation: 'interrupted-read' }
|
|
1010
|
+
: {}),
|
|
967
1011
|
};
|
|
968
1012
|
let result;
|
|
969
1013
|
try {
|
|
@@ -979,7 +1023,11 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
979
1023
|
checkRetryActive();
|
|
980
1024
|
return false;
|
|
981
1025
|
}
|
|
982
|
-
const sameAccount = {
|
|
1026
|
+
const sameAccount = {
|
|
1027
|
+
accountId: result.accountId,
|
|
1028
|
+
input,
|
|
1029
|
+
...(afterOutput ? { continuation: true } : {}),
|
|
1030
|
+
};
|
|
983
1031
|
try {
|
|
984
1032
|
checkRetryActive();
|
|
985
1033
|
}
|
|
@@ -1017,7 +1065,9 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
1017
1065
|
sameAccount,
|
|
1018
1066
|
});
|
|
1019
1067
|
rec.judged = true;
|
|
1020
|
-
draft.decision =
|
|
1068
|
+
draft.decision = afterOutput
|
|
1069
|
+
? hostDecision
|
|
1070
|
+
: { retry: true, delay: 0 };
|
|
1021
1071
|
return true;
|
|
1022
1072
|
});
|
|
1023
1073
|
checkRetryActive();
|
|
@@ -1027,7 +1077,7 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
1027
1077
|
accountId: rec.accountId,
|
|
1028
1078
|
kind: rec.scope.kind,
|
|
1029
1079
|
attempt: draft.attempt,
|
|
1030
|
-
reason: 'same-account',
|
|
1080
|
+
reason: afterOutput ? 'continue-same-account' : 'same-account',
|
|
1031
1081
|
hostDecision,
|
|
1032
1082
|
decision: draft.decision,
|
|
1033
1083
|
handle: rec.attempt,
|
|
@@ -1082,8 +1132,7 @@ export async function installOpenCode2Auth(ctx, adapter, options = {}) {
|
|
|
1082
1132
|
reason = 'no-account';
|
|
1083
1133
|
}
|
|
1084
1134
|
else if (rec.outputStarted) {
|
|
1085
|
-
//
|
|
1086
|
-
// send it again.
|
|
1135
|
+
// Only the guarded same-account path above may continue partial output.
|
|
1087
1136
|
decision = { retry: false };
|
|
1088
1137
|
reason = 'output-started';
|
|
1089
1138
|
}
|
|
@@ -221,6 +221,14 @@ export interface SameAccountRetryInput extends AccountRequest {
|
|
|
221
221
|
* limitFromError is not called before this callback in a mixed session.
|
|
222
222
|
*/
|
|
223
223
|
readonly limit?: LimitSignal;
|
|
224
|
+
/**
|
|
225
|
+
* Set only when output had already started and our own HTTP body reader saw
|
|
226
|
+
* the read fail, so the host is offering to continue the step rather than
|
|
227
|
+
* retry it. The adapter approves by returning the same accountId when the
|
|
228
|
+
* account and identity are still usable; it has no prepared recovery state
|
|
229
|
+
* to consume, and `limit` is always absent here.
|
|
230
|
+
*/
|
|
231
|
+
readonly continuation?: 'interrupted-read';
|
|
224
232
|
}
|
|
225
233
|
/** Request an immediate retry; a different account ID is ignored. */
|
|
226
234
|
export interface SameAccountRetryResult {
|
|
@@ -437,7 +445,7 @@ export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends C
|
|
|
437
445
|
* A different accountId is ignored. Never move a routing pin or select another
|
|
438
446
|
* account here: use chooseAccount for failover and holds.
|
|
439
447
|
*
|
|
440
|
-
* Runs
|
|
448
|
+
* Runs for an attributable attempt before output, and, when gated, only
|
|
441
449
|
* while the latest transport is owned. Unlike failover and holds, it also runs
|
|
442
450
|
* in mixed-ownership sessions. The next matching owned request skips selection
|
|
443
451
|
* and calls accountHeaders again for this account, so newer credentials or a
|
|
@@ -449,6 +457,12 @@ export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends C
|
|
|
449
457
|
* No choice was committed through chooseAccount; unused recovery state is
|
|
450
458
|
* released through dropSameAccountRetry instead of dropChoice.
|
|
451
459
|
* Errors are logged and treated as declining the retry.
|
|
460
|
+
* After output it also gates a host-approved continuation when the attributed
|
|
461
|
+
* HTTP body reader failed, no limit or veto exists, ownership is unmixed and
|
|
462
|
+
* the host retry budget remains. The host's decision and delay are preserved;
|
|
463
|
+
* the callback must decline if the account is no longer usable or its identity
|
|
464
|
+
* changed. Native WebSocket failures and clean but incomplete streams lack
|
|
465
|
+
* the structured host error fields needed to allow this exception.
|
|
452
466
|
*/
|
|
453
467
|
retrySameAccount?(input: SameAccountRetryInput): Promise<SameAccountRetryResult | undefined> | SameAccountRetryResult | undefined;
|
|
454
468
|
/**
|
|
@@ -526,7 +540,9 @@ export interface InstallOpenCode2AuthOptions {
|
|
|
526
540
|
*
|
|
527
541
|
* - `reroute`: refused for a limit before any output, and `chooseAccount`
|
|
528
542
|
* named another account for the next attempt, so the host retries at once;
|
|
529
|
-
* - `output-started`: output
|
|
543
|
+
* - `output-started`: output reached the user without a safe continuation, so no retry;
|
|
544
|
+
* - `continue-same-account`: a witnessed HTTP read failure after output, with
|
|
545
|
+
* adapter-approved identity preservation; keeps the host's continuation and delay;
|
|
530
546
|
* - `no-account`: the attempt had no account, so no retry;
|
|
531
547
|
* - `host-decides-last-account`: refused for a limit before any output, but
|
|
532
548
|
* no other account can serve the next attempt, so the host's own decision
|
|
@@ -541,7 +557,7 @@ export interface InstallOpenCode2AuthOptions {
|
|
|
541
557
|
* attributed safely (ambiguous attempts or mixed ownership in a gated
|
|
542
558
|
* session), so the host's decision stands.
|
|
543
559
|
*/
|
|
544
|
-
export type RetryReason = 'reroute' | 'hold' | 'wait-then-reselect' | 'adapter-veto' | 'same-account' | 'output-started' | 'no-account' | 'host-decides-last-account' | 'host-decides';
|
|
560
|
+
export type RetryReason = 'reroute' | 'hold' | 'wait-then-reselect' | 'adapter-veto' | 'same-account' | 'continue-same-account' | 'output-started' | 'no-account' | 'host-decides-last-account' | 'host-decides';
|
|
545
561
|
/**
|
|
546
562
|
* The hook that picked an account. Normally `model.request`; a transport hook
|
|
547
563
|
* picks only when the host skipped `model.request` for that request, which a
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional THALAMUS routing for vault mode and advisory turn notes for request
|
|
3
|
+
* shaping. Account ids are vault account ids, not local pool rows. Nothing is
|
|
4
|
+
* persisted here; plugins on routes the runner does not serve get no turn notes.
|
|
5
|
+
*/
|
|
1
6
|
/** An eligible vault route, not a local pool row. */
|
|
2
7
|
export interface RoutingCandidate {
|
|
3
8
|
/** Vault account id, not the plugin's route id. */
|
|
@@ -35,7 +40,7 @@ interface RoutingReportIdentity {
|
|
|
35
40
|
accountId: string;
|
|
36
41
|
credentialId?: string;
|
|
37
42
|
}
|
|
38
|
-
export type ReportRoutingInput = RoutingReportIdentity & ({
|
|
43
|
+
export type ReportRoutingInput = (RoutingReportIdentity & ({
|
|
39
44
|
outcome: 'served';
|
|
40
45
|
/**
|
|
41
46
|
* Pass only rate-limit headers, never the whole response headers.
|
|
@@ -56,7 +61,26 @@ export type ReportRoutingInput = RoutingReportIdentity & ({
|
|
|
56
61
|
pool?: string;
|
|
57
62
|
/** Optional reset time in epoch milliseconds. */
|
|
58
63
|
resetsAt?: number;
|
|
59
|
-
})
|
|
64
|
+
})) | {
|
|
65
|
+
sessionId: string;
|
|
66
|
+
kind: 'turn_notes_supported';
|
|
67
|
+
model: string;
|
|
68
|
+
supported: boolean;
|
|
69
|
+
} | {
|
|
70
|
+
sessionId: string;
|
|
71
|
+
kind: 'turn_note_skipped';
|
|
72
|
+
after_tool_use_id: string;
|
|
73
|
+
reason: 'anchor_missing' | 'before_user_message' | 'unsupported_model' | 'not_oauth';
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Read advisory input for request shaping, in landing order, without persisting
|
|
77
|
+
* it. If no routing handle is available or the runner does not serve the route,
|
|
78
|
+
* returns [].
|
|
79
|
+
*/
|
|
80
|
+
export declare function turnNotes(sessionId: string): readonly {
|
|
81
|
+
afterToolUseId: string;
|
|
82
|
+
text: string;
|
|
83
|
+
}[];
|
|
60
84
|
/**
|
|
61
85
|
* Ask routing for an eligible vault route. Any failure or unfamiliar answer
|
|
62
86
|
* yields undefined so the plugin can keep its own choice. This does not admit
|
|
@@ -64,9 +88,10 @@ export type ReportRoutingInput = RoutingReportIdentity & ({
|
|
|
64
88
|
*/
|
|
65
89
|
export declare function askRouting<Candidate extends RoutingCandidate>(input: AskRoutingInput<Candidate>): Promise<RoutingSelection<Candidate> | undefined>;
|
|
66
90
|
/**
|
|
67
|
-
* Report a vault request without waiting for routing. Only
|
|
68
|
-
* sent, and all accessor failures are ignored. Headers must
|
|
69
|
-
* to rate-limit headers by the caller; values are not filtered
|
|
91
|
+
* Report a vault request or turn-note event without waiting for routing. Only
|
|
92
|
+
* contract fields are sent, and all accessor failures are ignored. Headers must
|
|
93
|
+
* already be limited to rate-limit headers by the caller; values are not filtered
|
|
94
|
+
* or redacted here.
|
|
70
95
|
*/
|
|
71
96
|
export declare function reportRouting(input: ReportRoutingInput): void;
|
|
72
97
|
export {};
|