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