next-issue 6.6.98 → 6.6.99
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/agents.mjs +19 -3
- package/package.json +1 -1
package/dist/agents.mjs
CHANGED
|
@@ -27,15 +27,31 @@ export async function runAgent(recorder, request) {
|
|
|
27
27
|
process.argv[1] = PI_CLI;
|
|
28
28
|
log.event('agent.start', { model: request.model, timeoutMs: request.timeoutMs });
|
|
29
29
|
const session = await openSession(recorder, log, request, agentDir);
|
|
30
|
-
|
|
30
|
+
// pi drops an abort that comes before its run starts (during bindExtensions or the prompt
|
|
31
|
+
// preflight), so remember it and abort again once the run is active, before its first turn.
|
|
32
|
+
let ended = false;
|
|
33
|
+
const end = () => {
|
|
34
|
+
ended = true;
|
|
35
|
+
void session.abort();
|
|
36
|
+
};
|
|
37
|
+
const timer = deadline(request.timeoutMs, end);
|
|
31
38
|
const unsubscribe = session.subscribe((event) => observe(log, event));
|
|
32
|
-
const release = onStop(
|
|
39
|
+
const release = onStop(end);
|
|
33
40
|
try {
|
|
34
41
|
refuseWhenStopped();
|
|
35
42
|
await session.bindExtensions({});
|
|
36
43
|
let result;
|
|
37
44
|
try {
|
|
38
|
-
|
|
45
|
+
if (!ended) {
|
|
46
|
+
await session.prompt(request.prompt, {
|
|
47
|
+
expandPromptTemplates: false,
|
|
48
|
+
preflightResult: (disposition) => {
|
|
49
|
+
if (disposition === 'started' && ended) {
|
|
50
|
+
void session.abort();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
39
55
|
}
|
|
40
56
|
finally {
|
|
41
57
|
// A call that times out, fails or is stopped has spent tokens too.
|