agents 0.0.0-b4d83b9 → 0.0.0-b507395

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 (104) hide show
  1. package/README.md +5 -3
  2. package/dist/ai-chat-agent.d.ts +100 -20
  3. package/dist/ai-chat-agent.js +812 -644
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DguhuLKF.js +155 -0
  6. package/dist/ai-chat-v5-migration-DguhuLKF.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 +20 -24
  10. package/dist/ai-react.js +408 -349
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-CwgHzwUb.js +24 -0
  13. package/dist/ai-types-CwgHzwUb.js.map +1 -0
  14. package/dist/ai-types-D_hTbf25.d.ts +103 -0
  15. package/dist/ai-types.d.ts +6 -92
  16. package/dist/ai-types.js +3 -8
  17. package/dist/cli/index.d.ts +1 -0
  18. package/dist/cli/index.js +28 -0
  19. package/dist/cli/index.js.map +1 -0
  20. package/dist/client-CcyhkGfN.js +117 -0
  21. package/dist/client-CcyhkGfN.js.map +1 -0
  22. package/dist/client-ClORm6f0.d.ts +104 -0
  23. package/dist/client-DfIOsabL.d.ts +834 -0
  24. package/dist/client-QZa2Rq0l.js +1105 -0
  25. package/dist/client-QZa2Rq0l.js.map +1 -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 +91 -5139
  30. package/dist/codemode/ai.js.map +1 -1
  31. package/dist/context-BkKbAa1R.js +8 -0
  32. package/dist/context-BkKbAa1R.js.map +1 -0
  33. package/dist/context-_sPQqJWv.d.ts +24 -0
  34. package/dist/context.d.ts +6 -0
  35. package/dist/context.js +3 -0
  36. package/dist/do-oauth-client-provider-B-ryFIPr.d.ts +70 -0
  37. package/dist/do-oauth-client-provider-B1fVIshX.js +155 -0
  38. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  39. package/dist/index-CyDpAVHZ.d.ts +58 -0
  40. package/dist/index-DPJ32qQn.d.ts +577 -0
  41. package/dist/index.d.ts +55 -542
  42. package/dist/index.js +8 -32
  43. package/dist/mcp/client.d.ts +4 -12
  44. package/dist/mcp/client.js +4 -10
  45. package/dist/mcp/do-oauth-client-provider.d.ts +2 -42
  46. package/dist/mcp/do-oauth-client-provider.js +3 -8
  47. package/dist/mcp/index.d.ts +191 -76
  48. package/dist/mcp/index.js +1429 -1080
  49. package/dist/mcp/index.js.map +1 -1
  50. package/dist/mcp/x402.d.ts +22 -27
  51. package/dist/mcp/x402.js +190 -3187
  52. package/dist/mcp/x402.js.map +1 -1
  53. package/dist/{mcp-BH1fJeiU.d.ts → mcp-CzbSsLfc.d.ts} +6 -3
  54. package/dist/observability/index.d.ts +3 -34
  55. package/dist/observability/index.js +8 -12
  56. package/dist/react-MaOSl7Pr.d.ts +113 -0
  57. package/dist/react.d.ts +11 -127
  58. package/dist/react.js +173 -200
  59. package/dist/react.js.map +1 -1
  60. package/dist/schedule.d.ts +13 -10
  61. package/dist/schedule.js +43 -33
  62. package/dist/schedule.js.map +1 -1
  63. package/dist/serializable-C4GLimgv.d.ts +39 -0
  64. package/dist/serializable.d.ts +7 -32
  65. package/dist/serializable.js +1 -1
  66. package/dist/src-BmbDclOA.js +1181 -0
  67. package/dist/src-BmbDclOA.js.map +1 -0
  68. package/package.json +56 -30
  69. package/dist/_esm-LV5FJ3HK.js +0 -3922
  70. package/dist/_esm-LV5FJ3HK.js.map +0 -1
  71. package/dist/ai-chat-v5-migration.js.map +0 -1
  72. package/dist/ai-types.js.map +0 -1
  73. package/dist/ccip-CMBYN64O.js +0 -15
  74. package/dist/ccip-CMBYN64O.js.map +0 -1
  75. package/dist/chunk-5Y6BEZDY.js +0 -276
  76. package/dist/chunk-5Y6BEZDY.js.map +0 -1
  77. package/dist/chunk-BER7KXUJ.js +0 -18
  78. package/dist/chunk-BER7KXUJ.js.map +0 -1
  79. package/dist/chunk-C2OEBJZ2.js +0 -113
  80. package/dist/chunk-C2OEBJZ2.js.map +0 -1
  81. package/dist/chunk-JJBFIGUC.js +0 -5202
  82. package/dist/chunk-JJBFIGUC.js.map +0 -1
  83. package/dist/chunk-PR4QN5HX.js +0 -43
  84. package/dist/chunk-PR4QN5HX.js.map +0 -1
  85. package/dist/chunk-QEVM4BVL.js +0 -116
  86. package/dist/chunk-QEVM4BVL.js.map +0 -1
  87. package/dist/chunk-TYAY6AU6.js +0 -159
  88. package/dist/chunk-TYAY6AU6.js.map +0 -1
  89. package/dist/chunk-UJVEAURM.js +0 -150
  90. package/dist/chunk-UJVEAURM.js.map +0 -1
  91. package/dist/chunk-XGMKNUJA.js +0 -1343
  92. package/dist/chunk-XGMKNUJA.js.map +0 -1
  93. package/dist/chunk-ZMMHNOMZ.js +0 -942
  94. package/dist/chunk-ZMMHNOMZ.js.map +0 -1
  95. package/dist/client-DVoPb3-C.d.ts +0 -5120
  96. package/dist/client.js.map +0 -1
  97. package/dist/index.js.map +0 -1
  98. package/dist/mcp/client.js.map +0 -1
  99. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  100. package/dist/observability/index.js.map +0 -1
  101. package/dist/secp256k1-M22GZP2U.js +0 -2193
  102. package/dist/secp256k1-M22GZP2U.js.map +0 -1
  103. package/dist/serializable.js.map +0 -1
  104. 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,13 @@
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 "./context-_sPQqJWv.js";
2
+ import "./client-DfIOsabL.js";
3
+ import "./mcp-CzbSsLfc.js";
4
+ import "./do-oauth-client-provider-B-ryFIPr.js";
5
+ import "./index-CyDpAVHZ.js";
6
+ import "./ai-types-D_hTbf25.js";
7
+ import { n as AgentContext, t as Agent } from "./index-DPJ32qQn.js";
8
+ import { StreamTextOnFinishCallback, ToolSet, UIMessage } from "ai";
18
9
 
