@applica-software-guru/persona-sdk 0.1.84 → 0.1.86

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 (67) hide show
  1. package/README.md +92 -0
  2. package/dist/bundle.cjs.js +18 -18
  3. package/dist/bundle.cjs.js.map +1 -1
  4. package/dist/bundle.es.js +3345 -2891
  5. package/dist/bundle.es.js.map +1 -1
  6. package/dist/bundle.iife.js +17 -17
  7. package/dist/bundle.iife.js.map +1 -1
  8. package/dist/bundle.umd.js +17 -17
  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 +4 -3
  39. package/playground/src/chat.tsx +58 -65
  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
package/README.md CHANGED
@@ -236,6 +236,98 @@ 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 apiKey="your-api-key" agentId="your-agent-id" protocols={{ rest: true }} threads={true} messageStorage={storage}>
255
+ {/* Your app */}
256
+ </PersonaRuntimeProvider>;
257
+ ```
258
+
259
+ #### LocalStorageMessageStorage
260
+
261
+ Messages persist across page reloads using browser localStorage.
262
+
263
+ ```tsx
264
+ import { PersonaRuntimeProvider, LocalStorageMessageStorage } from '@applica-software-guru/persona-sdk';
265
+
266
+ const storage = new LocalStorageMessageStorage('my_app_messages_');
267
+
268
+ <PersonaRuntimeProvider apiKey="your-api-key" agentId="your-agent-id" protocols={{ rest: true }} threads={true} messageStorage={storage}>
269
+ {/* Your app */}
270
+ </PersonaRuntimeProvider>;
271
+ ```
272
+
273
+ ### Custom Storage Implementation
274
+
275
+ You can implement your own storage solution by implementing the `MessageStorage` interface:
276
+
277
+ ```tsx
278
+ import { MessageStorage, PersonaMessage, Session } from '@applica-software-guru/persona-sdk';
279
+
280
+ class CustomMessageStorage implements MessageStorage {
281
+ async saveMessages(sessionId: Session, messages: PersonaMessage[]): Promise<void> {
282
+ // Your custom save logic (e.g., IndexedDB, remote API)
283
+ await fetch('/api/save-messages', {
284
+ method: 'POST',
285
+ body: JSON.stringify({ sessionId, messages }),
286
+ });
287
+ }
288
+
289
+ async loadMessages(sessionId: Session): Promise<PersonaMessage[]> {
290
+ // Your custom load logic
291
+ const response = await fetch(`/api/load-messages/${sessionId}`);
292
+ return await response.json();
293
+ }
294
+
295
+ async deleteMessages(sessionId: Session): Promise<void> {
296
+ // Your custom delete logic
297
+ await fetch(`/api/delete-messages/${sessionId}`, { method: 'DELETE' });
298
+ }
299
+
300
+ async clearAll(): Promise<void> {
301
+ // Clear all messages
302
+ await fetch('/api/clear-all-messages', { method: 'DELETE' });
303
+ }
304
+
305
+ async getAllSessionIds(): Promise<Session[]> {
306
+ // Get all session IDs
307
+ const response = await fetch('/api/session-ids');
308
+ return await response.json();
309
+ }
310
+ }
311
+
312
+ const customStorage = new CustomMessageStorage();
313
+
314
+ <PersonaRuntimeProvider
315
+ messageStorage={customStorage}
316
+ // ... other props
317
+ />;
318
+ ```
319
+
320
+ ### How It Works
321
+
322
+ When thread management is enabled (`threads={true}`):
323
+
324
+ - Each thread has its own session ID
325
+ - Messages are automatically saved to storage when updated
326
+ - When switching threads, messages are loaded from storage
327
+ - This allows seamless conversation persistence across sessions
328
+
329
+ ---
330
+
239
331
  ## Protocols Overview
240
332
 
241
333
  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.