@applica-software-guru/persona-sdk 0.1.62 → 0.1.63
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 +3 -3
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +270 -269
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +3 -3
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +3 -3
- package/dist/bundle.umd.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/runtime.tsx +2 -1
- package/src/types.ts +5 -0
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (
|
|
4
|
-
import { createContext as
|
|
5
|
-
import { useExternalStoreRuntime as
|
|
6
|
-
var
|
|
1
|
+
var K = Object.defineProperty;
|
|
2
|
+
var q = (i, e, t) => e in i ? K(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var o = (i, e, t) => q(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { createContext as B, useContext as A, useState as R, useRef as Y, useMemo as G, useEffect as V, useCallback as v } from "react";
|
|
5
|
+
import { useExternalStoreRuntime as H, CompositeAttachmentAdapter as Q, SimpleImageAttachmentAdapter as X, AssistantRuntimeProvider as Z } from "@assistant-ui/react";
|
|
6
|
+
var W = { exports: {} }, S = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
@@ -13,75 +13,75 @@ var U = { exports: {} }, S = {};
|
|
|
13
13
|
* This source code is licensed under the MIT license found in the
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*/
|
|
16
|
-
var
|
|
17
|
-
function
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
function t(
|
|
22
|
-
var
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
for (var l in
|
|
26
|
-
l !== "key" && (
|
|
27
|
-
} else
|
|
28
|
-
return
|
|
29
|
-
$$typeof:
|
|
30
|
-
type:
|
|
31
|
-
key:
|
|
32
|
-
ref:
|
|
33
|
-
props:
|
|
16
|
+
var I;
|
|
17
|
+
function tt() {
|
|
18
|
+
if (I) return S;
|
|
19
|
+
I = 1;
|
|
20
|
+
var i = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
21
|
+
function t(s, n, a) {
|
|
22
|
+
var r = null;
|
|
23
|
+
if (a !== void 0 && (r = "" + a), n.key !== void 0 && (r = "" + n.key), "key" in n) {
|
|
24
|
+
a = {};
|
|
25
|
+
for (var l in n)
|
|
26
|
+
l !== "key" && (a[l] = n[l]);
|
|
27
|
+
} else a = n;
|
|
28
|
+
return n = a.ref, {
|
|
29
|
+
$$typeof: i,
|
|
30
|
+
type: s,
|
|
31
|
+
key: r,
|
|
32
|
+
ref: n !== void 0 ? n : null,
|
|
33
|
+
props: a
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
return S.Fragment = e, S.jsx = t, S.jsxs = t, S;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
function
|
|
41
|
-
return
|
|
38
|
+
W.exports = tt();
|
|
39
|
+
var $ = W.exports;
|
|
40
|
+
function et(i) {
|
|
41
|
+
return i.filter((e) => {
|
|
42
42
|
var t;
|
|
43
43
|
return e.finishReason === "stop" ? e.text !== null && ((t = e.text) == null ? void 0 : t.trim()) !== "" : !0;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function M(i) {
|
|
47
47
|
const e = [];
|
|
48
48
|
let t = null;
|
|
49
|
-
for (const
|
|
50
|
-
|
|
49
|
+
for (const n of i)
|
|
50
|
+
n.type !== "transaction" && (n.type === "reasoning" ? (t != null && (e.push(t), t = null), e.push(n)) : n.functionCalls ? (t && e.push(t), e.push(n), t = null) : n.functionResponse ? e[e.length - 1] = {
|
|
51
51
|
...e[e.length - 1],
|
|
52
|
-
functionResponse:
|
|
53
|
-
} : t &&
|
|
54
|
-
...
|
|
52
|
+
functionResponse: n.functionResponse
|
|
53
|
+
} : t && n.protocol === t.protocol && (t.role === n.role || n.finishReason === "stop") ? (t.text += n.text, t.files = [...t.files ?? [], ...n.files ?? []]) : (t && e.push(t), t = {
|
|
54
|
+
...n
|
|
55
55
|
}));
|
|
56
|
-
return t && e.push(t),
|
|
56
|
+
return t && e.push(t), et(e);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
var t,
|
|
60
|
-
const e = ((t =
|
|
61
|
-
(
|
|
58
|
+
function st(i) {
|
|
59
|
+
var t, s;
|
|
60
|
+
const e = ((t = i.files) == null ? void 0 : t.map(
|
|
61
|
+
(n) => ({
|
|
62
62
|
type: "file",
|
|
63
|
-
data:
|
|
64
|
-
mimeType:
|
|
63
|
+
data: n.url,
|
|
64
|
+
mimeType: n.contentType
|
|
65
65
|
})
|
|
66
66
|
)) ?? [];
|
|
67
|
-
return
|
|
68
|
-
id:
|
|
67
|
+
return i.role === "function" ? {
|
|
68
|
+
id: i.id,
|
|
69
69
|
role: "assistant",
|
|
70
|
-
status: (
|
|
71
|
-
content: ((
|
|
72
|
-
var
|
|
70
|
+
status: (i == null ? void 0 : i.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
|
|
71
|
+
content: ((s = i.functionCalls) == null ? void 0 : s.map((n) => {
|
|
72
|
+
var a;
|
|
73
73
|
return {
|
|
74
74
|
type: "tool-call",
|
|
75
|
-
toolName:
|
|
76
|
-
toolCallId:
|
|
77
|
-
args:
|
|
78
|
-
result: (
|
|
75
|
+
toolName: n.name,
|
|
76
|
+
toolCallId: n.id,
|
|
77
|
+
args: n.args,
|
|
78
|
+
result: (a = i.functionResponse) == null ? void 0 : a.result
|
|
79
79
|
};
|
|
80
80
|
})) ?? []
|
|
81
81
|
} : {
|
|
82
|
-
id:
|
|
83
|
-
role:
|
|
84
|
-
content:
|
|
82
|
+
id: i.id,
|
|
83
|
+
role: i.role,
|
|
84
|
+
content: i.type === "reasoning" ? [{ type: "reasoning", text: i.text }, ...e] : [{ type: "text", text: i.text }, ...e]
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
class E {
|
|
@@ -103,7 +103,7 @@ class E {
|
|
|
103
103
|
}
|
|
104
104
|
async notifyPackets(e) {
|
|
105
105
|
e.forEach((t) => {
|
|
106
|
-
this.messageCallbacks.forEach((
|
|
106
|
+
this.messageCallbacks.forEach((s) => s(t));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
async setSession(e) {
|
|
@@ -111,7 +111,7 @@ class E {
|
|
|
111
111
|
}
|
|
112
112
|
async setStatus(e) {
|
|
113
113
|
const t = this.status !== e;
|
|
114
|
-
this.status = e, t && this.statusChangeCallbacks.forEach((
|
|
114
|
+
this.status = e, t && this.statusChangeCallbacks.forEach((s) => s(e));
|
|
115
115
|
}
|
|
116
116
|
clearListeners() {
|
|
117
117
|
this.statusChangeCallbacks = [], this.messageCallbacks = [];
|
|
@@ -119,7 +119,7 @@ class E {
|
|
|
119
119
|
onTransaction(e) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class
|
|
122
|
+
class z extends E {
|
|
123
123
|
constructor(t) {
|
|
124
124
|
super();
|
|
125
125
|
o(this, "status");
|
|
@@ -146,29 +146,29 @@ class M extends E {
|
|
|
146
146
|
this.session = t;
|
|
147
147
|
}
|
|
148
148
|
async sendPacket(t) {
|
|
149
|
-
var g,
|
|
150
|
-
const { apiUrl:
|
|
149
|
+
var g, w;
|
|
150
|
+
const { apiUrl: s, apiKey: n, agentId: a } = this.config, r = this.session ?? "new";
|
|
151
151
|
if (t.type === "command" && ((g = t == null ? void 0 : t.payload) == null ? void 0 : g.command) == "set_initial_context") {
|
|
152
|
-
this.context = (
|
|
152
|
+
this.context = (w = t == null ? void 0 : t.payload) == null ? void 0 : w.arguments;
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
|
-
const l = t.payload,
|
|
156
|
-
body: JSON.stringify({ agentId:
|
|
155
|
+
const l = t.payload, p = await (await fetch(`${s}/sessions/${r}/messages`, {
|
|
156
|
+
body: JSON.stringify({ agentId: a, userMessage: l, initial_context: this.context }),
|
|
157
157
|
method: "POST",
|
|
158
158
|
headers: {
|
|
159
159
|
"Content-Type": "application/json",
|
|
160
|
-
"x-persona-apikey":
|
|
160
|
+
"x-persona-apikey": n
|
|
161
161
|
}
|
|
162
162
|
})).json();
|
|
163
163
|
this.notifyPackets(
|
|
164
|
-
|
|
164
|
+
p.response.messages.map((T) => ({
|
|
165
165
|
type: "message",
|
|
166
|
-
payload:
|
|
166
|
+
payload: T
|
|
167
167
|
}))
|
|
168
168
|
);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
class
|
|
171
|
+
class D extends E {
|
|
172
172
|
constructor(t) {
|
|
173
173
|
super();
|
|
174
174
|
o(this, "status");
|
|
@@ -185,28 +185,28 @@ class z extends E {
|
|
|
185
185
|
return 500;
|
|
186
186
|
}
|
|
187
187
|
async syncSession(t) {
|
|
188
|
-
var
|
|
189
|
-
(
|
|
188
|
+
var s;
|
|
189
|
+
(s = this.config.logger) == null || s.debug("Syncing session with WebSocket protocol:", t), this.session = t, this.webSocket && this.status === "connected" && (this.disconnect(), this.connect(t));
|
|
190
190
|
}
|
|
191
191
|
connect(t) {
|
|
192
192
|
var l;
|
|
193
193
|
if (this.webSocket !== null && this.status === "connected")
|
|
194
194
|
return Promise.resolve(this.session);
|
|
195
|
-
const
|
|
196
|
-
(l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:",
|
|
197
|
-
const
|
|
198
|
-
return this.setStatus("connecting"), this.webSocket = new WebSocket(
|
|
195
|
+
const s = t || this.session || "new";
|
|
196
|
+
(l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", s);
|
|
197
|
+
const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
|
|
198
|
+
return this.setStatus("connecting"), this.webSocket = new WebSocket(r), this.webSocket.addEventListener("open", () => {
|
|
199
199
|
this.setStatus("connected");
|
|
200
200
|
}), this.webSocket.addEventListener("message", (u) => {
|
|
201
|
-
const
|
|
202
|
-
this.notifyPacket(
|
|
201
|
+
const p = JSON.parse(u.data);
|
|
202
|
+
this.notifyPacket(p);
|
|
203
203
|
}), this.webSocket.addEventListener("close", () => {
|
|
204
204
|
var u;
|
|
205
205
|
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.warn("WebSocket connection closed");
|
|
206
206
|
}), this.webSocket.addEventListener("error", (u) => {
|
|
207
|
-
var
|
|
208
|
-
this.setStatus("disconnected"), this.webSocket = null, (
|
|
209
|
-
}), Promise.resolve(
|
|
207
|
+
var p;
|
|
208
|
+
this.setStatus("disconnected"), this.webSocket = null, (p = this.config.logger) == null || p.error("WebSocket error", u);
|
|
209
|
+
}), Promise.resolve(s);
|
|
210
210
|
}
|
|
211
211
|
disconnect() {
|
|
212
212
|
var t;
|
|
@@ -216,7 +216,7 @@ class z extends E {
|
|
|
216
216
|
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify(t)), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
class
|
|
219
|
+
class nt {
|
|
220
220
|
constructor(e) {
|
|
221
221
|
o(this, "config");
|
|
222
222
|
o(this, "pc", null);
|
|
@@ -234,13 +234,13 @@ class st {
|
|
|
234
234
|
this.config = e;
|
|
235
235
|
}
|
|
236
236
|
async connect(e) {
|
|
237
|
-
var
|
|
237
|
+
var s;
|
|
238
238
|
if (this.isConnected) return;
|
|
239
239
|
this.isConnected = !0;
|
|
240
240
|
try {
|
|
241
241
|
this.localStream = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
242
|
-
} catch (
|
|
243
|
-
(
|
|
242
|
+
} catch (n) {
|
|
243
|
+
(s = this.config.logger) == null || s.error("Error accessing microphone:", n);
|
|
244
244
|
return;
|
|
245
245
|
}
|
|
246
246
|
this.pc = new RTCPeerConnection({
|
|
@@ -254,68 +254,68 @@ class st {
|
|
|
254
254
|
credential: "webrtc"
|
|
255
255
|
}
|
|
256
256
|
]
|
|
257
|
-
}), this.localStream.getTracks().forEach((
|
|
258
|
-
this.pc.addTrack(
|
|
259
|
-
}), this.pc.ontrack = (
|
|
260
|
-
|
|
261
|
-
this.remoteStream.addTrack(
|
|
257
|
+
}), this.localStream.getTracks().forEach((n) => {
|
|
258
|
+
this.pc.addTrack(n, this.localStream);
|
|
259
|
+
}), this.pc.ontrack = (n) => {
|
|
260
|
+
n.streams[0].getTracks().forEach((r) => {
|
|
261
|
+
this.remoteStream.addTrack(r);
|
|
262
262
|
}), this.audioCtx || this._startAnalyzers();
|
|
263
|
-
const
|
|
264
|
-
|
|
263
|
+
const a = new Audio();
|
|
264
|
+
a.srcObject = this.remoteStream, a.play().catch((r) => {
|
|
265
265
|
var l;
|
|
266
|
-
(l = this.config.logger) == null || l.error("Error playing remote audio:",
|
|
266
|
+
(l = this.config.logger) == null || l.error("Error playing remote audio:", r);
|
|
267
267
|
});
|
|
268
|
-
}, this.pc.onicecandidate = (
|
|
269
|
-
var
|
|
270
|
-
|
|
268
|
+
}, this.pc.onicecandidate = (n) => {
|
|
269
|
+
var a;
|
|
270
|
+
n.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
|
|
271
271
|
JSON.stringify({
|
|
272
272
|
type: "CANDIDATE",
|
|
273
273
|
src: "client",
|
|
274
|
-
payload: { candidate:
|
|
274
|
+
payload: { candidate: n.candidate }
|
|
275
275
|
})
|
|
276
276
|
);
|
|
277
|
-
}, this.pc.ondatachannel = (
|
|
278
|
-
const
|
|
279
|
-
|
|
277
|
+
}, this.pc.ondatachannel = (n) => {
|
|
278
|
+
const a = n.channel;
|
|
279
|
+
a.onmessage = (r) => {
|
|
280
280
|
this.messageCallbacks.forEach((l) => {
|
|
281
|
-
l(
|
|
281
|
+
l(r);
|
|
282
282
|
});
|
|
283
283
|
};
|
|
284
284
|
};
|
|
285
285
|
const t = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
|
|
286
286
|
this.ws = new WebSocket(`${t}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
|
|
287
287
|
var l, u;
|
|
288
|
-
const
|
|
289
|
-
await this.pc.setLocalDescription(
|
|
290
|
-
const
|
|
288
|
+
const n = await this.pc.createOffer();
|
|
289
|
+
await this.pc.setLocalDescription(n);
|
|
290
|
+
const a = {
|
|
291
291
|
apiKey: this.config.apiKey,
|
|
292
292
|
agentId: this.config.agentId,
|
|
293
293
|
sessionCode: e
|
|
294
294
|
};
|
|
295
|
-
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ",
|
|
296
|
-
const
|
|
295
|
+
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", a);
|
|
296
|
+
const r = {
|
|
297
297
|
type: "OFFER",
|
|
298
298
|
src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
|
|
299
299
|
payload: {
|
|
300
300
|
sdp: {
|
|
301
|
-
sdp:
|
|
302
|
-
type:
|
|
301
|
+
sdp: n.sdp,
|
|
302
|
+
type: n.type
|
|
303
303
|
},
|
|
304
304
|
connectionId: (Date.now() % 1e6).toString(),
|
|
305
|
-
metadata:
|
|
305
|
+
metadata: a
|
|
306
306
|
}
|
|
307
307
|
};
|
|
308
|
-
this.ws.send(JSON.stringify(
|
|
309
|
-
}, this.ws.onmessage = async (
|
|
310
|
-
var
|
|
311
|
-
const
|
|
312
|
-
if (
|
|
313
|
-
await this.pc.setRemoteDescription(new RTCSessionDescription(
|
|
314
|
-
else if (
|
|
308
|
+
this.ws.send(JSON.stringify(r));
|
|
309
|
+
}, this.ws.onmessage = async (n) => {
|
|
310
|
+
var r;
|
|
311
|
+
const a = JSON.parse(n.data);
|
|
312
|
+
if (a.type === "ANSWER")
|
|
313
|
+
await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
|
|
314
|
+
else if (a.type === "CANDIDATE")
|
|
315
315
|
try {
|
|
316
|
-
await this.pc.addIceCandidate(new RTCIceCandidate(
|
|
316
|
+
await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
|
|
317
317
|
} catch (l) {
|
|
318
|
-
(
|
|
318
|
+
(r = this.config.logger) == null || r.error("Error adding ICE candidate:", l);
|
|
319
319
|
}
|
|
320
320
|
}, this.ws.onclose = () => {
|
|
321
321
|
this._stopAnalyzers();
|
|
@@ -336,18 +336,18 @@ class st {
|
|
|
336
336
|
var t;
|
|
337
337
|
return (t = this.config.logger) == null ? void 0 : t.info("Data channel opened");
|
|
338
338
|
}, this.dataChannel.onmessage = (t) => {
|
|
339
|
-
this.messageCallbacks.forEach((
|
|
340
|
-
|
|
339
|
+
this.messageCallbacks.forEach((s) => {
|
|
340
|
+
s(t);
|
|
341
341
|
});
|
|
342
342
|
});
|
|
343
343
|
}
|
|
344
344
|
sendPacket(e) {
|
|
345
|
-
var t,
|
|
345
|
+
var t, s;
|
|
346
346
|
if (!this.dataChannel) {
|
|
347
347
|
(t = this.config.logger) == null || t.warn("Data channel is not open, cannot send message");
|
|
348
348
|
return;
|
|
349
349
|
}
|
|
350
|
-
this.dataChannel.send(JSON.stringify(e)), (
|
|
350
|
+
this.dataChannel.send(JSON.stringify(e)), (s = this.config.logger) == null || s.info("Sent message:", e);
|
|
351
351
|
}
|
|
352
352
|
_startAnalyzers() {
|
|
353
353
|
if (!this.localStream || !this.remoteStream || this.visualizerCallbacks.length === 0)
|
|
@@ -355,26 +355,26 @@ class st {
|
|
|
355
355
|
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
356
356
|
const e = this.audioCtx.createMediaStreamSource(this.localStream), t = this.audioCtx.createMediaStreamSource(this.remoteStream);
|
|
357
357
|
this.localAnalyser = this.audioCtx.createAnalyser(), this.remoteAnalyser = this.audioCtx.createAnalyser(), this.localAnalyser.fftSize = 256, this.remoteAnalyser.fftSize = 256, e.connect(this.localAnalyser), t.connect(this.remoteAnalyser);
|
|
358
|
-
const
|
|
358
|
+
const s = () => {
|
|
359
359
|
if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
|
|
360
360
|
return;
|
|
361
|
-
const
|
|
362
|
-
this.localAnalyser.getByteFrequencyData(
|
|
363
|
-
const
|
|
361
|
+
const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
362
|
+
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
|
|
363
|
+
const r = n.reduce((u, p) => u + p, 0) / n.length, l = a.reduce((u, p) => u + p, 0) / a.length;
|
|
364
364
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
365
365
|
u({
|
|
366
|
-
localAmplitude:
|
|
366
|
+
localAmplitude: r,
|
|
367
367
|
remoteAmplitude: l
|
|
368
368
|
});
|
|
369
|
-
}), this.analyzerFrame = requestAnimationFrame(
|
|
369
|
+
}), this.analyzerFrame = requestAnimationFrame(s);
|
|
370
370
|
};
|
|
371
|
-
this.analyzerFrame = requestAnimationFrame(
|
|
371
|
+
this.analyzerFrame = requestAnimationFrame(s);
|
|
372
372
|
}
|
|
373
373
|
_stopAnalyzers() {
|
|
374
374
|
this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
class
|
|
377
|
+
class U extends E {
|
|
378
378
|
constructor(t) {
|
|
379
379
|
super();
|
|
380
380
|
o(this, "status");
|
|
@@ -382,9 +382,9 @@ class D extends E {
|
|
|
382
382
|
o(this, "autostart");
|
|
383
383
|
o(this, "config");
|
|
384
384
|
o(this, "webRTCClient");
|
|
385
|
-
this.config = t, this.status = "disconnected", this.session = null, this.autostart = (t == null ? void 0 : t.autostart) ?? !1, this.webRTCClient = new
|
|
386
|
-
const
|
|
387
|
-
this.notifyPacket(
|
|
385
|
+
this.config = t, this.status = "disconnected", this.session = null, this.autostart = (t == null ? void 0 : t.autostart) ?? !1, this.webRTCClient = new nt(t), this.webRTCClient.addMessageCallback((s) => {
|
|
386
|
+
const n = JSON.parse(s.data);
|
|
387
|
+
this.notifyPacket(n);
|
|
388
388
|
});
|
|
389
389
|
}
|
|
390
390
|
getName() {
|
|
@@ -397,31 +397,31 @@ class D extends E {
|
|
|
397
397
|
super.syncSession(t), this.status === "connected" && (await this.disconnect(), await this.connect(t));
|
|
398
398
|
}
|
|
399
399
|
async connect(t) {
|
|
400
|
-
var
|
|
401
|
-
return this.status === "connected" ? Promise.resolve(this.session) : (this.session = t || this.session || "new", this.setStatus("connecting"), (
|
|
400
|
+
var s;
|
|
401
|
+
return this.status === "connected" ? Promise.resolve(this.session) : (this.session = t || this.session || "new", this.setStatus("connecting"), (s = this.config.logger) == null || s.debug("Connecting to WebRTC with sessionId:", this.session), await this.webRTCClient.connect(this.session), this.setStatus("connected"), await this.webRTCClient.createDataChannel(), this.session);
|
|
402
402
|
}
|
|
403
403
|
async disconnect() {
|
|
404
|
-
var t,
|
|
404
|
+
var t, s, n;
|
|
405
405
|
if (this.status === "disconnected")
|
|
406
406
|
return (t = this.config.logger) == null || t.warn("Already disconnected"), Promise.resolve();
|
|
407
|
-
await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (
|
|
407
|
+
await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (n = (s = this.config) == null ? void 0 : s.logger) == null || n.debug("Disconnected from WebRTC");
|
|
408
408
|
}
|
|
409
409
|
sendPacket(t) {
|
|
410
410
|
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendPacket(t), Promise.resolve());
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
|
-
class
|
|
413
|
+
class it {
|
|
414
414
|
constructor(e) {
|
|
415
415
|
o(this, "config");
|
|
416
416
|
this.config = e;
|
|
417
417
|
}
|
|
418
418
|
async complete(e, t) {
|
|
419
|
-
var
|
|
420
|
-
await this.persist(e, { ...t, success: !0 }), (
|
|
419
|
+
var s;
|
|
420
|
+
await this.persist(e, { ...t, success: !0 }), (s = this.config.logger) == null || s.debug("Transaction completed:", e);
|
|
421
421
|
}
|
|
422
422
|
async fail(e, t) {
|
|
423
|
-
var
|
|
424
|
-
await this.persist(e, { ...t, success: !1 }), (
|
|
423
|
+
var s;
|
|
424
|
+
await this.persist(e, { ...t, success: !1 }), (s = this.config.logger) == null || s.debug("Transaction failed:", { ...e, ...t });
|
|
425
425
|
}
|
|
426
426
|
async persist(e, t) {
|
|
427
427
|
await fetch(`${this.config.apiUrl}/transactions/${e.id}`, {
|
|
@@ -435,7 +435,7 @@ class nt {
|
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
|
-
class
|
|
438
|
+
class at {
|
|
439
439
|
constructor(e, t) {
|
|
440
440
|
o(this, "transaction");
|
|
441
441
|
o(this, "manager");
|
|
@@ -450,16 +450,16 @@ class it {
|
|
|
450
450
|
await this.fail("No function call found");
|
|
451
451
|
return;
|
|
452
452
|
}
|
|
453
|
-
const
|
|
454
|
-
if (!
|
|
455
|
-
await this.fail(`Tool ${
|
|
453
|
+
const s = t.name, n = t.args, a = e[s];
|
|
454
|
+
if (!a) {
|
|
455
|
+
await this.fail(`Tool ${s} not found`);
|
|
456
456
|
return;
|
|
457
457
|
}
|
|
458
458
|
try {
|
|
459
|
-
const
|
|
460
|
-
await this.complete(
|
|
461
|
-
} catch (
|
|
462
|
-
await this.fail(`Error executing tool ${
|
|
459
|
+
const r = await a(n);
|
|
460
|
+
await this.complete(r);
|
|
461
|
+
} catch (r) {
|
|
462
|
+
await this.fail(`Error executing tool ${s}: ${r}`);
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
async complete(e) {
|
|
@@ -469,7 +469,7 @@ class it {
|
|
|
469
469
|
await this.manager.fail(this.transaction, { success: !1, output: null, error: e });
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
class
|
|
472
|
+
class ot extends E {
|
|
473
473
|
constructor(t) {
|
|
474
474
|
super();
|
|
475
475
|
o(this, "status");
|
|
@@ -497,169 +497,170 @@ class at extends E {
|
|
|
497
497
|
async sendPacket(t) {
|
|
498
498
|
}
|
|
499
499
|
onTransaction(t) {
|
|
500
|
-
var
|
|
500
|
+
var a;
|
|
501
501
|
if (!this.config.onTransaction) {
|
|
502
|
-
(
|
|
502
|
+
(a = this.config.logger) == null || a.error("Transaction protocol config is not set");
|
|
503
503
|
return;
|
|
504
504
|
}
|
|
505
|
-
const
|
|
506
|
-
this.config.onTransaction(
|
|
505
|
+
const s = new it(this.config), n = new at(t, s);
|
|
506
|
+
this.config.onTransaction(n);
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
-
const P =
|
|
510
|
-
function
|
|
509
|
+
const P = B(void 0);
|
|
510
|
+
function rt(i) {
|
|
511
511
|
return new Promise((e, t) => {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
e(
|
|
516
|
-
},
|
|
517
|
-
t(
|
|
512
|
+
const s = new FileReader();
|
|
513
|
+
s.readAsDataURL(i), s.onload = () => {
|
|
514
|
+
const a = s.result.split(";base64,")[1];
|
|
515
|
+
e(a);
|
|
516
|
+
}, s.onerror = (n) => {
|
|
517
|
+
t(n);
|
|
518
518
|
};
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
|
-
function
|
|
522
|
-
dev:
|
|
523
|
-
|
|
524
|
-
|
|
521
|
+
function ct({
|
|
522
|
+
dev: i = !1,
|
|
523
|
+
baseUrl: e,
|
|
524
|
+
protocols: t,
|
|
525
|
+
logger: s,
|
|
525
526
|
children: n,
|
|
526
|
-
session:
|
|
527
|
-
...
|
|
527
|
+
session: a = "new",
|
|
528
|
+
...r
|
|
528
529
|
}) {
|
|
529
|
-
const [
|
|
530
|
-
if (Array.isArray(
|
|
531
|
-
return
|
|
532
|
-
if (typeof
|
|
533
|
-
const
|
|
534
|
-
let m = Object.keys(
|
|
530
|
+
const [l, u] = R(!1), [p, g] = R([]), [w, T] = R(a), [k, j] = R(/* @__PURE__ */ new Map()), N = Y(!1), b = G(() => {
|
|
531
|
+
if (Array.isArray(t))
|
|
532
|
+
return t;
|
|
533
|
+
if (typeof t == "object" && t !== null) {
|
|
534
|
+
const c = i ? "localhost:8000" : e || "persona.applica.guru/api", f = i ? "http" : "https", d = i ? "ws" : "wss";
|
|
535
|
+
let m = Object.keys(t).map((y) => {
|
|
535
536
|
switch (y) {
|
|
536
537
|
case "rest":
|
|
537
|
-
const h =
|
|
538
|
-
return h === !0 ? new
|
|
539
|
-
apiUrl: `${
|
|
540
|
-
apiKey:
|
|
541
|
-
agentId:
|
|
542
|
-
logger:
|
|
543
|
-
}) : typeof h == "object" && h !== null ? new
|
|
538
|
+
const h = t[y];
|
|
539
|
+
return h === !0 ? new z({
|
|
540
|
+
apiUrl: `${f}://${c}`,
|
|
541
|
+
apiKey: r.apiKey,
|
|
542
|
+
agentId: r.agentId,
|
|
543
|
+
logger: s
|
|
544
|
+
}) : typeof h == "object" && h !== null ? new z(h) : null;
|
|
544
545
|
case "webrtc":
|
|
545
|
-
const C =
|
|
546
|
-
return C === !0 ? new
|
|
547
|
-
webrtcUrl: `${d}://${
|
|
548
|
-
apiKey:
|
|
549
|
-
agentId:
|
|
550
|
-
logger:
|
|
551
|
-
}) : typeof C == "object" && C !== null ? new
|
|
546
|
+
const C = t[y];
|
|
547
|
+
return C === !0 ? new U({
|
|
548
|
+
webrtcUrl: `${d}://${c}/webrtc`,
|
|
549
|
+
apiKey: r.apiKey,
|
|
550
|
+
agentId: r.agentId,
|
|
551
|
+
logger: s
|
|
552
|
+
}) : typeof C == "object" && C !== null ? new U(C) : null;
|
|
552
553
|
case "websocket":
|
|
553
|
-
const x =
|
|
554
|
-
return x === !0 ? new
|
|
555
|
-
webSocketUrl: `${d}://${
|
|
556
|
-
apiKey:
|
|
557
|
-
agentId:
|
|
558
|
-
logger:
|
|
559
|
-
}) : typeof x == "object" && x !== null ? new
|
|
554
|
+
const x = t[y];
|
|
555
|
+
return x === !0 ? new D({
|
|
556
|
+
webSocketUrl: `${d}://${c}/websocket`,
|
|
557
|
+
apiKey: r.apiKey,
|
|
558
|
+
agentId: r.agentId,
|
|
559
|
+
logger: s
|
|
560
|
+
}) : typeof x == "object" && x !== null ? new D(x) : null;
|
|
560
561
|
default:
|
|
561
562
|
throw new Error(`Unknown protocol: ${y}`);
|
|
562
563
|
}
|
|
563
564
|
}).filter((y) => y !== null);
|
|
564
|
-
return
|
|
565
|
-
new
|
|
566
|
-
apiUrl: `${
|
|
567
|
-
apiKey:
|
|
568
|
-
agentId:
|
|
565
|
+
return r.tools && m.push(
|
|
566
|
+
new ot({
|
|
567
|
+
apiUrl: `${f}://${c}`,
|
|
568
|
+
apiKey: r.apiKey,
|
|
569
|
+
agentId: r.agentId,
|
|
569
570
|
onTransaction: async (y) => {
|
|
570
|
-
await y.invoke(
|
|
571
|
+
await y.invoke(r.tools);
|
|
571
572
|
},
|
|
572
|
-
logger:
|
|
573
|
+
logger: s
|
|
573
574
|
})
|
|
574
575
|
), m;
|
|
575
576
|
}
|
|
576
577
|
throw new Error("Invalid protocols configuration");
|
|
577
578
|
}, []);
|
|
578
|
-
|
|
579
|
-
|
|
579
|
+
V(() => {
|
|
580
|
+
N.current || (N.current = !0, s == null || s.debug(
|
|
580
581
|
"Initializing protocols: ",
|
|
581
|
-
b.map((
|
|
582
|
-
), b.forEach((
|
|
583
|
-
|
|
584
|
-
|
|
582
|
+
b.map((c) => c.getName())
|
|
583
|
+
), b.forEach((c) => {
|
|
584
|
+
c.setSession(w), c.clearListeners(), c.addStatusChangeListener((f) => {
|
|
585
|
+
s == null || s.debug(`${c.getName()} has notified new status: ${f}`), k.set(c.getName(), f), f === "connected" && r.context && c.sendPacket({
|
|
585
586
|
type: "command",
|
|
586
587
|
payload: {
|
|
587
588
|
command: "set_initial_context",
|
|
588
|
-
arguments:
|
|
589
|
+
arguments: r.context
|
|
589
590
|
}
|
|
590
|
-
}),
|
|
591
|
-
}),
|
|
592
|
-
if (
|
|
593
|
-
const d =
|
|
594
|
-
|
|
595
|
-
(m) =>
|
|
591
|
+
}), j(new Map(k));
|
|
592
|
+
}), c.addPacketListener((f) => {
|
|
593
|
+
if (f.type === "message") {
|
|
594
|
+
const d = f.payload;
|
|
595
|
+
g(
|
|
596
|
+
(m) => M([...m, { ...d, protocol: c.getName() }])
|
|
596
597
|
);
|
|
597
|
-
} else if (
|
|
598
|
-
const d =
|
|
598
|
+
} else if (f.type === "reasoning") {
|
|
599
|
+
const d = f.payload;
|
|
599
600
|
let m = d.thought;
|
|
600
601
|
d.imageUrl && (m += `
|
|
601
602
|
|
|
602
603
|
`);
|
|
603
604
|
const y = { type: "reasoning", text: m, role: "assistant", finishReason: "stop" };
|
|
604
|
-
|
|
605
|
-
(h) =>
|
|
605
|
+
g(
|
|
606
|
+
(h) => M([...h, { ...y, protocol: c.getName() }])
|
|
606
607
|
);
|
|
607
|
-
} else
|
|
608
|
-
}),
|
|
608
|
+
} else f.type === "transaction" && b.filter((d) => d !== c).forEach((d) => d.onTransaction(f.payload));
|
|
609
|
+
}), c.autostart && c.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${c.getName()}`), c.connect(w));
|
|
609
610
|
}));
|
|
610
|
-
}, [
|
|
611
|
-
const
|
|
611
|
+
}, [w, b, s, k]);
|
|
612
|
+
const O = async (c) => {
|
|
612
613
|
var y;
|
|
613
|
-
if (((y =
|
|
614
|
-
const
|
|
615
|
-
|
|
614
|
+
if (((y = c.content[0]) == null ? void 0 : y.type) !== "text") throw new Error("Only text messages are supported");
|
|
615
|
+
const f = c.content[0].text;
|
|
616
|
+
g((h) => [...h, { role: "user", type: "text", text: f }]), u(!0);
|
|
616
617
|
const d = b.sort((h, C) => C.getPriority() - h.getPriority()).find((h) => h.status === "connected"), m = [];
|
|
617
|
-
if (
|
|
618
|
-
for (const h of
|
|
618
|
+
if (c.attachments)
|
|
619
|
+
for (const h of c.attachments)
|
|
619
620
|
h.contentType.startsWith("image/") && h.file && m.push({
|
|
620
621
|
role: "user",
|
|
621
622
|
image: {
|
|
622
623
|
contentType: h.contentType,
|
|
623
|
-
content: await
|
|
624
|
+
content: await rt(h.file)
|
|
624
625
|
},
|
|
625
626
|
text: "",
|
|
626
627
|
type: "text"
|
|
627
628
|
});
|
|
628
|
-
|
|
629
|
+
c.content && m.push({
|
|
629
630
|
role: "user",
|
|
630
|
-
text:
|
|
631
|
+
text: c.content[0].text,
|
|
631
632
|
type: "text"
|
|
632
|
-
}),
|
|
633
|
-
},
|
|
634
|
-
isRunning:
|
|
635
|
-
messages:
|
|
636
|
-
convertMessage:
|
|
637
|
-
onNew:
|
|
638
|
-
onCancel:
|
|
639
|
-
onReload:
|
|
633
|
+
}), s == null || s.debug("Sending message:", m), await (d == null ? void 0 : d.sendPacket({ type: "request", payload: m })), u(!1);
|
|
634
|
+
}, L = v(() => (u(!1), g([]), T("new"), Promise.resolve()), []), F = v(() => Promise.resolve(), []), _ = v(() => p, [p]), J = H({
|
|
635
|
+
isRunning: l,
|
|
636
|
+
messages: p,
|
|
637
|
+
convertMessage: st,
|
|
638
|
+
onNew: O,
|
|
639
|
+
onCancel: L,
|
|
640
|
+
onReload: F,
|
|
640
641
|
adapters: {
|
|
641
|
-
attachments: new
|
|
642
|
+
attachments: new Q([new X()])
|
|
642
643
|
}
|
|
643
644
|
});
|
|
644
|
-
return /* @__PURE__ */
|
|
645
|
+
return /* @__PURE__ */ $.jsx(P.Provider, { value: { protocols: b, protocolsStatus: k, getMessages: _ }, children: /* @__PURE__ */ $.jsx(Z, { runtime: J, children: n }) });
|
|
645
646
|
}
|
|
646
|
-
function
|
|
647
|
-
return /* @__PURE__ */
|
|
647
|
+
function ft({ children: i, ...e }) {
|
|
648
|
+
return /* @__PURE__ */ $.jsx(ct, { ...e, children: i });
|
|
648
649
|
}
|
|
649
|
-
function
|
|
650
|
-
const
|
|
651
|
-
if (!
|
|
650
|
+
function pt() {
|
|
651
|
+
const i = A(P);
|
|
652
|
+
if (!i)
|
|
652
653
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
653
|
-
return
|
|
654
|
+
return i;
|
|
654
655
|
}
|
|
655
|
-
function
|
|
656
|
+
function lt(i) {
|
|
656
657
|
const e = A(P);
|
|
657
658
|
if (!e)
|
|
658
659
|
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
659
|
-
const t = e.protocols.find((
|
|
660
|
+
const t = e.protocols.find((n) => n.getName() === i);
|
|
660
661
|
if (!t)
|
|
661
662
|
return null;
|
|
662
|
-
const
|
|
663
|
+
const s = e.protocolsStatus.get(t.getName());
|
|
663
664
|
return {
|
|
664
665
|
...t,
|
|
665
666
|
connect: t.connect.bind(t),
|
|
@@ -670,28 +671,28 @@ function ct(a) {
|
|
|
670
671
|
addPacketListener: t.addPacketListener.bind(t),
|
|
671
672
|
getName: t.getName.bind(t),
|
|
672
673
|
getPriority: t.getPriority.bind(t),
|
|
673
|
-
status:
|
|
674
|
+
status: s || t.status
|
|
674
675
|
};
|
|
675
676
|
}
|
|
676
|
-
function
|
|
677
|
-
const
|
|
678
|
-
if (!
|
|
677
|
+
function yt() {
|
|
678
|
+
const i = A(P);
|
|
679
|
+
if (!i)
|
|
679
680
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
680
|
-
for (const e of
|
|
681
|
+
for (const e of i.protocols)
|
|
681
682
|
if (e.getName() === "rest")
|
|
682
683
|
return e.config.apiUrl;
|
|
683
684
|
throw new Error("REST protocol not found");
|
|
684
685
|
}
|
|
685
|
-
function yt() {
|
|
686
|
-
return ct("webrtc");
|
|
687
|
-
}
|
|
688
686
|
function mt() {
|
|
689
|
-
|
|
690
|
-
|
|
687
|
+
return lt("webrtc");
|
|
688
|
+
}
|
|
689
|
+
function gt() {
|
|
690
|
+
const i = A(P);
|
|
691
|
+
if (!i)
|
|
691
692
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
692
|
-
return
|
|
693
|
+
return i.getMessages();
|
|
693
694
|
}
|
|
694
|
-
class
|
|
695
|
+
class wt {
|
|
695
696
|
constructor() {
|
|
696
697
|
o(this, "prefix", "[Persona]");
|
|
697
698
|
}
|
|
@@ -712,17 +713,17 @@ class gt {
|
|
|
712
713
|
}
|
|
713
714
|
}
|
|
714
715
|
export {
|
|
715
|
-
|
|
716
|
+
wt as PersonaConsoleLogger,
|
|
716
717
|
E as PersonaProtocolBase,
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
718
|
+
z as PersonaRESTProtocol,
|
|
719
|
+
ft as PersonaRuntimeProvider,
|
|
720
|
+
ot as PersonaTransactionProtocol,
|
|
721
|
+
U as PersonaWebRTCProtocol,
|
|
722
|
+
D as PersonaWebSocketProtocol,
|
|
723
|
+
pt as usePersonaRuntime,
|
|
724
|
+
yt as usePersonaRuntimeEndpoint,
|
|
725
|
+
gt as usePersonaRuntimeMessages,
|
|
726
|
+
lt as usePersonaRuntimeProtocol,
|
|
727
|
+
mt as usePersonaRuntimeWebRTCProtocol
|
|
727
728
|
};
|
|
728
729
|
//# sourceMappingURL=bundle.es.js.map
|