@cloudflare/ai-chat 0.1.7 → 0.1.9
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/dist/ai-chat-v5-migration.js +1 -1
- package/dist/ai-chat-v5-migration.js.map +1 -1
- package/dist/experimental/forever.d.ts +2 -15
- package/dist/experimental/forever.js +1 -1
- package/dist/experimental/forever.js.map +1 -1
- package/dist/index-BLQX_nE0.d.ts +598 -0
- package/dist/index.d.ts +5 -470
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/{message-builder-uSvexDl2.js → message-builder-BAgcFJMf.js} +2 -2
- package/dist/{message-builder-uSvexDl2.js.map → message-builder-BAgcFJMf.js.map} +1 -1
- package/dist/react.js +29 -7
- package/dist/react.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.js +3 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/dist/resumable-stream-DTLAk9XC.d.ts +0 -126
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Connection } from "agents";
|
|
2
|
-
|
|
3
|
-
//#region src/resumable-stream.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Minimal SQL interface matching Agent's this.sql tagged template.
|
|
6
|
-
* Allows ResumableStream to work with the Agent's SQLite without
|
|
7
|
-
* depending on the full Agent class.
|
|
8
|
-
*/
|
|
9
|
-
type SqlTaggedTemplate = {
|
|
10
|
-
<T = Record<string, unknown>>(
|
|
11
|
-
strings: TemplateStringsArray,
|
|
12
|
-
...values: (string | number | boolean | null)[]
|
|
13
|
-
): T[];
|
|
14
|
-
};
|
|
15
|
-
declare class ResumableStream {
|
|
16
|
-
private sql;
|
|
17
|
-
private _activeStreamId;
|
|
18
|
-
private _activeRequestId;
|
|
19
|
-
private _streamChunkIndex;
|
|
20
|
-
/**
|
|
21
|
-
* Whether the active stream was started in this instance (true) or
|
|
22
|
-
* restored from SQLite after hibernation/restart (false). An orphaned
|
|
23
|
-
* stream has no live LLM reader — the ReadableStream was lost when the
|
|
24
|
-
* DO was evicted.
|
|
25
|
-
*/
|
|
26
|
-
private _isLive;
|
|
27
|
-
private _chunkBuffer;
|
|
28
|
-
private _isFlushingChunks;
|
|
29
|
-
private _lastCleanupTime;
|
|
30
|
-
constructor(sql: SqlTaggedTemplate);
|
|
31
|
-
get activeStreamId(): string | null;
|
|
32
|
-
get activeRequestId(): string | null;
|
|
33
|
-
hasActiveStream(): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Whether the active stream has a live LLM reader (started in this
|
|
36
|
-
* instance) vs being restored from SQLite after hibernation (orphaned).
|
|
37
|
-
*/
|
|
38
|
-
get isLive(): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Start tracking a new stream for resumable streaming.
|
|
41
|
-
* Creates metadata entry in SQLite and sets up tracking state.
|
|
42
|
-
* @param requestId - The unique ID of the chat request
|
|
43
|
-
* @returns The generated stream ID
|
|
44
|
-
*/
|
|
45
|
-
start(requestId: string): string;
|
|
46
|
-
/**
|
|
47
|
-
* Mark a stream as completed and flush any pending chunks.
|
|
48
|
-
* @param streamId - The stream to mark as completed
|
|
49
|
-
*/
|
|
50
|
-
complete(streamId: string): void;
|
|
51
|
-
/**
|
|
52
|
-
* Mark a stream as errored and clean up state.
|
|
53
|
-
* @param streamId - The stream to mark as errored
|
|
54
|
-
*/
|
|
55
|
-
markError(streamId: string): void;
|
|
56
|
-
/** Maximum chunk body size before skipping storage (bytes). Prevents SQLite row limit crash. */
|
|
57
|
-
private static CHUNK_MAX_BYTES;
|
|
58
|
-
/**
|
|
59
|
-
* Buffer a stream chunk for batch write to SQLite.
|
|
60
|
-
* Chunks exceeding the row size limit are skipped to prevent crashes.
|
|
61
|
-
* The chunk is still broadcast to live clients (caller handles that),
|
|
62
|
-
* but will be missing from replay on reconnection.
|
|
63
|
-
* @param streamId - The stream this chunk belongs to
|
|
64
|
-
* @param body - The serialized chunk body
|
|
65
|
-
*/
|
|
66
|
-
storeChunk(streamId: string, body: string): void;
|
|
67
|
-
/**
|
|
68
|
-
* Flush buffered chunks to SQLite in a single batch.
|
|
69
|
-
* Uses a lock to prevent concurrent flush operations.
|
|
70
|
-
*/
|
|
71
|
-
flushBuffer(): void;
|
|
72
|
-
/**
|
|
73
|
-
* Send stored stream chunks to a connection for replay.
|
|
74
|
-
* Chunks are marked with replay: true so the client can batch-apply them.
|
|
75
|
-
*
|
|
76
|
-
* Three outcomes:
|
|
77
|
-
* - **Live stream**: sends chunks + `replayComplete` — client flushes and
|
|
78
|
-
* continues receiving live chunks from the LLM reader.
|
|
79
|
-
* - **Orphaned stream** (restored from SQLite after hibernation, no reader):
|
|
80
|
-
* sends chunks + `done` and completes the stream. The caller should
|
|
81
|
-
* reconstruct and persist the partial message from the stored chunks.
|
|
82
|
-
* - **Completed during replay** (defensive): sends chunks + `done`.
|
|
83
|
-
*
|
|
84
|
-
* @param connection - The WebSocket connection
|
|
85
|
-
* @param requestId - The original request ID
|
|
86
|
-
* @returns The stream ID if the stream was orphaned and finalized, null otherwise.
|
|
87
|
-
* When non-null the caller should reconstruct the message from chunks.
|
|
88
|
-
*/
|
|
89
|
-
replayChunks(connection: Connection, requestId: string): string | null;
|
|
90
|
-
/**
|
|
91
|
-
* Restore active stream state if the agent was restarted during streaming.
|
|
92
|
-
* Validates stream freshness to avoid sending stale resume notifications.
|
|
93
|
-
*/
|
|
94
|
-
restore(): void;
|
|
95
|
-
/**
|
|
96
|
-
* Clear all stream data (called on chat history clear).
|
|
97
|
-
*/
|
|
98
|
-
clearAll(): void;
|
|
99
|
-
/**
|
|
100
|
-
* Drop all stream tables (called on destroy).
|
|
101
|
-
*/
|
|
102
|
-
destroy(): void;
|
|
103
|
-
private _maybeCleanupOldStreams;
|
|
104
|
-
/** @internal For testing only */
|
|
105
|
-
getStreamChunks(streamId: string): Array<{
|
|
106
|
-
body: string;
|
|
107
|
-
chunk_index: number;
|
|
108
|
-
}>;
|
|
109
|
-
/** @internal For testing only */
|
|
110
|
-
getStreamMetadata(streamId: string): {
|
|
111
|
-
status: string;
|
|
112
|
-
request_id: string;
|
|
113
|
-
} | null;
|
|
114
|
-
/** @internal For testing only */
|
|
115
|
-
getAllStreamMetadata(): Array<{
|
|
116
|
-
id: string;
|
|
117
|
-
status: string;
|
|
118
|
-
request_id: string;
|
|
119
|
-
created_at: number;
|
|
120
|
-
}>;
|
|
121
|
-
/** @internal For testing only */
|
|
122
|
-
insertStaleStream(streamId: string, requestId: string, ageMs: number): void;
|
|
123
|
-
}
|
|
124
|
-
//#endregion
|
|
125
|
-
export { ResumableStream as t };
|
|
126
|
-
//# sourceMappingURL=resumable-stream-DTLAk9XC.d.ts.map
|