@applica-software-guru/persona-sdk 0.1.68 → 0.1.69
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 +265 -258
- 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/rest.d.ts.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/package.json +1 -1
- package/playground/src/chat.tsx +20 -4
- package/playground/src/tools.ts +22 -0
- package/src/protocol/rest.ts +11 -8
- package/src/runtime.tsx +27 -23
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var i = (
|
|
4
|
-
import { createContext as
|
|
5
|
-
import { useExternalStoreRuntime as
|
|
6
|
-
var
|
|
1
|
+
var V = Object.defineProperty;
|
|
2
|
+
var Y = (o, t, e) => t in o ? V(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var i = (o, t, e) => Y(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createContext as G, useContext as v, useState as E, useRef as H, useMemo as Q, useEffect as X, useCallback as M } from "react";
|
|
5
|
+
import { useExternalStoreRuntime as Z, CompositeAttachmentAdapter as ee, SimpleImageAttachmentAdapter as te, AssistantRuntimeProvider as se } from "@assistant-ui/react";
|
|
6
|
+
var W = { exports: {} }, k = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
@@ -14,77 +14,77 @@ var z = { exports: {} }, x = {};
|
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*/
|
|
16
16
|
var O;
|
|
17
|
-
function
|
|
18
|
-
if (O) return
|
|
17
|
+
function ne() {
|
|
18
|
+
if (O) return k;
|
|
19
19
|
O = 1;
|
|
20
|
-
var
|
|
21
|
-
function e(s, n,
|
|
20
|
+
var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
|
+
function e(s, n, a) {
|
|
22
22
|
var r = null;
|
|
23
|
-
if (
|
|
24
|
-
|
|
23
|
+
if (a !== void 0 && (r = "" + a), n.key !== void 0 && (r = "" + n.key), "key" in n) {
|
|
24
|
+
a = {};
|
|
25
25
|
for (var c in n)
|
|
26
|
-
c !== "key" && (
|
|
27
|
-
} else
|
|
28
|
-
return n =
|
|
29
|
-
$$typeof:
|
|
26
|
+
c !== "key" && (a[c] = n[c]);
|
|
27
|
+
} else a = n;
|
|
28
|
+
return n = a.ref, {
|
|
29
|
+
$$typeof: o,
|
|
30
30
|
type: s,
|
|
31
31
|
key: r,
|
|
32
32
|
ref: n !== void 0 ? n : null,
|
|
33
|
-
props:
|
|
33
|
+
props: a
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return k.Fragment = t, k.jsx = e, k.jsxs = e, k;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
function
|
|
41
|
-
return
|
|
38
|
+
W.exports = ne();
|
|
39
|
+
var I = W.exports;
|
|
40
|
+
function oe(o) {
|
|
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 j(
|
|
46
|
+
function j(o) {
|
|
47
47
|
const t = [];
|
|
48
48
|
let e = null;
|
|
49
|
-
for (const n of
|
|
49
|
+
for (const n of o)
|
|
50
50
|
n.type !== "transaction" && (n.type === "reasoning" ? (e != null && (t.push(e), e = null), t.push(n)) : n.functionCalls ? (e && t.push(e), t.push(n), e = null) : n.functionResponse ? t[t.length - 1] = {
|
|
51
51
|
...t[t.length - 1],
|
|
52
52
|
functionResponse: n.functionResponse
|
|
53
53
|
} : e && n.protocol === e.protocol && (e.role === n.role || n.finishReason === "stop") ? (e.text += n.text, e.files = [...e.files ?? [], ...n.files ?? []]) : (e && t.push(e), e = {
|
|
54
54
|
...n
|
|
55
55
|
}));
|
|
56
|
-
return e && t.push(e),
|
|
56
|
+
return e && t.push(e), oe(t);
|
|
57
57
|
}
|
|
58
|
-
function ae(
|
|
58
|
+
function ae(o) {
|
|
59
59
|
var e, s;
|
|
60
|
-
const t = ((e =
|
|
60
|
+
const t = ((e = o.files) == null ? void 0 : e.map(
|
|
61
61
|
(n) => ({
|
|
62
62
|
type: "file",
|
|
63
63
|
data: n.url,
|
|
64
64
|
mimeType: n.contentType
|
|
65
65
|
})
|
|
66
66
|
)) ?? [];
|
|
67
|
-
return
|
|
68
|
-
id:
|
|
67
|
+
return o.role === "function" ? {
|
|
68
|
+
id: o.id,
|
|
69
69
|
role: "assistant",
|
|
70
|
-
status: (
|
|
71
|
-
content: ((s =
|
|
72
|
-
var
|
|
70
|
+
status: (o == null ? void 0 : o.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
|
|
71
|
+
content: ((s = o.functionCalls) == null ? void 0 : s.map((n) => {
|
|
72
|
+
var a;
|
|
73
73
|
return {
|
|
74
74
|
type: "tool-call",
|
|
75
75
|
toolName: n.name,
|
|
76
76
|
toolCallId: n.id,
|
|
77
77
|
args: n.args,
|
|
78
|
-
result: (
|
|
78
|
+
result: (a = o.functionResponse) == null ? void 0 : a.result
|
|
79
79
|
};
|
|
80
80
|
})) ?? []
|
|
81
81
|
} : {
|
|
82
|
-
id:
|
|
83
|
-
role:
|
|
84
|
-
content:
|
|
82
|
+
id: o.id,
|
|
83
|
+
role: o.role,
|
|
84
|
+
content: o.type === "reasoning" ? [{ type: "reasoning", text: o.text }, ...t] : [{ type: "text", text: o.text }, ...t]
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
class
|
|
87
|
+
class $ {
|
|
88
88
|
constructor() {
|
|
89
89
|
i(this, "statusChangeCallbacks", []);
|
|
90
90
|
i(this, "messageCallbacks", []);
|
|
@@ -119,7 +119,7 @@ class v {
|
|
|
119
119
|
onTransaction(t) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class _ extends
|
|
122
|
+
class _ extends $ {
|
|
123
123
|
constructor(e) {
|
|
124
124
|
super();
|
|
125
125
|
i(this, "status");
|
|
@@ -147,13 +147,14 @@ class _ extends v {
|
|
|
147
147
|
this.session = e;
|
|
148
148
|
}
|
|
149
149
|
async sendPacket(e) {
|
|
150
|
-
var
|
|
151
|
-
const { apiUrl: s, apiKey: n, agentId:
|
|
152
|
-
if (e.type === "command" && ((
|
|
153
|
-
this.context = (
|
|
150
|
+
var l, p, g, C, A;
|
|
151
|
+
const { apiUrl: s, apiKey: n, agentId: a } = this.config, r = this.session ?? "new";
|
|
152
|
+
if (e.type === "command" && ((l = e == null ? void 0 : e.payload) == null ? void 0 : l.command) == "set_initial_context") {
|
|
153
|
+
this.context = (p = e == null ? void 0 : e.payload) == null ? void 0 : p.arguments;
|
|
154
154
|
return;
|
|
155
|
-
} else if (e.type === "command" && ((
|
|
156
|
-
|
|
155
|
+
} else if (e.type === "command" && ((g = e == null ? void 0 : e.payload) == null ? void 0 : g.command) == "set_local_tools") {
|
|
156
|
+
const w = (C = e == null ? void 0 : e.payload) == null ? void 0 : C.arguments.tools;
|
|
157
|
+
(w == null ? void 0 : w.length) > 0 && this.notifyPacket({
|
|
157
158
|
type: "message",
|
|
158
159
|
payload: {
|
|
159
160
|
type: "text",
|
|
@@ -165,8 +166,8 @@ class _ extends v {
|
|
|
165
166
|
}
|
|
166
167
|
const c = e.payload;
|
|
167
168
|
try {
|
|
168
|
-
const
|
|
169
|
-
body: JSON.stringify({ agentId:
|
|
169
|
+
const N = await (await fetch(`${s}/sessions/${r}/messages`, {
|
|
170
|
+
body: JSON.stringify({ agentId: a, userMessage: c, initialContext: this.context, tools: this.tools }),
|
|
170
171
|
method: "POST",
|
|
171
172
|
headers: {
|
|
172
173
|
"Content-Type": "application/json",
|
|
@@ -174,12 +175,12 @@ class _ extends v {
|
|
|
174
175
|
}
|
|
175
176
|
})).json();
|
|
176
177
|
this.notifyPackets(
|
|
177
|
-
|
|
178
|
+
N.response.messages.map((T) => ({
|
|
178
179
|
type: "message",
|
|
179
|
-
payload:
|
|
180
|
+
payload: T
|
|
180
181
|
}))
|
|
181
182
|
);
|
|
182
|
-
} catch (
|
|
183
|
+
} catch (w) {
|
|
183
184
|
this.notifyPacket({
|
|
184
185
|
type: "message",
|
|
185
186
|
payload: {
|
|
@@ -187,11 +188,11 @@ class _ extends v {
|
|
|
187
188
|
type: "text",
|
|
188
189
|
text: "An error occurred while processing your request. Please try again later."
|
|
189
190
|
}
|
|
190
|
-
}), (
|
|
191
|
+
}), (A = this.config.logger) == null || A.error("Error sending packet:", w);
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
|
-
class U extends
|
|
195
|
+
class U extends $ {
|
|
195
196
|
constructor(e) {
|
|
196
197
|
super();
|
|
197
198
|
i(this, "status");
|
|
@@ -217,25 +218,25 @@ class U extends v {
|
|
|
217
218
|
return Promise.resolve(this.session);
|
|
218
219
|
const s = e || this.session || "new";
|
|
219
220
|
(c = this.config.logger) == null || c.debug("Connecting to WebSocket with sessionId:", s);
|
|
220
|
-
const n = encodeURIComponent(this.config.apiKey),
|
|
221
|
+
const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
|
|
221
222
|
return this.setStatus("connecting"), this.webSocket = new WebSocket(r), this.webSocket.addEventListener("open", () => {
|
|
222
223
|
this.setStatus("connected");
|
|
223
|
-
}), this.webSocket.addEventListener("message", (
|
|
224
|
-
const
|
|
225
|
-
this.notifyPacket(
|
|
226
|
-
}), this.webSocket.addEventListener("close", (
|
|
227
|
-
var
|
|
228
|
-
this.setStatus("disconnected"), this.webSocket = null,
|
|
224
|
+
}), this.webSocket.addEventListener("message", (l) => {
|
|
225
|
+
const p = JSON.parse(l.data);
|
|
226
|
+
this.notifyPacket(p);
|
|
227
|
+
}), this.webSocket.addEventListener("close", (l) => {
|
|
228
|
+
var p;
|
|
229
|
+
this.setStatus("disconnected"), this.webSocket = null, l.code !== 1e3 && (this.notifyPacket({
|
|
229
230
|
type: "message",
|
|
230
231
|
payload: {
|
|
231
232
|
role: "assistant",
|
|
232
233
|
type: "text",
|
|
233
234
|
text: "Oops! The connection to the server was lost. Please try again later."
|
|
234
235
|
}
|
|
235
|
-
}), (
|
|
236
|
+
}), (p = this.config.logger) == null || p.warn("WebSocket connection closed"));
|
|
236
237
|
}), this.webSocket.addEventListener("error", () => {
|
|
237
|
-
var
|
|
238
|
-
this.setStatus("disconnected"), this.webSocket = null, (
|
|
238
|
+
var l;
|
|
239
|
+
this.setStatus("disconnected"), this.webSocket = null, (l = this.config.logger) == null || l.error("WebSocket connection error");
|
|
239
240
|
}), Promise.resolve(s);
|
|
240
241
|
}
|
|
241
242
|
disconnect() {
|
|
@@ -246,7 +247,7 @@ class U extends v {
|
|
|
246
247
|
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify(e)), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
|
-
class
|
|
250
|
+
class re {
|
|
250
251
|
constructor(t) {
|
|
251
252
|
i(this, "config");
|
|
252
253
|
i(this, "pc", null);
|
|
@@ -292,14 +293,14 @@ class oe {
|
|
|
292
293
|
n.streams[0].getTracks().forEach((r) => {
|
|
293
294
|
this.remoteStream.addTrack(r);
|
|
294
295
|
}), this.audioCtx || this._startAnalyzers();
|
|
295
|
-
const
|
|
296
|
-
|
|
296
|
+
const a = new Audio();
|
|
297
|
+
a.srcObject = this.remoteStream, a.play().catch((r) => {
|
|
297
298
|
var c;
|
|
298
299
|
(c = this.config.logger) == null || c.error("Error playing remote audio:", r);
|
|
299
300
|
});
|
|
300
301
|
}, this.pc.onicecandidate = (n) => {
|
|
301
|
-
var
|
|
302
|
-
n.candidate && ((
|
|
302
|
+
var a;
|
|
303
|
+
n.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
|
|
303
304
|
JSON.stringify({
|
|
304
305
|
type: "CANDIDATE",
|
|
305
306
|
src: "client",
|
|
@@ -307,57 +308,57 @@ class oe {
|
|
|
307
308
|
})
|
|
308
309
|
);
|
|
309
310
|
}, this.pc.ondatachannel = (n) => {
|
|
310
|
-
const
|
|
311
|
-
|
|
311
|
+
const a = n.channel;
|
|
312
|
+
a.onmessage = (r) => {
|
|
312
313
|
this.messageCallbacks.forEach((c) => {
|
|
313
314
|
c(r);
|
|
314
315
|
});
|
|
315
|
-
},
|
|
316
|
+
}, a.onopen = () => {
|
|
316
317
|
var r;
|
|
317
318
|
for (; this.queuedMessages.length > 0; ) {
|
|
318
319
|
const c = this.queuedMessages.shift();
|
|
319
|
-
c && (
|
|
320
|
+
c && (a.send(JSON.stringify(c)), (r = this.config.logger) == null || r.info("Sent queued message:", c));
|
|
320
321
|
}
|
|
321
322
|
};
|
|
322
323
|
};
|
|
323
324
|
const e = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
|
|
324
325
|
this.ws = new WebSocket(`${e}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
|
|
325
|
-
var c,
|
|
326
|
+
var c, l;
|
|
326
327
|
const n = await this.pc.createOffer();
|
|
327
328
|
await this.pc.setLocalDescription(n);
|
|
328
|
-
const
|
|
329
|
+
const a = {
|
|
329
330
|
apiKey: this.config.apiKey,
|
|
330
331
|
agentId: this.config.agentId,
|
|
331
332
|
sessionCode: t
|
|
332
333
|
};
|
|
333
|
-
(c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ",
|
|
334
|
+
(c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ", a);
|
|
334
335
|
const r = {
|
|
335
336
|
type: "OFFER",
|
|
336
|
-
src: ((
|
|
337
|
+
src: ((l = crypto.randomUUID) == null ? void 0 : l.call(crypto)) || "client_" + Date.now(),
|
|
337
338
|
payload: {
|
|
338
339
|
sdp: {
|
|
339
340
|
sdp: n.sdp,
|
|
340
341
|
type: n.type
|
|
341
342
|
},
|
|
342
343
|
connectionId: (Date.now() % 1e6).toString(),
|
|
343
|
-
metadata:
|
|
344
|
+
metadata: a
|
|
344
345
|
}
|
|
345
346
|
};
|
|
346
347
|
this.ws.send(JSON.stringify(r));
|
|
347
348
|
}, this.ws.onmessage = async (n) => {
|
|
348
349
|
var r;
|
|
349
|
-
const
|
|
350
|
-
if (
|
|
351
|
-
await this.pc.setRemoteDescription(new RTCSessionDescription(
|
|
352
|
-
else if (
|
|
350
|
+
const a = JSON.parse(n.data);
|
|
351
|
+
if (a.type === "ANSWER")
|
|
352
|
+
await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
|
|
353
|
+
else if (a.type === "CANDIDATE")
|
|
353
354
|
try {
|
|
354
|
-
await this.pc.addIceCandidate(new RTCIceCandidate(
|
|
355
|
+
await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
|
|
355
356
|
} catch (c) {
|
|
356
357
|
(r = this.config.logger) == null || r.error("Error adding ICE candidate:", c);
|
|
357
358
|
}
|
|
358
359
|
}, this.ws.onclose = (n) => {
|
|
359
|
-
n.code !== 1e3 && this.errorCallbacks.forEach((
|
|
360
|
-
|
|
360
|
+
n.code !== 1e3 && this.errorCallbacks.forEach((a) => {
|
|
361
|
+
a("Oops! The connection to the server was lost. Please try again later.");
|
|
361
362
|
}), this._stopAnalyzers();
|
|
362
363
|
};
|
|
363
364
|
}
|
|
@@ -404,11 +405,11 @@ class oe {
|
|
|
404
405
|
const s = () => {
|
|
405
406
|
if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
|
|
406
407
|
return;
|
|
407
|
-
const n = new Uint8Array(this.localAnalyser.frequencyBinCount),
|
|
408
|
-
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(
|
|
409
|
-
const r = n.reduce((
|
|
410
|
-
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((
|
|
411
|
-
|
|
408
|
+
const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
409
|
+
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
|
|
410
|
+
const r = n.reduce((l, p) => l + p, 0) / n.length, c = a.reduce((l, p) => l + p, 0) / a.length;
|
|
411
|
+
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((l) => {
|
|
412
|
+
l({
|
|
412
413
|
localAmplitude: r,
|
|
413
414
|
remoteAmplitude: c
|
|
414
415
|
});
|
|
@@ -420,7 +421,7 @@ class oe {
|
|
|
420
421
|
this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
|
|
421
422
|
}
|
|
422
423
|
}
|
|
423
|
-
class
|
|
424
|
+
class F extends $ {
|
|
424
425
|
constructor(e) {
|
|
425
426
|
super();
|
|
426
427
|
i(this, "status");
|
|
@@ -428,7 +429,7 @@ class W extends v {
|
|
|
428
429
|
i(this, "autostart");
|
|
429
430
|
i(this, "config");
|
|
430
431
|
i(this, "webRTCClient");
|
|
431
|
-
this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new
|
|
432
|
+
this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new re(e), this.webRTCClient.addMessageCallback((s) => {
|
|
432
433
|
const n = JSON.parse(s.data);
|
|
433
434
|
this.notifyPacket(n);
|
|
434
435
|
}), this.webRTCClient.addErrorCallback((s) => {
|
|
@@ -466,7 +467,7 @@ class W extends v {
|
|
|
466
467
|
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendPacket(e), Promise.resolve());
|
|
467
468
|
}
|
|
468
469
|
}
|
|
469
|
-
class
|
|
470
|
+
class ie {
|
|
470
471
|
constructor(t) {
|
|
471
472
|
i(this, "config");
|
|
472
473
|
this.config = t;
|
|
@@ -491,7 +492,7 @@ class re {
|
|
|
491
492
|
});
|
|
492
493
|
}
|
|
493
494
|
}
|
|
494
|
-
class
|
|
495
|
+
class ce {
|
|
495
496
|
constructor(t, e) {
|
|
496
497
|
i(this, "transaction");
|
|
497
498
|
i(this, "manager");
|
|
@@ -507,14 +508,14 @@ class ie {
|
|
|
507
508
|
await this.fail("No function call found");
|
|
508
509
|
return;
|
|
509
510
|
}
|
|
510
|
-
const s = e.name, n = e.args,
|
|
511
|
-
if (!
|
|
511
|
+
const s = e.name, n = e.args, a = t[s];
|
|
512
|
+
if (!a) {
|
|
512
513
|
await this.fail(`Tool ${s} not found`);
|
|
513
514
|
return;
|
|
514
515
|
}
|
|
515
516
|
try {
|
|
516
|
-
const
|
|
517
|
-
await this.complete(
|
|
517
|
+
const l = (((r = a.toString().replace(/\n/g, " ").match(/^[^(]*\(([^)]*)\)/)) == null ? void 0 : r[1].split(",").map((g) => g.trim()).filter(Boolean)) || []).map((g) => n[g]), p = await a.apply(null, l);
|
|
518
|
+
await this.complete(p);
|
|
518
519
|
} catch (c) {
|
|
519
520
|
await this.fail(`Error executing tool ${s}: ${c}`);
|
|
520
521
|
}
|
|
@@ -526,7 +527,7 @@ class ie {
|
|
|
526
527
|
await this.manager.fail(this.transaction, { success: !1, output: null, error: t });
|
|
527
528
|
}
|
|
528
529
|
}
|
|
529
|
-
class
|
|
530
|
+
class le extends $ {
|
|
530
531
|
constructor(e) {
|
|
531
532
|
super();
|
|
532
533
|
i(this, "status");
|
|
@@ -561,179 +562,195 @@ class ce extends v {
|
|
|
561
562
|
}
|
|
562
563
|
onTransaction(e) {
|
|
563
564
|
console.log("transaction received:", e);
|
|
564
|
-
const s = new
|
|
565
|
+
const s = new ie(this.config), n = new ce(e, s);
|
|
565
566
|
this.config.onTransaction ? this.config.onTransaction(n) : n.invoke(this._tools);
|
|
566
567
|
}
|
|
567
568
|
getTools() {
|
|
568
569
|
return this._tools;
|
|
569
570
|
}
|
|
570
571
|
}
|
|
571
|
-
const R =
|
|
572
|
-
function
|
|
572
|
+
const R = G(void 0);
|
|
573
|
+
function ue(o) {
|
|
573
574
|
return new Promise((t, e) => {
|
|
574
575
|
const s = new FileReader();
|
|
575
|
-
s.readAsDataURL(
|
|
576
|
-
const
|
|
577
|
-
t(
|
|
576
|
+
s.readAsDataURL(o), s.onload = () => {
|
|
577
|
+
const a = s.result.split(";base64,")[1];
|
|
578
|
+
t(a);
|
|
578
579
|
}, s.onerror = (n) => {
|
|
579
580
|
e(n);
|
|
580
581
|
};
|
|
581
582
|
});
|
|
582
583
|
}
|
|
583
|
-
function
|
|
584
|
-
|
|
584
|
+
function z(o) {
|
|
585
|
+
const t = {
|
|
586
|
+
rest: (e) => e.config.apiUrl,
|
|
587
|
+
webrtc: (e) => e.config.webrtcUrl.replace("/webrtc", "").replace("ws://", "http://").replace("wss://", "https://"),
|
|
588
|
+
websocket: (e) => e.config.webSocketUrl.replace("/websocket", "").replace("ws://", "http://").replace("wss://", "https://")
|
|
589
|
+
};
|
|
590
|
+
for (const e of o) {
|
|
591
|
+
const s = t[e.getName()];
|
|
592
|
+
if (s)
|
|
593
|
+
return s(e);
|
|
594
|
+
}
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
function he({
|
|
598
|
+
dev: o = !1,
|
|
585
599
|
baseUrl: t,
|
|
586
600
|
protocols: e,
|
|
587
601
|
logger: s,
|
|
588
602
|
children: n,
|
|
589
|
-
session:
|
|
603
|
+
session: a = "new",
|
|
590
604
|
...r
|
|
591
605
|
}) {
|
|
592
|
-
const [c,
|
|
606
|
+
const [c, l] = E(!1), [p, g] = E([]), [C, A] = E(a), [w, N] = E(/* @__PURE__ */ new Map()), T = H(!1), S = Q(() => {
|
|
593
607
|
if (Array.isArray(e))
|
|
594
608
|
return e;
|
|
595
609
|
if (typeof e == "object" && e !== null) {
|
|
596
|
-
const
|
|
597
|
-
let
|
|
598
|
-
switch (
|
|
610
|
+
const y = o ? "localhost:8000" : t || "persona.applica.guru/api", h = o ? "http" : "https", f = o ? "ws" : "wss";
|
|
611
|
+
let d = Object.keys(e).map((m) => {
|
|
612
|
+
switch (m) {
|
|
599
613
|
case "rest":
|
|
600
|
-
const
|
|
601
|
-
return
|
|
602
|
-
apiUrl: `${
|
|
614
|
+
const b = e[m];
|
|
615
|
+
return b === !0 ? new _({
|
|
616
|
+
apiUrl: `${h}://${y}`,
|
|
603
617
|
apiKey: r.apiKey,
|
|
604
618
|
agentId: r.agentId,
|
|
605
619
|
logger: s
|
|
606
|
-
}) : typeof
|
|
620
|
+
}) : typeof b == "object" && b !== null ? new _(b) : null;
|
|
607
621
|
case "webrtc":
|
|
608
|
-
const
|
|
609
|
-
return
|
|
610
|
-
webrtcUrl: `${
|
|
622
|
+
const u = e[m];
|
|
623
|
+
return u === !0 ? new F({
|
|
624
|
+
webrtcUrl: `${f}://${y}/webrtc`,
|
|
611
625
|
apiKey: r.apiKey,
|
|
612
626
|
agentId: r.agentId,
|
|
613
627
|
logger: s
|
|
614
|
-
}) : typeof
|
|
628
|
+
}) : typeof u == "object" && u !== null ? new F(u) : null;
|
|
615
629
|
case "websocket":
|
|
616
|
-
const P = e[
|
|
630
|
+
const P = e[m];
|
|
617
631
|
return P === !0 ? new U({
|
|
618
|
-
webSocketUrl: `${
|
|
632
|
+
webSocketUrl: `${f}://${y}/websocket`,
|
|
619
633
|
apiKey: r.apiKey,
|
|
620
634
|
agentId: r.agentId,
|
|
621
635
|
logger: s
|
|
622
636
|
}) : typeof P == "object" && P !== null ? new U(P) : null;
|
|
623
637
|
default:
|
|
624
|
-
throw new Error(`Unknown protocol: ${
|
|
638
|
+
throw new Error(`Unknown protocol: ${m}`);
|
|
625
639
|
}
|
|
626
|
-
}).filter((
|
|
627
|
-
return r.tools &&
|
|
628
|
-
new
|
|
629
|
-
apiUrl: `${
|
|
640
|
+
}).filter((m) => m !== null);
|
|
641
|
+
return r.tools && d.push(
|
|
642
|
+
new le({
|
|
643
|
+
apiUrl: `${h}://${y}`,
|
|
630
644
|
apiKey: r.apiKey,
|
|
631
645
|
agentId: r.agentId,
|
|
632
646
|
tools: r.tools,
|
|
633
647
|
// Pass raw tools
|
|
634
648
|
logger: s
|
|
635
649
|
})
|
|
636
|
-
),
|
|
650
|
+
), d;
|
|
637
651
|
}
|
|
638
652
|
throw new Error("Invalid protocols configuration");
|
|
639
653
|
}, []);
|
|
640
|
-
|
|
641
|
-
|
|
654
|
+
X(() => {
|
|
655
|
+
if (T.current) return;
|
|
656
|
+
T.current = !0, s == null || s.debug(
|
|
642
657
|
"Initializing protocols: ",
|
|
643
|
-
|
|
644
|
-
)
|
|
645
|
-
|
|
646
|
-
|
|
658
|
+
S.map((h) => h.getName())
|
|
659
|
+
);
|
|
660
|
+
const y = z(S);
|
|
661
|
+
S.forEach((h) => {
|
|
662
|
+
h.setSession(C), h.clearListeners(), h.addStatusChangeListener((f) => {
|
|
663
|
+
s == null || s.debug(`${h.getName()} has notified new status: ${f}`), w.set(h.getName(), f), f === "connected" && (r.context && h.sendPacket({
|
|
647
664
|
type: "command",
|
|
648
665
|
payload: {
|
|
649
666
|
command: "set_initial_context",
|
|
650
667
|
arguments: r.context
|
|
651
668
|
}
|
|
652
|
-
}), r.tools && Array.isArray(r.tools) &&
|
|
669
|
+
}), r.tools && Array.isArray(r.tools) && h.sendPacket({
|
|
653
670
|
type: "command",
|
|
654
671
|
payload: {
|
|
655
672
|
command: "set_local_tools",
|
|
656
673
|
arguments: {
|
|
657
|
-
tools: r.tools.map((
|
|
674
|
+
tools: r.tools.map((d) => d.schema)
|
|
658
675
|
}
|
|
659
676
|
}
|
|
660
|
-
})),
|
|
661
|
-
}),
|
|
662
|
-
if (
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
(
|
|
677
|
+
})), N(new Map(w));
|
|
678
|
+
}), h.addPacketListener((f) => {
|
|
679
|
+
if (f.type === "message") {
|
|
680
|
+
const d = f.payload;
|
|
681
|
+
g(
|
|
682
|
+
(m) => j([...m, { ...d, protocol: h.getName() }])
|
|
666
683
|
);
|
|
667
|
-
} else if (
|
|
668
|
-
const
|
|
669
|
-
let
|
|
670
|
-
|
|
684
|
+
} else if (f.type === "reasoning") {
|
|
685
|
+
const d = f.payload;
|
|
686
|
+
let m = d.thought;
|
|
687
|
+
d.imageUrl && (m += `
|
|
671
688
|
|
|
672
|
-
`);
|
|
690
|
+
const b = { type: "reasoning", text: m, role: "assistant", finishReason: "stop" };
|
|
691
|
+
g(
|
|
692
|
+
(u) => j([...u, { ...b, protocol: h.getName() }])
|
|
676
693
|
);
|
|
677
|
-
} else
|
|
678
|
-
}),
|
|
679
|
-
})
|
|
680
|
-
}, [
|
|
681
|
-
const
|
|
682
|
-
var
|
|
683
|
-
if (((
|
|
684
|
-
if (!
|
|
685
|
-
|
|
686
|
-
...
|
|
694
|
+
} else f.type === "transaction" && S.filter((d) => d !== h).forEach((d) => d.onTransaction(f.payload));
|
|
695
|
+
}), h.autostart && h.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${h.getName()}`), h.connect(C));
|
|
696
|
+
});
|
|
697
|
+
}, [C, S, s, w]);
|
|
698
|
+
const D = async (y) => {
|
|
699
|
+
var b;
|
|
700
|
+
if (((b = y.content[0]) == null ? void 0 : b.type) !== "text") throw new Error("Only text messages are supported");
|
|
701
|
+
if (!S.some((u) => u.getName() !== "transaction" && u.status === "connected")) {
|
|
702
|
+
g((u) => [
|
|
703
|
+
...u,
|
|
687
704
|
{ role: "assistant", type: "text", text: "No protocol is connected." }
|
|
688
705
|
]);
|
|
689
706
|
return;
|
|
690
707
|
}
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
if (
|
|
695
|
-
for (const
|
|
696
|
-
|
|
708
|
+
const f = y.content[0].text;
|
|
709
|
+
g((u) => [...u, { role: "user", type: "text", text: f }]), l(!0);
|
|
710
|
+
const d = S.sort((u, P) => P.getPriority() - u.getPriority()).find((u) => u.status === "connected"), m = [];
|
|
711
|
+
if (y.attachments)
|
|
712
|
+
for (const u of y.attachments)
|
|
713
|
+
u.contentType.startsWith("image/") && u.file && m.push({
|
|
697
714
|
role: "user",
|
|
698
715
|
image: {
|
|
699
|
-
contentType:
|
|
700
|
-
content: await
|
|
716
|
+
contentType: u.contentType,
|
|
717
|
+
content: await ue(u.file)
|
|
701
718
|
},
|
|
702
719
|
text: "",
|
|
703
720
|
type: "text"
|
|
704
721
|
});
|
|
705
|
-
|
|
722
|
+
y.content && m.push({
|
|
706
723
|
role: "user",
|
|
707
|
-
text:
|
|
724
|
+
text: y.content[0].text,
|
|
708
725
|
type: "text"
|
|
709
|
-
}), s == null || s.debug("Sending message:",
|
|
710
|
-
},
|
|
726
|
+
}), s == null || s.debug("Sending message:", m), await (d == null ? void 0 : d.sendPacket({ type: "request", payload: m })), l(!1);
|
|
727
|
+
}, L = M(() => (l(!1), g([]), A("new"), Promise.resolve()), []), J = M(() => Promise.resolve(), []), K = M(() => p, [p]), B = Z({
|
|
711
728
|
isRunning: c,
|
|
712
|
-
messages:
|
|
729
|
+
messages: p,
|
|
713
730
|
convertMessage: ae,
|
|
714
|
-
onNew:
|
|
715
|
-
onCancel:
|
|
716
|
-
onReload:
|
|
731
|
+
onNew: D,
|
|
732
|
+
onCancel: L,
|
|
733
|
+
onReload: J,
|
|
717
734
|
adapters: {
|
|
718
|
-
attachments: new
|
|
735
|
+
attachments: new ee([new te()])
|
|
719
736
|
}
|
|
720
737
|
});
|
|
721
|
-
return /* @__PURE__ */
|
|
738
|
+
return /* @__PURE__ */ I.jsx(R.Provider, { value: { protocols: S, protocolsStatus: w, getMessages: K }, children: /* @__PURE__ */ I.jsx(se, { runtime: B, children: n }) });
|
|
722
739
|
}
|
|
723
|
-
function
|
|
724
|
-
return /* @__PURE__ */
|
|
740
|
+
function we({ children: o, ...t }) {
|
|
741
|
+
return /* @__PURE__ */ I.jsx(he, { ...t, children: o });
|
|
725
742
|
}
|
|
726
|
-
function
|
|
727
|
-
const
|
|
728
|
-
if (!
|
|
743
|
+
function be() {
|
|
744
|
+
const o = v(R);
|
|
745
|
+
if (!o)
|
|
729
746
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
730
|
-
return
|
|
747
|
+
return o;
|
|
731
748
|
}
|
|
732
|
-
function
|
|
733
|
-
const t =
|
|
749
|
+
function de(o) {
|
|
750
|
+
const t = v(R);
|
|
734
751
|
if (!t)
|
|
735
752
|
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
736
|
-
const e = t.protocols.find((n) => n.getName() ===
|
|
753
|
+
const e = t.protocols.find((n) => n.getName() === o);
|
|
737
754
|
if (!e)
|
|
738
755
|
return null;
|
|
739
756
|
const s = t.protocolsStatus.get(e.getName());
|
|
@@ -750,32 +767,22 @@ function he(a) {
|
|
|
750
767
|
status: s || e.status
|
|
751
768
|
};
|
|
752
769
|
}
|
|
753
|
-
function be() {
|
|
754
|
-
const a = E(R);
|
|
755
|
-
if (!a)
|
|
756
|
-
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
757
|
-
const t = {
|
|
758
|
-
rest: (e) => e.config.apiUrl,
|
|
759
|
-
webrtc: (e) => e.config.webrtcUrl.replace("/webrtc", "").replace("ws://", "http://").replace("wss://", "https://"),
|
|
760
|
-
websocket: (e) => e.config.webSocketUrl.replace("/websocket", "").replace("ws://", "http://").replace("wss://", "https://")
|
|
761
|
-
};
|
|
762
|
-
for (const e of a.protocols) {
|
|
763
|
-
const s = t[e.getName()];
|
|
764
|
-
if (s)
|
|
765
|
-
return s(e);
|
|
766
|
-
}
|
|
767
|
-
return null;
|
|
768
|
-
}
|
|
769
770
|
function Se() {
|
|
770
|
-
|
|
771
|
+
const o = v(R);
|
|
772
|
+
if (!o)
|
|
773
|
+
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
774
|
+
return z(o.protocols);
|
|
771
775
|
}
|
|
772
776
|
function Ce() {
|
|
773
|
-
|
|
774
|
-
|
|
777
|
+
return de("webrtc");
|
|
778
|
+
}
|
|
779
|
+
function Pe() {
|
|
780
|
+
const o = v(R);
|
|
781
|
+
if (!o)
|
|
775
782
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
776
|
-
return
|
|
783
|
+
return o.getMessages();
|
|
777
784
|
}
|
|
778
|
-
class
|
|
785
|
+
class xe {
|
|
779
786
|
constructor() {
|
|
780
787
|
i(this, "prefix", "[Persona]");
|
|
781
788
|
}
|
|
@@ -795,129 +802,129 @@ class Pe {
|
|
|
795
802
|
console.debug(`${this.prefix} - ${t}`, ...e);
|
|
796
803
|
}
|
|
797
804
|
}
|
|
798
|
-
function
|
|
805
|
+
function x(o, t, e) {
|
|
799
806
|
return {
|
|
800
|
-
type:
|
|
807
|
+
type: o,
|
|
801
808
|
description: t,
|
|
802
809
|
...e
|
|
803
810
|
};
|
|
804
811
|
}
|
|
805
|
-
function
|
|
806
|
-
const t = Object.entries(
|
|
812
|
+
function pe(o) {
|
|
813
|
+
const t = Object.entries(o.parameters).filter(([e, s]) => s.required).map(([e]) => e);
|
|
807
814
|
return {
|
|
808
815
|
type: "local",
|
|
809
|
-
name:
|
|
810
|
-
description:
|
|
816
|
+
name: o.name,
|
|
817
|
+
description: o.description,
|
|
811
818
|
config: {
|
|
812
|
-
timeout:
|
|
819
|
+
timeout: o.timeout || 60,
|
|
813
820
|
parameters: {
|
|
814
821
|
type: "object",
|
|
815
|
-
title:
|
|
822
|
+
title: o.title || `${o.name} parameters`,
|
|
816
823
|
required: t,
|
|
817
|
-
properties:
|
|
824
|
+
properties: o.parameters
|
|
818
825
|
},
|
|
819
826
|
output: {
|
|
820
827
|
type: "object",
|
|
821
|
-
title: `${
|
|
822
|
-
properties:
|
|
828
|
+
title: `${o.name} output`,
|
|
829
|
+
properties: o.output
|
|
823
830
|
}
|
|
824
831
|
}
|
|
825
832
|
};
|
|
826
833
|
}
|
|
827
|
-
function
|
|
834
|
+
function q(o) {
|
|
828
835
|
return {
|
|
829
|
-
schema:
|
|
830
|
-
implementation:
|
|
836
|
+
schema: pe(o),
|
|
837
|
+
implementation: o.implementation
|
|
831
838
|
};
|
|
832
839
|
}
|
|
833
|
-
function
|
|
840
|
+
function me(o, t, e, s, n, a) {
|
|
834
841
|
const r = {
|
|
835
|
-
name:
|
|
842
|
+
name: o,
|
|
836
843
|
description: t,
|
|
837
|
-
title:
|
|
838
|
-
timeout:
|
|
844
|
+
title: a == null ? void 0 : a.title,
|
|
845
|
+
timeout: a == null ? void 0 : a.timeout,
|
|
839
846
|
parameters: s,
|
|
840
847
|
output: n,
|
|
841
848
|
implementation: e
|
|
842
849
|
};
|
|
843
|
-
return
|
|
850
|
+
return q(r);
|
|
844
851
|
}
|
|
845
|
-
const ke =
|
|
852
|
+
const ke = me(
|
|
846
853
|
"sum",
|
|
847
854
|
"Sum two numbers",
|
|
848
855
|
function(t, e) {
|
|
849
856
|
return { result: t + e };
|
|
850
857
|
},
|
|
851
858
|
{
|
|
852
|
-
a:
|
|
853
|
-
b:
|
|
859
|
+
a: x("number", "First number to sum", { required: !0 }),
|
|
860
|
+
b: x("number", "Second number to sum", { required: !0 })
|
|
854
861
|
},
|
|
855
862
|
{
|
|
856
|
-
result:
|
|
863
|
+
result: x("number", "Sum of two numbers")
|
|
857
864
|
}
|
|
858
|
-
),
|
|
865
|
+
), Re = q({
|
|
859
866
|
name: "navigate_to",
|
|
860
867
|
description: "Allow agent to redirect user to specific sub page like /foo or #/foo or anything like that",
|
|
861
868
|
title: "Sum two numbers",
|
|
862
869
|
// As per the user's example
|
|
863
870
|
timeout: 60,
|
|
864
871
|
parameters: {
|
|
865
|
-
a:
|
|
866
|
-
b:
|
|
872
|
+
a: x("number", "First number to sum"),
|
|
873
|
+
b: x("number", "Seconth number to sum")
|
|
867
874
|
// Keeping the typo as in the original
|
|
868
875
|
},
|
|
869
876
|
output: {
|
|
870
|
-
result:
|
|
877
|
+
result: x("number", "Sum of two numbers")
|
|
871
878
|
},
|
|
872
879
|
implementation: function(t, e) {
|
|
873
880
|
return { result: t + e };
|
|
874
881
|
}
|
|
875
882
|
});
|
|
876
|
-
function
|
|
883
|
+
function Ae(o) {
|
|
877
884
|
const t = [], e = {};
|
|
878
|
-
return
|
|
879
|
-
const { schema: n, implementation:
|
|
880
|
-
t.push(n), e[s.name] =
|
|
885
|
+
return o.forEach((s) => {
|
|
886
|
+
const { schema: n, implementation: a } = q(s);
|
|
887
|
+
t.push(n), e[s.name] = a;
|
|
881
888
|
}), { schemas: t, implementations: e };
|
|
882
889
|
}
|
|
883
|
-
function Te(
|
|
890
|
+
function Te(o, t) {
|
|
884
891
|
const { required: e, properties: s } = t.config.parameters;
|
|
885
892
|
for (const n of e)
|
|
886
|
-
if (!(n in
|
|
893
|
+
if (!(n in o))
|
|
887
894
|
throw new Error(`Missing required parameter: ${n}`);
|
|
888
|
-
for (const [n,
|
|
895
|
+
for (const [n, a] of Object.entries(o)) {
|
|
889
896
|
const r = s[n];
|
|
890
897
|
if (r) {
|
|
891
|
-
if (r.type === "number" && typeof
|
|
898
|
+
if (r.type === "number" && typeof a != "number")
|
|
892
899
|
throw new Error(`Parameter ${n} should be a number`);
|
|
893
|
-
if (r.type === "string" && typeof
|
|
900
|
+
if (r.type === "string" && typeof a != "string")
|
|
894
901
|
throw new Error(`Parameter ${n} should be a string`);
|
|
895
|
-
if (r.type === "boolean" && typeof
|
|
902
|
+
if (r.type === "boolean" && typeof a != "boolean")
|
|
896
903
|
throw new Error(`Parameter ${n} should be a boolean`);
|
|
897
904
|
}
|
|
898
905
|
}
|
|
899
906
|
return !0;
|
|
900
907
|
}
|
|
901
908
|
export {
|
|
902
|
-
|
|
903
|
-
|
|
909
|
+
xe as PersonaConsoleLogger,
|
|
910
|
+
$ as PersonaProtocolBase,
|
|
904
911
|
_ as PersonaRESTProtocol,
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
912
|
+
we as PersonaRuntimeProvider,
|
|
913
|
+
le as PersonaTransactionProtocol,
|
|
914
|
+
F as PersonaWebRTCProtocol,
|
|
908
915
|
U as PersonaWebSocketProtocol,
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
916
|
+
x as createParameter,
|
|
917
|
+
q as createTool,
|
|
918
|
+
me as createToolFromFunction,
|
|
919
|
+
Ae as createToolRegistry,
|
|
920
|
+
pe as generateToolSchema,
|
|
921
|
+
Re as navigateToToolExample,
|
|
915
922
|
ke as sumTool,
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
923
|
+
be as usePersonaRuntime,
|
|
924
|
+
Se as usePersonaRuntimeEndpoint,
|
|
925
|
+
Pe as usePersonaRuntimeMessages,
|
|
926
|
+
de as usePersonaRuntimeProtocol,
|
|
927
|
+
Ce as usePersonaRuntimeWebRTCProtocol,
|
|
921
928
|
Te as validateToolParameters
|
|
922
929
|
};
|
|
923
930
|
//# sourceMappingURL=bundle.es.js.map
|