@useknest/widget-core 0.1.0-beta.8 → 0.1.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/dist/attachments.d.ts +44 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/auth.d.ts +2 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/constants.d.ts +16 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +732 -547
- package/dist/persistence.d.ts +27 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/realtime.d.ts +24 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/scroll-lock.d.ts +4 -0
- package/dist/scroll-lock.d.ts.map +1 -0
- package/dist/streaming.d.ts +8 -1
- package/dist/streaming.d.ts.map +1 -1
- package/dist/types.d.ts +24 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Message } from './types';
|
|
2
|
+
export interface PersistedChatState {
|
|
3
|
+
threadId: string | undefined;
|
|
4
|
+
messages: Message[];
|
|
5
|
+
input: string;
|
|
6
|
+
savedAt: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Loads persisted chat state from localStorage.
|
|
10
|
+
* Returns null if missing, expired, or corrupt — callers should fall back to a fresh state.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadChatState(publishableApiKey: string): PersistedChatState | null;
|
|
13
|
+
/**
|
|
14
|
+
* Writes chat state to localStorage immediately.
|
|
15
|
+
*/
|
|
16
|
+
export declare function saveChatState(publishableApiKey: string, state: PersistedChatState): void;
|
|
17
|
+
/**
|
|
18
|
+
* Debounced variant of saveChatState (300ms trailing).
|
|
19
|
+
* Use during streaming to avoid excessive writes on every onContent callback.
|
|
20
|
+
*/
|
|
21
|
+
export declare function saveChatStateDebounced(publishableApiKey: string, state: PersistedChatState): void;
|
|
22
|
+
/**
|
|
23
|
+
* Removes persisted state and cancels any pending debounced save.
|
|
24
|
+
* Call when the user explicitly resets the chat.
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearChatState(publishableApiKey: string): void;
|
|
27
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAOvC,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB;AASD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,iBAAiB,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAgBlF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAMxF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAUjG;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAW9D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface BroadcastMessage {
|
|
2
|
+
id: string;
|
|
3
|
+
thread_id: string;
|
|
4
|
+
role: string;
|
|
5
|
+
content: string;
|
|
6
|
+
metadata: Record<string, unknown>;
|
|
7
|
+
created_at: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PresenceOptions {
|
|
10
|
+
role: 'visitor' | 'agent';
|
|
11
|
+
onPresenceChange: (isOtherOnline: boolean) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Subscribes to broadcast messages on a thread channel.
|
|
15
|
+
* Optionally co-tracks presence on the same channel to show online indicators.
|
|
16
|
+
*
|
|
17
|
+
* Presence is fully best-effort: `track()` is fire-and-forget, the sync handler is
|
|
18
|
+
* guarded with try/catch, and the subscribe callback is kept synchronous so that no
|
|
19
|
+
* presence error can ever disrupt broadcast delivery.
|
|
20
|
+
*
|
|
21
|
+
* @returns Cleanup function — call on component destroy.
|
|
22
|
+
*/
|
|
23
|
+
export declare function subscribeToThread(threadId: string, onMessage: (message: BroadcastMessage) => void, presence?: PresenceOptions): () => void;
|
|
24
|
+
//# sourceMappingURL=realtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../src/realtime.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;IAC1B,gBAAgB,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,IAAI,CAAC;CACnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,EAC9C,QAAQ,CAAC,EAAE,eAAe,GACxB,MAAM,IAAI,CAwCZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-lock.d.ts","sourceRoot":"","sources":["../src/scroll-lock.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wBAAgB,cAAc,SAE7B;AAED,wBAAgB,gBAAgB,SAE/B"}
|
package/dist/streaming.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { Source } from './types';
|
|
1
|
+
import { Source, WidgetUser } from './types';
|
|
2
2
|
export interface StreamCallbacks {
|
|
3
3
|
onInit?: (threadId: string) => void;
|
|
4
4
|
onContent: (content: string) => void;
|
|
5
5
|
onComplete?: (sources: Source[]) => void;
|
|
6
|
+
onDone?: (info: {
|
|
7
|
+
humanTakeover?: boolean;
|
|
8
|
+
}) => void;
|
|
6
9
|
onError: (error: string) => void;
|
|
7
10
|
}
|
|
8
11
|
export interface StreamMessageOptions {
|
|
@@ -12,6 +15,10 @@ export interface StreamMessageOptions {
|
|
|
12
15
|
callbacks: StreamCallbacks;
|
|
13
16
|
/** Base URL for the API. Defaults to https://useknest.com. Pass empty string for relative paths. */
|
|
14
17
|
baseUrl?: string;
|
|
18
|
+
/** Optional metadata to attach to the message (e.g. attachment info). */
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
/** Identifies the logged-in user on the customer's platform. Requires at least id or email. */
|
|
21
|
+
user?: WidgetUser;
|
|
15
22
|
}
|
|
16
23
|
/**
|
|
17
24
|
* Sends a chat message and streams the response via SSE.
|
package/dist/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAsB,MAAM,EAAY,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAsB,MAAM,EAAY,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhF,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACzC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACpC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,eAAe,CAAC;IAC3B,oGAAoG;IACpG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,+FAA+F;IAC/F,IAAI,CAAC,EAAE,UAAU,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyHpF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* These align with the database schema and API contracts.
|
|
4
4
|
*/
|
|
5
5
|
export type WidgetMode = 'inline' | 'bubble';
|
|
6
|
-
export type MessageRole = 'user' | 'assistant' | 'system';
|
|
6
|
+
export type MessageRole = 'user' | 'assistant' | 'system' | 'human';
|
|
7
7
|
export interface Source {
|
|
8
8
|
url: string;
|
|
9
9
|
title: string;
|
|
@@ -11,21 +11,42 @@ export interface Source {
|
|
|
11
11
|
snippet: string;
|
|
12
12
|
score?: number;
|
|
13
13
|
}
|
|
14
|
+
export interface Attachment {
|
|
15
|
+
fileName: string;
|
|
16
|
+
fileType: string;
|
|
17
|
+
fileSize: number;
|
|
18
|
+
storagePath: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
}
|
|
14
21
|
export interface Message {
|
|
15
22
|
id?: string;
|
|
16
23
|
role: MessageRole;
|
|
17
24
|
content: string;
|
|
18
25
|
sources?: Source[];
|
|
26
|
+
attachments?: Attachment[];
|
|
19
27
|
hasRagContext?: boolean;
|
|
20
28
|
createdAt?: string;
|
|
21
29
|
metadata?: Record<string, unknown>;
|
|
22
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Identifies the logged-in user on the customer's platform.
|
|
33
|
+
* At least `id` or `email` must be provided; the backend enforces this via Zod refine.
|
|
34
|
+
*/
|
|
35
|
+
export interface WidgetUser {
|
|
36
|
+
/** External ID from the customer's system — used as the cross-device dedup key. */
|
|
37
|
+
id?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
fullName?: string;
|
|
40
|
+
/** Custom attributes (e.g. plan, company). Full-replace semantics per message. */
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
42
|
+
}
|
|
23
43
|
export interface ChatMessageRequest {
|
|
24
44
|
threadId?: string;
|
|
25
45
|
content: string;
|
|
26
46
|
email?: string;
|
|
27
47
|
fullName?: string;
|
|
28
48
|
metadata?: Record<string, unknown>;
|
|
49
|
+
user?: WidgetUser;
|
|
29
50
|
}
|
|
30
51
|
export interface ChatMessageResponse {
|
|
31
52
|
messageId: string;
|
|
@@ -47,10 +68,11 @@ export interface WidgetConfig {
|
|
|
47
68
|
updatedAt: string;
|
|
48
69
|
}
|
|
49
70
|
export interface SSEEvent {
|
|
50
|
-
type: 'init' | 'content' | 'complete' | 'error';
|
|
71
|
+
type: 'init' | 'content' | 'complete' | 'error' | 'done' | 'status';
|
|
51
72
|
threadId?: string;
|
|
52
73
|
content?: string;
|
|
53
74
|
sources?: Source[];
|
|
54
75
|
error?: string;
|
|
76
|
+
humanTakeover?: boolean;
|
|
55
77
|
}
|
|
56
78
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEpE,MAAM,WAAW,MAAM;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,OAAO;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B,mFAAmF;IACnF,EAAE,CAAC,EAAE,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AAC,EAAE,OAAO,CAAC;CACxB"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -4,4 +4,6 @@
|
|
|
4
4
|
* Code blocks are syntax-highlighted using Prism.js.
|
|
5
5
|
*/
|
|
6
6
|
export declare function formatContent(content: string): string;
|
|
7
|
+
/** Formats a byte count as a human-readable string (B / KB / MB). */
|
|
8
|
+
export declare function formatFileSize(bytes: number): string;
|
|
7
9
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,iCAAiC,CAAC;AACzC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC;AACtC,OAAO,iCAAiC,CAAC;AACzC,OAAO,8BAA8B,CAAC;AAmCtC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,iCAAiC,CAAC;AACzC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC;AACtC,OAAO,iCAAiC,CAAC;AACzC,OAAO,8BAA8B,CAAC;AAmCtC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,qEAAqE;AACrE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIpD"}
|