@theokit/sdk 3.2.2 → 3.3.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
@@ -5156,12 +5156,23 @@ var init_objective_coerce = __esm({
5156
5156
  // src/internal/persistence/pagination.ts
5157
5157
  function paginate(items, opts) {
5158
5158
  if (opts === void 0 || opts.offset === void 0 && opts.limit === void 0) return items;
5159
- const start = Math.max(0, opts.offset ?? 0);
5160
- const end = opts.limit === void 0 ? items.length : start + Math.max(0, opts.limit);
5159
+ const start = opts.offset === void 0 ? 0 : requireNonNegativeInt(opts.offset, "offset");
5160
+ const limit = opts.limit === void 0 ? void 0 : requireNonNegativeInt(opts.limit, "limit");
5161
+ const end = limit === void 0 ? items.length : start + limit;
5161
5162
  return items.slice(start, end);
5162
5163
  }
5164
+ function requireNonNegativeInt(value, field) {
5165
+ if (!Number.isInteger(value) || value < 0) {
5166
+ throw new ConfigurationError(
5167
+ `Invalid pagination ${field}: expected a non-negative integer, got ${value}`,
5168
+ { code: "pagination_invalid" }
5169
+ );
5170
+ }
5171
+ return value;
5172
+ }
5163
5173
  var init_pagination = __esm({
5164
5174
  "src/internal/persistence/pagination.ts"() {
5175
+ init_errors();
5165
5176
  }
5166
5177
  });
5167
5178
 
@@ -8988,7 +8999,9 @@ async function vetoFromPluginPreHook(inputs, call, callId, events) {
8988
8999
  name: call.name,
8989
9000
  args: call.input,
8990
9001
  agentId: inputs.agentId,
8991
- runId: inputs.runId
9002
+ runId: inputs.runId,
9003
+ // SE1 — thread the run's permission mode so a PermissionPlugin gates per-run.
9004
+ ...inputs.permissionMode !== void 0 ? { permissionMode: inputs.permissionMode } : {}
8992
9005
  });
8993
9006
  if (pluginVeto === void 0) return void 0;
8994
9007
  emitRunEvent(inputs.runEventSink, {
@@ -10319,6 +10332,8 @@ function parseRetryAfter(headers) {
10319
10332
  if (raw === null) return void 0;
10320
10333
  const n = Number(raw);
10321
10334
  if (Number.isFinite(n) && n >= 0) return Math.ceil(n);
10335
+ const dateMs = Date.parse(raw);
10336
+ if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1e3));
10322
10337
  return void 0;
10323
10338
  }
10324
10339
  function truncateRaw(body) {
@@ -10639,6 +10654,7 @@ function buildAnthropicBody(request) {
10639
10654
  var AnthropicClient, AnthropicStreamAccumulator;
10640
10655
  var init_anthropic3 = __esm({
10641
10656
  "src/internal/llm/anthropic.ts"() {
10657
+ init_errors();
10642
10658
  init_anthropic2();
10643
10659
  init_anthropic_shared();
10644
10660
  init_finish();
@@ -10692,12 +10708,23 @@ var init_anthropic3 = __esm({
10692
10708
  const events = accumulator.consume(parsed);
10693
10709
  for (const event of events) yield event;
10694
10710
  }
10711
+ if (!accumulator.finishReasonSeen) {
10712
+ throw new NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
10713
+ code: "stream_truncated"
10714
+ });
10715
+ }
10695
10716
  return accumulator.finish();
10696
10717
  }
10697
10718
  };
10698
10719
  AnthropicStreamAccumulator = class {
10699
10720
  text = "";
10700
10721
  stopReason = "end_turn";
10722
+ /**
10723
+ * M2 #61 — whether a `message_delta` carrying a real `stop_reason` was seen.
10724
+ * A stream that closes before it is a truncation (server FIN / proxy hiccup),
10725
+ * not a clean `end_turn` — the caller throws `stream_truncated` on `false`.
10726
+ */
10727
+ sawStopReason = false;
10701
10728
  inputTokens;
10702
10729
  outputTokens;
10703
10730
  cacheReadTokens;
@@ -10744,6 +10771,9 @@ var init_anthropic3 = __esm({
10744
10771
  * spinning the SSE parser.
10745
10772
  */
10746
10773
  handleMessageDelta(md) {
10774
+ if (md.delta.stop_reason !== void 0 && md.delta.stop_reason !== null) {
10775
+ this.sawStopReason = true;
10776
+ }
10747
10777
  this.stopReason = mapAnthropicStopReason(md.delta.stop_reason);
10748
10778
  if (md.usage?.input_tokens !== void 0) this.inputTokens = md.usage.input_tokens;
10749
10779
  if (md.usage?.output_tokens !== void 0) this.outputTokens = md.usage.output_tokens;
@@ -10754,6 +10784,10 @@ var init_anthropic3 = __esm({
10754
10784
  this.cacheReadTokens = md.usage.cache_read_input_tokens;
10755
10785
  }
10756
10786
  }
10787
+ /** M2 #61 — whether the terminal `message_delta` (stop_reason) was seen. */
10788
+ get finishReasonSeen() {
10789
+ return this.sawStopReason;
10790
+ }
10757
10791
  finish() {
10758
10792
  const toolCalls = [];
10759
10793
  for (const [index, tool] of this.toolCalls.entries()) {
@@ -12987,7 +13021,6 @@ var init_client = __esm({
12987
13021
  // concurrent request so parallel tool dispatch after a drop awaits one handshake
12988
13022
  // instead of racing (or spuriously failing with mcp_not_init).
12989
13023
  dropped = false;
12990
- reconnectAttempts = 0;
12991
13024
  reconnectPromise;
12992
13025
  get timeoutMs() {
12993
13026
  return this.config.requestTimeoutMs ?? DEFAULT_MCP_TIMEOUT_MS;
@@ -13040,15 +13073,22 @@ var init_client = __esm({
13040
13073
  return this.reconnectPromise;
13041
13074
  }
13042
13075
  async reconnect() {
13043
- if (this.reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
13044
- throw new NetworkError(`MCP ${this.name} reconnect exhausted`, { code: "mcp_disconnected" });
13076
+ let lastErr;
13077
+ for (let attempt = 0; attempt < MAX_RECONNECT_ATTEMPTS; attempt += 1) {
13078
+ await reconnectDelay(attempt);
13079
+ this.spawnChild();
13080
+ try {
13081
+ await super.initialize();
13082
+ this.dropped = false;
13083
+ return;
13084
+ } catch (err) {
13085
+ lastErr = err;
13086
+ }
13045
13087
  }
13046
- await reconnectDelay(this.reconnectAttempts);
13047
- this.reconnectAttempts += 1;
13048
- this.spawnChild();
13049
- await super.initialize();
13050
- this.dropped = false;
13051
- this.reconnectAttempts = 0;
13088
+ throw new NetworkError(`MCP ${this.name} reconnect exhausted`, {
13089
+ code: "mcp_disconnected",
13090
+ ...lastErr instanceof Error ? { cause: lastErr } : {}
13091
+ });
13052
13092
  }
13053
13093
  async close() {
13054
13094
  this.rejectAllPending(new NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));
@@ -13372,6 +13412,10 @@ function buildLoopInputs(options, runId, userText) {
13372
13412
  ...options.onDelta !== void 0 ? { onDelta: options.onDelta } : {},
13373
13413
  ...options.sendOptions.toolChoice !== void 0 ? { toolChoice: options.sendOptions.toolChoice } : {},
13374
13414
  ...options.sendOptions.activeTools !== void 0 ? { activeTools: options.sendOptions.activeTools } : {},
13415
+ // SE1 — resolve the run's permission mode: per-send wins over creation-time.
13416
+ ...(options.sendOptions.permissionMode ?? options.agentOptions.permissionMode) !== void 0 ? {
13417
+ permissionMode: options.sendOptions.permissionMode ?? options.agentOptions.permissionMode
13418
+ } : {},
13375
13419
  ...options.priorMessages !== void 0 ? { priorMessages: options.priorMessages } : {},
13376
13420
  ...options.memoryTools !== void 0 && options.memoryTools.length > 0 ? { memoryTools: options.memoryTools } : {},
13377
13421
  ...buildCustomToolsInput(