@applica-software-guru/persona-sdk 0.1.83 → 0.1.85
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 +104 -0
- package/dist/bundle.cjs.js +18 -30
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +3506 -7033
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +18 -30
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +17 -29
- package/dist/bundle.umd.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/messages.d.ts +2 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/protocol/webrtc.d.ts.map +1 -1
- package/dist/protocol/websocket.d.ts.map +1 -1
- package/dist/runtime/context.d.ts +34 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/handlers.d.ts +21 -0
- package/dist/runtime/handlers.d.ts.map +1 -0
- package/dist/runtime/listeners.d.ts +6 -0
- package/dist/runtime/listeners.d.ts.map +1 -0
- package/dist/runtime/protocols.d.ts +17 -0
- package/dist/runtime/protocols.d.ts.map +1 -0
- package/dist/runtime/threads.d.ts +35 -0
- package/dist/runtime/threads.d.ts.map +1 -0
- package/dist/runtime/utils.d.ts +10 -0
- package/dist/runtime/utils.d.ts.map +1 -0
- package/dist/runtime.d.ts +4 -22
- package/dist/runtime.d.ts.map +1 -1
- package/dist/storage/base.d.ts +19 -0
- package/dist/storage/base.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/persona.d.ts +30 -0
- package/dist/storage/persona.d.ts.map +1 -0
- package/dist/types.d.ts +51 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -10
- package/playground/src/chat.tsx +51 -66
- package/playground/src/components/assistant-ui/thread-list.tsx +45 -12
- package/playground/src/components/assistant-ui/thread.tsx +34 -96
- package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +59 -0
- package/playground/src/components/chat/logging.tsx +53 -0
- package/playground/src/components/ui/input.tsx +21 -0
- package/playground/src/components/ui/separator.tsx +26 -0
- package/playground/src/components/ui/sheet.tsx +139 -0
- package/playground/src/components/ui/sidebar.tsx +619 -0
- package/playground/src/components/ui/skeleton.tsx +13 -0
- package/playground/src/components/ui/tooltip.tsx +0 -2
- package/playground/src/hooks/theme.ts +70 -0
- package/playground/src/hooks/use-mobile.ts +19 -0
- package/src/index.ts +1 -0
- package/src/messages.ts +98 -8
- package/src/protocol/webrtc.ts +1 -0
- package/src/protocol/websocket.ts +5 -2
- package/src/runtime/context.ts +88 -0
- package/src/runtime/handlers.ts +276 -0
- package/src/runtime/index.ts +6 -0
- package/src/runtime/listeners.ts +79 -0
- package/src/runtime/protocols.ts +169 -0
- package/src/runtime/threads.ts +120 -0
- package/src/runtime/utils.ts +46 -0
- package/src/runtime.tsx +226 -326
- package/src/storage/base.ts +21 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/persona.ts +132 -0
- package/src/types.ts +64 -2
- package/vite.config.ts +11 -1
package/README.md
CHANGED
|
@@ -236,6 +236,110 @@ For complete working examples, see the `examples/message-filter-example.tsx` fil
|
|
|
236
236
|
|
|
237
237
|
---
|
|
238
238
|
|
|
239
|
+
## Message Storage
|
|
240
|
+
|
|
241
|
+
The Persona SDK provides a flexible message storage system that allows you to persist conversation history across sessions. By default, messages are stored in memory, but you can easily switch to localStorage or implement your own custom storage solution.
|
|
242
|
+
|
|
243
|
+
### Storage Implementations
|
|
244
|
+
|
|
245
|
+
#### InMemoryMessageStorage (Default)
|
|
246
|
+
|
|
247
|
+
Messages are stored in memory and lost on page reload. This is the default if no storage is specified.
|
|
248
|
+
|
|
249
|
+
```tsx
|
|
250
|
+
import { PersonaRuntimeProvider, InMemoryMessageStorage } from '@applica-software-guru/persona-sdk';
|
|
251
|
+
|
|
252
|
+
const storage = new InMemoryMessageStorage();
|
|
253
|
+
|
|
254
|
+
<PersonaRuntimeProvider
|
|
255
|
+
apiKey="your-api-key"
|
|
256
|
+
agentId="your-agent-id"
|
|
257
|
+
protocols={{ rest: true }}
|
|
258
|
+
enableThreads={true}
|
|
259
|
+
messageStorage={storage}
|
|
260
|
+
>
|
|
261
|
+
{/* Your app */}
|
|
262
|
+
</PersonaRuntimeProvider>;
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### LocalStorageMessageStorage
|
|
266
|
+
|
|
267
|
+
Messages persist across page reloads using browser localStorage.
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
import { PersonaRuntimeProvider, LocalStorageMessageStorage } from '@applica-software-guru/persona-sdk';
|
|
271
|
+
|
|
272
|
+
const storage = new LocalStorageMessageStorage('my_app_messages_');
|
|
273
|
+
|
|
274
|
+
<PersonaRuntimeProvider
|
|
275
|
+
apiKey="your-api-key"
|
|
276
|
+
agentId="your-agent-id"
|
|
277
|
+
protocols={{ rest: true }}
|
|
278
|
+
enableThreads={true}
|
|
279
|
+
messageStorage={storage}
|
|
280
|
+
>
|
|
281
|
+
{/* Your app */}
|
|
282
|
+
</PersonaRuntimeProvider>;
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Custom Storage Implementation
|
|
286
|
+
|
|
287
|
+
You can implement your own storage solution by implementing the `MessageStorage` interface:
|
|
288
|
+
|
|
289
|
+
```tsx
|
|
290
|
+
import { MessageStorage, PersonaMessage, Session } from '@applica-software-guru/persona-sdk';
|
|
291
|
+
|
|
292
|
+
class CustomMessageStorage implements MessageStorage {
|
|
293
|
+
async saveMessages(sessionId: Session, messages: PersonaMessage[]): Promise<void> {
|
|
294
|
+
// Your custom save logic (e.g., IndexedDB, remote API)
|
|
295
|
+
await fetch('/api/save-messages', {
|
|
296
|
+
method: 'POST',
|
|
297
|
+
body: JSON.stringify({ sessionId, messages }),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async loadMessages(sessionId: Session): Promise<PersonaMessage[]> {
|
|
302
|
+
// Your custom load logic
|
|
303
|
+
const response = await fetch(`/api/load-messages/${sessionId}`);
|
|
304
|
+
return await response.json();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async deleteMessages(sessionId: Session): Promise<void> {
|
|
308
|
+
// Your custom delete logic
|
|
309
|
+
await fetch(`/api/delete-messages/${sessionId}`, { method: 'DELETE' });
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async clearAll(): Promise<void> {
|
|
313
|
+
// Clear all messages
|
|
314
|
+
await fetch('/api/clear-all-messages', { method: 'DELETE' });
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async getAllSessionIds(): Promise<Session[]> {
|
|
318
|
+
// Get all session IDs
|
|
319
|
+
const response = await fetch('/api/session-ids');
|
|
320
|
+
return await response.json();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const customStorage = new CustomMessageStorage();
|
|
325
|
+
|
|
326
|
+
<PersonaRuntimeProvider
|
|
327
|
+
messageStorage={customStorage}
|
|
328
|
+
// ... other props
|
|
329
|
+
/>;
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### How It Works
|
|
333
|
+
|
|
334
|
+
When thread management is enabled (`enableThreads={true}`):
|
|
335
|
+
|
|
336
|
+
- Each thread has its own session ID
|
|
337
|
+
- Messages are automatically saved to storage when updated
|
|
338
|
+
- When switching threads, messages are loaded from storage
|
|
339
|
+
- This allows seamless conversation persistence across sessions
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
239
343
|
## Protocols Overview
|
|
240
344
|
|
|
241
345
|
The Persona SDK supports multiple communication protocols to provide flexibility and performance. These protocols can work together, sharing the same session and data, to ensure the best possible experience.
|