@namzu/sdk 58.1.1 → 60.0.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/CHANGELOG.md +124 -0
- package/dist/account/binding.d.ts +20 -0
- package/dist/account/binding.d.ts.map +1 -0
- package/dist/account/binding.js +27 -0
- package/dist/account/binding.js.map +1 -0
- package/dist/account/index.d.ts +9 -0
- package/dist/account/index.d.ts.map +1 -0
- package/dist/account/index.js +5 -0
- package/dist/account/index.js.map +1 -0
- package/dist/account/lock.d.ts +33 -0
- package/dist/account/lock.d.ts.map +1 -0
- package/dist/account/lock.js +170 -0
- package/dist/account/lock.js.map +1 -0
- package/dist/account/registry.d.ts +21 -0
- package/dist/account/registry.d.ts.map +1 -0
- package/dist/account/registry.js +340 -0
- package/dist/account/registry.js.map +1 -0
- package/dist/account/types.d.ts +124 -0
- package/dist/account/types.d.ts.map +1 -0
- package/dist/account/types.js +35 -0
- package/dist/account/types.js.map +1 -0
- package/dist/compaction/context-window.d.ts +53 -0
- package/dist/compaction/context-window.d.ts.map +1 -1
- package/dist/compaction/context-window.js +141 -2
- package/dist/compaction/context-window.js.map +1 -1
- package/dist/execution/workflow/index.d.ts +3 -1
- package/dist/execution/workflow/index.d.ts.map +1 -1
- package/dist/execution/workflow/index.js +2 -1
- package/dist/execution/workflow/index.js.map +1 -1
- package/dist/execution/workflow/journal.d.ts +24 -4
- package/dist/execution/workflow/journal.d.ts.map +1 -1
- package/dist/execution/workflow/journal.js +131 -9
- package/dist/execution/workflow/journal.js.map +1 -1
- package/dist/execution/workflow/prelude.d.ts +2 -0
- package/dist/execution/workflow/prelude.d.ts.map +1 -1
- package/dist/execution/workflow/prelude.js +49 -8
- package/dist/execution/workflow/prelude.js.map +1 -1
- package/dist/execution/workflow/resume.d.ts +59 -0
- package/dist/execution/workflow/resume.d.ts.map +1 -0
- package/dist/execution/workflow/resume.js +273 -0
- package/dist/execution/workflow/resume.js.map +1 -0
- package/dist/execution/workflow/runtime.d.ts.map +1 -1
- package/dist/execution/workflow/runtime.js +112 -8
- package/dist/execution/workflow/runtime.js.map +1 -1
- package/dist/execution/workflow/types.d.ts +105 -1
- package/dist/execution/workflow/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/pals/communication/ingress-schema.d.ts +38 -38
- package/dist/peers/record.d.ts +98 -0
- package/dist/peers/record.d.ts.map +1 -1
- package/dist/peers/record.js +17 -0
- package/dist/peers/record.js.map +1 -1
- package/dist/peers/registry.d.ts.map +1 -1
- package/dist/peers/registry.js +2 -2
- package/dist/peers/registry.js.map +1 -1
- package/dist/plugin/compat.d.ts +24 -0
- package/dist/plugin/compat.d.ts.map +1 -0
- package/dist/plugin/compat.js +149 -0
- package/dist/plugin/compat.js.map +1 -0
- package/dist/plugin/loader.d.ts +2 -1
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +6 -0
- package/dist/plugin/loader.js.map +1 -1
- package/dist/pricing/index.d.ts.map +1 -1
- package/dist/pricing/index.js +2 -1
- package/dist/pricing/index.js.map +1 -1
- package/dist/process/kill-tree.d.ts +44 -0
- package/dist/process/kill-tree.d.ts.map +1 -1
- package/dist/process/kill-tree.js +102 -4
- package/dist/process/kill-tree.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +9 -1
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +25 -2
- package/dist/provider/errors.js.map +1 -1
- package/dist/provider/model-window-suffix.d.ts +18 -0
- package/dist/provider/model-window-suffix.d.ts.map +1 -0
- package/dist/provider/model-window-suffix.js +77 -0
- package/dist/provider/model-window-suffix.js.map +1 -0
- package/dist/provider/token-budget.d.ts.map +1 -1
- package/dist/provider/token-budget.js +9 -1
- package/dist/provider/token-budget.js.map +1 -1
- package/dist/public-runtime.d.ts +6 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +6 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +3 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts +1 -4
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +0 -28
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/runtime/jobs/awaited-jobs.d.ts +6 -0
- package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
- package/dist/runtime/jobs/awaited-jobs.js +11 -0
- package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
- package/dist/runtime/jobs/host-exit-finalizer.d.ts +20 -0
- package/dist/runtime/jobs/host-exit-finalizer.d.ts.map +1 -0
- package/dist/runtime/jobs/host-exit-finalizer.js +57 -0
- package/dist/runtime/jobs/host-exit-finalizer.js.map +1 -0
- package/dist/runtime/jobs/liveness.d.ts +67 -0
- package/dist/runtime/jobs/liveness.d.ts.map +1 -0
- package/dist/runtime/jobs/liveness.js +94 -0
- package/dist/runtime/jobs/liveness.js.map +1 -0
- package/dist/runtime/jobs/registry.d.ts +21 -0
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +104 -2
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/jobs/wake-budget.d.ts +35 -0
- package/dist/runtime/jobs/wake-budget.d.ts.map +1 -0
- package/dist/runtime/jobs/wake-budget.js +48 -0
- package/dist/runtime/jobs/wake-budget.js.map +1 -0
- package/dist/runtime/query/detached-calls.d.ts +65 -0
- package/dist/runtime/query/detached-calls.d.ts.map +1 -0
- package/dist/runtime/query/detached-calls.js +116 -0
- package/dist/runtime/query/detached-calls.js.map +1 -0
- package/dist/runtime/query/executor.d.ts +11 -3
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +100 -8
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +20 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +31 -5
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.js +11 -3
- package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +7 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +63 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/session-storage.d.ts.map +1 -1
- package/dist/runtime/query/session-storage.js +8 -3
- package/dist/runtime/query/session-storage.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +29 -3
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +58 -3
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +1 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/system-events.d.ts +5 -0
- package/dist/runtime/system-events.d.ts.map +1 -1
- package/dist/runtime/system-events.js +7 -1
- package/dist/runtime/system-events.js.map +1 -1
- package/dist/sandbox/denial.d.ts +11 -0
- package/dist/sandbox/denial.d.ts.map +1 -0
- package/dist/sandbox/denial.js +61 -0
- package/dist/sandbox/denial.js.map +1 -0
- package/dist/sandbox/file-walk-program.d.ts.map +1 -1
- package/dist/sandbox/file-walk-program.js +31 -13
- package/dist/sandbox/file-walk-program.js.map +1 -1
- package/dist/sandbox/file-walk.d.ts +2 -0
- package/dist/sandbox/file-walk.d.ts.map +1 -1
- package/dist/sandbox/file-walk.js +64 -13
- package/dist/sandbox/file-walk.js.map +1 -1
- package/dist/sandbox/ignore-matcher.d.ts +30 -0
- package/dist/sandbox/ignore-matcher.d.ts.map +1 -0
- package/dist/sandbox/ignore-matcher.js +11 -0
- package/dist/sandbox/ignore-matcher.js.map +1 -0
- package/dist/sandbox/ignore-source.d.ts +26 -0
- package/dist/sandbox/ignore-source.d.ts.map +1 -0
- package/dist/sandbox/ignore-source.js +221 -0
- package/dist/sandbox/ignore-source.js.map +1 -0
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +11 -1
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +1 -0
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/session/log-hash.d.ts.map +1 -1
- package/dist/session/log-hash.js +18 -1
- package/dist/session/log-hash.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +169 -16
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +10 -4
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +35 -0
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +512 -67
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/glob.d.ts +1 -0
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +65 -28
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts +2 -0
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +94 -40
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/job.d.ts +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +34 -7
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/search-support.d.ts +44 -0
- package/dist/tools/builtins/search-support.d.ts.map +1 -0
- package/dist/tools/builtins/search-support.js +89 -0
- package/dist/tools/builtins/search-support.js.map +1 -0
- package/dist/tools/builtins/wait-for-job-bounds.d.ts +2 -0
- package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job-bounds.js +3 -1
- package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +13 -2
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +14 -5
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/types/computer-use/index.d.ts +129 -13
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/errors/catalog.d.ts.map +1 -1
- package/dist/types/errors/catalog.js +6 -0
- package/dist/types/errors/catalog.js.map +1 -1
- package/dist/types/plugin/index.d.ts +24 -0
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +4 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/errors.d.ts +7 -0
- package/dist/types/provider/errors.d.ts.map +1 -1
- package/dist/types/provider/errors.js +27 -3
- package/dist/types/provider/errors.js.map +1 -1
- package/dist/types/sandbox/index.d.ts +38 -1
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/records.d.ts +479 -1
- package/dist/types/session/records.d.ts.map +1 -1
- package/dist/types/session/records.js +45 -1
- package/dist/types/session/records.js.map +1 -1
- package/dist/types/tool/index.d.ts +30 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +8 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/account/binding.ts +43 -0
- package/src/account/index.ts +32 -0
- package/src/account/lock.ts +184 -0
- package/src/account/registry.ts +413 -0
- package/src/account/types.ts +137 -0
- package/src/compaction/context-window.ts +163 -2
- package/src/execution/workflow/index.ts +14 -1
- package/src/execution/workflow/journal.ts +161 -11
- package/src/execution/workflow/prelude.ts +51 -8
- package/src/execution/workflow/resume.ts +313 -0
- package/src/execution/workflow/runtime.ts +127 -9
- package/src/execution/workflow/types.ts +109 -1
- package/src/index.ts +17 -0
- package/src/peers/record.ts +18 -0
- package/src/peers/registry.ts +2 -2
- package/src/plugin/compat.ts +173 -0
- package/src/plugin/loader.ts +7 -1
- package/src/pricing/index.ts +2 -1
- package/src/process/kill-tree.ts +106 -4
- package/src/prompt/coding-agent-doctrine.ts +9 -1
- package/src/provider/errors.ts +27 -1
- package/src/provider/model-window-suffix.ts +84 -0
- package/src/provider/token-budget.ts +9 -3
- package/src/public-runtime.ts +38 -2
- package/src/public-types.ts +16 -0
- package/src/registry/command/kernel-commands.ts +1 -32
- package/src/runtime/jobs/awaited-jobs.ts +11 -0
- package/src/runtime/jobs/host-exit-finalizer.ts +67 -0
- package/src/runtime/jobs/liveness.ts +144 -0
- package/src/runtime/jobs/registry.ts +114 -2
- package/src/runtime/jobs/wake-budget.ts +55 -0
- package/src/runtime/query/detached-calls.ts +135 -0
- package/src/runtime/query/executor.ts +102 -12
- package/src/runtime/query/index.ts +50 -7
- package/src/runtime/query/iteration/outstanding-work.ts +12 -3
- package/src/runtime/query/iteration/phases/context.ts +7 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +73 -8
- package/src/runtime/query/session-storage.ts +8 -3
- package/src/runtime/query/steering.ts +77 -6
- package/src/runtime/query/tooling.ts +2 -0
- package/src/runtime/system-events.ts +12 -1
- package/src/sandbox/denial.ts +79 -0
- package/src/sandbox/file-walk-program.ts +32 -13
- package/src/sandbox/file-walk.ts +75 -12
- package/src/sandbox/ignore-matcher.ts +46 -0
- package/src/sandbox/ignore-source.ts +220 -0
- package/src/sandbox/provider/local.ts +11 -1
- package/src/scheduler/completion-inbox.ts +1 -0
- package/src/session/log-hash.ts +21 -0
- package/src/store/session-index/sqlite.ts +171 -16
- package/src/tools/builtins/bash.ts +11 -4
- package/src/tools/builtins/computer-use.ts +593 -68
- package/src/tools/builtins/glob.ts +79 -32
- package/src/tools/builtins/grep.ts +107 -43
- package/src/tools/builtins/job.ts +42 -12
- package/src/tools/builtins/search-support.ts +107 -0
- package/src/tools/builtins/wait-for-job-bounds.ts +5 -1
- package/src/tools/builtins/wait-for-job.ts +14 -2
- package/src/tools/command-shell.ts +13 -5
- package/src/types/computer-use/index.ts +157 -15
- package/src/types/errors/catalog.ts +6 -0
- package/src/types/plugin/index.ts +8 -0
- package/src/types/provider/errors.ts +40 -3
- package/src/types/sandbox/index.ts +40 -1
- package/src/types/session/records.ts +52 -2
- package/src/types/tool/index.ts +30 -0
- package/src/types/tool/presentation.ts +8 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { chmodSync, closeSync, fsyncSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmSync, unlinkSync, writeSync, } from 'node:fs';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { resolveNamzuHome } from '../session/home.js';
|
|
6
|
+
import { withAccountLockSync } from './lock.js';
|
|
7
|
+
import { AccountRegistryError, CredentialWithdrawnError, DEFAULT_ACCOUNT_LABEL, } from './types.js';
|
|
8
|
+
export const ACCOUNTS_FILE_NAME = 'accounts.json';
|
|
9
|
+
export const ACCOUNTS_FILE_VERSION = 1;
|
|
10
|
+
const LABEL = /^[a-z0-9-]{1,32}$/;
|
|
11
|
+
const CODEX_PROVIDER = 'codex';
|
|
12
|
+
const PROVIDER = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
13
|
+
// Unknown keys are kept so a store written by a newer build survives a rewrite by this one.
|
|
14
|
+
const SourceSchema = z.discriminatedUnion('kind', [
|
|
15
|
+
z.object({ kind: z.literal('codex-home'), dir: z.string().min(1) }).passthrough(),
|
|
16
|
+
z.object({ kind: z.literal('api-key'), keyRef: z.string().min(1) }).passthrough(),
|
|
17
|
+
]);
|
|
18
|
+
const AccountSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
id: z.string().min(1),
|
|
21
|
+
provider: z.string().min(1),
|
|
22
|
+
label: z.string().min(1),
|
|
23
|
+
source: SourceSchema,
|
|
24
|
+
createdAt: z.string(),
|
|
25
|
+
display: z.string().optional(),
|
|
26
|
+
baseUrl: z.string().optional(),
|
|
27
|
+
defaultModel: z.string().optional(),
|
|
28
|
+
})
|
|
29
|
+
.passthrough();
|
|
30
|
+
const FileSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
version: z.literal(ACCOUNTS_FILE_VERSION),
|
|
33
|
+
accounts: z.array(AccountSchema),
|
|
34
|
+
keys: z.record(z.string()),
|
|
35
|
+
})
|
|
36
|
+
.passthrough();
|
|
37
|
+
function sleepBlocking() {
|
|
38
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
|
|
39
|
+
}
|
|
40
|
+
export function accountId(provider, label) {
|
|
41
|
+
return `${provider}:${label}`;
|
|
42
|
+
}
|
|
43
|
+
/** Split an id into provider and label, or `undefined` if it is not shaped `<provider>:<label>`. */
|
|
44
|
+
export function parseAccountId(id) {
|
|
45
|
+
const at = id.indexOf(':');
|
|
46
|
+
if (at <= 0 || at === id.length - 1)
|
|
47
|
+
return undefined;
|
|
48
|
+
return { provider: id.slice(0, at), label: id.slice(at + 1) };
|
|
49
|
+
}
|
|
50
|
+
function writeAtomic(path, text) {
|
|
51
|
+
const temporary = join(dirname(path), `.${randomBytes(8).toString('hex')}.accounts.tmp`);
|
|
52
|
+
const fd = openSync(temporary, 'wx', 0o600);
|
|
53
|
+
try {
|
|
54
|
+
writeSync(fd, text);
|
|
55
|
+
fsyncSync(fd);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
closeSync(fd);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
renameSync(temporary, path);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
try {
|
|
65
|
+
unlinkSync(temporary);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// The rename already failed; the leftover temporary is not the failure to report.
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function createAccountRegistry(options = {}) {
|
|
74
|
+
const home = options.home ?? resolveNamzuHome();
|
|
75
|
+
const path = join(home, ACCOUNTS_FILE_NAME);
|
|
76
|
+
const lockPath = `${path}.lock`;
|
|
77
|
+
const accountsRoot = join(home, 'accounts');
|
|
78
|
+
const now = options.now ?? (() => new Date());
|
|
79
|
+
function defaultAccount(provider) {
|
|
80
|
+
return {
|
|
81
|
+
id: accountId(provider, DEFAULT_ACCOUNT_LABEL),
|
|
82
|
+
provider,
|
|
83
|
+
label: DEFAULT_ACCOUNT_LABEL,
|
|
84
|
+
source: { kind: 'existing-default' },
|
|
85
|
+
createdAt: new Date(0).toISOString(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function read() {
|
|
89
|
+
let text;
|
|
90
|
+
try {
|
|
91
|
+
text = readFileSync(path, 'utf8');
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error.code === 'ENOENT') {
|
|
95
|
+
return { version: ACCOUNTS_FILE_VERSION, accounts: [], keys: {} };
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
let json;
|
|
100
|
+
try {
|
|
101
|
+
json = JSON.parse(text);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
throw new AccountRegistryError(`${path} is not valid JSON; no account was changed.`);
|
|
105
|
+
}
|
|
106
|
+
const parsed = FileSchema.safeParse(json);
|
|
107
|
+
if (!parsed.success) {
|
|
108
|
+
throw new AccountRegistryError(`${path} is not a version ${ACCOUNTS_FILE_VERSION} account store.`);
|
|
109
|
+
}
|
|
110
|
+
return parsed.data;
|
|
111
|
+
}
|
|
112
|
+
function mutate(change) {
|
|
113
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
114
|
+
return withAccountLockSync(lockPath, () => {
|
|
115
|
+
const file = read();
|
|
116
|
+
const result = change(file);
|
|
117
|
+
writeAtomic(path, `${JSON.stringify(file, null, 2)}\n`);
|
|
118
|
+
try {
|
|
119
|
+
chmodSync(path, 0o600);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Windows has no POSIX mode; the temporary was already created 0600 where it applies.
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}, { attempts: 80, wait: options.lockWait ?? sleepBlocking });
|
|
126
|
+
}
|
|
127
|
+
function ownDir(source) {
|
|
128
|
+
return String(source.dir);
|
|
129
|
+
}
|
|
130
|
+
function toAccount(stored) {
|
|
131
|
+
return stored;
|
|
132
|
+
}
|
|
133
|
+
function checkLabel(label) {
|
|
134
|
+
if (!LABEL.test(label)) {
|
|
135
|
+
throw new AccountRegistryError('An account label is 1 to 32 characters: lowercase letters, digits and hyphens.');
|
|
136
|
+
}
|
|
137
|
+
if (label === DEFAULT_ACCOUNT_LABEL) {
|
|
138
|
+
throw new AccountRegistryError('The label "default" belongs to the existing sign-in.');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function checkEndpointAndModel(input) {
|
|
142
|
+
if (input.baseUrl !== undefined) {
|
|
143
|
+
let url;
|
|
144
|
+
try {
|
|
145
|
+
url = new URL(input.baseUrl);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
throw new AccountRegistryError('The base URL is not a valid address.');
|
|
149
|
+
}
|
|
150
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
151
|
+
throw new AccountRegistryError('The base URL must start with https:// or http://.');
|
|
152
|
+
}
|
|
153
|
+
if (url.username !== '' || url.password !== '') {
|
|
154
|
+
throw new AccountRegistryError('The base URL must not contain a user name or password.');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (input.defaultModel !== undefined && !/^\S{1,200}$/.test(input.defaultModel)) {
|
|
158
|
+
throw new AccountRegistryError('The default model is one name of up to 200 characters.');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function realOrSelf(target) {
|
|
162
|
+
// Resolve symlinks through the deepest existing ancestor, so a symlinked
|
|
163
|
+
// parent cannot lead outside the accounts folder.
|
|
164
|
+
let existing = resolve(target);
|
|
165
|
+
const rest = [];
|
|
166
|
+
for (;;) {
|
|
167
|
+
try {
|
|
168
|
+
return join(realpathSync(existing), ...rest.reverse());
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
const parent = dirname(existing);
|
|
172
|
+
if (parent === existing)
|
|
173
|
+
return resolve(target);
|
|
174
|
+
rest.push(basename(existing));
|
|
175
|
+
existing = parent;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function insideAccountsRoot(dir) {
|
|
180
|
+
const rel = relative(realOrSelf(accountsRoot), realOrSelf(dir));
|
|
181
|
+
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
|
|
182
|
+
}
|
|
183
|
+
function nests(outer, inner) {
|
|
184
|
+
const rel = relative(realOrSelf(outer), realOrSelf(inner));
|
|
185
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
186
|
+
}
|
|
187
|
+
const registry = {
|
|
188
|
+
list(provider) {
|
|
189
|
+
const stored = read().accounts.map(toAccount);
|
|
190
|
+
const providers = new Set([
|
|
191
|
+
...(options.defaultProviders ?? []),
|
|
192
|
+
...stored.map((a) => a.provider),
|
|
193
|
+
]);
|
|
194
|
+
if (provider !== undefined)
|
|
195
|
+
providers.add(provider);
|
|
196
|
+
const defaults = [...providers]
|
|
197
|
+
.filter((p) => provider === undefined || p === provider)
|
|
198
|
+
.map(defaultAccount);
|
|
199
|
+
return [
|
|
200
|
+
...defaults,
|
|
201
|
+
...stored.filter((a) => provider === undefined || a.provider === provider),
|
|
202
|
+
];
|
|
203
|
+
},
|
|
204
|
+
get(id) {
|
|
205
|
+
const parsed = parseAccountId(id);
|
|
206
|
+
if (!parsed)
|
|
207
|
+
return undefined;
|
|
208
|
+
if (parsed.label === DEFAULT_ACCOUNT_LABEL)
|
|
209
|
+
return defaultAccount(parsed.provider);
|
|
210
|
+
const stored = read().accounts.find((a) => a.id === id);
|
|
211
|
+
return stored ? toAccount(stored) : undefined;
|
|
212
|
+
},
|
|
213
|
+
add(input) {
|
|
214
|
+
if (!PROVIDER.test(input.provider)) {
|
|
215
|
+
throw new AccountRegistryError('The provider name is not valid.');
|
|
216
|
+
}
|
|
217
|
+
checkLabel(input.label);
|
|
218
|
+
const id = accountId(input.provider, input.label);
|
|
219
|
+
return mutate((file) => {
|
|
220
|
+
if (file.accounts.some((a) => a.id === id)) {
|
|
221
|
+
throw new AccountRegistryError(`There is already an account labelled "${input.label}".`);
|
|
222
|
+
}
|
|
223
|
+
let source;
|
|
224
|
+
if (input.kind === 'api-key') {
|
|
225
|
+
if (input.apiKey.length === 0)
|
|
226
|
+
throw new AccountRegistryError('The API key is empty.');
|
|
227
|
+
checkEndpointAndModel(input);
|
|
228
|
+
const keyRef = `key-${randomBytes(9).toString('hex')}`;
|
|
229
|
+
file.keys[keyRef] = input.apiKey;
|
|
230
|
+
source = { kind: 'api-key', keyRef };
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
if (input.provider !== CODEX_PROVIDER) {
|
|
234
|
+
throw new AccountRegistryError('A Codex home account belongs to the codex provider only.');
|
|
235
|
+
}
|
|
236
|
+
const dir = resolve(input.dir ?? join(accountsRoot, 'codex', input.label));
|
|
237
|
+
if (!insideAccountsRoot(dir)) {
|
|
238
|
+
throw new AccountRegistryError('A Codex account directory must live under the Namzu accounts folder.');
|
|
239
|
+
}
|
|
240
|
+
if (file.accounts.some((a) => a.source.kind === 'codex-home' &&
|
|
241
|
+
(nests(a.source.dir, dir) || nests(dir, a.source.dir)))) {
|
|
242
|
+
throw new AccountRegistryError('Another account already uses that Codex directory, or one inside or around it.');
|
|
243
|
+
}
|
|
244
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
245
|
+
source = { kind: 'codex-home', dir };
|
|
246
|
+
}
|
|
247
|
+
const account = {
|
|
248
|
+
id,
|
|
249
|
+
provider: input.provider,
|
|
250
|
+
label: input.label,
|
|
251
|
+
source,
|
|
252
|
+
createdAt: now().toISOString(),
|
|
253
|
+
...(input.display !== undefined ? { display: input.display } : {}),
|
|
254
|
+
...(input.kind === 'api-key' && input.baseUrl !== undefined
|
|
255
|
+
? { baseUrl: input.baseUrl }
|
|
256
|
+
: {}),
|
|
257
|
+
...(input.kind === 'api-key' && input.defaultModel !== undefined
|
|
258
|
+
? { defaultModel: input.defaultModel }
|
|
259
|
+
: {}),
|
|
260
|
+
};
|
|
261
|
+
file.accounts.push(account);
|
|
262
|
+
return account;
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
rename(id, label) {
|
|
266
|
+
checkLabel(label);
|
|
267
|
+
return mutate((file) => {
|
|
268
|
+
const index = file.accounts.findIndex((a) => a.id === id);
|
|
269
|
+
const current = file.accounts[index];
|
|
270
|
+
if (!current)
|
|
271
|
+
throw new AccountRegistryError('No such account.');
|
|
272
|
+
const nextId = accountId(current.provider, label);
|
|
273
|
+
if (file.accounts.some((a) => a.id === nextId)) {
|
|
274
|
+
throw new AccountRegistryError(`There is already an account labelled "${label}".`);
|
|
275
|
+
}
|
|
276
|
+
const renamed = { ...current, id: nextId, label };
|
|
277
|
+
file.accounts[index] = renamed;
|
|
278
|
+
return toAccount(renamed);
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
remove(id) {
|
|
282
|
+
const parsed = parseAccountId(id);
|
|
283
|
+
if (parsed?.label === DEFAULT_ACCOUNT_LABEL) {
|
|
284
|
+
throw new AccountRegistryError('The existing sign-in is not an account that can be removed.');
|
|
285
|
+
}
|
|
286
|
+
mutate((file) => {
|
|
287
|
+
const index = file.accounts.findIndex((a) => a.id === id);
|
|
288
|
+
const current = file.accounts[index];
|
|
289
|
+
if (!current)
|
|
290
|
+
throw new AccountRegistryError('No such account.');
|
|
291
|
+
file.accounts.splice(index, 1);
|
|
292
|
+
if (current.source.kind === 'api-key') {
|
|
293
|
+
delete file.keys[current.source.keyRef];
|
|
294
|
+
}
|
|
295
|
+
else if (insideAccountsRoot(ownDir(current.source)) &&
|
|
296
|
+
!file.accounts.some((a) => a.source.kind === 'codex-home' && nests(ownDir(current.source), a.source.dir))) {
|
|
297
|
+
// Only a directory this registry could have created, and that holds no
|
|
298
|
+
// other account's directory, is ever deleted.
|
|
299
|
+
rmSync(ownDir(current.source), { recursive: true, force: true });
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
async resolve(id, signal) {
|
|
304
|
+
const account = registry.get(id);
|
|
305
|
+
if (!account)
|
|
306
|
+
throw new CredentialWithdrawnError(id, 'That account no longer exists.');
|
|
307
|
+
const { source } = account;
|
|
308
|
+
if (source.kind === 'existing-default') {
|
|
309
|
+
if (!options.readers?.existingDefault) {
|
|
310
|
+
throw new CredentialWithdrawnError(id, 'No reader is configured for the existing sign-in.');
|
|
311
|
+
}
|
|
312
|
+
return options.readers.existingDefault(account.provider, signal);
|
|
313
|
+
}
|
|
314
|
+
if (source.kind === 'codex-home') {
|
|
315
|
+
if (account.provider !== CODEX_PROVIDER) {
|
|
316
|
+
throw new CredentialWithdrawnError(id, 'A Codex home is only valid for the codex provider.');
|
|
317
|
+
}
|
|
318
|
+
if (!options.readers?.codexHome) {
|
|
319
|
+
throw new CredentialWithdrawnError(id, 'No reader is configured for Codex accounts.');
|
|
320
|
+
}
|
|
321
|
+
return options.readers.codexHome(account, signal);
|
|
322
|
+
}
|
|
323
|
+
const secret = read().keys[source.keyRef];
|
|
324
|
+
if (secret === undefined) {
|
|
325
|
+
throw new CredentialWithdrawnError(id, 'The saved key for this account is missing.');
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
kind: 'api-key',
|
|
329
|
+
accessToken: secret,
|
|
330
|
+
...(account.baseUrl !== undefined ? { baseUrl: account.baseUrl } : {}),
|
|
331
|
+
...(account.defaultModel !== undefined ? { defaultModel: account.defaultModel } : {}),
|
|
332
|
+
};
|
|
333
|
+
},
|
|
334
|
+
next(provider, excluding) {
|
|
335
|
+
return registry.list(provider).find((a) => !excluding.includes(a.id));
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
return registry;
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/account/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EACN,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,MAAM,EACN,UAAU,EACV,SAAS,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAKN,oBAAoB,EAEpB,wBAAwB,EACxB,qBAAqB,GAGrB,MAAM,YAAY,CAAA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EAAE,CAAC;gBAC1B,MAAM,IAAI,wBAAwB,CAAC,EAAE,EAAE,4CAA4C,CAAC,CAAA;YACrF,CAAC;YACD,OAAO;gBACN,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,MAAM;gBACnB,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACrF,CAAA;QACF,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,SAAS;YACvB,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACtE,CAAC;KACD,CAAA;IACD,OAAO,QAAQ,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts: more than one credential for one provider, chosen per session.
|
|
3
|
+
*
|
|
4
|
+
* An account is a provider plus a label. Today's single sign-in for each
|
|
5
|
+
* provider is the account labelled `default`; it is read exactly as before and
|
|
6
|
+
* is never stored here. Further accounts are one of two kinds: a private
|
|
7
|
+
* Codex home directory that holds its own `auth.json`, or a labelled API key.
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
10
|
+
*/
|
|
11
|
+
/** `<provider>:<label>`. The label is `[a-z0-9-]{1,32}`; `default` is reserved for today's sign-in. */
|
|
12
|
+
export type AccountId = string;
|
|
13
|
+
/** The label of the account that wraps a provider's existing sign-in. */
|
|
14
|
+
export declare const DEFAULT_ACCOUNT_LABEL = "default";
|
|
15
|
+
/** Where an account's credential comes from. */
|
|
16
|
+
export type AccountSource =
|
|
17
|
+
/** The provider's existing sign-in, read the way it was before accounts existed. Synthesised, never stored. */
|
|
18
|
+
{
|
|
19
|
+
readonly kind: 'existing-default';
|
|
20
|
+
}
|
|
21
|
+
/** A private Codex home: `dir/auth.json` was written by `codex login` run with `CODEX_HOME=dir`. */
|
|
22
|
+
| {
|
|
23
|
+
readonly kind: 'codex-home';
|
|
24
|
+
readonly dir: string;
|
|
25
|
+
}
|
|
26
|
+
/** A labelled API key. `keyRef` names a slot in the registry's secret map; the key itself is never in a log. */
|
|
27
|
+
| {
|
|
28
|
+
readonly kind: 'api-key';
|
|
29
|
+
readonly keyRef: string;
|
|
30
|
+
};
|
|
31
|
+
export interface Account {
|
|
32
|
+
readonly id: AccountId;
|
|
33
|
+
readonly provider: string;
|
|
34
|
+
readonly label: string;
|
|
35
|
+
readonly source: AccountSource;
|
|
36
|
+
readonly createdAt: string;
|
|
37
|
+
/** A short human tag such as the tail of the provider's account id. Never a token. */
|
|
38
|
+
readonly display?: string;
|
|
39
|
+
/** API-key accounts only: the endpoint this key belongs to. A different endpoint is a different account. */
|
|
40
|
+
readonly baseUrl?: string;
|
|
41
|
+
/** API-key accounts only: the model a session on this account starts with. */
|
|
42
|
+
readonly defaultModel?: string;
|
|
43
|
+
}
|
|
44
|
+
/** What `add` accepts. The id, the creation time and the key slot are assigned by the registry. */
|
|
45
|
+
export type NewAccount = {
|
|
46
|
+
readonly provider: string;
|
|
47
|
+
readonly label: string;
|
|
48
|
+
readonly kind: 'api-key';
|
|
49
|
+
readonly apiKey: string;
|
|
50
|
+
readonly display?: string;
|
|
51
|
+
/** An http(s) endpoint without embedded credentials. */
|
|
52
|
+
readonly baseUrl?: string;
|
|
53
|
+
readonly defaultModel?: string;
|
|
54
|
+
} | {
|
|
55
|
+
readonly provider: 'codex';
|
|
56
|
+
readonly label: string;
|
|
57
|
+
readonly kind: 'codex-home';
|
|
58
|
+
/** Defaults to `<home>/accounts/codex/<label>`; must stay inside `<home>/accounts`. */
|
|
59
|
+
readonly dir?: string;
|
|
60
|
+
readonly display?: string;
|
|
61
|
+
};
|
|
62
|
+
/** A credential ready to put on a request. Never logged. */
|
|
63
|
+
export interface ResolvedAccountCredential {
|
|
64
|
+
readonly kind: 'api-key' | 'oauth';
|
|
65
|
+
readonly accessToken: string;
|
|
66
|
+
/** Set for an API-key account that names its own endpoint. */
|
|
67
|
+
readonly baseUrl?: string;
|
|
68
|
+
/** Set for an API-key account that names a starting model. */
|
|
69
|
+
readonly defaultModel?: string;
|
|
70
|
+
/** The provider-side account identity some drivers send as a header. */
|
|
71
|
+
readonly accountId?: string;
|
|
72
|
+
/** Epoch milliseconds, when the credential expires. */
|
|
73
|
+
readonly expiresAt?: number;
|
|
74
|
+
}
|
|
75
|
+
/** The credential behind an account is gone or unusable; the caller should offer another account. */
|
|
76
|
+
export declare class CredentialWithdrawnError extends Error {
|
|
77
|
+
readonly accountId: AccountId;
|
|
78
|
+
readonly name = "CredentialWithdrawnError";
|
|
79
|
+
constructor(accountId: AccountId, message: string);
|
|
80
|
+
}
|
|
81
|
+
/** A registry mutation was refused: bad label, duplicate, unknown account, unreadable store. */
|
|
82
|
+
export declare class AccountRegistryError extends Error {
|
|
83
|
+
readonly name = "AccountRegistryError";
|
|
84
|
+
}
|
|
85
|
+
/** Another owner holds the lock for a store or an account's credential file. */
|
|
86
|
+
export declare class AccountLockError extends Error {
|
|
87
|
+
readonly lockPath: string;
|
|
88
|
+
readonly name = "AccountLockError";
|
|
89
|
+
constructor(lockPath: string, message: string);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Source-specific readers. The registry owns the bookkeeping; the code that
|
|
93
|
+
* knows how a provider's sign-in is discovered or refreshed lives with the
|
|
94
|
+
* provider and is handed in here.
|
|
95
|
+
*/
|
|
96
|
+
export interface AccountCredentialReaders {
|
|
97
|
+
/** Read the provider's existing sign-in. Throws {@link CredentialWithdrawnError} when there is none. */
|
|
98
|
+
readonly existingDefault?: (provider: string, signal: AbortSignal) => Promise<ResolvedAccountCredential>;
|
|
99
|
+
/**
|
|
100
|
+
* Read, and refresh when due, the credential in a private Codex home. An
|
|
101
|
+
* implementation holds `withAccountRefreshLock` across the read-refresh-write
|
|
102
|
+
* so two processes never spend one refresh token twice.
|
|
103
|
+
*/
|
|
104
|
+
readonly codexHome?: (account: Account & {
|
|
105
|
+
readonly source: {
|
|
106
|
+
readonly kind: 'codex-home';
|
|
107
|
+
readonly dir: string;
|
|
108
|
+
};
|
|
109
|
+
}, signal: AbortSignal) => Promise<ResolvedAccountCredential>;
|
|
110
|
+
}
|
|
111
|
+
export interface AccountRegistry {
|
|
112
|
+
/** Stored accounts plus the synthesised `default` of each known provider. Defaults first, then creation order. */
|
|
113
|
+
list(provider?: string): Account[];
|
|
114
|
+
get(id: AccountId): Account | undefined;
|
|
115
|
+
add(account: NewAccount): Account;
|
|
116
|
+
/** Change an account's label; its id changes with it. Sessions bound to the old id fall back to `default`. */
|
|
117
|
+
rename(id: AccountId, label: string): Account;
|
|
118
|
+
/** Remove a stored account and its secret or private Codex directory. The `default` account cannot be removed. */
|
|
119
|
+
remove(id: AccountId): void;
|
|
120
|
+
resolve(id: AccountId, signal: AbortSignal): Promise<ResolvedAccountCredential>;
|
|
121
|
+
/** The next account of `provider` not in `excluding`, for the "continue with another account" picker. */
|
|
122
|
+
next(provider: string, excluding: readonly AccountId[]): Account | undefined;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/account/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,uGAAuG;AACvG,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,YAAY,CAAA;AAE9C,gDAAgD;AAChD,MAAM,MAAM,aAAa;AACxB,+GAA+G;AAC7G;IAAE,QAAQ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O,GAAG;QAAE,QAAQ,CAAC,MAAM,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;YAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EAC7F,MAAM,EAAE,WAAW,KACf,OAAO,CAAC,yBAAyB,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,eAAe;IAC/B,kHAAkH;IAClH,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;IAClC,GAAG,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;IACvC,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAA;IACjC,8GAA8G;IAC9G,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;IAC7C,kHAAkH;IAClH,MAAM,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,CAAA;IAC3B,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;IAC/E,yGAAyG;IACzG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,GAAG,SAAS,CAAA;CAC5E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts: more than one credential for one provider, chosen per session.
|
|
3
|
+
*
|
|
4
|
+
* An account is a provider plus a label. Today's single sign-in for each
|
|
5
|
+
* provider is the account labelled `default`; it is read exactly as before and
|
|
6
|
+
* is never stored here. Further accounts are one of two kinds: a private
|
|
7
|
+
* Codex home directory that holds its own `auth.json`, or a labelled API key.
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
10
|
+
*/
|
|
11
|
+
/** The label of the account that wraps a provider's existing sign-in. */
|
|
12
|
+
export const DEFAULT_ACCOUNT_LABEL = 'default';
|
|
13
|
+
/** The credential behind an account is gone or unusable; the caller should offer another account. */
|
|
14
|
+
export class CredentialWithdrawnError extends Error {
|
|
15
|
+
accountId;
|
|
16
|
+
name = 'CredentialWithdrawnError';
|
|
17
|
+
constructor(accountId, message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.accountId = accountId;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** A registry mutation was refused: bad label, duplicate, unknown account, unreadable store. */
|
|
23
|
+
export class AccountRegistryError extends Error {
|
|
24
|
+
name = 'AccountRegistryError';
|
|
25
|
+
}
|
|
26
|
+
/** Another owner holds the lock for a store or an account's credential file. */
|
|
27
|
+
export class AccountLockError extends Error {
|
|
28
|
+
lockPath;
|
|
29
|
+
name = 'AccountLockError';
|
|
30
|
+
constructor(lockPath, message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.lockPath = lockPath;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/account/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAA;AA4D9C,qGAAqG;AACrG,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAGxC;IAFQ,IAAI,GAAG,0BAA0B,CAAA;IACnD,YACU,SAAoB,EAC7B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,cAAS,GAAT,SAAS,CAAW;IAI9B,CAAC;CACD;AAED,gGAAgG;AAChG,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC5B,IAAI,GAAG,sBAAsB,CAAA;CAC/C;AAED,gFAAgF;AAChF,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAGhC;IAFQ,IAAI,GAAG,kBAAkB,CAAA;IAC3C,YACU,QAAgB,EACzB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,aAAQ,GAAR,QAAQ,CAAQ;IAI1B,CAAC;CACD"}
|
|
@@ -29,6 +29,59 @@
|
|
|
29
29
|
* accumulates every release. Until a driver does that, an entry here is
|
|
30
30
|
* only ever as fresh as the day someone checked it.
|
|
31
31
|
*/
|
|
32
|
+
/** The window an id declares with the `[1m]` suffix, and the ceiling `NAMZU_AUTO_COMPACT_WINDOW` accepts. */
|
|
33
|
+
export declare const ONE_MILLION_WINDOW_TOKENS = 1000000;
|
|
34
|
+
/** The window a model is held to when `NAMZU_DISABLE_1M_CONTEXT` is on. */
|
|
35
|
+
export declare const DISABLED_ONE_MILLION_WINDOW_CAP_TOKENS = 200000;
|
|
36
|
+
/**
|
|
37
|
+
* A model id may end in `[1m]` (any case) to declare a one-million-token
|
|
38
|
+
* window, whether or not the id is recognised. The suffix is a marker for
|
|
39
|
+
* Namzu, never part of the vendor's name: strip it with this before an id
|
|
40
|
+
* reaches a driver or a wire.
|
|
41
|
+
*/
|
|
42
|
+
export declare function splitModelWindowSuffix(model: string): {
|
|
43
|
+
readonly model: string;
|
|
44
|
+
readonly declaresOneMillion: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** The id with any `[1m]` suffix removed. */
|
|
47
|
+
export declare function stripModelWindowSuffix(model: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* `NAMZU_DISABLE_1M_CONTEXT` (1, true, yes or on): the suffix is still
|
|
50
|
+
* stripped but declares nothing, and no window above 200,000 tokens is
|
|
51
|
+
* assumed for a model whose window comes from a driver or the table.
|
|
52
|
+
*/
|
|
53
|
+
export declare function oneMillionWindowDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
54
|
+
/** Smallest and largest window `NAMZU_AUTO_COMPACT_WINDOW` can name. */
|
|
55
|
+
export declare const AUTO_COMPACT_WINDOW_MIN_TOKENS = 100000;
|
|
56
|
+
export declare const AUTO_COMPACT_WINDOW_MAX_TOKENS = 1000000;
|
|
57
|
+
export type AutoCompactWindowParse = {
|
|
58
|
+
readonly kind: 'in_range';
|
|
59
|
+
readonly tokens: number;
|
|
60
|
+
} | {
|
|
61
|
+
readonly kind: 'below_minimum';
|
|
62
|
+
readonly tokens: number;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: 'above_maximum';
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: 'unusable';
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Read an automatic-summary window the way people write one: a plain number
|
|
70
|
+
* (`200000`) or one with a `k` or `m` suffix (`786k`, `1m`, `1.5m`). Anything
|
|
71
|
+
* under 100,000 is `below_minimum`, over 1,000,000 `above_maximum`, and
|
|
72
|
+
* something that is not a size at all `unusable`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseAutoCompactWindow(raw: string): AutoCompactWindowParse;
|
|
75
|
+
/**
|
|
76
|
+
* The window to use for a written size, and a one-line warning when what was
|
|
77
|
+
* written had to be changed: below 100,000 reads as 100,000, above 1,000,000
|
|
78
|
+
* as 1,000,000, and a non-size is ignored (`tokens` undefined). `source`
|
|
79
|
+
* names where it was written, e.g. `NAMZU_AUTO_COMPACT_WINDOW`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveAutoCompactWindowSetting(raw: string | number, source: string): {
|
|
82
|
+
readonly tokens: number | undefined;
|
|
83
|
+
readonly warning?: string;
|
|
84
|
+
};
|
|
32
85
|
/**
|
|
33
86
|
* Conservative default for a model we do not recognise.
|
|
34
87
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-window.d.ts","sourceRoot":"","sources":["../../src/compaction/context-window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,SAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"context-window.d.ts","sourceRoot":"","sources":["../../src/compaction/context-window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;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