@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.
@@ -1,4 +1,4 @@
1
- import { p as RunOperation } from './run-DrwUpFxZ.js';
1
+ import { p as RunOperation } from './run-ekGKZlmg.js';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
@@ -1,4 +1,4 @@
1
- import { p as RunOperation } from './run-DrwUpFxZ.cjs';
1
+ import { p as RunOperation } from './run-ekGKZlmg.cjs';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
package/dist/errors.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-C9xkhNEF.cjs';
2
- import './run-DrwUpFxZ.cjs';
1
+ export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-Vhg6ZV4o.cjs';
2
+ import './run-ekGKZlmg.cjs';
package/dist/eval.cjs CHANGED
@@ -4315,8 +4315,7 @@ var FixtureRunBase = class {
4315
4315
  if (status === "error" && this.script.errorDetail !== void 0) {
4316
4316
  base.error = this.script.errorDetail;
4317
4317
  }
4318
- if (this.script.usage !== void 0) base.usage = this.script.usage;
4319
- if (this.script.cost !== void 0) base.cost = this.script.cost;
4318
+ applyScriptMetrics(base, this.script);
4320
4319
  return this.extendRunResult(applyExtraRunFields(base, this.script));
4321
4320
  }
4322
4321
  /** Subclasses override to attach runtime-specific fields (e.g. cloud git info). */
@@ -4350,6 +4349,11 @@ function makeNotifier() {
4350
4349
  });
4351
4350
  return { promise, resolve: resolve3 };
4352
4351
  }
4352
+ function applyScriptMetrics(base, script) {
4353
+ if (script.usage !== void 0) base.usage = script.usage;
4354
+ if (script.cost !== void 0) base.cost = script.cost;
4355
+ if (script.stoppedAtIterationLimit === true) base.stoppedAtIterationLimit = true;
4356
+ }
4353
4357
 
4354
4358
  // src/internal/runtime/cloud/cloud-run.ts
4355
4359
  function createCloudRun(options) {
@@ -7982,6 +7986,9 @@ var LocalRun = class extends FixtureRunBase {
7982
7986
  }
7983
7987
  };
7984
7988
 
7989
+ // src/internal/runtime/local-agent/real-local-run.ts
7990
+ init_errors();
7991
+
7985
7992
  // src/internal/runtime/budget/budget.ts
7986
7993
  var IterationBudget = class {
7987
7994
  #remaining;
@@ -9206,6 +9213,7 @@ async function runAgentLoop(inputs) {
9206
9213
  const ctx = await initLoopContext(inputs);
9207
9214
  ctxRef = ctx;
9208
9215
  const budget = inputs.budget ?? new IterationBudget({ maxIterations: inputs.maxIterations ?? 8 });
9216
+ let lastTurnDecision;
9209
9217
  while (budget.shouldContinue()) {
9210
9218
  if (inputs.budgetTracker !== void 0) {
9211
9219
  const decision2 = evaluateBudgetGate(inputs.budgetTracker);
@@ -9214,18 +9222,26 @@ async function runAgentLoop(inputs) {
9214
9222
  if (decision2.detail !== void 0) {
9215
9223
  ctx.error = { message: decision2.detail, code: decision2.reason ?? "budget" };
9216
9224
  }
9225
+ if (decision2.reason === "iteration_limit") {
9226
+ ctx.stoppedAtIterationLimit = true;
9227
+ }
9217
9228
  break;
9218
9229
  }
9219
9230
  }
9220
9231
  const usingGrace = budget.remaining <= 0 && !budget.graceCallUsed;
9221
9232
  if (usingGrace) budget.useGraceCall();
9222
9233
  const decision = await runIteration(inputs, ctx);
9234
+ lastTurnDecision = decision;
9223
9235
  if (decision === "done") break;
9224
9236
  if (decision === "error") {
9225
9237
  ctx.finalStatus = "error";
9226
9238
  break;
9227
9239
  }
9228
9240
  budget.consume();
9241
+ inputs.budgetTracker?.nextIteration?.();
9242
+ }
9243
+ if (lastTurnDecision === "continue" && budget.shouldContinue() === false) {
9244
+ ctx.stoppedAtIterationLimit = true;
9229
9245
  }
9230
9246
  if (budget.shouldContinue() === false && ctx.finalStatus === "finished" && ctx.finalText === "") {
9231
9247
  ctx.finalStatus = "error";
@@ -9256,7 +9272,8 @@ async function runAgentLoop(inputs) {
9256
9272
  conversation: ctx.conversation,
9257
9273
  ...usage !== void 0 ? { usage } : {},
9258
9274
  ...cost !== void 0 ? { cost } : {},
9259
- ...ctx.error !== void 0 ? { error: ctx.error } : {}
9275
+ ...ctx.error !== void 0 ? { error: ctx.error } : {},
9276
+ ...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {}
9260
9277
  };
9261
9278
  } finally {
9262
9279
  if (ctxRef !== void 0 && ctxRef.memoryProviderHandle !== void 0 && inputs.memoryProvider !== void 0) {
@@ -11675,6 +11692,13 @@ function resolveRunProvider(options) {
11675
11692
  return { primary, effectiveModelId };
11676
11693
  }
11677
11694
  function buildLoopInputs(options, runId, userText) {
11695
+ const maxIterations = options.sendOptions.maxIterations;
11696
+ if (maxIterations !== void 0 && (!Number.isInteger(maxIterations) || maxIterations < 1)) {
11697
+ throw new ConfigurationError(
11698
+ `SendOptions.maxIterations must be a positive integer, got ${maxIterations}`,
11699
+ { code: "invalid_max_iterations" }
11700
+ );
11701
+ }
11678
11702
  const { primary, effectiveModelId } = resolveRunProvider(options);
11679
11703
  const fallback = options.agentOptions.providers?.fallback;
11680
11704
  const apiKeys = options.agentOptions.providers?.apiKeys;
@@ -11713,6 +11737,9 @@ function buildLoopInputs(options, runId, userText) {
11713
11737
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
11714
11738
  // can attach it to the LLM `fetch({ signal })` call.
11715
11739
  ...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
11740
+ // M1-2: per-send iteration ceiling (validated above). The loop reads
11741
+ // inputs.maxIterations (default 8 when unset).
11742
+ ...maxIterations !== void 0 ? { maxIterations } : {},
11716
11743
  // D315-D317 — tool lifecycle hooks (cost tracking + audit + retry/alert)
11717
11744
  ...options.agentOptions.onToolStart !== void 0 ? { onToolStart: options.agentOptions.onToolStart } : {},
11718
11745
  ...options.agentOptions.onToolEnd !== void 0 ? { onToolEnd: options.agentOptions.onToolEnd } : {},
@@ -11844,6 +11871,7 @@ var RealLocalRun = class extends FixtureRunBase {
11844
11871
  if (output.result.length > 0) this.script.result = output.result;
11845
11872
  if (output.usage !== void 0) this.script.usage = output.usage;
11846
11873
  if (output.cost !== void 0) this.script.cost = output.cost;
11874
+ if (output.stoppedAtIterationLimit === true) this.script.stoppedAtIterationLimit = true;
11847
11875
  if (output.error !== void 0 && this.script.errorDetail === void 0) {
11848
11876
  this.script.errorDetail = {
11849
11877
  message: output.error.message,