@dougbots/avenor-core 0.12.0 → 0.13.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/index.d.ts +38 -4
- package/dist/index.js +129 -34
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -144,6 +144,11 @@ interface WorkflowControllerCreateParams {
|
|
|
144
144
|
controller_id: string;
|
|
145
145
|
max_inflight: number;
|
|
146
146
|
}
|
|
147
|
+
declare class RpcError extends Error {
|
|
148
|
+
readonly code: number;
|
|
149
|
+
readonly data?: unknown;
|
|
150
|
+
constructor(code: number, message: string, data?: unknown);
|
|
151
|
+
}
|
|
147
152
|
declare class Client {
|
|
148
153
|
private socket;
|
|
149
154
|
private rl;
|
|
@@ -163,7 +168,9 @@ declare class Client {
|
|
|
163
168
|
});
|
|
164
169
|
private startReadLoop;
|
|
165
170
|
private pushEvent;
|
|
166
|
-
call(method: string, params?: unknown
|
|
171
|
+
call(method: string, params?: unknown, opts?: {
|
|
172
|
+
timeoutMs?: number;
|
|
173
|
+
}): Promise<unknown>;
|
|
167
174
|
subscribe(options?: SubscribeOptions): Promise<void>;
|
|
168
175
|
events(options?: SubscribeOptions): AsyncIterableIterator<Event>;
|
|
169
176
|
history(options: HistoryOptions): Promise<HistoryResult>;
|
|
@@ -194,7 +201,7 @@ declare class Client {
|
|
|
194
201
|
workflowControllerEnable(controllerId: string): Promise<Record<string, unknown>>;
|
|
195
202
|
workflowControllerDisable(controllerId: string, reason: string): Promise<Record<string, unknown>>;
|
|
196
203
|
brokerSend(fromRunId: string, toRunId: string, message: string, role?: string): Promise<void>;
|
|
197
|
-
brokerAsk(toRunId: string, message: string, role?: string): Promise<Record<string, unknown>>;
|
|
204
|
+
brokerAsk(toRunId: string, message: string, role?: string, timeoutMs?: number): Promise<Record<string, unknown>>;
|
|
198
205
|
brokerPeers(): Promise<Array<Record<string, unknown>>>;
|
|
199
206
|
brokerCancel(messageId: string): Promise<void>;
|
|
200
207
|
brokerReceive(): Promise<Array<{
|
|
@@ -424,8 +431,16 @@ declare class Supervisor {
|
|
|
424
431
|
getRunByReference(reference: string): RunInfo | undefined;
|
|
425
432
|
/** Match a stored run by its broker runtime ID. */
|
|
426
433
|
getRunByRuntimeId(runtimeId: string): RunInfo | undefined;
|
|
434
|
+
/**
|
|
435
|
+
* The live singleton when it owns supervisorId, null otherwise. Single
|
|
436
|
+
* source of truth for the ownership check, so callers cannot observe
|
|
437
|
+
* isCurrentInstance true while currentInstance is null.
|
|
438
|
+
*/
|
|
439
|
+
static getInstance(supervisorId: string): Supervisor | null;
|
|
427
440
|
static isCurrentInstance(supervisorId: string): boolean;
|
|
428
441
|
static currentInstance(): Supervisor | null;
|
|
442
|
+
/** Iterate stored runs without exposing the internal map. */
|
|
443
|
+
forEachRun(callback: (info: RunInfo) => void): void;
|
|
429
444
|
getClient(): Client;
|
|
430
445
|
spawn(params: SpawnParams, runId?: `${string}-${string}-${string}-${string}-${string}`, metadata?: SpawnMetadata): Promise<RunInfo>;
|
|
431
446
|
close(options?: {
|
|
@@ -491,6 +506,12 @@ interface StatusToolArgs {
|
|
|
491
506
|
supervisorId?: string;
|
|
492
507
|
view?: StatusView;
|
|
493
508
|
}
|
|
509
|
+
/** List form of the status tool result (no runId). structuredContent must be
|
|
510
|
+
* an object, so the runs array is wrapped with a count. */
|
|
511
|
+
interface StatusListResult {
|
|
512
|
+
runs: StatusResult[];
|
|
513
|
+
count: number;
|
|
514
|
+
}
|
|
494
515
|
interface StatusResult {
|
|
495
516
|
run_id: string;
|
|
496
517
|
label: string;
|
|
@@ -529,7 +550,7 @@ interface StatusResult {
|
|
|
529
550
|
final_output?: string;
|
|
530
551
|
final_output_truncated?: boolean;
|
|
531
552
|
}
|
|
532
|
-
declare const statusTool: (args: StatusToolArgs) => Promise<StatusResult |
|
|
553
|
+
declare const statusTool: (args: StatusToolArgs) => Promise<StatusResult | StatusListResult>;
|
|
533
554
|
//#endregion
|
|
534
555
|
//#region src/tools/events.d.ts
|
|
535
556
|
interface EventsToolArgs {
|
|
@@ -633,6 +654,7 @@ interface AskToolArgs {
|
|
|
633
654
|
toRunId: string;
|
|
634
655
|
message: string;
|
|
635
656
|
supervisorId?: string;
|
|
657
|
+
timeoutMs?: number;
|
|
636
658
|
}
|
|
637
659
|
interface AskResult {
|
|
638
660
|
reply: string;
|
|
@@ -667,6 +689,18 @@ interface CancelResult {
|
|
|
667
689
|
}
|
|
668
690
|
declare const cancelTool: (args: CancelToolArgs) => Promise<CancelResult>;
|
|
669
691
|
//#endregion
|
|
692
|
+
//#region src/tools/kill.d.ts
|
|
693
|
+
interface KillToolArgs {
|
|
694
|
+
runId: string;
|
|
695
|
+
supervisorId?: string;
|
|
696
|
+
}
|
|
697
|
+
interface KillResult {
|
|
698
|
+
killed: boolean;
|
|
699
|
+
run_id: string;
|
|
700
|
+
runtime_id?: string;
|
|
701
|
+
}
|
|
702
|
+
declare const killTool: (args: KillToolArgs) => Promise<KillResult>;
|
|
703
|
+
//#endregion
|
|
670
704
|
//#region src/tools/broker-receive.d.ts
|
|
671
705
|
interface BrokerReceiveArgs {
|
|
672
706
|
supervisorId?: string;
|
|
@@ -771,4 +805,4 @@ type WorkflowReadyResult = Record<string, unknown>;
|
|
|
771
805
|
declare function createWorkflowReadyTool(getSupervisorClient: GetSupervisorClient): (args: WorkflowReadyToolArgs) => Promise<WorkflowReadyResult>;
|
|
772
806
|
declare const workflowReadyTool: (args: WorkflowReadyToolArgs) => Promise<WorkflowReadyResult>;
|
|
773
807
|
//#endregion
|
|
774
|
-
export { type AskResult, type AskToolArgs, type BrokerReceiveArgs, type BrokerReceiveResult, type BrokerReplyArgs, type BrokerReplyResult, type CancelResult, type CancelToolArgs, type Client, DEFAULT_RUN_REDUCER_LIMITS, type Event, type ExecutionIdentity, type FollowUpToolArgs, type FollowUpToolResult, type HistoryOptions, type HistoryResult, type InboundAsk, type InspectResult, type NormalizedRunEvent, type ObserveRunOptions, type PeerEntry, type PeersResult, type ResultResult, type ResultToolArgs, type RunChunkRole, type RunIdentity, type RunInfo, type RunObserver, type RunObserverClient, type RunPermissionOption, type RunPermissionSummary, RunReducer, type RunReducerLimits, type RunSnapshot, type RunSnapshotSeed, type RunToolState, type RunToolSummary, type RunTranscriptEntry, type SpawnMetadata, type SpawnParams, type SpawnResult, type SpawnSelectionInput, type SpawnToolArgs, type SpawnToolResult, type StatusResult, type StatusToolArgs, type StatusView, type SubscribeOptions, Supervisor, type SupervisorOptions, THINKING_LEVELS, type ThinkingLevel, type ThinkingOutcome, type WorkflowCompleteParams, type WorkflowCompleteResult, type WorkflowCompleteToolArgs, type WorkflowControllerCreateParams, type WorkflowControllerStatusResult, type WorkflowControllerStatusToolArgs, type WorkflowEventsResult, type WorkflowEventsToolArgs, type WorkflowGateOperation, type WorkflowGateParams, type WorkflowGateResult, type WorkflowGateToolArgs, type WorkflowHeartbeatParams, type WorkflowInspectResult, type WorkflowInspectToolArgs, type WorkflowReadyResult, type WorkflowReadyToolArgs, type WorkflowStatusResult, type WorkflowStatusToolArgs, type WorkflowWaitResult, type WorkflowWaitToolArgs, answerPermissionTool, askTool, brokerReceiveTool, brokerReplyTool, cancelTool, createRunSnapshot, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, isThinkingLevel, normalizeRunEvent, observeRun, peersTool, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
|
|
808
|
+
export { type AskResult, type AskToolArgs, type BrokerReceiveArgs, type BrokerReceiveResult, type BrokerReplyArgs, type BrokerReplyResult, type CancelResult, type CancelToolArgs, type Client, DEFAULT_RUN_REDUCER_LIMITS, type Event, type ExecutionIdentity, type FollowUpToolArgs, type FollowUpToolResult, type HistoryOptions, type HistoryResult, type InboundAsk, type InspectResult, type KillResult, type KillToolArgs, type NormalizedRunEvent, type ObserveRunOptions, type PeerEntry, type PeersResult, type ResultResult, type ResultToolArgs, RpcError, type RunChunkRole, type RunIdentity, type RunInfo, type RunObserver, type RunObserverClient, type RunPermissionOption, type RunPermissionSummary, RunReducer, type RunReducerLimits, type RunSnapshot, type RunSnapshotSeed, type RunToolState, type RunToolSummary, type RunTranscriptEntry, type SpawnMetadata, type SpawnParams, type SpawnResult, type SpawnSelectionInput, type SpawnToolArgs, type SpawnToolResult, type StatusListResult, type StatusResult, type StatusToolArgs, type StatusView, type SubscribeOptions, Supervisor, type SupervisorOptions, THINKING_LEVELS, type ThinkingLevel, type ThinkingOutcome, type WorkflowCompleteParams, type WorkflowCompleteResult, type WorkflowCompleteToolArgs, type WorkflowControllerCreateParams, type WorkflowControllerStatusResult, type WorkflowControllerStatusToolArgs, type WorkflowEventsResult, type WorkflowEventsToolArgs, type WorkflowGateOperation, type WorkflowGateParams, type WorkflowGateResult, type WorkflowGateToolArgs, type WorkflowHeartbeatParams, type WorkflowInspectResult, type WorkflowInspectToolArgs, type WorkflowReadyResult, type WorkflowReadyToolArgs, type WorkflowStatusResult, type WorkflowStatusToolArgs, type WorkflowWaitResult, type WorkflowWaitToolArgs, answerPermissionTool, askTool, brokerReceiveTool, brokerReplyTool, cancelTool, createRunSnapshot, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, isThinkingLevel, killTool, normalizeRunEvent, observeRun, peersTool, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,16 @@ function removeResolver(resolvers, target) {
|
|
|
25
25
|
const index = resolvers.indexOf(target);
|
|
26
26
|
if (index >= 0) resolvers.splice(index, 1);
|
|
27
27
|
}
|
|
28
|
+
var RpcError = class extends Error {
|
|
29
|
+
code;
|
|
30
|
+
data;
|
|
31
|
+
constructor(code, message, data) {
|
|
32
|
+
super(`rpc error [${code}]: ${message}`);
|
|
33
|
+
this.name = "RpcError";
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.data = data;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
28
38
|
var Client = class {
|
|
29
39
|
socket;
|
|
30
40
|
rl;
|
|
@@ -73,7 +83,7 @@ var Client = class {
|
|
|
73
83
|
if (pc) {
|
|
74
84
|
clearTimeout(pc.timer);
|
|
75
85
|
this.pending.delete(id);
|
|
76
|
-
if (parsed.error) pc.reject(
|
|
86
|
+
if (parsed.error) pc.reject(new RpcError(parsed.error.code, parsed.error.message, parsed.error.data));
|
|
77
87
|
else pc.resolve(parsed.result);
|
|
78
88
|
}
|
|
79
89
|
return;
|
|
@@ -123,7 +133,7 @@ var Client = class {
|
|
|
123
133
|
if (this.eventQueue.length < 256) this.eventQueue.push(ev);
|
|
124
134
|
else this.dropped++;
|
|
125
135
|
}
|
|
126
|
-
async call(method, params) {
|
|
136
|
+
async call(method, params, opts) {
|
|
127
137
|
if (this.isClosed()) throw new Error("control socket is closed");
|
|
128
138
|
this.startReadLoop();
|
|
129
139
|
const id = ++this.nextID;
|
|
@@ -134,11 +144,14 @@ var Client = class {
|
|
|
134
144
|
};
|
|
135
145
|
if (params !== void 0) req.params = params;
|
|
136
146
|
const data = JSON.stringify(req) + "\n";
|
|
147
|
+
const MAX_TIMER_MS = 2147483647;
|
|
148
|
+
const requested = opts?.timeoutMs !== void 0 ? !Number.isFinite(opts.timeoutMs) || opts.timeoutMs > MAX_TIMER_MS - 1e4 ? MAX_TIMER_MS : Math.max(this.callTimeout, opts.timeoutMs + 1e4) : this.callTimeout;
|
|
149
|
+
const timeout = Number.isFinite(requested) ? Math.min(requested, MAX_TIMER_MS) : MAX_TIMER_MS;
|
|
137
150
|
return new Promise((resolve, reject) => {
|
|
138
151
|
const timer = setTimeout(() => {
|
|
139
152
|
this.pending.delete(id);
|
|
140
153
|
reject(/* @__PURE__ */ new Error("read response: timeout"));
|
|
141
|
-
},
|
|
154
|
+
}, timeout);
|
|
142
155
|
this.pending.set(id, {
|
|
143
156
|
resolve,
|
|
144
157
|
reject,
|
|
@@ -386,12 +399,14 @@ var Client = class {
|
|
|
386
399
|
role: role ?? "agent"
|
|
387
400
|
});
|
|
388
401
|
}
|
|
389
|
-
async brokerAsk(toRunId, message, role) {
|
|
390
|
-
|
|
402
|
+
async brokerAsk(toRunId, message, role, timeoutMs) {
|
|
403
|
+
const params = {
|
|
391
404
|
to_run_id: toRunId,
|
|
392
405
|
message,
|
|
393
406
|
role: role ?? "agent"
|
|
394
|
-
}
|
|
407
|
+
};
|
|
408
|
+
if (timeoutMs !== void 0) params.timeout_ms = timeoutMs;
|
|
409
|
+
return await this.call("broker_ask", params, timeoutMs !== void 0 ? { timeoutMs } : void 0);
|
|
395
410
|
}
|
|
396
411
|
async brokerPeers() {
|
|
397
412
|
return (await this.call("broker_peers")).sessions ?? [];
|
|
@@ -1534,12 +1549,24 @@ var Supervisor = class Supervisor {
|
|
|
1534
1549
|
if (!runtimeId) return void 0;
|
|
1535
1550
|
for (const runInfo of this.runs.values()) if (runInfo.runtimeId === runtimeId) return runInfo;
|
|
1536
1551
|
}
|
|
1552
|
+
/**
|
|
1553
|
+
* The live singleton when it owns supervisorId, null otherwise. Single
|
|
1554
|
+
* source of truth for the ownership check, so callers cannot observe
|
|
1555
|
+
* isCurrentInstance true while currentInstance is null.
|
|
1556
|
+
*/
|
|
1557
|
+
static getInstance(supervisorId) {
|
|
1558
|
+
return Supervisor.instance !== null && Supervisor.instance.supervisorId === supervisorId ? Supervisor.instance : null;
|
|
1559
|
+
}
|
|
1537
1560
|
static isCurrentInstance(supervisorId) {
|
|
1538
|
-
return Supervisor.
|
|
1561
|
+
return Supervisor.getInstance(supervisorId) !== null;
|
|
1539
1562
|
}
|
|
1540
1563
|
static currentInstance() {
|
|
1541
1564
|
return Supervisor.instance;
|
|
1542
1565
|
}
|
|
1566
|
+
/** Iterate stored runs without exposing the internal map. */
|
|
1567
|
+
forEachRun(callback) {
|
|
1568
|
+
for (const runInfo of this.runs.values()) callback(runInfo);
|
|
1569
|
+
}
|
|
1543
1570
|
getClient() {
|
|
1544
1571
|
if (this.crashed) {
|
|
1545
1572
|
const state = this.crashCode === 0 ? "exited" : "crashed";
|
|
@@ -1689,8 +1716,8 @@ async function getSupervisorClient(supervisorId) {
|
|
|
1689
1716
|
};
|
|
1690
1717
|
}
|
|
1691
1718
|
const id = validateSupervisorSocketPath(supervisorId);
|
|
1692
|
-
const current = Supervisor.
|
|
1693
|
-
if (current !== null
|
|
1719
|
+
const current = Supervisor.getInstance(id);
|
|
1720
|
+
if (current !== null) return {
|
|
1694
1721
|
client: current.getClient(),
|
|
1695
1722
|
isSingleton: true,
|
|
1696
1723
|
sup: current,
|
|
@@ -2371,7 +2398,10 @@ async function executeStatusTool(args, getSupervisorClient) {
|
|
|
2371
2398
|
session_id: entry.session_id
|
|
2372
2399
|
}, translateStatus(rawStatusPhase(entry), null)), args.view));
|
|
2373
2400
|
}
|
|
2374
|
-
return
|
|
2401
|
+
return {
|
|
2402
|
+
runs: results,
|
|
2403
|
+
count: results.length
|
|
2404
|
+
};
|
|
2375
2405
|
} finally {
|
|
2376
2406
|
if (!isSingleton) client.close();
|
|
2377
2407
|
}
|
|
@@ -2409,7 +2439,10 @@ async function executeStatusTool(args, getSupervisorClient) {
|
|
|
2409
2439
|
session_id: entry.session_id
|
|
2410
2440
|
}, translateStatus(rawStatusPhase(entry), null)), args.view));
|
|
2411
2441
|
}
|
|
2412
|
-
return
|
|
2442
|
+
return {
|
|
2443
|
+
runs: results,
|
|
2444
|
+
count: results.length
|
|
2445
|
+
};
|
|
2413
2446
|
}
|
|
2414
2447
|
function createStatusTool(getSupervisorClient) {
|
|
2415
2448
|
return (args) => executeStatusTool(args, getSupervisorClient);
|
|
@@ -2837,6 +2870,15 @@ function rejectSessionConflict(sentinel, liveStatus) {
|
|
|
2837
2870
|
const liveStopReason = value(liveStatus?.stop_reason);
|
|
2838
2871
|
if (sentinelStopReason === "session_id_conflict" || liveStopReason === "session_id_conflict") throw new Error("run is not resumable: session_id_conflict");
|
|
2839
2872
|
}
|
|
2873
|
+
const RESUMABLE_SENTINEL_STATUSES = new Set([
|
|
2874
|
+
"DONE",
|
|
2875
|
+
"FAILED",
|
|
2876
|
+
"BLOCKED"
|
|
2877
|
+
]);
|
|
2878
|
+
function rejectNotResumableStatus(sentinel) {
|
|
2879
|
+
const status = (sentinel?._status ?? "").trim().toUpperCase();
|
|
2880
|
+
if (status !== "" && !RESUMABLE_SENTINEL_STATUSES.has(status)) throw new Error(`run is not resumable (status: ${status.toLowerCase()})`);
|
|
2881
|
+
}
|
|
2840
2882
|
async function executeFollowUpTool(args, getSupervisorClient) {
|
|
2841
2883
|
if (args.supervisorId) {
|
|
2842
2884
|
const { client, isSingleton, sup, supervisorId } = await getSupervisorClient(args.supervisorId);
|
|
@@ -2852,6 +2894,7 @@ async function executeFollowUpTool(args, getSupervisorClient) {
|
|
|
2852
2894
|
} catch {}
|
|
2853
2895
|
const sentinel = await parseSentinel(liveStatus?.sentinel_file ?? runInfo?.sentinelPath ?? path.join(runsRoot(), args.runId, "sentinel.done"));
|
|
2854
2896
|
rejectSessionConflict(sentinel, liveStatus);
|
|
2897
|
+
rejectNotResumableStatus(sentinel);
|
|
2855
2898
|
const sessionId = sentinel?.SESSION ?? liveStatus?.session_id ?? fallbackSessionId;
|
|
2856
2899
|
if (!sessionId) throw new Error("run has no session to resume");
|
|
2857
2900
|
const agent = resolvedIdentity(liveStatus, "effective_agent", "agent", runInfo?.effectiveAgent, runInfo?.agent);
|
|
@@ -2930,6 +2973,7 @@ async function executeFollowUpTool(args, getSupervisorClient) {
|
|
|
2930
2973
|
if (!runInfo) throw new Error(`run not found: ${args.runId}`);
|
|
2931
2974
|
const sentinel = await parseSentinel(runInfo.sentinelPath);
|
|
2932
2975
|
rejectSessionConflict(sentinel, null);
|
|
2976
|
+
rejectNotResumableStatus(sentinel);
|
|
2933
2977
|
const sessionId = sentinel?.SESSION ?? runInfo.sessionId;
|
|
2934
2978
|
if (!sessionId) throw new Error("run has no session to resume");
|
|
2935
2979
|
const client = sup.getClient();
|
|
@@ -2982,21 +3026,23 @@ async function shutdownTool(args) {
|
|
|
2982
3026
|
const cleanedUp = [];
|
|
2983
3027
|
if (args.supervisorId) {
|
|
2984
3028
|
const supervisorId = validateSupervisorSocketPath(args.supervisorId);
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
if (!sup) throw new Error("supervisor not started");
|
|
3029
|
+
const sup = Supervisor.getInstance(supervisorId);
|
|
3030
|
+
if (sup) {
|
|
2988
3031
|
await sup.getClient().shutdown(args.force ? "force" : "graceful");
|
|
2989
|
-
const
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3032
|
+
const cleanups = [];
|
|
3033
|
+
sup.forEachRun((info) => {
|
|
3034
|
+
cleanups.push((async () => {
|
|
3035
|
+
try {
|
|
3036
|
+
await fs.promises.unlink(info.sentinelPath);
|
|
3037
|
+
cleanedUp.push(info.sentinelPath);
|
|
3038
|
+
} catch {}
|
|
3039
|
+
try {
|
|
3040
|
+
await fs.promises.unlink(info.eventLogPath);
|
|
3041
|
+
cleanedUp.push(info.eventLogPath);
|
|
3042
|
+
} catch {}
|
|
3043
|
+
})());
|
|
3044
|
+
});
|
|
3045
|
+
await Promise.all(cleanups);
|
|
3000
3046
|
await sup.close({ skipShutdown: true });
|
|
3001
3047
|
} else {
|
|
3002
3048
|
const client = await dial(supervisorId);
|
|
@@ -3030,8 +3076,7 @@ async function shutdownTool(args) {
|
|
|
3030
3076
|
try {
|
|
3031
3077
|
await sup.getClient().shutdown(args.force ? "force" : "graceful");
|
|
3032
3078
|
} catch {}
|
|
3033
|
-
|
|
3034
|
-
for (const info of runs.values()) {
|
|
3079
|
+
sup.forEachRun((info) => {
|
|
3035
3080
|
try {
|
|
3036
3081
|
fs.unlinkSync(info.sentinelPath);
|
|
3037
3082
|
cleanedUp.push(info.sentinelPath);
|
|
@@ -3040,7 +3085,7 @@ async function shutdownTool(args) {
|
|
|
3040
3085
|
fs.unlinkSync(info.eventLogPath);
|
|
3041
3086
|
cleanedUp.push(info.eventLogPath);
|
|
3042
3087
|
} catch {}
|
|
3043
|
-
}
|
|
3088
|
+
});
|
|
3044
3089
|
await sup.close({ skipShutdown: true });
|
|
3045
3090
|
return {
|
|
3046
3091
|
ok: true,
|
|
@@ -3063,11 +3108,24 @@ async function executeAskTool(args, getSupervisorClient) {
|
|
|
3063
3108
|
const { client, isSingleton, sup, supervisorId } = await getSupervisorClient(args.supervisorId);
|
|
3064
3109
|
try {
|
|
3065
3110
|
const target = (isSingleton && sup ? findLocalRunByReference(sup, args.toRunId) : findExternalRun(supervisorId, args.toRunId))?.runtimeId ?? args.toRunId;
|
|
3066
|
-
const
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3111
|
+
const timeoutMs = args.timeoutMs !== void 0 && Number.isFinite(args.timeoutMs) && args.timeoutMs > 0 ? args.timeoutMs : void 0;
|
|
3112
|
+
try {
|
|
3113
|
+
const result = await client.brokerAsk(target, args.message, void 0, timeoutMs);
|
|
3114
|
+
return {
|
|
3115
|
+
reply: extractReplyMessage(result),
|
|
3116
|
+
from_run_id: result.from_run_id ?? ""
|
|
3117
|
+
};
|
|
3118
|
+
} catch (error) {
|
|
3119
|
+
if (error instanceof RpcError && error.data && typeof error.data === "object") {
|
|
3120
|
+
const data = error.data;
|
|
3121
|
+
const messageId = data.message_id;
|
|
3122
|
+
if (typeof messageId === "string" && messageId) {
|
|
3123
|
+
if (data.pending === false) throw new Error(`ask failed (message_id: ${messageId} — the pending ask was already withdrawn): ${error.message}`);
|
|
3124
|
+
throw new Error(`ask failed (message_id: ${messageId} — pass to avenor_cancel to withdraw): ${error.message}`);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
throw error;
|
|
3128
|
+
}
|
|
3071
3129
|
} finally {
|
|
3072
3130
|
if (!isSingleton) client.close();
|
|
3073
3131
|
}
|
|
@@ -3106,6 +3164,43 @@ function createCancelTool(getSupervisorClient) {
|
|
|
3106
3164
|
}
|
|
3107
3165
|
const cancelTool = createCancelTool(getSupervisorClient);
|
|
3108
3166
|
//#endregion
|
|
3167
|
+
//#region src/tools/kill.ts
|
|
3168
|
+
function matchEntry(entry, reference) {
|
|
3169
|
+
const runtimeId = typeof entry.runtime_id === "string" ? entry.runtime_id : "";
|
|
3170
|
+
if (!runtimeId) return void 0;
|
|
3171
|
+
if (runtimeId === reference) return runtimeId;
|
|
3172
|
+
if (typeof entry.label === "string" && entry.label === reference) return runtimeId;
|
|
3173
|
+
if (typeof entry.run_id === "string" && entry.run_id === reference) return runtimeId;
|
|
3174
|
+
if (typeof entry.session_id === "string" && entry.session_id === reference) return runtimeId;
|
|
3175
|
+
}
|
|
3176
|
+
async function resolveRuntimeId(client, reference) {
|
|
3177
|
+
const list = await client.list();
|
|
3178
|
+
for (const entry of list) {
|
|
3179
|
+
const runtimeId = matchEntry(entry, reference);
|
|
3180
|
+
if (runtimeId) return runtimeId;
|
|
3181
|
+
}
|
|
3182
|
+
throw new Error(`run not found: ${reference}`);
|
|
3183
|
+
}
|
|
3184
|
+
async function executeKillTool(args, getSupervisorClient) {
|
|
3185
|
+
validateRunId(args.runId);
|
|
3186
|
+
const { client, isSingleton, sup, supervisorId } = await getSupervisorClient(args.supervisorId);
|
|
3187
|
+
try {
|
|
3188
|
+
const runtimeId = (isSingleton && sup ? findLocalRunByReference(sup, args.runId) : findExternalRun(supervisorId, args.runId))?.runtimeId ?? await resolveRuntimeId(client, args.runId);
|
|
3189
|
+
await client.cancel(runtimeId);
|
|
3190
|
+
return {
|
|
3191
|
+
killed: true,
|
|
3192
|
+
run_id: args.runId,
|
|
3193
|
+
runtime_id: runtimeId
|
|
3194
|
+
};
|
|
3195
|
+
} finally {
|
|
3196
|
+
if (!isSingleton) client.close();
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
function createKillTool(getSupervisorClient) {
|
|
3200
|
+
return (args) => executeKillTool(args, getSupervisorClient);
|
|
3201
|
+
}
|
|
3202
|
+
const killTool = createKillTool(getSupervisorClient);
|
|
3203
|
+
//#endregion
|
|
3109
3204
|
//#region src/tools/broker-receive.ts
|
|
3110
3205
|
async function executeBrokerReceive(args, getSupervisorClient) {
|
|
3111
3206
|
const { client, isSingleton } = await getSupervisorClient(args.supervisorId);
|
|
@@ -3247,4 +3342,4 @@ function createWorkflowReadyTool(getSupervisorClient) {
|
|
|
3247
3342
|
}
|
|
3248
3343
|
const workflowReadyTool = createWorkflowReadyTool(getSupervisorClient);
|
|
3249
3344
|
//#endregion
|
|
3250
|
-
export { DEFAULT_RUN_REDUCER_LIMITS, RunReducer, Supervisor, THINKING_LEVELS, answerPermissionTool, askTool, brokerReceiveTool, brokerReplyTool, cancelTool, createRunSnapshot, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, isThinkingLevel, normalizeRunEvent, observeRun, peersTool, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
|
|
3345
|
+
export { DEFAULT_RUN_REDUCER_LIMITS, RpcError, RunReducer, Supervisor, THINKING_LEVELS, answerPermissionTool, askTool, brokerReceiveTool, brokerReplyTool, cancelTool, createRunSnapshot, createWorkflowCompleteTool, createWorkflowControllerStatusTool, createWorkflowEventsTool, createWorkflowGateTool, createWorkflowInspectTool, createWorkflowReadyTool, createWorkflowStatusTool, createWorkflowWaitTool, dial, evaluateThinkingPolicy, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, isThinkingLevel, killTool, normalizeRunEvent, observeRun, peersTool, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool, validateSpawnSelection, validateThinking, validateThinkingForBackend, validateThinkingForBackendResume, workflowCompleteTool, workflowControllerStatusTool, workflowEventsTool, workflowGateTool, workflowInspectTool, workflowReadyTool, workflowStatusTool, workflowWaitTool };
|