@applica-software-guru/persona-sdk 0.1.66 → 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 -262
- 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/dist/runtime.d.ts +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/protocol/transaction.ts +0 -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,31 +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 = (((
|
|
517
|
-
console.log(`Invoking tool ${s} with args:`, u);
|
|
518
|
-
const d = await a.apply(null, 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);
|
|
519
517
|
await this.complete(d);
|
|
520
518
|
} catch (c) {
|
|
521
519
|
await this.fail(`Error executing tool ${s}: ${c}`);
|
|
@@ -531,12 +529,12 @@ class re {
|
|
|
531
529
|
class ce extends v {
|
|
532
530
|
constructor(e) {
|
|
533
531
|
super();
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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");
|
|
540
538
|
if (this.config = e, this.status = "disconnected", this.autostart = !0, Array.isArray(e.tools)) {
|
|
541
539
|
this._tools = {};
|
|
542
540
|
for (const s of e.tools)
|
|
@@ -563,136 +561,143 @@ class ce extends v {
|
|
|
563
561
|
}
|
|
564
562
|
onTransaction(e) {
|
|
565
563
|
console.log("transaction received:", e);
|
|
566
|
-
const s = new
|
|
564
|
+
const s = new re(this.config), n = new ie(e, s);
|
|
567
565
|
this.config.onTransaction ? this.config.onTransaction(n) : n.invoke(this._tools);
|
|
568
566
|
}
|
|
569
567
|
getTools() {
|
|
570
568
|
return this._tools;
|
|
571
569
|
}
|
|
572
570
|
}
|
|
573
|
-
const
|
|
574
|
-
function le(
|
|
571
|
+
const R = Y(void 0);
|
|
572
|
+
function le(a) {
|
|
575
573
|
return new Promise((t, e) => {
|
|
576
574
|
const s = new FileReader();
|
|
577
|
-
s.readAsDataURL(
|
|
578
|
-
const
|
|
579
|
-
t(
|
|
575
|
+
s.readAsDataURL(a), s.onload = () => {
|
|
576
|
+
const o = s.result.split(";base64,")[1];
|
|
577
|
+
t(o);
|
|
580
578
|
}, s.onerror = (n) => {
|
|
581
579
|
e(n);
|
|
582
580
|
};
|
|
583
581
|
});
|
|
584
582
|
}
|
|
585
583
|
function ue({
|
|
586
|
-
dev:
|
|
584
|
+
dev: a = !1,
|
|
587
585
|
baseUrl: t,
|
|
588
586
|
protocols: e,
|
|
589
587
|
logger: s,
|
|
590
588
|
children: n,
|
|
591
|
-
session:
|
|
592
|
-
...
|
|
589
|
+
session: o = "new",
|
|
590
|
+
...r
|
|
593
591
|
}) {
|
|
594
|
-
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(() => {
|
|
595
593
|
if (Array.isArray(e))
|
|
596
594
|
return e;
|
|
597
595
|
if (typeof e == "object" && e !== null) {
|
|
598
|
-
const l =
|
|
599
|
-
let
|
|
600
|
-
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) {
|
|
601
599
|
case "rest":
|
|
602
|
-
const
|
|
603
|
-
return
|
|
600
|
+
const w = e[f];
|
|
601
|
+
return w === !0 ? new _({
|
|
604
602
|
apiUrl: `${m}://${l}`,
|
|
605
|
-
apiKey:
|
|
606
|
-
agentId:
|
|
603
|
+
apiKey: r.apiKey,
|
|
604
|
+
agentId: r.agentId,
|
|
607
605
|
logger: s
|
|
608
|
-
}) : typeof
|
|
606
|
+
}) : typeof w == "object" && w !== null ? new _(w) : null;
|
|
609
607
|
case "webrtc":
|
|
610
|
-
const
|
|
611
|
-
return
|
|
612
|
-
webrtcUrl: `${
|
|
613
|
-
apiKey:
|
|
614
|
-
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,
|
|
615
613
|
logger: s
|
|
616
|
-
}) : typeof
|
|
614
|
+
}) : typeof h == "object" && h !== null ? new W(h) : null;
|
|
617
615
|
case "websocket":
|
|
618
|
-
const
|
|
619
|
-
return
|
|
620
|
-
webSocketUrl: `${
|
|
621
|
-
apiKey:
|
|
622
|
-
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,
|
|
623
621
|
logger: s
|
|
624
|
-
}) : typeof
|
|
622
|
+
}) : typeof P == "object" && P !== null ? new U(P) : null;
|
|
625
623
|
default:
|
|
626
|
-
throw new Error(`Unknown protocol: ${
|
|
624
|
+
throw new Error(`Unknown protocol: ${f}`);
|
|
627
625
|
}
|
|
628
|
-
}).filter((
|
|
629
|
-
return
|
|
626
|
+
}).filter((f) => f !== null);
|
|
627
|
+
return r.tools && g.push(
|
|
630
628
|
new ce({
|
|
631
629
|
apiUrl: `${m}://${l}`,
|
|
632
|
-
apiKey:
|
|
633
|
-
agentId:
|
|
634
|
-
tools:
|
|
630
|
+
apiKey: r.apiKey,
|
|
631
|
+
agentId: r.agentId,
|
|
632
|
+
tools: r.tools,
|
|
635
633
|
// Pass raw tools
|
|
636
634
|
logger: s
|
|
637
635
|
})
|
|
638
|
-
),
|
|
636
|
+
), g;
|
|
639
637
|
}
|
|
640
638
|
throw new Error("Invalid protocols configuration");
|
|
641
639
|
}, []);
|
|
642
640
|
Q(() => {
|
|
643
641
|
q.current || (q.current = !0, s == null || s.debug(
|
|
644
642
|
"Initializing protocols: ",
|
|
645
|
-
|
|
646
|
-
),
|
|
647
|
-
l.setSession(
|
|
648
|
-
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({
|
|
649
647
|
type: "command",
|
|
650
648
|
payload: {
|
|
651
649
|
command: "set_initial_context",
|
|
652
|
-
arguments:
|
|
650
|
+
arguments: r.context
|
|
653
651
|
}
|
|
654
|
-
}),
|
|
652
|
+
}), r.tools && Array.isArray(r.tools) && l.sendPacket({
|
|
655
653
|
type: "command",
|
|
656
654
|
payload: {
|
|
657
655
|
command: "set_local_tools",
|
|
658
656
|
arguments: {
|
|
659
|
-
tools:
|
|
657
|
+
tools: r.tools.map((p) => p.schema)
|
|
660
658
|
}
|
|
661
659
|
}
|
|
662
|
-
})), $(new Map(
|
|
660
|
+
})), $(new Map(C));
|
|
663
661
|
}), l.addPacketListener((m) => {
|
|
664
662
|
if (m.type === "message") {
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
(
|
|
663
|
+
const p = m.payload;
|
|
664
|
+
y(
|
|
665
|
+
(g) => j([...g, { ...p, protocol: l.getName() }])
|
|
668
666
|
);
|
|
669
667
|
} else if (m.type === "reasoning") {
|
|
670
|
-
const
|
|
671
|
-
let
|
|
672
|
-
|
|
668
|
+
const p = m.payload;
|
|
669
|
+
let g = p.thought;
|
|
670
|
+
p.imageUrl && (g += `
|
|
673
671
|
|
|
674
|
-
`);
|
|
673
|
+
const f = { type: "reasoning", text: g, role: "assistant", finishReason: "stop" };
|
|
674
|
+
y(
|
|
675
|
+
(w) => j([...w, { ...f, protocol: l.getName() }])
|
|
678
676
|
);
|
|
679
|
-
} else m.type === "transaction" &&
|
|
680
|
-
}), 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));
|
|
681
679
|
}));
|
|
682
|
-
}, [
|
|
683
|
-
const
|
|
684
|
-
var
|
|
685
|
-
if (((
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
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 = [];
|
|
689
694
|
if (l.attachments)
|
|
690
|
-
for (const
|
|
691
|
-
|
|
695
|
+
for (const h of l.attachments)
|
|
696
|
+
h.contentType.startsWith("image/") && h.file && f.push({
|
|
692
697
|
role: "user",
|
|
693
698
|
image: {
|
|
694
|
-
contentType:
|
|
695
|
-
content: await le(
|
|
699
|
+
contentType: h.contentType,
|
|
700
|
+
content: await le(h.file)
|
|
696
701
|
},
|
|
697
702
|
text: "",
|
|
698
703
|
type: "text"
|
|
@@ -701,34 +706,34 @@ function ue({
|
|
|
701
706
|
role: "user",
|
|
702
707
|
text: l.content[0].text,
|
|
703
708
|
type: "text"
|
|
704
|
-
}), s == null || s.debug("Sending message:", f), await (
|
|
705
|
-
}, 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({
|
|
706
711
|
isRunning: c,
|
|
707
712
|
messages: d,
|
|
708
|
-
convertMessage:
|
|
709
|
-
onNew:
|
|
713
|
+
convertMessage: ae,
|
|
714
|
+
onNew: F,
|
|
710
715
|
onCancel: D,
|
|
711
716
|
onReload: L,
|
|
712
717
|
adapters: {
|
|
713
718
|
attachments: new Z([new ee()])
|
|
714
719
|
}
|
|
715
720
|
});
|
|
716
|
-
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 }) });
|
|
717
722
|
}
|
|
718
|
-
function ge({ children:
|
|
719
|
-
return /* @__PURE__ */ M.jsx(ue, { ...t, children:
|
|
723
|
+
function ge({ children: a, ...t }) {
|
|
724
|
+
return /* @__PURE__ */ M.jsx(ue, { ...t, children: a });
|
|
720
725
|
}
|
|
721
726
|
function we() {
|
|
722
|
-
const
|
|
723
|
-
if (!
|
|
727
|
+
const a = E(R);
|
|
728
|
+
if (!a)
|
|
724
729
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
725
|
-
return
|
|
730
|
+
return a;
|
|
726
731
|
}
|
|
727
|
-
function he(
|
|
728
|
-
const t =
|
|
732
|
+
function he(a) {
|
|
733
|
+
const t = E(R);
|
|
729
734
|
if (!t)
|
|
730
735
|
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
731
|
-
const e = t.protocols.find((n) => n.getName() ===
|
|
736
|
+
const e = t.protocols.find((n) => n.getName() === a);
|
|
732
737
|
if (!e)
|
|
733
738
|
return null;
|
|
734
739
|
const s = t.protocolsStatus.get(e.getName());
|
|
@@ -746,26 +751,33 @@ function he(o) {
|
|
|
746
751
|
};
|
|
747
752
|
}
|
|
748
753
|
function be() {
|
|
749
|
-
const
|
|
750
|
-
if (!
|
|
754
|
+
const a = E(R);
|
|
755
|
+
if (!a)
|
|
751
756
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
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;
|
|
756
768
|
}
|
|
757
769
|
function Se() {
|
|
758
770
|
return he("webrtc");
|
|
759
771
|
}
|
|
760
772
|
function Ce() {
|
|
761
|
-
const
|
|
762
|
-
if (!
|
|
773
|
+
const a = E(R);
|
|
774
|
+
if (!a)
|
|
763
775
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
764
|
-
return
|
|
776
|
+
return a.getMessages();
|
|
765
777
|
}
|
|
766
778
|
class Pe {
|
|
767
779
|
constructor() {
|
|
768
|
-
|
|
780
|
+
i(this, "prefix", "[Persona]");
|
|
769
781
|
}
|
|
770
782
|
log(t, ...e) {
|
|
771
783
|
console.log(`${this.prefix} - ${t}`, ...e);
|
|
@@ -783,52 +795,52 @@ class Pe {
|
|
|
783
795
|
console.debug(`${this.prefix} - ${t}`, ...e);
|
|
784
796
|
}
|
|
785
797
|
}
|
|
786
|
-
function
|
|
798
|
+
function k(a, t, e) {
|
|
787
799
|
return {
|
|
788
|
-
type:
|
|
800
|
+
type: a,
|
|
789
801
|
description: t,
|
|
790
802
|
...e
|
|
791
803
|
};
|
|
792
804
|
}
|
|
793
|
-
function de(
|
|
794
|
-
const t = Object.entries(
|
|
805
|
+
function de(a) {
|
|
806
|
+
const t = Object.entries(a.parameters).filter(([e, s]) => s.required).map(([e]) => e);
|
|
795
807
|
return {
|
|
796
808
|
type: "local",
|
|
797
|
-
name:
|
|
798
|
-
description:
|
|
809
|
+
name: a.name,
|
|
810
|
+
description: a.description,
|
|
799
811
|
config: {
|
|
800
|
-
timeout:
|
|
812
|
+
timeout: a.timeout || 60,
|
|
801
813
|
parameters: {
|
|
802
814
|
type: "object",
|
|
803
|
-
title:
|
|
815
|
+
title: a.title || `${a.name} parameters`,
|
|
804
816
|
required: t,
|
|
805
|
-
properties:
|
|
817
|
+
properties: a.parameters
|
|
806
818
|
},
|
|
807
819
|
output: {
|
|
808
820
|
type: "object",
|
|
809
|
-
title: `${
|
|
810
|
-
properties:
|
|
821
|
+
title: `${a.name} output`,
|
|
822
|
+
properties: a.output
|
|
811
823
|
}
|
|
812
824
|
}
|
|
813
825
|
};
|
|
814
826
|
}
|
|
815
|
-
function I(
|
|
827
|
+
function I(a) {
|
|
816
828
|
return {
|
|
817
|
-
schema: de(
|
|
818
|
-
implementation:
|
|
829
|
+
schema: de(a),
|
|
830
|
+
implementation: a.implementation
|
|
819
831
|
};
|
|
820
832
|
}
|
|
821
|
-
function pe(
|
|
822
|
-
const
|
|
823
|
-
name:
|
|
833
|
+
function pe(a, t, e, s, n, o) {
|
|
834
|
+
const r = {
|
|
835
|
+
name: a,
|
|
824
836
|
description: t,
|
|
825
|
-
title:
|
|
826
|
-
timeout:
|
|
837
|
+
title: o == null ? void 0 : o.title,
|
|
838
|
+
timeout: o == null ? void 0 : o.timeout,
|
|
827
839
|
parameters: s,
|
|
828
840
|
output: n,
|
|
829
841
|
implementation: e
|
|
830
842
|
};
|
|
831
|
-
return I(
|
|
843
|
+
return I(r);
|
|
832
844
|
}
|
|
833
845
|
const ke = pe(
|
|
834
846
|
"sum",
|
|
@@ -837,11 +849,11 @@ const ke = pe(
|
|
|
837
849
|
return { result: t + e };
|
|
838
850
|
},
|
|
839
851
|
{
|
|
840
|
-
a:
|
|
841
|
-
b:
|
|
852
|
+
a: k("number", "First number to sum", { required: !0 }),
|
|
853
|
+
b: k("number", "Second number to sum", { required: !0 })
|
|
842
854
|
},
|
|
843
855
|
{
|
|
844
|
-
result:
|
|
856
|
+
result: k("number", "Sum of two numbers")
|
|
845
857
|
}
|
|
846
858
|
), xe = I({
|
|
847
859
|
name: "navigate_to",
|
|
@@ -850,37 +862,37 @@ const ke = pe(
|
|
|
850
862
|
// As per the user's example
|
|
851
863
|
timeout: 60,
|
|
852
864
|
parameters: {
|
|
853
|
-
a:
|
|
854
|
-
b:
|
|
865
|
+
a: k("number", "First number to sum"),
|
|
866
|
+
b: k("number", "Seconth number to sum")
|
|
855
867
|
// Keeping the typo as in the original
|
|
856
868
|
},
|
|
857
869
|
output: {
|
|
858
|
-
result:
|
|
870
|
+
result: k("number", "Sum of two numbers")
|
|
859
871
|
},
|
|
860
872
|
implementation: function(t, e) {
|
|
861
873
|
return { result: t + e };
|
|
862
874
|
}
|
|
863
875
|
});
|
|
864
|
-
function Re(
|
|
876
|
+
function Re(a) {
|
|
865
877
|
const t = [], e = {};
|
|
866
|
-
return
|
|
867
|
-
const { schema: n, implementation:
|
|
868
|
-
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;
|
|
869
881
|
}), { schemas: t, implementations: e };
|
|
870
882
|
}
|
|
871
|
-
function Te(
|
|
883
|
+
function Te(a, t) {
|
|
872
884
|
const { required: e, properties: s } = t.config.parameters;
|
|
873
885
|
for (const n of e)
|
|
874
|
-
if (!(n in
|
|
886
|
+
if (!(n in a))
|
|
875
887
|
throw new Error(`Missing required parameter: ${n}`);
|
|
876
|
-
for (const [n,
|
|
877
|
-
const
|
|
878
|
-
if (
|
|
879
|
-
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")
|
|
880
892
|
throw new Error(`Parameter ${n} should be a number`);
|
|
881
|
-
if (
|
|
893
|
+
if (r.type === "string" && typeof o != "string")
|
|
882
894
|
throw new Error(`Parameter ${n} should be a string`);
|
|
883
|
-
if (
|
|
895
|
+
if (r.type === "boolean" && typeof o != "boolean")
|
|
884
896
|
throw new Error(`Parameter ${n} should be a boolean`);
|
|
885
897
|
}
|
|
886
898
|
}
|
|
@@ -892,9 +904,9 @@ export {
|
|
|
892
904
|
_ as PersonaRESTProtocol,
|
|
893
905
|
ge as PersonaRuntimeProvider,
|
|
894
906
|
ce as PersonaTransactionProtocol,
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
907
|
+
W as PersonaWebRTCProtocol,
|
|
908
|
+
U as PersonaWebSocketProtocol,
|
|
909
|
+
k as createParameter,
|
|
898
910
|
I as createTool,
|
|
899
911
|
pe as createToolFromFunction,
|
|
900
912
|
Re as createToolRegistry,
|