@applica-software-guru/persona-sdk 0.1.48 → 0.1.52

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 (38) hide show
  1. package/.nvmrc +1 -1
  2. package/bitbucket-pipelines.yml +1 -1
  3. package/components.json +21 -0
  4. package/dist/bundle.cjs.js +2 -2
  5. package/dist/bundle.cjs.js.map +1 -1
  6. package/dist/bundle.es.js +280 -251
  7. package/dist/bundle.es.js.map +1 -1
  8. package/dist/bundle.iife.js +2 -2
  9. package/dist/bundle.iife.js.map +1 -1
  10. package/dist/bundle.umd.js +2 -2
  11. package/dist/bundle.umd.js.map +1 -1
  12. package/dist/protocol/base.d.ts +2 -2
  13. package/dist/protocol/base.d.ts.map +1 -1
  14. package/dist/protocol/rest.d.ts +2 -2
  15. package/dist/protocol/rest.d.ts.map +1 -1
  16. package/dist/protocol/transaction.d.ts +2 -2
  17. package/dist/protocol/transaction.d.ts.map +1 -1
  18. package/dist/protocol/webrtc.d.ts +3 -3
  19. package/dist/protocol/webrtc.d.ts.map +1 -1
  20. package/dist/protocol/websocket.d.ts +2 -2
  21. package/dist/protocol/websocket.d.ts.map +1 -1
  22. package/dist/runtime.d.ts.map +1 -1
  23. package/dist/types.d.ts +6 -2
  24. package/dist/types.d.ts.map +1 -1
  25. package/package.json +12 -6
  26. package/playground/src/chat.tsx +4 -1
  27. package/playground/src/components/assistant-ui/attachment.tsx +214 -0
  28. package/playground/src/components/assistant-ui/thread.tsx +5 -1
  29. package/playground/src/components/ui/dialog.tsx +133 -0
  30. package/playground/src/lib/utils.ts +3 -3
  31. package/playground/src/styles.css +119 -0
  32. package/src/protocol/base.ts +2 -2
  33. package/src/protocol/rest.ts +2 -2
  34. package/src/protocol/transaction.ts +2 -2
  35. package/src/protocol/webrtc.ts +5 -5
  36. package/src/protocol/websocket.ts +2 -2
  37. package/src/runtime.tsx +53 -2
  38. package/src/types.ts +8 -3
package/src/runtime.tsx CHANGED
@@ -1,5 +1,11 @@
1
1
  import { useState, useEffect, useCallback, PropsWithChildren, createContext, useContext, useMemo, useRef } from 'react';
2
- import { useExternalStoreRuntime, AppendMessage, AssistantRuntimeProvider } from '@assistant-ui/react';
2
+ import {
3
+ useExternalStoreRuntime,
4
+ AppendMessage,
5
+ AssistantRuntimeProvider,
6
+ CompositeAttachmentAdapter,
7
+ SimpleImageAttachmentAdapter,
8
+ } from '@assistant-ui/react';
3
9
  import {
4
10
  PersonaConfig,
5
11
  PersonaMessage,
@@ -30,6 +36,24 @@ type PersonaRuntimeContextType = {
30
36
 
31
37
  const PersonaRuntimeContext = createContext<PersonaRuntimeContextType | undefined>(undefined);
32
38
 
39
+ function fileToBase64(file: File): Promise<string> {
40
+ return new Promise((resolve, reject) => {
41
+ const reader = new FileReader();
42
+ reader.readAsDataURL(file); // Converte il file in Data URL (base64)
43
+
44
+ reader.onload = () => {
45
+ //remove data url using ;base64, to split
46
+ const base64 = reader.result as string;
47
+ const base64WithoutPrefix = base64.split(';base64,')[1];
48
+ resolve(base64WithoutPrefix);
49
+ };
50
+
51
+ reader.onerror = (error) => {
52
+ reject(error);
53
+ };
54
+ });
55
+ }
56
+
33
57
  function PersonaRuntimeProviderInner({
34
58
  dev = false,
35
59
  protocols: _protocols,
@@ -152,8 +176,32 @@ function PersonaRuntimeProviderInner({
152
176
  setIsRunning(true);
153
177
 
154
178
  const protocol = protocols.sort((a, b) => b.getPriority() - a.getPriority()).find((protocol) => protocol.status === 'connected');
179
+ const content: Array<PersonaMessage> = [];
180
+ if (message.attachments) {
181
+ for (const attachment of message.attachments) {
182
+ if (attachment.contentType.startsWith('image/') && attachment.file) {
183
+ content.push({
184
+ role: 'user',
185
+ image: {
186
+ contentType: attachment.contentType,
187
+ content: await fileToBase64(attachment.file),
188
+ },
189
+ text: '',
190
+ type: 'text',
191
+ });
192
+ }
193
+ }
194
+ }
155
195
 
156
- await protocol?.send(input);
196
+ if (message.content) {
197
+ content.push({
198
+ role: 'user',
199
+ text: message.content[0].text,
200
+ type: 'text',
201
+ });
202
+ }
203
+ logger?.debug('Sending message:', content);
204
+ await protocol?.send(content);
157
205
 
158
206
  setIsRunning(false);
159
207
  };
@@ -176,6 +224,9 @@ function PersonaRuntimeProviderInner({
176
224
  onNew,
177
225
  onCancel,
178
226
  onReload,
227
+ adapters: {
228
+ attachments: new CompositeAttachmentAdapter([new SimpleImageAttachmentAdapter()]),
229
+ },
179
230
  });
180
231
 
181
232
  return (
package/src/types.ts CHANGED
@@ -53,11 +53,17 @@ export type PersonaTransaction = {
53
53
  context: PersonaAgentContext;
54
54
  };
55
55
 
56
+ export type PersonaImage = {
57
+ content: string;
58
+ contentType: string;
59
+ };
60
+
56
61
  export type PersonaMessage = {
57
62
  id?: string | null;
58
63
  protocol?: string;
59
64
  thought?: string;
60
- text: string;
65
+ text: string; //todo: puo essere null
66
+ image?: PersonaImage;
61
67
  type: 'reasoning' | 'text' | 'transaction';
62
68
  role: 'user' | 'assistant' | 'function';
63
69
  files?: PersonaFile[];
@@ -92,7 +98,6 @@ export type PersonaWebRTCConfig = PersonaBaseConfig & {
92
98
  };
93
99
 
94
100
  export type Session = string | null | undefined;
95
- export type Message = string;
96
101
 
97
102
  export type MessageListenerCallback = (message: PersonaPayload) => void;
98
103
  export type StatusChangeCallback = (status: ProtocolStatus) => void;
@@ -118,7 +123,7 @@ export interface PersonaProtocol {
118
123
 
119
124
  setSession: (session: Session) => Promise<void>;
120
125
 
121
- send: (message: Message) => Promise<void>;
126
+ send: (content: Array<PersonaMessage> | PersonaMessage) => Promise<void>;
122
127
  clearListeners: () => void;
123
128
  addStatusChangeListener: (callback: StatusChangeCallback) => void;
124
129
  addMessageListener: (callback: MessageListenerCallback) => void;