@theokit/sdk 3.2.2 → 3.2.3

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
 
@@ -10162,6 +10173,8 @@ function parseRetryAfter(headers) {
10162
10173
  if (raw === null) return void 0;
10163
10174
  const n = Number(raw);
10164
10175
  if (Number.isFinite(n) && n >= 0) return Math.ceil(n);
10176
+ const dateMs = Date.parse(raw);
10177
+ if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1e3));
10165
10178
  return void 0;
10166
10179
  }
10167
10180
  function truncateRaw(body) {
@@ -10482,6 +10495,7 @@ function buildAnthropicBody(request) {
10482
10495
  var AnthropicClient, AnthropicStreamAccumulator;
10483
10496
  var init_anthropic3 = __esm({
10484
10497
  "src/internal/llm/anthropic.ts"() {
10498
+ init_errors();
10485
10499
  init_anthropic2();
10486
10500
  init_anthropic_shared();
10487
10501
  init_finish();
@@ -10535,12 +10549,23 @@ var init_anthropic3 = __esm({
10535
10549
  const events = accumulator.consume(parsed);
10536
10550
  for (const event of events) yield event;
10537
10551
  }
10552
+ if (!accumulator.finishReasonSeen) {
10553
+ throw new NetworkError("Anthropic SSE stream truncated (no stop_reason)", {
10554
+ code: "stream_truncated"
10555
+ });
10556
+ }
10538
10557
  return accumulator.finish();
10539
10558
  }
10540
10559
  };
10541
10560
  AnthropicStreamAccumulator = class {
10542
10561
  text = "";
10543
10562
  stopReason = "end_turn";
10563
+ /**
10564
+ * M2 #61 — whether a `message_delta` carrying a real `stop_reason` was seen.
10565
+ * A stream that closes before it is a truncation (server FIN / proxy hiccup),
10566
+ * not a clean `end_turn` — the caller throws `stream_truncated` on `false`.
10567
+ */
10568
+ sawStopReason = false;
10544
10569
  inputTokens;
10545
10570
  outputTokens;
10546
10571
  cacheReadTokens;
@@ -10587,6 +10612,9 @@ var init_anthropic3 = __esm({
10587
10612
  * spinning the SSE parser.
10588
10613
  */
10589
10614
  handleMessageDelta(md) {
10615
+ if (md.delta.stop_reason !== void 0 && md.delta.stop_reason !== null) {
10616
+ this.sawStopReason = true;
10617
+ }
10590
10618
  this.stopReason = mapAnthropicStopReason(md.delta.stop_reason);
10591
10619
  if (md.usage?.input_tokens !== void 0) this.inputTokens = md.usage.input_tokens;
10592
10620
  if (md.usage?.output_tokens !== void 0) this.outputTokens = md.usage.output_tokens;
@@ -10597,6 +10625,10 @@ var init_anthropic3 = __esm({
10597
10625
  this.cacheReadTokens = md.usage.cache_read_input_tokens;
10598
10626
  }
10599
10627
  }
10628
+ /** M2 #61 — whether the terminal `message_delta` (stop_reason) was seen. */
10629
+ get finishReasonSeen() {
10630
+ return this.sawStopReason;
10631
+ }
10600
10632
  finish() {
10601
10633
  const toolCalls = [];
10602
10634
  for (const [index, tool] of this.toolCalls.entries()) {
@@ -12830,7 +12862,6 @@ var init_client = __esm({
12830
12862
  // concurrent request so parallel tool dispatch after a drop awaits one handshake
12831
12863
  // instead of racing (or spuriously failing with mcp_not_init).
12832
12864
  dropped = false;
12833
- reconnectAttempts = 0;
12834
12865
  reconnectPromise;
12835
12866
  get timeoutMs() {
12836
12867
  return this.config.requestTimeoutMs ?? DEFAULT_MCP_TIMEOUT_MS;
@@ -12883,15 +12914,22 @@ var init_client = __esm({
12883
12914
  return this.reconnectPromise;
12884
12915
  }
12885
12916
  async reconnect() {
12886
- if (this.reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
12887
- throw new NetworkError(`MCP ${this.name} reconnect exhausted`, { code: "mcp_disconnected" });
12917
+ let lastErr;
12918
+ for (let attempt = 0; attempt < MAX_RECONNECT_ATTEMPTS; attempt += 1) {
12919
+ await reconnectDelay(attempt);
12920
+ this.spawnChild();
12921
+ try {
12922
+ await super.initialize();
12923
+ this.dropped = false;
12924
+ return;
12925
+ } catch (err) {
12926
+ lastErr = err;
12927
+ }
12888
12928
  }
12889
- await reconnectDelay(this.reconnectAttempts);
12890
- this.reconnectAttempts += 1;
12891
- this.spawnChild();
12892
- await super.initialize();
12893
- this.dropped = false;
12894
- this.reconnectAttempts = 0;
12929
+ throw new NetworkError(`MCP ${this.name} reconnect exhausted`, {
12930
+ code: "mcp_disconnected",
12931
+ ...lastErr instanceof Error ? { cause: lastErr } : {}
12932
+ });
12895
12933
  }
12896
12934
  async close() {
12897
12935
  this.rejectAllPending(new NetworkError(`MCP ${this.name} closed`, { code: "mcp_closed" }));