agents 0.0.0-d72c6a2 → 0.0.0-d7b2f14

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 (85) hide show
  1. package/README.md +5 -3
  2. package/dist/ai-chat-agent.d.ts +99 -19
  3. package/dist/ai-chat-agent.js +804 -351
  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 -19
  9. package/dist/ai-react.d.ts +25 -23
  10. package/dist/ai-react.js +409 -304
  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 -91
  16. package/dist/ai-types.js +3 -7
  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-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-CFhjXCiO.js +1093 -0
  24. package/dist/client-CFhjXCiO.js.map +1 -0
  25. package/dist/client-z9RQJDtK.d.ts +833 -0
  26. package/dist/client.d.ts +11 -92
  27. package/dist/client.js +4 -12
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +151 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/do-oauth-client-provider-C2CHH5x-.d.ts +55 -0
  32. package/dist/do-oauth-client-provider-CwqK5SXm.js +94 -0
  33. package/dist/do-oauth-client-provider-CwqK5SXm.js.map +1 -0
  34. package/dist/index-BUle9RiP.d.ts +58 -0
  35. package/dist/index-D3s0zwxa.d.ts +587 -0
  36. package/dist/index.d.ts +56 -550
  37. package/dist/index.js +7 -31
  38. package/dist/mcp/client.d.ts +4 -11
  39. package/dist/mcp/client.js +4 -9
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -42
  41. package/dist/mcp/do-oauth-client-provider.js +3 -7
  42. package/dist/mcp/index.d.ts +188 -92
  43. package/dist/mcp/index.js +1430 -1012
  44. package/dist/mcp/index.js.map +1 -1
  45. package/dist/mcp/x402.d.ts +34 -0
  46. package/dist/mcp/x402.js +198 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-BwPscEiF.d.ts +61 -0
  49. package/dist/observability/index.d.ts +3 -46
  50. package/dist/observability/index.js +7 -11
  51. package/dist/react-D9Ou_tyQ.d.ts +113 -0
  52. package/dist/react.d.ts +10 -123
  53. package/dist/react.js +183 -112
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +13 -10
  56. package/dist/schedule.js +43 -31
  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-CNAXL7wY.js +1182 -0
  62. package/dist/src-CNAXL7wY.js.map +1 -0
  63. package/package.json +71 -32
  64. package/dist/ai-chat-v5-migration.js.map +0 -1
  65. package/dist/ai-types.js.map +0 -1
  66. package/dist/chunk-AVYJQSLW.js +0 -17
  67. package/dist/chunk-AVYJQSLW.js.map +0 -1
  68. package/dist/chunk-LL2AFX7V.js +0 -109
  69. package/dist/chunk-LL2AFX7V.js.map +0 -1
  70. package/dist/chunk-MH46VMM4.js +0 -612
  71. package/dist/chunk-MH46VMM4.js.map +0 -1
  72. package/dist/chunk-QEVM4BVL.js +0 -116
  73. package/dist/chunk-QEVM4BVL.js.map +0 -1
  74. package/dist/chunk-UJVEAURM.js +0 -150
  75. package/dist/chunk-UJVEAURM.js.map +0 -1
  76. package/dist/chunk-YDUDMOL6.js +0 -1296
  77. package/dist/chunk-YDUDMOL6.js.map +0 -1
  78. package/dist/client-CvaJdLQA.d.ts +0 -5015
  79. package/dist/client.js.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/mcp/client.js.map +0 -1
  82. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  83. package/dist/observability/index.js.map +0 -1
  84. package/dist/serializable.js.map +0 -1
  85. package/src/index.ts +0 -1947
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,20 +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-CvaJdLQA.js";
8
- import "zod";
9
- import "@modelcontextprotocol/sdk/shared/protocol.js";
10
- import "@modelcontextprotocol/sdk/client/sse.js";
11
- import "@modelcontextprotocol/sdk/client/streamableHttp.js";
12
- import "./mcp/do-oauth-client-provider.js";
13
- import "@modelcontextprotocol/sdk/client/auth.js";
14
- import "@modelcontextprotocol/sdk/shared/auth.js";
15
- import "./observability/index.js";
16
- import "./ai-types.js";
1
+ import "./client-z9RQJDtK.js";
2
+ import "./mcp-BwPscEiF.js";
3
+ import "./do-oauth-client-provider-C2CHH5x-.js";
4
+ import "./index-BUle9RiP.js";
5
+ import "./ai-types-81H_-Uxh.js";
6
+ import { n as AgentContext, t as Agent } from "./index-D3s0zwxa.js";
7
+ import { StreamTextOnFinishCallback, ToolSet, UIMessage } from "ai";
17
8
 
9
+ //#region src/ai-chat-agent.d.ts
18
10
  /**
19
11
  * Extension of Agent with built-in chat capabilities
20
12
  * @template Env Environment type containing bindings
@@ -28,11 +20,92 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
28
20
  * useful to propagate request cancellation signals for any external calls made by the agent
29
21
  */
