@applica-software-guru/persona-sdk 0.1.67 → 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 +269 -248
- 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 +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 +37 -12
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
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,13 +14,13 @@ var F = { exports: {} }, k = {};
|
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*/
|
|
16
16
|
var O;
|
|
17
|
-
function
|
|
17
|
+
function ne() {
|
|
18
18
|
if (O) return k;
|
|
19
19
|
O = 1;
|
|
20
20
|
var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
21
|
function e(s, n, a) {
|
|
22
|
-
var
|
|
23
|
-
if (a !== void 0 && (
|
|
22
|
+
var r = null;
|
|
23
|
+
if (a !== void 0 && (r = "" + a), n.key !== void 0 && (r = "" + n.key), "key" in n) {
|
|
24
24
|
a = {};
|
|
25
25
|
for (var c in n)
|
|
26
26
|
c !== "key" && (a[c] = n[c]);
|
|
@@ -28,16 +28,16 @@ function se() {
|
|
|
28
28
|
return n = a.ref, {
|
|
29
29
|
$$typeof: o,
|
|
30
30
|
type: s,
|
|
31
|
-
key:
|
|
31
|
+
key: r,
|
|
32
32
|
ref: n !== void 0 ? n : null,
|
|
33
33
|
props: a
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
return k.Fragment = t, k.jsx = e, k.jsxs = e, k;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
function
|
|
38
|
+
W.exports = ne();
|
|
39
|
+
var I = W.exports;
|
|
40
|
+
function oe(o) {
|
|
41
41
|
return o.filter((t) => {
|
|
42
42
|
var e;
|
|
43
43
|
return t.finishReason === "stop" ? t.text !== null && ((e = t.text) == null ? void 0 : e.trim()) !== "" : !0;
|
|
@@ -53,9 +53,9 @@ function j(o) {
|
|
|
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
|
|
58
|
+
function ae(o) {
|
|
59
59
|
var e, s;
|
|
60
60
|
const t = ((e = o.files) == null ? void 0 : e.map(
|
|
61
61
|
(n) => ({
|
|
@@ -84,10 +84,10 @@ function oe(o) {
|
|
|
84
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
|
-
|
|
90
|
-
|
|
89
|
+
i(this, "statusChangeCallbacks", []);
|
|
90
|
+
i(this, "messageCallbacks", []);
|
|
91
91
|
}
|
|
92
92
|
addStatusChangeListener(t) {
|
|
93
93
|
this.statusChangeCallbacks.push(t);
|
|
@@ -119,16 +119,16 @@ class v {
|
|
|
119
119
|
onTransaction(t) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class _ extends
|
|
122
|
+
class _ extends $ {
|
|
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,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: a } = this.config,
|
|
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
155
|
} else if (e.type === "command" && ((g = e == null ? void 0 : e.payload) == null ? void 0 : g.command) == "set_local_tools") {
|
|
156
|
-
|
|
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,7 +166,7 @@ class _ extends v {
|
|
|
165
166
|
}
|
|
166
167
|
const c = e.payload;
|
|
167
168
|
try {
|
|
168
|
-
const
|
|
169
|
+
const N = await (await fetch(`${s}/sessions/${r}/messages`, {
|
|
169
170
|
body: JSON.stringify({ agentId: a, userMessage: c, initialContext: this.context, tools: this.tools }),
|
|
170
171
|
method: "POST",
|
|
171
172
|
headers: {
|
|
@@ -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,18 +188,18 @@ 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
|
|
195
|
+
class U extends $ {
|
|
195
196
|
constructor(e) {
|
|
196
197
|
super();
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
i(this, "status");
|
|
199
|
+
i(this, "autostart");
|
|
200
|
+
i(this, "session");
|
|
201
|
+
i(this, "config");
|
|
202
|
+
i(this, "webSocket");
|
|
202
203
|
this.config = e, this.status = "disconnected", this.autostart = !0, this.session = null, this.webSocket = null;
|
|
203
204
|
}
|
|
204
205
|
getName() {
|
|
@@ -217,25 +218,25 @@ class W 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), a = this.config.agentId,
|
|
221
|
-
return this.setStatus("connecting"), this.webSocket = new WebSocket(
|
|
221
|
+
const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
|
|
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,23 +247,23 @@ class W 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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
252
|
+
i(this, "config");
|
|
253
|
+
i(this, "pc", null);
|
|
254
|
+
i(this, "ws", null);
|
|
255
|
+
i(this, "localStream", null);
|
|
256
|
+
i(this, "remoteStream", new MediaStream());
|
|
257
|
+
i(this, "audioCtx", null);
|
|
258
|
+
i(this, "localAnalyser", null);
|
|
259
|
+
i(this, "remoteAnalyser", null);
|
|
260
|
+
i(this, "analyzerFrame", null);
|
|
261
|
+
i(this, "dataChannel", null);
|
|
262
|
+
i(this, "isConnected", !1);
|
|
263
|
+
i(this, "visualizerCallbacks", []);
|
|
264
|
+
i(this, "messageCallbacks", []);
|
|
265
|
+
i(this, "errorCallbacks", []);
|
|
266
|
+
i(this, "queuedMessages", []);
|
|
266
267
|
this.config = t;
|
|
267
268
|
}
|
|
268
269
|
async connect(t) {
|
|
@@ -289,13 +290,13 @@ class ae {
|
|
|
289
290
|
}), this.localStream.getTracks().forEach((n) => {
|
|
290
291
|
this.pc.addTrack(n, this.localStream);
|
|
291
292
|
}), this.pc.ontrack = (n) => {
|
|
292
|
-
n.streams[0].getTracks().forEach((
|
|
293
|
-
this.remoteStream.addTrack(
|
|
293
|
+
n.streams[0].getTracks().forEach((r) => {
|
|
294
|
+
this.remoteStream.addTrack(r);
|
|
294
295
|
}), this.audioCtx || this._startAnalyzers();
|
|
295
296
|
const a = new Audio();
|
|
296
|
-
a.srcObject = this.remoteStream, a.play().catch((
|
|
297
|
+
a.srcObject = this.remoteStream, a.play().catch((r) => {
|
|
297
298
|
var c;
|
|
298
|
-
(c = this.config.logger) == null || c.error("Error playing remote audio:",
|
|
299
|
+
(c = this.config.logger) == null || c.error("Error playing remote audio:", r);
|
|
299
300
|
});
|
|
300
301
|
}, this.pc.onicecandidate = (n) => {
|
|
301
302
|
var a;
|
|
@@ -308,21 +309,21 @@ class ae {
|
|
|
308
309
|
);
|
|
309
310
|
}, this.pc.ondatachannel = (n) => {
|
|
310
311
|
const a = n.channel;
|
|
311
|
-
a.onmessage = (
|
|
312
|
+
a.onmessage = (r) => {
|
|
312
313
|
this.messageCallbacks.forEach((c) => {
|
|
313
|
-
c(
|
|
314
|
+
c(r);
|
|
314
315
|
});
|
|
315
316
|
}, a.onopen = () => {
|
|
316
|
-
var
|
|
317
|
+
var r;
|
|
317
318
|
for (; this.queuedMessages.length > 0; ) {
|
|
318
319
|
const c = this.queuedMessages.shift();
|
|
319
|
-
c && (a.send(JSON.stringify(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
329
|
const a = {
|
|
@@ -331,9 +332,9 @@ class ae {
|
|
|
331
332
|
sessionCode: t
|
|
332
333
|
};
|
|
333
334
|
(c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ", a);
|
|
334
|
-
const
|
|
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,
|
|
@@ -343,9 +344,9 @@ class ae {
|
|
|
343
344
|
metadata: a
|
|
344
345
|
}
|
|
345
346
|
};
|
|
346
|
-
this.ws.send(JSON.stringify(
|
|
347
|
+
this.ws.send(JSON.stringify(r));
|
|
347
348
|
}, this.ws.onmessage = async (n) => {
|
|
348
|
-
var
|
|
349
|
+
var r;
|
|
349
350
|
const a = JSON.parse(n.data);
|
|
350
351
|
if (a.type === "ANSWER")
|
|
351
352
|
await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
|
|
@@ -353,7 +354,7 @@ class ae {
|
|
|
353
354
|
try {
|
|
354
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
360
|
n.code !== 1e3 && this.errorCallbacks.forEach((a) => {
|
|
@@ -406,10 +407,10 @@ class ae {
|
|
|
406
407
|
return;
|
|
407
408
|
const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
408
409
|
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
|
|
409
|
-
const
|
|
410
|
-
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((
|
|
411
|
-
|
|
412
|
-
localAmplitude:
|
|
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({
|
|
413
|
+
localAmplitude: r,
|
|
413
414
|
remoteAmplitude: c
|
|
414
415
|
});
|
|
415
416
|
}), this.analyzerFrame = requestAnimationFrame(s);
|
|
@@ -420,15 +421,15 @@ class ae {
|
|
|
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
|
-
|
|
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
|
|
427
|
+
i(this, "status");
|
|
428
|
+
i(this, "session");
|
|
429
|
+
i(this, "autostart");
|
|
430
|
+
i(this, "config");
|
|
431
|
+
i(this, "webRTCClient");
|
|
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) => {
|
|
@@ -468,7 +469,7 @@ class z extends v {
|
|
|
468
469
|
}
|
|
469
470
|
class ie {
|
|
470
471
|
constructor(t) {
|
|
471
|
-
|
|
472
|
+
i(this, "config");
|
|
472
473
|
this.config = t;
|
|
473
474
|
}
|
|
474
475
|
async complete(t, e) {
|
|
@@ -491,17 +492,17 @@ class ie {
|
|
|
491
492
|
});
|
|
492
493
|
}
|
|
493
494
|
}
|
|
494
|
-
class
|
|
495
|
+
class ce {
|
|
495
496
|
constructor(t, e) {
|
|
496
|
-
|
|
497
|
-
|
|
497
|
+
i(this, "transaction");
|
|
498
|
+
i(this, "manager");
|
|
498
499
|
this.transaction = t, this.manager = e;
|
|
499
500
|
}
|
|
500
501
|
getFunctionCall() {
|
|
501
502
|
return this.transaction.functionCall;
|
|
502
503
|
}
|
|
503
504
|
async invoke(t) {
|
|
504
|
-
var
|
|
505
|
+
var r;
|
|
505
506
|
const e = this.transaction.functionCall;
|
|
506
507
|
if (!e) {
|
|
507
508
|
await this.fail("No function call found");
|
|
@@ -513,8 +514,8 @@ class re {
|
|
|
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,15 +527,15 @@ class re {
|
|
|
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
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
533
|
+
i(this, "status");
|
|
534
|
+
i(this, "autostart");
|
|
535
|
+
i(this, "session");
|
|
536
|
+
i(this, "config");
|
|
537
|
+
i(this, "notify", !0);
|
|
538
|
+
i(this, "_tools");
|
|
538
539
|
if (this.config = e, this.status = "disconnected", this.autostart = !0, Array.isArray(e.tools)) {
|
|
539
540
|
this._tools = {};
|
|
540
541
|
for (const s of e.tools)
|
|
@@ -561,15 +562,15 @@ class ce extends v {
|
|
|
561
562
|
}
|
|
562
563
|
onTransaction(e) {
|
|
563
564
|
console.log("transaction received:", e);
|
|
564
|
-
const s = new ie(this.config), n = 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
|
|
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
576
|
s.readAsDataURL(o), s.onload = () => {
|
|
@@ -580,150 +581,173 @@ function le(o) {
|
|
|
580
581
|
};
|
|
581
582
|
});
|
|
582
583
|
}
|
|
583
|
-
function
|
|
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({
|
|
584
598
|
dev: o = !1,
|
|
585
599
|
baseUrl: t,
|
|
586
600
|
protocols: e,
|
|
587
601
|
logger: s,
|
|
588
602
|
children: n,
|
|
589
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: `${
|
|
603
|
-
apiKey:
|
|
604
|
-
agentId:
|
|
614
|
+
const b = e[m];
|
|
615
|
+
return b === !0 ? new _({
|
|
616
|
+
apiUrl: `${h}://${y}`,
|
|
617
|
+
apiKey: r.apiKey,
|
|
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: `${
|
|
611
|
-
apiKey:
|
|
612
|
-
agentId:
|
|
622
|
+
const u = e[m];
|
|
623
|
+
return u === !0 ? new F({
|
|
624
|
+
webrtcUrl: `${f}://${y}/webrtc`,
|
|
625
|
+
apiKey: r.apiKey,
|
|
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
|
|
617
|
-
return
|
|
618
|
-
webSocketUrl: `${
|
|
619
|
-
apiKey:
|
|
620
|
-
agentId:
|
|
630
|
+
const P = e[m];
|
|
631
|
+
return P === !0 ? new U({
|
|
632
|
+
webSocketUrl: `${f}://${y}/websocket`,
|
|
633
|
+
apiKey: r.apiKey,
|
|
634
|
+
agentId: r.agentId,
|
|
621
635
|
logger: s
|
|
622
|
-
}) : typeof
|
|
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
|
|
628
|
-
new
|
|
629
|
-
apiUrl: `${
|
|
630
|
-
apiKey:
|
|
631
|
-
agentId:
|
|
632
|
-
tools:
|
|
640
|
+
}).filter((m) => m !== null);
|
|
641
|
+
return r.tools && d.push(
|
|
642
|
+
new le({
|
|
643
|
+
apiUrl: `${h}://${y}`,
|
|
644
|
+
apiKey: r.apiKey,
|
|
645
|
+
agentId: r.agentId,
|
|
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
|
-
S.map((
|
|
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
|
-
arguments:
|
|
667
|
+
arguments: r.context
|
|
651
668
|
}
|
|
652
|
-
}),
|
|
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:
|
|
674
|
+
tools: r.tools.map((d) => d.schema)
|
|
658
675
|
}
|
|
659
676
|
}
|
|
660
|
-
})),
|
|
661
|
-
}),
|
|
662
|
-
if (
|
|
663
|
-
const
|
|
677
|
+
})), N(new Map(w));
|
|
678
|
+
}), h.addPacketListener((f) => {
|
|
679
|
+
if (f.type === "message") {
|
|
680
|
+
const d = f.payload;
|
|
664
681
|
g(
|
|
665
|
-
(
|
|
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" };
|
|
674
691
|
g(
|
|
675
|
-
(
|
|
692
|
+
(u) => j([...u, { ...b, protocol: h.getName() }])
|
|
676
693
|
);
|
|
677
|
-
} else
|
|
678
|
-
}),
|
|
679
|
-
})
|
|
680
|
-
}, [
|
|
681
|
-
const
|
|
682
|
-
var
|
|
683
|
-
if (((
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
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,
|
|
704
|
+
{ role: "assistant", type: "text", text: "No protocol is connected." }
|
|
705
|
+
]);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
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({
|
|
690
714
|
role: "user",
|
|
691
715
|
image: {
|
|
692
|
-
contentType:
|
|
693
|
-
content: await
|
|
716
|
+
contentType: u.contentType,
|
|
717
|
+
content: await ue(u.file)
|
|
694
718
|
},
|
|
695
719
|
text: "",
|
|
696
720
|
type: "text"
|
|
697
721
|
});
|
|
698
|
-
|
|
722
|
+
y.content && m.push({
|
|
699
723
|
role: "user",
|
|
700
|
-
text:
|
|
724
|
+
text: y.content[0].text,
|
|
701
725
|
type: "text"
|
|
702
|
-
}), s == null || s.debug("Sending message:",
|
|
703
|
-
},
|
|
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({
|
|
704
728
|
isRunning: c,
|
|
705
|
-
messages:
|
|
706
|
-
convertMessage:
|
|
707
|
-
onNew:
|
|
708
|
-
onCancel:
|
|
709
|
-
onReload:
|
|
729
|
+
messages: p,
|
|
730
|
+
convertMessage: ae,
|
|
731
|
+
onNew: D,
|
|
732
|
+
onCancel: L,
|
|
733
|
+
onReload: J,
|
|
710
734
|
adapters: {
|
|
711
|
-
attachments: new
|
|
735
|
+
attachments: new ee([new te()])
|
|
712
736
|
}
|
|
713
737
|
});
|
|
714
|
-
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 }) });
|
|
715
739
|
}
|
|
716
|
-
function
|
|
717
|
-
return /* @__PURE__ */
|
|
740
|
+
function we({ children: o, ...t }) {
|
|
741
|
+
return /* @__PURE__ */ I.jsx(he, { ...t, children: o });
|
|
718
742
|
}
|
|
719
|
-
function
|
|
720
|
-
const o =
|
|
743
|
+
function be() {
|
|
744
|
+
const o = v(R);
|
|
721
745
|
if (!o)
|
|
722
746
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
723
747
|
return o;
|
|
724
748
|
}
|
|
725
|
-
function
|
|
726
|
-
const t =
|
|
749
|
+
function de(o) {
|
|
750
|
+
const t = v(R);
|
|
727
751
|
if (!t)
|
|
728
752
|
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
729
753
|
const e = t.protocols.find((n) => n.getName() === o);
|
|
@@ -743,27 +767,24 @@ function he(o) {
|
|
|
743
767
|
status: s || e.status
|
|
744
768
|
};
|
|
745
769
|
}
|
|
746
|
-
function
|
|
747
|
-
const o =
|
|
770
|
+
function Se() {
|
|
771
|
+
const o = v(R);
|
|
748
772
|
if (!o)
|
|
749
773
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
750
|
-
|
|
751
|
-
if (t.getName() === "rest")
|
|
752
|
-
return t.config.apiUrl;
|
|
753
|
-
throw new Error("REST protocol not found");
|
|
754
|
-
}
|
|
755
|
-
function Se() {
|
|
756
|
-
return he("webrtc");
|
|
774
|
+
return z(o.protocols);
|
|
757
775
|
}
|
|
758
776
|
function Ce() {
|
|
759
|
-
|
|
777
|
+
return de("webrtc");
|
|
778
|
+
}
|
|
779
|
+
function Pe() {
|
|
780
|
+
const o = v(R);
|
|
760
781
|
if (!o)
|
|
761
782
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
762
783
|
return o.getMessages();
|
|
763
784
|
}
|
|
764
|
-
class
|
|
785
|
+
class xe {
|
|
765
786
|
constructor() {
|
|
766
|
-
|
|
787
|
+
i(this, "prefix", "[Persona]");
|
|
767
788
|
}
|
|
768
789
|
log(t, ...e) {
|
|
769
790
|
console.log(`${this.prefix} - ${t}`, ...e);
|
|
@@ -781,14 +802,14 @@ class Pe {
|
|
|
781
802
|
console.debug(`${this.prefix} - ${t}`, ...e);
|
|
782
803
|
}
|
|
783
804
|
}
|
|
784
|
-
function
|
|
805
|
+
function x(o, t, e) {
|
|
785
806
|
return {
|
|
786
807
|
type: o,
|
|
787
808
|
description: t,
|
|
788
809
|
...e
|
|
789
810
|
};
|
|
790
811
|
}
|
|
791
|
-
function
|
|
812
|
+
function pe(o) {
|
|
792
813
|
const t = Object.entries(o.parameters).filter(([e, s]) => s.required).map(([e]) => e);
|
|
793
814
|
return {
|
|
794
815
|
type: "local",
|
|
@@ -810,14 +831,14 @@ function de(o) {
|
|
|
810
831
|
}
|
|
811
832
|
};
|
|
812
833
|
}
|
|
813
|
-
function
|
|
834
|
+
function q(o) {
|
|
814
835
|
return {
|
|
815
|
-
schema:
|
|
836
|
+
schema: pe(o),
|
|
816
837
|
implementation: o.implementation
|
|
817
838
|
};
|
|
818
839
|
}
|
|
819
|
-
function
|
|
820
|
-
const
|
|
840
|
+
function me(o, t, e, s, n, a) {
|
|
841
|
+
const r = {
|
|
821
842
|
name: o,
|
|
822
843
|
description: t,
|
|
823
844
|
title: a == null ? void 0 : a.title,
|
|
@@ -826,43 +847,43 @@ function pe(o, t, e, s, n, a) {
|
|
|
826
847
|
output: n,
|
|
827
848
|
implementation: e
|
|
828
849
|
};
|
|
829
|
-
return
|
|
850
|
+
return q(r);
|
|
830
851
|
}
|
|
831
|
-
const ke =
|
|
852
|
+
const ke = me(
|
|
832
853
|
"sum",
|
|
833
854
|
"Sum two numbers",
|
|
834
855
|
function(t, e) {
|
|
835
856
|
return { result: t + e };
|
|
836
857
|
},
|
|
837
858
|
{
|
|
838
|
-
a:
|
|
839
|
-
b:
|
|
859
|
+
a: x("number", "First number to sum", { required: !0 }),
|
|
860
|
+
b: x("number", "Second number to sum", { required: !0 })
|
|
840
861
|
},
|
|
841
862
|
{
|
|
842
|
-
result:
|
|
863
|
+
result: x("number", "Sum of two numbers")
|
|
843
864
|
}
|
|
844
|
-
),
|
|
865
|
+
), Re = q({
|
|
845
866
|
name: "navigate_to",
|
|
846
867
|
description: "Allow agent to redirect user to specific sub page like /foo or #/foo or anything like that",
|
|
847
868
|
title: "Sum two numbers",
|
|
848
869
|
// As per the user's example
|
|
849
870
|
timeout: 60,
|
|
850
871
|
parameters: {
|
|
851
|
-
a:
|
|
852
|
-
b:
|
|
872
|
+
a: x("number", "First number to sum"),
|
|
873
|
+
b: x("number", "Seconth number to sum")
|
|
853
874
|
// Keeping the typo as in the original
|
|
854
875
|
},
|
|
855
876
|
output: {
|
|
856
|
-
result:
|
|
877
|
+
result: x("number", "Sum of two numbers")
|
|
857
878
|
},
|
|
858
879
|
implementation: function(t, e) {
|
|
859
880
|
return { result: t + e };
|
|
860
881
|
}
|
|
861
882
|
});
|
|
862
|
-
function
|
|
883
|
+
function Ae(o) {
|
|
863
884
|
const t = [], e = {};
|
|
864
885
|
return o.forEach((s) => {
|
|
865
|
-
const { schema: n, implementation: a } =
|
|
886
|
+
const { schema: n, implementation: a } = q(s);
|
|
866
887
|
t.push(n), e[s.name] = a;
|
|
867
888
|
}), { schemas: t, implementations: e };
|
|
868
889
|
}
|
|
@@ -872,38 +893,38 @@ function Te(o, t) {
|
|
|
872
893
|
if (!(n in o))
|
|
873
894
|
throw new Error(`Missing required parameter: ${n}`);
|
|
874
895
|
for (const [n, a] of Object.entries(o)) {
|
|
875
|
-
const
|
|
876
|
-
if (
|
|
877
|
-
if (
|
|
896
|
+
const r = s[n];
|
|
897
|
+
if (r) {
|
|
898
|
+
if (r.type === "number" && typeof a != "number")
|
|
878
899
|
throw new Error(`Parameter ${n} should be a number`);
|
|
879
|
-
if (
|
|
900
|
+
if (r.type === "string" && typeof a != "string")
|
|
880
901
|
throw new Error(`Parameter ${n} should be a string`);
|
|
881
|
-
if (
|
|
902
|
+
if (r.type === "boolean" && typeof a != "boolean")
|
|
882
903
|
throw new Error(`Parameter ${n} should be a boolean`);
|
|
883
904
|
}
|
|
884
905
|
}
|
|
885
906
|
return !0;
|
|
886
907
|
}
|
|
887
908
|
export {
|
|
888
|
-
|
|
889
|
-
|
|
909
|
+
xe as PersonaConsoleLogger,
|
|
910
|
+
$ as PersonaProtocolBase,
|
|
890
911
|
_ as PersonaRESTProtocol,
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
912
|
+
we as PersonaRuntimeProvider,
|
|
913
|
+
le as PersonaTransactionProtocol,
|
|
914
|
+
F as PersonaWebRTCProtocol,
|
|
915
|
+
U as PersonaWebSocketProtocol,
|
|
916
|
+
x as createParameter,
|
|
917
|
+
q as createTool,
|
|
918
|
+
me as createToolFromFunction,
|
|
919
|
+
Ae as createToolRegistry,
|
|
920
|
+
pe as generateToolSchema,
|
|
921
|
+
Re as navigateToToolExample,
|
|
901
922
|
ke as sumTool,
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
923
|
+
be as usePersonaRuntime,
|
|
924
|
+
Se as usePersonaRuntimeEndpoint,
|
|
925
|
+
Pe as usePersonaRuntimeMessages,
|
|
926
|
+
de as usePersonaRuntimeProtocol,
|
|
927
|
+
Ce as usePersonaRuntimeWebRTCProtocol,
|
|
907
928
|
Te as validateToolParameters
|
|
908
929
|
};
|
|
909
930
|
//# sourceMappingURL=bundle.es.js.map
|