@applica-software-guru/persona-sdk 0.1.44-preview8 → 0.1.44

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,298 +1,86 @@
1
- var ie = Object.defineProperty;
2
- var ce = (r, t, e) => t in r ? ie(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var i = (r, t, e) => ce(r, typeof t != "symbol" ? t + "" : t, e);
4
- import le, { createContext as ue, useContext as ne, useState as j, useRef as de, useMemo as he, useEffect as fe, useCallback as Z } from "react";
5
- import { useExternalStoreRuntime as me, AssistantRuntimeProvider as pe } from "@assistant-ui/react";
6
- var re = { exports: {} }, x = {}, Q;
7
- function ge() {
8
- if (Q) return x;
9
- Q = 1;
10
- /**
11
- * @license React
12
- * react-jsx-runtime.development.js
13
- *
14
- * Copyright (c) Meta Platforms, Inc. and affiliates.
15
- *
16
- * This source code is licensed under the MIT license found in the
17
- * LICENSE file in the root directory of this source tree.
18
- */
19
- return function() {
20
- function r(s) {
21
- if (s == null) return null;
22
- if (typeof s == "function")
23
- return s.$$typeof === I ? null : s.displayName || s.name || null;
24
- if (typeof s == "string") return s;
25
- switch (s) {
26
- case R:
27
- return "Fragment";
28
- case M:
29
- return "Profiler";
30
- case $:
31
- return "StrictMode";
32
- case y:
33
- return "Suspense";
34
- case S:
35
- return "SuspenseList";
36
- case P:
37
- return "Activity";
38
- }
39
- if (typeof s == "object")
40
- switch (typeof s.tag == "number" && console.error(
41
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
42
- ), s.$$typeof) {
43
- case _:
44
- return "Portal";
45
- case W:
46
- return (s.displayName || "Context") + ".Provider";
47
- case D:
48
- return (s._context.displayName || "Context") + ".Consumer";
49
- case u:
50
- var a = s.render;
51
- return s = s.displayName, s || (s = a.displayName || a.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
52
- case T:
53
- return a = s.displayName || null, a !== null ? a : r(s.type) || "Memo";
54
- case b:
55
- a = s._payload, s = s._init;
56
- try {
57
- return r(s(a));
58
- } catch {
59
- }
60
- }
61
- return null;
62
- }
63
- function t(s) {
64
- return "" + s;
65
- }
66
- function e(s) {
67
- try {
68
- t(s);
69
- var a = !1;
70
- } catch {
71
- a = !0;
72
- }
73
- if (a) {
74
- a = console;
75
- var l = a.error, m = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
76
- return l.call(
77
- a,
78
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
79
- m
80
- ), t(s);
81
- }
82
- }
83
- function n(s) {
84
- if (s === R) return "<>";
85
- if (typeof s == "object" && s !== null && s.$$typeof === b)
86
- return "<...>";
87
- try {
88
- var a = r(s);
89
- return a ? "<" + a + ">" : "<...>";
90
- } catch {
91
- return "<...>";
92
- }
93
- }
94
- function o() {
95
- var s = A.A;
96
- return s === null ? null : s.getOwner();
97
- }
98
- function c() {
99
- return Error("react-stack-top-frame");
100
- }
101
- function d(s) {
102
- if (J.call(s, "key")) {
103
- var a = Object.getOwnPropertyDescriptor(s, "key").get;
104
- if (a && a.isReactWarning) return !1;
105
- }
106
- return s.key !== void 0;
107
- }
108
- function g(s, a) {
109
- function l() {
110
- B || (B = !0, console.error(
111
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
112
- a
113
- ));
114
- }
115
- l.isReactWarning = !0, Object.defineProperty(s, "key", {
116
- get: l,
117
- configurable: !0
118
- });
119
- }
120
- function h() {
121
- var s = r(this.type);
122
- return V[s] || (V[s] = !0, console.error(
123
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
124
- )), s = this.props.ref, s !== void 0 ? s : null;
125
- }
126
- function f(s, a, l, m, E, C, L, F) {
127
- return l = C.ref, s = {
128
- $$typeof: N,
129
- type: s,
130
- key: a,
131
- props: C,
132
- _owner: E
133
- }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(s, "ref", {
134
- enumerable: !1,
135
- get: h
136
- }) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
137
- configurable: !1,
138
- enumerable: !1,
139
- writable: !0,
140
- value: 0
141
- }), Object.defineProperty(s, "_debugInfo", {
142
- configurable: !1,
143
- enumerable: !1,
144
- writable: !0,
145
- value: null
146
- }), Object.defineProperty(s, "_debugStack", {
147
- configurable: !1,
148
- enumerable: !1,
149
- writable: !0,
150
- value: L
151
- }), Object.defineProperty(s, "_debugTask", {
152
- configurable: !1,
153
- enumerable: !1,
154
- writable: !0,
155
- value: F
156
- }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
157
- }
158
- function w(s, a, l, m, E, C, L, F) {
159
- var p = a.children;
160
- if (p !== void 0)
161
- if (m)
162
- if (ae(p)) {
163
- for (m = 0; m < p.length; m++)
164
- O(p[m]);
165
- Object.freeze && Object.freeze(p);
166
- } else
167
- console.error(
168
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
169
- );
170
- else O(p);
171
- if (J.call(a, "key")) {
172
- p = r(s);
173
- var v = Object.keys(a).filter(function(oe) {
174
- return oe !== "key";
175
- });
176
- m = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", H[p + m] || (v = 0 < v.length ? "{" + v.join(": ..., ") + ": ...}" : "{}", console.error(
177
- `A props object containing a "key" prop is being spread into JSX:
178
- let props = %s;
179
- <%s {...props} />
180
- React keys must be passed directly to JSX without using spread:
181
- let props = %s;
182
- <%s key={someKey} {...props} />`,
183
- m,
184
- p,
185
- v,
186
- p
187
- ), H[p + m] = !0);
188
- }
189
- if (p = null, l !== void 0 && (e(l), p = "" + l), d(a) && (e(a.key), p = "" + a.key), "key" in a) {
190
- l = {};
191
- for (var U in a)
192
- U !== "key" && (l[U] = a[U]);
193
- } else l = a;
194
- return p && g(
195
- l,
196
- typeof s == "function" ? s.displayName || s.name || "Unknown" : s
197
- ), f(
198
- s,
199
- p,
200
- C,
201
- E,
202
- o(),
203
- l,
204
- L,
205
- F
206
- );
207
- }
208
- function O(s) {
209
- typeof s == "object" && s !== null && s.$$typeof === N && s._store && (s._store.validated = 1);
210
- }
211
- var k = le, N = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), R = Symbol.for("react.fragment"), $ = Symbol.for("react.strict_mode"), M = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), W = Symbol.for("react.context"), u = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), S = Symbol.for("react.suspense_list"), T = Symbol.for("react.memo"), b = Symbol.for("react.lazy"), P = Symbol.for("react.activity"), I = Symbol.for("react.client.reference"), A = k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ae = Array.isArray, z = console.createTask ? console.createTask : function() {
212
- return null;
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 C, useRef as _, useMemo as B, useEffect as K, useCallback as v } from "react";
5
+ import { useExternalStoreRuntime as Y, AssistantRuntimeProvider as G } from "@assistant-ui/react";
6
+ var z = { exports: {} }, w = {};
7
+ /**
8
+ * @license React
9
+ * react-jsx-runtime.production.js
10
+ *
11
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
12
+ *
13
+ * This source code is licensed under the MIT license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ */
16
+ var M;
17
+ function V() {
18
+ if (M) return w;
19
+ M = 1;
20
+ var i = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
21
+ function e(s, n, a) {
22
+ var r = null;
23
+ if (a !== void 0 && (r = "" + a), n.key !== void 0 && (r = "" + n.key), "key" in n) {
24
+ a = {};
25
+ for (var l in n)
26
+ l !== "key" && (a[l] = n[l]);
27
+ } else a = n;
28
+ return n = a.ref, {
29
+ $$typeof: i,
30
+ type: s,
31
+ key: r,
32
+ ref: n !== void 0 ? n : null,
33
+ props: a
213
34
  };
214
- k = {
215
- "react-stack-bottom-frame": function(s) {
216
- return s();
217
- }
218
- };
219
- var B, V = {}, G = k["react-stack-bottom-frame"].bind(
220
- k,
221
- c
222
- )(), X = z(n(c)), H = {};
223
- x.Fragment = R, x.jsx = function(s, a, l, m, E) {
224
- var C = 1e4 > A.recentlyCreatedOwnerStacks++;
225
- return w(
226
- s,
227
- a,
228
- l,
229
- !1,
230
- m,
231
- E,
232
- C ? Error("react-stack-top-frame") : G,
233
- C ? z(n(s)) : X
234
- );
235
- }, x.jsxs = function(s, a, l, m, E) {
236
- var C = 1e4 > A.recentlyCreatedOwnerStacks++;
237
- return w(
238
- s,
239
- a,
240
- l,
241
- !0,
242
- m,
243
- E,
244
- C ? Error("react-stack-top-frame") : G,
245
- C ? z(n(s)) : X
246
- );
247
- };
248
- }(), x;
35
+ }
36
+ return w.Fragment = t, w.jsx = e, w.jsxs = e, w;
249
37
  }
