@applica-software-guru/persona-sdk 0.1.61 → 0.1.63
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.cjs.js +3 -3
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +372 -361
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +3 -3
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +3 -3
- package/dist/bundle.umd.js.map +1 -1
- package/dist/protocol/base.d.ts +5 -5
- package/dist/protocol/base.d.ts.map +1 -1
- package/dist/protocol/rest.d.ts +3 -2
- package/dist/protocol/rest.d.ts.map +1 -1
- package/dist/protocol/transaction.d.ts +2 -2
- package/dist/protocol/transaction.d.ts.map +1 -1
- package/dist/protocol/webrtc.d.ts +3 -3
- package/dist/protocol/webrtc.d.ts.map +1 -1
- package/dist/protocol/websocket.d.ts +2 -2
- package/dist/protocol/websocket.d.ts.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/types.d.ts +23 -11
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/playground/src/chat.tsx +8 -3
- package/src/protocol/base.ts +5 -6
- package/src/protocol/rest.ts +19 -8
- package/src/protocol/transaction.ts +2 -5
- package/src/protocol/webrtc.ts +8 -8
- package/src/protocol/websocket.ts +5 -5
- package/src/runtime.tsx +16 -6
- package/src/types.ts +27 -12
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var K = Object.defineProperty;
|
|
2
|
-
var q = (i,
|
|
3
|
-
var o = (i,
|
|
4
|
-
import { createContext as
|
|
5
|
-
import { useExternalStoreRuntime as
|
|
6
|
-
var
|
|
2
|
+
var q = (i, e, t) => e in i ? K(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var o = (i, e, t) => q(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { createContext as B, useContext as A, useState as R, useRef as Y, useMemo as G, useEffect as V, useCallback as v } from "react";
|
|
5
|
+
import { useExternalStoreRuntime as H, CompositeAttachmentAdapter as Q, SimpleImageAttachmentAdapter as X, AssistantRuntimeProvider as Z } from "@assistant-ui/react";
|
|
6
|
+
var W = { exports: {} }, S = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
@@ -13,121 +13,122 @@ var D = { exports: {} }, C = {};
|
|
|
13
13
|
* This source code is licensed under the MIT license found in the
|
|
14
14
|
* LICENSE file in the root directory of this source tree.
|
|
15
15
|
*/
|
|
16
|
-
var
|
|
17
|
-
function
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
var i = Symbol.for("react.transitional.element"),
|
|
21
|
-
function
|
|
22
|
-
var
|
|
23
|
-
if (a !== void 0 && (
|
|
16
|
+
var I;
|
|
17
|
+
function tt() {
|
|
18
|
+
if (I) return S;
|
|
19
|
+
I = 1;
|
|
20
|
+
var i = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
|
|
21
|
+
function t(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
24
|
a = {};
|
|
25
|
-
for (var l in
|
|
26
|
-
l !== "key" && (a[l] =
|
|
27
|
-
} else a =
|
|
28
|
-
return
|
|
25
|
+
for (var l in n)
|
|
26
|
+
l !== "key" && (a[l] = n[l]);
|
|
27
|
+
} else a = n;
|
|
28
|
+
return n = a.ref, {
|
|
29
29
|
$$typeof: i,
|
|
30
|
-
type:
|
|
31
|
-
key:
|
|
32
|
-
ref:
|
|
30
|
+
type: s,
|
|
31
|
+
key: r,
|
|
32
|
+
ref: n !== void 0 ? n : null,
|
|
33
33
|
props: a
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return S.Fragment = e, S.jsx = t, S.jsxs = t, S;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
function
|
|
41
|
-
return i.filter((
|
|
42
|
-
var
|
|
43
|
-
return
|
|
38
|
+
W.exports = tt();
|
|
39
|
+
var $ = W.exports;
|
|
40
|
+
function et(i) {
|
|
41
|
+
return i.filter((e) => {
|
|
42
|
+
var t;
|
|
43
|
+
return e.finishReason === "stop" ? e.text !== null && ((t = e.text) == null ? void 0 : t.trim()) !== "" : !0;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
let
|
|
49
|
-
for (const
|
|
50
|
-
|
|
51
|
-
...
|
|
52
|
-
functionResponse:
|
|
53
|
-
} :
|
|
54
|
-
...
|
|
46
|
+
function M(i) {
|
|
47
|
+
const e = [];
|
|
48
|
+
let t = null;
|
|
49
|
+
for (const n of i)
|
|
50
|
+
n.type !== "transaction" && (n.type === "reasoning" ? (t != null && (e.push(t), t = null), e.push(n)) : n.functionCalls ? (t && e.push(t), e.push(n), t = null) : n.functionResponse ? e[e.length - 1] = {
|
|
51
|
+
...e[e.length - 1],
|
|
52
|
+
functionResponse: n.functionResponse
|
|
53
|
+
} : t && n.protocol === t.protocol && (t.role === n.role || n.finishReason === "stop") ? (t.text += n.text, t.files = [...t.files ?? [], ...n.files ?? []]) : (t && e.push(t), t = {
|
|
54
|
+
...n
|
|
55
55
|
}));
|
|
56
|
-
return
|
|
56
|
+
return t && e.push(t), et(e);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
var
|
|
60
|
-
const
|
|
61
|
-
(
|
|
58
|
+
function st(i) {
|
|
59
|
+
var t, s;
|
|
60
|
+
const e = ((t = i.files) == null ? void 0 : t.map(
|
|
61
|
+
(n) => ({
|
|
62
62
|
type: "file",
|
|
63
|
-
data:
|
|
64
|
-
mimeType:
|
|
63
|
+
data: n.url,
|
|
64
|
+
mimeType: n.contentType
|
|
65
65
|
})
|
|
66
66
|
)) ?? [];
|
|
67
67
|
return i.role === "function" ? {
|
|
68
68
|
id: i.id,
|
|
69
69
|
role: "assistant",
|
|
70
70
|
status: (i == null ? void 0 : i.functionResponse) === null ? { type: "running" } : { type: "complete", reason: "stop" },
|
|
71
|
-
content: ((
|
|
71
|
+
content: ((s = i.functionCalls) == null ? void 0 : s.map((n) => {
|
|
72
72
|
var a;
|
|
73
73
|
return {
|
|
74
74
|
type: "tool-call",
|
|
75
|
-
toolName:
|
|
76
|
-
toolCallId:
|
|
77
|
-
args:
|
|
75
|
+
toolName: n.name,
|
|
76
|
+
toolCallId: n.id,
|
|
77
|
+
args: n.args,
|
|
78
78
|
result: (a = i.functionResponse) == null ? void 0 : a.result
|
|
79
79
|
};
|
|
80
80
|
})) ?? []
|
|
81
81
|
} : {
|
|
82
82
|
id: i.id,
|
|
83
83
|
role: i.role,
|
|
84
|
-
content: i.type === "reasoning" ? [{ type: "reasoning", text: i.text }, ...
|
|
84
|
+
content: i.type === "reasoning" ? [{ type: "reasoning", text: i.text }, ...e] : [{ type: "text", text: i.text }, ...e]
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
class
|
|
87
|
+
class E {
|
|
88
88
|
constructor() {
|
|
89
89
|
o(this, "statusChangeCallbacks", []);
|
|
90
90
|
o(this, "messageCallbacks", []);
|
|
91
91
|
}
|
|
92
|
-
addStatusChangeListener(
|
|
93
|
-
this.statusChangeCallbacks.push(
|
|
92
|
+
addStatusChangeListener(e) {
|
|
93
|
+
this.statusChangeCallbacks.push(e);
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
this.messageCallbacks.push(
|
|
95
|
+
addPacketListener(e) {
|
|
96
|
+
this.messageCallbacks.push(e);
|
|
97
97
|
}
|
|
98
|
-
async syncSession(
|
|
99
|
-
this.session =
|
|
98
|
+
async syncSession(e) {
|
|
99
|
+
this.session = e;
|
|
100
100
|
}
|
|
101
|
-
async
|
|
102
|
-
this.messageCallbacks.forEach((
|
|
101
|
+
async notifyPacket(e) {
|
|
102
|
+
this.messageCallbacks.forEach((t) => t(e));
|
|
103
103
|
}
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
this.messageCallbacks.forEach((
|
|
104
|
+
async notifyPackets(e) {
|
|
105
|
+
e.forEach((t) => {
|
|
106
|
+
this.messageCallbacks.forEach((s) => s(t));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
-
async setSession(
|
|
110
|
-
this.session =
|
|
109
|
+
async setSession(e) {
|
|
110
|
+
this.session = e;
|
|
111
111
|
}
|
|
112
|
-
async setStatus(
|
|
113
|
-
const
|
|
114
|
-
this.status =
|
|
112
|
+
async setStatus(e) {
|
|
113
|
+
const t = this.status !== e;
|
|
114
|
+
this.status = e, t && this.statusChangeCallbacks.forEach((s) => s(e));
|
|
115
115
|
}
|
|
116
116
|
clearListeners() {
|
|
117
117
|
this.statusChangeCallbacks = [], this.messageCallbacks = [];
|
|
118
118
|
}
|
|
119
|
-
onTransaction(
|
|
119
|
+
onTransaction(e) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class
|
|
123
|
-
constructor(
|
|
122
|
+
class z extends E {
|
|
123
|
+
constructor(t) {
|
|
124
124
|
super();
|
|
125
125
|
o(this, "status");
|
|
126
126
|
o(this, "autostart");
|
|
127
127
|
o(this, "session");
|
|
128
128
|
o(this, "config");
|
|
129
129
|
o(this, "notify", !0);
|
|
130
|
-
this
|
|
130
|
+
o(this, "context", {});
|
|
131
|
+
this.config = t, this.status = "disconnected", this.autostart = !0;
|
|
131
132
|
}
|
|
132
133
|
getName() {
|
|
133
134
|
return "rest";
|
|
@@ -135,42 +136,47 @@ class N extends A {
|
|
|
135
136
|
getPriority() {
|
|
136
137
|
return 100;
|
|
137
138
|
}
|
|
138
|
-
async connect(
|
|
139
|
-
return this.setStatus("connected"),
|
|
139
|
+
async connect(t) {
|
|
140
|
+
return this.setStatus("connected"), t;
|
|
140
141
|
}
|
|
141
142
|
async disconnect() {
|
|
142
143
|
this.setStatus("disconnected"), this.session = null;
|
|
143
144
|
}
|
|
144
|
-
async syncSession(
|
|
145
|
-
this.session =
|
|
145
|
+
async syncSession(t) {
|
|
146
|
+
this.session = t;
|
|
146
147
|
}
|
|
147
|
-
async
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
async sendPacket(t) {
|
|
149
|
+
var g, w;
|
|
150
|
+
const { apiUrl: s, apiKey: n, agentId: a } = this.config, r = this.session ?? "new";
|
|
151
|
+
if (t.type === "command" && ((g = t == null ? void 0 : t.payload) == null ? void 0 : g.command) == "set_initial_context") {
|
|
152
|
+
this.context = (w = t == null ? void 0 : t.payload) == null ? void 0 : w.arguments;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const l = t.payload, p = await (await fetch(`${s}/sessions/${r}/messages`, {
|
|
156
|
+
body: JSON.stringify({ agentId: a, userMessage: l, initial_context: this.context }),
|
|
150
157
|
method: "POST",
|
|
151
158
|
headers: {
|
|
152
159
|
"Content-Type": "application/json",
|
|
153
|
-
"x-
|
|
154
|
-
"x-persona-apikey": s
|
|
160
|
+
"x-persona-apikey": n
|
|
155
161
|
}
|
|
156
162
|
})).json();
|
|
157
|
-
this.
|
|
158
|
-
|
|
163
|
+
this.notifyPackets(
|
|
164
|
+
p.response.messages.map((T) => ({
|
|
159
165
|
type: "message",
|
|
160
|
-
payload:
|
|
166
|
+
payload: T
|
|
161
167
|
}))
|
|
162
168
|
);
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
|
-
class
|
|
166
|
-
constructor(
|
|
171
|
+
class D extends E {
|
|
172
|
+
constructor(t) {
|
|
167
173
|
super();
|
|
168
174
|
o(this, "status");
|
|
169
175
|
o(this, "autostart");
|
|
170
176
|
o(this, "session");
|
|
171
177
|
o(this, "config");
|
|
172
178
|
o(this, "webSocket");
|
|
173
|
-
this.config =
|
|
179
|
+
this.config = t, this.status = "disconnected", this.autostart = !0, this.session = null, this.webSocket = null;
|
|
174
180
|
}
|
|
175
181
|
getName() {
|
|
176
182
|
return "websocket";
|
|
@@ -178,40 +184,40 @@ class I extends A {
|
|
|
178
184
|
getPriority() {
|
|
179
185
|
return 500;
|
|
180
186
|
}
|
|
181
|
-
async syncSession(
|
|
182
|
-
var
|
|
183
|
-
(
|
|
187
|
+
async syncSession(t) {
|
|
188
|
+
var s;
|
|
189
|
+
(s = this.config.logger) == null || s.debug("Syncing session with WebSocket protocol:", t), this.session = t, this.webSocket && this.status === "connected" && (this.disconnect(), this.connect(t));
|
|
184
190
|
}
|
|
185
|
-
connect(
|
|
191
|
+
connect(t) {
|
|
186
192
|
var l;
|
|
187
193
|
if (this.webSocket !== null && this.status === "connected")
|
|
188
194
|
return Promise.resolve(this.session);
|
|
189
|
-
const
|
|
190
|
-
(l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:",
|
|
191
|
-
const
|
|
192
|
-
return this.setStatus("connecting"), this.webSocket = new WebSocket(
|
|
195
|
+
const s = t || this.session || "new";
|
|
196
|
+
(l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", s);
|
|
197
|
+
const n = encodeURIComponent(this.config.apiKey), a = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${s}&agentId=${a}&apiKey=${n}`;
|
|
198
|
+
return this.setStatus("connecting"), this.webSocket = new WebSocket(r), this.webSocket.addEventListener("open", () => {
|
|
193
199
|
this.setStatus("connected");
|
|
194
200
|
}), this.webSocket.addEventListener("message", (u) => {
|
|
195
|
-
const
|
|
196
|
-
this.
|
|
201
|
+
const p = JSON.parse(u.data);
|
|
202
|
+
this.notifyPacket(p);
|
|
197
203
|
}), this.webSocket.addEventListener("close", () => {
|
|
198
204
|
var u;
|
|
199
205
|
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.warn("WebSocket connection closed");
|
|
200
206
|
}), this.webSocket.addEventListener("error", (u) => {
|
|
201
|
-
var
|
|
202
|
-
this.setStatus("disconnected"), this.webSocket = null, (
|
|
203
|
-
}), Promise.resolve(
|
|
207
|
+
var p;
|
|
208
|
+
this.setStatus("disconnected"), this.webSocket = null, (p = this.config.logger) == null || p.error("WebSocket error", u);
|
|
209
|
+
}), Promise.resolve(s);
|
|
204
210
|
}
|
|
205
211
|
disconnect() {
|
|
206
|
-
var
|
|
207
|
-
return (
|
|
212
|
+
var t;
|
|
213
|
+
return (t = this.config.logger) == null || t.debug("Disconnecting WebSocket"), this.webSocket && this.status === "connected" && (this.webSocket.close(), this.setStatus("disconnected"), this.webSocket = null), Promise.resolve();
|
|
208
214
|
}
|
|
209
|
-
|
|
210
|
-
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify(
|
|
215
|
+
sendPacket(t) {
|
|
216
|
+
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify(t)), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
|
|
211
217
|
}
|
|
212
218
|
}
|
|
213
|
-
class
|
|
214
|
-
constructor(
|
|
219
|
+
class nt {
|
|
220
|
+
constructor(e) {
|
|
215
221
|
o(this, "config");
|
|
216
222
|
o(this, "pc", null);
|
|
217
223
|
o(this, "ws", null);
|
|
@@ -225,16 +231,16 @@ class se {
|
|
|
225
231
|
o(this, "isConnected", !1);
|
|
226
232
|
o(this, "visualizerCallbacks", []);
|
|
227
233
|
o(this, "messageCallbacks", []);
|
|
228
|
-
this.config =
|
|
234
|
+
this.config = e;
|
|
229
235
|
}
|
|
230
|
-
async connect(
|
|
231
|
-
var
|
|
236
|
+
async connect(e) {
|
|
237
|
+
var s;
|
|
232
238
|
if (this.isConnected) return;
|
|
233
239
|
this.isConnected = !0;
|
|
234
240
|
try {
|
|
235
241
|
this.localStream = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
236
|
-
} catch (
|
|
237
|
-
(
|
|
242
|
+
} catch (n) {
|
|
243
|
+
(s = this.config.logger) == null || s.error("Error accessing microphone:", n);
|
|
238
244
|
return;
|
|
239
245
|
}
|
|
240
246
|
this.pc = new RTCPeerConnection({
|
|
@@ -248,137 +254,137 @@ class se {
|
|
|
248
254
|
credential: "webrtc"
|
|
249
255
|
}
|
|
250
256
|
]
|
|
251
|
-
}), this.localStream.getTracks().forEach((
|
|
252
|
-
this.pc.addTrack(
|
|
253
|
-
}), this.pc.ontrack = (
|
|
254
|
-
|
|
255
|
-
this.remoteStream.addTrack(
|
|
257
|
+
}), this.localStream.getTracks().forEach((n) => {
|
|
258
|
+
this.pc.addTrack(n, this.localStream);
|
|
259
|
+
}), this.pc.ontrack = (n) => {
|
|
260
|
+
n.streams[0].getTracks().forEach((r) => {
|
|
261
|
+
this.remoteStream.addTrack(r);
|
|
256
262
|
}), this.audioCtx || this._startAnalyzers();
|
|
257
263
|
const a = new Audio();
|
|
258
|
-
a.srcObject = this.remoteStream, a.play().catch((
|
|
264
|
+
a.srcObject = this.remoteStream, a.play().catch((r) => {
|
|
259
265
|
var l;
|
|
260
|
-
(l = this.config.logger) == null || l.error("Error playing remote audio:",
|
|
266
|
+
(l = this.config.logger) == null || l.error("Error playing remote audio:", r);
|
|
261
267
|
});
|
|
262
|
-
}, this.pc.onicecandidate = (
|
|
268
|
+
}, this.pc.onicecandidate = (n) => {
|
|
263
269
|
var a;
|
|
264
|
-
|
|
270
|
+
n.candidate && ((a = this.ws) == null ? void 0 : a.readyState) === WebSocket.OPEN && this.ws.send(
|
|
265
271
|
JSON.stringify({
|
|
266
272
|
type: "CANDIDATE",
|
|
267
273
|
src: "client",
|
|
268
|
-
payload: { candidate:
|
|
274
|
+
payload: { candidate: n.candidate }
|
|
269
275
|
})
|
|
270
276
|
);
|
|
271
|
-
}, this.pc.ondatachannel = (
|
|
272
|
-
const a =
|
|
273
|
-
a.onmessage = (
|
|
277
|
+
}, this.pc.ondatachannel = (n) => {
|
|
278
|
+
const a = n.channel;
|
|
279
|
+
a.onmessage = (r) => {
|
|
274
280
|
this.messageCallbacks.forEach((l) => {
|
|
275
|
-
l(
|
|
281
|
+
l(r);
|
|
276
282
|
});
|
|
277
283
|
};
|
|
278
284
|
};
|
|
279
|
-
const
|
|
280
|
-
this.ws = new WebSocket(`${
|
|
285
|
+
const t = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
|
|
286
|
+
this.ws = new WebSocket(`${t}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
|
|
281
287
|
var l, u;
|
|
282
|
-
const
|
|
283
|
-
await this.pc.setLocalDescription(
|
|
288
|
+
const n = await this.pc.createOffer();
|
|
289
|
+
await this.pc.setLocalDescription(n);
|
|
284
290
|
const a = {
|
|
285
291
|
apiKey: this.config.apiKey,
|
|
286
292
|
agentId: this.config.agentId,
|
|
287
|
-
sessionCode:
|
|
293
|
+
sessionCode: e
|
|
288
294
|
};
|
|
289
295
|
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", a);
|
|
290
|
-
const
|
|
296
|
+
const r = {
|
|
291
297
|
type: "OFFER",
|
|
292
298
|
src: ((u = crypto.randomUUID) == null ? void 0 : u.call(crypto)) || "client_" + Date.now(),
|
|
293
299
|
payload: {
|
|
294
300
|
sdp: {
|
|
295
|
-
sdp:
|
|
296
|
-
type:
|
|
301
|
+
sdp: n.sdp,
|
|
302
|
+
type: n.type
|
|
297
303
|
},
|
|
298
304
|
connectionId: (Date.now() % 1e6).toString(),
|
|
299
305
|
metadata: a
|
|
300
306
|
}
|
|
301
307
|
};
|
|
302
|
-
this.ws.send(JSON.stringify(
|
|
303
|
-
}, this.ws.onmessage = async (
|
|
304
|
-
var
|
|
305
|
-
const a = JSON.parse(
|
|
308
|
+
this.ws.send(JSON.stringify(r));
|
|
309
|
+
}, this.ws.onmessage = async (n) => {
|
|
310
|
+
var r;
|
|
311
|
+
const a = JSON.parse(n.data);
|
|
306
312
|
if (a.type === "ANSWER")
|
|
307
313
|
await this.pc.setRemoteDescription(new RTCSessionDescription(a.payload.sdp));
|
|
308
314
|
else if (a.type === "CANDIDATE")
|
|
309
315
|
try {
|
|
310
316
|
await this.pc.addIceCandidate(new RTCIceCandidate(a.payload.candidate));
|
|
311
317
|
} catch (l) {
|
|
312
|
-
(
|
|
318
|
+
(r = this.config.logger) == null || r.error("Error adding ICE candidate:", l);
|
|
313
319
|
}
|
|
314
320
|
}, this.ws.onclose = () => {
|
|
315
321
|
this._stopAnalyzers();
|
|
316
322
|
};
|
|
317
323
|
}
|
|
318
324
|
async disconnect() {
|
|
319
|
-
var
|
|
320
|
-
this.isConnected && (this.isConnected = !1, ((
|
|
325
|
+
var e;
|
|
326
|
+
this.isConnected && (this.isConnected = !1, ((e = this.ws) == null ? void 0 : e.readyState) === WebSocket.OPEN && this.ws.close(), this.pc && this.pc.close(), this.localStream && this.localStream.getTracks().forEach((t) => t.stop()), this.remoteStream = new MediaStream(), this.audioCtx && (await this.audioCtx.close(), this.audioCtx = null), this._stopAnalyzers());
|
|
321
327
|
}
|
|
322
|
-
addVisualizerCallback(
|
|
323
|
-
this.visualizerCallbacks.push(
|
|
328
|
+
addVisualizerCallback(e) {
|
|
329
|
+
this.visualizerCallbacks.push(e);
|
|
324
330
|
}
|
|
325
|
-
addMessageCallback(
|
|
326
|
-
this.messageCallbacks.push(
|
|
331
|
+
addMessageCallback(e) {
|
|
332
|
+
this.messageCallbacks.push(e);
|
|
327
333
|
}
|
|
328
|
-
createDataChannel(
|
|
329
|
-
this.pc && (this.dataChannel = this.pc.createDataChannel(
|
|
330
|
-
var
|
|
331
|
-
return (
|
|
332
|
-
}, this.dataChannel.onmessage = (
|
|
333
|
-
this.messageCallbacks.forEach((
|
|
334
|
-
|
|
334
|
+
createDataChannel(e = "messages") {
|
|
335
|
+
this.pc && (this.dataChannel = this.pc.createDataChannel(e), this.dataChannel.onopen = () => {
|
|
336
|
+
var t;
|
|
337
|
+
return (t = this.config.logger) == null ? void 0 : t.info("Data channel opened");
|
|
338
|
+
}, this.dataChannel.onmessage = (t) => {
|
|
339
|
+
this.messageCallbacks.forEach((s) => {
|
|
340
|
+
s(t);
|
|
335
341
|
});
|
|
336
342
|
});
|
|
337
343
|
}
|
|
338
|
-
|
|
339
|
-
var
|
|
344
|
+
sendPacket(e) {
|
|
345
|
+
var t, s;
|
|
340
346
|
if (!this.dataChannel) {
|
|
341
|
-
(
|
|
347
|
+
(t = this.config.logger) == null || t.warn("Data channel is not open, cannot send message");
|
|
342
348
|
return;
|
|
343
349
|
}
|
|
344
|
-
this.dataChannel.send(JSON.stringify(
|
|
350
|
+
this.dataChannel.send(JSON.stringify(e)), (s = this.config.logger) == null || s.info("Sent message:", e);
|
|
345
351
|
}
|
|
346
352
|
_startAnalyzers() {
|
|
347
353
|
if (!this.localStream || !this.remoteStream || this.visualizerCallbacks.length === 0)
|
|
348
354
|
return;
|
|
349
355
|
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
350
|
-
const
|
|
351
|
-
this.localAnalyser = this.audioCtx.createAnalyser(), this.remoteAnalyser = this.audioCtx.createAnalyser(), this.localAnalyser.fftSize = 256, this.remoteAnalyser.fftSize = 256,
|
|
352
|
-
const
|
|
356
|
+
const e = this.audioCtx.createMediaStreamSource(this.localStream), t = this.audioCtx.createMediaStreamSource(this.remoteStream);
|
|
357
|
+
this.localAnalyser = this.audioCtx.createAnalyser(), this.remoteAnalyser = this.audioCtx.createAnalyser(), this.localAnalyser.fftSize = 256, this.remoteAnalyser.fftSize = 256, e.connect(this.localAnalyser), t.connect(this.remoteAnalyser);
|
|
358
|
+
const s = () => {
|
|
353
359
|
if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
|
|
354
360
|
return;
|
|
355
|
-
const
|
|
356
|
-
this.localAnalyser.getByteFrequencyData(
|
|
357
|
-
const
|
|
361
|
+
const n = new Uint8Array(this.localAnalyser.frequencyBinCount), a = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
362
|
+
this.localAnalyser.getByteFrequencyData(n), this.remoteAnalyser.getByteFrequencyData(a);
|
|
363
|
+
const r = n.reduce((u, p) => u + p, 0) / n.length, l = a.reduce((u, p) => u + p, 0) / a.length;
|
|
358
364
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
359
365
|
u({
|
|
360
|
-
localAmplitude:
|
|
366
|
+
localAmplitude: r,
|
|
361
367
|
remoteAmplitude: l
|
|
362
368
|
});
|
|
363
|
-
}), this.analyzerFrame = requestAnimationFrame(
|
|
369
|
+
}), this.analyzerFrame = requestAnimationFrame(s);
|
|
364
370
|
};
|
|
365
|
-
this.analyzerFrame = requestAnimationFrame(
|
|
371
|
+
this.analyzerFrame = requestAnimationFrame(s);
|
|
366
372
|
}
|
|
367
373
|
_stopAnalyzers() {
|
|
368
374
|
this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
|
|
369
375
|
}
|
|
370
376
|
}
|
|
371
|
-
class
|
|
372
|
-
constructor(
|
|
377
|
+
class U extends E {
|
|
378
|
+
constructor(t) {
|
|
373
379
|
super();
|
|
374
380
|
o(this, "status");
|
|
375
381
|
o(this, "session");
|
|
376
382
|
o(this, "autostart");
|
|
377
383
|
o(this, "config");
|
|
378
384
|
o(this, "webRTCClient");
|
|
379
|
-
this.config =
|
|
380
|
-
const
|
|
381
|
-
this.
|
|
385
|
+
this.config = t, this.status = "disconnected", this.session = null, this.autostart = (t == null ? void 0 : t.autostart) ?? !1, this.webRTCClient = new nt(t), this.webRTCClient.addMessageCallback((s) => {
|
|
386
|
+
const n = JSON.parse(s.data);
|
|
387
|
+
this.notifyPacket(n);
|
|
382
388
|
});
|
|
383
389
|
}
|
|
384
390
|
getName() {
|
|
@@ -387,39 +393,39 @@ class z extends A {
|
|
|
387
393
|
getPriority() {
|
|
388
394
|
return 1e3;
|
|
389
395
|
}
|
|
390
|
-
async syncSession(
|
|
391
|
-
super.syncSession(
|
|
396
|
+
async syncSession(t) {
|
|
397
|
+
super.syncSession(t), this.status === "connected" && (await this.disconnect(), await this.connect(t));
|
|
392
398
|
}
|
|
393
|
-
async connect(
|
|
394
|
-
var
|
|
395
|
-
return this.status === "connected" ? Promise.resolve(this.session) : (this.session =
|
|
399
|
+
async connect(t) {
|
|
400
|
+
var s;
|
|
401
|
+
return this.status === "connected" ? Promise.resolve(this.session) : (this.session = t || 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);
|
|
396
402
|
}
|
|
397
403
|
async disconnect() {
|
|
398
|
-
var
|
|
404
|
+
var t, s, n;
|
|
399
405
|
if (this.status === "disconnected")
|
|
400
|
-
return (
|
|
401
|
-
await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (
|
|
406
|
+
return (t = this.config.logger) == null || t.warn("Already disconnected"), Promise.resolve();
|
|
407
|
+
await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (n = (s = this.config) == null ? void 0 : s.logger) == null || n.debug("Disconnected from WebRTC");
|
|
402
408
|
}
|
|
403
|
-
|
|
404
|
-
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.
|
|
409
|
+
sendPacket(t) {
|
|
410
|
+
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendPacket(t), Promise.resolve());
|
|
405
411
|
}
|
|
406
412
|
}
|
|
407
|
-
class
|
|
408
|
-
constructor(
|
|
413
|
+
class it {
|
|
414
|
+
constructor(e) {
|
|
409
415
|
o(this, "config");
|
|
410
|
-
this.config =
|
|
416
|
+
this.config = e;
|
|
411
417
|
}
|
|
412
|
-
async complete(
|
|
413
|
-
var
|
|
414
|
-
await this.persist(
|
|
418
|
+
async complete(e, t) {
|
|
419
|
+
var s;
|
|
420
|
+
await this.persist(e, { ...t, success: !0 }), (s = this.config.logger) == null || s.debug("Transaction completed:", e);
|
|
415
421
|
}
|
|
416
|
-
async fail(
|
|
417
|
-
var
|
|
418
|
-
await this.persist(
|
|
422
|
+
async fail(e, t) {
|
|
423
|
+
var s;
|
|
424
|
+
await this.persist(e, { ...t, success: !1 }), (s = this.config.logger) == null || s.debug("Transaction failed:", { ...e, ...t });
|
|
419
425
|
}
|
|
420
|
-
async persist(
|
|
421
|
-
await fetch(`${this.config.apiUrl}/transactions/${
|
|
422
|
-
body: JSON.stringify(
|
|
426
|
+
async persist(e, t) {
|
|
427
|
+
await fetch(`${this.config.apiUrl}/transactions/${e.id}`, {
|
|
428
|
+
body: JSON.stringify(t),
|
|
423
429
|
method: "POST",
|
|
424
430
|
headers: {
|
|
425
431
|
"Content-Type": "application/json",
|
|
@@ -429,49 +435,49 @@ class ne {
|
|
|
429
435
|
});
|
|
430
436
|
}
|
|
431
437
|
}
|
|
432
|
-
class
|
|
433
|
-
constructor(
|
|
438
|
+
class at {
|
|
439
|
+
constructor(e, t) {
|
|
434
440
|
o(this, "transaction");
|
|
435
441
|
o(this, "manager");
|
|
436
|
-
this.transaction =
|
|
442
|
+
this.transaction = e, this.manager = t;
|
|
437
443
|
}
|
|
438
444
|
getFunctionCall() {
|
|
439
445
|
return this.transaction.functionCall;
|
|
440
446
|
}
|
|
441
|
-
async invoke(
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
447
|
+
async invoke(e) {
|
|
448
|
+
const t = this.transaction.functionCall;
|
|
449
|
+
if (!t) {
|
|
444
450
|
await this.fail("No function call found");
|
|
445
451
|
return;
|
|
446
452
|
}
|
|
447
|
-
const
|
|
453
|
+
const s = t.name, n = t.args, a = e[s];
|
|
448
454
|
if (!a) {
|
|
449
|
-
await this.fail(`Tool ${
|
|
455
|
+
await this.fail(`Tool ${s} not found`);
|
|
450
456
|
return;
|
|
451
457
|
}
|
|
452
458
|
try {
|
|
453
|
-
const
|
|
454
|
-
await this.complete(
|
|
455
|
-
} catch (
|
|
456
|
-
await this.fail(`Error executing tool ${
|
|
459
|
+
const r = await a(n);
|
|
460
|
+
await this.complete(r);
|
|
461
|
+
} catch (r) {
|
|
462
|
+
await this.fail(`Error executing tool ${s}: ${r}`);
|
|
457
463
|
}
|
|
458
464
|
}
|
|
459
|
-
async complete(
|
|
460
|
-
await this.manager.complete(this.transaction, { success: !0, output:
|
|
465
|
+
async complete(e) {
|
|
466
|
+
await this.manager.complete(this.transaction, { success: !0, output: e, error: null });
|
|
461
467
|
}
|
|
462
|
-
async fail(
|
|
463
|
-
await this.manager.fail(this.transaction, { success: !1, output: null, error:
|
|
468
|
+
async fail(e) {
|
|
469
|
+
await this.manager.fail(this.transaction, { success: !1, output: null, error: e });
|
|
464
470
|
}
|
|
465
471
|
}
|
|
466
|
-
class
|
|
467
|
-
constructor(
|
|
472
|
+
class ot extends E {
|
|
473
|
+
constructor(t) {
|
|
468
474
|
super();
|
|
469
475
|
o(this, "status");
|
|
470
476
|
o(this, "autostart");
|
|
471
477
|
o(this, "session");
|
|
472
478
|
o(this, "config");
|
|
473
479
|
o(this, "notify", !0);
|
|
474
|
-
this.config =
|
|
480
|
+
this.config = t, this.status = "disconnected", this.autostart = !0;
|
|
475
481
|
}
|
|
476
482
|
getName() {
|
|
477
483
|
return "transaction";
|
|
@@ -479,240 +485,245 @@ class ae extends A {
|
|
|
479
485
|
getPriority() {
|
|
480
486
|
return 0;
|
|
481
487
|
}
|
|
482
|
-
async connect(
|
|
483
|
-
return this.setStatus("connected"),
|
|
488
|
+
async connect(t) {
|
|
489
|
+
return this.setStatus("connected"), t;
|
|
484
490
|
}
|
|
485
491
|
async disconnect() {
|
|
486
492
|
this.setStatus("disconnected"), this.session = null;
|
|
487
493
|
}
|
|
488
|
-
async syncSession(
|
|
489
|
-
this.session =
|
|
494
|
+
async syncSession(t) {
|
|
495
|
+
this.session = t;
|
|
490
496
|
}
|
|
491
|
-
async
|
|
492
|
-
var n;
|
|
493
|
-
throw (n = this.config.logger) == null || n.debug("Sending message:", e), new Error("Not implemented");
|
|
497
|
+
async sendPacket(t) {
|
|
494
498
|
}
|
|
495
|
-
onTransaction(
|
|
499
|
+
onTransaction(t) {
|
|
496
500
|
var a;
|
|
497
501
|
if (!this.config.onTransaction) {
|
|
498
502
|
(a = this.config.logger) == null || a.error("Transaction protocol config is not set");
|
|
499
503
|
return;
|
|
500
504
|
}
|
|
501
|
-
const
|
|
502
|
-
this.config.onTransaction(
|
|
505
|
+
const s = new it(this.config), n = new at(t, s);
|
|
506
|
+
this.config.onTransaction(n);
|
|
503
507
|
}
|
|
504
508
|
}
|
|
505
|
-
const
|
|
506
|
-
function
|
|
507
|
-
return new Promise((
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
const a =
|
|
511
|
-
|
|
512
|
-
},
|
|
513
|
-
|
|
509
|
+
const P = B(void 0);
|
|
510
|
+
function rt(i) {
|
|
511
|
+
return new Promise((e, t) => {
|
|
512
|
+
const s = new FileReader();
|
|
513
|
+
s.readAsDataURL(i), s.onload = () => {
|
|
514
|
+
const a = s.result.split(";base64,")[1];
|
|
515
|
+
e(a);
|
|
516
|
+
}, s.onerror = (n) => {
|
|
517
|
+
t(n);
|
|
514
518
|
};
|
|
515
519
|
});
|
|
516
520
|
}
|
|
517
|
-
function
|
|
521
|
+
function ct({
|
|
518
522
|
dev: i = !1,
|
|
523
|
+
baseUrl: e,
|
|
519
524
|
protocols: t,
|
|
520
|
-
logger:
|
|
525
|
+
logger: s,
|
|
521
526
|
children: n,
|
|
522
|
-
session:
|
|
523
|
-
...
|
|
527
|
+
session: a = "new",
|
|
528
|
+
...r
|
|
524
529
|
}) {
|
|
525
|
-
const [
|
|
530
|
+
const [l, u] = R(!1), [p, g] = R([]), [w, T] = R(a), [k, j] = R(/* @__PURE__ */ new Map()), N = Y(!1), b = G(() => {
|
|
526
531
|
if (Array.isArray(t))
|
|
527
532
|
return t;
|
|
528
533
|
if (typeof t == "object" && t !== null) {
|
|
529
|
-
const
|
|
530
|
-
let
|
|
531
|
-
switch (
|
|
534
|
+
const c = i ? "localhost:8000" : e || "persona.applica.guru/api", f = i ? "http" : "https", d = i ? "ws" : "wss";
|
|
535
|
+
let m = Object.keys(t).map((y) => {
|
|
536
|
+
switch (y) {
|
|
532
537
|
case "rest":
|
|
533
|
-
const h = t[
|
|
534
|
-
return h === !0 ? new
|
|
535
|
-
apiUrl: `${
|
|
536
|
-
apiKey:
|
|
537
|
-
agentId:
|
|
538
|
-
logger:
|
|
539
|
-
}) : typeof h == "object" && h !== null ? new
|
|
538
|
+
const h = t[y];
|
|
539
|
+
return h === !0 ? new z({
|
|
540
|
+
apiUrl: `${f}://${c}`,
|
|
541
|
+
apiKey: r.apiKey,
|
|
542
|
+
agentId: r.agentId,
|
|
543
|
+
logger: s
|
|
544
|
+
}) : typeof h == "object" && h !== null ? new z(h) : null;
|
|
540
545
|
case "webrtc":
|
|
541
|
-
const
|
|
542
|
-
return
|
|
543
|
-
webrtcUrl: `${d}://${
|
|
544
|
-
apiKey:
|
|
545
|
-
agentId:
|
|
546
|
-
logger:
|
|
547
|
-
}) : typeof
|
|
546
|
+
const C = t[y];
|
|
547
|
+
return C === !0 ? new U({
|
|
548
|
+
webrtcUrl: `${d}://${c}/webrtc`,
|
|
549
|
+
apiKey: r.apiKey,
|
|
550
|
+
agentId: r.agentId,
|
|
551
|
+
logger: s
|
|
552
|
+
}) : typeof C == "object" && C !== null ? new U(C) : null;
|
|
548
553
|
case "websocket":
|
|
549
|
-
const
|
|
550
|
-
return
|
|
551
|
-
webSocketUrl: `${d}://${
|
|
552
|
-
apiKey:
|
|
553
|
-
agentId:
|
|
554
|
-
logger:
|
|
555
|
-
}) : typeof
|
|
554
|
+
const x = t[y];
|
|
555
|
+
return x === !0 ? new D({
|
|
556
|
+
webSocketUrl: `${d}://${c}/websocket`,
|
|
557
|
+
apiKey: r.apiKey,
|
|
558
|
+
agentId: r.agentId,
|
|
559
|
+
logger: s
|
|
560
|
+
}) : typeof x == "object" && x !== null ? new D(x) : null;
|
|
556
561
|
default:
|
|
557
|
-
throw new Error(`Unknown protocol: ${
|
|
562
|
+
throw new Error(`Unknown protocol: ${y}`);
|
|
558
563
|
}
|
|
559
|
-
}).filter((
|
|
560
|
-
return
|
|
561
|
-
new
|
|
562
|
-
apiUrl: `${
|
|
563
|
-
apiKey:
|
|
564
|
-
agentId:
|
|
565
|
-
onTransaction: async (
|
|
566
|
-
await
|
|
564
|
+
}).filter((y) => y !== null);
|
|
565
|
+
return r.tools && m.push(
|
|
566
|
+
new ot({
|
|
567
|
+
apiUrl: `${f}://${c}`,
|
|
568
|
+
apiKey: r.apiKey,
|
|
569
|
+
agentId: r.agentId,
|
|
570
|
+
onTransaction: async (y) => {
|
|
571
|
+
await y.invoke(r.tools);
|
|
567
572
|
},
|
|
568
|
-
logger:
|
|
573
|
+
logger: s
|
|
569
574
|
})
|
|
570
|
-
),
|
|
575
|
+
), m;
|
|
571
576
|
}
|
|
572
577
|
throw new Error("Invalid protocols configuration");
|
|
573
578
|
}, []);
|
|
574
|
-
|
|
575
|
-
|
|
579
|
+
V(() => {
|
|
580
|
+
N.current || (N.current = !0, s == null || s.debug(
|
|
576
581
|
"Initializing protocols: ",
|
|
577
|
-
|
|
578
|
-
),
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
582
|
+
b.map((c) => c.getName())
|
|
583
|
+
), b.forEach((c) => {
|
|
584
|
+
c.setSession(w), c.clearListeners(), c.addStatusChangeListener((f) => {
|
|
585
|
+
s == null || s.debug(`${c.getName()} has notified new status: ${f}`), k.set(c.getName(), f), f === "connected" && r.context && c.sendPacket({
|
|
586
|
+
type: "command",
|
|
587
|
+
payload: {
|
|
588
|
+
command: "set_initial_context",
|
|
589
|
+
arguments: r.context
|
|
590
|
+
}
|
|
591
|
+
}), j(new Map(k));
|
|
592
|
+
}), c.addPacketListener((f) => {
|
|
593
|
+
if (f.type === "message") {
|
|
594
|
+
const d = f.payload;
|
|
595
|
+
g(
|
|
596
|
+
(m) => M([...m, { ...d, protocol: c.getName() }])
|
|
586
597
|
);
|
|
587
|
-
} else if (
|
|
588
|
-
const d =
|
|
589
|
-
let
|
|
590
|
-
d.imageUrl && (
|
|
598
|
+
} else if (f.type === "reasoning") {
|
|
599
|
+
const d = f.payload;
|
|
600
|
+
let m = d.thought;
|
|
601
|
+
d.imageUrl && (m += `
|
|
591
602
|
|
|
592
603
|
`);
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
(h) =>
|
|
604
|
+
const y = { type: "reasoning", text: m, role: "assistant", finishReason: "stop" };
|
|
605
|
+
g(
|
|
606
|
+
(h) => M([...h, { ...y, protocol: c.getName() }])
|
|
596
607
|
);
|
|
597
|
-
} else
|
|
598
|
-
}),
|
|
608
|
+
} else f.type === "transaction" && b.filter((d) => d !== c).forEach((d) => d.onTransaction(f.payload));
|
|
609
|
+
}), c.autostart && c.status === "disconnected" && (s == null || s.debug(`Connecting to protocol: ${c.getName()}`), c.connect(w));
|
|
599
610
|
}));
|
|
600
|
-
}, [
|
|
601
|
-
const
|
|
602
|
-
var
|
|
603
|
-
if (((
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
const d =
|
|
607
|
-
if (
|
|
608
|
-
for (const h of
|
|
609
|
-
h.contentType.startsWith("image/") && h.file &&
|
|
611
|
+
}, [w, b, s, k]);
|
|
612
|
+
const O = async (c) => {
|
|
613
|
+
var y;
|
|
614
|
+
if (((y = c.content[0]) == null ? void 0 : y.type) !== "text") throw new Error("Only text messages are supported");
|
|
615
|
+
const f = c.content[0].text;
|
|
616
|
+
g((h) => [...h, { role: "user", type: "text", text: f }]), u(!0);
|
|
617
|
+
const d = b.sort((h, C) => C.getPriority() - h.getPriority()).find((h) => h.status === "connected"), m = [];
|
|
618
|
+
if (c.attachments)
|
|
619
|
+
for (const h of c.attachments)
|
|
620
|
+
h.contentType.startsWith("image/") && h.file && m.push({
|
|
610
621
|
role: "user",
|
|
611
622
|
image: {
|
|
612
623
|
contentType: h.contentType,
|
|
613
|
-
content: await
|
|
624
|
+
content: await rt(h.file)
|
|
614
625
|
},
|
|
615
626
|
text: "",
|
|
616
627
|
type: "text"
|
|
617
628
|
});
|
|
618
|
-
|
|
629
|
+
c.content && m.push({
|
|
619
630
|
role: "user",
|
|
620
|
-
text:
|
|
631
|
+
text: c.content[0].text,
|
|
621
632
|
type: "text"
|
|
622
|
-
}),
|
|
623
|
-
},
|
|
624
|
-
isRunning:
|
|
625
|
-
messages:
|
|
626
|
-
convertMessage:
|
|
627
|
-
onNew:
|
|
628
|
-
onCancel:
|
|
629
|
-
onReload:
|
|
633
|
+
}), s == null || s.debug("Sending message:", m), await (d == null ? void 0 : d.sendPacket({ type: "request", payload: m })), u(!1);
|
|
634
|
+
}, L = v(() => (u(!1), g([]), T("new"), Promise.resolve()), []), F = v(() => Promise.resolve(), []), _ = v(() => p, [p]), J = H({
|
|
635
|
+
isRunning: l,
|
|
636
|
+
messages: p,
|
|
637
|
+
convertMessage: st,
|
|
638
|
+
onNew: O,
|
|
639
|
+
onCancel: L,
|
|
640
|
+
onReload: F,
|
|
630
641
|
adapters: {
|
|
631
|
-
attachments: new
|
|
642
|
+
attachments: new Q([new X()])
|
|
632
643
|
}
|
|
633
644
|
});
|
|
634
|
-
return /* @__PURE__ */
|
|
645
|
+
return /* @__PURE__ */ $.jsx(P.Provider, { value: { protocols: b, protocolsStatus: k, getMessages: _ }, children: /* @__PURE__ */ $.jsx(Z, { runtime: J, children: n }) });
|
|
635
646
|
}
|
|
636
|
-
function
|
|
637
|
-
return /* @__PURE__ */
|
|
647
|
+
function ft({ children: i, ...e }) {
|
|
648
|
+
return /* @__PURE__ */ $.jsx(ct, { ...e, children: i });
|
|
638
649
|
}
|
|
639
|
-
function
|
|
640
|
-
const i =
|
|
650
|
+
function pt() {
|
|
651
|
+
const i = A(P);
|
|
641
652
|
if (!i)
|
|
642
653
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
643
654
|
return i;
|
|
644
655
|
}
|
|
645
|
-
function
|
|
646
|
-
const
|
|
647
|
-
if (!t)
|
|
648
|
-
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
649
|
-
const e = t.protocols.find((s) => s.getName() === i);
|
|
656
|
+
function lt(i) {
|
|
657
|
+
const e = A(P);
|
|
650
658
|
if (!e)
|
|
659
|
+
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
660
|
+
const t = e.protocols.find((n) => n.getName() === i);
|
|
661
|
+
if (!t)
|
|
651
662
|
return null;
|
|
652
|
-
const
|
|
663
|
+
const s = e.protocolsStatus.get(t.getName());
|
|
653
664
|
return {
|
|
654
|
-
...
|
|
655
|
-
connect:
|
|
656
|
-
disconnect:
|
|
657
|
-
|
|
658
|
-
setSession:
|
|
659
|
-
addStatusChangeListener:
|
|
660
|
-
|
|
661
|
-
getName:
|
|
662
|
-
getPriority:
|
|
663
|
-
status:
|
|
665
|
+
...t,
|
|
666
|
+
connect: t.connect.bind(t),
|
|
667
|
+
disconnect: t.disconnect.bind(t),
|
|
668
|
+
sendPacket: t.sendPacket.bind(t),
|
|
669
|
+
setSession: t.setSession.bind(t),
|
|
670
|
+
addStatusChangeListener: t.addStatusChangeListener.bind(t),
|
|
671
|
+
addPacketListener: t.addPacketListener.bind(t),
|
|
672
|
+
getName: t.getName.bind(t),
|
|
673
|
+
getPriority: t.getPriority.bind(t),
|
|
674
|
+
status: s || t.status
|
|
664
675
|
};
|
|
665
676
|
}
|
|
666
|
-
function
|
|
667
|
-
const i =
|
|
677
|
+
function yt() {
|
|
678
|
+
const i = A(P);
|
|
668
679
|
if (!i)
|
|
669
680
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
670
|
-
for (const
|
|
671
|
-
if (
|
|
672
|
-
return
|
|
681
|
+
for (const e of i.protocols)
|
|
682
|
+
if (e.getName() === "rest")
|
|
683
|
+
return e.config.apiUrl;
|
|
673
684
|
throw new Error("REST protocol not found");
|
|
674
685
|
}
|
|
675
|
-
function
|
|
676
|
-
return
|
|
686
|
+
function mt() {
|
|
687
|
+
return lt("webrtc");
|
|
677
688
|
}
|
|
678
|
-
function
|
|
679
|
-
const i =
|
|
689
|
+
function gt() {
|
|
690
|
+
const i = A(P);
|
|
680
691
|
if (!i)
|
|
681
692
|
throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");
|
|
682
693
|
return i.getMessages();
|
|
683
694
|
}
|
|
684
|
-
class
|
|
695
|
+
class wt {
|
|
685
696
|
constructor() {
|
|
686
697
|
o(this, "prefix", "[Persona]");
|
|
687
698
|
}
|
|
688
|
-
log(
|
|
689
|
-
console.log(`${this.prefix} - ${
|
|
699
|
+
log(e, ...t) {
|
|
700
|
+
console.log(`${this.prefix} - ${e}`, ...t);
|
|
690
701
|
}
|
|
691
|
-
info(
|
|
692
|
-
console.info(`${this.prefix} - ${
|
|
702
|
+
info(e, ...t) {
|
|
703
|
+
console.info(`${this.prefix} - ${e}`, ...t);
|
|
693
704
|
}
|
|
694
|
-
warn(
|
|
695
|
-
console.warn(`${this.prefix} - ${
|
|
705
|
+
warn(e, ...t) {
|
|
706
|
+
console.warn(`${this.prefix} - ${e}`, ...t);
|
|
696
707
|
}
|
|
697
|
-
error(
|
|
698
|
-
console.error(`${this.prefix} - ${
|
|
708
|
+
error(e, ...t) {
|
|
709
|
+
console.error(`${this.prefix} - ${e}`, ...t);
|
|
699
710
|
}
|
|
700
|
-
debug(
|
|
701
|
-
console.debug(`${this.prefix} - ${
|
|
711
|
+
debug(e, ...t) {
|
|
712
|
+
console.debug(`${this.prefix} - ${e}`, ...t);
|
|
702
713
|
}
|
|
703
714
|
}
|
|
704
715
|
export {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
716
|
+
wt as PersonaConsoleLogger,
|
|
717
|
+
E as PersonaProtocolBase,
|
|
718
|
+
z as PersonaRESTProtocol,
|
|
719
|
+
ft as PersonaRuntimeProvider,
|
|
720
|
+
ot as PersonaTransactionProtocol,
|
|
721
|
+
U as PersonaWebRTCProtocol,
|
|
722
|
+
D as PersonaWebSocketProtocol,
|
|
723
|
+
pt as usePersonaRuntime,
|
|
724
|
+
yt as usePersonaRuntimeEndpoint,
|
|
725
|
+
gt as usePersonaRuntimeMessages,
|
|
726
|
+
lt as usePersonaRuntimeProtocol,
|
|
727
|
+
mt as usePersonaRuntimeWebRTCProtocol
|
|
717
728
|
};
|
|
718
729
|
//# sourceMappingURL=bundle.es.js.map
|