@theokit/sdk 2.2.0 → 2.3.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 +25 -0
- package/dist/a2a/index.cjs +88 -0
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +88 -0
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-JSPSFczQ.d.cts → cron-B_H8rn-j.d.cts} +20 -2
- package/dist/{cron-Aksw2Hy4.d.ts → cron-DX6HbHxd.d.ts} +20 -2
- package/dist/cron.cjs +88 -0
- 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 +88 -0
- package/dist/cron.js.map +1 -1
- package/dist/{errors-Bcw_Pakm.d.ts → errors-DG_7CAUg.d.ts} +1 -1
- package/dist/{errors-Vhg6ZV4o.d.cts → errors-QDYUPABr.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +88 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +88 -0
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +171 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -7
- package/dist/index.d.ts +50 -7
- package/dist/index.js +171 -12
- package/dist/index.js.map +1 -1
- package/dist/internal/runtime/lifecycle/run-to-completion.d.ts +22 -0
- package/dist/{run-ekGKZlmg.d.cts → run-BPRYG1Id.d.cts} +55 -2
- package/dist/{run-ekGKZlmg.d.ts → run-BPRYG1Id.d.ts} +55 -2
- package/dist/types/agent.d.ts +14 -0
- package/dist/types/conversation-storage.d.ts +5 -1
- package/dist/types/run.d.ts +54 -1
- package/package.json +3 -3
package/dist/eval.js
CHANGED
|
@@ -1436,6 +1436,71 @@ var init_agent_factory_registry = __esm({
|
|
|
1436
1436
|
}
|
|
1437
1437
|
});
|
|
1438
1438
|
|
|
1439
|
+
// src/internal/runtime/lifecycle/run-to-completion.ts
|
|
1440
|
+
var run_to_completion_exports = {};
|
|
1441
|
+
__export(run_to_completion_exports, {
|
|
1442
|
+
classifyRound: () => classifyRound,
|
|
1443
|
+
runToCompletionImpl: () => runToCompletionImpl
|
|
1444
|
+
});
|
|
1445
|
+
function isEmptyRound(result) {
|
|
1446
|
+
return (result.result ?? "").trim() === "";
|
|
1447
|
+
}
|
|
1448
|
+
function classifyRound(result, round, maxRounds, emptyStreak) {
|
|
1449
|
+
if (result.stoppedAtIterationLimit !== true) return "done";
|
|
1450
|
+
if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
|
|
1451
|
+
if (round >= maxRounds) return "step_limit";
|
|
1452
|
+
return "continue";
|
|
1453
|
+
}
|
|
1454
|
+
function addUsage(acc, u) {
|
|
1455
|
+
if (u === void 0) return acc;
|
|
1456
|
+
const inputTokens = (acc?.inputTokens ?? 0) + u.inputTokens;
|
|
1457
|
+
const outputTokens = (acc?.outputTokens ?? 0) + u.outputTokens;
|
|
1458
|
+
const sumOpt = (a, b) => a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
|
|
1459
|
+
return {
|
|
1460
|
+
inputTokens,
|
|
1461
|
+
outputTokens,
|
|
1462
|
+
totalTokens: inputTokens + outputTokens,
|
|
1463
|
+
cacheReadTokens: sumOpt(acc?.cacheReadTokens, u.cacheReadTokens),
|
|
1464
|
+
cacheWriteTokens: sumOpt(acc?.cacheWriteTokens, u.cacheWriteTokens),
|
|
1465
|
+
reasoningTokens: sumOpt(acc?.reasoningTokens, u.reasoningTokens)
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function buildResult(terminal, rounds, lastResult, usage) {
|
|
1469
|
+
return { terminal, rounds, lastResult, ...usage !== void 0 ? { usage } : {} };
|
|
1470
|
+
}
|
|
1471
|
+
async function stepRound(agent, prompt, sendOptions, round, maxRounds, state2) {
|
|
1472
|
+
const run = await agent.send(prompt, sendOptions);
|
|
1473
|
+
const result = await run.wait();
|
|
1474
|
+
const usage = addUsage(state2.usage, result.usage);
|
|
1475
|
+
const decision = classifyRound(result, round, maxRounds, state2.emptyStreak);
|
|
1476
|
+
if (decision !== "continue") return { terminal: buildResult(decision, round, result, usage) };
|
|
1477
|
+
const emptyStreak = isEmptyRound(result) ? state2.emptyStreak + 1 : 0;
|
|
1478
|
+
return { next: { usage, emptyStreak }, lastResult: result };
|
|
1479
|
+
}
|
|
1480
|
+
async function runToCompletionImpl(agent, message, options) {
|
|
1481
|
+
const maxRounds = options?.maxRounds ?? DEFAULT_MAX_ROUNDS;
|
|
1482
|
+
const continuationPrompt = options?.continuationPrompt ?? DEFAULT_CONTINUATION_PROMPT;
|
|
1483
|
+
const { onTruncated, signal, sendOptions } = options ?? {};
|
|
1484
|
+
let state2 = { usage: void 0, emptyStreak: 0 };
|
|
1485
|
+
for (let round = 0; ; round += 1) {
|
|
1486
|
+
const prompt = round === 0 ? message : continuationPrompt;
|
|
1487
|
+
const outcome = await stepRound(agent, prompt, sendOptions, round, maxRounds, state2);
|
|
1488
|
+
if ("terminal" in outcome) return outcome.terminal;
|
|
1489
|
+
state2 = outcome.next;
|
|
1490
|
+
await onTruncated?.({ round });
|
|
1491
|
+
if (signal?.aborted === true) {
|
|
1492
|
+
return buildResult("step_limit", round, outcome.lastResult, state2.usage);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
var DEFAULT_MAX_ROUNDS, DEFAULT_CONTINUATION_PROMPT;
|
|
1497
|
+
var init_run_to_completion = __esm({
|
|
1498
|
+
"src/internal/runtime/lifecycle/run-to-completion.ts"() {
|
|
1499
|
+
DEFAULT_MAX_ROUNDS = 5;
|
|
1500
|
+
DEFAULT_CONTINUATION_PROMPT = "Continue from where you left off and finish the task. If it is already complete, give the final answer.";
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1439
1504
|
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1440
1505
|
var fork_agent_exports = {};
|
|
1441
1506
|
__export(fork_agent_exports, {
|
|
@@ -4859,6 +4924,18 @@ var CloudAgent = class {
|
|
|
4859
4924
|
"fork"
|
|
4860
4925
|
);
|
|
4861
4926
|
}
|
|
4927
|
+
/**
|
|
4928
|
+
* The continuation driver re-sends against a stateful local session; the
|
|
4929
|
+
* cloud runtime manages its own continuation policy server-side (M1 Phase 3).
|
|
4930
|
+
*
|
|
4931
|
+
* @public
|
|
4932
|
+
*/
|
|
4933
|
+
runToCompletion() {
|
|
4934
|
+
throw new UnsupportedRunOperationError(
|
|
4935
|
+
"Agent.runToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
|
|
4936
|
+
"runToCompletion"
|
|
4937
|
+
);
|
|
4938
|
+
}
|
|
4862
4939
|
/**
|
|
4863
4940
|
* Personality presets require consistent server-side enforcement that
|
|
4864
4941
|
* the cloud runtime (pre-release) does not yet provide. Reject explicitly
|
|
@@ -14339,6 +14416,13 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14339
14416
|
}
|
|
14340
14417
|
return wrap();
|
|
14341
14418
|
}
|
|
14419
|
+
function localAgentRunToCompletion(agent, message, options) {
|
|
14420
|
+
async function run() {
|
|
14421
|
+
const { runToCompletionImpl: runToCompletionImpl2 } = await Promise.resolve().then(() => (init_run_to_completion(), run_to_completion_exports));
|
|
14422
|
+
return runToCompletionImpl2({ send: (m, o) => agent.send(m, o) }, message, options);
|
|
14423
|
+
}
|
|
14424
|
+
return run();
|
|
14425
|
+
}
|
|
14342
14426
|
async function localAgentFork(parent, options) {
|
|
14343
14427
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14344
14428
|
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
@@ -14879,6 +14963,10 @@ var LocalAgent = class {
|
|
|
14879
14963
|
fork(options) {
|
|
14880
14964
|
return localAgentFork({ agentId: this.agentId, options: this.options, personalitySlugSnapshot: this.personalityStore.active(this.agentId) }, options);
|
|
14881
14965
|
}
|
|
14966
|
+
// biome-ignore format: G8 budget — see runUntil comment above.
|
|
14967
|
+
runToCompletion(message, options) {
|
|
14968
|
+
return localAgentRunToCompletion(this, message, options);
|
|
14969
|
+
}
|
|
14882
14970
|
};
|
|
14883
14971
|
function resolveCwd(cwd) {
|
|
14884
14972
|
return (Array.isArray(cwd) ? cwd[0] : cwd) ?? process.cwd();
|