@chatcops/widget 0.4.1 → 0.4.2

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.
@@ -3,10 +3,14 @@ export interface ChatClientOptions {
3
3
  apiUrl: string;
4
4
  timeout?: number;
5
5
  }
6
+ export interface SendMessageOptions {
7
+ signal?: AbortSignal;
8
+ timeout?: number;
9
+ }
6
10
  export declare class ChatClient {
7
11
  private apiUrl;
8
12
  private timeout;
9
13
  constructor(options: ChatClientOptions);
10
- sendMessage(request: WidgetChatRequest): AsyncGenerator<WidgetChatChunk>;
14
+ sendMessage(request: WidgetChatRequest, options?: SendMessageOptions): AsyncGenerator<WidgetChatChunk>;
11
15
  }
12
16
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,iBAAiB;IAK/B,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,CAAC,eAAe,CAAC;CAmEhF"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,iBAAiB;IAK/B,WAAW,CAChB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,kBAAuB,GAC/B,cAAc,CAAC,eAAe,CAAC;CA8EnC"}
@@ -1,7 +1,7 @@
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;opacity:1;transform:none;pointer-events:auto;transition:none}.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-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-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-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-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}}";
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-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-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}}";
5
5
  function createShadowRoot(container) {
6
6
  const host = document.createElement("div");
7
7
  host.id = "chatcops-root";
@@ -77,12 +77,23 @@ function isSafeHref(href) {
77
77
  const scheme = /^([^:/?#]+):/.exec(normalized);
78
78
  return !scheme || SAFE_SCHEMES.has(scheme[1].toLowerCase());
79
79
  }
80
+ function reserveToken(text) {
81
+ let token = "\0";
82
+ while (text.includes(token)) token += "\0";
83
+ return token;
84
+ }
80
85
  function renderMarkdown(input) {
81
86
  let html = escapeHtml(input);
87
+ const token = reserveToken(html);
88
+ const stash = [];
89
+ const stashHtml = (value) => {
90
+ const index = stash.push(value) - 1;
91
+ return `${token}${index}${token}`;
92
+ };
82
93
  html = html.replace(/```(?:\w*)\n?([\s\S]*?)```/g, (_match, code) => {
83
- return `<pre><code>${code.trim()}</code></pre>`;
94
+ return stashHtml(`<pre><code>${code.trim()}</code></pre>`);
84
95
  });
85
- html = html.replace(/`([^`]+)`/g, "<code>$1</code>");
96
+ html = html.replace(/`([^`]+)`/g, (_match, code) => stashHtml(`<code>${code}</code>`));
86
97
  html = html.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
87
98
  html = html.replace(/\*(.+?)\*/g, "<em>$1</em>");
88
99
  html = html.replace(
@@ -102,6 +113,9 @@ function renderMarkdown(input) {
102
113
  );
103
114
  html = html.replace(/\n\n/g, "<br><br>");
104
115
  html = html.replace(/\n/g, "<br>");
116
+ for (let i = 0; i < stash.length; i++) {
117
+ html = html.replace(`${token}${i}${token}`, () => stash[i]);
118
+ }
105
119
  return html;
106
120
  }
107
121
  const 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>';
@@ -256,6 +270,7 @@ class Messages {
256
270
  return div.innerHTML;
257
271
  }
258
272
  }
273
+ const MAX_MESSAGE_LENGTH = 1e4;
259
274
  class Input {
260
275
  constructor(parent, options) {
261
276
  __publicField(this, "area");
@@ -269,6 +284,7 @@ class Input {
269
284
  this.textarea.className = "cc-input";
270
285
  this.textarea.placeholder = options.placeholder;
271
286
  this.textarea.rows = 1;
287
+ this.textarea.maxLength = MAX_MESSAGE_LENGTH;
272
288
  this.textarea.addEventListener("input", () => this.autoResize());
273
289
  this.textarea.addEventListener("keydown", (e) => this.handleKeydown(e));
274
290
  this.sendBtn = document.createElement("button");
@@ -306,6 +322,7 @@ class Input {
306
322
  this.clear();
307
323
  }
308
324
  handleKeydown(e) {
325
+ if (e.isComposing || e.keyCode === 229) return;
309
326
  if (e.key === "Enter" && !e.shiftKey) {
310
327
  e.preventDefault();
311
328
  this.send();
@@ -464,10 +481,19 @@ class ChatClient {
464
481
  this.apiUrl = options.apiUrl;
465
482
  this.timeout = options.timeout ?? 3e4;
466
483
  }
467
- async *sendMessage(request) {
484
+ async *sendMessage(request, options = {}) {
468
485
  var _a;
469
486
  const controller = new AbortController();
470
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
487
+ const timeoutId = setTimeout(() => controller.abort(), options.timeout ?? this.timeout);
488
+ const externalSignal = options.signal;
489
+ const onExternalAbort = () => controller.abort();
490
+ if (externalSignal) {
491
+ if (externalSignal.aborted) {
492
+ controller.abort();
493
+ } else {
494
+ externalSignal.addEventListener("abort", onExternalAbort);
495
+ }
496
+ }
471
497
  try {
472
498
  const response = await fetch(this.apiUrl, {
473
499
  method: "POST",
@@ -513,12 +539,13 @@ class ChatClient {
513
539
  yield { done: true };
514
540
  } catch (err) {
515
541
  if (err instanceof DOMException && err.name === "AbortError") {
516
- yield { error: "timeout" };
542
+ yield (externalSignal == null ? void 0 : externalSignal.aborted) ? { error: "aborted" } : { error: "timeout" };
517
543
  } else {
518
544
  yield { error: "network" };
519
545
  }
520
546
  } finally {
521
547
  clearTimeout(timeoutId);
548
+ externalSignal == null ? void 0 : externalSignal.removeEventListener("abort", onExternalAbort);
522
549
  }
523
550
  }
524
551
  }
@@ -597,10 +624,16 @@ function applyTheme(root, theme) {
597
624
  if (theme.fontFamily) {
598
625
  host.style.setProperty("--cc-font", theme.fontFamily);
599
626
  }
600
- if (theme.borderRadius) {
601
- host.style.setProperty("--cc-radius", theme.borderRadius);
627
+ if (theme.borderRadius !== void 0) {
628
+ const radius = toCssLength(theme.borderRadius);
629
+ if (radius) host.style.setProperty("--cc-radius", radius);
602
630
  }
603
631
  }
632
+ function toCssLength(value) {
633
+ if (typeof value === "number" && !Number.isFinite(value)) return "";
634
+ const text = String(value).trim();
635
+ return /^(?:\d+(?:\.\d+)?|\.\d+)$/.test(text) ? `${text}px` : text;
636
+ }
604
637
  function parseHex(hex) {
605
638
  if (!/^#?[\da-f]{3}(?:[\da-f]{3})?$/i.test(hex)) return [0, 0, 0];
606
639
  const h = hex.replace("#", "");
@@ -645,6 +678,7 @@ function getWidgetLocale(code, overrides) {
645
678
  const base = locales[code] ?? en;
646
679
  return overrides ? { ...base, ...overrides } : base;
647
680
  }
681
+ const MAX_PRECHAT_FIELD_LENGTH = 500;
648
682
  class PreChatForm {
649
683
  constructor(parent, options) {
650
684
  __publicField(this, "container");
@@ -669,6 +703,7 @@ class PreChatForm {
669
703
  }
670
704
  const form = document.createElement("form");
671
705
  form.className = "cc-prechat-fields";
706
+ form.noValidate = true;
672
707
  form.addEventListener("submit", (e) => {
673
708
  e.preventDefault();
674
709
  this.handleSubmit();
@@ -692,8 +727,11 @@ class PreChatForm {
692
727
  createField(field) {
693
728
  const wrapper = document.createElement("div");
694
729
  wrapper.className = "cc-prechat-field";
730
+ const inputId = `cc-prechat-${field.name}`;
731
+ const errorId = `cc-prechat-${field.name}-error`;
695
732
  const label = document.createElement("label");
696
733
  label.className = "cc-prechat-label";
734
+ label.htmlFor = inputId;
697
735
  label.textContent = field.label;
698
736
  if (field.required) {
699
737
  const req = document.createElement("span");
@@ -724,15 +762,21 @@ class PreChatForm {
724
762
  textarea.className = "cc-prechat-textarea";
725
763
  textarea.placeholder = field.placeholder ?? "";
726
764
  textarea.rows = 3;
765
+ textarea.maxLength = MAX_PRECHAT_FIELD_LENGTH;
727
766
  input = textarea;
728
767
  } else {
729
768
  const textInput = document.createElement("input");
730
769
  textInput.type = field.type;
731
770
  textInput.className = "cc-prechat-input";
771
+ textInput.maxLength = MAX_PRECHAT_FIELD_LENGTH;
732
772
  textInput.placeholder = field.placeholder ?? "";
733
773
  input = textInput;
734
774
  }
735
775
  input.name = field.name;
776
+ input.id = inputId;
777
+ if (field.required) {
778
+ input.setAttribute("aria-required", "true");
779
+ }
736
780
  input.addEventListener("input", () => {
737
781
  this.clearError(field.name);
738
782
  this.updateSubmitState();
@@ -747,6 +791,7 @@ class PreChatForm {
747
791
  this.fieldElements.set(field.name, input);
748
792
  const error = document.createElement("div");
749
793
  error.className = "cc-prechat-error";
794
+ error.id = errorId;
750
795
  wrapper.appendChild(error);
751
796
  this.errorElements.set(field.name, error);
752
797
  return wrapper;
@@ -785,10 +830,24 @@ class PreChatForm {
785
830
  showError(fieldName, message) {
786
831
  const el = this.errorElements.get(fieldName);
787
832
  if (el) el.textContent = message;
833
+ const fieldEl = this.fieldElements.get(fieldName);
834
+ if (fieldEl && el) {
835
+ fieldEl.setAttribute("aria-invalid", "true");
836
+ fieldEl.setAttribute("aria-describedby", el.id);
837
+ }
788
838
  }
789
839
  clearError(fieldName) {
790
840
  const el = this.errorElements.get(fieldName);
791
841
  if (el) el.textContent = "";
842
+ const fieldEl = this.fieldElements.get(fieldName);
843
+ if (fieldEl && el) {
844
+ if (fieldEl.getAttribute("aria-describedby") === el.id) {
845
+ fieldEl.removeAttribute("aria-describedby");
846
+ }
847
+ if (fieldEl.getAttribute("aria-invalid") === "true") {
848
+ fieldEl.removeAttribute("aria-invalid");
849
+ }
850
+ }
792
851
  }
793
852
  isValidEmail(email) {
794
853
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
@@ -815,9 +874,12 @@ class Widget {
815
874
  __publicField(this, "userData");
816
875
  __publicField(this, "userDataSent", false);
817
876
  __publicField(this, "isStreaming", false);
877
+ __publicField(this, "destroyed", false);
878
+ __publicField(this, "abortController");
818
879
  __publicField(this, "retryRequests", /* @__PURE__ */ new Map());
819
880
  __publicField(this, "eventHandlers", /* @__PURE__ */ new Map());
820
881
  __publicField(this, "containerEl");
882
+ __publicField(this, "autoOpenTimer");
821
883
  this.config = config;
822
884
  this.client = new ChatClient({ apiUrl: config.apiUrl });
823
885
  this.storage = new ConversationStorage();
@@ -913,7 +975,7 @@ class Widget {
913
975
  }
914
976
  if (!this.isInline && this.config.autoOpen !== void 0 && this.config.autoOpen !== false) {
915
977
  const delay = typeof this.config.autoOpen === "number" ? this.config.autoOpen : 0;
916
- setTimeout(() => this.open(), delay);
978
+ this.autoOpenTimer = setTimeout(() => this.open(), delay);
917
979
  }
918
980
  }
919
981
  open() {
@@ -944,11 +1006,15 @@ class Widget {
944
1006
  }
945
1007
  }
946
1008
  destroy() {
947
- var _a, _b, _c;
948
- (_a = this.preChatFormEl) == null ? void 0 : _a.destroy();
949
- (_b = this.bubble) == null ? void 0 : _b.destroy();
1009
+ var _a, _b, _c, _d;
1010
+ this.destroyed = true;
1011
+ if (this.autoOpenTimer !== void 0) clearTimeout(this.autoOpenTimer);
1012
+ (_a = this.abortController) == null ? void 0 : _a.abort();
1013
+ this.abortController = void 0;
1014
+ (_b = this.preChatFormEl) == null ? void 0 : _b.destroy();
1015
+ (_c = this.bubble) == null ? void 0 : _c.destroy();
950
1016
  this.panel.destroy();
951
- (_c = this.fab) == null ? void 0 : _c.destroy();
1017
+ (_d = this.fab) == null ? void 0 : _d.destroy();
952
1018
  destroyShadowRoot(this.containerEl);
953
1019
  this.eventHandlers.clear();
954
1020
  this.messages = [];
@@ -965,6 +1031,7 @@ class Widget {
965
1031
  }
966
1032
  emit(event, ...args) {
967
1033
  var _a;
1034
+ if (this.destroyed) return;
968
1035
  (_a = this.eventHandlers.get(event)) == null ? void 0 : _a.forEach((h) => h(...args));
969
1036
  }
970
1037
  isPreChatCompleted() {
@@ -1086,8 +1153,14 @@ class Widget {
1086
1153
  let firstChunk = true;
1087
1154
  let requestCompleted = false;
1088
1155
  let hasError = false;
1156
+ const abortController = new AbortController();
1157
+ this.abortController = abortController;
1089
1158
  try {
1090
- for await (const chunk of this.client.sendMessage(this.createRequest(text, options, includeUserData))) {
1159
+ for await (const chunk of this.client.sendMessage(
1160
+ this.createRequest(text, options, includeUserData),
1161
+ { signal: abortController.signal }
1162
+ )) {
1163
+ if (this.destroyed) break;
1091
1164
  if (chunk.error) {
1092
1165
  const errorType = this.resolveErrorType(chunk.error);
1093
1166
  assistantMsg.content = this.getErrorMessage(errorType);
@@ -1128,6 +1201,7 @@ class Widget {
1128
1201
  this.panel.messages.updateMessage(assistantMsg);
1129
1202
  }
1130
1203
  }
1204
+ if (this.destroyed) return;
1131
1205
  if (!hasError && !requestCompleted) {
1132
1206
  requestCompleted = true;
1133
1207
  }
@@ -1146,6 +1220,7 @@ class Widget {
1146
1220
  }
1147
1221
  }
1148
1222
  } catch (err) {
1223
+ if (this.destroyed) return;
1149
1224
  assistantMsg.content = this.locale.errorGeneric;
1150
1225
  assistantMsg.status = "error";
1151
1226
  assistantMsg.errorType = "network";
@@ -1160,13 +1235,18 @@ class Widget {
1160
1235
  (_i = (_h = this.config).onError) == null ? void 0 : _i.call(_h, error);
1161
1236
  this.emit("error", error);
1162
1237
  } finally {
1163
- if (includeUserData && requestCompleted) {
1164
- this.userDataSent = true;
1238
+ if (this.abortController === abortController) {
1239
+ this.abortController = void 0;
1240
+ }
1241
+ if (!this.destroyed) {
1242
+ if (includeUserData && requestCompleted) {
1243
+ this.userDataSent = true;
1244
+ }
1245
+ this.isStreaming = false;
1246
+ this.panel.input.setDisabled(false);
1247
+ this.panel.input.focus();
1248
+ this.saveHistory();
1165
1249
  }
1166
- this.isStreaming = false;
1167
- this.panel.input.setDisabled(false);
1168
- this.panel.input.focus();
1169
- this.saveHistory();
1170
1250
  }
1171
1251
  }
1172
1252
  createRequest(text, options, includeUserData) {
@@ -1251,6 +1331,13 @@ class Widget {
1251
1331
  }
1252
1332
  }
1253
1333
  let instance = null;
1334
+ function parseAutoOpen(value) {
1335
+ if (value === void 0) return void 0;
1336
+ if (value === "" || value === "true") return true;
1337
+ if (value === "false") return false;
1338
+ if (/^\d+$/.test(value)) return Number(value);
1339
+ return void 0;
1340
+ }
1254
1341
  const ChatCops = {
1255
1342
  init(config) {
1256
1343
  if (instance) {
@@ -1277,8 +1364,7 @@ const ChatCops = {
1277
1364
  instance == null ? void 0 : instance.off(event, handler);
1278
1365
  }
1279
1366
  };
1280
- function autoInit() {
1281
- const script = document.currentScript;
1367
+ function autoInit(script) {
1282
1368
  if (!script) return;
1283
1369
  const apiUrl = script.dataset.apiUrl;
1284
1370
  if (!apiUrl) return;
@@ -1306,23 +1392,27 @@ function autoInit() {
1306
1392
  text: script.dataset.welcomeBubble,
1307
1393
  delay: script.dataset.welcomeBubbleDelay ? parseInt(script.dataset.welcomeBubbleDelay, 10) : void 0
1308
1394
  } : void 0,
1309
- autoOpen: script.dataset.autoOpen !== void 0 ? script.dataset.autoOpen === "" || script.dataset.autoOpen === "true" ? true : parseInt(script.dataset.autoOpen, 10) || true : void 0,
1395
+ autoOpen: parseAutoOpen(script.dataset.autoOpen),
1310
1396
  placeholder: script.dataset.placeholder,
1311
1397
  locale: script.dataset.locale
1312
1398
  });
1313
1399
  }
1314
- const currentScript = document.currentScript;
1400
+ const currentScript = typeof document !== "undefined" ? document.currentScript : null;
1315
1401
  if (currentScript && currentScript.dataset.apiUrl) {
1316
1402
  if (document.readyState === "loading") {
1317
- document.addEventListener("DOMContentLoaded", autoInit);
1403
+ document.addEventListener("DOMContentLoaded", () => autoInit(currentScript));
1318
1404
  } else {
1319
- autoInit();
1405
+ autoInit(currentScript);
1320
1406
  }
1321
1407
  }
1322
1408
  if (typeof window !== "undefined") {
1323
1409
  window.ChatCops = ChatCops;
1324
1410
  }
1411
+ if (typeof window !== "undefined" && window.ChatCops && window.ChatCops.default) {
1412
+ Object.assign(window.ChatCops, window.ChatCops.default);
1413
+ }
1325
1414
  export {
1326
1415
  Widget,
1327
- ChatCops as default
1416
+ ChatCops as default,
1417
+ parseAutoOpen
1328
1418
  };
@@ -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;opacity:1;transform:none;pointer-events:auto;transition:none}.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-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-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-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-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}}",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),this.el=document.createElement("button"),this.el.className="cc-fab cc-pulse",this.el.setAttribute("aria-label","Open chat"),"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?"Close chat":"Open chat")}showBadge(){this.badge.classList.add("cc-visible")}hideBadge(){this.badge.classList.remove("cc-visible")}destroy(){this.el.remove()}}const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};const o=new Set(["http","https","mailto","tel"]);function c(e){let t=e.replace(/[&<>"']/g,e=>r[e]??e);return t=t.replace(/```(?:\w*)\n?([\s\S]*?)```/g,(e,t)=>`<pre><code>${t.trim()}</code></pre>`),t=t.replace(/`([^`]+)`/g,"<code>$1</code>"),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/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(/\n\n/g,"<br><br>"),t=t.replace(/\n/g,"<br>"),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",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(){this.typingEl||(this.typingEl=document.createElement("div"),this.typingEl.className="cc-typing",this.typingEl.innerHTML='<div class="cc-typing-dot"></div><div class="cc-typing-dot"></div><div class="cc-typing-dot"></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,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.rows=1,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","Send message"),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){"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","Close chat"),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,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.className="cc-bubble-close",a.innerHTML="&times;",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){var t;const s=new AbortController,a=setTimeout(()=>s.abort(),this.timeout);try{const a=await fetch(this.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:s.signal});if(!a.ok)return 429===a.status?void(yield{error:"rate_limit"}):void(yield{error:`HTTP ${a.status}`});const i=null==(t=a.body)?void 0:t.getReader();if(!i)return void(yield{error:"No response body"});const n=new TextDecoder;let r="";for(;;){const{done:e,value:t}=await i.read();if(e)break;r+=n.decode(t,{stream:!0});const s=r.split("\n");r=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 void(yield{done:!0});try{yield JSON.parse(t)}catch{}}}yield{done:!0}}catch(i){i instanceof DOMException&&"AbortError"===i.name?yield{error:"timeout"}:yield{error:"network"}}finally{clearTimeout(a)}}}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){try{sessionStorage.setItem(`chatcops-prechat-${e}`,"true")}catch{}}}function f(e,t){const s=e.host;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),t.borderRadius&&s.style.setProperty("--cc-radius",t.borderRadius)}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:"Hi! How can I help you today?",inputPlaceholder:"Type a message...",sendButton:"Send",closeButton:"Close",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.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=document.createElement("label");if(s.className="cc-prechat-label",s.textContent=e.label,e.required){const e=document.createElement("span");e.className="cc-required",e.textContent="*",s.appendChild(e)}let a;if(t.appendChild(s),"select"===e.type){const t=document.createElement("select");t.className="cc-prechat-select";const s=document.createElement("option");s.value="",s.textContent=e.placeholder??`Select ${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)}a=t}else if("textarea"===e.type){const t=document.createElement("textarea");t.className="cc-prechat-textarea",t.placeholder=e.placeholder??"",t.rows=3,a=t}else{const t=document.createElement("input");t.type=e.type,t.className="cc-prechat-input",t.placeholder=e.placeholder??"",a=t}a.name=e.name,a.addEventListener("input",()=>{this.clearError(e.name),this.updateSubmitState()}),a instanceof HTMLSelectElement&&a.addEventListener("change",()=>{this.clearError(e.name),this.updateSubmitState()}),t.appendChild(a),this.fieldElements.set(e.name,a);const i=document.createElement("div");return i.className="cc-prechat-error",t.appendChild(i),this.errorElements.set(e.name,i),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)}clearError(e){const t=this.errorElements.get(e);t&&(t.textContent="")}isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}destroy(){this.container.remove(),this.fieldElements.clear(),this.errorElements.clear()}}class M{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,"userDataSent",!1),s(this,"isStreaming",!1),s(this,"retryRequests",new Map),s(this,"eventHandlers",new Map),s(this,"containerEl"),this.config=e,this.client=new m({apiUrl:e.apiUrl}),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;this.isInline?(this.containerEl=this.resolveContainer(),this.shadow=a(this.containerEl)):this.shadow=a(),this.config.theme&&f(this.shadow,this.config.theme);const c=(null==(e=this.config.theme)?void 0:e.position)??"bottom-right";if(this.isInline||(this.fab=new n(this.shadow,{position:c,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)??"AI Assistant",avatar:null==(i=this.config.branding)?void 0:i.avatar,subtitle:(null==(r=this.config.branding)?void 0:r.subtitle)??"Online"},placeholder:this.config.placeholder??this.locale.inputPlaceholder,footerText:this.locale.poweredBy,messageActions:{onRetry:e=>{this.handleRetry(e)},onRegenerate:e=>{this.handleRegenerate(e)},retryLabel:this.locale.retryButton,regenerateLabel:this.locale.regenerateButton},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)&&!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:c,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;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;null==(e=this.preChatFormEl)||e.destroy(),null==(t=this.bubble)||t.destroy(),this.panel.destroy(),null==(s=this.fab)||s.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=[]}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;null==(s=this.eventHandlers.get(e))||s.forEach(e=>e(...t))}isPreChatCompleted(){return this.storage.isPreChatCompleted(this.conversationId)}setPreChatCompleted(){this.storage.setPreChatCompleted(this.conversationId)}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;this.userData=e,this.setPreChatCompleted(),null==(t=this.preChatFormEl)||t.destroy(),this.preChatFormEl=void 0,this.panel.showMessages(),this.panel.input.setVisible(!0),this.showChatView(),null==(a=(s=this.config).onPreChatSubmit)||a.call(s,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={id:"welcome",role:"assistant",content:t?`Hi ${t}! ${this.config.welcomeMessage??this.locale.welcomeMessage}`:this.config.welcomeMessage??this.locale.welcomeMessage};this.messages.push(s),this.panel.addMessage(s)}}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"},p=!(!this.userData||this.userDataSent);let u=!0,m=!1,g=!1;try{for await(const r of this.client.sendMessage(this.createRequest(e,t,p))){if(r.error){const e=this.resolveErrorType(r.error);h.content=this.getErrorMessage(e),h.status="error",h.errorType=e,g=!0,this.retryRequests.set(h.id,{regenerate:t.regenerate,userMessageId:t.userMessageId}),this.panel.messages.removeTyping(),u?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){m=!0;break}r.leadCaptured&&(null==(n=(i=this.config).onLeadCaptured)||n.call(i,r.leadData),this.emit("leadCaptured",r.leadData)),r.content&&(u&&(this.panel.messages.removeTyping(),this.panel.addMessage(h),u=!1),h.content+=r.content,this.panel.messages.updateMessage(h))}g||m||(m=!0),!g&&u&&this.panel.messages.removeTyping(),!g&&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){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{p&&m&&(this.userDataSent=!0),this.isStreaming=!1,this.panel.input.setDisabled(!1),this.panel.input.focus(),this.saveHistory()}}createRequest(e,t,s){const a=!1!==this.config.pageContext?{url:window.location.href,title:document.title}:void 0;return{conversationId:this.conversationId,message:e,messageId:t.userMessageId,regenerate:t.regenerate,pageContext:a,locale:this.config.locale,...s?{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 S=null;const k={init:e=>(S&&S.destroy(),S=new M(e),S.init(),S),open(){null==S||S.open()},close(){null==S||S.close()},destroy(){null==S||S.destroy(),S=null},on(e,t){null==S||S.on(e,t)},off(e,t){null==S||S.off(e,t)}};function L(){const e=document.currentScript;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:void 0!==e.dataset.autoOpen?""===e.dataset.autoOpen||"true"===e.dataset.autoOpen||(parseInt(e.dataset.autoOpen,10)||!0):void 0,placeholder:e.dataset.placeholder,locale:e.dataset.locale})}const B=document.currentScript;return B&&B.dataset.apiUrl&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",L):L()),"undefined"!=typeof window&&(window.ChatCops=k),e.Widget=M,e.default=k,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});
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-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-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),this.el=document.createElement("button"),this.el.className="cc-fab cc-pulse",this.el.setAttribute("aria-label","Open chat"),"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?"Close chat":"Open chat")}showBadge(){this.badge.classList.add("cc-visible")}hideBadge(){this.badge.classList.remove("cc-visible")}destroy(){this.el.remove()}}const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};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(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/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(/\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",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(){this.typingEl||(this.typingEl=document.createElement("div"),this.typingEl.className="cc-typing",this.typingEl.innerHTML='<div class="cc-typing-dot"></div><div class="cc-typing-dot"></div><div class="cc-typing-dot"></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,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.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","Send message"),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","Close chat"),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,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.className="cc-bubble-close",a.innerHTML="&times;",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=setTimeout(()=>a.abort(),t.timeout??this.timeout),n=t.signal,r=()=>a.abort();n&&(n.aborted?a.abort():n.addEventListener("abort",r));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 429===t.status?void(yield{error:"rate_limit"}):void(yield{error:`HTTP ${t.status}`});const i=null==(s=t.body)?void 0:s.getReader();if(!i)return void(yield{error:"No response body"});const n=new TextDecoder;let r="";for(;;){const{done:e,value:t}=await i.read();if(e)break;r+=n.decode(t,{stream:!0});const s=r.split("\n");r=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 void(yield{done:!0});try{yield JSON.parse(t)}catch{}}}yield{done:!0}}catch(o){o instanceof DOMException&&"AbortError"===o.name?yield(null==n?void 0:n.aborted)?{error:"aborted"}:{error:"timeout"}:yield{error:"network"}}finally{clearTimeout(i),null==n||n.removeEventListener("abort",r)}}}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){try{sessionStorage.setItem(`chatcops-prechat-${e}`,"true")}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:"Hi! How can I help you today?",inputPlaceholder:"Type a message...",sendButton:"Send",closeButton:"Close",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??`Select ${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 M{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,"userDataSent",!1),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}),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;this.isInline?(this.containerEl=this.resolveContainer(),this.shadow=a(this.containerEl)):this.shadow=a(),this.config.theme&&f(this.shadow,this.config.theme);const c=(null==(e=this.config.theme)?void 0:e.position)??"bottom-right";if(this.isInline||(this.fab=new n(this.shadow,{position:c,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)??"AI Assistant",avatar:null==(i=this.config.branding)?void 0:i.avatar,subtitle:(null==(r=this.config.branding)?void 0:r.subtitle)??"Online"},placeholder:this.config.placeholder??this.locale.inputPlaceholder,footerText:this.locale.poweredBy,messageActions:{onRetry:e=>{this.handleRetry(e)},onRegenerate:e=>{this.handleRegenerate(e)},retryLabel:this.locale.retryButton,regenerateLabel:this.locale.regenerateButton},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)&&!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:c,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=[]}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(){this.storage.setPreChatCompleted(this.conversationId)}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;this.userData=e,this.setPreChatCompleted(),null==(t=this.preChatFormEl)||t.destroy(),this.preChatFormEl=void 0,this.panel.showMessages(),this.panel.input.setVisible(!0),this.showChatView(),null==(a=(s=this.config).onPreChatSubmit)||a.call(s,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={id:"welcome",role:"assistant",content:t?`Hi ${t}! ${this.config.welcomeMessage??this.locale.welcomeMessage}`:this.config.welcomeMessage??this.locale.welcomeMessage};this.messages.push(s),this.panel.addMessage(s)}}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"},p=!(!this.userData||this.userDataSent);let u=!0,m=!1,g=!1;const b=new AbortController;this.abortController=b;try{for await(const r of this.client.sendMessage(this.createRequest(e,t,p),{signal:b.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,g=!0,this.retryRequests.set(h.id,{regenerate:t.regenerate,userMessageId:t.userMessageId}),this.panel.messages.removeTyping(),u?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){m=!0;break}r.leadCaptured&&(null==(n=(i=this.config).onLeadCaptured)||n.call(i,r.leadData),this.emit("leadCaptured",r.leadData)),r.content&&(u&&(this.panel.messages.removeTyping(),this.panel.addMessage(h),u=!1),h.content+=r.content,this.panel.messages.updateMessage(h))}if(this.destroyed)return;g||m||(m=!0),!g&&u&&this.panel.messages.removeTyping(),!g&&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(f){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=f instanceof Error?f:new Error(String(f));null==(d=(l=this.config).onError)||d.call(l,e),this.emit("error",e)}finally{this.abortController===b&&(this.abortController=void 0),this.destroyed||(p&&m&&(this.userDataSent=!0),this.isStreaming=!1,this.panel.input.setDisabled(!1),this.panel.input.focus(),this.saveHistory())}}createRequest(e,t,s){const a=!1!==this.config.pageContext?{url:window.location.href,title:document.title}:void 0;return{conversationId:this.conversationId,message:e,messageId:t.userMessageId,regenerate:t.regenerate,pageContext:a,locale:this.config.locale,...s?{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 S=null;function k(e){if(void 0!==e)return""===e||"true"===e||"false"!==e&&(/^\d+$/.test(e)?Number(e):void 0)}const L={init:e=>(S&&S.destroy(),S=new M(e),S.init(),S),open(){null==S||S.open()},close(){null==S||S.close()},destroy(){null==S||S.destroy(),S=null},on(e,t){null==S||S.on(e,t)},off(e,t){null==S||S.off(e,t)}};function T(e){if(!e)return;const t=e.dataset.apiUrl;if(!t)return;const s=e.dataset.mode,a=e.dataset.container;L.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:k(e.dataset.autoOpen),placeholder:e.dataset.placeholder,locale:e.dataset.locale})}const B="undefined"!=typeof document?document.currentScript:null;return B&&B.dataset.apiUrl&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>T(B)):T(B)),"undefined"!=typeof window&&(window.ChatCops=L),e.Widget=M,e.default=L,e.parseAutoOpen=k,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 +1 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/dom/input.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,MAAM,CAAyB;gBAE3B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY;IA6BtD,KAAK,IAAI,IAAI;IAIb,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAKpC,KAAK,IAAI,IAAI;IAMb,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,UAAU;CAKnB"}
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/dom/input.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,MAAM,CAAyB;gBAE3B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY;IA8BtD,KAAK,IAAI,IAAI;IAIb,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAKpC,KAAK,IAAI,IAAI;IAMb,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,UAAU;CAKnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"prechat-form.d.ts","sourceRoot":"","sources":["../../src/dom/prechat-form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAClD;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,aAAa,CAAiF;IACtG,OAAO,CAAC,aAAa,CAAqC;IAC1D,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAqB;gBAExB,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB;IA+C5D,OAAO,CAAC,WAAW;IAqEnB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,YAAY;IA4BpB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAIpB,OAAO,IAAI,IAAI;CAKhB"}
1
+ {"version":3,"file":"prechat-form.d.ts","sourceRoot":"","sources":["../../src/dom/prechat-form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAKtD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAClD;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,aAAa,CAAiF;IACtG,OAAO,CAAC,aAAa,CAAqC;IAC1D,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,OAAO,CAAqB;gBAExB,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB;IAgD5D,OAAO,CAAC,WAAW;IAgFnB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,YAAY;IA4BpB,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,YAAY;IAIpB,OAAO,IAAI,IAAI;CAKhB"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Widget, type WidgetConfig } from './widget.js';
2
2
  export { Widget, type WidgetConfig } from './widget.js';
3
+ export declare function parseAutoOpen(value?: string): boolean | number | undefined;
3
4
  declare const ChatCops: {
4
5
  init(config: WidgetConfig): Widget;
5
6
  open(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,QAAA,MAAM,QAAQ;iBACC,YAAY,GAAG,MAAM;YAS1B,IAAI;aAIH,IAAI;eAIF,IAAI;cAKL,MAAM,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;eAInD,MAAM,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;CAGhE,CAAC;AA8DF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAM1E;AAED,QAAA,MAAM,QAAQ;iBACC,YAAY,GAAG,MAAM;YAS1B,IAAI;aAIH,IAAI;eAIF,IAAI;cAKL,MAAM,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;eAInD,MAAM,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;CAGhE,CAAC;AAyDF,eAAe,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAuBA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA8CpD"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AA+BA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA4DpD"}
package/dist/theme.d.ts CHANGED
@@ -3,7 +3,7 @@ export interface ThemeConfig {
3
3
  textColor?: string;
4
4
  bgColor?: string;
5
5
  fontFamily?: string;
6
- borderRadius?: string;
6
+ borderRadius?: string | number;
7
7
  position?: 'bottom-right' | 'bottom-left';
8
8
  }
9
9
  export declare function applyTheme(root: ShadowRoot, theme: ThemeConfig): void;
@@ -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,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;CAC3C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAoBrE"}
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,CAqBrE"}
package/dist/widget.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface WidgetConfig {
24
24
  textColor?: string;
25
25
  bgColor?: string;
26
26
  fontFamily?: string;
27
- borderRadius?: string;
27
+ borderRadius?: string | number;
28
28
  position?: 'bottom-right' | 'bottom-left';
29
29
  };
30
30
  branding?: {
@@ -70,9 +70,12 @@ export declare class Widget {
70
70
  private userData?;
71
71
  private userDataSent;
72
72
  private isStreaming;
73
+ private destroyed;
74
+ private abortController?;
73
75
  private retryRequests;
74
76
  private eventHandlers;
75
77
  private containerEl?;
78
+ private autoOpenTimer?;
76
79
  get isInline(): boolean;
77
80
  constructor(config: WidgetConfig);
78
81
  private resolveContainer;
@@ -1 +1 @@
1
- {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAOA,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,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC1B,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,KAAK,eAAe,GAChB,MAAM,GACN,OAAO,GACP,SAAS,GACT,OAAO,GACP,cAAc,GACd,eAAe,CAAC;AACpB,KAAK,kBAAkB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAMvD,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAc;IAC5B,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,MAAM,CAAsB;IACpC,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,QAAQ,CAAC,CAAyB;IAC1C,OAAO,CAAC,YAAY,CAAS;IAC7B,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;IAQhC,OAAO,CAAC,gBAAgB;IAcxB,IAAI,IAAI,IAAI;IA+FZ,IAAI,IAAI,IAAI;IAWZ,KAAK,IAAI,IAAI;IASb,MAAM,IAAI,IAAI;IAQd,OAAO,IAAI,IAAI;IAcf,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAO7D,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;IAoB3B,OAAO,CAAC,YAAY;YAgBN,UAAU;YAgBV,WAAW;YAgCX,gBAAgB;YAuBhB,YAAY;IAwI1B,OAAO,CAAC,aAAa;IAoBrB,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,gCAAgC;IAiBxC,OAAO,CAAC,0BAA0B;IASlC,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,WAAW;CAmBpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatcops/widget",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Embeddable AI chatbot widget - zero dependencies, Shadow DOM isolated",
5
5
  "type": "module",
6
6
  "main": "dist/chatcops.min.js",