@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/a2a/index.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
 
@@ -8831,7 +8842,9 @@ async function vetoFromPluginPreHook(inputs, call, callId, events) {
8831
8842
  name: call.name,
8832
8843
  args: call.input,
8833
8844
  agentId: inputs.agentId,
8834
- runId: inputs.runId
8845
+ runId: inputs.runId,
8846
+ // SE1 — thread the run's permission mode so a PermissionPlugin gates per-run.
8847
+ ...inputs.permissionMode !== void 0 ? { permissionMode: inputs.permissionMode } : {}
8835
8848
  });
8836
8849
  if (pluginVeto === void 0) return void 0;
8837
8850
  emitRunEvent(inputs.runEventSink, {
@@ -10162,6 +10175,8 @@ function parseRetryAfter(headers) {
10162
10175
  if (raw === null) return void 0;
10163
10176
  const n = Number(raw);
10164
10177
  if (Number.isFinite(n) && n >= 0) return Math.ceil(n);
10178
+ const dateMs = Date.parse(raw);
10179
+ if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1e3));
10165
10180
  return void 0;
10166
10181
  }
10167
10182
  function truncateRaw(body) {
@@ -10482,6 +10497,7 @@ function buildAnthropicBody(request) {
10482
10497
  var AnthropicClient, AnthropicStreamAccumulator;
10483
10498
  var init_anthropic3 = __esm({
10484
10499
  "src/internal/llm/anthropic.ts"() {
10500
+ init_errors();
10485
10501
  init_anthropic2();
10486
10502
  init_anthropic_shared();
10487
10503
  init_finish();
@@ -10535,12 +10551,23 @@ var init_anthropic3 = __esm({
10535
10551
  const events = accumulator.consume(parsed);
10536
10552
  for (const event of events) yield event;
10537
10553
  }
10554
+ if (!accumulator.finishReasonSeen) {
10555
+ throw new NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
10556
+ code: "stream_truncated"
10557
+ });
10558
+ }
10538
10559
  return accumulator.finish();
10539
10560
  }
10540
10561
  };
10541
10562
  AnthropicStreamAccumulator = class {
10542
10563
  text = "";
10543
10564
  stopReason = "end_turn";
10565
+ /**
10566
+ * M2 #61 — whether a `message_delta` carrying a real `stop_reason` was seen.
10567
+ * A stream that closes before it is a truncation (server FIN / proxy hiccup),
10568
+ * not a clean `end_turn` — the caller throws `stream_truncated` on `false`.
10569
+ */
10570
+ sawStopReason = false;
10544
10571
  inputTokens;
10545
10572
  outputTokens;
10546
10573
  cacheReadTokens;
@@ -10587,6 +10614,9 @@ var init_anthropic3 = __esm({
10587
10614
  * spinning the SSE parser.
10588
10615
  */
10589
10616
  handleMessageDelta(md) {
10617
+ if (md.delta.stop_reason !== void 0 && md.delta.stop_reason !== null) {
10618
+ this.sawStopReason = true;
10619
+ }
10590
10620
  this.stopReason = mapAnthropicStopReason(md.delta.stop_reason);
10591
10621
  if (md.usage?.input_tokens !== void 0) this.inputTokens = md.usage.input_tokens;
10592
10622
  if (md.usage?.output_tokens !== void 0) this.outputTokens = md.usage.output_tokens;
@@ -10597,6 +10627,10 @@ var init_anthropic3 = __esm({
10597
10627
  this.cacheReadTokens = md.usage.cache_read_input_tokens;
10598
10628
  }
10599
10629
  }
10630
+ /** M2 #61 — whether the terminal `message_delta` (stop_reason) was seen. */
10631
+ get finishReasonSeen() {
10632
+ return this.sawStopReason;
10633
+ }
10600
10634
  finish() {
10601
10635
  const toolCalls = [];
10602
10636
  for (const [index, tool] of this.toolCalls.entries()) {
@@ -12830,7 +12864,6 @@ var init_client = __esm({
12830
12864
  // concurrent request so parallel tool dispatch after a drop awaits one handshake
12831
12865
  // instead of racing (or spuriously failing with mcp_not_init).
12832
12866
  dropped = false;
12833
- reconnectAttempts = 0;
12834
12867
  reconnectPromise;
12835
12868
  get timeoutMs() {
12836
12869
  return this.config.requestTimeoutMs ?? DEFAULT_MCP_TIMEOUT_MS;
@@ -12883,15 +12916,22 @@ var init_client = __esm({
12883
12916
  return this.reconnectPromise;
12884
12917
  }
12885
12918
  async reconnect() {
12886
- if (this.reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
12887
- throw new NetworkError(`MCP ${this.name} reconnect exhausted`, { code: "mcp_disconnected" });
12919
+ let lastErr;
12920
+ for (let attempt = 0; attempt < MAX_RECONNECT_ATTEMPTS; attempt += 1) {
12921
+ await reconnectDelay(attempt);
12922
+ this.spawnChild();
12923
+ try {
12924
+ await super.initialize();
12925
+ this.dropped = false;
12926
+ return;
12927
+ } catch (err) {
12928
+ lastErr = err;
12929
+ }
12888
12930
  }
12889
- await reconnectDelay(this.reconnectAttempts);
12890
- this.reconnectAttempts += 1;
12891
- this.spawnChild();
12892
- await super.initialize();
12893
- this.dropped = false;
12894
- this.reconnectAttempts = 0;
12931
+ throw new NetworkError(`MCP ${this.name} reconnect exhausted`, {
12932
+ code: "mcp_disconnected",
12933
+ ...lastErr instanceof Error ? { cause: lastErr } : {}
12934
+ });
12895
12935
  }
12896
12936
  async close() {
12897
12937
  this.rejectAllPending(new NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));
@@ -13215,6 +13255,10 @@ function buildLoopInputs(options, runId, userText) {
13215
13255
  ...options.onDelta !== void 0 ? { onDelta: options.onDelta } : {},
13216
13256
  ...options.sendOptions.toolChoice !== void 0 ? { toolChoice: options.sendOptions.toolChoice } : {},
13217
13257
  ...options.sendOptions.activeTools !== void 0 ? { activeTools: options.sendOptions.activeTools } : {},
13258
+ // SE1 — resolve the run's permission mode: per-send wins over creation-time.
13259
+ ...(options.sendOptions.permissionMode ?? options.agentOptions.permissionMode) !== void 0 ? {
13260
+ permissionMode: options.sendOptions.permissionMode ?? options.agentOptions.permissionMode
13261
+ } : {},
13218
13262
  ...options.priorMessages !== void 0 ? { priorMessages: options.priorMessages } : {},
13219
13263
  ...options.memoryTools !== void 0 && options.memoryTools.length > 0 ? { memoryTools: options.memoryTools } : {},
13220
13264
  ...buildCustomToolsInput(