@usecrow/ui 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,202 @@
1
+ # @usecrow/ui
2
+
3
+ React components for [Crow](https://usecrow.ai) AI agents. Includes floating widget and copilot sidebar components built on top of `@usecrow/client`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @usecrow/client @usecrow/ui
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Floating Widget
14
+
15
+ Add a floating chat bubble to any React app:
16
+
17
+ ```tsx
18
+ import { CrowWidget } from '@usecrow/ui';
19
+ import '@usecrow/ui/styles.css';
20
+
21
+ function App() {
22
+ return (
23
+ <>
24
+ <YourApp />
25
+ <CrowWidget
26
+ productId="YOUR_PRODUCT_ID"
27
+ apiUrl="https://api.usecrow.org"
28
+ agentName="Support Bot"
29
+ />
30
+ </>
31
+ );
32
+ }
33
+ ```
34
+
35
+ ### Copilot Sidebar
36
+
37
+ Add a sidebar chat panel:
38
+
39
+ ```tsx
40
+ import { CrowProvider, CrowCopilot } from '@usecrow/ui';
41
+ import '@usecrow/ui/styles.css';
42
+
43
+ function App() {
44
+ return (
45
+ <CrowProvider productId="YOUR_PRODUCT_ID" apiUrl="https://api.usecrow.org">
46
+ <div className="flex h-screen">
47
+ <main className="flex-1">
48
+ <YourApp />
49
+ </main>
50
+ <CrowCopilot position="right" width={400} />
51
+ </div>
52
+ </CrowProvider>
53
+ );
54
+ }
55
+ ```
56
+
57
+ ## Components
58
+
59
+ ### `<CrowWidget />`
60
+
61
+ Floating bottom-right chat bubble. Can work standalone or within `CrowProvider`.
62
+
63
+ ```tsx
64
+ <CrowWidget
65
+ productId="YOUR_PRODUCT_ID"
66
+ apiUrl="https://api.usecrow.org"
67
+ agentName="Assistant"
68
+ defaultCollapsed={true}
69
+ tools={{
70
+ addToCart: async ({ productId }) => ({ status: 'success' })
71
+ }}
72
+ onIdentify={(identify) => {
73
+ // Call identify() with JWT when user logs in
74
+ identify({ token: 'jwt-from-backend', name: 'John' });
75
+ }}
76
+ />
77
+ ```
78
+
79
+ #### Props
80
+
81
+ | Prop | Type | Default | Description |
82
+ |------|------|---------|-------------|
83
+ | `productId` | `string` | Required | Your Crow product ID |
84
+ | `apiUrl` | `string` | `https://api.usecrow.org` | API URL |
85
+ | `agentName` | `string` | `"Assistant"` | Name shown in header |
86
+ | `defaultCollapsed` | `boolean` | `true` | Initial collapsed state |
87
+ | `tools` | `ToolHandlers` | - | Client-side tool handlers |
88
+ | `onIdentify` | `function` | - | Callback to handle user identification |
89
+ | `className` | `string` | - | Custom CSS class |
90
+ | `zIndex` | `number` | `999999` | Z-index for widget |
91
+
92
+ ### `<CrowCopilot />`
93
+
94
+ Sidebar chat panel. Best used with `CrowProvider` to share state.
95
+
96
+ ```tsx
97
+ <CrowCopilot
98
+ title="Copilot"
99
+ position="right"
100
+ width={400}
101
+ showClose={true}
102
+ onClose={() => setShowCopilot(false)}
103
+ />
104
+ ```
105
+
106
+ #### Props
107
+
108
+ | Prop | Type | Default | Description |
109
+ |------|------|---------|-------------|
110
+ | `productId` | `string` | - | Product ID (if not using Provider) |
111
+ | `apiUrl` | `string` | - | API URL (if not using Provider) |
112
+ | `title` | `string` | `"Copilot"` | Header title |
113
+ | `position` | `'left' \| 'right'` | `'right'` | Sidebar position |
114
+ | `width` | `number \| string` | `400` | Sidebar width |
115
+ | `showClose` | `boolean` | `false` | Show close button |
116
+ | `onClose` | `function` | - | Close button callback |
117
+ | `tools` | `ToolHandlers` | - | Client-side tool handlers |
118
+
119
+ ### `<CrowProvider />`
120
+
121
+ Context provider for sharing a single `CrowClient` instance:
122
+
123
+ ```tsx
124
+ <CrowProvider productId="..." apiUrl="...">
125
+ <YourApp />
126
+ <CrowCopilot />
127
+ </CrowProvider>
128
+ ```
129
+
130
+ ## Hooks
131
+
132
+ ### `useCrowClient()`
133
+
134
+ Access the `CrowClient` from context:
135
+
136
+ ```tsx
137
+ import { useCrowClient } from '@usecrow/ui';
138
+
139
+ function MyComponent() {
140
+ const client = useCrowClient();
141
+
142
+ const handleLogin = () => {
143
+ client.identify({ token: 'jwt', name: 'John' });
144
+ };
145
+ }
146
+ ```
147
+
148
+ ### `useChat()`
149
+
150
+ React hook for chat state:
151
+
152
+ ```tsx
153
+ import { useChat, useCrowClient } from '@usecrow/ui';
154
+
155
+ function CustomChat() {
156
+ const client = useCrowClient();
157
+ const { messages, isLoading, sendMessage, stop } = useChat({ client });
158
+
159
+ return (
160
+ <div>
161
+ {messages.map(msg => <div key={msg.id}>{msg.content}</div>)}
162
+ <button onClick={() => sendMessage('Hello!')}>Send</button>
163
+ </div>
164
+ );
165
+ }
166
+ ```
167
+
168
+ ## Building Custom UIs
169
+
170
+ Export individual components for building custom interfaces:
171
+
172
+ ```tsx
173
+ import {
174
+ MessageList,
175
+ MessageBubble,
176
+ PromptInput,
177
+ ChatBubble,
178
+ WidgetHeader,
179
+ } from '@usecrow/ui';
180
+ ```
181
+
182
+ ## Styling
183
+
184
+ Import the default styles:
185
+
186
+ ```tsx
187
+ import '@usecrow/ui/styles.css';
188
+ ```
189
+
190
+ All classes are prefixed with `crow-` to avoid conflicts. Customize with CSS variables:
191
+
192
+ ```css
193
+ :root {
194
+ --crow-primary: #6366f1;
195
+ --crow-primary-dark: #4f46e5;
196
+ }
197
+ ```
198
+
199
+ ## License
200
+
201
+ MIT
202
+