@cortexkit/opencode-openai-auth 1.19.1 → 1.20.0
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/bin.js +8 -8
- package/dist/{codex-request-Bj3F3fFg.d.ts → codex-request-Dvj28zFK.d.ts} +9 -2
- package/dist/{index-3wr1ebxp.js → index-0jknjejt.js} +1 -1
- package/dist/index-2dxas810.js +64 -0
- package/dist/index-3898z307.js +101 -0
- package/dist/{index-hsrx1pkq.js → index-74mg470w.js} +1 -1
- package/dist/{index-nrkvrvpw.js → index-7tkppvqd.js} +1 -1
- package/dist/index-asjkhkty.js +2 -0
- package/dist/index-d5er9yht.js +75 -0
- package/dist/{index-kgzevj7y.js → index-pdsqgqng.js} +1 -1
- package/dist/{index-977gx5br.js → index-wy84wezx.js} +1 -1
- package/dist/{index-1ttg64ny.js → index-xbh03w1v.js} +1 -1
- package/dist/{index-mbxq1g4n.js → index-z1hz7e5y.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +3 -3
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +31 -14
- package/src/tui-compiled/raw/shared/375d9cca2def037d-private-files.js +8 -3
- package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +34 -13
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +31 -14
- package/src/tui-compiled/runtime/shared/375d9cca2def037d-private-files.js +8 -3
- package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +34 -13
- package/dist/index-34r6y4jf.js +0 -64
- package/dist/index-8km6f9bq.js +0 -2
- package/dist/index-ckkhe4r4.js +0 -76
- package/dist/index-jk0zyyny.js +0 -101
|
@@ -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 {
|
|
@@ -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 "./7211cfec06a298bc-atomic-write.js";
|
|
3
|
-
import { readPrivateText, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
3
|
+
import { isWindowsSharingViolation, readPrivateText, windowsPrivateFiles, } from "./375d9cca2def037d-private-files.js";
|
|
4
4
|
import { LockContentionError, LockOwnershipError } from "./4825e03209d6ae3e-with-lock.js";
|
|
5
5
|
import { PoolOperationError, } from "./04a6357627de5ed0-errors.js";
|
|
6
6
|
import { callFailureHook } from "./9deae3c4da4fd63b-hooks.js";
|
|
@@ -8,14 +8,25 @@ import { LockStack, } from "./43fc9e6b994519c7-refresh-lock.js";
|
|
|
8
8
|
import { assertNotReserved } from "./08eef45626a94992-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 "./cd94316a888b0a8e-schema.js";
|
|
10
10
|
import { completeTornRows, loadRows } from "./fd45e82f2f9c0a0d-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));
|
|
@@ -145,22 +145,38 @@ function credentialTypeOf(row, family) {
|
|
|
145
145
|
}
|
|
146
146
|
return { kind: 'refused', code: 'unclassified' };
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
const type = row.credentialType;
|
|
149
|
+
if (type === 'oauth') {
|
|
150
|
+
if (row.refreshAdapter !== family.refreshAdapter)
|
|
151
|
+
return notMine;
|
|
152
|
+
}
|
|
153
|
+
else if (type === 'api_key') {
|
|
154
|
+
if (!family.apiKeys || row.refreshAdapter !== undefined)
|
|
155
|
+
return notMine;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
149
158
|
return notMine;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
}
|
|
160
|
+
const { authMethod } = rowFactsOf(row, { includeProviderIds: false });
|
|
161
|
+
// Older vaults omit the method. If present, it must match the serving type.
|
|
162
|
+
if (authMethod !== undefined) {
|
|
163
|
+
const matchesType = type === 'oauth'
|
|
164
|
+
? authMethod === 'chatgpt' ||
|
|
165
|
+
authMethod === 'antigravity' ||
|
|
166
|
+
authMethod === 'oauth'
|
|
167
|
+
: authMethod === 'apikey';
|
|
168
|
+
if (!matchesType)
|
|
169
|
+
return { kind: 'refused', code: 'unknown-auth-method' };
|
|
170
|
+
}
|
|
171
|
+
return { kind: 'mine', type };
|
|
159
172
|
}
|
|
160
173
|
/** Structural access keeps the public facts independent of client declarations. */
|
|
161
|
-
function rowFactsOf(row) {
|
|
174
|
+
function rowFactsOf(row, { includeProviderIds = true } = {}) {
|
|
162
175
|
const metadata = row;
|
|
163
|
-
return {
|
|
176
|
+
return {
|
|
177
|
+
providerIds: includeProviderIds ? metadata.providerIds : undefined,
|
|
178
|
+
authMethod: metadata.authMethod,
|
|
179
|
+
};
|
|
164
180
|
}
|
|
165
181
|
/**
|
|
166
182
|
* The grants named in the vault's list reply, or undefined when it names none.
|
|
@@ -513,14 +529,15 @@ export class ClaustrumScopedCustody {
|
|
|
513
529
|
for (const record of skipped)
|
|
514
530
|
this.#logger.warn('skipped malformed vault record', record);
|
|
515
531
|
const grantReach = grantReachOf(inventory);
|
|
532
|
+
const classifying = 'classify' in this.#family;
|
|
516
533
|
return {
|
|
517
534
|
view: inventory.view,
|
|
518
535
|
credentials: Object.freeze(credentials),
|
|
519
536
|
skipped: Object.freeze(skipped),
|
|
520
|
-
...(
|
|
537
|
+
...((classifying || refused.length > 0) && {
|
|
521
538
|
refused: Object.freeze(refused),
|
|
522
|
-
notMine,
|
|
523
539
|
}),
|
|
540
|
+
...(classifying && { notMine }),
|
|
524
541
|
...(grantReach && { grantReach }),
|
|
525
542
|
};
|
|
526
543
|
}
|
|
@@ -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 {
|
|
@@ -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 "./7211cfec06a298bc-atomic-write.js";
|
|
3
|
-
import { readPrivateText, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
3
|
+
import { isWindowsSharingViolation, readPrivateText, windowsPrivateFiles, } from "./375d9cca2def037d-private-files.js";
|
|
4
4
|
import { LockContentionError, LockOwnershipError } from "./4825e03209d6ae3e-with-lock.js";
|
|
5
5
|
import { PoolOperationError, } from "./04a6357627de5ed0-errors.js";
|
|
6
6
|
import { callFailureHook } from "./9deae3c4da4fd63b-hooks.js";
|
|
@@ -8,14 +8,25 @@ import { LockStack, } from "./43fc9e6b994519c7-refresh-lock.js";
|
|
|
8
8
|
import { assertNotReserved } from "./08eef45626a94992-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 "./cd94316a888b0a8e-schema.js";
|
|
10
10
|
import { completeTornRows, loadRows } from "./fd45e82f2f9c0a0d-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));
|