@applica-software-guru/persona-sdk 0.1.65 → 0.1.67
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 +91 -90
- 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/protocol/transaction.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/protocol/transaction.ts +12 -1
package/dist/bundle.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var B = Object.defineProperty;
|
|
2
2
|
var V = (o, t, e) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
3
|
var r = (o, t, e) => V(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { createContext as Y, useContext as A, useState as E, useRef as G, useMemo as H, useEffect as Q, useCallback as
|
|
4
|
+
import { createContext as Y, useContext as A, useState as E, useRef as G, useMemo as H, useEffect as Q, useCallback as N } from "react";
|
|
5
5
|
import { useExternalStoreRuntime as X, CompositeAttachmentAdapter as Z, SimpleImageAttachmentAdapter as ee, AssistantRuntimeProvider as te } from "@assistant-ui/react";
|
|
6
6
|
var F = { exports: {} }, k = {};
|
|
7
7
|
/**
|
|
@@ -13,17 +13,17 @@ var F = { exports: {} }, k = {};
|
|
|
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
|
|
16
|
+
var O;
|
|
17
17
|
function se() {
|
|
18
|
-
if (
|
|
19
|
-
|
|
18
|
+
if (O) return k;
|
|
19
|
+
O = 1;
|
|
20
20
|
var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
21
|
function e(s, n, a) {
|
|
22
22
|
var i = null;
|
|
23
23
|
if (a !== void 0 && (i = "" + a), n.key !== void 0 && (i = "" + n.key), "key" in n) {
|
|
24
24
|
a = {};
|
|
25
|
-
for (var
|
|
26
|
-
|
|
25
|
+
for (var c in n)
|
|
26
|
+
c !== "key" && (a[c] = n[c]);
|
|
27
27
|
} else a = n;
|
|
28
28
|
return n = a.ref, {
|
|
29
29
|
$$typeof: o,
|
|
@@ -36,14 +36,14 @@ function se() {
|
|
|
36
36
|
return k.Fragment = t, k.jsx = e, k.jsxs = e, k;
|
|
37
37
|
}
|
|
38
38
|
F.exports = se();
|
|
39
|
-
var
|
|
39
|
+
var M = F.exports;
|
|
40
40
|
function ne(o) {
|
|
41
41
|
return o.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 j(o) {
|
|
47
47
|
const t = [];
|
|
48
48
|
let e = null;
|
|
49
49
|
for (const n of o)
|
|
@@ -147,10 +147,10 @@ class _ extends v {
|
|
|
147
147
|
this.session = e;
|
|
148
148
|
}
|
|
149
149
|
async sendPacket(e) {
|
|
150
|
-
var u,
|
|
150
|
+
var u, d, g, w;
|
|
151
151
|
const { apiUrl: s, apiKey: n, agentId: a } = this.config, i = this.session ?? "new";
|
|
152
152
|
if (e.type === "command" && ((u = e == null ? void 0 : e.payload) == null ? void 0 : u.command) == "set_initial_context") {
|
|
153
|
-
this.context = (
|
|
153
|
+
this.context = (d = e == null ? void 0 : e.payload) == null ? void 0 : d.arguments;
|
|
154
154
|
return;
|
|
155
155
|
} else if (e.type === "command" && ((g = e == null ? void 0 : e.payload) == null ? void 0 : g.command) == "set_local_tools") {
|
|
156
156
|
this.notifyPacket({
|
|
@@ -163,10 +163,10 @@ class _ extends v {
|
|
|
163
163
|
});
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
const
|
|
166
|
+
const c = e.payload;
|
|
167
167
|
try {
|
|
168
168
|
const b = await (await fetch(`${s}/sessions/${i}/messages`, {
|
|
169
|
-
body: JSON.stringify({ agentId: a, userMessage:
|
|
169
|
+
body: JSON.stringify({ agentId: a, userMessage: c, initialContext: this.context, tools: this.tools }),
|
|
170
170
|
method: "POST",
|
|
171
171
|
headers: {
|
|
172
172
|
"Content-Type": "application/json",
|
|
@@ -212,19 +212,19 @@ class W extends v {
|
|
|
212
212
|
(s = this.config.logger) == null || s.debug("Syncing session with WebSocket protocol:", e), this.session = e, this.webSocket && this.status === "connected" && (this.disconnect(), this.connect(e));
|
|
213
213
|
}
|
|
214
214
|
connect(e) {
|
|
215
|
-
var
|
|
215
|
+
var c;
|
|
216
216
|
if (this.webSocket !== null && this.status === "connected")
|
|
217
217
|
return Promise.resolve(this.session);
|
|
218
218
|
const s = e || this.session || "new";
|
|
219
|
-
(
|
|
219
|
+
(c = this.config.logger) == null || c.debug("Connecting to WebSocket with sessionId:", s);
|
|
220
220
|
const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, i = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
|
|
221
221
|
return this.setStatus("connecting"), this.webSocket = new WebSocket(i), this.webSocket.addEventListener("open", () => {
|
|
222
222
|
this.setStatus("connected");
|
|
223
223
|
}), this.webSocket.addEventListener("message", (u) => {
|
|
224
|
-
const
|
|
225
|
-
this.notifyPacket(
|
|
224
|
+
const d = JSON.parse(u.data);
|
|
225
|
+
this.notifyPacket(d);
|
|
226
226
|
}), this.webSocket.addEventListener("close", (u) => {
|
|
227
|
-
var
|
|
227
|
+
var d;
|
|
228
228
|
this.setStatus("disconnected"), this.webSocket = null, u.code !== 1e3 && (this.notifyPacket({
|
|
229
229
|
type: "message",
|
|
230
230
|
payload: {
|
|
@@ -232,7 +232,7 @@ class W extends v {
|
|
|
232
232
|
type: "text",
|
|
233
233
|
text: "Oops! The connection to the server was lost. Please try again later."
|
|
234
234
|
}
|
|
235
|
-
}), (
|
|
235
|
+
}), (d = this.config.logger) == null || d.warn("WebSocket connection closed"));
|
|
236
236
|
}), this.webSocket.addEventListener("error", () => {
|
|
237
237
|
var u;
|
|
238
238
|
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.error("WebSocket connection error");
|
|
@@ -294,8 +294,8 @@ class ae {
|
|
|
294
294
|
}), this.audioCtx || this._startAnalyzers();
|
|
295
295
|
const a = new Audio();
|
|
296
296
|
a.srcObject = this.remoteStream, a.play().catch((i) => {
|
|
297
|
-
var
|
|
298
|
-
(
|
|
297
|
+
var c;
|
|
298
|
+
(c = this.config.logger) == null || c.error("Error playing remote audio:", i);
|
|
299
299
|
});
|
|
300
300
|
}, this.pc.onicecandidate = (n) => {
|
|
301
301
|
var a;
|
|
@@ -309,20 +309,20 @@ class ae {
|
|
|
309
309
|
}, this.pc.ondatachannel = (n) => {
|
|
310
310
|
const a = n.channel;
|
|
311
311
|
a.onmessage = (i) => {
|
|
312
|
-
this.messageCallbacks.forEach((
|
|
313
|
-
|
|
312
|
+
this.messageCallbacks.forEach((c) => {
|
|
313
|
+
c(i);
|
|
314
314
|
});
|
|
315
315
|
}, a.onopen = () => {
|
|
316
316
|
var i;
|
|
317
317
|
for (; this.queuedMessages.length > 0; ) {
|
|
318
|
-
const
|
|
319
|
-
|
|
318
|
+
const c = this.queuedMessages.shift();
|
|
319
|
+
c && (a.send(JSON.stringify(c)), (i = this.config.logger) == null || i.info("Sent queued message:", c));
|
|
320
320
|
}
|
|
321
321
|
};
|
|
322
322
|
};
|
|
323
323
|
const e = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
|
|
324
324
|
this.ws = new WebSocket(`${e}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
|
|
325
|
-
var
|
|
325
|
+
var c, u;
|
|
326
326
|
const n = await this.pc.createOffer();
|
|
327
327
|
await this.pc.setLocalDescription(n);
|
|
328
328
|
const a = {
|
|
@@ -330,7 +330,7 @@ class ae {
|
|
|
330
330
|
agentId: this.config.agentId,
|
|
331
331
|
sessionCode: t
|
|
332
332
|
};
|
|
333
|
-
(
|
|
333
|
+
(c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ", a);
|
|
334
334
|
const i = {
|
|
335
335
|
type: "OFFER",
|
|
336
336
|
src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
|
|
@@ -352,8 +352,8 @@ class ae {
|
|
|
352
352
|
else if (a.type === "CANDIDATE")
|
|
353
353
|
try {
|
|
354
354
|
await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
|
|
355
|
-
} catch (
|
|
356
|
-
(i = this.config.logger) == null || i.error("Error adding ICE candidate:",
|
|
355
|
+
} catch (c) {
|
|
356
|
+
(i = this.config.logger) == null || i.error("Error adding ICE candidate:", c);
|
|
357
357
|
}
|
|
358
358
|
}, this.ws.onclose = (n) => {
|
|
359
359
|
n.code !== 1e3 && this.errorCallbacks.forEach((a) => {
|
|
@@ -406,11 +406,11 @@ class ae {
|
|
|
406
406
|
return;
|
|
407
407
|
const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
408
408
|
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
|
|
409
|
-
const i = n.reduce((u,
|
|
409
|
+
const i = n.reduce((u, d) => u + d, 0) / n.length, c = a.reduce((u, d) => u + d, 0) / a.length;
|
|
410
410
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
411
411
|
u({
|
|
412
412
|
localAmplitude: i,
|
|
413
|
-
remoteAmplitude:
|
|
413
|
+
remoteAmplitude: c
|
|
414
414
|
});
|
|
415
415
|
}), this.analyzerFrame = requestAnimationFrame(s);
|
|
416
416
|
};
|
|
@@ -501,6 +501,7 @@ class re {
|
|
|
501
501
|
return this.transaction.functionCall;
|
|
502
502
|
}
|
|
503
503
|
async invoke(t) {
|
|
504
|
+
var i;
|
|
504
505
|
const e = this.transaction.functionCall;
|
|
505
506
|
if (!e) {
|
|
506
507
|
await this.fail("No function call found");
|
|
@@ -512,10 +513,10 @@ class re {
|
|
|
512
513
|
return;
|
|
513
514
|
}
|
|
514
515
|
try {
|
|
515
|
-
const i =
|
|
516
|
-
await this.complete(
|
|
517
|
-
} catch (
|
|
518
|
-
await this.fail(`Error executing tool ${s}: ${
|
|
516
|
+
const u = (((i = a.toString().replace(/\n/g, " ").match(/^[^(]*\(([^)]*)\)/)) == null ? void 0 : i[1].split(",").map((g) => g.trim()).filter(Boolean)) || []).map((g) => n[g]), d = await a.apply(null, u);
|
|
517
|
+
await this.complete(d);
|
|
518
|
+
} catch (c) {
|
|
519
|
+
await this.fail(`Error executing tool ${s}: ${c}`);
|
|
519
520
|
}
|
|
520
521
|
}
|
|
521
522
|
async complete(t) {
|
|
@@ -588,33 +589,33 @@ function ue({
|
|
|
588
589
|
session: a = "new",
|
|
589
590
|
...i
|
|
590
591
|
}) {
|
|
591
|
-
const [
|
|
592
|
+
const [c, u] = E(!1), [d, g] = E([]), [w, R] = E(a), [b, $] = E(/* @__PURE__ */ new Map()), q = G(!1), S = H(() => {
|
|
592
593
|
if (Array.isArray(e))
|
|
593
594
|
return e;
|
|
594
595
|
if (typeof e == "object" && e !== null) {
|
|
595
|
-
const
|
|
596
|
-
let
|
|
596
|
+
const l = o ? "localhost:8000" : t || "persona.applica.guru/api", m = o ? "http" : "https", h = o ? "ws" : "wss";
|
|
597
|
+
let f = Object.keys(e).map((y) => {
|
|
597
598
|
switch (y) {
|
|
598
599
|
case "rest":
|
|
599
|
-
const
|
|
600
|
-
return
|
|
601
|
-
apiUrl: `${
|
|
600
|
+
const p = e[y];
|
|
601
|
+
return p === !0 ? new _({
|
|
602
|
+
apiUrl: `${m}://${l}`,
|
|
602
603
|
apiKey: i.apiKey,
|
|
603
604
|
agentId: i.agentId,
|
|
604
605
|
logger: s
|
|
605
|
-
}) : typeof
|
|
606
|
+
}) : typeof p == "object" && p !== null ? new _(p) : null;
|
|
606
607
|
case "webrtc":
|
|
607
|
-
const
|
|
608
|
-
return
|
|
609
|
-
webrtcUrl: `${h}://${
|
|
608
|
+
const C = e[y];
|
|
609
|
+
return C === !0 ? new z({
|
|
610
|
+
webrtcUrl: `${h}://${l}/webrtc`,
|
|
610
611
|
apiKey: i.apiKey,
|
|
611
612
|
agentId: i.agentId,
|
|
612
613
|
logger: s
|
|
613
|
-
}) : typeof
|
|
614
|
+
}) : typeof C == "object" && C !== null ? new z(C) : null;
|
|
614
615
|
case "websocket":
|
|
615
616
|
const T = e[y];
|
|
616
617
|
return T === !0 ? new W({
|
|
617
|
-
webSocketUrl: `${h}://${
|
|
618
|
+
webSocketUrl: `${h}://${l}/websocket`,
|
|
618
619
|
apiKey: i.apiKey,
|
|
619
620
|
agentId: i.agentId,
|
|
620
621
|
logger: s
|
|
@@ -623,32 +624,32 @@ function ue({
|
|
|
623
624
|
throw new Error(`Unknown protocol: ${y}`);
|
|
624
625
|
}
|
|
625
626
|
}).filter((y) => y !== null);
|
|
626
|
-
return i.tools &&
|
|
627
|
+
return i.tools && f.push(
|
|
627
628
|
new ce({
|
|
628
|
-
apiUrl: `${
|
|
629
|
+
apiUrl: `${m}://${l}`,
|
|
629
630
|
apiKey: i.apiKey,
|
|
630
631
|
agentId: i.agentId,
|
|
631
632
|
tools: i.tools,
|
|
632
633
|
// Pass raw tools
|
|
633
634
|
logger: s
|
|
634
635
|
})
|
|
635
|
-
),
|
|
636
|
+
), f;
|
|
636
637
|
}
|
|
637
638
|
throw new Error("Invalid protocols configuration");
|
|
638
639
|
}, []);
|
|
639
640
|
Q(() => {
|
|
640
|
-
|
|
641
|
+
q.current || (q.current = !0, s == null || s.debug(
|
|
641
642
|
"Initializing protocols: ",
|
|
642
|
-
|
|
643
|
-
),
|
|
644
|
-
|
|
645
|
-
s == null || s.debug(`${
|
|
643
|
+
S.map((l) => l.getName())
|
|
644
|
+
), S.forEach((l) => {
|
|
645
|
+
l.setSession(w), l.clearListeners(), l.addStatusChangeListener((m) => {
|
|
646
|
+
s == null || s.debug(`${l.getName()} has notified new status: ${m}`), b.set(l.getName(), m), m === "connected" && (i.context && l.sendPacket({
|
|
646
647
|
type: "command",
|
|
647
648
|
payload: {
|
|
648
649
|
command: "set_initial_context",
|
|
649
650
|
arguments: i.context
|
|
650
651
|
}
|
|
651
|
-
}), i.tools && Array.isArray(i.tools) &&
|
|
652
|
+
}), i.tools && Array.isArray(i.tools) && l.sendPacket({
|
|
652
653
|
type: "command",
|
|
653
654
|
payload: {
|
|
654
655
|
command: "set_local_tools",
|
|
@@ -657,51 +658,51 @@ function ue({
|
|
|
657
658
|
}
|
|
658
659
|
}
|
|
659
660
|
})), $(new Map(b));
|
|
660
|
-
}),
|
|
661
|
-
if (
|
|
662
|
-
const h =
|
|
661
|
+
}), l.addPacketListener((m) => {
|
|
662
|
+
if (m.type === "message") {
|
|
663
|
+
const h = m.payload;
|
|
663
664
|
g(
|
|
664
|
-
(
|
|
665
|
+
(f) => j([...f, { ...h, protocol: l.getName() }])
|
|
665
666
|
);
|
|
666
|
-
} else if (
|
|
667
|
-
const h =
|
|
668
|
-
let
|
|
669
|
-
h.imageUrl && (
|
|
667
|
+
} else if (m.type === "reasoning") {
|
|
668
|
+
const h = m.payload;
|
|
669
|
+
let f = h.thought;
|
|
670
|
+
h.imageUrl && (f += `
|
|
670
671
|
|
|
671
672
|
`);
|
|
672
|
-
const y = { type: "reasoning", text:
|
|
673
|
+
const y = { type: "reasoning", text: f, role: "assistant", finishReason: "stop" };
|
|
673
674
|
g(
|
|
674
|
-
(
|
|
675
|
+
(p) => j([...p, { ...y, protocol: l.getName() }])
|
|
675
676
|
);
|
|
676
|
-
} else
|
|
677
|
-
}),
|
|
677
|
+
} else m.type === "transaction" && S.filter((h) => h !== l).forEach((h) => h.onTransaction(m.payload));
|
|
678
|
+
}), l.autostart && l.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${l.getName()}`), l.connect(w));
|
|
678
679
|
}));
|
|
679
|
-
}, [w,
|
|
680
|
-
const U = async (
|
|
680
|
+
}, [w, S, s, b]);
|
|
681
|
+
const U = async (l) => {
|
|
681
682
|
var y;
|
|
682
|
-
if (((y =
|
|
683
|
-
const
|
|
684
|
-
g((
|
|
685
|
-
const h =
|
|
686
|
-
if (
|
|
687
|
-
for (const
|
|
688
|
-
|
|
683
|
+
if (((y = l.content[0]) == null ? void 0 : y.type) !== "text") throw new Error("Only text messages are supported");
|
|
684
|
+
const m = l.content[0].text;
|
|
685
|
+
g((p) => [...p, { role: "user", type: "text", text: m }]), u(!0);
|
|
686
|
+
const h = S.sort((p, C) => C.getPriority() - p.getPriority()).find((p) => p.status === "connected"), f = [];
|
|
687
|
+
if (l.attachments)
|
|
688
|
+
for (const p of l.attachments)
|
|
689
|
+
p.contentType.startsWith("image/") && p.file && f.push({
|
|
689
690
|
role: "user",
|
|
690
691
|
image: {
|
|
691
|
-
contentType:
|
|
692
|
-
content: await le(
|
|
692
|
+
contentType: p.contentType,
|
|
693
|
+
content: await le(p.file)
|
|
693
694
|
},
|
|
694
695
|
text: "",
|
|
695
696
|
type: "text"
|
|
696
697
|
});
|
|
697
|
-
|
|
698
|
+
l.content && f.push({
|
|
698
699
|
role: "user",
|
|
699
|
-
text:
|
|
700
|
+
text: l.content[0].text,
|
|
700
701
|
type: "text"
|
|
701
|
-
}), s == null || s.debug("Sending message:",
|
|
702
|
-
}, D =
|
|
703
|
-
isRunning:
|
|
704
|
-
messages:
|
|
702
|
+
}), s == null || s.debug("Sending message:", f), await (h == null ? void 0 : h.sendPacket({ type: "request", payload: f })), u(!1);
|
|
703
|
+
}, D = N(() => (u(!1), g([]), R("new"), Promise.resolve()), []), L = N(() => Promise.resolve(), []), J = N(() => d, [d]), K = X({
|
|
704
|
+
isRunning: c,
|
|
705
|
+
messages: d,
|
|
705
706
|
convertMessage: oe,
|
|
706
707
|
onNew: U,
|
|
707
708
|
onCancel: D,
|
|
@@ -710,10 +711,10 @@ function ue({
|
|
|
710
711
|
attachments: new Z([new ee()])
|
|
711
712
|
}
|
|
712
713
|
});
|
|
713
|
-
return /* @__PURE__ */
|
|
714
|
+
return /* @__PURE__ */ M.jsx(x.Provider, { value: { protocols: S, protocolsStatus: b, getMessages: J }, children: /* @__PURE__ */ M.jsx(te, { runtime: K, children: n }) });
|
|
714
715
|
}
|
|
715
716
|
function ge({ children: o, ...t }) {
|
|
716
|
-
return /* @__PURE__ */
|
|
717
|
+
return /* @__PURE__ */ M.jsx(ue, { ...t, children: o });
|
|
717
718
|
}
|
|
718
719
|
function we() {
|
|
719
720
|
const o = A(x);
|
|
@@ -751,10 +752,10 @@ function be() {
|
|
|
751
752
|
return t.config.apiUrl;
|
|
752
753
|
throw new Error("REST protocol not found");
|
|
753
754
|
}
|
|
754
|
-
function
|
|
755
|
+
function Se() {
|
|
755
756
|
return he("webrtc");
|
|
756
757
|
}
|
|
757
|
-
function
|
|
758
|
+
function Ce() {
|
|
758
759
|
const o = A(x);
|
|
759
760
|
if (!o)
|
|
760
761
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
@@ -900,9 +901,9 @@ export {
|
|
|
900
901
|
ke as sumTool,
|
|
901
902
|
we as usePersonaRuntime,
|
|
902
903
|
be as usePersonaRuntimeEndpoint,
|
|
903
|
-
|
|
904
|
+
Ce as usePersonaRuntimeMessages,
|
|
904
905
|
he as usePersonaRuntimeProtocol,
|
|
905
|
-
|
|
906
|
+
Se as usePersonaRuntimeWebRTCProtocol,
|
|
906
907
|
Te as validateToolParameters
|
|
907
908
|
};
|
|
908
909
|
//# sourceMappingURL=bundle.es.js.map
|