@theokit/sdk 4.17.0 → 4.18.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,3 +1,3 @@
1
- export { N as Cron } from './cron-Dj8FAU5V.cjs';
1
+ export { N as Cron } from './cron-DvP-E6Xx.cjs';
2
2
  import './run-DFM1H2jW.cjs';
3
3
  import 'zod';
package/dist/cron.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { N as Cron } from './cron-B_vVYc-_.js';
1
+ export { N as Cron } from './cron-DOW3f-Xu.js';
2
2
  import './run-DFM1H2jW.js';
3
3
  import 'zod';
package/dist/cron.js CHANGED
@@ -5945,9 +5945,7 @@ async function hydrateSession(agentId, loc) {
5945
5945
  hydratedKeys.add(key);
5946
5946
  const persisted = await readSessionMessages(loc.store, agentId);
5947
5947
  if (persisted.length === 0) return;
5948
- if (!sessions.has(agentId) || sessions.get(agentId)?.length === 0) {
5949
- sessions.set(agentId, persisted);
5950
- }
5948
+ sessions.set(agentId, persisted);
5951
5949
  }
5952
5950
  async function flushSessionWrites() {
5953
5951
  while (pendingWrites.size > 0) {
@@ -6255,10 +6253,12 @@ __export(run_until_exports, {
6255
6253
  async function* runUntilImpl(agent, goal, options, deps) {
6256
6254
  const maxTurns = options?.maxTurns ?? 20;
6257
6255
  const maxFails = options?.maxConsecutiveJudgeFailures ?? 3;
6256
+ const tokenBudget = options?.tokenBudget;
6258
6257
  const signal = options?.signal;
6259
6258
  const isAborted = () => signal !== void 0 && signal.aborted;
6260
6259
  let turn = 0;
6261
6260
  let consecutiveFailures = 0;
6261
+ let tokensUsed = 0;
6262
6262
  let lastResponse = "";
6263
6263
  if (isAborted()) {
6264
6264
  yield {
@@ -6266,13 +6266,13 @@ async function* runUntilImpl(agent, goal, options, deps) {
6266
6266
  status: "paused",
6267
6267
  reason: "aborted via AbortSignal before first turn"
6268
6268
  };
6269
- return { status: "paused", turnsUsed: 0, finalResponse: void 0 };
6269
+ return { status: "paused", turnsUsed: 0, tokensUsed, finalResponse: void 0 };
6270
6270
  }
6271
6271
  yield { type: "status_change", status: "active", reason: "Goal started" };
6272
6272
  while (turn < maxTurns) {
6273
6273
  if (isAborted()) {
6274
6274
  yield { type: "status_change", status: "paused", reason: "aborted via AbortSignal" };
6275
- return { status: "paused", turnsUsed: turn, finalResponse: lastResponse || void 0 };
6275
+ return { status: "paused", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
6276
6276
  }
6277
6277
  turn += 1;
6278
6278
  yield { type: "turn_start", turn, goal };
@@ -6280,6 +6280,8 @@ async function* runUntilImpl(agent, goal, options, deps) {
6280
6280
  const run = await agent.send(continuationPrompt);
6281
6281
  const result = await run.wait();
6282
6282
  lastResponse = result.result ?? "";
6283
+ const turnTokens = result.usage?.totalTokens;
6284
+ if (typeof turnTokens === "number") tokensUsed += turnTokens;
6283
6285
  yield { type: "agent_response", turn, content: lastResponse };
6284
6286
  const judgeOpts = {};
6285
6287
  if (options?.judgeModel !== void 0) judgeOpts.judgeModel = options.judgeModel;
@@ -6305,6 +6307,7 @@ async function* runUntilImpl(agent, goal, options, deps) {
6305
6307
  return {
6306
6308
  status: "failed",
6307
6309
  turnsUsed: turn,
6310
+ tokensUsed,
6308
6311
  finalResponse: lastResponse || void 0
6309
6312
  };
6310
6313
  }
@@ -6313,7 +6316,7 @@ async function* runUntilImpl(agent, goal, options, deps) {
6313
6316
  }
6314
6317
  if (judgment.verdict === "done") {
6315
6318
  yield { type: "status_change", status: "completed", reason: judgment.reason };
6316
- return { status: "completed", turnsUsed: turn, finalResponse: lastResponse || void 0 };
6319
+ return { status: "completed", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
6317
6320
  }
6318
6321
  if (judgment.verdict === "skipped") {
6319
6322
  yield {
@@ -6321,7 +6324,15 @@ async function* runUntilImpl(agent, goal, options, deps) {
6321
6324
  status: "completed",
6322
6325
  reason: `skipped: ${judgment.reason}`
6323
6326
  };
6324
- return { status: "completed", turnsUsed: turn, finalResponse: lastResponse || void 0 };
6327
+ return { status: "completed", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
6328
+ }
6329
+ if (tokenBudget !== void 0 && tokensUsed >= tokenBudget) {
6330
+ yield {
6331
+ type: "status_change",
6332
+ status: "budget_limited",
6333
+ reason: `token budget (${tokenBudget}) reached: ${tokensUsed} used`
6334
+ };
6335
+ return { status: "budget_limited", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
6325
6336
  }
6326
6337
  yield { type: "continuation", turn, prompt: continuationPrompt };
6327
6338
  }
@@ -6330,13 +6341,32 @@ async function* runUntilImpl(agent, goal, options, deps) {
6330
6341
  status: "failed",
6331
6342
  reason: `max turns (${maxTurns}) exhausted`
6332
6343
  };
6333
- return { status: "failed", turnsUsed: turn, finalResponse: lastResponse || void 0 };
6344
+ return { status: "failed", turnsUsed: turn, tokensUsed, finalResponse: lastResponse || void 0 };
6334
6345
  }
6335
6346
  function composeContinuation(goal, lastResponse) {
6336
- return `Continue working toward the goal: ${goal}
6337
-
6338
- Your last response was:
6339
- ${lastResponse.slice(0, 1e3)}`;
6347
+ return [
6348
+ "Continue working toward the active goal.",
6349
+ "",
6350
+ `<objective>
6351
+ ${goal}
6352
+ </objective>`,
6353
+ "",
6354
+ "Continuation behavior:",
6355
+ "- This goal persists across turns. Keep the full objective intact; if it cannot be finished now,",
6356
+ " make concrete progress toward the real requested end state and do not redefine success around a",
6357
+ " smaller or easier task.",
6358
+ "",
6359
+ "Work from evidence:",
6360
+ "- Use the current worktree and external state as authoritative. Inspect the current state before",
6361
+ " relying on it. Improve, replace, or remove existing work as needed to satisfy the actual objective.",
6362
+ "",
6363
+ "Completion audit:",
6364
+ "- Before deciding the goal is achieved, treat completion as unproven and verify it against the actual",
6365
+ " current state, requirement by requirement. Treat uncertain or indirect evidence as not achieved.",
6366
+ "",
6367
+ `Your last response was:
6368
+ ${lastResponse.slice(0, 1e3)}`
6369
+ ].join("\n");
6340
6370
  }
6341
6371
  var init_run_until = __esm({
6342
6372
  "src/internal/runtime/lifecycle/run-until.ts"() {
@@ -18580,7 +18610,7 @@ function localAgentRunUntil(agent, goal, options) {
18580
18610
  status: "paused",
18581
18611
  reason: "runUntil() requires an explicit goal (durable objectives removed in v4.0)"
18582
18612
  };
18583
- return { status: "paused", turnsUsed: 0, finalResponse: void 0 };
18613
+ return { status: "paused", turnsUsed: 0, tokensUsed: 0, finalResponse: void 0 };
18584
18614
  }
18585
18615
  return yield* runUntilImpl2(agent, goal, options, await buildDeps());
18586
18616
  }