@applica-software-guru/persona-sdk 0.1.72 → 0.1.74
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/bundle.cjs.js +8 -8
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +438 -438
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +8 -8
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +8 -8
- package/dist/bundle.umd.js.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/messages.ts +11 -10
- package/src/runtime.tsx +6 -6
- package/src/types.ts +4 -4
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAmB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAOzE;AACD,iBAAS,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CA+CnE;AAED,iBAAS,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAmB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAOzE;AACD,iBAAS,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CA+CnE;AAED,iBAAS,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,iBAAiB,CAkClE;AAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export type PersonaMessage = {
|
|
|
85
85
|
image?: PersonaImage;
|
|
86
86
|
type: 'reasoning' | 'text' | 'transaction' | 'command';
|
|
87
87
|
role: 'user' | 'assistant' | 'function';
|
|
88
|
-
|
|
88
|
+
file?: PersonaFile;
|
|
89
89
|
sources?: PersonaSource[];
|
|
90
90
|
sessionId?: string;
|
|
91
91
|
finishReason?: 'stop' | 'function_call';
|
|
@@ -108,7 +108,7 @@ export type PersonaWebRTCConfig = PersonaBaseConfig & {
|
|
|
108
108
|
onDataMessage?: (msg: MessageEvent) => void;
|
|
109
109
|
};
|
|
110
110
|
export type Session = string | null | undefined;
|
|
111
|
-
export type
|
|
111
|
+
export type TransformMessages = (messages: PersonaMessage[]) => PersonaMessage[];
|
|
112
112
|
export type MessageListenerCallback = (message: PersonaPacket) => void;
|
|
113
113
|
export type StatusChangeCallback = (status: ProtocolStatus) => void;
|
|
114
114
|
export type ProtocolStatus = 'disconnected' | 'connecting' | 'connected';
|
|
@@ -155,8 +155,8 @@ export type PersonaConfig = PersonaBaseConfig & PersonaProtocolBaseConfig & {
|
|
|
155
155
|
*/
|
|
156
156
|
tools?: PersonaTools | ToolInstance[];
|
|
157
157
|
/**
|
|
158
|
-
* Optional message
|
|
158
|
+
* Optional message transform function that processes messages before they are displayed
|
|
159
159
|
*/
|
|
160
|
-
|
|
160
|
+
transformMessages?: TransformMessages;
|
|
161
161
|
};
|
|
162
162
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,c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AC;QAC3C,MAAM,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC;QAC7C,SAAS,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC;KACjD,CAAC;IAEN;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;IAEtC;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC,CAAC"}
|
package/package.json
CHANGED
package/src/messages.ts
CHANGED
|
@@ -39,8 +39,8 @@ function parseMessages(messages: PersonaMessage[]): PersonaMessage[] {
|
|
|
39
39
|
message.protocol === currentMessage.protocol &&
|
|
40
40
|
(currentMessage.role === message.role || message.finishReason === 'stop')
|
|
41
41
|
) {
|
|
42
|
-
currentMessage.text += message.text;
|
|
43
|
-
currentMessage.
|
|
42
|
+
currentMessage.text += message.file ? '' : message.text;
|
|
43
|
+
currentMessage.file = currentMessage.file || message.file;
|
|
44
44
|
} else {
|
|
45
45
|
if (currentMessage) {
|
|
46
46
|
outputMessages.push(currentMessage);
|
|
@@ -59,15 +59,16 @@ function parseMessages(messages: PersonaMessage[]): PersonaMessage[] {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function convertMessage(message: PersonaMessage): ThreadMessageLike {
|
|
62
|
-
const files =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
({
|
|
62
|
+
const files = message.file
|
|
63
|
+
? [
|
|
64
|
+
{
|
|
66
65
|
type: 'file',
|
|
67
|
-
data: file.url,
|
|
68
|
-
mimeType: file.contentType,
|
|
69
|
-
} as FileContentPart
|
|
70
|
-
|
|
66
|
+
data: message.file.url,
|
|
67
|
+
mimeType: message.file.contentType,
|
|
68
|
+
} as FileContentPart,
|
|
69
|
+
]
|
|
70
|
+
: [];
|
|
71
|
+
|
|
71
72
|
if (message.role === 'function') {
|
|
72
73
|
return {
|
|
73
74
|
id: message.id!,
|
package/src/runtime.tsx
CHANGED
|
@@ -83,7 +83,7 @@ function PersonaRuntimeProviderInner({
|
|
|
83
83
|
logger,
|
|
84
84
|
children,
|
|
85
85
|
session: defaultSession = 'new',
|
|
86
|
-
|
|
86
|
+
transformMessages,
|
|
87
87
|
...config
|
|
88
88
|
}: Readonly<PersonaConfig>) {
|
|
89
89
|
const [isRunning, setIsRunning] = useState(false);
|
|
@@ -212,7 +212,7 @@ function PersonaRuntimeProviderInner({
|
|
|
212
212
|
const personaMessage = message.payload as PersonaMessage;
|
|
213
213
|
setMessages((currentConversation) => {
|
|
214
214
|
const newMessages = parseMessages([...currentConversation, ...[{ ...personaMessage, protocol: protocol.getName() }]]);
|
|
215
|
-
return
|
|
215
|
+
return transformMessages ? transformMessages(newMessages) : newMessages;
|
|
216
216
|
});
|
|
217
217
|
} else if (message.type === 'reasoning') {
|
|
218
218
|
const reasoning = message.payload as PersonaReasoning;
|
|
@@ -225,7 +225,7 @@ function PersonaRuntimeProviderInner({
|
|
|
225
225
|
|
|
226
226
|
setMessages((currentConversation) => {
|
|
227
227
|
const newMessages = parseMessages([...currentConversation, ...[{ ...personaMessage, protocol: protocol.getName() }]]);
|
|
228
|
-
return
|
|
228
|
+
return transformMessages ? transformMessages(newMessages) : newMessages;
|
|
229
229
|
});
|
|
230
230
|
} else if (message.type === 'transaction') {
|
|
231
231
|
protocols.filter((p) => p !== protocol).forEach((p) => p.onTransaction(message.payload as PersonaTransaction));
|
|
@@ -236,7 +236,7 @@ function PersonaRuntimeProviderInner({
|
|
|
236
236
|
protocol.connect(session);
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
|
-
}, [session, protocols, logger, protocolsStatus]);
|
|
239
|
+
}, [session, protocols, logger, protocolsStatus, transformMessages]);
|
|
240
240
|
|
|
241
241
|
const onNew = async (message: AppendMessage) => {
|
|
242
242
|
if (message.content[0]?.type !== 'text') throw new Error('Only text messages are supported');
|
|
@@ -247,7 +247,7 @@ function PersonaRuntimeProviderInner({
|
|
|
247
247
|
...currentConversation,
|
|
248
248
|
{ role: 'assistant' as const, type: 'text' as const, text: 'No protocol is connected.' },
|
|
249
249
|
];
|
|
250
|
-
return
|
|
250
|
+
return transformMessages ? transformMessages(newMessages) : newMessages;
|
|
251
251
|
});
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
@@ -255,7 +255,7 @@ function PersonaRuntimeProviderInner({
|
|
|
255
255
|
const input = message.content[0].text;
|
|
256
256
|
setMessages((currentConversation) => {
|
|
257
257
|
const newMessages = [...currentConversation, { role: 'user' as const, type: 'text' as const, text: input }];
|
|
258
|
-
return
|
|
258
|
+
return transformMessages ? transformMessages(newMessages) : newMessages;
|
|
259
259
|
});
|
|
260
260
|
setIsRunning(true);
|
|
261
261
|
|
package/src/types.ts
CHANGED
|
@@ -101,7 +101,7 @@ export type PersonaMessage = {
|
|
|
101
101
|
image?: PersonaImage;
|
|
102
102
|
type: 'reasoning' | 'text' | 'transaction' | 'command';
|
|
103
103
|
role: 'user' | 'assistant' | 'function';
|
|
104
|
-
|
|
104
|
+
file?: PersonaFile;
|
|
105
105
|
sources?: PersonaSource[];
|
|
106
106
|
sessionId?: string;
|
|
107
107
|
finishReason?: 'stop' | 'function_call';
|
|
@@ -130,7 +130,7 @@ export type PersonaWebRTCConfig = PersonaBaseConfig & {
|
|
|
130
130
|
|
|
131
131
|
export type Session = string | null | undefined;
|
|
132
132
|
|
|
133
|
-
export type
|
|
133
|
+
export type TransformMessages = (messages: PersonaMessage[]) => PersonaMessage[];
|
|
134
134
|
|
|
135
135
|
export type MessageListenerCallback = (message: PersonaPacket) => void;
|
|
136
136
|
export type StatusChangeCallback = (status: ProtocolStatus) => void;
|
|
@@ -191,7 +191,7 @@ export type PersonaConfig = PersonaBaseConfig &
|
|
|
191
191
|
tools?: PersonaTools | ToolInstance[];
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
|
-
* Optional message
|
|
194
|
+
* Optional message transform function that processes messages before they are displayed
|
|
195
195
|
*/
|
|
196
|
-
|
|
196
|
+
transformMessages?: TransformMessages;
|
|
197
197
|
};
|