@cortexkit/opencode-openai-auth 1.21.1 → 1.23.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.
Files changed (54) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/index-2z4dbnsf.js +60 -0
  3. package/dist/{index-fgt2dy20.js → index-7hcv94as.js} +1 -1
  4. package/dist/{index-hxp3dm9e.js → index-897br01q.js} +2 -2
  5. package/dist/{index-7v9tyyrn.js → index-bbrpg1ms.js} +2 -2
  6. package/dist/index-bpx4spyr.js +1 -0
  7. package/dist/{index-wwp78jx3.js → index-d0g5g290.js} +1 -1
  8. package/dist/index-f340dq90.js +101 -0
  9. package/dist/{index-0cpz8t4q.js → index-fasy4end.js} +2 -2
  10. package/dist/{index-vqy1mwn3.js → index-j700j6at.js} +1 -1
  11. package/dist/index-q2czrasr.js +2 -0
  12. package/dist/{index-0hk39zee.js → index-r31f36mn.js} +2 -2
  13. package/dist/index-s7dwe5n8.js +79 -0
  14. package/dist/{index-ecqb42ev.js → index-sx9jjkry.js} +2 -2
  15. package/dist/{index-r891a915.js → index-x25m9spd.js} +2 -2
  16. package/dist/index.d.ts +4 -24
  17. package/dist/index.js +1 -1
  18. package/dist/map-D5PHhv4z.d.ts +72 -0
  19. package/dist/openai-auth.schema.json +274 -27
  20. package/dist/rpc/port-file.js +1 -1
  21. package/dist/rpc/protocol.js +1 -1
  22. package/dist/rpc/rpc-client.js +1 -1
  23. package/dist/rpc/rpc-dir.js +1 -1
  24. package/dist/{codex-request-WGAY0gn4.d.ts → runtime-layout-B07ApQZL.d.ts} +665 -645
  25. package/dist/{sidebar-state-CrRiE9hw.d.ts → sidebar-state--OTpRzFd.d.ts} +2 -72
  26. package/dist/sidebar-state.d.ts +1 -1
  27. package/dist/sidebar-state.js +1 -1
  28. package/dist/{token-8afntt1a.js → token-hczqrmmz.js} +1 -1
  29. package/dist/token-util-9t4ma4jz.js +1 -0
  30. package/dist/tui-preferences.js +1 -1
  31. package/dist/tui.d.ts +1 -1
  32. package/dist/v2/server.d.ts +16 -8
  33. package/dist/v2/server.js +4 -4
  34. package/package.json +2 -2
  35. package/src/tui-compiled/raw/logger.js +5 -22
  36. package/src/tui-compiled/raw/shared/58bc35a3cd459085-define.js +10 -1
  37. package/src/tui-compiled/raw/shared/87f6e22d4fc34918-resolve.js +10 -5
  38. package/src/tui-compiled/raw/shared/bfbdd0f9aae56b47-pool-quota.js +10 -0
  39. package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +30 -1
  40. package/src/tui-compiled/raw/shared/dbc61cd405941828-accounts.js +1 -1
  41. package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +8 -3
  42. package/src/tui-compiled/runtime/logger.js +5 -22
  43. package/src/tui-compiled/runtime/shared/58bc35a3cd459085-define.js +10 -1
  44. package/src/tui-compiled/runtime/shared/87f6e22d4fc34918-resolve.js +10 -5
  45. package/src/tui-compiled/runtime/shared/bfbdd0f9aae56b47-pool-quota.js +10 -0
  46. package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +30 -1
  47. package/src/tui-compiled/runtime/shared/dbc61cd405941828-accounts.js +1 -1
  48. package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +8 -3
  49. package/dist/index-0cht4a77.js +0 -64
  50. package/dist/index-dmdmb1pp.js +0 -1
  51. package/dist/index-j28pt8dy.js +0 -2
  52. package/dist/index-jq1efs0q.js +0 -101
  53. package/dist/index-s1tk4br4.js +0 -75
  54. package/dist/token-util-htrre2k8.js +0 -1
