@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.
@@ -1,4 +1,4 @@
1
- import { H as RunOperation } from './run-CrHz9BAP.js';
1
+ import { Q as RunOperation } from './run-CL5Rw6a5.js';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
@@ -1,4 +1,4 @@
1
- import { H as RunOperation } from './run-CrHz9BAP.cjs';
1
+ import { Q as RunOperation } from './run-CL5Rw6a5.cjs';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
package/dist/errors.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, m as ErrorCode, E 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-jxK4yfp5.cjs';
2
- import './run-CrHz9BAP.cjs';
1
+ export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, m as ErrorCode, E 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-CIDoPGa7.cjs';
2
+ import './run-CL5Rw6a5.cjs';
3
3
  import 'zod';
package/dist/eval.cjs CHANGED
@@ -5159,12 +5159,23 @@ var init_objective_coerce = __esm({
5159
5159
  // src/internal/persistence/pagination.ts
5160
5160
  function paginate(items, opts) {
5161
5161
  if (opts === void 0 || opts.offset === void 0 && opts.limit === void 0) return items;
5162
- const start = Math.max(0, opts.offset ?? 0);
5163
- const end = opts.limit === void 0 ? items.length : start + Math.max(0, opts.limit);
5162
+ const start = opts.offset === void 0 ? 0 : requireNonNegativeInt(opts.offset, "offset");
5163
+ const limit = opts.limit === void 0 ? void 0 : requireNonNegativeInt(opts.limit, "limit");
5164
+ const end = limit === void 0 ? items.length : start + limit;
5164
5165
  return items.slice(start, end);
5165
5166
  }
5167
+ function requireNonNegativeInt(value, field) {
5168
+ if (!Number.isInteger(value) || value < 0) {
5169
+ throw new ConfigurationError(
5170
+ `Invalid pagination ${field}: expected a non-negative integer, got ${value}`,
5171
+ { code: "pagination_invalid" }
5172
+ );
5173
+ }
5174
+ return value;
5175
+ }
5166
5176
  var init_pagination = __esm({
5167
5177
  "src/internal/persistence/pagination.ts"() {
5178
+ init_errors();
5168
5179
  }
5169
5180
  });
5170
5181
 
@@ -8991,7 +9002,9 @@ async function vetoFromPluginPreHook(inputs, call, callId, events) {
8991
9002
  name: call.name,
8992
9003
  args: call.input,
8993
9004
  agentId: inputs.agentId,
8994
- runId: inputs.runId
9005
+ runId: inputs.runId,
9006
+ // SE1 — thread the run's permission mode so a PermissionPlugin gates per-run.
9007
+ ...inputs.permissionMode !== void 0 ? { permissionMode: inputs.permissionMode } : {}
8995
9008
  });
8996
9009
  if (pluginVeto === void 0) return void 0;
8997
9010
  emitRunEvent(inputs.runEventSink, {
@@ -10322,6 +10335,8 @@ function parseRetryAfter(headers) {
10322
10335
  if (raw === null) return void 0;
10323
10336
  const n = Number(raw);
10324
10337
  if (Number.isFinite(n) && n >= 0) return Math.ceil(n);
10338
+ const dateMs = Date.parse(raw);
10339
+ if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1e3));
10325
10340
  return void 0;
10326
10341
  }
10327
10342
  function truncateRaw(body) {
@@ -10642,6 +10657,7 @@ function buildAnthropicBody(request) {
10642
10657
  var AnthropicClient, AnthropicStreamAccumulator;
10643
10658
  var init_anthropic3 = __esm({
10644
10659
  "src/internal/llm/anthropic.ts"() {
10660
+ init_errors();
10645
10661
  init_anthropic2();
10646
10662
  init_anthropic_shared();
10647
10663
  init_finish();
@@ -10695,12 +10711,23 @@ var init_anthropic3 = __esm({
10695
10711
  const events = accumulator.consume(parsed);
10696
10712
  for (const event of events) yield event;
10697
10713
  }
10714
+ if (!accumulator.finishReasonSeen) {
10715
+ throw new NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
10716
+ code: "stream_truncated"
10717
+ });
10718
+ }
10698
10719
  return accumulator.finish();
10699
10720
  }
10700
10721
  };
10701
10722
  AnthropicStreamAccumulator = class {
10702
10723
  text = "";
10703
10724
  stopReason = "end_turn";
10725
+ /**
10726
+ * M2 #61 — whether a `message_delta` carrying a real `stop_reason` was seen.
10727
+ * A stream that closes before it is a truncation (server FIN / proxy hiccup),
10728
+ * not a clean `end_turn` — the caller throws `stream_truncated` on `false`.
10729
+ */
10730
+ sawStopReason = false;
10704
10731
  inputTokens;
10705
10732
  outputTokens;
10706
10733
  cacheReadTokens;
@@ -10747,6 +10774,9 @@ var init_anthropic3 = __esm({
10747
10774
  * spinning the SSE parser.
10748
10775
  */
10749
10776
  handleMessageDelta(md) {
10777
+ if (md.delta.stop_reason !== void 0 && md.delta.stop_reason !== null) {
10778
+ this.sawStopReason = true;
10779
+ }
10750
10780
  this.stopReason = mapAnthropicStopReason(md.delta.stop_reason);
10751
10781
  if (md.usage?.input_tokens !== void 0) this.inputTokens = md.usage.input_tokens;
10752
10782
  if (md.usage?.output_tokens !== void 0) this.outputTokens = md.usage.output_tokens;
@@ -10757,6 +10787,10 @@ var init_anthropic3 = __esm({
10757
10787
  this.cacheReadTokens = md.usage.cache_read_input_tokens;
10758
10788
  }
10759
10789
  }
10790
+ /** M2 #61 — whether the terminal `message_delta` (stop_reason) was seen. */
10791
+ get finishReasonSeen() {
10792
+ return this.sawStopReason;
10793
+ }
10760
10794
  finish() {
10761
10795
  const toolCalls = [];
10762
10796
  for (const [index, tool] of this.toolCalls.entries()) {
@@ -12990,7 +13024,6 @@ var init_client = __esm({
12990
13024
  // concurrent request so parallel tool dispatch after a drop awaits one handshake
12991
13025
  // instead of racing (or spuriously failing with mcp_not_init).
12992
13026
  dropped = false;
12993
- reconnectAttempts = 0;
12994
13027
  reconnectPromise;
12995
13028
  get timeoutMs() {
12996
13029
  return this.config.requestTimeoutMs ?? DEFAULT_MCP_TIMEOUT_MS;
@@ -13043,15 +13076,22 @@ var init_client = __esm({
13043
13076
  return this.reconnectPromise;
13044
13077
  }
13045
13078
  async reconnect() {
13046
- if (this.reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
13047
- throw new NetworkError(`MCP ${this.name} reconnect exhausted`, { code: "mcp_disconnected" });
13079
+ let lastErr;
13080
+ for (let attempt = 0; attempt < MAX_RECONNECT_ATTEMPTS; attempt += 1) {
13081
+ await reconnectDelay(attempt);
13082
+ this.spawnChild();
13083
+ try {
13084
+ await super.initialize();
13085
+ this.dropped = false;
13086
+ return;
13087
+ } catch (err) {
13088
+ lastErr = err;
13089
+ }
13048
13090
  }
13049
- await reconnectDelay(this.reconnectAttempts);
13050
- this.reconnectAttempts += 1;
13051
- this.spawnChild();
13052
- await super.initialize();
13053
- this.dropped = false;
13054
- this.reconnectAttempts = 0;
13091
+ throw new NetworkError(`MCP ${this.name} reconnect exhausted`, {
13092
+ code: "mcp_disconnected",
13093
+ ...lastErr instanceof Error ? { cause: lastErr } : {}
13094
+ });
13055
13095
  }
13056
13096
  async close() {
13057
13097
  this.rejectAllPending(new NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));
@@ -13375,6 +13415,10 @@ function buildLoopInputs(options, runId, userText) {
13375
13415
  ...options.onDelta !== void 0 ? { onDelta: options.onDelta } : {},
13376
13416
  ...options.sendOptions.toolChoice !== void 0 ? { toolChoice: options.sendOptions.toolChoice } : {},
13377
13417
  ...options.sendOptions.activeTools !== void 0 ? { activeTools: options.sendOptions.activeTools } : {},
13418
+ // SE1 — resolve the run's permission mode: per-send wins over creation-time.
13419
+ ...(options.sendOptions.permissionMode ?? options.agentOptions.permissionMode) !== void 0 ? {
13420
+ permissionMode: options.sendOptions.permissionMode ?? options.agentOptions.permissionMode
13421
+ } : {},
13378
13422
  ...options.priorMessages !== void 0 ? { priorMessages: options.priorMessages } : {},
13379
13423
  ...options.memoryTools !== void 0 && options.memoryTools.length > 0 ? { memoryTools: options.memoryTools } : {},
13380
13424
  ...buildCustomToolsInput(