@xpert-ai/chatkit-web-component 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -168
- package/dist/xpert-chatkit.js +86 -78
- package/dist/xpert-chatkit.js.map +1 -1
- package/dist/xpert-chatkit.umd.cjs +98 -90
- package/dist/xpert-chatkit.umd.cjs.map +1 -1
- package/package.json +18 -11
- package/LICENSE +0 -201
|
@@ -43,6 +43,7 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
|
43
43
|
}
|
|
44
44
|
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
45
45
|
};
|
|
46
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
46
47
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
47
48
|
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
48
49
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
@@ -50,11 +51,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
50
51
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
51
52
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
52
53
|
|
|
53
|
-
var _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec,
|
|
54
|
-
var __defProp2 = Object.defineProperty;
|
|
55
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
56
|
-
var __publicField = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
57
|
-
var _a, _b;
|
|
54
|
+
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, _shadow, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
|
|
58
55
|
class EventEmitter {
|
|
59
56
|
constructor() {
|
|
60
57
|
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
@@ -66,16 +63,16 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
66
63
|
this.callbacks.get(event).add(callback);
|
|
67
64
|
}
|
|
68
65
|
emit(event, ...args) {
|
|
69
|
-
var
|
|
66
|
+
var _a2;
|
|
70
67
|
const data = args[0];
|
|
71
|
-
(
|
|
68
|
+
(_a2 = this.callbacks.get(event)) == null ? void 0 : _a2.forEach((callback) => callback(data));
|
|
72
69
|
}
|
|
73
70
|
off(event, callback) {
|
|
74
|
-
var
|
|
71
|
+
var _a2;
|
|
75
72
|
if (!callback) {
|
|
76
73
|
this.callbacks.delete(event);
|
|
77
74
|
} else {
|
|
78
|
-
(
|
|
75
|
+
(_a2 = this.callbacks.get(event)) == null ? void 0 : _a2.delete(callback);
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
78
|
allOff() {
|
|
@@ -200,8 +197,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
200
197
|
const EventStreamContentType = "text/event-stream";
|
|
201
198
|
const DefaultRetryInterval = 1e3;
|
|
202
199
|
const LastEventId = "last-event-id";
|
|
203
|
-
function fetchEventSource(input,
|
|
204
|
-
var { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch } =
|
|
200
|
+
function fetchEventSource(input, _a2) {
|
|
201
|
+
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"]);
|
|
205
202
|
return new Promise((resolve, reject) => {
|
|
206
203
|
const headers = Object.assign({}, inputHeaders);
|
|
207
204
|
if (!headers.accept) {
|
|
@@ -303,7 +300,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
303
300
|
}
|
|
304
301
|
}
|
|
305
302
|
_a = FRAME_SAFE_ERROR_KEY;
|
|
306
|
-
const _FrameSafeHttpError = class
|
|
303
|
+
const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
307
304
|
constructor(message, res, metadata) {
|
|
308
305
|
__publicField(this, _a, "HttpError");
|
|
309
306
|
__publicField(this, "message");
|
|
@@ -318,7 +315,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
318
315
|
this.metadata = metadata;
|
|
319
316
|
}
|
|
320
317
|
static fromHttpError(error) {
|
|
321
|
-
return new
|
|
318
|
+
return new _FrameSafeHttpError(
|
|
322
319
|
error.message,
|
|
323
320
|
{
|
|
324
321
|
status: error.status,
|
|
@@ -348,9 +345,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
348
345
|
await fetchEventSource(url, {
|
|
349
346
|
...restParams,
|
|
350
347
|
onopen: async (res) => {
|
|
351
|
-
var
|
|
348
|
+
var _a2;
|
|
352
349
|
onopen == null ? void 0 : onopen(res);
|
|
353
|
-
if (res.ok && ((
|
|
350
|
+
if (res.ok && ((_a2 = res.headers.get("content-type")) == null ? void 0 : _a2.startsWith("text/event-stream"))) {
|
|
354
351
|
retryAttempt = 0;
|
|
355
352
|
return;
|
|
356
353
|
}
|
|
@@ -373,7 +370,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
373
370
|
}
|
|
374
371
|
});
|
|
375
372
|
};
|
|
376
|
-
let IntegrationError$1 = class
|
|
373
|
+
let IntegrationError$1 = class IntegrationError2 extends Error {
|
|
377
374
|
constructor(message) {
|
|
378
375
|
super(message);
|
|
379
376
|
__publicField(this, "_name");
|
|
@@ -383,7 +380,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
383
380
|
static fromPossibleFrameSafeError(error) {
|
|
384
381
|
if (error && typeof error === "object" && FRAME_SAFE_ERROR_KEY in error && error[FRAME_SAFE_ERROR_KEY] === "IntegrationError") {
|
|
385
382
|
const safeError = error;
|
|
386
|
-
const parsedError = new
|
|
383
|
+
const parsedError = new IntegrationError2(safeError.message);
|
|
387
384
|
parsedError.stack = safeError.stack;
|
|
388
385
|
return parsedError;
|
|
389
386
|
}
|
|
@@ -438,8 +435,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
438
435
|
}
|
|
439
436
|
));
|
|
440
437
|
__publicField(this, "handleMessage", async (event) => {
|
|
441
|
-
var
|
|
442
|
-
console.log("Received message", event.data, event.origin, this.targetOrigin, event.source, this.target());
|
|
438
|
+
var _a2, _b2, _c2, _d;
|
|
443
439
|
if (!event.data || event.data.__xpaiChatKit !== true || event.origin !== this.targetOrigin || event.source !== this.target()) {
|
|
444
440
|
return;
|
|
445
441
|
}
|
|
@@ -512,7 +508,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
512
508
|
break;
|
|
513
509
|
}
|
|
514
510
|
case "command": {
|
|
515
|
-
console.log("Received command", data.command, data.data);
|
|
516
511
|
if (!this.canReceiveCommand(data.command)) {
|
|
517
512
|
this.sendMessage({
|
|
518
513
|
type: "response",
|
|
@@ -522,7 +517,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
522
517
|
return;
|
|
523
518
|
}
|
|
524
519
|
try {
|
|
525
|
-
const response = await ((_b2 = (
|
|
520
|
+
const response = await ((_b2 = (_a2 = this.commandHandlers)[data.command]) == null ? void 0 : _b2.call(_a2, data.data));
|
|
526
521
|
this.sendMessage({
|
|
527
522
|
type: "response",
|
|
528
523
|
response,
|
|
@@ -566,7 +561,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
566
561
|
console.error("No handler found for nonce", data.nonce);
|
|
567
562
|
return;
|
|
568
563
|
}
|
|
569
|
-
(_d = (
|
|
564
|
+
(_d = (_c2 = this.fetchEventSourceHandlers.get(data.nonce)) == null ? void 0 : _c2.onmessage) == null ? void 0 : _d.call(_c2, data.message);
|
|
570
565
|
break;
|
|
571
566
|
}
|
|
572
567
|
case "abortSignal": {
|
|
@@ -588,12 +583,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
588
583
|
this.targetOrigin = targetOrigin;
|
|
589
584
|
}
|
|
590
585
|
sendMessage(data, transfer) {
|
|
591
|
-
var
|
|
586
|
+
var _a2;
|
|
592
587
|
const message = {
|
|
593
588
|
__xpaiChatKit: true,
|
|
594
589
|
...data
|
|
595
590
|
};
|
|
596
|
-
(
|
|
591
|
+
(_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
|
|
597
592
|
}
|
|
598
593
|
connect() {
|
|
599
594
|
window.addEventListener("message", this.handleMessage);
|
|
@@ -615,11 +610,11 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
615
610
|
}
|
|
616
611
|
if (params.signal) {
|
|
617
612
|
params.signal.addEventListener("abort", () => {
|
|
618
|
-
var
|
|
613
|
+
var _a2;
|
|
619
614
|
this.sendMessage({
|
|
620
615
|
type: "abortSignal",
|
|
621
616
|
nonce,
|
|
622
|
-
reason: (
|
|
617
|
+
reason: (_a2 = params.signal) == null ? void 0 : _a2.reason
|
|
623
618
|
});
|
|
624
619
|
});
|
|
625
620
|
params.signal = void 0;
|
|
@@ -681,7 +676,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
681
676
|
for (const b of bytes) bin += String.fromCharCode(b);
|
|
682
677
|
return toUrlBase64(bin);
|
|
683
678
|
};
|
|
684
|
-
class
|
|
679
|
+
class IntegrationError extends Error {
|
|
685
680
|
}
|
|
686
681
|
function fromPossibleFrameSafeError(err) {
|
|
687
682
|
return err.message;
|
|
@@ -885,14 +880,14 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
885
880
|
const command = String(context.name);
|
|
886
881
|
return function(...args) {
|
|
887
882
|
if (!this.capabilities.commands.has(command)) {
|
|
888
|
-
throw new
|
|
883
|
+
throw new IntegrationError(
|
|
889
884
|
`ChatKit command "${String(command)}" is not available for the "${this.profile}" profile.`
|
|
890
885
|
);
|
|
891
886
|
}
|
|
892
887
|
return value.apply(this, args);
|
|
893
888
|
};
|
|
894
889
|
}
|
|
895
|
-
class ChatKitElementBase extends (
|
|
890
|
+
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) {
|
|
896
891
|
constructor({ profile }) {
|
|
897
892
|
super();
|
|
898
893
|
__runInitializers(_init, 5, this);
|
|
@@ -908,17 +903,19 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
908
903
|
}));
|
|
909
904
|
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
910
905
|
fetch: (...args) => {
|
|
911
|
-
var
|
|
912
|
-
const customFetch = ((
|
|
906
|
+
var _a2;
|
|
907
|
+
const customFetch = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
913
908
|
return customFetch ? customFetch(...args) : fetch(...args);
|
|
914
909
|
},
|
|
915
910
|
target: () => {
|
|
916
|
-
var
|
|
917
|
-
return ((
|
|
911
|
+
var _a2;
|
|
912
|
+
return ((_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.contentWindow) ?? null;
|
|
918
913
|
},
|
|
919
914
|
targetOrigin: window.location.origin,
|
|
920
915
|
handlers: {
|
|
921
|
-
onFileInputClick: ({
|
|
916
|
+
onFileInputClick: ({
|
|
917
|
+
inputAttributes
|
|
918
|
+
}) => {
|
|
922
919
|
return new Promise((resolve) => {
|
|
923
920
|
const input = document.createElement("input");
|
|
924
921
|
for (const [key, value] of Object.entries(inputAttributes)) {
|
|
@@ -942,40 +939,43 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
942
939
|
id,
|
|
943
940
|
tool_call_id
|
|
944
941
|
}) => {
|
|
945
|
-
var
|
|
946
|
-
const onClientTool = (
|
|
942
|
+
var _a2;
|
|
943
|
+
const onClientTool = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.onClientTool;
|
|
947
944
|
if (!onClientTool) {
|
|
948
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new
|
|
945
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError(
|
|
949
946
|
`No handler for client tool calls. You'll need to add onClientTool to your ChatKit options.`
|
|
950
947
|
));
|
|
951
948
|
}
|
|
952
949
|
return onClientTool({ name, params, id, tool_call_id });
|
|
953
950
|
},
|
|
954
|
-
onWidgetAction: async ({
|
|
955
|
-
|
|
956
|
-
|
|
951
|
+
onWidgetAction: async ({
|
|
952
|
+
action,
|
|
953
|
+
widgetItem
|
|
954
|
+
}) => {
|
|
955
|
+
var _a2, _b2;
|
|
956
|
+
const onAction = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.widgets) == null ? void 0 : _b2.onAction;
|
|
957
957
|
if (!onAction) {
|
|
958
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new
|
|
958
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError(
|
|
959
959
|
`No handler for widget actions. You'll need to add widgets.onAction to your ChatKit options.`
|
|
960
960
|
));
|
|
961
961
|
}
|
|
962
962
|
return onAction(action, widgetItem);
|
|
963
963
|
},
|
|
964
964
|
onEntitySearch: async ({ query }) => {
|
|
965
|
-
var
|
|
966
|
-
return ((
|
|
965
|
+
var _a2, _b2, _c2;
|
|
966
|
+
return ((_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onTagSearch) == null ? void 0 : _c2.call(_b2, query)) ?? [];
|
|
967
967
|
},
|
|
968
968
|
onEntityClick: async ({ entity }) => {
|
|
969
|
-
var
|
|
970
|
-
return (
|
|
969
|
+
var _a2, _b2, _c2;
|
|
970
|
+
return (_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onClick) == null ? void 0 : _c2.call(_b2, entity);
|
|
971
971
|
},
|
|
972
972
|
onEntityPreview: async ({ entity }) => {
|
|
973
|
-
var
|
|
974
|
-
return ((
|
|
973
|
+
var _a2, _b2, _c2;
|
|
974
|
+
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 };
|
|
975
975
|
},
|
|
976
976
|
onGetClientSecret: async (currentClientSecret) => {
|
|
977
977
|
if (!__privateGet(this, _opts) || !("getClientSecret" in __privateGet(this, _opts).api) || !__privateGet(this, _opts).api.getClientSecret) {
|
|
978
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new
|
|
978
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError(
|
|
979
979
|
"Could not refresh the session because ChatKitOptions.api.getClientSecret is not configured."
|
|
980
980
|
));
|
|
981
981
|
}
|
|
@@ -985,15 +985,19 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
985
985
|
op,
|
|
986
986
|
params
|
|
987
987
|
}) => {
|
|
988
|
-
throw new
|
|
988
|
+
throw new IntegrationError(
|
|
989
|
+
"ChatKit: onAddMetadataToRequest is unimplemented."
|
|
990
|
+
);
|
|
989
991
|
}
|
|
990
992
|
}
|
|
991
993
|
}));
|
|
992
994
|
__privateAdd(this, _handleFrameLoad, () => {
|
|
993
|
-
var
|
|
995
|
+
var _a2;
|
|
994
996
|
this.dataset.loaded = "true";
|
|
995
|
-
this.dispatchEvent(
|
|
996
|
-
|
|
997
|
+
this.dispatchEvent(
|
|
998
|
+
new CustomEvent("chatkit.ready", { bubbles: true, composed: true })
|
|
999
|
+
);
|
|
1000
|
+
(_a2 = __privateGet(this, _resolveLoaded)) == null ? void 0 : _a2.call(this);
|
|
997
1001
|
});
|
|
998
1002
|
__privateAdd(this, _initialized, false);
|
|
999
1003
|
this.profile = profile;
|
|
@@ -1052,19 +1056,21 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1052
1056
|
__privateSet(this, _wrapper, wrapper);
|
|
1053
1057
|
__privateGet(this, _shadow).append(style);
|
|
1054
1058
|
__privateGet(this, _messenger).on("left_header_icon_click", () => {
|
|
1055
|
-
var
|
|
1056
|
-
(
|
|
1059
|
+
var _a2, _b2, _c2;
|
|
1060
|
+
(_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.leftAction) == null ? void 0 : _c2.onClick();
|
|
1057
1061
|
});
|
|
1058
1062
|
__privateGet(this, _messenger).on("right_header_icon_click", () => {
|
|
1059
|
-
var
|
|
1060
|
-
(
|
|
1063
|
+
var _a2, _b2, _c2;
|
|
1064
|
+
(_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.rightAction) == null ? void 0 : _c2.onClick();
|
|
1061
1065
|
});
|
|
1062
1066
|
__privateGet(this, _messenger).on("public_event", ([event, data]) => {
|
|
1063
1067
|
if (!this.capabilities.events.has(event)) return;
|
|
1064
1068
|
if (event === "error" && "error" in data) {
|
|
1065
1069
|
const error = fromPossibleFrameSafeError(data.error);
|
|
1066
|
-
this.dispatchEvent(
|
|
1067
|
-
|
|
1070
|
+
this.dispatchEvent(
|
|
1071
|
+
new CustomEvent("chatkit.error", { detail: { error } })
|
|
1072
|
+
);
|
|
1073
|
+
if (error instanceof IntegrationError) {
|
|
1068
1074
|
throw error;
|
|
1069
1075
|
}
|
|
1070
1076
|
return;
|
|
@@ -1089,12 +1095,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1089
1095
|
__privateMethod(this, _ChatKitElementBase_instances, maybeInit_fn).call(this);
|
|
1090
1096
|
} catch (error) {
|
|
1091
1097
|
console.error(error);
|
|
1092
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new
|
|
1098
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new IntegrationError("Failed to initialize ChatKit"));
|
|
1093
1099
|
}
|
|
1094
1100
|
}
|
|
1095
1101
|
disconnectedCallback() {
|
|
1096
|
-
var
|
|
1097
|
-
(
|
|
1102
|
+
var _a2;
|
|
1103
|
+
(_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
|
|
1098
1104
|
__privateGet(this, _messenger).disconnect();
|
|
1099
1105
|
}
|
|
1100
1106
|
applySanitizedOptions(newOptions) {
|
|
@@ -1114,62 +1120,62 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1114
1120
|
__privateMethod(this, _ChatKitElementBase_instances, consumeFrameUrl_fn).call(this, sanitized);
|
|
1115
1121
|
this.applySanitizedOptions(sanitized);
|
|
1116
1122
|
} catch (error) {
|
|
1117
|
-
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new
|
|
1123
|
+
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, error instanceof Error ? error : new IntegrationError("Failed to parse options"));
|
|
1118
1124
|
}
|
|
1119
1125
|
}
|
|
1120
1126
|
async focusComposer() {
|
|
1121
|
-
var
|
|
1127
|
+
var _a2, _b2;
|
|
1122
1128
|
await __privateGet(this, _loaded);
|
|
1123
|
-
(
|
|
1129
|
+
(_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.focus();
|
|
1124
1130
|
await ((_b2 = __privateGet(this, _messenger)) == null ? void 0 : _b2.commands.focusComposer());
|
|
1125
1131
|
}
|
|
1126
1132
|
async fetchUpdates() {
|
|
1127
|
-
var
|
|
1133
|
+
var _a2;
|
|
1128
1134
|
await __privateGet(this, _loaded);
|
|
1129
|
-
await ((
|
|
1135
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.fetchUpdates());
|
|
1130
1136
|
}
|
|
1131
1137
|
async sendUserMessage(params) {
|
|
1132
|
-
var
|
|
1138
|
+
var _a2;
|
|
1133
1139
|
await __privateGet(this, _loaded);
|
|
1134
|
-
await ((
|
|
1140
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.sendUserMessage(params));
|
|
1135
1141
|
}
|
|
1136
1142
|
async setComposerValue(params) {
|
|
1137
|
-
var
|
|
1143
|
+
var _a2;
|
|
1138
1144
|
await __privateGet(this, _loaded);
|
|
1139
|
-
await ((
|
|
1145
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setComposerValue(params));
|
|
1140
1146
|
}
|
|
1141
1147
|
async setThreadId(threadId) {
|
|
1142
|
-
var
|
|
1148
|
+
var _a2;
|
|
1143
1149
|
await __privateGet(this, _loaded);
|
|
1144
|
-
await ((
|
|
1150
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setThreadId({ threadId }));
|
|
1145
1151
|
}
|
|
1146
1152
|
async shareThread() {
|
|
1147
|
-
var
|
|
1153
|
+
var _a2;
|
|
1148
1154
|
await __privateGet(this, _loaded);
|
|
1149
|
-
return (
|
|
1155
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.shareThread();
|
|
1150
1156
|
}
|
|
1151
1157
|
async sendCustomAction(action, itemId) {
|
|
1152
|
-
var
|
|
1158
|
+
var _a2;
|
|
1153
1159
|
await __privateGet(this, _loaded);
|
|
1154
|
-
return (
|
|
1160
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.sendCustomAction({ action, itemId });
|
|
1155
1161
|
}
|
|
1156
1162
|
async showHistory() {
|
|
1157
|
-
var
|
|
1163
|
+
var _a2;
|
|
1158
1164
|
await __privateGet(this, _loaded);
|
|
1159
|
-
return (
|
|
1165
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.showHistory();
|
|
1160
1166
|
}
|
|
1161
1167
|
async hideHistory() {
|
|
1162
|
-
var
|
|
1168
|
+
var _a2;
|
|
1163
1169
|
await __privateGet(this, _loaded);
|
|
1164
|
-
return (
|
|
1170
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.hideHistory();
|
|
1165
1171
|
}
|
|
1166
1172
|
async setTrainingOptOut(value) {
|
|
1167
|
-
var
|
|
1173
|
+
var _a2;
|
|
1168
1174
|
await __privateGet(this, _loaded);
|
|
1169
|
-
return (
|
|
1175
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setTrainingOptOut({ value });
|
|
1170
1176
|
}
|
|
1171
1177
|
}
|
|
1172
|
-
_init = __decoratorStart(
|
|
1178
|
+
_init = __decoratorStart(_c);
|
|
1173
1179
|
_opts = new WeakMap();
|
|
1174
1180
|
_frameUrl = new WeakMap();
|
|
1175
1181
|
_frame = new WeakMap();
|
|
@@ -1184,12 +1190,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1184
1190
|
throw error;
|
|
1185
1191
|
};
|
|
1186
1192
|
setOptionsDataAttributes_fn = function(options) {
|
|
1187
|
-
var
|
|
1188
|
-
this.dataset.colorScheme = typeof options.theme === "string" ? options.theme : ((
|
|
1193
|
+
var _a2;
|
|
1194
|
+
this.dataset.colorScheme = typeof options.theme === "string" ? options.theme : ((_a2 = options.theme) == null ? void 0 : _a2.colorScheme) ?? "light";
|
|
1189
1195
|
};
|
|
1190
1196
|
getFrameUrl_fn = function() {
|
|
1191
1197
|
if (!__privateGet(this, _frameUrl)) {
|
|
1192
|
-
throw new
|
|
1198
|
+
throw new IntegrationError(
|
|
1193
1199
|
"ChatKit frameUrl is not configured. Provide it via setOptions({ frameUrl }) before mounting."
|
|
1194
1200
|
);
|
|
1195
1201
|
}
|
|
@@ -1197,7 +1203,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1197
1203
|
};
|
|
1198
1204
|
setFrameUrl_fn = function(frameUrl) {
|
|
1199
1205
|
if (__privateGet(this, _initialized) && __privateGet(this, _frameUrl) && __privateGet(this, _frameUrl) !== frameUrl) {
|
|
1200
|
-
throw new
|
|
1206
|
+
throw new IntegrationError(
|
|
1201
1207
|
"ChatKit frameUrl cannot be changed after initialization. Create a new element to use a different URL."
|
|
1202
1208
|
);
|
|
1203
1209
|
}
|
|
@@ -1209,7 +1215,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1209
1215
|
delete options.frameUrl;
|
|
1210
1216
|
if (frameUrl == null) return;
|
|
1211
1217
|
if (typeof frameUrl !== "string" || frameUrl.trim() === "") {
|
|
1212
|
-
throw new
|
|
1218
|
+
throw new IntegrationError(
|
|
1219
|
+
"ChatKit frameUrl must be a non-empty string."
|
|
1220
|
+
);
|
|
1213
1221
|
}
|
|
1214
1222
|
__privateMethod(this, _ChatKitElementBase_instances, setFrameUrl_fn).call(this, frameUrl);
|
|
1215
1223
|
};
|
|
@@ -1250,8 +1258,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
1250
1258
|
super({ profile: "chatkit" });
|
|
1251
1259
|
}
|
|
1252
1260
|
sanitizeOptions(options) {
|
|
1253
|
-
var
|
|
1254
|
-
(
|
|
1261
|
+
var _a2;
|
|
1262
|
+
(_a2 = options.threadItemActions) == null ? true : delete _a2.share;
|
|
1255
1263
|
return options;
|
|
1256
1264
|
}
|
|
1257
1265
|
}
|