@opencorelabs/lucidity 0.7.0 → 0.8.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/README.md +9 -2
- package/dist/assets/speech/lucidity-speech +0 -0
- package/dist/automations/agent.d.ts.map +1 -1
- package/dist/automations/agent.js +2 -0
- package/dist/automations/designer.d.ts +1 -1
- package/dist/chat/server.d.ts +1 -0
- package/dist/chat/server.d.ts.map +1 -1
- package/dist/chat/server.js +6 -1
- package/dist/coding/conduct.d.ts +1 -22
- package/dist/coding/conduct.d.ts.map +1 -1
- package/dist/coding/conduct.js +9 -94
- package/dist/coding/runCodeTurn.d.ts +3 -16
- package/dist/coding/runCodeTurn.d.ts.map +1 -1
- package/dist/coding/runCodeTurn.js +157 -165
- package/dist/coding/workspaceRegistry.d.ts +24 -0
- package/dist/coding/workspaceRegistry.d.ts.map +1 -0
- package/dist/coding/workspaceRegistry.js +230 -0
- package/dist/coding/worktree.d.ts +11 -14
- package/dist/coding/worktree.d.ts.map +1 -1
- package/dist/coding/worktree.js +41 -21
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/daemonLease.d.ts +12 -0
- package/dist/daemonLease.d.ts.map +1 -0
- package/dist/daemonLease.js +32 -0
- package/dist/goals/assessment.d.ts +115 -0
- package/dist/goals/assessment.d.ts.map +1 -0
- package/dist/goals/assessment.js +67 -0
- package/dist/goals/notes.d.ts +18 -0
- package/dist/goals/notes.d.ts.map +1 -0
- package/dist/goals/notes.js +72 -0
- package/dist/index.js +57 -15
- package/dist/jobs/goals.d.ts +15 -0
- package/dist/jobs/goals.d.ts.map +1 -0
- package/dist/jobs/goals.js +286 -0
- package/dist/jobs/weeklyReview.d.ts.map +1 -1
- package/dist/jobs/weeklyReview.js +3 -2
- package/dist/queue.d.ts +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +4 -0
- package/dist/room/client.d.ts +5 -0
- package/dist/room/client.d.ts.map +1 -1
- package/dist/room/client.js +116 -101
- package/dist/room/computer.d.ts.map +1 -1
- package/dist/room/computer.js +1 -0
- package/dist/room/durablePublish.d.ts +6 -0
- package/dist/room/durablePublish.d.ts.map +1 -0
- package/dist/room/durablePublish.js +19 -0
- package/dist/room/incidents.d.ts +1 -1
- package/dist/room/incidents.d.ts.map +1 -1
- package/dist/room/incidents.js +14 -7
- package/dist/room/turnQueue.d.ts.map +1 -1
- package/dist/room/turnQueue.js +27 -24
- package/dist/runtimeStore.d.ts +44 -0
- package/dist/runtimeStore.d.ts.map +1 -0
- package/dist/runtimeStore.js +188 -0
- package/dist/setup/server.js +1 -1
- package/dist/turnLog.d.ts +10 -40
- package/dist/turnLog.d.ts.map +1 -1
- package/dist/turnLog.js +33 -56
- package/package.json +4 -4
- package/src/automations/agent.ts +2 -0
- package/src/chat/server.ts +7 -1
- package/src/coding/conduct.ts +10 -147
- package/src/coding/runCodeTurn.ts +42 -61
- package/src/coding/workspaceRegistry.ts +210 -0
- package/src/coding/worktree.ts +44 -20
- package/src/config.ts +2 -0
- package/src/daemonLease.ts +33 -0
- package/src/goals/assessment.ts +106 -0
- package/src/goals/notes.ts +88 -0
- package/src/index.ts +57 -18
- package/src/jobs/goals.ts +384 -0
- package/src/jobs/weeklyReview.ts +4 -3
- package/src/queue.ts +4 -0
- package/src/room/client.ts +77 -74
- package/src/room/computer.ts +1 -0
- package/src/room/durablePublish.ts +25 -0
- package/src/room/incidents.ts +16 -8
- package/src/room/turnQueue.ts +26 -27
- package/src/runtimeStore.ts +190 -0
- package/src/setup/server.ts +1 -1
- package/src/turnLog.ts +32 -75
- package/vendor/mcp-server/dist/index.js +2 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/goals.js +38 -0
- package/vendor/mcp-server/package.json +1 -1
- package/vendor/mcp-server/src/index.ts +2 -0
- package/vendor/mcp-server/src/tools/goals.ts +62 -0
- package/vendor/runtime/README.md +2 -2
- package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
- package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.js +20 -9
- package/vendor/runtime/dist/executor/codex.d.ts +1 -0
- package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codex.js +68 -36
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.d.ts +10 -3
- package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.js +18 -3
- package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
- package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexSessions.js +88 -0
- package/vendor/runtime/dist/executor/health.d.ts +2 -1
- package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/health.js +17 -5
- package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
- package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/liveTurns.js +12 -5
- package/vendor/runtime/dist/executor/ownership.d.ts +35 -0
- package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/ownership.js +99 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/providerRouter.js +5 -0
- package/vendor/runtime/dist/executor/types.d.ts +2 -0
- package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
- package/vendor/runtime/dist/index.d.ts +1 -0
- package/vendor/runtime/dist/index.d.ts.map +1 -1
- package/vendor/runtime/dist/index.js +1 -0
- package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
- package/vendor/runtime/src/executor/claudeAgent.ts +16 -9
- package/vendor/runtime/src/executor/codex.ts +75 -44
- package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
- package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
- package/vendor/runtime/src/executor/codexRpc.ts +22 -4
- package/vendor/runtime/src/executor/codexSessions.ts +108 -0
- package/vendor/runtime/src/executor/health.ts +16 -6
- package/vendor/runtime/src/executor/liveTurns.ts +12 -5
- package/vendor/runtime/src/executor/ownership.ts +76 -0
- package/vendor/runtime/src/executor/providerRouter.ts +6 -0
- package/vendor/runtime/src/executor/types.ts +2 -0
- package/vendor/runtime/src/index.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.d.ts +41 -0
- package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.js +13 -3
- package/vendor/shared/dist/computer.d.ts +7 -1
- package/vendor/shared/dist/computer.d.ts.map +1 -1
- package/vendor/shared/dist/computer.js +12 -2
- package/vendor/shared/dist/constants.d.ts +3 -3
- package/vendor/shared/dist/constants.d.ts.map +1 -1
- package/vendor/shared/dist/constants.js +5 -4
- package/vendor/shared/dist/goalNotes.d.ts +4 -0
- package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
- package/vendor/shared/dist/goalNotes.js +23 -0
- package/vendor/shared/dist/goals.d.ts +835 -0
- package/vendor/shared/dist/goals.d.ts.map +1 -0
- package/vendor/shared/dist/goals.js +198 -0
- package/vendor/shared/dist/index.d.ts +3 -0
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +3 -0
- package/vendor/shared/dist/schemas/harness.d.ts +101 -0
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +6 -0
- package/vendor/shared/dist/workspaces.d.ts +138 -0
- package/vendor/shared/dist/workspaces.d.ts.map +1 -0
- package/vendor/shared/dist/workspaces.js +40 -0
- package/vendor/shared/src/agentCommands.ts +1 -0
- package/vendor/shared/src/cardStudio.ts +13 -3
- package/vendor/shared/src/computer.ts +16 -2
- package/vendor/shared/src/constants.ts +5 -4
- package/vendor/shared/src/goalNotes.ts +23 -0
- package/vendor/shared/src/goals.ts +237 -0
- package/vendor/shared/src/index.ts +4 -0
- package/vendor/shared/src/schemas/harness.ts +6 -0
- package/vendor/shared/src/workspaces.ts +48 -0
- package/dist/coding/fleetIntegrate.d.ts +0 -37
- package/dist/coding/fleetIntegrate.d.ts.map +0 -1
- package/dist/coding/fleetIntegrate.js +0 -64
- package/dist/coding/openFleetPr.d.ts +0 -41
- package/dist/coding/openFleetPr.d.ts.map +0 -1
- package/dist/coding/openFleetPr.js +0 -121
- package/src/coding/fleetIntegrate.ts +0 -95
- package/src/coding/openFleetPr.ts +0 -148
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
type RpcMessage,
|
|
13
13
|
} from './codexRpc.js';
|
|
14
14
|
import { LiveTurns, abortError } from './liveTurns.js';
|
|
15
|
+
import {
|
|
16
|
+
CodexSessions,
|
|
17
|
+
codexBindingFingerprint,
|
|
18
|
+
type CodexThread,
|
|
19
|
+
} from './codexSessions.js';
|
|
15
20
|
import type {
|
|
16
21
|
AgentExecutor,
|
|
17
22
|
ExecutorRunInput,
|
|
@@ -157,6 +162,7 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
157
162
|
readonly name = 'codex-app-server';
|
|
158
163
|
readonly strictResume = true;
|
|
159
164
|
private readonly turns = new LiveTurns();
|
|
165
|
+
private readonly sessions = new CodexSessions();
|
|
160
166
|
constructor(
|
|
161
167
|
private readonly options: {
|
|
162
168
|
command?: string;
|
|
@@ -175,7 +181,7 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
175
181
|
return this.turns.interrupt(requestId);
|
|
176
182
|
}
|
|
177
183
|
async dispose() {
|
|
178
|
-
this.turns.dispose();
|
|
184
|
+
await Promise.all([this.turns.dispose(), this.sessions.dispose()]);
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
async models(): Promise<ExecutorModel[]> {
|
|
@@ -206,7 +212,7 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
206
212
|
} while (cursor);
|
|
207
213
|
return models;
|
|
208
214
|
} finally {
|
|
209
|
-
rpc.close();
|
|
215
|
+
await rpc.close();
|
|
210
216
|
}
|
|
211
217
|
}
|
|
212
218
|
|
|
@@ -313,39 +319,38 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
313
319
|
let threadId = '';
|
|
314
320
|
let turnId = '';
|
|
315
321
|
let ended = false;
|
|
316
|
-
|
|
317
|
-
let
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
rpc.close();
|
|
335
|
-
throw error;
|
|
336
|
-
}
|
|
322
|
+
let rpc: CodexConnection | undefined;
|
|
323
|
+
let thread: CodexThread | undefined;
|
|
324
|
+
let fingerprint = '';
|
|
325
|
+
let reusable = false;
|
|
326
|
+
const owner = this.turns.open(input, async (text) => {
|
|
327
|
+
if (command)
|
|
328
|
+
throw new Error(
|
|
329
|
+
'Wait for the command to finish before sending a message.',
|
|
330
|
+
);
|
|
331
|
+
if (!rpc || !turnId || ended)
|
|
332
|
+
throw new Error('Codex has no active turn to steer.');
|
|
333
|
+
const params: TurnSteerParams = {
|
|
334
|
+
threadId,
|
|
335
|
+
expectedTurnId: turnId,
|
|
336
|
+
input: userInput({ userPrompt: text }),
|
|
337
|
+
};
|
|
338
|
+
await rpc.request('turn/steer', params);
|
|
339
|
+
});
|
|
337
340
|
const abort = () => {
|
|
341
|
+
const active = rpc;
|
|
342
|
+
if (!active) return;
|
|
338
343
|
if (turnId && !ended) {
|
|
339
|
-
void
|
|
344
|
+
void active
|
|
340
345
|
.request('turn/interrupt', { threadId, turnId })
|
|
341
346
|
.catch(() => {})
|
|
342
|
-
.finally(() =>
|
|
343
|
-
const timer = setTimeout(() =>
|
|
347
|
+
.finally(() => active.close());
|
|
348
|
+
const timer = setTimeout(() => active.close(), 1000);
|
|
344
349
|
timer.unref();
|
|
345
|
-
} else
|
|
350
|
+
} else active.close();
|
|
346
351
|
};
|
|
347
352
|
owner.controller.signal.addEventListener('abort', abort, { once: true });
|
|
348
|
-
|
|
353
|
+
const onRequest = async (request: RpcMessage) => {
|
|
349
354
|
const p = request.params ?? {};
|
|
350
355
|
if (
|
|
351
356
|
ended ||
|
|
@@ -388,7 +393,21 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
388
393
|
};
|
|
389
394
|
try {
|
|
390
395
|
owner.check();
|
|
391
|
-
await
|
|
396
|
+
const pooled = await this.sessions.take(input.resume);
|
|
397
|
+
rpc = pooled?.rpc ?? this.connect(input.cwd);
|
|
398
|
+
rpc.onRequest = onRequest;
|
|
399
|
+
owner.check();
|
|
400
|
+
if (!pooled) await initializeCodex(rpc);
|
|
401
|
+
else {
|
|
402
|
+
const account = await rpc.request<{ account: { type: string } | null }>(
|
|
403
|
+
'account/read',
|
|
404
|
+
{ refreshToken: false },
|
|
405
|
+
);
|
|
406
|
+
if (account.account?.type !== 'chatgpt')
|
|
407
|
+
throw new Error(
|
|
408
|
+
'Codex needs ChatGPT subscription login. Run codex login on this computer.',
|
|
409
|
+
);
|
|
410
|
+
}
|
|
392
411
|
const inherited = await rpc.request<{ config: Record<string, unknown> }>(
|
|
393
412
|
'config/read',
|
|
394
413
|
{ includeLayers: false, cwd: input.cwd },
|
|
@@ -416,19 +435,25 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
416
435
|
developerInstructions: input.systemPrompt,
|
|
417
436
|
config: codexRunConfig(input, inherited.config),
|
|
418
437
|
};
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
model
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
438
|
+
fingerprint = codexBindingFingerprint(params);
|
|
439
|
+
if (pooled && pooled.fingerprint !== fingerprint) {
|
|
440
|
+
// Permissions, MCP tools, model, cwd or instructions changed. A new transport
|
|
441
|
+
// resumes only after the old owner has fully exited.
|
|
442
|
+
await rpc.close();
|
|
443
|
+
owner.check();
|
|
444
|
+
rpc = this.connect(input.cwd);
|
|
445
|
+
rpc.onRequest = onRequest;
|
|
446
|
+
await initializeCodex(rpc);
|
|
447
|
+
}
|
|
448
|
+
thread =
|
|
449
|
+
pooled?.fingerprint === fingerprint
|
|
450
|
+
? pooled.thread
|
|
451
|
+
: input.resume && !isEmptySession(input.resume)
|
|
452
|
+
? await rpc.request<CodexThread>('thread/resume', {
|
|
453
|
+
...params,
|
|
454
|
+
threadId: input.resume,
|
|
455
|
+
} satisfies ThreadResumeParams)
|
|
456
|
+
: await rpc.request<CodexThread>('thread/start', params);
|
|
432
457
|
threadId = thread.thread.id;
|
|
433
458
|
const sessionId =
|
|
434
459
|
isEmptySession(input.resume) &&
|
|
@@ -604,6 +629,7 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
604
629
|
throw new Error(
|
|
605
630
|
completed.error?.message ?? `Codex turn ${completed.status}.`,
|
|
606
631
|
);
|
|
632
|
+
reusable = true;
|
|
607
633
|
if (command)
|
|
608
634
|
yield {
|
|
609
635
|
type: 'tool_call',
|
|
@@ -631,8 +657,13 @@ export class CodexExecutor implements AgentExecutor {
|
|
|
631
657
|
} finally {
|
|
632
658
|
ended = true;
|
|
633
659
|
owner.controller.signal.removeEventListener('abort', abort);
|
|
634
|
-
|
|
635
|
-
|
|
660
|
+
try {
|
|
661
|
+
if (rpc && reusable && thread && !owner.controller.signal.aborted)
|
|
662
|
+
await this.sessions.keep({ rpc, thread, fingerprint });
|
|
663
|
+
else await rpc?.close();
|
|
664
|
+
} finally {
|
|
665
|
+
owner.close();
|
|
666
|
+
}
|
|
636
667
|
}
|
|
637
668
|
}
|
|
638
669
|
}
|
|
@@ -7,4 +7,4 @@ import type { ImageDetail } from "./ImageDetail.js";
|
|
|
7
7
|
* Responses API compatible content items that can be returned by a tool call.
|
|
8
8
|
* This is a subset of ContentItem with the types we support as function call outputs.
|
|
9
9
|
*/
|
|
10
|
-
export type FunctionCallOutputContentItem = { "type": "input_text", text: string, } | { "type": "input_image", image_url: string,
|
|
10
|
+
export type FunctionCallOutputContentItem = { "type": "input_text", text: string, } | { "type": "input_image", detail?: ImageDetail, } & ({ image_url: string, } | { file_id: string, }) | { "type": "input_audio", audio_url: string, } | { "type": "encrypted_content", encrypted_content: string, };
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
4
4
|
|
|
5
|
-
export type PlanType = "free" | "go" | "plus" | "pro" | "prolite" | "team" | "self_serve_business_prolite" | "self_serve_business_usage_based" | "business" | "ent26" | "enterprise_cbp_automation" | "enterprise_cbp_usage_based" | "enterprise" | "edu" | "edu_plus" | "edu_pro" | "unknown";
|
|
5
|
+
export type PlanType = "free" | "go" | "plus" | "pro" | "prolite" | "promax" | "team" | "self_serve_business_prolite" | "self_serve_business_usage_based" | "business" | "ent26" | "enterprise_cbp_automation" | "enterprise_cbp_usage_based" | "enterprise" | "edu" | "edu_plus" | "edu_pro" | "unknown";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Codex App Server protocol
|
|
2
2
|
|
|
3
|
-
Generated from the pinned `@openai/codex` **0.
|
|
4
|
-
Apache-2.0). Source: https://github.com/openai/codex/tree/rust-v0.
|
|
3
|
+
Generated from the pinned `@openai/codex` **0.160.0** runtime (OpenAI Codex,
|
|
4
|
+
Apache-2.0). Source: https://github.com/openai/codex/tree/rust-v0.160.0
|
|
5
5
|
|
|
6
6
|
Run `node scripts/generate-codex-protocol.mjs` from `packages/runtime` after
|
|
7
7
|
installing dependencies. The script keeps the adapter's transitive type subset
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
|
2
|
+
|
|
3
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Requested cyber treatment for a ChatGPT-authenticated Codex turn.
|
|
7
|
+
* Authorization and model-tier restrictions remain server-owned.
|
|
8
|
+
*/
|
|
9
|
+
export type CyberAccessProgram = "standard" | "daybreakBlue" | "daybreakRed";
|
|
@@ -6,6 +6,11 @@ import type { RateLimitResetCreditsSummary } from "./RateLimitResetCreditsSummar
|
|
|
6
6
|
import type { RateLimitSnapshot } from "./RateLimitSnapshot.js";
|
|
7
7
|
|
|
8
8
|
export type GetAccountRateLimitsResponse = {
|
|
9
|
+
/**
|
|
10
|
+
* Backend permission for ordinary included usage, validated against the active account.
|
|
11
|
+
* Null means unavailable; clients must not infer recovery from percentages or reset times.
|
|
12
|
+
*/
|
|
13
|
+
ordinaryUsageAllowed: boolean | null,
|
|
9
14
|
/**
|
|
10
15
|
* Backward-compatible single-bucket view; mirrors the historical payload.
|
|
11
16
|
*/
|
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
4
4
|
import type { InputModality } from "../InputModality.js";
|
|
5
5
|
import type { ReasoningEffort } from "../ReasoningEffort.js";
|
|
6
|
+
import type { ModelAccessPrograms } from "./ModelAccessPrograms.js";
|
|
6
7
|
import type { ModelAvailabilityNux } from "./ModelAvailabilityNux.js";
|
|
7
8
|
import type { ModelServiceTier } from "./ModelServiceTier.js";
|
|
8
9
|
import type { ModelUpgradeInfo } from "./ModelUpgradeInfo.js";
|
|
9
10
|
import type { MultiAgentVersion } from "./MultiAgentVersion.js";
|
|
10
11
|
import type { ReasoningEffortOption } from "./ReasoningEffortOption.js";
|
|
11
12
|
|
|
12
|
-
export type Model = { id: string, model: string, upgrade: string | null, upgradeInfo: ModelUpgradeInfo | null, availabilityNux: ModelAvailabilityNux | null, displayName: string, description: string, modelSpecialty: string | null, hidden: boolean, supportedReasoningEfforts: Array<ReasoningEffortOption>, defaultReasoningEffort: ReasoningEffort, inputModalities: Array<InputModality>,
|
|
13
|
+
export type Model = { id: string, model: string, upgrade: string | null, upgradeInfo: ModelUpgradeInfo | null, availabilityNux: ModelAvailabilityNux | null, displayName: string, description: string, modelSpecialty: string | null, hidden: boolean, supportedReasoningEfforts: Array<ReasoningEffortOption>, defaultReasoningEffort: ReasoningEffort, inputModalities: Array<InputModality>,
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Always false; models no longer support personality selection.
|
|
16
|
+
*/
|
|
17
|
+
supportsPersonality: boolean,
|
|
13
18
|
/**
|
|
14
19
|
* Multi-agent runtime declared by this model, when available.
|
|
15
20
|
*/
|
|
@@ -21,4 +26,8 @@ additionalSpeedTiers: Array<string>, serviceTiers: Array<ModelServiceTier>,
|
|
|
21
26
|
/**
|
|
22
27
|
* Catalog default service tier id for this model, when one is configured.
|
|
23
28
|
*/
|
|
24
|
-
defaultServiceTier: string | null,
|
|
29
|
+
defaultServiceTier: string | null,
|
|
30
|
+
/**
|
|
31
|
+
* Null when the catalog does not provide access-program metadata.
|
|
32
|
+
*/
|
|
33
|
+
availableAccessPrograms: ModelAccessPrograms | null, isDefault: boolean, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
|
2
|
+
|
|
3
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
4
|
+
import type { CyberAccessProgram } from "./CyberAccessProgram.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Caller-specific explicit access programs advertised by model discovery.
|
|
8
|
+
*/
|
|
9
|
+
export type ModelAccessPrograms = {
|
|
10
|
+
/**
|
|
11
|
+
* Accepted explicit selections.
|
|
12
|
+
*/
|
|
13
|
+
cyber: Array<CyberAccessProgram>, };
|
|
@@ -7,7 +7,11 @@ import type { RateLimitReachedType } from "./RateLimitReachedType.js";
|
|
|
7
7
|
import type { RateLimitWindow } from "./RateLimitWindow.js";
|
|
8
8
|
import type { SpendControlLimitSnapshot } from "./SpendControlLimitSnapshot.js";
|
|
9
9
|
|
|
10
|
-
export type RateLimitSnapshot = { limitId: string | null, limitName: string | null,
|
|
10
|
+
export type RateLimitSnapshot = { limitId: string | null, limitName: string | null,
|
|
11
|
+
/**
|
|
12
|
+
* Normal model whose display name and reasoning options describe this quota alias.
|
|
13
|
+
*/
|
|
14
|
+
normalModelSlug: string | null, primary: RateLimitWindow | null, secondary: RateLimitWindow | null, credits: CreditsSnapshot | null, individualLimit: SpendControlLimitSnapshot | null,
|
|
11
15
|
/**
|
|
12
16
|
* Backend-reported spend-control state. `None` is unavailable, not a sparse-update recovery.
|
|
13
17
|
*/
|
|
@@ -8,5 +8,7 @@ export type ReviewStartParams = { threadId: string, target: ReviewTarget,
|
|
|
8
8
|
/**
|
|
9
9
|
* Where to run the review: inline (default) on the current thread or
|
|
10
10
|
* detached on a new thread (returned in `reviewThreadId`).
|
|
11
|
+
* Detached delivery is deprecated and emits `deprecationNotice`.
|
|
12
|
+
* Use `thread/start` followed by an inline review for a separate review thread.
|
|
11
13
|
*/
|
|
12
14
|
delivery?: ReviewDelivery | null, };
|
|
@@ -30,7 +30,11 @@ model?: string | null, modelProvider?: string | null, serviceTier?: string | nul
|
|
|
30
30
|
* Override where approval requests are routed for review on this thread
|
|
31
31
|
* and subsequent turns.
|
|
32
32
|
*/
|
|
33
|
-
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, developerInstructions?: string | null,
|
|
33
|
+
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, baseInstructions?: string | null, developerInstructions?: string | null, /**
|
|
34
|
+
* @deprecated `friendly` and `pragmatic` no longer select a style.
|
|
35
|
+
* Changing this does not rewrite the thread's existing instructions.
|
|
36
|
+
*/
|
|
37
|
+
personality?: Personality | null, /**
|
|
34
38
|
* When true, return only thread metadata and live-resume state without
|
|
35
39
|
* populating `thread.turns`. This is useful when the client plans to call
|
|
36
40
|
* `thread/turns/list` immediately after resuming. Full-history hydration
|
|
@@ -13,7 +13,10 @@ export type ThreadStartParams = {model?: string | null, modelProvider?: string |
|
|
|
13
13
|
* Override where approval requests are routed for review on this thread
|
|
14
14
|
* and subsequent turns.
|
|
15
15
|
*/
|
|
16
|
-
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, serviceName?: string | null, baseInstructions?: string | null, developerInstructions?: string | null,
|
|
16
|
+
approvalsReviewer?: ApprovalsReviewer | null, sandbox?: SandboxMode | null, config?: { [key in string]?: JsonValue } | null, serviceName?: string | null, baseInstructions?: string | null, developerInstructions?: string | null, /**
|
|
17
|
+
* @deprecated `friendly` and `pragmatic` no longer select a style.
|
|
18
|
+
*/
|
|
19
|
+
personality?: Personality | null, ephemeral?: boolean | null, sessionStartSource?: ThreadStartSource | null, /**
|
|
17
20
|
* Optional client-supplied analytics source classification for this thread.
|
|
18
21
|
*/
|
|
19
22
|
threadSource?: ThreadSource | null};
|
|
@@ -11,7 +11,11 @@ import type { SandboxPolicy } from "./SandboxPolicy.js";
|
|
|
11
11
|
import type { TurnToolOutput } from "./TurnToolOutput.js";
|
|
12
12
|
import type { UserInput } from "./UserInput.js";
|
|
13
13
|
|
|
14
|
-
export type TurnStartParams = {threadId: string,
|
|
14
|
+
export type TurnStartParams = {threadId: string, /**
|
|
15
|
+
* Replace this thread's disabled plugin IDs.
|
|
16
|
+
* Omitted/null preserves the list; [] clears it.
|
|
17
|
+
*/
|
|
18
|
+
disabledPluginIds?: Array<string> | null, clientUserMessageId?: string | null, input: Array<UserInput>, /**
|
|
15
19
|
* Optional source classification for the caller that starts this turn.
|
|
16
20
|
* Ignored when this request steers an already-active turn.
|
|
17
21
|
*/
|
|
@@ -46,7 +50,8 @@ effort?: ReasoningEffort | null, /**
|
|
|
46
50
|
* Override the reasoning summary for this turn and subsequent turns.
|
|
47
51
|
*/
|
|
48
52
|
summary?: ReasoningSummary | null, /**
|
|
49
|
-
*
|
|
53
|
+
* @deprecated `friendly` and `pragmatic` no longer select a style.
|
|
54
|
+
* Changing this does not rewrite the thread's existing instructions.
|
|
50
55
|
*/
|
|
51
56
|
personality?: Personality | null, /**
|
|
52
57
|
* Optional JSON Schema used to constrain the final assistant message for
|
|
@@ -8,4 +8,4 @@ export type UserInput = { "type": "text", text: string,
|
|
|
8
8
|
/**
|
|
9
9
|
* UI-defined spans within `text` used to render or persist special elements.
|
|
10
10
|
*/
|
|
11
|
-
text_elements: Array<TextElement>, } | { "type": "image", detail?: ImageDetail, url: string, } | { "type": "localImage", detail?: ImageDetail, path: string, } | { "type": "audio", url: string, } | { "type": "localAudio", path: string, } | { "type": "skill", name: string, path: string, } | { "type": "mention", name: string, path: string, };
|
|
11
|
+
text_elements: Array<TextElement>, } | { "type": "image", detail?: ImageDetail, } & ({ url: string, } | { fileId: string, }) | { "type": "localImage", detail?: ImageDetail, path: string, } | { "type": "audio", url: string, } | { "type": "localAudio", path: string, } | { "type": "skill", name: string, path: string, } | { "type": "mention", name: string, path: string, };
|
|
@@ -9,7 +9,7 @@ const { version: lucidityVersion } = require('../../package.json') as {
|
|
|
9
9
|
version: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const CODEX_RUNTIME_VERSION = '0.
|
|
12
|
+
export const CODEX_RUNTIME_VERSION = '0.160.0';
|
|
13
13
|
export interface RpcMessage {
|
|
14
14
|
id?: number | string;
|
|
15
15
|
method?: string;
|
|
@@ -18,11 +18,14 @@ export interface RpcMessage {
|
|
|
18
18
|
error?: { message: string };
|
|
19
19
|
}
|
|
20
20
|
export interface CodexConnection {
|
|
21
|
+
readonly isConnected?: boolean;
|
|
21
22
|
events: AsyncIterable<RpcMessage>;
|
|
22
23
|
request<T>(method: string, params: unknown): Promise<T>;
|
|
23
24
|
respond(id: number | string, result: unknown): void;
|
|
24
25
|
onRequest?: (message: RpcMessage) => Promise<unknown>;
|
|
25
|
-
|
|
26
|
+
/** Completed turns may retain the transport while discarding idle notifications. */
|
|
27
|
+
setIdle?(idle: boolean): void;
|
|
28
|
+
close(): void | Promise<void>;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export function codexSubscriptionEnv(): NodeJS.ProcessEnv {
|
|
@@ -37,8 +40,13 @@ export class CodexRpc implements CodexConnection {
|
|
|
37
40
|
readonly events = new AsyncQueue<RpcMessage>();
|
|
38
41
|
onRequest?: (message: RpcMessage) => Promise<unknown>;
|
|
39
42
|
private child: ChildProcessWithoutNullStreams;
|
|
43
|
+
private readonly exited: Promise<void>;
|
|
40
44
|
private sequence = 0;
|
|
41
45
|
private closed = false;
|
|
46
|
+
private idle = false;
|
|
47
|
+
get isConnected(): boolean {
|
|
48
|
+
return !this.closed;
|
|
49
|
+
}
|
|
42
50
|
private pending = new Map<
|
|
43
51
|
number,
|
|
44
52
|
{
|
|
@@ -70,6 +78,10 @@ export class CodexRpc implements CodexConnection {
|
|
|
70
78
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
71
79
|
},
|
|
72
80
|
);
|
|
81
|
+
this.exited = new Promise((resolve) => {
|
|
82
|
+
this.child.once('close', () => resolve());
|
|
83
|
+
this.child.once('error', () => resolve());
|
|
84
|
+
});
|
|
73
85
|
// Drain stderr without retaining potentially sensitive prompt/config diagnostics.
|
|
74
86
|
this.child.stderr.on('data', () => {});
|
|
75
87
|
this.child.stdin.on('error', () => {});
|
|
@@ -108,7 +120,8 @@ export class CodexRpc implements CodexConnection {
|
|
|
108
120
|
clearTimeout(pending.timer);
|
|
109
121
|
if (message.error) pending.reject(new Error(message.error.message));
|
|
110
122
|
else pending.resolve(message.result);
|
|
111
|
-
} else if (message.method && !this.closed
|
|
123
|
+
} else if (message.method && !this.closed && !this.idle)
|
|
124
|
+
this.events.push(message);
|
|
112
125
|
});
|
|
113
126
|
}
|
|
114
127
|
|
|
@@ -116,6 +129,10 @@ export class CodexRpc implements CodexConnection {
|
|
|
116
129
|
if (this.closed) throw new Error('Codex is disconnected.');
|
|
117
130
|
this.child.stdin.write(JSON.stringify(value) + '\n');
|
|
118
131
|
}
|
|
132
|
+
setIdle(idle: boolean): void {
|
|
133
|
+
this.idle = idle;
|
|
134
|
+
if (idle) this.events.discardPending();
|
|
135
|
+
}
|
|
119
136
|
notify(method: string, params?: unknown): void {
|
|
120
137
|
this.write({ method, params });
|
|
121
138
|
}
|
|
@@ -160,8 +177,9 @@ export class CodexRpc implements CodexConnection {
|
|
|
160
177
|
kill.unref();
|
|
161
178
|
this.child.once('close', () => clearTimeout(kill));
|
|
162
179
|
}
|
|
163
|
-
close(): void {
|
|
180
|
+
async close(): Promise<void> {
|
|
164
181
|
this.finish(new Error('Codex session closed.'));
|
|
182
|
+
await this.exited;
|
|
165
183
|
}
|
|
166
184
|
}
|
|
167
185
|
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { CodexConnection } from './codexRpc.js';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
/** Rust maps may arrive in a different order; credentials never become a stored key. */
|
|
5
|
+
export function codexBindingFingerprint(value: unknown): string {
|
|
6
|
+
const ordered = (value: unknown): unknown =>
|
|
7
|
+
Array.isArray(value)
|
|
8
|
+
? value.map(ordered)
|
|
9
|
+
: value && typeof value === 'object'
|
|
10
|
+
? Object.fromEntries(
|
|
11
|
+
Object.entries(value)
|
|
12
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
13
|
+
.map(([key, item]) => [key, ordered(item)]),
|
|
14
|
+
)
|
|
15
|
+
: value;
|
|
16
|
+
return createHash('sha256')
|
|
17
|
+
.update(JSON.stringify(ordered(value)))
|
|
18
|
+
.digest('hex');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CodexThread {
|
|
22
|
+
thread: { id: string };
|
|
23
|
+
model?: string;
|
|
24
|
+
reasoningEffort?: string | null;
|
|
25
|
+
cwd?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface CodexSession {
|
|
28
|
+
rpc: CodexConnection;
|
|
29
|
+
thread: CodexThread;
|
|
30
|
+
fingerprint: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Completed threads retain one transport; idle eviction still awaits the native exit. */
|
|
34
|
+
export class CodexSessions {
|
|
35
|
+
private idle = new Map<
|
|
36
|
+
string,
|
|
37
|
+
CodexSession & { timer: ReturnType<typeof setTimeout> }
|
|
38
|
+
>();
|
|
39
|
+
private closing = new Map<string, Promise<void>>();
|
|
40
|
+
private disposed = false;
|
|
41
|
+
constructor(
|
|
42
|
+
private readonly limit = 2,
|
|
43
|
+
private readonly idleMs = 3 * 60_000,
|
|
44
|
+
) {}
|
|
45
|
+
|
|
46
|
+
async take(id?: string): Promise<CodexSession | undefined> {
|
|
47
|
+
if (!id) return;
|
|
48
|
+
await this.closing.get(id);
|
|
49
|
+
if (this.disposed) throw new Error('Codex is shutting down.');
|
|
50
|
+
const session = this.idle.get(id);
|
|
51
|
+
if (!session) return;
|
|
52
|
+
clearTimeout(session.timer);
|
|
53
|
+
this.idle.delete(id);
|
|
54
|
+
if (session.rpc.isConnected === false) {
|
|
55
|
+
await session.rpc.close();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
session.rpc.setIdle?.(false);
|
|
59
|
+
return session;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private evict(id: string): Promise<void> {
|
|
63
|
+
const session = this.idle.get(id);
|
|
64
|
+
if (!session) return this.closing.get(id) ?? Promise.resolve();
|
|
65
|
+
clearTimeout(session.timer);
|
|
66
|
+
this.idle.delete(id);
|
|
67
|
+
const closing = Promise.resolve()
|
|
68
|
+
.then(() => session.rpc.close())
|
|
69
|
+
.finally(() => {
|
|
70
|
+
if (this.closing.get(id) === closing) this.closing.delete(id);
|
|
71
|
+
});
|
|
72
|
+
this.closing.set(id, closing);
|
|
73
|
+
return closing;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async keep(session: CodexSession): Promise<void> {
|
|
77
|
+
const id = session.thread.thread.id;
|
|
78
|
+
if (
|
|
79
|
+
this.disposed ||
|
|
80
|
+
session.rpc.isConnected === false ||
|
|
81
|
+
!session.rpc.setIdle ||
|
|
82
|
+
this.limit <= 0
|
|
83
|
+
) {
|
|
84
|
+
await session.rpc.close();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
await this.evict(id);
|
|
88
|
+
if (this.disposed) {
|
|
89
|
+
await session.rpc.close();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
session.rpc.onRequest = undefined;
|
|
93
|
+
session.rpc.setIdle(true);
|
|
94
|
+
const timer = setTimeout(() => {
|
|
95
|
+
void this.evict(id).catch(() => {});
|
|
96
|
+
}, this.idleMs);
|
|
97
|
+
timer.unref();
|
|
98
|
+
this.idle.set(id, { ...session, timer });
|
|
99
|
+
while (this.idle.size > this.limit)
|
|
100
|
+
await this.evict(this.idle.keys().next().value!);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async dispose(): Promise<void> {
|
|
104
|
+
this.disposed = true;
|
|
105
|
+
await Promise.all([...this.idle.keys()].map((id) => this.evict(id)));
|
|
106
|
+
await Promise.all(this.closing.values());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { AgentExecutor, ExecutorRunInput } from './types.js';
|
|
|
3
3
|
|
|
4
4
|
export function providerFailure(
|
|
5
5
|
error: unknown,
|
|
6
|
-
): Pick<ProviderHealth, 'auth' | 'allowance' | 'problem'> {
|
|
6
|
+
): Pick<ProviderHealth, 'auth' | 'allowance' | 'problem'> | undefined {
|
|
7
7
|
const message = error instanceof Error ? error.message : String(error);
|
|
8
8
|
if (
|
|
9
9
|
/quota|rate.?limit|usage.?limit|allowance|insufficient.*credit|limit.*reached/i.test(
|
|
@@ -21,7 +21,8 @@ export function providerFailure(
|
|
|
21
21
|
)
|
|
22
22
|
)
|
|
23
23
|
return { auth: 'login_required', allowance: 'unknown', problem: 'login' };
|
|
24
|
-
|
|
24
|
+
// A failed thread, command, model, or workspace says nothing about account readiness.
|
|
25
|
+
return undefined;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/** Observes the same adapter used by interactive and scheduled work. No probe inference. */
|
|
@@ -51,12 +52,15 @@ export class HealthAwareExecutor implements AgentExecutor {
|
|
|
51
52
|
if (
|
|
52
53
|
!signal?.aborted &&
|
|
53
54
|
!(error instanceof Error && error.name === 'AbortError')
|
|
54
|
-
)
|
|
55
|
-
|
|
55
|
+
) {
|
|
56
|
+
const failure = providerFailure(error);
|
|
57
|
+
if (failure) this.update(failure);
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
60
|
async models() {
|
|
58
61
|
if (this.check) return this.check;
|
|
59
|
-
|
|
62
|
+
if (this.state.auth !== 'authenticated')
|
|
63
|
+
this.update({ ...this.state, auth: 'checking' });
|
|
60
64
|
this.check = (async () => {
|
|
61
65
|
try {
|
|
62
66
|
if (!this.executor.models)
|
|
@@ -67,7 +71,10 @@ export class HealthAwareExecutor implements AgentExecutor {
|
|
|
67
71
|
this.update({ auth: 'authenticated', allowance: 'unknown' });
|
|
68
72
|
return models;
|
|
69
73
|
} catch (error) {
|
|
70
|
-
|
|
74
|
+
const failure = providerFailure(error);
|
|
75
|
+
if (failure) this.update(failure);
|
|
76
|
+
else if (this.state.auth !== 'authenticated')
|
|
77
|
+
this.update({ auth: 'unknown', allowance: 'unknown', problem: 'unavailable' });
|
|
71
78
|
throw error;
|
|
72
79
|
} finally {
|
|
73
80
|
this.check = undefined;
|
|
@@ -78,6 +85,9 @@ export class HealthAwareExecutor implements AgentExecutor {
|
|
|
78
85
|
async commands(input?: Pick<ExecutorRunInput, 'cwd' | 'permissionMode' | 'mcp'>) {
|
|
79
86
|
return (await this.executor.commands?.(input)) ?? [];
|
|
80
87
|
}
|
|
88
|
+
withOwnership<T>(input: ExecutorRunInput, action: () => Promise<T>): Promise<T> {
|
|
89
|
+
return this.executor.withOwnership ? this.executor.withOwnership(input, action) : action();
|
|
90
|
+
}
|
|
81
91
|
async run(input: ExecutorRunInput) {
|
|
82
92
|
try {
|
|
83
93
|
const result = await this.executor.run(input);
|