@dougbots/avenor-core 0.8.2 → 0.8.3
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 +39 -31
- package/dist/index.js +57 -37
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ interface HistoryResult<TEvent = Event> {
|
|
|
25
25
|
latest_seq?: number;
|
|
26
26
|
}
|
|
27
27
|
interface SpawnParams {
|
|
28
|
-
agent
|
|
28
|
+
agent?: string;
|
|
29
29
|
prompt_file?: string;
|
|
30
30
|
prompt?: string;
|
|
31
31
|
dir?: string;
|
|
@@ -253,6 +253,7 @@ interface SupervisorOptions {
|
|
|
253
253
|
declare function findAvenorBinary(): string;
|
|
254
254
|
declare class Supervisor {
|
|
255
255
|
private static instance;
|
|
256
|
+
private static starting;
|
|
256
257
|
private static cleanupRegistered;
|
|
257
258
|
private static registerCleanup;
|
|
258
259
|
private client;
|
|
@@ -265,6 +266,7 @@ declare class Supervisor {
|
|
|
265
266
|
private callTimeoutMs;
|
|
266
267
|
private constructor();
|
|
267
268
|
static get(opts?: SupervisorOptions): Promise<Supervisor>;
|
|
269
|
+
private static start;
|
|
268
270
|
private startProcess;
|
|
269
271
|
get supervisorId(): string;
|
|
270
272
|
static isCurrentInstance(supervisorId: string): boolean;
|
|
@@ -281,7 +283,7 @@ declare function socketsRoot(): string;
|
|
|
281
283
|
//#endregion
|
|
282
284
|
//#region src/tools/spawn.d.ts
|
|
283
285
|
declare function spawnTool(args: {
|
|
284
|
-
agent
|
|
286
|
+
agent?: string;
|
|
285
287
|
prompt?: string;
|
|
286
288
|
promptFile?: string;
|
|
287
289
|
label?: string;
|
|
@@ -305,6 +307,11 @@ declare function spawnTool(args: {
|
|
|
305
307
|
//#endregion
|
|
306
308
|
//#region src/tools/status.d.ts
|
|
307
309
|
type StatusView = 'lifecycle' | 'full';
|
|
310
|
+
interface StatusToolArgs {
|
|
311
|
+
runId?: string;
|
|
312
|
+
supervisorId?: string;
|
|
313
|
+
view?: StatusView;
|
|
314
|
+
}
|
|
308
315
|
interface StatusResult {
|
|
309
316
|
run_id: string;
|
|
310
317
|
label: string;
|
|
@@ -337,13 +344,33 @@ interface StatusResult {
|
|
|
337
344
|
final_output?: string;
|
|
338
345
|
final_output_truncated?: boolean;
|
|
339
346
|
}
|
|
340
|
-
declare
|
|
341
|
-
|
|
347
|
+
declare const statusTool: (args: StatusToolArgs) => Promise<StatusResult | StatusResult[]>;
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/tools/events.d.ts
|
|
350
|
+
interface EventsToolArgs {
|
|
351
|
+
runId: string;
|
|
352
|
+
types?: string[];
|
|
353
|
+
limit?: number;
|
|
342
354
|
supervisorId?: string;
|
|
343
|
-
|
|
344
|
-
}
|
|
355
|
+
after_seq?: number;
|
|
356
|
+
}
|
|
357
|
+
interface EventsToolResult {
|
|
358
|
+
events: Array<{
|
|
359
|
+
event?: string;
|
|
360
|
+
type?: string;
|
|
361
|
+
ts?: number;
|
|
362
|
+
[key: string]: unknown;
|
|
363
|
+
}>;
|
|
364
|
+
}
|
|
365
|
+
declare const eventsTool: (args: EventsToolArgs) => Promise<EventsToolResult>;
|
|
345
366
|
//#endregion
|
|
346
367
|
//#region src/tools/inspect.d.ts
|
|
368
|
+
interface InspectToolArgs {
|
|
369
|
+
runId: string;
|
|
370
|
+
supervisorId?: string;
|
|
371
|
+
limit?: number;
|
|
372
|
+
after_seq?: number;
|
|
373
|
+
}
|
|
347
374
|
interface InspectResult {
|
|
348
375
|
run_id: string;
|
|
349
376
|
label: string;
|
|
@@ -356,12 +383,7 @@ interface InspectResult {
|
|
|
356
383
|
pending_permission?: RunSnapshot['pending_permission'];
|
|
357
384
|
final_output?: string;
|
|
358
385
|
}
|
|
359
|
-
declare
|
|
360
|
-
runId: string;
|
|
361
|
-
supervisorId?: string;
|
|
362
|
-
limit?: number;
|
|
363
|
-
after_seq?: number;
|
|
364
|
-
}): Promise<InspectResult>;
|
|
386
|
+
declare const inspectTool: (args: InspectToolArgs) => Promise<InspectResult>;
|
|
365
387
|
//#endregion
|
|
366
388
|
//#region src/tools/result.d.ts
|
|
367
389
|
interface ResultResult {
|
|
@@ -399,31 +421,17 @@ declare function answerPermissionTool(args: {
|
|
|
399
421
|
}>;
|
|
400
422
|
//#endregion
|
|
401
423
|
//#region src/tools/follow-up.d.ts
|
|
402
|
-
|
|
424
|
+
interface FollowUpToolArgs {
|
|
403
425
|
runId: string;
|
|
404
426
|
message: string;
|
|
405
427
|
label?: string;
|
|
406
428
|
supervisorId?: string;
|
|
407
|
-
}
|
|
429
|
+
}
|
|
430
|
+
interface FollowUpToolResult {
|
|
408
431
|
run_id: string;
|
|
409
432
|
label: string;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
//#region src/tools/events.d.ts
|
|
413
|
-
declare function eventsTool(args: {
|
|
414
|
-
runId: string;
|
|
415
|
-
types?: string[];
|
|
416
|
-
limit?: number;
|
|
417
|
-
supervisorId?: string;
|
|
418
|
-
after_seq?: number;
|
|
419
|
-
}): Promise<{
|
|
420
|
-
events: Array<{
|
|
421
|
-
event?: string;
|
|
422
|
-
type?: string;
|
|
423
|
-
ts?: number;
|
|
424
|
-
[key: string]: unknown;
|
|
425
|
-
}>;
|
|
426
|
-
}>;
|
|
433
|
+
}
|
|
434
|
+
declare const followUpTool: (args: FollowUpToolArgs) => Promise<FollowUpToolResult>;
|
|
427
435
|
//#endregion
|
|
428
436
|
//#region src/tools/shutdown.d.ts
|
|
429
437
|
declare function shutdownTool(args: {
|
package/dist/index.js
CHANGED
|
@@ -1118,6 +1118,7 @@ function findAvenorBinary() {
|
|
|
1118
1118
|
}
|
|
1119
1119
|
var Supervisor = class Supervisor {
|
|
1120
1120
|
static instance = null;
|
|
1121
|
+
static starting = null;
|
|
1121
1122
|
static cleanupRegistered = false;
|
|
1122
1123
|
static registerCleanup() {
|
|
1123
1124
|
if (Supervisor.cleanupRegistered) return;
|
|
@@ -1148,8 +1149,18 @@ var Supervisor = class Supervisor {
|
|
|
1148
1149
|
this.socketPath = socketPath;
|
|
1149
1150
|
this.callTimeoutMs = opts?.callTimeoutMs ?? 3e4;
|
|
1150
1151
|
}
|
|
1151
|
-
static
|
|
1152
|
-
if (Supervisor.instance && !Supervisor.instance.crashed) return Supervisor.instance;
|
|
1152
|
+
static get(opts) {
|
|
1153
|
+
if (Supervisor.instance && !Supervisor.instance.crashed) return Promise.resolve(Supervisor.instance);
|
|
1154
|
+
if (Supervisor.starting) return Supervisor.starting;
|
|
1155
|
+
const starting = Supervisor.start(opts);
|
|
1156
|
+
Supervisor.starting = starting;
|
|
1157
|
+
const clearStarting = () => {
|
|
1158
|
+
if (Supervisor.starting === starting) Supervisor.starting = null;
|
|
1159
|
+
};
|
|
1160
|
+
starting.then(clearStarting, clearStarting);
|
|
1161
|
+
return starting;
|
|
1162
|
+
}
|
|
1163
|
+
static async start(opts) {
|
|
1153
1164
|
Supervisor.registerCleanup();
|
|
1154
1165
|
const binaryPath = opts?.binaryPath ?? findAvenorBinary();
|
|
1155
1166
|
const socketDir = socketsRoot();
|
|
@@ -1354,25 +1365,28 @@ async function getSupervisorClient(supervisorId) {
|
|
|
1354
1365
|
async function spawnTool(args) {
|
|
1355
1366
|
const runId = crypto.randomUUID();
|
|
1356
1367
|
const label = args.label ?? runId;
|
|
1368
|
+
const baseParams = {
|
|
1369
|
+
prompt: args.prompt,
|
|
1370
|
+
prompt_file: args.promptFile,
|
|
1371
|
+
label,
|
|
1372
|
+
dir: args.dir,
|
|
1373
|
+
timeout: args.timeout !== void 0 ? validateTimeout(args.timeout) : void 0,
|
|
1374
|
+
model: args.model,
|
|
1375
|
+
agent_profile: args.agentProfile,
|
|
1376
|
+
backend: args.backend,
|
|
1377
|
+
server_url: args.serverUrl,
|
|
1378
|
+
session_id: args.sessionId,
|
|
1379
|
+
parent_run_id: args.parent_run_id
|
|
1380
|
+
};
|
|
1381
|
+
if (args.agent) baseParams.agent = args.agent;
|
|
1357
1382
|
if (args.supervisorId) {
|
|
1358
1383
|
const { client, isSingleton, supervisorId } = await getSupervisorClient(args.supervisorId);
|
|
1359
1384
|
const { sentinelPath, eventLogPath } = ensureRunPaths(runId);
|
|
1360
1385
|
try {
|
|
1361
1386
|
const result = await client.spawn({
|
|
1362
|
-
|
|
1363
|
-
prompt: args.prompt,
|
|
1364
|
-
prompt_file: args.promptFile,
|
|
1365
|
-
label,
|
|
1366
|
-
dir: args.dir,
|
|
1367
|
-
timeout: args.timeout !== void 0 ? validateTimeout(args.timeout) : void 0,
|
|
1368
|
-
model: args.model,
|
|
1369
|
-
agent_profile: args.agentProfile,
|
|
1370
|
-
backend: args.backend,
|
|
1371
|
-
server_url: args.serverUrl,
|
|
1372
|
-
session_id: args.sessionId,
|
|
1387
|
+
...baseParams,
|
|
1373
1388
|
sentinel_file: sentinelPath,
|
|
1374
|
-
on_event: eventLogPath
|
|
1375
|
-
parent_run_id: args.parent_run_id
|
|
1389
|
+
on_event: eventLogPath
|
|
1376
1390
|
});
|
|
1377
1391
|
return {
|
|
1378
1392
|
run_id: result.runtime_id ?? runId,
|
|
@@ -1387,20 +1401,7 @@ async function spawnTool(args) {
|
|
|
1387
1401
|
}
|
|
1388
1402
|
}
|
|
1389
1403
|
const sup = await Supervisor.get();
|
|
1390
|
-
const runInfo = await sup.spawn(
|
|
1391
|
-
agent: args.agent,
|
|
1392
|
-
prompt: args.prompt,
|
|
1393
|
-
prompt_file: args.promptFile,
|
|
1394
|
-
label,
|
|
1395
|
-
dir: args.dir,
|
|
1396
|
-
timeout: args.timeout !== void 0 ? validateTimeout(args.timeout) : void 0,
|
|
1397
|
-
model: args.model,
|
|
1398
|
-
agent_profile: args.agentProfile,
|
|
1399
|
-
backend: args.backend,
|
|
1400
|
-
server_url: args.serverUrl,
|
|
1401
|
-
session_id: args.sessionId,
|
|
1402
|
-
parent_run_id: args.parent_run_id
|
|
1403
|
-
}, runId);
|
|
1404
|
+
const runInfo = await sup.spawn(baseParams, runId);
|
|
1404
1405
|
return {
|
|
1405
1406
|
run_id: runInfo.runId,
|
|
1406
1407
|
label: runInfo.label,
|
|
@@ -1564,7 +1565,7 @@ async function queryLiveStatus(client, runtimeId) {
|
|
|
1564
1565
|
return null;
|
|
1565
1566
|
}
|
|
1566
1567
|
}
|
|
1567
|
-
async function
|
|
1568
|
+
async function executeStatusTool(args, getSupervisorClient) {
|
|
1568
1569
|
if (args.supervisorId) {
|
|
1569
1570
|
const { client, isSingleton, sup } = await getSupervisorClient(args.supervisorId);
|
|
1570
1571
|
try {
|
|
@@ -1638,6 +1639,10 @@ async function statusTool(args) {
|
|
|
1638
1639
|
}
|
|
1639
1640
|
return results;
|
|
1640
1641
|
}
|
|
1642
|
+
function createStatusTool(getSupervisorClient) {
|
|
1643
|
+
return (args) => executeStatusTool(args, getSupervisorClient);
|
|
1644
|
+
}
|
|
1645
|
+
const statusTool = createStatusTool(getSupervisorClient);
|
|
1641
1646
|
//#endregion
|
|
1642
1647
|
//#region src/tools/events.ts
|
|
1643
1648
|
const MAX_EVENT_LIMIT = 1e3;
|
|
@@ -1717,7 +1722,7 @@ async function readNdjsonEvents(filePath, args) {
|
|
|
1717
1722
|
}
|
|
1718
1723
|
return events;
|
|
1719
1724
|
}
|
|
1720
|
-
async function resolveRun(args) {
|
|
1725
|
+
async function resolveRun(args, getSupervisorClient) {
|
|
1721
1726
|
if (args.supervisorId) {
|
|
1722
1727
|
const { client, isSingleton, sup } = await getSupervisorClient(args.supervisorId);
|
|
1723
1728
|
const runInfo = isSingleton && sup ? findRunByLabel$2(sup, args.runId) : void 0;
|
|
@@ -1788,9 +1793,9 @@ async function resolveRun(args) {
|
|
|
1788
1793
|
eventLogPath
|
|
1789
1794
|
};
|
|
1790
1795
|
}
|
|
1791
|
-
async function
|
|
1796
|
+
async function executeEventsTool(args, getSupervisorClient) {
|
|
1792
1797
|
const limit = normalizeLimit(args.limit);
|
|
1793
|
-
const resolved = await resolveRun(args);
|
|
1798
|
+
const resolved = await resolveRun(args, getSupervisorClient);
|
|
1794
1799
|
try {
|
|
1795
1800
|
const failures = [];
|
|
1796
1801
|
if (resolved.eventLogPath) try {
|
|
@@ -1818,21 +1823,25 @@ async function eventsTool(args) {
|
|
|
1818
1823
|
if (!resolved.isSingleton) resolved.client.close();
|
|
1819
1824
|
}
|
|
1820
1825
|
}
|
|
1826
|
+
function createEventsTool(getSupervisorClient) {
|
|
1827
|
+
return (args) => executeEventsTool(args, getSupervisorClient);
|
|
1828
|
+
}
|
|
1829
|
+
const eventsTool = createEventsTool(getSupervisorClient);
|
|
1821
1830
|
//#endregion
|
|
1822
1831
|
//#region src/tools/inspect.ts
|
|
1823
1832
|
function publicSnapshot(snapshot) {
|
|
1824
1833
|
const { _seen_seq_by_scope: _seen, _recent_legacy_keys: _recent, _last_semantic_fingerprint: _fingerprint, _last_source_event: _source, ...rest } = snapshot;
|
|
1825
1834
|
return rest;
|
|
1826
1835
|
}
|
|
1827
|
-
async function
|
|
1828
|
-
const rawStatus = await
|
|
1836
|
+
async function executeInspectTool(args, deps) {
|
|
1837
|
+
const rawStatus = await deps.status({
|
|
1829
1838
|
runId: args.runId,
|
|
1830
1839
|
supervisorId: args.supervisorId
|
|
1831
1840
|
});
|
|
1832
1841
|
const status = Array.isArray(rawStatus) ? rawStatus[0] : rawStatus;
|
|
1833
1842
|
if (!status) throw new Error(`run not found: ${args.runId}`);
|
|
1834
1843
|
const reducer = new RunReducer();
|
|
1835
|
-
const { events } = await
|
|
1844
|
+
const { events } = await deps.events({
|
|
1836
1845
|
runId: args.runId,
|
|
1837
1846
|
supervisorId: args.supervisorId,
|
|
1838
1847
|
limit: args.limit,
|
|
@@ -1875,6 +1884,13 @@ async function inspectTool(args) {
|
|
|
1875
1884
|
final_output: clean.final_output
|
|
1876
1885
|
};
|
|
1877
1886
|
}
|
|
1887
|
+
function createInspectTool(deps) {
|
|
1888
|
+
return (args) => executeInspectTool(args, deps);
|
|
1889
|
+
}
|
|
1890
|
+
const inspectTool = createInspectTool({
|
|
1891
|
+
status: statusTool,
|
|
1892
|
+
events: eventsTool
|
|
1893
|
+
});
|
|
1878
1894
|
//#endregion
|
|
1879
1895
|
//#region src/tools/result.ts
|
|
1880
1896
|
const DEFAULT_POLL_INTERVAL_MS = 1e3;
|
|
@@ -2057,7 +2073,7 @@ async function parseSentinel(filePath) {
|
|
|
2057
2073
|
return null;
|
|
2058
2074
|
}
|
|
2059
2075
|
}
|
|
2060
|
-
async function
|
|
2076
|
+
async function executeFollowUpTool(args, getSupervisorClient) {
|
|
2061
2077
|
if (args.supervisorId) {
|
|
2062
2078
|
const { client, isSingleton, sup } = await getSupervisorClient(args.supervisorId);
|
|
2063
2079
|
try {
|
|
@@ -2134,6 +2150,10 @@ async function followUpTool(args) {
|
|
|
2134
2150
|
label: followUpRun.label
|
|
2135
2151
|
};
|
|
2136
2152
|
}
|
|
2153
|
+
function createFollowUpTool(getSupervisorClient) {
|
|
2154
|
+
return (args) => executeFollowUpTool(args, getSupervisorClient);
|
|
2155
|
+
}
|
|
2156
|
+
const followUpTool = createFollowUpTool(getSupervisorClient);
|
|
2137
2157
|
//#endregion
|
|
2138
2158
|
//#region src/tools/shutdown.ts
|
|
2139
2159
|
async function shutdownTool(args) {
|