@theokit/sdk 2.21.0 → 2.22.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 +33 -0
- package/dist/a2a/index.cjs +73 -19
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.d.cts +2 -1
- package/dist/a2a/index.d.ts +2 -1
- package/dist/a2a/index.js +73 -19
- package/dist/a2a/index.js.map +1 -1
- package/dist/a2a/subagent.d.cts +70 -1
- package/dist/a2a/subagent.d.ts +70 -1
- package/dist/{cron-dpvtRoro.d.ts → cron-7CruUd_0.d.ts} +1 -1
- package/dist/{cron-YrmsszEN.d.cts → cron-Bpt_1khA.d.cts} +1 -1
- package/dist/cron.cjs +16 -6
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +16 -6
- package/dist/cron.js.map +1 -1
- package/dist/{errors-C4vZPqXf.d.ts → errors-BuwwkrAk.d.ts} +1 -1
- package/dist/{errors-DrcpYVfZ.d.cts → errors-CkCaIqVP.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +16 -6
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +16 -6
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +16 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/dist/{run-BMo8yRwK.d.cts → run-CrIulPF7.d.cts} +22 -2
- package/dist/{run-BMo8yRwK.d.ts → run-CrIulPF7.d.ts} +22 -2
- package/dist/types/agent-prims.d.ts +21 -1
- package/dist/types/agent.d.ts +1 -1
- package/package.json +3 -3
package/dist/a2a/index.d.cts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Exported via `@theokit/sdk/a2a`.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
+
export type { ToolContextMessage } from "../types/agent-prims.js";
|
|
6
7
|
export { AgentMailbox } from "./agent-mailbox.js";
|
|
7
8
|
export { MessageBus, type RequestOptions } from "./message-bus.js";
|
|
8
|
-
export { defineSubAgent, MaxDelegationDepthError, type SubAgentSpec, } from "./subagent.js";
|
|
9
|
+
export { type DelegationCompleteContext, type DelegationCompleteDecision, type DelegationStartContext, type DelegationStartDecision, defineSubAgent, MaxDelegationDepthError, type MessageFilterArgs, type SubAgentSpec, } from "./subagent.js";
|
|
9
10
|
export type { A2AMessage, MessageHandler } from "./types.js";
|
package/dist/a2a/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Exported via `@theokit/sdk/a2a`.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
+
export type { ToolContextMessage } from "../types/agent-prims.js";
|
|
6
7
|
export { AgentMailbox } from "./agent-mailbox.js";
|
|
7
8
|
export { MessageBus, type RequestOptions } from "./message-bus.js";
|
|
8
|
-
export { defineSubAgent, MaxDelegationDepthError, type SubAgentSpec, } from "./subagent.js";
|
|
9
|
+
export { type DelegationCompleteContext, type DelegationCompleteDecision, type DelegationStartContext, type DelegationStartDecision, defineSubAgent, MaxDelegationDepthError, type MessageFilterArgs, type SubAgentSpec, } from "./subagent.js";
|
|
9
10
|
export type { A2AMessage, MessageHandler } from "./types.js";
|
package/dist/a2a/index.js
CHANGED
|
@@ -8323,21 +8323,21 @@ async function executeTool(inputs, resolved, call) {
|
|
|
8323
8323
|
if (resolved.origin === "shell") return runShellTool(inputs, call);
|
|
8324
8324
|
if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
|
|
8325
8325
|
if (resolved.origin === "custom")
|
|
8326
|
-
return runCustomTool(resolved, call, inputs.signal, inputs.context);
|
|
8326
|
+
return runCustomTool(resolved, call, inputs.signal, inputs.context, inputs.messages);
|
|
8327
8327
|
return runMcpTool(inputs, resolved, call);
|
|
8328
8328
|
}
|
|
8329
8329
|
async function runMemoryTool(resolved, call, context) {
|
|
8330
8330
|
return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
|
|
8331
8331
|
}
|
|
8332
|
-
async function runCustomTool(resolved, call, signal, context) {
|
|
8333
|
-
return runHandlerTool("custom", resolved.customHandler, call, signal, context);
|
|
8332
|
+
async function runCustomTool(resolved, call, signal, context, messages) {
|
|
8333
|
+
return runHandlerTool("custom", resolved.customHandler, call, signal, context, messages);
|
|
8334
8334
|
}
|
|
8335
|
-
async function runHandlerTool(kind, handler, call, signal, context) {
|
|
8335
|
+
async function runHandlerTool(kind, handler, call, signal, context, messages) {
|
|
8336
8336
|
if (handler === void 0) {
|
|
8337
8337
|
return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
|
|
8338
8338
|
}
|
|
8339
8339
|
try {
|
|
8340
|
-
const out = await handler(call.input, { signal, context });
|
|
8340
|
+
const out = await handler(call.input, { signal, context, messages });
|
|
8341
8341
|
if (typeof out !== "string") return { stdout: "", stderr: "", exitCode: 0, content: out };
|
|
8342
8342
|
return { stdout: out, stderr: "", exitCode: 0 };
|
|
8343
8343
|
} catch (cause) {
|
|
@@ -9162,6 +9162,14 @@ var init_usage_and_cost = __esm({
|
|
|
9162
9162
|
});
|
|
9163
9163
|
|
|
9164
9164
|
// src/internal/agent-loop/loop.ts
|
|
9165
|
+
function projectToolContextMessages(messages) {
|
|
9166
|
+
const projected = [];
|
|
9167
|
+
for (const m of messages) {
|
|
9168
|
+
const content = m.content.flatMap((p) => p.type === "text" ? [p.text] : []).join("");
|
|
9169
|
+
if (content !== "") projected.push({ role: m.role, content });
|
|
9170
|
+
}
|
|
9171
|
+
return projected;
|
|
9172
|
+
}
|
|
9165
9173
|
async function runAgentLoop(inputs) {
|
|
9166
9174
|
const sendSpan = inputs.telemetry?.startSpan("agent.send", {
|
|
9167
9175
|
agentId: inputs.agentId,
|
|
@@ -9402,7 +9410,9 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
|
|
|
9402
9410
|
const outText = await transformLlmOutputText(inputs, llmOutput.text, tCtx);
|
|
9403
9411
|
ctx.messages.push(buildAssistantTurn(outText, llmOutput.toolCalls));
|
|
9404
9412
|
const rawResults = await dispatchTools(
|
|
9405
|
-
|
|
9413
|
+
// SE12 — forward a read-only text projection of the transcript-so-far to tool
|
|
9414
|
+
// handlers via `ctx.messages` (consumed by defineSubAgent's messageFilter).
|
|
9415
|
+
{ ...inputs, messages: projectToolContextMessages(ctx.messages) },
|
|
9406
9416
|
ctx.tools,
|
|
9407
9417
|
llmOutput.toolCalls,
|
|
9408
9418
|
ctx.events,
|
|
@@ -18413,6 +18423,52 @@ var MaxDelegationDepthError = class extends Error {
|
|
|
18413
18423
|
maxDepth;
|
|
18414
18424
|
code = "max_delegation_depth";
|
|
18415
18425
|
};
|
|
18426
|
+
async function applyDelegationStart(spec, input) {
|
|
18427
|
+
if (spec.onDelegationStart === void 0) return { input };
|
|
18428
|
+
const decision = await spec.onDelegationStart({ input, name: spec.name });
|
|
18429
|
+
if (decision === void 0) return { input };
|
|
18430
|
+
if (decision.proceed === false)
|
|
18431
|
+
return { reject: decision.rejectionReason ?? "(delegation rejected)" };
|
|
18432
|
+
return { input: decision.modifiedInput ?? input };
|
|
18433
|
+
}
|
|
18434
|
+
async function runChildAgent(spec, input, signal) {
|
|
18435
|
+
const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
|
|
18436
|
+
const agent = await Agent2.create({
|
|
18437
|
+
...spec.model ? { model: { id: spec.model } } : {},
|
|
18438
|
+
systemPrompt: spec.instructions,
|
|
18439
|
+
tools: spec.tools ?? []
|
|
18440
|
+
});
|
|
18441
|
+
try {
|
|
18442
|
+
const run = signal !== void 0 ? await agent.send(input, { signal }) : await agent.send(input);
|
|
18443
|
+
const result = await run.wait();
|
|
18444
|
+
return result.result ?? "(no response)";
|
|
18445
|
+
} finally {
|
|
18446
|
+
agent.dispose();
|
|
18447
|
+
}
|
|
18448
|
+
}
|
|
18449
|
+
async function notifyDelegationError(spec, input, error) {
|
|
18450
|
+
if (spec.onDelegationComplete === void 0) return;
|
|
18451
|
+
try {
|
|
18452
|
+
await spec.onDelegationComplete({ input, name: spec.name, error });
|
|
18453
|
+
} catch {
|
|
18454
|
+
}
|
|
18455
|
+
}
|
|
18456
|
+
function applyMessageFilter(spec, input, messages) {
|
|
18457
|
+
if (spec.messageFilter === void 0 || messages === void 0) return input;
|
|
18458
|
+
const filtered = spec.messageFilter({ messages, input, name: spec.name });
|
|
18459
|
+
if (filtered.length === 0) return input;
|
|
18460
|
+
const preamble = filtered.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
18461
|
+
return `Prior conversation:
|
|
18462
|
+
${preamble}
|
|
18463
|
+
|
|
18464
|
+
Task:
|
|
18465
|
+
${input}`;
|
|
18466
|
+
}
|
|
18467
|
+
async function applyDelegationComplete(spec, input, result) {
|
|
18468
|
+
if (spec.onDelegationComplete === void 0) return result;
|
|
18469
|
+
const completion = await spec.onDelegationComplete({ input, name: spec.name, result });
|
|
18470
|
+
return completion?.feedback !== void 0 ? result + completion.feedback : result;
|
|
18471
|
+
}
|
|
18416
18472
|
function defineSubAgent(spec, _parentDepth = 0) {
|
|
18417
18473
|
const currentDepth = _parentDepth + 1;
|
|
18418
18474
|
const maxDepth = spec.maxDelegationDepth ?? 3;
|
|
@@ -18426,21 +18482,19 @@ function defineSubAgent(spec, _parentDepth = 0) {
|
|
|
18426
18482
|
name: spec.name,
|
|
18427
18483
|
description: spec.description,
|
|
18428
18484
|
inputSchema,
|
|
18429
|
-
handler: async (rawInput) => {
|
|
18430
|
-
const { input } = inputSchema.parse(rawInput);
|
|
18431
|
-
const
|
|
18432
|
-
|
|
18433
|
-
|
|
18434
|
-
|
|
18435
|
-
tools: spec.tools ?? []
|
|
18436
|
-
});
|
|
18485
|
+
handler: async (rawInput, ctx) => {
|
|
18486
|
+
const { input: parsed } = inputSchema.parse(rawInput);
|
|
18487
|
+
const start = await applyDelegationStart(spec, parsed);
|
|
18488
|
+
if ("reject" in start) return start.reject;
|
|
18489
|
+
const input = applyMessageFilter(spec, start.input, ctx?.messages);
|
|
18490
|
+
let result;
|
|
18437
18491
|
try {
|
|
18438
|
-
|
|
18439
|
-
|
|
18440
|
-
|
|
18441
|
-
|
|
18442
|
-
agent.dispose();
|
|
18492
|
+
result = await runChildAgent(spec, input, ctx?.signal);
|
|
18493
|
+
} catch (error) {
|
|
18494
|
+
await notifyDelegationError(spec, input, error);
|
|
18495
|
+
throw error;
|
|
18443
18496
|
}
|
|
18497
|
+
return applyDelegationComplete(spec, input, result);
|
|
18444
18498
|
}
|
|
18445
18499
|
};
|
|
18446
18500
|
}
|