@applica-software-guru/persona-sdk 0.1.57 → 0.1.59

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,8 +1,8 @@
1
- var J = Object.defineProperty;
2
- var K = (a, t, e) => t in a ? J(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var o = (a, t, e) => K(a, typeof t != "symbol" ? t + "" : t, e);
4
- import { createContext as q, useContext as E, useState as P, useRef as _, useMemo as B, useEffect as Y, useCallback as v } from "react";
5
- import { useExternalStoreRuntime as G, CompositeAttachmentAdapter as V, SimpleImageAttachmentAdapter as H, AssistantRuntimeProvider as Q } from "@assistant-ui/react";
1
+ var K = Object.defineProperty;
2
+ var q = (i, t, e) => t in i ? K(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var o = (i, t, e) => q(i, typeof t != "symbol" ? t + "" : t, e);
4
+ import { createContext as _, useContext as R, useState as x, useRef as B, useMemo as Y, useEffect as G, useCallback as E } from "react";
5
+ import { useExternalStoreRuntime as V, CompositeAttachmentAdapter as H, SimpleImageAttachmentAdapter as Q, AssistantRuntimeProvider as X } from "@assistant-ui/react";
6
6
  var D = { exports: {} }, C = {};
7
7
  /**
8
8
  * @license React
@@ -13,78 +13,78 @@ var D = { exports: {} }, C = {};
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 $;
17
- function X() {
18
- if ($) return C;
19
- $ = 1;
20
- var a = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
- function e(n, s, i) {
16
+ var M;
17
+ function Z() {
18
+ if (M) return C;
19
+ M = 1;
20
+ var i = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
+ function e(n, s, a) {
22
22
  var c = null;
23
- if (i !== void 0 && (c = "" + i), s.key !== void 0 && (c = "" + s.key), "key" in s) {
24
- i = {};
23
+ if (a !== void 0 && (c = "" + a), s.key !== void 0 && (c = "" + s.key), "key" in s) {
24
+ a = {};
25
25
  for (var l in s)
26
- l !== "key" && (i[l] = s[l]);
27
- } else i = s;
28
- return s = i.ref, {
29
- $$typeof: a,
26
+ l !== "key" && (a[l] = s[l]);
27
+ } else a = s;
28
+ return s = a.ref, {
29
+ $$typeof: i,
30
30
  type: n,
31
31
  key: c,
32
32
  ref: s !== void 0 ? s : null,
33
- props: i
33
+ props: a
34
34
  };
35
35
  }
36
36
  return C.Fragment = t, C.jsx = e, C.jsxs = e, C;
37
37
  }
38
- D.exports = X();
39
- var A = D.exports;
40
- function Z(a) {
41
- return a.filter((t) => {
38
+ D.exports = Z();
39
+ var T = D.exports;
40
+ function ee(i) {
41
+ return i.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 M(a) {
46
+ function $(i) {
47
47
  const t = [];
48
48
  let e = null;
49
- for (const s of a)
49
+ for (const s of i)
50
50
  s.type !== "transaction" && (s.type === "reasoning" ? (e != null && (t.push(e), e = null), t.push(s)) : s.functionCalls ? (e && t.push(e), t.push(s), e = null) : s.functionResponse ? t[t.length - 1] = {
51
51
  ...t[t.length - 1],
52
52
  functionResponse: s.functionResponse
53
53
  } : e && s.protocol === e.protocol && (e.role === s.role || s.finishReason === "stop") ? (e.text += s.text, e.files = [...e.files ?? [], ...s.files ?? []]) : (e && t.push(e), e = {
54
54
  ...s
55
55
  }));
56
- return e && t.push(e), Z(t);
56
+ return e && t.push(e), ee(t);
57
57
  }
58
- function ee(a) {
58
+ function te(i) {
59
59
  var e, n;
60
- const t = ((e = a.files) == null ? void 0 : e.map(
60
+ const t = ((e = i.files) == null ? void 0 : e.map(
61
61
  (s) => ({
62
62
  type: "file",
63
63
  data: s.url,
64
64
  mimeType: s.contentType
65
65
  })
66
66
  )) ?? [];
67
- return a.role === "function" ? {
68
- id: a.id,
67
+ return i.role === "function" ? {
68
+ id: i.id,
69
69
  role: "assistant",
70
- status: (a == null ? void 0 : a.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
71
- content: ((n = a.functionCalls) == null ? void 0 : n.map((s) => {
72
- var i;
70
+ status: (i == null ? void 0 : i.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
71
+ content: ((n = i.functionCalls) == null ? void 0 : n.map((s) => {
72
+ var a;
73
73
  return {
74
74
  type: "tool-call",
75
75
  toolName: s.name,
76
76
  toolCallId: s.id,
77
77
  args: s.args,
78
- result: (i = a.functionResponse) == null ? void 0 : i.result
78
+ result: (a = i.functionResponse) == null ? void 0 : a.result
79
79
  };
80
80
  })) ?? []
81
81
  } : {
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]
82
+ id: i.id,
83
+ role: i.role,
84
+ content: i.type === "reasoning" ? [{ type: "reasoning", text: i.text }, ...t] : [{ type: "text", text: i.text }, ...t]
85
85
  };
86
86
  }
87
- class x {
87
+ class A {
88
88
  constructor() {
89
89
  o(this, "statusChangeCallbacks", []);
90
90
  o(this, "messageCallbacks", []);
@@ -119,7 +119,7 @@ class x {
119
119
  onTransaction(t) {
120
120
  }
121
121
  }
122
- class N extends x {
122
+ class N extends A {
123
123
  constructor(e) {
124
124
  super();
125
125
  o(this, "status");
@@ -145,7 +145,7 @@ class N extends x {
145
145
  this.session = e;
146
146
  }
147
147
  async send(e) {
148
- const { apiUrl: n, apiKey: s, agentId: i } = this.config, c = this.session ?? "new", l = e, h = await (await fetch(`${n}/agents/${i}/sessions/${c}/messages`, {
148
+ const { apiUrl: n, apiKey: s, agentId: a } = this.config, c = this.session ?? "new", l = e, f = await (await fetch(`${n}/agents/${a}/sessions/${c}/messages`, {
149
149
  body: JSON.stringify({ userMessage: l }),
150
150
  method: "POST",
151
151
  headers: {
@@ -155,14 +155,14 @@ class N extends x {
155
155
  }
156
156
  })).json();
157
157
  this.notifyMessages(
158
- h.response.messages.map((b) => ({
158
+ f.response.messages.map((b) => ({
159
159
  type: "message",
160
160
  payload: b
161
161
  }))
162
162
  );
163
163
  }
164
164
  }
165
- class I extends x {
165
+ class I extends A {
166
166
  constructor(e) {
167
167
  super();
168
168
  o(this, "status");
@@ -188,18 +188,18 @@ class I extends x {
188
188
  return Promise.resolve(this.session);
189
189
  const n = e || this.session || "new";
190
190
  (l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", n);
191
- const s = encodeURIComponent(this.config.apiKey), i = this.config.agentId, c = `${this.config.webSocketUrl}?sessionCode=${n}&agentId=${i}&apiKey=${s}`;
191
+ const s = encodeURIComponent(this.config.apiKey), a = this.config.agentId, c = `${this.config.webSocketUrl}?sessionCode=${n}&agentId=${a}&apiKey=${s}`;
192
192
  return this.setStatus("connecting"), this.webSocket = new WebSocket(c), this.webSocket.addEventListener("open", () => {
193
193
  this.setStatus("connected");
194
194
  }), this.webSocket.addEventListener("message", (u) => {
195
- const h = JSON.parse(u.data);
196
- this.notifyMessage(h);
195
+ const f = JSON.parse(u.data);
196
+ this.notifyMessage(f);
197
197
  }), this.webSocket.addEventListener("close", () => {
198
198
  var u;
199
199
  this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.warn("WebSocket connection closed");
200
200
  }), this.webSocket.addEventListener("error", (u) => {
201
- var h;
202
- this.setStatus("disconnected"), this.webSocket = null, (h = this.config.logger) == null || h.error("WebSocket error", u);
201
+ var f;
202
+ this.setStatus("disconnected"), this.webSocket = null, (f = this.config.logger) == null || f.error("WebSocket error", u);
203
203
  }), Promise.resolve(n);
204
204
  }
205
205
  disconnect() {
@@ -210,7 +210,7 @@ class I extends x {
210
210
  return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify({ type: "request", payload: e })), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
211
211
  }
212
212
  }
213
- class te {
213
+ class se {
214
214
  constructor(t) {
215
215
  o(this, "config");
216
216
  o(this, "pc", null);
@@ -254,14 +254,14 @@ class te {
254
254
  s.streams[0].getTracks().forEach((c) => {
255
255
  this.remoteStream.addTrack(c);
256
256
  }), this.audioCtx || this._startAnalyzers();
257
- const i = new Audio();
258
- i.srcObject = this.remoteStream, i.play().catch((c) => {
257
+ const a = new Audio();
258
+ a.srcObject = this.remoteStream, a.play().catch((c) => {
259
259
  var l;
260
260
  (l = this.config.logger) == null || l.error("Error playing remote audio:", c);
261
261
  });
262
262
  }, this.pc.onicecandidate = (s) => {
263
- var i;
264
- s.candidate && ((i = this.ws) == null ? void 0 : i.readyState) === WebSocket.OPEN && this.ws.send(
263
+ var a;
264
+ s.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
265
265
  JSON.stringify({
266
266
  type: "CANDIDATE",
267
267
  src: "client",
@@ -269,8 +269,8 @@ class te {
269
269
  })
270
270
  );
271
271
  }, this.pc.ondatachannel = (s) => {
272
- const i = s.channel;
273
- i.onmessage = (c) => {
272
+ const a = s.channel;
273
+ a.onmessage = (c) => {
274
274
  this.messageCallbacks.forEach((l) => {
275
275
  l(c);
276
276
  });
@@ -281,12 +281,12 @@ class te {
281
281
  var l, u;
282
282
  const s = await this.pc.createOffer();
283
283
  await this.pc.setLocalDescription(s);
284
- const i = {
284
+ const a = {
285
285
  apiKey: this.config.apiKey,
286
286
  agentId: this.config.agentId,
287
287
  sessionCode: t
288
288
  };
289
- (l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", i);
289
+ (l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", a);
290
290
  const c = {
291
291
  type: "OFFER",
292
292
  src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
@@ -296,18 +296,18 @@ class te {
296
296
  type: s.type
297
297
  },
298
298
  connectionId: (Date.now() % 1e6).toString(),
299
- metadata: i
299
+ metadata: a
300
300
  }
301
301
  };
302
302
  this.ws.send(JSON.stringify(c));
303
303
  }, this.ws.onmessage = async (s) => {
304
304
  var c;
305
- const i = JSON.parse(s.data);
306
- if (i.type === "ANSWER")
307
- await this.pc.setRemoteDescription(new RTCSessionDescription(i.payload.sdp));
308
- else if (i.type === "CANDIDATE")
305
+ const a = JSON.parse(s.data);
306
+ if (a.type === "ANSWER")
307
+ await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
308
+ else if (a.type === "CANDIDATE")
309
309
  try {
310
- await this.pc.addIceCandidate(new RTCIceCandidate(i.payload.candidate));
310
+ await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
311
311
  } catch (l) {
312
312
  (c = this.config.logger) == null || c.error("Error adding ICE candidate:", l);
313
313
  }
@@ -352,9 +352,9 @@ class te {
352
352
  const n = () => {
353
353
  if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
354
354
  return;
355
- const s = new Uint8Array(this.localAnalyser.frequencyBinCount), i = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
356
- this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(i);
357
- const c = s.reduce((u, h) => u + h, 0) / s.length, l = i.reduce((u, h) => u + h, 0) / i.length;
355
+ const s = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
356
+ this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(a);
357
+ const c = s.reduce((u, f) => u + f, 0) / s.length, l = a.reduce((u, f) => u + f, 0) / a.length;
358
358
  this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
359
359
  u({
360
360
  localAmplitude: c,
@@ -368,7 +368,7 @@ class te {
368
368
  this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
369
369
  }
370
370
  }
371
- class z extends x {
371
+ class z extends A {
372
372
  constructor(e) {
373
373
  super();
374
374
  o(this, "status");
@@ -376,7 +376,7 @@ class z extends x {
376
376
  o(this, "autostart");
377
377
  o(this, "config");
378
378
  o(this, "webRTCClient");
379
- this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new te(e), this.webRTCClient.addMessageCallback((n) => {
379
+ this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new se(e), this.webRTCClient.addMessageCallback((n) => {
380
380
  const s = JSON.parse(n.data);
381
381
  this.notifyMessage(s);
382
382
  });
@@ -404,7 +404,7 @@ class z extends x {
404
404
  return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendMessage(e), Promise.resolve());
405
405
  }
406
406
  }
407
- class se {
407
+ class ne {
408
408
  constructor(t) {
409
409
  o(this, "config");
410
410
  this.config = t;
@@ -429,7 +429,7 @@ class se {
429
429
  });
430
430
  }
431
431
  }
432
- class ne {
432
+ class ie {
433
433
  constructor(t, e) {
434
434
  o(this, "transaction");
435
435
  o(this, "manager");
@@ -444,13 +444,13 @@ class ne {
444
444
  await this.fail("No function call found");
445
445
  return;
446
446
  }
447
- const n = e.name, s = e.args, i = t[n];
448
- if (!i) {
447
+ const n = e.name, s = e.args, a = t[n];
448
+ if (!a) {
449
449
  await this.fail(`Tool ${n} not found`);
450
450
  return;
451
451
  }
452
452
  try {
453
- const c = await i(s);
453
+ const c = await a(s);
454
454
  await this.complete(c);
455
455
  } catch (c) {
456
456
  await this.fail(`Error executing tool ${n}: ${c}`);
@@ -463,7 +463,7 @@ class ne {
463
463
  await this.manager.fail(this.transaction, { success: !1, output: null, error: t });
464
464
  }
465
465
  }
466
- class ie extends x {
466
+ class ae extends A {
467
467
  constructor(e) {
468
468
  super();
469
469
  o(this, "status");
@@ -493,155 +493,160 @@ class ie extends x {
493
493
  throw (n = this.config.logger) == null || n.debug("Sending message:", e), new Error("Not implemented");
494
494
  }
495
495
  onTransaction(e) {
496
- var i;
496
+ var a;
497
497
  if (!this.config.onTransaction) {
498
- (i = this.config.logger) == null || i.error("Transaction protocol config is not set");
498
+ (a = this.config.logger) == null || a.error("Transaction protocol config is not set");
499
499
  return;
500
500
  }
501
- const n = new se(this.config), s = new ne(e, n);
501
+ const n = new ne(this.config), s = new ie(e, n);
502
502
  this.config.onTransaction(s);
503
503
  }
504
504
  }
505
- const R = q(void 0);
506
- function ae(a) {
505
+ const S = _(void 0);
506
+ function oe(i) {
507
507
  return new Promise((t, e) => {
508
508
  const n = new FileReader();
509
- n.readAsDataURL(a), n.onload = () => {
510
- const i = n.result.split(";base64,")[1];
511
- t(i);
509
+ n.readAsDataURL(i), n.onload = () => {
510
+ const a = n.result.split(";base64,")[1];
511
+ t(a);
512
512
  }, n.onerror = (s) => {
513
513
  e(s);
514
514
  };
515
515
  });
516
516
  }
517
- function oe({
518
- dev: a = !1,
517
+ function re({
518
+ dev: i = !1,
519
519
  protocols: t,
520
520
  logger: e,
521
521
  children: n,
522
522
  session: s = "new",
523
- ...i
523
+ ...a
524
524
  }) {
525
- const [c, l] = P(!1), [u, h] = P([]), [b, W] = P(s), [S, j] = P(/* @__PURE__ */ new Map()), T = _(!1), m = B(() => {
525
+ const [c, l] = x(!1), [u, f] = x([]), [b, U] = x(s), [P, W] = x(/* @__PURE__ */ new Map()), v = B(!1), m = Y(() => {
526
526
  if (Array.isArray(t))
527
527
  return t;
528
528
  if (typeof t == "object" && t !== null) {
529
- const r = a ? "localhost:8000" : "persona.applica.guru/api", f = a ? "http" : "https", y = a ? "ws" : "wss";
530
- let g = Object.keys(t).map((p) => {
531
- switch (p) {
529
+ const r = i ? "localhost:8000" : "persona.applica.guru/api", p = i ? "http" : "https", d = i ? "ws" : "wss";
530
+ let y = Object.keys(t).map((g) => {
531
+ switch (g) {
532
532
  case "rest":
533
- const d = t[p];
534
- return d === !0 ? new N({
535
- apiUrl: `${f}://${r}`,
536
- apiKey: i.apiKey,
537
- agentId: i.agentId,
533
+ const h = t[g];
534
+ return h === !0 ? new N({
535
+ apiUrl: `${p}://${r}`,
536
+ apiKey: a.apiKey,
537
+ agentId: a.agentId,
538
538
  logger: e
539
- }) : typeof d == "object" && d !== null ? new N(d) : null;
539
+ }) : typeof h == "object" && h !== null ? new N(h) : null;
540
540
  case "webrtc":
541
- const w = t[p];
541
+ const w = t[g];
542
542
  return w === !0 ? new z({
543
- webrtcUrl: `${y}://${r}/webrtc`,
544
- apiKey: i.apiKey,
545
- agentId: i.agentId,
543
+ webrtcUrl: `${d}://${r}/webrtc`,
544
+ apiKey: a.apiKey,
545
+ agentId: a.agentId,
546
546
  logger: e
547
547
  }) : typeof w == "object" && w !== null ? new z(w) : null;
548
548
  case "websocket":
549
- const k = t[p];
549
+ const k = t[g];
550
550
  return k === !0 ? new I({
551
- webSocketUrl: `${y}://${r}/websocket`,
552
- apiKey: i.apiKey,
553
- agentId: i.agentId,
551
+ webSocketUrl: `${d}://${r}/websocket`,
552
+ apiKey: a.apiKey,
553
+ agentId: a.agentId,
554
554
  logger: e
555
555
  }) : typeof k == "object" && k !== null ? new I(k) : null;
556
556
  default:
557
- throw new Error(`Unknown protocol: ${p}`);
557
+ throw new Error(`Unknown protocol: ${g}`);
558
558
  }
559
- }).filter((p) => p !== null);
560
- return i.tools && g.push(
561
- new ie({
562
- apiUrl: `${f}://${r}`,
563
- apiKey: i.apiKey,
564
- agentId: i.agentId,
565
- onTransaction: async (p) => {
566
- await p.invoke(i.tools);
559
+ }).filter((g) => g !== null);
560
+ return a.tools && y.push(
561
+ new ae({
562
+ apiUrl: `${p}://${r}`,
563
+ apiKey: a.apiKey,
564
+ agentId: a.agentId,
565
+ onTransaction: async (g) => {
566
+ await g.invoke(a.tools);
567
567
  },
568
568
  logger: e
569
569
  })
570
- ), g;
570
+ ), y;
571
571
  }
572
572
  throw new Error("Invalid protocols configuration");
573
573
  }, []);
574
- Y(() => {
575
- T.current || (T.current = !0, e == null || e.debug(
574
+ G(() => {
575
+ v.current || (v.current = !0, e == null || e.debug(
576
576
  "Initializing protocols: ",
577
577
  m.map((r) => r.getName())
578
578
  ), m.forEach((r) => {
579
- r.setSession(b), r.clearListeners(), r.addStatusChangeListener((f) => {
580
- e == null || e.debug(`${r.getName()} has notified new status: ${f}`), S.set(r.getName(), f), j(new Map(S));
581
- }), r.addMessageListener((f) => {
582
- if (f.type === "message") {
583
- const y = f.payload;
584
- h(
585
- (g) => M([...g, { ...y, protocol: r.getName() }])
579
+ r.setSession(b), r.clearListeners(), r.addStatusChangeListener((p) => {
580
+ e == null || e.debug(`${r.getName()} has notified new status: ${p}`), P.set(r.getName(), p), W(new Map(P));
581
+ }), r.addMessageListener((p) => {
582
+ if (p.type === "message") {
583
+ const d = p.payload;
584
+ f(
585
+ (y) => $([...y, { ...d, protocol: r.getName() }])
586
586
  );
587
- } else if (f.type === "reasoning") {
588
- const g = { type: "reasoning", text: f.payload.thought, role: "assistant", finishReason: "stop" };
589
- h(
590
- (p) => M([...p, { ...g, protocol: r.getName() }])
587
+ } else if (p.type === "reasoning") {
588
+ const d = p.payload;
589
+ let y = d.thought;
590
+ d.imageUrl && (y += `
591
+
592
+ ![image](https://persona.applica.guru/api/files/${d.imageUrl})`);
593
+ const g = { type: "reasoning", text: y, role: "assistant", finishReason: "stop" };
594
+ f(
595
+ (h) => $([...h, { ...g, protocol: r.getName() }])
591
596
  );
592
- } else f.type === "transaction" && m.filter((y) => y !== r).forEach((y) => y.onTransaction(f.payload));
597
+ } else p.type === "transaction" && m.filter((d) => d !== r).forEach((d) => d.onTransaction(p.payload));
593
598
  }), r.autostart && r.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${r.getName()}`), r.connect(b));
594
599
  }));
595
- }, [b, m, e, S]);
596
- const O = async (r) => {
597
- var p;
598
- if (((p = r.content[0]) == null ? void 0 : p.type) !== "text") throw new Error("Only text messages are supported");
599
- const f = r.content[0].text;
600
- h((d) => [...d, { role: "user", type: "text", text: f }]), l(!0);
601
- const y = m.sort((d, w) => w.getPriority() - d.getPriority()).find((d) => d.status === "connected"), g = [];
600
+ }, [b, m, e, P]);
601
+ const j = async (r) => {
602
+ var g;
603
+ if (((g = r.content[0]) == null ? void 0 : g.type) !== "text") throw new Error("Only text messages are supported");
604
+ const p = r.content[0].text;
605
+ f((h) => [...h, { role: "user", type: "text", text: p }]), l(!0);
606
+ const d = m.sort((h, w) => w.getPriority() - h.getPriority()).find((h) => h.status === "connected"), y = [];
602
607
  if (r.attachments)
603
- for (const d of r.attachments)
604
- d.contentType.startsWith("image/") && d.file && g.push({
608
+ for (const h of r.attachments)
609
+ h.contentType.startsWith("image/") && h.file && y.push({
605
610
  role: "user",
606
611
  image: {
607
- contentType: d.contentType,
608
- content: await ae(d.file)
612
+ contentType: h.contentType,
613
+ content: await oe(h.file)
609
614
  },
610
615
  text: "",
611
616
  type: "text"
612
617
  });
613
- r.content && g.push({
618
+ r.content && y.push({
614
619
  role: "user",
615
620
  text: r.content[0].text,
616
621
  type: "text"
617
- }), e == null || e.debug("Sending message:", g), await (y == null ? void 0 : y.send(g)), l(!1);
618
- }, U = v(() => (l(!1), h([]), W("new"), Promise.resolve()), []), L = v(() => Promise.resolve(), []), F = G({
622
+ }), e == null || e.debug("Sending message:", y), await (d == null ? void 0 : d.send(y)), l(!1);
623
+ }, O = E(() => (l(!1), f([]), U("new"), Promise.resolve()), []), L = E(() => Promise.resolve(), []), F = E(() => u, [u]), J = V({
619
624
  isRunning: c,
620
625
  messages: u,
621
- convertMessage: ee,
622
- onNew: O,
623
- onCancel: U,
626
+ convertMessage: te,
627
+ onNew: j,
628
+ onCancel: O,
624
629
  onReload: L,
625
630
  adapters: {
626
- attachments: new V([new H()])
631
+ attachments: new H([new Q()])
627
632
  }
628
633
  });
629
- return /* @__PURE__ */ A.jsx(R.Provider, { value: { protocols: m, protocolsStatus: S }, children: /* @__PURE__ */ A.jsx(Q, { runtime: F, children: n }) });
634
+ return /* @__PURE__ */ T.jsx(S.Provider, { value: { protocols: m, protocolsStatus: P, getMessages: F }, children: /* @__PURE__ */ T.jsx(X, { runtime: J, children: n }) });
630
635
  }
631
- function he({ children: a, ...t }) {
632
- return /* @__PURE__ */ A.jsx(oe, { ...t, children: a });
636
+ function de({ children: i, ...t }) {
637
+ return /* @__PURE__ */ T.jsx(re, { ...t, children: i });
633
638
  }
634
- function de() {
635
- const a = E(R);
636
- if (!a)
639
+ function fe() {
640
+ const i = R(S);
641
+ if (!i)
637
642
  throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
638
- return a;
643
+ return i;
639
644
  }
640
- function re(a) {
641
- const t = E(R);
645
+ function ce(i) {
646
+ const t = R(S);
642
647
  if (!t)
643
648
  throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
644
- const e = t.protocols.find((s) => s.getName() === a);
649
+ const e = t.protocols.find((s) => s.getName() === i);
645
650
  if (!e)
646
651
  return null;
647
652
  const n = t.protocolsStatus.get(e.getName());
@@ -658,19 +663,25 @@ function re(a) {
658
663
  status: n || e.status
659
664
  };
660
665
  }
661
- function fe() {
662
- const a = E(R);
663
- if (!a)
666
+ function pe() {
667
+ const i = R(S);
668
+ if (!i)
664
669
  throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
665
- for (const t of a.protocols)
670
+ for (const t of i.protocols)
666
671
  if (t.getName() === "rest")
667
672
  return t.config.apiUrl;
668
673
  throw new Error("REST protocol not found");
669
674
  }
670
- function pe() {
671
- return re("webrtc");
675
+ function ge() {
676
+ return ce("webrtc");
677
+ }
678
+ function ye() {
679
+ const i = R(S);
680
+ if (!i)
681
+ throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
682
+ return i.getMessages();
672
683
  }
673
- class ye {
684
+ class me {
674
685
  constructor() {
675
686
  o(this, "prefix", "[Persona]");
676
687
  }
@@ -691,16 +702,17 @@ class ye {
691
702
  }
692
703
  }
693
704
  export {
694
- ye as PersonaConsoleLogger,
695
- x as PersonaProtocolBase,
705
+ me as PersonaConsoleLogger,
706
+ A as PersonaProtocolBase,
696
707
  N as PersonaRESTProtocol,
697
- he as PersonaRuntimeProvider,
698
- ie as PersonaTransactionProtocol,
708
+ de as PersonaRuntimeProvider,
709
+ ae as PersonaTransactionProtocol,
699
710
  z as PersonaWebRTCProtocol,
700
711
  I as PersonaWebSocketProtocol,
701
- de as usePersonaRuntime,
702
- fe as usePersonaRuntimeEndpoint,
703
- re as usePersonaRuntimeProtocol,
704
- pe as usePersonaRuntimeWebRTCProtocol
712
+ fe as usePersonaRuntime,
713
+ pe as usePersonaRuntimeEndpoint,
714
+ ye as usePersonaRuntimeMessages,
715
+ ce as usePersonaRuntimeProtocol,
716
+ ge as usePersonaRuntimeWebRTCProtocol
705
717
  };
706
718
  //# sourceMappingURL=bundle.es.js.map