agents 0.16.1 → 0.16.2

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.
@@ -821,6 +821,14 @@ declare class MCPClientConnection {
821
821
  instructions?: string;
822
822
  tools: Tool$1[];
823
823
  private _transport?;
824
+ /**
825
+ * Transport that received the 401 during the initial connect attempt.
826
+ * Kept so finishAuth() runs on the transport that captured the resource
827
+ * metadata URL from the WWW-Authenticate header — a fresh transport would
828
+ * rediscover from defaults and exchange the code at the wrong token
829
+ * endpoint when the authorization server is not at the default location.
830
+ */
831
+ private _pendingAuthTransport?;
824
832
  prompts: Prompt[];
825
833
  resources: Resource[];
826
834
  resourceTemplates: ResourceTemplate[];
@@ -4847,4 +4855,4 @@ export {
4847
4855
  MCPServer as z,
4848
4856
  WorkerTransport as zt
4849
4857
  };
4850
- //# sourceMappingURL=agent-tool-types-NofdbL9X.d.ts.map
4858
+ //# sourceMappingURL=agent-tool-types-CTw3UJUP.d.ts.map
@@ -16,7 +16,7 @@ import {
16
16
  s as AgentToolInterruptedReason,
17
17
  t as AgentToolChildAdapter,
18
18
  u as AgentToolRunInspection
19
- } from "./agent-tool-types-NofdbL9X.js";
19
+ } from "./agent-tool-types-CTw3UJUP.js";
20
20
  export {
21
21
  AgentToolChildAdapter,
22
22
  AgentToolDisplayMetadata,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  a as AgentToolEventState,
3
3
  i as AgentToolEventMessage
4
- } from "./agent-tool-types-NofdbL9X.js";
4
+ } from "./agent-tool-types-CTw3UJUP.js";
5
5
 
6
6
  //#region src/chat/agent-tools.d.ts
7
7
  declare function createAgentToolEventState(): AgentToolEventState;
@@ -11,4 +11,4 @@ declare function applyAgentToolEvent(
11
11
  ): AgentToolEventState;
12
12
  //#endregion
13
13
  export { createAgentToolEventState as n, applyAgentToolEvent as t };
14
- //# sourceMappingURL=agent-tools-DLquv-dp.d.ts.map
14
+ //# sourceMappingURL=agent-tools-DZhI5F6Q.d.ts.map
@@ -16,7 +16,7 @@ import {
16
16
  s as AgentToolInterruptedReason,
17
17
  t as AgentToolChildAdapter,
18
18
  u as AgentToolRunInspection
19
- } from "./agent-tool-types-NofdbL9X.js";
19
+ } from "./agent-tool-types-CTw3UJUP.js";
20
20
  import { Tool } from "ai";
21
21
 
22
22
  //#region src/agent-tools.d.ts
@@ -3,11 +3,11 @@ import {
3
3
  d as AgentToolRunState,
4
4
  i as AgentToolEventMessage,
5
5
  r as AgentToolEvent
6
- } from "../agent-tool-types-NofdbL9X.js";
6
+ } from "../agent-tool-types-CTw3UJUP.js";
7
7
  import {
8
8
  n as createAgentToolEventState,
9
9
  t as applyAgentToolEvent
10
- } from "../agent-tools-DLquv-dp.js";
10
+ } from "../agent-tools-DZhI5F6Q.js";
11
11
  import { JSONSchema7, Tool, ToolSet, UIMessage } from "ai";
12
12
  import { Connection } from "agents";
13
13
 
