@chatcops/widget 0.4.4 → 0.5.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 +2 -2
- package/dist/chatcops.esm.js +234 -67
- package/dist/chatcops.min.js +1 -1
- package/dist/dom/bubble.d.ts +1 -0
- package/dist/dom/bubble.d.ts.map +1 -1
- package/dist/dom/fab.d.ts +1 -0
- package/dist/dom/fab.d.ts.map +1 -1
- package/dist/dom/messages.d.ts +3 -0
- package/dist/dom/messages.d.ts.map +1 -1
- package/dist/dom/panel.d.ts +3 -0
- package/dist/dom/panel.d.ts.map +1 -1
- package/dist/dom/shadow.d.ts +8 -1
- package/dist/dom/shadow.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/namespace.d.ts +7 -0
- package/dist/namespace.d.ts.map +1 -0
- package/dist/storage.d.ts +2 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/theme.d.ts +14 -0
- package/dist/theme.d.ts.map +1 -1
- package/dist/widget.d.ts +16 -4
- package/dist/widget.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,11 +116,11 @@ ChatCops.init(config) // Initialize the widget
|
|
|
116
116
|
ChatCops.open() // Open the chat panel (popup mode)
|
|
117
117
|
ChatCops.close() // Close the chat panel
|
|
118
118
|
ChatCops.destroy() // Remove widget and clean up
|
|
119
|
-
ChatCops.on(event, handler) // Subscribe to events
|
|
119
|
+
ChatCops.on(event, handler) // Subscribe to events (returns unsubscribe function)
|
|
120
120
|
ChatCops.off(event, handler) // Unsubscribe
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
Events: `open`, `close`, `message`, `error`.
|
|
123
|
+
Events: `open`, `close`, `message`, `error`, `leadCaptured`, `preChatSubmit`.
|
|
124
124
|
|
|
125
125
|
## Script Tag Attributes
|
|
126
126
|
|
package/dist/chatcops.esm.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
const widgetStyles = ":host{--cc-accent: #6366f1;--cc-accent-hover: #4f46e5;--cc-text: #ffffff;--cc-bg: #0a0a0a;--cc-bg-surface: #1a1a1a;--cc-bg-input: #2a2a2a;--cc-border: #333333;--cc-text-secondary: #a0a0a0;--cc-font: system-ui, -apple-system, sans-serif;--cc-radius: 12px;--cc-shadow: 0 8px 32px rgba(0, 0, 0, .4);--cc-fab-size: 56px;--cc-panel-width: 400px;--cc-panel-height: 560px;all:initial;font-family:var(--cc-font);font-size:14px;line-height:1.5;color:var(--cc-text);-webkit-font-smoothing:antialiased}*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}.cc-fab{position:fixed;bottom:20px;right:20px;width:var(--cc-fab-size);height:var(--cc-fab-size);border-radius:50%;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 16px #0000004d;transition:transform .2s ease,box-shadow .2s ease;z-index:10000;outline:none}.cc-fab:hover{transform:scale(1.05);box-shadow:0 6px 24px #0006}.cc-fab:active{transform:scale(.95)}.cc-fab.cc-left{right:auto;left:20px}.cc-fab svg{width:24px;height:24px;fill:var(--cc-text);transition:transform .3s ease}.cc-fab.cc-open svg{transform:rotate(90deg)}.cc-fab-badge{position:absolute;top:-2px;right:-2px;width:12px;height:12px;border-radius:50%;background:#ef4444;border:2px solid var(--cc-bg);display:none}.cc-fab-badge.cc-visible{display:block}@keyframes cc-pulse{0%,to{box-shadow:0 4px 16px #0000004d}50%{box-shadow:0 4px 16px #6366f180}}.cc-fab.cc-pulse{animation:cc-pulse 2s ease-in-out 3}.cc-panel{position:fixed;bottom:88px;right:20px;width:var(--cc-panel-width);height:var(--cc-panel-height);max-height:calc(100vh - 100px);background:var(--cc-bg);border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);display:flex;flex-direction:column;overflow:hidden;z-index:9999;opacity:0;transform:translateY(16px) scale(.95);pointer-events:none;transition:opacity .2s ease,transform .2s ease}.cc-panel.cc-visible{opacity:1;transform:translateY(0) scale(1);pointer-events:auto}.cc-panel.cc-left{right:auto;left:20px}.cc-panel.cc-inline{position:relative;bottom:auto;right:auto;left:auto;width:100%;height:100%;max-height:100%;z-index:auto;transform:none;transition:none}.cc-panel.cc-inline:not(.cc-visible){visibility:hidden}.cc-panel.cc-inline.cc-visible{transform:none}.cc-header{display:flex;align-items:center;padding:16px;background:var(--cc-bg-surface);border-bottom:1px solid var(--cc-border);flex-shrink:0}.cc-header-avatar{width:36px;height:36px;border-radius:50%;margin-right:12px;object-fit:cover}.cc-header-avatar-placeholder{width:36px;height:36px;border-radius:50%;margin-right:12px;background:var(--cc-accent);display:flex;align-items:center;justify-content:center}.cc-header-avatar-placeholder svg{width:20px;height:20px;fill:var(--cc-text)}.cc-header-info{flex:1}.cc-header-name{font-size:15px;font-weight:600;color:var(--cc-text)}.cc-header-subtitle{font-size:12px;color:var(--cc-text-secondary)}.cc-header-close{width:32px;height:32px;border-radius:8px;background:transparent;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s ease}.cc-header-close:hover{background:var(--cc-bg-input)}.cc-header-close svg{width:16px;height:16px;fill:var(--cc-text-secondary)}.cc-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px}.cc-messages::-webkit-scrollbar{width:4px}.cc-messages::-webkit-scrollbar-track{background:transparent}.cc-messages::-webkit-scrollbar-thumb{background:var(--cc-border);border-radius:2px}.cc-message{max-width:85%;padding:10px 14px;border-radius:var(--cc-radius);word-wrap:break-word;overflow-wrap:break-word;font-size:14px;line-height:1.5;display:flex;flex-direction:column;gap:8px}.cc-message-user{align-self:flex-end;background:var(--cc-accent);color:var(--cc-text);border-bottom-right-radius:4px}.cc-message-assistant{align-self:flex-start;background:var(--cc-bg-surface);color:var(--cc-text);border-bottom-left-radius:4px}.cc-message a{color:var(--cc-accent);text-decoration:underline}.cc-message-user a{color:var(--cc-text)}.cc-message code{background:#0003;padding:1px 4px;border-radius:4px;font-family:SF Mono,Cascadia Code,Consolas,monospace;font-size:13px}.cc-message pre{background:#0000004d;padding:8px 12px;border-radius:8px;overflow-x:auto;margin:4px 0}.cc-message pre code{background:transparent;padding:0}.cc-message ul,.cc-message ol{padding-left:20px;margin:4px 0}.cc-message h1,.cc-message h2,.cc-message h3,.cc-message h4,.cc-message h5,.cc-message h6{font-size:15px;font-weight:600;line-height:1.4;margin:4px 0 0}.cc-message-actions{display:flex;align-items:center}.cc-message-retry,.cc-message-regenerate{display:inline-flex;align-items:center;gap:4px;padding:4px 10px;background:transparent;border:1px solid var(--cc-border);border-radius:6px;color:var(--cc-text-secondary);font-family:var(--cc-font);font-size:12px;cursor:pointer;transition:background .15s ease,color .15s ease,opacity .15s ease}.cc-message-retry:hover,.cc-message-regenerate:hover{background:var(--cc-bg-input);color:var(--cc-text)}.cc-message-retry svg,.cc-message-regenerate svg{fill:currentColor}.cc-message-regenerate{opacity:0}.cc-message:hover .cc-message-regenerate{opacity:1}.cc-message:focus-within .cc-message-regenerate,.cc-message-regenerate:focus-visible{opacity:1}@media(hover:none){.cc-message-regenerate{opacity:1}}.cc-message-retry{border-color:#ef4444;color:#ef4444}.cc-message-retry:hover{background:#ef44441a;color:#ef4444}.cc-typing{display:flex;align-items:center;gap:4px;padding:10px 14px;align-self:flex-start;background:var(--cc-bg-surface);border-radius:var(--cc-radius);border-bottom-left-radius:4px}.cc-typing-dot{width:6px;height:6px;border-radius:50%;background:var(--cc-text-secondary);animation:cc-bounce 1.2s infinite}.cc-typing-dot:nth-child(2){animation-delay:.2s}.cc-typing-dot:nth-child(3){animation-delay:.4s}@keyframes cc-bounce{0%,60%,to{transform:translateY(0)}30%{transform:translateY(-4px)}}.cc-input-area{display:flex;align-items:flex-end;padding:12px 16px;border-top:1px solid var(--cc-border);background:var(--cc-bg);gap:8px}.cc-input{flex:1;background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;line-height:1.5;resize:none;outline:none;max-height:96px;overflow-y:auto;transition:border-color .15s ease}.cc-input:focus{border-color:var(--cc-accent);outline:2px solid var(--cc-accent);outline-offset:1px}.cc-input::placeholder{color:var(--cc-text-secondary)}.cc-send-btn{width:36px;height:36px;border-radius:8px;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:background .15s ease,opacity .15s ease}.cc-send-btn:hover{background:var(--cc-accent-hover)}.cc-send-btn:disabled{opacity:.4;cursor:not-allowed}.cc-send-btn svg{width:16px;height:16px;fill:var(--cc-text)}.cc-footer{padding:6px 16px;text-align:center;font-size:11px;color:var(--cc-text-secondary);border-top:1px solid var(--cc-border)}.cc-footer a{color:var(--cc-text-secondary);text-decoration:none}.cc-footer a:hover{text-decoration:underline}.cc-bubble{position:fixed;bottom:84px;right:20px;background:var(--cc-bg-surface);color:var(--cc-text);padding:10px 16px;border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);max-width:260px;font-size:13px;line-height:1.4;z-index:9998;opacity:0;transform:translateY(8px);pointer-events:none;transition:opacity .3s ease,transform .3s ease;cursor:pointer}.cc-bubble.cc-visible{opacity:1;transform:translateY(0);pointer-events:auto}.cc-bubble.cc-left{right:auto;left:20px}.cc-bubble-close{position:absolute;top:-8px;right:-8px;width:20px;height:20px;border-radius:50%;background:var(--cc-bg);border:1px solid var(--cc-border);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:10px;color:var(--cc-text-secondary)}.cc-hidden{display:none}.cc-sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cc-messages-wrapper{flex:1;display:flex;flex-direction:column;min-height:0}.cc-prechat{flex:1;overflow-y:auto;padding:24px 16px;display:flex;flex-direction:column;gap:16px}.cc-prechat-title{font-size:18px;font-weight:600;color:var(--cc-text)}.cc-prechat-subtitle{font-size:13px;color:var(--cc-text-secondary);margin-top:-8px}.cc-prechat-fields{display:flex;flex-direction:column;gap:14px}.cc-prechat-field{display:flex;flex-direction:column;gap:4px}.cc-prechat-label{font-size:13px;font-weight:500;color:var(--cc-text)}.cc-prechat-label .cc-required{color:#ef4444;margin-left:2px}.cc-prechat-input,.cc-prechat-select,.cc-prechat-textarea{background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;outline:none;transition:border-color .15s ease}.cc-prechat-input:focus,.cc-prechat-select:focus,.cc-prechat-textarea:focus{border-color:var(--cc-accent)}.cc-prechat-select{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}.cc-prechat-textarea{resize:none;line-height:1.5}.cc-prechat-error{font-size:12px;color:#ef4444;min-height:0}.cc-prechat-error:empty{display:none}.cc-prechat-submit{background:var(--cc-accent);color:var(--cc-text);border:none;border-radius:8px;padding:10px 16px;font-family:var(--cc-font);font-size:14px;font-weight:500;cursor:pointer;transition:background .15s ease;margin-top:8px}.cc-prechat-submit:hover{background:var(--cc-accent-hover)}.cc-prechat-submit:disabled{opacity:.5;cursor:not-allowed}@media(max-width:768px){.cc-fab.cc-open{display:none}.cc-panel:not(.cc-inline){width:100%;height:100%;max-height:100%;bottom:0;right:0;left:0;border-radius:0;border:none}.cc-panel.cc-left:not(.cc-inline){left:0}.cc-bubble{bottom:84px;right:16px;left:16px;max-width:none}}.cc-fab:focus-visible,.cc-header-close:focus-visible,.cc-send-btn:focus-visible,.cc-message-retry:focus-visible,.cc-message-regenerate:focus-visible,.cc-bubble-close:focus-visible,.cc-prechat-submit:focus-visible{outline:2px solid var(--cc-accent);outline-offset:3px}@media(prefers-reduced-motion:reduce){.cc-fab.cc-pulse,.cc-typing-dot{animation:none}.cc-panel,.cc-bubble{transition:none}}";
|
|
4
|
+
const widgetStyles = ":host{--cc-accent: #6366f1;--cc-accent-hover: #4f46e5;--cc-on-accent: #ffffff;--cc-accent-contrast: #6164ec;--cc-text: #ffffff;--cc-bg: #0a0a0a;--cc-bg-surface: #1a1a1a;--cc-bg-input: #2a2a2a;--cc-border: #333333;--cc-text-secondary: #a0a0a0;--cc-font: system-ui, -apple-system, sans-serif;--cc-radius: 12px;--cc-shadow: 0 8px 32px rgba(0, 0, 0, .4);--cc-fab-size: 56px;--cc-panel-width: 400px;--cc-panel-height: 560px;all:initial;font-family:var(--cc-font);font-size:14px;line-height:1.5;color:var(--cc-text);-webkit-font-smoothing:antialiased}*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}.cc-fab{position:fixed;bottom:20px;right:20px;width:var(--cc-fab-size);height:var(--cc-fab-size);border-radius:50%;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 16px #0000004d;transition:transform .2s ease,box-shadow .2s ease;z-index:10000;outline:none}.cc-fab:hover{transform:scale(1.05);box-shadow:0 6px 24px #0006}.cc-fab:active{transform:scale(.95)}.cc-fab.cc-left{right:auto;left:20px}.cc-fab svg{width:24px;height:24px;fill:var(--cc-on-accent);transition:transform .3s ease}.cc-fab.cc-open svg{transform:rotate(90deg)}.cc-fab-badge{position:absolute;top:-2px;right:-2px;width:12px;height:12px;border-radius:50%;background:#ef4444;border:2px solid var(--cc-bg);display:none}.cc-fab-badge.cc-visible{display:block}@keyframes cc-pulse{0%,to{box-shadow:0 4px 16px #0000004d}50%{box-shadow:0 4px 16px #6366f180}}.cc-fab.cc-pulse{animation:cc-pulse 2s ease-in-out 3}.cc-panel{position:fixed;bottom:88px;right:20px;width:var(--cc-panel-width);height:var(--cc-panel-height);max-height:calc(100vh - 100px);background:var(--cc-bg);border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);display:flex;flex-direction:column;overflow:hidden;z-index:9999;opacity:0;transform:translateY(16px) scale(.95);pointer-events:none;transition:opacity .2s ease,transform .2s ease}.cc-panel.cc-visible{opacity:1;transform:translateY(0) scale(1);pointer-events:auto}.cc-panel.cc-left{right:auto;left:20px}.cc-panel.cc-inline{position:relative;bottom:auto;right:auto;left:auto;width:100%;height:100%;max-height:100%;z-index:auto;transform:none;transition:none}.cc-panel.cc-inline:not(.cc-visible){visibility:hidden}.cc-panel.cc-inline.cc-visible{transform:none}.cc-header{display:flex;align-items:center;padding:16px;background:var(--cc-bg-surface);border-bottom:1px solid var(--cc-border);flex-shrink:0}.cc-header-avatar{width:36px;height:36px;border-radius:50%;margin-right:12px;object-fit:cover}.cc-header-avatar-placeholder{width:36px;height:36px;border-radius:50%;margin-right:12px;background:var(--cc-accent);display:flex;align-items:center;justify-content:center}.cc-header-avatar-placeholder svg{width:20px;height:20px;fill:var(--cc-on-accent)}.cc-header-info{flex:1}.cc-header-name{font-size:15px;font-weight:600;color:var(--cc-text)}.cc-header-subtitle{font-size:12px;color:var(--cc-text-secondary)}.cc-header-close{width:32px;height:32px;border-radius:8px;background:transparent;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s ease}.cc-header-close:hover{background:var(--cc-bg-input)}.cc-header-close svg{width:16px;height:16px;fill:var(--cc-text-secondary)}.cc-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px}.cc-messages::-webkit-scrollbar{width:4px}.cc-messages::-webkit-scrollbar-track{background:transparent}.cc-messages::-webkit-scrollbar-thumb{background:var(--cc-border);border-radius:2px}.cc-message{max-width:85%;padding:10px 14px;border-radius:var(--cc-radius);word-wrap:break-word;overflow-wrap:break-word;font-size:14px;line-height:1.5;display:flex;flex-direction:column;gap:8px}.cc-message-user{align-self:flex-end;background:var(--cc-accent-contrast);color:var(--cc-on-accent);border-bottom-right-radius:4px}.cc-message-assistant{align-self:flex-start;background:var(--cc-bg-surface);color:var(--cc-text);border-bottom-left-radius:4px}.cc-message a{color:var(--cc-accent);text-decoration:underline}.cc-message-user a{color:var(--cc-on-accent)}.cc-message-error-note{margin-top:6px;font-size:12px;color:var(--cc-text-secondary)}.cc-message code{background:#0003;padding:1px 4px;border-radius:4px;font-family:SF Mono,Cascadia Code,Consolas,monospace;font-size:13px}.cc-message pre{background:#0000004d;padding:8px 12px;border-radius:8px;overflow-x:auto;margin:4px 0}.cc-message pre code{background:transparent;padding:0}.cc-message ul,.cc-message ol{padding-left:20px;margin:4px 0}.cc-message h1,.cc-message h2,.cc-message h3,.cc-message h4,.cc-message h5,.cc-message h6{font-size:15px;font-weight:600;line-height:1.4;margin:4px 0 0}.cc-message-actions{display:flex;align-items:center}.cc-message-retry,.cc-message-regenerate{display:inline-flex;align-items:center;gap:4px;padding:4px 10px;background:transparent;border:1px solid var(--cc-border);border-radius:6px;color:var(--cc-text-secondary);font-family:var(--cc-font);font-size:12px;cursor:pointer;transition:background .15s ease,color .15s ease,opacity .15s ease}.cc-message-retry:hover,.cc-message-regenerate:hover{background:var(--cc-bg-input);color:var(--cc-text)}.cc-message-retry svg,.cc-message-regenerate svg{fill:currentColor}.cc-message-regenerate{opacity:0}.cc-message:hover .cc-message-regenerate{opacity:1}.cc-message:focus-within .cc-message-regenerate,.cc-message-regenerate:focus-visible{opacity:1}@media(hover:none){.cc-message-regenerate{opacity:1}}.cc-message-retry{border-color:#ef4444;color:#ef4444}.cc-message-retry:hover{background:#ef44441a;color:#ef4444}.cc-typing{display:flex;align-items:center;gap:4px;padding:10px 14px;align-self:flex-start;background:var(--cc-bg-surface);border-radius:var(--cc-radius);border-bottom-left-radius:4px}.cc-typing-dot{width:6px;height:6px;border-radius:50%;background:var(--cc-text-secondary);animation:cc-bounce 1.2s infinite}.cc-typing-dot:nth-child(2){animation-delay:.2s}.cc-typing-dot:nth-child(3){animation-delay:.4s}@keyframes cc-bounce{0%,60%,to{transform:translateY(0)}30%{transform:translateY(-4px)}}.cc-input-area{display:flex;align-items:flex-end;padding:12px 16px;border-top:1px solid var(--cc-border);background:var(--cc-bg);gap:8px}.cc-input{flex:1;background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;line-height:1.5;resize:none;outline:none;max-height:96px;overflow-y:auto;transition:border-color .15s ease}.cc-input:focus{border-color:var(--cc-accent);outline:2px solid var(--cc-accent);outline-offset:1px}.cc-input::placeholder{color:var(--cc-text-secondary)}.cc-send-btn{width:36px;height:36px;border-radius:8px;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:background .15s ease,opacity .15s ease}.cc-send-btn:hover{background:var(--cc-accent-hover)}.cc-send-btn:disabled{opacity:.4;cursor:not-allowed}.cc-send-btn svg{width:16px;height:16px;fill:var(--cc-on-accent)}.cc-footer{padding:6px 16px;text-align:center;font-size:11px;color:var(--cc-text-secondary);border-top:1px solid var(--cc-border)}.cc-footer a{color:var(--cc-text-secondary);text-decoration:none}.cc-footer a:hover{text-decoration:underline}.cc-bubble{position:fixed;bottom:84px;right:20px;background:var(--cc-bg-surface);color:var(--cc-text);padding:10px 16px;border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);max-width:260px;font-size:13px;line-height:1.4;z-index:9998;opacity:0;transform:translateY(8px);pointer-events:none;transition:opacity .3s ease,transform .3s ease;cursor:pointer}.cc-bubble.cc-visible{opacity:1;transform:translateY(0);pointer-events:auto}.cc-bubble.cc-left{right:auto;left:20px}.cc-bubble-close{position:absolute;top:-8px;right:-8px;width:20px;height:20px;border-radius:50%;background:var(--cc-bg);border:1px solid var(--cc-border);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:10px;color:var(--cc-text-secondary)}.cc-hidden{display:none}.cc-sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cc-messages-wrapper{flex:1;display:flex;flex-direction:column;min-height:0}.cc-prechat{flex:1;overflow-y:auto;padding:24px 16px;display:flex;flex-direction:column;gap:16px}.cc-prechat-title{font-size:18px;font-weight:600;color:var(--cc-text)}.cc-prechat-subtitle{font-size:13px;color:var(--cc-text-secondary);margin-top:-8px}.cc-prechat-fields{display:flex;flex-direction:column;gap:14px}.cc-prechat-field{display:flex;flex-direction:column;gap:4px}.cc-prechat-label{font-size:13px;font-weight:500;color:var(--cc-text)}.cc-prechat-label .cc-required{color:#ef4444;margin-left:2px}.cc-prechat-input,.cc-prechat-select,.cc-prechat-textarea{background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;outline:none;transition:border-color .15s ease}.cc-prechat-input:focus,.cc-prechat-select:focus,.cc-prechat-textarea:focus{border-color:var(--cc-accent)}.cc-prechat-select{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}.cc-prechat-textarea{resize:none;line-height:1.5}.cc-prechat-error{font-size:12px;color:#ef4444;min-height:0}.cc-prechat-error:empty{display:none}.cc-prechat-submit{background:var(--cc-accent-contrast);color:var(--cc-on-accent);border:none;border-radius:8px;padding:10px 16px;font-family:var(--cc-font);font-size:14px;font-weight:500;cursor:pointer;transition:background .15s ease;margin-top:8px}.cc-prechat-submit:hover{background:var(--cc-accent-hover)}.cc-prechat-submit:disabled{opacity:.5;cursor:not-allowed}@media(max-width:768px){.cc-fab.cc-open{display:none}.cc-panel:not(.cc-inline){width:100%;height:100%;max-height:100%;bottom:0;right:0;left:0;border-radius:0;border:none}.cc-panel.cc-left:not(.cc-inline){left:0}.cc-bubble{bottom:84px;right:16px;left:16px;max-width:none}}.cc-fab:focus-visible,.cc-header-close:focus-visible,.cc-send-btn:focus-visible,.cc-message-retry:focus-visible,.cc-message-regenerate:focus-visible,.cc-bubble-close:focus-visible,.cc-prechat-submit:focus-visible{outline:2px solid var(--cc-accent);outline-offset:3px}@media(prefers-reduced-motion:reduce){.cc-fab.cc-pulse,.cc-typing-dot{animation:none}.cc-panel,.cc-bubble{transition:none}}";
|
|
5
|
+
const HOST_ID = "chatcops-root";
|
|
5
6
|
function createShadowRoot(container) {
|
|
6
7
|
const host = document.createElement("div");
|
|
7
|
-
host.id =
|
|
8
|
+
host.id = nextHostId();
|
|
9
|
+
host.className = HOST_ID;
|
|
8
10
|
if (container) {
|
|
9
11
|
container.appendChild(host);
|
|
10
12
|
} else {
|
|
@@ -16,54 +18,14 @@ function createShadowRoot(container) {
|
|
|
16
18
|
shadow.appendChild(style);
|
|
17
19
|
return shadow;
|
|
18
20
|
}
|
|
19
|
-
function destroyShadowRoot(
|
|
20
|
-
|
|
21
|
-
const host = searchRoot.querySelector("#chatcops-root") ?? document.getElementById("chatcops-root");
|
|
22
|
-
if (host) host.remove();
|
|
21
|
+
function destroyShadowRoot(shadow) {
|
|
22
|
+
shadow == null ? void 0 : shadow.host.remove();
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
__publicField(this, "badge");
|
|
30
|
-
__publicField(this, "isOpen", false);
|
|
31
|
-
__publicField(this, "openLabel");
|
|
32
|
-
__publicField(this, "closeLabel");
|
|
33
|
-
this.openLabel = options.openLabel;
|
|
34
|
-
this.closeLabel = options.closeLabel;
|
|
35
|
-
this.el = document.createElement("button");
|
|
36
|
-
this.el.className = "cc-fab cc-pulse";
|
|
37
|
-
this.el.setAttribute("aria-label", this.openLabel);
|
|
38
|
-
if (options.position === "bottom-left") {
|
|
39
|
-
this.el.classList.add("cc-left");
|
|
40
|
-
}
|
|
41
|
-
this.el.innerHTML = CHAT_ICON;
|
|
42
|
-
this.badge = document.createElement("div");
|
|
43
|
-
this.badge.className = "cc-fab-badge";
|
|
44
|
-
this.el.appendChild(this.badge);
|
|
45
|
-
this.el.addEventListener("click", () => {
|
|
46
|
-
this.el.classList.remove("cc-pulse");
|
|
47
|
-
options.onClick();
|
|
48
|
-
});
|
|
49
|
-
root.appendChild(this.el);
|
|
50
|
-
}
|
|
51
|
-
setOpen(open) {
|
|
52
|
-
this.isOpen = open;
|
|
53
|
-
this.el.innerHTML = open ? CLOSE_ICON$1 : CHAT_ICON;
|
|
54
|
-
if (!open) this.el.appendChild(this.badge);
|
|
55
|
-
this.el.classList.toggle("cc-open", open);
|
|
56
|
-
this.el.setAttribute("aria-label", open ? this.closeLabel : this.openLabel);
|
|
57
|
-
}
|
|
58
|
-
showBadge() {
|
|
59
|
-
this.badge.classList.add("cc-visible");
|
|
60
|
-
}
|
|
61
|
-
hideBadge() {
|
|
62
|
-
this.badge.classList.remove("cc-visible");
|
|
63
|
-
}
|
|
64
|
-
destroy() {
|
|
65
|
-
this.el.remove();
|
|
66
|
-
}
|
|
24
|
+
function nextHostId() {
|
|
25
|
+
if (!document.getElementById(HOST_ID)) return HOST_ID;
|
|
26
|
+
let n = 2;
|
|
27
|
+
while (document.getElementById(`${HOST_ID}-${n}`)) n += 1;
|
|
28
|
+
return `${HOST_ID}-${n}`;
|
|
67
29
|
}
|
|
68
30
|
const ESCAPE_MAP = {
|
|
69
31
|
"&": "&",
|
|
@@ -149,7 +111,7 @@ class Messages {
|
|
|
149
111
|
return el;
|
|
150
112
|
}
|
|
151
113
|
updateMessage(msg) {
|
|
152
|
-
const el = this.
|
|
114
|
+
const el = this.findMessage(msg.id);
|
|
153
115
|
if (el) {
|
|
154
116
|
this.renderMessageElement(el, msg);
|
|
155
117
|
this.scrollToBottom();
|
|
@@ -175,7 +137,7 @@ class Messages {
|
|
|
175
137
|
this.typingEl = null;
|
|
176
138
|
}
|
|
177
139
|
removeMessage(id) {
|
|
178
|
-
const el = this.
|
|
140
|
+
const el = this.findMessage(id);
|
|
179
141
|
el == null ? void 0 : el.remove();
|
|
180
142
|
}
|
|
181
143
|
clearRegenerateButtons() {
|
|
@@ -186,7 +148,7 @@ class Messages {
|
|
|
186
148
|
var _a;
|
|
187
149
|
this.clearRegenerateButtons();
|
|
188
150
|
if (!((_a = this.actions) == null ? void 0 : _a.onRegenerate)) return;
|
|
189
|
-
const msgEl = this.
|
|
151
|
+
const msgEl = this.findMessage(messageId);
|
|
190
152
|
if (!msgEl || !msgEl.classList.contains("cc-message-assistant")) return;
|
|
191
153
|
const actions = this.ensureActionsContainer(msgEl);
|
|
192
154
|
actions.appendChild(this.createActionButton({
|
|
@@ -202,6 +164,10 @@ class Messages {
|
|
|
202
164
|
setVisible(visible) {
|
|
203
165
|
this.container.classList.toggle("cc-hidden", !visible);
|
|
204
166
|
}
|
|
167
|
+
findMessage(id) {
|
|
168
|
+
const found = Array.from(this.container.children).find((el) => el.dataset.id === id);
|
|
169
|
+
return found ?? null;
|
|
170
|
+
}
|
|
205
171
|
scrollToBottom() {
|
|
206
172
|
this.container.scrollTop = this.container.scrollHeight;
|
|
207
173
|
}
|
|
@@ -233,6 +199,12 @@ class Messages {
|
|
|
233
199
|
content.className = "cc-message-content";
|
|
234
200
|
content.innerHTML = msg.role === "assistant" ? renderMarkdown(msg.content) : this.escapeHtml(msg.content);
|
|
235
201
|
el.appendChild(content);
|
|
202
|
+
if (msg.status === "error" && msg.errorText) {
|
|
203
|
+
const note = document.createElement("div");
|
|
204
|
+
note.className = "cc-message-error-note";
|
|
205
|
+
note.textContent = msg.errorText;
|
|
206
|
+
el.appendChild(note);
|
|
207
|
+
}
|
|
236
208
|
const actions = this.createActionsContainer(msg);
|
|
237
209
|
if (actions) {
|
|
238
210
|
el.appendChild(actions);
|
|
@@ -352,8 +324,9 @@ class Input {
|
|
|
352
324
|
this.textarea.style.height = Math.min(this.textarea.scrollHeight, maxHeight) + "px";
|
|
353
325
|
}
|
|
354
326
|
}
|
|
327
|
+
const PANEL_ID = "cc-panel";
|
|
355
328
|
const BOT_ICON = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z"/></svg>`;
|
|
356
|
-
const CLOSE_ICON = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>`;
|
|
329
|
+
const CLOSE_ICON$1 = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>`;
|
|
357
330
|
class Panel {
|
|
358
331
|
constructor(root, options) {
|
|
359
332
|
__publicField(this, "el");
|
|
@@ -370,6 +343,15 @@ class Panel {
|
|
|
370
343
|
if (options.position === "bottom-left") {
|
|
371
344
|
this.el.classList.add("cc-left");
|
|
372
345
|
}
|
|
346
|
+
if (!options.inline) {
|
|
347
|
+
this.el.id = PANEL_ID;
|
|
348
|
+
this.el.setAttribute("role", "dialog");
|
|
349
|
+
this.el.setAttribute("aria-label", options.branding.name);
|
|
350
|
+
this.el.addEventListener("keydown", (e) => {
|
|
351
|
+
if (e.key === "Escape") options.onClose();
|
|
352
|
+
});
|
|
353
|
+
this.setHidden(true);
|
|
354
|
+
}
|
|
373
355
|
const header = document.createElement("div");
|
|
374
356
|
header.className = "cc-header";
|
|
375
357
|
if (options.branding.avatar) {
|
|
@@ -392,7 +374,7 @@ class Panel {
|
|
|
392
374
|
const closeBtn = document.createElement("button");
|
|
393
375
|
closeBtn.className = "cc-header-close";
|
|
394
376
|
closeBtn.setAttribute("aria-label", options.closeLabel);
|
|
395
|
-
closeBtn.innerHTML = CLOSE_ICON;
|
|
377
|
+
closeBtn.innerHTML = CLOSE_ICON$1;
|
|
396
378
|
closeBtn.addEventListener("click", options.onClose);
|
|
397
379
|
header.appendChild(closeBtn);
|
|
398
380
|
}
|
|
@@ -419,11 +401,16 @@ class Panel {
|
|
|
419
401
|
show() {
|
|
420
402
|
this.el.classList.add("cc-visible");
|
|
421
403
|
if (!this.inline) {
|
|
404
|
+
this.setHidden(false);
|
|
422
405
|
this.input.focus();
|
|
423
406
|
}
|
|
424
407
|
}
|
|
425
408
|
hide() {
|
|
426
409
|
this.el.classList.remove("cc-visible");
|
|
410
|
+
if (!this.inline) this.setHidden(true);
|
|
411
|
+
}
|
|
412
|
+
containsFocus() {
|
|
413
|
+
return this.el.contains(this.el.getRootNode().activeElement);
|
|
427
414
|
}
|
|
428
415
|
get isVisible() {
|
|
429
416
|
return this.el.classList.contains("cc-visible");
|
|
@@ -440,12 +427,68 @@ class Panel {
|
|
|
440
427
|
destroy() {
|
|
441
428
|
this.el.remove();
|
|
442
429
|
}
|
|
430
|
+
// A closed popup can't be focused or read by screen readers.
|
|
431
|
+
setHidden(hidden) {
|
|
432
|
+
this.el.toggleAttribute("inert", hidden);
|
|
433
|
+
if (hidden) this.el.setAttribute("aria-hidden", "true");
|
|
434
|
+
else this.el.removeAttribute("aria-hidden");
|
|
435
|
+
}
|
|
443
436
|
escapeHtml(text) {
|
|
444
437
|
const div = document.createElement("div");
|
|
445
438
|
div.textContent = text;
|
|
446
439
|
return div.innerHTML;
|
|
447
440
|
}
|
|
448
441
|
}
|
|
442
|
+
const CHAT_ICON = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12z"/><path d="M7 9h10v2H7zm0-3h10v2H7z"/></svg>`;
|
|
443
|
+
const CLOSE_ICON = `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>`;
|
|
444
|
+
class FAB {
|
|
445
|
+
constructor(root, options) {
|
|
446
|
+
__publicField(this, "el");
|
|
447
|
+
__publicField(this, "badge");
|
|
448
|
+
__publicField(this, "isOpen", false);
|
|
449
|
+
__publicField(this, "openLabel");
|
|
450
|
+
__publicField(this, "closeLabel");
|
|
451
|
+
this.openLabel = options.openLabel;
|
|
452
|
+
this.closeLabel = options.closeLabel;
|
|
453
|
+
this.el = document.createElement("button");
|
|
454
|
+
this.el.className = "cc-fab cc-pulse";
|
|
455
|
+
this.el.setAttribute("aria-label", this.openLabel);
|
|
456
|
+
this.el.setAttribute("aria-expanded", "false");
|
|
457
|
+
this.el.setAttribute("aria-controls", PANEL_ID);
|
|
458
|
+
if (options.position === "bottom-left") {
|
|
459
|
+
this.el.classList.add("cc-left");
|
|
460
|
+
}
|
|
461
|
+
this.el.innerHTML = CHAT_ICON;
|
|
462
|
+
this.badge = document.createElement("div");
|
|
463
|
+
this.badge.className = "cc-fab-badge";
|
|
464
|
+
this.el.appendChild(this.badge);
|
|
465
|
+
this.el.addEventListener("click", () => {
|
|
466
|
+
this.el.classList.remove("cc-pulse");
|
|
467
|
+
options.onClick();
|
|
468
|
+
});
|
|
469
|
+
root.appendChild(this.el);
|
|
470
|
+
}
|
|
471
|
+
setOpen(open) {
|
|
472
|
+
this.isOpen = open;
|
|
473
|
+
this.el.innerHTML = open ? CLOSE_ICON : CHAT_ICON;
|
|
474
|
+
if (!open) this.el.appendChild(this.badge);
|
|
475
|
+
this.el.classList.toggle("cc-open", open);
|
|
476
|
+
this.el.setAttribute("aria-label", open ? this.closeLabel : this.openLabel);
|
|
477
|
+
this.el.setAttribute("aria-expanded", String(open));
|
|
478
|
+
}
|
|
479
|
+
focus() {
|
|
480
|
+
this.el.focus();
|
|
481
|
+
}
|
|
482
|
+
showBadge() {
|
|
483
|
+
this.badge.classList.add("cc-visible");
|
|
484
|
+
}
|
|
485
|
+
hideBadge() {
|
|
486
|
+
this.badge.classList.remove("cc-visible");
|
|
487
|
+
}
|
|
488
|
+
destroy() {
|
|
489
|
+
this.el.remove();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
449
492
|
const BUBBLE_SHOWN_KEY = "chatcops_bubble_shown";
|
|
450
493
|
class WelcomeBubble {
|
|
451
494
|
constructor(root, options) {
|
|
@@ -457,6 +500,7 @@ class WelcomeBubble {
|
|
|
457
500
|
this.el.classList.add("cc-left");
|
|
458
501
|
}
|
|
459
502
|
this.el.textContent = options.text;
|
|
503
|
+
this.setHidden(true);
|
|
460
504
|
const closeBtn = document.createElement("button");
|
|
461
505
|
closeBtn.type = "button";
|
|
462
506
|
closeBtn.className = "cc-bubble-close";
|
|
@@ -481,15 +525,22 @@ class WelcomeBubble {
|
|
|
481
525
|
}
|
|
482
526
|
this.timerId = setTimeout(() => {
|
|
483
527
|
this.el.classList.add("cc-visible");
|
|
528
|
+
this.setHidden(false);
|
|
484
529
|
}, options.delay ?? 3e3);
|
|
485
530
|
}
|
|
486
531
|
hide() {
|
|
487
532
|
this.el.classList.remove("cc-visible");
|
|
533
|
+
this.setHidden(true);
|
|
488
534
|
if (this.timerId) {
|
|
489
535
|
clearTimeout(this.timerId);
|
|
490
536
|
this.timerId = null;
|
|
491
537
|
}
|
|
492
538
|
}
|
|
539
|
+
setHidden(hidden) {
|
|
540
|
+
this.el.toggleAttribute("inert", hidden);
|
|
541
|
+
if (hidden) this.el.setAttribute("aria-hidden", "true");
|
|
542
|
+
else this.el.removeAttribute("aria-hidden");
|
|
543
|
+
}
|
|
493
544
|
destroy() {
|
|
494
545
|
this.hide();
|
|
495
546
|
this.el.remove();
|
|
@@ -605,10 +656,14 @@ class ChatClient {
|
|
|
605
656
|
}
|
|
606
657
|
}
|
|
607
658
|
const KEY_PREFIX = "chatcops_conversation";
|
|
659
|
+
const SESSION_KEY_PREFIX = "chatcops_session_id";
|
|
608
660
|
class ConversationStorage {
|
|
661
|
+
/** Without a siteId the keys are the ones the widget has always used. */
|
|
609
662
|
constructor(siteId) {
|
|
610
663
|
__publicField(this, "key");
|
|
664
|
+
__publicField(this, "sessionKey");
|
|
611
665
|
this.key = siteId ? `${KEY_PREFIX}_${siteId}` : KEY_PREFIX;
|
|
666
|
+
this.sessionKey = siteId ? `${SESSION_KEY_PREFIX}_${siteId}` : SESSION_KEY_PREFIX;
|
|
612
667
|
}
|
|
613
668
|
load() {
|
|
614
669
|
try {
|
|
@@ -636,12 +691,11 @@ class ConversationStorage {
|
|
|
636
691
|
}
|
|
637
692
|
}
|
|
638
693
|
getSessionId() {
|
|
639
|
-
const SESSION_KEY = "chatcops_session_id";
|
|
640
694
|
try {
|
|
641
|
-
let id = sessionStorage.getItem(
|
|
695
|
+
let id = sessionStorage.getItem(this.sessionKey);
|
|
642
696
|
if (!id) {
|
|
643
697
|
id = crypto.randomUUID();
|
|
644
|
-
sessionStorage.setItem(
|
|
698
|
+
sessionStorage.setItem(this.sessionKey, id);
|
|
645
699
|
}
|
|
646
700
|
return id;
|
|
647
701
|
} catch {
|
|
@@ -684,11 +738,53 @@ class ConversationStorage {
|
|
|
684
738
|
}
|
|
685
739
|
}
|
|
686
740
|
}
|
|
741
|
+
const DEFAULT = "";
|
|
742
|
+
const CLAIMS_KEY = Symbol.for("chatcops.storageClaims");
|
|
743
|
+
const store = globalThis;
|
|
744
|
+
const claims = store[CLAIMS_KEY] ?? (store[CLAIMS_KEY] = /* @__PURE__ */ new Map());
|
|
745
|
+
function inUse(name) {
|
|
746
|
+
const live = claims.get(name);
|
|
747
|
+
if (!live) return false;
|
|
748
|
+
for (const isLive of live) {
|
|
749
|
+
if (!isLive()) live.delete(isLive);
|
|
750
|
+
}
|
|
751
|
+
if (live.size === 0) claims.delete(name);
|
|
752
|
+
return live.size > 0;
|
|
753
|
+
}
|
|
754
|
+
function claimNamespace(siteId, mode, isLive) {
|
|
755
|
+
let name = siteId ?? DEFAULT;
|
|
756
|
+
if (siteId === void 0 && inUse(DEFAULT)) {
|
|
757
|
+
name = mode;
|
|
758
|
+
for (let n = 2; inUse(name); n += 1) name = `${mode}-${n}`;
|
|
759
|
+
console.warn(
|
|
760
|
+
`[chatcops] Another widget on this page already uses the default storage, so this one keeps its conversation under "${name}". Set a \`siteId\` on each widget to name them yourself.`
|
|
761
|
+
);
|
|
762
|
+
} else if (siteId !== void 0 && inUse(siteId)) {
|
|
763
|
+
console.warn(`[chatcops] Two widgets on this page use the siteId "${siteId}", so they share one conversation.`);
|
|
764
|
+
}
|
|
765
|
+
if (!claims.has(name)) claims.set(name, /* @__PURE__ */ new Set());
|
|
766
|
+
claims.get(name).add(isLive);
|
|
767
|
+
return {
|
|
768
|
+
siteId: name === DEFAULT ? void 0 : name,
|
|
769
|
+
release() {
|
|
770
|
+
var _a, _b;
|
|
771
|
+
(_a = claims.get(name)) == null ? void 0 : _a.delete(isLive);
|
|
772
|
+
if (((_b = claims.get(name)) == null ? void 0 : _b.size) === 0) claims.delete(name);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
687
776
|
function applyTheme(root, theme) {
|
|
688
777
|
const host = root.host;
|
|
689
778
|
if (theme.accent) {
|
|
690
779
|
host.style.setProperty("--cc-accent", theme.accent);
|
|
691
780
|
host.style.setProperty("--cc-accent-hover", darken(theme.accent, 10));
|
|
781
|
+
const pair = accentTextColors(theme.accent);
|
|
782
|
+
if (pair) {
|
|
783
|
+
host.style.setProperty("--cc-on-accent", pair.onAccent);
|
|
784
|
+
host.style.setProperty("--cc-accent-contrast", pair.background);
|
|
785
|
+
} else {
|
|
786
|
+
host.style.setProperty("--cc-accent-contrast", theme.accent);
|
|
787
|
+
}
|
|
692
788
|
}
|
|
693
789
|
if (theme.textColor) {
|
|
694
790
|
host.style.setProperty("--cc-text", theme.textColor);
|
|
@@ -711,6 +807,34 @@ function toCssLength(value) {
|
|
|
711
807
|
const text = String(value).trim();
|
|
712
808
|
return /^(?:\d+(?:\.\d+)?|\.\d+)$/.test(text) ? `${text}px` : text;
|
|
713
809
|
}
|
|
810
|
+
const WHITE = "#ffffff";
|
|
811
|
+
const NEAR_BLACK = "#0a0a0a";
|
|
812
|
+
const MIN_TEXT_CONTRAST = 4.5;
|
|
813
|
+
function isHex(color) {
|
|
814
|
+
return /^#?[\da-f]{3}(?:[\da-f]{3})?$/i.test(color.trim());
|
|
815
|
+
}
|
|
816
|
+
function relativeLuminance(hex) {
|
|
817
|
+
const channels = parseHex(hex).map((value) => {
|
|
818
|
+
const c = value / 255;
|
|
819
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
820
|
+
});
|
|
821
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2];
|
|
822
|
+
}
|
|
823
|
+
function contrastRatio(a, b) {
|
|
824
|
+
const [light, dark] = [relativeLuminance(a), relativeLuminance(b)].sort((x, y) => y - x);
|
|
825
|
+
return (light + 0.05) / (dark + 0.05);
|
|
826
|
+
}
|
|
827
|
+
function accentTextColors(accent) {
|
|
828
|
+
if (!isHex(accent)) return null;
|
|
829
|
+
const color = accent.trim().startsWith("#") ? accent.trim() : `#${accent.trim()}`;
|
|
830
|
+
if (contrastRatio(WHITE, color) >= MIN_TEXT_CONTRAST) return { onAccent: WHITE, background: color };
|
|
831
|
+
if (contrastRatio(NEAR_BLACK, color) >= MIN_TEXT_CONTRAST) return { onAccent: NEAR_BLACK, background: color };
|
|
832
|
+
for (let percent = 2; percent <= 60; percent += 2) {
|
|
833
|
+
const darker = darken(color, percent);
|
|
834
|
+
if (contrastRatio(WHITE, darker) >= MIN_TEXT_CONTRAST) return { onAccent: WHITE, background: darker };
|
|
835
|
+
}
|
|
836
|
+
return { onAccent: WHITE, background: NEAR_BLACK };
|
|
837
|
+
}
|
|
714
838
|
function parseHex(hex) {
|
|
715
839
|
if (!/^#?[\da-f]{3}(?:[\da-f]{3})?$/i.test(hex)) return [0, 0, 0];
|
|
716
840
|
const h = hex.replace("#", "");
|
|
@@ -945,12 +1069,14 @@ class Widget {
|
|
|
945
1069
|
constructor(config) {
|
|
946
1070
|
__publicField(this, "config");
|
|
947
1071
|
__publicField(this, "shadow");
|
|
1072
|
+
__publicField(this, "mounted", false);
|
|
948
1073
|
__publicField(this, "fab");
|
|
949
1074
|
__publicField(this, "panel");
|
|
950
1075
|
__publicField(this, "bubble");
|
|
951
1076
|
__publicField(this, "preChatFormEl");
|
|
952
1077
|
__publicField(this, "client");
|
|
953
1078
|
__publicField(this, "storage");
|
|
1079
|
+
__publicField(this, "namespace");
|
|
954
1080
|
__publicField(this, "locale");
|
|
955
1081
|
__publicField(this, "conversationId");
|
|
956
1082
|
__publicField(this, "messages", []);
|
|
@@ -964,7 +1090,12 @@ class Widget {
|
|
|
964
1090
|
__publicField(this, "autoOpenTimer");
|
|
965
1091
|
this.config = config;
|
|
966
1092
|
this.client = new ChatClient({ apiUrl: config.apiUrl, timeout: config.timeout });
|
|
967
|
-
this.
|
|
1093
|
+
this.namespace = claimNamespace(
|
|
1094
|
+
config.siteId,
|
|
1095
|
+
config.mode ?? "popup",
|
|
1096
|
+
() => !this.destroyed && (!this.mounted || this.shadow.host.isConnected)
|
|
1097
|
+
);
|
|
1098
|
+
this.storage = new ConversationStorage(this.namespace.siteId);
|
|
968
1099
|
this.locale = getWidgetLocale(config.locale ?? "en", config.strings);
|
|
969
1100
|
this.conversationId = this.storage.getSessionId();
|
|
970
1101
|
}
|
|
@@ -992,6 +1123,7 @@ class Widget {
|
|
|
992
1123
|
} else {
|
|
993
1124
|
this.shadow = createShadowRoot();
|
|
994
1125
|
}
|
|
1126
|
+
this.mounted = true;
|
|
995
1127
|
if (this.config.theme) {
|
|
996
1128
|
applyTheme(this.shadow, this.config.theme);
|
|
997
1129
|
}
|
|
@@ -1084,12 +1216,14 @@ class Widget {
|
|
|
1084
1216
|
this.emit("open");
|
|
1085
1217
|
}
|
|
1086
1218
|
close() {
|
|
1087
|
-
var _a, _b, _c;
|
|
1219
|
+
var _a, _b, _c, _d;
|
|
1220
|
+
const hadFocus = this.panel.containsFocus();
|
|
1088
1221
|
this.panel.hide();
|
|
1089
1222
|
if (!this.isInline) {
|
|
1090
1223
|
(_a = this.fab) == null ? void 0 : _a.setOpen(false);
|
|
1224
|
+
if (hadFocus) (_b = this.fab) == null ? void 0 : _b.focus();
|
|
1091
1225
|
}
|
|
1092
|
-
(
|
|
1226
|
+
(_d = (_c = this.config).onClose) == null ? void 0 : _d.call(_c);
|
|
1093
1227
|
this.emit("close");
|
|
1094
1228
|
}
|
|
1095
1229
|
toggle() {
|
|
@@ -1109,7 +1243,8 @@ class Widget {
|
|
|
1109
1243
|
(_c = this.bubble) == null ? void 0 : _c.destroy();
|
|
1110
1244
|
this.panel.destroy();
|
|
1111
1245
|
(_d = this.fab) == null ? void 0 : _d.destroy();
|
|
1112
|
-
destroyShadowRoot(this.
|
|
1246
|
+
destroyShadowRoot(this.shadow);
|
|
1247
|
+
this.namespace.release();
|
|
1113
1248
|
this.eventHandlers.clear();
|
|
1114
1249
|
this.messages = [];
|
|
1115
1250
|
this.userData = void 0;
|
|
@@ -1119,6 +1254,7 @@ class Widget {
|
|
|
1119
1254
|
this.eventHandlers.set(event, /* @__PURE__ */ new Set());
|
|
1120
1255
|
}
|
|
1121
1256
|
this.eventHandlers.get(event).add(handler);
|
|
1257
|
+
return () => this.off(event, handler);
|
|
1122
1258
|
}
|
|
1123
1259
|
off(event, handler) {
|
|
1124
1260
|
var _a;
|
|
@@ -1259,8 +1395,7 @@ class Widget {
|
|
|
1259
1395
|
if (this.destroyed) break;
|
|
1260
1396
|
if (chunk.error) {
|
|
1261
1397
|
const errorType = this.resolveErrorType(chunk.error);
|
|
1262
|
-
assistantMsg
|
|
1263
|
-
assistantMsg.status = "error";
|
|
1398
|
+
this.markFailed(assistantMsg, this.getErrorMessage(errorType));
|
|
1264
1399
|
assistantMsg.errorType = errorType;
|
|
1265
1400
|
hasError = true;
|
|
1266
1401
|
this.retryRequests.set(assistantMsg.id, {
|
|
@@ -1317,15 +1452,18 @@ class Widget {
|
|
|
1317
1452
|
}
|
|
1318
1453
|
} catch (err) {
|
|
1319
1454
|
if (this.destroyed) return;
|
|
1320
|
-
assistantMsg
|
|
1321
|
-
assistantMsg.status = "error";
|
|
1455
|
+
this.markFailed(assistantMsg, this.locale.errorGeneric);
|
|
1322
1456
|
assistantMsg.errorType = "network";
|
|
1323
1457
|
this.retryRequests.set(assistantMsg.id, {
|
|
1324
1458
|
regenerate: options.regenerate,
|
|
1325
1459
|
userMessageId: options.userMessageId
|
|
1326
1460
|
});
|
|
1327
1461
|
this.panel.messages.removeTyping();
|
|
1328
|
-
|
|
1462
|
+
if (firstChunk) {
|
|
1463
|
+
this.panel.addMessage(assistantMsg);
|
|
1464
|
+
} else {
|
|
1465
|
+
this.panel.messages.updateMessage(assistantMsg);
|
|
1466
|
+
}
|
|
1329
1467
|
this.messages.push(assistantMsg);
|
|
1330
1468
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
1331
1469
|
(_i = (_h = this.config).onError) == null ? void 0 : _i.call(_h, error);
|
|
@@ -1396,6 +1534,18 @@ class Widget {
|
|
|
1396
1534
|
return "provider_error";
|
|
1397
1535
|
}
|
|
1398
1536
|
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Marks a reply as failed. Text that already streamed stays, and the error
|
|
1539
|
+
* shows as a note under it; an empty reply shows the error as its content.
|
|
1540
|
+
*/
|
|
1541
|
+
markFailed(message, errorMessage) {
|
|
1542
|
+
message.status = "error";
|
|
1543
|
+
if (message.content.trim()) {
|
|
1544
|
+
message.errorText = errorMessage;
|
|
1545
|
+
} else {
|
|
1546
|
+
message.content = errorMessage;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1399
1549
|
getErrorMessage(errorType) {
|
|
1400
1550
|
switch (errorType) {
|
|
1401
1551
|
case "rate_limit":
|
|
@@ -1426,6 +1576,7 @@ class Widget {
|
|
|
1426
1576
|
}
|
|
1427
1577
|
}
|
|
1428
1578
|
let instance = null;
|
|
1579
|
+
const persistentHandlers = /* @__PURE__ */ new Map();
|
|
1429
1580
|
function parseAutoOpen(value) {
|
|
1430
1581
|
if (value === void 0) return void 0;
|
|
1431
1582
|
if (value === "" || value === "true") return true;
|
|
@@ -1439,6 +1590,11 @@ const ChatCops = {
|
|
|
1439
1590
|
instance.destroy();
|
|
1440
1591
|
}
|
|
1441
1592
|
instance = new Widget(config);
|
|
1593
|
+
for (const [event, handlers] of persistentHandlers) {
|
|
1594
|
+
for (const handler of handlers) {
|
|
1595
|
+
instance.on(event, handler);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1442
1598
|
instance.init();
|
|
1443
1599
|
return instance;
|
|
1444
1600
|
},
|
|
@@ -1453,9 +1609,20 @@ const ChatCops = {
|
|
|
1453
1609
|
instance = null;
|
|
1454
1610
|
},
|
|
1455
1611
|
on(event, handler) {
|
|
1612
|
+
let handlers = persistentHandlers.get(event);
|
|
1613
|
+
if (!handlers) {
|
|
1614
|
+
handlers = /* @__PURE__ */ new Set();
|
|
1615
|
+
persistentHandlers.set(event, handlers);
|
|
1616
|
+
}
|
|
1617
|
+
handlers.add(handler);
|
|
1456
1618
|
instance == null ? void 0 : instance.on(event, handler);
|
|
1619
|
+
return () => {
|
|
1620
|
+
ChatCops.off(event, handler);
|
|
1621
|
+
};
|
|
1457
1622
|
},
|
|
1458
1623
|
off(event, handler) {
|
|
1624
|
+
var _a;
|
|
1625
|
+
(_a = persistentHandlers.get(event)) == null ? void 0 : _a.delete(handler);
|
|
1459
1626
|
instance == null ? void 0 : instance.off(event, handler);
|
|
1460
1627
|
}
|
|
1461
1628
|
};
|
|
@@ -1495,7 +1662,7 @@ function autoInit(script) {
|
|
|
1495
1662
|
const currentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
1496
1663
|
if (currentScript && currentScript.dataset.apiUrl) {
|
|
1497
1664
|
if (document.readyState === "loading") {
|
|
1498
|
-
document.addEventListener("DOMContentLoaded", () => autoInit(currentScript));
|
|
1665
|
+
document.addEventListener("DOMContentLoaded", () => autoInit(currentScript), { once: true });
|
|
1499
1666
|
} else {
|
|
1500
1667
|
autoInit(currentScript);
|
|
1501
1668
|
}
|
package/dist/chatcops.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ChatCops=function(e){"use strict";var t=Object.defineProperty,s=(e,s,a)=>((e,s,a)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[s]=a)(e,"symbol"!=typeof s?s+"":s,a);function a(e){const t=document.createElement("div");t.id="chatcops-root",e?e.appendChild(t):document.body.appendChild(t);const s=t.attachShadow({mode:"open"}),a=document.createElement("style");return a.textContent=":host{--cc-accent: #6366f1;--cc-accent-hover: #4f46e5;--cc-text: #ffffff;--cc-bg: #0a0a0a;--cc-bg-surface: #1a1a1a;--cc-bg-input: #2a2a2a;--cc-border: #333333;--cc-text-secondary: #a0a0a0;--cc-font: system-ui, -apple-system, sans-serif;--cc-radius: 12px;--cc-shadow: 0 8px 32px rgba(0, 0, 0, .4);--cc-fab-size: 56px;--cc-panel-width: 400px;--cc-panel-height: 560px;all:initial;font-family:var(--cc-font);font-size:14px;line-height:1.5;color:var(--cc-text);-webkit-font-smoothing:antialiased}*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}.cc-fab{position:fixed;bottom:20px;right:20px;width:var(--cc-fab-size);height:var(--cc-fab-size);border-radius:50%;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 16px #0000004d;transition:transform .2s ease,box-shadow .2s ease;z-index:10000;outline:none}.cc-fab:hover{transform:scale(1.05);box-shadow:0 6px 24px #0006}.cc-fab:active{transform:scale(.95)}.cc-fab.cc-left{right:auto;left:20px}.cc-fab svg{width:24px;height:24px;fill:var(--cc-text);transition:transform .3s ease}.cc-fab.cc-open svg{transform:rotate(90deg)}.cc-fab-badge{position:absolute;top:-2px;right:-2px;width:12px;height:12px;border-radius:50%;background:#ef4444;border:2px solid var(--cc-bg);display:none}.cc-fab-badge.cc-visible{display:block}@keyframes cc-pulse{0%,to{box-shadow:0 4px 16px #0000004d}50%{box-shadow:0 4px 16px #6366f180}}.cc-fab.cc-pulse{animation:cc-pulse 2s ease-in-out 3}.cc-panel{position:fixed;bottom:88px;right:20px;width:var(--cc-panel-width);height:var(--cc-panel-height);max-height:calc(100vh - 100px);background:var(--cc-bg);border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);display:flex;flex-direction:column;overflow:hidden;z-index:9999;opacity:0;transform:translateY(16px) scale(.95);pointer-events:none;transition:opacity .2s ease,transform .2s ease}.cc-panel.cc-visible{opacity:1;transform:translateY(0) scale(1);pointer-events:auto}.cc-panel.cc-left{right:auto;left:20px}.cc-panel.cc-inline{position:relative;bottom:auto;right:auto;left:auto;width:100%;height:100%;max-height:100%;z-index:auto;transform:none;transition:none}.cc-panel.cc-inline:not(.cc-visible){visibility:hidden}.cc-panel.cc-inline.cc-visible{transform:none}.cc-header{display:flex;align-items:center;padding:16px;background:var(--cc-bg-surface);border-bottom:1px solid var(--cc-border);flex-shrink:0}.cc-header-avatar{width:36px;height:36px;border-radius:50%;margin-right:12px;object-fit:cover}.cc-header-avatar-placeholder{width:36px;height:36px;border-radius:50%;margin-right:12px;background:var(--cc-accent);display:flex;align-items:center;justify-content:center}.cc-header-avatar-placeholder svg{width:20px;height:20px;fill:var(--cc-text)}.cc-header-info{flex:1}.cc-header-name{font-size:15px;font-weight:600;color:var(--cc-text)}.cc-header-subtitle{font-size:12px;color:var(--cc-text-secondary)}.cc-header-close{width:32px;height:32px;border-radius:8px;background:transparent;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s ease}.cc-header-close:hover{background:var(--cc-bg-input)}.cc-header-close svg{width:16px;height:16px;fill:var(--cc-text-secondary)}.cc-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px}.cc-messages::-webkit-scrollbar{width:4px}.cc-messages::-webkit-scrollbar-track{background:transparent}.cc-messages::-webkit-scrollbar-thumb{background:var(--cc-border);border-radius:2px}.cc-message{max-width:85%;padding:10px 14px;border-radius:var(--cc-radius);word-wrap:break-word;overflow-wrap:break-word;font-size:14px;line-height:1.5;display:flex;flex-direction:column;gap:8px}.cc-message-user{align-self:flex-end;background:var(--cc-accent);color:var(--cc-text);border-bottom-right-radius:4px}.cc-message-assistant{align-self:flex-start;background:var(--cc-bg-surface);color:var(--cc-text);border-bottom-left-radius:4px}.cc-message a{color:var(--cc-accent);text-decoration:underline}.cc-message-user a{color:var(--cc-text)}.cc-message code{background:#0003;padding:1px 4px;border-radius:4px;font-family:SF Mono,Cascadia Code,Consolas,monospace;font-size:13px}.cc-message pre{background:#0000004d;padding:8px 12px;border-radius:8px;overflow-x:auto;margin:4px 0}.cc-message pre code{background:transparent;padding:0}.cc-message ul,.cc-message ol{padding-left:20px;margin:4px 0}.cc-message h1,.cc-message h2,.cc-message h3,.cc-message h4,.cc-message h5,.cc-message h6{font-size:15px;font-weight:600;line-height:1.4;margin:4px 0 0}.cc-message-actions{display:flex;align-items:center}.cc-message-retry,.cc-message-regenerate{display:inline-flex;align-items:center;gap:4px;padding:4px 10px;background:transparent;border:1px solid var(--cc-border);border-radius:6px;color:var(--cc-text-secondary);font-family:var(--cc-font);font-size:12px;cursor:pointer;transition:background .15s ease,color .15s ease,opacity .15s ease}.cc-message-retry:hover,.cc-message-regenerate:hover{background:var(--cc-bg-input);color:var(--cc-text)}.cc-message-retry svg,.cc-message-regenerate svg{fill:currentColor}.cc-message-regenerate{opacity:0}.cc-message:hover .cc-message-regenerate{opacity:1}.cc-message:focus-within .cc-message-regenerate,.cc-message-regenerate:focus-visible{opacity:1}@media(hover:none){.cc-message-regenerate{opacity:1}}.cc-message-retry{border-color:#ef4444;color:#ef4444}.cc-message-retry:hover{background:#ef44441a;color:#ef4444}.cc-typing{display:flex;align-items:center;gap:4px;padding:10px 14px;align-self:flex-start;background:var(--cc-bg-surface);border-radius:var(--cc-radius);border-bottom-left-radius:4px}.cc-typing-dot{width:6px;height:6px;border-radius:50%;background:var(--cc-text-secondary);animation:cc-bounce 1.2s infinite}.cc-typing-dot:nth-child(2){animation-delay:.2s}.cc-typing-dot:nth-child(3){animation-delay:.4s}@keyframes cc-bounce{0%,60%,to{transform:translateY(0)}30%{transform:translateY(-4px)}}.cc-input-area{display:flex;align-items:flex-end;padding:12px 16px;border-top:1px solid var(--cc-border);background:var(--cc-bg);gap:8px}.cc-input{flex:1;background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;line-height:1.5;resize:none;outline:none;max-height:96px;overflow-y:auto;transition:border-color .15s ease}.cc-input:focus{border-color:var(--cc-accent);outline:2px solid var(--cc-accent);outline-offset:1px}.cc-input::placeholder{color:var(--cc-text-secondary)}.cc-send-btn{width:36px;height:36px;border-radius:8px;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:background .15s ease,opacity .15s ease}.cc-send-btn:hover{background:var(--cc-accent-hover)}.cc-send-btn:disabled{opacity:.4;cursor:not-allowed}.cc-send-btn svg{width:16px;height:16px;fill:var(--cc-text)}.cc-footer{padding:6px 16px;text-align:center;font-size:11px;color:var(--cc-text-secondary);border-top:1px solid var(--cc-border)}.cc-footer a{color:var(--cc-text-secondary);text-decoration:none}.cc-footer a:hover{text-decoration:underline}.cc-bubble{position:fixed;bottom:84px;right:20px;background:var(--cc-bg-surface);color:var(--cc-text);padding:10px 16px;border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);max-width:260px;font-size:13px;line-height:1.4;z-index:9998;opacity:0;transform:translateY(8px);pointer-events:none;transition:opacity .3s ease,transform .3s ease;cursor:pointer}.cc-bubble.cc-visible{opacity:1;transform:translateY(0);pointer-events:auto}.cc-bubble.cc-left{right:auto;left:20px}.cc-bubble-close{position:absolute;top:-8px;right:-8px;width:20px;height:20px;border-radius:50%;background:var(--cc-bg);border:1px solid var(--cc-border);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:10px;color:var(--cc-text-secondary)}.cc-hidden{display:none}.cc-sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cc-messages-wrapper{flex:1;display:flex;flex-direction:column;min-height:0}.cc-prechat{flex:1;overflow-y:auto;padding:24px 16px;display:flex;flex-direction:column;gap:16px}.cc-prechat-title{font-size:18px;font-weight:600;color:var(--cc-text)}.cc-prechat-subtitle{font-size:13px;color:var(--cc-text-secondary);margin-top:-8px}.cc-prechat-fields{display:flex;flex-direction:column;gap:14px}.cc-prechat-field{display:flex;flex-direction:column;gap:4px}.cc-prechat-label{font-size:13px;font-weight:500;color:var(--cc-text)}.cc-prechat-label .cc-required{color:#ef4444;margin-left:2px}.cc-prechat-input,.cc-prechat-select,.cc-prechat-textarea{background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;outline:none;transition:border-color .15s ease}.cc-prechat-input:focus,.cc-prechat-select:focus,.cc-prechat-textarea:focus{border-color:var(--cc-accent)}.cc-prechat-select{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}.cc-prechat-textarea{resize:none;line-height:1.5}.cc-prechat-error{font-size:12px;color:#ef4444;min-height:0}.cc-prechat-error:empty{display:none}.cc-prechat-submit{background:var(--cc-accent);color:var(--cc-text);border:none;border-radius:8px;padding:10px 16px;font-family:var(--cc-font);font-size:14px;font-weight:500;cursor:pointer;transition:background .15s ease;margin-top:8px}.cc-prechat-submit:hover{background:var(--cc-accent-hover)}.cc-prechat-submit:disabled{opacity:.5;cursor:not-allowed}@media(max-width:768px){.cc-fab.cc-open{display:none}.cc-panel:not(.cc-inline){width:100%;height:100%;max-height:100%;bottom:0;right:0;left:0;border-radius:0;border:none}.cc-panel.cc-left:not(.cc-inline){left:0}.cc-bubble{bottom:84px;right:16px;left:16px;max-width:none}}.cc-fab:focus-visible,.cc-header-close:focus-visible,.cc-send-btn:focus-visible,.cc-message-retry:focus-visible,.cc-message-regenerate:focus-visible,.cc-bubble-close:focus-visible,.cc-prechat-submit:focus-visible{outline:2px solid var(--cc-accent);outline-offset:3px}@media(prefers-reduced-motion:reduce){.cc-fab.cc-pulse,.cc-typing-dot{animation:none}.cc-panel,.cc-bubble{transition:none}}",s.appendChild(a),s}const i='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12z"/><path d="M7 9h10v2H7zm0-3h10v2H7z"/></svg>';class n{constructor(e,t){s(this,"el"),s(this,"badge"),s(this,"isOpen",!1),s(this,"openLabel"),s(this,"closeLabel"),this.openLabel=t.openLabel,this.closeLabel=t.closeLabel,this.el=document.createElement("button"),this.el.className="cc-fab cc-pulse",this.el.setAttribute("aria-label",this.openLabel),"bottom-left"===t.position&&this.el.classList.add("cc-left"),this.el.innerHTML=i,this.badge=document.createElement("div"),this.badge.className="cc-fab-badge",this.el.appendChild(this.badge),this.el.addEventListener("click",()=>{this.el.classList.remove("cc-pulse"),t.onClick()}),e.appendChild(this.el)}setOpen(e){this.isOpen=e,this.el.innerHTML=e?'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>':i,e||this.el.appendChild(this.badge),this.el.classList.toggle("cc-open",e),this.el.setAttribute("aria-label",e?this.closeLabel:this.openLabel)}showBadge(){this.badge.classList.add("cc-visible")}hideBadge(){this.badge.classList.remove("cc-visible")}destroy(){this.el.remove()}}const r={"&":"&","<":"<",">":">",'"':""","'":"'"};const o=new Set(["http","https","mailto","tel"]);function c(e){let t=e.replace(/[&<>"']/g,e=>r[e]??e);const s=function(e){let t="\0";for(;e.includes(t);)t+="\0";return t}(t),a=[],i=e=>{const t=a.push(e)-1;return`${s}${t}${s}`};t=t.replace(/```(?:\w*)\n?([\s\S]*?)```/g,(e,t)=>i(`<pre><code>${t.trim()}</code></pre>`)),t=t.replace(/`([^`]+)`/g,(e,t)=>i(`<code>${t}</code>`)),t=t.replace(/^(#{1,6}) (.+)$/gm,(e,t,s)=>{const a=t.length;return`<h${a}>${s}</h${a}>`}),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(\S(?:.*?\S)??)\*/g,"<em>$1</em>"),t=t.replace(/\[([^\]]+)\]\(((?:[^()]*|\([^()]*\))*)\)/g,(e,t,s)=>function(e){const t=e.replace(/[\t\n\r]/g,"").replace(/^[\u0000-\u0020]+/,""),s=/^([^:/?#]+):/.exec(t);return!s||o.has(s[1].toLowerCase())}(s)?`<a href="${s}" target="_blank" rel="noopener noreferrer">${t}</a>`:t),t=t.replace(/^[-*+] (.+)$/gm,'<li data-md="ul">$1</li>'),t=t.replace(/^\d+\. (.+)$/gm,'<li data-md="ol">$1</li>'),t=t.replace(/(?:<li data-md="ul">.*?<\/li>\n?)+|(?:<li data-md="ol">.*?<\/li>\n?)+/g,e=>{const t=e.includes('data-md="ol"')?"ol":"ul";return`<${t}>${e.replace(/ data-md="(?:ul|ol)"/g,"").replace(/\n/g,"")}</${t}>`}),t=t.replace(/(<\/h[1-6]>)\n+/g,"$1"),t=t.replace(/\n\n/g,"<br><br>"),t=t.replace(/\n/g,"<br>");for(let n=0;n<a.length;n++)t=t.replace(`${s}${n}${s}`,()=>a[n]);return t}class l{constructor(e,t){s(this,"container"),s(this,"typingEl",null),s(this,"actions"),this.actions=t,this.container=document.createElement("div"),this.container.className="cc-messages",this.container.setAttribute("role","log"),this.container.setAttribute("aria-live","polite"),e.appendChild(this.container)}addMessage(e){this.removeTyping();const t=this.createMessageElement(e);return this.container.appendChild(t),this.scrollToBottom(),t}updateMessage(e){const t=this.container.querySelector(`[data-id="${e.id}"]`);t&&(this.renderMessageElement(t,e),this.scrollToBottom())}showTyping(){var e;this.typingEl||(this.typingEl=document.createElement("div"),this.typingEl.className="cc-typing",this.typingEl.innerHTML=`<span class="cc-sr-only">${this.escapeHtml((null==(e=this.actions)?void 0:e.typingLabel)??"Typing...")}</span><div class="cc-typing-dot" aria-hidden="true"></div><div class="cc-typing-dot" aria-hidden="true"></div><div class="cc-typing-dot" aria-hidden="true"></div>`,this.container.appendChild(this.typingEl),this.scrollToBottom())}removeTyping(){this.typingEl&&(this.typingEl.remove(),this.typingEl=null)}clear(){this.container.innerHTML="",this.typingEl=null}removeMessage(e){const t=this.container.querySelector(`[data-id="${e}"]`);null==t||t.remove()}clearRegenerateButtons(){this.container.querySelectorAll(".cc-message-regenerate").forEach(e=>e.remove()),this.cleanupEmptyActionContainers()}showRegenerateButton(e){var t;if(this.clearRegenerateButtons(),!(null==(t=this.actions)?void 0:t.onRegenerate))return;const s=this.container.querySelector(`[data-id="${e}"]`);if(!s||!s.classList.contains("cc-message-assistant"))return;this.ensureActionsContainer(s).appendChild(this.createActionButton({className:"cc-message-regenerate",label:this.actions.regenerateLabel??"Regenerate",icon:'<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0020 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74A7.93 7.93 0 004 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>',onClick:()=>{var t,s;return null==(s=null==(t=this.actions)?void 0:t.onRegenerate)?void 0:s.call(t,e)}}))}setVisible(e){this.container.classList.toggle("cc-hidden",!e)}scrollToBottom(){this.container.scrollTop=this.container.scrollHeight}createMessageElement(e){const t=document.createElement("div");return this.renderMessageElement(t,e),t}renderMessageElement(e,t){e.className=`cc-message cc-message-${t.role}`,e.dataset.id=t.id,t.status?e.dataset.status=t.status:delete e.dataset.status,"streaming"===t.status?e.setAttribute("aria-busy","true"):e.removeAttribute("aria-busy"),t.errorType?e.dataset.errorType=t.errorType:delete e.dataset.errorType,e.innerHTML="";const s=document.createElement("div");s.className="cc-message-content",s.innerHTML="assistant"===t.role?c(t.content):this.escapeHtml(t.content),e.appendChild(s);const a=this.createActionsContainer(t);a&&e.appendChild(a)}createActionsContainer(e){var t;if("error"!==e.status||!(null==(t=this.actions)?void 0:t.onRetry))return null;const s=document.createElement("div");return s.className="cc-message-actions",s.appendChild(this.createActionButton({className:"cc-message-retry",label:this.actions.retryLabel??"Retry",icon:'<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M17.65 6.35A7.96 7.96 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>',onClick:()=>{var t,s;return null==(s=null==(t=this.actions)?void 0:t.onRetry)?void 0:s.call(t,e.id)}})),s}ensureActionsContainer(e){const t=e.querySelector(".cc-message-actions");if(t)return t;const s=document.createElement("div");return s.className="cc-message-actions",e.appendChild(s),s}cleanupEmptyActionContainers(){this.container.querySelectorAll(".cc-message-actions").forEach(e=>{e.hasChildNodes()||e.remove()})}createActionButton(e){const t=document.createElement("button");return t.type="button",t.className=e.className,t.innerHTML=`${e.icon}<span>${this.escapeHtml(e.label)}</span>`,t.addEventListener("click",e.onClick),t}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}}class d{constructor(e,t){s(this,"area"),s(this,"textarea"),s(this,"sendBtn"),s(this,"onSend"),this.onSend=t.onSend,this.area=document.createElement("div"),this.area.className="cc-input-area",this.textarea=document.createElement("textarea"),this.textarea.className="cc-input",this.textarea.placeholder=t.placeholder,this.textarea.setAttribute("aria-label",t.placeholder),this.textarea.rows=1,this.textarea.maxLength=1e4,this.textarea.addEventListener("input",()=>this.autoResize()),this.textarea.addEventListener("keydown",e=>this.handleKeydown(e)),this.sendBtn=document.createElement("button"),this.sendBtn.className="cc-send-btn",this.sendBtn.disabled=!0,this.sendBtn.setAttribute("aria-label",t.sendLabel),this.sendBtn.innerHTML='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>',this.sendBtn.addEventListener("click",()=>this.send()),this.textarea.addEventListener("input",()=>{this.sendBtn.disabled=0===this.textarea.value.trim().length}),this.area.appendChild(this.textarea),this.area.appendChild(this.sendBtn),e.appendChild(this.area)}focus(){this.textarea.focus()}setDisabled(e){this.textarea.disabled=e,this.sendBtn.disabled=e||0===this.textarea.value.trim().length}clear(){this.textarea.value="",this.sendBtn.disabled=!0,this.autoResize()}setVisible(e){this.area.classList.toggle("cc-hidden",!e)}send(){const e=this.textarea.value.trim();e&&(this.onSend(e),this.clear())}handleKeydown(e){e.isComposing||229===e.keyCode||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),this.send())}autoResize(){this.textarea.style.height="auto";this.textarea.style.height=Math.min(this.textarea.scrollHeight,96)+"px"}}class h{constructor(e,t){s(this,"el"),s(this,"inline"),s(this,"messages"),s(this,"input"),s(this,"messagesContainer"),this.inline=t.inline??!1,this.el=document.createElement("div"),this.el.className="cc-panel",t.inline&&this.el.classList.add("cc-inline"),"bottom-left"===t.position&&this.el.classList.add("cc-left");const a=document.createElement("div");if(a.className="cc-header",t.branding.avatar){const e=document.createElement("img");e.className="cc-header-avatar",e.src=t.branding.avatar,e.alt=t.branding.name,a.appendChild(e)}else{const e=document.createElement("div");e.className="cc-header-avatar-placeholder",e.innerHTML='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z"/></svg>',a.appendChild(e)}const i=document.createElement("div");if(i.className="cc-header-info",i.innerHTML=`<div class="cc-header-name">${this.escapeHtml(t.branding.name)}</div><div class="cc-header-subtitle">${this.escapeHtml(t.branding.subtitle)}</div>`,a.appendChild(i),!t.inline){const e=document.createElement("button");e.className="cc-header-close",e.setAttribute("aria-label",t.closeLabel),e.innerHTML='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>',e.addEventListener("click",t.onClose),a.appendChild(e)}this.el.appendChild(a),t.preChatEnabled?(this.messagesContainer=document.createElement("div"),this.messagesContainer.className="cc-messages-wrapper",this.el.appendChild(this.messagesContainer)):this.messagesContainer=this.el,this.messages=new l(this.messagesContainer,t.messageActions),this.input=new d(this.el,{placeholder:t.placeholder,sendLabel:t.sendLabel,onSend:t.onSend});const n=document.createElement("div");n.className="cc-footer",n.innerHTML=t.footerText,this.el.appendChild(n),e.appendChild(this.el)}show(){this.el.classList.add("cc-visible"),this.inline||this.input.focus()}hide(){this.el.classList.remove("cc-visible")}get isVisible(){return this.el.classList.contains("cc-visible")}addMessage(e){return this.messages.addMessage(e)}hideMessages(){this.messages.setVisible(!1)}showMessages(){this.messages.setVisible(!0)}destroy(){this.el.remove()}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}}const p="chatcops_bubble_shown";class u{constructor(e,t){s(this,"el"),s(this,"timerId",null),this.el=document.createElement("div"),this.el.className="cc-bubble","bottom-left"===t.position&&this.el.classList.add("cc-left"),this.el.textContent=t.text;const a=document.createElement("button");if(a.type="button",a.className="cc-bubble-close",a.setAttribute("aria-label",t.dismissLabel),a.innerHTML="×",a.addEventListener("click",e=>{e.stopPropagation(),this.hide()}),this.el.appendChild(a),this.el.addEventListener("click",()=>{this.hide(),t.onClick()}),e.appendChild(this.el),t.showOnce)try{if(sessionStorage.getItem(p))return;sessionStorage.setItem(p,"1")}catch{}this.timerId=setTimeout(()=>{this.el.classList.add("cc-visible")},t.delay??3e3)}hide(){this.el.classList.remove("cc-visible"),this.timerId&&(clearTimeout(this.timerId),this.timerId=null)}destroy(){this.hide(),this.el.remove()}}class m{constructor(e){s(this,"apiUrl"),s(this,"timeout"),this.apiUrl=e.apiUrl,this.timeout=e.timeout??3e4}async*sendMessage(e,t={}){var s;const a=new AbortController,i=t.timeout??this.timeout;let n,r,o=!1;const c=t.signal,l=()=>{clearTimeout(n),a.abort()},d=()=>{clearTimeout(n),a.signal.aborted||(n=setTimeout(()=>{o=!0,a.abort()},i))},h=async()=>{if(clearTimeout(n),null==c||c.removeEventListener("abort",l),r){const e=r;r=void 0;try{await e.cancel()}catch{}finally{e.releaseLock()}}};c&&(c.aborted?a.abort():c.addEventListener("abort",l)),d();try{const t=await fetch(this.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:a.signal});if(!t.ok)return await h(),429===t.status?void(yield{error:"rate_limit"}):void(yield{error:`HTTP ${t.status}`});if(r=null==(s=t.body)?void 0:s.getReader(),!r)return await h(),void(yield{error:"No response body"});const i=new TextDecoder;let n="";for(;;){const{done:e,value:t}=await r.read();if(e)break;t.byteLength>0&&d(),n+=i.decode(t,{stream:!0});const s=n.split("\n");n=s.pop()??"";for(const a of s){const e=a.trim();if(!e||!e.startsWith("data: "))continue;const t=e.slice(6);if("[DONE]"===t)return await h(),void(yield{done:!0});try{yield JSON.parse(t)}catch{}}}await h(),yield{done:!0}}catch(p){await h(),p instanceof DOMException&&"AbortError"===p.name?yield o?{error:"timeout"}:{error:"aborted"}:yield{error:"network"}}finally{await h()}}}const g="chatcops_conversation";class b{constructor(e){s(this,"key"),this.key=e?`${g}_${e}`:g}load(){try{const e=localStorage.getItem(this.key);return e?JSON.parse(e):null}catch{return null}}save(e){try{const t={...e,messages:e.messages.filter(e=>"error"!==e.status).map(({status:e,...t})=>t)};localStorage.setItem(this.key,JSON.stringify(t))}catch{}}clear(){try{localStorage.removeItem(this.key)}catch{}}getSessionId(){const e="chatcops_session_id";try{let t=sessionStorage.getItem(e);return t||(t=crypto.randomUUID(),sessionStorage.setItem(e,t)),t}catch{return crypto.randomUUID()}}isPreChatCompleted(e){try{return"true"===sessionStorage.getItem(`chatcops-prechat-${e}`)}catch{return!1}}setPreChatCompleted(e,t){try{sessionStorage.setItem(`chatcops-prechat-${e}`,"true")}catch{}t&&this.setPreChatData(e,t)}getPreChatData(e){try{const t=sessionStorage.getItem(`chatcops-prechat-data-${e}`);if(!t)return null;const s=JSON.parse(t);return"object"!=typeof s||null===s||Array.isArray(s)?null:s}catch{return null}}setPreChatData(e,t){try{sessionStorage.setItem(`chatcops-prechat-data-${e}`,JSON.stringify(t))}catch{}}}function f(e,t){const s=e.host;if(t.accent&&(s.style.setProperty("--cc-accent",t.accent),s.style.setProperty("--cc-accent-hover",function(e,t){const[s,a,i]=v(e),n=1-t/100;return x(Math.round(s*n),Math.round(a*n),Math.round(i*n))}(t.accent,10))),t.textColor&&s.style.setProperty("--cc-text",t.textColor),t.bgColor&&(s.style.setProperty("--cc-bg",t.bgColor),s.style.setProperty("--cc-bg-surface",y(t.bgColor,8)),s.style.setProperty("--cc-bg-input",y(t.bgColor,14))),t.fontFamily&&s.style.setProperty("--cc-font",t.fontFamily),void 0!==t.borderRadius){const e=function(e){if("number"==typeof e&&!Number.isFinite(e))return"";const t=String(e).trim();return/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(t)?`${t}px`:t}(t.borderRadius);e&&s.style.setProperty("--cc-radius",e)}}function v(e){if(!/^#?[\da-f]{3}(?:[\da-f]{3})?$/i.test(e))return[0,0,0];const t=e.replace("#",""),s=parseInt(3===t.length?t.split("").map(e=>e+e).join(""):t,16);return[s>>16&255,s>>8&255,255&s]}function x(e,t,s){return"#"+[e,t,s].map(e=>Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")).join("")}function y(e,t){const[s,a,i]=v(e),n=t/100;return x(Math.round(s+(255-s)*n),Math.round(a+(255-a)*n),Math.round(i+(255-i)*n))}const w={welcomeMessage:"How can I help you today?",inputPlaceholder:"Type a message...",sendButton:"Send",closeButton:"Close",openChat:"Open chat",defaultName:"AI Assistant",defaultSubtitle:"Online",greetingWithName:"Hi {name}!",selectPlaceholder:"Select {label}...",dismissBubble:"Dismiss",errorGeneric:"Something went wrong. Please try again.",errorNetwork:"Connection error. Please check your network.",errorRateLimit:"Too many messages. Please wait a moment.",typingIndicator:"Typing...",poweredBy:"Powered by ChatCops",newConversation:"New conversation",welcomeBubbleDefault:"Need help? Chat with us!",preChatTitle:"Before we start...",preChatSubtitle:"Tell us a bit about yourself",preChatSubmit:"Start Chat",preChatRequired:"This field is required",preChatInvalidEmail:"Please enter a valid email",retryButton:"Retry",regenerateButton:"Regenerate"},C={en:w};class E{constructor(e,t){if(s(this,"container"),s(this,"fieldElements",new Map),s(this,"errorElements",new Map),s(this,"submitBtn"),s(this,"options"),this.options=t,this.container=document.createElement("div"),this.container.className="cc-prechat",t.title){const e=document.createElement("div");e.className="cc-prechat-title",e.textContent=t.title,this.container.appendChild(e)}if(t.subtitle){const e=document.createElement("div");e.className="cc-prechat-subtitle",e.textContent=t.subtitle,this.container.appendChild(e)}const a=document.createElement("form");a.className="cc-prechat-fields",a.noValidate=!0,a.addEventListener("submit",e=>{e.preventDefault(),this.handleSubmit()});for(const s of t.fields)a.appendChild(this.createField(s));this.submitBtn=document.createElement("button"),this.submitBtn.type="submit",this.submitBtn.className="cc-prechat-submit",this.submitBtn.textContent=t.submitLabel,a.appendChild(this.submitBtn),this.container.appendChild(a),e.appendChild(this.container),this.updateSubmitState();const i=this.fieldElements.values().next().value;i&&setTimeout(()=>i.focus(),100)}createField(e){const t=document.createElement("div");t.className="cc-prechat-field";const s=`cc-prechat-${e.name}`,a=`cc-prechat-${e.name}-error`,i=document.createElement("label");if(i.className="cc-prechat-label",i.htmlFor=s,i.textContent=e.label,e.required){const e=document.createElement("span");e.className="cc-required",e.textContent="*",i.appendChild(e)}let n;if(t.appendChild(i),"select"===e.type){const t=document.createElement("select");t.className="cc-prechat-select";const s=document.createElement("option");s.value="",s.textContent=e.placeholder??this.options.locale.selectPlaceholder.replace("{label}",e.label.toLowerCase()),s.disabled=!0,s.selected=!0,t.appendChild(s);for(const a of e.options??[]){const e=document.createElement("option");e.value=a,e.textContent=a,t.appendChild(e)}n=t}else if("textarea"===e.type){const t=document.createElement("textarea");t.className="cc-prechat-textarea",t.placeholder=e.placeholder??"",t.rows=3,t.maxLength=500,n=t}else{const t=document.createElement("input");t.type=e.type,t.className="cc-prechat-input",t.maxLength=500,t.placeholder=e.placeholder??"",n=t}n.name=e.name,n.id=s,e.required&&n.setAttribute("aria-required","true"),n.addEventListener("input",()=>{this.clearError(e.name),this.updateSubmitState()}),n instanceof HTMLSelectElement&&n.addEventListener("change",()=>{this.clearError(e.name),this.updateSubmitState()}),t.appendChild(n),this.fieldElements.set(e.name,n);const r=document.createElement("div");return r.className="cc-prechat-error",r.id=a,t.appendChild(r),this.errorElements.set(e.name,r),t}updateSubmitState(){const e=this.options.fields.every(e=>{if(!e.required)return!0;const t=this.fieldElements.get(e.name);return!!t&&t.value.trim().length>0});this.submitBtn.disabled=!e}handleSubmit(){const e={};let t=!0;for(const s of this.options.fields){const a=this.fieldElements.get(s.name);if(!a)continue;const i=a.value.trim();e[s.name]=i,!s.required||i?"email"!==s.type||!i||this.isValidEmail(i)||(this.showError(s.name,this.options.locale.preChatInvalidEmail),t=!1):(this.showError(s.name,this.options.locale.preChatRequired),t=!1)}t&&this.options.onSubmit(e)}showError(e,t){const s=this.errorElements.get(e);s&&(s.textContent=t);const a=this.fieldElements.get(e);a&&s&&(a.setAttribute("aria-invalid","true"),a.setAttribute("aria-describedby",s.id))}clearError(e){const t=this.errorElements.get(e);t&&(t.textContent="");const s=this.fieldElements.get(e);s&&t&&(s.getAttribute("aria-describedby")===t.id&&s.removeAttribute("aria-describedby"),"true"===s.getAttribute("aria-invalid")&&s.removeAttribute("aria-invalid"))}isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}destroy(){this.container.remove(),this.fieldElements.clear(),this.errorElements.clear()}}class L{constructor(e){s(this,"config"),s(this,"shadow"),s(this,"fab"),s(this,"panel"),s(this,"bubble"),s(this,"preChatFormEl"),s(this,"client"),s(this,"storage"),s(this,"locale"),s(this,"conversationId"),s(this,"messages",[]),s(this,"userData"),s(this,"isStreaming",!1),s(this,"destroyed",!1),s(this,"abortController"),s(this,"retryRequests",new Map),s(this,"eventHandlers",new Map),s(this,"containerEl"),s(this,"autoOpenTimer"),this.config=e,this.client=new m({apiUrl:e.apiUrl,timeout:e.timeout}),this.storage=new b,this.locale=function(e,t){const s=C[e]??w;return t?{...s,...t}:s}(e.locale??"en",e.strings),this.conversationId=this.storage.getSessionId()}get isInline(){return"inline"===this.config.mode}resolveContainer(){if(!this.config.container)throw new Error('ChatCops: "container" is required when mode is "inline"');if("string"==typeof this.config.container){const e=document.querySelector(this.config.container);if(!e)throw new Error(`ChatCops: container element not found: ${this.config.container}`);return e}return this.config.container}init(){var e,t,s,i,r,o,c;this.isInline?(this.containerEl=this.resolveContainer(),this.shadow=a(this.containerEl)):this.shadow=a(),this.config.theme&&f(this.shadow,this.config.theme);const l=(null==(e=this.config.theme)?void 0:e.position)??"bottom-right";if(this.isInline||(this.fab=new n(this.shadow,{position:l,openLabel:this.locale.openChat,closeLabel:this.locale.closeButton,onClick:()=>this.toggle()})),this.panel=new h(this.shadow,{position:l,inline:this.isInline,preChatEnabled:(null==(t=this.config.preChatForm)?void 0:t.enabled)??!1,branding:{name:(null==(s=this.config.branding)?void 0:s.name)??this.locale.defaultName,avatar:null==(i=this.config.branding)?void 0:i.avatar,subtitle:(null==(r=this.config.branding)?void 0:r.subtitle)??this.locale.defaultSubtitle},placeholder:this.config.placeholder??this.locale.inputPlaceholder,footerText:this.locale.poweredBy,closeLabel:this.locale.closeButton,sendLabel:this.locale.sendButton,messageActions:{onRetry:e=>{this.handleRetry(e)},onRegenerate:e=>{this.handleRegenerate(e)},retryLabel:this.locale.retryButton,regenerateLabel:this.locale.regenerateButton,typingLabel:this.locale.typingIndicator},onSend:e=>this.handleSend(e),onClose:()=>this.close()}),!1!==this.config.persistHistory){const e=this.storage.load();if(e){this.conversationId=e.id;for(const t of e.messages)this.messages.push(t),this.panel.addMessage(t)}}if(null==(o=this.config.preChatForm)?void 0:o.enabled){const e=this.storage.getPreChatData(this.conversationId);e&&(this.userData=e)}if((null==(c=this.config.preChatForm)?void 0:c.enabled)&&!this.isPreChatCompleted()&&0===this.messages.length?this.showPreChatForm():this.showChatView(),this.showLatestRegenerateButton(),!this.isInline&&this.config.welcomeBubble&&(this.bubble=new u(this.shadow,{text:this.config.welcomeBubble.text,delay:this.config.welcomeBubble.delay,showOnce:this.config.welcomeBubble.showOnce??!0,position:l,dismissLabel:this.locale.dismissBubble,onClick:()=>this.open()})),this.isInline&&this.panel.show(),!this.isInline&&void 0!==this.config.autoOpen&&!1!==this.config.autoOpen){const e="number"==typeof this.config.autoOpen?this.config.autoOpen:0;this.autoOpenTimer=setTimeout(()=>this.open(),e)}}open(){var e,t,s,a,i;this.panel.show(),this.isInline||(null==(e=this.fab)||e.setOpen(!0),null==(t=this.fab)||t.hideBadge(),null==(s=this.bubble)||s.hide()),null==(i=(a=this.config).onOpen)||i.call(a),this.emit("open")}close(){var e,t,s;this.panel.hide(),this.isInline||null==(e=this.fab)||e.setOpen(!1),null==(s=(t=this.config).onClose)||s.call(t),this.emit("close")}toggle(){this.panel.isVisible?this.close():this.open()}destroy(){var e,t,s,a;this.destroyed=!0,void 0!==this.autoOpenTimer&&clearTimeout(this.autoOpenTimer),null==(e=this.abortController)||e.abort(),this.abortController=void 0,null==(t=this.preChatFormEl)||t.destroy(),null==(s=this.bubble)||s.destroy(),this.panel.destroy(),null==(a=this.fab)||a.destroy(),function(e){const t=(e??document.body).querySelector("#chatcops-root")??document.getElementById("chatcops-root");t&&t.remove()}(this.containerEl),this.eventHandlers.clear(),this.messages=[],this.userData=void 0}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set),this.eventHandlers.get(e).add(t)}off(e,t){var s;null==(s=this.eventHandlers.get(e))||s.delete(t)}emit(e,...t){var s;this.destroyed||null==(s=this.eventHandlers.get(e))||s.forEach(e=>e(...t))}isPreChatCompleted(){return this.storage.isPreChatCompleted(this.conversationId)}setPreChatCompleted(e){this.storage.setPreChatCompleted(this.conversationId,e)}showPreChatForm(){const e=this.config.preChatForm;this.panel.hideMessages(),this.panel.input.setVisible(!1),this.preChatFormEl=new E(this.panel.messagesContainer,{title:e.title??this.locale.preChatTitle,subtitle:e.subtitle??this.locale.preChatSubtitle,fields:e.fields,submitLabel:e.submitLabel??this.locale.preChatSubmit,locale:this.locale,onSubmit:e=>this.handlePreChatSubmit(e)})}handlePreChatSubmit(e){var t,s,a,i;(null==(t=this.config.preChatForm)?void 0:t.enabled)&&(this.userData=e,this.setPreChatCompleted(e),null==(s=this.preChatFormEl)||s.destroy(),this.preChatFormEl=void 0,this.panel.showMessages(),this.panel.input.setVisible(!0),this.showChatView(),null==(i=(a=this.config).onPreChatSubmit)||i.call(a,e),this.emit("preChatSubmit",e),e.message&&this.handleSend(e.message))}showChatView(){var e;if(0===this.messages.length){const t=null==(e=this.userData)?void 0:e.name,s=this.locale.greetingWithName.replace("{name}",()=>t),a={id:"welcome",role:"assistant",content:t?`${s} ${this.config.welcomeMessage??this.locale.welcomeMessage}`:this.config.welcomeMessage??this.locale.welcomeMessage};this.messages.push(a),this.panel.addMessage(a)}}async handleSend(e){var t,s;if(this.isStreaming)return;const a={id:crypto.randomUUID(),role:"user",content:e};this.messages.push(a),this.panel.addMessage(a),null==(s=(t=this.config).onMessage)||s.call(t,a),this.emit("message",a),await this.sendToServer(e,{userMessageId:a.id})}async handleRetry(e){if(this.isStreaming)return;const t=this.messages.findIndex(t=>t.id===e);if(-1===t)return;const s=this.retryRequests.get(e);let a=(null==s?void 0:s.userMessageId)?this.messages.find(e=>e.id===s.userMessageId):void 0;if(!a)for(let i=t-1;i>=0;i--)if("user"===this.messages[i].role){a=this.messages[i];break}a&&(this.panel.messages.removeMessage(e),this.retryRequests.delete(e),this.messages=this.messages.filter(t=>t.id!==e),await this.sendToServer(a.content,{regenerate:null==s?void 0:s.regenerate,userMessageId:(null==s?void 0:s.userMessageId)??a.id}))}async handleRegenerate(e){if(this.isStreaming)return;const t=this.messages.findIndex(t=>t.id===e);if(-1===t)return;if("assistant"!==this.messages[t].role)return;const s=this.findUserMessageForAssistant(t);s&&(this.panel.messages.clearRegenerateButtons(),this.panel.messages.removeMessage(e),this.retryRequests.delete(e),this.messages=this.messages.filter(t=>t.id!==e),await this.sendToServer(s.content,{regenerate:!0,userMessageId:s.id}))}async sendToServer(e,t={}){var s,a,i,n,r,o,c,l,d;if(this.isStreaming)return;this.isStreaming=!0,this.panel.input.setDisabled(!0),this.panel.messages.clearRegenerateButtons(),this.panel.messages.showTyping();const h={id:crypto.randomUUID(),role:"assistant",content:"",status:"streaming"};let p=!0,u=!1,m=!1;const g=new AbortController;this.abortController=g;try{for await(const r of this.client.sendMessage(this.createRequest(e,t),{signal:g.signal})){if(this.destroyed)break;if(r.error){const e=this.resolveErrorType(r.error);h.content=this.getErrorMessage(e),h.status="error",h.errorType=e,m=!0,this.retryRequests.set(h.id,{regenerate:t.regenerate,userMessageId:t.userMessageId}),this.panel.messages.removeTyping(),p?this.panel.addMessage(h):this.panel.messages.updateMessage(h),this.messages.push(h);const i=new Error(r.error);null==(a=(s=this.config).onError)||a.call(s,i),this.emit("error",i);break}if(r.done){u=!0;break}r.leadCaptured&&(null==(n=(i=this.config).onLeadCaptured)||n.call(i,r.leadData),this.emit("leadCaptured",r.leadData)),r.content&&(p&&(this.panel.messages.removeTyping(),this.panel.addMessage(h),p=!1),h.content+=r.content,this.panel.messages.updateMessage(h))}if(this.destroyed)return;m||u||(u=!0),!m&&p&&this.panel.messages.removeTyping(),!m&&h.content&&(h.status="complete",this.panel.messages.updateMessage(h),this.messages.push(h),null==(o=(r=this.config).onMessage)||o.call(r,h),this.emit("message",h),this.showLatestRegenerateButton(),this.isInline||this.panel.isVisible||null==(c=this.fab)||c.showBadge())}catch(b){if(this.destroyed)return;h.content=this.locale.errorGeneric,h.status="error",h.errorType="network",this.retryRequests.set(h.id,{regenerate:t.regenerate,userMessageId:t.userMessageId}),this.panel.messages.removeTyping(),this.panel.addMessage(h),this.messages.push(h);const e=b instanceof Error?b:new Error(String(b));null==(d=(l=this.config).onError)||d.call(l,e),this.emit("error",e)}finally{this.abortController===g&&(this.abortController=void 0),this.destroyed||(this.isStreaming=!1,this.panel.input.setDisabled(!1),this.panel.input.focus(),this.saveHistory())}}createRequest(e,t){var s;const a=!1!==this.config.pageContext?{url:window.location.href,title:document.title}:void 0,i=Boolean((null==(s=this.config.preChatForm)?void 0:s.enabled)&&this.userData);return{conversationId:this.conversationId,message:e,messageId:t.userMessageId,regenerate:t.regenerate,pageContext:a,locale:this.config.locale,...i?{userData:this.userData}:{}}}findUserMessageForAssistant(e){for(let t=e-1;t>=0;t--)if("user"===this.messages[t].role)return this.messages[t]}findLatestRegeneratableAssistant(){for(let e=this.messages.length-1;e>=0;e--){const t=this.messages[e];if("welcome"!==t.id){if("assistant"!==t.role||"error"===t.status)return;return t}}}showLatestRegenerateButton(){const e=this.findLatestRegeneratableAssistant();e?this.panel.messages.showRegenerateButton(e.id):this.panel.messages.clearRegenerateButtons()}resolveErrorType(e){switch(e){case"rate_limit":case"network":case"provider_error":case"timeout":return e;default:return"provider_error"}}getErrorMessage(e){switch(e){case"rate_limit":return this.locale.errorRateLimit;case"network":case"timeout":return this.locale.errorNetwork;default:return this.locale.errorGeneric}}saveHistory(){if(!1===this.config.persistHistory)return;const e=this.config.maxMessages??50,t=this.messages.filter(e=>"welcome"!==e.id).slice(-e);this.storage.save({id:this.conversationId,messages:t.map(e=>({id:e.id,role:e.role,content:e.content,status:e.status,errorType:e.errorType,timestamp:Date.now()})),updatedAt:Date.now()})}}let M=null;function S(e){if(void 0!==e)return""===e||"true"===e||"false"!==e&&(/^\d+$/.test(e)?Number(e):void 0)}const k={init:e=>(M&&M.destroy(),M=new L(e),M.init(),M),open(){null==M||M.open()},close(){null==M||M.close()},destroy(){null==M||M.destroy(),M=null},on(e,t){null==M||M.on(e,t)},off(e,t){null==M||M.off(e,t)}};function B(e){if(!e)return;const t=e.dataset.apiUrl;if(!t)return;const s=e.dataset.mode,a=e.dataset.container;k.init({apiUrl:t,mode:s||void 0,container:a||void 0,theme:{accent:e.dataset.accent,textColor:e.dataset.textColor,bgColor:e.dataset.bgColor,fontFamily:e.dataset.fontFamily,borderRadius:e.dataset.borderRadius,position:e.dataset.position||void 0},branding:{name:e.dataset.brandName,avatar:e.dataset.brandAvatar,subtitle:e.dataset.brandSubtitle},welcomeMessage:e.dataset.welcomeMessage,welcomeBubble:e.dataset.welcomeBubble?{text:e.dataset.welcomeBubble,delay:e.dataset.welcomeBubbleDelay?parseInt(e.dataset.welcomeBubbleDelay,10):void 0}:void 0,autoOpen:S(e.dataset.autoOpen),placeholder:e.dataset.placeholder,locale:e.dataset.locale})}const T="undefined"!=typeof document?document.currentScript:null;return T&&T.dataset.apiUrl&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>B(T)):B(T)),"undefined"!=typeof window&&(window.ChatCops=k),e.Widget=L,e.default=k,e.parseAutoOpen=S,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});"undefined"!=typeof window&&window.ChatCops&&window.ChatCops.default&&Object.assign(window.ChatCops,window.ChatCops.default);
|
|
1
|
+
var ChatCops=function(e){"use strict";var t=Object.defineProperty,s=(e,s,a)=>((e,s,a)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[s]=a)(e,"symbol"!=typeof s?s+"":s,a);const a="chatcops-root";function i(e){const t=document.createElement("div");t.id=function(){if(!document.getElementById(a))return a;let e=2;for(;document.getElementById(`${a}-${e}`);)e+=1;return`${a}-${e}`}(),t.className=a,e?e.appendChild(t):document.body.appendChild(t);const s=t.attachShadow({mode:"open"}),i=document.createElement("style");return i.textContent=":host{--cc-accent: #6366f1;--cc-accent-hover: #4f46e5;--cc-on-accent: #ffffff;--cc-accent-contrast: #6164ec;--cc-text: #ffffff;--cc-bg: #0a0a0a;--cc-bg-surface: #1a1a1a;--cc-bg-input: #2a2a2a;--cc-border: #333333;--cc-text-secondary: #a0a0a0;--cc-font: system-ui, -apple-system, sans-serif;--cc-radius: 12px;--cc-shadow: 0 8px 32px rgba(0, 0, 0, .4);--cc-fab-size: 56px;--cc-panel-width: 400px;--cc-panel-height: 560px;all:initial;font-family:var(--cc-font);font-size:14px;line-height:1.5;color:var(--cc-text);-webkit-font-smoothing:antialiased}*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}.cc-fab{position:fixed;bottom:20px;right:20px;width:var(--cc-fab-size);height:var(--cc-fab-size);border-radius:50%;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 16px #0000004d;transition:transform .2s ease,box-shadow .2s ease;z-index:10000;outline:none}.cc-fab:hover{transform:scale(1.05);box-shadow:0 6px 24px #0006}.cc-fab:active{transform:scale(.95)}.cc-fab.cc-left{right:auto;left:20px}.cc-fab svg{width:24px;height:24px;fill:var(--cc-on-accent);transition:transform .3s ease}.cc-fab.cc-open svg{transform:rotate(90deg)}.cc-fab-badge{position:absolute;top:-2px;right:-2px;width:12px;height:12px;border-radius:50%;background:#ef4444;border:2px solid var(--cc-bg);display:none}.cc-fab-badge.cc-visible{display:block}@keyframes cc-pulse{0%,to{box-shadow:0 4px 16px #0000004d}50%{box-shadow:0 4px 16px #6366f180}}.cc-fab.cc-pulse{animation:cc-pulse 2s ease-in-out 3}.cc-panel{position:fixed;bottom:88px;right:20px;width:var(--cc-panel-width);height:var(--cc-panel-height);max-height:calc(100vh - 100px);background:var(--cc-bg);border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);display:flex;flex-direction:column;overflow:hidden;z-index:9999;opacity:0;transform:translateY(16px) scale(.95);pointer-events:none;transition:opacity .2s ease,transform .2s ease}.cc-panel.cc-visible{opacity:1;transform:translateY(0) scale(1);pointer-events:auto}.cc-panel.cc-left{right:auto;left:20px}.cc-panel.cc-inline{position:relative;bottom:auto;right:auto;left:auto;width:100%;height:100%;max-height:100%;z-index:auto;transform:none;transition:none}.cc-panel.cc-inline:not(.cc-visible){visibility:hidden}.cc-panel.cc-inline.cc-visible{transform:none}.cc-header{display:flex;align-items:center;padding:16px;background:var(--cc-bg-surface);border-bottom:1px solid var(--cc-border);flex-shrink:0}.cc-header-avatar{width:36px;height:36px;border-radius:50%;margin-right:12px;object-fit:cover}.cc-header-avatar-placeholder{width:36px;height:36px;border-radius:50%;margin-right:12px;background:var(--cc-accent);display:flex;align-items:center;justify-content:center}.cc-header-avatar-placeholder svg{width:20px;height:20px;fill:var(--cc-on-accent)}.cc-header-info{flex:1}.cc-header-name{font-size:15px;font-weight:600;color:var(--cc-text)}.cc-header-subtitle{font-size:12px;color:var(--cc-text-secondary)}.cc-header-close{width:32px;height:32px;border-radius:8px;background:transparent;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s ease}.cc-header-close:hover{background:var(--cc-bg-input)}.cc-header-close svg{width:16px;height:16px;fill:var(--cc-text-secondary)}.cc-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px}.cc-messages::-webkit-scrollbar{width:4px}.cc-messages::-webkit-scrollbar-track{background:transparent}.cc-messages::-webkit-scrollbar-thumb{background:var(--cc-border);border-radius:2px}.cc-message{max-width:85%;padding:10px 14px;border-radius:var(--cc-radius);word-wrap:break-word;overflow-wrap:break-word;font-size:14px;line-height:1.5;display:flex;flex-direction:column;gap:8px}.cc-message-user{align-self:flex-end;background:var(--cc-accent-contrast);color:var(--cc-on-accent);border-bottom-right-radius:4px}.cc-message-assistant{align-self:flex-start;background:var(--cc-bg-surface);color:var(--cc-text);border-bottom-left-radius:4px}.cc-message a{color:var(--cc-accent);text-decoration:underline}.cc-message-user a{color:var(--cc-on-accent)}.cc-message-error-note{margin-top:6px;font-size:12px;color:var(--cc-text-secondary)}.cc-message code{background:#0003;padding:1px 4px;border-radius:4px;font-family:SF Mono,Cascadia Code,Consolas,monospace;font-size:13px}.cc-message pre{background:#0000004d;padding:8px 12px;border-radius:8px;overflow-x:auto;margin:4px 0}.cc-message pre code{background:transparent;padding:0}.cc-message ul,.cc-message ol{padding-left:20px;margin:4px 0}.cc-message h1,.cc-message h2,.cc-message h3,.cc-message h4,.cc-message h5,.cc-message h6{font-size:15px;font-weight:600;line-height:1.4;margin:4px 0 0}.cc-message-actions{display:flex;align-items:center}.cc-message-retry,.cc-message-regenerate{display:inline-flex;align-items:center;gap:4px;padding:4px 10px;background:transparent;border:1px solid var(--cc-border);border-radius:6px;color:var(--cc-text-secondary);font-family:var(--cc-font);font-size:12px;cursor:pointer;transition:background .15s ease,color .15s ease,opacity .15s ease}.cc-message-retry:hover,.cc-message-regenerate:hover{background:var(--cc-bg-input);color:var(--cc-text)}.cc-message-retry svg,.cc-message-regenerate svg{fill:currentColor}.cc-message-regenerate{opacity:0}.cc-message:hover .cc-message-regenerate{opacity:1}.cc-message:focus-within .cc-message-regenerate,.cc-message-regenerate:focus-visible{opacity:1}@media(hover:none){.cc-message-regenerate{opacity:1}}.cc-message-retry{border-color:#ef4444;color:#ef4444}.cc-message-retry:hover{background:#ef44441a;color:#ef4444}.cc-typing{display:flex;align-items:center;gap:4px;padding:10px 14px;align-self:flex-start;background:var(--cc-bg-surface);border-radius:var(--cc-radius);border-bottom-left-radius:4px}.cc-typing-dot{width:6px;height:6px;border-radius:50%;background:var(--cc-text-secondary);animation:cc-bounce 1.2s infinite}.cc-typing-dot:nth-child(2){animation-delay:.2s}.cc-typing-dot:nth-child(3){animation-delay:.4s}@keyframes cc-bounce{0%,60%,to{transform:translateY(0)}30%{transform:translateY(-4px)}}.cc-input-area{display:flex;align-items:flex-end;padding:12px 16px;border-top:1px solid var(--cc-border);background:var(--cc-bg);gap:8px}.cc-input{flex:1;background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;line-height:1.5;resize:none;outline:none;max-height:96px;overflow-y:auto;transition:border-color .15s ease}.cc-input:focus{border-color:var(--cc-accent);outline:2px solid var(--cc-accent);outline-offset:1px}.cc-input::placeholder{color:var(--cc-text-secondary)}.cc-send-btn{width:36px;height:36px;border-radius:8px;background:var(--cc-accent);border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:background .15s ease,opacity .15s ease}.cc-send-btn:hover{background:var(--cc-accent-hover)}.cc-send-btn:disabled{opacity:.4;cursor:not-allowed}.cc-send-btn svg{width:16px;height:16px;fill:var(--cc-on-accent)}.cc-footer{padding:6px 16px;text-align:center;font-size:11px;color:var(--cc-text-secondary);border-top:1px solid var(--cc-border)}.cc-footer a{color:var(--cc-text-secondary);text-decoration:none}.cc-footer a:hover{text-decoration:underline}.cc-bubble{position:fixed;bottom:84px;right:20px;background:var(--cc-bg-surface);color:var(--cc-text);padding:10px 16px;border-radius:var(--cc-radius);box-shadow:var(--cc-shadow);border:1px solid var(--cc-border);max-width:260px;font-size:13px;line-height:1.4;z-index:9998;opacity:0;transform:translateY(8px);pointer-events:none;transition:opacity .3s ease,transform .3s ease;cursor:pointer}.cc-bubble.cc-visible{opacity:1;transform:translateY(0);pointer-events:auto}.cc-bubble.cc-left{right:auto;left:20px}.cc-bubble-close{position:absolute;top:-8px;right:-8px;width:20px;height:20px;border-radius:50%;background:var(--cc-bg);border:1px solid var(--cc-border);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:10px;color:var(--cc-text-secondary)}.cc-hidden{display:none}.cc-sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.cc-messages-wrapper{flex:1;display:flex;flex-direction:column;min-height:0}.cc-prechat{flex:1;overflow-y:auto;padding:24px 16px;display:flex;flex-direction:column;gap:16px}.cc-prechat-title{font-size:18px;font-weight:600;color:var(--cc-text)}.cc-prechat-subtitle{font-size:13px;color:var(--cc-text-secondary);margin-top:-8px}.cc-prechat-fields{display:flex;flex-direction:column;gap:14px}.cc-prechat-field{display:flex;flex-direction:column;gap:4px}.cc-prechat-label{font-size:13px;font-weight:500;color:var(--cc-text)}.cc-prechat-label .cc-required{color:#ef4444;margin-left:2px}.cc-prechat-input,.cc-prechat-select,.cc-prechat-textarea{background:var(--cc-bg-input);border:1px solid var(--cc-border);border-radius:8px;padding:8px 12px;color:var(--cc-text);font-family:var(--cc-font);font-size:14px;outline:none;transition:border-color .15s ease}.cc-prechat-input:focus,.cc-prechat-select:focus,.cc-prechat-textarea:focus{border-color:var(--cc-accent)}.cc-prechat-select{-webkit-appearance:auto;-moz-appearance:auto;appearance:auto}.cc-prechat-textarea{resize:none;line-height:1.5}.cc-prechat-error{font-size:12px;color:#ef4444;min-height:0}.cc-prechat-error:empty{display:none}.cc-prechat-submit{background:var(--cc-accent-contrast);color:var(--cc-on-accent);border:none;border-radius:8px;padding:10px 16px;font-family:var(--cc-font);font-size:14px;font-weight:500;cursor:pointer;transition:background .15s ease;margin-top:8px}.cc-prechat-submit:hover{background:var(--cc-accent-hover)}.cc-prechat-submit:disabled{opacity:.5;cursor:not-allowed}@media(max-width:768px){.cc-fab.cc-open{display:none}.cc-panel:not(.cc-inline){width:100%;height:100%;max-height:100%;bottom:0;right:0;left:0;border-radius:0;border:none}.cc-panel.cc-left:not(.cc-inline){left:0}.cc-bubble{bottom:84px;right:16px;left:16px;max-width:none}}.cc-fab:focus-visible,.cc-header-close:focus-visible,.cc-send-btn:focus-visible,.cc-message-retry:focus-visible,.cc-message-regenerate:focus-visible,.cc-bubble-close:focus-visible,.cc-prechat-submit:focus-visible{outline:2px solid var(--cc-accent);outline-offset:3px}@media(prefers-reduced-motion:reduce){.cc-fab.cc-pulse,.cc-typing-dot{animation:none}.cc-panel,.cc-bubble{transition:none}}",s.appendChild(i),s}const n={"&":"&","<":"<",">":">",'"':""","'":"'"};const r=new Set(["http","https","mailto","tel"]);function o(e){let t=e.replace(/[&<>"']/g,e=>n[e]??e);const s=function(e){let t="\0";for(;e.includes(t);)t+="\0";return t}(t),a=[],i=e=>{const t=a.push(e)-1;return`${s}${t}${s}`};t=t.replace(/```(?:\w*)\n?([\s\S]*?)```/g,(e,t)=>i(`<pre><code>${t.trim()}</code></pre>`)),t=t.replace(/`([^`]+)`/g,(e,t)=>i(`<code>${t}</code>`)),t=t.replace(/^(#{1,6}) (.+)$/gm,(e,t,s)=>{const a=t.length;return`<h${a}>${s}</h${a}>`}),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(\S(?:.*?\S)??)\*/g,"<em>$1</em>"),t=t.replace(/\[([^\]]+)\]\(((?:[^()]*|\([^()]*\))*)\)/g,(e,t,s)=>function(e){const t=e.replace(/[\t\n\r]/g,"").replace(/^[\u0000-\u0020]+/,""),s=/^([^:/?#]+):/.exec(t);return!s||r.has(s[1].toLowerCase())}(s)?`<a href="${s}" target="_blank" rel="noopener noreferrer">${t}</a>`:t),t=t.replace(/^[-*+] (.+)$/gm,'<li data-md="ul">$1</li>'),t=t.replace(/^\d+\. (.+)$/gm,'<li data-md="ol">$1</li>'),t=t.replace(/(?:<li data-md="ul">.*?<\/li>\n?)+|(?:<li data-md="ol">.*?<\/li>\n?)+/g,e=>{const t=e.includes('data-md="ol"')?"ol":"ul";return`<${t}>${e.replace(/ data-md="(?:ul|ol)"/g,"").replace(/\n/g,"")}</${t}>`}),t=t.replace(/(<\/h[1-6]>)\n+/g,"$1"),t=t.replace(/\n\n/g,"<br><br>"),t=t.replace(/\n/g,"<br>");for(let n=0;n<a.length;n++)t=t.replace(`${s}${n}${s}`,()=>a[n]);return t}class c{constructor(e,t){s(this,"container"),s(this,"typingEl",null),s(this,"actions"),this.actions=t,this.container=document.createElement("div"),this.container.className="cc-messages",this.container.setAttribute("role","log"),this.container.setAttribute("aria-live","polite"),e.appendChild(this.container)}addMessage(e){this.removeTyping();const t=this.createMessageElement(e);return this.container.appendChild(t),this.scrollToBottom(),t}updateMessage(e){const t=this.findMessage(e.id);t&&(this.renderMessageElement(t,e),this.scrollToBottom())}showTyping(){var e;this.typingEl||(this.typingEl=document.createElement("div"),this.typingEl.className="cc-typing",this.typingEl.innerHTML=`<span class="cc-sr-only">${this.escapeHtml((null==(e=this.actions)?void 0:e.typingLabel)??"Typing...")}</span><div class="cc-typing-dot" aria-hidden="true"></div><div class="cc-typing-dot" aria-hidden="true"></div><div class="cc-typing-dot" aria-hidden="true"></div>`,this.container.appendChild(this.typingEl),this.scrollToBottom())}removeTyping(){this.typingEl&&(this.typingEl.remove(),this.typingEl=null)}clear(){this.container.innerHTML="",this.typingEl=null}removeMessage(e){const t=this.findMessage(e);null==t||t.remove()}clearRegenerateButtons(){this.container.querySelectorAll(".cc-message-regenerate").forEach(e=>e.remove()),this.cleanupEmptyActionContainers()}showRegenerateButton(e){var t;if(this.clearRegenerateButtons(),!(null==(t=this.actions)?void 0:t.onRegenerate))return;const s=this.findMessage(e);if(!s||!s.classList.contains("cc-message-assistant"))return;this.ensureActionsContainer(s).appendChild(this.createActionButton({className:"cc-message-regenerate",label:this.actions.regenerateLabel??"Regenerate",icon:'<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0020 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74A7.93 7.93 0 004 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>',onClick:()=>{var t,s;return null==(s=null==(t=this.actions)?void 0:t.onRegenerate)?void 0:s.call(t,e)}}))}setVisible(e){this.container.classList.toggle("cc-hidden",!e)}findMessage(e){return Array.from(this.container.children).find(t=>t.dataset.id===e)??null}scrollToBottom(){this.container.scrollTop=this.container.scrollHeight}createMessageElement(e){const t=document.createElement("div");return this.renderMessageElement(t,e),t}renderMessageElement(e,t){e.className=`cc-message cc-message-${t.role}`,e.dataset.id=t.id,t.status?e.dataset.status=t.status:delete e.dataset.status,"streaming"===t.status?e.setAttribute("aria-busy","true"):e.removeAttribute("aria-busy"),t.errorType?e.dataset.errorType=t.errorType:delete e.dataset.errorType,e.innerHTML="";const s=document.createElement("div");if(s.className="cc-message-content",s.innerHTML="assistant"===t.role?o(t.content):this.escapeHtml(t.content),e.appendChild(s),"error"===t.status&&t.errorText){const s=document.createElement("div");s.className="cc-message-error-note",s.textContent=t.errorText,e.appendChild(s)}const a=this.createActionsContainer(t);a&&e.appendChild(a)}createActionsContainer(e){var t;if("error"!==e.status||!(null==(t=this.actions)?void 0:t.onRetry))return null;const s=document.createElement("div");return s.className="cc-message-actions",s.appendChild(this.createActionButton({className:"cc-message-retry",label:this.actions.retryLabel??"Retry",icon:'<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d="M17.65 6.35A7.96 7.96 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>',onClick:()=>{var t,s;return null==(s=null==(t=this.actions)?void 0:t.onRetry)?void 0:s.call(t,e.id)}})),s}ensureActionsContainer(e){const t=e.querySelector(".cc-message-actions");if(t)return t;const s=document.createElement("div");return s.className="cc-message-actions",e.appendChild(s),s}cleanupEmptyActionContainers(){this.container.querySelectorAll(".cc-message-actions").forEach(e=>{e.hasChildNodes()||e.remove()})}createActionButton(e){const t=document.createElement("button");return t.type="button",t.className=e.className,t.innerHTML=`${e.icon}<span>${this.escapeHtml(e.label)}</span>`,t.addEventListener("click",e.onClick),t}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}}class l{constructor(e,t){s(this,"area"),s(this,"textarea"),s(this,"sendBtn"),s(this,"onSend"),this.onSend=t.onSend,this.area=document.createElement("div"),this.area.className="cc-input-area",this.textarea=document.createElement("textarea"),this.textarea.className="cc-input",this.textarea.placeholder=t.placeholder,this.textarea.setAttribute("aria-label",t.placeholder),this.textarea.rows=1,this.textarea.maxLength=1e4,this.textarea.addEventListener("input",()=>this.autoResize()),this.textarea.addEventListener("keydown",e=>this.handleKeydown(e)),this.sendBtn=document.createElement("button"),this.sendBtn.className="cc-send-btn",this.sendBtn.disabled=!0,this.sendBtn.setAttribute("aria-label",t.sendLabel),this.sendBtn.innerHTML='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>',this.sendBtn.addEventListener("click",()=>this.send()),this.textarea.addEventListener("input",()=>{this.sendBtn.disabled=0===this.textarea.value.trim().length}),this.area.appendChild(this.textarea),this.area.appendChild(this.sendBtn),e.appendChild(this.area)}focus(){this.textarea.focus()}setDisabled(e){this.textarea.disabled=e,this.sendBtn.disabled=e||0===this.textarea.value.trim().length}clear(){this.textarea.value="",this.sendBtn.disabled=!0,this.autoResize()}setVisible(e){this.area.classList.toggle("cc-hidden",!e)}send(){const e=this.textarea.value.trim();e&&(this.onSend(e),this.clear())}handleKeydown(e){e.isComposing||229===e.keyCode||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),this.send())}autoResize(){this.textarea.style.height="auto";this.textarea.style.height=Math.min(this.textarea.scrollHeight,96)+"px"}}const d="cc-panel";class h{constructor(e,t){s(this,"el"),s(this,"inline"),s(this,"messages"),s(this,"input"),s(this,"messagesContainer"),this.inline=t.inline??!1,this.el=document.createElement("div"),this.el.className="cc-panel",t.inline&&this.el.classList.add("cc-inline"),"bottom-left"===t.position&&this.el.classList.add("cc-left"),t.inline||(this.el.id=d,this.el.setAttribute("role","dialog"),this.el.setAttribute("aria-label",t.branding.name),this.el.addEventListener("keydown",e=>{"Escape"===e.key&&t.onClose()}),this.setHidden(!0));const a=document.createElement("div");if(a.className="cc-header",t.branding.avatar){const e=document.createElement("img");e.className="cc-header-avatar",e.src=t.branding.avatar,e.alt=t.branding.name,a.appendChild(e)}else{const e=document.createElement("div");e.className="cc-header-avatar-placeholder",e.innerHTML='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z"/></svg>',a.appendChild(e)}const i=document.createElement("div");if(i.className="cc-header-info",i.innerHTML=`<div class="cc-header-name">${this.escapeHtml(t.branding.name)}</div><div class="cc-header-subtitle">${this.escapeHtml(t.branding.subtitle)}</div>`,a.appendChild(i),!t.inline){const e=document.createElement("button");e.className="cc-header-close",e.setAttribute("aria-label",t.closeLabel),e.innerHTML='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>',e.addEventListener("click",t.onClose),a.appendChild(e)}this.el.appendChild(a),t.preChatEnabled?(this.messagesContainer=document.createElement("div"),this.messagesContainer.className="cc-messages-wrapper",this.el.appendChild(this.messagesContainer)):this.messagesContainer=this.el,this.messages=new c(this.messagesContainer,t.messageActions),this.input=new l(this.el,{placeholder:t.placeholder,sendLabel:t.sendLabel,onSend:t.onSend});const n=document.createElement("div");n.className="cc-footer",n.innerHTML=t.footerText,this.el.appendChild(n),e.appendChild(this.el)}show(){this.el.classList.add("cc-visible"),this.inline||(this.setHidden(!1),this.input.focus())}hide(){this.el.classList.remove("cc-visible"),this.inline||this.setHidden(!0)}containsFocus(){return this.el.contains(this.el.getRootNode().activeElement)}get isVisible(){return this.el.classList.contains("cc-visible")}addMessage(e){return this.messages.addMessage(e)}hideMessages(){this.messages.setVisible(!1)}showMessages(){this.messages.setVisible(!0)}destroy(){this.el.remove()}setHidden(e){this.el.toggleAttribute("inert",e),e?this.el.setAttribute("aria-hidden","true"):this.el.removeAttribute("aria-hidden")}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}}const p='<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H5.17L4 17.17V4h16v12z"/><path d="M7 9h10v2H7zm0-3h10v2H7z"/></svg>';class u{constructor(e,t){s(this,"el"),s(this,"badge"),s(this,"isOpen",!1),s(this,"openLabel"),s(this,"closeLabel"),this.openLabel=t.openLabel,this.closeLabel=t.closeLabel,this.el=document.createElement("button"),this.el.className="cc-fab cc-pulse",this.el.setAttribute("aria-label",this.openLabel),this.el.setAttribute("aria-expanded","false"),this.el.setAttribute("aria-controls",d),"bottom-left"===t.position&&this.el.classList.add("cc-left"),this.el.innerHTML=p,this.badge=document.createElement("div"),this.badge.className="cc-fab-badge",this.el.appendChild(this.badge),this.el.addEventListener("click",()=>{this.el.classList.remove("cc-pulse"),t.onClick()}),e.appendChild(this.el)}setOpen(e){this.isOpen=e,this.el.innerHTML=e?'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>':p,e||this.el.appendChild(this.badge),this.el.classList.toggle("cc-open",e),this.el.setAttribute("aria-label",e?this.closeLabel:this.openLabel),this.el.setAttribute("aria-expanded",String(e))}focus(){this.el.focus()}showBadge(){this.badge.classList.add("cc-visible")}hideBadge(){this.badge.classList.remove("cc-visible")}destroy(){this.el.remove()}}const m="chatcops_bubble_shown";class g{constructor(e,t){s(this,"el"),s(this,"timerId",null),this.el=document.createElement("div"),this.el.className="cc-bubble","bottom-left"===t.position&&this.el.classList.add("cc-left"),this.el.textContent=t.text,this.setHidden(!0);const a=document.createElement("button");if(a.type="button",a.className="cc-bubble-close",a.setAttribute("aria-label",t.dismissLabel),a.innerHTML="×",a.addEventListener("click",e=>{e.stopPropagation(),this.hide()}),this.el.appendChild(a),this.el.addEventListener("click",()=>{this.hide(),t.onClick()}),e.appendChild(this.el),t.showOnce)try{if(sessionStorage.getItem(m))return;sessionStorage.setItem(m,"1")}catch{}this.timerId=setTimeout(()=>{this.el.classList.add("cc-visible"),this.setHidden(!1)},t.delay??3e3)}hide(){this.el.classList.remove("cc-visible"),this.setHidden(!0),this.timerId&&(clearTimeout(this.timerId),this.timerId=null)}setHidden(e){this.el.toggleAttribute("inert",e),e?this.el.setAttribute("aria-hidden","true"):this.el.removeAttribute("aria-hidden")}destroy(){this.hide(),this.el.remove()}}class b{constructor(e){s(this,"apiUrl"),s(this,"timeout"),this.apiUrl=e.apiUrl,this.timeout=e.timeout??3e4}async*sendMessage(e,t={}){var s;const a=new AbortController,i=t.timeout??this.timeout;let n,r,o=!1;const c=t.signal,l=()=>{clearTimeout(n),a.abort()},d=()=>{clearTimeout(n),a.signal.aborted||(n=setTimeout(()=>{o=!0,a.abort()},i))},h=async()=>{if(clearTimeout(n),null==c||c.removeEventListener("abort",l),r){const e=r;r=void 0;try{await e.cancel()}catch{}finally{e.releaseLock()}}};c&&(c.aborted?a.abort():c.addEventListener("abort",l)),d();try{const t=await fetch(this.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:a.signal});if(!t.ok)return await h(),429===t.status?void(yield{error:"rate_limit"}):void(yield{error:`HTTP ${t.status}`});if(r=null==(s=t.body)?void 0:s.getReader(),!r)return await h(),void(yield{error:"No response body"});const i=new TextDecoder;let n="";for(;;){const{done:e,value:t}=await r.read();if(e)break;t.byteLength>0&&d(),n+=i.decode(t,{stream:!0});const s=n.split("\n");n=s.pop()??"";for(const a of s){const e=a.trim();if(!e||!e.startsWith("data: "))continue;const t=e.slice(6);if("[DONE]"===t)return await h(),void(yield{done:!0});try{yield JSON.parse(t)}catch{}}}await h(),yield{done:!0}}catch(p){await h(),p instanceof DOMException&&"AbortError"===p.name?yield o?{error:"timeout"}:{error:"aborted"}:yield{error:"network"}}finally{await h()}}}const f="chatcops_conversation",v="chatcops_session_id";class x{constructor(e){s(this,"key"),s(this,"sessionKey"),this.key=e?`${f}_${e}`:f,this.sessionKey=e?`${v}_${e}`:v}load(){try{const e=localStorage.getItem(this.key);return e?JSON.parse(e):null}catch{return null}}save(e){try{const t={...e,messages:e.messages.filter(e=>"error"!==e.status).map(({status:e,...t})=>t)};localStorage.setItem(this.key,JSON.stringify(t))}catch{}}clear(){try{localStorage.removeItem(this.key)}catch{}}getSessionId(){try{let e=sessionStorage.getItem(this.sessionKey);return e||(e=crypto.randomUUID(),sessionStorage.setItem(this.sessionKey,e)),e}catch{return crypto.randomUUID()}}isPreChatCompleted(e){try{return"true"===sessionStorage.getItem(`chatcops-prechat-${e}`)}catch{return!1}}setPreChatCompleted(e,t){try{sessionStorage.setItem(`chatcops-prechat-${e}`,"true")}catch{}t&&this.setPreChatData(e,t)}getPreChatData(e){try{const t=sessionStorage.getItem(`chatcops-prechat-data-${e}`);if(!t)return null;const s=JSON.parse(t);return"object"!=typeof s||null===s||Array.isArray(s)?null:s}catch{return null}}setPreChatData(e,t){try{sessionStorage.setItem(`chatcops-prechat-data-${e}`,JSON.stringify(t))}catch{}}}const y=Symbol.for("chatcops.storageClaims"),w=globalThis,C=w[y]??(w[y]=new Map);function E(e){const t=C.get(e);if(!t)return!1;for(const s of t)s()||t.delete(s);return 0===t.size&&C.delete(e),t.size>0}function M(e,t){const s=e.host;if(t.accent){s.style.setProperty("--cc-accent",t.accent),s.style.setProperty("--cc-accent-hover",N(t.accent,10));const e=function(e){if(!function(e){return/^#?[\da-f]{3}(?:[\da-f]{3})?$/i.test(e.trim())}(e))return null;const t=e.trim().startsWith("#")?e.trim():`#${e.trim()}`;if(B(L,t)>=k)return{onAccent:L,background:t};if(B(S,t)>=k)return{onAccent:S,background:t};for(let s=2;s<=60;s+=2){const e=N(t,s);if(B(L,e)>=k)return{onAccent:L,background:e}}return{onAccent:L,background:S}}(t.accent);e?(s.style.setProperty("--cc-on-accent",e.onAccent),s.style.setProperty("--cc-accent-contrast",e.background)):s.style.setProperty("--cc-accent-contrast",t.accent)}if(t.textColor&&s.style.setProperty("--cc-text",t.textColor),t.bgColor&&(s.style.setProperty("--cc-bg",t.bgColor),s.style.setProperty("--cc-bg-surface",$(t.bgColor,8)),s.style.setProperty("--cc-bg-input",$(t.bgColor,14))),t.fontFamily&&s.style.setProperty("--cc-font",t.fontFamily),void 0!==t.borderRadius){const e=function(e){if("number"==typeof e&&!Number.isFinite(e))return"";const t=String(e).trim();return/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(t)?`${t}px`:t}(t.borderRadius);e&&s.style.setProperty("--cc-radius",e)}}const L="#ffffff",S="#0a0a0a",k=4.5;function T(e){const t=I(e).map(e=>{const t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4});return.2126*t[0]+.7152*t[1]+.0722*t[2]}function B(e,t){const[s,a]=[T(e),T(t)].sort((e,t)=>t-e);return(s+.05)/(a+.05)}function I(e){if(!/^#?[\da-f]{3}(?:[\da-f]{3})?$/i.test(e))return[0,0,0];const t=e.replace("#",""),s=parseInt(3===t.length?t.split("").map(e=>e+e).join(""):t,16);return[s>>16&255,s>>8&255,255&s]}function A(e,t,s){return"#"+[e,t,s].map(e=>Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")).join("")}function N(e,t){const[s,a,i]=I(e),n=1-t/100;return A(Math.round(s*n),Math.round(a*n),Math.round(i*n))}function $(e,t){const[s,a,i]=I(e),n=t/100;return A(Math.round(s+(255-s)*n),Math.round(a+(255-a)*n),Math.round(i+(255-i)*n))}const H={welcomeMessage:"How can I help you today?",inputPlaceholder:"Type a message...",sendButton:"Send",closeButton:"Close",openChat:"Open chat",defaultName:"AI Assistant",defaultSubtitle:"Online",greetingWithName:"Hi {name}!",selectPlaceholder:"Select {label}...",dismissBubble:"Dismiss",errorGeneric:"Something went wrong. Please try again.",errorNetwork:"Connection error. Please check your network.",errorRateLimit:"Too many messages. Please wait a moment.",typingIndicator:"Typing...",poweredBy:"Powered by ChatCops",newConversation:"New conversation",welcomeBubbleDefault:"Need help? Chat with us!",preChatTitle:"Before we start...",preChatSubtitle:"Tell us a bit about yourself",preChatSubmit:"Start Chat",preChatRequired:"This field is required",preChatInvalidEmail:"Please enter a valid email",retryButton:"Retry",regenerateButton:"Regenerate"},z={en:H};class R{constructor(e,t){if(s(this,"container"),s(this,"fieldElements",new Map),s(this,"errorElements",new Map),s(this,"submitBtn"),s(this,"options"),this.options=t,this.container=document.createElement("div"),this.container.className="cc-prechat",t.title){const e=document.createElement("div");e.className="cc-prechat-title",e.textContent=t.title,this.container.appendChild(e)}if(t.subtitle){const e=document.createElement("div");e.className="cc-prechat-subtitle",e.textContent=t.subtitle,this.container.appendChild(e)}const a=document.createElement("form");a.className="cc-prechat-fields",a.noValidate=!0,a.addEventListener("submit",e=>{e.preventDefault(),this.handleSubmit()});for(const s of t.fields)a.appendChild(this.createField(s));this.submitBtn=document.createElement("button"),this.submitBtn.type="submit",this.submitBtn.className="cc-prechat-submit",this.submitBtn.textContent=t.submitLabel,a.appendChild(this.submitBtn),this.container.appendChild(a),e.appendChild(this.container),this.updateSubmitState();const i=this.fieldElements.values().next().value;i&&setTimeout(()=>i.focus(),100)}createField(e){const t=document.createElement("div");t.className="cc-prechat-field";const s=`cc-prechat-${e.name}`,a=`cc-prechat-${e.name}-error`,i=document.createElement("label");if(i.className="cc-prechat-label",i.htmlFor=s,i.textContent=e.label,e.required){const e=document.createElement("span");e.className="cc-required",e.textContent="*",i.appendChild(e)}let n;if(t.appendChild(i),"select"===e.type){const t=document.createElement("select");t.className="cc-prechat-select";const s=document.createElement("option");s.value="",s.textContent=e.placeholder??this.options.locale.selectPlaceholder.replace("{label}",e.label.toLowerCase()),s.disabled=!0,s.selected=!0,t.appendChild(s);for(const a of e.options??[]){const e=document.createElement("option");e.value=a,e.textContent=a,t.appendChild(e)}n=t}else if("textarea"===e.type){const t=document.createElement("textarea");t.className="cc-prechat-textarea",t.placeholder=e.placeholder??"",t.rows=3,t.maxLength=500,n=t}else{const t=document.createElement("input");t.type=e.type,t.className="cc-prechat-input",t.maxLength=500,t.placeholder=e.placeholder??"",n=t}n.name=e.name,n.id=s,e.required&&n.setAttribute("aria-required","true"),n.addEventListener("input",()=>{this.clearError(e.name),this.updateSubmitState()}),n instanceof HTMLSelectElement&&n.addEventListener("change",()=>{this.clearError(e.name),this.updateSubmitState()}),t.appendChild(n),this.fieldElements.set(e.name,n);const r=document.createElement("div");return r.className="cc-prechat-error",r.id=a,t.appendChild(r),this.errorElements.set(e.name,r),t}updateSubmitState(){const e=this.options.fields.every(e=>{if(!e.required)return!0;const t=this.fieldElements.get(e.name);return!!t&&t.value.trim().length>0});this.submitBtn.disabled=!e}handleSubmit(){const e={};let t=!0;for(const s of this.options.fields){const a=this.fieldElements.get(s.name);if(!a)continue;const i=a.value.trim();e[s.name]=i,!s.required||i?"email"!==s.type||!i||this.isValidEmail(i)||(this.showError(s.name,this.options.locale.preChatInvalidEmail),t=!1):(this.showError(s.name,this.options.locale.preChatRequired),t=!1)}t&&this.options.onSubmit(e)}showError(e,t){const s=this.errorElements.get(e);s&&(s.textContent=t);const a=this.fieldElements.get(e);a&&s&&(a.setAttribute("aria-invalid","true"),a.setAttribute("aria-describedby",s.id))}clearError(e){const t=this.errorElements.get(e);t&&(t.textContent="");const s=this.fieldElements.get(e);s&&t&&(s.getAttribute("aria-describedby")===t.id&&s.removeAttribute("aria-describedby"),"true"===s.getAttribute("aria-invalid")&&s.removeAttribute("aria-invalid"))}isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}destroy(){this.container.remove(),this.fieldElements.clear(),this.errorElements.clear()}}class P{constructor(e){s(this,"config"),s(this,"shadow"),s(this,"mounted",!1),s(this,"fab"),s(this,"panel"),s(this,"bubble"),s(this,"preChatFormEl"),s(this,"client"),s(this,"storage"),s(this,"namespace"),s(this,"locale"),s(this,"conversationId"),s(this,"messages",[]),s(this,"userData"),s(this,"isStreaming",!1),s(this,"destroyed",!1),s(this,"abortController"),s(this,"retryRequests",new Map),s(this,"eventHandlers",new Map),s(this,"containerEl"),s(this,"autoOpenTimer"),this.config=e,this.client=new b({apiUrl:e.apiUrl,timeout:e.timeout}),this.namespace=function(e,t,s){let a=e??"";if(void 0===e&&E("")){a=t;for(let e=2;E(a);e+=1)a=`${t}-${e}`;console.warn(`[chatcops] Another widget on this page already uses the default storage, so this one keeps its conversation under "${a}". Set a \`siteId\` on each widget to name them yourself.`)}else void 0!==e&&E(e)&&console.warn(`[chatcops] Two widgets on this page use the siteId "${e}", so they share one conversation.`);return C.has(a)||C.set(a,new Set),C.get(a).add(s),{siteId:""===a?void 0:a,release(){var e,t;null==(e=C.get(a))||e.delete(s),0===(null==(t=C.get(a))?void 0:t.size)&&C.delete(a)}}}(e.siteId,e.mode??"popup",()=>!this.destroyed&&(!this.mounted||this.shadow.host.isConnected)),this.storage=new x(this.namespace.siteId),this.locale=function(e,t){const s=z[e]??H;return t?{...s,...t}:s}(e.locale??"en",e.strings),this.conversationId=this.storage.getSessionId()}get isInline(){return"inline"===this.config.mode}resolveContainer(){if(!this.config.container)throw new Error('ChatCops: "container" is required when mode is "inline"');if("string"==typeof this.config.container){const e=document.querySelector(this.config.container);if(!e)throw new Error(`ChatCops: container element not found: ${this.config.container}`);return e}return this.config.container}init(){var e,t,s,a,n,r,o;this.isInline?(this.containerEl=this.resolveContainer(),this.shadow=i(this.containerEl)):this.shadow=i(),this.mounted=!0,this.config.theme&&M(this.shadow,this.config.theme);const c=(null==(e=this.config.theme)?void 0:e.position)??"bottom-right";if(this.isInline||(this.fab=new u(this.shadow,{position:c,openLabel:this.locale.openChat,closeLabel:this.locale.closeButton,onClick:()=>this.toggle()})),this.panel=new h(this.shadow,{position:c,inline:this.isInline,preChatEnabled:(null==(t=this.config.preChatForm)?void 0:t.enabled)??!1,branding:{name:(null==(s=this.config.branding)?void 0:s.name)??this.locale.defaultName,avatar:null==(a=this.config.branding)?void 0:a.avatar,subtitle:(null==(n=this.config.branding)?void 0:n.subtitle)??this.locale.defaultSubtitle},placeholder:this.config.placeholder??this.locale.inputPlaceholder,footerText:this.locale.poweredBy,closeLabel:this.locale.closeButton,sendLabel:this.locale.sendButton,messageActions:{onRetry:e=>{this.handleRetry(e)},onRegenerate:e=>{this.handleRegenerate(e)},retryLabel:this.locale.retryButton,regenerateLabel:this.locale.regenerateButton,typingLabel:this.locale.typingIndicator},onSend:e=>this.handleSend(e),onClose:()=>this.close()}),!1!==this.config.persistHistory){const e=this.storage.load();if(e){this.conversationId=e.id;for(const t of e.messages)this.messages.push(t),this.panel.addMessage(t)}}if(null==(r=this.config.preChatForm)?void 0:r.enabled){const e=this.storage.getPreChatData(this.conversationId);e&&(this.userData=e)}if((null==(o=this.config.preChatForm)?void 0:o.enabled)&&!this.isPreChatCompleted()&&0===this.messages.length?this.showPreChatForm():this.showChatView(),this.showLatestRegenerateButton(),!this.isInline&&this.config.welcomeBubble&&(this.bubble=new g(this.shadow,{text:this.config.welcomeBubble.text,delay:this.config.welcomeBubble.delay,showOnce:this.config.welcomeBubble.showOnce??!0,position:c,dismissLabel:this.locale.dismissBubble,onClick:()=>this.open()})),this.isInline&&this.panel.show(),!this.isInline&&void 0!==this.config.autoOpen&&!1!==this.config.autoOpen){const e="number"==typeof this.config.autoOpen?this.config.autoOpen:0;this.autoOpenTimer=setTimeout(()=>this.open(),e)}}open(){var e,t,s,a,i;this.panel.show(),this.isInline||(null==(e=this.fab)||e.setOpen(!0),null==(t=this.fab)||t.hideBadge(),null==(s=this.bubble)||s.hide()),null==(i=(a=this.config).onOpen)||i.call(a),this.emit("open")}close(){var e,t,s,a;const i=this.panel.containsFocus();this.panel.hide(),this.isInline||(null==(e=this.fab)||e.setOpen(!1),i&&(null==(t=this.fab)||t.focus())),null==(a=(s=this.config).onClose)||a.call(s),this.emit("close")}toggle(){this.panel.isVisible?this.close():this.open()}destroy(){var e,t,s,a,i;this.destroyed=!0,void 0!==this.autoOpenTimer&&clearTimeout(this.autoOpenTimer),null==(e=this.abortController)||e.abort(),this.abortController=void 0,null==(t=this.preChatFormEl)||t.destroy(),null==(s=this.bubble)||s.destroy(),this.panel.destroy(),null==(a=this.fab)||a.destroy(),null==(i=this.shadow)||i.host.remove(),this.namespace.release(),this.eventHandlers.clear(),this.messages=[],this.userData=void 0}on(e,t){return this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set),this.eventHandlers.get(e).add(t),()=>this.off(e,t)}off(e,t){var s;null==(s=this.eventHandlers.get(e))||s.delete(t)}emit(e,...t){var s;this.destroyed||null==(s=this.eventHandlers.get(e))||s.forEach(e=>e(...t))}isPreChatCompleted(){return this.storage.isPreChatCompleted(this.conversationId)}setPreChatCompleted(e){this.storage.setPreChatCompleted(this.conversationId,e)}showPreChatForm(){const e=this.config.preChatForm;this.panel.hideMessages(),this.panel.input.setVisible(!1),this.preChatFormEl=new R(this.panel.messagesContainer,{title:e.title??this.locale.preChatTitle,subtitle:e.subtitle??this.locale.preChatSubtitle,fields:e.fields,submitLabel:e.submitLabel??this.locale.preChatSubmit,locale:this.locale,onSubmit:e=>this.handlePreChatSubmit(e)})}handlePreChatSubmit(e){var t,s,a,i;(null==(t=this.config.preChatForm)?void 0:t.enabled)&&(this.userData=e,this.setPreChatCompleted(e),null==(s=this.preChatFormEl)||s.destroy(),this.preChatFormEl=void 0,this.panel.showMessages(),this.panel.input.setVisible(!0),this.showChatView(),null==(i=(a=this.config).onPreChatSubmit)||i.call(a,e),this.emit("preChatSubmit",e),e.message&&this.handleSend(e.message))}showChatView(){var e;if(0===this.messages.length){const t=null==(e=this.userData)?void 0:e.name,s=this.locale.greetingWithName.replace("{name}",()=>t),a={id:"welcome",role:"assistant",content:t?`${s} ${this.config.welcomeMessage??this.locale.welcomeMessage}`:this.config.welcomeMessage??this.locale.welcomeMessage};this.messages.push(a),this.panel.addMessage(a)}}async handleSend(e){var t,s;if(this.isStreaming)return;const a={id:crypto.randomUUID(),role:"user",content:e};this.messages.push(a),this.panel.addMessage(a),null==(s=(t=this.config).onMessage)||s.call(t,a),this.emit("message",a),await this.sendToServer(e,{userMessageId:a.id})}async handleRetry(e){if(this.isStreaming)return;const t=this.messages.findIndex(t=>t.id===e);if(-1===t)return;const s=this.retryRequests.get(e);let a=(null==s?void 0:s.userMessageId)?this.messages.find(e=>e.id===s.userMessageId):void 0;if(!a)for(let i=t-1;i>=0;i--)if("user"===this.messages[i].role){a=this.messages[i];break}a&&(this.panel.messages.removeMessage(e),this.retryRequests.delete(e),this.messages=this.messages.filter(t=>t.id!==e),await this.sendToServer(a.content,{regenerate:null==s?void 0:s.regenerate,userMessageId:(null==s?void 0:s.userMessageId)??a.id}))}async handleRegenerate(e){if(this.isStreaming)return;const t=this.messages.findIndex(t=>t.id===e);if(-1===t)return;if("assistant"!==this.messages[t].role)return;const s=this.findUserMessageForAssistant(t);s&&(this.panel.messages.clearRegenerateButtons(),this.panel.messages.removeMessage(e),this.retryRequests.delete(e),this.messages=this.messages.filter(t=>t.id!==e),await this.sendToServer(s.content,{regenerate:!0,userMessageId:s.id}))}async sendToServer(e,t={}){var s,a,i,n,r,o,c,l,d;if(this.isStreaming)return;this.isStreaming=!0,this.panel.input.setDisabled(!0),this.panel.messages.clearRegenerateButtons(),this.panel.messages.showTyping();const h={id:crypto.randomUUID(),role:"assistant",content:"",status:"streaming"};let p=!0,u=!1,m=!1;const g=new AbortController;this.abortController=g;try{for await(const r of this.client.sendMessage(this.createRequest(e,t),{signal:g.signal})){if(this.destroyed)break;if(r.error){const e=this.resolveErrorType(r.error);this.markFailed(h,this.getErrorMessage(e)),h.errorType=e,m=!0,this.retryRequests.set(h.id,{regenerate:t.regenerate,userMessageId:t.userMessageId}),this.panel.messages.removeTyping(),p?this.panel.addMessage(h):this.panel.messages.updateMessage(h),this.messages.push(h);const i=new Error(r.error);null==(a=(s=this.config).onError)||a.call(s,i),this.emit("error",i);break}if(r.done){u=!0;break}r.leadCaptured&&(null==(n=(i=this.config).onLeadCaptured)||n.call(i,r.leadData),this.emit("leadCaptured",r.leadData)),r.content&&(p&&(this.panel.messages.removeTyping(),this.panel.addMessage(h),p=!1),h.content+=r.content,this.panel.messages.updateMessage(h))}if(this.destroyed)return;m||u||(u=!0),!m&&p&&this.panel.messages.removeTyping(),!m&&h.content&&(h.status="complete",this.panel.messages.updateMessage(h),this.messages.push(h),null==(o=(r=this.config).onMessage)||o.call(r,h),this.emit("message",h),this.showLatestRegenerateButton(),this.isInline||this.panel.isVisible||null==(c=this.fab)||c.showBadge())}catch(b){if(this.destroyed)return;this.markFailed(h,this.locale.errorGeneric),h.errorType="network",this.retryRequests.set(h.id,{regenerate:t.regenerate,userMessageId:t.userMessageId}),this.panel.messages.removeTyping(),p?this.panel.addMessage(h):this.panel.messages.updateMessage(h),this.messages.push(h);const e=b instanceof Error?b:new Error(String(b));null==(d=(l=this.config).onError)||d.call(l,e),this.emit("error",e)}finally{this.abortController===g&&(this.abortController=void 0),this.destroyed||(this.isStreaming=!1,this.panel.input.setDisabled(!1),this.panel.input.focus(),this.saveHistory())}}createRequest(e,t){var s;const a=!1!==this.config.pageContext?{url:window.location.href,title:document.title}:void 0,i=Boolean((null==(s=this.config.preChatForm)?void 0:s.enabled)&&this.userData);return{conversationId:this.conversationId,message:e,messageId:t.userMessageId,regenerate:t.regenerate,pageContext:a,locale:this.config.locale,...i?{userData:this.userData}:{}}}findUserMessageForAssistant(e){for(let t=e-1;t>=0;t--)if("user"===this.messages[t].role)return this.messages[t]}findLatestRegeneratableAssistant(){for(let e=this.messages.length-1;e>=0;e--){const t=this.messages[e];if("welcome"!==t.id){if("assistant"!==t.role||"error"===t.status)return;return t}}}showLatestRegenerateButton(){const e=this.findLatestRegeneratableAssistant();e?this.panel.messages.showRegenerateButton(e.id):this.panel.messages.clearRegenerateButtons()}resolveErrorType(e){switch(e){case"rate_limit":case"network":case"provider_error":case"timeout":return e;default:return"provider_error"}}markFailed(e,t){e.status="error",e.content.trim()?e.errorText=t:e.content=t}getErrorMessage(e){switch(e){case"rate_limit":return this.locale.errorRateLimit;case"network":case"timeout":return this.locale.errorNetwork;default:return this.locale.errorGeneric}}saveHistory(){if(!1===this.config.persistHistory)return;const e=this.config.maxMessages??50,t=this.messages.filter(e=>"welcome"!==e.id).slice(-e);this.storage.save({id:this.conversationId,messages:t.map(e=>({id:e.id,role:e.role,content:e.content,status:e.status,errorType:e.errorType,timestamp:Date.now()})),updatedAt:Date.now()})}}let O=null;const D=new Map;function F(e){if(void 0!==e)return""===e||"true"===e||"false"!==e&&(/^\d+$/.test(e)?Number(e):void 0)}const q={init(e){O&&O.destroy(),O=new P(e);for(const[t,s]of D)for(const e of s)O.on(t,e);return O.init(),O},open(){null==O||O.open()},close(){null==O||O.close()},destroy(){null==O||O.destroy(),O=null},on(e,t){let s=D.get(e);return s||(s=new Set,D.set(e,s)),s.add(t),null==O||O.on(e,t),()=>{q.off(e,t)}},off(e,t){var s;null==(s=D.get(e))||s.delete(t),null==O||O.off(e,t)}};function V(e){if(!e)return;const t=e.dataset.apiUrl;if(!t)return;const s=e.dataset.mode,a=e.dataset.container;q.init({apiUrl:t,mode:s||void 0,container:a||void 0,theme:{accent:e.dataset.accent,textColor:e.dataset.textColor,bgColor:e.dataset.bgColor,fontFamily:e.dataset.fontFamily,borderRadius:e.dataset.borderRadius,position:e.dataset.position||void 0},branding:{name:e.dataset.brandName,avatar:e.dataset.brandAvatar,subtitle:e.dataset.brandSubtitle},welcomeMessage:e.dataset.welcomeMessage,welcomeBubble:e.dataset.welcomeBubble?{text:e.dataset.welcomeBubble,delay:e.dataset.welcomeBubbleDelay?parseInt(e.dataset.welcomeBubbleDelay,10):void 0}:void 0,autoOpen:F(e.dataset.autoOpen),placeholder:e.dataset.placeholder,locale:e.dataset.locale})}const U="undefined"!=typeof document?document.currentScript:null;return U&&U.dataset.apiUrl&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>V(U),{once:!0}):V(U)),"undefined"!=typeof window&&(window.ChatCops=q),e.Widget=P,e.default=q,e.parseAutoOpen=F,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});"undefined"!=typeof window&&window.ChatCops&&window.ChatCops.default&&Object.assign(window.ChatCops,window.ChatCops.default);
|
package/dist/dom/bubble.d.ts
CHANGED
package/dist/dom/bubble.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bubble.d.ts","sourceRoot":"","sources":["../../src/dom/bubble.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAID,qBAAa,aAAa;IACxB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,OAAO,CAA8C;gBAEjD,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa;
|
|
1
|
+
{"version":3,"file":"bubble.d.ts","sourceRoot":"","sources":["../../src/dom/bubble.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAID,qBAAa,aAAa;IACxB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,OAAO,CAA8C;gBAEjD,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa;IA2CpD,IAAI,IAAI,IAAI;IASZ,OAAO,CAAC,SAAS;IAMjB,OAAO,IAAI,IAAI;CAIhB"}
|
package/dist/dom/fab.d.ts
CHANGED
package/dist/dom/fab.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fab.d.ts","sourceRoot":"","sources":["../../src/dom/fab.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fab.d.ts","sourceRoot":"","sources":["../../src/dom/fab.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,qBAAa,GAAG;IACd,OAAO,CAAC,EAAE,CAAoB;IAC9B,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;gBAEf,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU;IA0BjD,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAS5B,KAAK,IAAI,IAAI;IAIb,SAAS,IAAI,IAAI;IAIjB,SAAS,IAAI,IAAI;IAIjB,OAAO,IAAI,IAAI;CAGhB"}
|
package/dist/dom/messages.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface MessageData {
|
|
|
6
6
|
content: string;
|
|
7
7
|
status?: MessageStatus;
|
|
8
8
|
errorType?: MessageErrorType;
|
|
9
|
+
/** Shown under the content when a reply fails after some of it already streamed. */
|
|
10
|
+
errorText?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface MessageActions {
|
|
11
13
|
onRetry?: (messageId: string) => void;
|
|
@@ -28,6 +30,7 @@ export declare class Messages {
|
|
|
28
30
|
clearRegenerateButtons(): void;
|
|
29
31
|
showRegenerateButton(messageId: string): void;
|
|
30
32
|
setVisible(visible: boolean): void;
|
|
33
|
+
private findMessage;
|
|
31
34
|
private scrollToBottom;
|
|
32
35
|
private createMessageElement;
|
|
33
36
|
private renderMessageElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/dom/messages.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAC/D,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAEvF,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/dom/messages.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAC/D,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAEvF,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,OAAO,CAAC,CAAiB;gBAErB,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc;IASzD,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,cAAc;IAQ5C,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAQrC,UAAU,IAAI,IAAI;IASlB,YAAY,IAAI,IAAI;IAOpB,KAAK,IAAI,IAAI;IAKb,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,IAAI,IAAI;IAK9B,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAiB7C,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,oBAAoB;IA0C5B,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,4BAA4B;IAQpC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,UAAU;CAKnB"}
|
package/dist/dom/panel.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Messages, type MessageActions, type MessageData } from './messages.js';
|
|
2
2
|
import { Input } from './input.js';
|
|
3
|
+
export declare const PANEL_ID = "cc-panel";
|
|
3
4
|
export interface PanelOptions {
|
|
4
5
|
position: 'bottom-right' | 'bottom-left';
|
|
5
6
|
inline?: boolean;
|
|
@@ -26,11 +27,13 @@ export declare class Panel {
|
|
|
26
27
|
constructor(root: ShadowRoot, options: PanelOptions);
|
|
27
28
|
show(): void;
|
|
28
29
|
hide(): void;
|
|
30
|
+
containsFocus(): boolean;
|
|
29
31
|
get isVisible(): boolean;
|
|
30
32
|
addMessage(msg: MessageData): HTMLDivElement;
|
|
31
33
|
hideMessages(): void;
|
|
32
34
|
showMessages(): void;
|
|
33
35
|
destroy(): void;
|
|
36
|
+
private setHidden;
|
|
34
37
|
private escapeHtml;
|
|
35
38
|
}
|
|
36
39
|
//# sourceMappingURL=panel.d.ts.map
|
package/dist/dom/panel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/dom/panel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAKnC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,MAAM,CAAU;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,iBAAiB,EAAE,WAAW,CAAC;gBAEnB,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY;
|
|
1
|
+
{"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/dom/panel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,eAAO,MAAM,QAAQ,aAAa,CAAC;AAKnC,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,MAAM,CAAU;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,iBAAiB,EAAE,WAAW,CAAC;gBAEnB,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY;IA8EnD,IAAI,IAAI,IAAI;IAQZ,IAAI,IAAI,IAAI;IAKZ,aAAa,IAAI,OAAO;IAIxB,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,cAAc;IAI5C,YAAY,IAAI,IAAI;IAIpB,YAAY,IAAI,IAAI;IAIpB,OAAO,IAAI,IAAI;IAKf,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;CAKnB"}
|
package/dist/dom/shadow.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the widget's host element and shadow root. The first widget on the
|
|
3
|
+
* page keeps the id `chatcops-root` (sites style it); later ones get
|
|
4
|
+
* `chatcops-root-2`, `chatcops-root-3` and so on. Every host has the class
|
|
5
|
+
* `chatcops-root`.
|
|
6
|
+
*/
|
|
1
7
|
export declare function createShadowRoot(container?: HTMLElement): ShadowRoot;
|
|
2
|
-
|
|
8
|
+
/** Removes the host this widget created, and no other widget's. */
|
|
9
|
+
export declare function destroyShadowRoot(shadow?: ShadowRoot): void;
|
|
3
10
|
//# sourceMappingURL=shadow.d.ts.map
|
package/dist/dom/shadow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow.d.ts","sourceRoot":"","sources":["../../src/dom/shadow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shadow.d.ts","sourceRoot":"","sources":["../../src/dom/shadow.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,WAAW,GAAG,UAAU,CAkBpE;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAE3D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Widget, type WidgetConfig } from './widget.js';
|
|
2
|
-
export { Widget, type WidgetConfig } from './widget.js';
|
|
1
|
+
import { Widget, type WidgetConfig, type WidgetEventType, type WidgetEventHandler } from './widget.js';
|
|
2
|
+
export { Widget, type WidgetConfig, type WidgetEventType, type WidgetEventHandler, } from './widget.js';
|
|
3
3
|
export declare function parseAutoOpen(value?: string): boolean | number | undefined;
|
|
4
4
|
declare const ChatCops: {
|
|
5
5
|
init(config: WidgetConfig): Widget;
|
|
6
6
|
open(): void;
|
|
7
7
|
close(): void;
|
|
8
8
|
destroy(): void;
|
|
9
|
-
on(event:
|
|
10
|
-
off(event:
|
|
9
|
+
on(event: WidgetEventType, handler: WidgetEventHandler): () => void;
|
|
10
|
+
off(event: WidgetEventType, handler: WidgetEventHandler): void;
|
|
11
11
|
};
|
|
12
12
|
export default ChatCops;
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAKrB,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAM1E;AAED,QAAA,MAAM,QAAQ;iBACC,YAAY,GAAG,MAAM;YAc1B,IAAI;aAIH,IAAI;eAIF,IAAI;cAKL,eAAe,WAAW,kBAAkB,GAAG,MAAM,IAAI;eAaxD,eAAe,WAAW,kBAAkB,GAAG,IAAI;CAI/D,CAAC;AAyDF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ClaimedNamespace {
|
|
2
|
+
/** `undefined` means the default keys, which a single widget always gets. */
|
|
3
|
+
siteId?: string;
|
|
4
|
+
release(): void;
|
|
5
|
+
}
|
|
6
|
+
export declare function claimNamespace(siteId: string | undefined, mode: 'popup' | 'inline', isLive: () => boolean): ClaimedNamespace;
|
|
7
|
+
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,IAAI,IAAI,CAAC;CACjB;AAYD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,OAAO,GAAG,QAAQ,EACxB,MAAM,EAAE,MAAM,OAAO,GACpB,gBAAgB,CAuBlB"}
|
package/dist/storage.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ interface StoredConversation {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class ConversationStorage {
|
|
14
14
|
private key;
|
|
15
|
+
private sessionKey;
|
|
16
|
+
/** Without a siteId the keys are the ones the widget has always used. */
|
|
15
17
|
constructor(siteId?: string);
|
|
16
18
|
load(): StoredConversation | null;
|
|
17
19
|
save(conversation: StoredConversation): void;
|
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAC3B,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;QAC5C,SAAS,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAAC;QACpE,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,UAAU,kBAAkB;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAC3B,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;QAC5C,SAAS,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAAC;QACpE,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAKD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,UAAU,CAAS;IAE3B,yEAAyE;gBAC7D,MAAM,CAAC,EAAE,MAAM;IAK3B,IAAI,IAAI,kBAAkB,GAAG,IAAI;IAUjC,IAAI,CAAC,YAAY,EAAE,kBAAkB,GAAG,IAAI;IAc5C,KAAK,IAAI,IAAI;IAQb,YAAY,IAAI,MAAM;IAatB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAQ9C,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAW3E,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAchE,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAOtE"}
|
package/dist/theme.d.ts
CHANGED
|
@@ -7,4 +7,18 @@ export interface ThemeConfig {
|
|
|
7
7
|
position?: 'bottom-right' | 'bottom-left';
|
|
8
8
|
}
|
|
9
9
|
export declare function applyTheme(root: ShadowRoot, theme: ThemeConfig): void;
|
|
10
|
+
export declare function contrastRatio(a: string, b: string): number;
|
|
11
|
+
/**
|
|
12
|
+
* Picks the text color for an accent background, and the accent shade to put
|
|
13
|
+
* text on, so text always reaches 4.5:1:
|
|
14
|
+
* - white text when it passes on the accent as is
|
|
15
|
+
* - near-black text when that passes (light accents keep their exact color)
|
|
16
|
+
* - otherwise white text on the accent darkened just enough
|
|
17
|
+
* Icons can keep using the plain accent with `onAccent`; they need only 3:1.
|
|
18
|
+
* Returns null for colors that aren't hex, which keep the default tokens.
|
|
19
|
+
*/
|
|
20
|
+
export declare function accentTextColors(accent: string): {
|
|
21
|
+
onAccent: string;
|
|
22
|
+
background: string;
|
|
23
|
+
} | null;
|
|
10
24
|
//# sourceMappingURL=theme.d.ts.map
|
package/dist/theme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;CAC3C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;CAC3C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CA6BrE;AA6BD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAYhG"}
|
package/dist/widget.d.ts
CHANGED
|
@@ -20,6 +20,12 @@ export interface WidgetConfig {
|
|
|
20
20
|
/** Request/stream inactivity timeout in milliseconds. Defaults to 30000. */
|
|
21
21
|
timeout?: number;
|
|
22
22
|
mode?: 'popup' | 'inline';
|
|
23
|
+
/**
|
|
24
|
+
* Names this widget's saved conversation. Set a different one on each widget
|
|
25
|
+
* when a page has more than one. Without it a single widget uses the default
|
|
26
|
+
* storage, and a second widget on the page is given its own automatically.
|
|
27
|
+
*/
|
|
28
|
+
siteId?: string;
|
|
23
29
|
container?: string | HTMLElement;
|
|
24
30
|
theme?: {
|
|
25
31
|
accent?: string;
|
|
@@ -55,17 +61,19 @@ export interface WidgetConfig {
|
|
|
55
61
|
onLeadCaptured?: (leadData?: Record<string, unknown>) => void;
|
|
56
62
|
onPreChatSubmit?: (data: Record<string, string>) => void;
|
|
57
63
|
}
|
|
58
|
-
type WidgetEventType = 'open' | 'close' | 'message' | 'error' | 'leadCaptured' | 'preChatSubmit';
|
|
59
|
-
type WidgetEventHandler = (...args: unknown[]) => void;
|
|
64
|
+
export type WidgetEventType = 'open' | 'close' | 'message' | 'error' | 'leadCaptured' | 'preChatSubmit';
|
|
65
|
+
export type WidgetEventHandler = (...args: unknown[]) => void;
|
|
60
66
|
export declare class Widget {
|
|
61
67
|
private config;
|
|
62
68
|
private shadow;
|
|
69
|
+
private mounted;
|
|
63
70
|
private fab?;
|
|
64
71
|
private panel;
|
|
65
72
|
private bubble?;
|
|
66
73
|
private preChatFormEl?;
|
|
67
74
|
private client;
|
|
68
75
|
private storage;
|
|
76
|
+
private namespace;
|
|
69
77
|
private locale;
|
|
70
78
|
private conversationId;
|
|
71
79
|
private messages;
|
|
@@ -85,7 +93,7 @@ export declare class Widget {
|
|
|
85
93
|
close(): void;
|
|
86
94
|
toggle(): void;
|
|
87
95
|
destroy(): void;
|
|
88
|
-
on(event: WidgetEventType, handler: WidgetEventHandler): void;
|
|
96
|
+
on(event: WidgetEventType, handler: WidgetEventHandler): () => void;
|
|
89
97
|
off(event: WidgetEventType, handler: WidgetEventHandler): void;
|
|
90
98
|
private emit;
|
|
91
99
|
private isPreChatCompleted;
|
|
@@ -102,8 +110,12 @@ export declare class Widget {
|
|
|
102
110
|
private findLatestRegeneratableAssistant;
|
|
103
111
|
private showLatestRegenerateButton;
|
|
104
112
|
private resolveErrorType;
|
|
113
|
+
/**
|
|
114
|
+
* Marks a reply as failed. Text that already streamed stays, and the error
|
|
115
|
+
* shows as a note under it; an empty reply shows the error as its content.
|
|
116
|
+
*/
|
|
117
|
+
private markFailed;
|
|
105
118
|
private getErrorMessage;
|
|
106
119
|
private saveHistory;
|
|
107
120
|
}
|
|
108
|
-
export {};
|
|
109
121
|
//# sourceMappingURL=widget.d.ts.map
|
package/dist/widget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGtE,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAEvE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC1B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACjC,KAAK,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC/B,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;KAC3C,CAAC;IACF,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC3C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC9D,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC1D;AAED,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,OAAO,GACP,SAAS,GACT,OAAO,GACP,cAAc,GACd,eAAe,CAAC;AACpB,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAM9D,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,GAAG,CAAC,CAAM;IAClB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAC,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAC,CAAc;IACpC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,QAAQ,CAAC,CAAyB;IAC1C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAC,CAAkB;IAC1C,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,aAAa,CAAuD;IAC5E,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,aAAa,CAAC,CAAgC;IAEtD,IAAI,QAAQ,IAAI,OAAO,CAEtB;gBAEW,MAAM,EAAE,YAAY;IAahC,OAAO,CAAC,gBAAgB;IAcxB,IAAI,IAAI,IAAI;IA6GZ,IAAI,IAAI,IAAI;IAWZ,KAAK,IAAI,IAAI;IAWb,MAAM,IAAI,IAAI;IAQd,OAAO,IAAI,IAAI;IAgBf,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,IAAI;IAQnE,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAI9D,OAAO,CAAC,IAAI;IAKZ,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,YAAY;YAiBN,UAAU;YAgBV,WAAW;YAgCX,gBAAgB;YAuBhB,YAAY;IAuI1B,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,gCAAgC;IAiBxC,OAAO,CAAC,0BAA0B;IASlC,OAAO,CAAC,gBAAgB;IAYxB;;;OAGG;IACH,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,WAAW;CAmBpB"}
|