blink 0.1.92 → 0.1.93
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/cli/{dev-LbQr0Fws.js → dev-Dc7M3oIW.js} +43 -4
- package/dist/cli/disk-store-Cbn2SJoD.js +21 -0
- package/dist/cli/index.js +2 -2
- package/dist/cli/run-DPPy_-IS.js +1 -0
- package/dist/node/react/index.node.cjs +143 -110
- package/dist/node/react/index.node.d.cts +48 -2
- package/dist/node/react/index.node.d.ts +48 -2
- package/dist/node/react/index.node.js +54 -21
- package/package.json +1 -1
- package/dist/cli/chat-manager-Crb5wc0l.js +0 -21
- package/dist/cli/run-KAT6MOpw.js +0 -1
|
@@ -70,6 +70,39 @@ interface StoreEntry {
|
|
|
70
70
|
* It works with filesystem locks - so multiple processes can
|
|
71
71
|
* read and write to the store concurrently.
|
|
72
72
|
*/
|
|
73
|
+
interface Store<T extends object> {
|
|
74
|
+
get: (key: string) => Promise<T | undefined>;
|
|
75
|
+
list: () => Promise<StoreEntry[]>;
|
|
76
|
+
lock: (key: string, opts?: {
|
|
77
|
+
force?: boolean;
|
|
78
|
+
}) => Promise<LockedStoreEntry<T>>;
|
|
79
|
+
dispose: () => void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* createFileStore creates a simple file-based store with atomic read/write.
|
|
83
|
+
* All operations are protected by filesystem locks for multi-process safety.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
interface DiskStoreWatcher<T = any> {
|
|
87
|
+
onChange: (callback: (event: {
|
|
88
|
+
key: string;
|
|
89
|
+
value: T | undefined;
|
|
90
|
+
locked: boolean;
|
|
91
|
+
pid?: number;
|
|
92
|
+
}) => void) => () => void;
|
|
93
|
+
dispose: () => void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* createDiskStoreWatcher creates a watcher for the disk store.
|
|
97
|
+
* It watches the disk store for changes and emits events when the
|
|
98
|
+
* store changes.
|
|
99
|
+
*
|
|
100
|
+
* It also polls the store for changes in case the watcher misses
|
|
101
|
+
* any changes.
|
|
102
|
+
*
|
|
103
|
+
* It also debounces the changes to prevent too many events from
|
|
104
|
+
* being emitted.
|
|
105
|
+
*/
|
|
73
106
|
//#endregion
|
|
74
107
|
//#region src/local/types.d.ts
|
|
75
108
|
interface StoredChat {
|
|
@@ -111,7 +144,8 @@ interface ChatState {
|
|
|
111
144
|
}
|
|
112
145
|
interface ChatManagerOptions {
|
|
113
146
|
readonly chatId: string;
|
|
114
|
-
readonly
|
|
147
|
+
readonly store: Store<StoredChat>;
|
|
148
|
+
readonly watcher: DiskStoreWatcher<StoredChat>;
|
|
115
149
|
/**
|
|
116
150
|
* Optional function to filter messages before persisting them.
|
|
117
151
|
* Return undefined to skip persisting the message.
|
|
@@ -142,7 +176,7 @@ declare class ChatManager {
|
|
|
142
176
|
private abortController;
|
|
143
177
|
private isProcessingQueue;
|
|
144
178
|
private listeners;
|
|
145
|
-
private
|
|
179
|
+
private unwatchStore;
|
|
146
180
|
private disposed;
|
|
147
181
|
constructor(options: ChatManagerOptions);
|
|
148
182
|
/**
|
|
@@ -161,6 +195,7 @@ declare class ChatManager {
|
|
|
161
195
|
* Upsert a message to the chat
|
|
162
196
|
*/
|
|
163
197
|
upsertMessage(message: UIMessage, lock?: LockedStoreEntry<StoredChat>): Promise<void>;
|
|
198
|
+
deleteMessage(id: string): Promise<void>;
|
|
164
199
|
/**
|
|
165
200
|
* Send a message to the agent
|
|
166
201
|
*/
|
|
@@ -191,6 +226,14 @@ interface UseChatOptions {
|
|
|
191
226
|
readonly chatId: string;
|
|
192
227
|
readonly agent: Client | undefined;
|
|
193
228
|
readonly chatsDirectory: string;
|
|
229
|
+
/**
|
|
230
|
+
* Optional shared store to use. If not provided, a new one will be created.
|
|
231
|
+
*/
|
|
232
|
+
readonly store?: Store<StoredChat>;
|
|
233
|
+
/**
|
|
234
|
+
* Optional shared watcher to use. If not provided, a new one will be created.
|
|
235
|
+
*/
|
|
236
|
+
readonly watcher?: DiskStoreWatcher<StoredChat>;
|
|
194
237
|
/**
|
|
195
238
|
* Optional function to filter messages before persisting them.
|
|
196
239
|
* Return undefined to skip persisting the message.
|
|
@@ -205,6 +248,7 @@ interface UseChatOptions {
|
|
|
205
248
|
interface UseChat extends ChatState {
|
|
206
249
|
readonly sendMessage: (message: StoredMessage) => Promise<void>;
|
|
207
250
|
readonly upsertMessage: (message: StoredMessage) => Promise<void>;
|
|
251
|
+
readonly deleteMessage: (id: string) => Promise<void>;
|
|
208
252
|
readonly stopStreaming: () => void;
|
|
209
253
|
readonly resetChat: () => Promise<void>;
|
|
210
254
|
readonly clearQueue: () => void;
|
|
@@ -231,6 +275,8 @@ declare function createLocalServer(options: CreateLocalServerOptions): {
|
|
|
231
275
|
url: string;
|
|
232
276
|
runtime: Context;
|
|
233
277
|
chatsDirectory: string;
|
|
278
|
+
chatStore: Store<StoredChat>;
|
|
279
|
+
chatWatcher: DiskStoreWatcher<StoredChat>;
|
|
234
280
|
getChatManager: (chatId: string) => ChatManager;
|
|
235
281
|
listChats: () => Promise<StoreEntry[]>;
|
|
236
282
|
lockChat: (chatId: string) => Promise<LockedStoreEntry<StoredChat>>;
|
|
@@ -70,6 +70,39 @@ interface StoreEntry {
|
|
|
70
70
|
* It works with filesystem locks - so multiple processes can
|
|
71
71
|
* read and write to the store concurrently.
|
|
72
72
|
*/
|
|
73
|
+
interface Store<T extends object> {
|
|
74
|
+
get: (key: string) => Promise<T | undefined>;
|
|
75
|
+
list: () => Promise<StoreEntry[]>;
|
|
76
|
+
lock: (key: string, opts?: {
|
|
77
|
+
force?: boolean;
|
|
78
|
+
}) => Promise<LockedStoreEntry<T>>;
|
|
79
|
+
dispose: () => void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* createFileStore creates a simple file-based store with atomic read/write.
|
|
83
|
+
* All operations are protected by filesystem locks for multi-process safety.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
interface DiskStoreWatcher<T = any> {
|
|
87
|
+
onChange: (callback: (event: {
|
|
88
|
+
key: string;
|
|
89
|
+
value: T | undefined;
|
|
90
|
+
locked: boolean;
|
|
91
|
+
pid?: number;
|
|
92
|
+
}) => void) => () => void;
|
|
93
|
+
dispose: () => void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* createDiskStoreWatcher creates a watcher for the disk store.
|
|
97
|
+
* It watches the disk store for changes and emits events when the
|
|
98
|
+
* store changes.
|
|
99
|
+
*
|
|
100
|
+
* It also polls the store for changes in case the watcher misses
|
|
101
|
+
* any changes.
|
|
102
|
+
*
|
|
103
|
+
* It also debounces the changes to prevent too many events from
|
|
104
|
+
* being emitted.
|
|
105
|
+
*/
|
|
73
106
|
//#endregion
|
|
74
107
|
//#region src/local/types.d.ts
|
|
75
108
|
interface StoredChat {
|
|
@@ -111,7 +144,8 @@ interface ChatState {
|
|
|
111
144
|
}
|
|
112
145
|
interface ChatManagerOptions {
|
|
113
146
|
readonly chatId: string;
|
|
114
|
-
readonly
|
|
147
|
+
readonly store: Store<StoredChat>;
|
|
148
|
+
readonly watcher: DiskStoreWatcher<StoredChat>;
|
|
115
149
|
/**
|
|
116
150
|
* Optional function to filter messages before persisting them.
|
|
117
151
|
* Return undefined to skip persisting the message.
|
|
@@ -142,7 +176,7 @@ declare class ChatManager {
|
|
|
142
176
|
private abortController;
|
|
143
177
|
private isProcessingQueue;
|
|
144
178
|
private listeners;
|
|
145
|
-
private
|
|
179
|
+
private unwatchStore;
|
|
146
180
|
private disposed;
|
|
147
181
|
constructor(options: ChatManagerOptions);
|
|
148
182
|
/**
|
|
@@ -161,6 +195,7 @@ declare class ChatManager {
|
|
|
161
195
|
* Upsert a message to the chat
|
|
162
196
|
*/
|
|
163
197
|
upsertMessage(message: UIMessage, lock?: LockedStoreEntry<StoredChat>): Promise<void>;
|
|
198
|
+
deleteMessage(id: string): Promise<void>;
|
|
164
199
|
/**
|
|
165
200
|
* Send a message to the agent
|
|
166
201
|
*/
|
|
@@ -191,6 +226,14 @@ interface UseChatOptions {
|
|
|
191
226
|
readonly chatId: string;
|
|
192
227
|
readonly agent: Client | undefined;
|
|
193
228
|
readonly chatsDirectory: string;
|
|
229
|
+
/**
|
|
230
|
+
* Optional shared store to use. If not provided, a new one will be created.
|
|
231
|
+
*/
|
|
232
|
+
readonly store?: Store<StoredChat>;
|
|
233
|
+
/**
|
|
234
|
+
* Optional shared watcher to use. If not provided, a new one will be created.
|
|
235
|
+
*/
|
|
236
|
+
readonly watcher?: DiskStoreWatcher<StoredChat>;
|
|
194
237
|
/**
|
|
195
238
|
* Optional function to filter messages before persisting them.
|
|
196
239
|
* Return undefined to skip persisting the message.
|
|
@@ -205,6 +248,7 @@ interface UseChatOptions {
|
|
|
205
248
|
interface UseChat extends ChatState {
|
|
206
249
|
readonly sendMessage: (message: StoredMessage) => Promise<void>;
|
|
207
250
|
readonly upsertMessage: (message: StoredMessage) => Promise<void>;
|
|
251
|
+
readonly deleteMessage: (id: string) => Promise<void>;
|
|
208
252
|
readonly stopStreaming: () => void;
|
|
209
253
|
readonly resetChat: () => Promise<void>;
|
|
210
254
|
readonly clearQueue: () => void;
|
|
@@ -231,6 +275,8 @@ declare function createLocalServer(options: CreateLocalServerOptions): {
|
|
|
231
275
|
url: string;
|
|
232
276
|
runtime: Context;
|
|
233
277
|
chatsDirectory: string;
|
|
278
|
+
chatStore: Store<StoredChat>;
|
|
279
|
+
chatWatcher: DiskStoreWatcher<StoredChat>;
|
|
234
280
|
getChatManager: (chatId: string) => ChatManager;
|
|
235
281
|
listChats: () => Promise<StoreEntry[]>;
|
|
236
282
|
lockChat: (chatId: string) => Promise<LockedStoreEntry<StoredChat>>;
|