10
+ //#region src/ai-chat-agent.d.ts
19
11
  /**
20
12
  * Extension of Agent with built-in chat capabilities
21
13
  * @template Env Environment type containing bindings
@@ -29,11 +21,92 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
29
21
  * useful to propagate request cancellation signals for any external calls made by the agent
30
22
  */
31
23
  private _chatMessageAbortControllers;
24
+ /**
25
+ * Currently active stream ID for resumable streaming.
26
+ * Stored in memory for quick access; persisted in stream_metadata table.
27
+ * @internal Protected for testing purposes.
28
+ */
29
+ protected _activeStreamId: string | null;
30
+ /**
31
+ * Request ID associated with the active stream.
32
+ * @internal Protected for testing purposes.
33
+ */
34
+ protected _activeRequestId: string | null;
35
+ /**
36
+ * Current chunk index for the active stream
37
+ */
38
+ private _streamChunkIndex;
39
+ /**
40
+ * Buffer for stream chunks pending write to SQLite.
41
+ * Chunks are batched and flushed when buffer reaches CHUNK_BUFFER_SIZE.
42
+ */
43
+ private _chunkBuffer;
44
+ /**
45
+ * Lock to prevent concurrent flush operations
46
+ */
47
+ private _isFlushingChunks;
48
+ /**
49
+ * Timestamp of the last cleanup operation for old streams
50
+ */
51
+ private _lastCleanupTime;
32
52
  /** Array of chat messages for the current conversation */
