agents 0.0.0-cb5957e → 0.0.0-cccbd0f

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.
Files changed (99) hide show
  1. package/README.md +5 -3
  2. package/dist/ai-chat-agent.d.ts +91 -20
  3. package/dist/ai-chat-agent.js +798 -644
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-BSiGZmYU.js +155 -0
  6. package/dist/ai-chat-v5-migration-BSiGZmYU.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +7 -4
  8. package/dist/ai-chat-v5-migration.js +3 -20
  9. package/dist/ai-react.d.ts +19 -24
  10. package/dist/ai-react.js +393 -349
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-81H_-Uxh.d.ts +103 -0
  13. package/dist/ai-types-CrMqkwc_.js +24 -0
  14. package/dist/ai-types-CrMqkwc_.js.map +1 -0
  15. package/dist/ai-types.d.ts +6 -92
  16. package/dist/ai-types.js +3 -8
  17. package/dist/cli.d.ts +8 -0
  18. package/dist/cli.js +27 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/client-B3SR12TQ.js +117 -0
  21. package/dist/client-B3SR12TQ.js.map +1 -0
  22. package/dist/client-BAQA84dr.d.ts +104 -0
  23. package/dist/client-BZ-xTxF5.js +901 -0
  24. package/dist/client-BZ-xTxF5.js.map +1 -0
  25. package/dist/client-ctTw3KHG.d.ts +1440 -0
  26. package/dist/client.d.ts +11 -92
  27. package/dist/client.js +4 -13
  28. package/dist/codemode/ai.d.ts +19 -17
  29. package/dist/codemode/ai.js +90 -5051
  30. package/dist/codemode/ai.js.map +1 -1
  31. package/dist/do-oauth-client-provider-Cs9QpXYp.js +93 -0
  32. package/dist/do-oauth-client-provider-Cs9QpXYp.js.map +1 -0
  33. package/dist/do-oauth-client-provider-UhQDpDb8.d.ts +134 -0
  34. package/dist/index-BUle9RiP.d.ts +58 -0
  35. package/dist/index-D2dnUH0r.d.ts +578 -0
  36. package/dist/index.d.ts +55 -542
  37. package/dist/index.js +7 -32
  38. package/dist/mcp/client.d.ts +4 -12
  39. package/dist/mcp/client.js +4 -10
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -42
  41. package/dist/mcp/do-oauth-client-provider.js +3 -8
  42. package/dist/mcp/index.d.ts +190 -76
  43. package/dist/mcp/index.js +1428 -1080
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/mcp/x402.d.ts +22 -27
  46. package/dist/mcp/x402.js +190 -3187
  47. package/dist/mcp/x402.js.map +1 -1
  48. package/dist/{mcp-BH1fJeiU.d.ts → mcp-BwPscEiF.d.ts} +6 -3
  49. package/dist/observability/index.d.ts +3 -34
  50. package/dist/observability/index.js +7 -12
  51. package/dist/react-B_ENAdCe.d.ts +113 -0
  52. package/dist/react.d.ts +10 -127
  53. package/dist/react.js +173 -200
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +13 -10
  56. package/dist/schedule.js +43 -33
  57. package/dist/schedule.js.map +1 -1
  58. package/dist/serializable-faDkMCai.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -32
  60. package/dist/serializable.js +1 -1
  61. package/dist/src-C6rC6ZpH.js +1248 -0
  62. package/dist/src-C6rC6ZpH.js.map +1 -0
  63. package/package.json +58 -32
  64. package/dist/_esm-LV5FJ3HK.js +0 -3922
  65. package/dist/_esm-LV5FJ3HK.js.map +0 -1
  66. package/dist/ai-chat-v5-migration.js.map +0 -1
  67. package/dist/ai-types.js.map +0 -1
  68. package/dist/ccip-CMBYN64O.js +0 -15
  69. package/dist/ccip-CMBYN64O.js.map +0 -1
  70. package/dist/chunk-254F4GDT.js +0 -1343
  71. package/dist/chunk-254F4GDT.js.map +0 -1
  72. package/dist/chunk-3OT2NNEW.js +0 -941
  73. package/dist/chunk-3OT2NNEW.js.map +0 -1
  74. package/dist/chunk-5Y6BEZDY.js +0 -276
  75. package/dist/chunk-5Y6BEZDY.js.map +0 -1
  76. package/dist/chunk-BER7KXUJ.js +0 -18
  77. package/dist/chunk-BER7KXUJ.js.map +0 -1
  78. package/dist/chunk-JJBFIGUC.js +0 -5202
  79. package/dist/chunk-JJBFIGUC.js.map +0 -1
  80. package/dist/chunk-PR4QN5HX.js +0 -43
  81. package/dist/chunk-PR4QN5HX.js.map +0 -1
  82. package/dist/chunk-QEVM4BVL.js +0 -116
  83. package/dist/chunk-QEVM4BVL.js.map +0 -1
  84. package/dist/chunk-TYAY6AU6.js +0 -159
  85. package/dist/chunk-TYAY6AU6.js.map +0 -1
  86. package/dist/chunk-UJVEAURM.js +0 -150
  87. package/dist/chunk-UJVEAURM.js.map +0 -1
  88. package/dist/chunk-Z44WASMA.js +0 -114
  89. package/dist/chunk-Z44WASMA.js.map +0 -1
  90. package/dist/client-DVoPb3-C.d.ts +0 -5120
  91. package/dist/client.js.map +0 -1
  92. package/dist/index.js.map +0 -1
  93. package/dist/mcp/client.js.map +0 -1
  94. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  95. package/dist/observability/index.js.map +0 -1
  96. package/dist/secp256k1-M22GZP2U.js +0 -2193
  97. package/dist/secp256k1-M22GZP2U.js.map +0 -1
  98. package/dist/serializable.js.map +0 -1
  99. package/src/index.ts +0 -2031
