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.
- package/README.md +5 -3
- package/dist/ai-chat-agent.d.ts +99 -19
- package/dist/ai-chat-agent.js +804 -351
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration-BSiGZmYU.js +155 -0
- package/dist/ai-chat-v5-migration-BSiGZmYU.js.map +1 -0
- package/dist/ai-chat-v5-migration.d.ts +7 -4
- package/dist/ai-chat-v5-migration.js +3 -19
- package/dist/ai-react.d.ts +25 -23
- package/dist/ai-react.js +409 -304
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types-81H_-Uxh.d.ts +103 -0
- package/dist/ai-types-CrMqkwc_.js +24 -0
- package/dist/ai-types-CrMqkwc_.js.map +1 -0
- package/dist/ai-types.d.ts +6 -91
- package/dist/ai-types.js +3 -7
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +28 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client-B3SR12TQ.js +117 -0
- package/dist/client-B3SR12TQ.js.map +1 -0
- package/dist/client-BAQA84dr.d.ts +104 -0
- package/dist/client-CFhjXCiO.js +1093 -0
- package/dist/client-CFhjXCiO.js.map +1 -0
- package/dist/client-z9RQJDtK.d.ts +833 -0
- package/dist/client.d.ts +11 -92
- package/dist/client.js +4 -12
- package/dist/codemode/ai.d.ts +27 -0
- package/dist/codemode/ai.js +151 -0
- package/dist/codemode/ai.js.map +1 -0
- package/dist/do-oauth-client-provider-C2CHH5x-.d.ts +55 -0
- package/dist/do-oauth-client-provider-CwqK5SXm.js +94 -0
- package/dist/do-oauth-client-provider-CwqK5SXm.js.map +1 -0
- package/dist/index-BUle9RiP.d.ts +58 -0
- package/dist/index-D3s0zwxa.d.ts +587 -0
- package/dist/index.d.ts +56 -550
- package/dist/index.js +7 -31
- package/dist/mcp/client.d.ts +4 -11
- package/dist/mcp/client.js +4 -9
- package/dist/mcp/do-oauth-client-provider.d.ts +2 -42
- package/dist/mcp/do-oauth-client-provider.js +3 -7
- package/dist/mcp/index.d.ts +188 -92
- package/dist/mcp/index.js +1430 -1012
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/x402.d.ts +34 -0
- package/dist/mcp/x402.js +198 -0
- package/dist/mcp/x402.js.map +1 -0
- package/dist/mcp-BwPscEiF.d.ts +61 -0
- package/dist/observability/index.d.ts +3 -46
- package/dist/observability/index.js +7 -11
- package/dist/react-D9Ou_tyQ.d.ts +113 -0
- package/dist/react.d.ts +10 -123
- package/dist/react.js +183 -112
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +13 -10
- package/dist/schedule.js +43 -31
- package/dist/schedule.js.map +1 -1
- package/dist/serializable-faDkMCai.d.ts +39 -0
- package/dist/serializable.d.ts +7 -32
- package/dist/serializable.js +1 -1
- package/dist/src-CNAXL7wY.js +1182 -0
- package/dist/src-CNAXL7wY.js.map +1 -0
- package/package.json +71 -32
- package/dist/ai-chat-v5-migration.js.map +0 -1
- package/dist/ai-types.js.map +0 -1
- package/dist/chunk-AVYJQSLW.js +0 -17
- package/dist/chunk-AVYJQSLW.js.map +0 -1
- package/dist/chunk-LL2AFX7V.js +0 -109
- package/dist/chunk-LL2AFX7V.js.map +0 -1
- package/dist/chunk-MH46VMM4.js +0 -612
- package/dist/chunk-MH46VMM4.js.map +0 -1
- package/dist/chunk-QEVM4BVL.js +0 -116
- package/dist/chunk-QEVM4BVL.js.map +0 -1
- package/dist/chunk-UJVEAURM.js +0 -150
- package/dist/chunk-UJVEAURM.js.map +0 -1
- package/dist/chunk-YDUDMOL6.js +0 -1296
- package/dist/chunk-YDUDMOL6.js.map +0 -1
- package/dist/client-CvaJdLQA.d.ts +0 -5015
- package/dist/client.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/do-oauth-client-provider.js.map +0 -1
- package/dist/observability/index.js.map +0 -1
- package/dist/serializable.js.map +0 -1
- 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.
|
|
552
|
+
this.server.registerTool(
|
|
553
553
|
"add",
|
|
554
|
-
|
|
555
|
-
|
|
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
|
|
package/dist/ai-chat-agent.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import "
|
|
7
|
-
import "
|
|
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
|
-
|
|
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
|