@lichen-ai/chatkit-web-component 0.3.5
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/LICENSE +201 -0
- package/README.md +9 -0
- package/dist/xpert-chatkit.d.ts +1 -0
- package/dist/xpert-chatkit.js +3313 -0
- package/dist/xpert-chatkit.js.map +1 -0
- package/dist/xpert-chatkit.umd.cjs +3318 -0
- package/dist/xpert-chatkit.umd.cjs.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,3313 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
11
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
12
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
13
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
14
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
15
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
16
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
20
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
21
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
22
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
23
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
24
|
+
return __privateGet(this, extra);
|
|
25
|
+
}, set [name](x) {
|
|
26
|
+
return __privateSet(this, extra, x);
|
|
27
|
+
} }, name));
|
|
28
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
29
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
30
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
31
|
+
if (k) {
|
|
32
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
33
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
34
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
35
|
+
}
|
|
36
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
37
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
38
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
39
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
40
|
+
}
|
|
41
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
42
|
+
};
|
|
43
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
44
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
45
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
46
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
47
|
+
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);
|
|
48
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
49
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
50
|
+
var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _launcherCloseButton, _launcherOpen, _chatMinimizedToPet, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, setChatMinimizedToPet_fn, syncPetOverlayOptions_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
|
|
51
|
+
class EventEmitter {
|
|
52
|
+
constructor() {
|
|
53
|
+
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
54
|
+
}
|
|
55
|
+
on(event, callback) {
|
|
56
|
+
if (!this.callbacks.has(event)) {
|
|
57
|
+
this.callbacks.set(event, /* @__PURE__ */ new Set());
|
|
58
|
+
}
|
|
59
|
+
this.callbacks.get(event).add(callback);
|
|
60
|
+
}
|
|
61
|
+
emit(event, ...args) {
|
|
62
|
+
var _a2;
|
|
63
|
+
const data = args[0];
|
|
64
|
+
(_a2 = this.callbacks.get(event)) == null ? void 0 : _a2.forEach((callback) => callback(data));
|
|
65
|
+
}
|
|
66
|
+
off(event, callback) {
|
|
67
|
+
var _a2;
|
|
68
|
+
if (!callback) {
|
|
69
|
+
this.callbacks.delete(event);
|
|
70
|
+
} else {
|
|
71
|
+
(_a2 = this.callbacks.get(event)) == null ? void 0 : _a2.delete(callback);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
allOff() {
|
|
75
|
+
this.callbacks.clear();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function getBytes(stream, onChunk) {
|
|
79
|
+
const reader = stream.getReader();
|
|
80
|
+
let result;
|
|
81
|
+
while (!(result = await reader.read()).done) {
|
|
82
|
+
onChunk(result.value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function getLines(onLine) {
|
|
86
|
+
let buffer;
|
|
87
|
+
let position;
|
|
88
|
+
let fieldLength;
|
|
89
|
+
let discardTrailingNewline = false;
|
|
90
|
+
return function onChunk(arr) {
|
|
91
|
+
if (buffer === void 0) {
|
|
92
|
+
buffer = arr;
|
|
93
|
+
position = 0;
|
|
94
|
+
fieldLength = -1;
|
|
95
|
+
} else {
|
|
96
|
+
buffer = concat(buffer, arr);
|
|
97
|
+
}
|
|
98
|
+
const bufLength = buffer.length;
|
|
99
|
+
let lineStart = 0;
|
|
100
|
+
while (position < bufLength) {
|
|
101
|
+
if (discardTrailingNewline) {
|
|
102
|
+
if (buffer[position] === 10) {
|
|
103
|
+
lineStart = ++position;
|
|
104
|
+
}
|
|
105
|
+
discardTrailingNewline = false;
|
|
106
|
+
}
|
|
107
|
+
let lineEnd = -1;
|
|
108
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
|
109
|
+
switch (buffer[position]) {
|
|
110
|
+
case 58:
|
|
111
|
+
if (fieldLength === -1) {
|
|
112
|
+
fieldLength = position - lineStart;
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
case 13:
|
|
116
|
+
discardTrailingNewline = true;
|
|
117
|
+
case 10:
|
|
118
|
+
lineEnd = position;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (lineEnd === -1) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
|
126
|
+
lineStart = position;
|
|
127
|
+
fieldLength = -1;
|
|
128
|
+
}
|
|
129
|
+
if (lineStart === bufLength) {
|
|
130
|
+
buffer = void 0;
|
|
131
|
+
} else if (lineStart !== 0) {
|
|
132
|
+
buffer = buffer.subarray(lineStart);
|
|
133
|
+
position -= lineStart;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function getMessages(onId, onRetry, onMessage) {
|
|
138
|
+
let message = newMessage();
|
|
139
|
+
const decoder = new TextDecoder();
|
|
140
|
+
return function onLine(line, fieldLength) {
|
|
141
|
+
if (line.length === 0) {
|
|
142
|
+
onMessage === null || onMessage === void 0 ? void 0 : onMessage(message);
|
|
143
|
+
message = newMessage();
|
|
144
|
+
} else if (fieldLength > 0) {
|
|
145
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
|
146
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 ? 2 : 1);
|
|
147
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
|
148
|
+
switch (field) {
|
|
149
|
+
case "data":
|
|
150
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
|
151
|
+
break;
|
|
152
|
+
case "event":
|
|
153
|
+
message.event = value;
|
|
154
|
+
break;
|
|
155
|
+
case "id":
|
|
156
|
+
onId(message.id = value);
|
|
157
|
+
break;
|
|
158
|
+
case "retry":
|
|
159
|
+
const retry = parseInt(value, 10);
|
|
160
|
+
if (!isNaN(retry)) {
|
|
161
|
+
onRetry(message.retry = retry);
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function concat(a, b) {
|
|
169
|
+
const res = new Uint8Array(a.length + b.length);
|
|
170
|
+
res.set(a);
|
|
171
|
+
res.set(b, a.length);
|
|
172
|
+
return res;
|
|
173
|
+
}
|
|
174
|
+
function newMessage() {
|
|
175
|
+
return {
|
|
176
|
+
data: "",
|
|
177
|
+
event: "",
|
|
178
|
+
id: "",
|
|
179
|
+
retry: void 0
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
var __rest = function(s, e) {
|
|
183
|
+
var t = {};
|
|
184
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
185
|
+
t[p] = s[p];
|
|
186
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
187
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
188
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
189
|
+
t[p[i]] = s[p[i]];
|
|
190
|
+
}
|
|
191
|
+
return t;
|
|
192
|
+
};
|
|
193
|
+
const EventStreamContentType = "text/event-stream";
|
|
194
|
+
const DefaultRetryInterval = 1e3;
|
|
195
|
+
const LastEventId = "last-event-id";
|
|
196
|
+
function fetchEventSource(input, _a2) {
|
|
197
|
+
var { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch } = _a2, rest = __rest(_a2, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const headers = Object.assign({}, inputHeaders);
|
|
200
|
+
if (!headers.accept) {
|
|
201
|
+
headers.accept = EventStreamContentType;
|
|
202
|
+
}
|
|
203
|
+
let curRequestController;
|
|
204
|
+
function onVisibilityChange() {
|
|
205
|
+
curRequestController.abort();
|
|
206
|
+
if (!document.hidden) {
|
|
207
|
+
create();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (!openWhenHidden) {
|
|
211
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
212
|
+
}
|
|
213
|
+
let retryInterval = DefaultRetryInterval;
|
|
214
|
+
let retryTimer = 0;
|
|
215
|
+
function dispose() {
|
|
216
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
217
|
+
window.clearTimeout(retryTimer);
|
|
218
|
+
curRequestController.abort();
|
|
219
|
+
}
|
|
220
|
+
inputSignal === null || inputSignal === void 0 ? void 0 : inputSignal.addEventListener("abort", () => {
|
|
221
|
+
dispose();
|
|
222
|
+
resolve();
|
|
223
|
+
});
|
|
224
|
+
const fetch2 = inputFetch !== null && inputFetch !== void 0 ? inputFetch : window.fetch;
|
|
225
|
+
const onopen = inputOnOpen !== null && inputOnOpen !== void 0 ? inputOnOpen : defaultOnOpen;
|
|
226
|
+
async function create() {
|
|
227
|
+
var _a3;
|
|
228
|
+
curRequestController = new AbortController();
|
|
229
|
+
try {
|
|
230
|
+
const response = await fetch2(input, Object.assign(Object.assign({}, rest), { headers, signal: curRequestController.signal }));
|
|
231
|
+
await onopen(response);
|
|
232
|
+
await getBytes(response.body, getLines(getMessages((id) => {
|
|
233
|
+
if (id) {
|
|
234
|
+
headers[LastEventId] = id;
|
|
235
|
+
} else {
|
|
236
|
+
delete headers[LastEventId];
|
|
237
|
+
}
|
|
238
|
+
}, (retry) => {
|
|
239
|
+
retryInterval = retry;
|
|
240
|
+
}, onmessage)));
|
|
241
|
+
onclose === null || onclose === void 0 ? void 0 : onclose();
|
|
242
|
+
dispose();
|
|
243
|
+
resolve();
|
|
244
|
+
} catch (err) {
|
|
245
|
+
if (!curRequestController.signal.aborted) {
|
|
246
|
+
try {
|
|
247
|
+
const interval = (_a3 = onerror === null || onerror === void 0 ? void 0 : onerror(err)) !== null && _a3 !== void 0 ? _a3 : retryInterval;
|
|
248
|
+
window.clearTimeout(retryTimer);
|
|
249
|
+
retryTimer = window.setTimeout(create, interval);
|
|
250
|
+
} catch (innerErr) {
|
|
251
|
+
dispose();
|
|
252
|
+
reject(innerErr);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
create();
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function defaultOnOpen(response) {
|
|
261
|
+
const contentType = response.headers.get("content-type");
|
|
262
|
+
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith(EventStreamContentType))) {
|
|
263
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const FRAME_SAFE_ERROR_KEY = "__chatkit_error__";
|
|
267
|
+
class HttpError extends Error {
|
|
268
|
+
constructor(message, res, metadata) {
|
|
269
|
+
super(message);
|
|
270
|
+
__publicField(this, "status");
|
|
271
|
+
__publicField(this, "statusText");
|
|
272
|
+
__publicField(this, "metadata");
|
|
273
|
+
this.name = "HttpError";
|
|
274
|
+
this.statusText = res.statusText;
|
|
275
|
+
this.status = res.status;
|
|
276
|
+
this.metadata = metadata;
|
|
277
|
+
}
|
|
278
|
+
static fromPossibleFrameSafeError(error) {
|
|
279
|
+
if (error instanceof HttpError) {
|
|
280
|
+
return error;
|
|
281
|
+
}
|
|
282
|
+
if (error && typeof error === "object" && FRAME_SAFE_ERROR_KEY in error && error[FRAME_SAFE_ERROR_KEY] === "HttpError") {
|
|
283
|
+
const safeError = error;
|
|
284
|
+
const parsedError = new HttpError(
|
|
285
|
+
safeError.message,
|
|
286
|
+
{
|
|
287
|
+
status: safeError.status,
|
|
288
|
+
statusText: safeError.statusText
|
|
289
|
+
},
|
|
290
|
+
safeError.metadata
|
|
291
|
+
);
|
|
292
|
+
parsedError.stack = safeError.stack;
|
|
293
|
+
return parsedError;
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
_a = FRAME_SAFE_ERROR_KEY;
|
|
299
|
+
const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
300
|
+
constructor(message, res, metadata) {
|
|
301
|
+
__publicField(this, _a, "HttpError");
|
|
302
|
+
__publicField(this, "message");
|
|
303
|
+
__publicField(this, "stack");
|
|
304
|
+
__publicField(this, "status");
|
|
305
|
+
__publicField(this, "statusText");
|
|
306
|
+
__publicField(this, "metadata");
|
|
307
|
+
this.message = message;
|
|
308
|
+
this.stack = new Error(message).stack;
|
|
309
|
+
this.status = res.status;
|
|
310
|
+
this.statusText = res.statusText;
|
|
311
|
+
this.metadata = metadata;
|
|
312
|
+
}
|
|
313
|
+
static fromHttpError(error) {
|
|
314
|
+
return new _FrameSafeHttpError(
|
|
315
|
+
error.message,
|
|
316
|
+
{
|
|
317
|
+
status: error.status,
|
|
318
|
+
statusText: error.statusText
|
|
319
|
+
},
|
|
320
|
+
error.metadata
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
let FrameSafeHttpError = _FrameSafeHttpError;
|
|
325
|
+
const BASE_RETRY_DELAY_MS = 1e3;
|
|
326
|
+
const MAX_RETRY_DELAY_MS = 1e4;
|
|
327
|
+
const MAX_RETRY_ATTEMPTS = 5;
|
|
328
|
+
const nextDelay = (attempt, maxRetryDelay = MAX_RETRY_DELAY_MS, baseDelayMs = BASE_RETRY_DELAY_MS) => {
|
|
329
|
+
const max = Math.min(maxRetryDelay, baseDelayMs * 2 ** attempt);
|
|
330
|
+
return Math.floor(max * (0.5 + Math.random() * 0.5));
|
|
331
|
+
};
|
|
332
|
+
class RetryableError extends Error {
|
|
333
|
+
constructor(cause) {
|
|
334
|
+
super();
|
|
335
|
+
this.cause = cause;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const fetchEventSourceWithRetry = async (url, params) => {
|
|
339
|
+
let retryAttempt = 0;
|
|
340
|
+
const { onopen, ...restParams } = params;
|
|
341
|
+
await fetchEventSource(url, {
|
|
342
|
+
...restParams,
|
|
343
|
+
onopen: async (res) => {
|
|
344
|
+
var _a2;
|
|
345
|
+
onopen == null ? void 0 : onopen(res);
|
|
346
|
+
if (res.ok && ((_a2 = res.headers.get("content-type")) == null ? void 0 : _a2.startsWith("text/event-stream"))) {
|
|
347
|
+
retryAttempt = 0;
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const httpError = new FrameSafeHttpError(`Streaming failed: ${res.statusText}`, res);
|
|
351
|
+
if (res.status >= 400 && res.status < 500) {
|
|
352
|
+
throw httpError;
|
|
353
|
+
} else {
|
|
354
|
+
throw new RetryableError(httpError);
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
onerror: (error) => {
|
|
358
|
+
if (error instanceof RetryableError) {
|
|
359
|
+
if (retryAttempt >= MAX_RETRY_ATTEMPTS) {
|
|
360
|
+
throw error.cause;
|
|
361
|
+
}
|
|
362
|
+
retryAttempt += 1;
|
|
363
|
+
return nextDelay(retryAttempt);
|
|
364
|
+
}
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
function safeRandomUUID() {
|
|
370
|
+
const cryptoRef = globalThis.crypto;
|
|
371
|
+
if (typeof (cryptoRef == null ? void 0 : cryptoRef.randomUUID) === "function") {
|
|
372
|
+
return cryptoRef.randomUUID();
|
|
373
|
+
}
|
|
374
|
+
if (typeof (cryptoRef == null ? void 0 : cryptoRef.getRandomValues) === "function") {
|
|
375
|
+
const bytes = new Uint8Array(16);
|
|
376
|
+
cryptoRef.getRandomValues(bytes);
|
|
377
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
378
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
379
|
+
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
380
|
+
}
|
|
381
|
+
return `ck_${Date.now()}_${Math.random().toString(16).slice(2)}`;
|
|
382
|
+
}
|
|
383
|
+
let IntegrationError$1 = class IntegrationError extends Error {
|
|
384
|
+
constructor(message) {
|
|
385
|
+
super(message);
|
|
386
|
+
__publicField(this, "_name");
|
|
387
|
+
this.name = "IntegrationError";
|
|
388
|
+
this._name = this.name;
|
|
389
|
+
}
|
|
390
|
+
static fromPossibleFrameSafeError(error) {
|
|
391
|
+
if (error && typeof error === "object" && FRAME_SAFE_ERROR_KEY in error && error[FRAME_SAFE_ERROR_KEY] === "IntegrationError") {
|
|
392
|
+
const safeError = error;
|
|
393
|
+
const parsedError = new IntegrationError(safeError.message);
|
|
394
|
+
parsedError.stack = safeError.stack;
|
|
395
|
+
return parsedError;
|
|
396
|
+
}
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
_b = FRAME_SAFE_ERROR_KEY;
|
|
401
|
+
class FrameSafeIntegrationError {
|
|
402
|
+
constructor(message) {
|
|
403
|
+
__publicField(this, _b, "IntegrationError");
|
|
404
|
+
__publicField(this, "message");
|
|
405
|
+
__publicField(this, "stack");
|
|
406
|
+
this.message = message;
|
|
407
|
+
this.stack = new Error(message).stack;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
class BaseMessenger {
|
|
411
|
+
constructor({
|
|
412
|
+
handlers,
|
|
413
|
+
target,
|
|
414
|
+
targetOrigin,
|
|
415
|
+
fetch: fetch2 = window.fetch
|
|
416
|
+
}) {
|
|
417
|
+
__publicField(this, "targetOrigin");
|
|
418
|
+
__publicField(this, "target");
|
|
419
|
+
__publicField(this, "commandHandlers");
|
|
420
|
+
__publicField(this, "_fetch");
|
|
421
|
+
__publicField(this, "emitter", new EventEmitter());
|
|
422
|
+
__publicField(this, "handlers", /* @__PURE__ */ new Map());
|
|
423
|
+
__publicField(this, "fetchEventSourceHandlers", /* @__PURE__ */ new Map());
|
|
424
|
+
__publicField(this, "abortControllers", /* @__PURE__ */ new Map());
|
|
425
|
+
__publicField(this, "commands", new Proxy(
|
|
426
|
+
{},
|
|
427
|
+
{
|
|
428
|
+
get: (_, command) => {
|
|
429
|
+
return (data, transfer) => {
|
|
430
|
+
return new Promise((resolve, reject) => {
|
|
431
|
+
const nonce = safeRandomUUID();
|
|
432
|
+
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
433
|
+
this.sendMessage(
|
|
434
|
+
{
|
|
435
|
+
type: "command",
|
|
436
|
+
nonce,
|
|
437
|
+
command: `on${command.charAt(0).toUpperCase()}${command.slice(1)}`,
|
|
438
|
+
data
|
|
439
|
+
},
|
|
440
|
+
transfer
|
|
441
|
+
);
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
));
|
|
447
|
+
__publicField(this, "handleMessage", async (event) => {
|
|
448
|
+
var _a2, _b2, _c2, _d;
|
|
449
|
+
if (!event.data || event.data.__xpaiChatKit !== true || event.origin !== this.targetOrigin || event.source !== this.target()) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const data = event.data;
|
|
453
|
+
switch (data.type) {
|
|
454
|
+
case "event": {
|
|
455
|
+
this.emitter.emit(data.event, data.data);
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
case "fetch": {
|
|
459
|
+
try {
|
|
460
|
+
if (data.formData) {
|
|
461
|
+
const formData = new FormData();
|
|
462
|
+
for (const [key, value] of Object.entries(data.formData)) {
|
|
463
|
+
formData.append(key, value);
|
|
464
|
+
}
|
|
465
|
+
data.params.body = formData;
|
|
466
|
+
}
|
|
467
|
+
const controller = new AbortController();
|
|
468
|
+
this.abortControllers.set(data.nonce, controller);
|
|
469
|
+
data.params.signal = controller.signal;
|
|
470
|
+
const res = await this._fetch(data.url, data.params);
|
|
471
|
+
if (!res.ok) {
|
|
472
|
+
const message = await res.json().then((json2) => json2.message || res.statusText).catch(() => res.statusText);
|
|
473
|
+
throw new FrameSafeHttpError(message, res);
|
|
474
|
+
}
|
|
475
|
+
const json = await res.json().catch(() => ({}));
|
|
476
|
+
this.sendMessage({
|
|
477
|
+
type: "response",
|
|
478
|
+
response: json,
|
|
479
|
+
nonce: data.nonce
|
|
480
|
+
});
|
|
481
|
+
} catch (error) {
|
|
482
|
+
this.sendMessage({
|
|
483
|
+
type: "response",
|
|
484
|
+
error,
|
|
485
|
+
nonce: data.nonce
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
case "fetchEventSource": {
|
|
491
|
+
try {
|
|
492
|
+
const controller = new AbortController();
|
|
493
|
+
this.abortControllers.set(data.nonce, controller);
|
|
494
|
+
await fetchEventSourceWithRetry(data.url, {
|
|
495
|
+
...data.params,
|
|
496
|
+
signal: controller.signal,
|
|
497
|
+
fetch: this._fetch,
|
|
498
|
+
onmessage: (message) => {
|
|
499
|
+
this.sendMessage({
|
|
500
|
+
type: "fetchEventSourceMessage",
|
|
501
|
+
message,
|
|
502
|
+
nonce: data.nonce
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
this.sendMessage({
|
|
507
|
+
type: "response",
|
|
508
|
+
response: void 0,
|
|
509
|
+
nonce: data.nonce
|
|
510
|
+
});
|
|
511
|
+
} catch (error) {
|
|
512
|
+
this.sendMessage({
|
|
513
|
+
type: "response",
|
|
514
|
+
error,
|
|
515
|
+
nonce: data.nonce
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
case "command": {
|
|
521
|
+
if (!this.canReceiveCommand(data.command)) {
|
|
522
|
+
this.sendMessage({
|
|
523
|
+
type: "response",
|
|
524
|
+
error: new FrameSafeIntegrationError(`Command ${data.command} not supported`),
|
|
525
|
+
nonce: data.nonce
|
|
526
|
+
});
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
530
|
+
const response = await ((_b2 = (_a2 = this.commandHandlers)[data.command]) == null ? void 0 : _b2.call(_a2, data.data));
|
|
531
|
+
this.sendMessage({
|
|
532
|
+
type: "response",
|
|
533
|
+
response,
|
|
534
|
+
nonce: data.nonce
|
|
535
|
+
});
|
|
536
|
+
} catch (error) {
|
|
537
|
+
this.sendMessage({
|
|
538
|
+
type: "response",
|
|
539
|
+
error,
|
|
540
|
+
nonce: data.nonce
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
case "response": {
|
|
546
|
+
const handler = this.handlers.get(data.nonce);
|
|
547
|
+
if (!handler) {
|
|
548
|
+
console.error("No handler found for nonce", data.nonce);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
if (data.error) {
|
|
552
|
+
const integrationError = IntegrationError$1.fromPossibleFrameSafeError(data.error);
|
|
553
|
+
const httpError = HttpError.fromPossibleFrameSafeError(data.error);
|
|
554
|
+
if (integrationError) {
|
|
555
|
+
integrationError.stack = handler.stack;
|
|
556
|
+
handler.reject(integrationError);
|
|
557
|
+
} else if (httpError) {
|
|
558
|
+
handler.reject(httpError);
|
|
559
|
+
} else {
|
|
560
|
+
handler.reject(data.error);
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
handler.resolve(data.response);
|
|
564
|
+
}
|
|
565
|
+
this.handlers.delete(data.nonce);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
case "fetchEventSourceMessage": {
|
|
569
|
+
const handler = this.fetchEventSourceHandlers.get(data.nonce);
|
|
570
|
+
if (!handler) {
|
|
571
|
+
console.error("No handler found for nonce", data.nonce);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
(_d = (_c2 = this.fetchEventSourceHandlers.get(data.nonce)) == null ? void 0 : _c2.onmessage) == null ? void 0 : _d.call(_c2, data.message);
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
case "abortSignal": {
|
|
578
|
+
const controller = this.abortControllers.get(data.nonce);
|
|
579
|
+
if (controller) {
|
|
580
|
+
controller.abort(data.reason);
|
|
581
|
+
this.abortControllers.delete(data.nonce);
|
|
582
|
+
}
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
this.commandHandlers = handlers;
|
|
588
|
+
this.target = target;
|
|
589
|
+
this.targetOrigin = targetOrigin;
|
|
590
|
+
this._fetch = (...args) => fetch2(...args);
|
|
591
|
+
}
|
|
592
|
+
setTargetOrigin(targetOrigin) {
|
|
593
|
+
this.targetOrigin = targetOrigin;
|
|
594
|
+
}
|
|
595
|
+
sendMessage(data, transfer) {
|
|
596
|
+
var _a2;
|
|
597
|
+
const message = {
|
|
598
|
+
__xpaiChatKit: true,
|
|
599
|
+
...data
|
|
600
|
+
};
|
|
601
|
+
(_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
|
|
602
|
+
}
|
|
603
|
+
connect() {
|
|
604
|
+
window.addEventListener("message", this.handleMessage);
|
|
605
|
+
}
|
|
606
|
+
disconnect() {
|
|
607
|
+
window.removeEventListener("message", this.handleMessage);
|
|
608
|
+
}
|
|
609
|
+
fetch(url, params) {
|
|
610
|
+
return new Promise((resolve, reject) => {
|
|
611
|
+
const nonce = safeRandomUUID();
|
|
612
|
+
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
613
|
+
let formData;
|
|
614
|
+
if (params.body instanceof FormData) {
|
|
615
|
+
formData = {};
|
|
616
|
+
for (const [key, value] of params.body.entries()) {
|
|
617
|
+
formData[key] = value;
|
|
618
|
+
}
|
|
619
|
+
params.body = void 0;
|
|
620
|
+
}
|
|
621
|
+
if (params.signal) {
|
|
622
|
+
params.signal.addEventListener("abort", () => {
|
|
623
|
+
var _a2;
|
|
624
|
+
this.sendMessage({
|
|
625
|
+
type: "abortSignal",
|
|
626
|
+
nonce,
|
|
627
|
+
reason: (_a2 = params.signal) == null ? void 0 : _a2.reason
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
params.signal = void 0;
|
|
631
|
+
}
|
|
632
|
+
this.sendMessage({ type: "fetch", nonce, params, formData, url });
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
// Supporting onopen would require a good way for us to serialize the Response object
|
|
636
|
+
// across the iframe boundary, which is not trivial and also not really necessary.
|
|
637
|
+
fetchEventSource(url, params) {
|
|
638
|
+
return new Promise((resolve, reject) => {
|
|
639
|
+
const { onmessage, signal, ...rest } = params;
|
|
640
|
+
const nonce = safeRandomUUID();
|
|
641
|
+
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
642
|
+
this.fetchEventSourceHandlers.set(nonce, {
|
|
643
|
+
onmessage
|
|
644
|
+
});
|
|
645
|
+
if (signal) {
|
|
646
|
+
signal.addEventListener("abort", () => {
|
|
647
|
+
this.sendMessage({
|
|
648
|
+
type: "abortSignal",
|
|
649
|
+
nonce,
|
|
650
|
+
reason: signal.reason
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
this.sendMessage({ type: "fetchEventSource", nonce, params: rest, url });
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
emit(...[event, data, transfer]) {
|
|
658
|
+
this.sendMessage(
|
|
659
|
+
{
|
|
660
|
+
type: "event",
|
|
661
|
+
event,
|
|
662
|
+
data
|
|
663
|
+
},
|
|
664
|
+
transfer
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
on(...[event, callback]) {
|
|
668
|
+
this.emitter.on(event, callback);
|
|
669
|
+
}
|
|
670
|
+
destroy() {
|
|
671
|
+
window.removeEventListener("message", this.handleMessage);
|
|
672
|
+
this.emitter.allOff();
|
|
673
|
+
this.handlers.clear();
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const toUrlBase64 = (bin) => btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
677
|
+
const encodeBase64 = (value) => {
|
|
678
|
+
if (value === void 0) {
|
|
679
|
+
throw new TypeError(
|
|
680
|
+
"encodeBase64: `undefined` cannot be encoded to valid JSON. Pass null instead."
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
const json = JSON.stringify(value);
|
|
684
|
+
const bytes = new TextEncoder().encode(json);
|
|
685
|
+
let bin = "";
|
|
686
|
+
for (const b of bytes) bin += String.fromCharCode(b);
|
|
687
|
+
return toUrlBase64(bin);
|
|
688
|
+
};
|
|
689
|
+
class IntegrationError2 extends Error {
|
|
690
|
+
}
|
|
691
|
+
function fromPossibleFrameSafeError(err) {
|
|
692
|
+
return err.message;
|
|
693
|
+
}
|
|
694
|
+
const BASE_CAPABILITY_ALLOWLIST = [
|
|
695
|
+
// commands
|
|
696
|
+
"command.setOptions",
|
|
697
|
+
"command.sendUserMessage",
|
|
698
|
+
"command.setComposerValue",
|
|
699
|
+
"command.setThreadId",
|
|
700
|
+
"command.focusComposer",
|
|
701
|
+
"command.fetchUpdates",
|
|
702
|
+
"command.sendCustomAction",
|
|
703
|
+
"command.showHistory",
|
|
704
|
+
"command.hideHistory",
|
|
705
|
+
// events
|
|
706
|
+
"event.ready",
|
|
707
|
+
"event.error",
|
|
708
|
+
"event.log",
|
|
709
|
+
"event.response.start",
|
|
710
|
+
"event.response.end",
|
|
711
|
+
"event.response.stop",
|
|
712
|
+
"event.thread.change",
|
|
713
|
+
"event.tool.change",
|
|
714
|
+
"event.thread.load.start",
|
|
715
|
+
"event.thread.load.end",
|
|
716
|
+
"event.deeplink",
|
|
717
|
+
"event.effect",
|
|
718
|
+
// errors
|
|
719
|
+
"error.StreamError",
|
|
720
|
+
"error.StreamEventParsingError",
|
|
721
|
+
"error.WidgetItemError",
|
|
722
|
+
"error.InitialThreadLoadError",
|
|
723
|
+
"error.FileAttachmentError",
|
|
724
|
+
"error.HistoryViewError",
|
|
725
|
+
"error.FatalAppError",
|
|
726
|
+
"error.IntegrationError",
|
|
727
|
+
"error.EntitySearchError",
|
|
728
|
+
"error.DomainVerificationRequestError",
|
|
729
|
+
// backend
|
|
730
|
+
"backend.threads.get_by_id",
|
|
731
|
+
"backend.threads.list",
|
|
732
|
+
"backend.threads.update",
|
|
733
|
+
"backend.threads.delete",
|
|
734
|
+
"backend.threads.create",
|
|
735
|
+
"backend.threads.add_user_message",
|
|
736
|
+
"backend.threads.add_client_tool_output",
|
|
737
|
+
"backend.threads.retry_after_item",
|
|
738
|
+
"backend.threads.custom_action",
|
|
739
|
+
"backend.attachments.create",
|
|
740
|
+
"backend.attachments.get_preview",
|
|
741
|
+
"backend.attachments.delete",
|
|
742
|
+
"backend.items.list",
|
|
743
|
+
"backend.items.feedback",
|
|
744
|
+
// thread item types
|
|
745
|
+
"thread.item.generated_image",
|
|
746
|
+
"thread.item.user_message",
|
|
747
|
+
"thread.item.assistant_message",
|
|
748
|
+
"thread.item.client_tool_call",
|
|
749
|
+
"thread.item.widget",
|
|
750
|
+
"thread.item.task",
|
|
751
|
+
"thread.item.workflow",
|
|
752
|
+
"thread.item.end_of_turn",
|
|
753
|
+
"thread.item.image_generation",
|
|
754
|
+
// widgets
|
|
755
|
+
"widget.Basic",
|
|
756
|
+
"widget.Card",
|
|
757
|
+
"widget.ListView",
|
|
758
|
+
"widget.ListViewItem",
|
|
759
|
+
"widget.Badge",
|
|
760
|
+
"widget.Box",
|
|
761
|
+
"widget.Row",
|
|
762
|
+
"widget.Col",
|
|
763
|
+
"widget.Button",
|
|
764
|
+
"widget.Caption",
|
|
765
|
+
"widget.Chart",
|
|
766
|
+
"widget.Checkbox",
|
|
767
|
+
"widget.DatePicker",
|
|
768
|
+
"widget.Divider",
|
|
769
|
+
"widget.Form",
|
|
770
|
+
"widget.Icon",
|
|
771
|
+
"widget.Image",
|
|
772
|
+
"widget.Input",
|
|
773
|
+
"widget.Label",
|
|
774
|
+
"widget.Markdown",
|
|
775
|
+
"widget.RadioGroup",
|
|
776
|
+
"widget.Select",
|
|
777
|
+
"widget.Spacer",
|
|
778
|
+
"widget.Text",
|
|
779
|
+
"widget.Textarea",
|
|
780
|
+
"widget.Title",
|
|
781
|
+
"widget.Transition"
|
|
782
|
+
];
|
|
783
|
+
const BASE_CAPABILITY_DENYLIST = [
|
|
784
|
+
// --- commands
|
|
785
|
+
"command.shareThread",
|
|
786
|
+
"command.setTrainingOptOut",
|
|
787
|
+
// --- events
|
|
788
|
+
"event.thread.restore",
|
|
789
|
+
"event.message.share",
|
|
790
|
+
"event.image.download",
|
|
791
|
+
"event.history.open",
|
|
792
|
+
"event.history.close",
|
|
793
|
+
"event.log.chatgpt",
|
|
794
|
+
// --- errors
|
|
795
|
+
// These errors considered internal and are not exposed to the user by default.
|
|
796
|
+
"error.HttpError",
|
|
797
|
+
"error.NetworkError",
|
|
798
|
+
"error.UnhandledError",
|
|
799
|
+
"error.UnhandledPromiseRejectionError",
|
|
800
|
+
"error.StreamEventHandlingError",
|
|
801
|
+
"error.StreamStopError",
|
|
802
|
+
"error.ThreadRenderingError",
|
|
803
|
+
"error.IntlError",
|
|
804
|
+
"error.AppError",
|
|
805
|
+
// --- backend
|
|
806
|
+
"backend.threads.stop",
|
|
807
|
+
"backend.threads.share",
|
|
808
|
+
"backend.threads.create_from_shared",
|
|
809
|
+
"backend.threads.init",
|
|
810
|
+
"backend.attachments.process",
|
|
811
|
+
// widgets
|
|
812
|
+
"widget.CardCarousel",
|
|
813
|
+
"widget.Favicon",
|
|
814
|
+
"widget.CardLinkItem",
|
|
815
|
+
"widget.Map"
|
|
816
|
+
];
|
|
817
|
+
const PROFILE_TO_RULES = {
|
|
818
|
+
"chatkit": {
|
|
819
|
+
allow: [...BASE_CAPABILITY_ALLOWLIST, "thread.item.image_generation"],
|
|
820
|
+
deny: BASE_CAPABILITY_DENYLIST
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
const getCapabilities = (profile) => {
|
|
824
|
+
const rules = PROFILE_TO_RULES[profile];
|
|
825
|
+
const effective = new Set(rules.allow);
|
|
826
|
+
for (const capability of rules.deny ?? []) {
|
|
827
|
+
effective.delete(capability);
|
|
828
|
+
}
|
|
829
|
+
const commands = /* @__PURE__ */ new Set();
|
|
830
|
+
const events = /* @__PURE__ */ new Set();
|
|
831
|
+
const backend = /* @__PURE__ */ new Set();
|
|
832
|
+
const threadItems = /* @__PURE__ */ new Set();
|
|
833
|
+
const errors = /* @__PURE__ */ new Set();
|
|
834
|
+
const widgets = /* @__PURE__ */ new Set();
|
|
835
|
+
for (const capability of effective) {
|
|
836
|
+
if (capability.startsWith("command.")) {
|
|
837
|
+
commands.add(capability.slice("command.".length));
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
if (capability.startsWith("event.")) {
|
|
841
|
+
events.add(capability.slice("event.".length));
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
if (capability.startsWith("backend.")) {
|
|
845
|
+
backend.add(capability.slice("backend.".length));
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
if (capability.startsWith("thread.item.")) {
|
|
849
|
+
threadItems.add(capability.slice("thread.item.".length));
|
|
850
|
+
}
|
|
851
|
+
if (capability.startsWith("error.")) {
|
|
852
|
+
errors.add(capability.slice("error.".length));
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (capability.startsWith("widget.")) {
|
|
856
|
+
widgets.add(capability.slice("widget.".length));
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return { commands, events, backend, threadItems, errors, widgets };
|
|
861
|
+
};
|
|
862
|
+
class ChatFrameMessenger extends BaseMessenger {
|
|
863
|
+
// Messenger running in outer can always handle commands coming from inner
|
|
864
|
+
canReceiveCommand(_) {
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
const PET_ANIMATION_NAMES = [
|
|
869
|
+
"idle",
|
|
870
|
+
"running-right",
|
|
871
|
+
"running-left",
|
|
872
|
+
"waving",
|
|
873
|
+
"jumping",
|
|
874
|
+
"failed",
|
|
875
|
+
"waiting",
|
|
876
|
+
"running",
|
|
877
|
+
"review"
|
|
878
|
+
];
|
|
879
|
+
const petSpriteAtlas = {
|
|
880
|
+
columns: 8,
|
|
881
|
+
rows: 9,
|
|
882
|
+
cellWidth: 192,
|
|
883
|
+
cellHeight: 208,
|
|
884
|
+
animations: {
|
|
885
|
+
idle: {
|
|
886
|
+
row: 0,
|
|
887
|
+
frames: 6,
|
|
888
|
+
frameDurations: [280, 110, 110, 140, 140, 320]
|
|
889
|
+
},
|
|
890
|
+
"running-right": {
|
|
891
|
+
row: 1,
|
|
892
|
+
frames: 8,
|
|
893
|
+
frameDurations: [120, 120, 120, 120, 120, 120, 120, 220]
|
|
894
|
+
},
|
|
895
|
+
"running-left": {
|
|
896
|
+
row: 2,
|
|
897
|
+
frames: 8,
|
|
898
|
+
frameDurations: [120, 120, 120, 120, 120, 120, 120, 220]
|
|
899
|
+
},
|
|
900
|
+
waving: {
|
|
901
|
+
row: 3,
|
|
902
|
+
frames: 4,
|
|
903
|
+
frameDurations: [140, 140, 140, 280]
|
|
904
|
+
},
|
|
905
|
+
jumping: {
|
|
906
|
+
row: 4,
|
|
907
|
+
frames: 5,
|
|
908
|
+
frameDurations: [140, 140, 140, 140, 280]
|
|
909
|
+
},
|
|
910
|
+
failed: {
|
|
911
|
+
row: 5,
|
|
912
|
+
frames: 8,
|
|
913
|
+
frameDurations: [140, 140, 140, 140, 140, 140, 140, 240]
|
|
914
|
+
},
|
|
915
|
+
waiting: {
|
|
916
|
+
row: 6,
|
|
917
|
+
frames: 6,
|
|
918
|
+
frameDurations: [150, 150, 150, 150, 150, 260]
|
|
919
|
+
},
|
|
920
|
+
running: {
|
|
921
|
+
row: 7,
|
|
922
|
+
frames: 6,
|
|
923
|
+
frameDurations: [120, 120, 120, 120, 120, 220]
|
|
924
|
+
},
|
|
925
|
+
review: {
|
|
926
|
+
row: 8,
|
|
927
|
+
frames: 6,
|
|
928
|
+
frameDurations: [150, 150, 150, 150, 150, 280]
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
const DEFAULT_PET_BOUNDS_PADDING = {
|
|
933
|
+
top: 0,
|
|
934
|
+
right: 0,
|
|
935
|
+
bottom: 0,
|
|
936
|
+
left: 0
|
|
937
|
+
};
|
|
938
|
+
const DEFAULT_PET_STORAGE_KEY = "chatkit:pet:position:v1";
|
|
939
|
+
const DEFAULT_PET_SPRITESHEET_URL = "/pets/boba/spritesheet.webp";
|
|
940
|
+
const DEFAULT_PET_CHARACTER = {
|
|
941
|
+
type: "sprite-atlas",
|
|
942
|
+
src: DEFAULT_PET_SPRITESHEET_URL
|
|
943
|
+
};
|
|
944
|
+
const DEFAULT_POSITION = {
|
|
945
|
+
pin: "bottom-right",
|
|
946
|
+
draggable: true,
|
|
947
|
+
scale: 0.25,
|
|
948
|
+
persist: true,
|
|
949
|
+
zIndex: 40
|
|
950
|
+
};
|
|
951
|
+
function mergeFrameAnimation(base, override) {
|
|
952
|
+
return {
|
|
953
|
+
row: (override == null ? void 0 : override.row) ?? base.row,
|
|
954
|
+
frames: (override == null ? void 0 : override.frames) ?? base.frames,
|
|
955
|
+
frameDurations: (override == null ? void 0 : override.frameDurations) && override.frameDurations.length > 0 ? override.frameDurations : base.frameDurations
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
function mergePetSpriteAtlas(override) {
|
|
959
|
+
var _a2;
|
|
960
|
+
const animations = {};
|
|
961
|
+
for (const name of PET_ANIMATION_NAMES) {
|
|
962
|
+
animations[name] = mergeFrameAnimation(
|
|
963
|
+
petSpriteAtlas.animations[name],
|
|
964
|
+
(_a2 = override == null ? void 0 : override.animations) == null ? void 0 : _a2[name]
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
return {
|
|
968
|
+
columns: (override == null ? void 0 : override.columns) ?? petSpriteAtlas.columns,
|
|
969
|
+
rows: (override == null ? void 0 : override.rows) ?? petSpriteAtlas.rows,
|
|
970
|
+
cellWidth: (override == null ? void 0 : override.cellWidth) ?? petSpriteAtlas.cellWidth,
|
|
971
|
+
cellHeight: (override == null ? void 0 : override.cellHeight) ?? petSpriteAtlas.cellHeight,
|
|
972
|
+
animations
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
function normalizeCharacter(character) {
|
|
976
|
+
if (!character) {
|
|
977
|
+
return DEFAULT_PET_CHARACTER;
|
|
978
|
+
}
|
|
979
|
+
if (character.src) {
|
|
980
|
+
return character;
|
|
981
|
+
}
|
|
982
|
+
return DEFAULT_PET_CHARACTER;
|
|
983
|
+
}
|
|
984
|
+
function normalizePetOptions(pet) {
|
|
985
|
+
if (!pet) {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
988
|
+
if (pet === true) {
|
|
989
|
+
return {
|
|
990
|
+
character: DEFAULT_PET_CHARACTER,
|
|
991
|
+
position: DEFAULT_POSITION,
|
|
992
|
+
behavior: "auto",
|
|
993
|
+
ariaLabel: "Animated pet",
|
|
994
|
+
imageRendering: "auto"
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
if (pet.enabled === false) {
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
return {
|
|
1001
|
+
character: normalizeCharacter(pet.character),
|
|
1002
|
+
position: {
|
|
1003
|
+
...DEFAULT_POSITION,
|
|
1004
|
+
...pet.position
|
|
1005
|
+
},
|
|
1006
|
+
behavior: pet.behavior ?? "auto",
|
|
1007
|
+
ariaLabel: pet.ariaLabel ?? "Animated pet",
|
|
1008
|
+
imageRendering: pet.imageRendering ?? "auto"
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
function resolvePetCharacter(character) {
|
|
1012
|
+
if (!character.src) {
|
|
1013
|
+
return null;
|
|
1014
|
+
}
|
|
1015
|
+
return {
|
|
1016
|
+
kind: "atlas",
|
|
1017
|
+
src: character.src,
|
|
1018
|
+
atlas: mergePetSpriteAtlas(character.atlas)
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
function normalizeBoundsPadding(value) {
|
|
1022
|
+
if (typeof value === "number") {
|
|
1023
|
+
return {
|
|
1024
|
+
top: value,
|
|
1025
|
+
right: value,
|
|
1026
|
+
bottom: value,
|
|
1027
|
+
left: value
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
1031
|
+
top: (value == null ? void 0 : value.top) ?? DEFAULT_PET_BOUNDS_PADDING.top,
|
|
1032
|
+
right: (value == null ? void 0 : value.right) ?? DEFAULT_PET_BOUNDS_PADDING.right,
|
|
1033
|
+
bottom: (value == null ? void 0 : value.bottom) ?? DEFAULT_PET_BOUNDS_PADDING.bottom,
|
|
1034
|
+
left: (value == null ? void 0 : value.left) ?? DEFAULT_PET_BOUNDS_PADDING.left
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
function clampPetPosition(position, size, viewport, padding) {
|
|
1038
|
+
const minX = padding.left;
|
|
1039
|
+
const minY = padding.top;
|
|
1040
|
+
const maxX = Math.max(minX, viewport.width - size.width - padding.right);
|
|
1041
|
+
const maxY = Math.max(minY, viewport.height - size.height - padding.bottom);
|
|
1042
|
+
return {
|
|
1043
|
+
x: Math.min(maxX, Math.max(minX, position.x)),
|
|
1044
|
+
y: Math.min(maxY, Math.max(minY, position.y))
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
function getPinnedPetPosition(pin, size, viewport, padding) {
|
|
1048
|
+
const horizontalCenter = (viewport.width - size.width) / 2;
|
|
1049
|
+
const verticalCenter = (viewport.height - size.height) / 2;
|
|
1050
|
+
const right = viewport.width - size.width - padding.right;
|
|
1051
|
+
const bottom = viewport.height - size.height - padding.bottom;
|
|
1052
|
+
switch (pin) {
|
|
1053
|
+
case "top-left":
|
|
1054
|
+
return clampPetPosition(
|
|
1055
|
+
{ x: padding.left, y: padding.top },
|
|
1056
|
+
size,
|
|
1057
|
+
viewport,
|
|
1058
|
+
padding
|
|
1059
|
+
);
|
|
1060
|
+
case "top":
|
|
1061
|
+
return clampPetPosition(
|
|
1062
|
+
{ x: horizontalCenter, y: padding.top },
|
|
1063
|
+
size,
|
|
1064
|
+
viewport,
|
|
1065
|
+
padding
|
|
1066
|
+
);
|
|
1067
|
+
case "top-right":
|
|
1068
|
+
return clampPetPosition(
|
|
1069
|
+
{ x: right, y: padding.top },
|
|
1070
|
+
size,
|
|
1071
|
+
viewport,
|
|
1072
|
+
padding
|
|
1073
|
+
);
|
|
1074
|
+
case "left":
|
|
1075
|
+
return clampPetPosition(
|
|
1076
|
+
{ x: padding.left, y: verticalCenter },
|
|
1077
|
+
size,
|
|
1078
|
+
viewport,
|
|
1079
|
+
padding
|
|
1080
|
+
);
|
|
1081
|
+
case "center":
|
|
1082
|
+
return clampPetPosition(
|
|
1083
|
+
{ x: horizontalCenter, y: verticalCenter },
|
|
1084
|
+
size,
|
|
1085
|
+
viewport,
|
|
1086
|
+
padding
|
|
1087
|
+
);
|
|
1088
|
+
case "right":
|
|
1089
|
+
return clampPetPosition(
|
|
1090
|
+
{ x: right, y: verticalCenter },
|
|
1091
|
+
size,
|
|
1092
|
+
viewport,
|
|
1093
|
+
padding
|
|
1094
|
+
);
|
|
1095
|
+
case "bottom-left":
|
|
1096
|
+
return clampPetPosition(
|
|
1097
|
+
{ x: padding.left, y: bottom },
|
|
1098
|
+
size,
|
|
1099
|
+
viewport,
|
|
1100
|
+
padding
|
|
1101
|
+
);
|
|
1102
|
+
case "bottom":
|
|
1103
|
+
return clampPetPosition(
|
|
1104
|
+
{ x: horizontalCenter, y: bottom },
|
|
1105
|
+
size,
|
|
1106
|
+
viewport,
|
|
1107
|
+
padding
|
|
1108
|
+
);
|
|
1109
|
+
case "bottom-right":
|
|
1110
|
+
default:
|
|
1111
|
+
return clampPetPosition({ x: right, y: bottom }, size, viewport, padding);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
const removeMethods = (obj, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
1115
|
+
if (typeof obj === "function") return "[ChatKitMethod]";
|
|
1116
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
1117
|
+
if (seen.has(obj)) return obj;
|
|
1118
|
+
seen.add(obj);
|
|
1119
|
+
if (Array.isArray(obj)) {
|
|
1120
|
+
return obj.map((c) => removeMethods(c, seen));
|
|
1121
|
+
}
|
|
1122
|
+
const result = {};
|
|
1123
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1124
|
+
if (typeof value !== "function") {
|
|
1125
|
+
result[key] = removeMethods(value, seen);
|
|
1126
|
+
} else {
|
|
1127
|
+
result[key] = "[ChatKitMethod]";
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
return result;
|
|
1131
|
+
};
|
|
1132
|
+
const DRAG_DIRECTION_THRESHOLD_PX = 2;
|
|
1133
|
+
const PET_BASE_RENDER_SCALE = 0.5;
|
|
1134
|
+
const PET_FRAME_DURATION_MULTIPLIER = 1.5;
|
|
1135
|
+
const PET_RESTING_FRAME_DURATION_MULTIPLIER = 3;
|
|
1136
|
+
const PET_RESTING_DELAY_MS = 2e3;
|
|
1137
|
+
const PET_SUMMARY_GAP = 12;
|
|
1138
|
+
const PET_SUMMARY_WIDTH = 320;
|
|
1139
|
+
const PET_SUMMARY_MARGIN = 12;
|
|
1140
|
+
const PET_CONTEXT_MENU_MARGIN = 8;
|
|
1141
|
+
const PET_SUMMARY_FONT_FAMILY = 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
|
1142
|
+
const PET_OVERLAY_COPY = {
|
|
1143
|
+
"en-US": {
|
|
1144
|
+
closePetMenuItem: "Close pet",
|
|
1145
|
+
hideMessage: "Hide message",
|
|
1146
|
+
expandMessage: "Expand message",
|
|
1147
|
+
collapseMessage: "Collapse message",
|
|
1148
|
+
restoreMessage: "Show message",
|
|
1149
|
+
replyButton: "Reply",
|
|
1150
|
+
replyPlaceholder: "Reply...",
|
|
1151
|
+
sendButton: "Send",
|
|
1152
|
+
sendingButton: "Sending...",
|
|
1153
|
+
sendFailed: "Failed to send"
|
|
1154
|
+
},
|
|
1155
|
+
"zh-CN": {
|
|
1156
|
+
closePetMenuItem: "关闭宠物",
|
|
1157
|
+
hideMessage: "隐藏消息",
|
|
1158
|
+
expandMessage: "展开消息",
|
|
1159
|
+
collapseMessage: "收起消息",
|
|
1160
|
+
restoreMessage: "显示消息",
|
|
1161
|
+
replyButton: "回复",
|
|
1162
|
+
replyPlaceholder: "输入回复...",
|
|
1163
|
+
sendButton: "发送",
|
|
1164
|
+
sendingButton: "发送中...",
|
|
1165
|
+
sendFailed: "发送失败"
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
function stopEventPropagation(event) {
|
|
1169
|
+
event.stopPropagation();
|
|
1170
|
+
}
|
|
1171
|
+
function getViewportSize() {
|
|
1172
|
+
const visualViewport = window.visualViewport;
|
|
1173
|
+
return {
|
|
1174
|
+
width: (visualViewport == null ? void 0 : visualViewport.width) || window.innerWidth || 320,
|
|
1175
|
+
height: (visualViewport == null ? void 0 : visualViewport.height) || window.innerHeight || 480
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
function readPersistedPosition(storageKey, persist) {
|
|
1179
|
+
if (!persist) {
|
|
1180
|
+
return null;
|
|
1181
|
+
}
|
|
1182
|
+
try {
|
|
1183
|
+
const raw = window.localStorage.getItem(storageKey);
|
|
1184
|
+
if (!raw) {
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1187
|
+
const parsed = JSON.parse(raw);
|
|
1188
|
+
if (!parsed || typeof parsed !== "object" || typeof parsed.x !== "number" || typeof parsed.y !== "number") {
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
return { x: parsed.x, y: parsed.y };
|
|
1192
|
+
} catch {
|
|
1193
|
+
return null;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
function writePersistedPosition(storageKey, persist, position) {
|
|
1197
|
+
if (!persist) {
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
try {
|
|
1201
|
+
window.localStorage.setItem(storageKey, JSON.stringify(position));
|
|
1202
|
+
} catch {
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function escapeCssUrl(value) {
|
|
1206
|
+
return value.replace(/["\\]/g, "\\$&");
|
|
1207
|
+
}
|
|
1208
|
+
function getRenderScale(scale) {
|
|
1209
|
+
return Math.max(0.1, scale) * PET_BASE_RENDER_SCALE;
|
|
1210
|
+
}
|
|
1211
|
+
function clampNumber(value, min, max) {
|
|
1212
|
+
return Math.min(max, Math.max(min, value));
|
|
1213
|
+
}
|
|
1214
|
+
function getDefaultLocale() {
|
|
1215
|
+
if (typeof window !== "undefined") {
|
|
1216
|
+
try {
|
|
1217
|
+
const stored = window.localStorage.getItem("chatkit:locale");
|
|
1218
|
+
if (stored) {
|
|
1219
|
+
return stored;
|
|
1220
|
+
}
|
|
1221
|
+
} catch {
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
return typeof navigator !== "undefined" ? navigator.language : null;
|
|
1225
|
+
}
|
|
1226
|
+
function resolveCopyLocale(locale) {
|
|
1227
|
+
const normalized = (locale ?? getDefaultLocale() ?? "").trim().toLowerCase();
|
|
1228
|
+
if (normalized === "zh-cn" || normalized === "zh-hans" || normalized.startsWith("zh")) {
|
|
1229
|
+
return "zh-CN";
|
|
1230
|
+
}
|
|
1231
|
+
return "en-US";
|
|
1232
|
+
}
|
|
1233
|
+
function getSummaryDensityMetrics(density) {
|
|
1234
|
+
switch (density) {
|
|
1235
|
+
case "compact":
|
|
1236
|
+
return {
|
|
1237
|
+
padding: "8px 10px",
|
|
1238
|
+
gap: 6,
|
|
1239
|
+
marginTop: 3,
|
|
1240
|
+
toggleSize: 30,
|
|
1241
|
+
actionSize: 22
|
|
1242
|
+
};
|
|
1243
|
+
case "spacious":
|
|
1244
|
+
return {
|
|
1245
|
+
padding: "14px 16px",
|
|
1246
|
+
gap: 10,
|
|
1247
|
+
marginTop: 6,
|
|
1248
|
+
toggleSize: 38,
|
|
1249
|
+
actionSize: 28
|
|
1250
|
+
};
|
|
1251
|
+
case "normal":
|
|
1252
|
+
default:
|
|
1253
|
+
return {
|
|
1254
|
+
padding: "12px 14px",
|
|
1255
|
+
gap: 8,
|
|
1256
|
+
marginTop: 4,
|
|
1257
|
+
toggleSize: 34,
|
|
1258
|
+
actionSize: 26
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
function getSummaryRadius(radius) {
|
|
1263
|
+
switch (radius) {
|
|
1264
|
+
case "pill":
|
|
1265
|
+
return 24;
|
|
1266
|
+
case "round":
|
|
1267
|
+
return 16;
|
|
1268
|
+
case "sharp":
|
|
1269
|
+
return 0;
|
|
1270
|
+
case "soft":
|
|
1271
|
+
default:
|
|
1272
|
+
return 12;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function getSummaryThemeMetrics(theme) {
|
|
1276
|
+
var _a2, _b2;
|
|
1277
|
+
const themeObject = typeof theme === "string" ? null : theme;
|
|
1278
|
+
const baseSize = ((_a2 = themeObject == null ? void 0 : themeObject.typography) == null ? void 0 : _a2.baseSize) ?? 16;
|
|
1279
|
+
const density = (themeObject == null ? void 0 : themeObject.density) ?? "normal";
|
|
1280
|
+
const densityOffset = density === "compact" ? -1 : density === "spacious" ? 1 : 0;
|
|
1281
|
+
const bodySize = clampNumber(baseSize - 2 + densityOffset, 11, 17);
|
|
1282
|
+
const densityMetrics = getSummaryDensityMetrics(density);
|
|
1283
|
+
return {
|
|
1284
|
+
...densityMetrics,
|
|
1285
|
+
bodySize,
|
|
1286
|
+
titleSize: bodySize + 1,
|
|
1287
|
+
iconSize: clampNumber(bodySize + 2, 13, 19),
|
|
1288
|
+
radius: getSummaryRadius(themeObject == null ? void 0 : themeObject.radius),
|
|
1289
|
+
fontFamily: ((_b2 = themeObject == null ? void 0 : themeObject.typography) == null ? void 0 : _b2.fontFamily) ?? PET_SUMMARY_FONT_FAMILY
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
function isPetState(value) {
|
|
1293
|
+
return value === "idle" || value === "running-right" || value === "running-left" || value === "waving" || value === "jumping" || value === "failed" || value === "waiting" || value === "running" || value === "review";
|
|
1294
|
+
}
|
|
1295
|
+
function parsePetStateChangePayload(value) {
|
|
1296
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1297
|
+
return null;
|
|
1298
|
+
}
|
|
1299
|
+
const payload = value;
|
|
1300
|
+
return isPetState(payload.state) ? { state: payload.state } : null;
|
|
1301
|
+
}
|
|
1302
|
+
function parsePetOptionsChangePayload(value) {
|
|
1303
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
const payload = value;
|
|
1307
|
+
if (payload.pet === null || typeof payload.pet === "boolean") {
|
|
1308
|
+
return { pet: payload.pet };
|
|
1309
|
+
}
|
|
1310
|
+
if (payload.pet && typeof payload.pet === "object" && !Array.isArray(payload.pet)) {
|
|
1311
|
+
return { pet: payload.pet };
|
|
1312
|
+
}
|
|
1313
|
+
return null;
|
|
1314
|
+
}
|
|
1315
|
+
function isThreadSummaryStatus(value) {
|
|
1316
|
+
return value === "running" || value === "completed" || value === "failed";
|
|
1317
|
+
}
|
|
1318
|
+
function getThreadSummaryKey(summary) {
|
|
1319
|
+
if (!summary) {
|
|
1320
|
+
return null;
|
|
1321
|
+
}
|
|
1322
|
+
return [
|
|
1323
|
+
summary.threadId,
|
|
1324
|
+
summary.messageId || summary.updatedAt || summary.message
|
|
1325
|
+
].join(":");
|
|
1326
|
+
}
|
|
1327
|
+
function getThreadSummaryInteractionKey(summary) {
|
|
1328
|
+
if (!summary) {
|
|
1329
|
+
return null;
|
|
1330
|
+
}
|
|
1331
|
+
return [summary.threadId, summary.messageId ?? ""].join(":");
|
|
1332
|
+
}
|
|
1333
|
+
function parseThreadSummaryPayload(value) {
|
|
1334
|
+
if (value === null) {
|
|
1335
|
+
return { summary: null };
|
|
1336
|
+
}
|
|
1337
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1338
|
+
return null;
|
|
1339
|
+
}
|
|
1340
|
+
const payload = value;
|
|
1341
|
+
if (typeof payload.threadId !== "string" || !payload.threadId.trim() || typeof payload.title !== "string" || !payload.title.trim() || typeof payload.message !== "string" || !payload.message.trim() || !isThreadSummaryStatus(payload.status)) {
|
|
1342
|
+
return null;
|
|
1343
|
+
}
|
|
1344
|
+
return {
|
|
1345
|
+
summary: {
|
|
1346
|
+
threadId: payload.threadId,
|
|
1347
|
+
title: payload.title,
|
|
1348
|
+
message: payload.message,
|
|
1349
|
+
status: payload.status,
|
|
1350
|
+
...typeof payload.messageId === "string" && payload.messageId.trim() ? { messageId: payload.messageId } : {},
|
|
1351
|
+
...typeof payload.updatedAt === "string" && payload.updatedAt.trim() ? { updatedAt: payload.updatedAt } : {}
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
function parseThreadSummaryLogPayload(value) {
|
|
1356
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1357
|
+
return null;
|
|
1358
|
+
}
|
|
1359
|
+
const payload = value;
|
|
1360
|
+
if (payload.name !== "thread.summary") {
|
|
1361
|
+
return null;
|
|
1362
|
+
}
|
|
1363
|
+
return parseThreadSummaryPayload(payload.data ?? null);
|
|
1364
|
+
}
|
|
1365
|
+
class PetOverlay {
|
|
1366
|
+
constructor(root, options) {
|
|
1367
|
+
this.overlayElement = null;
|
|
1368
|
+
this.petElement = null;
|
|
1369
|
+
this.contextMenuElement = null;
|
|
1370
|
+
this.summaryElement = null;
|
|
1371
|
+
this.summaryToggleElement = null;
|
|
1372
|
+
this.mediaElement = null;
|
|
1373
|
+
this.options = null;
|
|
1374
|
+
this.theme = null;
|
|
1375
|
+
this.resolved = null;
|
|
1376
|
+
this.summary = null;
|
|
1377
|
+
this.summaryRenderKey = null;
|
|
1378
|
+
this.dismissedSummaryKey = null;
|
|
1379
|
+
this.isSummaryCollapsed = false;
|
|
1380
|
+
this.isSummaryExpanded = false;
|
|
1381
|
+
this.isSummaryHovering = false;
|
|
1382
|
+
this.isReplyOpen = false;
|
|
1383
|
+
this.isReplySubmitting = false;
|
|
1384
|
+
this.replyError = null;
|
|
1385
|
+
this.replyDraft = "";
|
|
1386
|
+
this.replyInputElement = null;
|
|
1387
|
+
this.copyLocale = resolveCopyLocale();
|
|
1388
|
+
this.copy = PET_OVERLAY_COPY[this.copyLocale];
|
|
1389
|
+
this.currentState = "waiting";
|
|
1390
|
+
this.lastAutoState = "waiting";
|
|
1391
|
+
this.transient = null;
|
|
1392
|
+
this.position = null;
|
|
1393
|
+
this.dragPosition = null;
|
|
1394
|
+
this.dragOffset = { x: 0, y: 0 };
|
|
1395
|
+
this.lastDragPosition = null;
|
|
1396
|
+
this.lastDragClientX = null;
|
|
1397
|
+
this.dragAnimation = null;
|
|
1398
|
+
this.isDragging = false;
|
|
1399
|
+
this.isHovering = false;
|
|
1400
|
+
this.movedDuringDrag = false;
|
|
1401
|
+
this.prefersReducedMotion = false;
|
|
1402
|
+
this.frame = 0;
|
|
1403
|
+
this.completed = false;
|
|
1404
|
+
this.activeAnimationName = null;
|
|
1405
|
+
this.activeAnimationMode = null;
|
|
1406
|
+
this.frameTimer = null;
|
|
1407
|
+
this.restingDelayTimer = null;
|
|
1408
|
+
this.mediaQuery = null;
|
|
1409
|
+
this.connected = false;
|
|
1410
|
+
this.handleViewportChange = () => {
|
|
1411
|
+
this.closeContextMenu();
|
|
1412
|
+
this.render();
|
|
1413
|
+
};
|
|
1414
|
+
this.handleReducedMotionChange = () => {
|
|
1415
|
+
var _a2;
|
|
1416
|
+
this.prefersReducedMotion = Boolean((_a2 = this.mediaQuery) == null ? void 0 : _a2.matches);
|
|
1417
|
+
if (this.prefersReducedMotion) {
|
|
1418
|
+
this.transient = null;
|
|
1419
|
+
}
|
|
1420
|
+
this.render();
|
|
1421
|
+
};
|
|
1422
|
+
this.handlePointerEnter = () => {
|
|
1423
|
+
this.clearRestingDelayTimer();
|
|
1424
|
+
this.isHovering = true;
|
|
1425
|
+
this.rescheduleAnimation();
|
|
1426
|
+
};
|
|
1427
|
+
this.handlePointerLeave = () => {
|
|
1428
|
+
if (!this.isDragging) {
|
|
1429
|
+
this.enterRestingAfterDelay();
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
this.handleContextMenu = (event) => {
|
|
1433
|
+
event.preventDefault();
|
|
1434
|
+
event.stopPropagation();
|
|
1435
|
+
this.openContextMenu({ x: event.clientX, y: event.clientY });
|
|
1436
|
+
};
|
|
1437
|
+
this.handleContextMenuEvent = (event) => {
|
|
1438
|
+
event.preventDefault();
|
|
1439
|
+
event.stopPropagation();
|
|
1440
|
+
};
|
|
1441
|
+
this.handleContextMenuOutsidePointerDown = (event) => {
|
|
1442
|
+
const menu = this.contextMenuElement;
|
|
1443
|
+
if (menu && event.composedPath().includes(menu)) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
this.closeContextMenu();
|
|
1447
|
+
};
|
|
1448
|
+
this.handleContextMenuKeyDown = (event) => {
|
|
1449
|
+
if (event.key !== "Escape") {
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
event.preventDefault();
|
|
1453
|
+
this.closeContextMenu();
|
|
1454
|
+
};
|
|
1455
|
+
this.handleClosePetMenuItemClick = (event) => {
|
|
1456
|
+
var _a2;
|
|
1457
|
+
event.preventDefault();
|
|
1458
|
+
event.stopPropagation();
|
|
1459
|
+
this.closeContextMenu();
|
|
1460
|
+
(_a2 = this.onClose) == null ? void 0 : _a2.call(this);
|
|
1461
|
+
};
|
|
1462
|
+
this.handleSummaryPointerEnter = () => {
|
|
1463
|
+
this.isSummaryHovering = true;
|
|
1464
|
+
this.render();
|
|
1465
|
+
};
|
|
1466
|
+
this.handleSummaryPointerLeave = () => {
|
|
1467
|
+
this.isSummaryHovering = false;
|
|
1468
|
+
if (!this.isReplyOpen) {
|
|
1469
|
+
this.render();
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
this.handleSummaryClick = () => {
|
|
1473
|
+
var _a2, _b2;
|
|
1474
|
+
const threadId = (_a2 = this.summary) == null ? void 0 : _a2.threadId.trim();
|
|
1475
|
+
if (!threadId) {
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
(_b2 = this.onThreadSummaryActivate) == null ? void 0 : _b2.call(this, threadId);
|
|
1479
|
+
};
|
|
1480
|
+
this.handleSummaryDelete = () => {
|
|
1481
|
+
const summaryKey = getThreadSummaryKey(this.summary);
|
|
1482
|
+
if (summaryKey) {
|
|
1483
|
+
this.dismissedSummaryKey = summaryKey;
|
|
1484
|
+
}
|
|
1485
|
+
this.isSummaryCollapsed = false;
|
|
1486
|
+
this.isReplyOpen = false;
|
|
1487
|
+
this.replyDraft = "";
|
|
1488
|
+
this.replyError = null;
|
|
1489
|
+
this.removeSummaryElements();
|
|
1490
|
+
};
|
|
1491
|
+
this.handleSummaryCollapseToggle = () => {
|
|
1492
|
+
this.isSummaryCollapsed = !this.isSummaryCollapsed;
|
|
1493
|
+
this.isSummaryExpanded = false;
|
|
1494
|
+
this.isReplyOpen = false;
|
|
1495
|
+
this.replyError = null;
|
|
1496
|
+
this.render();
|
|
1497
|
+
};
|
|
1498
|
+
this.handleSummaryExpandToggle = () => {
|
|
1499
|
+
this.isSummaryExpanded = !this.isSummaryExpanded;
|
|
1500
|
+
this.render();
|
|
1501
|
+
};
|
|
1502
|
+
this.handleReplyOpen = () => {
|
|
1503
|
+
this.isReplyOpen = true;
|
|
1504
|
+
this.replyError = null;
|
|
1505
|
+
this.render();
|
|
1506
|
+
};
|
|
1507
|
+
this.handleReplyInput = (event) => {
|
|
1508
|
+
const target = event.currentTarget;
|
|
1509
|
+
if (target instanceof HTMLInputElement) {
|
|
1510
|
+
this.replyDraft = target.value;
|
|
1511
|
+
this.replyError = null;
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
this.handleReplySubmit = (event) => {
|
|
1515
|
+
event.preventDefault();
|
|
1516
|
+
void this.submitReply();
|
|
1517
|
+
};
|
|
1518
|
+
this.handleReplyKeyDown = (event) => {
|
|
1519
|
+
if (event.key !== "Escape") {
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
event.preventDefault();
|
|
1523
|
+
this.isReplyOpen = false;
|
|
1524
|
+
this.replyError = null;
|
|
1525
|
+
this.render();
|
|
1526
|
+
};
|
|
1527
|
+
this.handlePointerDown = (event) => {
|
|
1528
|
+
var _a2, _b2;
|
|
1529
|
+
if (event.button !== 0 || event.ctrlKey) {
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
this.closeContextMenu();
|
|
1533
|
+
if (!((_a2 = this.options) == null ? void 0 : _a2.position.draggable)) {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
event.preventDefault();
|
|
1537
|
+
const rect = (_b2 = this.petElement) == null ? void 0 : _b2.getBoundingClientRect();
|
|
1538
|
+
if (!rect) {
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const nextPosition = {
|
|
1542
|
+
x: rect.left,
|
|
1543
|
+
y: rect.top
|
|
1544
|
+
};
|
|
1545
|
+
this.dragOffset = {
|
|
1546
|
+
x: event.clientX - rect.left,
|
|
1547
|
+
y: event.clientY - rect.top
|
|
1548
|
+
};
|
|
1549
|
+
this.lastDragPosition = nextPosition;
|
|
1550
|
+
this.lastDragClientX = event.clientX;
|
|
1551
|
+
this.dragAnimation = null;
|
|
1552
|
+
this.movedDuringDrag = false;
|
|
1553
|
+
this.dragPosition = nextPosition;
|
|
1554
|
+
this.isDragging = true;
|
|
1555
|
+
this.clearRestingDelayTimer();
|
|
1556
|
+
this.isHovering = true;
|
|
1557
|
+
this.installDragListeners();
|
|
1558
|
+
this.rescheduleAnimation();
|
|
1559
|
+
};
|
|
1560
|
+
this.handlePointerMove = (event) => {
|
|
1561
|
+
const nextPosition = this.getNextDragPosition(event);
|
|
1562
|
+
const last = this.lastDragPosition;
|
|
1563
|
+
if (last && (Math.abs(last.x - nextPosition.x) > DRAG_DIRECTION_THRESHOLD_PX || Math.abs(last.y - nextPosition.y) > DRAG_DIRECTION_THRESHOLD_PX)) {
|
|
1564
|
+
this.movedDuringDrag = true;
|
|
1565
|
+
}
|
|
1566
|
+
if (this.lastDragClientX !== null) {
|
|
1567
|
+
const deltaX = event.clientX - this.lastDragClientX;
|
|
1568
|
+
if (deltaX > DRAG_DIRECTION_THRESHOLD_PX) {
|
|
1569
|
+
this.dragAnimation = "running-right";
|
|
1570
|
+
} else if (deltaX < -DRAG_DIRECTION_THRESHOLD_PX) {
|
|
1571
|
+
this.dragAnimation = "running-left";
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
this.lastDragClientX = event.clientX;
|
|
1575
|
+
this.lastDragPosition = nextPosition;
|
|
1576
|
+
this.dragPosition = nextPosition;
|
|
1577
|
+
this.render();
|
|
1578
|
+
};
|
|
1579
|
+
this.handlePointerUp = (event) => {
|
|
1580
|
+
const finalPosition = this.lastDragPosition ?? this.getNextDragPosition(event);
|
|
1581
|
+
this.isDragging = false;
|
|
1582
|
+
this.dragPosition = null;
|
|
1583
|
+
this.dragAnimation = null;
|
|
1584
|
+
this.lastDragClientX = null;
|
|
1585
|
+
this.removeDragListeners();
|
|
1586
|
+
this.persistPosition(finalPosition);
|
|
1587
|
+
if (event.pointerType === "mouse" && this.isPointerOverPet(event)) {
|
|
1588
|
+
this.isHovering = true;
|
|
1589
|
+
this.rescheduleAnimation();
|
|
1590
|
+
} else {
|
|
1591
|
+
this.enterRestingAfterDelay();
|
|
1592
|
+
this.rescheduleAnimation();
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
this.handleClick = () => {
|
|
1596
|
+
var _a2;
|
|
1597
|
+
if (this.movedDuringDrag) {
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
(_a2 = this.onActivate) == null ? void 0 : _a2.call(this);
|
|
1601
|
+
if (this.prefersReducedMotion) {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
this.transient = { name: "waving" };
|
|
1605
|
+
this.render();
|
|
1606
|
+
};
|
|
1607
|
+
this.root = root;
|
|
1608
|
+
this.onActivate = options == null ? void 0 : options.onActivate;
|
|
1609
|
+
this.onClose = options == null ? void 0 : options.onClose;
|
|
1610
|
+
this.onReply = options == null ? void 0 : options.onReply;
|
|
1611
|
+
this.onThreadSummaryActivate = options == null ? void 0 : options.onThreadSummaryActivate;
|
|
1612
|
+
this.connect();
|
|
1613
|
+
}
|
|
1614
|
+
connect() {
|
|
1615
|
+
if (this.connected) {
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
this.connected = true;
|
|
1619
|
+
this.installViewportListeners();
|
|
1620
|
+
this.installReducedMotionListener();
|
|
1621
|
+
this.render();
|
|
1622
|
+
}
|
|
1623
|
+
setOptions(pet, theme) {
|
|
1624
|
+
this.closeContextMenu();
|
|
1625
|
+
const nextOptions = normalizePetOptions(pet);
|
|
1626
|
+
this.options = nextOptions;
|
|
1627
|
+
this.theme = theme ?? null;
|
|
1628
|
+
if (!nextOptions) {
|
|
1629
|
+
this.isDragging = false;
|
|
1630
|
+
this.isHovering = false;
|
|
1631
|
+
this.position = null;
|
|
1632
|
+
this.dragPosition = null;
|
|
1633
|
+
this.dragAnimation = null;
|
|
1634
|
+
this.lastDragPosition = null;
|
|
1635
|
+
this.lastDragClientX = null;
|
|
1636
|
+
this.transient = null;
|
|
1637
|
+
this.resolved = null;
|
|
1638
|
+
this.clearRestingDelayTimer();
|
|
1639
|
+
this.removeDragListeners();
|
|
1640
|
+
this.removeOverlay();
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
this.position = readPersistedPosition(
|
|
1644
|
+
DEFAULT_PET_STORAGE_KEY,
|
|
1645
|
+
nextOptions.position.persist
|
|
1646
|
+
);
|
|
1647
|
+
if (nextOptions.behavior === "auto" && !this.prefersReducedMotion) {
|
|
1648
|
+
this.transient = { name: "waving" };
|
|
1649
|
+
}
|
|
1650
|
+
this.resolveCharacter();
|
|
1651
|
+
this.render();
|
|
1652
|
+
}
|
|
1653
|
+
setState(state) {
|
|
1654
|
+
var _a2;
|
|
1655
|
+
const previous = this.lastAutoState;
|
|
1656
|
+
this.lastAutoState = state;
|
|
1657
|
+
this.currentState = state;
|
|
1658
|
+
if (((_a2 = this.options) == null ? void 0 : _a2.behavior) === "auto" && !this.prefersReducedMotion && state === "idle" && (previous === "running" || previous === "review") && !this.transient) {
|
|
1659
|
+
this.transient = { name: "jumping" };
|
|
1660
|
+
} else if (state !== "idle") {
|
|
1661
|
+
this.transient = null;
|
|
1662
|
+
}
|
|
1663
|
+
this.render();
|
|
1664
|
+
}
|
|
1665
|
+
setLocale(locale) {
|
|
1666
|
+
const nextLocale = resolveCopyLocale(locale);
|
|
1667
|
+
if (nextLocale === this.copyLocale) {
|
|
1668
|
+
return;
|
|
1669
|
+
}
|
|
1670
|
+
this.copyLocale = nextLocale;
|
|
1671
|
+
this.copy = PET_OVERLAY_COPY[nextLocale];
|
|
1672
|
+
this.summaryRenderKey = null;
|
|
1673
|
+
this.closeContextMenu();
|
|
1674
|
+
this.render();
|
|
1675
|
+
}
|
|
1676
|
+
setThreadSummary(summary) {
|
|
1677
|
+
const previousKey = getThreadSummaryInteractionKey(this.summary);
|
|
1678
|
+
const nextKey = getThreadSummaryInteractionKey(summary);
|
|
1679
|
+
this.summary = summary;
|
|
1680
|
+
if (!summary) {
|
|
1681
|
+
this.isSummaryCollapsed = false;
|
|
1682
|
+
this.isSummaryExpanded = false;
|
|
1683
|
+
this.isSummaryHovering = false;
|
|
1684
|
+
this.isReplyOpen = false;
|
|
1685
|
+
this.isReplySubmitting = false;
|
|
1686
|
+
this.replyError = null;
|
|
1687
|
+
this.replyDraft = "";
|
|
1688
|
+
this.summaryRenderKey = null;
|
|
1689
|
+
this.removeSummaryElements();
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
if (previousKey !== nextKey) {
|
|
1693
|
+
this.isSummaryCollapsed = false;
|
|
1694
|
+
this.isSummaryExpanded = false;
|
|
1695
|
+
this.isSummaryHovering = false;
|
|
1696
|
+
this.isReplyOpen = false;
|
|
1697
|
+
this.isReplySubmitting = false;
|
|
1698
|
+
this.replyError = null;
|
|
1699
|
+
this.replyDraft = "";
|
|
1700
|
+
}
|
|
1701
|
+
this.render();
|
|
1702
|
+
}
|
|
1703
|
+
setThreadSummaryStatus(status) {
|
|
1704
|
+
if (!this.summary || this.summary.status === status) {
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
this.summary = { ...this.summary, status };
|
|
1708
|
+
this.render();
|
|
1709
|
+
}
|
|
1710
|
+
destroy() {
|
|
1711
|
+
var _a2, _b2, _c2, _d;
|
|
1712
|
+
if (!this.connected) {
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
this.connected = false;
|
|
1716
|
+
this.clearRestingDelayTimer();
|
|
1717
|
+
this.clearTimers();
|
|
1718
|
+
this.removeDragListeners();
|
|
1719
|
+
this.removeOverlay();
|
|
1720
|
+
window.removeEventListener("resize", this.handleViewportChange);
|
|
1721
|
+
(_a2 = window.visualViewport) == null ? void 0 : _a2.removeEventListener(
|
|
1722
|
+
"resize",
|
|
1723
|
+
this.handleViewportChange
|
|
1724
|
+
);
|
|
1725
|
+
(_b2 = window.visualViewport) == null ? void 0 : _b2.removeEventListener(
|
|
1726
|
+
"scroll",
|
|
1727
|
+
this.handleViewportChange
|
|
1728
|
+
);
|
|
1729
|
+
(_d = (_c2 = this.mediaQuery) == null ? void 0 : _c2.removeEventListener) == null ? void 0 : _d.call(
|
|
1730
|
+
_c2,
|
|
1731
|
+
"change",
|
|
1732
|
+
this.handleReducedMotionChange
|
|
1733
|
+
);
|
|
1734
|
+
this.mediaQuery = null;
|
|
1735
|
+
}
|
|
1736
|
+
installViewportListeners() {
|
|
1737
|
+
var _a2, _b2;
|
|
1738
|
+
window.addEventListener("resize", this.handleViewportChange);
|
|
1739
|
+
(_a2 = window.visualViewport) == null ? void 0 : _a2.addEventListener(
|
|
1740
|
+
"resize",
|
|
1741
|
+
this.handleViewportChange
|
|
1742
|
+
);
|
|
1743
|
+
(_b2 = window.visualViewport) == null ? void 0 : _b2.addEventListener(
|
|
1744
|
+
"scroll",
|
|
1745
|
+
this.handleViewportChange
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
installReducedMotionListener() {
|
|
1749
|
+
var _a2, _b2;
|
|
1750
|
+
if (!window.matchMedia) {
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
this.mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
1754
|
+
this.prefersReducedMotion = this.mediaQuery.matches;
|
|
1755
|
+
(_b2 = (_a2 = this.mediaQuery).addEventListener) == null ? void 0 : _b2.call(
|
|
1756
|
+
_a2,
|
|
1757
|
+
"change",
|
|
1758
|
+
this.handleReducedMotionChange
|
|
1759
|
+
);
|
|
1760
|
+
}
|
|
1761
|
+
resolveCharacter() {
|
|
1762
|
+
if (!this.options) {
|
|
1763
|
+
this.resolved = null;
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
const character = this.options.character;
|
|
1767
|
+
this.resolved = resolvePetCharacter(character);
|
|
1768
|
+
}
|
|
1769
|
+
ensureOverlay() {
|
|
1770
|
+
if (this.overlayElement && this.petElement) {
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
const overlay = document.createElement("div");
|
|
1774
|
+
overlay.setAttribute("data-chatkit-host-pet-layer", "");
|
|
1775
|
+
overlay.style.position = "fixed";
|
|
1776
|
+
overlay.style.inset = "0";
|
|
1777
|
+
overlay.style.pointerEvents = "none";
|
|
1778
|
+
overlay.style.overflow = "visible";
|
|
1779
|
+
const style = document.createElement("style");
|
|
1780
|
+
style.textContent = `
|
|
1781
|
+
@keyframes chatkit-pet-summary-spin {
|
|
1782
|
+
to { transform: rotate(360deg); }
|
|
1783
|
+
}
|
|
1784
|
+
`;
|
|
1785
|
+
const pet = document.createElement("div");
|
|
1786
|
+
pet.setAttribute("data-chatkit-host-pet", "");
|
|
1787
|
+
pet.style.position = "absolute";
|
|
1788
|
+
pet.style.top = "0";
|
|
1789
|
+
pet.style.left = "0";
|
|
1790
|
+
pet.style.pointerEvents = "auto";
|
|
1791
|
+
pet.style.touchAction = "none";
|
|
1792
|
+
pet.style.userSelect = "none";
|
|
1793
|
+
pet.style.willChange = "transform";
|
|
1794
|
+
pet.addEventListener("pointerenter", this.handlePointerEnter);
|
|
1795
|
+
pet.addEventListener("pointerleave", this.handlePointerLeave);
|
|
1796
|
+
pet.addEventListener("pointerdown", this.handlePointerDown);
|
|
1797
|
+
pet.addEventListener("contextmenu", this.handleContextMenu);
|
|
1798
|
+
pet.addEventListener("click", this.handleClick);
|
|
1799
|
+
overlay.append(style, pet);
|
|
1800
|
+
this.root.append(overlay);
|
|
1801
|
+
this.overlayElement = overlay;
|
|
1802
|
+
this.petElement = pet;
|
|
1803
|
+
}
|
|
1804
|
+
removeOverlay() {
|
|
1805
|
+
var _a2;
|
|
1806
|
+
this.clearRestingDelayTimer();
|
|
1807
|
+
this.clearTimers();
|
|
1808
|
+
this.closeContextMenu();
|
|
1809
|
+
if (this.petElement) {
|
|
1810
|
+
this.petElement.removeEventListener(
|
|
1811
|
+
"pointerenter",
|
|
1812
|
+
this.handlePointerEnter
|
|
1813
|
+
);
|
|
1814
|
+
this.petElement.removeEventListener(
|
|
1815
|
+
"pointerleave",
|
|
1816
|
+
this.handlePointerLeave
|
|
1817
|
+
);
|
|
1818
|
+
this.petElement.removeEventListener(
|
|
1819
|
+
"pointerdown",
|
|
1820
|
+
this.handlePointerDown
|
|
1821
|
+
);
|
|
1822
|
+
this.petElement.removeEventListener(
|
|
1823
|
+
"contextmenu",
|
|
1824
|
+
this.handleContextMenu
|
|
1825
|
+
);
|
|
1826
|
+
this.petElement.removeEventListener("click", this.handleClick);
|
|
1827
|
+
}
|
|
1828
|
+
this.isHovering = false;
|
|
1829
|
+
this.removeSummaryElements();
|
|
1830
|
+
(_a2 = this.overlayElement) == null ? void 0 : _a2.remove();
|
|
1831
|
+
this.overlayElement = null;
|
|
1832
|
+
this.petElement = null;
|
|
1833
|
+
this.mediaElement = null;
|
|
1834
|
+
}
|
|
1835
|
+
removeSummaryElements() {
|
|
1836
|
+
var _a2, _b2;
|
|
1837
|
+
(_a2 = this.summaryElement) == null ? void 0 : _a2.remove();
|
|
1838
|
+
(_b2 = this.summaryToggleElement) == null ? void 0 : _b2.remove();
|
|
1839
|
+
this.summaryElement = null;
|
|
1840
|
+
this.summaryToggleElement = null;
|
|
1841
|
+
this.replyInputElement = null;
|
|
1842
|
+
this.summaryRenderKey = null;
|
|
1843
|
+
}
|
|
1844
|
+
getSize() {
|
|
1845
|
+
if (!this.options || !this.resolved) {
|
|
1846
|
+
return { width: 0, height: 0 };
|
|
1847
|
+
}
|
|
1848
|
+
const scale = getRenderScale(this.options.position.scale);
|
|
1849
|
+
const baseSize = {
|
|
1850
|
+
width: this.resolved.atlas.cellWidth,
|
|
1851
|
+
height: this.resolved.atlas.cellHeight
|
|
1852
|
+
};
|
|
1853
|
+
return {
|
|
1854
|
+
width: baseSize.width * scale,
|
|
1855
|
+
height: baseSize.height * scale
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
getCurrentPosition(size) {
|
|
1859
|
+
const options = this.options;
|
|
1860
|
+
if (!options) {
|
|
1861
|
+
return { x: 0, y: 0 };
|
|
1862
|
+
}
|
|
1863
|
+
const viewport = getViewportSize();
|
|
1864
|
+
const padding = normalizeBoundsPadding(options.position.boundsPadding);
|
|
1865
|
+
const pin = options.position.pin === void 0 ? "bottom-right" : options.position.pin;
|
|
1866
|
+
const pinnedPosition = pin ? getPinnedPetPosition(pin, size, viewport, padding) : null;
|
|
1867
|
+
return clampPetPosition(
|
|
1868
|
+
this.dragPosition ?? this.position ?? pinnedPosition ?? { x: padding.left, y: padding.top },
|
|
1869
|
+
size,
|
|
1870
|
+
viewport,
|
|
1871
|
+
padding
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
persistPosition(nextPosition) {
|
|
1875
|
+
if (!this.options) {
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
const size = this.getSize();
|
|
1879
|
+
const clamped = clampPetPosition(
|
|
1880
|
+
nextPosition,
|
|
1881
|
+
size,
|
|
1882
|
+
getViewportSize(),
|
|
1883
|
+
normalizeBoundsPadding(this.options.position.boundsPadding)
|
|
1884
|
+
);
|
|
1885
|
+
this.position = clamped;
|
|
1886
|
+
writePersistedPosition(
|
|
1887
|
+
DEFAULT_PET_STORAGE_KEY,
|
|
1888
|
+
this.options.position.persist,
|
|
1889
|
+
clamped
|
|
1890
|
+
);
|
|
1891
|
+
}
|
|
1892
|
+
getActiveAnimationName() {
|
|
1893
|
+
if (!this.options) {
|
|
1894
|
+
return "idle";
|
|
1895
|
+
}
|
|
1896
|
+
if (this.isDragging) {
|
|
1897
|
+
return this.dragAnimation ?? "running";
|
|
1898
|
+
}
|
|
1899
|
+
if (this.transient) {
|
|
1900
|
+
return this.transient.name;
|
|
1901
|
+
}
|
|
1902
|
+
if (this.options.behavior === "manual") {
|
|
1903
|
+
return "idle";
|
|
1904
|
+
}
|
|
1905
|
+
return this.currentState;
|
|
1906
|
+
}
|
|
1907
|
+
getActiveAnimationMode() {
|
|
1908
|
+
if (this.isDragging) {
|
|
1909
|
+
return "loop";
|
|
1910
|
+
}
|
|
1911
|
+
return this.transient ? "once" : "loop";
|
|
1912
|
+
}
|
|
1913
|
+
resetAnimationIfNeeded(name, mode) {
|
|
1914
|
+
if (this.activeAnimationName === name && this.activeAnimationMode === mode) {
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
this.clearTimers();
|
|
1918
|
+
this.activeAnimationName = name;
|
|
1919
|
+
this.activeAnimationMode = mode;
|
|
1920
|
+
this.frame = 0;
|
|
1921
|
+
this.completed = false;
|
|
1922
|
+
}
|
|
1923
|
+
render() {
|
|
1924
|
+
if (!this.options || !this.resolved) {
|
|
1925
|
+
this.clearTimers();
|
|
1926
|
+
if (this.petElement) {
|
|
1927
|
+
this.petElement.replaceChildren();
|
|
1928
|
+
}
|
|
1929
|
+
this.removeSummaryElements();
|
|
1930
|
+
this.mediaElement = null;
|
|
1931
|
+
this.activeAnimationName = null;
|
|
1932
|
+
this.activeAnimationMode = null;
|
|
1933
|
+
this.frame = 0;
|
|
1934
|
+
this.completed = false;
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
this.ensureOverlay();
|
|
1938
|
+
const overlay = this.overlayElement;
|
|
1939
|
+
const pet = this.petElement;
|
|
1940
|
+
if (!overlay || !pet) {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
const size = this.getSize();
|
|
1944
|
+
const position = this.getCurrentPosition(size);
|
|
1945
|
+
const animationName = this.getActiveAnimationName();
|
|
1946
|
+
const animationMode = this.getActiveAnimationMode();
|
|
1947
|
+
this.resetAnimationIfNeeded(animationName, animationMode);
|
|
1948
|
+
overlay.style.zIndex = String(this.options.position.zIndex);
|
|
1949
|
+
pet.style.width = `${size.width}px`;
|
|
1950
|
+
pet.style.height = `${size.height}px`;
|
|
1951
|
+
pet.style.transform = `translate3d(${position.x}px, ${position.y}px, 0)`;
|
|
1952
|
+
pet.style.cursor = this.options.position.draggable ? this.isDragging ? "grabbing" : "grab" : "default";
|
|
1953
|
+
pet.dataset.petAnimation = animationName;
|
|
1954
|
+
pet.setAttribute("aria-label", this.options.ariaLabel);
|
|
1955
|
+
pet.setAttribute("role", "img");
|
|
1956
|
+
this.renderAtlas(animationName, animationMode);
|
|
1957
|
+
this.renderThreadSummary(position, size);
|
|
1958
|
+
this.scheduleNextFrame(animationName, animationMode);
|
|
1959
|
+
}
|
|
1960
|
+
renderThreadSummary(position, size) {
|
|
1961
|
+
var _a2, _b2, _c2;
|
|
1962
|
+
const summary = this.summary;
|
|
1963
|
+
const summaryKey = getThreadSummaryKey(summary);
|
|
1964
|
+
if (!summary || !summaryKey || this.dismissedSummaryKey === summaryKey) {
|
|
1965
|
+
this.removeSummaryElements();
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
if (this.isSummaryCollapsed) {
|
|
1969
|
+
this.renderCollapsedSummary(position, size);
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1972
|
+
const nextRenderKey = [
|
|
1973
|
+
this.copyLocale,
|
|
1974
|
+
this.isSummaryExpanded ? "expanded" : "compact",
|
|
1975
|
+
this.isSummaryHovering ? "hover" : "rest",
|
|
1976
|
+
this.isReplyOpen ? "reply" : "closed",
|
|
1977
|
+
this.isReplySubmitting ? "submitting" : "ready",
|
|
1978
|
+
this.replyError ?? ""
|
|
1979
|
+
].join("|");
|
|
1980
|
+
if (!this.summaryElement || this.summaryRenderKey !== nextRenderKey) {
|
|
1981
|
+
(_a2 = this.summaryElement) == null ? void 0 : _a2.remove();
|
|
1982
|
+
(_b2 = this.summaryToggleElement) == null ? void 0 : _b2.remove();
|
|
1983
|
+
this.summaryElement = this.createSummaryBubble(summary);
|
|
1984
|
+
this.summaryToggleElement = this.createSummaryToggleButton("v");
|
|
1985
|
+
(_c2 = this.overlayElement) == null ? void 0 : _c2.append(
|
|
1986
|
+
this.summaryElement,
|
|
1987
|
+
this.summaryToggleElement
|
|
1988
|
+
);
|
|
1989
|
+
this.summaryRenderKey = nextRenderKey;
|
|
1990
|
+
if (this.isReplyOpen && !this.isReplySubmitting) {
|
|
1991
|
+
window.setTimeout(() => {
|
|
1992
|
+
var _a3;
|
|
1993
|
+
return (_a3 = this.replyInputElement) == null ? void 0 : _a3.focus();
|
|
1994
|
+
}, 0);
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
this.updateSummaryBubbleContent(summary);
|
|
1998
|
+
this.positionSummaryBubble(position, size);
|
|
1999
|
+
}
|
|
2000
|
+
renderCollapsedSummary(position, size) {
|
|
2001
|
+
var _a2, _b2;
|
|
2002
|
+
(_a2 = this.summaryElement) == null ? void 0 : _a2.remove();
|
|
2003
|
+
this.summaryElement = null;
|
|
2004
|
+
this.summaryRenderKey = null;
|
|
2005
|
+
if (!this.summaryToggleElement) {
|
|
2006
|
+
this.summaryToggleElement = this.createSummaryToggleButton("1");
|
|
2007
|
+
(_b2 = this.overlayElement) == null ? void 0 : _b2.append(this.summaryToggleElement);
|
|
2008
|
+
}
|
|
2009
|
+
this.summaryToggleElement.textContent = "1";
|
|
2010
|
+
this.positionSummaryToggleBadge(position, size);
|
|
2011
|
+
}
|
|
2012
|
+
positionSummaryToggleBadge(position, size) {
|
|
2013
|
+
const badge = this.summaryToggleElement;
|
|
2014
|
+
if (!badge) {
|
|
2015
|
+
return;
|
|
2016
|
+
}
|
|
2017
|
+
const viewport = getViewportSize();
|
|
2018
|
+
const badgeSize = getSummaryThemeMetrics(this.theme).toggleSize;
|
|
2019
|
+
const x = clampNumber(
|
|
2020
|
+
position.x + size.width - badgeSize * 0.35,
|
|
2021
|
+
PET_SUMMARY_MARGIN,
|
|
2022
|
+
viewport.width - badgeSize - PET_SUMMARY_MARGIN
|
|
2023
|
+
);
|
|
2024
|
+
const y = clampNumber(
|
|
2025
|
+
position.y - badgeSize * 0.35,
|
|
2026
|
+
PET_SUMMARY_MARGIN,
|
|
2027
|
+
viewport.height - badgeSize - PET_SUMMARY_MARGIN
|
|
2028
|
+
);
|
|
2029
|
+
badge.style.width = `${badgeSize}px`;
|
|
2030
|
+
badge.style.height = `${badgeSize}px`;
|
|
2031
|
+
badge.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
2032
|
+
badge.style.borderRadius = "999px";
|
|
2033
|
+
}
|
|
2034
|
+
positionSummaryBubble(position, size) {
|
|
2035
|
+
const bubble = this.summaryElement;
|
|
2036
|
+
const toggle = this.summaryToggleElement;
|
|
2037
|
+
if (!bubble || !toggle) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
const viewport = getViewportSize();
|
|
2041
|
+
const width = Math.min(
|
|
2042
|
+
PET_SUMMARY_WIDTH,
|
|
2043
|
+
viewport.width - PET_SUMMARY_MARGIN * 2
|
|
2044
|
+
);
|
|
2045
|
+
bubble.style.width = `${width}px`;
|
|
2046
|
+
const bubbleHeight = bubble.offsetHeight || 96;
|
|
2047
|
+
const aboveY = position.y - bubbleHeight - PET_SUMMARY_GAP;
|
|
2048
|
+
const showAbove = aboveY >= PET_SUMMARY_MARGIN;
|
|
2049
|
+
const y = showAbove ? aboveY : clampNumber(
|
|
2050
|
+
position.y + size.height + PET_SUMMARY_GAP,
|
|
2051
|
+
PET_SUMMARY_MARGIN,
|
|
2052
|
+
viewport.height - bubbleHeight - PET_SUMMARY_MARGIN
|
|
2053
|
+
);
|
|
2054
|
+
const x = clampNumber(
|
|
2055
|
+
position.x + size.width / 2 - width / 2,
|
|
2056
|
+
PET_SUMMARY_MARGIN,
|
|
2057
|
+
viewport.width - width - PET_SUMMARY_MARGIN
|
|
2058
|
+
);
|
|
2059
|
+
bubble.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
2060
|
+
this.positionSummaryToggleBadge(position, size);
|
|
2061
|
+
}
|
|
2062
|
+
createSummaryBubble(summary) {
|
|
2063
|
+
const shouldShowReplyButton = this.isSummaryHovering && !this.isReplyOpen;
|
|
2064
|
+
const metrics = getSummaryThemeMetrics(this.theme);
|
|
2065
|
+
const bubble = document.createElement("div");
|
|
2066
|
+
bubble.setAttribute("data-chatkit-pet-summary", "");
|
|
2067
|
+
bubble.addEventListener("pointerenter", this.handleSummaryPointerEnter);
|
|
2068
|
+
bubble.addEventListener("pointerleave", this.handleSummaryPointerLeave);
|
|
2069
|
+
bubble.addEventListener("click", this.handleSummaryClick);
|
|
2070
|
+
bubble.style.position = "absolute";
|
|
2071
|
+
bubble.style.top = "0";
|
|
2072
|
+
bubble.style.left = "0";
|
|
2073
|
+
bubble.style.boxSizing = "border-box";
|
|
2074
|
+
bubble.style.pointerEvents = "auto";
|
|
2075
|
+
bubble.style.padding = metrics.padding;
|
|
2076
|
+
bubble.style.border = "1px solid rgba(148, 163, 184, 0.22)";
|
|
2077
|
+
bubble.style.borderRadius = `${metrics.radius}px`;
|
|
2078
|
+
bubble.style.background = "rgba(255, 255, 255, 0.94)";
|
|
2079
|
+
bubble.style.color = "#1f2937";
|
|
2080
|
+
bubble.style.boxShadow = "0 8px 24px rgba(15, 23, 42, 0.1)";
|
|
2081
|
+
bubble.style.font = `500 ${metrics.bodySize}px/1.35 ${metrics.fontFamily}`;
|
|
2082
|
+
bubble.style.backdropFilter = "blur(10px)";
|
|
2083
|
+
const header = document.createElement("div");
|
|
2084
|
+
header.style.display = "flex";
|
|
2085
|
+
header.style.alignItems = "center";
|
|
2086
|
+
header.style.gap = `${metrics.gap}px`;
|
|
2087
|
+
if (this.isSummaryHovering || this.isReplyOpen) {
|
|
2088
|
+
header.append(
|
|
2089
|
+
this.createSummaryActionButton(
|
|
2090
|
+
"x",
|
|
2091
|
+
this.copy.hideMessage,
|
|
2092
|
+
this.handleSummaryDelete
|
|
2093
|
+
)
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
const title = document.createElement("div");
|
|
2097
|
+
title.textContent = summary.title;
|
|
2098
|
+
title.style.minWidth = "0";
|
|
2099
|
+
title.style.flex = "1";
|
|
2100
|
+
title.style.overflow = "hidden";
|
|
2101
|
+
title.style.textOverflow = "ellipsis";
|
|
2102
|
+
title.style.whiteSpace = "nowrap";
|
|
2103
|
+
title.style.fontWeight = "700";
|
|
2104
|
+
title.style.fontSize = `${metrics.titleSize}px`;
|
|
2105
|
+
title.dataset.chatkitPetSummaryTitle = "";
|
|
2106
|
+
header.append(title);
|
|
2107
|
+
if (this.isSummaryHovering || this.isReplyOpen) {
|
|
2108
|
+
header.append(
|
|
2109
|
+
this.createSummaryActionButton(
|
|
2110
|
+
this.isSummaryExpanded ? "-" : ">",
|
|
2111
|
+
this.isSummaryExpanded ? this.copy.collapseMessage : this.copy.expandMessage,
|
|
2112
|
+
this.handleSummaryExpandToggle
|
|
2113
|
+
)
|
|
2114
|
+
);
|
|
2115
|
+
} else {
|
|
2116
|
+
header.append(this.createStatusIcon(summary.status));
|
|
2117
|
+
}
|
|
2118
|
+
const message = document.createElement("div");
|
|
2119
|
+
message.textContent = summary.message;
|
|
2120
|
+
message.style.marginTop = `${metrics.marginTop}px`;
|
|
2121
|
+
message.style.fontWeight = "400";
|
|
2122
|
+
message.style.color = "#374151";
|
|
2123
|
+
message.style.overflow = "hidden";
|
|
2124
|
+
if (this.isSummaryExpanded) {
|
|
2125
|
+
message.style.maxHeight = "7em";
|
|
2126
|
+
message.style.overflowY = "auto";
|
|
2127
|
+
} else {
|
|
2128
|
+
message.style.display = "-webkit-box";
|
|
2129
|
+
message.style.setProperty("-webkit-line-clamp", "2");
|
|
2130
|
+
message.style.setProperty("-webkit-box-orient", "vertical");
|
|
2131
|
+
}
|
|
2132
|
+
message.dataset.chatkitPetSummaryMessage = "";
|
|
2133
|
+
bubble.append(header, message);
|
|
2134
|
+
if (shouldShowReplyButton) {
|
|
2135
|
+
const reply = this.createTextButton(
|
|
2136
|
+
this.copy.replyButton,
|
|
2137
|
+
this.handleReplyOpen
|
|
2138
|
+
);
|
|
2139
|
+
reply.style.position = "absolute";
|
|
2140
|
+
reply.style.right = "14px";
|
|
2141
|
+
reply.style.bottom = "10px";
|
|
2142
|
+
bubble.append(reply);
|
|
2143
|
+
}
|
|
2144
|
+
if (this.isReplyOpen) {
|
|
2145
|
+
bubble.append(this.createReplyForm());
|
|
2146
|
+
}
|
|
2147
|
+
return bubble;
|
|
2148
|
+
}
|
|
2149
|
+
updateSummaryBubbleContent(summary) {
|
|
2150
|
+
var _a2, _b2, _c2;
|
|
2151
|
+
const title = (_a2 = this.summaryElement) == null ? void 0 : _a2.querySelector(
|
|
2152
|
+
"[data-chatkit-pet-summary-title]"
|
|
2153
|
+
);
|
|
2154
|
+
if (title && title.textContent !== summary.title) {
|
|
2155
|
+
title.textContent = summary.title;
|
|
2156
|
+
}
|
|
2157
|
+
const message = (_b2 = this.summaryElement) == null ? void 0 : _b2.querySelector(
|
|
2158
|
+
"[data-chatkit-pet-summary-message]"
|
|
2159
|
+
);
|
|
2160
|
+
if (message && message.textContent !== summary.message) {
|
|
2161
|
+
message.textContent = summary.message;
|
|
2162
|
+
}
|
|
2163
|
+
const statusIcon = (_c2 = this.summaryElement) == null ? void 0 : _c2.querySelector(
|
|
2164
|
+
"[data-chatkit-pet-summary-status]"
|
|
2165
|
+
);
|
|
2166
|
+
if (statusIcon && statusIcon.dataset.chatkitPetSummaryStatus !== summary.status) {
|
|
2167
|
+
const nextIcon = this.createStatusIcon(summary.status);
|
|
2168
|
+
statusIcon.replaceWith(nextIcon);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
createSummaryToggleButton(label) {
|
|
2172
|
+
const metrics = getSummaryThemeMetrics(this.theme);
|
|
2173
|
+
const button = document.createElement("button");
|
|
2174
|
+
button.type = "button";
|
|
2175
|
+
button.textContent = label;
|
|
2176
|
+
button.title = label === "1" ? this.copy.restoreMessage : this.copy.collapseMessage;
|
|
2177
|
+
button.addEventListener("click", stopEventPropagation);
|
|
2178
|
+
button.addEventListener("click", this.handleSummaryCollapseToggle);
|
|
2179
|
+
button.style.position = "absolute";
|
|
2180
|
+
button.style.top = "0";
|
|
2181
|
+
button.style.left = "0";
|
|
2182
|
+
button.style.pointerEvents = "auto";
|
|
2183
|
+
button.style.border = "1px solid rgba(148, 163, 184, 0.28)";
|
|
2184
|
+
button.style.background = "rgba(248, 250, 252, 0.94)";
|
|
2185
|
+
button.style.color = "#475569";
|
|
2186
|
+
button.style.boxShadow = "0 6px 18px rgba(15, 23, 42, 0.1)";
|
|
2187
|
+
button.style.cursor = "pointer";
|
|
2188
|
+
button.style.font = `600 ${metrics.titleSize}px/1 ${metrics.fontFamily}`;
|
|
2189
|
+
button.style.display = "flex";
|
|
2190
|
+
button.style.alignItems = "center";
|
|
2191
|
+
button.style.justifyContent = "center";
|
|
2192
|
+
return button;
|
|
2193
|
+
}
|
|
2194
|
+
createStatusIcon(status) {
|
|
2195
|
+
const metrics = getSummaryThemeMetrics(this.theme);
|
|
2196
|
+
const iconSize = metrics.iconSize;
|
|
2197
|
+
const icon = document.createElement("span");
|
|
2198
|
+
icon.setAttribute("aria-hidden", "true");
|
|
2199
|
+
icon.dataset.chatkitPetSummaryStatus = status;
|
|
2200
|
+
icon.style.display = "inline-flex";
|
|
2201
|
+
icon.style.width = `${iconSize}px`;
|
|
2202
|
+
icon.style.height = `${iconSize}px`;
|
|
2203
|
+
icon.style.alignItems = "center";
|
|
2204
|
+
icon.style.justifyContent = "center";
|
|
2205
|
+
icon.style.flex = "0 0 auto";
|
|
2206
|
+
if (status === "running") {
|
|
2207
|
+
icon.style.border = "2px solid rgba(71, 85, 105, 0.32)";
|
|
2208
|
+
icon.style.borderTopColor = "#64748b";
|
|
2209
|
+
icon.style.borderRadius = "999px";
|
|
2210
|
+
icon.style.animation = "chatkit-pet-summary-spin 900ms linear infinite";
|
|
2211
|
+
return icon;
|
|
2212
|
+
}
|
|
2213
|
+
icon.style.borderRadius = "999px";
|
|
2214
|
+
icon.style.fontSize = `${Math.max(10, iconSize - 4)}px`;
|
|
2215
|
+
icon.style.fontWeight = "700";
|
|
2216
|
+
if (status === "failed") {
|
|
2217
|
+
icon.textContent = "!";
|
|
2218
|
+
icon.style.background = "#fee2e2";
|
|
2219
|
+
icon.style.color = "#b91c1c";
|
|
2220
|
+
return icon;
|
|
2221
|
+
}
|
|
2222
|
+
icon.textContent = "";
|
|
2223
|
+
icon.style.border = "2px solid #22c55e";
|
|
2224
|
+
icon.style.position = "relative";
|
|
2225
|
+
const check = document.createElement("span");
|
|
2226
|
+
check.style.width = `${Math.round(iconSize * 0.44)}px`;
|
|
2227
|
+
check.style.height = `${Math.round(iconSize * 0.25)}px`;
|
|
2228
|
+
check.style.borderLeft = "2px solid #22c55e";
|
|
2229
|
+
check.style.borderBottom = "2px solid #22c55e";
|
|
2230
|
+
check.style.transform = "rotate(-45deg) translate(1px, -1px)";
|
|
2231
|
+
icon.append(check);
|
|
2232
|
+
return icon;
|
|
2233
|
+
}
|
|
2234
|
+
createSummaryActionButton(label, title, onClick) {
|
|
2235
|
+
const metrics = getSummaryThemeMetrics(this.theme);
|
|
2236
|
+
const button = document.createElement("button");
|
|
2237
|
+
button.type = "button";
|
|
2238
|
+
button.textContent = label;
|
|
2239
|
+
button.title = title;
|
|
2240
|
+
button.addEventListener("click", (event) => {
|
|
2241
|
+
event.preventDefault();
|
|
2242
|
+
event.stopPropagation();
|
|
2243
|
+
onClick();
|
|
2244
|
+
});
|
|
2245
|
+
button.style.width = `${metrics.actionSize}px`;
|
|
2246
|
+
button.style.height = `${metrics.actionSize}px`;
|
|
2247
|
+
button.style.border = "0";
|
|
2248
|
+
button.style.borderRadius = "999px";
|
|
2249
|
+
button.style.background = "rgba(241, 245, 249, 0.96)";
|
|
2250
|
+
button.style.color = "#475569";
|
|
2251
|
+
button.style.cursor = "pointer";
|
|
2252
|
+
button.style.font = `600 ${metrics.titleSize}px/1 ${metrics.fontFamily}`;
|
|
2253
|
+
return button;
|
|
2254
|
+
}
|
|
2255
|
+
createTextButton(label, onClick) {
|
|
2256
|
+
const button = document.createElement("button");
|
|
2257
|
+
button.type = "button";
|
|
2258
|
+
button.textContent = label;
|
|
2259
|
+
button.addEventListener("click", (event) => {
|
|
2260
|
+
event.preventDefault();
|
|
2261
|
+
event.stopPropagation();
|
|
2262
|
+
onClick();
|
|
2263
|
+
});
|
|
2264
|
+
button.style.border = "1px solid rgba(148, 163, 184, 0.28)";
|
|
2265
|
+
button.style.borderRadius = "999px";
|
|
2266
|
+
button.style.background = "rgba(248, 250, 252, 0.95)";
|
|
2267
|
+
button.style.color = "#334155";
|
|
2268
|
+
button.style.cursor = "pointer";
|
|
2269
|
+
button.style.padding = "3px 10px";
|
|
2270
|
+
button.style.font = '600 12px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
|
2271
|
+
return button;
|
|
2272
|
+
}
|
|
2273
|
+
createReplyForm() {
|
|
2274
|
+
const form = document.createElement("form");
|
|
2275
|
+
form.addEventListener("click", stopEventPropagation);
|
|
2276
|
+
form.addEventListener("submit", this.handleReplySubmit);
|
|
2277
|
+
form.addEventListener("keydown", this.handleReplyKeyDown);
|
|
2278
|
+
form.style.display = "flex";
|
|
2279
|
+
form.style.gap = "6px";
|
|
2280
|
+
form.style.alignItems = "center";
|
|
2281
|
+
form.style.marginTop = "8px";
|
|
2282
|
+
const input = document.createElement("input");
|
|
2283
|
+
input.type = "text";
|
|
2284
|
+
input.value = this.replyDraft;
|
|
2285
|
+
input.disabled = this.isReplySubmitting;
|
|
2286
|
+
input.placeholder = this.copy.replyPlaceholder;
|
|
2287
|
+
input.addEventListener("input", this.handleReplyInput);
|
|
2288
|
+
input.style.minWidth = "0";
|
|
2289
|
+
input.style.flex = "1";
|
|
2290
|
+
input.style.border = "1px solid rgba(148, 163, 184, 0.35)";
|
|
2291
|
+
input.style.borderRadius = "999px";
|
|
2292
|
+
input.style.padding = "6px 10px";
|
|
2293
|
+
input.style.font = '400 13px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
|
2294
|
+
this.replyInputElement = input;
|
|
2295
|
+
const send = document.createElement("button");
|
|
2296
|
+
send.type = "submit";
|
|
2297
|
+
send.textContent = this.isReplySubmitting ? this.copy.sendingButton : this.copy.sendButton;
|
|
2298
|
+
send.disabled = this.isReplySubmitting;
|
|
2299
|
+
send.style.border = "0";
|
|
2300
|
+
send.style.borderRadius = "999px";
|
|
2301
|
+
send.style.background = "#22c55e";
|
|
2302
|
+
send.style.color = "#052e16";
|
|
2303
|
+
send.style.cursor = this.isReplySubmitting ? "default" : "pointer";
|
|
2304
|
+
send.style.padding = "6px 10px";
|
|
2305
|
+
send.style.font = '700 12px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
|
2306
|
+
form.append(input, send);
|
|
2307
|
+
if (this.replyError) {
|
|
2308
|
+
const error = document.createElement("div");
|
|
2309
|
+
error.textContent = this.copy.sendFailed;
|
|
2310
|
+
error.style.flexBasis = "100%";
|
|
2311
|
+
error.style.color = "#b91c1c";
|
|
2312
|
+
error.style.fontSize = "12px";
|
|
2313
|
+
form.style.flexWrap = "wrap";
|
|
2314
|
+
form.append(error);
|
|
2315
|
+
}
|
|
2316
|
+
return form;
|
|
2317
|
+
}
|
|
2318
|
+
createContextMenu() {
|
|
2319
|
+
const menu = document.createElement("div");
|
|
2320
|
+
menu.setAttribute("data-chatkit-pet-context-menu", "");
|
|
2321
|
+
menu.setAttribute("role", "menu");
|
|
2322
|
+
menu.addEventListener("contextmenu", this.handleContextMenuEvent);
|
|
2323
|
+
menu.addEventListener("pointerdown", stopEventPropagation);
|
|
2324
|
+
menu.addEventListener("click", stopEventPropagation);
|
|
2325
|
+
menu.style.position = "absolute";
|
|
2326
|
+
menu.style.top = "0";
|
|
2327
|
+
menu.style.left = "0";
|
|
2328
|
+
menu.style.boxSizing = "border-box";
|
|
2329
|
+
menu.style.minWidth = "132px";
|
|
2330
|
+
menu.style.padding = "4px";
|
|
2331
|
+
menu.style.pointerEvents = "auto";
|
|
2332
|
+
menu.style.border = "1px solid rgba(148, 163, 184, 0.28)";
|
|
2333
|
+
menu.style.borderRadius = "10px";
|
|
2334
|
+
menu.style.background = "rgba(255, 255, 255, 0.96)";
|
|
2335
|
+
menu.style.color = "#1f2937";
|
|
2336
|
+
menu.style.boxShadow = "0 12px 28px rgba(15, 23, 42, 0.16)";
|
|
2337
|
+
menu.style.font = '500 13px/1.3 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
|
|
2338
|
+
menu.style.backdropFilter = "blur(10px)";
|
|
2339
|
+
const closeItem = document.createElement("button");
|
|
2340
|
+
closeItem.type = "button";
|
|
2341
|
+
closeItem.textContent = this.copy.closePetMenuItem;
|
|
2342
|
+
closeItem.setAttribute("role", "menuitem");
|
|
2343
|
+
closeItem.addEventListener("click", this.handleClosePetMenuItemClick);
|
|
2344
|
+
closeItem.style.display = "block";
|
|
2345
|
+
closeItem.style.width = "100%";
|
|
2346
|
+
closeItem.style.border = "0";
|
|
2347
|
+
closeItem.style.borderRadius = "7px";
|
|
2348
|
+
closeItem.style.background = "transparent";
|
|
2349
|
+
closeItem.style.color = "inherit";
|
|
2350
|
+
closeItem.style.cursor = "pointer";
|
|
2351
|
+
closeItem.style.padding = "7px 10px";
|
|
2352
|
+
closeItem.style.textAlign = "left";
|
|
2353
|
+
closeItem.style.font = "inherit";
|
|
2354
|
+
menu.append(closeItem);
|
|
2355
|
+
return menu;
|
|
2356
|
+
}
|
|
2357
|
+
openContextMenu(position) {
|
|
2358
|
+
var _a2;
|
|
2359
|
+
const overlay = this.overlayElement;
|
|
2360
|
+
if (!overlay) {
|
|
2361
|
+
return;
|
|
2362
|
+
}
|
|
2363
|
+
this.closeContextMenu();
|
|
2364
|
+
const menu = this.createContextMenu();
|
|
2365
|
+
overlay.append(menu);
|
|
2366
|
+
this.contextMenuElement = menu;
|
|
2367
|
+
this.positionContextMenu(position);
|
|
2368
|
+
(_a2 = menu.querySelector("button")) == null ? void 0 : _a2.focus({ preventScroll: true });
|
|
2369
|
+
window.addEventListener(
|
|
2370
|
+
"pointerdown",
|
|
2371
|
+
this.handleContextMenuOutsidePointerDown,
|
|
2372
|
+
true
|
|
2373
|
+
);
|
|
2374
|
+
window.addEventListener("keydown", this.handleContextMenuKeyDown);
|
|
2375
|
+
}
|
|
2376
|
+
closeContextMenu() {
|
|
2377
|
+
var _a2;
|
|
2378
|
+
(_a2 = this.contextMenuElement) == null ? void 0 : _a2.remove();
|
|
2379
|
+
this.contextMenuElement = null;
|
|
2380
|
+
window.removeEventListener(
|
|
2381
|
+
"pointerdown",
|
|
2382
|
+
this.handleContextMenuOutsidePointerDown,
|
|
2383
|
+
true
|
|
2384
|
+
);
|
|
2385
|
+
window.removeEventListener("keydown", this.handleContextMenuKeyDown);
|
|
2386
|
+
}
|
|
2387
|
+
positionContextMenu(position) {
|
|
2388
|
+
const menu = this.contextMenuElement;
|
|
2389
|
+
if (!menu) {
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2392
|
+
const viewport = getViewportSize();
|
|
2393
|
+
const width = menu.offsetWidth || 132;
|
|
2394
|
+
const height = menu.offsetHeight || 40;
|
|
2395
|
+
const maxX = Math.max(
|
|
2396
|
+
PET_CONTEXT_MENU_MARGIN,
|
|
2397
|
+
viewport.width - width - PET_CONTEXT_MENU_MARGIN
|
|
2398
|
+
);
|
|
2399
|
+
const maxY = Math.max(
|
|
2400
|
+
PET_CONTEXT_MENU_MARGIN,
|
|
2401
|
+
viewport.height - height - PET_CONTEXT_MENU_MARGIN
|
|
2402
|
+
);
|
|
2403
|
+
const x = clampNumber(position.x, PET_CONTEXT_MENU_MARGIN, maxX);
|
|
2404
|
+
const y = clampNumber(position.y, PET_CONTEXT_MENU_MARGIN, maxY);
|
|
2405
|
+
menu.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
2406
|
+
}
|
|
2407
|
+
renderAtlas(animationName, animationMode) {
|
|
2408
|
+
var _a2;
|
|
2409
|
+
if (!this.petElement || ((_a2 = this.resolved) == null ? void 0 : _a2.kind) !== "atlas" || !this.options) {
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
if (!(this.mediaElement instanceof HTMLDivElement)) {
|
|
2413
|
+
const frame = document.createElement("div");
|
|
2414
|
+
frame.setAttribute("aria-hidden", "true");
|
|
2415
|
+
this.petElement.replaceChildren(frame);
|
|
2416
|
+
this.mediaElement = frame;
|
|
2417
|
+
}
|
|
2418
|
+
const frameElement = this.mediaElement;
|
|
2419
|
+
const atlas = this.resolved.atlas;
|
|
2420
|
+
const definition = atlas.animations[animationName] ?? atlas.animations.idle;
|
|
2421
|
+
const safeFrame = animationMode === "once" && this.completed ? Math.max(0, definition.frames - 1) : Math.min(this.frame, Math.max(0, definition.frames - 1));
|
|
2422
|
+
const scale = getRenderScale(this.options.position.scale);
|
|
2423
|
+
const sourceWidth = atlas.cellWidth;
|
|
2424
|
+
const sourceHeight = atlas.cellHeight;
|
|
2425
|
+
const backgroundWidth = atlas.columns * sourceWidth;
|
|
2426
|
+
const backgroundHeight = atlas.rows * sourceHeight;
|
|
2427
|
+
frameElement.style.width = `${sourceWidth}px`;
|
|
2428
|
+
frameElement.style.height = `${sourceHeight}px`;
|
|
2429
|
+
frameElement.style.overflow = "hidden";
|
|
2430
|
+
frameElement.style.transform = `scale(${scale})`;
|
|
2431
|
+
frameElement.style.transformOrigin = "top left";
|
|
2432
|
+
frameElement.style.pointerEvents = "none";
|
|
2433
|
+
frameElement.style.backgroundImage = `url("${escapeCssUrl(
|
|
2434
|
+
this.resolved.src
|
|
2435
|
+
)}")`;
|
|
2436
|
+
frameElement.style.backgroundRepeat = "no-repeat";
|
|
2437
|
+
frameElement.style.backgroundSize = `${backgroundWidth}px ${backgroundHeight}px`;
|
|
2438
|
+
frameElement.style.backgroundPosition = `${-safeFrame * sourceWidth}px ${-definition.row * sourceHeight}px`;
|
|
2439
|
+
frameElement.style.imageRendering = this.options.imageRendering;
|
|
2440
|
+
frameElement.dataset.petFrame = String(safeFrame);
|
|
2441
|
+
}
|
|
2442
|
+
scheduleNextFrame(animationName, animationMode) {
|
|
2443
|
+
if (this.prefersReducedMotion || this.completed || !this.resolved) {
|
|
2444
|
+
this.clearTimers();
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
if (this.frameTimer !== null) {
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
const atlas = this.resolved.atlas;
|
|
2451
|
+
const definition = atlas.animations[animationName] ?? atlas.animations.idle;
|
|
2452
|
+
const duration = definition.frameDurations[this.frame] ?? definition.frameDurations[definition.frameDurations.length - 1] ?? 150;
|
|
2453
|
+
const baseDuration = duration * PET_FRAME_DURATION_MULTIPLIER;
|
|
2454
|
+
const effectiveDuration = this.isHovering || this.isDragging ? baseDuration : baseDuration * PET_RESTING_FRAME_DURATION_MULTIPLIER;
|
|
2455
|
+
this.frameTimer = window.setTimeout(() => {
|
|
2456
|
+
this.frameTimer = null;
|
|
2457
|
+
const nextFrame = this.frame + 1;
|
|
2458
|
+
if (nextFrame >= definition.frames) {
|
|
2459
|
+
if (animationMode === "once") {
|
|
2460
|
+
this.completed = true;
|
|
2461
|
+
this.frame = Math.max(0, definition.frames - 1);
|
|
2462
|
+
this.finishTransient();
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
this.frame = 0;
|
|
2466
|
+
this.render();
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
this.frame = nextFrame;
|
|
2470
|
+
this.render();
|
|
2471
|
+
}, effectiveDuration);
|
|
2472
|
+
}
|
|
2473
|
+
clearTimers() {
|
|
2474
|
+
if (this.frameTimer !== null) {
|
|
2475
|
+
window.clearTimeout(this.frameTimer);
|
|
2476
|
+
this.frameTimer = null;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
clearRestingDelayTimer() {
|
|
2480
|
+
if (this.restingDelayTimer !== null) {
|
|
2481
|
+
window.clearTimeout(this.restingDelayTimer);
|
|
2482
|
+
this.restingDelayTimer = null;
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
finishTransient() {
|
|
2486
|
+
this.transient = null;
|
|
2487
|
+
this.activeAnimationName = null;
|
|
2488
|
+
this.activeAnimationMode = null;
|
|
2489
|
+
this.render();
|
|
2490
|
+
}
|
|
2491
|
+
rescheduleAnimation() {
|
|
2492
|
+
this.clearTimers();
|
|
2493
|
+
this.render();
|
|
2494
|
+
}
|
|
2495
|
+
enterRestingAfterDelay() {
|
|
2496
|
+
this.clearRestingDelayTimer();
|
|
2497
|
+
this.isHovering = true;
|
|
2498
|
+
this.restingDelayTimer = window.setTimeout(() => {
|
|
2499
|
+
this.restingDelayTimer = null;
|
|
2500
|
+
if (this.isDragging) {
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
this.isHovering = false;
|
|
2504
|
+
this.rescheduleAnimation();
|
|
2505
|
+
}, PET_RESTING_DELAY_MS);
|
|
2506
|
+
}
|
|
2507
|
+
isPointOverPet(clientX, clientY) {
|
|
2508
|
+
var _a2;
|
|
2509
|
+
const rect = (_a2 = this.petElement) == null ? void 0 : _a2.getBoundingClientRect();
|
|
2510
|
+
if (!rect) {
|
|
2511
|
+
return false;
|
|
2512
|
+
}
|
|
2513
|
+
return clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
|
|
2514
|
+
}
|
|
2515
|
+
isPointerOverPet(event) {
|
|
2516
|
+
return this.isPointOverPet(event.clientX, event.clientY);
|
|
2517
|
+
}
|
|
2518
|
+
async submitReply() {
|
|
2519
|
+
var _a2;
|
|
2520
|
+
const text = this.replyDraft.trim();
|
|
2521
|
+
if (!text || this.isReplySubmitting) {
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
this.isReplySubmitting = true;
|
|
2525
|
+
this.replyError = null;
|
|
2526
|
+
this.render();
|
|
2527
|
+
try {
|
|
2528
|
+
await ((_a2 = this.onReply) == null ? void 0 : _a2.call(this, text));
|
|
2529
|
+
this.replyDraft = "";
|
|
2530
|
+
this.isReplyOpen = false;
|
|
2531
|
+
this.isSummaryHovering = false;
|
|
2532
|
+
} catch {
|
|
2533
|
+
this.replyError = "Failed to send";
|
|
2534
|
+
} finally {
|
|
2535
|
+
this.isReplySubmitting = false;
|
|
2536
|
+
this.render();
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
getNextDragPosition(event) {
|
|
2540
|
+
if (!this.options) {
|
|
2541
|
+
return { x: 0, y: 0 };
|
|
2542
|
+
}
|
|
2543
|
+
return clampPetPosition(
|
|
2544
|
+
{
|
|
2545
|
+
x: event.clientX - this.dragOffset.x,
|
|
2546
|
+
y: event.clientY - this.dragOffset.y
|
|
2547
|
+
},
|
|
2548
|
+
this.getSize(),
|
|
2549
|
+
getViewportSize(),
|
|
2550
|
+
normalizeBoundsPadding(this.options.position.boundsPadding)
|
|
2551
|
+
);
|
|
2552
|
+
}
|
|
2553
|
+
installDragListeners() {
|
|
2554
|
+
window.addEventListener("pointermove", this.handlePointerMove);
|
|
2555
|
+
window.addEventListener("pointerup", this.handlePointerUp, { once: true });
|
|
2556
|
+
window.addEventListener("pointercancel", this.handlePointerUp, {
|
|
2557
|
+
once: true
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
removeDragListeners() {
|
|
2561
|
+
window.removeEventListener("pointermove", this.handlePointerMove);
|
|
2562
|
+
window.removeEventListener("pointerup", this.handlePointerUp);
|
|
2563
|
+
window.removeEventListener("pointercancel", this.handlePointerUp);
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
function getInnerOptions(options) {
|
|
2567
|
+
return removeMethods(options);
|
|
2568
|
+
}
|
|
2569
|
+
function requireCommandCapability(value, context) {
|
|
2570
|
+
const command = String(context.name);
|
|
2571
|
+
return function(...args) {
|
|
2572
|
+
if (!this.capabilities.commands.has(command)) {
|
|
2573
|
+
throw new IntegrationError2(
|
|
2574
|
+
`ChatKit command "${String(command)}" is not available for the "${this.profile}" profile.`
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2577
|
+
return value.apply(this, args);
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
class ChatKitElementBase extends (_c = 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], _c) {
|
|
2581
|
+
constructor({ profile }) {
|
|
2582
|
+
super();
|
|
2583
|
+
__runInitializers(_init, 5, this);
|
|
2584
|
+
__privateAdd(this, _ChatKitElementBase_instances);
|
|
2585
|
+
__privateAdd(this, _opts);
|
|
2586
|
+
__privateAdd(this, _frameUrl);
|
|
2587
|
+
__privateAdd(this, _frame);
|
|
2588
|
+
__privateAdd(this, _wrapper);
|
|
2589
|
+
__privateAdd(this, _launcherCloseButton);
|
|
2590
|
+
__privateAdd(this, _launcherOpen, false);
|
|
2591
|
+
__privateAdd(this, _chatMinimizedToPet, false);
|
|
2592
|
+
__privateAdd(this, _framePetOptionsOverride);
|
|
2593
|
+
__privateAdd(this, _petClosedByContextMenu, false);
|
|
2594
|
+
__privateAdd(this, _shadow, this.attachShadow({ mode: "open" }));
|
|
2595
|
+
__privateAdd(this, _petOverlay, new PetOverlay(__privateGet(this, _shadow), {
|
|
2596
|
+
onActivate: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetActivate_fn).call(this),
|
|
2597
|
+
onClose: () => __privateMethod(this, _ChatKitElementBase_instances, handlePetClose_fn).call(this),
|
|
2598
|
+
onReply: (text) => __privateMethod(this, _ChatKitElementBase_instances, handlePetReply_fn).call(this, text),
|
|
2599
|
+
onThreadSummaryActivate: (threadId) => void __privateMethod(this, _ChatKitElementBase_instances, handlePetThreadSummaryActivate_fn).call(this, threadId)
|
|
2600
|
+
}));
|
|
2601
|
+
__privateAdd(this, _resolveLoaded);
|
|
2602
|
+
__privateAdd(this, _loaded, new Promise((resolve) => {
|
|
2603
|
+
__privateSet(this, _resolveLoaded, resolve);
|
|
2604
|
+
}));
|
|
2605
|
+
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
2606
|
+
fetch: (...args) => {
|
|
2607
|
+
var _a2;
|
|
2608
|
+
const customFetch = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
2609
|
+
return customFetch ? customFetch(...args) : fetch(...args);
|
|
2610
|
+
},
|
|
2611
|
+
target: () => {
|
|
2612
|
+
var _a2;
|
|
2613
|
+
return ((_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.contentWindow) ?? null;
|
|
2614
|
+
},
|
|
2615
|
+
targetOrigin: window.location.origin,
|
|
2616
|
+
handlers: {
|
|
2617
|
+
onFileInputClick: ({
|
|
2618
|
+
inputAttributes
|
|
2619
|
+
}) => {
|
|
2620
|
+
return new Promise((resolve) => {
|
|
2621
|
+
const input = document.createElement("input");
|
|
2622
|
+
for (const [key, value] of Object.entries(inputAttributes)) {
|
|
2623
|
+
input.setAttribute(key, String(value));
|
|
2624
|
+
}
|
|
2625
|
+
const respond = () => {
|
|
2626
|
+
resolve(Array.from(input.files || []));
|
|
2627
|
+
if (__privateGet(this, _shadow).contains(input)) {
|
|
2628
|
+
__privateGet(this, _shadow).removeChild(input);
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
input.addEventListener("cancel", respond);
|
|
2632
|
+
input.addEventListener("change", respond);
|
|
2633
|
+
__privateGet(this, _shadow).appendChild(input);
|
|
2634
|
+
input.click();
|
|
2635
|
+
});
|
|
2636
|
+
},
|
|
2637
|
+
onClientToolCall: async ({
|
|
2638
|
+
name,
|
|
2639
|
+
params,
|
|
2640
|
+
id,
|
|
2641
|
+
tool_call_id
|
|
2642
|
+
}) => {
|
|
2643
|
+
var _a2;
|
|
2644
|
+
const onClientTool = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.onClientTool;
|
|
2645
|
+
if (!onClientTool) {
|
|
2646
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
2647
|
+
`No handler for client tool calls. You'll need to add onClientTool to your ChatKit options.`
|
|
2648
|
+
));
|
|
2649
|
+
}
|
|
2650
|
+
return onClientTool({ name, params, id, tool_call_id });
|
|
2651
|
+
},
|
|
2652
|
+
onWidgetAction: async ({
|
|
2653
|
+
action,
|
|
2654
|
+
widgetItem
|
|
2655
|
+
}) => {
|
|
2656
|
+
var _a2, _b2;
|
|
2657
|
+
const onAction = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.widgets) == null ? void 0 : _b2.onAction;
|
|
2658
|
+
if (!onAction) {
|
|
2659
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
2660
|
+
`No handler for widget actions. You'll need to add widgets.onAction to your ChatKit options.`
|
|
2661
|
+
));
|
|
2662
|
+
}
|
|
2663
|
+
return onAction(action, widgetItem);
|
|
2664
|
+
},
|
|
2665
|
+
onEntitySearch: async ({ query }) => {
|
|
2666
|
+
var _a2, _b2, _c2;
|
|
2667
|
+
return ((_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onTagSearch) == null ? void 0 : _c2.call(_b2, query)) ?? [];
|
|
2668
|
+
},
|
|
2669
|
+
onEntityClick: async ({ entity }) => {
|
|
2670
|
+
var _a2, _b2, _c2;
|
|
2671
|
+
return (_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onClick) == null ? void 0 : _c2.call(_b2, entity);
|
|
2672
|
+
},
|
|
2673
|
+
onEntityPreview: async ({ entity }) => {
|
|
2674
|
+
var _a2, _b2, _c2;
|
|
2675
|
+
return ((_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onRequestPreview) == null ? void 0 : _c2.call(_b2, entity)) ?? { preview: null };
|
|
2676
|
+
},
|
|
2677
|
+
onGetClientSecret: async (currentClientSecret) => {
|
|
2678
|
+
if (!__privateGet(this, _opts) || !("getClientSecret" in __privateGet(this, _opts).api) || !__privateGet(this, _opts).api.getClientSecret) {
|
|
2679
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
2680
|
+
"Could not refresh the session because ChatKitOptions.api.getClientSecret is not configured."
|
|
2681
|
+
));
|
|
2682
|
+
}
|
|
2683
|
+
return __privateGet(this, _opts).api.getClientSecret(currentClientSecret ?? null);
|
|
2684
|
+
},
|
|
2685
|
+
onAddMetadataToRequest: ({
|
|
2686
|
+
op,
|
|
2687
|
+
params
|
|
2688
|
+
}) => {
|
|
2689
|
+
throw new IntegrationError2(
|
|
2690
|
+
"ChatKit: onAddMetadataToRequest is unimplemented."
|
|
2691
|
+
);
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
}));
|
|
2695
|
+
__privateAdd(this, _handleLauncherClose, () => {
|
|
2696
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
|
|
2697
|
+
});
|
|
2698
|
+
__privateAdd(this, _handleFrameLoad, () => {
|
|
2699
|
+
var _a2;
|
|
2700
|
+
this.dataset.loaded = "true";
|
|
2701
|
+
this.dispatchEvent(
|
|
2702
|
+
new CustomEvent("chatkit.ready", { bubbles: true, composed: true })
|
|
2703
|
+
);
|
|
2704
|
+
(_a2 = __privateGet(this, _resolveLoaded)) == null ? void 0 : _a2.call(this);
|
|
2705
|
+
});
|
|
2706
|
+
__privateAdd(this, _initialized, false);
|
|
2707
|
+
this.profile = profile;
|
|
2708
|
+
this.capabilities = getCapabilities(profile);
|
|
2709
|
+
}
|
|
2710
|
+
setProfile(profile) {
|
|
2711
|
+
this.profile = profile;
|
|
2712
|
+
this.capabilities = getCapabilities(profile);
|
|
2713
|
+
}
|
|
2714
|
+
connectedCallback() {
|
|
2715
|
+
__privateGet(this, _petOverlay).connect();
|
|
2716
|
+
const style = document.createElement("style");
|
|
2717
|
+
style.textContent = `
|
|
2718
|
+
:host {
|
|
2719
|
+
display: block;
|
|
2720
|
+
position: relative;
|
|
2721
|
+
height: 100%;
|
|
2722
|
+
width: 100%;
|
|
2723
|
+
overflow: visible;
|
|
2724
|
+
}
|
|
2725
|
+
:host([data-display-mode="pet"]) {
|
|
2726
|
+
display: contents;
|
|
2727
|
+
}
|
|
2728
|
+
:host([data-chat-minimized-to-pet="true"]) {
|
|
2729
|
+
display: contents;
|
|
2730
|
+
}
|
|
2731
|
+
.ck-iframe {
|
|
2732
|
+
border: none;
|
|
2733
|
+
position: absolute;
|
|
2734
|
+
inset: 0;
|
|
2735
|
+
width: 100%;
|
|
2736
|
+
height: 100%;
|
|
2737
|
+
overflow: hidden;
|
|
2738
|
+
color-scheme: light only;
|
|
2739
|
+
}
|
|
2740
|
+
.ck-wrapper {
|
|
2741
|
+
position: absolute;
|
|
2742
|
+
inset: 0;
|
|
2743
|
+
width: 100%;
|
|
2744
|
+
height: 100%;
|
|
2745
|
+
overflow: hidden;
|
|
2746
|
+
opacity: 0;
|
|
2747
|
+
}
|
|
2748
|
+
.ck-launcher-close {
|
|
2749
|
+
display: none;
|
|
2750
|
+
}
|
|
2751
|
+
:host([data-display-mode="pet"]) .ck-wrapper {
|
|
2752
|
+
position: fixed;
|
|
2753
|
+
inset: auto 16px 16px auto;
|
|
2754
|
+
width: min(420px, calc(100vw - 32px));
|
|
2755
|
+
height: min(720px, calc(100vh - 32px));
|
|
2756
|
+
max-height: calc(100vh - 32px);
|
|
2757
|
+
overflow: visible;
|
|
2758
|
+
border: 1px solid rgba(148, 163, 184, 0.35);
|
|
2759
|
+
border-radius: 18px;
|
|
2760
|
+
background: Canvas;
|
|
2761
|
+
box-shadow:
|
|
2762
|
+
0 24px 80px rgba(15, 23, 42, 0.22),
|
|
2763
|
+
0 0 0 1px rgba(15, 23, 42, 0.04);
|
|
2764
|
+
opacity: 0;
|
|
2765
|
+
pointer-events: none;
|
|
2766
|
+
transform: translateY(12px) scale(0.98);
|
|
2767
|
+
transition:
|
|
2768
|
+
opacity 160ms ease,
|
|
2769
|
+
transform 160ms ease;
|
|
2770
|
+
z-index: 39;
|
|
2771
|
+
}
|
|
2772
|
+
:host([data-display-mode="pet"][data-chat-open="true"]) .ck-wrapper {
|
|
2773
|
+
opacity: 1;
|
|
2774
|
+
pointer-events: auto;
|
|
2775
|
+
transform: translateY(0) scale(1);
|
|
2776
|
+
}
|
|
2777
|
+
:host([data-display-mode="pet"]) .ck-iframe {
|
|
2778
|
+
border-radius: inherit;
|
|
2779
|
+
}
|
|
2780
|
+
:host([data-display-mode="pet"]) .ck-launcher-close {
|
|
2781
|
+
display: inline-flex;
|
|
2782
|
+
position: absolute;
|
|
2783
|
+
top: -10px;
|
|
2784
|
+
right: -10px;
|
|
2785
|
+
z-index: 2;
|
|
2786
|
+
width: 28px;
|
|
2787
|
+
height: 28px;
|
|
2788
|
+
align-items: center;
|
|
2789
|
+
justify-content: center;
|
|
2790
|
+
border: 1px solid rgba(148, 163, 184, 0.45);
|
|
2791
|
+
border-radius: 999px;
|
|
2792
|
+
background: rgba(255, 255, 255, 0.96);
|
|
2793
|
+
color: #475569;
|
|
2794
|
+
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
|
|
2795
|
+
cursor: pointer;
|
|
2796
|
+
font: inherit;
|
|
2797
|
+
font-size: 0;
|
|
2798
|
+
line-height: 1;
|
|
2799
|
+
}
|
|
2800
|
+
:host([data-display-mode="pet"]) .ck-launcher-close::before,
|
|
2801
|
+
:host([data-display-mode="pet"]) .ck-launcher-close::after {
|
|
2802
|
+
content: '';
|
|
2803
|
+
position: absolute;
|
|
2804
|
+
top: 50%;
|
|
2805
|
+
left: 50%;
|
|
2806
|
+
width: 14px;
|
|
2807
|
+
height: 2px;
|
|
2808
|
+
border-radius: 999px;
|
|
2809
|
+
background: currentColor;
|
|
2810
|
+
transform: translate(-50%, -50%) rotate(45deg);
|
|
2811
|
+
}
|
|
2812
|
+
:host([data-display-mode="pet"]) .ck-launcher-close::after {
|
|
2813
|
+
transform: translate(-50%, -50%) rotate(-45deg);
|
|
2814
|
+
}
|
|
2815
|
+
:host([data-display-mode="pet"]) .ck-launcher-close:hover {
|
|
2816
|
+
background: #fff;
|
|
2817
|
+
color: #0f172a;
|
|
2818
|
+
}
|
|
2819
|
+
:host([data-color-scheme="dark"]) .ck-iframe {
|
|
2820
|
+
color-scheme: dark only;
|
|
2821
|
+
}
|
|
2822
|
+
:host([data-color-scheme="dark"][data-display-mode="pet"]) .ck-wrapper {
|
|
2823
|
+
border-color: rgba(148, 163, 184, 0.28);
|
|
2824
|
+
background: #020617;
|
|
2825
|
+
box-shadow:
|
|
2826
|
+
0 24px 80px rgba(0, 0, 0, 0.5),
|
|
2827
|
+
0 0 0 1px rgba(255, 255, 255, 0.06);
|
|
2828
|
+
}
|
|
2829
|
+
:host([data-color-scheme="dark"][data-display-mode="pet"]) .ck-launcher-close {
|
|
2830
|
+
background: rgba(15, 23, 42, 0.88);
|
|
2831
|
+
border-color: rgba(148, 163, 184, 0.32);
|
|
2832
|
+
color: #cbd5e1;
|
|
2833
|
+
}
|
|
2834
|
+
:host([data-color-scheme="dark"][data-display-mode="pet"]) .ck-launcher-close:hover {
|
|
2835
|
+
background: #1e293b;
|
|
2836
|
+
color: #f8fafc;
|
|
2837
|
+
}
|
|
2838
|
+
:host([data-loaded="true"]) .ck-wrapper {
|
|
2839
|
+
opacity: 1;
|
|
2840
|
+
}
|
|
2841
|
+
:host([data-chat-minimized-to-pet="true"]) .ck-wrapper {
|
|
2842
|
+
opacity: 0;
|
|
2843
|
+
pointer-events: none;
|
|
2844
|
+
visibility: hidden;
|
|
2845
|
+
}
|
|
2846
|
+
:host([data-display-mode="pet"]:not([data-chat-open="true"])) .ck-wrapper {
|
|
2847
|
+
opacity: 0;
|
|
2848
|
+
}
|
|
2849
|
+
@media (max-width: 520px) {
|
|
2850
|
+
:host([data-display-mode="pet"]) .ck-wrapper {
|
|
2851
|
+
inset: auto 8px 8px 8px;
|
|
2852
|
+
width: auto;
|
|
2853
|
+
height: min(680px, calc(100vh - 16px));
|
|
2854
|
+
max-height: calc(100vh - 16px);
|
|
2855
|
+
border-radius: 16px;
|
|
2856
|
+
}
|
|
2857
|
+
:host([data-display-mode="pet"]) .ck-launcher-close {
|
|
2858
|
+
top: -8px;
|
|
2859
|
+
right: 8px;
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
`;
|
|
2863
|
+
const frame = document.createElement("iframe");
|
|
2864
|
+
frame.className = "ck-iframe";
|
|
2865
|
+
frame.name = "chatkit";
|
|
2866
|
+
frame.role = "presentation";
|
|
2867
|
+
frame.tabIndex = 0;
|
|
2868
|
+
frame.setAttribute("allowtransparency", "true");
|
|
2869
|
+
frame.setAttribute("frameborder", "0");
|
|
2870
|
+
frame.setAttribute("scrolling", "no");
|
|
2871
|
+
frame.setAttribute("allow", "clipboard-read; clipboard-write");
|
|
2872
|
+
__privateSet(this, _frame, frame);
|
|
2873
|
+
const wrapper = document.createElement("div");
|
|
2874
|
+
wrapper.className = "ck-wrapper";
|
|
2875
|
+
wrapper.appendChild(frame);
|
|
2876
|
+
__privateSet(this, _wrapper, wrapper);
|
|
2877
|
+
const closeButton = document.createElement("button");
|
|
2878
|
+
closeButton.className = "ck-launcher-close";
|
|
2879
|
+
closeButton.type = "button";
|
|
2880
|
+
closeButton.setAttribute("aria-label", "Close chat");
|
|
2881
|
+
closeButton.addEventListener("click", __privateGet(this, _handleLauncherClose));
|
|
2882
|
+
wrapper.appendChild(closeButton);
|
|
2883
|
+
__privateSet(this, _launcherCloseButton, closeButton);
|
|
2884
|
+
__privateGet(this, _shadow).append(style);
|
|
2885
|
+
__privateGet(this, _messenger).on("left_header_icon_click", () => {
|
|
2886
|
+
var _a2, _b2, _c2;
|
|
2887
|
+
(_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.leftAction) == null ? void 0 : _c2.onClick();
|
|
2888
|
+
});
|
|
2889
|
+
__privateGet(this, _messenger).on("right_header_icon_click", () => {
|
|
2890
|
+
var _a2, _b2, _c2;
|
|
2891
|
+
(_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.rightAction) == null ? void 0 : _c2.onClick();
|
|
2892
|
+
});
|
|
2893
|
+
__privateGet(this, _messenger).on("public_event", ([event, data]) => {
|
|
2894
|
+
if (event === "log") {
|
|
2895
|
+
const payload = parseThreadSummaryLogPayload(data);
|
|
2896
|
+
if (payload) {
|
|
2897
|
+
__privateGet(this, _petOverlay).setThreadSummary(payload.summary);
|
|
2898
|
+
}
|
|
2899
|
+
} else if (event === "response.start") {
|
|
2900
|
+
__privateGet(this, _petOverlay).setThreadSummaryStatus("running");
|
|
2901
|
+
} else if (event === "response.end") {
|
|
2902
|
+
__privateGet(this, _petOverlay).setThreadSummaryStatus("completed");
|
|
2903
|
+
} else if (event === "response.stop") {
|
|
2904
|
+
__privateGet(this, _petOverlay).setThreadSummaryStatus("completed");
|
|
2905
|
+
}
|
|
2906
|
+
if (!this.capabilities.events.has(event)) return;
|
|
2907
|
+
if (event === "error" && "error" in data) {
|
|
2908
|
+
const error = fromPossibleFrameSafeError(data.error);
|
|
2909
|
+
this.dispatchEvent(
|
|
2910
|
+
new CustomEvent("chatkit.error", { detail: { error } })
|
|
2911
|
+
);
|
|
2912
|
+
if (error instanceof IntegrationError2) {
|
|
2913
|
+
throw error;
|
|
2914
|
+
}
|
|
2915
|
+
return;
|
|
2916
|
+
}
|
|
2917
|
+
this.dispatchEvent(new CustomEvent(`chatkit.${event}`, { detail: data }));
|
|
2918
|
+
});
|
|
2919
|
+
__privateGet(this, _messenger).on("pet_state_change", (data) => {
|
|
2920
|
+
const payload = parsePetStateChangePayload(data);
|
|
2921
|
+
if (payload) {
|
|
2922
|
+
__privateGet(this, _petOverlay).setState(payload.state);
|
|
2923
|
+
}
|
|
2924
|
+
});
|
|
2925
|
+
__privateGet(this, _messenger).on("pet_options_change", (data) => {
|
|
2926
|
+
const payload = parsePetOptionsChangePayload(data);
|
|
2927
|
+
if (payload) {
|
|
2928
|
+
if (!__privateGet(this, _petClosedByContextMenu) || payload.pet === null) {
|
|
2929
|
+
__privateSet(this, _petClosedByContextMenu, false);
|
|
2930
|
+
}
|
|
2931
|
+
__privateSet(this, _framePetOptionsOverride, payload.pet);
|
|
2932
|
+
__privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
|
|
2933
|
+
}
|
|
2934
|
+
});
|
|
2935
|
+
__privateGet(this, _messenger).on("chat_minimize_change", (data) => {
|
|
2936
|
+
const minimized = typeof data === "object" && data !== null && "minimized" in data && data.minimized === true;
|
|
2937
|
+
if (minimized && !__privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this)) {
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
__privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, minimized);
|
|
2941
|
+
if (minimized) {
|
|
2942
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
|
|
2943
|
+
}
|
|
2944
|
+
});
|
|
2945
|
+
__privateGet(this, _messenger).on("unmount", () => {
|
|
2946
|
+
if (__privateGet(this, _wrapper) && __privateGet(this, _shadow).contains(__privateGet(this, _wrapper))) {
|
|
2947
|
+
__privateGet(this, _shadow).removeChild(__privateGet(this, _wrapper));
|
|
2948
|
+
__privateSet(this, _wrapper, void 0);
|
|
2949
|
+
__privateSet(this, _frame, void 0);
|
|
2950
|
+
}
|
|
2951
|
+
});
|
|
2952
|
+
__privateGet(this, _messenger).on(
|
|
2953
|
+
"capabilities_profile_change",
|
|
2954
|
+
({ profile }) => {
|
|
2955
|
+
this.setProfile(profile);
|
|
2956
|
+
}
|
|
2957
|
+
);
|
|
2958
|
+
frame.addEventListener("load", __privateGet(this, _handleFrameLoad), { once: true });
|
|
2959
|
+
try {
|
|
2960
|
+
__privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
|
|
2961
|
+
} catch (error) {
|
|
2962
|
+
console.error(error);
|
|
2963
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new IntegrationError2("Failed to initialize ChatKit"));
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
disconnectedCallback() {
|
|
2967
|
+
var _a2, _b2;
|
|
2968
|
+
(_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
|
|
2969
|
+
(_b2 = __privateGet(this, _launcherCloseButton)) == null ? void 0 : _b2.removeEventListener(
|
|
2970
|
+
"click",
|
|
2971
|
+
__privateGet(this, _handleLauncherClose)
|
|
2972
|
+
);
|
|
2973
|
+
__privateGet(this, _messenger).disconnect();
|
|
2974
|
+
__privateGet(this, _petOverlay).destroy();
|
|
2975
|
+
}
|
|
2976
|
+
applySanitizedOptions(newOptions) {
|
|
2977
|
+
__privateSet(this, _opts, newOptions);
|
|
2978
|
+
__privateSet(this, _petClosedByContextMenu, false);
|
|
2979
|
+
__privateGet(this, _petOverlay).setLocale(newOptions.locale);
|
|
2980
|
+
__privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
|
|
2981
|
+
if (__privateGet(this, _initialized)) {
|
|
2982
|
+
__privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
|
|
2983
|
+
__privateGet(this, _loaded).then(() => {
|
|
2984
|
+
__privateGet(this, _messenger).commands.setOptions(
|
|
2985
|
+
getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, newOptions))
|
|
2986
|
+
);
|
|
2987
|
+
});
|
|
2988
|
+
} else {
|
|
2989
|
+
__privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
setOptions(newOptions) {
|
|
2993
|
+
try {
|
|
2994
|
+
const sanitized = this.sanitizeOptions(newOptions);
|
|
2995
|
+
__privateMethod(this, _ChatKitElementBase_instances, consumeFrameUrl_fn).call(this, sanitized);
|
|
2996
|
+
this.applySanitizedOptions(sanitized);
|
|
2997
|
+
} catch (error) {
|
|
2998
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new IntegrationError2("Failed to parse options"));
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
async focusComposer() {
|
|
3002
|
+
var _a2, _b2;
|
|
3003
|
+
await __privateGet(this, _loaded);
|
|
3004
|
+
(_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.focus();
|
|
3005
|
+
await ((_b2 = __privateGet(this, _messenger)) == null ? void 0 : _b2.commands.focusComposer());
|
|
3006
|
+
}
|
|
3007
|
+
async fetchUpdates() {
|
|
3008
|
+
var _a2;
|
|
3009
|
+
await __privateGet(this, _loaded);
|
|
3010
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.fetchUpdates());
|
|
3011
|
+
}
|
|
3012
|
+
async sendUserMessage(params) {
|
|
3013
|
+
var _a2;
|
|
3014
|
+
await __privateGet(this, _loaded);
|
|
3015
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.sendUserMessage(params));
|
|
3016
|
+
}
|
|
3017
|
+
async setComposerValue(params) {
|
|
3018
|
+
var _a2;
|
|
3019
|
+
await __privateGet(this, _loaded);
|
|
3020
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setComposerValue(params));
|
|
3021
|
+
}
|
|
3022
|
+
async setThreadId(threadId) {
|
|
3023
|
+
var _a2;
|
|
3024
|
+
await __privateGet(this, _loaded);
|
|
3025
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setThreadId({ threadId }));
|
|
3026
|
+
}
|
|
3027
|
+
async shareThread() {
|
|
3028
|
+
var _a2;
|
|
3029
|
+
await __privateGet(this, _loaded);
|
|
3030
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.shareThread();
|
|
3031
|
+
}
|
|
3032
|
+
async sendCustomAction(action, itemId) {
|
|
3033
|
+
var _a2;
|
|
3034
|
+
await __privateGet(this, _loaded);
|
|
3035
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.sendCustomAction({ action, itemId });
|
|
3036
|
+
}
|
|
3037
|
+
async showHistory() {
|
|
3038
|
+
var _a2;
|
|
3039
|
+
await __privateGet(this, _loaded);
|
|
3040
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.showHistory();
|
|
3041
|
+
}
|
|
3042
|
+
async hideHistory() {
|
|
3043
|
+
var _a2;
|
|
3044
|
+
await __privateGet(this, _loaded);
|
|
3045
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.hideHistory();
|
|
3046
|
+
}
|
|
3047
|
+
async setTrainingOptOut(value) {
|
|
3048
|
+
var _a2;
|
|
3049
|
+
await __privateGet(this, _loaded);
|
|
3050
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setTrainingOptOut({ value });
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
_init = __decoratorStart(_c);
|
|
3054
|
+
_opts = new WeakMap();
|
|
3055
|
+
_frameUrl = new WeakMap();
|
|
3056
|
+
_frame = new WeakMap();
|
|
3057
|
+
_wrapper = new WeakMap();
|
|
3058
|
+
_launcherCloseButton = new WeakMap();
|
|
3059
|
+
_launcherOpen = new WeakMap();
|
|
3060
|
+
_chatMinimizedToPet = new WeakMap();
|
|
3061
|
+
_framePetOptionsOverride = new WeakMap();
|
|
3062
|
+
_petClosedByContextMenu = new WeakMap();
|
|
3063
|
+
_shadow = new WeakMap();
|
|
3064
|
+
_petOverlay = new WeakMap();
|
|
3065
|
+
_resolveLoaded = new WeakMap();
|
|
3066
|
+
_loaded = new WeakMap();
|
|
3067
|
+
_messenger = new WeakMap();
|
|
3068
|
+
_ChatKitElementBase_instances = new WeakSet();
|
|
3069
|
+
emitAndThrow_fn = function(error) {
|
|
3070
|
+
this.dispatchEvent(new CustomEvent("chatkit.error", { detail: { error } }));
|
|
3071
|
+
throw error;
|
|
3072
|
+
};
|
|
3073
|
+
setOptionsDataAttributes_fn = function(options) {
|
|
3074
|
+
var _a2;
|
|
3075
|
+
this.dataset.colorScheme = typeof options.theme === "string" ? options.theme : ((_a2 = options.theme) == null ? void 0 : _a2.colorScheme) ?? "light";
|
|
3076
|
+
this.dataset.displayMode = __privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options);
|
|
3077
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options) !== "pet") {
|
|
3078
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
getDisplayMode_fn = function(options = __privateGet(this, _opts)) {
|
|
3082
|
+
return (options == null ? void 0 : options.displayMode) === "pet" ? "pet" : "chat";
|
|
3083
|
+
};
|
|
3084
|
+
getConfiguredPetOptions_fn = function(options = __privateGet(this, _opts)) {
|
|
3085
|
+
if (!options) {
|
|
3086
|
+
return null;
|
|
3087
|
+
}
|
|
3088
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this, options) === "pet" && !normalizePetOptions(options.pet ?? null)) {
|
|
3089
|
+
return true;
|
|
3090
|
+
}
|
|
3091
|
+
return options.pet ?? null;
|
|
3092
|
+
};
|
|
3093
|
+
mergeConfiguredPetPositionDefaults_fn = function(pet) {
|
|
3094
|
+
if (!pet) {
|
|
3095
|
+
return pet;
|
|
3096
|
+
}
|
|
3097
|
+
const configured = normalizePetOptions(
|
|
3098
|
+
__privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this) ?? null
|
|
3099
|
+
);
|
|
3100
|
+
if (!configured) {
|
|
3101
|
+
return pet;
|
|
3102
|
+
}
|
|
3103
|
+
if (pet === true) {
|
|
3104
|
+
return { position: configured.position };
|
|
3105
|
+
}
|
|
3106
|
+
if (!pet.position) {
|
|
3107
|
+
return { ...pet, position: configured.position };
|
|
3108
|
+
}
|
|
3109
|
+
return {
|
|
3110
|
+
...pet,
|
|
3111
|
+
position: {
|
|
3112
|
+
...configured.position,
|
|
3113
|
+
...pet.position,
|
|
3114
|
+
boundsPadding: pet.position.boundsPadding ?? configured.position.boundsPadding,
|
|
3115
|
+
pin: "pin" in pet.position ? pet.position.pin : configured.position.pin
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
3118
|
+
};
|
|
3119
|
+
getOverlayPetOptions_fn = function() {
|
|
3120
|
+
if (__privateGet(this, _petClosedByContextMenu)) {
|
|
3121
|
+
return null;
|
|
3122
|
+
}
|
|
3123
|
+
let pet;
|
|
3124
|
+
if (__privateGet(this, _framePetOptionsOverride) !== void 0) {
|
|
3125
|
+
pet = __privateMethod(this, _ChatKitElementBase_instances, mergeConfiguredPetPositionDefaults_fn).call(this, __privateGet(this, _framePetOptionsOverride));
|
|
3126
|
+
} else {
|
|
3127
|
+
pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
|
|
3128
|
+
}
|
|
3129
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !normalizePetOptions(pet ?? null)) {
|
|
3130
|
+
pet = true;
|
|
3131
|
+
}
|
|
3132
|
+
return __privateMethod(this, _ChatKitElementBase_instances, resolveOverlayPetOptions_fn).call(this, pet);
|
|
3133
|
+
};
|
|
3134
|
+
resolvePetAssetUrl_fn = function(src) {
|
|
3135
|
+
try {
|
|
3136
|
+
const base = new URL(
|
|
3137
|
+
__privateGet(this, _frameUrl) ?? window.location.href,
|
|
3138
|
+
window.location.origin
|
|
3139
|
+
);
|
|
3140
|
+
return new URL(src, base).toString();
|
|
3141
|
+
} catch {
|
|
3142
|
+
return src;
|
|
3143
|
+
}
|
|
3144
|
+
};
|
|
3145
|
+
resolveOverlayPetOptions_fn = function(pet) {
|
|
3146
|
+
const normalized = normalizePetOptions(pet ?? null);
|
|
3147
|
+
if (!normalized) {
|
|
3148
|
+
return null;
|
|
3149
|
+
}
|
|
3150
|
+
return {
|
|
3151
|
+
character: {
|
|
3152
|
+
...normalized.character,
|
|
3153
|
+
src: __privateMethod(this, _ChatKitElementBase_instances, resolvePetAssetUrl_fn).call(this, normalized.character.src)
|
|
3154
|
+
},
|
|
3155
|
+
position: normalized.position,
|
|
3156
|
+
behavior: normalized.behavior,
|
|
3157
|
+
ariaLabel: normalized.ariaLabel,
|
|
3158
|
+
imageRendering: normalized.imageRendering
|
|
3159
|
+
};
|
|
3160
|
+
};
|
|
3161
|
+
getFrameOptions_fn = function(options) {
|
|
3162
|
+
const pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this, options);
|
|
3163
|
+
if (pet === (options.pet ?? null)) {
|
|
3164
|
+
return options;
|
|
3165
|
+
}
|
|
3166
|
+
const nextOptions = { ...options };
|
|
3167
|
+
if (pet === null) {
|
|
3168
|
+
delete nextOptions.pet;
|
|
3169
|
+
} else {
|
|
3170
|
+
nextOptions.pet = pet;
|
|
3171
|
+
}
|
|
3172
|
+
return nextOptions;
|
|
3173
|
+
};
|
|
3174
|
+
setLauncherOpen_fn = function(open) {
|
|
3175
|
+
__privateSet(this, _launcherOpen, open);
|
|
3176
|
+
if (open) {
|
|
3177
|
+
this.dataset.chatOpen = "true";
|
|
3178
|
+
} else {
|
|
3179
|
+
delete this.dataset.chatOpen;
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
setChatMinimizedToPet_fn = function(minimized) {
|
|
3183
|
+
const next = minimized && Boolean(__privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this));
|
|
3184
|
+
__privateSet(this, _chatMinimizedToPet, next);
|
|
3185
|
+
if (next) {
|
|
3186
|
+
this.dataset.chatMinimizedToPet = "true";
|
|
3187
|
+
} else {
|
|
3188
|
+
delete this.dataset.chatMinimizedToPet;
|
|
3189
|
+
}
|
|
3190
|
+
};
|
|
3191
|
+
syncPetOverlayOptions_fn = function() {
|
|
3192
|
+
var _a2;
|
|
3193
|
+
const overlayPetOptions = __privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this);
|
|
3194
|
+
__privateGet(this, _petOverlay).setOptions(overlayPetOptions, (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.theme);
|
|
3195
|
+
if (!overlayPetOptions) {
|
|
3196
|
+
__privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
|
|
3197
|
+
}
|
|
3198
|
+
};
|
|
3199
|
+
handlePetActivate_fn = function() {
|
|
3200
|
+
if (__privateGet(this, _chatMinimizedToPet)) {
|
|
3201
|
+
__privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
|
|
3202
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
|
|
3203
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, true);
|
|
3204
|
+
}
|
|
3205
|
+
__privateGet(this, _loaded).then(() => this.focusComposer()).catch(() => void 0);
|
|
3206
|
+
return;
|
|
3207
|
+
}
|
|
3208
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
|
|
3209
|
+
return;
|
|
3210
|
+
}
|
|
3211
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, true);
|
|
3212
|
+
__privateGet(this, _loaded).then(() => this.focusComposer()).catch(() => void 0);
|
|
3213
|
+
};
|
|
3214
|
+
handlePetClose_fn = function() {
|
|
3215
|
+
__privateSet(this, _petClosedByContextMenu, true);
|
|
3216
|
+
__privateSet(this, _framePetOptionsOverride, null);
|
|
3217
|
+
__privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
|
|
3218
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
|
|
3219
|
+
__privateGet(this, _petOverlay).setOptions(null);
|
|
3220
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
|
|
3221
|
+
return;
|
|
3222
|
+
}
|
|
3223
|
+
__privateGet(this, _loaded).then(() => __privateGet(this, _messenger).commands.setPetEnabled({ enabled: false })).catch(() => void 0);
|
|
3224
|
+
};
|
|
3225
|
+
handlePetReply_fn = async function(text) {
|
|
3226
|
+
await this.sendUserMessage({ text });
|
|
3227
|
+
};
|
|
3228
|
+
handlePetThreadSummaryActivate_fn = async function(threadId) {
|
|
3229
|
+
if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
|
|
3230
|
+
__privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, true);
|
|
3231
|
+
}
|
|
3232
|
+
await this.setThreadId(threadId);
|
|
3233
|
+
await this.focusComposer();
|
|
3234
|
+
};
|
|
3235
|
+
_handleLauncherClose = new WeakMap();
|
|
3236
|
+
getFrameUrl_fn = function() {
|
|
3237
|
+
if (!__privateGet(this, _frameUrl)) {
|
|
3238
|
+
throw new IntegrationError2(
|
|
3239
|
+
"ChatKit frameUrl is not configured. Provide it via setOptions({ frameUrl }) before mounting."
|
|
3240
|
+
);
|
|
3241
|
+
}
|
|
3242
|
+
return __privateGet(this, _frameUrl);
|
|
3243
|
+
};
|
|
3244
|
+
setFrameUrl_fn = function(frameUrl) {
|
|
3245
|
+
if (__privateGet(this, _initialized) && __privateGet(this, _frameUrl) && __privateGet(this, _frameUrl) !== frameUrl) {
|
|
3246
|
+
throw new IntegrationError2(
|
|
3247
|
+
"ChatKit frameUrl cannot be changed after initialization. Create a new element to use a different URL."
|
|
3248
|
+
);
|
|
3249
|
+
}
|
|
3250
|
+
__privateSet(this, _frameUrl, frameUrl);
|
|
3251
|
+
};
|
|
3252
|
+
consumeFrameUrl_fn = function(options) {
|
|
3253
|
+
if (!("frameUrl" in options)) return;
|
|
3254
|
+
const frameUrl = options.frameUrl;
|
|
3255
|
+
delete options.frameUrl;
|
|
3256
|
+
if (frameUrl == null) return;
|
|
3257
|
+
if (typeof frameUrl !== "string" || frameUrl.trim() === "") {
|
|
3258
|
+
throw new IntegrationError2(
|
|
3259
|
+
"ChatKit frameUrl must be a non-empty string."
|
|
3260
|
+
);
|
|
3261
|
+
}
|
|
3262
|
+
__privateMethod(this, _ChatKitElementBase_instances, setFrameUrl_fn).call(this, frameUrl);
|
|
3263
|
+
};
|
|
3264
|
+
_handleFrameLoad = new WeakMap();
|
|
3265
|
+
_initialized = new WeakMap();
|
|
3266
|
+
maybeInit_fn = function() {
|
|
3267
|
+
if (__privateGet(this, _initialized) || !__privateGet(this, _frame) || !__privateGet(this, _opts)) {
|
|
3268
|
+
return;
|
|
3269
|
+
}
|
|
3270
|
+
__privateSet(this, _initialized, true);
|
|
3271
|
+
__privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
|
|
3272
|
+
const frameURL = new URL(__privateMethod(this, _ChatKitElementBase_instances, getFrameUrl_fn).call(this), window.location.origin);
|
|
3273
|
+
__privateGet(this, _messenger).setTargetOrigin(frameURL.origin);
|
|
3274
|
+
frameURL.hash = encodeBase64({
|
|
3275
|
+
options: getInnerOptions(__privateMethod(this, _ChatKitElementBase_instances, getFrameOptions_fn).call(this, __privateGet(this, _opts))),
|
|
3276
|
+
referrer: window.location.origin,
|
|
3277
|
+
profile: this.profile
|
|
3278
|
+
});
|
|
3279
|
+
__privateGet(this, _messenger).connect();
|
|
3280
|
+
__privateGet(this, _frame).src = frameURL.toString();
|
|
3281
|
+
if (__privateGet(this, _wrapper)) {
|
|
3282
|
+
__privateGet(this, _shadow).append(__privateGet(this, _wrapper));
|
|
3283
|
+
}
|
|
3284
|
+
};
|
|
3285
|
+
__decorateElement(_init, 1, "focusComposer", _focusComposer_dec, ChatKitElementBase);
|
|
3286
|
+
__decorateElement(_init, 1, "fetchUpdates", _fetchUpdates_dec, ChatKitElementBase);
|
|
3287
|
+
__decorateElement(_init, 1, "sendUserMessage", _sendUserMessage_dec, ChatKitElementBase);
|
|
3288
|
+
__decorateElement(_init, 1, "setComposerValue", _setComposerValue_dec, ChatKitElementBase);
|
|
3289
|
+
__decorateElement(_init, 1, "setThreadId", _setThreadId_dec, ChatKitElementBase);
|
|
3290
|
+
__decorateElement(_init, 1, "shareThread", _shareThread_dec, ChatKitElementBase);
|
|
3291
|
+
__decorateElement(_init, 1, "sendCustomAction", _sendCustomAction_dec, ChatKitElementBase);
|
|
3292
|
+
__decorateElement(_init, 1, "showHistory", _showHistory_dec, ChatKitElementBase);
|
|
3293
|
+
__decorateElement(_init, 1, "hideHistory", _hideHistory_dec, ChatKitElementBase);
|
|
3294
|
+
__decorateElement(_init, 1, "setTrainingOptOut", _setTrainingOptOut_dec, ChatKitElementBase);
|
|
3295
|
+
__decoratorMetadata(_init, ChatKitElementBase);
|
|
3296
|
+
class ChatKitElement extends ChatKitElementBase {
|
|
3297
|
+
constructor() {
|
|
3298
|
+
super({ profile: "chatkit" });
|
|
3299
|
+
}
|
|
3300
|
+
sanitizeOptions(options) {
|
|
3301
|
+
var _a2;
|
|
3302
|
+
(_a2 = options.threadItemActions) == null ? true : delete _a2.share;
|
|
3303
|
+
return options;
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
function registerChatKitElement(tag = "xpertai-chatkit") {
|
|
3307
|
+
if (!("customElements" in globalThis)) return;
|
|
3308
|
+
if (!customElements.get(tag)) {
|
|
3309
|
+
customElements.define(tag, ChatKitElement);
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
registerChatKitElement();
|
|
3313
|
+
//# sourceMappingURL=xpert-chatkit.js.map
|