@theokit/sdk 2.22.0 → 2.23.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/CHANGELOG.md +24 -0
- package/dist/a2a/index.cjs +40 -14
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +40 -14
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/subagent.d.cts +27 -2
- package/dist/a2a/subagent.d.ts +27 -2
- package/package.json +3 -3
package/dist/a2a/index.js
CHANGED
|
@@ -18423,15 +18423,33 @@ var MaxDelegationDepthError = class extends Error {
|
|
|
18423
18423
|
maxDepth;
|
|
18424
18424
|
code = "max_delegation_depth";
|
|
18425
18425
|
};
|
|
18426
|
-
async function applyDelegationStart(spec, input) {
|
|
18426
|
+
async function applyDelegationStart(spec, input, iteration) {
|
|
18427
18427
|
if (spec.onDelegationStart === void 0) return { input };
|
|
18428
|
-
const decision = await spec.onDelegationStart({ input, name: spec.name });
|
|
18428
|
+
const decision = await spec.onDelegationStart({ input, name: spec.name, iteration });
|
|
18429
18429
|
if (decision === void 0) return { input };
|
|
18430
18430
|
if (decision.proceed === false)
|
|
18431
18431
|
return { reject: decision.rejectionReason ?? "(delegation rejected)" };
|
|
18432
|
-
return {
|
|
18432
|
+
return {
|
|
18433
|
+
input: decision.modifiedInput ?? input,
|
|
18434
|
+
...decision.modifiedMaxSteps !== void 0 ? { maxSteps: decision.modifiedMaxSteps } : {}
|
|
18435
|
+
};
|
|
18436
|
+
}
|
|
18437
|
+
async function collectChildToolResults(run) {
|
|
18438
|
+
const lines = [];
|
|
18439
|
+
for await (const event of run.stream()) {
|
|
18440
|
+
if (event.type === "tool_call" && event.status === "completed") {
|
|
18441
|
+
const rendered = typeof event.result === "string" ? event.result : JSON.stringify(event.result ?? null);
|
|
18442
|
+
lines.push(`${event.name}: ${rendered}`);
|
|
18443
|
+
}
|
|
18444
|
+
}
|
|
18445
|
+
if (lines.length === 0) return "";
|
|
18446
|
+
return `
|
|
18447
|
+
|
|
18448
|
+
<subagent-tool-results>
|
|
18449
|
+
${lines.join("\n")}
|
|
18450
|
+
</subagent-tool-results>`;
|
|
18433
18451
|
}
|
|
18434
|
-
async function runChildAgent(spec, input, signal) {
|
|
18452
|
+
async function runChildAgent(spec, input, signal, maxSteps) {
|
|
18435
18453
|
const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
|
|
18436
18454
|
const agent = await Agent2.create({
|
|
18437
18455
|
...spec.model ? { model: { id: spec.model } } : {},
|
|
@@ -18439,17 +18457,22 @@ async function runChildAgent(spec, input, signal) {
|
|
|
18439
18457
|
tools: spec.tools ?? []
|
|
18440
18458
|
});
|
|
18441
18459
|
try {
|
|
18442
|
-
const
|
|
18460
|
+
const sendOptions = {
|
|
18461
|
+
...signal !== void 0 ? { signal } : {},
|
|
18462
|
+
...maxSteps !== void 0 ? { maxIterations: maxSteps } : {}
|
|
18463
|
+
};
|
|
18464
|
+
const run = Object.keys(sendOptions).length > 0 ? await agent.send(input, sendOptions) : await agent.send(input);
|
|
18443
18465
|
const result = await run.wait();
|
|
18444
|
-
|
|
18466
|
+
const text = result.result ?? "(no response)";
|
|
18467
|
+
return spec.includeToolResults === true ? text + await collectChildToolResults(run) : text;
|
|
18445
18468
|
} finally {
|
|
18446
18469
|
agent.dispose();
|
|
18447
18470
|
}
|
|
18448
18471
|
}
|
|
18449
|
-
async function notifyDelegationError(spec, input, error) {
|
|
18472
|
+
async function notifyDelegationError(spec, input, error, iteration) {
|
|
18450
18473
|
if (spec.onDelegationComplete === void 0) return;
|
|
18451
18474
|
try {
|
|
18452
|
-
await spec.onDelegationComplete({ input, name: spec.name, error });
|
|
18475
|
+
await spec.onDelegationComplete({ input, name: spec.name, error, iteration });
|
|
18453
18476
|
} catch {
|
|
18454
18477
|
}
|
|
18455
18478
|
}
|
|
@@ -18464,9 +18487,9 @@ ${preamble}
|
|
|
18464
18487
|
Task:
|
|
18465
18488
|
${input}`;
|
|
18466
18489
|
}
|
|
18467
|
-
async function applyDelegationComplete(spec, input, result) {
|
|
18490
|
+
async function applyDelegationComplete(spec, input, result, iteration) {
|
|
18468
18491
|
if (spec.onDelegationComplete === void 0) return result;
|
|
18469
|
-
const completion = await spec.onDelegationComplete({ input, name: spec.name, result });
|
|
18492
|
+
const completion = await spec.onDelegationComplete({ input, name: spec.name, result, iteration });
|
|
18470
18493
|
return completion?.feedback !== void 0 ? result + completion.feedback : result;
|
|
18471
18494
|
}
|
|
18472
18495
|
function defineSubAgent(spec, _parentDepth = 0) {
|
|
@@ -18478,23 +18501,26 @@ function defineSubAgent(spec, _parentDepth = 0) {
|
|
|
18478
18501
|
const inputSchema = z.object({
|
|
18479
18502
|
input: z.string().describe("Task for the subagent")
|
|
18480
18503
|
});
|
|
18504
|
+
let iteration = 0;
|
|
18481
18505
|
return {
|
|
18482
18506
|
name: spec.name,
|
|
18483
18507
|
description: spec.description,
|
|
18484
18508
|
inputSchema,
|
|
18485
18509
|
handler: async (rawInput, ctx) => {
|
|
18486
18510
|
const { input: parsed } = inputSchema.parse(rawInput);
|
|
18487
|
-
|
|
18511
|
+
iteration += 1;
|
|
18512
|
+
const capturedIteration = iteration;
|
|
18513
|
+
const start = await applyDelegationStart(spec, parsed, capturedIteration);
|
|
18488
18514
|
if ("reject" in start) return start.reject;
|
|
18489
18515
|
const input = applyMessageFilter(spec, start.input, ctx?.messages);
|
|
18490
18516
|
let result;
|
|
18491
18517
|
try {
|
|
18492
|
-
result = await runChildAgent(spec, input, ctx?.signal);
|
|
18518
|
+
result = await runChildAgent(spec, input, ctx?.signal, start.maxSteps);
|
|
18493
18519
|
} catch (error) {
|
|
18494
|
-
await notifyDelegationError(spec, input, error);
|
|
18520
|
+
await notifyDelegationError(spec, input, error, capturedIteration);
|
|
18495
18521
|
throw error;
|
|
18496
18522
|
}
|
|
18497
|
-
return applyDelegationComplete(spec, input, result);
|
|
18523
|
+
return applyDelegationComplete(spec, input, result, capturedIteration);
|
|
18498
18524
|
}
|
|
18499
18525
|
};
|
|
18500
18526
|
}
|