@applica-software-guru/persona-sdk 0.1.57 → 0.1.59
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 +4 -2
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +180 -168
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +4 -2
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +4 -2
- package/dist/bundle.umd.js.map +1 -1
- package/dist/runtime.d.ts +3 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/playground/src/chat.tsx +35 -1
- package/playground/src/components/assistant-ui/thread.tsx +5 -1
- package/src/runtime.tsx +30 -5
- package/src/types.ts +1 -0
package/dist/bundle.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (
|
|
4
|
-
import { createContext as
|
|
5
|
-
import { useExternalStoreRuntime as
|
|
1
|
+
var K = Object.defineProperty;
|
|
2
|
+
var q = (i, t, e) => t in i ? K(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var o = (i, t, e) => q(i, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createContext as _, useContext as R, useState as x, useRef as B, useMemo as Y, useEffect as G, useCallback as E } from "react";
|
|
5
|
+
import { useExternalStoreRuntime as V, CompositeAttachmentAdapter as H, SimpleImageAttachmentAdapter as Q, AssistantRuntimeProvider as X } from "@assistant-ui/react";
|
|
6
6
|
var D = { exports: {} }, C = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
@@ -13,78 +13,78 @@ var D = { exports: {} }, C = {};
|
|
|
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 e(n, s,
|
|
16
|
+
var M;
|
|
17
|
+
function Z() {
|
|
18
|
+
if (M) return C;
|
|
19
|
+
M = 1;
|
|
20
|
+
var i = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
|
+
function e(n, s, a) {
|
|
22
22
|
var c = null;
|
|
23
|
-
if (
|
|
24
|
-
|
|
23
|
+
if (a !== void 0 && (c = "" + a), s.key !== void 0 && (c = "" + s.key), "key" in s) {
|
|
24
|
+
a = {};
|
|
25
25
|
for (var l in s)
|
|
26
|
-
l !== "key" && (
|
|
27
|
-
} else
|
|
28
|
-
return s =
|
|
29
|
-
$$typeof:
|
|
26
|
+
l !== "key" && (a[l] = s[l]);
|
|
27
|
+
} else a = s;
|
|
28
|
+
return s = a.ref, {
|
|
29
|
+
$$typeof: i,
|
|
30
30
|
type: n,
|
|
31
31
|
key: c,
|
|
32
32
|
ref: s !== void 0 ? s : null,
|
|
33
|
-
props:
|
|
33
|
+
props: a
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
return C.Fragment = t, C.jsx = e, C.jsxs = e, C;
|
|
37
37
|
}
|
|
38
|
-
D.exports =
|
|
39
|
-
var
|
|
40
|
-
function
|
|
41
|
-
return
|
|
38
|
+
D.exports = Z();
|
|
39
|
+
var T = D.exports;
|
|
40
|
+
function ee(i) {
|
|
41
|
+
return i.filter((t) => {
|
|
42
42
|
var e;
|
|
43
43
|
return t.finishReason === "stop" ? t.text !== null && ((e = t.text) == null ? void 0 : e.trim()) !== "" : !0;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function $(i) {
|
|
47
47
|
const t = [];
|
|
48
48
|
let e = null;
|
|
49
|
-
for (const s of
|
|
49
|
+
for (const s of i)
|
|
50
50
|
s.type !== "transaction" && (s.type === "reasoning" ? (e != null && (t.push(e), e = null), t.push(s)) : s.functionCalls ? (e && t.push(e), t.push(s), e = null) : s.functionResponse ? t[t.length - 1] = {
|
|
51
51
|
...t[t.length - 1],
|
|
52
52
|
functionResponse: s.functionResponse
|
|
53
53
|
} : e && s.protocol === e.protocol && (e.role === s.role || s.finishReason === "stop") ? (e.text += s.text, e.files = [...e.files ?? [], ...s.files ?? []]) : (e && t.push(e), e = {
|
|
54
54
|
...s
|
|
55
55
|
}));
|
|
56
|
-
return e && t.push(e),
|
|
56
|
+
return e && t.push(e), ee(t);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function te(i) {
|
|
59
59
|
var e, n;
|
|
60
|
-
const t = ((e =
|
|
60
|
+
const t = ((e = i.files) == null ? void 0 : e.map(
|
|
61
61
|
(s) => ({
|
|
62
62
|
type: "file",
|
|
63
63
|
data: s.url,
|
|
64
64
|
mimeType: s.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: ((n =
|
|
72
|
-
var
|
|
70
|
+
status: (i == null ? void 0 : i.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
|
|
71
|
+
content: ((n = i.functionCalls) == null ? void 0 : n.map((s) => {
|
|
72
|
+
var a;
|
|
73
73
|
return {
|
|
74
74
|
type: "tool-call",
|
|
75
75
|
toolName: s.name,
|
|
76
76
|
toolCallId: s.id,
|
|
77
77
|
args: s.args,
|
|
78
|
-
result: (
|
|
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 }, ...t] : [{ type: "text", text: i.text }, ...t]
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
class
|
|
87
|
+
class A {
|
|
88
88
|
constructor() {
|
|
89
89
|
o(this, "statusChangeCallbacks", []);
|
|
90
90
|
o(this, "messageCallbacks", []);
|
|
@@ -119,7 +119,7 @@ class x {
|
|
|
119
119
|
onTransaction(t) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class N extends
|
|
122
|
+
class N extends A {
|
|
123
123
|
constructor(e) {
|
|
124
124
|
super();
|
|
125
125
|
o(this, "status");
|
|
@@ -145,7 +145,7 @@ class N extends x {
|
|
|
145
145
|
this.session = e;
|
|
146
146
|
}
|
|
147
147
|
async send(e) {
|
|
148
|
-
const { apiUrl: n, apiKey: s, agentId:
|
|
148
|
+
const { apiUrl: n, apiKey: s, agentId: a } = this.config, c = this.session ?? "new", l = e, f = await (await fetch(`${n}/agents/${a}/sessions/${c}/messages`, {
|
|
149
149
|
body: JSON.stringify({ userMessage: l }),
|
|
150
150
|
method: "POST",
|
|
151
151
|
headers: {
|
|
@@ -155,14 +155,14 @@ class N extends x {
|
|
|
155
155
|
}
|
|
156
156
|
})).json();
|
|
157
157
|
this.notifyMessages(
|
|
158
|
-
|
|
158
|
+
f.response.messages.map((b) => ({
|
|
159
159
|
type: "message",
|
|
160
160
|
payload: b
|
|
161
161
|
}))
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
class I extends
|
|
165
|
+
class I extends A {
|
|
166
166
|
constructor(e) {
|
|
167
167
|
super();
|
|
168
168
|
o(this, "status");
|
|
@@ -188,18 +188,18 @@ class I extends x {
|
|
|
188
188
|
return Promise.resolve(this.session);
|
|
189
189
|
const n = e || this.session || "new";
|
|
190
190
|
(l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", n);
|
|
191
|
-
const s = encodeURIComponent(this.config.apiKey),
|
|
191
|
+
const s = encodeURIComponent(this.config.apiKey), a = this.config.agentId, c = `${this.config.webSocketUrl}?sessionCode=${n}&agentId=${a}&apiKey=${s}`;
|
|
192
192
|
return this.setStatus("connecting"), this.webSocket = new WebSocket(c), this.webSocket.addEventListener("open", () => {
|
|
193
193
|
this.setStatus("connected");
|
|
194
194
|
}), this.webSocket.addEventListener("message", (u) => {
|
|
195
|
-
const
|
|
196
|
-
this.notifyMessage(
|
|
195
|
+
const f = JSON.parse(u.data);
|
|
196
|
+
this.notifyMessage(f);
|
|
197
197
|
}), this.webSocket.addEventListener("close", () => {
|
|
198
198
|
var u;
|
|
199
199
|
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.warn("WebSocket connection closed");
|
|
200
200
|
}), this.webSocket.addEventListener("error", (u) => {
|
|
201
|
-
var
|
|
202
|
-
this.setStatus("disconnected"), this.webSocket = null, (
|
|
201
|
+
var f;
|
|
202
|
+
this.setStatus("disconnected"), this.webSocket = null, (f = this.config.logger) == null || f.error("WebSocket error", u);
|
|
203
203
|
}), Promise.resolve(n);
|
|
204
204
|
}
|
|
205
205
|
disconnect() {
|
|
@@ -210,7 +210,7 @@ class I extends x {
|
|
|
210
210
|
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify({ type: "request", payload: e })), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
class
|
|
213
|
+
class se {
|
|
214
214
|
constructor(t) {
|
|
215
215
|
o(this, "config");
|
|
216
216
|
o(this, "pc", null);
|
|
@@ -254,14 +254,14 @@ class te {
|
|
|
254
254
|
s.streams[0].getTracks().forEach((c) => {
|
|
255
255
|
this.remoteStream.addTrack(c);
|
|
256
256
|
}), this.audioCtx || this._startAnalyzers();
|
|
257
|
-
const
|
|
258
|
-
|
|
257
|
+
const a = new Audio();
|
|
258
|
+
a.srcObject = this.remoteStream, a.play().catch((c) => {
|
|
259
259
|
var l;
|
|
260
260
|
(l = this.config.logger) == null || l.error("Error playing remote audio:", c);
|
|
261
261
|
});
|
|
262
262
|
}, this.pc.onicecandidate = (s) => {
|
|
263
|
-
var
|
|
264
|
-
s.candidate && ((
|
|
263
|
+
var a;
|
|
264
|
+
s.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
|
|
265
265
|
JSON.stringify({
|
|
266
266
|
type: "CANDIDATE",
|
|
267
267
|
src: "client",
|
|
@@ -269,8 +269,8 @@ class te {
|
|
|
269
269
|
})
|
|
270
270
|
);
|
|
271
271
|
}, this.pc.ondatachannel = (s) => {
|
|
272
|
-
const
|
|
273
|
-
|
|
272
|
+
const a = s.channel;
|
|
273
|
+
a.onmessage = (c) => {
|
|
274
274
|
this.messageCallbacks.forEach((l) => {
|
|
275
275
|
l(c);
|
|
276
276
|
});
|
|
@@ -281,12 +281,12 @@ class te {
|
|
|
281
281
|
var l, u;
|
|
282
282
|
const s = await this.pc.createOffer();
|
|
283
283
|
await this.pc.setLocalDescription(s);
|
|
284
|
-
const
|
|
284
|
+
const a = {
|
|
285
285
|
apiKey: this.config.apiKey,
|
|
286
286
|
agentId: this.config.agentId,
|
|
287
287
|
sessionCode: t
|
|
288
288
|
};
|
|
289
|
-
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ",
|
|
289
|
+
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", a);
|
|
290
290
|
const c = {
|
|
291
291
|
type: "OFFER",
|
|
292
292
|
src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
|
|
@@ -296,18 +296,18 @@ class te {
|
|
|
296
296
|
type: s.type
|
|
297
297
|
},
|
|
298
298
|
connectionId: (Date.now() % 1e6).toString(),
|
|
299
|
-
metadata:
|
|
299
|
+
metadata: a
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
302
|
this.ws.send(JSON.stringify(c));
|
|
303
303
|
}, this.ws.onmessage = async (s) => {
|
|
304
304
|
var c;
|
|
305
|
-
const
|
|
306
|
-
if (
|
|
307
|
-
await this.pc.setRemoteDescription(new RTCSessionDescription(
|
|
308
|
-
else if (
|
|
305
|
+
const a = JSON.parse(s.data);
|
|
306
|
+
if (a.type === "ANSWER")
|
|
307
|
+
await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
|
|
308
|
+
else if (a.type === "CANDIDATE")
|
|
309
309
|
try {
|
|
310
|
-
await this.pc.addIceCandidate(new RTCIceCandidate(
|
|
310
|
+
await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
|
|
311
311
|
} catch (l) {
|
|
312
312
|
(c = this.config.logger) == null || c.error("Error adding ICE candidate:", l);
|
|
313
313
|
}
|
|
@@ -352,9 +352,9 @@ class te {
|
|
|
352
352
|
const n = () => {
|
|
353
353
|
if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
|
|
354
354
|
return;
|
|
355
|
-
const s = new Uint8Array(this.localAnalyser.frequencyBinCount),
|
|
356
|
-
this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(
|
|
357
|
-
const c = s.reduce((u,
|
|
355
|
+
const s = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
356
|
+
this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(a);
|
|
357
|
+
const c = s.reduce((u, f) => u + f, 0) / s.length, l = a.reduce((u, f) => u + f, 0) / a.length;
|
|
358
358
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
359
359
|
u({
|
|
360
360
|
localAmplitude: c,
|
|
@@ -368,7 +368,7 @@ class te {
|
|
|
368
368
|
this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
|
-
class z extends
|
|
371
|
+
class z extends A {
|
|
372
372
|
constructor(e) {
|
|
373
373
|
super();
|
|
374
374
|
o(this, "status");
|
|
@@ -376,7 +376,7 @@ class z extends x {
|
|
|
376
376
|
o(this, "autostart");
|
|
377
377
|
o(this, "config");
|
|
378
378
|
o(this, "webRTCClient");
|
|
379
|
-
this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new
|
|
379
|
+
this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new se(e), this.webRTCClient.addMessageCallback((n) => {
|
|
380
380
|
const s = JSON.parse(n.data);
|
|
381
381
|
this.notifyMessage(s);
|
|
382
382
|
});
|
|
@@ -404,7 +404,7 @@ class z extends x {
|
|
|
404
404
|
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendMessage(e), Promise.resolve());
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
|
-
class
|
|
407
|
+
class ne {
|
|
408
408
|
constructor(t) {
|
|
409
409
|
o(this, "config");
|
|
410
410
|
this.config = t;
|
|
@@ -429,7 +429,7 @@ class se {
|
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
class
|
|
432
|
+
class ie {
|
|
433
433
|
constructor(t, e) {
|
|
434
434
|
o(this, "transaction");
|
|
435
435
|
o(this, "manager");
|
|
@@ -444,13 +444,13 @@ class ne {
|
|
|
444
444
|
await this.fail("No function call found");
|
|
445
445
|
return;
|
|
446
446
|
}
|
|
447
|
-
const n = e.name, s = e.args,
|
|
448
|
-
if (!
|
|
447
|
+
const n = e.name, s = e.args, a = t[n];
|
|
448
|
+
if (!a) {
|
|
449
449
|
await this.fail(`Tool ${n} not found`);
|
|
450
450
|
return;
|
|
451
451
|
}
|
|
452
452
|
try {
|
|
453
|
-
const c = await
|
|
453
|
+
const c = await a(s);
|
|
454
454
|
await this.complete(c);
|
|
455
455
|
} catch (c) {
|
|
456
456
|
await this.fail(`Error executing tool ${n}: ${c}`);
|
|
@@ -463,7 +463,7 @@ class ne {
|
|
|
463
463
|
await this.manager.fail(this.transaction, { success: !1, output: null, error: t });
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
class
|
|
466
|
+
class ae extends A {
|
|
467
467
|
constructor(e) {
|
|
468
468
|
super();
|
|
469
469
|
o(this, "status");
|
|
@@ -493,155 +493,160 @@ class ie extends x {
|
|
|
493
493
|
throw (n = this.config.logger) == null || n.debug("Sending message:", e), new Error("Not implemented");
|
|
494
494
|
}
|
|
495
495
|
onTransaction(e) {
|
|
496
|
-
var
|
|
496
|
+
var a;
|
|
497
497
|
if (!this.config.onTransaction) {
|
|
498
|
-
(
|
|
498
|
+
(a = this.config.logger) == null || a.error("Transaction protocol config is not set");
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
|
-
const n = new
|
|
501
|
+
const n = new ne(this.config), s = new ie(e, n);
|
|
502
502
|
this.config.onTransaction(s);
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
-
const
|
|
506
|
-
function
|
|
505
|
+
const S = _(void 0);
|
|
506
|
+
function oe(i) {
|
|
507
507
|
return new Promise((t, e) => {
|
|
508
508
|
const n = new FileReader();
|
|
509
|
-
n.readAsDataURL(
|
|
510
|
-
const
|
|
511
|
-
t(
|
|
509
|
+
n.readAsDataURL(i), n.onload = () => {
|
|
510
|
+
const a = n.result.split(";base64,")[1];
|
|
511
|
+
t(a);
|
|
512
512
|
}, n.onerror = (s) => {
|
|
513
513
|
e(s);
|
|
514
514
|
};
|
|
515
515
|
});
|
|
516
516
|
}
|
|
517
|
-
function
|
|
518
|
-
dev:
|
|
517
|
+
function re({
|
|
518
|
+
dev: i = !1,
|
|
519
519
|
protocols: t,
|
|
520
520
|
logger: e,
|
|
521
521
|
children: n,
|
|
522
522
|
session: s = "new",
|
|
523
|
-
...
|
|
523
|
+
...a
|
|
524
524
|
}) {
|
|
525
|
-
const [c, l] =
|
|
525
|
+
const [c, l] = x(!1), [u, f] = x([]), [b, U] = x(s), [P, W] = x(/* @__PURE__ */ new Map()), v = B(!1), m = Y(() => {
|
|
526
526
|
if (Array.isArray(t))
|
|
527
527
|
return t;
|
|
528
528
|
if (typeof t == "object" && t !== null) {
|
|
529
|
-
const r =
|
|
530
|
-
let
|
|
531
|
-
switch (
|
|
529
|
+
const r = i ? "localhost:8000" : "persona.applica.guru/api", p = i ? "http" : "https", d = i ? "ws" : "wss";
|
|
530
|
+
let y = Object.keys(t).map((g) => {
|
|
531
|
+
switch (g) {
|
|
532
532
|
case "rest":
|
|
533
|
-
const
|
|
534
|
-
return
|
|
535
|
-
apiUrl: `${
|
|
536
|
-
apiKey:
|
|
537
|
-
agentId:
|
|
533
|
+
const h = t[g];
|
|
534
|
+
return h === !0 ? new N({
|
|
535
|
+
apiUrl: `${p}://${r}`,
|
|
536
|
+
apiKey: a.apiKey,
|
|
537
|
+
agentId: a.agentId,
|
|
538
538
|
logger: e
|
|
539
|
-
}) : typeof
|
|
539
|
+
}) : typeof h == "object" && h !== null ? new N(h) : null;
|
|
540
540
|
case "webrtc":
|
|
541
|
-
const w = t[
|
|
541
|
+
const w = t[g];
|
|
542
542
|
return w === !0 ? new z({
|
|
543
|
-
webrtcUrl: `${
|
|
544
|
-
apiKey:
|
|
545
|
-
agentId:
|
|
543
|
+
webrtcUrl: `${d}://${r}/webrtc`,
|
|
544
|
+
apiKey: a.apiKey,
|
|
545
|
+
agentId: a.agentId,
|
|
546
546
|
logger: e
|
|
547
547
|
}) : typeof w == "object" && w !== null ? new z(w) : null;
|
|
548
548
|
case "websocket":
|
|
549
|
-
const k = t[
|
|
549
|
+
const k = t[g];
|
|
550
550
|
return k === !0 ? new I({
|
|
551
|
-
webSocketUrl: `${
|
|
552
|
-
apiKey:
|
|
553
|
-
agentId:
|
|
551
|
+
webSocketUrl: `${d}://${r}/websocket`,
|
|
552
|
+
apiKey: a.apiKey,
|
|
553
|
+
agentId: a.agentId,
|
|
554
554
|
logger: e
|
|
555
555
|
}) : typeof k == "object" && k !== null ? new I(k) : null;
|
|
556
556
|
default:
|
|
557
|
-
throw new Error(`Unknown protocol: ${
|
|
557
|
+
throw new Error(`Unknown protocol: ${g}`);
|
|
558
558
|
}
|
|
559
|
-
}).filter((
|
|
560
|
-
return
|
|
561
|
-
new
|
|
562
|
-
apiUrl: `${
|
|
563
|
-
apiKey:
|
|
564
|
-
agentId:
|
|
565
|
-
onTransaction: async (
|
|
566
|
-
await
|
|
559
|
+
}).filter((g) => g !== null);
|
|
560
|
+
return a.tools && y.push(
|
|
561
|
+
new ae({
|
|
562
|
+
apiUrl: `${p}://${r}`,
|
|
563
|
+
apiKey: a.apiKey,
|
|
564
|
+
agentId: a.agentId,
|
|
565
|
+
onTransaction: async (g) => {
|
|
566
|
+
await g.invoke(a.tools);
|
|
567
567
|
},
|
|
568
568
|
logger: e
|
|
569
569
|
})
|
|
570
|
-
),
|
|
570
|
+
), y;
|
|
571
571
|
}
|
|
572
572
|
throw new Error("Invalid protocols configuration");
|
|
573
573
|
}, []);
|
|
574
|
-
|
|
575
|
-
|
|
574
|
+
G(() => {
|
|
575
|
+
v.current || (v.current = !0, e == null || e.debug(
|
|
576
576
|
"Initializing protocols: ",
|
|
577
577
|
m.map((r) => r.getName())
|
|
578
578
|
), m.forEach((r) => {
|
|
579
|
-
r.setSession(b), r.clearListeners(), r.addStatusChangeListener((
|
|
580
|
-
e == null || e.debug(`${r.getName()} has notified new status: ${
|
|
581
|
-
}), r.addMessageListener((
|
|
582
|
-
if (
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
(
|
|
579
|
+
r.setSession(b), r.clearListeners(), r.addStatusChangeListener((p) => {
|
|
580
|
+
e == null || e.debug(`${r.getName()} has notified new status: ${p}`), P.set(r.getName(), p), W(new Map(P));
|
|
581
|
+
}), r.addMessageListener((p) => {
|
|
582
|
+
if (p.type === "message") {
|
|
583
|
+
const d = p.payload;
|
|
584
|
+
f(
|
|
585
|
+
(y) => $([...y, { ...d, protocol: r.getName() }])
|
|
586
586
|
);
|
|
587
|
-
} else if (
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
587
|
+
} else if (p.type === "reasoning") {
|
|
588
|
+
const d = p.payload;
|
|
589
|
+
let y = d.thought;
|
|
590
|
+
d.imageUrl && (y += `
|
|
591
|
+
|
|
592
|
+
`);
|
|
593
|
+
const g = { type: "reasoning", text: y, role: "assistant", finishReason: "stop" };
|
|
594
|
+
f(
|
|
595
|
+
(h) => $([...h, { ...g, protocol: r.getName() }])
|
|
591
596
|
);
|
|
592
|
-
} else
|
|
597
|
+
} else p.type === "transaction" && m.filter((d) => d !== r).forEach((d) => d.onTransaction(p.payload));
|
|
593
598
|
}), r.autostart && r.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${r.getName()}`), r.connect(b));
|
|
594
599
|
}));
|
|
595
|
-
}, [b, m, e,
|
|
596
|
-
const
|
|
597
|
-
var
|
|
598
|
-
if (((
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
const
|
|
600
|
+
}, [b, m, e, P]);
|
|
601
|
+
const j = async (r) => {
|
|
602
|
+
var g;
|
|
603
|
+
if (((g = r.content[0]) == null ? void 0 : g.type) !== "text") throw new Error("Only text messages are supported");
|
|
604
|
+
const p = r.content[0].text;
|
|
605
|
+
f((h) => [...h, { role: "user", type: "text", text: p }]), l(!0);
|
|
606
|
+
const d = m.sort((h, w) => w.getPriority() - h.getPriority()).find((h) => h.status === "connected"), y = [];
|
|
602
607
|
if (r.attachments)
|
|
603
|
-
for (const
|
|
604
|
-
|
|
608
|
+
for (const h of r.attachments)
|
|
609
|
+
h.contentType.startsWith("image/") && h.file && y.push({
|
|
605
610
|
role: "user",
|
|
606
611
|
image: {
|
|
607
|
-
contentType:
|
|
608
|
-
content: await
|
|
612
|
+
contentType: h.contentType,
|
|
613
|
+
content: await oe(h.file)
|
|
609
614
|
},
|
|
610
615
|
text: "",
|
|
611
616
|
type: "text"
|
|
612
617
|
});
|
|
613
|
-
r.content &&
|
|
618
|
+
r.content && y.push({
|
|
614
619
|
role: "user",
|
|
615
620
|
text: r.content[0].text,
|
|
616
621
|
type: "text"
|
|
617
|
-
}), e == null || e.debug("Sending message:",
|
|
618
|
-
},
|
|
622
|
+
}), e == null || e.debug("Sending message:", y), await (d == null ? void 0 : d.send(y)), l(!1);
|
|
623
|
+
}, O = E(() => (l(!1), f([]), U("new"), Promise.resolve()), []), L = E(() => Promise.resolve(), []), F = E(() => u, [u]), J = V({
|
|
619
624
|
isRunning: c,
|
|
620
625
|
messages: u,
|
|
621
|
-
convertMessage:
|
|
622
|
-
onNew:
|
|
623
|
-
onCancel:
|
|
626
|
+
convertMessage: te,
|
|
627
|
+
onNew: j,
|
|
628
|
+
onCancel: O,
|
|
624
629
|
onReload: L,
|
|
625
630
|
adapters: {
|
|
626
|
-
attachments: new
|
|
631
|
+
attachments: new H([new Q()])
|
|
627
632
|
}
|
|
628
633
|
});
|
|
629
|
-
return /* @__PURE__ */
|
|
634
|
+
return /* @__PURE__ */ T.jsx(S.Provider, { value: { protocols: m, protocolsStatus: P, getMessages: F }, children: /* @__PURE__ */ T.jsx(X, { runtime: J, children: n }) });
|
|
630
635
|
}
|
|
631
|
-
function
|
|
632
|
-
return /* @__PURE__ */
|
|
636
|
+
function de({ children: i, ...t }) {
|
|
637
|
+
return /* @__PURE__ */ T.jsx(re, { ...t, children: i });
|
|
633
638
|
}
|
|
634
|
-
function
|
|
635
|
-
const
|
|
636
|
-
if (!
|
|
639
|
+
function fe() {
|
|
640
|
+
const i = R(S);
|
|
641
|
+
if (!i)
|
|
637
642
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
638
|
-
return
|
|
643
|
+
return i;
|
|
639
644
|
}
|
|
640
|
-
function
|
|
641
|
-
const t =
|
|
645
|
+
function ce(i) {
|
|
646
|
+
const t = R(S);
|
|
642
647
|
if (!t)
|
|
643
648
|
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
644
|
-
const e = t.protocols.find((s) => s.getName() ===
|
|
649
|
+
const e = t.protocols.find((s) => s.getName() === i);
|
|
645
650
|
if (!e)
|
|
646
651
|
return null;
|
|
647
652
|
const n = t.protocolsStatus.get(e.getName());
|
|
@@ -658,19 +663,25 @@ function re(a) {
|
|
|
658
663
|
status: n || e.status
|
|
659
664
|
};
|
|
660
665
|
}
|
|
661
|
-
function
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
666
|
+
function pe() {
|
|
667
|
+
const i = R(S);
|
|
668
|
+
if (!i)
|
|
664
669
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
665
|
-
for (const t of
|
|
670
|
+
for (const t of i.protocols)
|
|
666
671
|
if (t.getName() === "rest")
|
|
667
672
|
return t.config.apiUrl;
|
|
668
673
|
throw new Error("REST protocol not found");
|
|
669
674
|
}
|
|
670
|
-
function
|
|
671
|
-
return
|
|
675
|
+
function ge() {
|
|
676
|
+
return ce("webrtc");
|
|
677
|
+
}
|
|
678
|
+
function ye() {
|
|
679
|
+
const i = R(S);
|
|
680
|
+
if (!i)
|
|
681
|
+
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
682
|
+
return i.getMessages();
|
|
672
683
|
}
|
|
673
|
-
class
|
|
684
|
+
class me {
|
|
674
685
|
constructor() {
|
|
675
686
|
o(this, "prefix", "[Persona]");
|
|
676
687
|
}
|
|
@@ -691,16 +702,17 @@ class ye {
|
|
|
691
702
|
}
|
|
692
703
|
}
|
|
693
704
|
export {
|
|
694
|
-
|
|
695
|
-
|
|
705
|
+
me as PersonaConsoleLogger,
|
|
706
|
+
A as PersonaProtocolBase,
|
|
696
707
|
N as PersonaRESTProtocol,
|
|
697
|
-
|
|
698
|
-
|
|
708
|
+
de as PersonaRuntimeProvider,
|
|
709
|
+
ae as PersonaTransactionProtocol,
|
|
699
710
|
z as PersonaWebRTCProtocol,
|
|
700
711
|
I as PersonaWebSocketProtocol,
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
712
|
+
fe as usePersonaRuntime,
|
|
713
|
+
pe as usePersonaRuntimeEndpoint,
|
|
714
|
+
ye as usePersonaRuntimeMessages,
|
|
715
|
+
ce as usePersonaRuntimeProtocol,
|
|
716
|
+
ge as usePersonaRuntimeWebRTCProtocol
|
|
705
717
|
};
|
|
706
718
|
//# sourceMappingURL=bundle.es.js.map
|