@convokit/widget 0.0.1 → 0.0.3

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.
Files changed (43) hide show
  1. package/README.md +226 -42
  2. package/dist/DemoErrorBoundary.d.ts +17 -0
  3. package/dist/DemoErrorBoundary.d.ts.map +1 -0
  4. package/dist/FullScreenBackendWidget.d.ts +36 -0
  5. package/dist/FullScreenBackendWidget.d.ts.map +1 -0
  6. package/dist/FullScreenWidget.d.ts +34 -0
  7. package/dist/FullScreenWidget.d.ts.map +1 -0
  8. package/dist/PopupBackendWidget.d.ts +35 -0
  9. package/dist/PopupBackendWidget.d.ts.map +1 -0
  10. package/dist/PopupWidget-CGZOe6ZA.js +5815 -0
  11. package/dist/PopupWidget.d.ts +33 -0
  12. package/dist/PopupWidget.d.ts.map +1 -0
  13. package/dist/components/ChatPopup.d.ts +10 -0
  14. package/dist/components/ChatPopup.d.ts.map +1 -0
  15. package/dist/components/ChatPopupConnect.d.ts +10 -0
  16. package/dist/components/ChatPopupConnect.d.ts.map +1 -0
  17. package/dist/components/ChatPopupEmbed.d.ts +10 -0
  18. package/dist/components/ChatPopupEmbed.d.ts.map +1 -0
  19. package/dist/components/ChatWidget.d.ts +1 -5
  20. package/dist/components/ChatWidget.d.ts.map +1 -1
  21. package/dist/components/FullScreenChat.d.ts +12 -0
  22. package/dist/components/FullScreenChat.d.ts.map +1 -0
  23. package/dist/components/FullScreenChatConnect.d.ts +12 -0
  24. package/dist/components/FullScreenChatConnect.d.ts.map +1 -0
  25. package/dist/components/FullScreenChatEmbed.d.ts +12 -0
  26. package/dist/components/FullScreenChatEmbed.d.ts.map +1 -0
  27. package/dist/demo.d.ts +1 -1
  28. package/dist/demo.d.ts.map +1 -1
  29. package/dist/index.d.ts +12 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.esm.js +588 -695
  32. package/dist/next.d.ts +24 -0
  33. package/dist/next.d.ts.map +1 -0
  34. package/dist/next.esm.js +17 -0
  35. package/dist/types/index.d.ts +125 -7
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/utils/api.d.ts +29 -0
  38. package/dist/utils/api.d.ts.map +1 -0
  39. package/dist/utils/markdown.d.ts +3 -0
  40. package/dist/utils/markdown.d.ts.map +1 -0
  41. package/package.json +32 -6
  42. package/dist/index.umd.js +0 -30
  43. package/dist/style.css +0 -1
