@dougbots/avenor-core 0.8.3 → 0.9.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 +7 -1
- package/dist/index.js +43 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface HistoryResult<TEvent = Event> {
|
|
|
24
24
|
events: TEvent[];
|
|
25
25
|
latest_seq?: number;
|
|
26
26
|
}
|
|
27
|
+
type ThinkingLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
27
28
|
interface SpawnParams {
|
|
28
29
|
agent?: string;
|
|
29
30
|
prompt_file?: string;
|
|
@@ -32,6 +33,7 @@ interface SpawnParams {
|
|
|
32
33
|
label?: string;
|
|
33
34
|
timeout?: number;
|
|
34
35
|
model?: string;
|
|
36
|
+
thinking?: ThinkingLevel;
|
|
35
37
|
agent_profile?: string;
|
|
36
38
|
backend?: string;
|
|
37
39
|
server_url?: string;
|
|
@@ -44,6 +46,7 @@ interface SpawnParams {
|
|
|
44
46
|
declare class Client {
|
|
45
47
|
private socket;
|
|
46
48
|
private rl;
|
|
49
|
+
private closed;
|
|
47
50
|
private nextID;
|
|
48
51
|
private pending;
|
|
49
52
|
private started;
|
|
@@ -72,6 +75,7 @@ declare class Client {
|
|
|
72
75
|
prompt(runtimeId: string, text: string): Promise<void>;
|
|
73
76
|
interruptAndPrompt(runtimeId: string, text: string, keepQueue?: boolean): Promise<void>;
|
|
74
77
|
cancel(runtimeId?: string): Promise<void>;
|
|
78
|
+
isClosed(): boolean;
|
|
75
79
|
close(): void;
|
|
76
80
|
}
|
|
77
81
|
declare function dial(socketPath: string, opts?: {
|
|
@@ -241,6 +245,7 @@ interface RunInfo {
|
|
|
241
245
|
agentProfile?: string;
|
|
242
246
|
backend?: string;
|
|
243
247
|
model?: string;
|
|
248
|
+
thinking?: ThinkingLevel;
|
|
244
249
|
dir?: string;
|
|
245
250
|
brokerUrl?: string;
|
|
246
251
|
parentToken?: string;
|
|
@@ -290,6 +295,7 @@ declare function spawnTool(args: {
|
|
|
290
295
|
dir?: string;
|
|
291
296
|
timeout?: string;
|
|
292
297
|
model?: string;
|
|
298
|
+
thinking?: ThinkingLevel;
|
|
293
299
|
agentProfile?: string;
|
|
294
300
|
backend?: string;
|
|
295
301
|
serverUrl?: string;
|
|
@@ -442,4 +448,4 @@ declare function shutdownTool(args: {
|
|
|
442
448
|
cleaned_up: string[];
|
|
443
449
|
}>;
|
|
444
450
|
//#endregion
|
|
445
|
-
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 };
|
|
451
|
+
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, type ThinkingLevel, answerPermissionTool, createRunSnapshot, dial, eventsTool, extractEventText, findAvenorBinary, followUpTool, getInstallDir, getVersion, inspectTool, installerBinaryPath, normalizeRunEvent, observeRun, reduceRunSnapshot, resultTool, shutdownTool, socketsRoot, spawnTool, statusTool };
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ function removeResolver(resolvers, target) {
|
|
|
26
26
|
var Client = class {
|
|
27
27
|
socket;
|
|
28
28
|
rl;
|
|
29
|
+
closed = false;
|
|
29
30
|
nextID = 0;
|
|
30
31
|
pending = /* @__PURE__ */ new Map();
|
|
31
32
|
started = false;
|
|
@@ -44,11 +45,15 @@ var Client = class {
|
|
|
44
45
|
});
|
|
45
46
|
this.callTimeout = opts?.callTimeoutMs ?? 3e4;
|
|
46
47
|
this.socket.on("error", (err) => {
|
|
48
|
+
this.closed = true;
|
|
47
49
|
this.pushEvent({
|
|
48
50
|
event: "protocol-error",
|
|
49
51
|
message: err.message
|
|
50
52
|
});
|
|
51
53
|
});
|
|
54
|
+
this.socket.on("close", () => {
|
|
55
|
+
this.closed = true;
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
startReadLoop() {
|
|
54
59
|
if (this.started) return;
|
|
@@ -85,6 +90,7 @@ var Client = class {
|
|
|
85
90
|
}
|
|
86
91
|
});
|
|
87
92
|
this.rl.on("close", () => {
|
|
93
|
+
this.closed = true;
|
|
88
94
|
for (const [, pc] of this.pending) {
|
|
89
95
|
clearTimeout(pc.timer);
|
|
90
96
|
pc.reject(/* @__PURE__ */ new Error("read response: connection closed"));
|
|
@@ -116,6 +122,7 @@ var Client = class {
|
|
|
116
122
|
else this.dropped++;
|
|
117
123
|
}
|
|
118
124
|
async call(method, params) {
|
|
125
|
+
if (this.isClosed()) throw new Error("control socket is closed");
|
|
119
126
|
this.startReadLoop();
|
|
120
127
|
const id = ++this.nextID;
|
|
121
128
|
const req = {
|
|
@@ -137,6 +144,7 @@ var Client = class {
|
|
|
137
144
|
});
|
|
138
145
|
this.socket.write(data, (err) => {
|
|
139
146
|
if (err) {
|
|
147
|
+
this.closed = true;
|
|
140
148
|
clearTimeout(timer);
|
|
141
149
|
this.pending.delete(id);
|
|
142
150
|
reject(/* @__PURE__ */ new Error(`write request: ${err.message}`));
|
|
@@ -272,7 +280,11 @@ var Client = class {
|
|
|
272
280
|
const params = runtimeId ? { runtime_id: runtimeId } : void 0;
|
|
273
281
|
await this.call("cancel", params);
|
|
274
282
|
}
|
|
283
|
+
isClosed() {
|
|
284
|
+
return this.closed || this.socket.destroyed || this.socket.writableEnded;
|
|
285
|
+
}
|
|
275
286
|
close() {
|
|
287
|
+
this.closed = true;
|
|
276
288
|
this.rl.close();
|
|
277
289
|
this.socket.destroy();
|
|
278
290
|
}
|
|
@@ -1150,7 +1162,14 @@ var Supervisor = class Supervisor {
|
|
|
1150
1162
|
this.callTimeoutMs = opts?.callTimeoutMs ?? 3e4;
|
|
1151
1163
|
}
|
|
1152
1164
|
static get(opts) {
|
|
1153
|
-
|
|
1165
|
+
const current = Supervisor.instance;
|
|
1166
|
+
if (current && !current.crashed) {
|
|
1167
|
+
if (current.client && !current.client.isClosed()) return Promise.resolve(current);
|
|
1168
|
+
current.crashed = true;
|
|
1169
|
+
current.crashCode = 0;
|
|
1170
|
+
current.client?.close();
|
|
1171
|
+
current.client = null;
|
|
1172
|
+
}
|
|
1154
1173
|
if (Supervisor.starting) return Supervisor.starting;
|
|
1155
1174
|
const starting = Supervisor.start(opts);
|
|
1156
1175
|
Supervisor.starting = starting;
|
|
@@ -1216,15 +1235,13 @@ var Supervisor = class Supervisor {
|
|
|
1216
1235
|
reject(/* @__PURE__ */ new Error(`avenor exited with code ${code}${signal ? " signal " + signal : ""} during startup`));
|
|
1217
1236
|
return;
|
|
1218
1237
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
this.client = null;
|
|
1227
|
-
}
|
|
1238
|
+
this.crashed = true;
|
|
1239
|
+
this.crashCode = code ?? -1;
|
|
1240
|
+
if (this.client) {
|
|
1241
|
+
try {
|
|
1242
|
+
this.client.close();
|
|
1243
|
+
} catch {}
|
|
1244
|
+
this.client = null;
|
|
1228
1245
|
}
|
|
1229
1246
|
});
|
|
1230
1247
|
this.childProcess.on("error", (err) => {
|
|
@@ -1262,8 +1279,17 @@ var Supervisor = class Supervisor {
|
|
|
1262
1279
|
return Supervisor.instance;
|
|
1263
1280
|
}
|
|
1264
1281
|
getClient() {
|
|
1265
|
-
if (this.crashed)
|
|
1282
|
+
if (this.crashed) {
|
|
1283
|
+
const state = this.crashCode === 0 ? "exited" : "crashed";
|
|
1284
|
+
throw new Error(`avenor supervisor ${state} (exit code ${this.crashCode}). Call avenor_shutdown to clean up and retry.`);
|
|
1285
|
+
}
|
|
1266
1286
|
if (!this.client) throw new Error("supervisor not started");
|
|
1287
|
+
if (this.client.isClosed()) {
|
|
1288
|
+
this.crashed = true;
|
|
1289
|
+
this.crashCode = 0;
|
|
1290
|
+
this.client = null;
|
|
1291
|
+
throw new Error("avenor supervisor connection closed");
|
|
1292
|
+
}
|
|
1267
1293
|
return this.client;
|
|
1268
1294
|
}
|
|
1269
1295
|
async spawn(params, runId = crypto.randomUUID()) {
|
|
@@ -1287,6 +1313,7 @@ var Supervisor = class Supervisor {
|
|
|
1287
1313
|
agentProfile: spawnParams.agent_profile,
|
|
1288
1314
|
backend: spawnParams.backend,
|
|
1289
1315
|
model: spawnParams.model,
|
|
1316
|
+
thinking: spawnParams.thinking,
|
|
1290
1317
|
dir: spawnParams.dir,
|
|
1291
1318
|
brokerUrl: result.broker_url,
|
|
1292
1319
|
parentToken: result.parent_token,
|
|
@@ -1379,6 +1406,7 @@ async function spawnTool(args) {
|
|
|
1379
1406
|
parent_run_id: args.parent_run_id
|
|
1380
1407
|
};
|
|
1381
1408
|
if (args.agent) baseParams.agent = args.agent;
|
|
1409
|
+
if (args.thinking !== void 0) baseParams.thinking = args.thinking;
|
|
1382
1410
|
if (args.supervisorId) {
|
|
1383
1411
|
const { client, isSingleton, supervisorId } = await getSupervisorClient(args.supervisorId);
|
|
1384
1412
|
const { sentinelPath, eventLogPath } = ensureRunPaths(runId);
|
|
@@ -2090,6 +2118,7 @@ async function executeFollowUpTool(args, getSupervisorClient) {
|
|
|
2090
2118
|
const agent = requireResumableAgent(liveStatus?.agent ?? runInfo?.agent);
|
|
2091
2119
|
const backend = liveStatus?.backend ?? runInfo?.backend;
|
|
2092
2120
|
const model = liveStatus?.model ?? runInfo?.model;
|
|
2121
|
+
const thinking = liveStatus?.thinking ?? runInfo?.thinking;
|
|
2093
2122
|
const dir = liveStatus?.dir ?? runInfo?.dir;
|
|
2094
2123
|
const agentProfile = liveStatus?.agent_profile ?? runInfo?.agentProfile;
|
|
2095
2124
|
const autoApprove = resolveAutoApprove(liveStatus, runInfo);
|
|
@@ -2106,6 +2135,7 @@ async function executeFollowUpTool(args, getSupervisorClient) {
|
|
|
2106
2135
|
};
|
|
2107
2136
|
if (backend) spawnParams.backend = backend;
|
|
2108
2137
|
if (model) spawnParams.model = model;
|
|
2138
|
+
if (thinking) spawnParams.thinking = thinking;
|
|
2109
2139
|
if (dir) spawnParams.dir = dir;
|
|
2110
2140
|
if (agentProfile) spawnParams.agent_profile = agentProfile;
|
|
2111
2141
|
if (autoApprove === true) spawnParams.auto_approve = true;
|
|
@@ -2130,6 +2160,7 @@ async function executeFollowUpTool(args, getSupervisorClient) {
|
|
|
2130
2160
|
const agent = requireResumableAgent(liveStatus?.agent ?? runInfo.agent);
|
|
2131
2161
|
const backend = liveStatus?.backend ?? runInfo.backend;
|
|
2132
2162
|
const model = liveStatus?.model ?? runInfo.model;
|
|
2163
|
+
const thinking = liveStatus?.thinking ?? runInfo.thinking;
|
|
2133
2164
|
const dir = liveStatus?.dir ?? runInfo.dir;
|
|
2134
2165
|
const agentProfile = liveStatus?.agent_profile ?? runInfo.agentProfile;
|
|
2135
2166
|
const autoApprove = resolveAutoApprove(liveStatus, runInfo);
|
|
@@ -2138,6 +2169,7 @@ async function executeFollowUpTool(args, getSupervisorClient) {
|
|
|
2138
2169
|
agent,
|
|
2139
2170
|
backend,
|
|
2140
2171
|
model,
|
|
2172
|
+
thinking,
|
|
2141
2173
|
dir,
|
|
2142
2174
|
agent_profile: agentProfile,
|
|
2143
2175
|
prompt: args.message,
|