@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/errors.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-
|
|
2
|
-
import './run-
|
|
1
|
+
export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-QDYUPABr.cjs';
|
|
2
|
+
import './run-BPRYG1Id.cjs';
|
package/dist/eval.cjs
CHANGED
|
@@ -1439,6 +1439,71 @@ var init_agent_factory_registry = __esm({
|
|
|
1439
1439
|
}
|
|
1440
1440
|
});
|
|
1441
1441
|
|
|
1442
|
+
// src/internal/runtime/lifecycle/run-to-completion.ts
|
|
1443
|
+
var run_to_completion_exports = {};
|
|
1444
|
+
__export(run_to_completion_exports, {
|
|
1445
|
+
classifyRound: () => classifyRound,
|
|
1446
|
+
runToCompletionImpl: () => runToCompletionImpl
|
|
1447
|
+
});
|
|
1448
|
+
function isEmptyRound(result) {
|
|
1449
|
+
return (result.result ?? "").trim() === "";
|
|
1450
|
+
}
|
|
1451
|
+
function classifyRound(result, round, maxRounds, emptyStreak) {
|
|
1452
|
+
if (result.stoppedAtIterationLimit !== true) return "done";
|
|
1453
|
+
if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
|
|
1454
|
+
if (round >= maxRounds) return "step_limit";
|
|
1455
|
+
return "continue";
|
|
1456
|
+
}
|
|
1457
|
+
function addUsage(acc, u) {
|
|
1458
|
+
if (u === void 0) return acc;
|
|
1459
|
+
const inputTokens = (acc?.inputTokens ?? 0) + u.inputTokens;
|
|
1460
|
+
const outputTokens = (acc?.outputTokens ?? 0) + u.outputTokens;
|
|
1461
|
+
const sumOpt = (a, b) => a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
|
|
1462
|
+
return {
|
|
1463
|
+
inputTokens,
|
|
1464
|
+
outputTokens,
|
|
1465
|
+
totalTokens: inputTokens + outputTokens,
|
|
1466
|
+
cacheReadTokens: sumOpt(acc?.cacheReadTokens, u.cacheReadTokens),
|
|
1467
|
+
cacheWriteTokens: sumOpt(acc?.cacheWriteTokens, u.cacheWriteTokens),
|
|
1468
|
+
reasoningTokens: sumOpt(acc?.reasoningTokens, u.reasoningTokens)
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
function buildResult(terminal, rounds, lastResult, usage) {
|
|
1472
|
+
return { terminal, rounds, lastResult, ...usage !== void 0 ? { usage } : {} };
|
|
1473
|
+
}
|
|
1474
|
+
async function stepRound(agent, prompt, sendOptions, round, maxRounds, state2) {
|
|
1475
|
+
const run = await agent.send(prompt, sendOptions);
|
|
1476
|
+
const result = await run.wait();
|
|
1477
|
+
const usage = addUsage(state2.usage, result.usage);
|
|
1478
|
+
const decision = classifyRound(result, round, maxRounds, state2.emptyStreak);
|
|
1479
|
+
if (decision !== "continue") return { terminal: buildResult(decision, round, result, usage) };
|
|
1480
|
+
const emptyStreak = isEmptyRound(result) ? state2.emptyStreak + 1 : 0;
|
|
1481
|
+
return { next: { usage, emptyStreak }, lastResult: result };
|
|
1482
|
+
}
|
|
1483
|
+
async function runToCompletionImpl(agent, message, options) {
|
|
1484
|
+
const maxRounds = options?.maxRounds ?? DEFAULT_MAX_ROUNDS;
|
|
1485
|
+
const continuationPrompt = options?.continuationPrompt ?? DEFAULT_CONTINUATION_PROMPT;
|
|
1486
|
+
const { onTruncated, signal, sendOptions } = options ?? {};
|
|
1487
|
+
let state2 = { usage: void 0, emptyStreak: 0 };
|
|
1488
|
+
for (let round = 0; ; round += 1) {
|
|
1489
|
+
const prompt = round === 0 ? message : continuationPrompt;
|
|
1490
|
+
const outcome = await stepRound(agent, prompt, sendOptions, round, maxRounds, state2);
|
|
1491
|
+
if ("terminal" in outcome) return outcome.terminal;
|
|
1492
|
+
state2 = outcome.next;
|
|
1493
|
+
await onTruncated?.({ round });
|
|
1494
|
+
if (signal?.aborted === true) {
|
|
1495
|
+
return buildResult("step_limit", round, outcome.lastResult, state2.usage);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
var DEFAULT_MAX_ROUNDS, DEFAULT_CONTINUATION_PROMPT;
|
|
1500
|
+
var init_run_to_completion = __esm({
|
|
1501
|
+
"src/internal/runtime/lifecycle/run-to-completion.ts"() {
|
|
1502
|
+
DEFAULT_MAX_ROUNDS = 5;
|
|
1503
|
+
DEFAULT_CONTINUATION_PROMPT = "Continue from where you left off and finish the task. If it is already complete, give the final answer.";
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1442
1507
|
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1443
1508
|
var fork_agent_exports = {};
|
|
1444
1509
|
__export(fork_agent_exports, {
|
|
@@ -4862,6 +4927,18 @@ var CloudAgent = class {
|
|
|
4862
4927
|
"fork"
|
|
4863
4928
|
);
|
|
4864
4929
|
}
|
|
4930
|
+
/**
|
|
4931
|
+
* The continuation driver re-sends against a stateful local session; the
|
|
4932
|
+
* cloud runtime manages its own continuation policy server-side (M1 Phase 3).
|
|
4933
|
+
*
|
|
4934
|
+
* @public
|
|
4935
|
+
*/
|
|
4936
|
+
runToCompletion() {
|
|
4937
|
+
throw new UnsupportedRunOperationError(
|
|
4938
|
+
"Agent.runToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
|
|
4939
|
+
"runToCompletion"
|
|
4940
|
+
);
|
|
4941
|
+
}
|
|
4865
4942
|
/**
|
|
4866
4943
|
* Personality presets require consistent server-side enforcement that
|
|
4867
4944
|
* the cloud runtime (pre-release) does not yet provide. Reject explicitly
|
|
@@ -14342,6 +14419,13 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14342
14419
|
}
|
|
14343
14420
|
return wrap();
|
|
14344
14421
|
}
|
|
14422
|
+
function localAgentRunToCompletion(agent, message, options) {
|
|
14423
|
+
async function run() {
|
|
14424
|
+
const { runToCompletionImpl: runToCompletionImpl2 } = await Promise.resolve().then(() => (init_run_to_completion(), run_to_completion_exports));
|
|
14425
|
+
return runToCompletionImpl2({ send: (m, o) => agent.send(m, o) }, message, options);
|
|
14426
|
+
}
|
|
14427
|
+
return run();
|
|
14428
|
+
}
|
|
14345
14429
|
async function localAgentFork(parent, options) {
|
|
14346
14430
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14347
14431
|
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
@@ -14882,6 +14966,10 @@ var LocalAgent = class {
|
|
|
14882
14966
|
fork(options) {
|
|
14883
14967
|
return localAgentFork({ agentId: this.agentId, options: this.options, personalitySlugSnapshot: this.personalityStore.active(this.agentId) }, options);
|
|
14884
14968
|
}
|
|
14969
|
+
// biome-ignore format: G8 budget — see runUntil comment above.
|
|
14970
|
+
runToCompletion(message, options) {
|
|
14971
|
+
return localAgentRunToCompletion(this, message, options);
|
|
14972
|
+
}
|
|
14885
14973
|
};
|
|
14886
14974
|
function resolveCwd(cwd) {
|
|
14887
14975
|
return (Array.isArray(cwd) ? cwd[0] : cwd) ?? process.cwd();
|