open-ask-ai 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,236 @@
1
+ # Open Ask AI
2
+
3
+ AI-powered Q&A widget for documentation sites. A customizable button component that opens a drawer-style chat interface, designed to be embedded anywhere in your application.
4
+
5
+ ## Features
6
+
7
+ - 🎯 **Embeddable Button**: A regular button component that can be placed anywhere in your layout (header, sidebar, footer, etc.)
8
+ - 🎨 **Drawer-style UI**: Chat interface appears in a drawer that doesn't block documentation content
9
+ - 🌓 **Automatic Dark Mode**: Detects system and site theme automatically
10
+ - 🎨 **Customizable Theming**: Override styles via CSS variables
11
+ - 🌍 **Multi-language Support**: Customize all UI text through props
12
+ - ⌨️ **Keyboard Shortcut**: Optional hotkey support (e.g., Cmd+K)
13
+ - ⚡ **Modern Stack**: Built with React 19, TypeScript, and Tailwind CSS
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install open-ask-ai
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```tsx
24
+ import { AskAIWidget } from 'open-ask-ai'
25
+ import 'open-ask-ai/dist/index.css'
26
+
27
+ function Header() {
28
+ return (
29
+ <header>
30
+ <nav>
31
+ {/* Your navigation items */}
32
+ </nav>
33
+
34
+ {/* Embed the Ask AI button anywhere */}
35
+ <AskAIWidget
36
+ apiUrl="http://localhost:3000"
37
+ exampleQuestions={[
38
+ "How do I get started?",
39
+ "What are the key features?"
40
+ ]}
41
+ />
42
+ </header>
43
+ )
44
+ }
45
+ ```
46
+
47
+ ## Configuration
48
+
49
+ ### Widget Props
50
+
51
+ ```tsx
52
+ interface WidgetProps {
53
+ // Required
54
+ apiUrl: string // Agent API URL
55
+
56
+ // UI Configuration
57
+ drawerPosition?: 'right' | 'left' // Drawer slide direction (default: 'right')
58
+ drawerWidth?: number | string // Drawer width (default: 400)
59
+
60
+ // Content
61
+ texts?: WidgetTexts // All UI text labels (see below)
62
+ exampleQuestions?: string[] // Questions shown in empty state
63
+
64
+ // AI Configuration
65
+ systemPrompt?: string // Custom system prompt for AI assistant
66
+
67
+ // Interaction
68
+ hotkey?: string // Keyboard shortcut (e.g., 'cmd+k', 'ctrl+k')
69
+ enableHotkey?: boolean // Enable/disable hotkey (default: true)
70
+
71
+ // Callbacks
72
+ onOpen?: () => void // Called when drawer opens
73
+ onClose?: () => void // Called when drawer closes
74
+ onMessage?: (message: Message) => void
75
+ onError?: (error: Error) => void
76
+
77
+ // Styling
78
+ className?: string // Additional CSS classes
79
+ style?: React.CSSProperties // Inline styles (for CSS variables)
80
+ }
81
+ ```
82
+
83
+ ### Customizing Text Labels
84
+
85
+ All UI text can be customized through the `texts` prop:
86
+
87
+ ```tsx
88
+ interface WidgetTexts {
89
+ // Button
90
+ triggerButtonText?: string // Default: "Ask AI"
91
+ triggerButtonAriaLabel?: string // Default: "Open AI assistant"
92
+
93
+ // Drawer
94
+ drawerTitle?: string // Default: "Ask AI"
95
+ drawerCloseAriaLabel?: string // Default: "Close"
96
+
97
+ // Chat interface
98
+ welcomeMessage?: string
99
+ exampleQuestionsTitle?: string
100
+ inputPlaceholder?: string
101
+ sendButtonAriaLabel?: string
102
+
103
+ // Status messages
104
+ loadingText?: string
105
+ errorText?: string
106
+ retryButtonText?: string
107
+ }
108
+ ```
109
+
110
+ ### Theming
111
+
112
+ Override CSS variables to customize the appearance:
113
+
114
+ ```css
115
+ .ask-ai {
116
+ --ask-ai-primary: #10b981;
117
+ --ask-ai-primary-hover: #059669;
118
+ --ask-ai-font-family: 'Inter', sans-serif;
119
+ /* Add more custom variables as needed */
120
+ }
121
+ ```
122
+
123
+ ### Multi-language Support
124
+
125
+ ```tsx
126
+ <AskAIWidget
127
+ apiUrl="..."
128
+ texts={{
129
+ triggerButtonText: "问 AI",
130
+ drawerTitle: "AI 助手",
131
+ welcomeMessage: "你好!有什么可以帮你的吗?",
132
+ inputPlaceholder: "输入你的问题...",
133
+ }}
134
+ />
135
+ ```
136
+
137
+ ## Usage Examples
138
+
139
+ ### Embed in Header
140
+
141
+ ```tsx
142
+ import { AskAIWidget } from 'open-ask-ai'
143
+
144
+ function Header() {
145
+ return (
146
+ <header className="flex items-center justify-between">
147
+ <Logo />
148
+ <nav>{/* Navigation items */}</nav>
149
+ <div className="flex items-center gap-2">
150
+ <AskAIWidget apiUrl="http://localhost:3000" />
151
+ <ThemeToggle />
152
+ </div>
153
+ </header>
154
+ )
155
+ }
156
+ ```
157
+
158
+ ### Embed in Sidebar
159
+
160
+ ```tsx
161
+ function Sidebar() {
162
+ return (
163
+ <aside>
164
+ <nav>{/* Menu items */}</nav>
165
+ <div className="mt-auto p-4">
166
+ <AskAIWidget
167
+ apiUrl="http://localhost:3000"
168
+ drawerPosition="left"
169
+ />
170
+ </div>
171
+ </aside>
172
+ )
173
+ }
174
+ ```
175
+
176
+ ### With Keyboard Shortcut
177
+
178
+ ```tsx
179
+ <AskAIWidget
180
+ apiUrl="http://localhost:3000"
181
+ hotkey="cmd+k" // Cmd+K on Mac, Ctrl+K on Windows/Linux
182
+ enableHotkey={true}
183
+ />
184
+ ```
185
+
186
+ ### With Event Callbacks
187
+
188
+ ```tsx
189
+ <AskAIWidget
190
+ apiUrl="http://localhost:3000"
191
+ onOpen={() => console.log('AI assistant opened')}
192
+ onClose={() => console.log('AI assistant closed')}
193
+ onMessage={(message) => {
194
+ // Track messages for analytics
195
+ analytics.track('ai_message', { role: message.role })
196
+ }}
197
+ onError={(error) => {
198
+ // Handle errors
199
+ console.error('AI error:', error)
200
+ }}
201
+ />
202
+ ```
203
+
204
+ ### Custom System Prompt
205
+
206
+ Customize the AI assistant's behavior with a custom system prompt:
207
+
208
+ ```tsx
209
+ <AskAIWidget
210
+ apiUrl="http://localhost:3000"
211
+ systemPrompt="You are a helpful documentation assistant. Answer questions concisely based on the provided documentation. Always respond in the user's language."
212
+ />
213
+ ```
214
+
215
+ This allows you to:
216
+ - Define the assistant's personality and tone
217
+ - Set specific instructions for how to handle questions
218
+ - Configure response format preferences
219
+ - Specify language preferences
220
+
221
+ ## Development
222
+
223
+ ```bash
224
+ # Install dependencies
225
+ npm install
226
+
227
+ # Build
228
+ npm run build
229
+
230
+ # Type check
231
+ npm run typecheck
232
+ ```
233
+
234
+ ## License
235
+
236
+ MIT