@xpert-ai/chatkit-web-component 0.0.3 → 0.2.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 +103 -81
- package/dist/xpert-chatkit.js.map +1 -1
- package/dist/xpert-chatkit.umd.cjs +115 -93
- package/dist/xpert-chatkit.umd.cjs.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,172 +1,9 @@
|
|
|
1
1
|
# Xpert Chatkit Web Component
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package ships the ChatKit Web Component for embedding ChatKit in any web page.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Role in the ChatKit project
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- 🔒 Secure session management
|
|
11
|
-
- ⚡ Loading and error states built-in
|
|
12
|
-
- 🌐 Works with any framework (React, Vue, Angular, vanilla JS)
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install @xpert-ai/chatkit-web-component
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Or use via CDN:
|
|
21
|
-
|
|
22
|
-
```html
|
|
23
|
-
<script src="https://unpkg.com/@xpert-ai/chatkit-web-component/dist/xpert-chatkit.js"></script>
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
27
|
-
|
|
28
|
-
### Basic Example
|
|
29
|
-
|
|
30
|
-
```html
|
|
31
|
-
<!DOCTYPE html>
|
|
32
|
-
<html>
|
|
33
|
-
<head>
|
|
34
|
-
<script src="https://unpkg.com/@xpert-ai/chatkit-web-component/dist/xpert-chatkit.js"></script>
|
|
35
|
-
<style>
|
|
36
|
-
xpert-chatkit {
|
|
37
|
-
width: 100%;
|
|
38
|
-
height: 600px;
|
|
39
|
-
}
|
|
40
|
-
</style>
|
|
41
|
-
</head>
|
|
42
|
-
<body>
|
|
43
|
-
<xpert-chatkit
|
|
44
|
-
backend-url="https://your-backend.com"
|
|
45
|
-
chatkit-url="https://chatkit.xpert.ai"
|
|
46
|
-
assistant-id="assistant_123">
|
|
47
|
-
</xpert-chatkit>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### With Style Configuration
|
|
53
|
-
|
|
54
|
-
```html
|
|
55
|
-
<xpert-chatkit
|
|
56
|
-
backend-url="https://your-backend.com"
|
|
57
|
-
chatkit-url="https://chatkit.xpert.ai"
|
|
58
|
-
assistant-id="assistant_123"
|
|
59
|
-
style-config='{"primaryColor": "#007bff", "fontSize": "14px"}'>
|
|
60
|
-
</xpert-chatkit>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Programmatic Usage
|
|
64
|
-
|
|
65
|
-
```javascript
|
|
66
|
-
import '@xpert-ai/chatkit-web-component';
|
|
67
|
-
|
|
68
|
-
// Create element
|
|
69
|
-
const chatkit = document.createElement('xpert-chatkit');
|
|
70
|
-
chatkit.setAttribute('backend-url', 'https://your-backend.com');
|
|
71
|
-
chatkit.setAttribute('chatkit-url', 'https://chatkit.xpert.ai');
|
|
72
|
-
chatkit.setAttribute('assistant-id', 'assistant_123');
|
|
73
|
-
|
|
74
|
-
// Update style config
|
|
75
|
-
chatkit.updateStyleConfig({
|
|
76
|
-
primaryColor: '#007bff',
|
|
77
|
-
fontSize: '14px'
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
document.body.appendChild(chatkit);
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Attributes
|
|
84
|
-
|
|
85
|
-
| Attribute | Required | Description |
|
|
86
|
-
|-----------|----------|-------------|
|
|
87
|
-
| `backend-url` | Yes | Backend API URL for session creation |
|
|
88
|
-
| `chatkit-url` | Yes | Chatkit iframe URL |
|
|
89
|
-
| `assistant-id` | No | Assistant ID to use |
|
|
90
|
-
| `style-config` | No | JSON string for style configuration |
|
|
91
|
-
|
|
92
|
-
## Methods
|
|
93
|
-
|
|
94
|
-
### `updateStyleConfig(config: Record<string, unknown>)`
|
|
95
|
-
|
|
96
|
-
Updates the style configuration. Note: Currently only applied on initial load.
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
const chatkit = document.querySelector('xpert-chatkit');
|
|
100
|
-
chatkit.updateStyleConfig({
|
|
101
|
-
primaryColor: '#ff0000',
|
|
102
|
-
borderRadius: '8px'
|
|
103
|
-
});
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Styling
|
|
107
|
-
|
|
108
|
-
The component automatically fills its container. You can control its size with CSS:
|
|
109
|
-
|
|
110
|
-
```css
|
|
111
|
-
xpert-chatkit {
|
|
112
|
-
width: 100%;
|
|
113
|
-
height: 100vh;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/* Or fixed size */
|
|
117
|
-
xpert-chatkit {
|
|
118
|
-
width: 400px;
|
|
119
|
-
height: 600px;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/* In a flex/grid container */
|
|
123
|
-
.container {
|
|
124
|
-
display: flex;
|
|
125
|
-
height: 100vh;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
xpert-chatkit {
|
|
129
|
-
flex: 1;
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## Error Handling
|
|
134
|
-
|
|
135
|
-
The component displays loading and error states automatically:
|
|
136
|
-
- Shows "Creating session..." while fetching client secret
|
|
137
|
-
- Shows error message if session creation fails
|
|
138
|
-
- Logs errors to console with `[xpert-chatkit]` prefix
|
|
139
|
-
|
|
140
|
-
## Browser Support
|
|
141
|
-
|
|
142
|
-
- Chrome/Edge 54+
|
|
143
|
-
- Firefox 63+
|
|
144
|
-
- Safari 10.1+
|
|
145
|
-
- All modern browsers with Custom Elements v1 support
|
|
146
|
-
|
|
147
|
-
For older browsers, you may need the [Web Components polyfill](https://github.com/webcomponents/polyfills).
|
|
148
|
-
|
|
149
|
-
## Development
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
# Install dependencies
|
|
153
|
-
npm install
|
|
154
|
-
|
|
155
|
-
# Start development server (recommended)
|
|
156
|
-
npm run serve
|
|
157
|
-
|
|
158
|
-
# Build for production
|
|
159
|
-
npm run build
|
|
160
|
-
|
|
161
|
-
# Watch mode (build on change)
|
|
162
|
-
npm run dev
|
|
163
|
-
|
|
164
|
-
# Type check
|
|
165
|
-
npm run type-check
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
For detailed development instructions, see [DEVELOPMENT.md](./DEVELOPMENT.md).
|
|
169
|
-
|
|
170
|
-
## License
|
|
171
|
-
|
|
172
|
-
MIT
|
|
7
|
+
- Exposes a framework-agnostic custom element for integrating ChatKit.
|
|
8
|
+
- Manages the iframe lifecycle and wiring between the host page and the ChatKit UI.
|
|
9
|
+
- Serves as the primary distribution artifact for non-React web integrations.
|
package/dist/xpert-chatkit.js
CHANGED
|
@@ -40,17 +40,14 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
|
40
40
|
}
|
|
41
41
|
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
42
42
|
};
|
|
43
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
44
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
44
45
|
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
45
46
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
46
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);
|
|
47
48
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
48
49
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
49
|
-
var _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec,
|
|
50
|
-
var __defProp2 = Object.defineProperty;
|
|
51
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
|
-
var __publicField = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
53
|
-
var _a, _b;
|
|
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, _shadow, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
|
|
54
51
|
class EventEmitter {
|
|
55
52
|
constructor() {
|
|
56
53
|
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
@@ -62,16 +59,16 @@ class EventEmitter {
|
|
|
62
59
|
this.callbacks.get(event).add(callback);
|
|
63
60
|
}
|
|
64
61
|
emit(event, ...args) {
|
|
65
|
-
var
|
|
62
|
+
var _a2;
|
|
66
63
|
const data = args[0];
|
|
67
|
-
(
|
|
64
|
+
(_a2 = this.callbacks.get(event)) == null ? void 0 : _a2.forEach((callback) => callback(data));
|
|
68
65
|
}
|
|
69
66
|
off(event, callback) {
|
|
70
|
-
var
|
|
67
|
+
var _a2;
|
|
71
68
|
if (!callback) {
|
|
72
69
|
this.callbacks.delete(event);
|
|
73
70
|
} else {
|
|
74
|
-
(
|
|
71
|
+
(_a2 = this.callbacks.get(event)) == null ? void 0 : _a2.delete(callback);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
allOff() {
|
|
@@ -196,8 +193,8 @@ var __rest = function(s, e) {
|
|
|
196
193
|
const EventStreamContentType = "text/event-stream";
|
|
197
194
|
const DefaultRetryInterval = 1e3;
|
|
198
195
|
const LastEventId = "last-event-id";
|
|
199
|
-
function fetchEventSource(input,
|
|
200
|
-
var { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch } =
|
|
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"]);
|
|
201
198
|
return new Promise((resolve, reject) => {
|
|
202
199
|
const headers = Object.assign({}, inputHeaders);
|
|
203
200
|
if (!headers.accept) {
|
|
@@ -299,7 +296,7 @@ class HttpError extends Error {
|
|
|
299
296
|
}
|
|
300
297
|
}
|
|
301
298
|
_a = FRAME_SAFE_ERROR_KEY;
|
|
302
|
-
const _FrameSafeHttpError = class
|
|
299
|
+
const _FrameSafeHttpError = class _FrameSafeHttpError {
|
|
303
300
|
constructor(message, res, metadata) {
|
|
304
301
|
__publicField(this, _a, "HttpError");
|
|
305
302
|
__publicField(this, "message");
|
|
@@ -314,7 +311,7 @@ const _FrameSafeHttpError = class _FrameSafeHttpError2 {
|
|
|
314
311
|
this.metadata = metadata;
|
|
315
312
|
}
|
|
316
313
|
static fromHttpError(error) {
|
|
317
|
-
return new
|
|
314
|
+
return new _FrameSafeHttpError(
|
|
318
315
|
error.message,
|
|
319
316
|
{
|
|
320
317
|
status: error.status,
|
|
@@ -344,9 +341,9 @@ const fetchEventSourceWithRetry = async (url, params) => {
|
|
|
344
341
|
await fetchEventSource(url, {
|
|
345
342
|
...restParams,
|
|
346
343
|
onopen: async (res) => {
|
|
347
|
-
var
|
|
344
|
+
var _a2;
|
|
348
345
|
onopen == null ? void 0 : onopen(res);
|
|
349
|
-
if (res.ok && ((
|
|
346
|
+
if (res.ok && ((_a2 = res.headers.get("content-type")) == null ? void 0 : _a2.startsWith("text/event-stream"))) {
|
|
350
347
|
retryAttempt = 0;
|
|
351
348
|
return;
|
|
352
349
|
}
|
|
@@ -369,6 +366,20 @@ const fetchEventSourceWithRetry = async (url, params) => {
|
|
|
369
366
|
}
|
|
370
367
|
});
|
|
371
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
|
+
}
|
|
372
383
|
let IntegrationError$1 = class IntegrationError extends Error {
|
|
373
384
|
constructor(message) {
|
|
374
385
|
super(message);
|
|
@@ -417,7 +428,7 @@ class BaseMessenger {
|
|
|
417
428
|
get: (_, command) => {
|
|
418
429
|
return (data, transfer) => {
|
|
419
430
|
return new Promise((resolve, reject) => {
|
|
420
|
-
const nonce =
|
|
431
|
+
const nonce = safeRandomUUID();
|
|
421
432
|
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
422
433
|
this.sendMessage(
|
|
423
434
|
{
|
|
@@ -434,8 +445,7 @@ class BaseMessenger {
|
|
|
434
445
|
}
|
|
435
446
|
));
|
|
436
447
|
__publicField(this, "handleMessage", async (event) => {
|
|
437
|
-
var
|
|
438
|
-
console.log("Received message", event.data, event.origin, this.targetOrigin, event.source, this.target());
|
|
448
|
+
var _a2, _b2, _c2, _d;
|
|
439
449
|
if (!event.data || event.data.__xpaiChatKit !== true || event.origin !== this.targetOrigin || event.source !== this.target()) {
|
|
440
450
|
return;
|
|
441
451
|
}
|
|
@@ -508,7 +518,6 @@ class BaseMessenger {
|
|
|
508
518
|
break;
|
|
509
519
|
}
|
|
510
520
|
case "command": {
|
|
511
|
-
console.log("Received command", data.command, data.data);
|
|
512
521
|
if (!this.canReceiveCommand(data.command)) {
|
|
513
522
|
this.sendMessage({
|
|
514
523
|
type: "response",
|
|
@@ -518,7 +527,7 @@ class BaseMessenger {
|
|
|
518
527
|
return;
|
|
519
528
|
}
|
|
520
529
|
try {
|
|
521
|
-
const response = await ((_b2 = (
|
|
530
|
+
const response = await ((_b2 = (_a2 = this.commandHandlers)[data.command]) == null ? void 0 : _b2.call(_a2, data.data));
|
|
522
531
|
this.sendMessage({
|
|
523
532
|
type: "response",
|
|
524
533
|
response,
|
|
@@ -562,7 +571,7 @@ class BaseMessenger {
|
|
|
562
571
|
console.error("No handler found for nonce", data.nonce);
|
|
563
572
|
return;
|
|
564
573
|
}
|
|
565
|
-
(_d = (
|
|
574
|
+
(_d = (_c2 = this.fetchEventSourceHandlers.get(data.nonce)) == null ? void 0 : _c2.onmessage) == null ? void 0 : _d.call(_c2, data.message);
|
|
566
575
|
break;
|
|
567
576
|
}
|
|
568
577
|
case "abortSignal": {
|
|
@@ -584,12 +593,12 @@ class BaseMessenger {
|
|
|
584
593
|
this.targetOrigin = targetOrigin;
|
|
585
594
|
}
|
|
586
595
|
sendMessage(data, transfer) {
|
|
587
|
-
var
|
|
596
|
+
var _a2;
|
|
588
597
|
const message = {
|
|
589
598
|
__xpaiChatKit: true,
|
|
590
599
|
...data
|
|
591
600
|
};
|
|
592
|
-
(
|
|
601
|
+
(_a2 = this.target()) == null ? void 0 : _a2.postMessage(message, this.targetOrigin, transfer);
|
|
593
602
|
}
|
|
594
603
|
connect() {
|
|
595
604
|
window.addEventListener("message", this.handleMessage);
|
|
@@ -599,7 +608,7 @@ class BaseMessenger {
|
|
|
599
608
|
}
|
|
600
609
|
fetch(url, params) {
|
|
601
610
|
return new Promise((resolve, reject) => {
|
|
602
|
-
const nonce =
|
|
611
|
+
const nonce = safeRandomUUID();
|
|
603
612
|
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
604
613
|
let formData;
|
|
605
614
|
if (params.body instanceof FormData) {
|
|
@@ -611,11 +620,11 @@ class BaseMessenger {
|
|
|
611
620
|
}
|
|
612
621
|
if (params.signal) {
|
|
613
622
|
params.signal.addEventListener("abort", () => {
|
|
614
|
-
var
|
|
623
|
+
var _a2;
|
|
615
624
|
this.sendMessage({
|
|
616
625
|
type: "abortSignal",
|
|
617
626
|
nonce,
|
|
618
|
-
reason: (
|
|
627
|
+
reason: (_a2 = params.signal) == null ? void 0 : _a2.reason
|
|
619
628
|
});
|
|
620
629
|
});
|
|
621
630
|
params.signal = void 0;
|
|
@@ -628,7 +637,7 @@ class BaseMessenger {
|
|
|
628
637
|
fetchEventSource(url, params) {
|
|
629
638
|
return new Promise((resolve, reject) => {
|
|
630
639
|
const { onmessage, signal, ...rest } = params;
|
|
631
|
-
const nonce =
|
|
640
|
+
const nonce = safeRandomUUID();
|
|
632
641
|
this.handlers.set(nonce, { resolve, reject, stack: new Error().stack || "" });
|
|
633
642
|
this.fetchEventSourceHandlers.set(nonce, {
|
|
634
643
|
onmessage
|
|
@@ -888,7 +897,7 @@ function requireCommandCapability(value, context) {
|
|
|
888
897
|
return value.apply(this, args);
|
|
889
898
|
};
|
|
890
899
|
}
|
|
891
|
-
class ChatKitElementBase extends (
|
|
900
|
+
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) {
|
|
892
901
|
constructor({ profile }) {
|
|
893
902
|
super();
|
|
894
903
|
__runInitializers(_init, 5, this);
|
|
@@ -904,17 +913,19 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
904
913
|
}));
|
|
905
914
|
__privateAdd(this, _messenger, new ChatFrameMessenger({
|
|
906
915
|
fetch: (...args) => {
|
|
907
|
-
var
|
|
908
|
-
const customFetch = ((
|
|
916
|
+
var _a2;
|
|
917
|
+
const customFetch = ((_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.api) && "fetch" in __privateGet(this, _opts).api && __privateGet(this, _opts).api.fetch;
|
|
909
918
|
return customFetch ? customFetch(...args) : fetch(...args);
|
|
910
919
|
},
|
|
911
920
|
target: () => {
|
|
912
|
-
var
|
|
913
|
-
return ((
|
|
921
|
+
var _a2;
|
|
922
|
+
return ((_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.contentWindow) ?? null;
|
|
914
923
|
},
|
|
915
924
|
targetOrigin: window.location.origin,
|
|
916
925
|
handlers: {
|
|
917
|
-
onFileInputClick: ({
|
|
926
|
+
onFileInputClick: ({
|
|
927
|
+
inputAttributes
|
|
928
|
+
}) => {
|
|
918
929
|
return new Promise((resolve) => {
|
|
919
930
|
const input = document.createElement("input");
|
|
920
931
|
for (const [key, value] of Object.entries(inputAttributes)) {
|
|
@@ -938,8 +949,8 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
938
949
|
id,
|
|
939
950
|
tool_call_id
|
|
940
951
|
}) => {
|
|
941
|
-
var
|
|
942
|
-
const onClientTool = (
|
|
952
|
+
var _a2;
|
|
953
|
+
const onClientTool = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.onClientTool;
|
|
943
954
|
if (!onClientTool) {
|
|
944
955
|
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
945
956
|
`No handler for client tool calls. You'll need to add onClientTool to your ChatKit options.`
|
|
@@ -947,9 +958,12 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
947
958
|
}
|
|
948
959
|
return onClientTool({ name, params, id, tool_call_id });
|
|
949
960
|
},
|
|
950
|
-
onWidgetAction: async ({
|
|
951
|
-
|
|
952
|
-
|
|
961
|
+
onWidgetAction: async ({
|
|
962
|
+
action,
|
|
963
|
+
widgetItem
|
|
964
|
+
}) => {
|
|
965
|
+
var _a2, _b2;
|
|
966
|
+
const onAction = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.widgets) == null ? void 0 : _b2.onAction;
|
|
953
967
|
if (!onAction) {
|
|
954
968
|
__privateMethod(this, _ChatKitElementBase_instances, emitAndThrow_fn).call(this, new IntegrationError2(
|
|
955
969
|
`No handler for widget actions. You'll need to add widgets.onAction to your ChatKit options.`
|
|
@@ -958,16 +972,16 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
958
972
|
return onAction(action, widgetItem);
|
|
959
973
|
},
|
|
960
974
|
onEntitySearch: async ({ query }) => {
|
|
961
|
-
var
|
|
962
|
-
return ((
|
|
975
|
+
var _a2, _b2, _c2;
|
|
976
|
+
return ((_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onTagSearch) == null ? void 0 : _c2.call(_b2, query)) ?? [];
|
|
963
977
|
},
|
|
964
978
|
onEntityClick: async ({ entity }) => {
|
|
965
|
-
var
|
|
966
|
-
return (
|
|
979
|
+
var _a2, _b2, _c2;
|
|
980
|
+
return (_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.entities) == null ? void 0 : _b2.onClick) == null ? void 0 : _c2.call(_b2, entity);
|
|
967
981
|
},
|
|
968
982
|
onEntityPreview: async ({ entity }) => {
|
|
969
|
-
var
|
|
970
|
-
return ((
|
|
983
|
+
var _a2, _b2, _c2;
|
|
984
|
+
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 };
|
|
971
985
|
},
|
|
972
986
|
onGetClientSecret: async (currentClientSecret) => {
|
|
973
987
|
if (!__privateGet(this, _opts) || !("getClientSecret" in __privateGet(this, _opts).api) || !__privateGet(this, _opts).api.getClientSecret) {
|
|
@@ -981,15 +995,19 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
981
995
|
op,
|
|
982
996
|
params
|
|
983
997
|
}) => {
|
|
984
|
-
throw new IntegrationError2(
|
|
998
|
+
throw new IntegrationError2(
|
|
999
|
+
"ChatKit: onAddMetadataToRequest is unimplemented."
|
|
1000
|
+
);
|
|
985
1001
|
}
|
|
986
1002
|
}
|
|
987
1003
|
}));
|
|
988
1004
|
__privateAdd(this, _handleFrameLoad, () => {
|
|
989
|
-
var
|
|
1005
|
+
var _a2;
|
|
990
1006
|
this.dataset.loaded = "true";
|
|
991
|
-
this.dispatchEvent(
|
|
992
|
-
|
|
1007
|
+
this.dispatchEvent(
|
|
1008
|
+
new CustomEvent("chatkit.ready", { bubbles: true, composed: true })
|
|
1009
|
+
);
|
|
1010
|
+
(_a2 = __privateGet(this, _resolveLoaded)) == null ? void 0 : _a2.call(this);
|
|
993
1011
|
});
|
|
994
1012
|
__privateAdd(this, _initialized, false);
|
|
995
1013
|
this.profile = profile;
|
|
@@ -1048,18 +1066,20 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
1048
1066
|
__privateSet(this, _wrapper, wrapper);
|
|
1049
1067
|
__privateGet(this, _shadow).append(style);
|
|
1050
1068
|
__privateGet(this, _messenger).on("left_header_icon_click", () => {
|
|
1051
|
-
var
|
|
1052
|
-
(
|
|
1069
|
+
var _a2, _b2, _c2;
|
|
1070
|
+
(_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.leftAction) == null ? void 0 : _c2.onClick();
|
|
1053
1071
|
});
|
|
1054
1072
|
__privateGet(this, _messenger).on("right_header_icon_click", () => {
|
|
1055
|
-
var
|
|
1056
|
-
(
|
|
1073
|
+
var _a2, _b2, _c2;
|
|
1074
|
+
(_c2 = (_b2 = (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.header) == null ? void 0 : _b2.rightAction) == null ? void 0 : _c2.onClick();
|
|
1057
1075
|
});
|
|
1058
1076
|
__privateGet(this, _messenger).on("public_event", ([event, data]) => {
|
|
1059
1077
|
if (!this.capabilities.events.has(event)) return;
|
|
1060
1078
|
if (event === "error" && "error" in data) {
|
|
1061
1079
|
const error = fromPossibleFrameSafeError(data.error);
|
|
1062
|
-
this.dispatchEvent(
|
|
1080
|
+
this.dispatchEvent(
|
|
1081
|
+
new CustomEvent("chatkit.error", { detail: { error } })
|
|
1082
|
+
);
|
|
1063
1083
|
if (error instanceof IntegrationError2) {
|
|
1064
1084
|
throw error;
|
|
1065
1085
|
}
|
|
@@ -1089,8 +1109,8 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
1089
1109
|
}
|
|
1090
1110
|
}
|
|
1091
1111
|
disconnectedCallback() {
|
|
1092
|
-
var
|
|
1093
|
-
(
|
|
1112
|
+
var _a2;
|
|
1113
|
+
(_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.removeEventListener("load", __privateGet(this, _handleFrameLoad));
|
|
1094
1114
|
__privateGet(this, _messenger).disconnect();
|
|
1095
1115
|
}
|
|
1096
1116
|
applySanitizedOptions(newOptions) {
|
|
@@ -1114,58 +1134,58 @@ class ChatKitElementBase extends (_a2 = HTMLElement, _focusComposer_dec = [requi
|
|
|
1114
1134
|
}
|
|
1115
1135
|
}
|
|
1116
1136
|
async focusComposer() {
|
|
1117
|
-
var
|
|
1137
|
+
var _a2, _b2;
|
|
1118
1138
|
await __privateGet(this, _loaded);
|
|
1119
|
-
(
|
|
1139
|
+
(_a2 = __privateGet(this, _frame)) == null ? void 0 : _a2.focus();
|
|
1120
1140
|
await ((_b2 = __privateGet(this, _messenger)) == null ? void 0 : _b2.commands.focusComposer());
|
|
1121
1141
|
}
|
|
1122
1142
|
async fetchUpdates() {
|
|
1123
|
-
var
|
|
1143
|
+
var _a2;
|
|
1124
1144
|
await __privateGet(this, _loaded);
|
|
1125
|
-
await ((
|
|
1145
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.fetchUpdates());
|
|
1126
1146
|
}
|
|
1127
1147
|
async sendUserMessage(params) {
|
|
1128
|
-
var
|
|
1148
|
+
var _a2;
|
|
1129
1149
|
await __privateGet(this, _loaded);
|
|
1130
|
-
await ((
|
|
1150
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.sendUserMessage(params));
|
|
1131
1151
|
}
|
|
1132
1152
|
async setComposerValue(params) {
|
|
1133
|
-
var
|
|
1153
|
+
var _a2;
|
|
1134
1154
|
await __privateGet(this, _loaded);
|
|
1135
|
-
await ((
|
|
1155
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setComposerValue(params));
|
|
1136
1156
|
}
|
|
1137
1157
|
async setThreadId(threadId) {
|
|
1138
|
-
var
|
|
1158
|
+
var _a2;
|
|
1139
1159
|
await __privateGet(this, _loaded);
|
|
1140
|
-
await ((
|
|
1160
|
+
await ((_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setThreadId({ threadId }));
|
|
1141
1161
|
}
|
|
1142
1162
|
async shareThread() {
|
|
1143
|
-
var
|
|
1163
|
+
var _a2;
|
|
1144
1164
|
await __privateGet(this, _loaded);
|
|
1145
|
-
return (
|
|
1165
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.shareThread();
|
|
1146
1166
|
}
|
|
1147
1167
|
async sendCustomAction(action, itemId) {
|
|
1148
|
-
var
|
|
1168
|
+
var _a2;
|
|
1149
1169
|
await __privateGet(this, _loaded);
|
|
1150
|
-
return (
|
|
1170
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.sendCustomAction({ action, itemId });
|
|
1151
1171
|
}
|
|
1152
1172
|
async showHistory() {
|
|
1153
|
-
var
|
|
1173
|
+
var _a2;
|
|
1154
1174
|
await __privateGet(this, _loaded);
|
|
1155
|
-
return (
|
|
1175
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.showHistory();
|
|
1156
1176
|
}
|
|
1157
1177
|
async hideHistory() {
|
|
1158
|
-
var
|
|
1178
|
+
var _a2;
|
|
1159
1179
|
await __privateGet(this, _loaded);
|
|
1160
|
-
return (
|
|
1180
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.hideHistory();
|
|
1161
1181
|
}
|
|
1162
1182
|
async setTrainingOptOut(value) {
|
|
1163
|
-
var
|
|
1183
|
+
var _a2;
|
|
1164
1184
|
await __privateGet(this, _loaded);
|
|
1165
|
-
return (
|
|
1185
|
+
return (_a2 = __privateGet(this, _messenger)) == null ? void 0 : _a2.commands.setTrainingOptOut({ value });
|
|
1166
1186
|
}
|
|
1167
1187
|
}
|
|
1168
|
-
_init = __decoratorStart(
|
|
1188
|
+
_init = __decoratorStart(_c);
|
|
1169
1189
|
_opts = new WeakMap();
|
|
1170
1190
|
_frameUrl = new WeakMap();
|
|
1171
1191
|
_frame = new WeakMap();
|
|
@@ -1180,8 +1200,8 @@ emitAndThrow_fn = function(error) {
|
|
|
1180
1200
|
throw error;
|
|
1181
1201
|
};
|
|
1182
1202
|
setOptionsDataAttributes_fn = function(options) {
|
|
1183
|
-
var
|
|
1184
|
-
this.dataset.colorScheme = typeof options.theme === "string" ? options.theme : ((
|
|
1203
|
+
var _a2;
|
|
1204
|
+
this.dataset.colorScheme = typeof options.theme === "string" ? options.theme : ((_a2 = options.theme) == null ? void 0 : _a2.colorScheme) ?? "light";
|
|
1185
1205
|
};
|
|
1186
1206
|
getFrameUrl_fn = function() {
|
|
1187
1207
|
if (!__privateGet(this, _frameUrl)) {
|
|
@@ -1205,7 +1225,9 @@ consumeFrameUrl_fn = function(options) {
|
|
|
1205
1225
|
delete options.frameUrl;
|
|
1206
1226
|
if (frameUrl == null) return;
|
|
1207
1227
|
if (typeof frameUrl !== "string" || frameUrl.trim() === "") {
|
|
1208
|
-
throw new IntegrationError2(
|
|
1228
|
+
throw new IntegrationError2(
|
|
1229
|
+
"ChatKit frameUrl must be a non-empty string."
|
|
1230
|
+
);
|
|
1209
1231
|
}
|
|
1210
1232
|
__privateMethod(this, _ChatKitElementBase_instances, setFrameUrl_fn).call(this, frameUrl);
|
|
1211
1233
|
};
|
|
@@ -1246,8 +1268,8 @@ class ChatKitElement extends ChatKitElementBase {
|
|
|
1246
1268
|
super({ profile: "chatkit" });
|
|
1247
1269
|
}
|
|
1248
1270
|
sanitizeOptions(options) {
|
|
1249
|
-
var
|
|
1250
|
-
(
|
|
1271
|
+
var _a2;
|
|
1272
|
+
(_a2 = options.threadItemActions) == null ? true : delete _a2.share;
|
|
1251
1273
|
return options;
|
|
1252
1274
|
}
|
|
1253
1275
|
}
|