@theokit/sdk 2.6.0 → 2.8.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 +22 -0
- package/dist/a2a/index.cjs +90 -10
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +90 -10
- package/dist/a2a/index.js.map +1 -1
- package/dist/compaction.cjs +213 -16
- package/dist/compaction.cjs.map +1 -1
- package/dist/compaction.d.cts +63 -19
- package/dist/compaction.d.ts +63 -19
- package/dist/compaction.js +213 -17
- package/dist/compaction.js.map +1 -1
- package/dist/{cron-B656C3iq.d.cts → cron-Bhp8rP8i.d.ts} +19 -1
- package/dist/{cron-CM2M9mhB.d.ts → cron-CRPY-aKq.d.cts} +19 -1
- package/dist/cron.cjs +90 -10
- 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 +90 -10
- package/dist/cron.js.map +1 -1
- package/dist/{errors-DG_7CAUg.d.ts → errors-C8EVGqje.d.ts} +1 -1
- package/dist/{errors-QDYUPABr.d.cts → errors-FKoM44Mj.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +90 -10
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +90 -10
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +90 -10
- 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 +90 -10
- package/dist/index.js.map +1 -1
- package/dist/internal/runtime/lifecycle/stream-to-completion.d.ts +31 -0
- package/dist/{run-BPRYG1Id.d.cts → run-D22b53SU.d.cts} +11 -2
- package/dist/{run-BPRYG1Id.d.ts → run-D22b53SU.d.ts} +11 -2
- package/dist/types/agent.d.ts +18 -0
- package/dist/types/run.d.ts +10 -1
- package/package.json +14 -14
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
1
|
+
import { C as CustomTool, M as ModelSelection, F as SDKUserMessage, H as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, S as SDKMessage, T as StreamToCompletionResult, a as McpServerConfig } from './run-D22b53SU.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Fork primitive public type contracts (T1.2, ADRs D110-D114).
|
|
@@ -1473,6 +1473,24 @@ interface SDKAgent {
|
|
|
1473
1473
|
* @public
|
|
1474
1474
|
*/
|
|
1475
1475
|
runToCompletion?(message: string, options?: RunToCompletionOptions): Promise<RunToCompletionResult>;
|
|
1476
|
+
/**
|
|
1477
|
+
* STREAMING continuation driver (V3-4) — the streaming twin of
|
|
1478
|
+
* {@link SDKAgent.runToCompletion}. Returns an `AsyncGenerator` that yields each
|
|
1479
|
+
* round's {@link import("./messages.js").SDKMessage}s LIVE (for a UI), reusing the
|
|
1480
|
+
* same terminal policy (`done`/`step_limit`/`no_progress` + bounded re-prompt).
|
|
1481
|
+
*
|
|
1482
|
+
* The {@link import("./run.js").StreamToCompletionResult} is the generator's RETURN
|
|
1483
|
+
* value — read it via a manual `gen.next()` loop (`while (!res.done) res = await
|
|
1484
|
+
* gen.next()` → `res.value`); a plain `for await...of` consumes the yielded
|
|
1485
|
+
* messages but discards the return value. For the STATELESS path, reconstruct
|
|
1486
|
+
* history with `buildReplayHistory` into a fresh session first.
|
|
1487
|
+
*
|
|
1488
|
+
* Local agents only. Cloud agents throw
|
|
1489
|
+
* {@link import("../errors.js").UnsupportedRunOperationError}.
|
|
1490
|
+
*
|
|
1491
|
+
* @public
|
|
1492
|
+
*/
|
|
1493
|
+
streamToCompletion?(message: string, options?: RunToCompletionOptions): AsyncGenerator<SDKMessage, StreamToCompletionResult>;
|
|
1476
1494
|
/**
|
|
1477
1495
|
* Direct API to third-party memory adapter(s) registered via
|
|
1478
1496
|
* `plugins: [...]` (ADR D141 / D142). Returns `null` when no adapter
|
package/dist/cron.cjs
CHANGED
|
@@ -1443,7 +1443,15 @@ var init_agent_factory_registry = __esm({
|
|
|
1443
1443
|
// src/internal/runtime/lifecycle/run-to-completion.ts
|
|
1444
1444
|
var run_to_completion_exports = {};
|
|
1445
1445
|
__export(run_to_completion_exports, {
|
|
1446
|
+
DEFAULT_CONTINUATION_PROMPT: () => DEFAULT_CONTINUATION_PROMPT,
|
|
1447
|
+
DEFAULT_MAX_ROUNDS: () => DEFAULT_MAX_ROUNDS,
|
|
1448
|
+
addUsage: () => addUsage,
|
|
1449
|
+
buildResult: () => buildResult,
|
|
1446
1450
|
classifyRound: () => classifyRound,
|
|
1451
|
+
continuationTail: () => continuationTail,
|
|
1452
|
+
isEmptyRound: () => isEmptyRound,
|
|
1453
|
+
promptForRound: () => promptForRound,
|
|
1454
|
+
resolveContinuation: () => resolveContinuation,
|
|
1447
1455
|
runToCompletionImpl: () => runToCompletionImpl
|
|
1448
1456
|
});
|
|
1449
1457
|
function isEmptyRound(result) {
|
|
@@ -1472,6 +1480,23 @@ function addUsage(acc, u) {
|
|
|
1472
1480
|
function buildResult(terminal, rounds, lastResult, usage) {
|
|
1473
1481
|
return { terminal, rounds, lastResult, ...usage !== void 0 ? { usage } : {} };
|
|
1474
1482
|
}
|
|
1483
|
+
async function continuationTail(round, lastResult, usage, onTruncated, signal) {
|
|
1484
|
+
await onTruncated?.({ round });
|
|
1485
|
+
return signal?.aborted === true ? buildResult("step_limit", round, lastResult, usage) : void 0;
|
|
1486
|
+
}
|
|
1487
|
+
function resolveContinuation(options) {
|
|
1488
|
+
return {
|
|
1489
|
+
maxRounds: options?.maxRounds ?? DEFAULT_MAX_ROUNDS,
|
|
1490
|
+
continuationPrompt: options?.continuationPrompt ?? DEFAULT_CONTINUATION_PROMPT,
|
|
1491
|
+
onTruncated: options?.onTruncated,
|
|
1492
|
+
signal: options?.signal,
|
|
1493
|
+
sendOptions: options?.sendOptions,
|
|
1494
|
+
state: { usage: void 0, emptyStreak: 0 }
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
function promptForRound(round, message, continuationPrompt) {
|
|
1498
|
+
return round === 0 ? message : continuationPrompt;
|
|
1499
|
+
}
|
|
1475
1500
|
async function stepRound(agent, prompt, sendOptions, round, maxRounds, state3) {
|
|
1476
1501
|
const run = await agent.send(prompt, sendOptions);
|
|
1477
1502
|
const result = await run.wait();
|
|
@@ -1482,19 +1507,21 @@ async function stepRound(agent, prompt, sendOptions, round, maxRounds, state3) {
|
|
|
1482
1507
|
return { next: { usage, emptyStreak }, lastResult: result };
|
|
1483
1508
|
}
|
|
1484
1509
|
async function runToCompletionImpl(agent, message, options) {
|
|
1485
|
-
const
|
|
1486
|
-
|
|
1487
|
-
const { onTruncated, signal, sendOptions } = options ?? {};
|
|
1488
|
-
let state3 = { usage: void 0, emptyStreak: 0 };
|
|
1510
|
+
const cfg = resolveContinuation(options);
|
|
1511
|
+
let state3 = cfg.state;
|
|
1489
1512
|
for (let round = 0; ; round += 1) {
|
|
1490
|
-
const prompt = round
|
|
1491
|
-
const outcome = await stepRound(agent, prompt, sendOptions, round, maxRounds, state3);
|
|
1513
|
+
const prompt = promptForRound(round, message, cfg.continuationPrompt);
|
|
1514
|
+
const outcome = await stepRound(agent, prompt, cfg.sendOptions, round, cfg.maxRounds, state3);
|
|
1492
1515
|
if ("terminal" in outcome) return outcome.terminal;
|
|
1493
1516
|
state3 = outcome.next;
|
|
1494
|
-
await
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1517
|
+
const aborted = await continuationTail(
|
|
1518
|
+
round,
|
|
1519
|
+
outcome.lastResult,
|
|
1520
|
+
state3.usage,
|
|
1521
|
+
cfg.onTruncated,
|
|
1522
|
+
cfg.signal
|
|
1523
|
+
);
|
|
1524
|
+
if (aborted !== void 0) return aborted;
|
|
1498
1525
|
}
|
|
1499
1526
|
}
|
|
1500
1527
|
var DEFAULT_MAX_ROUNDS, DEFAULT_CONTINUATION_PROMPT;
|
|
@@ -1505,6 +1532,39 @@ var init_run_to_completion = __esm({
|
|
|
1505
1532
|
}
|
|
1506
1533
|
});
|
|
1507
1534
|
|
|
1535
|
+
// src/internal/runtime/lifecycle/stream-to-completion.ts
|
|
1536
|
+
var stream_to_completion_exports = {};
|
|
1537
|
+
__export(stream_to_completion_exports, {
|
|
1538
|
+
streamToCompletionImpl: () => streamToCompletionImpl
|
|
1539
|
+
});
|
|
1540
|
+
function decideRound(result, round, maxRounds, state3) {
|
|
1541
|
+
const usage = addUsage(state3.usage, result.usage);
|
|
1542
|
+
const decision = classifyRound(result, round, maxRounds, state3.emptyStreak);
|
|
1543
|
+
if (decision !== "continue") return { terminal: buildResult(decision, round, result, usage) };
|
|
1544
|
+
const emptyStreak = isEmptyRound(result) ? state3.emptyStreak + 1 : 0;
|
|
1545
|
+
return { next: { usage, emptyStreak } };
|
|
1546
|
+
}
|
|
1547
|
+
async function* streamToCompletionImpl(agent, message, options) {
|
|
1548
|
+
const cfg = resolveContinuation(options);
|
|
1549
|
+
let state3 = cfg.state;
|
|
1550
|
+
for (let round = 0; ; round += 1) {
|
|
1551
|
+
const prompt = promptForRound(round, message, cfg.continuationPrompt);
|
|
1552
|
+
const run = await agent.send(prompt, cfg.sendOptions);
|
|
1553
|
+
yield* run.stream();
|
|
1554
|
+
const result = await run.wait();
|
|
1555
|
+
const decision = decideRound(result, round, cfg.maxRounds, state3);
|
|
1556
|
+
if ("terminal" in decision) return decision.terminal;
|
|
1557
|
+
state3 = decision.next;
|
|
1558
|
+
const aborted = await continuationTail(round, result, state3.usage, cfg.onTruncated, cfg.signal);
|
|
1559
|
+
if (aborted !== void 0) return aborted;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
var init_stream_to_completion = __esm({
|
|
1563
|
+
"src/internal/runtime/lifecycle/stream-to-completion.ts"() {
|
|
1564
|
+
init_run_to_completion();
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
|
|
1508
1568
|
// src/internal/runtime/lifecycle/fork-agent.ts
|
|
1509
1569
|
var fork_agent_exports = {};
|
|
1510
1570
|
__export(fork_agent_exports, {
|
|
@@ -4944,6 +5004,18 @@ var CloudAgent = class {
|
|
|
4944
5004
|
"runToCompletion"
|
|
4945
5005
|
);
|
|
4946
5006
|
}
|
|
5007
|
+
/**
|
|
5008
|
+
* Cloud agents do not expose the streaming continuation driver (V3-4);
|
|
5009
|
+
* the cloud runtime manages continuation server-side.
|
|
5010
|
+
*
|
|
5011
|
+
* @public
|
|
5012
|
+
*/
|
|
5013
|
+
streamToCompletion() {
|
|
5014
|
+
throw new UnsupportedRunOperationError(
|
|
5015
|
+
"Agent.streamToCompletion() is not supported on cloud agents. Cloud runtime manages continuation server-side. Use a local agent.",
|
|
5016
|
+
"streamToCompletion"
|
|
5017
|
+
);
|
|
5018
|
+
}
|
|
4947
5019
|
/**
|
|
4948
5020
|
* Personality presets require consistent server-side enforcement that
|
|
4949
5021
|
* the cloud runtime (pre-release) does not yet provide. Reject explicitly
|
|
@@ -14478,6 +14550,10 @@ function localAgentRunToCompletion(agent, message, options) {
|
|
|
14478
14550
|
}
|
|
14479
14551
|
return run();
|
|
14480
14552
|
}
|
|
14553
|
+
async function* localAgentStreamToCompletion(agent, message, options) {
|
|
14554
|
+
const { streamToCompletionImpl: streamToCompletionImpl2 } = await Promise.resolve().then(() => (init_stream_to_completion(), stream_to_completion_exports));
|
|
14555
|
+
return yield* streamToCompletionImpl2({ send: (m, o) => agent.send(m, o) }, message, options);
|
|
14556
|
+
}
|
|
14481
14557
|
async function localAgentFork(parent, options) {
|
|
14482
14558
|
const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
|
|
14483
14559
|
const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
|
|
@@ -15022,6 +15098,10 @@ var LocalAgent = class {
|
|
|
15022
15098
|
runToCompletion(message, options) {
|
|
15023
15099
|
return localAgentRunToCompletion(this, message, options);
|
|
15024
15100
|
}
|
|
15101
|
+
// biome-ignore format: G8 budget — see runUntil comment above.
|
|
15102
|
+
streamToCompletion(message, options) {
|
|
15103
|
+
return localAgentStreamToCompletion(this, message, options);
|
|
15104
|
+
}
|
|
15025
15105
|
};
|
|
15026
15106
|
function resolveCwd(cwd) {
|
|
15027
15107
|
return (Array.isArray(cwd) ? cwd[0] : cwd) ?? process.cwd();
|