@applica-software-guru/persona-sdk 0.1.64 → 0.1.66
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 +182 -138
- 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/protocol/transaction.d.ts.map +1 -1
- package/dist/protocol/webrtc.d.ts +3 -0
- package/dist/protocol/webrtc.d.ts.map +1 -1
- package/dist/protocol/websocket.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/protocol/rest.ts +34 -17
- package/src/protocol/transaction.ts +13 -1
- package/src/protocol/webrtc.ts +24 -1
- package/src/protocol/websocket.ts +14 -6
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var B = Object.defineProperty;
|
|
2
2
|
var V = (o, t, e) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
3
|
var r = (o, t, e) => V(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { createContext as Y, useContext as
|
|
4
|
+
import { createContext as Y, useContext as A, useState as E, useRef as G, useMemo as H, useEffect as Q, useCallback as N } from "react";
|
|
5
5
|
import { useExternalStoreRuntime as X, CompositeAttachmentAdapter as Z, SimpleImageAttachmentAdapter as ee, AssistantRuntimeProvider as te } from "@assistant-ui/react";
|
|
6
|
-
var
|
|
6
|
+
var F = { exports: {} }, k = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
@@ -13,17 +13,17 @@ var U = { exports: {} }, k = {};
|
|
|
13
13
|
* This source code is licensed under the MIT license found in the
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*/
|
|
16
|
-
var
|
|
16
|
+
var O;
|
|
17
17
|
function se() {
|
|
18
|
-
if (
|
|
19
|
-
|
|
18
|
+
if (O) return k;
|
|
19
|
+
O = 1;
|
|
20
20
|
var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
21
|
function e(s, n, a) {
|
|
22
22
|
var i = null;
|
|
23
23
|
if (a !== void 0 && (i = "" + a), n.key !== void 0 && (i = "" + n.key), "key" in n) {
|
|
24
24
|
a = {};
|
|
25
|
-
for (var
|
|
26
|
-
|
|
25
|
+
for (var c in n)
|
|
26
|
+
c !== "key" && (a[c] = n[c]);
|
|
27
27
|
} else a = n;
|
|
28
28
|
return n = a.ref, {
|
|
29
29
|
$$typeof: o,
|
|
@@ -35,15 +35,15 @@ function se() {
|
|
|
35
35
|
}
|
|
36
36
|
return k.Fragment = t, k.jsx = e, k.jsxs = e, k;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
var
|
|
38
|
+
F.exports = se();
|
|
39
|
+
var M = F.exports;
|
|
40
40
|
function ne(o) {
|
|
41
41
|
return o.filter((t) => {
|
|
42
42
|
var e;
|
|
43
43
|
return t.finishReason === "stop" ? t.text !== null && ((e = t.text) == null ? void 0 : e.trim()) !== "" : !0;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function j(o) {
|
|
47
47
|
const t = [];
|
|
48
48
|
let e = null;
|
|
49
49
|
for (const n of o)
|
|
@@ -84,7 +84,7 @@ 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 v {
|
|
88
88
|
constructor() {
|
|
89
89
|
r(this, "statusChangeCallbacks", []);
|
|
90
90
|
r(this, "messageCallbacks", []);
|
|
@@ -119,7 +119,7 @@ class M {
|
|
|
119
119
|
onTransaction(t) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class _ extends
|
|
122
|
+
class _ extends v {
|
|
123
123
|
constructor(e) {
|
|
124
124
|
super();
|
|
125
125
|
r(this, "status");
|
|
@@ -147,33 +147,51 @@ class _ extends M {
|
|
|
147
147
|
this.session = e;
|
|
148
148
|
}
|
|
149
149
|
async sendPacket(e) {
|
|
150
|
-
var
|
|
150
|
+
var u, d, g, w;
|
|
151
151
|
const { apiUrl: s, apiKey: n, agentId: a } = this.config, i = this.session ?? "new";
|
|
152
|
-
if (e.type === "command" && ((
|
|
153
|
-
this.context = (
|
|
152
|
+
if (e.type === "command" && ((u = e == null ? void 0 : e.payload) == null ? void 0 : u.command) == "set_initial_context") {
|
|
153
|
+
this.context = (d = e == null ? void 0 : e.payload) == null ? void 0 : d.arguments;
|
|
154
154
|
return;
|
|
155
|
-
} else if (e.type === "command" && ((
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
} else if (e.type === "command" && ((g = e == null ? void 0 : e.payload) == null ? void 0 : g.command) == "set_local_tools") {
|
|
156
|
+
this.notifyPacket({
|
|
157
|
+
type: "message",
|
|
158
|
+
payload: {
|
|
159
|
+
type: "text",
|
|
160
|
+
role: "assistant",
|
|
161
|
+
text: "Local tools with rest protocol are not supported."
|
|
162
|
+
}
|
|
163
|
+
});
|
|
158
164
|
return;
|
|
159
165
|
}
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
const c = e.payload;
|
|
167
|
+
try {
|
|
168
|
+
const b = await (await fetch(`${s}/sessions/${i}/messages`, {
|
|
169
|
+
body: JSON.stringify({ agentId: a, userMessage: c, initialContext: this.context, tools: this.tools }),
|
|
170
|
+
method: "POST",
|
|
171
|
+
headers: {
|
|
172
|
+
"Content-Type": "application/json",
|
|
173
|
+
"x-persona-apikey": n
|
|
174
|
+
}
|
|
175
|
+
})).json();
|
|
176
|
+
this.notifyPackets(
|
|
177
|
+
b.response.messages.map(($) => ({
|
|
178
|
+
type: "message",
|
|
179
|
+
payload: $
|
|
180
|
+
}))
|
|
181
|
+
);
|
|
182
|
+
} catch (R) {
|
|
183
|
+
this.notifyPacket({
|
|
170
184
|
type: "message",
|
|
171
|
-
payload:
|
|
172
|
-
|
|
173
|
-
|
|
185
|
+
payload: {
|
|
186
|
+
role: "assistant",
|
|
187
|
+
type: "text",
|
|
188
|
+
text: "An error occurred while processing your request. Please try again later."
|
|
189
|
+
}
|
|
190
|
+
}), (w = this.config.logger) == null || w.error("Error sending packet:", R);
|
|
191
|
+
}
|
|
174
192
|
}
|
|
175
193
|
}
|
|
176
|
-
class
|
|
194
|
+
class W extends v {
|
|
177
195
|
constructor(e) {
|
|
178
196
|
super();
|
|
179
197
|
r(this, "status");
|
|
@@ -194,23 +212,30 @@ class z extends M {
|
|
|
194
212
|
(s = this.config.logger) == null || s.debug("Syncing session with WebSocket protocol:", e), this.session = e, this.webSocket && this.status === "connected" && (this.disconnect(), this.connect(e));
|
|
195
213
|
}
|
|
196
214
|
connect(e) {
|
|
197
|
-
var
|
|
215
|
+
var c;
|
|
198
216
|
if (this.webSocket !== null && this.status === "connected")
|
|
199
217
|
return Promise.resolve(this.session);
|
|
200
218
|
const s = e || this.session || "new";
|
|
201
|
-
(
|
|
219
|
+
(c = this.config.logger) == null || c.debug("Connecting to WebSocket with sessionId:", s);
|
|
202
220
|
const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, i = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
|
|
203
221
|
return this.setStatus("connecting"), this.webSocket = new WebSocket(i), this.webSocket.addEventListener("open", () => {
|
|
204
222
|
this.setStatus("connected");
|
|
205
223
|
}), this.webSocket.addEventListener("message", (u) => {
|
|
206
|
-
const
|
|
207
|
-
this.notifyPacket(
|
|
208
|
-
}), this.webSocket.addEventListener("close", () => {
|
|
224
|
+
const d = JSON.parse(u.data);
|
|
225
|
+
this.notifyPacket(d);
|
|
226
|
+
}), this.webSocket.addEventListener("close", (u) => {
|
|
227
|
+
var d;
|
|
228
|
+
this.setStatus("disconnected"), this.webSocket = null, u.code !== 1e3 && (this.notifyPacket({
|
|
229
|
+
type: "message",
|
|
230
|
+
payload: {
|
|
231
|
+
role: "assistant",
|
|
232
|
+
type: "text",
|
|
233
|
+
text: "Oops! The connection to the server was lost. Please try again later."
|
|
234
|
+
}
|
|
235
|
+
}), (d = this.config.logger) == null || d.warn("WebSocket connection closed"));
|
|
236
|
+
}), this.webSocket.addEventListener("error", () => {
|
|
209
237
|
var u;
|
|
210
|
-
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.
|
|
211
|
-
}), this.webSocket.addEventListener("error", (u) => {
|
|
212
|
-
var f;
|
|
213
|
-
this.setStatus("disconnected"), this.webSocket = null, (f = this.config.logger) == null || f.error("WebSocket error", u);
|
|
238
|
+
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.error("WebSocket connection error");
|
|
214
239
|
}), Promise.resolve(s);
|
|
215
240
|
}
|
|
216
241
|
disconnect() {
|
|
@@ -236,6 +261,7 @@ class ae {
|
|
|
236
261
|
r(this, "isConnected", !1);
|
|
237
262
|
r(this, "visualizerCallbacks", []);
|
|
238
263
|
r(this, "messageCallbacks", []);
|
|
264
|
+
r(this, "errorCallbacks", []);
|
|
239
265
|
r(this, "queuedMessages", []);
|
|
240
266
|
this.config = t;
|
|
241
267
|
}
|
|
@@ -268,8 +294,8 @@ class ae {
|
|
|
268
294
|
}), this.audioCtx || this._startAnalyzers();
|
|
269
295
|
const a = new Audio();
|
|
270
296
|
a.srcObject = this.remoteStream, a.play().catch((i) => {
|
|
271
|
-
var
|
|
272
|
-
(
|
|
297
|
+
var c;
|
|
298
|
+
(c = this.config.logger) == null || c.error("Error playing remote audio:", i);
|
|
273
299
|
});
|
|
274
300
|
}, this.pc.onicecandidate = (n) => {
|
|
275
301
|
var a;
|
|
@@ -283,20 +309,20 @@ class ae {
|
|
|
283
309
|
}, this.pc.ondatachannel = (n) => {
|
|
284
310
|
const a = n.channel;
|
|
285
311
|
a.onmessage = (i) => {
|
|
286
|
-
this.messageCallbacks.forEach((
|
|
287
|
-
|
|
312
|
+
this.messageCallbacks.forEach((c) => {
|
|
313
|
+
c(i);
|
|
288
314
|
});
|
|
289
315
|
}, a.onopen = () => {
|
|
290
316
|
var i;
|
|
291
317
|
for (; this.queuedMessages.length > 0; ) {
|
|
292
|
-
const
|
|
293
|
-
|
|
318
|
+
const c = this.queuedMessages.shift();
|
|
319
|
+
c && (a.send(JSON.stringify(c)), (i = this.config.logger) == null || i.info("Sent queued message:", c));
|
|
294
320
|
}
|
|
295
321
|
};
|
|
296
322
|
};
|
|
297
323
|
const e = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
|
|
298
324
|
this.ws = new WebSocket(`${e}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
|
|
299
|
-
var
|
|
325
|
+
var c, u;
|
|
300
326
|
const n = await this.pc.createOffer();
|
|
301
327
|
await this.pc.setLocalDescription(n);
|
|
302
328
|
const a = {
|
|
@@ -304,7 +330,7 @@ class ae {
|
|
|
304
330
|
agentId: this.config.agentId,
|
|
305
331
|
sessionCode: t
|
|
306
332
|
};
|
|
307
|
-
(
|
|
333
|
+
(c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ", a);
|
|
308
334
|
const i = {
|
|
309
335
|
type: "OFFER",
|
|
310
336
|
src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
|
|
@@ -326,11 +352,13 @@ class ae {
|
|
|
326
352
|
else if (a.type === "CANDIDATE")
|
|
327
353
|
try {
|
|
328
354
|
await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
|
|
329
|
-
} catch (
|
|
330
|
-
(i = this.config.logger) == null || i.error("Error adding ICE candidate:",
|
|
355
|
+
} catch (c) {
|
|
356
|
+
(i = this.config.logger) == null || i.error("Error adding ICE candidate:", c);
|
|
331
357
|
}
|
|
332
|
-
}, this.ws.onclose = () => {
|
|
333
|
-
this.
|
|
358
|
+
}, this.ws.onclose = (n) => {
|
|
359
|
+
n.code !== 1e3 && this.errorCallbacks.forEach((a) => {
|
|
360
|
+
a("Oops! The connection to the server was lost. Please try again later.");
|
|
361
|
+
}), this._stopAnalyzers();
|
|
334
362
|
};
|
|
335
363
|
}
|
|
336
364
|
async disconnect() {
|
|
@@ -343,6 +371,9 @@ class ae {
|
|
|
343
371
|
addMessageCallback(t) {
|
|
344
372
|
this.messageCallbacks.push(t);
|
|
345
373
|
}
|
|
374
|
+
addErrorCallback(t) {
|
|
375
|
+
this.errorCallbacks.push(t);
|
|
376
|
+
}
|
|
346
377
|
createDataChannel(t = "messages") {
|
|
347
378
|
this.pc && (this.dataChannel = this.pc.createDataChannel(t), this.dataChannel.onopen = () => {
|
|
348
379
|
var e, s;
|
|
@@ -375,11 +406,11 @@ class ae {
|
|
|
375
406
|
return;
|
|
376
407
|
const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
377
408
|
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
|
|
378
|
-
const i = n.reduce((u,
|
|
409
|
+
const i = n.reduce((u, d) => u + d, 0) / n.length, c = a.reduce((u, d) => u + d, 0) / a.length;
|
|
379
410
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
380
411
|
u({
|
|
381
412
|
localAmplitude: i,
|
|
382
|
-
remoteAmplitude:
|
|
413
|
+
remoteAmplitude: c
|
|
383
414
|
});
|
|
384
415
|
}), this.analyzerFrame = requestAnimationFrame(s);
|
|
385
416
|
};
|
|
@@ -389,7 +420,7 @@ class ae {
|
|
|
389
420
|
this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
|
|
390
421
|
}
|
|
391
422
|
}
|
|
392
|
-
class
|
|
423
|
+
class z extends v {
|
|
393
424
|
constructor(e) {
|
|
394
425
|
super();
|
|
395
426
|
r(this, "status");
|
|
@@ -400,6 +431,16 @@ class F extends M {
|
|
|
400
431
|
this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new ae(e), this.webRTCClient.addMessageCallback((s) => {
|
|
401
432
|
const n = JSON.parse(s.data);
|
|
402
433
|
this.notifyPacket(n);
|
|
434
|
+
}), this.webRTCClient.addErrorCallback((s) => {
|
|
435
|
+
var n;
|
|
436
|
+
(n = this.config.logger) == null || n.error("WebRTC error:", s), this.notifyPacket({
|
|
437
|
+
type: "message",
|
|
438
|
+
payload: {
|
|
439
|
+
type: "text",
|
|
440
|
+
role: "assistant",
|
|
441
|
+
text: s
|
|
442
|
+
}
|
|
443
|
+
});
|
|
403
444
|
});
|
|
404
445
|
}
|
|
405
446
|
getName() {
|
|
@@ -460,6 +501,7 @@ class re {
|
|
|
460
501
|
return this.transaction.functionCall;
|
|
461
502
|
}
|
|
462
503
|
async invoke(t) {
|
|
504
|
+
var i;
|
|
463
505
|
const e = this.transaction.functionCall;
|
|
464
506
|
if (!e) {
|
|
465
507
|
await this.fail("No function call found");
|
|
@@ -471,10 +513,12 @@ class re {
|
|
|
471
513
|
return;
|
|
472
514
|
}
|
|
473
515
|
try {
|
|
474
|
-
const i =
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
await this.
|
|
516
|
+
const u = (((i = a.toString().replace(/\n/g, " ").match(/^[^(]*\(([^)]*)\)/)) == null ? void 0 : i[1].split(",").map((g) => g.trim()).filter(Boolean)) || []).map((g) => n[g]);
|
|
517
|
+
console.log(`Invoking tool ${s} with args:`, u);
|
|
518
|
+
const d = await a.apply(null, u);
|
|
519
|
+
await this.complete(d);
|
|
520
|
+
} catch (c) {
|
|
521
|
+
await this.fail(`Error executing tool ${s}: ${c}`);
|
|
478
522
|
}
|
|
479
523
|
}
|
|
480
524
|
async complete(t) {
|
|
@@ -484,7 +528,7 @@ class re {
|
|
|
484
528
|
await this.manager.fail(this.transaction, { success: !1, output: null, error: t });
|
|
485
529
|
}
|
|
486
530
|
}
|
|
487
|
-
class ce extends
|
|
531
|
+
class ce extends v {
|
|
488
532
|
constructor(e) {
|
|
489
533
|
super();
|
|
490
534
|
r(this, "status");
|
|
@@ -526,7 +570,7 @@ class ce extends M {
|
|
|
526
570
|
return this._tools;
|
|
527
571
|
}
|
|
528
572
|
}
|
|
529
|
-
const
|
|
573
|
+
const x = Y(void 0);
|
|
530
574
|
function le(o) {
|
|
531
575
|
return new Promise((t, e) => {
|
|
532
576
|
const s = new FileReader();
|
|
@@ -547,67 +591,67 @@ function ue({
|
|
|
547
591
|
session: a = "new",
|
|
548
592
|
...i
|
|
549
593
|
}) {
|
|
550
|
-
const [
|
|
594
|
+
const [c, u] = E(!1), [d, g] = E([]), [w, R] = E(a), [b, $] = E(/* @__PURE__ */ new Map()), q = G(!1), S = H(() => {
|
|
551
595
|
if (Array.isArray(e))
|
|
552
596
|
return e;
|
|
553
597
|
if (typeof e == "object" && e !== null) {
|
|
554
|
-
const
|
|
555
|
-
let
|
|
556
|
-
switch (
|
|
598
|
+
const l = o ? "localhost:8000" : t || "persona.applica.guru/api", m = o ? "http" : "https", h = o ? "ws" : "wss";
|
|
599
|
+
let f = Object.keys(e).map((y) => {
|
|
600
|
+
switch (y) {
|
|
557
601
|
case "rest":
|
|
558
|
-
const
|
|
559
|
-
return
|
|
560
|
-
apiUrl: `${m}://${
|
|
602
|
+
const p = e[y];
|
|
603
|
+
return p === !0 ? new _({
|
|
604
|
+
apiUrl: `${m}://${l}`,
|
|
561
605
|
apiKey: i.apiKey,
|
|
562
606
|
agentId: i.agentId,
|
|
563
607
|
logger: s
|
|
564
|
-
}) : typeof
|
|
608
|
+
}) : typeof p == "object" && p !== null ? new _(p) : null;
|
|
565
609
|
case "webrtc":
|
|
566
|
-
const C = e[
|
|
567
|
-
return C === !0 ? new
|
|
568
|
-
webrtcUrl: `${h}://${
|
|
610
|
+
const C = e[y];
|
|
611
|
+
return C === !0 ? new z({
|
|
612
|
+
webrtcUrl: `${h}://${l}/webrtc`,
|
|
569
613
|
apiKey: i.apiKey,
|
|
570
614
|
agentId: i.agentId,
|
|
571
615
|
logger: s
|
|
572
|
-
}) : typeof C == "object" && C !== null ? new
|
|
616
|
+
}) : typeof C == "object" && C !== null ? new z(C) : null;
|
|
573
617
|
case "websocket":
|
|
574
|
-
const
|
|
575
|
-
return
|
|
576
|
-
webSocketUrl: `${h}://${
|
|
618
|
+
const T = e[y];
|
|
619
|
+
return T === !0 ? new W({
|
|
620
|
+
webSocketUrl: `${h}://${l}/websocket`,
|
|
577
621
|
apiKey: i.apiKey,
|
|
578
622
|
agentId: i.agentId,
|
|
579
623
|
logger: s
|
|
580
|
-
}) : typeof
|
|
624
|
+
}) : typeof T == "object" && T !== null ? new W(T) : null;
|
|
581
625
|
default:
|
|
582
|
-
throw new Error(`Unknown protocol: ${
|
|
626
|
+
throw new Error(`Unknown protocol: ${y}`);
|
|
583
627
|
}
|
|
584
|
-
}).filter((
|
|
585
|
-
return i.tools &&
|
|
628
|
+
}).filter((y) => y !== null);
|
|
629
|
+
return i.tools && f.push(
|
|
586
630
|
new ce({
|
|
587
|
-
apiUrl: `${m}://${
|
|
631
|
+
apiUrl: `${m}://${l}`,
|
|
588
632
|
apiKey: i.apiKey,
|
|
589
633
|
agentId: i.agentId,
|
|
590
634
|
tools: i.tools,
|
|
591
635
|
// Pass raw tools
|
|
592
636
|
logger: s
|
|
593
637
|
})
|
|
594
|
-
),
|
|
638
|
+
), f;
|
|
595
639
|
}
|
|
596
640
|
throw new Error("Invalid protocols configuration");
|
|
597
641
|
}, []);
|
|
598
642
|
Q(() => {
|
|
599
|
-
|
|
643
|
+
q.current || (q.current = !0, s == null || s.debug(
|
|
600
644
|
"Initializing protocols: ",
|
|
601
|
-
|
|
602
|
-
),
|
|
603
|
-
|
|
604
|
-
s == null || s.debug(`${
|
|
645
|
+
S.map((l) => l.getName())
|
|
646
|
+
), S.forEach((l) => {
|
|
647
|
+
l.setSession(w), l.clearListeners(), l.addStatusChangeListener((m) => {
|
|
648
|
+
s == null || s.debug(`${l.getName()} has notified new status: ${m}`), b.set(l.getName(), m), m === "connected" && (i.context && l.sendPacket({
|
|
605
649
|
type: "command",
|
|
606
650
|
payload: {
|
|
607
651
|
command: "set_initial_context",
|
|
608
652
|
arguments: i.context
|
|
609
653
|
}
|
|
610
|
-
}), i.tools && Array.isArray(i.tools) &&
|
|
654
|
+
}), i.tools && Array.isArray(i.tools) && l.sendPacket({
|
|
611
655
|
type: "command",
|
|
612
656
|
payload: {
|
|
613
657
|
command: "set_local_tools",
|
|
@@ -615,73 +659,73 @@ function ue({
|
|
|
615
659
|
tools: i.tools.map((h) => h.schema)
|
|
616
660
|
}
|
|
617
661
|
}
|
|
618
|
-
})),
|
|
619
|
-
}),
|
|
662
|
+
})), $(new Map(b));
|
|
663
|
+
}), l.addPacketListener((m) => {
|
|
620
664
|
if (m.type === "message") {
|
|
621
665
|
const h = m.payload;
|
|
622
|
-
|
|
623
|
-
(
|
|
666
|
+
g(
|
|
667
|
+
(f) => j([...f, { ...h, protocol: l.getName() }])
|
|
624
668
|
);
|
|
625
669
|
} else if (m.type === "reasoning") {
|
|
626
670
|
const h = m.payload;
|
|
627
|
-
let
|
|
628
|
-
h.imageUrl && (
|
|
671
|
+
let f = h.thought;
|
|
672
|
+
h.imageUrl && (f += `
|
|
629
673
|
|
|
630
674
|
`);
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
(
|
|
675
|
+
const y = { type: "reasoning", text: f, role: "assistant", finishReason: "stop" };
|
|
676
|
+
g(
|
|
677
|
+
(p) => j([...p, { ...y, protocol: l.getName() }])
|
|
634
678
|
);
|
|
635
|
-
} else m.type === "transaction" &&
|
|
636
|
-
}),
|
|
679
|
+
} else m.type === "transaction" && S.filter((h) => h !== l).forEach((h) => h.onTransaction(m.payload));
|
|
680
|
+
}), l.autostart && l.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${l.getName()}`), l.connect(w));
|
|
637
681
|
}));
|
|
638
|
-
}, [
|
|
639
|
-
const
|
|
640
|
-
var
|
|
641
|
-
if (((
|
|
642
|
-
const m =
|
|
643
|
-
|
|
644
|
-
const h =
|
|
645
|
-
if (
|
|
646
|
-
for (const
|
|
647
|
-
|
|
682
|
+
}, [w, S, s, b]);
|
|
683
|
+
const U = async (l) => {
|
|
684
|
+
var y;
|
|
685
|
+
if (((y = l.content[0]) == null ? void 0 : y.type) !== "text") throw new Error("Only text messages are supported");
|
|
686
|
+
const m = l.content[0].text;
|
|
687
|
+
g((p) => [...p, { role: "user", type: "text", text: m }]), u(!0);
|
|
688
|
+
const h = S.sort((p, C) => C.getPriority() - p.getPriority()).find((p) => p.status === "connected"), f = [];
|
|
689
|
+
if (l.attachments)
|
|
690
|
+
for (const p of l.attachments)
|
|
691
|
+
p.contentType.startsWith("image/") && p.file && f.push({
|
|
648
692
|
role: "user",
|
|
649
693
|
image: {
|
|
650
|
-
contentType:
|
|
651
|
-
content: await le(
|
|
694
|
+
contentType: p.contentType,
|
|
695
|
+
content: await le(p.file)
|
|
652
696
|
},
|
|
653
697
|
text: "",
|
|
654
698
|
type: "text"
|
|
655
699
|
});
|
|
656
|
-
|
|
700
|
+
l.content && f.push({
|
|
657
701
|
role: "user",
|
|
658
|
-
text:
|
|
702
|
+
text: l.content[0].text,
|
|
659
703
|
type: "text"
|
|
660
|
-
}), s == null || s.debug("Sending message:",
|
|
661
|
-
}, D = N(() => (u(!1),
|
|
662
|
-
isRunning:
|
|
663
|
-
messages:
|
|
704
|
+
}), s == null || s.debug("Sending message:", f), await (h == null ? void 0 : h.sendPacket({ type: "request", payload: f })), u(!1);
|
|
705
|
+
}, D = N(() => (u(!1), g([]), R("new"), Promise.resolve()), []), L = N(() => Promise.resolve(), []), J = N(() => d, [d]), K = X({
|
|
706
|
+
isRunning: c,
|
|
707
|
+
messages: d,
|
|
664
708
|
convertMessage: oe,
|
|
665
|
-
onNew:
|
|
709
|
+
onNew: U,
|
|
666
710
|
onCancel: D,
|
|
667
711
|
onReload: L,
|
|
668
712
|
adapters: {
|
|
669
713
|
attachments: new Z([new ee()])
|
|
670
714
|
}
|
|
671
715
|
});
|
|
672
|
-
return /* @__PURE__ */
|
|
716
|
+
return /* @__PURE__ */ M.jsx(x.Provider, { value: { protocols: S, protocolsStatus: b, getMessages: J }, children: /* @__PURE__ */ M.jsx(te, { runtime: K, children: n }) });
|
|
673
717
|
}
|
|
674
718
|
function ge({ children: o, ...t }) {
|
|
675
|
-
return /* @__PURE__ */
|
|
719
|
+
return /* @__PURE__ */ M.jsx(ue, { ...t, children: o });
|
|
676
720
|
}
|
|
677
721
|
function we() {
|
|
678
|
-
const o =
|
|
722
|
+
const o = A(x);
|
|
679
723
|
if (!o)
|
|
680
724
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
681
725
|
return o;
|
|
682
726
|
}
|
|
683
727
|
function he(o) {
|
|
684
|
-
const t =
|
|
728
|
+
const t = A(x);
|
|
685
729
|
if (!t)
|
|
686
730
|
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
687
731
|
const e = t.protocols.find((n) => n.getName() === o);
|
|
@@ -702,7 +746,7 @@ function he(o) {
|
|
|
702
746
|
};
|
|
703
747
|
}
|
|
704
748
|
function be() {
|
|
705
|
-
const o =
|
|
749
|
+
const o = A(x);
|
|
706
750
|
if (!o)
|
|
707
751
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
708
752
|
for (const t of o.protocols)
|
|
@@ -714,7 +758,7 @@ function Se() {
|
|
|
714
758
|
return he("webrtc");
|
|
715
759
|
}
|
|
716
760
|
function Ce() {
|
|
717
|
-
const o =
|
|
761
|
+
const o = A(x);
|
|
718
762
|
if (!o)
|
|
719
763
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
720
764
|
return o.getMessages();
|
|
@@ -768,13 +812,13 @@ function de(o) {
|
|
|
768
812
|
}
|
|
769
813
|
};
|
|
770
814
|
}
|
|
771
|
-
function
|
|
815
|
+
function I(o) {
|
|
772
816
|
return {
|
|
773
817
|
schema: de(o),
|
|
774
818
|
implementation: o.implementation
|
|
775
819
|
};
|
|
776
820
|
}
|
|
777
|
-
function
|
|
821
|
+
function pe(o, t, e, s, n, a) {
|
|
778
822
|
const i = {
|
|
779
823
|
name: o,
|
|
780
824
|
description: t,
|
|
@@ -784,9 +828,9 @@ function me(o, t, e, s, n, a) {
|
|
|
784
828
|
output: n,
|
|
785
829
|
implementation: e
|
|
786
830
|
};
|
|
787
|
-
return
|
|
831
|
+
return I(i);
|
|
788
832
|
}
|
|
789
|
-
const
|
|
833
|
+
const ke = pe(
|
|
790
834
|
"sum",
|
|
791
835
|
"Sum two numbers",
|
|
792
836
|
function(t, e) {
|
|
@@ -799,7 +843,7 @@ const xe = me(
|
|
|
799
843
|
{
|
|
800
844
|
result: P("number", "Sum of two numbers")
|
|
801
845
|
}
|
|
802
|
-
),
|
|
846
|
+
), xe = I({
|
|
803
847
|
name: "navigate_to",
|
|
804
848
|
description: "Allow agent to redirect user to specific sub page like /foo or #/foo or anything like that",
|
|
805
849
|
title: "Sum two numbers",
|
|
@@ -820,7 +864,7 @@ const xe = me(
|
|
|
820
864
|
function Re(o) {
|
|
821
865
|
const t = [], e = {};
|
|
822
866
|
return o.forEach((s) => {
|
|
823
|
-
const { schema: n, implementation: a } =
|
|
867
|
+
const { schema: n, implementation: a } = I(s);
|
|
824
868
|
t.push(n), e[s.name] = a;
|
|
825
869
|
}), { schemas: t, implementations: e };
|
|
826
870
|
}
|
|
@@ -844,19 +888,19 @@ function Te(o, t) {
|
|
|
844
888
|
}
|
|
845
889
|
export {
|
|
846
890
|
Pe as PersonaConsoleLogger,
|
|
847
|
-
|
|
891
|
+
v as PersonaProtocolBase,
|
|
848
892
|
_ as PersonaRESTProtocol,
|
|
849
893
|
ge as PersonaRuntimeProvider,
|
|
850
894
|
ce as PersonaTransactionProtocol,
|
|
851
|
-
|
|
852
|
-
|
|
895
|
+
z as PersonaWebRTCProtocol,
|
|
896
|
+
W as PersonaWebSocketProtocol,
|
|
853
897
|
P as createParameter,
|
|
854
|
-
|
|
855
|
-
|
|
898
|
+
I as createTool,
|
|
899
|
+
pe as createToolFromFunction,
|
|
856
900
|
Re as createToolRegistry,
|
|
857
901
|
de as generateToolSchema,
|
|
858
|
-
|
|
859
|
-
|
|
902
|
+
xe as navigateToToolExample,
|
|
903
|
+
ke as sumTool,
|
|
860
904
|
we as usePersonaRuntime,
|
|
861
905
|
be as usePersonaRuntimeEndpoint,
|
|
862
906
|
Ce as usePersonaRuntimeMessages,
|