@xpert-ai/chatkit-ui5 0.0.1 → 0.1.0
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 +6 -3
- package/dist/chatkit.cjs +4 -1252
- package/dist/chatkit.cjs.map +1 -1
- package/dist/chatkit.ui5.js +4 -1252
- package/dist/chatkit.ui5.js.map +1 -1
- package/dist/index.js +4 -1252
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -1,1251 +1,3 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
5
|
-
var __typeError = (msg) => {
|
|
6
|
-
throw TypeError(msg);
|
|
7
|
-
};
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
10
|
-
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
11
|
-
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
12
|
-
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
13
|
-
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
14
|
-
var __runInitializers = (array, flags, self, value) => {
|
|
15
|
-
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self);
|
|
16
|
-
return value;
|
|
17
|
-
};
|
|
18
|
-
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
19
|
-
var it, done, ctx, access, k = flags & 7, s = false, p = false;
|
|
20
|
-
var j = 2, key = __decoratorStrings[k + 5];
|
|
21
|
-
var extraInitializers = array[j] || (array[j] = []);
|
|
22
|
-
var desc = (target = target.prototype, __getOwnPropDesc(target, name));
|
|
23
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
24
|
-
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
25
|
-
{
|
|
26
|
-
ctx.static = s, ctx.private = p, access = ctx.access = { has: (x) => name in x };
|
|
27
|
-
access.get = (x) => x[name];
|
|
28
|
-
}
|
|
29
|
-
it = (0, decorators[i])(desc[key], ctx), done._ = 1;
|
|
30
|
-
__expectFn(it) && (desc[key] = it);
|
|
31
|
-
}
|
|
32
|
-
return desc && __defProp(target, name, desc), target;
|
|
33
|
-
};
|
|
34
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
35
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
36
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
37
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
38
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
39
|
-
var _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _a2, _opts, _frameUrl, _frame, _wrapper, _shadow, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
|
|
40
|
-
var __defProp2 = Object.defineProperty;
|
|
41
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
42
|
-
var __publicField = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
|
-
var _a, _b;
|
|
44
|
-
class EventEmitter {
|
|
45
|
-
constructor() {
|
|
46
|
-
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
47
|
-
}
|
|
48
|
-
on(event, callback) {
|
|
49
|
-
if (!this.callbacks.has(event)) {
|
|
50
|
-
this.callbacks.set(event, /* @__PURE__ */ new Set());
|
|
51
|
-
}
|
|
52
|
-
this.callbacks.get(event).add(callback);
|
|
53
|
-
}
|
|
54
|
-
emit(event, ...args) {
|
|
55
|
-
var _a22;
|
|
56
|
-
const data = args[0];
|
|
57
|
-
(_a22 = this.callbacks.get(event)) == null ? void 0 : _a22.forEach((callback) => callback(data));
|
|
58
|
-
}
|
|
59
|
-
off(event, callback) {
|
|
60
|
-
var _a22;
|
|
61
|
-
if (!callback) {
|
|
62
|
-
this.callbacks.delete(event);
|
|
63
|
-
} else {
|
|
64
|
-
(_a22 = this.callbacks.get(event)) == null ? void 0 : _a22.delete(callback);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
allOff() {
|
|
68
|
-
this.callbacks.clear();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async function getBytes(stream, onChunk) {
|
|
72
|
-
const reader = stream.getReader();
|
|
73
|
-
let result;
|
|
74
|
-
while (!(result = await reader.read()).done) {
|
|
75
|
-
onChunk(result.value);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function getLines(onLine) {
|
|
79
|
-
let buffer;
|
|
80
|
-
let position;
|
|
81
|
-
let fieldLength;
|
|
82
|
-
let discardTrailingNewline = false;
|
|
83
|
-
return function onChunk(arr) {
|
|
84
|
-
if (buffer === void 0) {
|
|
85
|
-
buffer = arr;
|
|
86
|
-
position = 0;
|
|
87
|
-
fieldLength = -1;
|
|
88
|
-
} else {
|
|
89
|
-
buffer = concat(buffer, arr);
|
|
90
|
-
}
|
|
91
|
-
const bufLength = buffer.length;
|
|
92
|
-
let lineStart = 0;
|
|
93
|
-
while (position < bufLength) {
|
|
94
|
-
if (discardTrailingNewline) {
|
|
95
|
-
if (buffer[position] === 10) {
|
|
96
|
-
lineStart = ++position;
|
|
97
|
-
}
|
|
98
|
-
discardTrailingNewline = false;
|
|
99
|
-
}
|
|
100
|
-
let lineEnd = -1;
|
|
101
|
-
for (; position < bufLength && lineEnd === -1; ++position) {
|
|
102
|
-
switch (buffer[position]) {
|
|
103
|
-
case 58:
|
|
104
|
-
if (fieldLength === -1) {
|
|
105
|
-
fieldLength = position - lineStart;
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
case 13:
|
|
109
|
-
discardTrailingNewline = true;
|
|
110
|
-
case 10:
|
|
111
|
-
lineEnd = position;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (lineEnd === -1) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
|
119
|
-
lineStart = position;
|
|
120
|
-
fieldLength = -1;
|
|
121
|
-
}
|
|
122
|
-
if (lineStart === bufLength) {
|
|
123
|
-
buffer = void 0;
|
|
124
|
-
} else if (lineStart !== 0) {
|
|
125
|
-
buffer = buffer.subarray(lineStart);
|
|
126
|
-
position -= lineStart;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function getMessages(onId, onRetry, onMessage) {
|
|
131
|
-
let message = newMessage();
|
|
132
|
-
const decoder = new TextDecoder();
|
|
133
|
-
return function onLine(line, fieldLength) {
|
|
134
|
-
if (line.length === 0) {
|
|
135
|
-
onMessage === null || onMessage === void 0 ? void 0 : onMessage(message);
|
|
136
|
-
message = newMessage();
|
|
137
|
-
} else if (fieldLength > 0) {
|
|
138
|
-
const field = decoder.decode(line.subarray(0, fieldLength));
|
|
139
|
-
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 ? 2 : 1);
|
|
140
|
-
const value = decoder.decode(line.subarray(valueOffset));
|
|
141
|
-
switch (field) {
|
|
142
|
-
case "data":
|
|
143
|
-
message.data = message.data ? message.data + "\n" + value : value;
|
|
144
|
-
break;
|
|
145
|
-
case "event":
|
|
146
|
-
message.event = value;
|
|
147
|
-
break;
|
|
148
|
-
case "id":
|
|
149
|
-
onId(message.id = value);
|
|
150
|
-
break;
|
|
151
|
-
case "retry":
|
|
152
|
-
const retry = parseInt(value, 10);
|
|
153
|
-
if (!isNaN(retry)) {
|
|
154
|
-
onRetry(message.retry = retry);
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function concat(a, b) {
|
|
162
|
-
const res = new Uint8Array(a.length + b.length);
|
|
163
|
-
res.set(a);
|
|
164
|
-
res.set(b, a.length);
|
|
165
|
-
return res;
|
|
166
|
-
}
|
|
167
|
-
function newMessage() {
|
|
168
|
-
return {
|
|
169
|
-
data: "",
|
|
170
|
-
event: "",
|
|
171
|
-
id: "",
|
|
172
|
-
retry: void 0
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
var __rest = function(s, e) {
|
|
176
|
-
var t = {};
|
|
177
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
178
|
-
t[p] = s[p];
|
|
179
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
180
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
181
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
182
|
-
t[p[i]] = s[p[i]];
|
|
183
|
-
}
|
|
184
|
-
return t;
|
|
185
|
-
};
|
|
186
|
-
const EventStreamContentType = "text/event-stream";
|
|
187
|
-
const DefaultRetryInterval = 1e3;
|
|
188
|
-
const LastEventId = "last-event-id";
|
|
189
|
-
function fetchEventSource(input, _a22) {
|
|
190
|
-
var { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch } = _a22, rest = __rest(_a22, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
191
|
-
return new Promise((resolve, reject) => {
|
|
192
|
-
const headers = Object.assign({}, inputHeaders);
|
|
193
|
-
if (!headers.accept) {
|
|
194
|
-
headers.accept = EventStreamContentType;
|
|
195
|
-
}
|
|
196
|
-
let curRequestController;
|
|
197
|
-
function onVisibilityChange() {
|
|
198
|
-
curRequestController.abort();
|
|
199
|
-
if (!document.hidden) {
|
|
200
|
-
create();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (!openWhenHidden) {
|
|
204
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
205
|
-
}
|
|
206
|
-
let retryInterval = DefaultRetryInterval;
|
|
207
|
-
let retryTimer = 0;
|
|
208
|
-
function dispose() {
|
|
209
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
210
|
-
window.clearTimeout(retryTimer);
|
|
211
|
-
curRequestController.abort();
|
|
212
|
-
}
|
|
213
|
-
inputSignal === null || inputSignal === void 0 ? void 0 : inputSignal.addEventListener("abort", () => {
|
|
214
|
-
dispose();
|
|
215
|
-
resolve();
|
|
216
|
-
});
|
|
217
|
-
const fetch2 = inputFetch !== null && inputFetch !== void 0 ? inputFetch : window.fetch;
|
|
218
|
-
const onopen = inputOnOpen !== null && inputOnOpen !== void 0 ? inputOnOpen : defaultOnOpen;
|
|
219
|
-
async function create() {
|
|
220
|
-
var _a3;
|
|
221
|
-
curRequestController = new AbortController();
|
|
222
|
-
try {
|
|
223
|
-
const response = await fetch2(input, Object.assign(Object.assign({}, rest), { headers, signal: curRequestController.signal }));
|
|
224
|
-
await onopen(response);
|
|
225
|
-
await getBytes(response.body, getLines(getMessages((id) => {
|
|
226
|
-
if (id) {
|
|
227
|
-
headers[LastEventId] = id;
|
|
228
|
-
} else {
|
|
229
|
-
delete headers[LastEventId];
|
|
230
|
-
}
|
|
231
|
-
}, (retry) => {
|
|
232
|
-
retryInterval = retry;
|
|
233
|
-
}, onmessage)));
|
|
234
|
-
onclose === null || onclose === void 0 ? void 0 : onclose();
|
|
235
|
-
dispose();
|
|
236
|
-
resolve();
|
|
237
|
-
} catch (err) {
|
|
238
|
-
if (!curRequestController.signal.aborted) {
|
|
239
|
-
try {
|
|
240
|
-
const interval = (_a3 = onerror === null || onerror === void 0 ? void 0 : onerror(err)) !== null && _a3 !== void 0 ? _a3 : retryInterval;
|
|
241
|
-
window.clearTimeout(retryTimer);
|
|
242
|
-
retryTimer = window.setTimeout(create, interval);
|
|
243
|
-
} catch (innerErr) {
|
|
244
|
-
dispose();
|
|
245
|
-
reject(innerErr);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
create();
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
function defaultOnOpen(response) {
|
|
254
|
-
const contentType = response.headers.get("content-type");
|
|
255
|
-
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith(EventStreamContentType))) {
|
|
256
|
-
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
const FRAME_SAFE_ERROR_KEY = "__chatkit_error__";
|
|
260
|
-
class HttpError extends Error {
|
|
261
|
-
constructor(message, res, metadata) {
|
|
262
|
-
super(message);
|
|
263
|
-
__publicField(this, "status");
|
|
264
|
-
__publicField(this, "statusText");
|
|
265
|
-
__publicField(this, "metadata");
|
|
266
|
-
this.name = "HttpError";
|
|
267
|
-
this.statusText = res.statusText;
|
|
268
|
-
this.status = res.status;
|
|
269
|
-
this.metadata = metadata;
|
|
270
|
-
}
|
|
271
|
-
static fromPossibleFrameSafeError(error) {
|
|
272
|
-
if (error instanceof HttpError) {
|
|
273
|
-
return error;
|
|
274
|
-
}
|
|
275
|
-
if (error && typeof error === "object" && FRAME_SAFE_ERROR_KEY in error && error[FRAME_SAFE_ERROR_KEY] === "HttpError") {
|
|
276
|
-
const safeError = error;
|
|
277
|
-
const parsedError = new HttpError(
|
|
278
|
-
safeError.message,
|
|
279
|
-
{
|
|
280
|
-
status: safeError.status,
|
|
281
|
-
statusText: safeError.statusText
|
|
282
|
-
},
|
|
283
|
-
safeError.metadata
|
|
284
|
-
);
|
|
285
|
-
parsedError.stack = safeError.stack;
|
|
286
|
-
return parsedError;
|
|
287
|
-
}
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
_a = FRAME_SAFE_ERROR_KEY;
|
|
292
|
-
const _FrameSafeHttpError = class _FrameSafeHttpError2 {
|
|
293
|
-
constructor(message, res, metadata) {
|
|
294
|
-
__publicField(this, _a, "HttpError");
|
|
295
|
-
__publicField(this, "message");
|
|
296
|
-
__publicField(this, "stack");
|
|
297
|
-
__publicField(this, "status");
|
|
298
|
-
__publicField(this, "statusText");
|
|
299
|
-
__publicField(this, "metadata");
|
|
300
|
-
this.message = message;
|
|
301
|
-
this.stack = new Error(message).stack;
|
|
302
|
-
this.status = res.status;
|
|
303
|
-
this.statusText = res.statusText;
|
|
304
|
-
this.metadata = metadata;
|
|
305
|
-
}
|
|
306
|
-
static fromHttpError(error) {
|
|
307
|
-
return new _FrameSafeHttpError2(
|
|
308
|
-
error.message,
|
|
309
|
-
{
|
|
310
|
-
status: error.status,
|
|
311
|
-
statusText: error.statusText
|
|
312
|
-
},
|
|
313
|
-
error.metadata
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
let FrameSafeHttpError = _FrameSafeHttpError;
|
|
318
|
-
const BASE_RETRY_DELAY_MS = 1e3;
|
|
319
|
-
const MAX_RETRY_DELAY_MS = 1e4;
|
|
320
|
-
const MAX_RETRY_ATTEMPTS = 5;
|
|
321
|
-
const nextDelay = (attempt, maxRetryDelay = MAX_RETRY_DELAY_MS, baseDelayMs = BASE_RETRY_DELAY_MS) => {
|
|
322
|
-
const max = Math.min(maxRetryDelay, baseDelayMs * 2 ** attempt);
|
|
323
|
-
return Math.floor(max * (0.5 + Math.random() * 0.5));
|
|
324
|
-
};
|
|
325
|
-
class RetryableError extends Error {
|
|
326
|
-
constructor(cause) {
|
|
327
|
-
super();
|
|
328
|
-
this.cause = cause;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const fetchEventSourceWithRetry = async (url, params) => {
|
|
332
|
-
let retryAttempt = 0;
|
|
333
|
-
const { onopen, ...restParams } = params;
|
|
334
|
-
await fetchEventSource(url, {
|
|
335
|
-
...restParams,
|
|
336
|
-
onopen: async (res) => {
|
|
337
|
-
var _a22;
|
|
338
|
-
onopen == null ? void 0 : onopen(res);
|
|
339
|
-
if (res.ok && ((_a22 = res.headers.get("content-type")) == null ? void 0 : _a22.startsWith("text/event-stream"))) {
|
|
340
|
-
retryAttempt = 0;
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
const httpError = new FrameSafeHttpError(`Streaming failed: ${res.statusText}`, res);
|
|
344
|
-
if (res.status >= 400 && res.status < 500) {
|
|
345
|
-
throw httpError;
|
|
346
|
-
} else {
|
|
347
|
-
throw new RetryableError(httpError);
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
onerror: (error) => {
|
|
351
|
-
if (error instanceof RetryableError) {
|
|
352
|
-
if (retryAttempt >= MAX_RETRY_ATTEMPTS) {
|
|
353
|
-
throw error.cause;
|
|
354
|
-
}
|
|
355
|
-
retryAttempt += 1;
|
|
356
|
-
return nextDelay(retryAttempt);
|
|
357
|
-
}
|
|
358
|
-
throw error;
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
};
|
|
362
|
-
let IntegrationError$1 = class IntegrationError extends Error {
|
|
363
|
-
constructor(message) {
|
|
364
|
-
super(message);
|
|
365
|
-
__publicField(this, "_name");
|
|
366
|
-
this.name = "IntegrationError";
|
|
367
|
-
this._name = this.name;
|
|
368
|
-
}
|
|
369
|
-
static fromPossibleFrameSafeError(error) {
|
|
370
|
-
if (error && typeof error === "object" && FRAME_SAFE_ERROR_KEY in error && error[FRAME_SAFE_ERROR_KEY] === "IntegrationError") {
|
|
371
|
-
const safeError = error;
|
|
372
|
-
const parsedError = new IntegrationError(safeError.message);
|
|
373
|
-
parsedError.stack = safeError.stack;
|
|
374
|
-
return parsedError;
|
|
375
|
-
}
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
_b = FRAME_SAFE_ERROR_KEY;
|
|
380
|
-
class FrameSafeIntegrationError {
|
|
381
|
-
constructor(message) {
|
|
382
|
-
__publicField(this, _b, "IntegrationError");
|
|
383
|
-
__publicField(this, "message");
|
|
384
|
-
__publicField(this, "stack");
|
|
385
|
-
this.message = message;
|
|
386
|
-
this.stack = new Error(message).stack;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
class BaseMessenger {
|
|
390
|
-
constructor({
|
|
391
|
-
handlers,
|
|
392
|
-
target,
|
|
393
|
-
targetOrigin,
|
|
394
|
-
fetch: fetch2 = window.fetch
|
|
395
|
-
}) {
|
|
396
|
-
__publicField(this, "targetOrigin");
|
|
397
|
-
__publicField(this, "target");
|
|
398
|
-
__publicField(this, "commandHandlers");
|
|
399
|
-
__publicField(this, "_fetch");
|
|
400
|
-
__publicField(this, "emitter", new EventEmitter());
|
|
401
|
-
__publicField(this, "handlers", /* @__PURE__ */ new Map());
|
|
402
|
-
__publicField(this, "fetchEventSourceHandlers", /* @__PURE__ */ new Map());
|
|
403
|
-
__publicField(this, "abortControllers", /* @__PURE__ */ new Map());
|
|
404
|
-
__publicField(this, "commands", new Proxy(
|
|
405
|
-
{},
|
|
406
|
-
{
|
|
407
|
-
get: (_, command) => {
|
|
408
|
-
return (data, transfer) => {
|
|
409
|
-
return new Promise((resolve, reject) => {
|
|
410
|
-
const nonce = crypto.randomUUID();
|
|
411
|
-
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
412
|
-
this.sendMessage(
|
|
413
|
-
{
|
|
414
|
-
type: "command",
|
|
415
|
-
nonce,
|
|
416
|
-
command: `on${command.charAt(0).toUpperCase()}${command.slice(1)}`,
|
|
417
|
-
data
|
|
418
|
-
},
|
|
419
|
-
transfer
|
|
420
|
-
);
|
|
421
|
-
});
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
));
|
|
426
|
-
__publicField(this, "handleMessage", async (event) => {
|
|
427
|
-
var _a22, _b2, _c, _d;
|
|
428
|
-
if (!event.data || event.data.__xpaiChatKit !== true || event.origin !== this.targetOrigin || event.source !== this.target()) {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
const data = event.data;
|
|
432
|
-
switch (data.type) {
|
|
433
|
-
case "event": {
|
|
434
|
-
this.emitter.emit(data.event, data.data);
|
|
435
|
-
break;
|
|
436
|
-
}
|
|
437
|
-
case "fetch": {
|
|
438
|
-
try {
|
|
439
|
-
if (data.formData) {
|
|
440
|
-
const formData = new FormData();
|
|
441
|
-
for (const [key, value] of Object.entries(data.formData)) {
|
|
442
|
-
formData.append(key, value);
|
|
443
|
-
}
|
|
444
|
-
data.params.body = formData;
|
|
445
|
-
}
|
|
446
|
-
const controller = new AbortController();
|
|
447
|
-
this.abortControllers.set(data.nonce, controller);
|
|
448
|
-
data.params.signal = controller.signal;
|
|
449
|
-
const res = await this._fetch(data.url, data.params);
|
|
450
|
-
if (!res.ok) {
|
|
451
|
-
const message = await res.json().then((json2) => json2.message || res.statusText).catch(() => res.statusText);
|
|
452
|
-
throw new FrameSafeHttpError(message, res);
|
|
453
|
-
}
|
|
454
|
-
const json = await res.json().catch(() => ({}));
|
|
455
|
-
this.sendMessage({
|
|
456
|
-
type: "response",
|
|
457
|
-
response: json,
|
|
458
|
-
nonce: data.nonce
|
|
459
|
-
});
|
|
460
|
-
} catch (error) {
|
|
461
|
-
this.sendMessage({
|
|
462
|
-
type: "response",
|
|
463
|
-
error,
|
|
464
|
-
nonce: data.nonce
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
break;
|
|
468
|
-
}
|
|
469
|
-
case "fetchEventSource": {
|
|
470
|
-
try {
|
|
471
|
-
const controller = new AbortController();
|
|
472
|
-
this.abortControllers.set(data.nonce, controller);
|
|
473
|
-
await fetchEventSourceWithRetry(data.url, {
|
|
474
|
-
...data.params,
|
|
475
|
-
signal: controller.signal,
|
|
476
|
-
fetch: this._fetch,
|
|
477
|
-
onmessage: (message) => {
|
|
478
|
-
this.sendMessage({
|
|
479
|
-
type: "fetchEventSourceMessage",
|
|
480
|
-
message,
|
|
481
|
-
nonce: data.nonce
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
this.sendMessage({
|
|
486
|
-
type: "response",
|
|
487
|
-
response: void 0,
|
|
488
|
-
nonce: data.nonce
|
|
489
|
-
});
|
|
490
|
-
} catch (error) {
|
|
491
|
-
this.sendMessage({
|
|
492
|
-
type: "response",
|
|
493
|
-
error,
|
|
494
|
-
nonce: data.nonce
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
break;
|
|
498
|
-
}
|
|
499
|
-
case "command": {
|
|
500
|
-
if (!this.canReceiveCommand(data.command)) {
|
|
501
|
-
this.sendMessage({
|
|
502
|
-
type: "response",
|
|
503
|
-
error: new FrameSafeIntegrationError(`Command ${data.command} not supported`),
|
|
504
|
-
nonce: data.nonce
|
|
505
|
-
});
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
try {
|
|
509
|
-
const response = await ((_b2 = (_a22 = this.commandHandlers)[data.command]) == null ? void 0 : _b2.call(_a22, data.data));
|
|
510
|
-
this.sendMessage({
|
|
511
|
-
type: "response",
|
|
512
|
-
response,
|
|
513
|
-
nonce: data.nonce
|
|
514
|
-
});
|
|
515
|
-
} catch (error) {
|
|
516
|
-
this.sendMessage({
|
|
517
|
-
type: "response",
|
|
518
|
-
error,
|
|
519
|
-
nonce: data.nonce
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
break;
|
|
523
|
-
}
|
|
524
|
-
case "response": {
|
|
525
|
-
const handler = this.handlers.get(data.nonce);
|
|
526
|
-
if (!handler) {
|
|
527
|
-
console.error("No handler found for nonce", data.nonce);
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
if (data.error) {
|
|
531
|
-
const integrationError = IntegrationError$1.fromPossibleFrameSafeError(data.error);
|
|
532
|
-
const httpError = HttpError.fromPossibleFrameSafeError(data.error);
|
|
533
|
-
if (integrationError) {
|
|
534
|
-
integrationError.stack = handler.stack;
|
|
535
|
-
handler.reject(integrationError);
|
|
536
|
-
} else if (httpError) {
|
|
537
|
-
handler.reject(httpError);
|
|
538
|
-
} else {
|
|
539
|
-
handler.reject(data.error);
|
|
540
|
-
}
|
|
541
|
-
} else {
|
|
542
|
-
handler.resolve(data.response);
|
|
543
|
-
}
|
|
544
|
-
this.handlers.delete(data.nonce);
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
case "fetchEventSourceMessage": {
|
|
548
|
-
const handler = this.fetchEventSourceHandlers.get(data.nonce);
|
|
549
|
-
if (!handler) {
|
|
550
|
-
console.error("No handler found for nonce", data.nonce);
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
(_d = (_c = this.fetchEventSourceHandlers.get(data.nonce)) == null ? void 0 : _c.onmessage) == null ? void 0 : _d.call(_c, data.message);
|
|
554
|
-
break;
|
|
555
|
-
}
|
|
556
|
-
case "abortSignal": {
|
|
557
|
-
const controller = this.abortControllers.get(data.nonce);
|
|
558
|
-
if (controller) {
|
|
559
|
-
controller.abort(data.reason);
|
|
560
|
-
this.abortControllers.delete(data.nonce);
|
|
561
|
-
}
|
|
562
|
-
break;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
this.commandHandlers = handlers;
|
|
567
|
-
this.target = target;
|
|
568
|
-
this.targetOrigin = targetOrigin;
|
|
569
|
-
this._fetch = (...args) => fetch2(...args);
|
|
570
|
-
}
|
|
571
|
-
setTargetOrigin(targetOrigin) {
|
|
572
|
-
this.targetOrigin = targetOrigin;
|
|
573
|
-
}
|
|
574
|
-
sendMessage(data, transfer) {
|
|
575
|
-
var _a22;
|
|
576
|
-
const message = {
|
|
577
|
-
__xpaiChatKit: true,
|
|
578
|
-
...data
|
|
579
|
-
};
|
|
580
|
-
(_a22 = this.target()) == null ? void 0 : _a22.postMessage(message, this.targetOrigin, transfer);
|
|
581
|
-
}
|
|
582
|
-
connect() {
|
|
583
|
-
window.addEventListener("message", this.handleMessage);
|
|
584
|
-
}
|
|
585
|
-
disconnect() {
|
|
586
|
-
window.removeEventListener("message", this.handleMessage);
|
|
587
|
-
}
|
|
588
|
-
fetch(url, params) {
|
|
589
|
-
return new Promise((resolve, reject) => {
|
|
590
|
-
const nonce = crypto.randomUUID();
|
|
591
|
-
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
592
|
-
let formData;
|
|
593
|
-
if (params.body instanceof FormData) {
|
|
594
|
-
formData = {};
|
|
595
|
-
for (const [key, value] of params.body.entries()) {
|
|
596
|
-
formData[key] = value;
|
|
597
|
-
}
|
|
598
|
-
params.body = void 0;
|
|
599
|
-
}
|
|
600
|
-
if (params.signal) {
|
|
601
|
-
params.signal.addEventListener("abort", () => {
|
|
602
|
-
var _a22;
|
|
603
|
-
this.sendMessage({
|
|
604
|
-
type: "abortSignal",
|
|
605
|
-
nonce,
|
|
606
|
-
reason: (_a22 = params.signal) == null ? void 0 : _a22.reason
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
params.signal = void 0;
|
|
610
|
-
}
|
|
611
|
-
this.sendMessage({ type: "fetch", nonce, params, formData, url });
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
// Supporting onopen would require a good way for us to serialize the Response object
|
|
615
|
-
// across the iframe boundary, which is not trivial and also not really necessary.
|
|
616
|
-
fetchEventSource(url, params) {
|
|
617
|
-
return new Promise((resolve, reject) => {
|
|
618
|
-
const { onmessage, signal, ...rest } = params;
|
|
619
|
-
const nonce = crypto.randomUUID();
|
|
620
|
-
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
621
|
-
this.fetchEventSourceHandlers.set(nonce, {
|
|
622
|
-
onmessage
|
|
623
|
-
});
|
|
624
|
-
if (signal) {
|
|
625
|
-
signal.addEventListener("abort", () => {
|
|
626
|
-
this.sendMessage({
|
|
627
|
-
type: "abortSignal",
|
|
628
|
-
nonce,
|
|
629
|
-
reason: signal.reason
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
this.sendMessage({ type: "fetchEventSource", nonce, params: rest, url });
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
emit(...[event, data, transfer]) {
|
|
637
|
-
this.sendMessage(
|
|
638
|
-
{
|
|
639
|
-
type: "event",
|
|
640
|
-
event,
|
|
641
|
-
data
|
|
642
|
-
},
|
|
643
|
-
transfer
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
on(...[event, callback]) {
|
|
647
|
-
this.emitter.on(event, callback);
|
|
648
|
-
}
|
|
649
|
-
destroy() {
|
|
650
|
-
window.removeEventListener("message", this.handleMessage);
|
|
651
|
-
this.emitter.allOff();
|
|
652
|
-
this.handlers.clear();
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
const toUrlBase64 = (bin) => btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
656
|
-
const encodeBase64 = (value) => {
|
|
657
|
-
if (value === void 0) {
|
|
658
|
-
throw new TypeError(
|
|
659
|
-
"encodeBase64: `undefined` cannot be encoded to valid JSON. Pass null instead."
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
const json = JSON.stringify(value);
|
|
663
|
-
const bytes = new TextEncoder().encode(json);
|
|
664
|
-
let bin = "";
|
|
665
|
-
for (const b of bytes) bin += String.fromCharCode(b);
|
|
666
|
-
return toUrlBase64(bin);
|
|
667
|
-
};
|
|
668
|
-
class IntegrationError2 extends Error {
|
|
669
|
-
}
|
|
670
|
-
function fromPossibleFrameSafeError(err) {
|
|
671
|
-
return err.message;
|
|
672
|
-
}
|
|
673
|
-
const BASE_CAPABILITY_ALLOWLIST = [
|
|
674
|
-
// commands
|
|
675
|
-
"command.setOptions",
|
|
676
|
-
"command.sendUserMessage",
|
|
677
|
-
"command.setComposerValue",
|
|
678
|
-
"command.setThreadId",
|
|
679
|
-
"command.focusComposer",
|
|
680
|
-
"command.fetchUpdates",
|
|
681
|
-
"command.sendCustomAction",
|
|
682
|
-
"command.showHistory",
|
|
683
|
-
"command.hideHistory",
|
|
684
|
-
// events
|
|
685
|
-
"event.ready",
|
|
686
|
-
"event.error",
|
|
687
|
-
"event.log",
|
|
688
|
-
"event.response.start",
|
|
689
|
-
"event.response.end",
|
|
690
|
-
"event.response.stop",
|
|
691
|
-
"event.thread.change",
|
|
692
|
-
"event.tool.change",
|
|
693
|
-
"event.thread.load.start",
|
|
694
|
-
"event.thread.load.end",
|
|
695
|
-
"event.deeplink",
|
|
696
|
-
"event.effect",
|
|
697
|
-
// errors
|
|
698
|
-
"error.StreamError",
|
|
699
|
-
"error.StreamEventParsingError",
|
|
700
|
-
"error.WidgetItemError",
|
|
701
|
-
"error.InitialThreadLoadError",
|
|
702
|
-
"error.FileAttachmentError",
|
|
703
|
-
"error.HistoryViewError",
|
|
704
|
-
"error.FatalAppError",
|
|
705
|
-
"error.IntegrationError",
|
|
706
|
-
"error.EntitySearchError",
|
|
707
|
-
"error.DomainVerificationRequestError",
|
|
708
|
-
// backend
|
|
709
|
-
"backend.threads.get_by_id",
|
|
710
|
-
"backend.threads.list",
|
|
711
|
-
"backend.threads.update",
|
|
712
|
-
"backend.threads.delete",
|
|
713
|
-
"backend.threads.create",
|
|
714
|
-
"backend.threads.add_user_message",
|
|
715
|
-
"backend.threads.add_client_tool_output",
|
|
716
|
-
"backend.threads.retry_after_item",
|
|
717
|
-
"backend.threads.custom_action",
|
|
718
|
-
"backend.attachments.create",
|
|
719
|
-
"backend.attachments.get_preview",
|
|
720
|
-
"backend.attachments.delete",
|
|
721
|
-
"backend.items.list",
|
|
722
|
-
"backend.items.feedback",
|
|
723
|
-
// thread item types
|
|
724
|
-
"thread.item.generated_image",
|
|
725
|
-
"thread.item.user_message",
|
|
726
|
-
"thread.item.assistant_message",
|
|
727
|
-
"thread.item.client_tool_call",
|
|
728
|
-
"thread.item.widget",
|
|
729
|
-
"thread.item.task",
|
|
730
|
-
"thread.item.workflow",
|
|
731
|
-
"thread.item.end_of_turn",
|
|
732
|
-
"thread.item.image_generation",
|
|
733
|
-
// widgets
|
|
734
|
-
"widget.Basic",
|
|
735
|
-
"widget.Card",
|
|
736
|
-
"widget.ListView",
|
|
737
|
-
"widget.ListViewItem",
|
|
738
|
-
"widget.Badge",
|
|
739
|
-
"widget.Box",
|
|
740
|
-
"widget.Row",
|
|
741
|
-
"widget.Col",
|
|
742
|
-
"widget.Button",
|
|
743
|
-
"widget.Caption",
|
|
744
|
-
"widget.Chart",
|
|
745
|
-
"widget.Checkbox",
|
|
746
|
-
"widget.DatePicker",
|
|
747
|
-
"widget.Divider",
|
|
748
|
-
"widget.Form",
|
|
749
|
-
"widget.Icon",
|
|
750
|
-
"widget.Image",
|
|
751
|
-
"widget.Input",
|
|
752
|
-
"widget.Label",
|
|
753
|
-
"widget.Markdown",
|
|
754
|
-
"widget.RadioGroup",
|
|
755
|
-
"widget.Select",
|
|
756
|
-
"widget.Spacer",
|
|
757
|
-
"widget.Text",
|
|
758
|
-
"widget.Textarea",
|
|
759
|
-
"widget.Title",
|
|
760
|
-
"widget.Transition"
|
|
761
|
-
];
|
|
762
|
-
const BASE_CAPABILITY_DENYLIST = [
|
|
763
|
-
// --- commands
|
|
764
|
-
"command.shareThread",
|
|
765
|
-
"command.setTrainingOptOut",
|
|
766
|
-
// --- events
|
|
767
|
-
"event.thread.restore",
|
|
768
|
-
"event.message.share",
|
|
769
|
-
"event.image.download",
|
|
770
|
-
"event.history.open",
|
|
771
|
-
"event.history.close",
|
|
772
|
-
"event.log.chatgpt",
|
|
773
|
-
// --- errors
|
|
774
|
-
// These errors considered internal and are not exposed to the user by default.
|
|
775
|
-
"error.HttpError",
|
|
776
|
-
"error.NetworkError",
|
|
777
|
-
"error.UnhandledError",
|
|
778
|
-
"error.UnhandledPromiseRejectionError",
|
|
779
|
-
"error.StreamEventHandlingError",
|
|
780
|
-
"error.StreamStopError",
|
|
781
|
-
"error.ThreadRenderingError",
|
|
782
|
-
"error.IntlError",
|
|
783
|
-
"error.AppError",
|
|
784
|
-
// --- backend
|
|
785
|
-
"backend.threads.stop",
|
|
786
|
-
"backend.threads.share",
|
|
787
|
-
"backend.threads.create_from_shared",
|
|
788
|
-
"backend.threads.init",
|
|
789
|
-
"backend.attachments.process",
|
|
790
|
-
// widgets
|
|
791
|
-
"widget.CardCarousel",
|
|
792
|
-
"widget.Favicon",
|
|
793
|
-
"widget.CardLinkItem",
|
|
794
|
-
"widget.Map"
|
|
795
|
-
];
|
|
796
|
-
const PROFILE_TO_RULES = {
|
|
797
|
-
"chatkit": {
|
|
798
|
-
allow: [...BASE_CAPABILITY_ALLOWLIST, "thread.item.image_generation"],
|
|
799
|
-
deny: BASE_CAPABILITY_DENYLIST
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
const getCapabilities = (profile) => {
|
|
803
|
-
const rules = PROFILE_TO_RULES[profile];
|
|
804
|
-
const effective = new Set(rules.allow);
|
|
805
|
-
for (const capability of rules.deny ?? []) {
|
|
806
|
-
effective.delete(capability);
|
|
807
|
-
}
|
|
808
|
-
const commands = /* @__PURE__ */ new Set();
|
|
809
|
-
const events = /* @__PURE__ */ new Set();
|
|
810
|
-
const backend = /* @__PURE__ */ new Set();
|
|
811
|
-
const threadItems = /* @__PURE__ */ new Set();
|
|
812
|
-
const errors = /* @__PURE__ */ new Set();
|
|
813
|
-
const widgets = /* @__PURE__ */ new Set();
|
|
814
|
-
for (const capability of effective) {
|
|
815
|
-
if (capability.startsWith("command.")) {
|
|
816
|
-
commands.add(capability.slice("command.".length));
|
|
817
|
-
continue;
|
|
818
|
-
}
|
|
819
|
-
if (capability.startsWith("event.")) {
|
|
820
|
-
events.add(capability.slice("event.".length));
|
|
821
|
-
continue;
|
|
822
|
-
}
|
|
823
|
-
if (capability.startsWith("backend.")) {
|
|
824
|
-
backend.add(capability.slice("backend.".length));
|
|
825
|
-
continue;
|
|
826
|
-
}
|
|
827
|
-
if (capability.startsWith("thread.item.")) {
|
|
828
|
-
threadItems.add(capability.slice("thread.item.".length));
|
|
829
|
-
}
|
|
830
|
-
if (capability.startsWith("error.")) {
|
|
831
|
-
errors.add(capability.slice("error.".length));
|
|
832
|
-
continue;
|
|
833
|
-
}
|
|
834
|
-
if (capability.startsWith("widget.")) {
|
|
835
|
-
widgets.add(capability.slice("widget.".length));
|
|
836
|
-
continue;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
return { commands, events, backend, threadItems, errors, widgets };
|
|
840
|
-
};
|
|
841
|
-
class ChatFrameMessenger extends BaseMessenger {
|
|
842
|
-
// Messenger running in outer can always handle commands coming from inner
|
|
843
|
-
canReceiveCommand(_) {
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
const removeMethods = (obj, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
848
|
-
if (typeof obj === "function") return "[ChatKitMethod]";
|
|
849
|
-
if (typeof obj !== "object" || obj === null) return obj;
|
|
850
|
-
if (seen.has(obj)) return obj;
|
|
851
|
-
seen.add(obj);
|
|
852
|
-
if (Array.isArray(obj)) {
|
|
853
|
-
return obj.map((c) => removeMethods(c, seen));
|
|
854
|
-
}
|
|
855
|
-
const result = {};
|
|
856
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
857
|
-
if (typeof value !== "function") {
|
|
858
|
-
result[key] = removeMethods(value, seen);
|
|
859
|
-
} else {
|
|
860
|
-
result[key] = "[ChatKitMethod]";
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
return result;
|
|
864
|
-
};
|
|
865
|
-
function getInnerOptions(options) {
|
|
866
|
-
return removeMethods(options);
|
|
867
|
-
}
|
|
868
|
-
function requireCommandCapability(value, context) {
|
|
869
|
-
const command = String(context.name);
|
|
870
|
-
return function(...args) {
|
|
871
|
-
if (!this.capabilities.commands.has(command)) {
|
|
872
|
-
throw new IntegrationError2(
|
|
873
|
-
`ChatKit command "${String(command)}" is not available for the "${this.profile}" profile.`
|
|
874
|
-
);
|
|
875
|
-
}
|
|
876
|
-
return value.apply(this, args);
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requireCommandCapability], _fetchUpdates_dec = [requireCommandCapability], _sendUserMessage_dec = [requireCommandCapability], _setComposerValue_dec = [requireCommandCapability], _setThreadId_dec = [requireCommandCapability], _shareThread_dec = [requireCommandCapability], _sendCustomAction_dec = [requireCommandCapability], _showHistory_dec = [requireCommandCapability], _hideHistory_dec = [requireCommandCapability], _setTrainingOptOut_dec = [requireCommandCapability], _a2) {
|
|
880
|
-
constructor({ profile }) {
|
|
881
|
-
super();
|
|
882
|
-
__runInitializers(_init, 5, this);
|
|
883
|
-
__privateAdd(this, _ChatKitElementBase_instances);
|
|
884
|
-
__privateAdd(this, _opts);
|
|
885
|
-
__privateAdd(this, _frameUrl);
|
|
886
|
-
__privateAdd(this, _frame);
|
|
887
|
-
__privateAdd(this, _wrapper);
|
|
888
|
-
__privateAdd(this, _shadow, this.attachShadow({ mode: "open" }));
|
|
889
|
-
__privateAdd(this, _resolveLoaded);
|
|
890
|
-
__privateAdd(this, _loaded, new Promise((resolve) => {
|
|
891
|
-
__privateSet(this, _resolveLoaded, resolve);
|
|
892
|
-
}));
|
|
893
|
-
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
894
|
-
fetch: (...args) => {
|
|
895
|
-
var _a3;
|
|
896
|
-
const customFetch = ((_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
897
|
-
return customFetch ? customFetch(...args) : fetch(...args);
|
|
898
|
-
},
|
|
899
|
-
target: () => {
|
|
900
|
-
var _a3;
|
|
901
|
-
return ((_a3 = __privateGet(this, _frame)) == null ? void 0 : _a3.contentWindow) ?? null;
|
|
902
|
-
},
|
|
903
|
-
targetOrigin: window.location.origin,
|
|
904
|
-
handlers: {
|
|
905
|
-
onFileInputClick: ({ inputAttributes }) => {
|
|
906
|
-
return new Promise((resolve) => {
|
|
907
|
-
const input = document.createElement("input");
|
|
908
|
-
for (const [key, value] of Object.entries(inputAttributes)) {
|
|
909
|
-
input.setAttribute(key, String(value));
|
|
910
|
-
}
|
|
911
|
-
const respond = () => {
|
|
912
|
-
resolve(Array.from(input.files || []));
|
|
913
|
-
if (__privateGet(this, _shadow).contains(input)) {
|
|
914
|
-
__privateGet(this, _shadow).removeChild(input);
|
|
915
|
-
}
|
|
916
|
-
};
|
|
917
|
-
input.addEventListener("cancel", respond);
|
|
918
|
-
input.addEventListener("change", respond);
|
|
919
|
-
__privateGet(this, _shadow).appendChild(input);
|
|
920
|
-
input.click();
|
|
921
|
-
});
|
|
922
|
-
},
|
|
923
|
-
onClientToolCall: async ({
|
|
924
|
-
name,
|
|
925
|
-
params,
|
|
926
|
-
id,
|
|
927
|
-
tool_call_id
|
|
928
|
-
}) => {
|
|
929
|
-
var _a3;
|
|
930
|
-
const onClientTool = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.onClientTool;
|
|
931
|
-
if (!onClientTool) {
|
|
932
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
933
|
-
`No handler for client tool calls. You'll need to add onClientTool to your ChatKit options.`
|
|
934
|
-
));
|
|
935
|
-
}
|
|
936
|
-
return onClientTool({ name, params, id, tool_call_id });
|
|
937
|
-
},
|
|
938
|
-
onWidgetAction: async ({ action, widgetItem }) => {
|
|
939
|
-
var _a3, _b2;
|
|
940
|
-
const onAction = (_b2 = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.widgets) == null ? void 0 : _b2.onAction;
|
|
941
|
-
if (!onAction) {
|
|
942
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
943
|
-
`No handler for widget actions. You'll need to add widgets.onAction to your ChatKit options.`
|
|
944
|
-
));
|
|
945
|
-
}
|
|
946
|
-
return onAction(action, widgetItem);
|
|
947
|
-
},
|
|
948
|
-
onEntitySearch: async ({ query }) => {
|
|
949
|
-
var _a3, _b2, _c;
|
|
950
|
-
return ((_c = (_b2 = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.entities) == null ? void 0 : _b2.onTagSearch) == null ? void 0 : _c.call(_b2, query)) ?? [];
|
|
951
|
-
},
|
|
952
|
-
onEntityClick: async ({ entity }) => {
|
|
953
|
-
var _a3, _b2, _c;
|
|
954
|
-
return (_c = (_b2 = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.entities) == null ? void 0 : _b2.onClick) == null ? void 0 : _c.call(_b2, entity);
|
|
955
|
-
},
|
|
956
|
-
onEntityPreview: async ({ entity }) => {
|
|
957
|
-
var _a3, _b2, _c;
|
|
958
|
-
return ((_c = (_b2 = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.entities) == null ? void 0 : _b2.onRequestPreview) == null ? void 0 : _c.call(_b2, entity)) ?? { preview: null };
|
|
959
|
-
},
|
|
960
|
-
onGetClientSecret: async (currentClientSecret) => {
|
|
961
|
-
if (!__privateGet(this, _opts) || !("getClientSecret" in __privateGet(this, _opts).api) || !__privateGet(this, _opts).api.getClientSecret) {
|
|
962
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
963
|
-
"Could not refresh the session because ChatKitOptions.api.getClientSecret is not configured."
|
|
964
|
-
));
|
|
965
|
-
}
|
|
966
|
-
return __privateGet(this, _opts).api.getClientSecret(currentClientSecret ?? null);
|
|
967
|
-
},
|
|
968
|
-
onAddMetadataToRequest: ({
|
|
969
|
-
op,
|
|
970
|
-
params
|
|
971
|
-
}) => {
|
|
972
|
-
throw new IntegrationError2("ChatKit: onAddMetadataToRequest is unimplemented.");
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
}));
|
|
976
|
-
__privateAdd(this, _handleFrameLoad, () => {
|
|
977
|
-
var _a3;
|
|
978
|
-
this.dataset.loaded = "true";
|
|
979
|
-
this.dispatchEvent(new CustomEvent("chatkit.ready", { bubbles: true, composed: true }));
|
|
980
|
-
(_a3 = __privateGet(this, _resolveLoaded)) == null ? void 0 : _a3.call(this);
|
|
981
|
-
});
|
|
982
|
-
__privateAdd(this, _initialized, false);
|
|
983
|
-
this.profile = profile;
|
|
984
|
-
this.capabilities = getCapabilities(profile);
|
|
985
|
-
}
|
|
986
|
-
setProfile(profile) {
|
|
987
|
-
this.profile = profile;
|
|
988
|
-
this.capabilities = getCapabilities(profile);
|
|
989
|
-
}
|
|
990
|
-
connectedCallback() {
|
|
991
|
-
const style = document.createElement("style");
|
|
992
|
-
style.textContent = `
|
|
993
|
-
:host {
|
|
994
|
-
display: block;
|
|
995
|
-
position: relative;
|
|
996
|
-
height: 100%;
|
|
997
|
-
width: 100%;
|
|
998
|
-
}
|
|
999
|
-
.ck-iframe {
|
|
1000
|
-
border: none;
|
|
1001
|
-
position: absolute;
|
|
1002
|
-
inset: 0;
|
|
1003
|
-
width: 100%;
|
|
1004
|
-
height: 100%;
|
|
1005
|
-
overflow: hidden;
|
|
1006
|
-
color-scheme: light only;
|
|
1007
|
-
}
|
|
1008
|
-
.ck-wrapper {
|
|
1009
|
-
position: absolute;
|
|
1010
|
-
inset: 0;
|
|
1011
|
-
width: 100%;
|
|
1012
|
-
height: 100%;
|
|
1013
|
-
overflow: hidden;
|
|
1014
|
-
opacity: 0;
|
|
1015
|
-
}
|
|
1016
|
-
:host([data-color-scheme="dark"]) .ck-iframe {
|
|
1017
|
-
color-scheme: dark only;
|
|
1018
|
-
}
|
|
1019
|
-
:host([data-loaded="true"]) .ck-wrapper {
|
|
1020
|
-
opacity: 1;
|
|
1021
|
-
}
|
|
1022
|
-
`;
|
|
1023
|
-
const frame = document.createElement("iframe");
|
|
1024
|
-
frame.className = "ck-iframe";
|
|
1025
|
-
frame.name = "chatkit";
|
|
1026
|
-
frame.role = "presentation";
|
|
1027
|
-
frame.tabIndex = 0;
|
|
1028
|
-
frame.setAttribute("allowtransparency", "true");
|
|
1029
|
-
frame.setAttribute("frameborder", "0");
|
|
1030
|
-
frame.setAttribute("scrolling", "no");
|
|
1031
|
-
frame.setAttribute("allow", "clipboard-read; clipboard-write");
|
|
1032
|
-
__privateSet(this, _frame, frame);
|
|
1033
|
-
const wrapper = document.createElement("div");
|
|
1034
|
-
wrapper.className = "ck-wrapper";
|
|
1035
|
-
wrapper.appendChild(frame);
|
|
1036
|
-
__privateSet(this, _wrapper, wrapper);
|
|
1037
|
-
__privateGet(this, _shadow).append(style);
|
|
1038
|
-
__privateGet(this, _messenger).on("left_header_icon_click", () => {
|
|
1039
|
-
var _a3, _b2, _c;
|
|
1040
|
-
(_c = (_b2 = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.header) == null ? void 0 : _b2.leftAction) == null ? void 0 : _c.onClick();
|
|
1041
|
-
});
|
|
1042
|
-
__privateGet(this, _messenger).on("right_header_icon_click", () => {
|
|
1043
|
-
var _a3, _b2, _c;
|
|
1044
|
-
(_c = (_b2 = (_a3 = __privateGet(this, _opts)) == null ? void 0 : _a3.header) == null ? void 0 : _b2.rightAction) == null ? void 0 : _c.onClick();
|
|
1045
|
-
});
|
|
1046
|
-
__privateGet(this, _messenger).on("public_event", ([event, data]) => {
|
|
1047
|
-
if (!this.capabilities.events.has(event)) return;
|
|
1048
|
-
if (event === "error" && "error" in data) {
|
|
1049
|
-
const error = fromPossibleFrameSafeError(data.error);
|
|
1050
|
-
this.dispatchEvent(new CustomEvent("chatkit.error", { detail: { error } }));
|
|
1051
|
-
if (error instanceof IntegrationError2) {
|
|
1052
|
-
throw error;
|
|
1053
|
-
}
|
|
1054
|
-
return;
|
|
1055
|
-
}
|
|
1056
|
-
this.dispatchEvent(new CustomEvent(`chatkit.${event}`, { detail: data }));
|
|
1057
|
-
});
|
|
1058
|
-
__privateGet(this, _messenger).on("unmount", () => {
|
|
1059
|
-
if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
|
|
1060
|
-
__privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
|
|
1061
|
-
__privateSet(this, _wrapper, void 0);
|
|
1062
|
-
__privateSet(this, _frame, void 0);
|
|
1063
|
-
}
|
|
1064
|
-
});
|
|
1065
|
-
__privateGet(this, _messenger).on(
|
|
1066
|
-
"capabilities_profile_change",
|
|
1067
|
-
({ profile }) => {
|
|
1068
|
-
this.setProfile(profile);
|
|
1069
|
-
}
|
|
1070
|
-
);
|
|
1071
|
-
frame.addEventListener("load", __privateGet(this, _handleFrameLoad), { once: true });
|
|
1072
|
-
try {
|
|
1073
|
-
__privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
|
|
1074
|
-
} catch (error) {
|
|
1075
|
-
console.error(error);
|
|
1076
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new IntegrationError2("Failed to initialize ChatKit"));
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
disconnectedCallback() {
|
|
1080
|
-
var _a3;
|
|
1081
|
-
(_a3 = __privateGet(this, _frame)) == null ? void 0 : _a3.removeEventListener("load", __privateGet(this, _handleFrameLoad));
|
|
1082
|
-
__privateGet(this, _messenger).disconnect();
|
|
1083
|
-
}
|
|
1084
|
-
applySanitizedOptions(newOptions) {
|
|
1085
|
-
__privateSet(this, _opts, newOptions);
|
|
1086
|
-
if (__privateGet(this, _initialized)) {
|
|
1087
|
-
__privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
|
|
1088
|
-
__privateGet(this, _loaded).then(() => {
|
|
1089
|
-
__privateGet(this, _messenger).commands.setOptions(getInnerOptions(newOptions));
|
|
1090
|
-
});
|
|
1091
|
-
} else {
|
|
1092
|
-
__privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
setOptions(newOptions) {
|
|
1096
|
-
try {
|
|
1097
|
-
const sanitized = this.sanitizeOptions(newOptions);
|
|
1098
|
-
__privateMethod(this, _ChatKitElementBase_instances, consumeFrameUrl_fn).call(this, sanitized);
|
|
1099
|
-
this.applySanitizedOptions(sanitized);
|
|
1100
|
-
} catch (error) {
|
|
1101
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new IntegrationError2("Failed to parse options"));
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
async focusComposer() {
|
|
1105
|
-
var _a3, _b2;
|
|
1106
|
-
await __privateGet(this, _loaded);
|
|
1107
|
-
(_a3 = __privateGet(this, _frame)) == null ? void 0 : _a3.focus();
|
|
1108
|
-
await ((_b2 = __privateGet(this, _messenger)) == null ? void 0 : _b2.commands.focusComposer());
|
|
1109
|
-
}
|
|
1110
|
-
async fetchUpdates() {
|
|
1111
|
-
var _a3;
|
|
1112
|
-
await __privateGet(this, _loaded);
|
|
1113
|
-
await ((_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.fetchUpdates());
|
|
1114
|
-
}
|
|
1115
|
-
async sendUserMessage(params) {
|
|
1116
|
-
var _a3;
|
|
1117
|
-
await __privateGet(this, _loaded);
|
|
1118
|
-
await ((_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.sendUserMessage(params));
|
|
1119
|
-
}
|
|
1120
|
-
async setComposerValue(params) {
|
|
1121
|
-
var _a3;
|
|
1122
|
-
await __privateGet(this, _loaded);
|
|
1123
|
-
await ((_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.setComposerValue(params));
|
|
1124
|
-
}
|
|
1125
|
-
async setThreadId(threadId) {
|
|
1126
|
-
var _a3;
|
|
1127
|
-
await __privateGet(this, _loaded);
|
|
1128
|
-
await ((_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.setThreadId({ threadId }));
|
|
1129
|
-
}
|
|
1130
|
-
async shareThread() {
|
|
1131
|
-
var _a3;
|
|
1132
|
-
await __privateGet(this, _loaded);
|
|
1133
|
-
return (_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.shareThread();
|
|
1134
|
-
}
|
|
1135
|
-
async sendCustomAction(action, itemId) {
|
|
1136
|
-
var _a3;
|
|
1137
|
-
await __privateGet(this, _loaded);
|
|
1138
|
-
return (_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.sendCustomAction({ action, itemId });
|
|
1139
|
-
}
|
|
1140
|
-
async showHistory() {
|
|
1141
|
-
var _a3;
|
|
1142
|
-
await __privateGet(this, _loaded);
|
|
1143
|
-
return (_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.showHistory();
|
|
1144
|
-
}
|
|
1145
|
-
async hideHistory() {
|
|
1146
|
-
var _a3;
|
|
1147
|
-
await __privateGet(this, _loaded);
|
|
1148
|
-
return (_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.hideHistory();
|
|
1149
|
-
}
|
|
1150
|
-
async setTrainingOptOut(value) {
|
|
1151
|
-
var _a3;
|
|
1152
|
-
await __privateGet(this, _loaded);
|
|
1153
|
-
return (_a3 = __privateGet(this, _messenger)) == null ? void 0 : _a3.commands.setTrainingOptOut({ value });
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
_init = __decoratorStart(_a2);
|
|
1157
|
-
_opts = /* @__PURE__ */ new WeakMap();
|
|
1158
|
-
_frameUrl = /* @__PURE__ */ new WeakMap();
|
|
1159
|
-
_frame = /* @__PURE__ */ new WeakMap();
|
|
1160
|
-
_wrapper = /* @__PURE__ */ new WeakMap();
|
|
1161
|
-
_shadow = /* @__PURE__ */ new WeakMap();
|
|
1162
|
-
_resolveLoaded = /* @__PURE__ */ new WeakMap();
|
|
1163
|
-
_loaded = /* @__PURE__ */ new WeakMap();
|
|
1164
|
-
_messenger = /* @__PURE__ */ new WeakMap();
|
|
1165
|
-
_ChatKitElementBase_instances = /* @__PURE__ */ new WeakSet();
|
|
1166
|
-
emitAndThrow_fn = function(error) {
|
|
1167
|
-
this.dispatchEvent(new CustomEvent("chatkit.error", { detail: { error } }));
|
|
1168
|
-
throw error;
|
|
1169
|
-
};
|
|
1170
|
-
setOptionsDataAttributes_fn = function(options) {
|
|
1171
|
-
var _a3;
|
|
1172
|
-
this.dataset.colorScheme = typeof options.theme === "string" ? options.theme : ((_a3 = options.theme) == null ? void 0 : _a3.colorScheme) ?? "light";
|
|
1173
|
-
};
|
|
1174
|
-
getFrameUrl_fn = function() {
|
|
1175
|
-
if (!__privateGet(this, _frameUrl)) {
|
|
1176
|
-
throw new IntegrationError2(
|
|
1177
|
-
"ChatKit frameUrl is not configured. Provide it via setOptions({ frameUrl }) before mounting."
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
return __privateGet(this, _frameUrl);
|
|
1181
|
-
};
|
|
1182
|
-
setFrameUrl_fn = function(frameUrl) {
|
|
1183
|
-
if (__privateGet(this, _initialized) && __privateGet(this, _frameUrl) && __privateGet(this, _frameUrl) !== frameUrl) {
|
|
1184
|
-
throw new IntegrationError2(
|
|
1185
|
-
"ChatKit frameUrl cannot be changed after initialization. Create a new element to use a different URL."
|
|
1186
|
-
);
|
|
1187
|
-
}
|
|
1188
|
-
__privateSet(this, _frameUrl, frameUrl);
|
|
1189
|
-
};
|
|
1190
|
-
consumeFrameUrl_fn = function(options) {
|
|
1191
|
-
if (!("frameUrl" in options)) return;
|
|
1192
|
-
const frameUrl = options.frameUrl;
|
|
1193
|
-
delete options.frameUrl;
|
|
1194
|
-
if (frameUrl == null) return;
|
|
1195
|
-
if (typeof frameUrl !== "string" || frameUrl.trim() === "") {
|
|
1196
|
-
throw new IntegrationError2("ChatKit frameUrl must be a non-empty string.");
|
|
1197
|
-
}
|
|
1198
|
-
__privateMethod(this, _ChatKitElementBase_instances, setFrameUrl_fn).call(this, frameUrl);
|
|
1199
|
-
};
|
|
1200
|
-
_handleFrameLoad = /* @__PURE__ */ new WeakMap();
|
|
1201
|
-
_initialized = /* @__PURE__ */ new WeakMap();
|
|
1202
|
-
maybeInit_fn = function() {
|
|
1203
|
-
if (__privateGet(this, _initialized) || !__privateGet(this, _frame) || !__privateGet(this, _opts)) {
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
|
-
__privateSet(this, _initialized, true);
|
|
1207
|
-
__privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
|
|
1208
|
-
const frameURL = new URL(__privateMethod(this, _ChatKitElementBase_instances, getFrameUrl_fn).call(this), window.location.origin);
|
|
1209
|
-
__privateGet(this, _messenger).setTargetOrigin(frameURL.origin);
|
|
1210
|
-
frameURL.hash = encodeBase64({
|
|
1211
|
-
options: getInnerOptions(__privateGet(this, _opts)),
|
|
1212
|
-
referrer: window.location.origin,
|
|
1213
|
-
profile: this.profile
|
|
1214
|
-
});
|
|
1215
|
-
__privateGet(this, _messenger).connect();
|
|
1216
|
-
__privateGet(this, _frame).src = frameURL.toString();
|
|
1217
|
-
if (__privateGet(this, _wrapper)) {
|
|
1218
|
-
__privateGet(this, _shadow).append(__privateGet(this, _wrapper));
|
|
1219
|
-
}
|
|
1220
|
-
};
|
|
1221
|
-
__decorateElement(_init, 1, "focusComposer", _focusComposer_dec, ChatKitElementBase);
|
|
1222
|
-
__decorateElement(_init, 1, "fetchUpdates", _fetchUpdates_dec, ChatKitElementBase);
|
|
1223
|
-
__decorateElement(_init, 1, "sendUserMessage", _sendUserMessage_dec, ChatKitElementBase);
|
|
1224
|
-
__decorateElement(_init, 1, "setComposerValue", _setComposerValue_dec, ChatKitElementBase);
|
|
1225
|
-
__decorateElement(_init, 1, "setThreadId", _setThreadId_dec, ChatKitElementBase);
|
|
1226
|
-
__decorateElement(_init, 1, "shareThread", _shareThread_dec, ChatKitElementBase);
|
|
1227
|
-
__decorateElement(_init, 1, "sendCustomAction", _sendCustomAction_dec, ChatKitElementBase);
|
|
1228
|
-
__decorateElement(_init, 1, "showHistory", _showHistory_dec, ChatKitElementBase);
|
|
1229
|
-
__decorateElement(_init, 1, "hideHistory", _hideHistory_dec, ChatKitElementBase);
|
|
1230
|
-
__decorateElement(_init, 1, "setTrainingOptOut", _setTrainingOptOut_dec, ChatKitElementBase);
|
|
1231
|
-
__decoratorMetadata(_init, ChatKitElementBase);
|
|
1232
|
-
class ChatKitElement extends ChatKitElementBase {
|
|
1233
|
-
constructor() {
|
|
1234
|
-
super({ profile: "chatkit" });
|
|
1235
|
-
}
|
|
1236
|
-
sanitizeOptions(options) {
|
|
1237
|
-
var _a3;
|
|
1238
|
-
(_a3 = options.threadItemActions) == null ? true : delete _a3.share;
|
|
1239
|
-
return options;
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
function registerChatKitElement(tag = "xpertai-chatkit") {
|
|
1243
|
-
if (!("customElements" in globalThis)) return;
|
|
1244
|
-
if (!customElements.get(tag)) {
|
|
1245
|
-
customElements.define(tag, ChatKitElement);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
registerChatKitElement();
|
|
1249
1
|
const EXCLUDED_HANDLER_KEYS = /* @__PURE__ */ new Set(["onClientTool"]);
|
|
1250
2
|
const EVENT_HANDLER_MAP = {
|
|
1251
3
|
"chatkit.error": "onError",
|
|
@@ -1310,8 +62,8 @@ function applyOptions(el, options, isCurrent) {
|
|
|
1310
62
|
};
|
|
1311
63
|
}
|
|
1312
64
|
function getControlBase() {
|
|
1313
|
-
var
|
|
1314
|
-
if ((
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if ((_b = (_a = sap == null ? void 0 : sap.ui) == null ? void 0 : _a.core) == null ? void 0 : _b.Control) {
|
|
1315
67
|
return sap.ui.core.Control;
|
|
1316
68
|
}
|
|
1317
69
|
throw new Error("sap.ui.core.Control is required for @xpert-ai/chatkit-ui5");
|
|
@@ -1407,10 +159,10 @@ const ChatKit = ControlBase.extend("xpertai.chatkit.ui5.ChatKit", {
|
|
|
1407
159
|
el.addEventListener(
|
|
1408
160
|
eventName,
|
|
1409
161
|
(e) => {
|
|
1410
|
-
var
|
|
162
|
+
var _a;
|
|
1411
163
|
const detail = e.detail;
|
|
1412
164
|
const handlerName = EVENT_HANDLER_MAP[eventName];
|
|
1413
|
-
const handler = (
|
|
165
|
+
const handler = (_a = this._handlers) == null ? void 0 : _a[handlerName];
|
|
1414
166
|
if (typeof handler === "function") {
|
|
1415
167
|
handler(detail);
|
|
1416
168
|
}
|