package/dist/next.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { PopupWidgetProps } from './PopupWidget';
2
+
3
+ /**
4
+ * Next.js–only: popup widget with dynamic import (ssr: false) and optional env apiKey.
5
+ * Use in any layout or page; no need to write your own dynamic() or wrapper.
6
+ *
7
+ * @example
8
+ * // app/layout.tsx
9
+ * import { PopupWidgetNext } from '@convokit/widget/next';
10
+ *
11
+ * export default function Layout({ children }) {
12
+ * return (
13
+ * <html><body>
14
+ * {children}
15
+ * <PopupWidgetNext />
16
+ * </body></html>
17
+ * );
18
+ * }
19
+ */
20
+ export declare function PopupWidgetNext(props: Omit<PopupWidgetProps, 'apiKey'> & {
21
+ apiKey?: string;
22
+ }): import("react/jsx-runtime").JSX.Element | null;
23
+ export type { PopupWidgetProps };
24
+ //# sourceMappingURL=next.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AActD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,kDAK5F;AAED,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ (function(){"use strict";try{if(typeof document!="undefined"){var o=document.createElement("style");o.appendChild(document.createTextNode(":root{--convokit-primary: #000;--convokit-header-bg: #000;--convokit-font-family: Inter, system-ui, sans-serif;--convokit-font-size: 14px;--convokit-border-radius: 18px;--convokit-chat-bg: #ffffff;--convokit-user-msg-bg: #000;--convokit-assistant-msg-bg: #f3f4f6;--convokit-input-bg: #ffffff;--convokit-input-border: #d1d5db}.convokit-widget{position:fixed;top:0;left:0;right:0;bottom:0;pointer-events:none;font-family:var(--convokit-font-family);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.convokit-button{width:56px;height:56px;border-radius:50%;border:2px solid var(--convokit-primary);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 2px 8px #0000001a;z-index:10000;transition:all .2s ease;background:var(--convokit-primary)}.convokit-button:hover{transform:translateY(-2px);box-shadow:0 4px 12px #00000026}.convokit-button:active{transform:translateY(0)}.convokit-button-hidden{opacity:0;transform:scale(0);pointer-events:none;transition:all .2s ease-in-out}.convokit-chat-window{width:380px;height:600px;background:#fff;border-radius:12px;box-shadow:0 4px 16px #0000001a;display:flex;flex-direction:column;overflow:hidden;position:absolute;bottom:0;right:0;z-index:9999;transform-origin:bottom right;border:2px solid #000;overscroll-behavior:contain}.convokit-chat-window-body{width:100%;height:100%;background:#fff;display:flex;flex-direction:column;overflow:hidden}.convokit-chat-wrapper{display:flex;flex-direction:column;flex:1;background:var(--convokit-chat-bg);overflow:hidden}.convokit-header{padding:16px 20px;color:#fff;display:flex;justify-content:space-between;align-items:center;min-height:60px;background:var(--convokit-header-bg);position:relative;border-bottom:2px solid var(--convokit-header-bg)}.convokit-header-subtitle{margin:0;font-size:12px;opacity:.85;line-height:1.3}.convokit-header-left{display:flex;align-items:center;gap:12px;flex:1}.convokit-avatar{display:none}.convokit-header-text{display:flex;flex-direction:column;gap:4px}.convokit-header-text h3{margin:0;font-size:16px;font-weight:600;line-height:1.3}.convokit-header-actions{display:flex;align-items:center;gap:4px}.convokit-header-icon{background:none;border:none;color:#fff;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;border-radius:4px;transition:opacity .2s ease}.convokit-header-icon:hover{opacity:.7}.convokit-header-icon:active{opacity:.5}.convokit-chat-window-content{display:flex;flex-direction:column;flex:1;overflow:hidden;min-height:0}.convokit-chat-container{display:flex;flex-direction:column;flex:1;padding:16px;border:none;overflow:hidden;background:transparent;overscroll-behavior:contain}.convokit-messages{flex:1;overflow-y:auto;padding:8px 0;display:flex;flex-direction:column;gap:16px;background:transparent;scrollbar-width:none;-ms-overflow-style:none;overscroll-behavior:contain}.convokit-messages::-webkit-scrollbar{display:none}.convokit-welcome{text-align:center;color:#666;padding:20px;font-size:14px}.convokit-message{display:flex;align-items:flex-end;gap:0;max-width:75%}.convokit-message-user{align-self:flex-end}.convokit-message-assistant{align-self:flex-start}.convokit-bot-icon{display:none}.convokit-message-content{padding:10px 14px;border-radius:var(--convokit-border-radius);word-wrap:break-word;font-size:var(--convokit-font-size);line-height:1.5;position:relative}.convokit-message-user .convokit-message-content{background:var(--convokit-user-msg-bg);color:#fff;border-bottom-right-radius:4px}.convokit-message-assistant .convokit-message-content{background:var(--convokit-assistant-msg-bg);color:#000;border-bottom-left-radius:4px}.convokit-message-content strong{font-weight:600}.convokit-message-content em{font-style:italic}.convokit-message-content a{text-decoration:underline}.convokit-typing{display:flex;gap:6px;padding:4px 0;align-items:center}.convokit-typing span{width:8px;height:8px;border-radius:50%;background:#6b7280;animation:typing-bounce 1.4s ease-in-out infinite}.convokit-typing span:nth-child(1){animation-delay:0s}.convokit-typing span:nth-child(2){animation-delay:.2s}.convokit-typing span:nth-child(3){animation-delay:.4s}@keyframes typing-bounce{0%,60%,to{transform:translateY(0)}30%{transform:translateY(-8px)}}.convokit-input-form{display:flex;align-items:center;padding:12px 0 0;gap:8px;flex-shrink:0;background:transparent;border-bottom:none}.convokit-input{flex:1;padding:11px 14px;border:1px solid color-mix(in srgb,var(--convokit-primary) 35%,transparent);background:var(--convokit-input-bg);border-radius:20px;font-size:var(--convokit-font-size);outline:none;color:#000;font-family:var(--convokit-font-family);transition:border-color .2s ease,box-shadow .2s ease}.convokit-input:focus{border-color:var(--convokit-primary);box-shadow:none}.convokit-input::placeholder{color:#9ca3af}.convokit-input:disabled{background:#f9fafb;color:#9ca3af;border-color:#e5e7eb}.convokit-send-button{width:40px;height:40px;border-radius:50%;border:none;color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;background:var(--convokit-primary);transition:opacity .2s ease}.convokit-send-button:hover:not(:disabled){opacity:.8}.convokit-send-button:active:not(:disabled){opacity:.6}.convokit-send-button:disabled{opacity:.3;cursor:not-allowed;background:var(--convokit-primary)}.convokit-footer{padding:10px 16px;text-align:center;background:var(--convokit-chat-bg);font-size:11px;color:#6b7280}.convokit-footer a{color:var(--convokit-primary);text-decoration:none;font-weight:500;transition:opacity .2s ease}.convokit-footer a:hover{opacity:.7}.convokit-rating-prompt{padding:16px;border-top:1px solid #e5e7eb;background-color:#f9fafb;border-bottom-left-radius:12px;border-bottom-right-radius:12px}.convokit-rating-question{margin:0 0 12px;font-size:14px;font-weight:500;color:#374151;text-align:center}.convokit-rating-buttons{display:flex;gap:12px;justify-content:center;margin-bottom:12px}.convokit-rating-button{width:48px;height:48px;border-radius:50%;border:2px solid #d1d5db;background-color:#fff;color:#6b7280;cursor:pointer;transition:all .2s ease;display:flex;align-items:center;justify-content:center;padding:0}.convokit-rating-button:hover:not(:disabled){border-color:#9ca3af;transform:scale(1.05)}.convokit-rating-button:disabled{opacity:.5;cursor:not-allowed}.convokit-rating-button.convokit-rating-selected{color:#fff;border-width:2px}.convokit-rating-feedback{margin-top:12px;animation:slideDown .3s ease}@keyframes slideDown{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}.convokit-rating-textarea{width:100%;padding:10px 12px;border:1px solid #d1d5db;border-radius:8px;font-size:14px;font-family:inherit;resize:vertical;min-height:60px;margin-bottom:8px;box-sizing:border-box}.convokit-rating-textarea:focus{outline:none;border-color:#3b82f6;box-shadow:0 0 0 3px #3b82f61a}.convokit-rating-textarea:disabled{background-color:#f3f4f6;cursor:not-allowed}.convokit-rating-submit{width:100%;padding:10px 16px;border:none;border-radius:8px;font-size:14px;font-weight:500;color:#fff;cursor:pointer;transition:opacity .2s ease}.convokit-rating-submit:hover:not(:disabled){opacity:.9}.convokit-rating-submit:disabled{opacity:.6;cursor:not-allowed}.convokit-rating-thankyou{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:24px 16px;animation:fadeIn .3s ease}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}.convokit-rating-icon{width:48px;height:48px;border-radius:50%;background-color:#10b981;color:#fff;display:flex;align-items:center;justify-content:center;font-size:24px;font-weight:700;margin-bottom:12px}.convokit-rating-message{margin:0;font-size:14px;font-weight:500;color:#374151}@media (max-width: 480px){.convokit-widget{bottom:10px;right:10px}.convokit-chat-window{width:calc(100vw - 20px);height:calc(100vh - 20px);max-width:calc(100vw - 20px);max-height:calc(100vh - 20px);bottom:0;right:0;border-radius:16px}.convokit-message{max-width:85%}.convokit-header{padding:16px 16px 12px;min-height:64px}.convokit-chat-container{padding:12px}}")),document.head.appendChild(o)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ import { jsx as o } from "react/jsx-runtime";
3
+ import n from "next/dynamic";
4
+ const i = n(
5
+ () => import("./PopupWidget-CGZOe6ZA.js").then((e) => e.h).then((e) => e.PopupWidget),
6
+ { ssr: !1 }
7
+ ), s = () => {
8
+ var e;
9
+ return typeof process < "u" && ((e = process.env) != null && e.NEXT_PUBLIC_CONVOKIT_KEY) ? process.env.NEXT_PUBLIC_CONVOKIT_KEY : "";
10
+ };
11
+ function K(e) {
12
+ const { apiKey: r, ...p } = e, t = r ?? s();
13
+ return !t || t.trim() === "" ? null : /* @__PURE__ */ o(i, { apiKey: t.trim(), ...p });
14
+ }
15
+ export {
16
+ K as PopupWidgetNext
17
+ };
@@ -1,15 +1,133 @@
1
- export interface ConvoKitConfig {
1
+ export interface ChatMessage {
2
+ role: 'user' | 'assistant';
3
+ content: string;
4
+ timestamp?: Date;
5
+ }
6
+ export interface ChatHistoryItem {
7
+ role: 'user' | 'assistant';
8
+ content: string;
9
+ }
10
+ export interface ChatResponse {
11
+ conversation_id: string;
12
+ reply: string;
13
+ usage?: {
14
+ prompt_tokens: number;
15
+ completion_tokens: number;
16
+ total_tokens: number;
17
+ };
18
+ jwt?: string;
19
+ }
20
+ export interface WidgetThemeConfig {
2
21
  widgetId: string;
3
- apiUrl: string;
4
22
  primaryColor?: string;
23
+ headerBg?: string;
24
+ fontFamily?: string;
25
+ fontSize?: string;
26
+ position?: 'bottom-right' | 'bottom-left' | 'bottom-middle' | 'top-right' | 'top-left' | 'top-middle';
27
+ borderRadius?: string;
28
+ buttonSize?: string;
29
+ welcomeMessage?: string;
30
+ placeholder?: string;
31
+ headerTitle?: string;
32
+ headerSubtitle?: string;
33
+ logoUrl?: string;
34
+ avatarUrl?: string;
35
+ showBranding?: boolean;
36
+ chatBg?: string;
37
+ userMsgBg?: string;
38
+ assistantMsgBg?: string;
39
+ inputBg?: string;
40
+ }
41
+ /** Shared UI/theme options used by all widget configs */
42
+ export interface ThemeOptions {
43
+ primaryColor?: string;
44
+ headerBg?: string;
45
+ chatBg?: string;
46
+ userMsgBg?: string;
47
+ assistantMsgBg?: string;
48
+ inputBg?: string;
5
49
  title?: string;
50
+ subtitle?: string;
6
51
  welcomeMessage?: string;
7
52
  placeholder?: string;
8
- position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
53
+ position?: 'bottom-right' | 'bottom-left' | 'bottom-middle' | 'top-right' | 'top-left' | 'top-middle';
54
+ /** URL of an image to show in the closed chat bubble. Omit to use the default chat icon. */
55
+ bubbleIconUrl?: string;
56
+ debug?: boolean;
9
57
  }
10
- export interface ChatMessage {
11
- role: 'user' | 'assistant';
12
- content: string;
13
- timestamp?: Date;
58
+ /** Key: use ConvoKit with your API key (pk_live_...). Easiest integration. */
59
+ export interface KeyConfig extends ThemeOptions {
60
+ /** Unique id for this instance (storage, theme cache). Omit to use default. */
61
+ widgetId?: string;
62
+ /** ConvoKit public API key (pk_live_... or pk_test_...). From ConvoKit dashboard. */
63
+ key: string;
64
+ sandbox?: boolean;
65
+ persistMessages?: boolean;
66
+ }
67
+ /** Backend: widget talks to your backend. You provide apiUrl + apiKey (no ConvoKit key in browser). */
68
+ export interface BackendConfig extends ThemeOptions {
69
+ /** Unique id for this instance (storage, theme cache). Omit to use default. */
70
+ widgetId?: string;
71
+ /** Your backend chat endpoint URL. */
72
+ apiUrl: string;
73
+ /** Your API key sent to your backend (e.g. X-API-Key header). */
74
+ apiKey: string;
75
+ /** Optional auth token sent as Authorization: Bearer to your backend. */
76
+ authToken?: string;
77
+ /** Optional: resolve auth token before each request. */
78
+ getAuthToken?: () => string | Promise<string>;
79
+ }
80
+ /** Controlled: you own messages and onSend. Full control; you call your backend and update state. */
81
+ export interface ControlledConfig extends ThemeOptions {
82
+ /** Unique id for this instance. Omit to use default. */
83
+ widgetId?: string;
84
+ /** Current messages (your state). */
85
+ messages: ChatMessage[];
86
+ /** Called when messages change (widget appends user message, you append assistant). */
87
+ onMessagesUpdate: (messages: ChatMessage[]) => void;
88
+ /** Called when user sends a message. Widget has already appended the user message; you call your backend and update messages with the reply. */
89
+ onSend: (message: string) => void | Promise<void>;
90
+ /** Optional: your conversation id. Widget does not use it; you can pass for your own tracking. */
91
+ conversationId?: string;
92
+ /** Optional: called when you want to set conversation id (e.g. from your backend response). */
93
+ setConversationId?: (id: string) => void;
94
+ }
95
+ /** @deprecated Use ThemeOptions */
96
+ export type BaseWidgetUIConfig = ThemeOptions;
97
+ /** @deprecated Use KeyConfig */
98
+ export type ChatPopupConfig = KeyConfig;
99
+ /** @deprecated Use BackendConfig */
100
+ export type ChatPopupConnectConfig = BackendConfig;
101
+ /** @deprecated Use ControlledConfig */
102
+ export type ChatPopupEmbedConfig = ControlledConfig;
103
+ /**
104
+ * @deprecated Use KeyConfig (PopupKey/FullScreenKey), BackendConfig (PopupBackend/FullScreenBackend), or ControlledConfig (PopupControlled/FullScreenControlled) instead.
105
+ */
106
+ export interface ConvoKitConfig {
107
+ widgetId?: string;
108
+ key?: string;
109
+ apiKey?: string;
110
+ sandbox?: boolean;
111
+ apiUrl?: string;
112
+ customBackend?: boolean;
113
+ authToken?: string;
114
+ getAuthToken?: () => string | Promise<string>;
115
+ persistMessages?: boolean;
116
+ messages?: ChatMessage[];
117
+ onMessagesUpdate?: (messages: ChatMessage[]) => void;
118
+ onSendMessage?: (message: string) => Promise<string>;
119
+ primaryColor?: string;
120
+ headerBg?: string;
121
+ chatBg?: string;
122
+ userMsgBg?: string;
123
+ assistantMsgBg?: string;
124
+ inputBg?: string;
125
+ bodyBackground?: string;
126
+ title?: string;
127
+ subtitle?: string;
128
+ welcomeMessage?: string;
129
+ placeholder?: string;
130
+ position?: 'bottom-right' | 'bottom-left' | 'bottom-middle' | 'top-right' | 'top-left' | 'top-middle';
131
+ debug?: boolean;
14
132
  }
15
133
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;CACtE;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAA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AAO,CAAC,MAAM,CAAC,CAAC;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,CAAC;IACtG,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,29 @@
1
+ import { ChatHistoryItem, ChatResponse, WidgetThemeConfig } from '../types';
2
+
3
+ export declare function sendFirstMessage(apiKey: string, message: string, apiUrl?: string, widgetId?: string): Promise<ChatResponse>;
4
+ export declare function sendMessage(message: string, chatHistory: ChatHistoryItem[], apiUrl?: string): Promise<ChatResponse>;
5
+ export declare function isJwtExpired(): boolean;
6
+ export declare function clearSession(): void;
7
+ export declare function getStoredCustomConversationId(widgetId: string): string | null;
8
+ export declare function setStoredCustomConversationId(widgetId: string, conversationId: string): void;
9
+ export declare function clearCustomBackendSession(widgetId: string): void;
10
+ /**
11
+ * Custom backend: first message. No ConvoKit key; request goes to user's apiUrl.
12
+ * User's backend should call convokit-server and return { reply, conversation_id?, usage? }.
13
+ * Optional apiKey sent as X-API-Key header to your backend.
14
+ */
15
+ export declare function sendFirstMessageCustomBackend(apiUrl: string, message: string, widgetId?: string, chatHistory?: ChatHistoryItem[], authToken?: string, apiKey?: string): Promise<ChatResponse>;
16
+ /**
17
+ * Custom backend: follow-up message. Send conversation_id so user's backend can continue the thread.
18
+ * Optional apiKey sent as X-API-Key header to your backend.
19
+ */
20
+ export declare function sendMessageCustomBackend(apiUrl: string, message: string, chatHistory: ChatHistoryItem[], conversationId: string, authToken?: string, apiKey?: string): Promise<ChatResponse>;
21
+ /**
22
+ * Submit a rating for the current conversation
23
+ */
24
+ export declare function submitRating(rating: 'positive' | 'negative', feedback?: string, apiUrl?: string): Promise<void>;
25
+ /**
26
+ * Fetch widget theme configuration for an API key
27
+ */
28
+ export declare function fetchWidgetConfig(apiKey: string, apiUrl?: string): Promise<WidgetThemeConfig | null>;
29
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AA4C5E,wBAAsB,gBAAgB,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,YAAY,CAAC,CAiDvB;AAED,wBAAsB,WAAW,CAC7B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,eAAe,EAAE,EAC9B,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC,CA8DvB;AAGD,wBAAgB,YAAY,IAAI,OAAO,CAwBtC;AAGD,wBAAgB,YAAY,IAAI,IAAI,CAMnC;AAQD,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG7E;AAED,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CAI5F;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAIhE;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CAC/C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,GAAE,eAAe,EAAO,EACnC,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC,CAyBvB;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC1C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,eAAe,EAAE,EAC9B,cAAc,EAAE,MAAM,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC,CA0BvB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAC9B,MAAM,EAAE,UAAU,GAAG,UAAU,EAC/B,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CA6Cf;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAkCnC"}
@@ -0,0 +1,3 @@
1
+ /** Renders simple markdown to HTML and sanitizes to prevent XSS. Safe for use with dangerouslySetInnerHTML. */
2
+ export declare function renderMarkdown(text: string): string;
3
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/utils/markdown.ts"],"names":[],"mappings":"AAEA,+GAA+G;AAC/G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWnD"}
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@convokit/widget",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "AI chat widget for your website",
5
- "main": "dist/index.js",
5
+ "type": "module",
6
+ "main": "dist/index.esm.js",
6
7
  "module": "dist/index.esm.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "files": [
@@ -12,7 +13,7 @@
12
13
  ],
13
14
  "scripts": {
14
15
  "dev": "vite",
15
- "build": "tsc && vite build",
16
+ "build": "tsc -p tsconfig.build.json && vite build",
16
17
  "preview": "vite preview",
17
18
  "lint": "eslint . --ext .ts,.tsx",
18
19
  "prepublishOnly": "npm run build"
@@ -28,18 +29,43 @@
28
29
  "author": "",
29
30
  "license": "MIT",
30
31
  "peerDependencies": {
31
- "react": "^18.0.0",
32
- "react-dom": "^18.0.0"
32
+ "next": ">=13.0.0",
33
+ "react": "^18.0.0 || ^19.0.0",
34
+ "react-dom": "^18.0.0 || ^19.0.0"
33
35
  },
34
36
  "devDependencies": {
37
+ "@types/dompurify": "^3.0.5",
38
+ "@types/node": "^25.2.2",
35
39
  "@types/react": "^18.2.45",
36
40
  "@types/react-dom": "^18.2.18",
37
41
  "@vitejs/plugin-react": "^4.2.1",
42
+ "next": "^14.0.0",
38
43
  "react": "^18.2.0",
39
44
  "react-dom": "^18.2.0",
40
45
  "typescript": "^5.3.3",
41
46
  "vite": "^5.0.8",
47
+ "vite-plugin-css-injected-by-js": "^2.0.1",
42
48
  "vite-plugin-dts": "^3.7.0"
43
49
  },
44
- "dependencies": {}
50
+ "dependencies": {
51
+ "dompurify": "^3.0.9",
52
+ "motion": "^12.27.1"
53
+ },
54
+ "exports": {
55
+ ".": {
56
+ "types": "./dist/index.d.ts",
57
+ "import": "./dist/index.esm.js",
58
+ "default": "./dist/index.esm.js"
59
+ },
60
+ "./next": {
61
+ "types": "./dist/next.d.ts",
62
+ "import": "./dist/next.esm.js",
63
+ "default": "./dist/next.esm.js"
64
+ }
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "next": {
68
+ "optional": true
69
+ }
70
+ }
45
71
  }
package/dist/index.umd.js DELETED
@@ -1,30 +0,0 @@
1
- (function(k,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],_):(k=typeof globalThis<"u"?globalThis:k||self,_(k.ConvoKit={},k.React))})(this,function(k,_){"use strict";var K={exports:{}},W={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var te;function Oe(){if(te)return W;te=1;var m=_,R=Symbol.for("react.element"),Y=Symbol.for("react.fragment"),j=Object.prototype.hasOwnProperty,x=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,C={key:!0,ref:!0,__self:!0,__source:!0};function S(y,f,T){var v,d={},b=null,w=null;T!==void 0&&(b=""+T),f.key!==void 0&&(b=""+f.key),f.ref!==void 0&&(w=f.ref);for(v in f)j.call(f,v)&&!C.hasOwnProperty(v)&&(d[v]=f[v]);if(y&&y.defaultProps)for(v in f=y.defaultProps,f)d[v]===void 0&&(d[v]=f[v]);return{$$typeof:R,type:y,key:b,ref:w,props:d,_owner:x.current}}return W.Fragment=Y,W.jsx=S,W.jsxs=S,W}var M={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var ne;function ke(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var m=_,R=Symbol.for("react.element"),Y=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),S=Symbol.for("react.provider"),y=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),w=Symbol.for("react.offscreen"),F=Symbol.iterator,z="@@iterator";function De(e){if(e===null||typeof e!="object")return null;var r=F&&e[F]||e[z];return typeof r=="function"?r:null}var A=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function p(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Fe("error",e,t)}}function Fe(e,r,t){{var n=A.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var s=t.map(function(o){return String(o)});s.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,s)}}var Ae=!1,Ie=!1,Ne=!1,We=!1,Me=!1,ae;ae=Symbol.for("react.module.reference");function Ye(e){return!!(typeof e=="string"||typeof e=="function"||e===j||e===C||Me||e===x||e===T||e===v||We||e===w||Ae||Ie||Ne||typeof e=="object"&&e!==null&&(e.$$typeof===b||e.$$typeof===d||e.$$typeof===S||e.$$typeof===y||e.$$typeof===f||e.$$typeof===ae||e.getModuleId!==void 0))}function Le(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function oe(e){return e.displayName||"Context"}function O(e){if(e==null)return null;if(typeof e.tag=="number"&&p("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case j:return"Fragment";case Y:return"Portal";case C:return"Profiler";case x:return"StrictMode";case T:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case y:var r=e;return oe(r)+".Consumer";case S:var t=e;return oe(t._context)+".Provider";case f:return Le(e,e.render,"ForwardRef");case d:var n=e.displayName||null;return n!==null?n:O(e.type)||"Memo";case b:{var i=e,s=i._payload,o=i._init;try{return O(o(s))}catch{return null}}}return null}var P=Object.assign,L=0,ie,se,ue,le,ce,fe,de;function ve(){}ve.__reactDisabledLog=!0;function Ve(){{if(L===0){ie=console.log,se=console.info,ue=console.warn,le=console.error,ce=console.group,fe=console.groupCollapsed,de=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}L++}}function Ue(){{if(L--,L===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},e,{value:ie}),info:P({},e,{value:se}),warn:P({},e,{value:ue}),error:P({},e,{value:le}),group:P({},e,{value:ce}),groupCollapsed:P({},e,{value:fe}),groupEnd:P({},e,{value:de})})}L<0&&p("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var G=A.ReactCurrentDispatcher,H;function U(e,r,t){{if(H===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);H=n&&n[1]||""}return`
18
- `+H+e}}var X=!1,$;{var $e=typeof WeakMap=="function"?WeakMap:Map;$=new $e}function pe(e,r){if(!e||X)return"";{var t=$.get(e);if(t!==void 0)return t}var n;X=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=G.current,G.current=null,Ve();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(g){n=g}Reflect.construct(e,[],o)}else{try{o.call()}catch(g){n=g}e.call(o.prototype)}}else{try{throw Error()}catch(g){n=g}e()}}catch(g){if(g&&n&&typeof g.stack=="string"){for(var a=g.stack.split(`
19
- `),h=n.stack.split(`
20
- `),l=a.length-1,c=h.length-1;l>=1&&c>=0&&a[l]!==h[c];)c--;for(;l>=1&&c>=0;l--,c--)if(a[l]!==h[c]){if(l!==1||c!==1)do if(l--,c--,c<0||a[l]!==h[c]){var E=`
21
- `+a[l].replace(" at new "," at ");return e.displayName&&E.includes("<anonymous>")&&(E=E.replace("<anonymous>",e.displayName)),typeof e=="function"&&$.set(e,E),E}while(l>=1&&c>=0);break}}}finally{X=!1,G.current=s,Ue(),Error.prepareStackTrace=i}var N=e?e.displayName||e.name:"",D=N?U(N):"";return typeof e=="function"&&$.set(e,D),D}function Be(e,r,t){return pe(e,!1)}function Je(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function B(e,r,t){if(e==null)return"";if(typeof e=="function")return pe(e,Je(e));if(typeof e=="string")return U(e);switch(e){case T:return U("Suspense");case v:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Be(e.render);case d:return B(e.type,r,t);case b:{var n=e,i=n._payload,s=n._init;try{return B(s(i),r,t)}catch{}}}return""}var V=Object.prototype.hasOwnProperty,he={},ge=A.ReactDebugCurrentFrame;function J(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);ge.setExtraStackFrame(t)}else ge.setExtraStackFrame(null)}function Ke(e,r,t,n,i){{var s=Function.call.bind(V);for(var o in e)if(s(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var h=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){a=l}a&&!(a instanceof Error)&&(J(i),p("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),J(null)),a instanceof Error&&!(a.message in he)&&(he[a.message]=!0,J(i),p("Failed %s type: %s",t,a.message),J(null))}}}var ze=Array.isArray;function q(e){return ze(e)}function Ge(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return me(e),!1}catch{return!0}}function me(e){return""+e}function ye(e){if(He(e))return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(e)),me(e)}var be=A.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Ee,_e;function qe(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Ze(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Qe(e,r){typeof e.ref=="string"&&be.current}function er(e,r){{var t=function(){Ee||(Ee=!0,p("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function rr(e,r){{var t=function(){_e||(_e=!0,p("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var tr=function(e,r,t,n,i,s,o){var a={$$typeof:R,type:e,key:r,ref:t,props:o,_owner:s};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function nr(e,r,t,n,i){{var s,o={},a=null,h=null;t!==void 0&&(ye(t),a=""+t),Ze(r)&&(ye(r.key),a=""+r.key),qe(r)&&(h=r.ref,Qe(r,i));for(s in r)V.call(r,s)&&!Xe.hasOwnProperty(s)&&(o[s]=r[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)o[s]===void 0&&(o[s]=l[s])}if(a||h){var c=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&er(o,c),h&&rr(o,c)}return tr(e,a,h,i,n,be.current,o)}}var Z=A.ReactCurrentOwner,Re=A.ReactDebugCurrentFrame;function I(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);Re.setExtraStackFrame(t)}else Re.setExtraStackFrame(null)}var Q;Q=!1;function ee(e){return typeof e=="object"&&e!==null&&e.$$typeof===R}function je(){{if(Z.current){var e=O(Z.current.type);if(e)return`
22
-
23
- Check the render method of \``+e+"`."}return""}}function ar(e){return""}var Ce={};function or(e){{var r=je();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
24
-
25
- Check the top-level render call using <`+t+">.")}return r}}function Te(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(Ce[t])return;Ce[t]=!0;var n="";e&&e._owner&&e._owner!==Z.current&&(n=" It was passed a child from "+O(e._owner.type)+"."),I(e),p('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),I(null)}}function we(e,r){{if(typeof e!="object")return;if(q(e))for(var t=0;t<e.length;t++){var n=e[t];ee(n)&&Te(n,r)}else if(ee(e))e._store&&(e._store.validated=!0);else if(e){var i=De(e);if(typeof i=="function"&&i!==e.entries)for(var s=i.call(e),o;!(o=s.next()).done;)ee(o.value)&&Te(o.value,r)}}}function ir(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===d))t=r.propTypes;else return;if(t){var n=O(r);Ke(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!Q){Q=!0;var i=O(r);p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){I(e),p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),I(null);break}}e.ref!==null&&(I(e),p("Invalid attribute `ref` supplied to `React.Fragment`."),I(null))}}var xe={};function Se(e,r,t,n,i,s){{var o=Ye(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var h=ar();h?a+=h:a+=je();var l;e===null?l="null":q(e)?l="array":e!==void 0&&e.$$typeof===R?(l="<"+(O(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):l=typeof e,p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",l,a)}var c=nr(e,r,t,i,s);if(c==null)return c;if(o){var E=r.children;if(E!==void 0)if(n)if(q(E)){for(var N=0;N<E.length;N++)we(E[N],e);Object.freeze&&Object.freeze(E)}else p("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else we(E,e)}if(V.call(r,"key")){var D=O(e),g=Object.keys(r).filter(function(vr){return vr!=="key"}),re=g.length>0?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}";if(!xe[D+re]){var dr=g.length>0?"{"+g.join(": ..., ")+": ...}":"{}";p(`A props object containing a "key" prop is being spread into JSX:
26
- let props = %s;
27
- <%s {...props} />
28
- React keys must be passed directly to JSX without using spread:
29
- let props = %s;
30
- <%s key={someKey} {...props} />`,re,D,dr,D),xe[D+re]=!0}}return e===j?sr(c):ir(c),c}}function ur(e,r,t){return Se(e,r,t,!0)}function lr(e,r,t){return Se(e,r,t,!1)}var cr=lr,fr=ur;M.Fragment=j,M.jsx=cr,M.jsxs=fr}()),M}process.env.NODE_ENV==="production"?K.exports=Oe():K.exports=ke();var u=K.exports;const Pe=({config:m})=>{const[R,Y]=_.useState(!1),[j,x]=_.useState([]),[C,S]=_.useState(""),[y,f]=_.useState(!1),T=()=>Y(!R),v=async d=>{if(d.preventDefault(),!C.trim()||y)return;const b=C.trim();S(""),x(w=>[...w,{role:"user",content:b}]),f(!0);try{const F=await(await fetch(`${m.apiUrl}/api/widget/${m.widgetId}/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:b})})).json();x(z=>[...z,{role:"assistant",content:F.message||"Coming soon..."}])}catch(w){console.error("Chat error:",w),x(F=>[...F,{role:"assistant",content:"Sorry, something went wrong."}])}finally{f(!1)}};return u.jsxs("div",{className:"convokit-widget",children:[!R&&u.jsx("button",{onClick:T,className:"convokit-button",style:{backgroundColor:m.primaryColor||"#000"},children:u.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:u.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),R&&u.jsxs("div",{className:"convokit-chat-window",children:[u.jsxs("div",{className:"convokit-header",style:{backgroundColor:m.primaryColor||"#000"},children:[u.jsx("h3",{children:m.title||"Chat"}),u.jsx("button",{onClick:T,className:"convokit-close",children:"×"})]}),u.jsxs("div",{className:"convokit-messages",children:[j.length===0&&u.jsx("div",{className:"convokit-welcome",children:m.welcomeMessage||"Hello! How can I help you?"}),j.map((d,b)=>u.jsx("div",{className:`convokit-message convokit-message-${d.role}`,children:d.content},b)),y&&u.jsx("div",{className:"convokit-message convokit-message-assistant",children:u.jsxs("div",{className:"convokit-typing",children:[u.jsx("span",{}),u.jsx("span",{}),u.jsx("span",{})]})})]}),u.jsxs("form",{onSubmit:v,className:"convokit-input-form",children:[u.jsx("input",{type:"text",value:C,onChange:d=>S(d.target.value),placeholder:m.placeholder||"Type a message...",disabled:y,className:"convokit-input"}),u.jsx("button",{type:"submit",disabled:y||!C.trim(),className:"convokit-send",style:{color:m.primaryColor||"#000"},children:u.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor",children:u.jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]})]})};k.ChatWidget=Pe,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css DELETED
@@ -1 +0,0 @@
1
- .convokit-widget{position:fixed;bottom:20px;right:20px;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif}.convokit-button{width:60px;height:60px;border-radius:50%;border:none;color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px #00000026;transition:transform .2s}.convokit-button:hover{transform:scale(1.05)}.convokit-chat-window{width:380px;height:600px;background:#fff;border-radius:12px;box-shadow:0 8px 24px #00000026;display:flex;flex-direction:column;overflow:hidden}.convokit-header{padding:16px;color:#fff;display:flex;justify-content:space-between;align-items:center}.convokit-header h3{margin:0;font-size:18px;font-weight:600}.convokit-close{background:none;border:none;color:#fff;font-size:28px;cursor:pointer;padding:0;width:28px;height:28px;display:flex;align-items:center;justify-content:center;line-height:1}.convokit-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:12px}.convokit-welcome{text-align:center;color:#666;padding:20px;font-size:14px}.convokit-message{padding:10px 14px;border-radius:12px;max-width:80%;word-wrap:break-word;font-size:14px;line-height:1.4}.convokit-message-user{background:#000;color:#fff;align-self:flex-end;border-bottom-right-radius:4px}.convokit-message-assistant{background:#f0f0f0;color:#000;align-self:flex-start;border-bottom-left-radius:4px}.convokit-typing{display:flex;gap:4px;padding:4px 0}.convokit-typing span{width:8px;height:8px;border-radius:50%;background:#999;animation:typing 1.4s infinite}.convokit-typing span:nth-child(2){animation-delay:.2s}.convokit-typing span:nth-child(3){animation-delay:.4s}@keyframes typing{0%,60%,to{opacity:.3;transform:translateY(0)}30%{opacity:1;transform:translateY(-4px)}}.convokit-input-form{display:flex;padding:16px;border-top:1px solid #e0e0e0;gap:8px}.convokit-input{flex:1;padding:10px 14px;border:1px solid #e0e0e0;border-radius:20px;font-size:14px;outline:none}.convokit-input:focus{border-color:#999}.convokit-send{background:none;border:none;cursor:pointer;padding:8px;display:flex;align-items:center;justify-content:center;transition:opacity .2s}.convokit-send:disabled{opacity:.3;cursor:not-allowed}.convokit-send:hover:not(:disabled){opacity:.7}@media (max-width: 480px){.convokit-widget{bottom:10px;right:10px}.convokit-chat-window{width:calc(100vw - 20px);height:calc(100vh - 100px)}}