33
53
  messages: UIMessage[];
34
54
  constructor(ctx: AgentContext, env: Env);
55
+ /**
56
+ * Restore active stream state if the agent was restarted during streaming.
57
+ * Called during construction to recover any interrupted streams.
58
+ * Validates stream freshness to avoid sending stale resume notifications.
59
+ * @internal Protected for testing purposes.
60
+ */
61
+ protected _restoreActiveStream(): void;
62
+ /**
63
+ * Notify a connection about an active stream that can be resumed.
64
+ * The client should respond with CF_AGENT_STREAM_RESUME_ACK to receive chunks.
65
+ * Uses in-memory state for request ID - no extra DB lookup needed.
66
+ * @param connection - The WebSocket connection to notify
67
+ */
68
+ private _notifyStreamResuming;
69
+ /**
70
+ * Send stream chunks to a connection after receiving ACK.
71
+ * @param connection - The WebSocket connection
72
+ * @param streamId - The stream to replay
73
+ * @param requestId - The original request ID
74
+ */
75
+ private _sendStreamChunks;
76
+ /**
77
+ * Buffer a stream chunk for batch write to SQLite.
78
+ * @param streamId - The stream this chunk belongs to
79
+ * @param body - The serialized chunk body
80
+ * @internal Protected for testing purposes.
81
+ */
82
+ protected _storeStreamChunk(streamId: string, body: string): void;
83
+ /**
84
+ * Flush buffered chunks to SQLite in a single batch.
85
+ * Uses a lock to prevent concurrent flush operations.
86
+ * @internal Protected for testing purposes.
87
+ */
88
+ protected _flushChunkBuffer(): void;
89
+ /**
90
+ * Start tracking a new stream for resumable streaming.
91
+ * Creates metadata entry in SQLite and sets up tracking state.
92
+ * @param requestId - The unique ID of the chat request
93
+ * @returns The generated stream ID
94
+ * @internal Protected for testing purposes.
95
+ */
96
+ protected _startStream(requestId: string): string;
97
+ /**
98
+ * Mark a stream as completed and flush any pending chunks.
99
+ * @param streamId - The stream to mark as completed
100
+ * @internal Protected for testing purposes.
101
+ */
102
+ protected _completeStream(streamId: string): void;
103
+ /**
104
+ * Clean up old completed streams if enough time has passed since last cleanup.
105
+ * This prevents database growth while avoiding cleanup overhead on every stream completion.
106
+ */
107
+ private _maybeCleanupOldStreams;
35
108
  private _broadcastChatMessage;
36
- onMessage(connection: Connection, message: WSMessage): Promise<void>;
109
+ private _loadMessagesFromDb;
37
110
  onRequest(request: Request): Promise<Response>;
38
111
  private _tryCatchChat;
39
112
  /**
@@ -58,6 +131,12 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
58
131
  excludeBroadcastIds?: string[]
59
132
  ): Promise<void>;
60
133
  private _reply;
134
+ /**
135
+ * Mark a stream as errored and clean up state.
136
+ * @param streamId - The stream to mark as errored
137
+ * @internal Protected for testing purposes.
138
+ */
139
+ protected _markStreamError(streamId: string): void;
61
140
  /**
62
141
  * For the given message id, look up its associated AbortController
63
142
  * If the AbortController does not exist, create and store one in memory
@@ -78,9 +157,10 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
78
157
  */
79
158
  private _destroyAbortControllers;
80
159
  /**
81
- * When the DO is destroyed, cancel all pending requests
160
+ * When the DO is destroyed, cancel all pending requests and clean up resources
82
161
  */
83
162
  destroy(): Promise<void>;
84
163
  }
85
-
164
+ //#endregion
86
165
  export { AIChatAgent };
166
+ //# sourceMappingURL=ai-chat-agent.d.ts.map