@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/CHANGELOG.md +10 -0
- package/dist/a2a/index.cjs +29 -3
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +29 -3
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-CSTqNZp9.d.cts → cron-Aksw2Hy4.d.ts} +9 -1
- package/dist/{cron-Da6vF_2y.d.ts → cron-JSPSFczQ.d.cts} +9 -1
- package/dist/cron.cjs +31 -3
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +31 -3
- package/dist/cron.js.map +1 -1
- package/dist/{errors--VP2qrGc.d.ts → errors-Bcw_Pakm.d.ts} +1 -1
- package/dist/{errors-C9xkhNEF.d.cts → errors-Vhg6ZV4o.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +31 -3
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +31 -3
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +31 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +31 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-loop/loop-types.d.ts +6 -0
- package/dist/internal/runtime/budget/budget-tracker.d.ts +8 -0
- package/dist/{run-DrwUpFxZ.d.cts → run-ekGKZlmg.d.cts} +20 -0
- package/dist/{run-DrwUpFxZ.d.ts → run-ekGKZlmg.d.ts} +20 -0
- package/dist/types/run.d.ts +20 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CustomTool, M as ModelSelection, D as SDKUserMessage, F as SendOptions, b as Run, a as McpServerConfig } from './run-
|
|
1
|
+
import { C as CustomTool, M as ModelSelection, D as SDKUserMessage, F as SendOptions, b as Run, a as McpServerConfig } from './run-ekGKZlmg.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Fork primitive public type contracts (T1.2, ADRs D110-D114).
|
|
@@ -559,6 +559,14 @@ interface BudgetTracker {
|
|
|
559
559
|
check(): BudgetCheck;
|
|
560
560
|
/** Snapshot of accumulated totals (for telemetry / final reporting). */
|
|
561
561
|
getTotal(): BudgetTotal;
|
|
562
|
+
/**
|
|
563
|
+
* Advance the iteration counter by one. Called by the agent loop ONCE per
|
|
564
|
+
* completed turn (M1-1) so that trackers which gate on `maxIterations`
|
|
565
|
+
* (e.g. `createCounterBudgetTracker`) actually halt. OPTIONAL: trackers that
|
|
566
|
+
* only gate on tokens/USD omit it and the loop no-ops via optional chaining.
|
|
567
|
+
* MUST be synchronous and non-throwing.
|
|
568
|
+
*/
|
|
569
|
+
nextIteration?(): void;
|
|
562
570
|
}
|
|
563
571
|
|
|
564
572
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CustomTool, M as ModelSelection, D as SDKUserMessage, F as SendOptions, b as Run, a as McpServerConfig } from './run-
|
|
1
|
+
import { C as CustomTool, M as ModelSelection, D as SDKUserMessage, F as SendOptions, b as Run, a as McpServerConfig } from './run-ekGKZlmg.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Fork primitive public type contracts (T1.2, ADRs D110-D114).
|
|
@@ -559,6 +559,14 @@ interface BudgetTracker {
|
|
|
559
559
|
check(): BudgetCheck;
|
|
560
560
|
/** Snapshot of accumulated totals (for telemetry / final reporting). */
|
|
561
561
|
getTotal(): BudgetTotal;
|
|
562
|
+
/**
|
|
563
|
+
* Advance the iteration counter by one. Called by the agent loop ONCE per
|
|
564
|
+
* completed turn (M1-1) so that trackers which gate on `maxIterations`
|
|
565
|
+
* (e.g. `createCounterBudgetTracker`) actually halt. OPTIONAL: trackers that
|
|
566
|
+
* only gate on tokens/USD omit it and the loop no-ops via optional chaining.
|
|
567
|
+
* MUST be synchronous and non-throwing.
|
|
568
|
+
*/
|
|
569
|
+
nextIteration?(): void;
|
|
562
570
|
}
|
|
563
571
|
|
|
564
572
|
/**
|
package/dist/cron.cjs
CHANGED
|
@@ -4320,8 +4320,7 @@ var FixtureRunBase = class {
|
|
|
4320
4320
|
if (status === "error" && this.script.errorDetail !== void 0) {
|
|
4321
4321
|
base.error = this.script.errorDetail;
|
|
4322
4322
|
}
|
|
4323
|
-
|
|
4324
|
-
if (this.script.cost !== void 0) base.cost = this.script.cost;
|
|
4323
|
+
applyScriptMetrics(base, this.script);
|
|
4325
4324
|
return this.extendRunResult(applyExtraRunFields(base, this.script));
|
|
4326
4325
|
}
|
|
4327
4326
|
/** Subclasses override to attach runtime-specific fields (e.g. cloud git info). */
|
|
@@ -4355,6 +4354,11 @@ function makeNotifier() {
|
|
|
4355
4354
|
});
|
|
4356
4355
|
return { promise, resolve: resolve3 };
|
|
4357
4356
|
}
|
|
4357
|
+
function applyScriptMetrics(base, script) {
|
|
4358
|
+
if (script.usage !== void 0) base.usage = script.usage;
|
|
4359
|
+
if (script.cost !== void 0) base.cost = script.cost;
|
|
4360
|
+
if (script.stoppedAtIterationLimit === true) base.stoppedAtIterationLimit = true;
|
|
4361
|
+
}
|
|
4358
4362
|
|
|
4359
4363
|
// src/internal/runtime/cloud/cloud-run.ts
|
|
4360
4364
|
function createCloudRun(options) {
|
|
@@ -7987,6 +7991,9 @@ var LocalRun = class extends FixtureRunBase {
|
|
|
7987
7991
|
}
|
|
7988
7992
|
};
|
|
7989
7993
|
|
|
7994
|
+
// src/internal/runtime/local-agent/real-local-run.ts
|
|
7995
|
+
init_errors();
|
|
7996
|
+
|
|
7990
7997
|
// src/internal/runtime/budget/budget.ts
|
|
7991
7998
|
var IterationBudget = class {
|
|
7992
7999
|
#remaining;
|
|
@@ -9211,6 +9218,7 @@ async function runAgentLoop(inputs) {
|
|
|
9211
9218
|
const ctx = await initLoopContext(inputs);
|
|
9212
9219
|
ctxRef = ctx;
|
|
9213
9220
|
const budget = inputs.budget ?? new IterationBudget({ maxIterations: inputs.maxIterations ?? 8 });
|
|
9221
|
+
let lastTurnDecision;
|
|
9214
9222
|
while (budget.shouldContinue()) {
|
|
9215
9223
|
if (inputs.budgetTracker !== void 0) {
|
|
9216
9224
|
const decision2 = evaluateBudgetGate(inputs.budgetTracker);
|
|
@@ -9219,18 +9227,26 @@ async function runAgentLoop(inputs) {
|
|
|
9219
9227
|
if (decision2.detail !== void 0) {
|
|
9220
9228
|
ctx.error = { message: decision2.detail, code: decision2.reason ?? "budget" };
|
|
9221
9229
|
}
|
|
9230
|
+
if (decision2.reason === "iteration_limit") {
|
|
9231
|
+
ctx.stoppedAtIterationLimit = true;
|
|
9232
|
+
}
|
|
9222
9233
|
break;
|
|
9223
9234
|
}
|
|
9224
9235
|
}
|
|
9225
9236
|
const usingGrace = budget.remaining <= 0 && !budget.graceCallUsed;
|
|
9226
9237
|
if (usingGrace) budget.useGraceCall();
|
|
9227
9238
|
const decision = await runIteration(inputs, ctx);
|
|
9239
|
+
lastTurnDecision = decision;
|
|
9228
9240
|
if (decision === "done") break;
|
|
9229
9241
|
if (decision === "error") {
|
|
9230
9242
|
ctx.finalStatus = "error";
|
|
9231
9243
|
break;
|
|
9232
9244
|
}
|
|
9233
9245
|
budget.consume();
|
|
9246
|
+
inputs.budgetTracker?.nextIteration?.();
|
|
9247
|
+
}
|
|
9248
|
+
if (lastTurnDecision === "continue" && budget.shouldContinue() === false) {
|
|
9249
|
+
ctx.stoppedAtIterationLimit = true;
|
|
9234
9250
|
}
|
|
9235
9251
|
if (budget.shouldContinue() === false && ctx.finalStatus === "finished" && ctx.finalText === "") {
|
|
9236
9252
|
ctx.finalStatus = "error";
|
|
@@ -9261,7 +9277,8 @@ async function runAgentLoop(inputs) {
|
|
|
9261
9277
|
conversation: ctx.conversation,
|
|
9262
9278
|
...usage !== void 0 ? { usage } : {},
|
|
9263
9279
|
...cost !== void 0 ? { cost } : {},
|
|
9264
|
-
...ctx.error !== void 0 ? { error: ctx.error } : {}
|
|
9280
|
+
...ctx.error !== void 0 ? { error: ctx.error } : {},
|
|
9281
|
+
...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {}
|
|
9265
9282
|
};
|
|
9266
9283
|
} finally {
|
|
9267
9284
|
if (ctxRef !== void 0 && ctxRef.memoryProviderHandle !== void 0 && inputs.memoryProvider !== void 0) {
|
|
@@ -11680,6 +11697,13 @@ function resolveRunProvider(options) {
|
|
|
11680
11697
|
return { primary, effectiveModelId };
|
|
11681
11698
|
}
|
|
11682
11699
|
function buildLoopInputs(options, runId, userText) {
|
|
11700
|
+
const maxIterations = options.sendOptions.maxIterations;
|
|
11701
|
+
if (maxIterations !== void 0 && (!Number.isInteger(maxIterations) || maxIterations < 1)) {
|
|
11702
|
+
throw new ConfigurationError(
|
|
11703
|
+
`SendOptions.maxIterations must be a positive integer, got ${maxIterations}`,
|
|
11704
|
+
{ code: "invalid_max_iterations" }
|
|
11705
|
+
);
|
|
11706
|
+
}
|
|
11683
11707
|
const { primary, effectiveModelId } = resolveRunProvider(options);
|
|
11684
11708
|
const fallback = options.agentOptions.providers?.fallback;
|
|
11685
11709
|
const apiKeys = options.agentOptions.providers?.apiKeys;
|
|
@@ -11718,6 +11742,9 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
11718
11742
|
// D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
|
|
11719
11743
|
// can attach it to the LLM `fetch({ signal })` call.
|
|
11720
11744
|
...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
|
|
11745
|
+
// M1-2: per-send iteration ceiling (validated above). The loop reads
|
|
11746
|
+
// inputs.maxIterations (default 8 when unset).
|
|
11747
|
+
...maxIterations !== void 0 ? { maxIterations } : {},
|
|
11721
11748
|
// D315-D317 — tool lifecycle hooks (cost tracking + audit + retry/alert)
|
|
11722
11749
|
...options.agentOptions.onToolStart !== void 0 ? { onToolStart: options.agentOptions.onToolStart } : {},
|
|
11723
11750
|
...options.agentOptions.onToolEnd !== void 0 ? { onToolEnd: options.agentOptions.onToolEnd } : {},
|
|
@@ -11849,6 +11876,7 @@ var RealLocalRun = class extends FixtureRunBase {
|
|
|
11849
11876
|
if (output.result.length > 0) this.script.result = output.result;
|
|
11850
11877
|
if (output.usage !== void 0) this.script.usage = output.usage;
|
|
11851
11878
|
if (output.cost !== void 0) this.script.cost = output.cost;
|
|
11879
|
+
if (output.stoppedAtIterationLimit === true) this.script.stoppedAtIterationLimit = true;
|
|
11852
11880
|
if (output.error !== void 0 && this.script.errorDetail === void 0) {
|
|
11853
11881
|
this.script.errorDetail = {
|
|
11854
11882
|
message: output.error.message,
|