@knowbl_ai/nexus-chat 1.0.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/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2025 Knowbl AI
2
+
3
+ All rights reserved. This software and associated documentation files
4
+ (the "Software") may not be used, copied, modified, merged, published,
5
+ distributed, sublicensed, or sold without prior written permission from
6
+ Knowbl AI.
7
+
8
+ For licensing inquiries, contact: support@knowbl.com
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # @knowbl_ai/nexus-chat
2
+
3
+ Embeddable AI chat widget for Nexus AI Platform.
4
+
5
+ For full documentation, visit: https://docs.nexus.knowbl.com/
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @knowbl_ai/nexus-chat
11
+ ```
12
+
13
+ Or via CDN:
14
+
15
+ ```html
16
+ <script src="https://unpkg.com/@knowbl_ai/nexus-chat"></script>
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### Script Tag (Recommended for most users)
22
+
23
+ ```html
24
+ <script
25
+ src="https://unpkg.com/@knowbl_ai/nexus-chat"
26
+ data-experience-id="your-experience-id"
27
+ ></script>
28
+ ```
29
+
30
+ The widget auto-initializes when loaded with the `data-experience-id` attribute.
31
+
32
+ ### ES Module
33
+
34
+ ```typescript
35
+ import { initWidget } from "@knowbl_ai/nexus-chat";
36
+
37
+ const widget = initWidget({
38
+ experienceId: "your-experience-id",
39
+ apiUrl: "https://nexus-api.knowbl.com/api/v2",
40
+ theme: {
41
+ primaryColor: "#007bff",
42
+ },
43
+ });
44
+
45
+ // Widget API
46
+ widget.open();
47
+ widget.close();
48
+ widget.toggle();
49
+ widget.sendMessage("Hello!");
50
+ ```
51
+
52
+ ### UMD (Browser Global)
53
+
54
+ ```html
55
+ <script src="https://unpkg.com/@knowbl_ai/nexus-chat"></script>
56
+ <script>
57
+ const widget = window.NexusChatWidget.init({
58
+ experienceId: "your-experience-id",
59
+ });
60
+ </script>
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ ```typescript
66
+ interface WidgetConfig {
67
+ experienceId: string;
68
+ apiUrl?: string; // Defaults to https://nexus-api.knowbl.com/api/v2
69
+ theme?: {
70
+ primaryColor?: string;
71
+ fontFamily?: string;
72
+ };
73
+ position?: "bottom-right" | "bottom-left";
74
+ messages?: {
75
+ welcomeMessage?: string;
76
+ placeholder?: string;
77
+ };
78
+ // See full documentation for all options
79
+ }
80
+ ```
81
+
82
+ ## TypeScript Support
83
+
84
+ Full TypeScript support included. Types are automatically loaded when you import the package.
85
+
86
+ ```typescript
87
+ import { initWidget } from "@knowbl_ai/nexus-chat";
88
+ import type { WidgetConfig, WidgetAPI } from "@knowbl_ai/nexus-chat";
89
+
90
+ const config: WidgetConfig = {
91
+ experienceId: "your-id",
92
+ };
93
+
94
+ const api: WidgetAPI = initWidget(config);
95
+ ```
96
+
97
+ ## Documentation
98
+
99
+ For complete documentation including:
100
+
101
+ - Full configuration options
102
+ - Theming and customization
103
+ - Event handling
104
+ - Message interceptors
105
+ - Authentication
106
+
107
+ Visit: https://docs.nexus.knowbl.com/
108
+
109
+ ## Browser Support
110
+
111
+ - Chrome 90+
112
+ - Firefox 88+
113
+ - Safari 14+
114
+ - Edge 90+
115
+
116
+ ## Bundle Size
117
+
118
+ ~30KB gzipped (all dependencies bundled)
119
+
120
+ ## License
121
+
122
+ Proprietary - see LICENSE file
123
+
124
+ ## Support
125
+
126
+ For support inquiries, contact: support@knowbl.com
@@ -0,0 +1,21 @@
1
+ import type { ActionConfig, ActionState, ChatEvent } from "../types";
2
+ export declare class ActionStateManager {
3
+ /**
4
+ * Create initial action states for a message
5
+ */
6
+ static initializeActionStates(messageId: string, actions: ActionConfig[]): ActionState[];
7
+ /**
8
+ * Mark action as used (for oneTimeUse behavior)
9
+ */
10
+ static markActionUsed(actionStates: ActionState[], actionId: string): ActionState[];
11
+ /**
12
+ * Update action states based on new turn
13
+ * This implements auto-disabling of previous turn actions
14
+ */
15
+ static updateStatesOnNewTurn(allEvents: ChatEvent[], currentTurnIndex: number): ChatEvent[];
16
+ /**
17
+ * Get current turn index (last assistant message index)
18
+ */
19
+ static getCurrentTurnIndex(events: ChatEvent[]): number;
20
+ }
21
+ //# sourceMappingURL=actionStateManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionStateManager.d.ts","sourceRoot":"","sources":["../../../src/services/actionStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErE,qBAAa,kBAAkB;IAC7B;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,EAAE,GACtB,WAAW,EAAE;IAUhB;;OAEG;IACH,MAAM,CAAC,cAAc,CACnB,YAAY,EAAE,WAAW,EAAE,EAC3B,QAAQ,EAAE,MAAM,GACf,WAAW,EAAE;IAchB;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAC1B,SAAS,EAAE,SAAS,EAAE,EACtB,gBAAgB,EAAE,MAAM,GACvB,SAAS,EAAE;IA2Dd;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM;CAYxD"}
@@ -0,0 +1,90 @@
1
+ import type { ChatEvent } from "../types";
2
+ export type TabMessage = {
3
+ type: "session_created";
4
+ experienceId: string;
5
+ sessionId: string;
6
+ timestamp: number;
7
+ } | {
8
+ type: "session_cleared";
9
+ experienceId: string;
10
+ timestamp: number;
11
+ } | {
12
+ type: "event_added";
13
+ experienceId: string;
14
+ event: ChatEvent;
15
+ timestamp: number;
16
+ } | {
17
+ type: "event_updated";
18
+ experienceId: string;
19
+ eventId: string;
20
+ updates: Partial<ChatEvent>;
21
+ timestamp: number;
22
+ } | {
23
+ type: "state_changed";
24
+ experienceId: string;
25
+ state: TabSyncState;
26
+ timestamp: number;
27
+ } | {
28
+ type: "request_sync";
29
+ experienceId: string;
30
+ tabId: string;
31
+ } | {
32
+ type: "sync_response";
33
+ experienceId: string;
34
+ targetTabId: string;
35
+ state: FullSyncState;
36
+ };
37
+ export interface TabSyncState {
38
+ isOpen: boolean;
39
+ isLoading: boolean;
40
+ }
41
+ export interface FullSyncState {
42
+ sessionId: string | null;
43
+ events: ChatEvent[];
44
+ isOpen: boolean;
45
+ isLoading: boolean;
46
+ timestamp: number;
47
+ }
48
+ export interface TabCoordinatorOptions {
49
+ experienceId: string;
50
+ onSessionCreated?: (sessionId: string) => void;
51
+ onSessionCleared?: () => void;
52
+ onEventAdded?: (event: ChatEvent) => void;
53
+ onEventUpdated?: (eventId: string, updates: Partial<ChatEvent>) => void;
54
+ onStateChanged?: (state: TabSyncState) => void;
55
+ onFullSync?: (state: FullSyncState) => void;
56
+ }
57
+ export declare class TabCoordinator {
58
+ private experienceId;
59
+ private tabId;
60
+ private channel;
61
+ private options;
62
+ private isDestroyed;
63
+ private updateDebounceTimers;
64
+ private pendingUpdates;
65
+ private visibilityHandler;
66
+ private storageHandler;
67
+ constructor(options: TabCoordinatorOptions);
68
+ private initBroadcastChannel;
69
+ private initVisibilityListener;
70
+ private initStorageListener;
71
+ private handleMessage;
72
+ private broadcast;
73
+ private getStorageKey;
74
+ private getFromStorage;
75
+ private setInStorage;
76
+ private removeFromStorage;
77
+ notifySessionCreated(sessionId: string): void;
78
+ notifySessionCleared(): void;
79
+ notifyEventAdded(event: ChatEvent): void;
80
+ notifyEventUpdated(eventId: string, updates: Partial<ChatEvent>): void;
81
+ notifyStateChanged(state: TabSyncState): void;
82
+ reconcileFromStorage(): FullSyncState | null;
83
+ getStoredSessionId(): string | null;
84
+ getStoredEvents(): ChatEvent[];
85
+ updateCallbacks(callbacks: Omit<TabCoordinatorOptions, "experienceId">): void;
86
+ destroy(): void;
87
+ }
88
+ export declare function getTabCoordinator(experienceId: string, options?: Omit<TabCoordinatorOptions, "experienceId">): TabCoordinator;
89
+ export declare function destroyTabCoordinator(experienceId: string): void;
90
+ //# sourceMappingURL=tabCoordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabCoordinator.d.ts","sourceRoot":"","sources":["../../../src/services/tabCoordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACpE;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,YAAY,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC7D;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEN,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EA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YtB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,iBAAiB;IAalB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAY7C,oBAAoB,IAAI,IAAI;IAY5B,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAuBxC,kBAAkB,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,GAC1B,IAAI;IA6CA,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAa7C,oBAAoB,IAAI,aAAa,GAAG,IAAI;IAgC5C,kBAAkB,IAAI,MAAM,GAAG,IAAI;IAKnC,eAAe,IAAI,SAAS,EAAE;IAS9B,eAAe,CACpB,SAAS,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,GACrD,IAAI;IAKA,OAAO,IAAI,IAAI;CAsBvB;AAKD,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,GACpD,cAAc,CAYhB;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAMhE"}
@@ -0,0 +1,68 @@
1
+ import type { FullSyncState, TabCoordinator, TabSyncState } from "../services/tabCoordinator";
2
+ import type { ActionsConfig, ChatEvent, DisclaimerEvent } from "../types";
3
+ import type { WidgetEventEmitter } from "../utils/eventEmitter";
4
+ export declare function createChatStore(eventEmitter?: WidgetEventEmitter, tabCoordinator?: TabCoordinator): {
5
+ isOpen: import("@preact/signals").Signal<boolean>;
6
+ events: import("@preact/signals").Signal<ChatEvent[]>;
7
+ isLoading: import("@preact/signals").Signal<boolean>;
8
+ currentSessionId: import("@preact/signals").Signal<string | null>;
9
+ currentUserId: import("@preact/signals").Signal<string | null>;
10
+ sessionStartTime: import("@preact/signals").Signal<Date | null>;
11
+ isExplicitSession: import("@preact/signals").Signal<boolean>;
12
+ isExplicitUser: import("@preact/signals").Signal<boolean>;
13
+ inputValue: import("@preact/signals").Signal<string>;
14
+ hasMessages: import("@preact/signals").ReadonlySignal<boolean>;
15
+ isTTSEnabled: import("@preact/signals").Signal<boolean>;
16
+ isTTSAvailable: import("@preact/signals").Signal<boolean>;
17
+ isTTSSpeaking: import("@preact/signals").Signal<boolean>;
18
+ spokenMessageIds: import("@preact/signals").Signal<Set<string>>;
19
+ windowSizeMode: import("@preact/signals").Signal<string>;
20
+ toggleChat: () => void;
21
+ openChat: () => void;
22
+ closeChat: () => void;
23
+ addEvent: (event: Omit<ChatEvent, "id" | "timestamp"> & {
24
+ timestamp?: Date;
25
+ }) => ChatEvent;
26
+ updateEvent: (id: string, updates: Partial<ChatEvent>) => void;
27
+ clearEvents: () => void;
28
+ createPersistentWelcomeEvent: (welcomeMessage: string, displayMode?: "static" | "bubble", welcomeActions?: ActionsConfig) => {
29
+ id: `${string}-${string}-${string}-${string}-${string}`;
30
+ kind: "message";
31
+ timestamp: Date;
32
+ role: "assistant";
33
+ content: string;
34
+ format: "markdown";
35
+ metadata: {
36
+ isPersistentWelcome: boolean;
37
+ isWelcomeBubble: boolean;
38
+ actions: ActionsConfig | undefined;
39
+ actionStates: import("../types").ActionState[] | undefined;
40
+ };
41
+ };
42
+ createPersistentDisclaimerEvent: (content: string, contentFormat?: "markdown" | "html" | "text", requiresAcceptance?: boolean, acceptButtonText?: string, accepted?: boolean, acceptedAt?: string) => DisclaimerEvent;
43
+ acceptDisclaimer: () => void;
44
+ isDisclaimerEventAccepted: () => boolean;
45
+ setSessionId: (id: string | null, explicit?: boolean) => void;
46
+ setInputValue: (value: string) => void;
47
+ clearInput: () => void;
48
+ initializeEvents: (initialEvents?: ChatEvent[]) => void;
49
+ resetChat: () => void;
50
+ startNewSession: (sessionId?: string, message?: string) => string;
51
+ toggleTTS: () => void;
52
+ setTTSEnabled: (enabled: boolean) => void;
53
+ setTTSAvailable: (available: boolean) => void;
54
+ setTTSSpeaking: (speaking: boolean) => void;
55
+ markMessageAsSpoken: (messageId: string) => void;
56
+ isMessageSpoken: (messageId: string) => boolean;
57
+ setWindowSizeMode: (mode: string) => void;
58
+ cycleWindowSize: (modes?: string[]) => void;
59
+ setLoading: (loading: boolean) => void;
60
+ applyRemoteSessionCreated: (sessionId: string) => void;
61
+ applyRemoteSessionCleared: () => void;
62
+ applyRemoteEventAdded: (event: ChatEvent) => void;
63
+ applyRemoteEventUpdated: (eventId: string, updates: Partial<ChatEvent>) => void;
64
+ applyRemoteStateChanged: (state: TabSyncState) => void;
65
+ applyFullSync: (syncState: FullSyncState) => void;
66
+ };
67
+ export type ChatStore = ReturnType<typeof createChatStore>;
68
+ //# sourceMappingURL=chatStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatStore.d.ts","sourceRoot":"","sources":["../../../src/store/chatStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,eAAe,EAEhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAKhE,wBAAgB,eAAe,CAC7B,YAAY,CAAC,EAAE,kBAAkB,EACjC,cAAc,CAAC,EAAE,cAAc;;;;;;;;;;;;;;;;;;;sBA4GtB,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,WAAW,CAAC,GAAG;QAAE,SAAS,CAAC,EAAE,IAAI,CAAA;KAAE;sBAiB1C,MAAM,WAAW,OAAO,CAAC,SAAS,CAAC;;mDA8C1C,MAAM,gBACR,QAAQ,GAAG,QAAQ,mBAChB,aAAa;;;;;;;;;;;;;;+CA0BrB,MAAM,kBACA,UAAU,GAAG,MAAM,GAAG,MAAM,uBACvB,OAAO,qBACR,MAAM,aACf,OAAO,eACJ,MAAM,KAClB,eAAe;;qCAuCoB,OAAO;uBAgBnB,MAAM,GAAG,IAAI,aAAY,OAAO;2BAkB5B,MAAM;;uCA4CM,SAAS,EAAE;;kCA0FhB,MAAM,YAAY,MAAM;;6BAoH7B,OAAO;iCAIH,OAAO;+BAIT,OAAO;qCAID,MAAM;iCAKV,MAAM,KAAG,OAAO;8BAKnB,MAAM;8BA0EN,MAAM,EAAE;0BAUZ,OAAO;2CAOU,MAAM;;mCA6Cd,SAAS;uCAcpC,MAAM,WACN,OAAO,CAAC,SAAS,CAAC;qCAYW,YAAY;+BAUlB,aAAa;EA4GhD;AAGD,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Public type exports for @knowbl_ai/nexus-chat package
3
+ * This file is used to generate the TypeScript declarations
4
+ */
5
+ export type { ActionConfig, ActionType, ActionsConfig, AgentHandoverEvent, ChatEvent, ChatSession, InterceptorAssistantMessage, InterceptorMessage, MessageEvent, MessageInterceptor, MessageInterceptorContext, MessageInterceptorResult, SessionEndEvent, SessionStartEvent, SpeechSynthesisConfig, SystemEvent, TTSConfig, TypingEvent, VoiceConfig, WidgetAPI, WidgetConfig, } from "./index";
6
+ //# sourceMappingURL=exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../../src/types/exports.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAEV,YAAY,EACZ,UAAU,EACV,aAAa,EACb,kBAAkB,EAElB,SAAS,EAET,WAAW,EACX,2BAA2B,EAC3B,kBAAkB,EAClB,YAAY,EAEZ,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EAEjB,qBAAqB,EACrB,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EAET,YAAY,GACb,MAAM,SAAS,CAAC"}