agl 42.2.2 → 43.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 +16 -0
- package/dist_serve/bundle.js +6697 -5287
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +29 -29
- package/dist_serve/bundle.js.third-party-notices.txt +29 -29
- package/dist_serve/third-party-notices.md +597 -8
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +114 -16
- package/dist_ts/aglapi/interfaces.d.ts +30 -0
- package/dist_ts/aglapi/interfaces.js +7 -1
- package/dist_ts/classes.authstore.d.ts +7 -0
- package/dist_ts/classes.authstore.js +12 -1
- package/dist_ts/classes.cli.js +10 -1
- package/dist_ts/classes.controller.d.ts +41 -11
- package/dist_ts/classes.controller.js +224 -48
- package/dist_ts/classes.harnessoperationmanager.d.ts +44 -0
- package/dist_ts/classes.harnessoperationmanager.js +15 -10
- package/dist_ts/classes.mcpclient.d.ts +5 -0
- package/dist_ts/classes.mcpclient.js +15 -3
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -0
- package/dist_ts/classes.mcpcontrollerhost.js +14 -2
- package/dist_ts/classes.mcptools.d.ts +4 -3
- package/dist_ts/classes.mcptools.js +20 -1
- package/dist_ts/classes.mcpvalidation.js +4 -1
- package/dist_ts/classes.ticketstore.d.ts +71 -3
- package/dist_ts/classes.ticketstore.js +299 -12
- package/dist_ts/classes.validation.d.ts +2 -0
- package/dist_ts/classes.validation.js +27 -5
- package/dist_ts/driver/classes.directreports.d.ts +23 -3
- package/dist_ts/driver/classes.directreports.js +59 -2
- package/dist_ts/driver/classes.drivereventrelay.js +3 -2
- package/dist_ts/driver/functions.driverinstructions.d.ts +1 -1
- package/dist_ts/driver/functions.driverinstructions.js +12 -3
- package/dist_ts/driver/functions.drivertools.d.ts +4 -0
- package/dist_ts/driver/functions.drivertools.js +8 -2
- package/dist_ts/fleet/classes.boardpump.d.ts +53 -3
- package/dist_ts/fleet/classes.boardpump.js +237 -32
- package/dist_ts/fleet/classes.claudeworkers.d.ts +10 -3
- package/dist_ts/fleet/classes.claudeworkers.js +43 -19
- package/dist_ts/fleet/classes.codexworkers.d.ts +5 -3
- package/dist_ts/fleet/classes.codexworkers.js +26 -9
- package/dist_ts/fleet/classes.deploymonitor.d.ts +253 -0
- package/dist_ts/fleet/classes.deploymonitor.js +821 -0
- package/dist_ts/fleet/classes.gitfacts.d.ts +61 -0
- package/dist_ts/fleet/classes.gitfacts.js +125 -0
- package/dist_ts/fleet/classes.releasereconciler.d.ts +51 -0
- package/dist_ts/fleet/classes.releasereconciler.js +101 -0
- package/dist_ts/fleet/classes.service.d.ts +13 -1
- package/dist_ts/fleet/classes.service.js +76 -7
- package/dist_ts/fleet/classes.ticketeffects.d.ts +13 -0
- package/dist_ts/fleet/classes.ticketeffects.js +42 -8
- package/dist_ts/fleet/classes.workers.d.ts +10 -3
- package/dist_ts/fleet/classes.workers.js +18 -3
- package/dist_ts/fleet/functions.controllerbuild.d.ts +23 -0
- package/dist_ts/fleet/functions.controllerbuild.js +75 -0
- package/dist_ts/fleet/functions.deployprobes.d.ts +39 -0
- package/dist_ts/fleet/functions.deployprobes.js +82 -0
- package/dist_ts/fleet/functions.deployvalidation.d.ts +27 -0
- package/dist_ts/fleet/functions.deployvalidation.js +43 -0
- package/dist_ts/fleet/functions.release.d.ts +2 -1
- package/dist_ts/fleet/functions.release.js +32 -5
- package/dist_ts/fleet/functions.releasefacts.d.ts +45 -0
- package/dist_ts/fleet/functions.releasefacts.js +68 -0
- package/dist_ts/fleet/functions.validation.d.ts +3 -3
- package/dist_ts/fleet/functions.validation.js +4 -7
- package/dist_ts/fleet/functions.watchprobes.js +7 -9
- package/dist_ts/fleet/functions.workervalidation.js +4 -3
- package/dist_ts/fleet/interfaces.workers.d.ts +30 -3
- package/dist_ts/fleet/interfaces.workers.js +14 -1
- package/dist_ts/functions.deploycli.d.ts +33 -0
- package/dist_ts/functions.deploycli.js +155 -0
- package/dist_ts/functions.mcpdeploytools.d.ts +13 -0
- package/dist_ts/functions.mcpdeploytools.js +16 -0
- package/dist_ts/functions.mcptickettools.d.ts +54 -0
- package/dist_ts/functions.mcptickettools.js +8 -7
- package/dist_ts/functions.ticketautolabels.d.ts +2 -0
- package/dist_ts/functions.ticketautolabels.js +9 -3
- package/dist_ts/functions.ticketcli.d.ts +16 -2
- package/dist_ts/functions.ticketcli.js +105 -27
- package/dist_ts/functions.ticketvalidation.d.ts +55 -0
- package/dist_ts/functions.ticketvalidation.js +26 -8
- package/dist_ts_interfaces/deployments.d.ts +241 -0
- package/dist_ts_interfaces/deployments.js +5 -6
- package/dist_ts_interfaces/fleet.d.ts +12 -0
- package/dist_ts_interfaces/fleetworkers.d.ts +21 -1
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/mcprequests.d.ts +3 -2
- package/dist_ts_interfaces/mcprequests.js +3 -1
- package/dist_ts_interfaces/requests.d.ts +3 -2
- package/dist_ts_interfaces/requests.directreports.d.ts +58 -6
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.tickets.d.ts +25 -5
- package/dist_ts_interfaces/requests.tickets.js +2 -2
- package/dist_ts_interfaces/tickets.d.ts +71 -6
- package/dist_ts_interfaces/tickets.js +34 -6
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +7 -0
- package/dist_ts_migration/classes.documentmigrationrunner.js +14 -1
- package/dist_ts_migration/index.d.ts +2 -0
- package/dist_ts_migration/index.js +3 -1
- package/dist_ts_migration/v41_ticketclosedcolumn.d.ts +20 -0
- package/dist_ts_migration/v41_ticketclosedcolumn.js +118 -0
- package/dist_ts_migration/v41_ticketlinkrepos.d.ts +24 -0
- package/dist_ts_migration/v41_ticketlinkrepos.js +101 -0
- package/package.json +6 -2
- package/readme.md +306 -36
- package/third-party-notices.md +597 -8
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +113 -15
- package/ts/aglapi/interfaces.ts +6 -0
- package/ts/classes.authstore.ts +13 -0
- package/ts/classes.cli.ts +9 -0
- package/ts/classes.controller.ts +238 -59
- package/ts/classes.harnessoperationmanager.ts +20 -14
- package/ts/classes.mcpclient.ts +17 -2
- package/ts/classes.mcpcontrollerhost.ts +15 -1
- package/ts/classes.mcptools.ts +21 -2
- package/ts/classes.mcpvalidation.ts +2 -0
- package/ts/classes.ticketstore.ts +312 -13
- package/ts/classes.validation.ts +28 -4
- package/ts/driver/classes.directreports.ts +58 -3
- package/ts/driver/classes.drivereventrelay.ts +2 -1
- package/ts/driver/functions.driverinstructions.ts +11 -2
- package/ts/driver/functions.drivertools.ts +10 -2
- package/ts/fleet/classes.boardpump.ts +235 -28
- package/ts/fleet/classes.claudeworkers.ts +36 -15
- package/ts/fleet/classes.codexworkers.ts +24 -7
- package/ts/fleet/classes.deploymonitor.ts +854 -0
- package/ts/fleet/classes.gitfacts.ts +135 -0
- package/ts/fleet/classes.releasereconciler.ts +103 -0
- package/ts/fleet/classes.service.ts +81 -8
- package/ts/fleet/classes.ticketeffects.ts +38 -6
- package/ts/fleet/classes.workers.ts +19 -5
- package/ts/fleet/functions.controllerbuild.ts +84 -0
- package/ts/fleet/functions.deployprobes.ts +84 -0
- package/ts/fleet/functions.deployvalidation.ts +50 -0
- package/ts/fleet/functions.release.ts +32 -3
- package/ts/fleet/functions.releasefacts.ts +91 -0
- package/ts/fleet/functions.validation.ts +3 -6
- package/ts/fleet/functions.watchprobes.ts +6 -8
- package/ts/fleet/functions.workervalidation.ts +3 -2
- package/ts/fleet/interfaces.workers.ts +23 -3
- package/ts/functions.deploycli.ts +151 -0
- package/ts/functions.mcpdeploytools.ts +18 -0
- package/ts/functions.mcptickettools.ts +7 -6
- package/ts/functions.ticketautolabels.ts +10 -2
- package/ts/functions.ticketcli.ts +100 -24
- package/ts/functions.ticketvalidation.ts +26 -7
- package/ts_interfaces/deployments.ts +194 -0
- package/ts_interfaces/fleet.ts +17 -2
- package/ts_interfaces/fleetworkers.ts +20 -0
- package/ts_interfaces/interfaces.ts +3 -1
- package/ts_interfaces/mcprequests.ts +3 -0
- package/ts_interfaces/requests.directreports.ts +52 -8
- package/ts_interfaces/requests.tickets.ts +20 -4
- package/ts_interfaces/requests.ts +6 -1
- package/ts_interfaces/tickets.ts +53 -6
- package/ts_migration/classes.documentmigrationrunner.ts +15 -0
- package/ts_migration/index.ts +2 -0
- package/ts_migration/v41_ticketclosedcolumn.ts +106 -0
- package/ts_migration/v41_ticketlinkrepos.ts +91 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements.deployments.ts +1066 -0
- package/ts_web/elements.directreport.ts +2 -2
- package/ts_web/elements.directreportsession.ts +5 -5
- package/ts_web/elements.harnesscontrollerapp.ts +179 -13
- package/ts_web/elements.makedirectreport.ts +444 -0
- package/ts_web/elements.nativesession.ts +29 -1
- package/ts_web/elements.ticketboard.ts +74 -18
- package/ts_web/functions.deployments.ts +225 -0
- package/ts_web/functions.sessionchat.ts +2 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
2
|
import { resolveControllerTerminalAgentTranscript } from '../functions.terminalagents.js';
|
|
3
3
|
import { fleetWorkerPath, resolveClaudeWorkerExecutable } from '../functions.workerprocessproof.js';
|
|
4
|
-
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
|
|
4
|
+
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetRelaunchBlocker, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
|
|
5
5
|
import { controllerSessionFeedExcerpt, type IControllerMessageBundle } from '../../ts_interfaces/index.js';
|
|
6
6
|
import { claudePage, claudeTranscript } from '../classes.claudeprojection.js';
|
|
7
|
-
import { FleetDispatchError, boundedFleetReport, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeAgent, type IFleetNativeSession, type IFleetNativePage } from './interfaces.workers.js';
|
|
7
|
+
import { FleetDispatchError, FleetNativeTurnError, boundedFleetReport, fleetMessageDigest, fleetReportMarker, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeAgent, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt } from './interfaces.workers.js';
|
|
8
8
|
import { runFleetWorkerCommand, type IFleetWorkerCommand, type TFleetWorkerRunner } from './classes.workercommand.js';
|
|
9
9
|
import { sanitizeFailureText } from '../functions.failuredescription.js';
|
|
10
10
|
import type { FleetWorkerLaunches } from './classes.workerlaunches.js';
|
|
@@ -295,7 +295,7 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
295
295
|
}
|
|
296
296
|
if (!trusted) throw new Error(`Claude workspace not trusted. ${instruction}`);
|
|
297
297
|
}
|
|
298
|
-
private async supported(worker: IFleetWorker, profile: IFleetWorkerProfile, starting = false): Promise<void> {
|
|
298
|
+
private async supported(worker: Pick<IFleetWorker, 'cwd'>, profile: IFleetWorkerProfile, starting = false): Promise<void> {
|
|
299
299
|
await this.supportedExecutable(profile, worker.cwd);
|
|
300
300
|
if (starting) await this.trustedWorkspace(profile, worker.cwd);
|
|
301
301
|
}
|
|
@@ -553,6 +553,31 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
553
553
|
throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude start outcome is unknown.', true, { cause: error });
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Why a relaunch of the session `nativeId` in `worker`'s directory would be refused now, read-only, or what the
|
|
558
|
+
* relaunch continues from: the profile home's fresh inventory, the session in it and its saved conversation. The
|
|
559
|
+
* relaunch and its preflight both run it, so they refuse alike.
|
|
560
|
+
*/
|
|
561
|
+
private async relaunchState(worker: Pick<IFleetWorker, 'cwd'>, profile: IFleetWorkerProfile, nativeId: string): Promise<{ blocker: IFleetRelaunchBlocker }
|
|
562
|
+
| { before: TClaudeAgent[]; original: TClaudeAgent; baseline: { records: Record<string, unknown>[]; end: number; path?: string } }> {
|
|
563
|
+
if (!plugins.z.string().uuid().safeParse(nativeId).success) return { blocker: { code: 'invalidId', message: 'A Claude session is relaunched by its full session id.' } };
|
|
564
|
+
try { await this.supported(worker, profile, true); }
|
|
565
|
+
catch (error) { return { blocker: { code: 'unsupported', message: error instanceof Error ? error.message : 'Claude cannot start in this directory.' } }; }
|
|
566
|
+
const before = await this.agents(worker, profile), found = before.find((entry) => entry.sessionId === nativeId);
|
|
567
|
+
if (!found) return { blocker: { code: 'notInInventory', message: `Claude session ${nativeId} is not in the inventory of this profile's Claude home; AGL cannot prove it is not running.` } };
|
|
568
|
+
if (live(found) || found.state === 'working') {
|
|
569
|
+
return { blocker: { code: live(found) ? 'running' : 'working', ...(found.pid ? { pid: found.pid } : {}),
|
|
570
|
+
message: `Claude session ${nativeId} is still running outside the fleet${found.pid ? ` (pid ${found.pid})` : ''}. Its owner stops it first${found.id ? ` (\`claude stop ${found.id}\`, or exits it)` : ' (exits it)'}; the adopt never stops a session it does not manage.` } };
|
|
571
|
+
}
|
|
572
|
+
if (found.kind === 'background' && !found.id) return { blocker: { code: 'noAgentId', message: 'Claude background session has no agent id.' } };
|
|
573
|
+
const baseline = await this.transcript({ ...worker, nativeId }, profile);
|
|
574
|
+
if (!baseline.path || !baseline.records.some((entry) => typeof entry.uuid === 'string')) return { blocker: { code: 'noTranscript', message: 'Claude session has no readable saved conversation.' } };
|
|
575
|
+
return { before, original: found, baseline };
|
|
576
|
+
}
|
|
577
|
+
public async relaunchBlocker(cwd: string, profile: IFleetWorkerProfile, nativeId: string): Promise<IFleetRelaunchBlocker | undefined> {
|
|
578
|
+
const state = await this.relaunchState({ cwd }, profile, nativeId);
|
|
579
|
+
return 'blocker' in state ? state.blocker : undefined;
|
|
580
|
+
}
|
|
556
581
|
/**
|
|
557
582
|
* Resumes the settled session `nativeId` as `worker`, under the worker's own options and caller overlay. Claude
|
|
558
583
|
* continues a background job's session as a copy under a new id, its saved options staying with the original, and
|
|
@@ -562,18 +587,10 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
562
587
|
public async relaunch(worker: IFleetWorker, profile: IFleetWorkerProfile, nativeId: string, prompt: string, bind: (id: string) => Promise<void>): Promise<void> {
|
|
563
588
|
let before: TClaudeAgent[], original: TClaudeAgent, baseline: { records: Record<string, unknown>[]; end: number; path?: string }, overlay: string | undefined;
|
|
564
589
|
try {
|
|
565
|
-
if (!plugins.z.string().uuid().safeParse(nativeId).success) throw new Error('A Claude session is relaunched by its full session id.');
|
|
566
590
|
if (Buffer.byteLength(prompt) > 96 * 1024) throw new Error('Claude relaunch prompt plus preamble exceeds 96 KiB.');
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
if (live(found) || found.state === 'working') {
|
|
571
|
-
throw new Error(`Claude session ${nativeId} is still running outside the fleet${found.pid ? ` (pid ${found.pid})` : ''}. Its owner stops it first${found.id ? ` (\`claude stop ${found.id}\`, or exits it)` : ' (exits it)'}; the adopt never stops a session it does not manage.`);
|
|
572
|
-
}
|
|
573
|
-
if (found.kind === 'background' && !found.id) throw new Error('Claude background session has no agent id.');
|
|
574
|
-
original = found;
|
|
575
|
-
baseline = await this.transcript({ ...worker, nativeId }, profile);
|
|
576
|
-
if (!baseline.path || !baseline.records.some((entry) => typeof entry.uuid === 'string')) throw new Error('Claude session has no readable saved conversation.');
|
|
591
|
+
const state = await this.relaunchState(worker, profile, nativeId);
|
|
592
|
+
if ('blocker' in state) throw new Error(state.blocker.message);
|
|
593
|
+
({ before, original, baseline } = state);
|
|
577
594
|
overlay = await this.callers?.prepareClaude(worker);
|
|
578
595
|
}
|
|
579
596
|
catch (error) { throw new FleetDispatchError(error instanceof Error ? error.message : 'Claude relaunch preflight failed.', false, { cause: error }); }
|
|
@@ -702,7 +719,10 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
702
719
|
* stopped) and with a readable conversation, is woken; anything else, and a message Claude Code would read as one of
|
|
703
720
|
* its options, is refused before dispatch. Claude Code does not report when the woken turn ends, so `settled` never runs.
|
|
704
721
|
*/
|
|
705
|
-
public async nativeSend(session: IFleetNativeSession, text: string, _settled: () => void): Promise<
|
|
722
|
+
public async nativeSend(session: IFleetNativeSession, text: string, _settled: () => void, turn?: IFleetNativeSendTurn): Promise<IFleetNativeSendReceipt> {
|
|
723
|
+
if (turn?.expectedTurnId !== undefined || turn?.agentMessage) {
|
|
724
|
+
throw new FleetNativeTurnError("delivery_unsupported", "Claude Code background jobs do not support guarded native turn delivery.");
|
|
725
|
+
}
|
|
706
726
|
const profile = { home: session.home };
|
|
707
727
|
let original: TClaudeAgent;
|
|
708
728
|
try {
|
|
@@ -724,6 +744,7 @@ export class FleetClaudeWorkers implements IFleetWorkerBackend {
|
|
|
724
744
|
catch (error) {
|
|
725
745
|
throw new FleetDispatchError(`Claude Code acknowledged the wake of background job ${original.id}, but its state is not confirmed: ${error instanceof Error ? error.message : 'unknown failure.'} Inspect it before sending again.`, true, { cause: error });
|
|
726
746
|
}
|
|
747
|
+
return { steered: false };
|
|
727
748
|
}
|
|
728
749
|
public async send(messages: Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string }>): Promise<void> {
|
|
729
750
|
const groups = new Map<string, Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string; to: string; mode: string; offset: number }>>();
|
|
@@ -6,7 +6,7 @@ import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport } from '../.
|
|
|
6
6
|
import { controllerSessionFeedExcerpt } from '../../ts_interfaces/sessionfeed.js';
|
|
7
7
|
import type { IControllerMessageBundle, IControllerPermission, IControllerQuestion, TControllerPermissionReply } from '../../ts_interfaces/index.js';
|
|
8
8
|
import type { FleetWorkerLaunches, IFleetCodexCallerRuntime } from './classes.workerlaunches.js';
|
|
9
|
-
import { FleetDispatchError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage } from './interfaces.workers.js';
|
|
9
|
+
import { FleetDispatchError, FleetNativeTurnError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt } from './interfaces.workers.js';
|
|
10
10
|
|
|
11
11
|
interface ICodexObservation { turns: Set<string>; items: Map<string, string>; status?: IFleetWorkerReport['status']; excerpt?: string }
|
|
12
12
|
export interface IFleetCodexConnection { supervisor: CodexSupervisor; adapter: CodexClientAdapter }
|
|
@@ -166,23 +166,34 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
|
|
|
166
166
|
/**
|
|
167
167
|
* Steers the thread's running turn, AGL's own or another client's, or starts a turn; `settled` runs once the turn
|
|
168
168
|
* that took the text ended. A steer of another client's turn proves that only when the turn ended before Codex took
|
|
169
|
-
* the input; otherwise `settled` never runs.
|
|
169
|
+
* the input; otherwise `settled` never runs. `turn` refuses a running turn the caller did not name before anything is
|
|
170
|
+
* sent; the steer itself proves the turn again on the server.
|
|
170
171
|
*/
|
|
171
172
|
private async deliver(adapter: CodexClientAdapter, id: string, text: string, model: Parameters<CodexClientAdapter['startTurn']>[3],
|
|
172
|
-
prepare: () => Promise<void>, settled: () => void = () => {}): Promise<
|
|
173
|
+
prepare: () => Promise<void>, settled: () => void = () => {}, turn: IFleetNativeSendTurn = {}): Promise<IFleetNativeSendReceipt> {
|
|
173
174
|
const turns = await this.turns(adapter, id);
|
|
174
175
|
const running = turns[0]?.status === 'inProgress' ? turns[0] : undefined;
|
|
176
|
+
if (turn.expectedTurnId !== undefined && !running) throw new FleetNativeTurnError('turn_ended', 'The Codex turn this message was to steer has ended; nothing was sent.');
|
|
175
177
|
await prepare();
|
|
176
178
|
const clientId = plugins.crypto.randomUUID(); let arm: () => void;
|
|
177
179
|
if (running) {
|
|
178
180
|
const turnId = codexString(running.id), activity = await adapter.refreshActivity(id, this.signal);
|
|
181
|
+
if (turn.expectedTurnId !== undefined && turn.expectedTurnId !== turnId) {
|
|
182
|
+
throw new FleetNativeTurnError('concurrent_change', 'Another Codex turn than the expected one runs; read the session again.');
|
|
183
|
+
}
|
|
184
|
+
if (turn.agentMessage && turn.expectedTurnId === undefined && activity.writer !== 'agl') {
|
|
185
|
+
throw new FleetNativeTurnError('delivery_unsupported', 'Steering a turn another Codex client runs requires expectedTurnId, the turn the last read reported.');
|
|
186
|
+
}
|
|
179
187
|
arm = await this.dispatch(() => activity.writer === 'agl'
|
|
180
188
|
? adapter.steer(id, text, clientId, () => {}, () => {}, turnId, this.signal, () => settled())
|
|
181
189
|
: adapter.steerObservedTurn(id, text, clientId, turnId, () => {}, (_outcome, _turnId, terminal) => { if (terminal) settled(); }, this.signal));
|
|
182
|
-
|
|
183
|
-
|
|
190
|
+
arm();
|
|
191
|
+
return { steered: true, turnId };
|
|
184
192
|
}
|
|
193
|
+
arm = await this.dispatch(() => adapter.startTurn(id, text, clientId, model, async () => {}, settled, this.signal));
|
|
185
194
|
arm();
|
|
195
|
+
const started = adapter.activitySummary(id).turnId;
|
|
196
|
+
return { steered: false, ...(started === undefined ? {} : { turnId: started }) };
|
|
186
197
|
}
|
|
187
198
|
public async stop(worker: IFleetWorker, _profile: IFleetWorkerProfile): Promise<void> {
|
|
188
199
|
const adapter = await this.scoped(worker), turns = await this.turns(adapter, worker.nativeId!);
|
|
@@ -211,9 +222,15 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
|
|
|
211
222
|
return { bundles: page.bundles, earlier: page.nextCursor !== undefined || page.truncated === true, ...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }) };
|
|
212
223
|
}
|
|
213
224
|
/** Sends to a thread outside the fleet through the shared server that owns it; the thread keeps its own model. */
|
|
214
|
-
public async nativeSend(session: IFleetNativeSession, text: string, settled: () => void): Promise<
|
|
225
|
+
public async nativeSend(session: IFleetNativeSession, text: string, settled: () => void, turn?: IFleetNativeSendTurn): Promise<IFleetNativeSendReceipt> {
|
|
226
|
+
const adapter = await this.scoped(session);
|
|
227
|
+
return await this.deliver(adapter, session.nativeId, text, undefined, async () => {}, settled, turn);
|
|
228
|
+
}
|
|
229
|
+
public async nativeTurn(session: IFleetNativeSession): Promise<string | undefined> {
|
|
215
230
|
const adapter = await this.scoped(session);
|
|
216
|
-
await
|
|
231
|
+
const result = await adapter.request('thread/turns/list', { threadId: session.nativeId, limit: 1, sortDirection: 'desc', itemsView: 'notLoaded' }, this.signal);
|
|
232
|
+
const latest = codexArray(result.data, 1).map(codexRecord)[0];
|
|
233
|
+
return latest?.status === 'inProgress' ? codexString(latest.id) : undefined;
|
|
217
234
|
}
|
|
218
235
|
/** The requests of turns this connection runs in the thread that wait for an answer. */
|
|
219
236
|
public async nativeAttention(session: IFleetNativeSession): Promise<{ permissions: IControllerPermission[]; questions: IControllerQuestion[] }> {
|