@hissuno/widget 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/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # @hissuno/widget
2
+
3
+ Embeddable AI-powered support chat widget for the Hissuno platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @hissuno/widget
9
+ # or
10
+ yarn add @hissuno/widget
11
+ # or
12
+ pnpm add @hissuno/widget
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```tsx
18
+ import { HissunoWidget } from '@hissuno/widget';
19
+ import '@hissuno/widget/styles.css';
20
+
21
+ function App() {
22
+ return (
23
+ <div>
24
+ <YourApp />
25
+ <HissunoWidget
26
+ projectId="your-project-id"
27
+ userId={currentUser?.id}
28
+ userMetadata={{ name: currentUser?.name, email: currentUser?.email }}
29
+ />
30
+ </div>
31
+ );
32
+ }
33
+ ```
34
+
35
+ ## Props
36
+
37
+ ### Required
38
+
39
+ | Prop | Type | Description |
40
+ |------|------|-------------|
41
+ | `projectId` | `string` | Your Hissuno project ID from the dashboard |
42
+
43
+ ### Optional
44
+
45
+ | Prop | Type | Default | Description |
46
+ |------|------|---------|-------------|
47
+ | `widgetToken` | `string` | - | JWT token for secure authentication (required if token auth is enabled) |
48
+ | `trigger` | `'bubble' \| 'drawer-badge' \| 'headless'` | `'bubble'` | Widget activation trigger type |
49
+ | `display` | `'popup' \| 'sidepanel' \| 'dialog'` | `'sidepanel'` | Chat UI display mode |
50
+ | `shortcut` | `string \| false` | `'mod+k'` | Keyboard shortcut (`mod` = Cmd on Mac, Ctrl on Windows) |
51
+ | `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | Color theme (`auto` follows system preference) |
52
+ | `userId` | `string` | - | End-user identifier for session tracking |
53
+ | `userMetadata` | `Record<string, string>` | - | Additional user info (name, email, plan, etc.) |
54
+ | `apiUrl` | `string` | `'/api/agent'` | Custom API endpoint URL |
55
+ | `title` | `string` | `'Support'` | Chat window title |
56
+ | `placeholder` | `string` | `'Ask a question...'` | Input field placeholder |
57
+ | `initialMessage` | `string` | `'Hi! How can I help?'` | First message shown to users |
58
+ | `defaultOpen` | `boolean` | `false` | Start with widget open |
59
+ | `fetchDefaults` | `boolean` | `true` | Fetch settings from server |
60
+
61
+ ### Position & Sizing
62
+
63
+ | Prop | Type | Default | Description |
64
+ |------|------|---------|-------------|
65
+ | `bubblePosition` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Bubble position |
66
+ | `bubbleOffset` | `{ x?: number, y?: number }` | `{ x: 20, y: 20 }` | Offset from edge (px) |
67
+ | `drawerBadgeLabel` | `string` | `'Support'` | Drawer badge label |
68
+ | `dialogWidth` | `number` | `600` | Dialog width (px) |
69
+ | `dialogHeight` | `number` | `500` | Dialog height (px) |
70
+
71
+ ### Callbacks
72
+
73
+ | Prop | Type | Description |
74
+ |------|------|-------------|
75
+ | `onOpen` | `() => void` | Called when widget opens |
76
+ | `onClose` | `() => void` | Called when widget closes |
77
+ | `renderTrigger` | `(props: TriggerRenderProps) => ReactNode` | Custom trigger component |
78
+
79
+ ## Trigger Types
80
+
81
+ ### Bubble (default)
82
+ ```tsx
83
+ <HissunoWidget projectId="..." trigger="bubble" bubblePosition="bottom-right" />
84
+ ```
85
+
86
+ ### Drawer Badge
87
+ ```tsx
88
+ <HissunoWidget projectId="..." trigger="drawer-badge" drawerBadgeLabel="Help" />
89
+ ```
90
+
91
+ ### Headless (custom trigger)
92
+ ```tsx
93
+ <HissunoWidget
94
+ projectId="..."
95
+ trigger="headless"
96
+ renderTrigger={({ open, isOpen }) => (
97
+ <button onClick={open}>{isOpen ? 'Close' : 'Need help?'}</button>
98
+ )}
99
+ />
100
+ ```
101
+
102
+ ## Display Types
103
+
104
+ - **sidepanel** (default): Full-height drawer from the right (400px)
105
+ - **popup**: Compact corner modal (380x520px)
106
+ - **dialog**: Centered modal with backdrop blur
107
+
108
+ ```tsx
109
+ <HissunoWidget projectId="..." display="dialog" dialogWidth={700} />
110
+ ```
111
+
112
+ ## Custom Hook
113
+
114
+ For advanced integrations:
115
+
116
+ ```tsx
117
+ import { useHissunoChat } from '@hissuno/widget';
118
+
119
+ function CustomChat() {
120
+ const {
121
+ messages,
122
+ input,
123
+ setInput,
124
+ handleSubmit,
125
+ isLoading,
126
+ isStreaming,
127
+ streamingContent,
128
+ error,
129
+ clearHistory,
130
+ } = useHissunoChat({
131
+ projectId: 'your-project-id',
132
+ userId: 'user-123',
133
+ });
134
+
135
+ return (
136
+ <div>
137
+ {messages.map((msg) => (
138
+ <div key={msg.id}>{msg.content}</div>
139
+ ))}
140
+ <form onSubmit={handleSubmit}>
141
+ <input value={input} onChange={(e) => setInput(e.target.value)} />
142
+ <button type="submit" disabled={isLoading}>Send</button>
143
+ </form>
144
+ </div>
145
+ );
146
+ }
147
+ ```
148
+
149
+ ### Hook Return Values
150
+
151
+ | Value | Type | Description |
152
+ |-------|------|-------------|
153
+ | `messages` | `ChatMessage[]` | All chat messages |
154
+ | `input` | `string` | Current input value |
155
+ | `setInput` | `(value: string) => void` | Update input |
156
+ | `handleSubmit` | `(e?: FormEvent) => void` | Send message |
157
+ | `isLoading` | `boolean` | Waiting for response |
158
+ | `isStreaming` | `boolean` | Response streaming |
159
+ | `streamingContent` | `string` | Current streaming text |
160
+ | `error` | `Error \| undefined` | Last error |
161
+ | `clearHistory` | `() => void` | Start new conversation |
162
+ | `currentSessionId` | `string \| null` | Active session ID |
163
+ | `getSessionHistory` | `() => SessionEntry[]` | Past sessions (requires userId) |
164
+
165
+ ## Conversation History
166
+
167
+ Enable with `userId` for automatic localStorage persistence:
168
+
169
+ ```tsx
170
+ <HissunoWidget projectId="..." userId={user.id} />
171
+ ```
172
+
173
+ ## Keyboard Shortcuts
174
+
175
+ ```tsx
176
+ // Custom shortcut
177
+ <HissunoWidget projectId="..." shortcut="ctrl+shift+h" />
178
+
179
+ // Disable
180
+ <HissunoWidget projectId="..." shortcut={false} />
181
+ ```
182
+
183
+ ## Security Features
184
+
185
+ - Input validation with 4KB message limit
186
+ - SSE event validation
187
+ - URL sanitization (strips sensitive query params)
188
+ - Server settings validation
189
+
190
+ ## Accessibility
191
+
192
+ - Semantic HTML with ARIA roles
193
+ - `aria-live` regions for streaming content
194
+ - Focus trap in dialog mode
195
+ - Keyboard navigation support
196
+ - Screen reader announcements
197
+
198
+ ## Browser Support
199
+
200
+ - Modern browsers (Chrome, Firefox, Safari, Edge)
201
+ - Requires `EventSource` (SSE) support
202
+ - ES2020 target
203
+
204
+ ## TypeScript
205
+
206
+ ```tsx
207
+ import type {
208
+ HissunoWidgetProps,
209
+ ChatMessage,
210
+ WidgetTrigger,
211
+ WidgetDisplay,
212
+ UseHissunoChatReturn,
213
+ } from '@hissuno/widget';
214
+ ```
215
+
216
+ ## License
217
+
218
+ MIT