@applica-software-guru/persona-sdk 0.1.56 → 0.1.57
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 +2 -2
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +104 -99
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +2 -2
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +2 -2
- package/dist/bundle.umd.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/runtime.tsx +9 -0
- package/src/types.ts +6 -2
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (a, t, e) =>
|
|
4
|
-
import { createContext as
|
|
5
|
-
import { useExternalStoreRuntime as
|
|
6
|
-
var
|
|
1
|
+
var J = Object.defineProperty;
|
|
2
|
+
var K = (a, t, e) => t in a ? J(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
+
var o = (a, t, e) => K(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createContext as q, useContext as E, useState as P, useRef as _, useMemo as B, useEffect as Y, useCallback as v } from "react";
|
|
5
|
+
import { useExternalStoreRuntime as G, CompositeAttachmentAdapter as V, SimpleImageAttachmentAdapter as H, AssistantRuntimeProvider as Q } from "@assistant-ui/react";
|
|
6
|
+
var D = { exports: {} }, C = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
@@ -14,13 +14,13 @@ var z = { exports: {} }, C = {};
|
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*/
|
|
16
16
|
var $;
|
|
17
|
-
function
|
|
17
|
+
function X() {
|
|
18
18
|
if ($) return C;
|
|
19
19
|
$ = 1;
|
|
20
20
|
var a = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
21
|
function e(n, s, i) {
|
|
22
|
-
var
|
|
23
|
-
if (i !== void 0 && (
|
|
22
|
+
var c = null;
|
|
23
|
+
if (i !== void 0 && (c = "" + i), s.key !== void 0 && (c = "" + s.key), "key" in s) {
|
|
24
24
|
i = {};
|
|
25
25
|
for (var l in s)
|
|
26
26
|
l !== "key" && (i[l] = s[l]);
|
|
@@ -28,22 +28,22 @@ function Q() {
|
|
|
28
28
|
return s = i.ref, {
|
|
29
29
|
$$typeof: a,
|
|
30
30
|
type: n,
|
|
31
|
-
key:
|
|
31
|
+
key: c,
|
|
32
32
|
ref: s !== void 0 ? s : null,
|
|
33
33
|
props: i
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
return C.Fragment = t, C.jsx = e, C.jsxs = e, C;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
var A =
|
|
40
|
-
function
|
|
38
|
+
D.exports = X();
|
|
39
|
+
var A = D.exports;
|
|
40
|
+
function Z(a) {
|
|
41
41
|
return a.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 M(a) {
|
|
47
47
|
const t = [];
|
|
48
48
|
let e = null;
|
|
49
49
|
for (const s of a)
|
|
@@ -53,7 +53,7 @@ function Z(a) {
|
|
|
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), Z(t);
|
|
57
57
|
}
|
|
58
58
|
function ee(a) {
|
|
59
59
|
var e, n;
|
|
@@ -119,7 +119,7 @@ class x {
|
|
|
119
119
|
onTransaction(t) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class
|
|
122
|
+
class N extends x {
|
|
123
123
|
constructor(e) {
|
|
124
124
|
super();
|
|
125
125
|
o(this, "status");
|
|
@@ -145,7 +145,7 @@ class M extends x {
|
|
|
145
145
|
this.session = e;
|
|
146
146
|
}
|
|
147
147
|
async send(e) {
|
|
148
|
-
const { apiUrl: n, apiKey: s, agentId: i } = this.config,
|
|
148
|
+
const { apiUrl: n, apiKey: s, agentId: i } = this.config, c = this.session ?? "new", l = e, h = await (await fetch(`${n}/agents/${i}/sessions/${c}/messages`, {
|
|
149
149
|
body: JSON.stringify({ userMessage: l }),
|
|
150
150
|
method: "POST",
|
|
151
151
|
headers: {
|
|
@@ -155,14 +155,14 @@ class M extends x {
|
|
|
155
155
|
}
|
|
156
156
|
})).json();
|
|
157
157
|
this.notifyMessages(
|
|
158
|
-
|
|
158
|
+
h.response.messages.map((b) => ({
|
|
159
159
|
type: "message",
|
|
160
160
|
payload: b
|
|
161
161
|
}))
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
class
|
|
165
|
+
class I extends x {
|
|
166
166
|
constructor(e) {
|
|
167
167
|
super();
|
|
168
168
|
o(this, "status");
|
|
@@ -188,18 +188,18 @@ class N 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), i = this.config.agentId,
|
|
192
|
-
return this.setStatus("connecting"), this.webSocket = new WebSocket(
|
|
191
|
+
const s = encodeURIComponent(this.config.apiKey), i = this.config.agentId, c = `${this.config.webSocketUrl}?sessionCode=${n}&agentId=${i}&apiKey=${s}`;
|
|
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 h = JSON.parse(u.data);
|
|
196
|
+
this.notifyMessage(h);
|
|
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 h;
|
|
202
|
+
this.setStatus("disconnected"), this.webSocket = null, (h = this.config.logger) == null || h.error("WebSocket error", u);
|
|
203
203
|
}), Promise.resolve(n);
|
|
204
204
|
}
|
|
205
205
|
disconnect() {
|
|
@@ -251,13 +251,13 @@ class te {
|
|
|
251
251
|
}), this.localStream.getTracks().forEach((s) => {
|
|
252
252
|
this.pc.addTrack(s, this.localStream);
|
|
253
253
|
}), this.pc.ontrack = (s) => {
|
|
254
|
-
s.streams[0].getTracks().forEach((
|
|
255
|
-
this.remoteStream.addTrack(
|
|
254
|
+
s.streams[0].getTracks().forEach((c) => {
|
|
255
|
+
this.remoteStream.addTrack(c);
|
|
256
256
|
}), this.audioCtx || this._startAnalyzers();
|
|
257
257
|
const i = new Audio();
|
|
258
|
-
i.srcObject = this.remoteStream, i.play().catch((
|
|
258
|
+
i.srcObject = this.remoteStream, i.play().catch((c) => {
|
|
259
259
|
var l;
|
|
260
|
-
(l = this.config.logger) == null || l.error("Error playing remote audio:",
|
|
260
|
+
(l = this.config.logger) == null || l.error("Error playing remote audio:", c);
|
|
261
261
|
});
|
|
262
262
|
}, this.pc.onicecandidate = (s) => {
|
|
263
263
|
var i;
|
|
@@ -270,9 +270,9 @@ class te {
|
|
|
270
270
|
);
|
|
271
271
|
}, this.pc.ondatachannel = (s) => {
|
|
272
272
|
const i = s.channel;
|
|
273
|
-
i.onmessage = (
|
|
273
|
+
i.onmessage = (c) => {
|
|
274
274
|
this.messageCallbacks.forEach((l) => {
|
|
275
|
-
l(
|
|
275
|
+
l(c);
|
|
276
276
|
});
|
|
277
277
|
};
|
|
278
278
|
};
|
|
@@ -287,7 +287,7 @@ class te {
|
|
|
287
287
|
sessionCode: t
|
|
288
288
|
};
|
|
289
289
|
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", i);
|
|
290
|
-
const
|
|
290
|
+
const c = {
|
|
291
291
|
type: "OFFER",
|
|
292
292
|
src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
|
|
293
293
|
payload: {
|
|
@@ -299,9 +299,9 @@ class te {
|
|
|
299
299
|
metadata: i
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
|
-
this.ws.send(JSON.stringify(
|
|
302
|
+
this.ws.send(JSON.stringify(c));
|
|
303
303
|
}, this.ws.onmessage = async (s) => {
|
|
304
|
-
var
|
|
304
|
+
var c;
|
|
305
305
|
const i = JSON.parse(s.data);
|
|
306
306
|
if (i.type === "ANSWER")
|
|
307
307
|
await this.pc.setRemoteDescription(new RTCSessionDescription(i.payload.sdp));
|
|
@@ -309,7 +309,7 @@ class te {
|
|
|
309
309
|
try {
|
|
310
310
|
await this.pc.addIceCandidate(new RTCIceCandidate(i.payload.candidate));
|
|
311
311
|
} catch (l) {
|
|
312
|
-
(
|
|
312
|
+
(c = this.config.logger) == null || c.error("Error adding ICE candidate:", l);
|
|
313
313
|
}
|
|
314
314
|
}, this.ws.onclose = () => {
|
|
315
315
|
this._stopAnalyzers();
|
|
@@ -354,10 +354,10 @@ class te {
|
|
|
354
354
|
return;
|
|
355
355
|
const s = new Uint8Array(this.localAnalyser.frequencyBinCount), i = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
356
356
|
this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(i);
|
|
357
|
-
const
|
|
357
|
+
const c = s.reduce((u, h) => u + h, 0) / s.length, l = i.reduce((u, h) => u + h, 0) / i.length;
|
|
358
358
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
359
359
|
u({
|
|
360
|
-
localAmplitude:
|
|
360
|
+
localAmplitude: c,
|
|
361
361
|
remoteAmplitude: l
|
|
362
362
|
});
|
|
363
363
|
}), this.analyzerFrame = requestAnimationFrame(n);
|
|
@@ -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
|
|
371
|
+
class z extends x {
|
|
372
372
|
constructor(e) {
|
|
373
373
|
super();
|
|
374
374
|
o(this, "status");
|
|
@@ -450,10 +450,10 @@ class ne {
|
|
|
450
450
|
return;
|
|
451
451
|
}
|
|
452
452
|
try {
|
|
453
|
-
const
|
|
454
|
-
await this.complete(
|
|
455
|
-
} catch (
|
|
456
|
-
await this.fail(`Error executing tool ${n}: ${
|
|
453
|
+
const c = await i(s);
|
|
454
|
+
await this.complete(c);
|
|
455
|
+
} catch (c) {
|
|
456
|
+
await this.fail(`Error executing tool ${n}: ${c}`);
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
async complete(t) {
|
|
@@ -502,7 +502,7 @@ class ie extends x {
|
|
|
502
502
|
this.config.onTransaction(s);
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
-
const R =
|
|
505
|
+
const R = q(void 0);
|
|
506
506
|
function ae(a) {
|
|
507
507
|
return new Promise((t, e) => {
|
|
508
508
|
const n = new FileReader();
|
|
@@ -522,48 +522,48 @@ function oe({
|
|
|
522
522
|
session: s = "new",
|
|
523
523
|
...i
|
|
524
524
|
}) {
|
|
525
|
-
const [
|
|
525
|
+
const [c, l] = P(!1), [u, h] = P([]), [b, W] = P(s), [S, j] = P(/* @__PURE__ */ new Map()), T = _(!1), m = B(() => {
|
|
526
526
|
if (Array.isArray(t))
|
|
527
527
|
return t;
|
|
528
528
|
if (typeof t == "object" && t !== null) {
|
|
529
|
-
const
|
|
530
|
-
let g = Object.keys(t).map((
|
|
531
|
-
switch (
|
|
529
|
+
const r = a ? "localhost:8000" : "persona.applica.guru/api", f = a ? "http" : "https", y = a ? "ws" : "wss";
|
|
530
|
+
let g = Object.keys(t).map((p) => {
|
|
531
|
+
switch (p) {
|
|
532
532
|
case "rest":
|
|
533
|
-
const
|
|
534
|
-
return
|
|
535
|
-
apiUrl: `${f}://${
|
|
533
|
+
const d = t[p];
|
|
534
|
+
return d === !0 ? new N({
|
|
535
|
+
apiUrl: `${f}://${r}`,
|
|
536
536
|
apiKey: i.apiKey,
|
|
537
537
|
agentId: i.agentId,
|
|
538
538
|
logger: e
|
|
539
|
-
}) : typeof
|
|
539
|
+
}) : typeof d == "object" && d !== null ? new N(d) : null;
|
|
540
540
|
case "webrtc":
|
|
541
|
-
const w = t[
|
|
542
|
-
return w === !0 ? new
|
|
543
|
-
webrtcUrl: `${
|
|
541
|
+
const w = t[p];
|
|
542
|
+
return w === !0 ? new z({
|
|
543
|
+
webrtcUrl: `${y}://${r}/webrtc`,
|
|
544
544
|
apiKey: i.apiKey,
|
|
545
545
|
agentId: i.agentId,
|
|
546
546
|
logger: e
|
|
547
|
-
}) : typeof w == "object" && w !== null ? new
|
|
547
|
+
}) : typeof w == "object" && w !== null ? new z(w) : null;
|
|
548
548
|
case "websocket":
|
|
549
|
-
const k = t[
|
|
550
|
-
return k === !0 ? new
|
|
551
|
-
webSocketUrl: `${
|
|
549
|
+
const k = t[p];
|
|
550
|
+
return k === !0 ? new I({
|
|
551
|
+
webSocketUrl: `${y}://${r}/websocket`,
|
|
552
552
|
apiKey: i.apiKey,
|
|
553
553
|
agentId: i.agentId,
|
|
554
554
|
logger: e
|
|
555
|
-
}) : typeof k == "object" && k !== null ? new
|
|
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: ${p}`);
|
|
558
558
|
}
|
|
559
|
-
}).filter((
|
|
559
|
+
}).filter((p) => p !== null);
|
|
560
560
|
return i.tools && g.push(
|
|
561
561
|
new ie({
|
|
562
|
-
apiUrl: `${f}://${
|
|
562
|
+
apiUrl: `${f}://${r}`,
|
|
563
563
|
apiKey: i.apiKey,
|
|
564
564
|
agentId: i.agentId,
|
|
565
|
-
onTransaction: async (
|
|
566
|
-
await
|
|
565
|
+
onTransaction: async (p) => {
|
|
566
|
+
await p.invoke(i.tools);
|
|
567
567
|
},
|
|
568
568
|
logger: e
|
|
569
569
|
})
|
|
@@ -571,57 +571,62 @@ function oe({
|
|
|
571
571
|
}
|
|
572
572
|
throw new Error("Invalid protocols configuration");
|
|
573
573
|
}, []);
|
|
574
|
-
|
|
574
|
+
Y(() => {
|
|
575
575
|
T.current || (T.current = !0, e == null || e.debug(
|
|
576
576
|
"Initializing protocols: ",
|
|
577
|
-
m.map((
|
|
578
|
-
), m.forEach((
|
|
579
|
-
|
|
580
|
-
e == null || e.debug(`${
|
|
581
|
-
}),
|
|
577
|
+
m.map((r) => r.getName())
|
|
578
|
+
), m.forEach((r) => {
|
|
579
|
+
r.setSession(b), r.clearListeners(), r.addStatusChangeListener((f) => {
|
|
580
|
+
e == null || e.debug(`${r.getName()} has notified new status: ${f}`), S.set(r.getName(), f), j(new Map(S));
|
|
581
|
+
}), r.addMessageListener((f) => {
|
|
582
582
|
if (f.type === "message") {
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
(g) =>
|
|
583
|
+
const y = f.payload;
|
|
584
|
+
h(
|
|
585
|
+
(g) => M([...g, { ...y, protocol: r.getName() }])
|
|
586
|
+
);
|
|
587
|
+
} else if (f.type === "reasoning") {
|
|
588
|
+
const g = { type: "reasoning", text: f.payload.thought, role: "assistant", finishReason: "stop" };
|
|
589
|
+
h(
|
|
590
|
+
(p) => M([...p, { ...g, protocol: r.getName() }])
|
|
586
591
|
);
|
|
587
|
-
} else f.type === "transaction" && m.filter((
|
|
588
|
-
}),
|
|
592
|
+
} else f.type === "transaction" && m.filter((y) => y !== r).forEach((y) => y.onTransaction(f.payload));
|
|
593
|
+
}), r.autostart && r.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${r.getName()}`), r.connect(b));
|
|
589
594
|
}));
|
|
590
595
|
}, [b, m, e, S]);
|
|
591
|
-
const
|
|
592
|
-
var
|
|
593
|
-
if (((
|
|
594
|
-
const f =
|
|
595
|
-
|
|
596
|
-
const
|
|
597
|
-
if (
|
|
598
|
-
for (const
|
|
599
|
-
|
|
596
|
+
const O = async (r) => {
|
|
597
|
+
var p;
|
|
598
|
+
if (((p = r.content[0]) == null ? void 0 : p.type) !== "text") throw new Error("Only text messages are supported");
|
|
599
|
+
const f = r.content[0].text;
|
|
600
|
+
h((d) => [...d, { role: "user", type: "text", text: f }]), l(!0);
|
|
601
|
+
const y = m.sort((d, w) => w.getPriority() - d.getPriority()).find((d) => d.status === "connected"), g = [];
|
|
602
|
+
if (r.attachments)
|
|
603
|
+
for (const d of r.attachments)
|
|
604
|
+
d.contentType.startsWith("image/") && d.file && g.push({
|
|
600
605
|
role: "user",
|
|
601
606
|
image: {
|
|
602
|
-
contentType:
|
|
603
|
-
content: await ae(
|
|
607
|
+
contentType: d.contentType,
|
|
608
|
+
content: await ae(d.file)
|
|
604
609
|
},
|
|
605
610
|
text: "",
|
|
606
611
|
type: "text"
|
|
607
612
|
});
|
|
608
|
-
|
|
613
|
+
r.content && g.push({
|
|
609
614
|
role: "user",
|
|
610
|
-
text:
|
|
615
|
+
text: r.content[0].text,
|
|
611
616
|
type: "text"
|
|
612
|
-
}), e == null || e.debug("Sending message:", g), await (
|
|
613
|
-
},
|
|
614
|
-
isRunning:
|
|
617
|
+
}), e == null || e.debug("Sending message:", g), await (y == null ? void 0 : y.send(g)), l(!1);
|
|
618
|
+
}, U = v(() => (l(!1), h([]), W("new"), Promise.resolve()), []), L = v(() => Promise.resolve(), []), F = G({
|
|
619
|
+
isRunning: c,
|
|
615
620
|
messages: u,
|
|
616
621
|
convertMessage: ee,
|
|
617
|
-
onNew:
|
|
618
|
-
onCancel:
|
|
619
|
-
onReload:
|
|
622
|
+
onNew: O,
|
|
623
|
+
onCancel: U,
|
|
624
|
+
onReload: L,
|
|
620
625
|
adapters: {
|
|
621
|
-
attachments: new
|
|
626
|
+
attachments: new V([new H()])
|
|
622
627
|
}
|
|
623
628
|
});
|
|
624
|
-
return /* @__PURE__ */ A.jsx(R.Provider, { value: { protocols: m, protocolsStatus: S }, children: /* @__PURE__ */ A.jsx(
|
|
629
|
+
return /* @__PURE__ */ A.jsx(R.Provider, { value: { protocols: m, protocolsStatus: S }, children: /* @__PURE__ */ A.jsx(Q, { runtime: F, children: n }) });
|
|
625
630
|
}
|
|
626
631
|
function he({ children: a, ...t }) {
|
|
627
632
|
return /* @__PURE__ */ A.jsx(oe, { ...t, children: a });
|
|
@@ -688,11 +693,11 @@ class ye {
|
|
|
688
693
|
export {
|
|
689
694
|
ye as PersonaConsoleLogger,
|
|
690
695
|
x as PersonaProtocolBase,
|
|
691
|
-
|
|
696
|
+
N as PersonaRESTProtocol,
|
|
692
697
|
he as PersonaRuntimeProvider,
|
|
693
698
|
ie as PersonaTransactionProtocol,
|
|
694
|
-
|
|
695
|
-
|
|
699
|
+
z as PersonaWebRTCProtocol,
|
|
700
|
+
I as PersonaWebSocketProtocol,
|
|
696
701
|
de as usePersonaRuntime,
|
|
697
702
|
fe as usePersonaRuntimeEndpoint,
|
|
698
703
|
re as usePersonaRuntimeProtocol,
|