@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.
Files changed (68) hide show
  1. package/README.md +104 -0
  2. package/dist/bundle.cjs.js +18 -30
  3. package/dist/bundle.cjs.js.map +1 -1
  4. package/dist/bundle.es.js +3506 -7033
  5. package/dist/bundle.es.js.map +1 -1
  6. package/dist/bundle.iife.js +18 -30
  7. package/dist/bundle.iife.js.map +1 -1
  8. package/dist/bundle.umd.js +17 -29
  9. package/dist/bundle.umd.js.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/messages.d.ts +2 -0
  13. package/dist/messages.d.ts.map +1 -1
  14. package/dist/protocol/webrtc.d.ts.map +1 -1
  15. package/dist/protocol/websocket.d.ts.map +1 -1
  16. package/dist/runtime/context.d.ts +34 -0
  17. package/dist/runtime/context.d.ts.map +1 -0
  18. package/dist/runtime/handlers.d.ts +21 -0
  19. package/dist/runtime/handlers.d.ts.map +1 -0
  20. package/dist/runtime/listeners.d.ts +6 -0
  21. package/dist/runtime/listeners.d.ts.map +1 -0
  22. package/dist/runtime/protocols.d.ts +17 -0
  23. package/dist/runtime/protocols.d.ts.map +1 -0
  24. package/dist/runtime/threads.d.ts +35 -0
  25. package/dist/runtime/threads.d.ts.map +1 -0
  26. package/dist/runtime/utils.d.ts +10 -0
  27. package/dist/runtime/utils.d.ts.map +1 -0
  28. package/dist/runtime.d.ts +4 -22
  29. package/dist/runtime.d.ts.map +1 -1
  30. package/dist/storage/base.d.ts +19 -0
  31. package/dist/storage/base.d.ts.map +1 -0
  32. package/dist/storage/index.d.ts +3 -0
  33. package/dist/storage/index.d.ts.map +1 -0
  34. package/dist/storage/persona.d.ts +30 -0
  35. package/dist/storage/persona.d.ts.map +1 -0
  36. package/dist/types.d.ts +51 -1
  37. package/dist/types.d.ts.map +1 -1
  38. package/package.json +16 -10
  39. package/playground/src/chat.tsx +51 -66
  40. package/playground/src/components/assistant-ui/thread-list.tsx +45 -12
  41. package/playground/src/components/assistant-ui/thread.tsx +34 -96
  42. package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +59 -0
  43. package/playground/src/components/chat/logging.tsx +53 -0
  44. package/playground/src/components/ui/input.tsx +21 -0
  45. package/playground/src/components/ui/separator.tsx +26 -0
  46. package/playground/src/components/ui/sheet.tsx +139 -0
  47. package/playground/src/components/ui/sidebar.tsx +619 -0
  48. package/playground/src/components/ui/skeleton.tsx +13 -0
  49. package/playground/src/components/ui/tooltip.tsx +0 -2
  50. package/playground/src/hooks/theme.ts +70 -0
  51. package/playground/src/hooks/use-mobile.ts +19 -0
  52. package/src/index.ts +1 -0
  53. package/src/messages.ts +98 -8
  54. package/src/protocol/webrtc.ts +1 -0
  55. package/src/protocol/websocket.ts +5 -2
  56. package/src/runtime/context.ts +88 -0
  57. package/src/runtime/handlers.ts +276 -0
  58. package/src/runtime/index.ts +6 -0
  59. package/src/runtime/listeners.ts +79 -0
  60. package/src/runtime/protocols.ts +169 -0
  61. package/src/runtime/threads.ts +120 -0
  62. package/src/runtime/utils.ts +46 -0
  63. package/src/runtime.tsx +226 -326
  64. package/src/storage/base.ts +21 -0
  65. package/src/storage/index.ts +2 -0
  66. package/src/storage/persona.ts +132 -0
  67. package/src/types.ts +64 -2
  68. 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.