@chatcops/widget 0.5.0 → 0.7.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 +4 -3
- package/dist/api/client.d.ts +21 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/protocol.d.ts +39 -0
- package/dist/api/protocol.d.ts.map +1 -0
- package/dist/api/turnstile.d.ts +8 -0
- package/dist/api/turnstile.d.ts.map +1 -0
- package/dist/api/types.d.ts +17 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/chatcops.esm.js +1217 -537
- package/dist/chatcops.full.min.js +1 -0
- package/dist/chatcops.min.js +1 -1
- package/dist/chatcops.panel.js +1 -0
- package/dist/chunks/prechat-form-DiHgHUnU.js +1 -0
- package/dist/chunks/turnstile-CAnVL3fK.js +1 -0
- package/dist/dom/bubble.d.ts +3 -0
- package/dist/dom/bubble.d.ts.map +1 -1
- package/dist/dom/fab.d.ts +4 -2
- package/dist/dom/fab.d.ts.map +1 -1
- package/dist/dom/icons.d.ts +4 -0
- package/dist/dom/icons.d.ts.map +1 -0
- package/dist/dom/input.d.ts +1 -0
- package/dist/dom/input.d.ts.map +1 -1
- package/dist/dom/messages.d.ts +39 -2
- package/dist/dom/messages.d.ts.map +1 -1
- package/dist/dom/panel.d.ts +8 -0
- package/dist/dom/panel.d.ts.map +1 -1
- package/dist/dom/prechat-form.d.ts.map +1 -1
- package/dist/dom/shadow.d.ts +10 -1
- package/dist/dom/shadow.d.ts.map +1 -1
- package/dist/i18n.d.ts +13 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/index.d.ts +41 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/loader/index.d.ts +2 -0
- package/dist/loader/index.d.ts.map +1 -0
- package/dist/loader/loader.d.ts +71 -0
- package/dist/loader/loader.d.ts.map +1 -0
- package/dist/locales/ar.d.ts +4 -0
- package/dist/locales/ar.d.ts.map +1 -0
- package/dist/locales/ar.js +1 -0
- package/dist/locales/de.d.ts +4 -0
- package/dist/locales/de.d.ts.map +1 -0
- package/dist/locales/de.js +1 -0
- package/dist/locales/es.d.ts +4 -0
- package/dist/locales/es.d.ts.map +1 -0
- package/dist/locales/es.js +1 -0
- package/dist/locales/fr.d.ts +4 -0
- package/dist/locales/fr.d.ts.map +1 -0
- package/dist/locales/fr.js +1 -0
- package/dist/locales/he.d.ts +4 -0
- package/dist/locales/he.d.ts.map +1 -0
- package/dist/locales/he.js +1 -0
- package/dist/locales/hi.d.ts +4 -0
- package/dist/locales/hi.d.ts.map +1 -0
- package/dist/locales/hi.js +1 -0
- package/dist/locales/it.d.ts +4 -0
- package/dist/locales/it.d.ts.map +1 -0
- package/dist/locales/it.js +1 -0
- package/dist/locales/ja.d.ts +4 -0
- package/dist/locales/ja.d.ts.map +1 -0
- package/dist/locales/ja.js +1 -0
- package/dist/locales/ko.d.ts +4 -0
- package/dist/locales/ko.d.ts.map +1 -0
- package/dist/locales/ko.js +1 -0
- package/dist/locales/nl.d.ts +4 -0
- package/dist/locales/nl.d.ts.map +1 -0
- package/dist/locales/nl.js +1 -0
- package/dist/locales/pt.d.ts +4 -0
- package/dist/locales/pt.d.ts.map +1 -0
- package/dist/locales/pt.js +1 -0
- package/dist/locales/ur.d.ts +4 -0
- package/dist/locales/ur.d.ts.map +1 -0
- package/dist/locales/ur.js +1 -0
- package/dist/locales/zh.d.ts +4 -0
- package/dist/locales/zh.d.ts.map +1 -0
- package/dist/locales/zh.js +1 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/namespace.d.ts.map +1 -1
- package/dist/panel.d.ts +6 -0
- package/dist/panel.d.ts.map +1 -0
- package/dist/script-config.d.ts +5 -0
- package/dist/script-config.d.ts.map +1 -0
- package/dist/storage.d.ts +30 -10
- package/dist/storage.d.ts.map +1 -1
- package/dist/theme.d.ts +15 -0
- package/dist/theme.d.ts.map +1 -1
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/widget.d.ts +132 -14
- package/dist/widget.d.ts.map +1 -1
- package/package.json +25 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @chatcops/widget
|
|
2
2
|
|
|
3
|
-
Embeddable AI chatbot widget. Zero dependencies, Shadow DOM isolated, ~
|
|
3
|
+
Embeddable AI chatbot widget. Zero dependencies, Shadow DOM isolated, ~13KB gzipped.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -95,7 +95,8 @@ ChatCops.init({
|
|
|
95
95
|
placeholder: 'Type a message...',
|
|
96
96
|
|
|
97
97
|
// Behavior
|
|
98
|
-
|
|
98
|
+
persistence: 'local', // 'local' | 'session' | 'none', default: 'local'
|
|
99
|
+
historyTtlDays: 30, // drop saved chats older than this
|
|
99
100
|
maxMessages: 50, // max persisted messages
|
|
100
101
|
pageContext: true, // send page URL/title to API
|
|
101
102
|
autoOpen: 5000, // auto-open after ms (popup only)
|
|
@@ -157,7 +158,7 @@ All configuration can be set via `data-*` attributes:
|
|
|
157
158
|
- **Conversation Persistence** - localStorage for history, sessionStorage for session ID
|
|
158
159
|
- **Theming** - CSS custom properties, auto-derived surface colors from `bgColor`
|
|
159
160
|
- **Mobile Responsive** - Full-screen panel on screens below 768px
|
|
160
|
-
- **i18n** -
|
|
161
|
+
- **i18n** - Ships in English with custom override support for any language
|
|
161
162
|
- **Accessible** - ARIA labels, semantic HTML, keyboard navigation
|
|
162
163
|
|
|
163
164
|
## License
|
package/dist/api/client.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { type KeyStore } from '../storage.js';
|
|
1
2
|
import type { WidgetChatRequest, WidgetChatChunk } from './types.js';
|
|
2
3
|
export interface ChatClientOptions {
|
|
3
4
|
apiUrl: string;
|
|
4
5
|
/** Inactivity timeout in milliseconds. Defaults to 30000. */
|
|
5
6
|
timeout?: number;
|
|
7
|
+
/** Cloudflare Turnstile site key, when the server checks Turnstile before issuing a session. */
|
|
8
|
+
turnstileSiteKey?: string;
|
|
9
|
+
/** The host site's signed token for a signed-in visitor, sent when asking for a session. */
|
|
10
|
+
userToken?: string;
|
|
11
|
+
/** Where the session token is kept. Defaults to localStorage; the widget passes its own store. */
|
|
12
|
+
store?: KeyStore;
|
|
6
13
|
}
|
|
7
14
|
export interface SendMessageOptions {
|
|
8
15
|
signal?: AbortSignal;
|
|
@@ -12,7 +19,21 @@ export interface SendMessageOptions {
|
|
|
12
19
|
export declare class ChatClient {
|
|
13
20
|
private apiUrl;
|
|
14
21
|
private timeout;
|
|
22
|
+
private sessionKey;
|
|
23
|
+
/** The last token, kept across page loads so the server can resume the conversation. Read on first use. */
|
|
24
|
+
private saved?;
|
|
25
|
+
private store;
|
|
26
|
+
private turnstileSiteKey?;
|
|
27
|
+
private userToken?;
|
|
15
28
|
constructor(options: ChatClientOptions);
|
|
29
|
+
/**
|
|
30
|
+
* The signed-in visitor's identity token for the next session, or none.
|
|
31
|
+
* The session token from before is dropped, so the next message gets one
|
|
32
|
+
* for the new identity (the server starts a new conversation for a
|
|
33
|
+
* different user).
|
|
34
|
+
*/
|
|
35
|
+
setUserToken(token: string | undefined): void;
|
|
36
|
+
get identity(): string | undefined;
|
|
16
37
|
sendMessage(request: WidgetChatRequest, options?: SendMessageOptions): AsyncGenerator<WidgetChatChunk>;
|
|
17
38
|
}
|
|
18
39
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,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;IAC1B,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;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,2GAA2G;IAC3G,OAAO,CAAC,KAAK,CAAC,CAAmB;IACjC,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,OAAO,EAAE,iBAAiB;IAStC;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAO7C,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IAEM,WAAW,CAChB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,kBAAuB,GAC/B,cAAc,CAAC,eAAe,CAAC;CA8KnC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
type: 'source';
|
|
30
|
+
sourceId: string;
|
|
31
|
+
url: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
snippet?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Parts the widget doesn't use yet. */
|
|
36
|
+
| {
|
|
37
|
+
type: 'text-start' | 'text-end' | 'tool-call' | 'tool-result' | 'handoff' | 'agent-message' | 'suggestions';
|
|
38
|
+
};
|
|
39
|
+
//# 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,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE;AACrF,wCAAwC;GACtC;IAAE,IAAI,EAAE,YAAY,GAAG,UAAU,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":"AAGA;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBrE"}
|
package/dist/api/types.d.ts
CHANGED
|
@@ -2,22 +2,38 @@ export interface WidgetChatRequest {
|
|
|
2
2
|
conversationId: string;
|
|
3
3
|
message: string;
|
|
4
4
|
messageId?: string;
|
|
5
|
-
|
|
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;
|
|
9
12
|
description?: string;
|
|
10
13
|
contentSnippet?: string;
|
|
14
|
+
/** What the site added with setContext(). */
|
|
15
|
+
data?: Record<string, string>;
|
|
11
16
|
};
|
|
12
17
|
locale?: string;
|
|
13
18
|
userData?: Record<string, string>;
|
|
14
19
|
}
|
|
15
20
|
export interface WidgetChatChunk {
|
|
21
|
+
/** The server gave this conversation a new id along with its session token. */
|
|
22
|
+
conversationId?: string;
|
|
23
|
+
/** The id the server saves the reply under (protocol v1). */
|
|
24
|
+
messageId?: string;
|
|
16
25
|
content?: string;
|
|
17
26
|
done?: boolean;
|
|
18
27
|
error?: string;
|
|
28
|
+
/** How long to wait before trying again, with a `rate_limit` error. */
|
|
29
|
+
retryAfterMs?: number;
|
|
19
30
|
leadCaptured?: boolean;
|
|
20
31
|
leadData?: Record<string, unknown>;
|
|
21
32
|
suggestedActions?: string[];
|
|
33
|
+
/** A page the reply cited (protocol v1 `source` part). */
|
|
34
|
+
source?: {
|
|
35
|
+
url: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
};
|
|
22
38
|
}
|
|
23
39
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/api/types.d.ts.map
CHANGED
|
@@ -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;
|
|
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,iGAAiG;IACjG,UAAU,CAAC,EAAE,OAAO,GAAG;QAAE,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,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;QACxB,6CAA6C;QAC7C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC/B,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,0DAA0D;IAC1D,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C"}
|