@applica-software-guru/persona-sdk 0.1.53 → 0.1.54
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/README.md +32 -8
- package/dist/bundle.cjs.js +2 -2
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +239 -239
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +2 -2
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +2 -2
- package/dist/bundle.umd.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/runtime.tsx +50 -39
- package/src/types.ts +3 -3
package/dist/bundle.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var F = Object.defineProperty;
|
|
2
|
-
var J = (a,
|
|
3
|
-
var o = (a,
|
|
4
|
-
import { createContext as K, useContext as
|
|
2
|
+
var J = (a, t, e) => t in a ? F(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
+
var o = (a, t, e) => J(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { createContext as K, useContext as E, useState as P, useRef as q, useMemo as _, useEffect as B, useCallback as v } from "react";
|
|
5
5
|
import { useExternalStoreRuntime as Y, CompositeAttachmentAdapter as G, SimpleImageAttachmentAdapter as V, AssistantRuntimeProvider as H } from "@assistant-ui/react";
|
|
6
|
-
var z = { exports: {} },
|
|
6
|
+
var z = { exports: {} }, C = {};
|
|
7
7
|
/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
@@ -15,10 +15,10 @@ var z = { exports: {} }, b = {};
|
|
|
15
15
|
*/
|
|
16
16
|
var $;
|
|
17
17
|
function Q() {
|
|
18
|
-
if ($) return
|
|
18
|
+
if ($) return C;
|
|
19
19
|
$ = 1;
|
|
20
|
-
var a = Symbol.for("react.transitional.element"),
|
|
21
|
-
function
|
|
20
|
+
var a = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
|
|
21
|
+
function e(n, s, i) {
|
|
22
22
|
var r = null;
|
|
23
23
|
if (i !== void 0 && (r = "" + i), s.key !== void 0 && (r = "" + s.key), "key" in s) {
|
|
24
24
|
i = {};
|
|
@@ -33,31 +33,31 @@ function Q() {
|
|
|
33
33
|
props: i
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return C.Fragment = t, C.jsx = e, C.jsxs = e, C;
|
|
37
37
|
}
|
|
38
38
|
z.exports = Q();
|
|
39
|
-
var
|
|
39
|
+
var A = z.exports;
|
|
40
40
|
function X(a) {
|
|
41
|
-
return a.filter((
|
|
42
|
-
var
|
|
43
|
-
return
|
|
41
|
+
return a.filter((t) => {
|
|
42
|
+
var e;
|
|
43
|
+
return t.finishReason === "stop" ? t.text !== null && ((e = t.text) == null ? void 0 : e.trim()) !== "" : !0;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
function Z(a) {
|
|
47
|
-
const
|
|
48
|
-
let
|
|
47
|
+
const t = [];
|
|
48
|
+
let e = null;
|
|
49
49
|
for (const s of a)
|
|
50
|
-
s.type !== "transaction" && (s.type === "reasoning" ? (
|
|
51
|
-
...
|
|
50
|
+
s.type !== "transaction" && (s.type === "reasoning" ? (e != null && (t.push(e), e = null), t.push(s)) : s.functionCalls ? (e && t.push(e), t.push(s), e = null) : s.functionResponse ? t[t.length - 1] = {
|
|
51
|
+
...t[t.length - 1],
|
|
52
52
|
functionResponse: s.functionResponse
|
|
53
|
-
} :
|
|
53
|
+
} : e && s.protocol === e.protocol && (e.role === s.role || s.finishReason === "stop") ? (e.text += s.text, e.files = [...e.files ?? [], ...s.files ?? []]) : (e && t.push(e), e = {
|
|
54
54
|
...s
|
|
55
55
|
}));
|
|
56
|
-
return
|
|
56
|
+
return e && t.push(e), X(t);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
var
|
|
60
|
-
const
|
|
58
|
+
function ee(a) {
|
|
59
|
+
var e, n;
|
|
60
|
+
const t = ((e = a.files) == null ? void 0 : e.map(
|
|
61
61
|
(s) => ({
|
|
62
62
|
type: "file",
|
|
63
63
|
data: s.url,
|
|
@@ -81,53 +81,53 @@ function tt(a) {
|
|
|
81
81
|
} : {
|
|
82
82
|
id: a.id,
|
|
83
83
|
role: a.role,
|
|
84
|
-
content: a.type === "reasoning" ? [{ type: "reasoning", text: a.text }, ...
|
|
84
|
+
content: a.type === "reasoning" ? [{ type: "reasoning", text: a.text }, ...t] : [{ type: "text", text: a.text }, ...t]
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
class
|
|
87
|
+
class x {
|
|
88
88
|
constructor() {
|
|
89
89
|
o(this, "statusChangeCallbacks", []);
|
|
90
90
|
o(this, "messageCallbacks", []);
|
|
91
91
|
}
|
|
92
|
-
addStatusChangeListener(
|
|
93
|
-
this.statusChangeCallbacks.push(
|
|
92
|
+
addStatusChangeListener(t) {
|
|
93
|
+
this.statusChangeCallbacks.push(t);
|
|
94
94
|
}
|
|
95
|
-
addMessageListener(
|
|
96
|
-
this.messageCallbacks.push(
|
|
95
|
+
addMessageListener(t) {
|
|
96
|
+
this.messageCallbacks.push(t);
|
|
97
97
|
}
|
|
98
|
-
async syncSession(
|
|
99
|
-
this.session =
|
|
98
|
+
async syncSession(t) {
|
|
99
|
+
this.session = t;
|
|
100
100
|
}
|
|
101
|
-
async notifyMessage(
|
|
102
|
-
this.messageCallbacks.forEach((
|
|
101
|
+
async notifyMessage(t) {
|
|
102
|
+
this.messageCallbacks.forEach((e) => e(t));
|
|
103
103
|
}
|
|
104
|
-
async notifyMessages(
|
|
105
|
-
|
|
106
|
-
this.messageCallbacks.forEach((n) => n(
|
|
104
|
+
async notifyMessages(t) {
|
|
105
|
+
t.forEach((e) => {
|
|
106
|
+
this.messageCallbacks.forEach((n) => n(e));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
-
async setSession(
|
|
110
|
-
this.session =
|
|
109
|
+
async setSession(t) {
|
|
110
|
+
this.session = t;
|
|
111
111
|
}
|
|
112
|
-
async setStatus(
|
|
113
|
-
const
|
|
114
|
-
this.status =
|
|
112
|
+
async setStatus(t) {
|
|
113
|
+
const e = this.status !== t;
|
|
114
|
+
this.status = t, e && this.statusChangeCallbacks.forEach((n) => n(t));
|
|
115
115
|
}
|
|
116
116
|
clearListeners() {
|
|
117
117
|
this.statusChangeCallbacks = [], this.messageCallbacks = [];
|
|
118
118
|
}
|
|
119
|
-
onTransaction(
|
|
119
|
+
onTransaction(t) {
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
class M extends
|
|
123
|
-
constructor(
|
|
122
|
+
class M extends x {
|
|
123
|
+
constructor(e) {
|
|
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.config =
|
|
130
|
+
this.config = e, this.status = "disconnected", this.autostart = !0;
|
|
131
131
|
}
|
|
132
132
|
getName() {
|
|
133
133
|
return "rest";
|
|
@@ -135,17 +135,17 @@ class M extends P {
|
|
|
135
135
|
getPriority() {
|
|
136
136
|
return 0;
|
|
137
137
|
}
|
|
138
|
-
async connect(
|
|
139
|
-
return this.setStatus("connected"),
|
|
138
|
+
async connect(e) {
|
|
139
|
+
return this.setStatus("connected"), e;
|
|
140
140
|
}
|
|
141
141
|
async disconnect() {
|
|
142
142
|
this.setStatus("disconnected"), this.session = null;
|
|
143
143
|
}
|
|
144
|
-
async syncSession(
|
|
145
|
-
this.session =
|
|
144
|
+
async syncSession(e) {
|
|
145
|
+
this.session = e;
|
|
146
146
|
}
|
|
147
|
-
async send(
|
|
148
|
-
const { apiUrl: n, apiKey: s, agentId: i } = this.config, r = this.session ?? "new", l =
|
|
147
|
+
async send(e) {
|
|
148
|
+
const { apiUrl: n, apiKey: s, agentId: i } = this.config, r = this.session ?? "new", l = e, d = await (await fetch(`${n}/agents/${i}/sessions/${r}/messages`, {
|
|
149
149
|
body: JSON.stringify({ userMessage: l }),
|
|
150
150
|
method: "POST",
|
|
151
151
|
headers: {
|
|
@@ -155,22 +155,22 @@ class M extends P {
|
|
|
155
155
|
}
|
|
156
156
|
})).json();
|
|
157
157
|
this.notifyMessages(
|
|
158
|
-
|
|
158
|
+
d.response.messages.map((b) => ({
|
|
159
159
|
type: "message",
|
|
160
|
-
payload:
|
|
160
|
+
payload: b
|
|
161
161
|
}))
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
class N extends
|
|
166
|
-
constructor(
|
|
165
|
+
class N extends x {
|
|
166
|
+
constructor(e) {
|
|
167
167
|
super();
|
|
168
168
|
o(this, "status");
|
|
169
169
|
o(this, "autostart");
|
|
170
170
|
o(this, "session");
|
|
171
171
|
o(this, "config");
|
|
172
172
|
o(this, "webSocket");
|
|
173
|
-
this.config =
|
|
173
|
+
this.config = e, this.status = "disconnected", this.autostart = !0, this.session = null, this.webSocket = null;
|
|
174
174
|
}
|
|
175
175
|
getName() {
|
|
176
176
|
return "websocket";
|
|
@@ -178,40 +178,40 @@ class N extends P {
|
|
|
178
178
|
getPriority() {
|
|
179
179
|
return 1;
|
|
180
180
|
}
|
|
181
|
-
async syncSession(
|
|
181
|
+
async syncSession(e) {
|
|
182
182
|
var n;
|
|
183
|
-
(n = this.config.logger) == null || n.debug("Syncing session with WebSocket protocol:",
|
|
183
|
+
(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));
|
|
184
184
|
}
|
|
185
|
-
connect(
|
|
185
|
+
connect(e) {
|
|
186
186
|
var l;
|
|
187
187
|
if (this.webSocket !== null && this.status === "connected")
|
|
188
188
|
return Promise.resolve(this.session);
|
|
189
|
-
const n =
|
|
189
|
+
const n = e || this.session || "new";
|
|
190
190
|
(l = this.config.logger) == null || l.debug("Connecting to WebSocket with sessionId:", n);
|
|
191
191
|
const s = encodeURIComponent(this.config.apiKey), i = this.config.agentId, r = `${this.config.webSocketUrl}?sessionCode=${n}&agentId=${i}&apiKey=${s}`;
|
|
192
192
|
return this.setStatus("connecting"), this.webSocket = new WebSocket(r), this.webSocket.addEventListener("open", () => {
|
|
193
193
|
this.setStatus("connected");
|
|
194
194
|
}), this.webSocket.addEventListener("message", (u) => {
|
|
195
|
-
const
|
|
196
|
-
this.notifyMessage(
|
|
195
|
+
const d = JSON.parse(u.data);
|
|
196
|
+
this.notifyMessage(d);
|
|
197
197
|
}), this.webSocket.addEventListener("close", () => {
|
|
198
198
|
var u;
|
|
199
199
|
this.setStatus("disconnected"), this.webSocket = null, (u = this.config.logger) == null || u.warn("WebSocket connection closed");
|
|
200
200
|
}), this.webSocket.addEventListener("error", (u) => {
|
|
201
|
-
var
|
|
202
|
-
this.setStatus("disconnected"), this.webSocket = null, (
|
|
201
|
+
var d;
|
|
202
|
+
this.setStatus("disconnected"), this.webSocket = null, (d = this.config.logger) == null || d.error("WebSocket error", u);
|
|
203
203
|
}), Promise.resolve(n);
|
|
204
204
|
}
|
|
205
205
|
disconnect() {
|
|
206
|
-
var
|
|
207
|
-
return (
|
|
206
|
+
var e;
|
|
207
|
+
return (e = this.config.logger) == null || e.debug("Disconnecting WebSocket"), this.webSocket && this.status === "connected" && (this.webSocket.close(), this.setStatus("disconnected"), this.webSocket = null), Promise.resolve();
|
|
208
208
|
}
|
|
209
|
-
send(
|
|
210
|
-
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify({ type: "request", payload:
|
|
209
|
+
send(e) {
|
|
210
|
+
return this.webSocket && this.status === "connected" ? (this.webSocket.send(JSON.stringify({ type: "request", payload: e })), Promise.resolve()) : Promise.reject(new Error("WebSocket is not connected"));
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
class
|
|
214
|
-
constructor(
|
|
213
|
+
class te {
|
|
214
|
+
constructor(t) {
|
|
215
215
|
o(this, "config");
|
|
216
216
|
o(this, "pc", null);
|
|
217
217
|
o(this, "ws", null);
|
|
@@ -225,9 +225,9 @@ class et {
|
|
|
225
225
|
o(this, "isConnected", !1);
|
|
226
226
|
o(this, "visualizerCallbacks", []);
|
|
227
227
|
o(this, "messageCallbacks", []);
|
|
228
|
-
this.config =
|
|
228
|
+
this.config = t;
|
|
229
229
|
}
|
|
230
|
-
async connect(
|
|
230
|
+
async connect(t) {
|
|
231
231
|
var n;
|
|
232
232
|
if (this.isConnected) return;
|
|
233
233
|
this.isConnected = !0;
|
|
@@ -276,15 +276,15 @@ class et {
|
|
|
276
276
|
});
|
|
277
277
|
};
|
|
278
278
|
};
|
|
279
|
-
const
|
|
280
|
-
this.ws = new WebSocket(`${
|
|
279
|
+
const e = this.config.webrtcUrl || "wss://persona.applica.guru/api/webrtc";
|
|
280
|
+
this.ws = new WebSocket(`${e}?apiKey=${encodeURIComponent(this.config.apiKey)}`), this.ws.onopen = async () => {
|
|
281
281
|
var l, u;
|
|
282
282
|
const s = await this.pc.createOffer();
|
|
283
283
|
await this.pc.setLocalDescription(s);
|
|
284
284
|
const i = {
|
|
285
285
|
apiKey: this.config.apiKey,
|
|
286
286
|
agentId: this.config.agentId,
|
|
287
|
-
sessionCode:
|
|
287
|
+
sessionCode: t
|
|
288
288
|
};
|
|
289
289
|
(l = this.config.logger) == null || l.debug("Opening connection to WebRTC server: ", i);
|
|
290
290
|
const r = {
|
|
@@ -316,45 +316,45 @@ class et {
|
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
318
|
async disconnect() {
|
|
319
|
-
var
|
|
320
|
-
this.isConnected && (this.isConnected = !1, ((
|
|
319
|
+
var t;
|
|
320
|
+
this.isConnected && (this.isConnected = !1, ((t = this.ws) == null ? void 0 : t.readyState) === WebSocket.OPEN && this.ws.close(), this.pc && this.pc.close(), this.localStream && this.localStream.getTracks().forEach((e) => e.stop()), this.remoteStream = new MediaStream(), this.audioCtx && (await this.audioCtx.close(), this.audioCtx = null), this._stopAnalyzers());
|
|
321
321
|
}
|
|
322
|
-
addVisualizerCallback(
|
|
323
|
-
this.visualizerCallbacks.push(
|
|
322
|
+
addVisualizerCallback(t) {
|
|
323
|
+
this.visualizerCallbacks.push(t);
|
|
324
324
|
}
|
|
325
|
-
addMessageCallback(
|
|
326
|
-
this.messageCallbacks.push(
|
|
325
|
+
addMessageCallback(t) {
|
|
326
|
+
this.messageCallbacks.push(t);
|
|
327
327
|
}
|
|
328
|
-
createDataChannel(
|
|
329
|
-
this.pc && (this.dataChannel = this.pc.createDataChannel(
|
|
330
|
-
var
|
|
331
|
-
return (
|
|
332
|
-
}, this.dataChannel.onmessage = (
|
|
328
|
+
createDataChannel(t = "messages") {
|
|
329
|
+
this.pc && (this.dataChannel = this.pc.createDataChannel(t), this.dataChannel.onopen = () => {
|
|
330
|
+
var e;
|
|
331
|
+
return (e = this.config.logger) == null ? void 0 : e.info("Data channel opened");
|
|
332
|
+
}, this.dataChannel.onmessage = (e) => {
|
|
333
333
|
this.messageCallbacks.forEach((n) => {
|
|
334
|
-
n(
|
|
334
|
+
n(e);
|
|
335
335
|
});
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
|
-
sendMessage(
|
|
339
|
-
var
|
|
338
|
+
sendMessage(t) {
|
|
339
|
+
var e, n;
|
|
340
340
|
if (!this.dataChannel) {
|
|
341
|
-
(
|
|
341
|
+
(e = this.config.logger) == null || e.warn("Data channel is not open, cannot send message");
|
|
342
342
|
return;
|
|
343
343
|
}
|
|
344
|
-
this.dataChannel.send(JSON.stringify({ type: "request", payload:
|
|
344
|
+
this.dataChannel.send(JSON.stringify({ type: "request", payload: t })), (n = this.config.logger) == null || n.info("Sent message:", t);
|
|
345
345
|
}
|
|
346
346
|
_startAnalyzers() {
|
|
347
347
|
if (!this.localStream || !this.remoteStream || this.visualizerCallbacks.length === 0)
|
|
348
348
|
return;
|
|
349
349
|
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,
|
|
350
|
+
const t = this.audioCtx.createMediaStreamSource(this.localStream), e = this.audioCtx.createMediaStreamSource(this.remoteStream);
|
|
351
|
+
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);
|
|
352
352
|
const n = () => {
|
|
353
353
|
if (!this.localAnalyser || !this.remoteAnalyser || this.visualizerCallbacks.length === 0)
|
|
354
354
|
return;
|
|
355
355
|
const s = new Uint8Array(this.localAnalyser.frequencyBinCount), i = new Uint8Array(this.remoteAnalyser.frequencyBinCount);
|
|
356
356
|
this.localAnalyser.getByteFrequencyData(s), this.remoteAnalyser.getByteFrequencyData(i);
|
|
357
|
-
const r = s.reduce((u,
|
|
357
|
+
const r = s.reduce((u, d) => u + d, 0) / s.length, l = i.reduce((u, d) => u + d, 0) / i.length;
|
|
358
358
|
this.visualizerCallbacks.length > 0 && this.visualizerCallbacks.forEach((u) => {
|
|
359
359
|
u({
|
|
360
360
|
localAmplitude: r,
|
|
@@ -368,15 +368,15 @@ class et {
|
|
|
368
368
|
this.analyzerFrame && (cancelAnimationFrame(this.analyzerFrame), this.analyzerFrame = null), this.localAnalyser = null, this.remoteAnalyser = null;
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
|
-
class I extends
|
|
372
|
-
constructor(
|
|
371
|
+
class I extends x {
|
|
372
|
+
constructor(e) {
|
|
373
373
|
super();
|
|
374
374
|
o(this, "status");
|
|
375
375
|
o(this, "session");
|
|
376
376
|
o(this, "autostart");
|
|
377
377
|
o(this, "config");
|
|
378
378
|
o(this, "webRTCClient");
|
|
379
|
-
this.config =
|
|
379
|
+
this.config = e, this.status = "disconnected", this.session = null, this.autostart = (e == null ? void 0 : e.autostart) ?? !1, this.webRTCClient = new te(e), this.webRTCClient.addMessageCallback((n) => {
|
|
380
380
|
const s = JSON.parse(n.data);
|
|
381
381
|
this.notifyMessage(s);
|
|
382
382
|
});
|
|
@@ -387,39 +387,39 @@ class I extends P {
|
|
|
387
387
|
getPriority() {
|
|
388
388
|
return 10;
|
|
389
389
|
}
|
|
390
|
-
async syncSession(
|
|
391
|
-
super.syncSession(
|
|
390
|
+
async syncSession(e) {
|
|
391
|
+
super.syncSession(e), this.status === "connected" && (await this.disconnect(), await this.connect(e));
|
|
392
392
|
}
|
|
393
|
-
async connect(
|
|
393
|
+
async connect(e) {
|
|
394
394
|
var n;
|
|
395
|
-
return this.status === "connected" ? Promise.resolve(this.session) : (this.session =
|
|
395
|
+
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);
|
|
396
396
|
}
|
|
397
397
|
async disconnect() {
|
|
398
|
-
var
|
|
398
|
+
var e, n, s;
|
|
399
399
|
if (this.status === "disconnected")
|
|
400
|
-
return (
|
|
400
|
+
return (e = this.config.logger) == null || e.warn("Already disconnected"), Promise.resolve();
|
|
401
401
|
await this.webRTCClient.disconnect(), this.setStatus("disconnected"), (s = (n = this.config) == null ? void 0 : n.logger) == null || s.debug("Disconnected from WebRTC");
|
|
402
402
|
}
|
|
403
|
-
send(
|
|
404
|
-
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendMessage(
|
|
403
|
+
send(e) {
|
|
404
|
+
return this.status !== "connected" ? Promise.reject(new Error("Not connected")) : (this.webRTCClient.sendMessage(e), Promise.resolve());
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
|
-
class
|
|
408
|
-
constructor(
|
|
407
|
+
class se {
|
|
408
|
+
constructor(t) {
|
|
409
409
|
o(this, "config");
|
|
410
|
-
this.config =
|
|
410
|
+
this.config = t;
|
|
411
411
|
}
|
|
412
|
-
async complete(
|
|
412
|
+
async complete(t, e) {
|
|
413
413
|
var n;
|
|
414
|
-
await this.persist(
|
|
414
|
+
await this.persist(t, { ...e, success: !0 }), (n = this.config.logger) == null || n.debug("Transaction completed:", t);
|
|
415
415
|
}
|
|
416
|
-
async fail(
|
|
416
|
+
async fail(t, e) {
|
|
417
417
|
var n;
|
|
418
|
-
await this.persist(
|
|
418
|
+
await this.persist(t, { ...e, success: !1 }), (n = this.config.logger) == null || n.debug("Transaction failed:", { ...t, ...e });
|
|
419
419
|
}
|
|
420
|
-
async persist(
|
|
421
|
-
await fetch(`${this.config.apiUrl}/transactions/${
|
|
422
|
-
body: JSON.stringify(
|
|
420
|
+
async persist(t, e) {
|
|
421
|
+
await fetch(`${this.config.apiUrl}/transactions/${t.id}`, {
|
|
422
|
+
body: JSON.stringify(e),
|
|
423
423
|
method: "POST",
|
|
424
424
|
headers: {
|
|
425
425
|
"Content-Type": "application/json",
|
|
@@ -429,22 +429,22 @@ class st {
|
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
class
|
|
433
|
-
constructor(
|
|
432
|
+
class ne {
|
|
433
|
+
constructor(t, e) {
|
|
434
434
|
o(this, "transaction");
|
|
435
435
|
o(this, "manager");
|
|
436
|
-
this.transaction =
|
|
436
|
+
this.transaction = t, this.manager = e;
|
|
437
437
|
}
|
|
438
438
|
getFunctionCall() {
|
|
439
439
|
return this.transaction.functionCall;
|
|
440
440
|
}
|
|
441
|
-
async invoke(
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
441
|
+
async invoke(t) {
|
|
442
|
+
const e = this.transaction.functionCall;
|
|
443
|
+
if (!e) {
|
|
444
444
|
await this.fail("No function call found");
|
|
445
445
|
return;
|
|
446
446
|
}
|
|
447
|
-
const n =
|
|
447
|
+
const n = e.name, s = e.args, i = t[n];
|
|
448
448
|
if (!i) {
|
|
449
449
|
await this.fail(`Tool ${n} not found`);
|
|
450
450
|
return;
|
|
@@ -456,22 +456,22 @@ class nt {
|
|
|
456
456
|
await this.fail(`Error executing tool ${n}: ${r}`);
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
|
-
async complete(
|
|
460
|
-
await this.manager.complete(this.transaction, { success: !0, output:
|
|
459
|
+
async complete(t) {
|
|
460
|
+
await this.manager.complete(this.transaction, { success: !0, output: t, error: null });
|
|
461
461
|
}
|
|
462
|
-
async fail(
|
|
463
|
-
await this.manager.fail(this.transaction, { success: !1, output: null, error:
|
|
462
|
+
async fail(t) {
|
|
463
|
+
await this.manager.fail(this.transaction, { success: !1, output: null, error: t });
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
class
|
|
467
|
-
constructor(
|
|
466
|
+
class ie extends x {
|
|
467
|
+
constructor(e) {
|
|
468
468
|
super();
|
|
469
469
|
o(this, "status");
|
|
470
470
|
o(this, "autostart");
|
|
471
471
|
o(this, "session");
|
|
472
472
|
o(this, "config");
|
|
473
473
|
o(this, "notify", !0);
|
|
474
|
-
this.config =
|
|
474
|
+
this.config = e, this.status = "disconnected", this.autostart = !0;
|
|
475
475
|
}
|
|
476
476
|
getName() {
|
|
477
477
|
return "transaction";
|
|
@@ -479,223 +479,223 @@ class it extends P {
|
|
|
479
479
|
getPriority() {
|
|
480
480
|
return 0;
|
|
481
481
|
}
|
|
482
|
-
async connect(
|
|
483
|
-
return this.setStatus("connected"),
|
|
482
|
+
async connect(e) {
|
|
483
|
+
return this.setStatus("connected"), e;
|
|
484
484
|
}
|
|
485
485
|
async disconnect() {
|
|
486
486
|
this.setStatus("disconnected"), this.session = null;
|
|
487
487
|
}
|
|
488
|
-
async syncSession(
|
|
489
|
-
this.session =
|
|
488
|
+
async syncSession(e) {
|
|
489
|
+
this.session = e;
|
|
490
490
|
}
|
|
491
|
-
async send(
|
|
491
|
+
async send(e) {
|
|
492
492
|
var n;
|
|
493
|
-
throw (n = this.config.logger) == null || n.debug("Sending message:",
|
|
493
|
+
throw (n = this.config.logger) == null || n.debug("Sending message:", e), new Error("Not implemented");
|
|
494
494
|
}
|
|
495
|
-
onTransaction(
|
|
495
|
+
onTransaction(e) {
|
|
496
496
|
var i;
|
|
497
497
|
if (!this.config.onTransaction) {
|
|
498
498
|
(i = this.config.logger) == null || i.error("Transaction protocol config is not set");
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
|
-
const n = new
|
|
501
|
+
const n = new se(this.config), s = new ne(e, n);
|
|
502
502
|
this.config.onTransaction(s);
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
-
const
|
|
506
|
-
function
|
|
507
|
-
return new Promise((
|
|
505
|
+
const R = K(void 0);
|
|
506
|
+
function ae(a) {
|
|
507
|
+
return new Promise((t, e) => {
|
|
508
508
|
const n = new FileReader();
|
|
509
509
|
n.readAsDataURL(a), n.onload = () => {
|
|
510
510
|
const i = n.result.split(";base64,")[1];
|
|
511
|
-
|
|
511
|
+
t(i);
|
|
512
512
|
}, n.onerror = (s) => {
|
|
513
|
-
|
|
513
|
+
e(s);
|
|
514
514
|
};
|
|
515
515
|
});
|
|
516
516
|
}
|
|
517
|
-
function
|
|
517
|
+
function oe({
|
|
518
518
|
dev: a = !1,
|
|
519
|
-
protocols:
|
|
520
|
-
logger:
|
|
519
|
+
protocols: t,
|
|
520
|
+
logger: e,
|
|
521
521
|
children: n,
|
|
522
522
|
session: s = "new",
|
|
523
523
|
...i
|
|
524
524
|
}) {
|
|
525
|
-
const [r, l] =
|
|
526
|
-
if (Array.isArray(
|
|
527
|
-
return
|
|
528
|
-
if (typeof
|
|
525
|
+
const [r, l] = P(!1), [u, d] = P([]), [b, D] = P(s), [S, W] = P(/* @__PURE__ */ new Map()), T = q(!1), m = _(() => {
|
|
526
|
+
if (Array.isArray(t))
|
|
527
|
+
return t;
|
|
528
|
+
if (typeof t == "object" && t !== null) {
|
|
529
529
|
const c = a ? "localhost:8000" : "persona.applica.guru/api", f = a ? "http" : "https", p = a ? "ws" : "wss";
|
|
530
|
-
let
|
|
531
|
-
switch (
|
|
530
|
+
let g = Object.keys(t).map((y) => {
|
|
531
|
+
switch (y) {
|
|
532
532
|
case "rest":
|
|
533
|
-
const
|
|
534
|
-
return
|
|
533
|
+
const h = t[y];
|
|
534
|
+
return h === !0 ? new M({
|
|
535
535
|
apiUrl: `${f}://${c}`,
|
|
536
536
|
apiKey: i.apiKey,
|
|
537
537
|
agentId: i.agentId,
|
|
538
|
-
logger:
|
|
539
|
-
}) : new M(
|
|
538
|
+
logger: e
|
|
539
|
+
}) : typeof h == "object" && h !== null ? new M(h) : null;
|
|
540
540
|
case "webrtc":
|
|
541
|
-
const
|
|
542
|
-
return
|
|
541
|
+
const w = t[y];
|
|
542
|
+
return w === !0 ? new I({
|
|
543
543
|
webrtcUrl: `${p}://${c}/webrtc`,
|
|
544
544
|
apiKey: i.apiKey,
|
|
545
545
|
agentId: i.agentId,
|
|
546
|
-
logger:
|
|
547
|
-
}) : new I(
|
|
546
|
+
logger: e
|
|
547
|
+
}) : typeof w == "object" && w !== null ? new I(w) : null;
|
|
548
548
|
case "websocket":
|
|
549
|
-
const
|
|
550
|
-
return
|
|
549
|
+
const k = t[y];
|
|
550
|
+
return k === !0 ? new N({
|
|
551
551
|
webSocketUrl: `${p}://${c}/websocket`,
|
|
552
552
|
apiKey: i.apiKey,
|
|
553
553
|
agentId: i.agentId,
|
|
554
|
-
logger:
|
|
555
|
-
}) : new N(
|
|
554
|
+
logger: e
|
|
555
|
+
}) : typeof k == "object" && k !== null ? new N(k) : null;
|
|
556
556
|
default:
|
|
557
|
-
throw new Error(`Unknown protocol: ${
|
|
557
|
+
throw new Error(`Unknown protocol: ${y}`);
|
|
558
558
|
}
|
|
559
|
-
});
|
|
560
|
-
return i.tools &&
|
|
561
|
-
new
|
|
559
|
+
}).filter((y) => y !== null);
|
|
560
|
+
return i.tools && g.push(
|
|
561
|
+
new ie({
|
|
562
562
|
apiUrl: `${f}://${c}`,
|
|
563
563
|
apiKey: i.apiKey,
|
|
564
564
|
agentId: i.agentId,
|
|
565
|
-
onTransaction: async (
|
|
566
|
-
await
|
|
565
|
+
onTransaction: async (y) => {
|
|
566
|
+
await y.invoke(i.tools);
|
|
567
567
|
},
|
|
568
|
-
logger:
|
|
568
|
+
logger: e
|
|
569
569
|
})
|
|
570
|
-
),
|
|
570
|
+
), g;
|
|
571
571
|
}
|
|
572
572
|
throw new Error("Invalid protocols configuration");
|
|
573
573
|
}, []);
|
|
574
574
|
B(() => {
|
|
575
|
-
|
|
575
|
+
T.current || (T.current = !0, e == null || e.debug(
|
|
576
576
|
"Initializing protocols: ",
|
|
577
577
|
m.map((c) => c.getName())
|
|
578
578
|
), m.forEach((c) => {
|
|
579
|
-
c.setSession(
|
|
580
|
-
|
|
579
|
+
c.setSession(b), c.clearListeners(), c.addStatusChangeListener((f) => {
|
|
580
|
+
e == null || e.debug(`${c.getName()} has notified new status: ${f}`), S.set(c.getName(), f), W(new Map(S));
|
|
581
581
|
}), c.addMessageListener((f) => {
|
|
582
582
|
if (f.type === "message") {
|
|
583
583
|
const p = f.payload;
|
|
584
|
-
|
|
585
|
-
(
|
|
584
|
+
d(
|
|
585
|
+
(g) => Z([...g, { ...p, protocol: c.getName() }])
|
|
586
586
|
);
|
|
587
587
|
} else f.type === "transaction" && m.filter((p) => p !== c).forEach((p) => p.onTransaction(f.payload));
|
|
588
|
-
}), c.autostart && c.status === "disconnected" && (
|
|
588
|
+
}), c.autostart && c.status === "disconnected" && (e == null || e.debug(`Connecting to protocol: ${c.getName()}`), c.connect(b));
|
|
589
589
|
}));
|
|
590
|
-
}, [
|
|
591
|
-
const
|
|
592
|
-
var
|
|
593
|
-
if (((
|
|
590
|
+
}, [b, m, e, S]);
|
|
591
|
+
const j = async (c) => {
|
|
592
|
+
var y;
|
|
593
|
+
if (((y = c.content[0]) == null ? void 0 : y.type) !== "text") throw new Error("Only text messages are supported");
|
|
594
594
|
const f = c.content[0].text;
|
|
595
|
-
|
|
596
|
-
const p = m.sort((
|
|
595
|
+
d((h) => [...h, { role: "user", type: "text", text: f }]), l(!0);
|
|
596
|
+
const p = m.sort((h, w) => w.getPriority() - h.getPriority()).find((h) => h.status === "connected"), g = [];
|
|
597
597
|
if (c.attachments)
|
|
598
|
-
for (const
|
|
599
|
-
|
|
598
|
+
for (const h of c.attachments)
|
|
599
|
+
h.contentType.startsWith("image/") && h.file && g.push({
|
|
600
600
|
role: "user",
|
|
601
601
|
image: {
|
|
602
|
-
contentType:
|
|
603
|
-
content: await
|
|
602
|
+
contentType: h.contentType,
|
|
603
|
+
content: await ae(h.file)
|
|
604
604
|
},
|
|
605
605
|
text: "",
|
|
606
606
|
type: "text"
|
|
607
607
|
});
|
|
608
|
-
c.content &&
|
|
608
|
+
c.content && g.push({
|
|
609
609
|
role: "user",
|
|
610
610
|
text: c.content[0].text,
|
|
611
611
|
type: "text"
|
|
612
|
-
}),
|
|
613
|
-
},
|
|
612
|
+
}), e == null || e.debug("Sending message:", g), await (p == null ? void 0 : p.send(g)), l(!1);
|
|
613
|
+
}, O = v(() => (l(!1), d([]), D("new"), Promise.resolve()), []), U = v(() => Promise.resolve(), []), L = Y({
|
|
614
614
|
isRunning: r,
|
|
615
615
|
messages: u,
|
|
616
|
-
convertMessage:
|
|
617
|
-
onNew:
|
|
618
|
-
onCancel:
|
|
619
|
-
onReload:
|
|
616
|
+
convertMessage: ee,
|
|
617
|
+
onNew: j,
|
|
618
|
+
onCancel: O,
|
|
619
|
+
onReload: U,
|
|
620
620
|
adapters: {
|
|
621
621
|
attachments: new G([new V()])
|
|
622
622
|
}
|
|
623
623
|
});
|
|
624
|
-
return /* @__PURE__ */
|
|
624
|
+
return /* @__PURE__ */ A.jsx(R.Provider, { value: { protocols: m, protocolsStatus: S }, children: /* @__PURE__ */ A.jsx(H, { runtime: L, children: n }) });
|
|
625
625
|
}
|
|
626
|
-
function
|
|
627
|
-
return /* @__PURE__ */
|
|
626
|
+
function he({ children: a, ...t }) {
|
|
627
|
+
return /* @__PURE__ */ A.jsx(oe, { ...t, children: a });
|
|
628
628
|
}
|
|
629
|
-
function
|
|
630
|
-
const a =
|
|
629
|
+
function de() {
|
|
630
|
+
const a = E(R);
|
|
631
631
|
if (!a)
|
|
632
632
|
throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");
|
|
633
633
|
return a;
|
|
634
634
|
}
|
|
635
|
-
function
|
|
636
|
-
const
|
|
637
|
-
if (!e)
|
|
638
|
-
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
639
|
-
const t = e.protocols.find((s) => s.getName() === a);
|
|
635
|
+
function re(a) {
|
|
636
|
+
const t = E(R);
|
|
640
637
|
if (!t)
|
|
638
|
+
throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");
|
|
639
|
+
const e = t.protocols.find((s) => s.getName() === a);
|
|
640
|
+
if (!e)
|
|
641
641
|
return null;
|
|
642
|
-
const n =
|
|
642
|
+
const n = t.protocolsStatus.get(e.getName());
|
|
643
643
|
return {
|
|
644
|
-
...
|
|
645
|
-
connect:
|
|
646
|
-
disconnect:
|
|
647
|
-
send:
|
|
648
|
-
setSession:
|
|
649
|
-
addStatusChangeListener:
|
|
650
|
-
addMessageListener:
|
|
651
|
-
getName:
|
|
652
|
-
getPriority:
|
|
653
|
-
status: n ||
|
|
644
|
+
...e,
|
|
645
|
+
connect: e.connect.bind(e),
|
|
646
|
+
disconnect: e.disconnect.bind(e),
|
|
647
|
+
send: e.send.bind(e),
|
|
648
|
+
setSession: e.setSession.bind(e),
|
|
649
|
+
addStatusChangeListener: e.addStatusChangeListener.bind(e),
|
|
650
|
+
addMessageListener: e.addMessageListener.bind(e),
|
|
651
|
+
getName: e.getName.bind(e),
|
|
652
|
+
getPriority: e.getPriority.bind(e),
|
|
653
|
+
status: n || e.status
|
|
654
654
|
};
|
|
655
655
|
}
|
|
656
|
-
function
|
|
657
|
-
const a =
|
|
656
|
+
function fe() {
|
|
657
|
+
const a = E(R);
|
|
658
658
|
if (!a)
|
|
659
659
|
throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");
|
|
660
|
-
for (const
|
|
661
|
-
if (
|
|
662
|
-
return
|
|
660
|
+
for (const t of a.protocols)
|
|
661
|
+
if (t.getName() === "rest")
|
|
662
|
+
return t.config.apiUrl;
|
|
663
663
|
throw new Error("REST protocol not found");
|
|
664
664
|
}
|
|
665
|
-
function
|
|
666
|
-
return
|
|
665
|
+
function pe() {
|
|
666
|
+
return re("webrtc");
|
|
667
667
|
}
|
|
668
|
-
class
|
|
668
|
+
class ye {
|
|
669
669
|
constructor() {
|
|
670
670
|
o(this, "prefix", "[Persona]");
|
|
671
671
|
}
|
|
672
|
-
log(
|
|
673
|
-
console.log(`${this.prefix} - ${
|
|
672
|
+
log(t, ...e) {
|
|
673
|
+
console.log(`${this.prefix} - ${t}`, ...e);
|
|
674
674
|
}
|
|
675
|
-
info(
|
|
676
|
-
console.info(`${this.prefix} - ${
|
|
675
|
+
info(t, ...e) {
|
|
676
|
+
console.info(`${this.prefix} - ${t}`, ...e);
|
|
677
677
|
}
|
|
678
|
-
warn(
|
|
679
|
-
console.warn(`${this.prefix} - ${
|
|
678
|
+
warn(t, ...e) {
|
|
679
|
+
console.warn(`${this.prefix} - ${t}`, ...e);
|
|
680
680
|
}
|
|
681
|
-
error(
|
|
682
|
-
console.error(`${this.prefix} - ${
|
|
681
|
+
error(t, ...e) {
|
|
682
|
+
console.error(`${this.prefix} - ${t}`, ...e);
|
|
683
683
|
}
|
|
684
|
-
debug(
|
|
685
|
-
console.debug(`${this.prefix} - ${
|
|
684
|
+
debug(t, ...e) {
|
|
685
|
+
console.debug(`${this.prefix} - ${t}`, ...e);
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
688
|
export {
|
|
689
|
-
|
|
690
|
-
|
|
689
|
+
ye as PersonaConsoleLogger,
|
|
690
|
+
x as PersonaProtocolBase,
|
|
691
691
|
M as PersonaRESTProtocol,
|
|
692
|
-
|
|
693
|
-
|
|
692
|
+
he as PersonaRuntimeProvider,
|
|
693
|
+
ie as PersonaTransactionProtocol,
|
|
694
694
|
I as PersonaWebRTCProtocol,
|
|
695
695
|
N as PersonaWebSocketProtocol,
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
696
|
+
de as usePersonaRuntime,
|
|
697
|
+
fe as usePersonaRuntimeEndpoint,
|
|
698
|
+
re as usePersonaRuntimeProtocol,
|
|
699
|
+
pe as usePersonaRuntimeWebRTCProtocol
|
|
700
700
|
};
|
|
701
701
|
//# sourceMappingURL=bundle.es.js.map
|