@dougbots/avenor-core 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/dist/index.d.ts +10 -2
- package/dist/index.js +36 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ declare class Client {
|
|
|
67
67
|
list(): Promise<Array<Record<string, unknown>>>;
|
|
68
68
|
spawn(params: SpawnParams): Promise<Record<string, unknown>>;
|
|
69
69
|
shutdown(mode: string): Promise<void>;
|
|
70
|
-
answerPermission(runtimeId: string, requestId: string, optionId: string): Promise<void>;
|
|
70
|
+
answerPermission(runtimeId: string, requestId: string, optionId: string, message?: string): Promise<void>;
|
|
71
71
|
prompt(runtimeId: string, text: string): Promise<void>;
|
|
72
72
|
interruptAndPrompt(runtimeId: string, text: string, keepQueue?: boolean): Promise<void>;
|
|
73
73
|
cancel(runtimeId?: string): Promise<void>;
|
|
@@ -83,6 +83,7 @@ interface RunPermissionOption {
|
|
|
83
83
|
option_id: string;
|
|
84
84
|
label: string;
|
|
85
85
|
kind: string;
|
|
86
|
+
requires_message?: boolean;
|
|
86
87
|
}
|
|
87
88
|
interface RunPermissionSummary {
|
|
88
89
|
request_id?: string;
|
|
@@ -238,6 +239,7 @@ interface RunInfo {
|
|
|
238
239
|
agent?: string;
|
|
239
240
|
agentProfile?: string;
|
|
240
241
|
backend?: string;
|
|
242
|
+
model?: string;
|
|
241
243
|
dir?: string;
|
|
242
244
|
brokerUrl?: string;
|
|
243
245
|
parentToken?: string;
|
|
@@ -272,6 +274,9 @@ declare class Supervisor {
|
|
|
272
274
|
}): Promise<void>;
|
|
273
275
|
}
|
|
274
276
|
//#endregion
|
|
277
|
+
//#region src/paths.d.ts
|
|
278
|
+
declare function socketsRoot(): string;
|
|
279
|
+
//#endregion
|
|
275
280
|
//#region src/tools/spawn.d.ts
|
|
276
281
|
declare function spawnTool(args: {
|
|
277
282
|
agent: string;
|
|
@@ -312,6 +317,7 @@ interface StatusResult {
|
|
|
312
317
|
option_id: string;
|
|
313
318
|
label: string;
|
|
314
319
|
kind: string;
|
|
320
|
+
requires_message?: boolean;
|
|
315
321
|
}>;
|
|
316
322
|
};
|
|
317
323
|
session_id?: string;
|
|
@@ -322,6 +328,7 @@ interface StatusResult {
|
|
|
322
328
|
dir?: string;
|
|
323
329
|
parent_id?: string;
|
|
324
330
|
children?: string[];
|
|
331
|
+
pid?: number;
|
|
325
332
|
event_path?: string;
|
|
326
333
|
usage?: Record<string, unknown>;
|
|
327
334
|
latest_seq?: number;
|
|
@@ -384,6 +391,7 @@ declare function answerPermissionTool(args: {
|
|
|
384
391
|
optionId: string;
|
|
385
392
|
requestId?: string;
|
|
386
393
|
supervisorId?: string;
|
|
394
|
+
message?: string;
|
|
387
395
|
}): Promise<{
|
|
388
396
|
ok: boolean;
|
|
389
397
|
}>;
|
|
@@ -424,4 +432,4 @@ declare function shutdownTool(args: {
|
|
|
424
432
|
cleaned_up: string[];
|
|
425
433
|
}>;
|
|
426
434
|
//#endregion
|
|
427
|
-
export { type Client, DEFAULT_RUN_REDUCER_LIMITS, type Event, type HistoryOptions, type HistoryResult, type InspectResult, type NormalizedRunEvent, type ObserveRunOptions, 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 SpawnParams, type StatusResult, type StatusView, type SubscribeOptions, Supervisor, type SupervisorOptions, answerPermissionTool, createRunSnapshot, dial, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, normalizeRunEvent, observeRun, reduceRunSnapshot, resultTool, shutdownTool, spawnTool, statusTool };
|
|
435
|
+
export { type Client, DEFAULT_RUN_REDUCER_LIMITS, type Event, type HistoryOptions, type HistoryResult, type InspectResult, type NormalizedRunEvent, type ObserveRunOptions, 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 SpawnParams, type StatusResult, type StatusView, type SubscribeOptions, Supervisor, type SupervisorOptions, answerPermissionTool, createRunSnapshot, dial, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, normalizeRunEvent, observeRun, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool };
|
package/dist/index.js
CHANGED
|
@@ -246,12 +246,14 @@ var Client = class {
|
|
|
246
246
|
async shutdown(mode) {
|
|
247
247
|
await this.call("shutdown", { mode });
|
|
248
248
|
}
|
|
249
|
-
async answerPermission(runtimeId, requestId, optionId) {
|
|
250
|
-
|
|
249
|
+
async answerPermission(runtimeId, requestId, optionId, message) {
|
|
250
|
+
const params = {
|
|
251
251
|
runtime_id: runtimeId,
|
|
252
252
|
request_id: requestId,
|
|
253
253
|
option_id: optionId
|
|
254
|
-
}
|
|
254
|
+
};
|
|
255
|
+
if (message) params.message = message;
|
|
256
|
+
await this.call("answer_permission", params);
|
|
255
257
|
}
|
|
256
258
|
async prompt(runtimeId, text) {
|
|
257
259
|
await this.call("prompt", {
|
|
@@ -363,13 +365,15 @@ function normalizePermissionOptions(value) {
|
|
|
363
365
|
const record = asRecord(item);
|
|
364
366
|
if (!record) continue;
|
|
365
367
|
const option_id = stringField(record, "option_id", "optionId") ?? "";
|
|
366
|
-
const label = stringField(record, "label") ?? option_id;
|
|
368
|
+
const label = stringField(record, "label", "name") ?? option_id;
|
|
367
369
|
const kind = stringField(record, "kind") ?? "";
|
|
370
|
+
const requires_message = record.requires_message === true || record.requiresMessage === true;
|
|
368
371
|
if (!option_id && !label && !kind) continue;
|
|
369
372
|
options.push({
|
|
370
373
|
option_id,
|
|
371
374
|
label,
|
|
372
|
-
kind
|
|
375
|
+
kind,
|
|
376
|
+
...requires_message && { requires_message: true }
|
|
373
377
|
});
|
|
374
378
|
}
|
|
375
379
|
return options;
|
|
@@ -1271,6 +1275,7 @@ var Supervisor = class Supervisor {
|
|
|
1271
1275
|
agent: spawnParams.agent ?? params.agent,
|
|
1272
1276
|
agentProfile: spawnParams.agent_profile,
|
|
1273
1277
|
backend: spawnParams.backend,
|
|
1278
|
+
model: spawnParams.model,
|
|
1274
1279
|
dir: spawnParams.dir,
|
|
1275
1280
|
brokerUrl: result.broker_url,
|
|
1276
1281
|
parentToken: result.parent_token
|
|
@@ -1438,6 +1443,9 @@ async function sentinelExists(filePath) {
|
|
|
1438
1443
|
return false;
|
|
1439
1444
|
}
|
|
1440
1445
|
}
|
|
1446
|
+
function rawStatusPhase(source) {
|
|
1447
|
+
return stringField(source ?? {}, "phase") || stringField(source ?? {}, "status") || "running";
|
|
1448
|
+
}
|
|
1441
1449
|
function sentinelStatusToResult(sentinelStatus) {
|
|
1442
1450
|
switch (sentinelStatus) {
|
|
1443
1451
|
case "DONE": return "done";
|
|
@@ -1475,8 +1483,9 @@ function normalizePermission(raw) {
|
|
|
1475
1483
|
if (!record) return null;
|
|
1476
1484
|
return {
|
|
1477
1485
|
option_id: stringField(record, "option_id", "optionId") ?? "",
|
|
1478
|
-
label: stringField(record, "label") ?? "",
|
|
1479
|
-
kind: stringField(record, "kind") ?? ""
|
|
1486
|
+
label: stringField(record, "label", "name") ?? "",
|
|
1487
|
+
kind: stringField(record, "kind") ?? "",
|
|
1488
|
+
...(record.requires_message === true || record.requiresMessage === true) && { requires_message: true }
|
|
1480
1489
|
};
|
|
1481
1490
|
}).filter((item) => item !== null) : [];
|
|
1482
1491
|
if (!request_id && !description && options.length === 0) return;
|
|
@@ -1511,6 +1520,7 @@ function buildBaseStatus(source, fallback, translatedStatus) {
|
|
|
1511
1520
|
dir: stringField(source, "dir"),
|
|
1512
1521
|
parent_id: stringField(source, "parent_id", "parentId"),
|
|
1513
1522
|
children: stringArrayField(source, "children"),
|
|
1523
|
+
pid: typeof source.pid === "number" ? source.pid : void 0,
|
|
1514
1524
|
event_path: stringField(source, "event_path", "on_event"),
|
|
1515
1525
|
usage: asRecord(source.usage) ?? void 0,
|
|
1516
1526
|
latest_seq: numberField(source, "latest_seq"),
|
|
@@ -1535,7 +1545,7 @@ function shapeStatusResult(result, view = "full") {
|
|
|
1535
1545
|
async function buildRunStatus(runInfo, liveStatus) {
|
|
1536
1546
|
let sentinel = null;
|
|
1537
1547
|
if (await sentinelExists(runInfo.sentinelPath)) sentinel = await parseSentinel$1(runInfo.sentinelPath);
|
|
1538
|
-
const translated = translateStatus(liveStatus
|
|
1548
|
+
const translated = translateStatus(rawStatusPhase(liveStatus), sentinel);
|
|
1539
1549
|
return buildBaseStatus(liveStatus ?? {}, {
|
|
1540
1550
|
run_id: runInfo.runId,
|
|
1541
1551
|
label: runInfo.label,
|
|
@@ -1580,14 +1590,14 @@ async function statusTool(args) {
|
|
|
1580
1590
|
runtime_id: stringField(liveStatus ?? {}, "runtime_id", "id"),
|
|
1581
1591
|
session_id: sentinel?.SESSION ?? liveStatus?.session_id,
|
|
1582
1592
|
stop_reason: sentinel?._status
|
|
1583
|
-
}, translateStatus(liveStatus
|
|
1593
|
+
}, translateStatus(rawStatusPhase(liveStatus), sentinel)), args.view);
|
|
1584
1594
|
}
|
|
1585
1595
|
return (await client.list()).map((entry) => shapeStatusResult(buildBaseStatus(entry, {
|
|
1586
1596
|
run_id: String(entry.run_id ?? entry.runtime_id ?? entry.id ?? ""),
|
|
1587
1597
|
label: String(entry.label ?? entry.runtime_id ?? entry.id ?? ""),
|
|
1588
1598
|
runtime_id: String(entry.runtime_id ?? entry.id ?? ""),
|
|
1589
1599
|
session_id: entry.session_id
|
|
1590
|
-
}, translateStatus(entry
|
|
1600
|
+
}, translateStatus(rawStatusPhase(entry), null)), args.view));
|
|
1591
1601
|
} finally {
|
|
1592
1602
|
if (!isSingleton) client.close();
|
|
1593
1603
|
}
|
|
@@ -1608,7 +1618,7 @@ async function statusTool(args) {
|
|
|
1608
1618
|
runtime_id: stringField(liveStatus ?? {}, "runtime_id", "id"),
|
|
1609
1619
|
session_id: sentinel?.SESSION ?? liveStatus?.session_id,
|
|
1610
1620
|
stop_reason: sentinel?._status
|
|
1611
|
-
}, translateStatus(liveStatus
|
|
1621
|
+
}, translateStatus(rawStatusPhase(liveStatus), sentinel)), args.view);
|
|
1612
1622
|
}
|
|
1613
1623
|
const list = await client.list();
|
|
1614
1624
|
const results = [];
|
|
@@ -1623,7 +1633,7 @@ async function statusTool(args) {
|
|
|
1623
1633
|
label: entryLabel,
|
|
1624
1634
|
runtime_id: entryId,
|
|
1625
1635
|
session_id: entry.session_id
|
|
1626
|
-
}, translateStatus(entry
|
|
1636
|
+
}, translateStatus(rawStatusPhase(entry), null)), args.view));
|
|
1627
1637
|
}
|
|
1628
1638
|
return results;
|
|
1629
1639
|
}
|
|
@@ -1981,6 +1991,12 @@ function findRunByLabel$1(sup, runId) {
|
|
|
1981
1991
|
if (byKey) return byKey;
|
|
1982
1992
|
for (const info of runs.values()) if (info.label === runId) return info;
|
|
1983
1993
|
}
|
|
1994
|
+
function pendingPermissionRequestID(liveStatus) {
|
|
1995
|
+
const status = asRecord(liveStatus);
|
|
1996
|
+
if (!status) return void 0;
|
|
1997
|
+
const permission = asRecord(status.permission) ?? asRecord(status.pending_permission);
|
|
1998
|
+
return permission ? stringField(permission, "request_id", "requestId") : void 0;
|
|
1999
|
+
}
|
|
1984
2000
|
async function answerPermissionTool(args) {
|
|
1985
2001
|
let client;
|
|
1986
2002
|
let sup = null;
|
|
@@ -1996,11 +2012,10 @@ async function answerPermissionTool(args) {
|
|
|
1996
2012
|
validateRunId(args.runId);
|
|
1997
2013
|
const runtimeId = (sup ? findRunByLabel$1(sup, args.runId) : void 0)?.runtimeId ?? args.runId;
|
|
1998
2014
|
if (!requestId) {
|
|
1999
|
-
|
|
2000
|
-
if (!
|
|
2001
|
-
requestId = pp.request_id;
|
|
2015
|
+
requestId = pendingPermissionRequestID(await client.status(runtimeId));
|
|
2016
|
+
if (!requestId) throw new Error("no pending permission request for this run");
|
|
2002
2017
|
}
|
|
2003
|
-
await client.answerPermission(runtimeId, requestId, args.optionId);
|
|
2018
|
+
await client.answerPermission(runtimeId, requestId, args.optionId, args.message);
|
|
2004
2019
|
return { ok: true };
|
|
2005
2020
|
} finally {
|
|
2006
2021
|
if (supervisorId && !isSingleton) client.close();
|
|
@@ -2052,6 +2067,7 @@ async function followUpTool(args) {
|
|
|
2052
2067
|
if (!sessionId) throw new Error("run has no session to resume");
|
|
2053
2068
|
const agent = requireResumableAgent(liveStatus?.agent ?? runInfo?.agent);
|
|
2054
2069
|
const backend = liveStatus?.backend ?? runInfo?.backend;
|
|
2070
|
+
const model = liveStatus?.model ?? runInfo?.model;
|
|
2055
2071
|
const dir = liveStatus?.dir ?? runInfo?.dir;
|
|
2056
2072
|
const agentProfile = liveStatus?.agent_profile ?? runInfo?.agentProfile;
|
|
2057
2073
|
const followUpRunId = crypto.randomUUID();
|
|
@@ -2066,6 +2082,7 @@ async function followUpTool(args) {
|
|
|
2066
2082
|
on_event: eventLogPath
|
|
2067
2083
|
};
|
|
2068
2084
|
if (backend) spawnParams.backend = backend;
|
|
2085
|
+
if (model) spawnParams.model = model;
|
|
2069
2086
|
if (dir) spawnParams.dir = dir;
|
|
2070
2087
|
if (agentProfile) spawnParams.agent_profile = agentProfile;
|
|
2071
2088
|
return {
|
|
@@ -2088,12 +2105,14 @@ async function followUpTool(args) {
|
|
|
2088
2105
|
} catch {}
|
|
2089
2106
|
const agent = requireResumableAgent(liveStatus?.agent ?? runInfo.agent);
|
|
2090
2107
|
const backend = liveStatus?.backend ?? runInfo.backend;
|
|
2108
|
+
const model = liveStatus?.model ?? runInfo.model;
|
|
2091
2109
|
const dir = liveStatus?.dir ?? runInfo.dir;
|
|
2092
2110
|
const agentProfile = liveStatus?.agent_profile ?? runInfo.agentProfile;
|
|
2093
2111
|
const followUpLabel = args.label ?? `${runInfo.label}-followup`;
|
|
2094
2112
|
const followUpRun = await sup.spawn({
|
|
2095
2113
|
agent,
|
|
2096
2114
|
backend,
|
|
2115
|
+
model,
|
|
2097
2116
|
dir,
|
|
2098
2117
|
agent_profile: agentProfile,
|
|
2099
2118
|
prompt: args.message,
|
|
@@ -2162,4 +2181,4 @@ async function shutdownTool(args) {
|
|
|
2162
2181
|
};
|
|
2163
2182
|
}
|
|
2164
2183
|
//#endregion
|
|
2165
|
-
export { DEFAULT_RUN_REDUCER_LIMITS, RunReducer, Supervisor, answerPermissionTool, createRunSnapshot, dial, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, normalizeRunEvent, observeRun, reduceRunSnapshot, resultTool, shutdownTool, spawnTool, statusTool };
|
|
2184
|
+
export { DEFAULT_RUN_REDUCER_LIMITS, RunReducer, Supervisor, answerPermissionTool, createRunSnapshot, dial, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, normalizeRunEvent, observeRun, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool };
|