operon-agents-core 0.1.0-alpha.17 → 0.1.0-alpha.19
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/agent/runner.js +1 -1
- package/dist/loop/events.d.ts +5 -1
- package/dist/loop/tool-call.js +48 -9
- package/dist/tool/index.d.ts +1 -0
- package/dist/tool/index.js +3 -0
- package/dist/tool/types.d.ts +3 -2
- package/package.json +2 -2
package/dist/agent/runner.js
CHANGED
|
@@ -664,7 +664,7 @@ class Engine {
|
|
|
664
664
|
maxRetriesPerStep: this.config.maxRetriesPerStep,
|
|
665
665
|
drainSteering: () => state.steer.drainSteering().map((s) => ({ message: s.message, origin: s.origin })),
|
|
666
666
|
// One sink: the loop dispatches real AgentEvent bodies; we only add the envelope.
|
|
667
|
-
dispatchEvent: (body) =>
|
|
667
|
+
dispatchEvent: (body) => emitRunEvent(state, body),
|
|
668
668
|
logger: state.session.logger,
|
|
669
669
|
resumeFrom: resume,
|
|
670
670
|
resume: resume !== undefined ? frameResume(state) : undefined,
|
package/dist/loop/events.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ import type { AgentEventBody } from "../events/events.ts";
|
|
|
9
9
|
* pi-agent design, where the loop emits AgentEvents through a single sink.
|
|
10
10
|
*
|
|
11
11
|
* (The loop has no `state`, so it cannot add the envelope itself — that is the sink's job.)
|
|
12
|
+
*
|
|
13
|
+
* The returned promise resolves once the event is published. Most emitters fire and forget; one
|
|
14
|
+
* that must order something after delivery (a nested call announced before its approval is
|
|
15
|
+
* asked) awaits it.
|
|
12
16
|
*/
|
|
13
|
-
export type LoopEventDispatcher = (event: AgentEventBody) => void
|
|
17
|
+
export type LoopEventDispatcher = (event: AgentEventBody) => void | Promise<void>;
|
|
14
18
|
//# sourceMappingURL=events.d.ts.map
|
package/dist/loop/tool-call.js
CHANGED
|
@@ -263,6 +263,11 @@ async function runAndFinalize(step, run) {
|
|
|
263
263
|
* and hooks a direct call would face. Nested calls of one parent are scheduled against each
|
|
264
264
|
* other by resource conflict — the batch's own rule — and their events carry `parentToolCallId`.
|
|
265
265
|
*
|
|
266
|
+
* An approval a nested call needs is asked in place when the run has a live approver (the
|
|
267
|
+
* responder answers inline, as the runner does for a top-level batch): the nested call waits for
|
|
268
|
+
* the answer while the rest of the program keeps running. `tool.call.started` goes out BEFORE the
|
|
269
|
+
* question, so a client has the call — name, arguments, parent — to hang the approval on.
|
|
270
|
+
*
|
|
266
271
|
* What a nested call cannot do is pause the turn. An approval with no live approver, or a tool
|
|
267
272
|
* that suspends for input, comes back as an error result instead of interrupting: the batch that
|
|
268
273
|
* owns the turn is already running, and re-running a program to resume it would repeat its side
|
|
@@ -292,10 +297,26 @@ function createNestedDispatcher(step, parent) {
|
|
|
292
297
|
// records and applies it like any other.
|
|
293
298
|
if (options?.approval !== undefined && step.answers !== undefined)
|
|
294
299
|
step.answers[call.id] = options.approval;
|
|
295
|
-
|
|
300
|
+
let prepared = await prepareCall(nestedStep, call);
|
|
301
|
+
let announced = false;
|
|
302
|
+
const approver = liveApproverOf(step.responder);
|
|
303
|
+
if (prepared.kind === "interrupt" && approver !== undefined && step.answers !== undefined) {
|
|
304
|
+
// Ask now, as the runner does for a live top-level batch, then authorize again with the
|
|
305
|
+
// answer filed — the same audited path a resumed batch's answers take.
|
|
306
|
+
const pending = prepared.pending;
|
|
307
|
+
await step.dispatchEvent?.({ type: "tool.call.started", toolCallId: call.id, toolName: name, args: call.arguments, parentToolCallId: parent.id });
|
|
308
|
+
announced = true;
|
|
309
|
+
step.answers[call.id] = await approver.requestApproval({
|
|
310
|
+
toolCallId: call.id,
|
|
311
|
+
toolName: name,
|
|
312
|
+
approvalRule: pending.approvalRule,
|
|
313
|
+
...(pending.display !== undefined ? { display: pending.display } : {}),
|
|
314
|
+
}, { signal: step.signal });
|
|
315
|
+
prepared = await prepareCall(nestedStep, call);
|
|
316
|
+
}
|
|
296
317
|
if (prepared.kind === "interrupt" || prepared.kind === "repark") {
|
|
297
318
|
const pending = prepared.pending;
|
|
298
|
-
|
|
319
|
+
const result = {
|
|
299
320
|
...errorResult(`${name} requires the user's approval, which cannot be requested from inside a nested call. Call the tool directly.`),
|
|
300
321
|
...(pending.kind === "approval"
|
|
301
322
|
? {
|
|
@@ -309,14 +330,21 @@ function createNestedDispatcher(step, parent) {
|
|
|
309
330
|
}
|
|
310
331
|
: {}),
|
|
311
332
|
};
|
|
333
|
+
// A call already announced must not be left running in the client's view.
|
|
334
|
+
if (announced) {
|
|
335
|
+
step.dispatchEvent?.({ type: "tool.result", toolCallId: call.id, toolName: name, result: { content: result.content, isError: true }, isError: true, parentToolCallId: parent.id });
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
if (!announced) {
|
|
340
|
+
step.dispatchEvent?.({
|
|
341
|
+
type: "tool.call.started",
|
|
342
|
+
toolCallId: call.id,
|
|
343
|
+
toolName: name,
|
|
344
|
+
args: prepared.kind === "run" ? prepared.args : call.arguments,
|
|
345
|
+
parentToolCallId: parent.id,
|
|
346
|
+
});
|
|
312
347
|
}
|
|
313
|
-
step.dispatchEvent?.({
|
|
314
|
-
type: "tool.call.started",
|
|
315
|
-
toolCallId: call.id,
|
|
316
|
-
toolName: name,
|
|
317
|
-
args: prepared.kind === "run" ? prepared.args : call.arguments,
|
|
318
|
-
parentToolCallId: parent.id,
|
|
319
|
-
});
|
|
320
348
|
let result;
|
|
321
349
|
if (prepared.kind === "result") {
|
|
322
350
|
result = prepared.result;
|
|
@@ -342,6 +370,17 @@ function createNestedDispatcher(step, parent) {
|
|
|
342
370
|
},
|
|
343
371
|
};
|
|
344
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* The responder, when it can answer an approval inline right now. The step carries it typed as
|
|
375
|
+
* the question channel (that is all a tool's run context gets); the runner hands in its full
|
|
376
|
+
* `Responder`, and `isLiveApprover() === false` means approvals go durable instead.
|
|
377
|
+
*/
|
|
378
|
+
function liveApproverOf(responder) {
|
|
379
|
+
if (responder === undefined || !("requestApproval" in responder) || typeof responder.requestApproval !== "function")
|
|
380
|
+
return undefined;
|
|
381
|
+
const approver = responder;
|
|
382
|
+
return (approver.isLiveApprover?.() ?? true) ? approver : undefined;
|
|
383
|
+
}
|
|
345
384
|
function planOf(p) {
|
|
346
385
|
return p?.kind === "run" ? p.plan : undefined;
|
|
347
386
|
}
|
package/dist/tool/index.d.ts
CHANGED
|
@@ -33,4 +33,5 @@ export type { QuestionSpawnOptions } from "./background.ts";
|
|
|
33
33
|
export { filesystemTools } from "./filesystem-tools.ts";
|
|
34
34
|
export type { FilesystemToolsOptions } from "./filesystem-tools.ts";
|
|
35
35
|
export * from "./web/index.ts";
|
|
36
|
+
export { searchDeferredTools } from "./search/deferral.ts";
|
|
36
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tool/index.js
CHANGED
|
@@ -30,4 +30,7 @@ export { grepTool } from "./builtin/grep.js";
|
|
|
30
30
|
export { askUserQuestionTool } from "./builtin/ask-user-question.js";
|
|
31
31
|
export { filesystemTools } from "./filesystem-tools.js";
|
|
32
32
|
export * from "./web/index.js";
|
|
33
|
+
// The keyword search behind SearchTool, for other surfaces that look tools up by intent
|
|
34
|
+
// (Code Mode's `searchTools`).
|
|
35
|
+
export { searchDeferredTools } from "./search/deferral.js";
|
|
33
36
|
//# sourceMappingURL=index.js.map
|
package/dist/tool/types.d.ts
CHANGED
|
@@ -86,8 +86,9 @@ export interface NestedToolDispatcher {
|
|
|
86
86
|
readonly schemas: readonly ToolSchema[];
|
|
87
87
|
/**
|
|
88
88
|
* Run `name` with `args`. Resolves to the tool's result; an unknown, denied or failed call is
|
|
89
|
-
* an error RESULT (`isError: true`), never a rejection.
|
|
90
|
-
*
|
|
89
|
+
* an error RESULT (`isError: true`), never a rejection. An approval the call needs is asked in
|
|
90
|
+
* place when the run has a live approver; the promise waits for the answer. A call that would
|
|
91
|
+
* pause the run — an approval with no live approver, a tool that suspends for input — comes back as an
|
|
91
92
|
* error result: a nested call cannot park the turn. For the approval case the result carries
|
|
92
93
|
* `interrupt`, so a caller able to pause ITSELF (`ToolRunContext.suspend`) can, and later
|
|
93
94
|
* re-issue the same call with the user's answer in `options.approval`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "operon-agents-core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.19",
|
|
4
4
|
"description": "Internal engine for operon-agents. Prefer operon-agents for application code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"README.md"
|
|
72
72
|
],
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@earendil-works/pi-ai": "
|
|
74
|
+
"@earendil-works/pi-ai": "1.3.0",
|
|
75
75
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
76
76
|
"@opentelemetry/api": "^1.9.0",
|
|
77
77
|
"acorn": "^8.17.0",
|