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