obi-sdk 0.1.2 → 0.1.4
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 +99 -65
- package/dist/index-e52b38be.js +5223 -0
- package/dist/modular/chunks/assistant-5a47c1b4.js +234 -0
- package/dist/modular/chunks/assistant-5a47c1b4.js.map +1 -0
- package/dist/modular/chunks/mitt-3c1f932d.js +20 -0
- package/dist/modular/chunks/mitt-3c1f932d.js.map +1 -0
- package/dist/modular/chunks/{index-634e0df5.js → obi-widget-0d63936f.js} +2258 -253
- package/dist/modular/chunks/obi-widget-0d63936f.js.map +1 -0
- package/dist/modular/chunks/{session-e208b5bb.js → session-88fd0dca.js} +18 -39
- package/dist/modular/chunks/session-88fd0dca.js.map +1 -0
- package/dist/modular/core.js +11 -207
- package/dist/modular/core.js.map +1 -1
- package/dist/modular/index.js +78 -400
- package/dist/modular/index.js.map +1 -1
- package/dist/modular/ui.js +29 -1992
- package/dist/modular/ui.js.map +1 -1
- package/dist/obi-loader.iife.js +1 -1
- package/dist/obi-loader.iife.js.map +1 -1
- package/dist/obi-loader.js +36 -33
- package/dist/obi-loader.js.map +1 -1
- package/dist/obi-loader.umd.cjs +1 -1
- package/dist/obi-loader.umd.cjs.map +1 -1
- package/dist/obi-sdk.es.js +8 -22713
- package/dist/obi-sdk.standalone.iife.js +72 -175
- package/dist/obi-sdk.standalone.iife.js.map +1 -1
- package/dist/obi-sdk.umd.js +121 -262
- package/dist/session-33b71dff.js +15762 -0
- package/package.json +1 -1
- package/dist/modular/chunks/index-634e0df5.js.map +0 -1
- package/dist/modular/chunks/session-e208b5bb.js.map +0 -1
package/dist/modular/index.js
CHANGED
|
@@ -1,411 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { O } from "./chunks/
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}, enqueueReplaceState: function() {
|
|
22
|
-
}, enqueueSetState: function() {
|
|
23
|
-
} }, C = Object.assign, D = {};
|
|
24
|
-
function E(a, b, e) {
|
|
25
|
-
this.props = a;
|
|
26
|
-
this.context = b;
|
|
27
|
-
this.refs = D;
|
|
28
|
-
this.updater = e || B;
|
|
29
|
-
}
|
|
30
|
-
E.prototype.isReactComponent = {};
|
|
31
|
-
E.prototype.setState = function(a, b) {
|
|
32
|
-
if ("object" !== typeof a && "function" !== typeof a && null != a)
|
|
33
|
-
throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
|
|
34
|
-
this.updater.enqueueSetState(this, a, b, "setState");
|
|
35
|
-
};
|
|
36
|
-
E.prototype.forceUpdate = function(a) {
|
|
37
|
-
this.updater.enqueueForceUpdate(this, a, "forceUpdate");
|
|
38
|
-
};
|
|
39
|
-
function F() {
|
|
40
|
-
}
|
|
41
|
-
F.prototype = E.prototype;
|
|
42
|
-
function G(a, b, e) {
|
|
43
|
-
this.props = a;
|
|
44
|
-
this.context = b;
|
|
45
|
-
this.refs = D;
|
|
46
|
-
this.updater = e || B;
|
|
47
|
-
}
|
|
48
|
-
var H = G.prototype = new F();
|
|
49
|
-
H.constructor = G;
|
|
50
|
-
C(H, E.prototype);
|
|
51
|
-
H.isPureReactComponent = true;
|
|
52
|
-
var I = Array.isArray, J = Object.prototype.hasOwnProperty, K = { current: null }, L = { key: true, ref: true, __self: true, __source: true };
|
|
53
|
-
function M(a, b, e) {
|
|
54
|
-
var d, c = {}, k = null, h = null;
|
|
55
|
-
if (null != b)
|
|
56
|
-
for (d in void 0 !== b.ref && (h = b.ref), void 0 !== b.key && (k = "" + b.key), b)
|
|
57
|
-
J.call(b, d) && !L.hasOwnProperty(d) && (c[d] = b[d]);
|
|
58
|
-
var g = arguments.length - 2;
|
|
59
|
-
if (1 === g)
|
|
60
|
-
c.children = e;
|
|
61
|
-
else if (1 < g) {
|
|
62
|
-
for (var f = Array(g), m = 0; m < g; m++)
|
|
63
|
-
f[m] = arguments[m + 2];
|
|
64
|
-
c.children = f;
|
|
65
|
-
}
|
|
66
|
-
if (a && a.defaultProps)
|
|
67
|
-
for (d in g = a.defaultProps, g)
|
|
68
|
-
void 0 === c[d] && (c[d] = g[d]);
|
|
69
|
-
return { $$typeof: l, type: a, key: k, ref: h, props: c, _owner: K.current };
|
|
70
|
-
}
|
|
71
|
-
function N(a, b) {
|
|
72
|
-
return { $$typeof: l, type: a.type, key: b, ref: a.ref, props: a.props, _owner: a._owner };
|
|
73
|
-
}
|
|
74
|
-
function O3(a) {
|
|
75
|
-
return "object" === typeof a && null !== a && a.$$typeof === l;
|
|
76
|
-
}
|
|
77
|
-
function escape(a) {
|
|
78
|
-
var b = { "=": "=0", ":": "=2" };
|
|
79
|
-
return "$" + a.replace(/[=:]/g, function(a2) {
|
|
80
|
-
return b[a2];
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
var P = /\/+/g;
|
|
84
|
-
function Q(a, b) {
|
|
85
|
-
return "object" === typeof a && null !== a && null != a.key ? escape("" + a.key) : b.toString(36);
|
|
86
|
-
}
|
|
87
|
-
function R(a, b, e, d, c) {
|
|
88
|
-
var k = typeof a;
|
|
89
|
-
if ("undefined" === k || "boolean" === k)
|
|
90
|
-
a = null;
|
|
91
|
-
var h = false;
|
|
92
|
-
if (null === a)
|
|
93
|
-
h = true;
|
|
94
|
-
else
|
|
95
|
-
switch (k) {
|
|
96
|
-
case "string":
|
|
97
|
-
case "number":
|
|
98
|
-
h = true;
|
|
99
|
-
break;
|
|
100
|
-
case "object":
|
|
101
|
-
switch (a.$$typeof) {
|
|
102
|
-
case l:
|
|
103
|
-
case n:
|
|
104
|
-
h = true;
|
|
1
|
+
import { E, a, S } from "./chunks/obi-widget-0d63936f.js";
|
|
2
|
+
import { a as a2, O } from "./chunks/assistant-5a47c1b4.js";
|
|
3
|
+
import "./chunks/mitt-3c1f932d.js";
|
|
4
|
+
const NPM_REGISTRY_URL = "https://registry.npmjs.org/obi-sdk/latest";
|
|
5
|
+
const UNPKG_BASE_URL = "https://unpkg.com/obi-sdk";
|
|
6
|
+
const getLatestVersion = () => {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
try {
|
|
9
|
+
const xhr = new XMLHttpRequest();
|
|
10
|
+
xhr.open("GET", NPM_REGISTRY_URL);
|
|
11
|
+
xhr.onload = () => {
|
|
12
|
+
if (xhr.status === 200) {
|
|
13
|
+
try {
|
|
14
|
+
const response = JSON.parse(xhr.responseText);
|
|
15
|
+
resolve(response.version);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
resolve(null);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
resolve(null);
|
|
105
21
|
}
|
|
22
|
+
};
|
|
23
|
+
xhr.onerror = () => resolve(null);
|
|
24
|
+
xhr.send();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
resolve(null);
|
|
106
27
|
}
|
|
107
|
-
if (h)
|
|
108
|
-
return h = a, c = c(h), a = "" === d ? "." + Q(h, 0) : d, I(c) ? (e = "", null != a && (e = a.replace(P, "$&/") + "/"), R(c, b, e, "", function(a2) {
|
|
109
|
-
return a2;
|
|
110
|
-
})) : null != c && (O3(c) && (c = N(c, e + (!c.key || h && h.key === c.key ? "" : ("" + c.key).replace(P, "$&/") + "/") + a)), b.push(c)), 1;
|
|
111
|
-
h = 0;
|
|
112
|
-
d = "" === d ? "." : d + ":";
|
|
113
|
-
if (I(a))
|
|
114
|
-
for (var g = 0; g < a.length; g++) {
|
|
115
|
-
k = a[g];
|
|
116
|
-
var f = d + Q(k, g);
|
|
117
|
-
h += R(k, b, e, f, c);
|
|
118
|
-
}
|
|
119
|
-
else if (f = A(a), "function" === typeof f)
|
|
120
|
-
for (a = f.call(a), g = 0; !(k = a.next()).done; )
|
|
121
|
-
k = k.value, f = d + Q(k, g++), h += R(k, b, e, f, c);
|
|
122
|
-
else if ("object" === k)
|
|
123
|
-
throw b = String(a), Error("Objects are not valid as a React child (found: " + ("[object Object]" === b ? "object with keys {" + Object.keys(a).join(", ") + "}" : b) + "). If you meant to render a collection of children, use an array instead.");
|
|
124
|
-
return h;
|
|
125
|
-
}
|
|
126
|
-
function S(a, b, e) {
|
|
127
|
-
if (null == a)
|
|
128
|
-
return a;
|
|
129
|
-
var d = [], c = 0;
|
|
130
|
-
R(a, d, "", "", function(a2) {
|
|
131
|
-
return b.call(e, a2, c++);
|
|
132
28
|
});
|
|
133
|
-
return d;
|
|
134
|
-
}
|
|
135
|
-
function T(a) {
|
|
136
|
-
if (-1 === a._status) {
|
|
137
|
-
var b = a._result;
|
|
138
|
-
b = b();
|
|
139
|
-
b.then(function(b2) {
|
|
140
|
-
if (0 === a._status || -1 === a._status)
|
|
141
|
-
a._status = 1, a._result = b2;
|
|
142
|
-
}, function(b2) {
|
|
143
|
-
if (0 === a._status || -1 === a._status)
|
|
144
|
-
a._status = 2, a._result = b2;
|
|
145
|
-
});
|
|
146
|
-
-1 === a._status && (a._status = 0, a._result = b);
|
|
147
|
-
}
|
|
148
|
-
if (1 === a._status)
|
|
149
|
-
return a._result.default;
|
|
150
|
-
throw a._result;
|
|
151
|
-
}
|
|
152
|
-
var U = { current: null }, V = { transition: null }, W = { ReactCurrentDispatcher: U, ReactCurrentBatchConfig: V, ReactCurrentOwner: K };
|
|
153
|
-
function X() {
|
|
154
|
-
throw Error("act(...) is not supported in production builds of React.");
|
|
155
|
-
}
|
|
156
|
-
react_production_min.Children = { map: S, forEach: function(a, b, e) {
|
|
157
|
-
S(a, function() {
|
|
158
|
-
b.apply(this, arguments);
|
|
159
|
-
}, e);
|
|
160
|
-
}, count: function(a) {
|
|
161
|
-
var b = 0;
|
|
162
|
-
S(a, function() {
|
|
163
|
-
b++;
|
|
164
|
-
});
|
|
165
|
-
return b;
|
|
166
|
-
}, toArray: function(a) {
|
|
167
|
-
return S(a, function(a2) {
|
|
168
|
-
return a2;
|
|
169
|
-
}) || [];
|
|
170
|
-
}, only: function(a) {
|
|
171
|
-
if (!O3(a))
|
|
172
|
-
throw Error("React.Children.only expected to receive a single React element child.");
|
|
173
|
-
return a;
|
|
174
|
-
} };
|
|
175
|
-
react_production_min.Component = E;
|
|
176
|
-
react_production_min.Fragment = p;
|
|
177
|
-
react_production_min.Profiler = r;
|
|
178
|
-
react_production_min.PureComponent = G;
|
|
179
|
-
react_production_min.StrictMode = q;
|
|
180
|
-
react_production_min.Suspense = w;
|
|
181
|
-
react_production_min.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = W;
|
|
182
|
-
react_production_min.act = X;
|
|
183
|
-
react_production_min.cloneElement = function(a, b, e) {
|
|
184
|
-
if (null === a || void 0 === a)
|
|
185
|
-
throw Error("React.cloneElement(...): The argument must be a React element, but you passed " + a + ".");
|
|
186
|
-
var d = C({}, a.props), c = a.key, k = a.ref, h = a._owner;
|
|
187
|
-
if (null != b) {
|
|
188
|
-
void 0 !== b.ref && (k = b.ref, h = K.current);
|
|
189
|
-
void 0 !== b.key && (c = "" + b.key);
|
|
190
|
-
if (a.type && a.type.defaultProps)
|
|
191
|
-
var g = a.type.defaultProps;
|
|
192
|
-
for (f in b)
|
|
193
|
-
J.call(b, f) && !L.hasOwnProperty(f) && (d[f] = void 0 === b[f] && void 0 !== g ? g[f] : b[f]);
|
|
194
|
-
}
|
|
195
|
-
var f = arguments.length - 2;
|
|
196
|
-
if (1 === f)
|
|
197
|
-
d.children = e;
|
|
198
|
-
else if (1 < f) {
|
|
199
|
-
g = Array(f);
|
|
200
|
-
for (var m = 0; m < f; m++)
|
|
201
|
-
g[m] = arguments[m + 2];
|
|
202
|
-
d.children = g;
|
|
203
|
-
}
|
|
204
|
-
return { $$typeof: l, type: a.type, key: c, ref: k, props: d, _owner: h };
|
|
205
|
-
};
|
|
206
|
-
react_production_min.createContext = function(a) {
|
|
207
|
-
a = { $$typeof: u, _currentValue: a, _currentValue2: a, _threadCount: 0, Provider: null, Consumer: null, _defaultValue: null, _globalName: null };
|
|
208
|
-
a.Provider = { $$typeof: t, _context: a };
|
|
209
|
-
return a.Consumer = a;
|
|
210
29
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
30
|
+
const loadSDKScript = (version) => {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
if (window.ObiAssistant) {
|
|
33
|
+
resolve({
|
|
34
|
+
ObiAssistant: window.ObiAssistant,
|
|
35
|
+
ObiSDK: window.ObiSDK,
|
|
36
|
+
createSession: window.ObiSDK?.createSession
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const script = document.createElement("script");
|
|
41
|
+
const sdkVersion = version || "latest";
|
|
42
|
+
script.src = `${UNPKG_BASE_URL}@${sdkVersion}/dist/obi-sdk.standalone.iife.js`;
|
|
43
|
+
script.type = "text/javascript";
|
|
44
|
+
script.async = true;
|
|
45
|
+
script.onload = () => {
|
|
46
|
+
resolve({
|
|
47
|
+
ObiAssistant: window.ObiAssistant,
|
|
48
|
+
ObiSDK: window.ObiSDK,
|
|
49
|
+
createSession: window.ObiSDK?.createSession
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
script.onerror = () => {
|
|
53
|
+
if (sdkVersion !== "latest") {
|
|
54
|
+
console.warn("Failed to load specific version, falling back to latest");
|
|
55
|
+
script.src = `${UNPKG_BASE_URL}@latest/dist/obi-sdk.standalone.iife.js`;
|
|
56
|
+
script.onload = () => {
|
|
57
|
+
resolve({
|
|
58
|
+
ObiAssistant: window.ObiAssistant,
|
|
59
|
+
ObiSDK: window.ObiSDK,
|
|
60
|
+
createSession: window.ObiSDK?.createSession
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
reject(new Error("Failed to load Obi SDK from CDN"));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
document.head.appendChild(script);
|
|
68
|
+
});
|
|
226
69
|
};
|
|
227
|
-
|
|
228
|
-
|
|
70
|
+
const loadLatestSDK = async () => {
|
|
71
|
+
const version = await getLatestVersion();
|
|
72
|
+
return loadSDKScript(version);
|
|
229
73
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
a();
|
|
235
|
-
} finally {
|
|
236
|
-
V.transition = b;
|
|
74
|
+
const initObi = async (config) => {
|
|
75
|
+
const { ObiAssistant } = await loadLatestSDK();
|
|
76
|
+
if (!ObiAssistant) {
|
|
77
|
+
throw new Error("Obi SDK loaded but ObiAssistant not found");
|
|
237
78
|
}
|
|
238
|
-
|
|
239
|
-
react_production_min.unstable_act = X;
|
|
240
|
-
react_production_min.useCallback = function(a, b) {
|
|
241
|
-
return U.current.useCallback(a, b);
|
|
242
|
-
};
|
|
243
|
-
react_production_min.useContext = function(a) {
|
|
244
|
-
return U.current.useContext(a);
|
|
245
|
-
};
|
|
246
|
-
react_production_min.useDebugValue = function() {
|
|
247
|
-
};
|
|
248
|
-
react_production_min.useDeferredValue = function(a) {
|
|
249
|
-
return U.current.useDeferredValue(a);
|
|
250
|
-
};
|
|
251
|
-
react_production_min.useEffect = function(a, b) {
|
|
252
|
-
return U.current.useEffect(a, b);
|
|
253
|
-
};
|
|
254
|
-
react_production_min.useId = function() {
|
|
255
|
-
return U.current.useId();
|
|
256
|
-
};
|
|
257
|
-
react_production_min.useImperativeHandle = function(a, b, e) {
|
|
258
|
-
return U.current.useImperativeHandle(a, b, e);
|
|
259
|
-
};
|
|
260
|
-
react_production_min.useInsertionEffect = function(a, b) {
|
|
261
|
-
return U.current.useInsertionEffect(a, b);
|
|
262
|
-
};
|
|
263
|
-
react_production_min.useLayoutEffect = function(a, b) {
|
|
264
|
-
return U.current.useLayoutEffect(a, b);
|
|
265
|
-
};
|
|
266
|
-
react_production_min.useMemo = function(a, b) {
|
|
267
|
-
return U.current.useMemo(a, b);
|
|
268
|
-
};
|
|
269
|
-
react_production_min.useReducer = function(a, b, e) {
|
|
270
|
-
return U.current.useReducer(a, b, e);
|
|
271
|
-
};
|
|
272
|
-
react_production_min.useRef = function(a) {
|
|
273
|
-
return U.current.useRef(a);
|
|
274
|
-
};
|
|
275
|
-
react_production_min.useState = function(a) {
|
|
276
|
-
return U.current.useState(a);
|
|
277
|
-
};
|
|
278
|
-
react_production_min.useSyncExternalStore = function(a, b, e) {
|
|
279
|
-
return U.current.useSyncExternalStore(a, b, e);
|
|
280
|
-
};
|
|
281
|
-
react_production_min.useTransition = function() {
|
|
282
|
-
return U.current.useTransition();
|
|
283
|
-
};
|
|
284
|
-
react_production_min.version = "18.3.1";
|
|
285
|
-
{
|
|
286
|
-
react.exports = react_production_min;
|
|
287
|
-
}
|
|
288
|
-
var reactExports = react.exports;
|
|
289
|
-
const React = /* @__PURE__ */ getDefaultExportFromCjs(reactExports);
|
|
290
|
-
function useObiSDK(config) {
|
|
291
|
-
const [sdk, setSDK] = reactExports.useState(null);
|
|
292
|
-
const [state, setState] = reactExports.useState(SDKState.READY);
|
|
293
|
-
const [error, setError] = reactExports.useState(null);
|
|
294
|
-
reactExports.useEffect(() => {
|
|
295
|
-
const newSDK = new ObiSDK(config);
|
|
296
|
-
setSDK(newSDK);
|
|
297
|
-
newSDK.init().catch((err) => {
|
|
298
|
-
console.error("Failed to initialize Obi SDK:", err);
|
|
299
|
-
});
|
|
300
|
-
newSDK.on(EventType.STATE_CHANGE, (newState) => {
|
|
301
|
-
setState(newState);
|
|
302
|
-
});
|
|
303
|
-
newSDK.on(EventType.ERROR, (err) => {
|
|
304
|
-
setError(err);
|
|
305
|
-
});
|
|
306
|
-
return () => {
|
|
307
|
-
newSDK.dispose();
|
|
308
|
-
};
|
|
309
|
-
}, []);
|
|
310
|
-
const startVoiceRecording = async () => {
|
|
311
|
-
if (sdk) {
|
|
312
|
-
return sdk.startVoiceRecording();
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
const stopVoiceRecording = async () => {
|
|
316
|
-
if (sdk) {
|
|
317
|
-
return sdk.stopVoiceRecording();
|
|
318
|
-
}
|
|
319
|
-
return { transcript: void 0 };
|
|
320
|
-
};
|
|
321
|
-
const startScreenCapture = async () => {
|
|
322
|
-
if (sdk) {
|
|
323
|
-
return sdk.startScreenCapture();
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
const stopScreenCapture = async () => {
|
|
327
|
-
if (sdk) {
|
|
328
|
-
return sdk.stopScreenCapture();
|
|
329
|
-
}
|
|
330
|
-
return { screenshot: void 0 };
|
|
331
|
-
};
|
|
332
|
-
return {
|
|
333
|
-
sdk,
|
|
334
|
-
state,
|
|
335
|
-
error,
|
|
336
|
-
startVoiceRecording,
|
|
337
|
-
stopVoiceRecording,
|
|
338
|
-
startScreenCapture,
|
|
339
|
-
stopScreenCapture,
|
|
340
|
-
isReady: state === SDKState.READY,
|
|
341
|
-
isActive: state !== SDKState.READY,
|
|
342
|
-
isError: state === SDKState.ERROR
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
function ObiStatusWidgetReact({ state = SDKState.READY, className }) {
|
|
346
|
-
return /* @__PURE__ */ React.createElement("obi-status-widget", { state, className });
|
|
347
|
-
}
|
|
348
|
-
function ObiControlPanelReact({
|
|
349
|
-
state = SDKState.READY,
|
|
350
|
-
voiceEnabled = true,
|
|
351
|
-
screenEnabled = true,
|
|
352
|
-
onVoiceStart,
|
|
353
|
-
onScreenStart,
|
|
354
|
-
onStop,
|
|
355
|
-
className
|
|
356
|
-
}) {
|
|
357
|
-
const handleVoiceStart = () => {
|
|
358
|
-
if (onVoiceStart)
|
|
359
|
-
onVoiceStart();
|
|
360
|
-
};
|
|
361
|
-
const handleScreenStart = () => {
|
|
362
|
-
if (onScreenStart)
|
|
363
|
-
onScreenStart();
|
|
364
|
-
};
|
|
365
|
-
const handleStop = () => {
|
|
366
|
-
if (onStop)
|
|
367
|
-
onStop();
|
|
368
|
-
};
|
|
369
|
-
return /* @__PURE__ */ React.createElement(
|
|
370
|
-
"obi-control-panel",
|
|
371
|
-
{
|
|
372
|
-
state,
|
|
373
|
-
voiceEnabled,
|
|
374
|
-
screenEnabled,
|
|
375
|
-
onvoicestart: handleVoiceStart,
|
|
376
|
-
onscreenstart: handleScreenStart,
|
|
377
|
-
onstop: handleStop,
|
|
378
|
-
className
|
|
379
|
-
}
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
const VERSION = "0.1.0";
|
|
383
|
-
const createSession = async (options = {}) => {
|
|
384
|
-
const { ObiSession } = await import("./chunks/session-e208b5bb.js").then((n2) => n2.s);
|
|
385
|
-
return new ObiSession(options);
|
|
79
|
+
return ObiAssistant.init(config);
|
|
386
80
|
};
|
|
387
81
|
export {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
NavIcon,
|
|
395
|
-
NavigationBar,
|
|
396
|
-
ObiControlPanel,
|
|
397
|
-
ObiControlPanelReact,
|
|
398
|
-
ObiSDK,
|
|
399
|
-
O as ObiSDKConfigSchema,
|
|
400
|
-
O2 as ObiSession,
|
|
401
|
-
ObiStatusWidget,
|
|
402
|
-
ObiStatusWidgetReact,
|
|
403
|
-
ObiWidget,
|
|
404
|
-
SDKState,
|
|
405
|
-
SearchingLoader,
|
|
406
|
-
VERSION,
|
|
407
|
-
createSession,
|
|
408
|
-
defineCustomElements,
|
|
409
|
-
useObiSDK
|
|
82
|
+
E as EventType,
|
|
83
|
+
a2 as ObiAssistant,
|
|
84
|
+
O as ObiSDK,
|
|
85
|
+
a as ObiWidget,
|
|
86
|
+
S as SDKState,
|
|
87
|
+
initObi
|
|
410
88
|
};
|
|
411
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../node_modules/react/cjs/react.production.min.js","../../node_modules/react/index.js","../../src/integration/react/hooks.ts","../../src/integration/react/components.tsx","../../src/index.ts"],"sourcesContent":["/**\n * @license React\n * react.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var l=Symbol.for(\"react.element\"),n=Symbol.for(\"react.portal\"),p=Symbol.for(\"react.fragment\"),q=Symbol.for(\"react.strict_mode\"),r=Symbol.for(\"react.profiler\"),t=Symbol.for(\"react.provider\"),u=Symbol.for(\"react.context\"),v=Symbol.for(\"react.forward_ref\"),w=Symbol.for(\"react.suspense\"),x=Symbol.for(\"react.memo\"),y=Symbol.for(\"react.lazy\"),z=Symbol.iterator;function A(a){if(null===a||\"object\"!==typeof a)return null;a=z&&a[z]||a[\"@@iterator\"];return\"function\"===typeof a?a:null}\nvar B={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},C=Object.assign,D={};function E(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B}E.prototype.isReactComponent={};\nE.prototype.setState=function(a,b){if(\"object\"!==typeof a&&\"function\"!==typeof a&&null!=a)throw Error(\"setState(...): takes an object of state variables to update or a function which returns an object of state variables.\");this.updater.enqueueSetState(this,a,b,\"setState\")};E.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,\"forceUpdate\")};function F(){}F.prototype=E.prototype;function G(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B}var H=G.prototype=new F;\nH.constructor=G;C(H,E.prototype);H.isPureReactComponent=!0;var I=Array.isArray,J=Object.prototype.hasOwnProperty,K={current:null},L={key:!0,ref:!0,__self:!0,__source:!0};\nfunction M(a,b,e){var d,c={},k=null,h=null;if(null!=b)for(d in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(k=\"\"+b.key),b)J.call(b,d)&&!L.hasOwnProperty(d)&&(c[d]=b[d]);var g=arguments.length-2;if(1===g)c.children=e;else if(1<g){for(var f=Array(g),m=0;m<g;m++)f[m]=arguments[m+2];c.children=f}if(a&&a.defaultProps)for(d in g=a.defaultProps,g)void 0===c[d]&&(c[d]=g[d]);return{$$typeof:l,type:a,key:k,ref:h,props:c,_owner:K.current}}\nfunction N(a,b){return{$$typeof:l,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}function O(a){return\"object\"===typeof a&&null!==a&&a.$$typeof===l}function escape(a){var b={\"=\":\"=0\",\":\":\"=2\"};return\"$\"+a.replace(/[=:]/g,function(a){return b[a]})}var P=/\\/+/g;function Q(a,b){return\"object\"===typeof a&&null!==a&&null!=a.key?escape(\"\"+a.key):b.toString(36)}\nfunction R(a,b,e,d,c){var k=typeof a;if(\"undefined\"===k||\"boolean\"===k)a=null;var h=!1;if(null===a)h=!0;else switch(k){case \"string\":case \"number\":h=!0;break;case \"object\":switch(a.$$typeof){case l:case n:h=!0}}if(h)return h=a,c=c(h),a=\"\"===d?\".\"+Q(h,0):d,I(c)?(e=\"\",null!=a&&(e=a.replace(P,\"$&/\")+\"/\"),R(c,b,e,\"\",function(a){return a})):null!=c&&(O(c)&&(c=N(c,e+(!c.key||h&&h.key===c.key?\"\":(\"\"+c.key).replace(P,\"$&/\")+\"/\")+a)),b.push(c)),1;h=0;d=\"\"===d?\".\":d+\":\";if(I(a))for(var g=0;g<a.length;g++){k=\na[g];var f=d+Q(k,g);h+=R(k,b,e,f,c)}else if(f=A(a),\"function\"===typeof f)for(a=f.call(a),g=0;!(k=a.next()).done;)k=k.value,f=d+Q(k,g++),h+=R(k,b,e,f,c);else if(\"object\"===k)throw b=String(a),Error(\"Objects are not valid as a React child (found: \"+(\"[object Object]\"===b?\"object with keys {\"+Object.keys(a).join(\", \")+\"}\":b)+\"). If you meant to render a collection of children, use an array instead.\");return h}\nfunction S(a,b,e){if(null==a)return a;var d=[],c=0;R(a,d,\"\",\"\",function(a){return b.call(e,a,c++)});return d}function T(a){if(-1===a._status){var b=a._result;b=b();b.then(function(b){if(0===a._status||-1===a._status)a._status=1,a._result=b},function(b){if(0===a._status||-1===a._status)a._status=2,a._result=b});-1===a._status&&(a._status=0,a._result=b)}if(1===a._status)return a._result.default;throw a._result;}\nvar U={current:null},V={transition:null},W={ReactCurrentDispatcher:U,ReactCurrentBatchConfig:V,ReactCurrentOwner:K};function X(){throw Error(\"act(...) is not supported in production builds of React.\");}\nexports.Children={map:S,forEach:function(a,b,e){S(a,function(){b.apply(this,arguments)},e)},count:function(a){var b=0;S(a,function(){b++});return b},toArray:function(a){return S(a,function(a){return a})||[]},only:function(a){if(!O(a))throw Error(\"React.Children.only expected to receive a single React element child.\");return a}};exports.Component=E;exports.Fragment=p;exports.Profiler=r;exports.PureComponent=G;exports.StrictMode=q;exports.Suspense=w;\nexports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=W;exports.act=X;\nexports.cloneElement=function(a,b,e){if(null===a||void 0===a)throw Error(\"React.cloneElement(...): The argument must be a React element, but you passed \"+a+\".\");var d=C({},a.props),c=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=K.current);void 0!==b.key&&(c=\"\"+b.key);if(a.type&&a.type.defaultProps)var g=a.type.defaultProps;for(f in b)J.call(b,f)&&!L.hasOwnProperty(f)&&(d[f]=void 0===b[f]&&void 0!==g?g[f]:b[f])}var f=arguments.length-2;if(1===f)d.children=e;else if(1<f){g=Array(f);\nfor(var m=0;m<f;m++)g[m]=arguments[m+2];d.children=g}return{$$typeof:l,type:a.type,key:c,ref:k,props:d,_owner:h}};exports.createContext=function(a){a={$$typeof:u,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};a.Provider={$$typeof:t,_context:a};return a.Consumer=a};exports.createElement=M;exports.createFactory=function(a){var b=M.bind(null,a);b.type=a;return b};exports.createRef=function(){return{current:null}};\nexports.forwardRef=function(a){return{$$typeof:v,render:a}};exports.isValidElement=O;exports.lazy=function(a){return{$$typeof:y,_payload:{_status:-1,_result:a},_init:T}};exports.memo=function(a,b){return{$$typeof:x,type:a,compare:void 0===b?null:b}};exports.startTransition=function(a){var b=V.transition;V.transition={};try{a()}finally{V.transition=b}};exports.unstable_act=X;exports.useCallback=function(a,b){return U.current.useCallback(a,b)};exports.useContext=function(a){return U.current.useContext(a)};\nexports.useDebugValue=function(){};exports.useDeferredValue=function(a){return U.current.useDeferredValue(a)};exports.useEffect=function(a,b){return U.current.useEffect(a,b)};exports.useId=function(){return U.current.useId()};exports.useImperativeHandle=function(a,b,e){return U.current.useImperativeHandle(a,b,e)};exports.useInsertionEffect=function(a,b){return U.current.useInsertionEffect(a,b)};exports.useLayoutEffect=function(a,b){return U.current.useLayoutEffect(a,b)};\nexports.useMemo=function(a,b){return U.current.useMemo(a,b)};exports.useReducer=function(a,b,e){return U.current.useReducer(a,b,e)};exports.useRef=function(a){return U.current.useRef(a)};exports.useState=function(a){return U.current.useState(a)};exports.useSyncExternalStore=function(a,b,e){return U.current.useSyncExternalStore(a,b,e)};exports.useTransition=function(){return U.current.useTransition()};exports.version=\"18.3.1\";\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react.production.min.js');\n} else {\n module.exports = require('./cjs/react.development.js');\n}\n","// This is a mock import to satisfy TypeScript without React installed\n// When consuming this SDK with React, the actual React package will be used\n// React is defined as a peer dependency\ndeclare module \"react\" {\n export function useState<T>(initialState: T): [T, (newState: T) => void]\n export function useEffect(effect: () => void | (() => void), deps?: any[]): void\n}\n\nimport { useEffect, useState } from \"react\"\n\nimport { EventType, ObiSDKConfig, SDKState } from \"../../core/types\"\nimport { ObiSDK } from \"../../core/sdk\"\nimport { ObiError } from \"../../core/types\"\n\n// React hook for using the Obi SDK\nexport function useObiSDK(config?: Partial<ObiSDKConfig>) {\n const [sdk, setSDK] = useState<ObiSDK | null>(null)\n const [state, setState] = useState<SDKState>(SDKState.READY)\n const [error, setError] = useState<ObiError | null>(null)\n\n useEffect(() => {\n const newSDK = new ObiSDK(config)\n\n setSDK(newSDK)\n\n // Initialize SDK\n newSDK.init().catch((err: any) => {\n console.error(\"Failed to initialize Obi SDK:\", err)\n })\n\n // Set up event listeners\n newSDK.on(EventType.STATE_CHANGE, (newState: SDKState) => {\n setState(newState)\n })\n\n newSDK.on(EventType.ERROR, (err: ObiError) => {\n setError(err)\n })\n\n return () => {\n newSDK.dispose()\n }\n }, [])\n\n const startVoiceRecording = async () => {\n if (sdk) {\n return sdk.startVoiceRecording()\n }\n }\n\n const stopVoiceRecording = async () => {\n if (sdk) {\n return sdk.stopVoiceRecording()\n }\n return { transcript: undefined }\n }\n\n const startScreenCapture = async () => {\n if (sdk) {\n return sdk.startScreenCapture()\n }\n }\n\n const stopScreenCapture = async () => {\n if (sdk) {\n return sdk.stopScreenCapture()\n }\n return { screenshot: undefined }\n }\n\n return {\n sdk,\n state,\n error,\n startVoiceRecording,\n stopVoiceRecording,\n startScreenCapture,\n stopScreenCapture,\n isReady: state === SDKState.READY,\n isActive: state !== SDKState.READY,\n isError: state === SDKState.ERROR,\n }\n}\n","import React from \"react\"\n\nimport { SDKState } from \"../../core/types\"\nimport \"../../ui/components/status-widget\"\nimport \"../../ui/components/control-panel\"\nimport { useObiSDK } from \"./hooks\"\n\n// Ensure the web components are properly typed\ndeclare global {\n namespace JSX {\n interface IntrinsicElements {\n \"obi-status-widget\": React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement> & { state?: SDKState },\n HTMLElement\n >\n \"obi-control-panel\": React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement> & {\n state?: SDKState\n voiceEnabled?: boolean\n screenEnabled?: boolean\n onvoicestart?: (e: Event) => void\n onscreenstart?: (e: Event) => void\n onstop?: (e: Event) => void\n },\n HTMLElement\n >\n }\n }\n}\n\nexport interface ObiStatusWidgetProps {\n state?: SDKState\n className?: string\n}\n\nexport function ObiStatusWidgetReact({ state = SDKState.READY, className }: ObiStatusWidgetProps) {\n return <obi-status-widget state={state} className={className} />\n}\n\nexport interface ObiControlPanelProps {\n state?: SDKState\n voiceEnabled?: boolean\n screenEnabled?: boolean\n onVoiceStart?: () => void\n onScreenStart?: () => void\n onStop?: () => void\n className?: string\n}\n\nexport function ObiControlPanelReact({\n state = SDKState.READY,\n voiceEnabled = true,\n screenEnabled = true,\n onVoiceStart,\n onScreenStart,\n onStop,\n className,\n}: ObiControlPanelProps) {\n const handleVoiceStart = () => {\n if (onVoiceStart) onVoiceStart()\n }\n\n const handleScreenStart = () => {\n if (onScreenStart) onScreenStart()\n }\n\n const handleStop = () => {\n if (onStop) onStop()\n }\n\n return (\n <obi-control-panel\n state={state}\n voiceEnabled={voiceEnabled}\n screenEnabled={screenEnabled}\n onvoicestart={handleVoiceStart}\n onscreenstart={handleScreenStart}\n onstop={handleStop}\n className={className}\n />\n )\n}\n\n// A ready-to-use React component that combines the SDK and UI\nexport function ObiWidget() {\n const {\n state,\n startVoiceRecording,\n startScreenCapture,\n stopVoiceRecording,\n stopScreenCapture,\n isActive,\n } = useObiSDK()\n\n const handleVoiceStart = () => {\n startVoiceRecording()\n }\n\n const handleScreenStart = () => {\n startScreenCapture()\n }\n\n const handleStop = () => {\n if (isActive) {\n stopVoiceRecording()\n stopScreenCapture()\n }\n }\n\n return (\n <div className=\"obi-widget\">\n <ObiStatusWidgetReact state={state} />\n <ObiControlPanelReact\n state={state}\n onVoiceStart={handleVoiceStart}\n onScreenStart={handleScreenStart}\n onStop={handleStop}\n />\n </div>\n )\n}\n","export * from \"./core\"\nexport { ObiWidget } from \"./ui/components/obi-widget\"\nexport * from \"./integration\"\n\nexport const VERSION = \"0.1.0\"\n\nexport { ObiSDK } from \"./core/sdk\"\nexport type { ObiSession } from \"./core/session\"\nexport { EventType, SDKState } from \"./core/types\"\n\n// Include UI components\nexport * from \"./ui/components\"\n\n// Add a lightweight session factory that dynamically imports the heavy session implementation\nexport const createSession = async (options = {}) => {\n // Dynamically import the session module only when needed\n const { ObiSession } = await import(\"./core/session\")\n return new ObiSession(options)\n}\n"],"names":["O","a","b","reactModule","require$$0","useState","useEffect","n"],"mappings":";;;;;;;;;;AASa,IAAI,IAAE,OAAO,IAAI,eAAe,GAAE,IAAE,OAAO,IAAI,cAAc,GAAE,IAAE,OAAO,IAAI,gBAAgB,GAAE,IAAE,OAAO,IAAI,mBAAmB,GAAE,IAAE,OAAO,IAAI,gBAAgB,GAAE,IAAE,OAAO,IAAI,gBAAgB,GAAE,IAAE,OAAO,IAAI,eAAe,GAAE,IAAE,OAAO,IAAI,mBAAmB,GAAE,IAAE,OAAO,IAAI,gBAAgB,GAAE,IAAE,OAAO,IAAI,YAAY,GAAE,IAAE,OAAO,IAAI,YAAY,GAAE,IAAE,OAAO;AAAS,SAAS,EAAE,GAAE;AAAC,MAAG,SAAO,KAAG,aAAW,OAAO;AAAE,WAAO;AAAK,MAAE,KAAG,EAAE,CAAC,KAAG,EAAE,YAAY;AAAE,SAAM,eAAa,OAAO,IAAE,IAAE;AAAI;AAC1e,IAAI,IAAE,EAAC,WAAU,WAAU;AAAC,SAAM;AAAE,GAAE,oBAAmB,WAAU;AAAA,GAAG,qBAAoB,WAAU;AAAA,GAAG,iBAAgB,WAAU;AAAA,EAAE,GAAE,IAAE,OAAO,QAAO,IAAE,CAAA;AAAG,SAAS,EAAE,GAAE,GAAE,GAAE;AAAC,OAAK,QAAM;AAAE,OAAK,UAAQ;AAAE,OAAK,OAAK;AAAE,OAAK,UAAQ,KAAG;AAAC;AAAC,EAAE,UAAU,mBAAiB;AACnQ,EAAE,UAAU,WAAS,SAAS,GAAE,GAAE;AAAC,MAAG,aAAW,OAAO,KAAG,eAAa,OAAO,KAAG,QAAM;AAAE,UAAM,MAAM,uHAAuH;AAAE,OAAK,QAAQ,gBAAgB,MAAK,GAAE,GAAE,UAAU;AAAC;AAAE,EAAE,UAAU,cAAY,SAAS,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}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/loader/index.ts"],"sourcesContent":["import type { ObiAssistantConfig } from \"../core/assistant\"\n// Constants for SDK loading\nconst NPM_REGISTRY_URL = \"https://registry.npmjs.org/obi-sdk/latest\"\nconst UNPKG_BASE_URL = \"https://unpkg.com/obi-sdk\"\n\n/**\n * Interface for the ObiSDK module that's loaded from CDN\n */\ninterface ObiSDKModule {\n ObiAssistant: {\n init: (config: ObiAssistantConfig) => HTMLElement\n }\n ObiSDK: any\n createSession: (options: any) => any\n}\n\n/**\n * Gets the latest version from npm registry\n */\nconst getLatestVersion = (): Promise<string | null> => {\n return new Promise((resolve) => {\n try {\n const xhr = new XMLHttpRequest()\n xhr.open(\"GET\", NPM_REGISTRY_URL)\n xhr.onload = () => {\n if (xhr.status === 200) {\n try {\n const response = JSON.parse(xhr.responseText)\n resolve(response.version)\n } catch (e) {\n resolve(null)\n }\n } else {\n resolve(null)\n }\n }\n xhr.onerror = () => resolve(null)\n xhr.send()\n } catch (e) {\n resolve(null)\n }\n })\n}\n\n/**\n * Loads the SDK script with the specified version\n */\nconst loadSDKScript = (version: string | null): Promise<ObiSDKModule> => {\n return new Promise((resolve, reject) => {\n // Check if already loaded in the window object\n if ((window as any).ObiAssistant) {\n resolve({\n ObiAssistant: (window as any).ObiAssistant,\n ObiSDK: (window as any).ObiSDK,\n createSession: (window as any).ObiSDK?.createSession,\n })\n return\n }\n\n const script = document.createElement(\"script\")\n const sdkVersion = version || \"latest\"\n script.src = `${UNPKG_BASE_URL}@${sdkVersion}/dist/obi-sdk.standalone.iife.js`\n script.type = \"text/javascript\"\n script.async = true\n\n script.onload = () => {\n resolve({\n ObiAssistant: (window as any).ObiAssistant,\n ObiSDK: (window as any).ObiSDK,\n createSession: (window as any).ObiSDK?.createSession,\n })\n }\n\n script.onerror = () => {\n if (sdkVersion !== \"latest\") {\n console.warn(\"Failed to load specific version, falling back to latest\")\n script.src = `${UNPKG_BASE_URL}@latest/dist/obi-sdk.standalone.iife.js`\n script.onload = () => {\n resolve({\n ObiAssistant: (window as any).ObiAssistant,\n ObiSDK: (window as any).ObiSDK,\n createSession: (window as any).ObiSDK?.createSession,\n })\n }\n } else {\n reject(new Error(\"Failed to load Obi SDK from CDN\"))\n }\n }\n\n document.head.appendChild(script)\n })\n}\n\n/**\n * Dynamically loads the latest Obi SDK script\n * Uses same version detection mechanism as the inline script\n */\nexport const loadLatestSDK = async (): Promise<ObiSDKModule> => {\n const version = await getLatestVersion()\n return loadSDKScript(version)\n}\n\n/**\n * Initialize the Obi Assistant widget with the latest SDK version\n */\nexport const initObi = async (config: ObiAssistantConfig): Promise<HTMLElement> => {\n const { ObiAssistant } = await loadLatestSDK()\n\n if (!ObiAssistant) {\n throw new Error(\"Obi SDK loaded but ObiAssistant not found\")\n }\n\n return ObiAssistant.init(config)\n}\n\n/**\n * Get the latest SDK instance for advanced usage\n */\nexport const getLatestSDK = async () => {\n const { ObiSDK } = await loadLatestSDK()\n\n if (!ObiSDK) {\n throw new Error(\"Obi SDK loaded but SDK instance not found\")\n }\n\n return ObiSDK\n}\n\n/**\n * Create a session using the latest SDK\n */\nexport const createLatestSession = async (options = {}) => {\n const { createSession } = await loadLatestSDK()\n\n if (!createSession) {\n throw new Error(\"Obi SDK loaded but createSession not found\")\n }\n\n return createSession(options)\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AAgBvB,MAAM,mBAAmB,MAA8B;AAC9C,SAAA,IAAI,QAAQ,CAAC,YAAY;AAC1B,QAAA;AACI,YAAA,MAAM,IAAI;AACZ,UAAA,KAAK,OAAO,gBAAgB;AAChC,UAAI,SAAS,MAAM;AACb,YAAA,IAAI,WAAW,KAAK;AAClB,cAAA;AACF,kBAAM,WAAW,KAAK,MAAM,IAAI,YAAY;AAC5C,oBAAQ,SAAS,OAAO;AAAA,mBACjB,GAAG;AACV,oBAAQ,IAAI;AAAA,UACd;AAAA,QAAA,OACK;AACL,kBAAQ,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