30
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
+ * @internal Protected for testing purposes.
27
+ */
28
+ protected _activeStreamId: string | null;
29
+ /**
30
+ * Request ID associated with the active stream.
31
+ * @internal Protected for testing purposes.
32
+ */
33
+ protected _activeRequestId: string | null;
34
+ /**
35
+ * Current chunk index for the active stream
36
+ */
37
+ private _streamChunkIndex;
38
+ /**
39
+ * Buffer for stream chunks pending write to SQLite.
40
+ * Chunks are batched and flushed when buffer reaches CHUNK_BUFFER_SIZE.
41
+ */
42
+ private _chunkBuffer;
43
+ /**
44
+ * Lock to prevent concurrent flush operations
45
+ */
46
+ private _isFlushingChunks;
47
+ /**
48
+ * Timestamp of the last cleanup operation for old streams
49
+ */
50
+ private _lastCleanupTime;
31
51
  /** Array of chat messages for the current conversation */
32
52
  messages: UIMessage[];
33
53
  constructor(ctx: AgentContext, env: Env);
54
+ /**
55
+ * Restore active stream state if the agent was restarted during streaming.
56
+ * Called during construction to recover any interrupted streams.
57
+ * Validates stream freshness to avoid sending stale resume notifications.
58
+ * @internal Protected for testing purposes.
59
+ */
60
+ protected _restoreActiveStream(): void;
61
+ /**
62
+ * Notify a connection about an active stream that can be resumed.
63
+ * The client should respond with CF_AGENT_STREAM_RESUME_ACK to receive chunks.
64
+ * Uses in-memory state for request ID - no extra DB lookup needed.
65
+ * @param connection - The WebSocket connection to notify
66
+ */
67
+ private _notifyStreamResuming;
68
+ /**
69
+ * Send stream chunks to a connection after receiving ACK.
70
+ * @param connection - The WebSocket connection
71
+ * @param streamId - The stream to replay
72
+ * @param requestId - The original request ID
73
+ */
74
+ private _sendStreamChunks;
75
+ /**
76
+ * Buffer a stream chunk for batch write to SQLite.
77
+ * @param streamId - The stream this chunk belongs to
78
+ * @param body - The serialized chunk body
79
+ * @internal Protected for testing purposes.
80
+ */
81
+ protected _storeStreamChunk(streamId: string, body: string): void;
82
+ /**
83
+ * Flush buffered chunks to SQLite in a single batch.
84
+ * Uses a lock to prevent concurrent flush operations.
85
+ * @internal Protected for testing purposes.
86
+ */
87
+ protected _flushChunkBuffer(): void;
88
+ /**
89
+ * Start tracking a new stream for resumable streaming.
90
+ * Creates metadata entry in SQLite and sets up tracking state.
91
+ * @param requestId - The unique ID of the chat request
92
+ * @returns The generated stream ID
93
+ * @internal Protected for testing purposes.
94
+ */
95
+ protected _startStream(requestId: string): string;
96
+ /**
97
+ * Mark a stream as completed and flush any pending chunks.
98
+ * @param streamId - The stream to mark as completed
99
+ * @internal Protected for testing purposes.
100
+ */
101
+ protected _completeStream(streamId: string): void;
102
+ /**
103
+ * Clean up old completed streams if enough time has passed since last cleanup.
104
+ * This prevents database growth while avoiding cleanup overhead on every stream completion.
105
+ */
106
+ private _maybeCleanupOldStreams;
34
107
  private _broadcastChatMessage;
35
- onMessage(connection: Connection, message: WSMessage): Promise<void>;
108
+ private _loadMessagesFromDb;
36
109
  onRequest(request: Request): Promise<Response>;
37
110
  private _tryCatchChat;
38
111
  /**
@@ -57,6 +130,12 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
57
130
  excludeBroadcastIds?: string[]
58
131
  ): Promise<void>;
59
132
  private _reply;
133
+ /**
134
+ * Mark a stream as errored and clean up state.
135
+ * @param streamId - The stream to mark as errored
136
+ * @internal Protected for testing purposes.
137
+ */
138
+ protected _markStreamError(streamId: string): void;
60
139
  /**
61
140
  * For the given message id, look up its associated AbortController
62
141
  * If the AbortController does not exist, create and store one in memory
@@ -77,9 +156,10 @@ declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
77
156
  */
78
157
  private _destroyAbortControllers;
79
158
  /**
80
- * When the DO is destroyed, cancel all pending requests
159
+ * When the DO is destroyed, cancel all pending requests and clean up resources
81
160
  */
82
161
  destroy(): Promise<void>;
83
162
  }
84
-
163
+ //#endregion
85
164
  export { AIChatAgent };
165
+ //# sourceMappingURL=ai-chat-agent.d.ts.map