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