@chatcops/widget 0.4.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @chatcops/widget
2
2
 
3
- Embeddable AI chatbot widget. Zero dependencies, Shadow DOM isolated, ~50KB gzipped.
3
+ Embeddable AI chatbot widget. Zero dependencies, Shadow DOM isolated, ~13KB gzipped.
4
4
 
5
5
  ## Install
6
6
 
@@ -116,11 +116,11 @@ ChatCops.init(config) // Initialize the widget
116
116
  ChatCops.open() // Open the chat panel (popup mode)
117
117
  ChatCops.close() // Close the chat panel
118
118
  ChatCops.destroy() // Remove widget and clean up
119
- ChatCops.on(event, handler) // Subscribe to events
119
+ ChatCops.on(event, handler) // Subscribe to events (returns unsubscribe function)
120
120
  ChatCops.off(event, handler) // Unsubscribe
121
121
  ```
122
122
 
123
- Events: `open`, `close`, `message`, `error`.
123
+ Events: `open`, `close`, `message`, `error`, `leadCaptured`, `preChatSubmit`.
124
124
 
125
125
  ## Script Tag Attributes
126
126
 
@@ -157,7 +157,7 @@ All configuration can be set via `data-*` attributes:
157
157
  - **Conversation Persistence** - localStorage for history, sessionStorage for session ID
158
158
  - **Theming** - CSS custom properties, auto-derived surface colors from `bgColor`
159
159
  - **Mobile Responsive** - Full-screen panel on screens below 768px
160
- - **i18n** - Built-in locale strings with custom override support
160
+ - **i18n** - Ships in English with custom override support for any language
161
161
  - **Accessible** - ARIA labels, semantic HTML, keyboard navigation
162
162
 
163
163
  ## License
@@ -3,6 +3,8 @@ export interface ChatClientOptions {
3
3
  apiUrl: string;
4
4
  /** Inactivity timeout in milliseconds. Defaults to 30000. */
5
5
  timeout?: number;
6
+ /** Cloudflare Turnstile site key, when the server checks Turnstile before issuing a session. */
7
+ turnstileSiteKey?: string;
6
8
  }
7
9
  export interface SendMessageOptions {
8
10
  signal?: AbortSignal;
@@ -12,6 +14,10 @@ export interface SendMessageOptions {
12
14
  export declare class ChatClient {
13
15
  private apiUrl;
14
16
  private timeout;
17
+ private sessionKey;
18
+ /** The last token, kept across page loads so the server can resume the conversation. */
19
+ private saved;
20
+ private turnstileSiteKey?;
15
21
  constructor(options: ChatClientOptions);
16
22
  sendMessage(request: WidgetChatRequest, options?: SendMessageOptions): AsyncGenerator<WidgetChatChunk>;
17
23
  }
@@ -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,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,kFAAkF;IAClF,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;CAmHnC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAQD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,wFAAwF;IACxF,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,gBAAgB,CAAC,CAAS;gBAEtB,OAAO,EAAE,iBAAiB;IAY/B,WAAW,CAChB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,kBAAuB,GAC/B,cAAc,CAAC,eAAe,CAAC;CAqKnC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The protocol v1 parts the widget reads, copied from `@chatcops/core`
3
+ * (`packages/core/src/protocol/v1.ts`) so the widget's types don't depend on
4
+ * core. `tests/protocol.test-d.ts` fails if core changes them.
5
+ */
6
+ export type WirePart = {
7
+ type: 'start';
8
+ protocol: 1;
9
+ conversationId: string;
10
+ messageId: string;
11
+ } | {
12
+ type: 'text-delta';
13
+ id: string;
14
+ delta: string;
15
+ } | {
16
+ type: 'lead-captured';
17
+ lead: Record<string, unknown>;
18
+ } | {
19
+ type: 'error';
20
+ code: string;
21
+ message?: string;
22
+ retryable: boolean;
23
+ retryAfterMs?: number;
24
+ scope?: string;
25
+ } | {
26
+ type: 'finish';
27
+ reason: string;
28
+ }
29
+ /** Parts the widget doesn't use yet. */
30
+ | {
31
+ type: 'text-start' | 'text-end' | 'source' | 'tool-call' | 'tool-result' | 'handoff' | 'agent-message' | 'suggestions';
32
+ };
33
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/api/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,CAAC,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5G;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AACpC,wCAAwC;GACtC;IAAE,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,CAAA;CAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A Cloudflare Turnstile token, for the server to check before it issues a
3
+ * session. Cloudflare's script loads only when this first runs, and the
4
+ * challenge renders in the page itself (not the widget's shadow root), in a
5
+ * box that stays empty unless the visitor has to click.
6
+ */
7
+ export declare function turnstileToken(siteKey: string): Promise<string>;
8
+ //# sourceMappingURL=turnstile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turnstile.d.ts","sourceRoot":"","sources":["../../src/api/turnstile.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBrE"}
@@ -2,7 +2,10 @@ export interface WidgetChatRequest {
2
2
  conversationId: string;
3
3
  message: string;
4
4
  messageId?: string;
5
- regenerate?: boolean;
5
+ /** `{ assistantMessageId }` only once the server speaks protocol v1; 0.5 servers take `true`. */
6
+ regenerate?: boolean | {
7
+ assistantMessageId: string;
8
+ };
6
9
  pageContext?: {
7
10
  url: string;
8
11
  title: string;
@@ -13,9 +16,15 @@ export interface WidgetChatRequest {
13
16
  userData?: Record<string, string>;
14
17
  }
15
18
  export interface WidgetChatChunk {
19
+ /** The server gave this conversation a new id along with its session token. */
20
+ conversationId?: string;
21
+ /** The id the server saves the reply under (protocol v1). */
22
+ messageId?: string;
16
23
  content?: string;
17
24
  done?: boolean;
18
25
  error?: string;
26
+ /** How long to wait before trying again, with a `rate_limit` error. */
27
+ retryAfterMs?: number;
19
28
  leadCaptured?: boolean;
20
29
  leadData?: Record<string, unknown>;
21
30
  suggestedActions?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B"}
1
+ {"version":3,"file":"types.d.ts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