@applica-software-guru/persona-sdk 0.1.66 → 0.1.68

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
- var V = (o, t, e) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
- var r = (o, t, e) => V(o, typeof t != "symbol" ? t + "" : t, e);
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";
2
+ var V = (a, t, e) => t in a ? B(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
+ var i = (a, t, e) => V(a, typeof t != "symbol" ? t + "" : t, e);
4
+ import { createContext as Y, useContext as E, useState as A, 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 F = { exports: {} }, k = {};
6
+ var z = { exports: {} }, x = {};
7
7
  /**
8
8
  * @license React
9
9
  * react-jsx-runtime.production.js
@@ -15,38 +15,38 @@ var F = { exports: {} }, k = {};
15
15
  */
16
16
  var O;
17
17
  function se() {
18
- if (O) return k;
18
+ if (O) return x;
19
19
  O = 1;
20
- var o = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
- function e(s, n, a) {
22
- var i = null;
23
- if (a !== void 0 && (i = "" + a), n.key !== void 0 && (i = "" + n.key), "key" in n) {
24
- a = {};
20
+ var a = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
+ function e(s, n, o) {
22
+ var r = null;
23
+ if (o !== void 0 && (r = "" + o), n.key !== void 0 && (r = "" + n.key), "key" in n) {
24
+ o = {};
25
25
  for (var c in n)
26
- c !== "key" && (a[c] = n[c]);
27
- } else a = n;
28
- return n = a.ref, {
29
- $$typeof: o,
26
+ c !== "key" && (o[c] = n[c]);
27
+ } else o = n;
28
+ return n = o.ref, {
29
+ $$typeof: a,
30
30
  type: s,
31
- key: i,
31
+ key: r,
32
32
  ref: n !== void 0 ? n : null,
33
- props: a
33
+ props: o
34
34
  };
35
35
  }
36
- return k.Fragment = t, k.jsx = e, k.jsxs = e, k;
36
+ return x.Fragment = t, x.jsx = e, x.jsxs = e, x;
37
37
  }
38
- F.exports = se();
39
- var M = F.exports;
40
- function ne(o) {
41
- return o.filter((t) => {
38
+ z.exports = se();
39
+ var M = z.exports;
40
+ function ne(a) {
41
+ return a.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 j(o) {
46
+ function j(a) {
47
47
  const t = [];
48
48
  let e = null;
49
- for (const n of o)
49
+ for (const n of a)
50
50
  n.type !== "transaction" && (n.type === "reasoning" ? (e != null && (t.push(e), e = null), t.push(n)) : n.functionCalls ? (e && t.push(e), t.push(n), e = null) : n.functionResponse ? t[t.length - 1] = {
51
51
  ...t[t.length - 1],
52
52
  functionResponse: n.functionResponse
@@ -55,39 +55,39 @@ function j(o) {
55
55
  }));
56
56
  return e && t.push(e), ne(t);
57
57
  }
58
- function oe(o) {
58
+ function ae(a) {
59
59
  var e, s;
60
- const t = ((e = o.files) == null ? void 0 : e.map(
60
+ const t = ((e = a.files) == null ? void 0 : e.map(
61
61
  (n) => ({
62
62
  type: "file",
63
63
  data: n.url,
64
64
  mimeType: n.contentType
65
65
  })
66
66
  )) ?? [];
67
- return o.role === "function" ? {
68
- id: o.id,
67
+ return a.role === "function" ? {
68
+ id: a.id,
69
69
  role: "assistant",
70
- status: (o == null ? void 0 : o.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
71
- content: ((s = o.functionCalls) == null ? void 0 : s.map((n) => {
72
- var a;
70
+ status: (a == null ? void 0 : a.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
71
+ content: ((s = a.functionCalls) == null ? void 0 : s.map((n) => {
72
+ var o;
73
73
  return {
74
74
  type: "tool-call",
75
75
  toolName: n.name,
76
76
  toolCallId: n.id,
77
77
  args: n.args,
78
- result: (a = o.functionResponse) == null ? void 0 : a.result
78
+ result: (o = a.functionResponse) == null ? void 0 : o.result
79
79
  };
80
80
  })) ?? []
81
81
  } : {
82
- id: o.id,
83
- role: o.role,
84
- content: o.type === "reasoning" ? [{ type: "reasoning", text: o.text }, ...t] : [{ type: "text", text: o.text }, ...t]
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]
85
85
  };
86
86
  }
87
87
  class v {
88
88
  constructor() {
89
- r(this, "statusChangeCallbacks", []);
90
- r(this, "messageCallbacks", []);
89
+ i(this, "statusChangeCallbacks", []);
90
+ i(this, "messageCallbacks", []);
91
91
  }
92
92
  addStatusChangeListener(t) {
93
93
  this.statusChangeCallbacks.push(t);
@@ -122,13 +122,13 @@ class v {
122
122
  class _ extends v {
123
123
  constructor(e) {
124
124
  super();
125
- r(this, "status");
126
- r(this, "autostart");
127
- r(this, "session");
128
- r(this, "config");
129
- r(this, "notify", !0);
130
- r(this, "context", {});
131
- r(this, "tools", []);
125
+ i(this, "status");
126
+ i(this, "autostart");
127
+ i(this, "session");
128
+ i(this, "config");
129
+ i(this, "notify", !0);
130
+ i(this, "context", {});
131
+ i(this, "tools", []);
132
132
  this.config = e, this.status = "disconnected", this.autostart = !0;
133
133
  }
134
134
  getName() {
@@ -147,12 +147,12 @@ class _ extends v {
147
147
  this.session = e;
148
148
  }
149
149
  async sendPacket(e) {
150
- var u, d, g, w;
151
- const { apiUrl: s, apiKey: n, agentId: a } = this.config, i = this.session ?? "new";
150
+ var u, d, y, S;
151
+ const { apiUrl: s, apiKey: n, agentId: o } = this.config, r = this.session ?? "new";
152
152
  if (e.type === "command" && ((u = e == null ? void 0 : e.payload) == null ? void 0 : u.command) == "set_initial_context") {
153
153
  this.context = (d = e == null ? void 0 : e.payload) == null ? void 0 : d.arguments;
154
154
  return;
155
- } else if (e.type === "command" && ((g = e == null ? void 0 : e.payload) == null ? void 0 : g.command) == "set_local_tools") {
155
+ } else if (e.type === "command" && ((y = e == null ? void 0 : e.payload) == null ? void 0 : y.command) == "set_local_tools") {
156
156
  this.notifyPacket({
157
157
  type: "message",
158
158
  payload: {
@@ -165,8 +165,8 @@ class _ extends v {
165
165
  }
166
166
  const c = e.payload;
167
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 }),
168
+ const C = await (await fetch(`${s}/sessions/${r}/messages`, {
169
+ body: JSON.stringify({ agentId: o, userMessage: c, initialContext: this.context, tools: this.tools }),
170
170
  method: "POST",
171
171
  headers: {
172
172
  "Content-Type": "application/json",
@@ -174,12 +174,12 @@ class _ extends v {
174
174
  }
175
175
  })).json();
176
176
  this.notifyPackets(
177
- b.response.messages.map(($) => ({
177
+ C.response.messages.map(($) => ({
178
178
  type: "message",
179
179
  payload: $
180
180
  }))
181
181
  );
182
- } catch (R) {
182
+ } catch (T) {
183
183
  this.notifyPacket({
184
184
  type: "message",
185
185
  payload: {
@@ -187,18 +187,18 @@ class _ extends v {
187
187
  type: "text",
188
188
  text: "An error occurred while processing your request. Please try again later."
189
189
  }
190
- }), (w = this.config.logger) == null || w.error("Error sending packet:", R);
190
+ }), (S = this.config.logger) == null || S.error("Error sending packet:", T);
191
191
  }
192
192
  }
193
193
  }
194
- class W extends v {
194
+ class U extends v {
195
195
  constructor(e) {
196
196
  super();
197
- r(this, "status");
198
- r(this, "autostart");
199
- r(this, "session");
200
- r(this, "config");
201
- r(this, "webSocket");
197
+ i(this, "status");
198
+ i(this, "autostart");
199
+ i(this, "session");
200
+ i(this, "config");
201
+ i(this, "webSocket");
202
202
  this.config = e, this.status = "disconnected", this.autostart = !0, this.session = null, this.webSocket = null;
203
203
  }
204
204
  getName() {
@@ -217,8 +217,8 @@ class W extends v {
217
217
  return Promise.resolve(this.session);
218
218
  const s = e || this.session || "new";
219
219
  (c = this.config.logger) == null || c.debug("Connecting to WebSocket with sessionId:", s);
220
- const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, i = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
221
- return this.setStatus("connecting"), this.webSocket = new WebSocket(i), this.webSocket.addEventListener("open", () => {
220
+ const n = encodeURIComponent(this.config.apiKey), o = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${o}&apiKey=${n}`;
221
+ return this.setStatus("connecting"), this.webSocket = new WebSocket(r), this.webSocket.addEventListener("open", () => {
222
222
  this.setStatus("connected");
223
223
  }), this.webSocket.addEventListener("message", (u) => {
224
224
  const d = JSON.parse(u.data);
@@ -246,23 +246,23 @@ class W extends v {
246
246
  return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify(e)), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
247
247
  }
248
248
  }
249
- class ae {
249
+ class oe {
250
250
  constructor(t) {
251
- r(this, "config");
252
- r(this, "pc", null);
253
- r(this, "ws", null);
254
- r(this, "localStream", null);
255
- r(this, "remoteStream", new MediaStream());
256
- r(this, "audioCtx", null);
257
- r(this, "localAnalyser", null);
258
- r(this, "remoteAnalyser", null);
259
- r(this, "analyzerFrame", null);
260
- r(this, "dataChannel", null);
261
- r(this, "isConnected", !1);
262
- r(this, "visualizerCallbacks", []);
263
- r(this, "messageCallbacks", []);
264
- r(this, "errorCallbacks", []);
265
- r(this, "queuedMessages", []);
251
+ i(this, "config");
252
+ i(this, "pc", null);
253
+ i(this, "ws", null);
254
+ i(this, "localStream", null);
255
+ i(this, "remoteStream", new MediaStream());
256
+ i(this, "audioCtx", null);
257
+ i(this, "localAnalyser", null);
258
+ i(this, "remoteAnalyser", null);
259
+ i(this, "analyzerFrame", null);
260
+ i(this, "dataChannel", null);
261
+ i(this, "isConnected", !1);
262
+ i(this, "visualizerCallbacks", []);
263
+ i(this, "messageCallbacks", []);
264
+ i(this, "errorCallbacks", []);
265
+ i(this, "queuedMessages", []);
266
266
  this.config = t;
267
267
  }
268
268
  async connect(t) {
@@ -289,17 +289,17 @@ class ae {
289
289
  }), this.localStream.getTracks().forEach((n) => {
290
290
  this.pc.addTrack(n, this.localStream);
291
291
  }), this.pc.ontrack = (n) => {
292
- n.streams[0].getTracks().forEach((i) => {
293
- this.remoteStream.addTrack(i);
292
+ n.streams[0].getTracks().forEach((r) => {
293
+ this.remoteStream.addTrack(r);
294
294
  }), this.audioCtx || this._startAnalyzers();
295
- const a = new Audio();
296
- a.srcObject = this.remoteStream, a.play().catch((i) => {
295
+ const o = new Audio();
296
+ o.srcObject = this.remoteStream, o.play().catch((r) => {
297
297
  var c;
298
- (c = this.config.logger) == null || c.error("Error playing remote audio:", i);
298
+ (c = this.config.logger) == null || c.error("Error playing remote audio:", r);
299
299
  });
300
300
  }, this.pc.onicecandidate = (n) => {
301
- var a;
302
- n.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
301
+ var o;
302
+ n.candidate && ((o = this.ws) == null ? void 0 : o.readyState) === WebSocket.OPEN && this.ws.send(
303
303
  JSON.stringify({
304
304
  type: "CANDIDATE",
305
305
  src: "client",
@@ -307,16 +307,16 @@ class ae {
307
307
  })
308
308
  );
309
309
  }, this.pc.ondatachannel = (n) => {
310
- const a = n.channel;
311
- a.onmessage = (i) => {
310
+ const o = n.channel;
311
+ o.onmessage = (r) => {
312
312
  this.messageCallbacks.forEach((c) => {
313
- c(i);
313
+ c(r);
314
314
  });
315
- }, a.onopen = () => {
316
- var i;
315
+ }, o.onopen = () => {
316
+ var r;
317
317
  for (; this.queuedMessages.length > 0; ) {
318
318
  const c = this.queuedMessages.shift();
319
- c && (a.send(JSON.stringify(c)), (i = this.config.logger) == null || i.info("Sent queued message:", c));
319
+ c && (o.send(JSON.stringify(c)), (r = this.config.logger) == null || r.info("Sent queued message:", c));
320
320
  }
321
321
  };
322
322
  };
@@ -325,13 +325,13 @@ class ae {
325
325
  var c, u;
326
326
  const n = await this.pc.createOffer();
327
327
  await this.pc.setLocalDescription(n);
328
- const a = {
328
+ const o = {
329
329
  apiKey: this.config.apiKey,
330
330
  agentId: this.config.agentId,
331
331
  sessionCode: t
332
332
  };
333
- (c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ", a);
334
- const i = {
333
+ (c = this.config.logger) == null || c.debug("Opening connection to WebRTC server: ", o);
334
+ const r = {
335
335
  type: "OFFER",
336
336
  src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
337
337
  payload: {
@@ -340,24 +340,24 @@ class ae {
340
340
  type: n.type
341
341
  },
342
342
  connectionId: (Date.now() % 1e6).toString(),
343
- metadata: a
343
+ metadata: o
344
344
  }
345
345
  };
346
- this.ws.send(JSON.stringify(i));
346
+ this.ws.send(JSON.stringify(r));
347
347
  }, this.ws.onmessage = async (n) => {
348
- var i;
349
- const a = JSON.parse(n.data);
350
- if (a.type === "ANSWER")
351
- await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
352
- else if (a.type === "CANDIDATE")
348
+ var r;
349
+ const o = JSON.parse(n.data);
350
+ if (o.type === "ANSWER")
351
+ await this.pc.setRemoteDescription(new RTCSessionDescription(o.payload.sdp));
352
+ else if (o.type === "CANDIDATE")
353
353
  try {
354
- await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
354
+ await this.pc.addIceCandidate(new RTCIceCandidate(o.payload.candidate));
355
355
  } catch (c) {
356
- (i = this.config.logger) == null || i.error("Error adding ICE candidate:", c);
356
+ (r = this.config.logger) == null || r.error("Error adding ICE candidate:", c);
357
357
  }
358
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.");
359
+ n.code !== 1e3 && this.errorCallbacks.forEach((o) => {
360
+ o("Oops! The connection to the server was lost. Please try again later.");
361
361
  }), this._stopAnalyzers();
362
362
  };
363
363
  }
@@ -404,12 +404,12 @@ class ae {
404
404
  const s = () => {
405
405
  if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
406
406
  return;
407
- const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
408
- this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
409
- const i = n.reduce((u, d) => u + d, 0) / n.length, c = a.reduce((u, d) => u + d, 0) / a.length;
407
+ const n = new Uint8Array(this.localAnalyser.frequencyBinCount), o = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
408
+ this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(o);
409
+ const r = n.reduce((u, d) => u + d, 0) / n.length, c = o.reduce((u, d) => u + d, 0) / o.length;
410
410
  this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
411
411
  u({
412
- localAmplitude: i,
412
+ localAmplitude: r,
413
413
  remoteAmplitude: c
414
414
  });
415
415
  }), this.analyzerFrame = requestAnimationFrame(s);
@@ -420,15 +420,15 @@ class ae {
420
420
  this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
421
421
  }
422
422
  }
423
- class z extends v {
423
+ class W extends v {
424
424
  constructor(e) {
425
425
  super();
426
- r(this, "status");
427
- r(this, "session");
428
- r(this, "autostart");
429
- r(this, "config");
430
- r(this, "webRTCClient");
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) => {
426
+ i(this, "status");
427
+ i(this, "session");
428
+ i(this, "autostart");
429
+ i(this, "config");
430
+ i(this, "webRTCClient");
431
+ this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new oe(e), this.webRTCClient.addMessageCallback((s) => {
432
432
  const n = JSON.parse(s.data);
433
433
  this.notifyPacket(n);
434
434
  }), this.webRTCClient.addErrorCallback((s) => {
@@ -466,9 +466,9 @@ class z extends v {
466
466
  return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendPacket(e), Promise.resolve());
467
467
  }
468
468
  }
469
- class ie {
469
+ class re {
470
470
  constructor(t) {
471
- r(this, "config");
471
+ i(this, "config");
472
472
  this.config = t;
473
473
  }
474
474
  async complete(t, e) {
@@ -491,31 +491,29 @@ class ie {
491
491
  });
492
492
  }
493
493
  }
494
- class re {
494
+ class ie {
495
495
  constructor(t, e) {
496
- r(this, "transaction");
497
- r(this, "manager");
496
+ i(this, "transaction");
497
+ i(this, "manager");
498
498
  this.transaction = t, this.manager = e;
499
499
  }
500
500
  getFunctionCall() {
501
501
  return this.transaction.functionCall;
502
502
  }
503
503
  async invoke(t) {
504
- var i;
504
+ var r;
505
505
  const e = this.transaction.functionCall;
506
506
  if (!e) {
507
507
  await this.fail("No function call found");
508
508
  return;
509
509
  }
510
- const s = e.name, n = e.args, a = t[s];
511
- if (!a) {
510
+ const s = e.name, n = e.args, o = t[s];
511
+ if (!o) {
512
512
  await this.fail(`Tool ${s} not found`);
513
513
  return;
514
514
  }
515
515
  try {
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);
516
+ const u = (((r = o.toString().replace(/\n/g, " ").match(/^[^(]*\(([^)]*)\)/)) == null ? void 0 : r[1].split(",").map((y) => y.trim()).filter(Boolean)) || []).map((y) => n[y]), d = await o.apply(null, u);
519
517
  await this.complete(d);
520
518
  } catch (c) {
521
519
  await this.fail(`Error executing tool ${s}: ${c}`);
@@ -531,12 +529,12 @@ class re {
531
529
  class ce extends v {
532
530
  constructor(e) {
533
531
  super();
534
- r(this, "status");
535
- r(this, "autostart");
536
- r(this, "session");
537
- r(this, "config");
538
- r(this, "notify", !0);
539
- r(this, "_tools");
532
+ i(this, "status");
533
+ i(this, "autostart");
534
+ i(this, "session");
535
+ i(this, "config");
536
+ i(this, "notify", !0);
537
+ i(this, "_tools");
540
538
  if (this.config = e, this.status = "disconnected", this.autostart = !0, Array.isArray(e.tools)) {
541
539
  this._tools = {};
542
540
  for (const s of e.tools)
@@ -563,136 +561,143 @@ class ce extends v {
563
561
  }
564
562
  onTransaction(e) {
565
563
  console.log("transaction received:", e);
566
- const s = new ie(this.config), n = new re(e, s);
564
+ const s = new re(this.config), n = new ie(e, s);
567
565
  this.config.onTransaction ? this.config.onTransaction(n) : n.invoke(this._tools);
568
566
  }
569
567
  getTools() {
570
568
  return this._tools;
571
569
  }
572
570
  }
573
- const x = Y(void 0);
574
- function le(o) {
571
+ const R = Y(void 0);
572
+ function le(a) {
575
573
  return new Promise((t, e) => {
576
574
  const s = new FileReader();
577
- s.readAsDataURL(o), s.onload = () => {
578
- const a = s.result.split(";base64,")[1];
579
- t(a);
575
+ s.readAsDataURL(a), s.onload = () => {
576
+ const o = s.result.split(";base64,")[1];
577
+ t(o);
580
578
  }, s.onerror = (n) => {
581
579
  e(n);
582
580
  };
583
581
  });
584
582
  }
585
583
  function ue({
586
- dev: o = !1,
584
+ dev: a = !1,
587
585
  baseUrl: t,
588
586
  protocols: e,
589
587
  logger: s,
590
588
  children: n,
591
- session: a = "new",
592
- ...i
589
+ session: o = "new",
590
+ ...r
593
591
  }) {
594
- const [c, u] = E(!1), [d, g] = E([]), [w, R] = E(a), [b, $] = E(/* @__PURE__ */ new Map()), q = G(!1), S = H(() => {
592
+ const [c, u] = A(!1), [d, y] = A([]), [S, T] = A(o), [C, $] = A(/* @__PURE__ */ new Map()), q = G(!1), b = H(() => {
595
593
  if (Array.isArray(e))
596
594
  return e;
597
595
  if (typeof e == "object" && e !== null) {
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) {
596
+ const l = a ? "localhost:8000" : t || "persona.applica.guru/api", m = a ? "http" : "https", p = a ? "ws" : "wss";
597
+ let g = Object.keys(e).map((f) => {
598
+ switch (f) {
601
599
  case "rest":
602
- const p = e[y];
603
- return p === !0 ? new _({
600
+ const w = e[f];
601
+ return w === !0 ? new _({
604
602
  apiUrl: `${m}://${l}`,
605
- apiKey: i.apiKey,
606
- agentId: i.agentId,
603
+ apiKey: r.apiKey,
604
+ agentId: r.agentId,
607
605
  logger: s
608
- }) : typeof p == "object" && p !== null ? new _(p) : null;
606
+ }) : typeof w == "object" && w !== null ? new _(w) : null;
609
607
  case "webrtc":
610
- const C = e[y];
611
- return C === !0 ? new z({
612
- webrtcUrl: `${h}://${l}/webrtc`,
613
- apiKey: i.apiKey,
614
- agentId: i.agentId,
608
+ const h = e[f];
609
+ return h === !0 ? new W({
610
+ webrtcUrl: `${p}://${l}/webrtc`,
611
+ apiKey: r.apiKey,
612
+ agentId: r.agentId,
615
613
  logger: s
616
- }) : typeof C == "object" && C !== null ? new z(C) : null;
614
+ }) : typeof h == "object" && h !== null ? new W(h) : null;
617
615
  case "websocket":
618
- const T = e[y];
619
- return T === !0 ? new W({
620
- webSocketUrl: `${h}://${l}/websocket`,
621
- apiKey: i.apiKey,
622
- agentId: i.agentId,
616
+ const P = e[f];
617
+ return P === !0 ? new U({
618
+ webSocketUrl: `${p}://${l}/websocket`,
619
+ apiKey: r.apiKey,
620
+ agentId: r.agentId,
623
621
  logger: s
624
- }) : typeof T == "object" && T !== null ? new W(T) : null;
622
+ }) : typeof P == "object" && P !== null ? new U(P) : null;
625
623
  default:
626
- throw new Error(`Unknown protocol: ${y}`);
624
+ throw new Error(`Unknown protocol: ${f}`);
627
625
  }
628
- }).filter((y) => y !== null);
629
- return i.tools && f.push(
626
+ }).filter((f) => f !== null);
627
+ return r.tools && g.push(
630
628
  new ce({
631
629
  apiUrl: `${m}://${l}`,
632
- apiKey: i.apiKey,
633
- agentId: i.agentId,
634
- tools: i.tools,
630
+ apiKey: r.apiKey,
631
+ agentId: r.agentId,
632
+ tools: r.tools,
635
633
  // Pass raw tools
636
634
  logger: s
637
635
  })
638
- ), f;
636
+ ), g;
639
637
  }
640
638
  throw new Error("Invalid protocols configuration");
641
639
  }, []);
642
640
  Q(() => {
643
641
  q.current || (q.current = !0, s == null || s.debug(
644
642
  "Initializing protocols: ",
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({
643
+ b.map((l) => l.getName())
644
+ ), b.forEach((l) => {
645
+ l.setSession(S), l.clearListeners(), l.addStatusChangeListener((m) => {
646
+ s == null || s.debug(`${l.getName()} has notified new status: ${m}`), C.set(l.getName(), m), m === "connected" && (r.context && l.sendPacket({
649
647
  type: "command",
650
648
  payload: {
651
649
  command: "set_initial_context",
652
- arguments: i.context
650
+ arguments: r.context
653
651
  }
654
- }), i.tools && Array.isArray(i.tools) && l.sendPacket({
652
+ }), r.tools && Array.isArray(r.tools) && l.sendPacket({
655
653
  type: "command",
656
654
  payload: {
657
655
  command: "set_local_tools",
658
656
  arguments: {
659
- tools: i.tools.map((h) => h.schema)
657
+ tools: r.tools.map((p) => p.schema)
660
658
  }
661
659
  }
662
- })), $(new Map(b));
660
+ })), $(new Map(C));
663
661
  }), l.addPacketListener((m) => {
664
662
  if (m.type === "message") {
665
- const h = m.payload;
666
- g(
667
- (f) => j([...f, { ...h, protocol: l.getName() }])
663
+ const p = m.payload;
664
+ y(
665
+ (g) => j([...g, { ...p, protocol: l.getName() }])
668
666
  );
669
667
  } else if (m.type === "reasoning") {
670
- const h = m.payload;
671
- let f = h.thought;
672
- h.imageUrl && (f += `
668
+ const p = m.payload;
669
+ let g = p.thought;
670
+ p.imageUrl && (g += `
673
671
 
674
- ![image](https://persona.applica.guru/api/files/${h.imageUrl})`);
675
- const y = { type: "reasoning", text: f, role: "assistant", finishReason: "stop" };
676
- g(
677
- (p) => j([...p, { ...y, protocol: l.getName() }])
672
+ ![image](https://persona.applica.guru/api/files/${p.imageUrl})`);
673
+ const f = { type: "reasoning", text: g, role: "assistant", finishReason: "stop" };
674
+ y(
675
+ (w) => j([...w, { ...f, protocol: l.getName() }])
678
676
  );
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));
677
+ } else m.type === "transaction" && b.filter((p) => p !== l).forEach((p) => p.onTransaction(m.payload));
678
+ }), l.autostart && l.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${l.getName()}`), l.connect(S));
681
679
  }));
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 = [];
680
+ }, [S, b, s, C]);
681
+ const F = async (l) => {
682
+ var w;
683
+ if (((w = l.content[0]) == null ? void 0 : w.type) !== "text") throw new Error("Only text messages are supported");
684
+ if (!b.some((h) => h.getName() !== "transaction" && h.status === "connected")) {
685
+ y((h) => [
686
+ ...h,
687
+ { role: "assistant", type: "text", text: "No protocol is connected." }
688
+ ]);
689
+ return;
690
+ }
691
+ const p = l.content[0].text;
692
+ y((h) => [...h, { role: "user", type: "text", text: p }]), u(!0);
693
+ const g = b.sort((h, P) => P.getPriority() - h.getPriority()).find((h) => h.status === "connected"), f = [];
689
694
  if (l.attachments)
690
- for (const p of l.attachments)
691
- p.contentType.startsWith("image/") && p.file && f.push({
695
+ for (const h of l.attachments)
696
+ h.contentType.startsWith("image/") && h.file && f.push({
692
697
  role: "user",
693
698
  image: {
694
- contentType: p.contentType,
695
- content: await le(p.file)
699
+ contentType: h.contentType,
700
+ content: await le(h.file)
696
701
  },
697
702
  text: "",
698
703
  type: "text"
@@ -701,34 +706,34 @@ function ue({
701
706
  role: "user",
702
707
  text: l.content[0].text,
703
708
  type: "text"
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({
709
+ }), s == null || s.debug("Sending message:", f), await (g == null ? void 0 : g.sendPacket({ type: "request", payload: f })), u(!1);
710
+ }, D = N(() => (u(!1), y([]), T("new"), Promise.resolve()), []), L = N(() => Promise.resolve(), []), J = N(() => d, [d]), K = X({
706
711
  isRunning: c,
707
712
  messages: d,
708
- convertMessage: oe,
709
- onNew: U,
713
+ convertMessage: ae,
714
+ onNew: F,
710
715
  onCancel: D,
711
716
  onReload: L,
712
717
  adapters: {
713
718
  attachments: new Z([new ee()])
714
719
  }
715
720
  });
716
- return /* @__PURE__ */ M.jsx(x.Provider, { value: { protocols: S, protocolsStatus: b, getMessages: J }, children: /* @__PURE__ */ M.jsx(te, { runtime: K, children: n }) });
721
+ return /* @__PURE__ */ M.jsx(R.Provider, { value: { protocols: b, protocolsStatus: C, getMessages: J }, children: /* @__PURE__ */ M.jsx(te, { runtime: K, children: n }) });
717
722
  }
718
- function ge({ children: o, ...t }) {
719
- return /* @__PURE__ */ M.jsx(ue, { ...t, children: o });
723
+ function ge({ children: a, ...t }) {
724
+ return /* @__PURE__ */ M.jsx(ue, { ...t, children: a });
720
725
  }
721
726
  function we() {
722
- const o = A(x);
723
- if (!o)
727
+ const a = E(R);
728
+ if (!a)
724
729
  throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
725
- return o;
730
+ return a;
726
731
  }
727
- function he(o) {
728
- const t = A(x);
732
+ function he(a) {
733
+ const t = E(R);
729
734
  if (!t)
730
735
  throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
731
- const e = t.protocols.find((n) => n.getName() === o);
736
+ const e = t.protocols.find((n) => n.getName() === a);
732
737
  if (!e)
733
738
  return null;
734
739
  const s = t.protocolsStatus.get(e.getName());
@@ -746,26 +751,33 @@ function he(o) {
746
751
  };
747
752
  }
748
753
  function be() {
749
- const o = A(x);
750
- if (!o)
754
+ const a = E(R);
755
+ if (!a)
751
756
  throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
752
- for (const t of o.protocols)
753
- if (t.getName() === "rest")
754
- return t.config.apiUrl;
755
- throw new Error("REST protocol not found");
757
+ const t = {
758
+ rest: (e) => e.config.apiUrl,
759
+ webrtc: (e) => e.config.webrtcUrl.replace("/webrtc", "").replace("ws://", "http://").replace("wss://", "https://"),
760
+ websocket: (e) => e.config.webSocketUrl.replace("/websocket", "").replace("ws://", "http://").replace("wss://", "https://")
761
+ };
762
+ for (const e of a.protocols) {
763
+ const s = t[e.getName()];
764
+ if (s)
765
+ return s(e);
766
+ }
767
+ return null;
756
768
  }
757
769
  function Se() {
758
770
  return he("webrtc");
759
771
  }
760
772
  function Ce() {
761
- const o = A(x);
762
- if (!o)
773
+ const a = E(R);
774
+ if (!a)
763
775
  throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
764
- return o.getMessages();
776
+ return a.getMessages();
765
777
  }
766
778
  class Pe {
767
779
  constructor() {
768
- r(this, "prefix", "[Persona]");
780
+ i(this, "prefix", "[Persona]");
769
781
  }
770
782
  log(t, ...e) {
771
783
  console.log(`${this.prefix} - ${t}`, ...e);
@@ -783,52 +795,52 @@ class Pe {
783
795
  console.debug(`${this.prefix} - ${t}`, ...e);
784
796
  }
785
797
  }
786
- function P(o, t, e) {
798
+ function k(a, t, e) {
787
799
  return {
788
- type: o,
800
+ type: a,
789
801
  description: t,
790
802
  ...e
791
803
  };
792
804
  }
793
- function de(o) {
794
- const t = Object.entries(o.parameters).filter(([e, s]) => s.required).map(([e]) => e);
805
+ function de(a) {
806
+ const t = Object.entries(a.parameters).filter(([e, s]) => s.required).map(([e]) => e);
795
807
  return {
796
808
  type: "local",
797
- name: o.name,
798
- description: o.description,
809
+ name: a.name,
810
+ description: a.description,
799
811
  config: {
800
- timeout: o.timeout || 60,
812
+ timeout: a.timeout || 60,
801
813
  parameters: {
802
814
  type: "object",
803
- title: o.title || `${o.name} parameters`,
815
+ title: a.title || `${a.name} parameters`,
804
816
  required: t,
805
- properties: o.parameters
817
+ properties: a.parameters
806
818
  },
807
819
  output: {
808
820
  type: "object",
809
- title: `${o.name} output`,
810
- properties: o.output
821
+ title: `${a.name} output`,
822
+ properties: a.output
811
823
  }
812
824
  }
813
825
  };
814
826
  }
815
- function I(o) {
827
+ function I(a) {
816
828
  return {
817
- schema: de(o),
818
- implementation: o.implementation
829
+ schema: de(a),
830
+ implementation: a.implementation
819
831
  };
820
832
  }
821
- function pe(o, t, e, s, n, a) {
822
- const i = {
823
- name: o,
833
+ function pe(a, t, e, s, n, o) {
834
+ const r = {
835
+ name: a,
824
836
  description: t,
825
- title: a == null ? void 0 : a.title,
826
- timeout: a == null ? void 0 : a.timeout,
837
+ title: o == null ? void 0 : o.title,
838
+ timeout: o == null ? void 0 : o.timeout,
827
839
  parameters: s,
828
840
  output: n,
829
841
  implementation: e
830
842
  };
831
- return I(i);
843
+ return I(r);
832
844
  }
833
845
  const ke = pe(
834
846
  "sum",
@@ -837,11 +849,11 @@ const ke = pe(
837
849
  return { result: t + e };
838
850
  },
839
851
  {
840
- a: P("number", "First number to sum", { required: !0 }),
841
- b: P("number", "Second number to sum", { required: !0 })
852
+ a: k("number", "First number to sum", { required: !0 }),
853
+ b: k("number", "Second number to sum", { required: !0 })
842
854
  },
843
855
  {
844
- result: P("number", "Sum of two numbers")
856
+ result: k("number", "Sum of two numbers")
845
857
  }
846
858
  ), xe = I({
847
859
  name: "navigate_to",
@@ -850,37 +862,37 @@ const ke = pe(
850
862
  // As per the user's example
851
863
  timeout: 60,
852
864
  parameters: {
853
- a: P("number", "First number to sum"),
854
- b: P("number", "Seconth number to sum")
865
+ a: k("number", "First number to sum"),
866
+ b: k("number", "Seconth number to sum")
855
867
  // Keeping the typo as in the original
856
868
  },
857
869
  output: {
858
- result: P("number", "Sum of two numbers")
870
+ result: k("number", "Sum of two numbers")
859
871
  },
860
872
  implementation: function(t, e) {
861
873
  return { result: t + e };
862
874
  }
863
875
  });
864
- function Re(o) {
876
+ function Re(a) {
865
877
  const t = [], e = {};
866
- return o.forEach((s) => {
867
- const { schema: n, implementation: a } = I(s);
868
- t.push(n), e[s.name] = a;
878
+ return a.forEach((s) => {
879
+ const { schema: n, implementation: o } = I(s);
880
+ t.push(n), e[s.name] = o;
869
881
  }), { schemas: t, implementations: e };
870
882
  }
871
- function Te(o, t) {
883
+ function Te(a, t) {
872
884
  const { required: e, properties: s } = t.config.parameters;
873
885
  for (const n of e)
874
- if (!(n in o))
886
+ if (!(n in a))
875
887
  throw new Error(`Missing required parameter: ${n}`);
876
- for (const [n, a] of Object.entries(o)) {
877
- const i = s[n];
878
- if (i) {
879
- if (i.type === "number" && typeof a != "number")
888
+ for (const [n, o] of Object.entries(a)) {
889
+ const r = s[n];
890
+ if (r) {
891
+ if (r.type === "number" && typeof o != "number")
880
892
  throw new Error(`Parameter ${n} should be a number`);
881
- if (i.type === "string" && typeof a != "string")
893
+ if (r.type === "string" && typeof o != "string")
882
894
  throw new Error(`Parameter ${n} should be a string`);
883
- if (i.type === "boolean" && typeof a != "boolean")
895
+ if (r.type === "boolean" && typeof o != "boolean")
884
896
  throw new Error(`Parameter ${n} should be a boolean`);
885
897
  }
886
898
  }
@@ -892,9 +904,9 @@ export {
892
904
  _ as PersonaRESTProtocol,
893
905
  ge as PersonaRuntimeProvider,
894
906
  ce as PersonaTransactionProtocol,
895
- z as PersonaWebRTCProtocol,
896
- W as PersonaWebSocketProtocol,
897
- P as createParameter,
907
+ W as PersonaWebRTCProtocol,
908
+ U as PersonaWebSocketProtocol,
909
+ k as createParameter,
898
910
  I as createTool,
899
911
  pe as createToolFromFunction,
900
912
  Re as createToolRegistry,