@ai-devkit/agent-manager 0.28.1 → 0.29.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/__tests__/capacity/codex.test.js +343 -0
- package/dist/__tests__/capacity/codex.test.js.map +1 -0
- package/dist/__tests__/capacity/index.test.js +50 -0
- package/dist/__tests__/capacity/index.test.js.map +1 -0
- package/dist/__tests__/print/ClaudePrintAgent.integration.test.js +11 -2
- package/dist/__tests__/print/ClaudePrintAgent.integration.test.js.map +1 -1
- package/dist/capacity/codex.d.ts +36 -0
- package/dist/capacity/codex.d.ts.map +1 -0
- package/dist/capacity/codex.js +317 -0
- package/dist/capacity/codex.js.map +1 -0
- package/dist/capacity/index.d.ts +11 -0
- package/dist/capacity/index.d.ts.map +1 -0
- package/dist/capacity/index.js +49 -0
- package/dist/capacity/index.js.map +1 -0
- package/dist/capacity/types.d.ts +17 -0
- package/dist/capacity/types.d.ts.map +1 -0
- package/dist/capacity/types.js +3 -0
- package/dist/capacity/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/capacity/codex.test.ts +184 -0
- package/src/__tests__/capacity/index.test.ts +38 -0
- package/src/__tests__/print/ClaudePrintAgent.integration.test.ts +9 -2
- package/src/capacity/codex.ts +320 -0
- package/src/capacity/index.ts +57 -0
- package/src/capacity/types.ts +18 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export const CODEX_APP_SERVER_ARGS = [
|
|
5
|
+
'-s',
|
|
6
|
+
'read-only',
|
|
7
|
+
'-a',
|
|
8
|
+
'untrusted',
|
|
9
|
+
'app-server'
|
|
10
|
+
];
|
|
11
|
+
function record(value) {
|
|
12
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
13
|
+
}
|
|
14
|
+
function finiteNumber(value) {
|
|
15
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
16
|
+
}
|
|
17
|
+
function nonEmptyText(value) {
|
|
18
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
19
|
+
}
|
|
20
|
+
function resetTime(value) {
|
|
21
|
+
const seconds = finiteNumber(value);
|
|
22
|
+
if (seconds !== null) return new Date(seconds * 1000).toISOString();
|
|
23
|
+
if (typeof value === 'string' && !Number.isNaN(Date.parse(value))) return new Date(value).toISOString();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
function safeIdentifier(value) {
|
|
27
|
+
const candidate = nonEmptyText(value);
|
|
28
|
+
if (!candidate || !/^[a-z][a-z0-9_-]{0,63}$/i.test(candidate)) return null;
|
|
29
|
+
if (/(?:account|token|secret|key)[_-]?\d{6,}/i.test(candidate)) return null;
|
|
30
|
+
return candidate;
|
|
31
|
+
}
|
|
32
|
+
export function resolveCodexAuthPath(env = process.env) {
|
|
33
|
+
const root = env.CODEX_HOME || join(env.HOME || '', '.codex');
|
|
34
|
+
return join(root, 'auth.json');
|
|
35
|
+
}
|
|
36
|
+
export function toRateWindow(value, id, label) {
|
|
37
|
+
const input = record(value);
|
|
38
|
+
if (!input) return null;
|
|
39
|
+
const used = finiteNumber(input.used_percent);
|
|
40
|
+
const seconds = finiteNumber(input.limit_window_seconds);
|
|
41
|
+
return {
|
|
42
|
+
id,
|
|
43
|
+
label,
|
|
44
|
+
durationMinutes: seconds === null ? null : seconds / 60,
|
|
45
|
+
usedPercent: used,
|
|
46
|
+
resetsAt: resetTime(input.reset_at)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function extraWindows(value) {
|
|
50
|
+
if (!Array.isArray(value)) return [];
|
|
51
|
+
return value.flatMap((entry, index)=>{
|
|
52
|
+
const limit = record(entry);
|
|
53
|
+
if (!limit) return [];
|
|
54
|
+
const scope = safeIdentifier(limit.limit_name) ?? `extra-${index + 1}`;
|
|
55
|
+
const windows = record(limit.rate_limit) ?? limit;
|
|
56
|
+
return [
|
|
57
|
+
toRateWindow(windows.primary_window, `${scope}:primary`, `${scope} primary`),
|
|
58
|
+
toRateWindow(windows.secondary_window, `${scope}:secondary`, `${scope} secondary`)
|
|
59
|
+
].filter((window)=>window !== null);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export function parseUsage(raw, source) {
|
|
63
|
+
const response = record(raw) ?? {};
|
|
64
|
+
const limits = record(response.rate_limit) ?? {};
|
|
65
|
+
const credits = record(response.credits) ?? {};
|
|
66
|
+
return {
|
|
67
|
+
windows: [
|
|
68
|
+
toRateWindow(limits.primary_window, 'session', 'Session'),
|
|
69
|
+
toRateWindow(limits.secondary_window, 'weekly', 'Weekly'),
|
|
70
|
+
...extraWindows(response.additional_rate_limits)
|
|
71
|
+
].filter((window)=>window !== null),
|
|
72
|
+
creditsRemaining: finiteNumber(credits.balance),
|
|
73
|
+
source
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function cliWindow(value, id, label) {
|
|
77
|
+
const input = record(value);
|
|
78
|
+
if (!input) return null;
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
label,
|
|
82
|
+
durationMinutes: finiteNumber(input.windowDurationMins),
|
|
83
|
+
usedPercent: finiteNumber(input.usedPercent),
|
|
84
|
+
resetsAt: resetTime(input.resetsAt)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function cliSnapshotWindows(value, fallbackId) {
|
|
88
|
+
const snapshot = record(value);
|
|
89
|
+
if (!snapshot) return [];
|
|
90
|
+
const scope = safeIdentifier(snapshot.limitId) ?? safeIdentifier(fallbackId) ?? 'codex';
|
|
91
|
+
return [
|
|
92
|
+
cliWindow(snapshot.primary, `${scope}:primary`, `${scope} primary`),
|
|
93
|
+
cliWindow(snapshot.secondary, `${scope}:secondary`, `${scope} secondary`)
|
|
94
|
+
].filter((item)=>item !== null);
|
|
95
|
+
}
|
|
96
|
+
export function parseCliUsage(raw) {
|
|
97
|
+
const response = record(raw) ?? {};
|
|
98
|
+
const primary = record(response.rateLimits);
|
|
99
|
+
const windows = primary ? cliSnapshotWindows(primary, 'codex') : [];
|
|
100
|
+
const buckets = record(response.rateLimitsByLimitId);
|
|
101
|
+
if (buckets) {
|
|
102
|
+
for (const [id, snapshot] of Object.entries(buckets))windows.push(...cliSnapshotWindows(snapshot, id));
|
|
103
|
+
}
|
|
104
|
+
const unique = [
|
|
105
|
+
...new Map(windows.map((window)=>[
|
|
106
|
+
window.id,
|
|
107
|
+
window
|
|
108
|
+
])).values()
|
|
109
|
+
];
|
|
110
|
+
return {
|
|
111
|
+
windows: unique,
|
|
112
|
+
creditsRemaining: null,
|
|
113
|
+
source: 'cli'
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function capacityFromSnapshot(snapshot, context, raw) {
|
|
117
|
+
const hasUsage = snapshot.windows.some((window)=>window.usedPercent !== null);
|
|
118
|
+
const rateLimits = record(record(raw)?.rateLimits);
|
|
119
|
+
const reached = nonEmptyText(rateLimits?.rateLimitReachedType);
|
|
120
|
+
const resetCredits = record(record(raw)?.rateLimitResetCredits) ?? record(record(raw)?.usageLimitResetCredits);
|
|
121
|
+
return {
|
|
122
|
+
provider: 'codex',
|
|
123
|
+
generatedAt: context.checkedAt,
|
|
124
|
+
authenticated: true,
|
|
125
|
+
available: reached ? 'no' : hasUsage ? 'yes' : 'unknown',
|
|
126
|
+
windows: snapshot.windows,
|
|
127
|
+
creditsRemaining: snapshot.creditsRemaining ?? finiteNumber(resetCredits?.availableCount)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function jwtExpiry(token) {
|
|
131
|
+
const part = token.split('.')[1];
|
|
132
|
+
if (!part) return null;
|
|
133
|
+
try {
|
|
134
|
+
return finiteNumber(record(JSON.parse(Buffer.from(part, 'base64url').toString('utf8')))?.exp);
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function staleOAuth(tokens, token, now) {
|
|
140
|
+
const metadata = tokens.expires_at ?? tokens.expiresAt ?? tokens.expiry;
|
|
141
|
+
let expiry = finiteNumber(metadata);
|
|
142
|
+
if (typeof metadata === 'string') {
|
|
143
|
+
const parsed = Date.parse(metadata);
|
|
144
|
+
expiry = Number.isNaN(parsed) ? null : parsed / 1000;
|
|
145
|
+
}
|
|
146
|
+
expiry ??= jwtExpiry(token);
|
|
147
|
+
return expiry !== null && expiry <= now.getTime() / 1000;
|
|
148
|
+
}
|
|
149
|
+
async function fetchJson(fetcher, url, init, timeoutMs) {
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
const timer = setTimeout(()=>controller.abort(), timeoutMs);
|
|
152
|
+
try {
|
|
153
|
+
const response = await fetcher(url, {
|
|
154
|
+
...init,
|
|
155
|
+
signal: controller.signal
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) throw new Error(response.status === 401 ? 'unauthorized' : 'request failed');
|
|
158
|
+
return await response.json();
|
|
159
|
+
} finally{
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function apiSnapshot(token, accountId, source, options) {
|
|
164
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
165
|
+
const raw = await fetchJson(fetcher, 'https://chatgpt.com/backend-api/wham/usage', {
|
|
166
|
+
headers: {
|
|
167
|
+
Authorization: `Bearer ${token}`,
|
|
168
|
+
'ChatGPT-Account-Id': accountId
|
|
169
|
+
}
|
|
170
|
+
}, options.timeoutMs ?? 5000);
|
|
171
|
+
return parseUsage(raw, source);
|
|
172
|
+
}
|
|
173
|
+
function appServerRpc(messages, timeoutMs = 5000) {
|
|
174
|
+
return new Promise((resolve, reject)=>{
|
|
175
|
+
const child = spawn('codex', CODEX_APP_SERVER_ARGS, {
|
|
176
|
+
stdio: [
|
|
177
|
+
'pipe',
|
|
178
|
+
'pipe',
|
|
179
|
+
'ignore'
|
|
180
|
+
]
|
|
181
|
+
});
|
|
182
|
+
const results = {};
|
|
183
|
+
let buffer = '';
|
|
184
|
+
let settled = false;
|
|
185
|
+
const finish = (error)=>{
|
|
186
|
+
if (settled) return;
|
|
187
|
+
settled = true;
|
|
188
|
+
clearTimeout(timer);
|
|
189
|
+
child.kill();
|
|
190
|
+
if (error) reject(error);
|
|
191
|
+
else resolve(results);
|
|
192
|
+
};
|
|
193
|
+
const timer = setTimeout(()=>finish(new Error('codex probe timed out')), timeoutMs);
|
|
194
|
+
child.once('error', ()=>finish(new Error('codex app-server unavailable')));
|
|
195
|
+
child.once('exit', ()=>{
|
|
196
|
+
if (!settled) finish(new Error('codex app-server exited'));
|
|
197
|
+
});
|
|
198
|
+
child.stdout.setEncoding('utf8');
|
|
199
|
+
child.stdout.on('data', (chunk)=>{
|
|
200
|
+
buffer += chunk;
|
|
201
|
+
for(;;){
|
|
202
|
+
const newline = buffer.indexOf('\n');
|
|
203
|
+
if (newline < 0) break;
|
|
204
|
+
const line = buffer.slice(0, newline).trim();
|
|
205
|
+
buffer = buffer.slice(newline + 1);
|
|
206
|
+
if (!line) continue;
|
|
207
|
+
let message;
|
|
208
|
+
try {
|
|
209
|
+
message = JSON.parse(line);
|
|
210
|
+
} catch {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (message.id === 1) {
|
|
214
|
+
for (const request of messages.slice(1))child.stdin.write(`${JSON.stringify(request)}\n`);
|
|
215
|
+
} else if (message.id === 2) {
|
|
216
|
+
if (message.error) finish(new Error('codex rate-limit method failed'));
|
|
217
|
+
else results.rateLimits = message.result;
|
|
218
|
+
} else if (message.id === 3) {
|
|
219
|
+
if (message.error) finish(new Error('codex account method failed'));
|
|
220
|
+
else results.account = message.result;
|
|
221
|
+
}
|
|
222
|
+
if ('rateLimits' in results && 'account' in results) finish();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
child.stdin.write(`${JSON.stringify(messages[0])}\n`);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function unavailable(options) {
|
|
229
|
+
return {
|
|
230
|
+
provider: 'codex',
|
|
231
|
+
generatedAt: options.checkedAt,
|
|
232
|
+
authenticated: null,
|
|
233
|
+
available: 'unknown',
|
|
234
|
+
windows: [],
|
|
235
|
+
creditsRemaining: null
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async function cliFallback(options) {
|
|
239
|
+
if (!options.installed) return unavailable(options);
|
|
240
|
+
const messages = [
|
|
241
|
+
{
|
|
242
|
+
id: 1,
|
|
243
|
+
method: 'initialize',
|
|
244
|
+
params: {
|
|
245
|
+
clientInfo: {
|
|
246
|
+
name: 'ai-devkit',
|
|
247
|
+
title: null,
|
|
248
|
+
version: '1'
|
|
249
|
+
},
|
|
250
|
+
capabilities: null
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
method: 'initialized'
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
id: 2,
|
|
258
|
+
method: 'account/rateLimits/read'
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: 3,
|
|
262
|
+
method: 'account/read'
|
|
263
|
+
}
|
|
264
|
+
];
|
|
265
|
+
try {
|
|
266
|
+
const rpc = options.rpc ?? ((requests)=>appServerRpc(requests, options.timeoutMs));
|
|
267
|
+
const response = await rpc(messages);
|
|
268
|
+
const result = capacityFromSnapshot(parseCliUsage(response.rateLimits), options, response.rateLimits);
|
|
269
|
+
const accountEnvelope = record(response.account);
|
|
270
|
+
if (accountEnvelope && Object.hasOwn(accountEnvelope, 'account') && !record(accountEnvelope.account)) {
|
|
271
|
+
result.authenticated = false;
|
|
272
|
+
result.available = 'unknown';
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
} catch {
|
|
276
|
+
return unavailable(options);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export async function probeCodexCapacity(options) {
|
|
280
|
+
let parsed = null;
|
|
281
|
+
try {
|
|
282
|
+
const contents = await (options.readFile ?? readFile)(resolveCodexAuthPath(options.env), 'utf8');
|
|
283
|
+
parsed = record(JSON.parse(contents));
|
|
284
|
+
} catch {
|
|
285
|
+
return cliFallback(options);
|
|
286
|
+
}
|
|
287
|
+
const auth = parsed ?? {};
|
|
288
|
+
const pat = nonEmptyText(auth.personal_access_token);
|
|
289
|
+
if (pat) {
|
|
290
|
+
try {
|
|
291
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
292
|
+
const whoami = record(await fetchJson(fetcher, 'https://auth.openai.com/api/accounts/v1/user-auth-credential/whoami', {
|
|
293
|
+
headers: {
|
|
294
|
+
Authorization: `Bearer ${pat}`
|
|
295
|
+
}
|
|
296
|
+
}, options.timeoutMs ?? 5000));
|
|
297
|
+
const accountId = nonEmptyText(whoami?.chatgpt_account_id);
|
|
298
|
+
if (!accountId) throw new Error('account unavailable');
|
|
299
|
+
return capacityFromSnapshot(await apiSnapshot(pat, accountId, 'pat', options), options);
|
|
300
|
+
} catch {
|
|
301
|
+
// Continue to a separately available OAuth credential before using the CLI.
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const tokens = record(auth.tokens);
|
|
305
|
+
const accessToken = nonEmptyText(tokens?.access_token);
|
|
306
|
+
const accountId = nonEmptyText(tokens?.account_id);
|
|
307
|
+
if (tokens && accessToken && accountId && !staleOAuth(tokens, accessToken, (options.now ?? (()=>new Date()))())) {
|
|
308
|
+
try {
|
|
309
|
+
return capacityFromSnapshot(await apiSnapshot(accessToken, accountId, 'oauth', options), options);
|
|
310
|
+
} catch {
|
|
311
|
+
return cliFallback(options);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return cliFallback(options);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//# sourceMappingURL=codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/capacity/codex.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { CapacityReport, CapacityWindow } from './types.js';\n\ntype CodexUsageSource = 'pat' | 'oauth' | 'cli';\ntype UsageSnapshot = { windows: CapacityWindow[]; creditsRemaining: number | null; source: CodexUsageSource };\n\ntype UnknownRecord = Record<string, unknown>;\ntype RpcMessage = { id?: number; method: string; params?: UnknownRecord };\ntype CliResponses = { rateLimits: unknown; account: unknown };\ntype CodexRpc = (messages: RpcMessage[]) => Promise<CliResponses>;\n\nexport const CODEX_APP_SERVER_ARGS = ['-s', 'read-only', '-a', 'untrusted', 'app-server'] as const;\n\ntype CodexProbeOptions = {\n installed: boolean;\n checkedAt: string;\n readFile?: (path: string, encoding: BufferEncoding) => Promise<string>;\n fetch?: typeof globalThis.fetch;\n rpc?: CodexRpc;\n timeoutMs?: number;\n env?: NodeJS.ProcessEnv;\n now?: () => Date;\n};\n\nfunction record(value: unknown): UnknownRecord | null {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as UnknownRecord\n : null;\n}\n\nfunction finiteNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null;\n}\n\nfunction nonEmptyText(value: unknown): string | null {\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n\nfunction resetTime(value: unknown): string | null {\n const seconds = finiteNumber(value);\n if (seconds !== null) return new Date(seconds * 1000).toISOString();\n if (typeof value === 'string' && !Number.isNaN(Date.parse(value))) return new Date(value).toISOString();\n return null;\n}\n\nfunction safeIdentifier(value: unknown): string | null {\n const candidate = nonEmptyText(value);\n if (!candidate || !/^[a-z][a-z0-9_-]{0,63}$/i.test(candidate)) return null;\n if (/(?:account|token|secret|key)[_-]?\\d{6,}/i.test(candidate)) return null;\n return candidate;\n}\n\nexport function resolveCodexAuthPath(env: NodeJS.ProcessEnv = process.env): string {\n const root = env.CODEX_HOME || join(env.HOME || '', '.codex');\n return join(root, 'auth.json');\n}\n\nexport function toRateWindow(\n value: unknown,\n id: string,\n label: string\n): CapacityWindow | null {\n const input = record(value);\n if (!input) return null;\n const used = finiteNumber(input.used_percent);\n const seconds = finiteNumber(input.limit_window_seconds);\n return {\n id,\n label,\n durationMinutes: seconds === null ? null : seconds / 60,\n usedPercent: used,\n resetsAt: resetTime(input.reset_at)\n };\n}\n\nfunction extraWindows(value: unknown): CapacityWindow[] {\n if (!Array.isArray(value)) return [];\n return value.flatMap((entry, index) => {\n const limit = record(entry);\n if (!limit) return [];\n const scope = safeIdentifier(limit.limit_name) ?? `extra-${index + 1}`;\n const windows = record(limit.rate_limit) ?? limit;\n return [\n toRateWindow(windows.primary_window, `${scope}:primary`, `${scope} primary`),\n toRateWindow(windows.secondary_window, `${scope}:secondary`, `${scope} secondary`)\n ].filter((window): window is CapacityWindow => window !== null);\n });\n}\n\nexport function parseUsage(raw: unknown, source: 'pat' | 'oauth'): UsageSnapshot {\n const response = record(raw) ?? {};\n const limits = record(response.rate_limit) ?? {};\n const credits = record(response.credits) ?? {};\n return {\n windows: [\n toRateWindow(limits.primary_window, 'session', 'Session'),\n toRateWindow(limits.secondary_window, 'weekly', 'Weekly'),\n ...extraWindows(response.additional_rate_limits)\n ].filter((window): window is CapacityWindow => window !== null),\n creditsRemaining: finiteNumber(credits.balance),\n source\n };\n}\n\nfunction cliWindow(value: unknown, id: string, label: string): CapacityWindow | null {\n const input = record(value);\n if (!input) return null;\n return {\n id,\n label,\n durationMinutes: finiteNumber(input.windowDurationMins),\n usedPercent: finiteNumber(input.usedPercent),\n resetsAt: resetTime(input.resetsAt)\n };\n}\n\nfunction cliSnapshotWindows(value: unknown, fallbackId: string): CapacityWindow[] {\n const snapshot = record(value);\n if (!snapshot) return [];\n const scope = safeIdentifier(snapshot.limitId) ?? safeIdentifier(fallbackId) ?? 'codex';\n return [\n cliWindow(snapshot.primary, `${scope}:primary`, `${scope} primary`),\n cliWindow(snapshot.secondary, `${scope}:secondary`, `${scope} secondary`)\n ].filter((item): item is CapacityWindow => item !== null);\n}\n\nexport function parseCliUsage(raw: unknown): UsageSnapshot {\n const response = record(raw) ?? {};\n const primary = record(response.rateLimits);\n const windows = primary ? cliSnapshotWindows(primary, 'codex') : [];\n const buckets = record(response.rateLimitsByLimitId);\n if (buckets) {\n for (const [id, snapshot] of Object.entries(buckets)) windows.push(...cliSnapshotWindows(snapshot, id));\n }\n const unique = [...new Map(windows.map(window => [window.id, window])).values()];\n return { windows: unique, creditsRemaining: null, source: 'cli' };\n}\n\nfunction capacityFromSnapshot(snapshot: UsageSnapshot, context: CodexProbeOptions, raw?: unknown): CapacityReport {\n const hasUsage = snapshot.windows.some(window => window.usedPercent !== null);\n const rateLimits = record(record(raw)?.rateLimits);\n const reached = nonEmptyText(rateLimits?.rateLimitReachedType);\n const resetCredits = record(record(raw)?.rateLimitResetCredits) ?? record(record(raw)?.usageLimitResetCredits);\n return {\n provider: 'codex',\n generatedAt: context.checkedAt,\n authenticated: true,\n available: reached ? 'no' : hasUsage ? 'yes' : 'unknown',\n windows: snapshot.windows,\n creditsRemaining: snapshot.creditsRemaining ?? finiteNumber(resetCredits?.availableCount)\n };\n}\n\nfunction jwtExpiry(token: string): number | null {\n const part = token.split('.')[1];\n if (!part) return null;\n try {\n return finiteNumber(record(JSON.parse(Buffer.from(part, 'base64url').toString('utf8')))?.exp);\n } catch {\n return null;\n }\n}\n\nfunction staleOAuth(tokens: UnknownRecord, token: string, now: Date): boolean {\n const metadata = tokens.expires_at ?? tokens.expiresAt ?? tokens.expiry;\n let expiry: number | null = finiteNumber(metadata);\n if (typeof metadata === 'string') {\n const parsed = Date.parse(metadata);\n expiry = Number.isNaN(parsed) ? null : parsed / 1000;\n }\n expiry ??= jwtExpiry(token);\n return expiry !== null && expiry <= now.getTime() / 1000;\n}\n\nasync function fetchJson(fetcher: typeof globalThis.fetch, url: string, init: RequestInit, timeoutMs: number): Promise<unknown> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const response = await fetcher(url, { ...init, signal: controller.signal });\n if (!response.ok) throw new Error(response.status === 401 ? 'unauthorized' : 'request failed');\n return await response.json();\n } finally {\n clearTimeout(timer);\n }\n}\n\nasync function apiSnapshot(\n token: string,\n accountId: string,\n source: 'pat' | 'oauth',\n options: CodexProbeOptions\n): Promise<UsageSnapshot> {\n const fetcher = options.fetch ?? globalThis.fetch;\n const raw = await fetchJson(fetcher, 'https://chatgpt.com/backend-api/wham/usage', {\n headers: { Authorization: `Bearer ${token}`, 'ChatGPT-Account-Id': accountId }\n }, options.timeoutMs ?? 5000);\n return parseUsage(raw, source);\n}\n\nfunction appServerRpc(messages: RpcMessage[], timeoutMs = 5000): Promise<CliResponses> {\n return new Promise((resolve, reject) => {\n const child = spawn('codex', CODEX_APP_SERVER_ARGS, {\n stdio: ['pipe', 'pipe', 'ignore']\n });\n const results: Partial<CliResponses> = {};\n let buffer = '';\n let settled = false;\n const finish = (error?: Error) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n child.kill();\n if (error) reject(error);\n else resolve(results as CliResponses);\n };\n const timer = setTimeout(() => finish(new Error('codex probe timed out')), timeoutMs);\n child.once('error', () => finish(new Error('codex app-server unavailable')));\n child.once('exit', () => { if (!settled) finish(new Error('codex app-server exited')); });\n child.stdout.setEncoding('utf8');\n child.stdout.on('data', (chunk: string) => {\n buffer += chunk;\n for (;;) {\n const newline = buffer.indexOf('\\n');\n if (newline < 0) break;\n const line = buffer.slice(0, newline).trim();\n buffer = buffer.slice(newline + 1);\n if (!line) continue;\n let message: UnknownRecord;\n try { message = JSON.parse(line) as UnknownRecord; } catch { continue; }\n if (message.id === 1) {\n for (const request of messages.slice(1)) child.stdin.write(`${JSON.stringify(request)}\\n`);\n } else if (message.id === 2) {\n if (message.error) finish(new Error('codex rate-limit method failed'));\n else results.rateLimits = message.result;\n } else if (message.id === 3) {\n if (message.error) finish(new Error('codex account method failed'));\n else results.account = message.result;\n }\n if ('rateLimits' in results && 'account' in results) finish();\n }\n });\n child.stdin.write(`${JSON.stringify(messages[0])}\\n`);\n });\n}\n\nfunction unavailable(options: CodexProbeOptions): CapacityReport {\n return {\n provider: 'codex',\n generatedAt: options.checkedAt,\n authenticated: null,\n available: 'unknown',\n windows: [],\n creditsRemaining: null\n };\n}\n\nasync function cliFallback(options: CodexProbeOptions): Promise<CapacityReport> {\n if (!options.installed) return unavailable(options);\n const messages: RpcMessage[] = [\n { id: 1, method: 'initialize', params: {\n clientInfo: { name: 'ai-devkit', title: null, version: '1' }, capabilities: null\n } },\n { method: 'initialized' },\n { id: 2, method: 'account/rateLimits/read' },\n { id: 3, method: 'account/read' }\n ];\n try {\n const rpc = options.rpc ?? (requests => appServerRpc(requests, options.timeoutMs));\n const response = await rpc(messages);\n const result = capacityFromSnapshot(parseCliUsage(response.rateLimits), options, response.rateLimits);\n const accountEnvelope = record(response.account);\n if (accountEnvelope && Object.hasOwn(accountEnvelope, 'account') && !record(accountEnvelope.account)) {\n result.authenticated = false;\n result.available = 'unknown';\n }\n return result;\n } catch {\n return unavailable(options);\n }\n}\n\nexport async function probeCodexCapacity(options: CodexProbeOptions): Promise<CapacityReport> {\n let parsed: UnknownRecord | null = null;\n try {\n const contents = await (options.readFile ?? readFile)(resolveCodexAuthPath(options.env), 'utf8');\n parsed = record(JSON.parse(contents));\n } catch {\n return cliFallback(options);\n }\n\n const auth = parsed ?? {};\n const pat = nonEmptyText(auth.personal_access_token);\n if (pat) {\n try {\n const fetcher = options.fetch ?? globalThis.fetch;\n const whoami = record(await fetchJson(fetcher,\n 'https://auth.openai.com/api/accounts/v1/user-auth-credential/whoami',\n { headers: { Authorization: `Bearer ${pat}` } }, options.timeoutMs ?? 5000));\n const accountId = nonEmptyText(whoami?.chatgpt_account_id);\n if (!accountId) throw new Error('account unavailable');\n return capacityFromSnapshot(await apiSnapshot(pat, accountId, 'pat', options), options);\n } catch {\n // Continue to a separately available OAuth credential before using the CLI.\n }\n }\n\n const tokens = record(auth.tokens);\n const accessToken = nonEmptyText(tokens?.access_token);\n const accountId = nonEmptyText(tokens?.account_id);\n if (tokens && accessToken && accountId && !staleOAuth(tokens, accessToken, (options.now ?? (() => new Date()))())) {\n try {\n return capacityFromSnapshot(await apiSnapshot(accessToken, accountId, 'oauth', options), options);\n } catch {\n return cliFallback(options);\n }\n }\n return cliFallback(options);\n}\n"],"names":["spawn","readFile","join","CODEX_APP_SERVER_ARGS","record","value","Array","isArray","finiteNumber","Number","isFinite","nonEmptyText","length","resetTime","seconds","Date","toISOString","isNaN","parse","safeIdentifier","candidate","test","resolveCodexAuthPath","env","process","root","CODEX_HOME","HOME","toRateWindow","id","label","input","used","used_percent","limit_window_seconds","durationMinutes","usedPercent","resetsAt","reset_at","extraWindows","flatMap","entry","index","limit","scope","limit_name","windows","rate_limit","primary_window","secondary_window","filter","window","parseUsage","raw","source","response","limits","credits","additional_rate_limits","creditsRemaining","balance","cliWindow","windowDurationMins","cliSnapshotWindows","fallbackId","snapshot","limitId","primary","secondary","item","parseCliUsage","rateLimits","buckets","rateLimitsByLimitId","Object","entries","push","unique","Map","map","values","capacityFromSnapshot","context","hasUsage","some","reached","rateLimitReachedType","resetCredits","rateLimitResetCredits","usageLimitResetCredits","provider","generatedAt","checkedAt","authenticated","available","availableCount","jwtExpiry","token","part","split","JSON","Buffer","from","toString","exp","staleOAuth","tokens","now","metadata","expires_at","expiresAt","expiry","parsed","getTime","fetchJson","fetcher","url","init","timeoutMs","controller","AbortController","timer","setTimeout","abort","signal","ok","Error","status","json","clearTimeout","apiSnapshot","accountId","options","fetch","globalThis","headers","Authorization","appServerRpc","messages","Promise","resolve","reject","child","stdio","results","buffer","settled","finish","error","kill","once","stdout","setEncoding","on","chunk","newline","indexOf","line","slice","trim","message","request","stdin","write","stringify","result","account","unavailable","cliFallback","installed","method","params","clientInfo","name","title","version","capabilities","rpc","requests","accountEnvelope","hasOwn","probeCodexCapacity","contents","auth","pat","personal_access_token","whoami","chatgpt_account_id","accessToken","access_token","account_id"],"mappings":"AAAA,SAASA,KAAK,QAAQ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,aAAa4K,KAAKE,qBAAqB;IACnD,IAAID,KAAK;QACP,IAAI;YACF,MAAMrE,UAAUiB,QAAQC,KAAK,IAAIC,WAAWD,KAAK;YACjD,MAAMqD,SAAStL,OAAO,MAAM8G,UAAUC,SACpC,uEACA;gBAAEoB,SAAS;oBAAEC,eAAe,CAAC,OAAO,EAAEgD,KAAK;gBAAC;YAAE,GAAGpD,QAAQd,SAAS,IAAI;YACxE,MAAMa,YAAYxH,aAAa+K,QAAQC;YACvC,IAAI,CAACxD,WAAW,MAAM,IAAIL,MAAM;YAChC,OAAO7C,qBAAqB,MAAMiD,YAAYsD,KAAKrD,WAAW,OAAOC,UAAUA;QACjF,EAAE,OAAM;QACN,4EAA4E;QAC9E;IACF;IAEA,MAAM1B,SAAStG,OAAOmL,KAAK7E,MAAM;IACjC,MAAMkF,cAAcjL,aAAa+F,QAAQmF;IACzC,MAAM1D,YAAYxH,aAAa+F,QAAQoF;IACvC,IAAIpF,UAAUkF,eAAezD,aAAa,CAAC1B,WAAWC,QAAQkF,aAAa,AAACxD,CAAAA,QAAQzB,GAAG,IAAK,CAAA,IAAM,IAAI5F,MAAK,CAAC,MAAO;QACjH,IAAI;YACF,OAAOkE,qBAAqB,MAAMiD,YAAY0D,aAAazD,WAAW,SAASC,UAAUA;QAC3F,EAAE,OAAM;YACN,OAAOoC,YAAYpC;QACrB;IACF;IACA,OAAOoC,YAAYpC;AACrB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { probeCodexCapacity } from './codex.js';
|
|
2
|
+
import type { CapacityReport } from './types.js';
|
|
3
|
+
export type { CapacityReport, CapacityWindow } from './types.js';
|
|
4
|
+
export type CapacityProbeOptions = {
|
|
5
|
+
now?: () => Date;
|
|
6
|
+
path?: string;
|
|
7
|
+
access?: (target: string) => Promise<void>;
|
|
8
|
+
probe?: typeof probeCodexCapacity;
|
|
9
|
+
};
|
|
10
|
+
export declare function getCodexCapacityReport(options?: CapacityProbeOptions): Promise<CapacityReport>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capacity/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,kBAAkB,CAAC;CACnC,CAAC;AA4BF,wBAAsB,sBAAsB,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,cAAc,CAAC,CAexG"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { access as fsAccess } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { probeCodexCapacity } from './codex.js';
|
|
5
|
+
async function canAccess(target, mode) {
|
|
6
|
+
try {
|
|
7
|
+
await fsAccess(target, mode);
|
|
8
|
+
return true;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function isCodexInstalled(pathValue, checkAccess) {
|
|
14
|
+
const directories = pathValue.split(path.delimiter).filter(Boolean);
|
|
15
|
+
for (const directory of directories){
|
|
16
|
+
const executable = path.join(directory, 'codex');
|
|
17
|
+
if (checkAccess) {
|
|
18
|
+
try {
|
|
19
|
+
await checkAccess(executable);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (await canAccess(executable, constants.X_OK)) return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
export async function getCodexCapacityReport(options = {}) {
|
|
30
|
+
const generatedAt = (options.now?.() ?? new Date()).toISOString();
|
|
31
|
+
const installed = await isCodexInstalled(options.path ?? process.env.PATH ?? '', options.access);
|
|
32
|
+
try {
|
|
33
|
+
return await (options.probe ?? probeCodexCapacity)({
|
|
34
|
+
installed,
|
|
35
|
+
checkedAt: generatedAt
|
|
36
|
+
});
|
|
37
|
+
} catch {
|
|
38
|
+
return {
|
|
39
|
+
provider: 'codex',
|
|
40
|
+
generatedAt,
|
|
41
|
+
authenticated: null,
|
|
42
|
+
available: 'unknown',
|
|
43
|
+
windows: [],
|
|
44
|
+
creditsRemaining: null
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/capacity/index.ts"],"sourcesContent":["import { constants } from 'node:fs';\nimport { access as fsAccess } from 'node:fs/promises';\nimport path from 'node:path';\nimport { probeCodexCapacity } from './codex.js';\nimport type { CapacityReport } from './types.js';\n\nexport type { CapacityReport, CapacityWindow } from './types.js';\n\nexport type CapacityProbeOptions = {\n now?: () => Date;\n path?: string;\n access?: (target: string) => Promise<void>;\n probe?: typeof probeCodexCapacity;\n};\n\nasync function canAccess(target: string, mode: number): Promise<boolean> {\n try {\n await fsAccess(target, mode);\n return true;\n } catch {\n return false;\n }\n}\n\nasync function isCodexInstalled(pathValue: string, checkAccess?: (target: string) => Promise<void>): Promise<boolean> {\n const directories = pathValue.split(path.delimiter).filter(Boolean);\n for (const directory of directories) {\n const executable = path.join(directory, 'codex');\n if (checkAccess) {\n try {\n await checkAccess(executable);\n return true;\n } catch {\n continue;\n }\n }\n if (await canAccess(executable, constants.X_OK)) return true;\n }\n return false;\n}\n\nexport async function getCodexCapacityReport(options: CapacityProbeOptions = {}): Promise<CapacityReport> {\n const generatedAt = (options.now?.() ?? new Date()).toISOString();\n const installed = await isCodexInstalled(options.path ?? process.env.PATH ?? '', options.access);\n try {\n return await (options.probe ?? probeCodexCapacity)({ installed, checkedAt: generatedAt });\n } catch {\n return {\n provider: 'codex',\n generatedAt,\n authenticated: null,\n available: 'unknown',\n windows: [],\n creditsRemaining: null\n };\n }\n}\n"],"names":["constants","access","fsAccess","path","probeCodexCapacity","canAccess","target","mode","isCodexInstalled","pathValue","checkAccess","directories","split","delimiter","filter","Boolean","directory","executable","join","X_OK","getCodexCapacityReport","options","generatedAt","now","Date","toISOString","installed","process","env","PATH","probe","checkedAt","provider","authenticated","available","windows","creditsRemaining"],"mappings":"AAAA,SAASA,SAAS,QAAQ,UAAU;AACpC,SAASC,UAAUC,QAAQ,QAAQ,mBAAmB;AACtD,OAAOC,UAAU,YAAY;AAC7B,SAASC,kBAAkB,QAAQ,aAAa;AAYhD,eAAeC,UAAUC,MAAc,EAAEC,IAAY;IACnD,IAAI;QACF,MAAML,SAASI,QAAQC;QACvB,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,eAAeC,iBAAiBC,SAAiB,EAAEC,WAA+C;IAChG,MAAMC,cAAcF,UAAUG,KAAK,CAACT,KAAKU,SAAS,EAAEC,MAAM,CAACC;IAC3D,KAAK,MAAMC,aAAaL,YAAa;QACnC,MAAMM,aAAad,KAAKe,IAAI,CAACF,WAAW;QACxC,IAAIN,aAAa;YACf,IAAI;gBACF,MAAMA,YAAYO;gBAClB,OAAO;YACT,EAAE,OAAM;gBACN;YACF;QACF;QACA,IAAI,MAAMZ,UAAUY,YAAYjB,UAAUmB,IAAI,GAAG,OAAO;IAC1D;IACA,OAAO;AACT;AAEA,OAAO,eAAeC,uBAAuBC,UAAgC,CAAC,CAAC;IAC7E,MAAMC,cAAc,AAACD,CAAAA,QAAQE,GAAG,QAAQ,IAAIC,MAAK,EAAGC,WAAW;IAC/D,MAAMC,YAAY,MAAMlB,iBAAiBa,QAAQlB,IAAI,IAAIwB,QAAQC,GAAG,CAACC,IAAI,IAAI,IAAIR,QAAQpB,MAAM;IAC/F,IAAI;QACF,OAAO,MAAM,AAACoB,CAAAA,QAAQS,KAAK,IAAI1B,kBAAiB,EAAG;YAAEsB;YAAWK,WAAWT;QAAY;IACzF,EAAE,OAAM;QACN,OAAO;YACLU,UAAU;YACVV;YACAW,eAAe;YACfC,WAAW;YACXC,SAAS,EAAE;YACXC,kBAAkB;QACpB;IACF;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Availability = 'yes' | 'no' | 'unknown';
|
|
2
|
+
export interface CapacityWindow {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
durationMinutes: number | null;
|
|
6
|
+
usedPercent: number | null;
|
|
7
|
+
resetsAt: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface CapacityReport {
|
|
10
|
+
provider: string;
|
|
11
|
+
generatedAt: string;
|
|
12
|
+
authenticated: boolean | null;
|
|
13
|
+
available: Availability;
|
|
14
|
+
windows: CapacityWindow[];
|
|
15
|
+
creditsRemaining: number | null;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/capacity/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/capacity/types.ts"],"sourcesContent":["export type Availability = 'yes' | 'no' | 'unknown';\n\nexport interface CapacityWindow {\n id: string;\n label: string;\n durationMinutes: number | null;\n usedPercent: number | null;\n resetsAt: string | null;\n}\n\nexport interface CapacityReport {\n provider: string;\n generatedAt: string;\n authenticated: boolean | null;\n available: Availability;\n windows: CapacityWindow[];\n creditsRemaining: number | null;\n}\n"],"names":[],"mappings":"AAUA,WAOC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { AgentManager, AgentNotRunningError } from './AgentManager.js';
|
|
2
|
+
export { getCodexCapacityReport } from './capacity/index.js';
|
|
3
|
+
export type { CapacityProbeOptions, CapacityReport, CapacityWindow, } from './capacity/index.js';
|
|
2
4
|
export { ClaudeCodeAdapter } from './adapters/ClaudeCodeAdapter.js';
|
|
3
5
|
export { CodexAdapter } from './adapters/CodexAdapter.js';
|
|
4
6
|
export { CopilotAdapter } from './adapters/CopilotAdapter.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAA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B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEzE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE3G,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,gBAAgB,GACnB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACR,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,YAAY,EACR,uBAAuB,EACvB,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,GACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EACR,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,YAAY,EACR,8BAA8B,EAC9B,qBAAqB,GACxB,MAAM,sCAAsC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AgentManager, AgentNotRunningError } from './AgentManager.js';
|
|
2
|
+
export { getCodexCapacityReport } from './capacity/index.js';
|
|
2
3
|
export { ClaudeCodeAdapter } from './adapters/ClaudeCodeAdapter.js';
|
|
3
4
|
export { CodexAdapter } from './adapters/CodexAdapter.js';
|
|
4
5
|
export { CopilotAdapter } from './adapters/CopilotAdapter.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { AgentManager, AgentNotRunningError } from './AgentManager.js';\n\nexport { ClaudeCodeAdapter } from './adapters/ClaudeCodeAdapter.js';\nexport { CodexAdapter } from './adapters/CodexAdapter.js';\nexport { CopilotAdapter } from './adapters/CopilotAdapter.js';\nexport { GeminiCliAdapter } from './adapters/GeminiCliAdapter.js';\nexport { GrokCliAdapter } from './adapters/GrokCliAdapter.js';\nexport { OpenCodeAdapter } from './adapters/OpenCodeAdapter.js';\nexport { PiAdapter } from './adapters/PiAdapter.js';\nexport { AgentStatus } from './adapters/AgentAdapter.js';\nexport type {\n AgentAdapter,\n AgentType,\n AgentInfo,\n ProcessInfo,\n ConversationMessage,\n SessionSummary,\n ListSessionsOptions,\n AgentDetectionContext,\n} from './adapters/AgentAdapter.js';\n\nexport { TerminalFocusManager, TerminalType } from './terminal/TerminalFocusManager.js';\nexport type { TerminalLocation } from './terminal/TerminalFocusManager.js';\nexport { TtyWriter } from './terminal/TtyWriter.js';\n\nexport { getProcessTty } from './utils/process.js';\nexport { captureProcessSnapshot, executableBasename, filterByProcessNames } from './utils/process.js';\nexport type { AgentSortKey } from './utils/sortAgents.js';\nexport type { ListAgentsOptions } from './AgentManager.js';\n\nexport { AgentRegistry, RenameNotFoundError, RenameConflictError } from './utils/AgentRegistry.js';\nexport type { AgentRegistryOptions, RegistryEntry } from './utils/AgentRegistry.js';\nexport { TmuxManager } from './terminal/TmuxManager.js';\nexport { AGENTS } from './utils/agents.js';\nexport type { AgentConfig, StartableAgentType } from './utils/agents.js';\n\nexport type { AgentRequest } from './utils/agent-requests.js';\nexport { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest } from './utils/agent-requests.js';\n\nexport {\n AGENT_MODES,\n DurableAgentError,\n DurableAgentBusyError,\n DurableAgentNotFoundError,\n DurableAgentRepositoryError,\n DurableAgentNameConflictError,\n ClaudePrintError,\n} from './durable/DurableAgent.js';\nexport type {\n DurableAgent,\n DurableAgentState,\n DurableSessionHealth,\n DurableRunStatus,\n DurableActiveRun,\n DurableLastResult,\n ProcessIdentity,\n} from './durable/DurableAgent.js';\nexport { DurableAgentRepository } from './durable/DurableAgentRepository.js';\nexport { LocalProcessInspector } from './durable/DurableAgentRepository.js';\nexport type {\n CreateDurableAgentInput,\n DurableAgentRepositoryOptions,\n ProcessInspector,\n DurableRunCompletion,\n} from './durable/DurableAgentRepository.js';\nexport { ClaudeCliProbe } from './durable/ClaudeCliProbe.js';\nexport type { ClaudeCliProbeOptions } from './durable/ClaudeCliProbe.js';\nexport { ClaudePrintRunner } from './durable/ClaudePrintRunner.js';\nexport type {\n ClaudePrintRunnerOptions,\n ClaudePrintRunRequest,\n ClaudePrintRunResult,\n} from './durable/ClaudePrintRunner.js';\nexport { ClaudePrintAgentService } from './durable/ClaudePrintAgentService.js';\nexport type {\n ClaudePrintAgentServiceOptions,\n ClaudePrintSendResult,\n} from './durable/ClaudePrintAgentService.js';\n"],"names":["AgentManager","AgentNotRunningError","ClaudeCodeAdapter","CodexAdapter","CopilotAdapter","GeminiCliAdapter","GrokCliAdapter","OpenCodeAdapter","PiAdapter","AgentStatus","TerminalFocusManager","TerminalType","TtyWriter","getProcessTty","captureProcessSnapshot","executableBasename","filterByProcessNames","AgentRegistry","RenameNotFoundError","RenameConflictError","TmuxManager","AGENTS","getAgentRequestPath","readLatestAgentRequest","writeAgentRequest","AGENT_MODES","DurableAgentError","DurableAgentBusyError","DurableAgentNotFoundError","DurableAgentRepositoryError","DurableAgentNameConflictError","ClaudePrintError","DurableAgentRepository","LocalProcessInspector","ClaudeCliProbe","ClaudePrintRunner","ClaudePrintAgentService"],"mappings":"AAAA,SAASA,YAAY,EAAEC,oBAAoB,QAAQ,oBAAoB;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { AgentManager, AgentNotRunningError } from './AgentManager.js';\nexport { getCodexCapacityReport } from './capacity/index.js';\nexport type {\n CapacityProbeOptions,\n CapacityReport,\n CapacityWindow,\n} from './capacity/index.js';\n\nexport { ClaudeCodeAdapter } from './adapters/ClaudeCodeAdapter.js';\nexport { CodexAdapter } from './adapters/CodexAdapter.js';\nexport { CopilotAdapter } from './adapters/CopilotAdapter.js';\nexport { GeminiCliAdapter } from './adapters/GeminiCliAdapter.js';\nexport { GrokCliAdapter } from './adapters/GrokCliAdapter.js';\nexport { OpenCodeAdapter } from './adapters/OpenCodeAdapter.js';\nexport { PiAdapter } from './adapters/PiAdapter.js';\nexport { AgentStatus } from './adapters/AgentAdapter.js';\nexport type {\n AgentAdapter,\n AgentType,\n AgentInfo,\n ProcessInfo,\n ConversationMessage,\n SessionSummary,\n ListSessionsOptions,\n AgentDetectionContext,\n} from './adapters/AgentAdapter.js';\n\nexport { TerminalFocusManager, TerminalType } from './terminal/TerminalFocusManager.js';\nexport type { TerminalLocation } from './terminal/TerminalFocusManager.js';\nexport { TtyWriter } from './terminal/TtyWriter.js';\n\nexport { getProcessTty } from './utils/process.js';\nexport { captureProcessSnapshot, executableBasename, filterByProcessNames } from './utils/process.js';\nexport type { AgentSortKey } from './utils/sortAgents.js';\nexport type { ListAgentsOptions } from './AgentManager.js';\n\nexport { AgentRegistry, RenameNotFoundError, RenameConflictError } from './utils/AgentRegistry.js';\nexport type { AgentRegistryOptions, RegistryEntry } from './utils/AgentRegistry.js';\nexport { TmuxManager } from './terminal/TmuxManager.js';\nexport { AGENTS } from './utils/agents.js';\nexport type { AgentConfig, StartableAgentType } from './utils/agents.js';\n\nexport type { AgentRequest } from './utils/agent-requests.js';\nexport { getAgentRequestPath, readLatestAgentRequest, writeAgentRequest } from './utils/agent-requests.js';\n\nexport {\n AGENT_MODES,\n DurableAgentError,\n DurableAgentBusyError,\n DurableAgentNotFoundError,\n DurableAgentRepositoryError,\n DurableAgentNameConflictError,\n ClaudePrintError,\n} from './durable/DurableAgent.js';\nexport type {\n DurableAgent,\n DurableAgentState,\n DurableSessionHealth,\n DurableRunStatus,\n DurableActiveRun,\n DurableLastResult,\n ProcessIdentity,\n} from './durable/DurableAgent.js';\nexport { DurableAgentRepository } from './durable/DurableAgentRepository.js';\nexport { LocalProcessInspector } from './durable/DurableAgentRepository.js';\nexport type {\n CreateDurableAgentInput,\n DurableAgentRepositoryOptions,\n ProcessInspector,\n DurableRunCompletion,\n} from './durable/DurableAgentRepository.js';\nexport { ClaudeCliProbe } from './durable/ClaudeCliProbe.js';\nexport type { ClaudeCliProbeOptions } from './durable/ClaudeCliProbe.js';\nexport { ClaudePrintRunner } from './durable/ClaudePrintRunner.js';\nexport type {\n ClaudePrintRunnerOptions,\n ClaudePrintRunRequest,\n ClaudePrintRunResult,\n} from './durable/ClaudePrintRunner.js';\nexport { ClaudePrintAgentService } from './durable/ClaudePrintAgentService.js';\nexport type {\n ClaudePrintAgentServiceOptions,\n ClaudePrintSendResult,\n} from './durable/ClaudePrintAgentService.js';\n"],"names":["AgentManager","AgentNotRunningError","getCodexCapacityReport","ClaudeCodeAdapter","CodexAdapter","CopilotAdapter","GeminiCliAdapter","GrokCliAdapter","OpenCodeAdapter","PiAdapter","AgentStatus","TerminalFocusManager","TerminalType","TtyWriter","getProcessTty","captureProcessSnapshot","executableBasename","filterByProcessNames","AgentRegistry","RenameNotFoundError","RenameConflictError","TmuxManager","AGENTS","getAgentRequestPath","readLatestAgentRequest","writeAgentRequest","AGENT_MODES","DurableAgentError","DurableAgentBusyError","DurableAgentNotFoundError","DurableAgentRepositoryError","DurableAgentNameConflictError","ClaudePrintError","DurableAgentRepository","LocalProcessInspector","ClaudeCliProbe","ClaudePrintRunner","ClaudePrintAgentService"],"mappings":"AAAA,SAASA,YAAY,EAAEC,oBAAoB,QAAQ,oBAAoB;AACvE,SAASC,sBAAsB,QAAQ,sBAAsB;AAO7D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,gBAAgB,QAAQ,iCAAiC;AAClE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,SAAS,QAAQ,0BAA0B;AACpD,SAASC,WAAW,QAAQ,6BAA6B;AAYzD,SAASC,oBAAoB,EAAEC,YAAY,QAAQ,qCAAqC;AAExF,SAASC,SAAS,QAAQ,0BAA0B;AAEpD,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,sBAAsB,EAAEC,kBAAkB,EAAEC,oBAAoB,QAAQ,qBAAqB;AAItG,SAASC,aAAa,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,2BAA2B;AAEnG,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,MAAM,QAAQ,oBAAoB;AAI3C,SAASC,mBAAmB,EAAEC,sBAAsB,EAAEC,iBAAiB,QAAQ,4BAA4B;AAE3G,SACIC,WAAW,EACXC,iBAAiB,EACjBC,qBAAqB,EACrBC,yBAAyB,EACzBC,2BAA2B,EAC3BC,6BAA6B,EAC7BC,gBAAgB,QACb,4BAA4B;AAUnC,SAASC,sBAAsB,QAAQ,sCAAsC;AAC7E,SAASC,qBAAqB,QAAQ,sCAAsC;AAO5E,SAASC,cAAc,QAAQ,8BAA8B;AAE7D,SAASC,iBAAiB,QAAQ,iCAAiC;AAMnE,SAASC,uBAAuB,QAAQ,uCAAuC"}
|