250
- re.exports = ge();
251
- var Y = re.exports;
252
- function be(r) {
253
- return r.filter((t) => {
38
+ z.exports = V();
39
+ var k = z.exports;
40
+ function H(i) {
41
+ return i.filter((t) => {
254
42
  var e;
255
43
  return t.finishReason === "stop" ? t.text !== null && ((e = t.text) == null ? void 0 : e.trim()) !== "" : !0;
256
44
  });
257
45
  }
258
- function we(r) {
46
+ function Q(i) {
259
47
  const t = [];
260
48
  let e = null;
261
- for (const n of r)
262
- 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] = {
49
+ for (const s of i)
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] = {
263
51
  ...t[t.length - 1],
264
- functionResponse: n.functionResponse
265
- } : e && n.protocol === e.protocol && (e.role === n.role || n.finishReason === "stop") ? e.text += n.text : (e && t.push(e), e = {
266
- ...n
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 = {
54
+ ...s
267
55
  });
268
- return e && t.push(e), be(t);
56
+ return e && t.push(e), H(t);
269
57
  }
270
- function ye(r) {
58
+ function X(i) {
271
59
  var t;
272
- return r.role === "function" ? {
273
- id: r.id,
60
+ return i.role === "function" ? {
61
+ id: i.id,
274
62
  role: "assistant",
275
- status: (r == null ? void 0 : r.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
276
- content: ((t = r.functionCalls) == null ? void 0 : t.map((e) => {
277
- var n;
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;
278
66
  return {
279
67
  type: "tool-call",
280
68
  toolName: e.name,
281
69
  toolCallId: e.id,
282
70
  args: e.args,
283
- result: (n = r.functionResponse) == null ? void 0 : n.result
71
+ result: (s = i.functionResponse) == null ? void 0 : s.result
284
72
  };
285
73
  })) ?? []
286
74
  } : {
287
- id: r.id,
288
- role: r.role,
289
- content: r.type === "reasoning" ? [{ type: "reasoning", text: r.text }] : [{ type: "text", text: r.text }]
75
+ id: i.id,
76
+ role: i.role,
77
+ content: i.type === "reasoning" ? [{ type: "reasoning", text: i.text }] : [{ type: "text", text: i.text }]
290
78
  };
291
79
  }
292
- class K {
80
+ class x {
293
81
  constructor() {
294
- i(this, "statusChangeCallbacks", []);
295
- i(this, "messageCallbacks", []);
82
+ o(this, "statusChangeCallbacks", []);
83
+ o(this, "messageCallbacks", []);
296
84
  }
297
85
  addStatusChangeListener(t) {
298
86
  this.statusChangeCallbacks.push(t);
@@ -308,7 +96,7 @@ class K {
308
96
  }
309
97
  async notifyMessages(t) {
310
98
  t.forEach((e) => {
311
- this.messageCallbacks.forEach((n) => n(e));
99
+ this.messageCallbacks.forEach((s) => s(e));
312
100
  });
313
101
  }
314
102
  async setSession(t) {
@@ -316,20 +104,20 @@ class K {
316
104
  }
317
105
  async setStatus(t) {
318
106
  const e = this.status !== t;
319
- this.status = t, e && this.statusChangeCallbacks.forEach((n) => n(t));
107
+ this.status = t, e && this.statusChangeCallbacks.forEach((s) => s(t));
320
108
  }
321
109
  clearListeners() {
322
110
  this.statusChangeCallbacks = [], this.messageCallbacks = [];
323
111
  }
324
112
  }
325
- class ee extends K {
113
+ class T extends x {
326
114
  constructor(e) {
327
115
  super();
328
- i(this, "status");
329
- i(this, "autostart");
330
- i(this, "session");
331
- i(this, "config");
332
- i(this, "notify", !0);
116
+ o(this, "status");
117
+ o(this, "autostart");
118
+ o(this, "session");
119
+ o(this, "config");
120
+ o(this, "notify", !0);
333
121
  this.config = e, this.status = "disconnected", this.autostart = !0;
334
122
  }
335
123
  getName() {
@@ -348,26 +136,26 @@ class ee extends K {
348
136
  this.session = e;
349
137
  }
350
138
  async send(e) {
351
- const { apiUrl: n, apiKey: o, agentId: c } = this.config, d = this.session ?? "new", g = e, f = await (await fetch(`${n}/agents/${c}/sessions/${d}/messages`, {
352
- body: JSON.stringify({ userMessage: g }),
139
+ const { apiUrl: s, apiKey: n, agentId: a } = this.config, r = this.session ?? "new", l = e, h = await (await fetch(`${s}/agents/${a}/sessions/${r}/messages`, {
140
+ body: JSON.stringify({ userMessage: l }),
353
141
  method: "POST",
354
142
  headers: {
355
143
  "Content-Type": "application/json",
356
- "x-fox-apikey": o,
357
- "x-persona-apikey": o
144
+ "x-fox-apikey": n,
145
+ "x-persona-apikey": n
358
146
  }
359
147
  })).json();
360
- this.notifyMessages(f.response.messages);
148
+ this.notifyMessages(h.response.messages);
361
149
  }
362
150
  }
363
- class te extends K {
151
+ class I extends x {
364
152
  constructor(e) {
365
153
  super();
366
- i(this, "status");
367
- i(this, "autostart");
368
- i(this, "session");
369
- i(this, "config");
370
- i(this, "webSocket");
154
+ o(this, "status");
155
+ o(this, "autostart");
156
+ o(this, "session");
157
+ o(this, "config");
158
+ o(this, "webSocket");
371
159
  this.config = e, this.status = "disconnected", this.autostart = !0, this.session = null, this.webSocket = null;
372
160
  }
373
161
  getName() {
@@ -377,31 +165,31 @@ class te extends K {
377
165
  return 1;
378
166
  }
379
167
  async syncSession(e) {
380
- var n;
381
- (n = this.config.logger) == null || n.debug("Syncing session with WebSocket protocol:", e), this.session = e, this.webSocket && this.status === "connected" && (this.disconnect(), this.connect(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));
382
170
  }
383
171
  connect(e) {
384
- var g;
172
+ var l;
385
173
  if (this.webSocket !== null && this.status === "connected")
386
174
  return Promise.resolve(this.session);
387
- const n = e || this.session || "new";
388
- (g = this.config.logger) == null || g.debug("Connecting to WebSocket with sessionId:", n);
389
- const o = encodeURIComponent(this.config.apiKey), c = this.config.agentId, d = `${this.config.webSocketUrl}?sessionCode=${n}&agentId=${c}&apiKey=${o}`;
390
- return this.setStatus("connecting"), this.webSocket = new WebSocket(d), this.webSocket.addEventListener("open", () => {
175
+ const s = e || this.session || "new";
176
+ (l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", s);
177
+ const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
178
+ return this.setStatus("connecting"), this.webSocket = new WebSocket(r), this.webSocket.addEventListener("open", () => {
391
179
  this.setStatus("connected");
392
- }), this.webSocket.addEventListener("message", (h) => {
393
- const f = JSON.parse(h.data);
394
- if (f.type !== "message")
180
+ }), this.webSocket.addEventListener("message", (u) => {
181
+ const h = JSON.parse(u.data);
182
+ if (h.type !== "message")
395
183
  return;
396
- const w = f.payload;
397
- this.notifyMessage(w != null && w.thought ? { role: "assistant", type: "reasoning", text: w.thought } : w);
184
+ const f = h.payload;
185
+ this.notifyMessage(f != null && f.thought ? { role: "assistant", type: "reasoning", text: f.thought } : f);
398
186
  }), this.webSocket.addEventListener("close", () => {
187
+ var u;
188
+ this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.warn("WebSocket connection closed");
189
+ }), this.webSocket.addEventListener("error", (u) => {
399
190
  var h;
400
- this.setStatus("disconnected"), this.webSocket = null, (h = this.config.logger) == null || h.warn("WebSocket connection closed");
401
- }), this.webSocket.addEventListener("error", (h) => {
402
- var f;
403
- this.setStatus("disconnected"), this.webSocket = null, (f = this.config.logger) == null || f.error("WebSocket error", h);
404
- }), Promise.resolve(n);
191
+ this.setStatus("disconnected"), this.webSocket = null, (h = this.config.logger) == null || h.error("WebSocket error", u);
192
+ }), Promise.resolve(s);
405
193
  }
406
194
  disconnect() {
407
195
  var e;
@@ -411,21 +199,21 @@ class te extends K {
411
199
  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"));
412
200
  }
413
201
  }
414
- class Se {
202
+ class Z {
415
203
  constructor(t) {
416
- i(this, "config");
417
- i(this, "pc", null);
418
- i(this, "ws", null);
419
- i(this, "localStream", null);
420
- i(this, "remoteStream", new MediaStream());
421
- i(this, "audioCtx", null);
422
- i(this, "localAnalyser", null);
423
- i(this, "remoteAnalyser", null);
424
- i(this, "analyzerFrame", null);
425
- i(this, "dataChannel", null);
426
- i(this, "isConnected", !1);
427
- i(this, "visualizerCallbacks", []);
428
- i(this, "messageCallbacks", []);
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", []);
429
217
  this.config = t;
430
218
  }
431
219
  async connect(t) {
@@ -434,8 +222,8 @@ class Se {
434
222
  this.isConnected = !0;
435
223
  try {
436
224
  this.localStream = await navigator.mediaDevices.getUserMedia({ audio: !0 });
437
- } catch (n) {
438
- (e = this.config.logger) == null || e.error("Error accessing microphone:", n);
225
+ } catch (s) {
226
+ (e = this.config.logger) == null || e.error("Error accessing microphone:", s);
439
227
  return;
440
228
  }
441
229
  this.pc = new RTCPeerConnection({
@@ -449,65 +237,65 @@ class Se {
449
237
  credential: "webrtc"
450
238
  }
451
239
  ]
452
- }), this.localStream.getTracks().forEach((n) => {
453
- this.pc.addTrack(n, this.localStream);
454
- }), this.pc.ontrack = (n) => {
455
- n.streams[0].getTracks().forEach((c) => {
456
- this.remoteStream.addTrack(c);
240
+ }), this.localStream.getTracks().forEach((s) => {
241
+ this.pc.addTrack(s, this.localStream);
242
+ }), this.pc.ontrack = (s) => {
243
+ s.streams[0].getTracks().forEach((a) => {
244
+ this.remoteStream.addTrack(a);
457
245
  }), this.audioCtx || this._startAnalyzers();
458
- const o = new Audio();
459
- o.srcObject = this.remoteStream, o.play().catch((c) => {
460
- var d;
461
- (d = this.config.logger) == null || d.error("Error playing remote audio:", c);
246
+ const n = new Audio();
247
+ n.srcObject = this.remoteStream, n.play().catch((a) => {
248
+ var r;
249
+ (r = this.config.logger) == null || r.error("Error playing remote audio:", a);
462
250
  });
463
- }, this.pc.onicecandidate = (n) => {
464
- var o;
465
- n.candidate && ((o = this.ws) == null ? void 0 : o.readyState) === WebSocket.OPEN && this.ws.send(
251
+ }, this.pc.onicecandidate = (s) => {
252
+ var n;
253
+ s.candidate && ((n = this.ws) == null ? void 0 : n.readyState) === WebSocket.OPEN && this.ws.send(
466
254
  JSON.stringify({
467
255
  type: "CANDIDATE",
468
256
  src: "client",
469
- payload: { candidate: n.candidate }
257
+ payload: { candidate: s.candidate }
470
258
  })
471
259
  );
472
- }, this.pc.ondatachannel = (n) => {
473
- const o = n.channel;
474
- o.onmessage = (c) => {
475
- this.messageCallbacks.forEach((d) => {
476
- d(c);
260
+ }, this.pc.ondatachannel = (s) => {
261
+ const n = s.channel;
262
+ n.onmessage = (a) => {
263
+ this.messageCallbacks.forEach((r) => {
264
+ r(a);
477
265
  });
478
266
  };
479
267
  }, this.ws = new WebSocket(this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc"), this.ws.onopen = async () => {
480
- var d, g;
481
- const n = await this.pc.createOffer();
482
- await this.pc.setLocalDescription(n);
483
- const o = {
268
+ var r, l;
269
+ const s = await this.pc.createOffer();
270
+ await this.pc.setLocalDescription(s);
271
+ const n = {
484
272
  agentId: this.config.agentId,
485
273
  sessionCode: t
486
274
  };
487
- (d = this.config.logger) == null || d.debug("Opening connection to WebRTC server: ", o);
488
- const c = {
275
+ (r = this.config.logger) == null || r.debug("Opening connection to WebRTC server: ", n);
276
+ const a = {
489
277
  type: "OFFER",
490
- src: ((g = crypto.randomUUID) == null ? void 0 : g.call(crypto)) || "client_" + Date.now(),
278
+ src: ((l = crypto.randomUUID) == null ? void 0 : l.call(crypto)) || "client_" + Date.now(),
491
279
  payload: {
492
280
  sdp: {
493
- sdp: n.sdp,
494
- type: n.type
281
+ sdp: s.sdp,
282
+ type: s.type
495
283
  },
496
284
  connectionId: (Date.now() % 1e6).toString(),
497
- metadata: o
285
+ metadata: n
498
286
  }
499
287
  };
500
- this.ws.send(JSON.stringify(c));
501
- }, this.ws.onmessage = async (n) => {
502
- var c;
503
- const o = JSON.parse(n.data);
504
- if (o.type === "ANSWER")
505
- await this.pc.setRemoteDescription(new RTCSessionDescription(o.payload.sdp));
506
- else if (o.type === "CANDIDATE")
288
+ this.ws.send(JSON.stringify(a));
289
+ }, this.ws.onmessage = async (s) => {
290
+ var a;
291
+ const n = JSON.parse(s.data);
292
+ if (n.type === "ANSWER")
293
+ await this.pc.setRemoteDescription(new RTCSessionDescription(n.payload.sdp));
294
+ else if (n.type === "CANDIDATE")
507
295
  try {
508
- await this.pc.addIceCandidate(new RTCIceCandidate(o.payload.candidate));
509
- } catch (d) {
510
- (c = this.config.logger) == null || c.error("Error adding ICE candidate:", d);
296
+ await this.pc.addIceCandidate(new RTCIceCandidate(n.payload.candidate));
297
+ } catch (r) {
298
+ (a = this.config.logger) == null || a.error("Error adding ICE candidate:", r);
511
299
  }
512
300
  }, this.ws.onclose = () => {
513
301
  this._stopAnalyzers();
@@ -529,18 +317,18 @@ class Se {
529
317
  var e;
530
318
  return (e = this.config.logger) == null ? void 0 : e.info("Data channel opened");
531
319
  }, this.dataChannel.onmessage = (e) => {
532
- this.messageCallbacks.forEach((n) => {
533
- n(e);
320
+ this.messageCallbacks.forEach((s) => {
321
+ s(e);
534
322
  });
535
323
  });
536
324
  }
537
325
  sendMessage(t) {
538
- var e, n;
326
+ var e, s;
539
327
  if (!this.dataChannel) {
540
328
  (e = this.config.logger) == null || e.warn("Data channel is not open, cannot send message");
541
329
  return;
542
330
  }
543
- this.dataChannel.send(t), (n = this.config.logger) == null || n.info("Sent message:", t);
331
+ this.dataChannel.send(t), (s = this.config.logger) == null || s.info("Sent message:", t);
544
332
  }
545
333
  _startAnalyzers() {
546
334
  if (!this.localStream || !this.remoteStream || this.visualizerCallbacks.length === 0)
@@ -548,38 +336,38 @@ class Se {
548
336
  this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
549
337
  const t = this.audioCtx.createMediaStreamSource(this.localStream), e = this.audioCtx.createMediaStreamSource(this.remoteStream);
550
338
  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);
551
- const n = () => {
339
+ const s = () => {
552
340
  if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
553
341
  return;
554
- const o = new Uint8Array(this.localAnalyser.frequencyBinCount), c = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
555
- this.localAnalyser.getByteFrequencyData(o), this.remoteAnalyser.getByteFrequencyData(c);
556
- const d = o.reduce((h, f) => h + f, 0) / o.length, g = c.reduce((h, f) => h + f, 0) / c.length;
557
- this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((h) => {
558
- h({
559
- localAmplitude: d,
560
- remoteAmplitude: g
342
+ const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
343
+ this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
344
+ const r = n.reduce((u, h) => u + h, 0) / n.length, l = a.reduce((u, h) => u + h, 0) / a.length;
345
+ this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
346
+ u({
347
+ localAmplitude: r,
348
+ remoteAmplitude: l
561
349
  });
562
- }), this.analyzerFrame = requestAnimationFrame(n);
350
+ }), this.analyzerFrame = requestAnimationFrame(s);
563
351
  };
564
- this.analyzerFrame = requestAnimationFrame(n);
352
+ this.analyzerFrame = requestAnimationFrame(s);
565
353
  }
566
354
  _stopAnalyzers() {
567
355
  this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
568
356
  }
569
357
  }
570
- class se extends K {
358
+ class $ extends x {
571
359
  constructor(e) {
572
360
  super();
573
- i(this, "status");
574
- i(this, "session");
575
- i(this, "autostart");
576
- i(this, "config");
577
- i(this, "webRTCClient");
578
- 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) => {
579
- var c;
580
- (c = e.logger) == null || c.debug("Received data message:", n.data);
581
- const o = JSON.parse(n.data);
582
- o.type === "message" && this.notifyMessage(o.payload);
361
+ o(this, "status");
362
+ o(this, "session");
363
+ o(this, "autostart");
364
+ o(this, "config");
365
+ o(this, "webRTCClient");
366
+ 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) => {
367
+ var a;
368
+ (a = e.logger) == null || a.debug("Received data message:", s.data);
369
+ const n = JSON.parse(s.data);
370
+ n.type === "message" && this.notifyMessage(n.payload);
583
371
  });
584
372
  }
585
373
  getName() {
@@ -592,112 +380,112 @@ class se extends K {
592
380
  super.syncSession(e), this.status === "connected" && (await this.disconnect(), await this.connect(e));
593
381
  }
594
382
  async connect(e) {
595
- var n;
596
- return this.status === "connected" ? Promise.resolve(this.session) : (this.session = e || this.session || "new", this.setStatus("connecting"), (n = this.config.logger) == null || n.debug("Connecting to WebRTC with sessionId:", this.session), await this.webRTCClient.connect(this.session), this.setStatus("connected"), await this.webRTCClient.createDataChannel(), this.session);
383
+ var s;
384
+ 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);
597
385
  }
598
386
  async disconnect() {
599
- var e, n, o;
387
+ var e, s, n;
600
388
  if (this.status === "disconnected")
601
389
  return (e = this.config.logger) == null || e.warn("Already disconnected"), Promise.resolve();
602
- await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (o = (n = this.config) == null ? void 0 : n.logger) == null || o.debug("Disconnected from WebRTC");
390
+ await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (n = (s = this.config) == null ? void 0 : s.logger) == null || n.debug("Disconnected from WebRTC");
603
391
  }
604
392
  send(e) {
605
393
  return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendMessage(e), Promise.resolve());
606
394
  }
607
395
  }
608
- const q = ue(void 0);
609
- function Ce({
610
- dev: r = !1,
396
+ const P = q(void 0);
397
+ function ee({
398
+ dev: i = !1,
611
399
  protocols: t,
612
400
  logger: e,
613
- children: n,
614
- session: o = "new",
615
- ...c
401
+ children: s,
402
+ session: n = "new",
403
+ ...a
616
404
  }) {
617
- const [d, g] = j(!1), [h, f] = j([]), [w, O] = j(o), [k, N] = j(/* @__PURE__ */ new Map()), _ = de(!1), R = he(() => {
405
+ const [r, l] = C(!1), [u, h] = C([]), [f, D] = C(n), [m, W] = C(/* @__PURE__ */ new Map()), R = _(!1), y = B(() => {
618
406
  if (Array.isArray(t))
619
407
  return t;
620
408
  if (typeof t == "object" && t !== null) {
621
- const u = r ? "localhost:8000" : "persona.applica.guru/api", y = r ? "http" : "https", S = r ? "ws" : "wss";
622
- return Object.keys(t).map((b) => {
623
- switch (b) {
409
+ const c = i ? "localhost:8000" : "persona.applica.guru/api", p = i ? "http" : "https", g = i ? "ws" : "wss";
410
+ return Object.keys(t).map((d) => {
411
+ switch (d) {
624
412
  case "rest":
625
- const P = t[b];
626
- return P === !0 ? new ee({
627
- apiUrl: `${y}://${u}`,
628
- apiKey: c.apiKey,
629
- agentId: c.agentId,
413
+ const b = t[d];
414
+ return b === !0 ? new T({
415
+ apiUrl: `${p}://${c}`,
416
+ apiKey: a.apiKey,
417
+ agentId: a.agentId,
630
418
  logger: e
631
- }) : new ee(P);
419
+ }) : new T(b);
632
420
  case "webrtc":
633
- const I = t[b];
634
- return I === !0 ? new se({
635
- webrtcUrl: `${S}://${u}/webrtc`,
636
- apiKey: c.apiKey,
637
- agentId: c.agentId,
421
+ const A = t[d];
422
+ return A === !0 ? new $({
423
+ webrtcUrl: `${g}://${c}/webrtc`,
424
+ apiKey: a.apiKey,
425
+ agentId: a.agentId,
638
426
  logger: e
639
- }) : new se(I);
427
+ }) : new $(A);
640
428
  case "websocket":
641
- const A = t[b];
642
- return A === !0 ? new te({
643
- webSocketUrl: `${S}://${u}/websocket`,
644
- apiKey: c.apiKey,
645
- agentId: c.agentId,
429
+ const E = t[d];
430
+ return E === !0 ? new I({
431
+ webSocketUrl: `${g}://${c}/websocket`,
432
+ apiKey: a.apiKey,
433
+ agentId: a.agentId,
646
434
  logger: e
647
- }) : new te(A);
435
+ }) : new I(E);
648
436
  default:
649
- throw new Error(`Unknown protocol: ${b}`);
437
+ throw new Error(`Unknown protocol: ${d}`);
650
438
  }
651
439
  });
652
440
  }
653
441
  throw new Error("Invalid protocols configuration");
654
442
  }, []);
655
- fe(() => {
656
- _.current || (_.current = !0, e == null || e.debug(
443
+ K(() => {
444
+ R.current || (R.current = !0, e == null || e.debug(
657
445
  "Initializing protocols: ",
658
- R.map((u) => u.getName())
659
- ), R.forEach((u) => {
660
- u.setSession(w), u.clearListeners(), u.addStatusChangeListener((y) => {
661
- e == null || e.debug(`${u.getName()} has notified new status: ${y}`), k.set(u.getName(), y), N(new Map(k));
662
- }), u.addMessageListener((y) => {
663
- f((S) => we([...S, { ...y, protocol: u.getName() }]));
664
- }), u.autostart && u.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${u.getName()}`), u.connect(w));
446
+ y.map((c) => c.getName())
447
+ ), y.forEach((c) => {
448
+ c.setSession(f), c.clearListeners(), c.addStatusChangeListener((p) => {
449
+ e == null || e.debug(`${c.getName()} has notified new status: ${p}`), m.set(c.getName(), p), W(new Map(m));
450
+ }), c.addMessageListener((p) => {
451
+ h((g) => Q([...g, { ...p, protocol: c.getName() }]));
452
+ }), c.autostart && c.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${c.getName()}`), c.connect(f));
665
453
  }));
666
- }, [w, R, e, k]);
667
- const $ = async (u) => {
668
- var T;
669
- if (((T = u.content[0]) == null ? void 0 : T.type) !== "text") throw new Error("Only text messages are supported");
670
- const y = u.content[0].text;
671
- f((b) => [...b, { role: "user", type: "text", text: y }]), g(!0);
672
- const S = R.sort((b, P) => P.getPriority() - b.getPriority()).find((b) => b.status === "connected");
673
- await (S == null ? void 0 : S.send(y)), g(!1);
674
- }, M = Z(() => (g(!1), f([]), O("new"), Promise.resolve()), []), D = Z(() => Promise.resolve(), []), W = me({
675
- isRunning: d,
676
- messages: h,
677
- convertMessage: ye,
678
- onNew: $,
679
- onCancel: M,
680
- onReload: D
454
+ }, [f, y, e, m]);
455
+ const L = async (c) => {
456
+ var S;
457
+ if (((S = c.content[0]) == null ? void 0 : S.type) !== "text") throw new Error("Only text messages are supported");
458
+ const p = c.content[0].text;
459
+ h((d) => [...d, { role: "user", type: "text", text: p }]), l(!0);
460
+ const g = y.sort((d, b) => b.getPriority() - d.getPriority()).find((d) => d.status === "connected");
461
+ await (g == null ? void 0 : g.send(p)), l(!1);
462
+ }, O = v(() => (l(!1), h([]), D("new"), Promise.resolve()), []), j = v(() => Promise.resolve(), []), F = Y({
463
+ isRunning: r,
464
+ messages: u,
465
+ convertMessage: X,
466
+ onNew: L,
467
+ onCancel: O,
468
+ onReload: j
681
469
  });
682
- return /* @__PURE__ */ Y.jsx(q.Provider, { value: { protocols: R, protocolsStatus: k }, children: /* @__PURE__ */ Y.jsx(pe, { runtime: W, children: n }) });
470
+ return /* @__PURE__ */ k.jsx(P.Provider, { value: { protocols: y, protocolsStatus: m }, children: /* @__PURE__ */ k.jsx(G, { runtime: F, children: s }) });
683
471
  }
684
- function Ae({ children: r, ...t }) {
685
- return /* @__PURE__ */ Y.jsx(Ce, { ...t, children: r });
472
+ function ae({ children: i, ...t }) {
473
+ return /* @__PURE__ */ k.jsx(ee, { ...t, children: i });
686
474
  }
687
- function ve() {
688
- const r = ne(q);
689
- if (!r)
475
+ function oe() {
476
+ const i = N(P);
477
+ if (!i)
690
478
  throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
691
- return r;
479
+ return i;
692
480
  }
693
- function ke(r) {
694
- const t = ne(q);
481
+ function te(i) {
482
+ const t = N(P);
695
483
  if (!t)
696
484
  throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
697
- const e = t.protocols.find((o) => o.getName() === r);
485
+ const e = t.protocols.find((n) => n.getName() === i);
698
486
  if (!e)
699
487
  return null;
700
- const n = t.protocolsStatus.get(e.getName());
488
+ const s = t.protocolsStatus.get(e.getName());
701
489
  return {
702
490
  ...e,
703
491
  connect: e.connect.bind(e),
@@ -708,15 +496,15 @@ function ke(r) {
708
496
  addMessageListener: e.addMessageListener.bind(e),
709
497
  getName: e.getName.bind(e),
710
498
  getPriority: e.getPriority.bind(e),
711
- status: n || e.status
499
+ status: s || e.status
712
500
  };
713
501
  }
714
- function Te() {
715
- return ke("webrtc");
502
+ function re() {
503
+ return te("webrtc");
716
504
  }
717
- class xe {
505
+ class ce {
718
506
  constructor() {
719
- i(this, "prefix", "[Persona]");
507
+ o(this, "prefix", "[Persona]");
720
508
  }
721
509
  log(t, ...e) {
722
510
  console.log(`${this.prefix} - ${t}`, ...e);
@@ -735,14 +523,14 @@ class xe {
735
523
  }
736
524
  }
737
525
  export {
738
- xe as PersonaConsoleLogger,
739
- K as PersonaProtocolBase,
740
- ee as PersonaRESTProtocol,
741
- Ae as PersonaRuntimeProvider,
742
- se as PersonaWebRTCProtocol,
743
- te as PersonaWebSocketProtocol,
744
- ve as usePersonaRuntime,
745
- ke as usePersonaRuntimeProtocol,
746
- Te as usePersonaRuntimeWebRTCProtocol
526
+ ce as PersonaConsoleLogger,
527
+ x as PersonaProtocolBase,
528
+ T as PersonaRESTProtocol,
529
+ ae as PersonaRuntimeProvider,
530
+ $ as PersonaWebRTCProtocol,
531
+ I as PersonaWebSocketProtocol,
532
+ oe as usePersonaRuntime,
533
+ te as usePersonaRuntimeProtocol,
534
+ re as usePersonaRuntimeWebRTCProtocol
747
535
  };
748
536
  //# sourceMappingURL=bundle.es.js.map