package/README.md CHANGED
@@ -549,10 +549,12 @@ export class MyMCP extends McpAgent<Env, State, {}> {
549
549
  };
550
550
  });
551
551
 
552
- this.server.tool(
552
+ this.server.registerTool(
553
553
  "add",
554
- "Add to the counter, stored in the MCP",
555
- { a: z.number() },
554
+ {
555
+ description: "Add to the counter, stored in the MCP",
556
+ inputSchema: { a: z.number() }
557
+ },
556
558
  async ({ a }) => {
557
559
  this.setState({ ...this.state, counter: this.state.counter + a });
558
560
 
@@ -1,21 +1,12 @@
1
- import { UIMessage, StreamTextOnFinishCallback, ToolSet } from "ai";
2
- import { Agent, AgentContext } from "./index.js";
3
- import { Connection, WSMessage } from "partyserver";
4
- import "cloudflare:workers";
5
- import "@modelcontextprotocol/sdk/client/index.js";
6
- import "@modelcontextprotocol/sdk/types.js";
7
- import "./client-DVoPb3-C.js";
8
- import "zod";
9
- import "@modelcontextprotocol/sdk/shared/protocol.js";
10
- import "./mcp-BH1fJeiU.js";
11
- import "@modelcontextprotocol/sdk/client/sse.js";
12
- import "@modelcontextprotocol/sdk/client/streamableHttp.js";
13
- import "./mcp/do-oauth-client-provider.js";
14
- import "@modelcontextprotocol/sdk/client/auth.js";
15
- import "@modelcontextprotocol/sdk/shared/auth.js";
16
- import "./observability/index.js";
17
- import "./ai-types.js";
1
+ import "./client-ctTw3KHG.js";
2
+ import "./mcp-BwPscEiF.js";
3
+ import "./do-oauth-client-provider-UhQDpDb8.js";
4
+ import "./index-BUle9RiP.js";
5
+ import "./ai-types-81H_-Uxh.js";
6
+ import { n as AgentContext, t as Agent } from "./index-D2dnUH0r.js";
7
+ import { StreamTextOnFinishCallback, ToolSet, UIMessage } from "ai";
18
8
 
9
+ //#region src/ai-chat-agent.d.ts
19
10
  /**
20
11
  * Extension of Agent with built-in chat capabilities
21
12
  * @template Env Environment type containing bindings
@@ -29,11 +20,85 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
29
20
  * useful to propagate request cancellation signals for any external calls made by the agent
30
21
  */
31
22
  private _chatMessageAbortControllers;
23
+ /**
24
+ * Currently active stream ID for resumable streaming.
25
+ * Stored in memory for quick access; persisted in stream_metadata table.
26
+ */
27
+ private _activeStreamId;
28
+ /**
29
+ * Request ID associated with the active stream.
30
+ */
31
+ private _activeRequestId;
32
+ /**
33
+ * Current chunk index for the active stream
34
+ */
35
+ private _streamChunkIndex;
36
+ /**
37
+ * Buffer for stream chunks pending write to SQLite.
38
+ * Chunks are batched and flushed when buffer reaches CHUNK_BUFFER_SIZE.
39
+ */
40
+ private _chunkBuffer;
41
+ /**
42
+ * Lock to prevent concurrent flush operations
43
+ */
44
+ private _isFlushingChunks;
45
+ /**
46
+ * Timestamp of the last cleanup operation for old streams
47
+ */
48
+ private _lastCleanupTime;
32
49
  /** Array of chat messages for the current conversation */
33
50
  messages: UIMessage[];
34
51
  constructor(ctx: AgentContext, env: Env);
52
+ /**
53
+ * Restore active stream state if the agent was restarted during streaming.
54
+ * Called during construction to recover any interrupted streams.
55
+ * Validates stream freshness to avoid sending stale resume notifications.
56
+ */
57
+ private _restoreActiveStream;
58
+ /**
59
+ * Notify a connection about an active stream that can be resumed.
60
+ * The client should respond with CF_AGENT_STREAM_RESUME_ACK to receive chunks.
61
+ * Uses in-memory state for request ID - no extra DB lookup needed.
62
+ * @param connection - The WebSocket connection to notify
63
+ */
64
+ private _notifyStreamResuming;
65
+ /**
66
+ * Send stream chunks to a connection after receiving ACK.
67
+ * @param connection - The WebSocket connection
68
+ * @param streamId - The stream to replay
69
+ * @param requestId - The original request ID
70
+ */
71
+ private _sendStreamChunks;
72
+ /**
73
+ * Buffer a stream chunk for batch write to SQLite.
74
+ * @param streamId - The stream this chunk belongs to
75
+ * @param body - The serialized chunk body
76
+ */
77
+ private _storeStreamChunk;
78
+ /**
79
+ * Flush buffered chunks to SQLite in a single batch.
80
+ * Uses a lock to prevent concurrent flush operations.
81
+ */
82
+ private _flushChunkBuffer;
83
+ /**
84
+ * Start tracking a new stream for resumable streaming.
85
+ * Creates metadata entry in SQLite and sets up tracking state.
86
+ * @param requestId - The unique ID of the chat request
87
+ * @returns The generated stream ID
88
+ */
89
+ private _startStream;
90
+ /**
91
+ * Mark a stream as completed and flush any pending chunks.
92
+ * @param streamId - The stream to mark as completed
93
+ */
94
+ private _completeStream;
95
+ /**
96
+ * Clean up old completed streams if enough time has passed since last cleanup.
97
+ * This prevents database growth while avoiding cleanup overhead on every stream completion.
98
+ */
99
+ private _maybeCleanupOldStreams;
35
100
  private _broadcastChatMessage;
36
- onMessage(connection: Connection, message: WSMessage): Promise<void>;
101
+ private _loadMessagesFromDb;
37
102
  onRequest(request: Request): Promise<Response>;
38
103
  private _tryCatchChat;
39
104
  /**
@@ -58,6 +123,11 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
58
123
  excludeBroadcastIds?: string[]
59
124
  ): Promise<void>;
60
125
  private _reply;
126
+ /**
127
+ * Mark a stream as errored and clean up state.
128
+ * @param streamId - The stream to mark as errored
129
+ */
130
+ private _markStreamError;
61
131
  /**
62
132
  * For the given message id, look up its associated AbortController
63
133
  * If the AbortController does not exist, create and store one in memory
@@ -78,9 +148,10 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
78
148
  */
79
149
  private _destroyAbortControllers;
80
150
  /**
81
- * When the DO is destroyed, cancel all pending requests
151
+ * When the DO is destroyed, cancel all pending requests and clean up resources
82
152
  */
83
153
  destroy(): Promise<void>;
84
154
  }
85
-
155
+ //#endregion
86
156
  export { AIChatAgent };
157
+ //# sourceMappingURL=ai-chat-agent.d.ts.map