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