@@ -1,11 +1,11 @@
1
1
  import { tmpdir } from "node:os";
2
2
  import { join } from "node:path";
3
3
  import {
4
- flushLogs,
5
- initLogger,
6
- setLogLevel
4
+ parseLogLevel,
5
+ setupLogger
7
6
  } from "./shared/3c2d4169d00f907e-tui-support.js";
8
7
  export {
8
+ applySettingsLogLevel,
9
9
  createLogger,
10
10
  flushForTest,
11
11
  flushLogs,
@@ -13,27 +13,10 @@ export {
13
13
  redactStrings,
14
14
  setLogLevel
15
15
  } from "./shared/3c2d4169d00f907e-tui-support.js";
16
- const LEVELS = ["error", "warn", "info", "debug", "trace"];
17
16
  export function getLogFile() {
18
17
  return process.env.OPENCODE_OPENAI_AUTH_LOG_FILE ?? (process.platform === "win32" ? join(tmpdir(), "opencode-openai-auth", "opencode-openai-auth.log") : join(tmpdir(), "opencode-openai-auth.log"));
19
18
  }
20
19
  export function getEnvLogLevel() {
21
- const env = process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL;
22
- return env && LEVELS.includes(env) ? env : void 0;
23
- }
24
- export function applySettingsLogLevel(level, phase) {
25
- if (level !== "default")
26
- setLogLevel(level);
27
- else if (phase === "refresh")
28
- setLogLevel(void 0);
20
+ return parseLogLevel(process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL);
29
21
  }
30
- initLogger({ file: getLogFile, level: getEnvLogLevel });
31
- process.once("beforeExit", async () => {
32
- try {
33
- await flushLogs();
34
- } catch {
35
- process.emitWarning("OpenAI auth could not flush its log file at shutdown");
36
- }
37
- });
38
- if (process.platform !== "win32")
39
- process.on("exit", () => flushLogs());
22
+ setupLogger({ file: getLogFile, level: getEnvLogLevel });
@@ -10,11 +10,20 @@ export function defineSettings(definition) {
10
10
  if (name === 'sidebar' && declaration.value.kind !== 'object') {
11
11
  throw new TypeError('The sidebar setting must use an object descriptor');
12
12
  }
13
- if (declaration.overrides !== undefined &&
13
+ const { overrides } = declaration;
14
+ if (overrides !== undefined &&
14
15
  (declaration.value.kind === 'object' ||
15
16
  declaration.value.kind === 'record')) {
16
17
  throw new TypeError(`Object and record settings cannot use overrides: ${name}`);
17
18
  }
19
+ if (overrides?.isolatedHosts !== undefined &&
20
+ (overrides.host !== true ||
21
+ overrides.model === true ||
22
+ !Array.isArray(overrides.isolatedHosts) ||
23
+ overrides.isolatedHosts.length === 0 ||
24
+ !Array.from(overrides.isolatedHosts).every((host) => typeof host === 'string'))) {
25
+ throw new TypeError(`isolatedHosts must be a non-empty array of host names and requires host overrides without model overrides: ${name}`);
26
+ }
18
27
  if (!Object.hasOwn(declaration, 'default') ||
19
28
  !validateValue(declaration.value, declaration.default, {
20
29
  completeObjects: true,
@@ -4,10 +4,13 @@ function valueAtLevel(declaration, name, snapshot, options) {
4
4
  if (!snapshot || !Object.hasOwn(snapshot.settings, name))
5
5
  return undefined;
6
6
  const value = snapshot.settings[name];
7
- if (declaration.overrides === undefined || !isJsonObject(value))
8
- return value;
7
+ const { overrides } = declaration;
9
8
  const { model, host } = options;
10
- if (declaration.overrides.model &&
9
+ const isolated = overrides?.isolatedHosts?.includes(host);
10
+ if (overrides === undefined || !isJsonObject(value)) {
11
+ return isolated ? undefined : value;
12
+ }
13
+ if (overrides.model &&
11
14
  model !== undefined &&
12
15
  model !== 'default' &&
13
16
  model !== 'opencode' &&
@@ -15,12 +18,14 @@ function valueAtLevel(declaration, name, snapshot, options) {
15
18
  Object.hasOwn(value, model)) {
16
19
  return value[model];
17
20
  }
18
- if (declaration.overrides.host &&
21
+ if (overrides.host &&
19
22
  (host === 'opencode' || host === 'pi') &&
20
23
  Object.hasOwn(value, host)) {
21
24
  return value[host];
22
25
  }
23
- return Object.hasOwn(value, 'default') ? value.default : undefined;
26
+ return !isolated && Object.hasOwn(value, 'default')
27
+ ? value.default
28
+ : undefined;
24
29
  }
25
30
  /** Snapshot validation has already removed unusable values and unknown fields. */
26
31
  function resolveValue(descriptor, levels) {
@@ -9,6 +9,16 @@ function isRecord(value) {
9
9
  function finite(value) {
10
10
  return typeof value === "number" && Number.isFinite(value);
11
11
  }
12
+ export function resetCreditsOfQuota(quota) {
13
+ const counters = isRecord(quota) ? quota.counters : void 0, resetCredits = isRecord(counters) ? counters.resetCredits : void 0, credits = isRecord(resetCredits) ? resetCredits.value : void 0;
14
+ return finite(credits) ? credits : void 0;
15
+ }
16
+ export function quotaReadAt(row) {
17
+ if (!isQuotaMap(row.quota))
18
+ return;
19
+ const projection = projectQuota(row.quota);
20
+ return projection.limits.some((limit) => limit.kind === "reading") ? projection.checkedAt : void 0;
21
+ }
12
22
  function readingFor(label, window) {
13
23
  if (!isRecord(window))
14
24
  return;
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  initLogger as commonInitLogger,
3
- createRedactor
3
+ createRedactor,
4
+ flushLogs,
5
+ setLogLevel
4
6
  } from "./cc9e0702a752cea7-index.js";
5
7
  export {
6
8
  createLogger,
@@ -17,3 +19,30 @@ export const { redact, redactStrings } = openaiRedactor;
17
19
  export function initLogger(options) {
18
20
  commonInitLogger({ ...options, extraSecretKeys: isOpenaiIdentityKey });
19
21
  }
22
+ const LEVELS = ["error", "warn", "info", "debug", "trace"];
23
+ export function parseLogLevel(value) {
24
+ const level = value;
25
+ return level && LEVELS.includes(level) ? level : void 0;
26
+ }
27
+ export function applySettingsLogLevel(level, phase) {
28
+ if (level !== "default")
29
+ setLogLevel(level);
30
+ else if (phase === "refresh")
31
+ setLogLevel(void 0);
32
+ }
33
+ let shutdownHookInstalled = !1;
34
+ export function setupLogger(options) {
35
+ initLogger(options);
36
+ if (shutdownHookInstalled)
37
+ return;
38
+ shutdownHookInstalled = !0;
39
+ process.once("beforeExit", async () => {
40
+ try {
41
+ await flushLogs();
42
+ } catch {
43
+ process.emitWarning("OpenAI auth could not flush its log file at shutdown");
44
+ }
45
+ });
46
+ if (process.platform !== "win32")
47
+ process.on("exit", () => flushLogs());
48
+ }
@@ -215,7 +215,7 @@ export function normalizeAccount(value) {
215
215
  quota: normalizeQuota(value.quota)
216
216
  };
217
217
  }
218
- function normalizeResetState(value) {
218
+ export function normalizeResetState(value) {
219
219
  if (!isRecord(value))
220
220
  return;
221
221
  const normalized = Object.create(null);
@@ -229,14 +229,15 @@ export function validateAttribution(operation, id, fence) {
229
229
  throw refusal(operation, id, 'invalid-input', 'the attribution must name a credential epoch that is a positive safe integer');
230
230
  }
231
231
  /** Exact recorded identity, including absence, is part of a credential fence. */
232
- export function assertRowAttribution(operation, id, row, fence) {
232
+ export function assertRowAttribution(operation, id, row, fence, expect) {
233
233
  if (!row)
234
234
  throw unknownRow(operation, id);
235
235
  // A row that failed validation has no usable credential epoch to compare.
236
236
  if (row.invalid)
237
237
  throw refusal(operation, id, 'invalid-row', `row ${id} failed validation`);
238
238
  if ((row.credentialEpoch ?? 1) !== fence.credentialEpoch ||
239
- row.identity !== fence.identity)
239
+ row.identity !== fence.identity ||
240
+ (expect?.credential === 'absent' && row.credential !== undefined))
240
241
  throw refusal(operation, id, 'attribution', `the ${operation} of ${id} was issued for a credential or account the row no longer holds`, true);
241
242
  }
242
243
  /** The row is recorded for another account than the one given. */
@@ -685,6 +686,10 @@ export async function replaceRow(rt, id, credential, input = {}, options = {}) {
685
686
  const result = await runOperation(ctx, 'replace', id, options.onFailure, async (locks, progress) => {
686
687
  checkInput('replace', id, credential);
687
688
  validateAttribution('replace', id, options.attribution);
689
+ const expected = options.attribution?.expect;
690
+ if (expected !== undefined &&
691
+ (!isRecord(expected) || expected.credential !== 'absent'))
692
+ throw refusal('replace', id, 'invalid-input', "the attribution's credential expectation must be 'absent'");
688
693
  const incoming = input.providerState === undefined
689
694
  ? undefined
690
695
  : acceptProviderState(ctx.providerState, 'replace', id, input.providerState);
@@ -701,7 +706,7 @@ export async function replaceRow(rt, id, credential, input = {}, options = {}) {
701
706
  // the fence with that row before finishing the interrupted write
702
707
  // on disk, so a stale caller does not even complete a replacement
703
708
  // it was never issued for.
704
- assertRowAttribution('replace', id, tx.row(id), options.attribution);
709
+ assertRowAttribution('replace', id, tx.row(id), options.attribution, expected);
705
710
  await tx.completeTorn();
706
711
  }
707
712
  const row = requireUsableRow('replace', id, tx.row(id), credential);
@@ -1,11 +1,11 @@
1
1
  import { tmpdir } from "node:os";
2
2
  import { join } from "node:path";
3
3
  import {
4
- flushLogs,
5
- initLogger,
6
- setLogLevel
4
+ parseLogLevel,
5
+ setupLogger
7
6
  } from "./shared/3c2d4169d00f907e-tui-support.js";
8
7
  export {
8
+ applySettingsLogLevel,
9
9
  createLogger,
10
10
  flushForTest,
11
11
  flushLogs,
@@ -13,27 +13,10 @@ export {
13
13
  redactStrings,
14
14
  setLogLevel
15
15
  } from "./shared/3c2d4169d00f907e-tui-support.js";
16
- const LEVELS = ["error", "warn", "info", "debug", "trace"];
17
16
  export function getLogFile() {
18
17
  return process.env.OPENCODE_OPENAI_AUTH_LOG_FILE ?? (process.platform === "win32" ? join(tmpdir(), "opencode-openai-auth", "opencode-openai-auth.log") : join(tmpdir(), "opencode-openai-auth.log"));
19
18
  }
20
19
  export function getEnvLogLevel() {
21
- const env = process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL;
22
- return env && LEVELS.includes(env) ? env : void 0;
23
- }
24
- export function applySettingsLogLevel(level, phase) {
25
- if (level !== "default")
26
- setLogLevel(level);
27
- else if (phase === "refresh")
28
- setLogLevel(void 0);
20
+ return parseLogLevel(process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL);
29
21
  }
30
- initLogger({ file: getLogFile, level: getEnvLogLevel });
31
- process.once("beforeExit", async () => {
32
- try {
33
- await flushLogs();
34
- } catch {
35
- process.emitWarning("OpenAI auth could not flush its log file at shutdown");
36
- }
37
- });
38
- if (process.platform !== "win32")
39
- process.on("exit", () => flushLogs());
22
+ setupLogger({ file: getLogFile, level: getEnvLogLevel });
@@ -10,11 +10,20 @@ export function defineSettings(definition) {
10
10
  if (name === 'sidebar' && declaration.value.kind !== 'object') {
11
11
  throw new TypeError('The sidebar setting must use an object descriptor');
12
12
  }
13
- if (declaration.overrides !== undefined &&
13
+ const { overrides } = declaration;
14
+ if (overrides !== undefined &&
14
15
  (declaration.value.kind === 'object' ||
15
16
  declaration.value.kind === 'record')) {
16
17
  throw new TypeError(`Object and record settings cannot use overrides: ${name}`);
17
18
  }
19
+ if (overrides?.isolatedHosts !== undefined &&
20
+ (overrides.host !== true ||
21
+ overrides.model === true ||
22
+ !Array.isArray(overrides.isolatedHosts) ||
23
+ overrides.isolatedHosts.length === 0 ||
24
+ !Array.from(overrides.isolatedHosts).every((host) => typeof host === 'string'))) {
25
+ throw new TypeError(`isolatedHosts must be a non-empty array of host names and requires host overrides without model overrides: ${name}`);
26
+ }
18
27
  if (!Object.hasOwn(declaration, 'default') ||
19
28
  !validateValue(declaration.value, declaration.default, {
20
29
  completeObjects: true,
@@ -4,10 +4,13 @@ function valueAtLevel(declaration, name, snapshot, options) {
4
4
  if (!snapshot || !Object.hasOwn(snapshot.settings, name))
5
5
  return undefined;
6
6
  const value = snapshot.settings[name];
7
- if (declaration.overrides === undefined || !isJsonObject(value))
8
- return value;
7
+ const { overrides } = declaration;
9
8
  const { model, host } = options;
10
- if (declaration.overrides.model &&
9
+ const isolated = overrides?.isolatedHosts?.includes(host);
10
+ if (overrides === undefined || !isJsonObject(value)) {
11
+ return isolated ? undefined : value;
12
+ }
13
+ if (overrides.model &&
11
14
  model !== undefined &&
12
15
  model !== 'default' &&
13
16
  model !== 'opencode' &&
@@ -15,12 +18,14 @@ function valueAtLevel(declaration, name, snapshot, options) {
15
18
  Object.hasOwn(value, model)) {
16
19
  return value[model];
17
20
  }
18
- if (declaration.overrides.host &&
21
+ if (overrides.host &&
19
22
  (host === 'opencode' || host === 'pi') &&
20
23
  Object.hasOwn(value, host)) {
21
24
  return value[host];
22
25
  }
23
- return Object.hasOwn(value, 'default') ? value.default : undefined;
26
+ return !isolated && Object.hasOwn(value, 'default')
27
+ ? value.default
28
+ : undefined;
24
29
  }
25
30
  /** Snapshot validation has already removed unusable values and unknown fields. */
26
31
  function resolveValue(descriptor, levels) {
@@ -9,6 +9,16 @@ function isRecord(value) {
9
9
  function finite(value) {
10
10
  return typeof value === "number" && Number.isFinite(value);
11
11
  }
12
+ export function resetCreditsOfQuota(quota) {
13
+ const counters = isRecord(quota) ? quota.counters : void 0, resetCredits = isRecord(counters) ? counters.resetCredits : void 0, credits = isRecord(resetCredits) ? resetCredits.value : void 0;
14
+ return finite(credits) ? credits : void 0;
15
+ }
16
+ export function quotaReadAt(row) {
17
+ if (!isQuotaMap(row.quota))
18
+ return;
19
+ const projection = projectQuota(row.quota);
20
+ return projection.limits.some((limit) => limit.kind === "reading") ? projection.checkedAt : void 0;
21
+ }
12
22
  function readingFor(label, window) {
13
23
  if (!isRecord(window))
14
24
  return;
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  initLogger as commonInitLogger,
3
- createRedactor
3
+ createRedactor,
4
+ flushLogs,
5
+ setLogLevel
4
6
  } from "./cc9e0702a752cea7-index.js";
5
7
  export {
6
8
  createLogger,
@@ -17,3 +19,30 @@ export const { redact, redactStrings } = openaiRedactor;
17
19
  export function initLogger(options) {
18
20
  commonInitLogger({ ...options, extraSecretKeys: isOpenaiIdentityKey });
19
21
  }
22
+ const LEVELS = ["error", "warn", "info", "debug", "trace"];
23
+ export function parseLogLevel(value) {
24
+ const level = value;
25
+ return level && LEVELS.includes(level) ? level : void 0;
26
+ }
27
+ export function applySettingsLogLevel(level, phase) {
28
+ if (level !== "default")
29
+ setLogLevel(level);
30
+ else if (phase === "refresh")
31
+ setLogLevel(void 0);
32
+ }
33
+ let shutdownHookInstalled = !1;
34
+ export function setupLogger(options) {
35
+ initLogger(options);
36
+ if (shutdownHookInstalled)
37
+ return;
38
+ shutdownHookInstalled = !0;
39
+ process.once("beforeExit", async () => {
40
+ try {
41
+ await flushLogs();
42
+ } catch {
43
+ process.emitWarning("OpenAI auth could not flush its log file at shutdown");
44
+ }
45
+ });
46
+ if (process.platform !== "win32")
47
+ process.on("exit", () => flushLogs());
48
+ }
@@ -215,7 +215,7 @@ export function normalizeAccount(value) {
215
215
  quota: normalizeQuota(value.quota)
216
216
  };
217
217
  }
218
- function normalizeResetState(value) {
218
+ export function normalizeResetState(value) {
219
219
  if (!isRecord(value))
220
220
  return;
221
221
  const normalized = Object.create(null);
@@ -229,14 +229,15 @@ export function validateAttribution(operation, id, fence) {
229
229
  throw refusal(operation, id, 'invalid-input', 'the attribution must name a credential epoch that is a positive safe integer');
230
230
  }
231
231
  /** Exact recorded identity, including absence, is part of a credential fence. */
232
- export function assertRowAttribution(operation, id, row, fence) {
232
+ export function assertRowAttribution(operation, id, row, fence, expect) {
233
233
  if (!row)
234
234
  throw unknownRow(operation, id);
235
235
  // A row that failed validation has no usable credential epoch to compare.
236
236
  if (row.invalid)
237
237
  throw refusal(operation, id, 'invalid-row', `row ${id} failed validation`);
238
238
  if ((row.credentialEpoch ?? 1) !== fence.credentialEpoch ||
239
- row.identity !== fence.identity)
239
+ row.identity !== fence.identity ||
240
+ (expect?.credential === 'absent' && row.credential !== undefined))
240
241
  throw refusal(operation, id, 'attribution', `the ${operation} of ${id} was issued for a credential or account the row no longer holds`, true);
241
242
  }
242
243
  /** The row is recorded for another account than the one given. */
@@ -685,6 +686,10 @@ export async function replaceRow(rt, id, credential, input = {}, options = {}) {
685
686
  const result = await runOperation(ctx, 'replace', id, options.onFailure, async (locks, progress) => {
686
687
  checkInput('replace', id, credential);
687
688
  validateAttribution('replace', id, options.attribution);
689
+ const expected = options.attribution?.expect;
690
+ if (expected !== undefined &&
691
+ (!isRecord(expected) || expected.credential !== 'absent'))
692
+ throw refusal('replace', id, 'invalid-input', "the attribution's credential expectation must be 'absent'");
688
693
  const incoming = input.providerState === undefined
689
694
  ? undefined
690
695
  : acceptProviderState(ctx.providerState, 'replace', id, input.providerState);
@@ -701,7 +706,7 @@ export async function replaceRow(rt, id, credential, input = {}, options = {}) {
701
706
  // the fence with that row before finishing the interrupted write
702
707
  // on disk, so a stale caller does not even complete a replacement
703
708
  // it was never issued for.
704
- assertRowAttribution('replace', id, tx.row(id), options.attribution);
709
+ assertRowAttribution('replace', id, tx.row(id), options.attribution, expected);
705
710
  await tx.completeTorn();
706
711
  }
707
712
  const row = requireUsableRow('replace', id, tx.row(id), credential);