@namiruai/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 +21 -0
- package/README.md +71 -0
- package/dist/core/api-client.d.ts +54 -0
- package/dist/core/env.d.ts +7 -0
- package/dist/core/inactivity-timer.d.ts +9 -0
- package/dist/core/markdown.d.ts +1 -0
- package/dist/core/pre-chat-templates.d.ts +3 -0
- package/dist/core/state-machine.d.ts +54 -0
- package/dist/core/types.d.ts +92 -0
- package/dist/core/websocket-client.d.ts +40 -0
- package/dist/index.d.ts +3 -0
- package/dist/namiru-chat.esm.js +1091 -0
- package/dist/namiru-chat.esm.js.map +7 -0
- package/dist/namiru-chat.umd.js +1091 -0
- package/dist/namiru-chat.umd.js.map +7 -0
- package/dist/ui/components/button-bubble.d.ts +9 -0
- package/dist/ui/components/chat-header.d.ts +11 -0
- package/dist/ui/components/chat-input.d.ts +4 -0
- package/dist/ui/components/chat-window.d.ts +26 -0
- package/dist/ui/components/contact-form.d.ts +8 -0
- package/dist/ui/components/email-form.d.ts +6 -0
- package/dist/ui/components/feedback-prompt.d.ts +5 -0
- package/dist/ui/components/limit-overlay.d.ts +8 -0
- package/dist/ui/components/message-bubble.d.ts +12 -0
- package/dist/ui/components/pre-chat-form.d.ts +7 -0
- package/dist/ui/icons.d.ts +22 -0
- package/dist/ui/styles.d.ts +19 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Namiru.ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @namiru/chat
|
|
2
|
+
|
|
3
|
+
Core chat widget for [Namiru.ai](https://namiru.ai) -- embeddable AI customer support chat for any website.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @namiru/chat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Script Tag
|
|
14
|
+
|
|
15
|
+
Add the widget to any website with a single script tag:
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script
|
|
19
|
+
src="https://cdn.jsdelivr.net/npm/@namiru/chat/dist/namiru-chat.umd.js"
|
|
20
|
+
data-agent-id="your-agent-id"
|
|
21
|
+
data-position="bottom-right"
|
|
22
|
+
></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### ESM Import
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { init } from '@namiru/chat';
|
|
29
|
+
|
|
30
|
+
const widget = init({
|
|
31
|
+
agentId: 'your-agent-id',
|
|
32
|
+
position: 'bottom-right',
|
|
33
|
+
mode: 'button',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Control programmatically
|
|
37
|
+
widget.open();
|
|
38
|
+
widget.close();
|
|
39
|
+
widget.toggle();
|
|
40
|
+
widget.destroy();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Inline Mode
|
|
44
|
+
|
|
45
|
+
Embed the chat directly into a container element:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { init } from '@namiru/chat';
|
|
49
|
+
|
|
50
|
+
const widget = init({
|
|
51
|
+
agentId: 'your-agent-id',
|
|
52
|
+
mode: 'inline',
|
|
53
|
+
container: document.getElementById('chat-container'),
|
|
54
|
+
width: '100%',
|
|
55
|
+
height: '500px',
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Framework Wrappers
|
|
60
|
+
|
|
61
|
+
- **React**: [@namiru/react](https://www.npmjs.com/package/@namiru/react)
|
|
62
|
+
- **Vue**: [@namiru/vue](https://www.npmjs.com/package/@namiru/vue)
|
|
63
|
+
- **Angular**: [@namiru/angular](https://www.npmjs.com/package/@namiru/angular)
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
|
|
67
|
+
For full documentation, visit [namiru.ai](https://namiru.ai).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AgentBrandingData } from "./types";
|
|
2
|
+
export interface ApiClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
}
|
|
5
|
+
export interface FeedbackPayload {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
rating: "up" | "down";
|
|
8
|
+
comment?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface EscalationPayload {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
userEmail: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TranscriptPayload {
|
|
15
|
+
email: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TranscriptResponse {
|
|
18
|
+
success: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface LimitMessagePayload {
|
|
21
|
+
agentId: string;
|
|
22
|
+
message: string;
|
|
23
|
+
visitorEmail?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface LeadSubmitPayload {
|
|
26
|
+
agentId: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
email: string;
|
|
29
|
+
message: string;
|
|
30
|
+
visitorId?: string;
|
|
31
|
+
fallbackReason?: "handoff_accepted" | "message_limit" | "conversation_limit";
|
|
32
|
+
conversationId?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare class ApiClient {
|
|
35
|
+
private baseUrl;
|
|
36
|
+
constructor(config: ApiClientConfig);
|
|
37
|
+
fetchBranding(agentId: string): Promise<AgentBrandingData>;
|
|
38
|
+
submitFeedback(agentId: string, payload: FeedbackPayload): Promise<void>;
|
|
39
|
+
submitEscalation(agentId: string, payload: EscalationPayload): Promise<void>;
|
|
40
|
+
requestTranscript(agentId: string, sessionId: string, payload: TranscriptPayload): Promise<TranscriptResponse>;
|
|
41
|
+
submitLimitMessage(payload: LimitMessagePayload): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
submitContactMessage(agentId: string, payload: {
|
|
45
|
+
email: string;
|
|
46
|
+
message: string;
|
|
47
|
+
visitorId?: string;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
success: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
submitLead(payload: LeadSubmitPayload): Promise<{
|
|
52
|
+
success: boolean;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared runtime flag indicating whether the widget is rendered inside Shadow DOM.
|
|
3
|
+
* When false the widget falls back to direct DOM injection and needs !important
|
|
4
|
+
* declarations to resist host-page CSS bleed-through.
|
|
5
|
+
*/
|
|
6
|
+
export declare let hasShadowDom: boolean;
|
|
7
|
+
export declare function setHasShadowDom(value: boolean): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderMarkdown(raw: string): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ChatMessage } from "./types";
|
|
2
|
+
export type ChatState = "idle" | "pre_chat" | "connecting" | "chatting" | "feedback" | "escalation" | "email_fallback" | "conversation_limit" | "domain_error" | "error";
|
|
3
|
+
export interface ChatStoreState {
|
|
4
|
+
state: ChatState;
|
|
5
|
+
messages: ChatMessage[];
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
streamingContent: string;
|
|
9
|
+
qualification: string | null;
|
|
10
|
+
feedbackGiven: boolean;
|
|
11
|
+
sessionId: string | null;
|
|
12
|
+
error: string | null;
|
|
13
|
+
}
|
|
14
|
+
export type ChatAction = {
|
|
15
|
+
type: "SET_STATE";
|
|
16
|
+
state: ChatState;
|
|
17
|
+
} | {
|
|
18
|
+
type: "SET_OPEN";
|
|
19
|
+
isOpen: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
type: "SET_LOADING";
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
} | {
|
|
24
|
+
type: "ADD_MESSAGE";
|
|
25
|
+
message: ChatMessage;
|
|
26
|
+
} | {
|
|
27
|
+
type: "APPEND_STREAMING";
|
|
28
|
+
token: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: "CLEAR_STREAMING";
|
|
31
|
+
} | {
|
|
32
|
+
type: "SET_QUALIFICATION";
|
|
33
|
+
qualification: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "SET_FEEDBACK_GIVEN";
|
|
36
|
+
} | {
|
|
37
|
+
type: "SET_SESSION_ID";
|
|
38
|
+
sessionId: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "SET_ERROR";
|
|
41
|
+
error: string | null;
|
|
42
|
+
} | {
|
|
43
|
+
type: "RESET";
|
|
44
|
+
};
|
|
45
|
+
export type StoreSubscriber = (state: ChatStoreState) => void;
|
|
46
|
+
export declare class ChatStore {
|
|
47
|
+
private state;
|
|
48
|
+
private subscribers;
|
|
49
|
+
constructor();
|
|
50
|
+
getState(): ChatStoreState;
|
|
51
|
+
dispatch(action: ChatAction): void;
|
|
52
|
+
subscribe(subscriber: StoreSubscriber): () => void;
|
|
53
|
+
private notify;
|
|
54
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export interface NamiruChatConfig {
|
|
2
|
+
agentId: string;
|
|
3
|
+
serverUrl?: string;
|
|
4
|
+
wsUrl?: string;
|
|
5
|
+
mode?: "button" | "inline";
|
|
6
|
+
position?: "bottom-left" | "bottom-right";
|
|
7
|
+
container?: HTMLElement;
|
|
8
|
+
preChatEnabled?: boolean;
|
|
9
|
+
preChatTemplate?: "ecommerce" | "saas" | "services" | "custom" | null;
|
|
10
|
+
preChatCustom?: PreChatCustomConfig;
|
|
11
|
+
greetingDelay?: number;
|
|
12
|
+
width?: string;
|
|
13
|
+
height?: string;
|
|
14
|
+
onLeadCapture?: (lead: LeadCaptureData) => void;
|
|
15
|
+
onFeedback?: (rating: "up" | "down") => void;
|
|
16
|
+
onSessionStart?: (sessionId: string) => void;
|
|
17
|
+
onSessionEnd?: (sessionId: string) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface PreChatCustomConfig {
|
|
20
|
+
question: string;
|
|
21
|
+
options: PreChatOption[];
|
|
22
|
+
}
|
|
23
|
+
export interface PreChatOption {
|
|
24
|
+
label: string;
|
|
25
|
+
icon: string;
|
|
26
|
+
}
|
|
27
|
+
export interface PreChatTemplate {
|
|
28
|
+
id: "ecommerce" | "saas" | "services" | "custom";
|
|
29
|
+
question: string;
|
|
30
|
+
options: PreChatOption[];
|
|
31
|
+
}
|
|
32
|
+
export interface NamiruChatInstance {
|
|
33
|
+
open: () => void;
|
|
34
|
+
close: () => void;
|
|
35
|
+
toggle: () => void;
|
|
36
|
+
destroy: () => void;
|
|
37
|
+
updateConfig: (config: Partial<NamiruChatConfig>) => void;
|
|
38
|
+
}
|
|
39
|
+
export interface AgentBrandingData {
|
|
40
|
+
agentId: string;
|
|
41
|
+
name: string;
|
|
42
|
+
primaryColor: string;
|
|
43
|
+
accentColor?: string;
|
|
44
|
+
logoUrl?: string;
|
|
45
|
+
agentAvatar?: string;
|
|
46
|
+
welcomeMessage?: string;
|
|
47
|
+
showPoweredBy?: boolean;
|
|
48
|
+
showHeader?: boolean;
|
|
49
|
+
headerColor?: string;
|
|
50
|
+
headerTitle?: string;
|
|
51
|
+
headerSubtitle?: string;
|
|
52
|
+
presetTheme?: "light" | "dark" | "custom";
|
|
53
|
+
backgroundColor?: string;
|
|
54
|
+
textColor?: string;
|
|
55
|
+
bubbleStyle?: "modern" | "rounded" | "square" | "classic";
|
|
56
|
+
fontFamily?: string;
|
|
57
|
+
fontSize?: "small" | "medium" | "large";
|
|
58
|
+
userMessageColor?: string;
|
|
59
|
+
agentMessageColor?: string;
|
|
60
|
+
bubbleGreeting?: string;
|
|
61
|
+
suggestedQuestions?: string[];
|
|
62
|
+
preChatConfig?: {
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
template: "ecommerce" | "saas" | "services" | "custom" | null;
|
|
65
|
+
custom?: PreChatCustomConfig;
|
|
66
|
+
};
|
|
67
|
+
feedbackConfig?: {
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
inactivityMinutes: number;
|
|
70
|
+
};
|
|
71
|
+
escalationConfig?: {
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
emailFallbackEnabled: boolean;
|
|
74
|
+
ownerEmail?: string;
|
|
75
|
+
customReplyMessage?: string;
|
|
76
|
+
liveChatEnabled: boolean;
|
|
77
|
+
};
|
|
78
|
+
allowedDomains?: string[];
|
|
79
|
+
}
|
|
80
|
+
export interface ChatMessage {
|
|
81
|
+
id: string;
|
|
82
|
+
role: "user" | "assistant" | "system";
|
|
83
|
+
content: string;
|
|
84
|
+
timestamp: number;
|
|
85
|
+
metadata?: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
export interface LeadCaptureData {
|
|
88
|
+
email: string;
|
|
89
|
+
sessionId: string;
|
|
90
|
+
source: "email_fallback" | "pre_chat" | "transcript_request";
|
|
91
|
+
qualification?: string;
|
|
92
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type WebSocketEventType = "connected" | "disconnected" | "agent_initialized" | "stream_token" | "final_response" | "stream_end" | "tool_start" | "tool_end" | "kit_trigger" | "usage_limit" | "show_handoff_form" | "handoff_active" | "error" | "status";
|
|
2
|
+
export interface WebSocketEvent {
|
|
3
|
+
type: WebSocketEventType;
|
|
4
|
+
data: any;
|
|
5
|
+
}
|
|
6
|
+
export type WebSocketEventHandler = (event: WebSocketEvent) => void;
|
|
7
|
+
export interface WebSocketClientConfig {
|
|
8
|
+
url: string;
|
|
9
|
+
agentId: string;
|
|
10
|
+
token?: string;
|
|
11
|
+
visitorId?: string;
|
|
12
|
+
maxReconnectAttempts?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class WebSocketClient {
|
|
15
|
+
private ws;
|
|
16
|
+
private config;
|
|
17
|
+
private listeners;
|
|
18
|
+
private reconnectAttempts;
|
|
19
|
+
private maxReconnectAttempts;
|
|
20
|
+
private isDestroyed;
|
|
21
|
+
private isInitialized;
|
|
22
|
+
constructor(config: WebSocketClientConfig);
|
|
23
|
+
connect(): void;
|
|
24
|
+
disconnect(): void;
|
|
25
|
+
sendMessage(content: string): void;
|
|
26
|
+
sendHandoffComplete(data: {
|
|
27
|
+
email: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
}): void;
|
|
31
|
+
sendEscalationEmail(email: string): void;
|
|
32
|
+
on(type: WebSocketEventType, handler: WebSocketEventHandler): () => void;
|
|
33
|
+
private send;
|
|
34
|
+
private emit;
|
|
35
|
+
private handleOpen;
|
|
36
|
+
private handleMessage;
|
|
37
|
+
private handleToolEnd;
|
|
38
|
+
private handleClose;
|
|
39
|
+
private handleError;
|
|
40
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { NamiruChatConfig, NamiruChatInstance, AgentBrandingData, ChatMessage, PreChatTemplate, PreChatCustomConfig, PreChatOption, LeadCaptureData, } from "./core/types";
|
|
2
|
+
import type { NamiruChatConfig, NamiruChatInstance } from "./core/types";
|
|
3
|
+
export declare function init(config: NamiruChatConfig): NamiruChatInstance;
|