@theokit/sdk 2.1.0 → 2.2.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/index.cjs CHANGED
@@ -6807,8 +6807,7 @@ var FixtureRunBase = class {
6807
6807
  if (status === "error" && this.script.errorDetail !== void 0) {
6808
6808
  base.error = this.script.errorDetail;
6809
6809
  }
6810
- if (this.script.usage !== void 0) base.usage = this.script.usage;
6811
- if (this.script.cost !== void 0) base.cost = this.script.cost;
6810
+ applyScriptMetrics(base, this.script);
6812
6811
  return this.extendRunResult(applyExtraRunFields(base, this.script));
6813
6812
  }
6814
6813
  /** Subclasses override to attach runtime-specific fields (e.g. cloud git info). */
@@ -6842,6 +6841,11 @@ function makeNotifier() {
6842
6841
  });
6843
6842
  return { promise, resolve: resolve3 };
6844
6843
  }
6844
+ function applyScriptMetrics(base, script) {
6845
+ if (script.usage !== void 0) base.usage = script.usage;
6846
+ if (script.cost !== void 0) base.cost = script.cost;
6847
+ if (script.stoppedAtIterationLimit === true) base.stoppedAtIterationLimit = true;
6848
+ }
6845
6849
 
6846
6850
  // src/internal/runtime/cloud/cloud-run.ts
6847
6851
  function createCloudRun(options) {
@@ -10444,6 +10448,9 @@ var LocalRun = class extends FixtureRunBase {
10444
10448
  }
10445
10449
  };
10446
10450
 
10451
+ // src/internal/runtime/local-agent/real-local-run.ts
10452
+ init_errors();
10453
+
10447
10454
  // src/internal/runtime/budget/budget.ts
10448
10455
  var IterationBudget = class {
10449
10456
  #remaining;
@@ -11668,6 +11675,7 @@ async function runAgentLoop(inputs) {
11668
11675
  const ctx = await initLoopContext(inputs);
11669
11676
  ctxRef = ctx;
11670
11677
  const budget = inputs.budget ?? new IterationBudget({ maxIterations: inputs.maxIterations ?? 8 });
11678
+ let lastTurnDecision;
11671
11679
  while (budget.shouldContinue()) {
11672
11680
  if (inputs.budgetTracker !== void 0) {
11673
11681
  const decision2 = evaluateBudgetGate(inputs.budgetTracker);
@@ -11676,18 +11684,26 @@ async function runAgentLoop(inputs) {
11676
11684
  if (decision2.detail !== void 0) {
11677
11685
  ctx.error = { message: decision2.detail, code: decision2.reason ?? "budget" };
11678
11686
  }
11687
+ if (decision2.reason === "iteration_limit") {
11688
+ ctx.stoppedAtIterationLimit = true;
11689
+ }
11679
11690
  break;
11680
11691
  }
11681
11692
  }
11682
11693
  const usingGrace = budget.remaining <= 0 && !budget.graceCallUsed;
11683
11694
  if (usingGrace) budget.useGraceCall();
11684
11695
  const decision = await runIteration(inputs, ctx);
11696
+ lastTurnDecision = decision;
11685
11697
  if (decision === "done") break;
11686
11698
  if (decision === "error") {
11687
11699
  ctx.finalStatus = "error";
11688
11700
  break;
11689
11701
  }
11690
11702
  budget.consume();
11703
+ inputs.budgetTracker?.nextIteration?.();
11704
+ }
11705
+ if (lastTurnDecision === "continue" && budget.shouldContinue() === false) {
11706
+ ctx.stoppedAtIterationLimit = true;
11691
11707
  }
11692
11708
  if (budget.shouldContinue() === false && ctx.finalStatus === "finished" && ctx.finalText === "") {
11693
11709
  ctx.finalStatus = "error";
@@ -11718,7 +11734,8 @@ async function runAgentLoop(inputs) {
11718
11734
  conversation: ctx.conversation,
11719
11735
  ...usage !== void 0 ? { usage } : {},
11720
11736
  ...cost !== void 0 ? { cost } : {},
11721
- ...ctx.error !== void 0 ? { error: ctx.error } : {}
11737
+ ...ctx.error !== void 0 ? { error: ctx.error } : {},
11738
+ ...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {}
11722
11739
  };
11723
11740
  } finally {
11724
11741
  if (ctxRef !== void 0 && ctxRef.memoryProviderHandle !== void 0 && inputs.memoryProvider !== void 0) {
@@ -14153,6 +14170,13 @@ function resolveRunProvider(options) {
14153
14170
  return { primary, effectiveModelId };
14154
14171
  }
14155
14172
  function buildLoopInputs(options, runId, userText) {
14173
+ const maxIterations = options.sendOptions.maxIterations;
14174
+ if (maxIterations !== void 0 && (!Number.isInteger(maxIterations) || maxIterations < 1)) {
14175
+ throw new exports.ConfigurationError(
14176
+ `SendOptions.maxIterations must be a positive integer, got ${maxIterations}`,
14177
+ { code: "invalid_max_iterations" }
14178
+ );
14179
+ }
14156
14180
  const { primary, effectiveModelId } = resolveRunProvider(options);
14157
14181
  const fallback = options.agentOptions.providers?.fallback;
14158
14182
  const apiKeys = options.agentOptions.providers?.apiKeys;
@@ -14191,6 +14215,9 @@ function buildLoopInputs(options, runId, userText) {
14191
14215
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
14192
14216
  // can attach it to the LLM `fetch({ signal })` call.
14193
14217
  ...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
14218
+ // M1-2: per-send iteration ceiling (validated above). The loop reads
14219
+ // inputs.maxIterations (default 8 when unset).
14220
+ ...maxIterations !== void 0 ? { maxIterations } : {},
14194
14221
  // D315-D317 — tool lifecycle hooks (cost tracking + audit + retry/alert)
14195
14222
  ...options.agentOptions.onToolStart !== void 0 ? { onToolStart: options.agentOptions.onToolStart } : {},
14196
14223
  ...options.agentOptions.onToolEnd !== void 0 ? { onToolEnd: options.agentOptions.onToolEnd } : {},
@@ -14322,6 +14349,7 @@ var RealLocalRun = class extends FixtureRunBase {
14322
14349
  if (output.result.length > 0) this.script.result = output.result;
14323
14350
  if (output.usage !== void 0) this.script.usage = output.usage;
14324
14351
  if (output.cost !== void 0) this.script.cost = output.cost;
14352
+ if (output.stoppedAtIterationLimit === true) this.script.stoppedAtIterationLimit = true;
14325
14353
  if (output.error !== void 0 && this.script.errorDetail === void 0) {
14326
14354
  this.script.errorDetail = {
14327
14355
  message: output.error.message,