@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d7d5215: M1-3 — `buildReplayHistory(base, events, options)` pure stateless continuation-history rebuild (plan `m1-continuation-history`).
|
|
8
|
+
|
|
9
|
+
The stateless complement to M1 Phase 3's `runToCompletion` (which covers the stateful-session path). For a server / serverless handler that re-runs an agent on a fresh request and must reconstruct working memory from persisted stream events, `buildReplayHistory` serializes a round's `SDKMessage[]` into a bounded `StoredMessage[]` you can replay as prior history:
|
|
10
|
+
|
|
11
|
+
- maps assistant text → `assistant`; tool `running` → `tool_call` (args); tool `completed`/`error` → `tool_result` (carrying the result content the continued model needs);
|
|
12
|
+
- drops the oldest turns — pair-safe (a `tool_call` and its `tool_result` are never split) — until the total fits a context-window-derived char budget, keeping ≥ 1;
|
|
13
|
+
- truncates an oversized single turn (reusing the SDK's `truncateWithMarker`) rather than dropping it;
|
|
14
|
+
- pure, synchronous, dependency-free; a non-finite `contextWindowTokens` collapses to budget 0 (never returns an unbounded history).
|
|
15
|
+
|
|
16
|
+
Exported from `@theokit/sdk` with `ReplayHistoryOptions`. Replaces the outer-loop history rebuild a code-assistant server otherwise hand-rolls.
|
|
17
|
+
|
|
18
|
+
- f218630: M1 Phase 3 — `agent.runToCompletion()` continuation driver (plan `m1-run-to-completion`).
|
|
19
|
+
|
|
20
|
+
Builds on M1-2's `RunResult.stoppedAtIterationLimit` signal: a single `agent.send()` truncates when the model still wants tools at the loop's iteration ceiling. `runToCompletion(message, options?)` re-sends a short continuation prompt — the agent's stateful session preserves the conversation — until a genuine terminal:
|
|
21
|
+
|
|
22
|
+
- `done` — a round finished without truncating.
|
|
23
|
+
- `step_limit` — `maxRounds` (default 5) exhausted, or aborted via `signal`, while still truncating.
|
|
24
|
+
- `no_progress` — two consecutive rounds produced empty output.
|
|
25
|
+
|
|
26
|
+
Returns `{ terminal, rounds, lastResult, usage }` with token usage summed across rounds. Options: `maxRounds`, `continuationPrompt`, `onTruncated`, `signal`, `sendOptions`. Local agents only — cloud agents throw `UnsupportedRunOperationError` (the cloud runtime manages continuation server-side). This replaces the outer continuation loop a code-assistant builder would otherwise hand-roll.
|
|
27
|
+
|
|
3
28
|
## 2.2.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/dist/a2a/index.cjs
CHANGED
|
@@ -3003,6 +3003,18 @@ var init_cloud_agent = __esm({
|
|
|
3003
3003
|
"fork"
|
|
3004
3004
|
);
|
|
3005
3005
|
}
|
|
3006
|
+
/**
|
|
3007
|
+
* The continuation driver re-sends against a stateful local session; the
|
|
3008
|
+
* cloud runtime manages its own continuation policy server-side (M1 Phase 3).
|
|
3009
|
+
*
|
|
3010
|
+
* @public
|
|
3011
|
+
*/
|
|
3012
|
+
runToCompletion() {
|
|
3013
|
+
throw new UnsupportedRunOperationError(
|
|
3014
|
+
"Agent.runToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
|
|
3015
|
+
"runToCompletion"
|
|
3016
|
+
);
|
|
3017
|
+
}
|
|
3006
3018
|
/**
|
|
3007
3019
|
* Personality presets require consistent server-side enforcement that
|
|
3008
3020
|
* the cloud runtime (pre-release) does not yet provide. Reject explicitly
|
|
@@ -14190,6 +14202,71 @@ var init_agent_factory_registry = __esm({
|
|
|
14190
14202
|
}
|
|
14191
14203
|
});
|
|
14192
14204
|
|
|
14205
|
+
// src/internal/runtime/lifecycle/run-to-completion.ts
|
|
14206
|
+
var run_to_completion_exports = {};
|
|
14207
|
+
__export(run_to_completion_exports, {
|
|
14208
|
+
classifyRound: () => classifyRound,
|
|
14209
|
+
runToCompletionImpl: () => runToCompletionImpl
|
|
14210
|
+
});
|
|
14211
|
+
function isEmptyRound(result) {
|
|
14212
|
+
return (result.result ?? "").trim() === "";
|
|
14213
|
+
}
|
|
14214
|
+
function classifyRound(result, round, maxRounds, emptyStreak) {
|
|
14215
|
+
if (result.stoppedAtIterationLimit !== true) return "done";
|
|
14216
|
+
if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
|
|
14217
|
+
if (round >= maxRounds) return "step_limit";
|
|
14218
|
+
return "continue";
|
|
14219
|
+
}
|
|
14220
|
+
function addUsage(acc, u) {
|
|
14221
|
+
if (u === void 0) return acc;
|
|
14222
|
+
const inputTokens = (acc?.inputTokens ?? 0) + u.inputTokens;
|
|
14223
|
+
const outputTokens = (acc?.outputTokens ?? 0) + u.outputTokens;
|
|
14224
|
+
const sumOpt = (a, b) => a === void 0 && b === void 0 ? void 0 : (a ?? 0) + (b ?? 0);
|
|
14225
|
+
return {
|
|
14226
|
+
inputTokens,
|
|
14227
|
+
outputTokens,
|
|
14228
|
+
totalTokens: inputTokens + outputTokens,
|
|
14229
|
+
cacheReadTokens: sumOpt(acc?.cacheReadTokens, u.cacheReadTokens),
|
|
14230
|
+
cacheWriteTokens: sumOpt(acc?.cacheWriteTokens, u.cacheWriteTokens),
|
|
14231
|
+
reasoningTokens: sumOpt(acc?.reasoningTokens, u.reasoningTokens)
|
|
14232
|
+
};
|
|
14233
|
+
}
|
|
14234
|
+
function buildResult(terminal, rounds, lastResult, usage) {
|
|
14235
|
+
return { terminal, rounds, lastResult, ...usage !== void 0 ? { usage } : {} };
|
|
14236
|
+
}
|
|
14237
|
+
async function stepRound(agent, prompt, sendOptions, round, maxRounds, state2) {
|
|
14238
|
+
const run = await agent.send(prompt, sendOptions);
|
|
14239
|
+
const result = await run.wait();
|
|
14240
|
+
const usage = addUsage(state2.usage, result.usage);
|
|
14241
|
+
const decision = classifyRound(result, round, maxRounds, state2.emptyStreak);
|
|
14242
|
+
if (decision !== "continue") return { terminal: buildResult(decision, round, result, usage) };
|
|
14243
|
+
const emptyStreak = isEmptyRound(result) ? state2.emptyStreak + 1 : 0;
|
|
14244
|
+
return { next: { usage, emptyStreak }, lastResult: result };
|
|
14245
|
+
}
|
|
14246
|
+
async function runToCompletionImpl(agent, message, options) {
|
|
14247
|
+
const maxRounds = options?.maxRounds ?? DEFAULT_MAX_ROUNDS;
|
|
14248
|
+
const continuationPrompt = options?.continuationPrompt ?? DEFAULT_CONTINUATION_PROMPT;
|
|
14249
|
+
const { onTruncated, signal, sendOptions } = options ?? {};
|
|
14250
|
+
let state2 = { usage: void 0, emptyStreak: 0 };
|
|
14251
|
+
for (let round = 0; ; round += 1) {
|
|
14252
|
+
const prompt = round === 0 ? message : continuationPrompt;
|
|
14253
|
+
const outcome = await stepRound(agent, prompt, sendOptions, round, maxRounds, state2);
|
|
14254
|
+
if ("terminal" in outcome) return outcome.terminal;
|
|
14255
|
+
state2 = outcome.next;
|
|
14256
|
+
await onTruncated?.({ round });
|
|
14257
|
+
if (signal?.aborted === true) {
|
|
14258
|
+
return buildResult("step_limit", round, outcome.lastResult, state2.usage);
|
|
14259
|
+
}
|
|
14260
|
+
}
|
|
14261
|
+
}
|
|
14262
|
+
var DEFAULT_MAX_ROUNDS, DEFAULT_CONTINUATION_PROMPT;
|
|
14263
|
+
var init_run_to_completion = __esm({
|
|
14264
|
+
"src/internal/runtime/lifecycle/run-to-completion.ts"() {
|
|
14265
|
+
DEFAULT_MAX_ROUNDS = 5;
|
|
14266
|
+
DEFAULT_CONTINUATION_PROMPT = "Continue from where you left off and finish the task. If it is already complete, give the final answer.";
|
|
14267
|
+
}
|
|
14268
|
+
});
|
|
14269
|
+
|
|
14193
14270
|
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
14194
14271
|
var fork_agent_exports = {};
|
|
14195
14272
|
__export(fork_agent_exports, {
|
|
@@ -14270,6 +14347,13 @@ function localAgentRunUntil(agent, goal, options) {
|
|
|
14270
14347
|
}
|
|
14271
14348
|
return wrap();
|
|
14272
14349
|
}
|
|
14350
|
+
function localAgentRunToCompletion(agent, message, options) {
|
|
14351
|
+
async function run() {
|
|
14352
|
+
const { runToCompletionImpl: runToCompletionImpl2 } = await Promise.resolve().then(() => (init_run_to_completion(), run_to_completion_exports));
|
|
14353
|
+
return runToCompletionImpl2({ send: (m, o) => agent.send(m, o) }, message, options);
|
|
14354
|
+
}
|
|
14355
|
+
return run();
|
|
14356
|
+
}
|
|
14273
14357
|
async function localAgentFork(parent, options) {
|
|
14274
14358
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14275
14359
|
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
@@ -15404,6 +15488,10 @@ var init_local_agent = __esm({
|
|
|
15404
15488
|
fork(options) {
|
|
15405
15489
|
return localAgentFork({ agentId: this.agentId, options: this.options, personalitySlugSnapshot: this.personalityStore.active(this.agentId) }, options);
|
|
15406
15490
|
}
|
|
15491
|
+
// biome-ignore format: G8 budget — see runUntil comment above.
|
|
15492
|
+
runToCompletion(message, options) {
|
|
15493
|
+
return localAgentRunToCompletion(this, message, options);
|
|
15494
|
+
}
|
|
15407
15495
|
};
|
|
15408
15496
|
}
|
|
15409
15497
|
});
|