@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.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 $, useState as v, useRef as G, useMemo as H, useEffect as Q, useCallback as N } from "react";
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 U = { exports: {} }, k = {};
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 q;
16
+ var O;
17
17
  function se() {
18
- if (q) return k;
19
- q = 1;
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 l in n)
26
- l !== "key" && (a[l] = n[l]);
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
- U.exports = se();
39
- var I = U.exports;
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 O(o) {
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 M {
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 M {
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 w, S, T, b, A, x;
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" && ((w = e == null ? void 0 : e.payload) == null ? void 0 : w.command) == "set_initial_context") {
153
- this.context = (S = e == null ? void 0 : e.payload) == null ? void 0 : S.arguments;
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" && ((T = e == null ? void 0 : e.payload) == null ? void 0 : T.command) == "set_local_tools") {
156
- const p = (b = e == null ? void 0 : e.payload) == null ? void 0 : b.arguments;
157
- this.tools = p == null ? void 0 : p.tools, (x = (A = this.config) == null ? void 0 : A.logger) == null || x.warn("Local tools are not supported in REST protocol, ignoring command");
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 l = e.payload, f = await (await fetch(`${s}/sessions/${i}/messages`, {
161
- body: JSON.stringify({ agentId: a, userMessage: l, initialContext: this.context, tools: this.tools }),
162
- method: "POST",
163
- headers: {
164
- "Content-Type": "application/json",
165
- "x-persona-apikey": n
166
- }
167
- })).json();
168
- this.notifyPackets(
169
- f.response.messages.map((p) => ({
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: p
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 z extends M {
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 l;
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
- (l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", s);
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 f = JSON.parse(u.data);
207
- this.notifyPacket(f);
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.warn("WebSocket connection closed");
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 l;
272
- (l = this.config.logger) == null || l.error("Error playing remote audio:", i);
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((l) => {
287
- l(i);
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 l = this.queuedMessages.shift();
293
- l && (a.send(JSON.stringify(l)), (i = this.config.logger) == null || i.info("Sent queued message:", l));
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 l, u;
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
- (l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", a);
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 (l) {
330
- (i = this.config.logger) == null || i.error("Error adding ICE candidate:", l);
355
+ } catch (c) {
356
+ (i = this.config.logger) == null || i.error("Error adding ICE candidate:", c);
331
357
  }
332
- }, this.ws.onclose = () => {
333
- this._stopAnalyzers();
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, f) => u + f, 0) / n.length, l = a.reduce((u, f) => u + f, 0) / a.length;
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: l
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 F extends M {
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 = await a.apply(null, Object.values(n));
475
- await this.complete(i);
476
- } catch (i) {
477
- await this.fail(`Error executing tool ${s}: ${i}`);
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 M {
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 R = Y(void 0);
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 [l, u] = v(!1), [f, w] = v([]), [S, T] = v(a), [b, A] = v(/* @__PURE__ */ new Map()), x = G(!1), p = H(() => {
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 c = o ? "localhost:8000" : t || "persona.applica.guru/api", m = o ? "http" : "https", h = o ? "ws" : "wss";
555
- let y = Object.keys(e).map((g) => {
556
- switch (g) {
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 d = e[g];
559
- return d === !0 ? new _({
560
- apiUrl: `${m}://${c}`,
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 d == "object" && d !== null ? new _(d) : null;
608
+ }) : typeof p == "object" && p !== null ? new _(p) : null;
565
609
  case "webrtc":
566
- const C = e[g];
567
- return C === !0 ? new F({
568
- webrtcUrl: `${h}://${c}/webrtc`,
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 F(C) : null;
616
+ }) : typeof C == "object" && C !== null ? new z(C) : null;
573
617
  case "websocket":
574
- const E = e[g];
575
- return E === !0 ? new z({
576
- webSocketUrl: `${h}://${c}/websocket`,
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 E == "object" && E !== null ? new z(E) : null;
624
+ }) : typeof T == "object" && T !== null ? new W(T) : null;
581
625
  default:
582
- throw new Error(`Unknown protocol: ${g}`);
626
+ throw new Error(`Unknown protocol: ${y}`);
583
627
  }
584
- }).filter((g) => g !== null);
585
- return i.tools && y.push(
628
+ }).filter((y) => y !== null);
629
+ return i.tools && f.push(
586
630
  new ce({
587
- apiUrl: `${m}://${c}`,
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
- ), y;
638
+ ), f;
595
639
  }
596
640
  throw new Error("Invalid protocols configuration");
597
641
  }, []);
598
642
  Q(() => {
599
- x.current || (x.current = !0, s == null || s.debug(
643
+ q.current || (q.current = !0, s == null || s.debug(
600
644
  "Initializing protocols: ",
601
- p.map((c) => c.getName())
602
- ), p.forEach((c) => {
603
- c.setSession(S), c.clearListeners(), c.addStatusChangeListener((m) => {
604
- s == null || s.debug(`${c.getName()} has notified new status: ${m}`), b.set(c.getName(), m), m === "connected" && (i.context && c.sendPacket({
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) && c.sendPacket({
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
- })), A(new Map(b));
619
- }), c.addPacketListener((m) => {
662
+ })), $(new Map(b));
663
+ }), l.addPacketListener((m) => {
620
664
  if (m.type === "message") {
621
665
  const h = m.payload;
622
- w(
623
- (y) => O([...y, { ...h, protocol: c.getName() }])
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 y = h.thought;
628
- h.imageUrl && (y += `
671
+ let f = h.thought;
672
+ h.imageUrl && (f += `
629
673
 
630
674
  ![image](https://persona.applica.guru/api/files/${h.imageUrl})`);
631
- const g = { type: "reasoning", text: y, role: "assistant", finishReason: "stop" };
632
- w(
633
- (d) => O([...d, { ...g, protocol: c.getName() }])
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" && p.filter((h) => h !== c).forEach((h) => h.onTransaction(m.payload));
636
- }), c.autostart && c.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${c.getName()}`), c.connect(S));
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
- }, [S, p, s, b]);
639
- const W = async (c) => {
640
- var g;
641
- if (((g = c.content[0]) == null ? void 0 : g.type) !== "text") throw new Error("Only text messages are supported");
642
- const m = c.content[0].text;
643
- w((d) => [...d, { role: "user", type: "text", text: m }]), u(!0);
644
- const h = p.sort((d, C) => C.getPriority() - d.getPriority()).find((d) => d.status === "connected"), y = [];
645
- if (c.attachments)
646
- for (const d of c.attachments)
647
- d.contentType.startsWith("image/") && d.file && y.push({
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: d.contentType,
651
- content: await le(d.file)
694
+ contentType: p.contentType,
695
+ content: await le(p.file)
652
696
  },
653
697
  text: "",
654
698
  type: "text"
655
699
  });
656
- c.content && y.push({
700
+ l.content && f.push({
657
701
  role: "user",
658
- text: c.content[0].text,
702
+ text: l.content[0].text,
659
703
  type: "text"
660
- }), s == null || s.debug("Sending message:", y), await (h == null ? void 0 : h.sendPacket({ type: "request", payload: y })), u(!1);
661
- }, D = N(() => (u(!1), w([]), T("new"), Promise.resolve()), []), L = N(() => Promise.resolve(), []), J = N(() => f, [f]), K = X({
662
- isRunning: l,
663
- messages: f,
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: W,
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__ */ I.jsx(R.Provider, { value: { protocols: p, protocolsStatus: b, getMessages: J }, children: /* @__PURE__ */ I.jsx(te, { runtime: K, children: n }) });
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__ */ I.jsx(ue, { ...t, children: o });
719
+ return /* @__PURE__ */ M.jsx(ue, { ...t, children: o });
676
720
  }
677
721
  function we() {
678
- const o = $(R);
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 = $(R);
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 = $(R);
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 = $(R);
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 j(o) {
815
+ function I(o) {
772
816
  return {
773
817
  schema: de(o),
774
818
  implementation: o.implementation
775
819
  };
776
820
  }
777
- function me(o, t, e, s, n, a) {
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 j(i);
831
+ return I(i);
788
832
  }
789
- const xe = me(
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
- ), ke = j({
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 } = j(s);
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
- M as PersonaProtocolBase,
891
+ v as PersonaProtocolBase,
848
892
  _ as PersonaRESTProtocol,
849
893
  ge as PersonaRuntimeProvider,
850
894
  ce as PersonaTransactionProtocol,
851
- F as PersonaWebRTCProtocol,
852
- z as PersonaWebSocketProtocol,
895
+ z as PersonaWebRTCProtocol,
896
+ W as PersonaWebSocketProtocol,
853
897
  P as createParameter,
854
- j as createTool,
855
- me as createToolFromFunction,
898
+ I as createTool,
899
+ pe as createToolFromFunction,
856
900
  Re as createToolRegistry,
857
901
  de as generateToolSchema,
858
- ke as navigateToToolExample,
859
- xe as sumTool,
902
+ xe as navigateToToolExample,
903
+ ke as sumTool,
860
904
  we as usePersonaRuntime,
861
905
  be as usePersonaRuntimeEndpoint,
862
906
  Ce as usePersonaRuntimeMessages,