@@ -705,10 +705,11 @@ declare class ResumableStream {
705
705
  private _lastCleanupTime;
706
706
  constructor(sql: SqlTaggedTemplate);
707
707
  /**
708
- * Add the #1691 recovery column to the metadata table for rows created before
709
- * it existed. Inspects the current schema and only runs `alter table` when the
710
- * column is absent idempotent across Durable Object restarts, with no
711
- * error-driven control flow.
708
+ * Add metadata columns for rows created before they existed. Constructors
709
+ * intentionally do not run this: most wakes never start a stream, so paying a
710
+ * schema-introspection read every time is wasteful. New tables include these
711
+ * columns in CREATE TABLE; legacy tables migrate lazily only if a write/read
712
+ * discovers the columns are missing.
712
713
  */
713
714
  private _migrateMetadataColumns;
714
715
  get activeStreamId(): string | null;
@@ -602,6 +602,10 @@ function sendIfOpen$1(connection, message) {
602
602
  function isWebSocketClosedSendError$1(error) {
603
603
  return error instanceof TypeError && error.message.includes("WebSocket send() after close");
604
604
  }
605
+ function isMissingMetadataColumnError(error) {
606
+ const message = error instanceof Error ? error.message : String(error);
607
+ return (message.includes("message_id") || message.includes("is_continuation")) && (message.toLowerCase().includes("no such column") || message.toLowerCase().includes("has no column named"));
608
+ }
605
609
  var ResumableStream = class ResumableStream {
606
610
  constructor(sql) {
607
611
  this.sql = sql;
@@ -626,18 +630,20 @@ var ResumableStream = class ResumableStream {
626
630
  request_id text not null,
627
631
  status text not null,
628
632
  created_at integer not null,
629
- completed_at integer
633
+ completed_at integer,
634
+ message_id text,
635
+ is_continuation integer
630
636
  )`;
631
- this._migrateMetadataColumns();
632
637
  this.sql`create index if not exists idx_stream_chunks_stream_id
633
638
  on cf_ai_chat_stream_chunks(stream_id, chunk_index)`;
634
639
  this.restore();
635
640
  }
636
641
  /**
637
- * Add the #1691 recovery column to the metadata table for rows created before
638
- * it existed. Inspects the current schema and only runs `alter table` when the
639
- * column is absent idempotent across Durable Object restarts, with no
640
- * error-driven control flow.
642
+ * Add metadata columns for rows created before they existed. Constructors
643
+ * intentionally do not run this: most wakes never start a stream, so paying a
644
+ * schema-introspection read every time is wasteful. New tables include these
645
+ * columns in CREATE TABLE; legacy tables migrate lazily only if a write/read
646
+ * discovers the columns are missing.
641
647
  */
642
648
  _migrateMetadataColumns() {
643
649
  const columns = this.sql`
@@ -677,10 +683,19 @@ var ResumableStream = class ResumableStream {
677
683
  this._isLive = true;
678
684
  this._activeIsContinuation = options.continuation ?? false;
679
685
  const messageId = options.messageId ?? null;
680
- this.sql`
681
- insert into cf_ai_chat_stream_metadata (id, request_id, status, created_at, message_id, is_continuation)
682
- values (${streamId}, ${requestId}, 'streaming', ${Date.now()}, ${messageId}, ${this._activeIsContinuation ? 1 : 0})
683
- `;
686
+ try {
687
+ this.sql`
688
+ insert into cf_ai_chat_stream_metadata (id, request_id, status, created_at, message_id, is_continuation)
689
+ values (${streamId}, ${requestId}, 'streaming', ${Date.now()}, ${messageId}, ${this._activeIsContinuation ? 1 : 0})
690
+ `;
691
+ } catch (error) {
692
+ if (!isMissingMetadataColumnError(error)) throw error;
693
+ this._migrateMetadataColumns();
694
+ this.sql`
695
+ insert into cf_ai_chat_stream_metadata (id, request_id, status, created_at, message_id, is_continuation)
696
+ values (${streamId}, ${requestId}, 'streaming', ${Date.now()}, ${messageId}, ${this._activeIsContinuation ? 1 : 0})
697
+ `;
698
+ }
684
699
  return streamId;
685
700
  }
686
701
  /**
@@ -690,10 +705,16 @@ var ResumableStream = class ResumableStream {
690
705
  * is a legacy row written before the `message_id` column existed.
691
706
  */
692
707
  getStreamMessageId(streamId) {
693
- const rows = this.sql`
694
- select message_id from cf_ai_chat_stream_metadata
695
- where id = ${streamId}
696
- `;
708
+ let rows;
709
+ try {
710
+ rows = this.sql`
711
+ select message_id from cf_ai_chat_stream_metadata
712
+ where id = ${streamId}
713
+ `;
714
+ } catch (error) {
715
+ if (!isMissingMetadataColumnError(error)) throw error;
716
+ return null;
717
+ }
697
718
  if (!rows || rows.length === 0) return null;
698
719
  return rows[0].message_id ?? null;
699
720
  }