@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CustomTool, M as ModelSelection,
|
|
1
|
+
import { C as CustomTool, M as ModelSelection, F as SDKUserMessage, H as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, a as McpServerConfig } from './run-BPRYG1Id.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Fork primitive public type contracts (T1.2, ADRs D110-D114).
|
|
@@ -591,7 +591,11 @@ interface BudgetTracker {
|
|
|
591
591
|
* @public
|
|
592
592
|
*/
|
|
593
593
|
interface StoredMessage {
|
|
594
|
-
/**
|
|
594
|
+
/**
|
|
595
|
+
* Origin of the message. `tool_call` / `tool_result` are produced by
|
|
596
|
+
* `buildReplayHistory` (M1-3) for stateless replay; a consumer feeding a
|
|
597
|
+
* `user`/`assistant`-only wire-mapper must map those two roles itself.
|
|
598
|
+
*/
|
|
595
599
|
role: "user" | "assistant" | "system" | "tool_call" | "tool_result";
|
|
596
600
|
/** UTF-8 payload. May be empty string (e.g., a tool with no return value). */
|
|
597
601
|
content: string;
|
|
@@ -1447,6 +1451,20 @@ interface SDKAgent {
|
|
|
1447
1451
|
* @public
|
|
1448
1452
|
*/
|
|
1449
1453
|
fork?(options: ForkOptions): Promise<ForkResult>;
|
|
1454
|
+
/**
|
|
1455
|
+
* Drive `send` to completion across iteration-ceiling truncations (M1 Phase 3).
|
|
1456
|
+
* When a `send` stops at the loop's iteration cap (`RunResult.stoppedAtIterationLimit`),
|
|
1457
|
+
* this re-sends a short continuation prompt — the agent's stateful session
|
|
1458
|
+
* preserves the conversation — until a genuine terminal: `done` (finished),
|
|
1459
|
+
* `step_limit` (`maxRounds` exhausted), or `no_progress` (two empty rounds).
|
|
1460
|
+
*
|
|
1461
|
+
* Local agents only. Cloud agents throw
|
|
1462
|
+
* {@link import("../errors.js").UnsupportedRunOperationError} (the cloud
|
|
1463
|
+
* runtime manages its own continuation policy server-side).
|
|
1464
|
+
*
|
|
1465
|
+
* @public
|
|
1466
|
+
*/
|
|
1467
|
+
runToCompletion?(message: string, options?: RunToCompletionOptions): Promise<RunToCompletionResult>;
|
|
1450
1468
|
/**
|
|
1451
1469
|
* Direct API to third-party memory adapter(s) registered via
|
|
1452
1470
|
* `plugins: [...]` (ADR D141 / D142). Returns `null` when no adapter
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CustomTool, M as ModelSelection,
|
|
1
|
+
import { C as CustomTool, M as ModelSelection, F as SDKUserMessage, H as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, a as McpServerConfig } from './run-BPRYG1Id.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Fork primitive public type contracts (T1.2, ADRs D110-D114).
|
|
@@ -591,7 +591,11 @@ interface BudgetTracker {
|
|
|
591
591
|
* @public
|
|
592
592
|
*/
|
|
593
593
|
interface StoredMessage {
|
|
594
|
-
/**
|
|
594
|
+
/**
|
|
595
|
+
* Origin of the message. `tool_call` / `tool_result` are produced by
|
|
596
|
+
* `buildReplayHistory` (M1-3) for stateless replay; a consumer feeding a
|
|
597
|
+
* `user`/`assistant`-only wire-mapper must map those two roles itself.
|
|
598
|
+
*/
|
|
595
599
|
role: "user" | "assistant" | "system" | "tool_call" | "tool_result";
|
|
596
600
|
/** UTF-8 payload. May be empty string (e.g., a tool with no return value). */
|
|
597
601
|
content: string;
|
|
@@ -1447,6 +1451,20 @@ interface SDKAgent {
|
|
|
1447
1451
|
* @public
|
|
1448
1452
|
*/
|
|
1449
1453
|
fork?(options: ForkOptions): Promise<ForkResult>;
|
|
1454
|
+
/**
|
|
1455
|
+
* Drive `send` to completion across iteration-ceiling truncations (M1 Phase 3).
|
|
1456
|
+
* When a `send` stops at the loop's iteration cap (`RunResult.stoppedAtIterationLimit`),
|
|
1457
|
+
* this re-sends a short continuation prompt — the agent's stateful session
|
|
1458
|
+
* preserves the conversation — until a genuine terminal: `done` (finished),
|
|
1459
|
+
* `step_limit` (`maxRounds` exhausted), or `no_progress` (two empty rounds).
|
|
1460
|
+
*
|
|
1461
|
+
* Local agents only. Cloud agents throw
|
|
1462
|
+
* {@link import("../errors.js").UnsupportedRunOperationError} (the cloud
|
|
1463
|
+
* runtime manages its own continuation policy server-side).
|
|
1464
|
+
*
|
|
1465
|
+
* @public
|
|
1466
|
+
*/
|
|
1467
|
+
runToCompletion?(message: string, options?: RunToCompletionOptions): Promise<RunToCompletionResult>;
|
|
1450
1468
|
/**
|
|
1451
1469
|
* Direct API to third-party memory adapter(s) registered via
|
|
1452
1470
|
* `plugins: [...]` (ADR D141 / D142). Returns `null` when no adapter
|
package/dist/cron.cjs
CHANGED
|
@@ -1440,6 +1440,71 @@ var init_agent_factory_registry = __esm({
|
|
|
1440
1440
|
}
|
|
1441
1441
|
});
|
|
1442
1442
|
|
|
1443
|
+
// src/internal/runtime/lifecycle/run-to-completion.ts
|
|
1444
|
+
var run_to_completion_exports = {};
|
|
1445
|
+
__export(run_to_completion_exports, {
|
|
1446
|
+
classifyRound: () => classifyRound,
|
|
1447
|
+
runToCompletionImpl: () => runToCompletionImpl
|
|
1448
|
+
});
|
|
1449
|
+
function isEmptyRound(result) {
|
|
1450
|
+
return (result.result ?? "").trim() === "";
|
|
1451
|
+
}
|
|
1452
|
+
function classifyRound(result, round, maxRounds, emptyStreak) {
|
|
1453
|
+
if (result.stoppedAtIterationLimit !== true) return "done";
|
|
1454
|
+
if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
|
|
1455
|
+
if (round >= maxRounds) return "step_limit";
|
|
1456
|
+
return "continue";
|
|
1457
|
+
}
|
|
1458
|
+
function addUsage(acc, u) {
|
|
1459
|
+
if (u === void 0) return acc;
|
|
1460
|
+
const inputTokens = (acc?.inputTokens ?? 0) + u.inputTokens;
|
|
1461
|
+
const outputTokens = (acc?.outputTokens ?? 0) + u.outputTokens;
|
|
1462
|
+
const sumOpt = (a, b) => a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
|
|
1463
|
+
return {
|
|
1464
|
+
inputTokens,
|
|
1465
|
+
outputTokens,
|
|
1466
|
+
totalTokens: inputTokens + outputTokens,
|
|
1467
|
+
cacheReadTokens: sumOpt(acc?.cacheReadTokens, u.cacheReadTokens),
|
|
1468
|
+
cacheWriteTokens: sumOpt(acc?.cacheWriteTokens, u.cacheWriteTokens),
|
|
1469
|
+
reasoningTokens: sumOpt(acc?.reasoningTokens, u.reasoningTokens)
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
function buildResult(terminal, rounds, lastResult, usage) {
|
|
1473
|
+
return { terminal, rounds, lastResult, ...usage !== void 0 ? { usage } : {} };
|
|
1474
|
+
}
|
|
1475
|
+
async function stepRound(agent, prompt, sendOptions, round, maxRounds, state3) {
|
|
1476
|
+
const run = await agent.send(prompt, sendOptions);
|
|
1477
|
+
const result = await run.wait();
|
|
1478
|
+
const usage = addUsage(state3.usage, result.usage);
|
|
1479
|
+
const decision = classifyRound(result, round, maxRounds, state3.emptyStreak);
|
|
1480
|
+
if (decision !== "continue") return { terminal: buildResult(decision, round, result, usage) };
|
|
1481
|
+
const emptyStreak = isEmptyRound(result) ? state3.emptyStreak + 1 : 0;
|
|
1482
|
+
return { next: { usage, emptyStreak }, lastResult: result };
|
|
1483
|
+
}
|
|
1484
|
+
async function runToCompletionImpl(agent, message, options) {
|
|
1485
|
+
const maxRounds = options?.maxRounds ?? DEFAULT_MAX_ROUNDS;
|
|
1486
|
+
const continuationPrompt = options?.continuationPrompt ?? DEFAULT_CONTINUATION_PROMPT;
|
|
1487
|
+
const { onTruncated, signal, sendOptions } = options ?? {};
|
|
1488
|
+
let state3 = { usage: void 0, emptyStreak: 0 };
|
|
1489
|
+
for (let round = 0; ; round += 1) {
|
|
1490
|
+
const prompt = round === 0 ? message : continuationPrompt;
|
|
1491
|
+
const outcome = await stepRound(agent, prompt, sendOptions, round, maxRounds, state3);
|
|
1492
|
+
if ("terminal" in outcome) return outcome.terminal;
|
|
1493
|
+
state3 = outcome.next;
|
|
1494
|
+
await onTruncated?.({ round });
|
|
1495
|
+
if (signal?.aborted === true) {
|
|
1496
|
+
return buildResult("step_limit", round, outcome.lastResult, state3.usage);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
var DEFAULT_MAX_ROUNDS, DEFAULT_CONTINUATION_PROMPT;
|
|
1501
|
+
var init_run_to_completion = __esm({
|
|
1502
|
+
"src/internal/runtime/lifecycle/run-to-completion.ts"() {
|
|
1503
|
+
DEFAULT_MAX_ROUNDS = 5;
|
|
1504
|
+
DEFAULT_CONTINUATION_PROMPT = "Continue from where you left off and finish the task. If it is already complete, give the final answer.";
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
|
|
1443
1508
|
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1444
1509
|
var fork_agent_exports = {};
|
|
1445
1510
|
__export(fork_agent_exports, {
|
|
@@ -4867,6 +4932,18 @@ var CloudAgent = class {
|
|
|
4867
4932
|
"fork"
|
|
4868
4933
|
);
|
|
4869
4934
|
}
|
|
4935
|
+
/**
|
|
4936
|
+
* The continuation driver re-sends against a stateful local session; the
|
|
4937
|
+
* cloud runtime manages its own continuation policy server-side (M1 Phase 3).
|
|
4938
|
+
*
|
|
4939
|
+
* @public
|
|
4940
|
+
*/
|
|
4941
|
+
runToCompletion() {
|
|
4942
|
+
throw new UnsupportedRunOperationError(
|
|
4943
|
+
"Agent.runToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
|
|
4944
|
+
"runToCompletion"
|
|
4945
|
+
);
|
|
4946
|
+
}
|
|
4870
4947
|
/**
|
|
4871
4948
|
* Personality presets require consistent server-side enforcement that
|
|
4872
4949
|
* the cloud runtime (pre-release) does not yet provide. Reject explicitly
|
|
@@ -14347,6 +14424,13 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14347
14424
|
}
|
|
14348
14425
|
return wrap();
|
|
14349
14426
|
}
|
|
14427
|
+
function localAgentRunToCompletion(agent, message, options) {
|
|
14428
|
+
async function run() {
|
|
14429
|
+
const { runToCompletionImpl: runToCompletionImpl2 } = await Promise.resolve().then(() => (init_run_to_completion(), run_to_completion_exports));
|
|
14430
|
+
return runToCompletionImpl2({ send: (m, o) => agent.send(m, o) }, message, options);
|
|
14431
|
+
}
|
|
14432
|
+
return run();
|
|
14433
|
+
}
|
|
14350
14434
|
async function localAgentFork(parent, options) {
|
|
14351
14435
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14352
14436
|
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
@@ -14887,6 +14971,10 @@ var LocalAgent = class {
|
|
|
14887
14971
|
fork(options) {
|
|
14888
14972
|
return localAgentFork({ agentId: this.agentId, options: this.options, personalitySlugSnapshot: this.personalityStore.active(this.agentId) }, options);
|
|
14889
14973
|
}
|
|
14974
|
+
// biome-ignore format: G8 budget — see runUntil comment above.
|
|
14975
|
+
runToCompletion(message, options) {
|
|
14976
|
+
return localAgentRunToCompletion(this, message, options);
|
|
14977
|
+
}
|
|
14890
14978
|
};
|
|
14891
14979
|
function resolveCwd(cwd) {
|
|
14892
14980
|
return (Array.isArray(cwd) ? cwd[0] : cwd) ?? process.cwd();
|