@applica-software-guru/persona-sdk 0.1.45 → 0.1.46

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
- var U = Object.defineProperty;
2
- var J = (i, t, e) => t in i ? U(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
- var o = (i, t, e) => J(i, typeof t != "symbol" ? t + "" : t, e);
4
- import { createContext as q, useContext as N, useState as b, useRef as K, useMemo as _, useEffect as B, useCallback as v } from "react";
1
+ var F = Object.defineProperty;
2
+ var J = (n, t, e) => t in n ? F(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var a = (n, t, e) => J(n, typeof t != "symbol" ? t + "" : t, e);
4
+ import { createContext as q, useContext as x, useState as C, useRef as K, useMemo as _, useEffect as B, useCallback as T } from "react";
5
5
  import { useExternalStoreRuntime as Y, AssistantRuntimeProvider as G } from "@assistant-ui/react";
6
- var z = { exports: {} }, w = {};
6
+ var z = { exports: {} }, m = {};
7
7
  /**
8
8
  * @license React
9
9
  * react-jsx-runtime.production.js
@@ -15,72 +15,79 @@ var z = { exports: {} }, w = {};
15
15
  */
16
16
  var M;
17
17
  function V() {
18
- if (M) return w;
18
+ if (M) return m;
19
19
  M = 1;
20
- var i = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
- function e(s, n, a) {
20
+ var n = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
+ function e(o, s, i) {
22
22
  var c = null;
23
- if (a !== void 0 && (c = "" + a), n.key !== void 0 && (c = "" + n.key), "key" in n) {
24
- a = {};
25
- for (var r in n)
26
- r !== "key" && (a[r] = n[r]);
27
- } else a = n;
28
- return n = a.ref, {
29
- $$typeof: i,
30
- type: s,
23
+ if (i !== void 0 && (c = "" + i), s.key !== void 0 && (c = "" + s.key), "key" in s) {
24
+ i = {};
25
+ for (var r in s)
26
+ r !== "key" && (i[r] = s[r]);
27
+ } else i = s;
28
+ return s = i.ref, {
29
+ $$typeof: n,
30
+ type: o,
31
31
  key: c,
32
- ref: n !== void 0 ? n : null,
33
- props: a
32
+ ref: s !== void 0 ? s : null,
33
+ props: i
34
34
  };
35
35
  }
36
- return w.Fragment = t, w.jsx = e, w.jsxs = e, w;
36
+ return m.Fragment = t, m.jsx = e, m.jsxs = e, m;
37
37
  }
38
38
  z.exports = V();
39
- var k = z.exports;
40
- function H(i) {
41
- return i.filter((t) => {
39
+ var P = z.exports;
40
+ function H(n) {
41
+ return n.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 Q(i) {
46
+ function Q(n) {
47
47
  const t = [];
48
48
  let e = null;
49
- for (const s of i)
49
+ for (const s of n)
50
50
  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
- } : e && s.protocol === e.protocol && (e.role === s.role || s.finishReason === "stop") ? e.text += s.text : (e && t.push(e), e = {
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
56
  return e && t.push(e), H(t);
57
57
  }
58
- function X(i) {
59
- var t;
60
- return i.role === "function" ? {
61
- id: i.id,
58
+ function X(n) {
59
+ var e, o;
60
+ const t = ((e = n.files) == null ? void 0 : e.map(
61
+ (s) => ({
62
+ type: "file",
63
+ data: s.url,
64
+ mimeType: s.contentType
65
+ })
66
+ )) ?? [];
67
+ return n.role === "function" ? {
68
+ id: n.id,
62
69
  role: "assistant",
63
- status: (i == null ? void 0 : i.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
64
- content: ((t = i.functionCalls) == null ? void 0 : t.map((e) => {
65
- var s;
70
+ status: (n == null ? void 0 : n.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
71
+ content: ((o = n.functionCalls) == null ? void 0 : o.map((s) => {
72
+ var i;
66
73
  return {
67
74
  type: "tool-call",
68
- toolName: e.name,
69
- toolCallId: e.id,
70
- args: e.args,
71
- result: (s = i.functionResponse) == null ? void 0 : s.result
75
+ toolName: s.name,
76
+ toolCallId: s.id,
77
+ args: s.args,
78
+ result: (i = n.functionResponse) == null ? void 0 : i.result
72
79
  };
73
80
  })) ?? []
74
81
  } : {
75
- id: i.id,
76
- role: i.role,
77
- content: i.type === "reasoning" ? [{ type: "reasoning", text: i.text }] : [{ type: "text", text: i.text }]
82
+ id: n.id,
83
+ role: n.role,
84
+ content: n.type === "reasoning" ? [{ type: "reasoning", text: n.text }, ...t] : [{ type: "text", text: n.text }, ...t]
78
85
  };
79
86
  }
80
- class x {
87
+ class R {
81
88
  constructor() {
82
- o(this, "statusChangeCallbacks", []);
83
- o(this, "messageCallbacks", []);
89
+ a(this, "statusChangeCallbacks", []);
90
+ a(this, "messageCallbacks", []);
84
91
  }
85
92
  addStatusChangeListener(t) {
86
93
  this.statusChangeCallbacks.push(t);
@@ -96,7 +103,7 @@ class x {
96
103
  }
97
104
  async notifyMessages(t) {
98
105
  t.forEach((e) => {
99
- this.messageCallbacks.forEach((s) => s(e));
106
+ this.messageCallbacks.forEach((o) => o(e));
100
107
  });
101
108
  }
102
109
  async setSession(t) {
@@ -104,20 +111,20 @@ class x {
104
111
  }
105
112
  async setStatus(t) {
106
113
  const e = this.status !== t;
107
- this.status = t, e && this.statusChangeCallbacks.forEach((s) => s(t));
114
+ this.status = t, e && this.statusChangeCallbacks.forEach((o) => o(t));
108
115
  }
109
116
  clearListeners() {
110
117
  this.statusChangeCallbacks = [], this.messageCallbacks = [];
111
118
  }
112
119
  }
113
- class T extends x {
120
+ class $ extends R {
114
121
  constructor(e) {
115
122
  super();
116
- o(this, "status");
117
- o(this, "autostart");
118
- o(this, "session");
119
- o(this, "config");
120
- o(this, "notify", !0);
123
+ a(this, "status");
124
+ a(this, "autostart");
125
+ a(this, "session");
126
+ a(this, "config");
127
+ a(this, "notify", !0);
121
128
  this.config = e, this.status = "disconnected", this.autostart = !0;
122
129
  }
123
130
  getName() {
@@ -136,26 +143,26 @@ class T extends x {
136
143
  this.session = e;
137
144
  }
138
145
  async send(e) {
139
- const { apiUrl: s, apiKey: n, agentId: a } = this.config, c = this.session ?? "new", r = e, h = await (await fetch(`${s}/agents/${a}/sessions/${c}/messages`, {
146
+ const { apiUrl: o, apiKey: s, agentId: i } = this.config, c = this.session ?? "new", r = e, h = await (await fetch(`${o}/agents/${i}/sessions/${c}/messages`, {
140
147
  body: JSON.stringify({ userMessage: r }),
141
148
  method: "POST",
142
149
  headers: {
143
150
  "Content-Type": "application/json",
144
- "x-fox-apikey": n,
145
- "x-persona-apikey": n
151
+ "x-fox-apikey": s,
152
+ "x-persona-apikey": s
146
153
  }
147
154
  })).json();
148
155
  this.notifyMessages(h.response.messages);
149
156
  }
150
157
  }
151
- class $ extends x {
158
+ class I extends R {
152
159
  constructor(e) {
153
160
  super();
154
- o(this, "status");
155
- o(this, "autostart");
156
- o(this, "session");
157
- o(this, "config");
158
- o(this, "webSocket");
161
+ a(this, "status");
162
+ a(this, "autostart");
163
+ a(this, "session");
164
+ a(this, "config");
165
+ a(this, "webSocket");
159
166
  this.config = e, this.status = "disconnected", this.autostart = !0, this.session = null, this.webSocket = null;
160
167
  }
161
168
  getName() {
@@ -165,16 +172,16 @@ class $ extends x {
165
172
  return 1;
166
173
  }
167
174
  async syncSession(e) {
168
- var s;
169
- (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));
175
+ var o;
176
+ (o = this.config.logger) == null || o.debug("Syncing session with WebSocket protocol:", e), this.session = e, this.webSocket && this.status === "connected" && (this.disconnect(), this.connect(e));
170
177
  }
171
178
  connect(e) {
172
179
  var r;
173
180
  if (this.webSocket !== null && this.status === "connected")
174
181
  return Promise.resolve(this.session);
175
- const s = e || this.session || "new";
176
- (r = this.config.logger) == null || r.debug("Connecting to WebSocket with sessionId:", s);
177
- const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, c = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
182
+ const o = e || this.session || "new";
183
+ (r = this.config.logger) == null || r.debug("Connecting to WebSocket with sessionId:", o);
184
+ const s = encodeURIComponent(this.config.apiKey), i = this.config.agentId, c = `${this.config.webSocketUrl}?sessionCode=${o}&agentId=${i}&apiKey=${s}`;
178
185
  return this.setStatus("connecting"), this.webSocket = new WebSocket(c), this.webSocket.addEventListener("open", () => {
179
186
  this.setStatus("connected");
180
187
  }), this.webSocket.addEventListener("message", (u) => {
@@ -189,7 +196,7 @@ class $ extends x {
189
196
  }), this.webSocket.addEventListener("error", (u) => {
190
197
  var h;
191
198
  this.setStatus("disconnected"), this.webSocket = null, (h = this.config.logger) == null || h.error("WebSocket error", u);
192
- }), Promise.resolve(s);
199
+ }), Promise.resolve(o);
193
200
  }
194
201
  disconnect() {
195
202
  var e;
@@ -201,29 +208,29 @@ class $ extends x {
201
208
  }
202
209
  class Z {
203
210
  constructor(t) {
204
- o(this, "config");
205
- o(this, "pc", null);
206
- o(this, "ws", null);
207
- o(this, "localStream", null);
208
- o(this, "remoteStream", new MediaStream());
209
- o(this, "audioCtx", null);
210
- o(this, "localAnalyser", null);
211
- o(this, "remoteAnalyser", null);
212
- o(this, "analyzerFrame", null);
213
- o(this, "dataChannel", null);
214
- o(this, "isConnected", !1);
215
- o(this, "visualizerCallbacks", []);
216
- o(this, "messageCallbacks", []);
211
+ a(this, "config");
212
+ a(this, "pc", null);
213
+ a(this, "ws", null);
214
+ a(this, "localStream", null);
215
+ a(this, "remoteStream", new MediaStream());
216
+ a(this, "audioCtx", null);
217
+ a(this, "localAnalyser", null);
218
+ a(this, "remoteAnalyser", null);
219
+ a(this, "analyzerFrame", null);
220
+ a(this, "dataChannel", null);
221
+ a(this, "isConnected", !1);
222
+ a(this, "visualizerCallbacks", []);
223
+ a(this, "messageCallbacks", []);
217
224
  this.config = t;
218
225
  }
219
226
  async connect(t) {
220
- var s;
227
+ var o;
221
228
  if (this.isConnected) return;
222
229
  this.isConnected = !0;
223
230
  try {
224
231
  this.localStream = await navigator.mediaDevices.getUserMedia({ audio: !0 });
225
- } catch (n) {
226
- (s = this.config.logger) == null || s.error("Error accessing microphone:", n);
232
+ } catch (s) {
233
+ (o = this.config.logger) == null || o.error("Error accessing microphone:", s);
227
234
  return;
228
235
  }
229
236
  this.pc = new RTCPeerConnection({
@@ -237,29 +244,29 @@ class Z {
237
244
  credential: "webrtc"
238
245
  }
239
246
  ]
240
- }), this.localStream.getTracks().forEach((n) => {
241
- this.pc.addTrack(n, this.localStream);
242
- }), this.pc.ontrack = (n) => {
243
- n.streams[0].getTracks().forEach((c) => {
247
+ }), this.localStream.getTracks().forEach((s) => {
248
+ this.pc.addTrack(s, this.localStream);
249
+ }), this.pc.ontrack = (s) => {
250
+ s.streams[0].getTracks().forEach((c) => {
244
251
  this.remoteStream.addTrack(c);
245
252
  }), this.audioCtx || this._startAnalyzers();
246
- const a = new Audio();
247
- a.srcObject = this.remoteStream, a.play().catch((c) => {
253
+ const i = new Audio();
254
+ i.srcObject = this.remoteStream, i.play().catch((c) => {
248
255
  var r;
249
256
  (r = this.config.logger) == null || r.error("Error playing remote audio:", c);
250
257
  });
251
- }, this.pc.onicecandidate = (n) => {
252
- var a;
253
- n.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
258
+ }, this.pc.onicecandidate = (s) => {
259
+ var i;
260
+ s.candidate && ((i = this.ws) == null ? void 0 : i.readyState) === WebSocket.OPEN && this.ws.send(
254
261
  JSON.stringify({
255
262
  type: "CANDIDATE",
256
263
  src: "client",
257
- payload: { candidate: n.candidate }
264
+ payload: { candidate: s.candidate }
258
265
  })
259
266
  );
260
- }, this.pc.ondatachannel = (n) => {
261
- const a = n.channel;
262
- a.onmessage = (c) => {
267
+ }, this.pc.ondatachannel = (s) => {
268
+ const i = s.channel;
269
+ i.onmessage = (c) => {
263
270
  this.messageCallbacks.forEach((r) => {
264
271
  r(c);
265
272
  });
@@ -268,35 +275,35 @@ class Z {
268
275
  const e = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
269
276
  this.ws = new WebSocket(`${e}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
270
277
  var r, u;
271
- const n = await this.pc.createOffer();
272
- await this.pc.setLocalDescription(n);
273
- const a = {
278
+ const s = await this.pc.createOffer();
279
+ await this.pc.setLocalDescription(s);
280
+ const i = {
274
281
  apiKey: this.config.apiKey,
275
282
  agentId: this.config.agentId,
276
283
  sessionCode: t
277
284
  };
278
- (r = this.config.logger) == null || r.debug("Opening connection to WebRTC server: ", a);
285
+ (r = this.config.logger) == null || r.debug("Opening connection to WebRTC server: ", i);
279
286
  const c = {
280
287
  type: "OFFER",
281
288
  src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
282
289
  payload: {
283
290
  sdp: {
284
- sdp: n.sdp,
285
- type: n.type
291
+ sdp: s.sdp,
292
+ type: s.type
286
293
  },
287
294
  connectionId: (Date.now() % 1e6).toString(),
288
- metadata: a
295
+ metadata: i
289
296
  }
290
297
  };
291
298
  this.ws.send(JSON.stringify(c));
292
- }, this.ws.onmessage = async (n) => {
299
+ }, this.ws.onmessage = async (s) => {
293
300
  var c;
294
- const a = JSON.parse(n.data);
295
- if (a.type === "ANSWER")
296
- await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
297
- else if (a.type === "CANDIDATE")
301
+ const i = JSON.parse(s.data);
302
+ if (i.type === "ANSWER")
303
+ await this.pc.setRemoteDescription(new RTCSessionDescription(i.payload.sdp));
304
+ else if (i.type === "CANDIDATE")
298
305
  try {
299
- await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
306
+ await this.pc.addIceCandidate(new RTCIceCandidate(i.payload.candidate));
300
307
  } catch (r) {
301
308
  (c = this.config.logger) == null || c.error("Error adding ICE candidate:", r);
302
309
  }
@@ -319,18 +326,18 @@ class Z {
319
326
  var e;
320
327
  return (e = this.config.logger) == null ? void 0 : e.info("Data channel opened");
321
328
  }, this.dataChannel.onmessage = (e) => {
322
- this.messageCallbacks.forEach((s) => {
323
- s(e);
329
+ this.messageCallbacks.forEach((o) => {
330
+ o(e);
324
331
  });
325
332
  });
326
333
  }
327
334
  sendMessage(t) {
328
- var e, s;
335
+ var e, o;
329
336
  if (!this.dataChannel) {
330
337
  (e = this.config.logger) == null || e.warn("Data channel is not open, cannot send message");
331
338
  return;
332
339
  }
333
- this.dataChannel.send(t), (s = this.config.logger) == null || s.info("Sent message:", t);
340
+ this.dataChannel.send(t), (o = this.config.logger) == null || o.info("Sent message:", t);
334
341
  }
335
342
  _startAnalyzers() {
336
343
  if (!this.localStream || !this.remoteStream || this.visualizerCallbacks.length === 0)
@@ -338,38 +345,38 @@ class Z {
338
345
  this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
339
346
  const t = this.audioCtx.createMediaStreamSource(this.localStream), e = this.audioCtx.createMediaStreamSource(this.remoteStream);
340
347
  this.localAnalyser = this.audioCtx.createAnalyser(), this.remoteAnalyser = this.audioCtx.createAnalyser(), this.localAnalyser.fftSize = 256, this.remoteAnalyser.fftSize = 256, t.connect(this.localAnalyser), e.connect(this.remoteAnalyser);
341
- const s = () => {
348
+ const o = () => {
342
349
  if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
343
350
  return;
344
- const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
345
- this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
346
- const c = n.reduce((u, h) => u + h, 0) / n.length, r = a.reduce((u, h) => u + h, 0) / a.length;
351
+ const s = new Uint8Array(this.localAnalyser.frequencyBinCount), i = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
352
+ this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(i);
353
+ const c = s.reduce((u, h) => u + h, 0) / s.length, r = i.reduce((u, h) => u + h, 0) / i.length;
347
354
  this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
348
355
  u({
349
356
  localAmplitude: c,
350
357
  remoteAmplitude: r
351
358
  });
352
- }), this.analyzerFrame = requestAnimationFrame(s);
359
+ }), this.analyzerFrame = requestAnimationFrame(o);
353
360
  };
354
- this.analyzerFrame = requestAnimationFrame(s);
361
+ this.analyzerFrame = requestAnimationFrame(o);
355
362
  }
356
363
  _stopAnalyzers() {
357
364
  this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
358
365
  }
359
366
  }
360
- class I extends x {
367
+ class N extends R {
361
368
  constructor(e) {
362
369
  super();
363
- o(this, "status");
364
- o(this, "session");
365
- o(this, "autostart");
366
- o(this, "config");
367
- o(this, "webRTCClient");
368
- this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new Z(e), this.webRTCClient.addMessageCallback((s) => {
369
- var a;
370
- (a = e.logger) == null || a.debug("Received data message:", s.data);
371
- const n = JSON.parse(s.data);
372
- n.type === "message" && this.notifyMessage(n.payload);
370
+ a(this, "status");
371
+ a(this, "session");
372
+ a(this, "autostart");
373
+ a(this, "config");
374
+ a(this, "webRTCClient");
375
+ this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new Z(e), this.webRTCClient.addMessageCallback((o) => {
376
+ var i;
377
+ (i = e.logger) == null || i.debug("Received data message:", o.data);
378
+ const s = JSON.parse(o.data);
379
+ s.type === "message" && this.notifyMessage(s.payload);
373
380
  });
374
381
  }
375
382
  getName() {
@@ -382,59 +389,59 @@ class I extends x {
382
389
  super.syncSession(e), this.status === "connected" && (await this.disconnect(), await this.connect(e));
383
390
  }
384
391
  async connect(e) {
385
- var s;
386
- return this.status === "connected" ? Promise.resolve(this.session) : (this.session = e || this.session || "new", this.setStatus("connecting"), (s = this.config.logger) == null || s.debug("Connecting to WebRTC with sessionId:", this.session), await this.webRTCClient.connect(this.session), this.setStatus("connected"), await this.webRTCClient.createDataChannel(), this.session);
392
+ var o;
393
+ return this.status === "connected" ? Promise.resolve(this.session) : (this.session = e || this.session || "new", this.setStatus("connecting"), (o = this.config.logger) == null || o.debug("Connecting to WebRTC with sessionId:", this.session), await this.webRTCClient.connect(this.session), this.setStatus("connected"), await this.webRTCClient.createDataChannel(), this.session);
387
394
  }
388
395
  async disconnect() {
389
- var e, s, n;
396
+ var e, o, s;
390
397
  if (this.status === "disconnected")
391
398
  return (e = this.config.logger) == null || e.warn("Already disconnected"), Promise.resolve();
392
- await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (n = (s = this.config) == null ? void 0 : s.logger) == null || n.debug("Disconnected from WebRTC");
399
+ await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (s = (o = this.config) == null ? void 0 : o.logger) == null || s.debug("Disconnected from WebRTC");
393
400
  }
394
401
  send(e) {
395
402
  return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendMessage(e), Promise.resolve());
396
403
  }
397
404
  }
398
- const P = q(void 0);
405
+ const S = q(void 0);
399
406
  function ee({
400
- dev: i = !1,
407
+ dev: n = !1,
401
408
  protocols: t,
402
409
  logger: e,
403
- children: s,
404
- session: n = "new",
405
- ...a
410
+ children: o,
411
+ session: s = "new",
412
+ ...i
406
413
  }) {
407
- const [c, r] = b(!1), [u, h] = b([]), [f, D] = b(n), [m, W] = b(/* @__PURE__ */ new Map()), R = K(!1), y = _(() => {
414
+ const [c, r] = C(!1), [u, h] = C([]), [f, D] = C(s), [w, W] = C(/* @__PURE__ */ new Map()), E = K(!1), y = _(() => {
408
415
  if (Array.isArray(t))
409
416
  return t;
410
417
  if (typeof t == "object" && t !== null) {
411
- const l = i ? "localhost:8000" : "persona.applica.guru/api", p = i ? "http" : "https", g = i ? "ws" : "wss";
418
+ const l = n ? "localhost:8000" : "persona.applica.guru/api", p = n ? "http" : "https", g = n ? "ws" : "wss";
412
419
  return Object.keys(t).map((d) => {
413
420
  switch (d) {
414
421
  case "rest":
415
- const C = t[d];
416
- return C === !0 ? new T({
422
+ const b = t[d];
423
+ return b === !0 ? new $({
417
424
  apiUrl: `${p}://${l}`,
418
- apiKey: a.apiKey,
419
- agentId: a.agentId,
425
+ apiKey: i.apiKey,
426
+ agentId: i.agentId,
420
427
  logger: e
421
- }) : new T(C);
428
+ }) : new $(b);
422
429
  case "webrtc":
423
430
  const A = t[d];
424
- return A === !0 ? new I({
431
+ return A === !0 ? new N({
425
432
  webrtcUrl: `${g}://${l}/webrtc`,
426
- apiKey: a.apiKey,
427
- agentId: a.agentId,
433
+ apiKey: i.apiKey,
434
+ agentId: i.agentId,
428
435
  logger: e
429
- }) : new I(A);
436
+ }) : new N(A);
430
437
  case "websocket":
431
- const E = t[d];
432
- return E === !0 ? new $({
438
+ const v = t[d];
439
+ return v === !0 ? new I({
433
440
  webSocketUrl: `${g}://${l}/websocket`,
434
- apiKey: a.apiKey,
435
- agentId: a.agentId,
441
+ apiKey: i.apiKey,
442
+ agentId: i.agentId,
436
443
  logger: e
437
- }) : new $(E);
444
+ }) : new I(v);
438
445
  default:
439
446
  throw new Error(`Unknown protocol: ${d}`);
440
447
  }
@@ -443,51 +450,51 @@ function ee({
443
450
  throw new Error("Invalid protocols configuration");
444
451
  }, []);
445
452
  B(() => {
446
- R.current || (R.current = !0, e == null || e.debug(
453
+ E.current || (E.current = !0, e == null || e.debug(
447
454
  "Initializing protocols: ",
448
455
  y.map((l) => l.getName())
449
456
  ), y.forEach((l) => {
450
457
  l.setSession(f), l.clearListeners(), l.addStatusChangeListener((p) => {
451
- e == null || e.debug(`${l.getName()} has notified new status: ${p}`), m.set(l.getName(), p), W(new Map(m));
458
+ e == null || e.debug(`${l.getName()} has notified new status: ${p}`), w.set(l.getName(), p), W(new Map(w));
452
459
  }), l.addMessageListener((p) => {
453
460
  h((g) => Q([...g, { ...p, protocol: l.getName() }]));
454
461
  }), l.autostart && l.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${l.getName()}`), l.connect(f));
455
462
  }));
456
- }, [f, y, e, m]);
463
+ }, [f, y, e, w]);
457
464
  const L = async (l) => {
458
- var S;
459
- if (((S = l.content[0]) == null ? void 0 : S.type) !== "text") throw new Error("Only text messages are supported");
465
+ var k;
466
+ if (((k = l.content[0]) == null ? void 0 : k.type) !== "text") throw new Error("Only text messages are supported");
460
467
  const p = l.content[0].text;
461
468
  h((d) => [...d, { role: "user", type: "text", text: p }]), r(!0);
462
- const g = y.sort((d, C) => C.getPriority() - d.getPriority()).find((d) => d.status === "connected");
469
+ const g = y.sort((d, b) => b.getPriority() - d.getPriority()).find((d) => d.status === "connected");
463
470
  await (g == null ? void 0 : g.send(p)), r(!1);
464
- }, O = v(() => (r(!1), h([]), D("new"), Promise.resolve()), []), j = v(() => Promise.resolve(), []), F = Y({
471
+ }, O = T(() => (r(!1), h([]), D("new"), Promise.resolve()), []), U = T(() => Promise.resolve(), []), j = Y({
465
472
  isRunning: c,
466
473
  messages: u,
467
474
  convertMessage: X,
468
475
  onNew: L,
469
476
  onCancel: O,
470
- onReload: j
477
+ onReload: U
471
478
  });
472
- return /* @__PURE__ */ k.jsx(P.Provider, { value: { protocols: y, protocolsStatus: m }, children: /* @__PURE__ */ k.jsx(G, { runtime: F, children: s }) });
479
+ return /* @__PURE__ */ P.jsx(S.Provider, { value: { protocols: y, protocolsStatus: w }, children: /* @__PURE__ */ P.jsx(G, { runtime: j, children: o }) });
473
480
  }
474
- function ae({ children: i, ...t }) {
475
- return /* @__PURE__ */ k.jsx(ee, { ...t, children: i });
481
+ function oe({ children: n, ...t }) {
482
+ return /* @__PURE__ */ P.jsx(ee, { ...t, children: n });
476
483
  }
477
- function oe() {
478
- const i = N(P);
479
- if (!i)
484
+ function ae() {
485
+ const n = x(S);
486
+ if (!n)
480
487
  throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
481
- return i;
488
+ return n;
482
489
  }
483
- function te(i) {
484
- const t = N(P);
490
+ function te(n) {
491
+ const t = x(S);
485
492
  if (!t)
486
493
  throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
487
- const e = t.protocols.find((n) => n.getName() === i);
494
+ const e = t.protocols.find((s) => s.getName() === n);
488
495
  if (!e)
489
496
  return null;
490
- const s = t.protocolsStatus.get(e.getName());
497
+ const o = t.protocolsStatus.get(e.getName());
491
498
  return {
492
499
  ...e,
493
500
  connect: e.connect.bind(e),
@@ -498,15 +505,24 @@ function te(i) {
498
505
  addMessageListener: e.addMessageListener.bind(e),
499
506
  getName: e.getName.bind(e),
500
507
  getPriority: e.getPriority.bind(e),
501
- status: s || e.status
508
+ status: o || e.status
502
509
  };
503
510
  }
504
511
  function re() {
512
+ const n = x(S);
513
+ if (!n)
514
+ throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
515
+ for (const t of n.protocols)
516
+ if (t.getName() === "rest")
517
+ return t.config.apiUrl;
518
+ throw new Error("REST protocol not found");
519
+ }
520
+ function ce() {
505
521
  return te("webrtc");
506
522
  }
507
- class ce {
523
+ class le {
508
524
  constructor() {
509
- o(this, "prefix", "[Persona]");
525
+ a(this, "prefix", "[Persona]");
510
526
  }
511
527
  log(t, ...e) {
512
528
  console.log(`${this.prefix} - ${t}`, ...e);
@@ -525,14 +541,15 @@ class ce {
525
541
  }
526
542
  }
527
543
  export {
528
- ce as PersonaConsoleLogger,
529
- x as PersonaProtocolBase,
530
- T as PersonaRESTProtocol,
531
- ae as PersonaRuntimeProvider,
532
- I as PersonaWebRTCProtocol,
533
- $ as PersonaWebSocketProtocol,
534
- oe as usePersonaRuntime,
544
+ le as PersonaConsoleLogger,
545
+ R as PersonaProtocolBase,
546
+ $ as PersonaRESTProtocol,
547
+ oe as PersonaRuntimeProvider,
548
+ N as PersonaWebRTCProtocol,
549
+ I as PersonaWebSocketProtocol,
550
+ ae as usePersonaRuntime,
551
+ re as usePersonaRuntimeEndpoint,
535
552
  te as usePersonaRuntimeProtocol,
536
- re as usePersonaRuntimeWebRTCProtocol
553
+ ce as usePersonaRuntimeWebRTCProtocol
537
554
  };
538
555
  //# sourceMappingURL=bundle.es.js.map