@timbal-ai/timbal-react 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,184 @@
1
+ # @timbal-ai/timbal-react
2
+
3
+ React components and runtime for building Timbal chat UIs. Provides a streaming chat interface that connects to Timbal workforce agents out of the box.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @timbal-ai/timbal-react
9
+ # or
10
+ bun add @timbal-ai/timbal-react
11
+ ```
12
+
13
+ ### Peer dependencies
14
+
15
+ ```bash
16
+ npm install react react-dom @assistant-ui/react @timbal-ai/timbal-sdk
17
+ ```
18
+
19
+ ## Tailwind setup
20
+
21
+ The package ships pre-built class names that Tailwind must scan. Add this line to your CSS entry file:
22
+
23
+ ```css
24
+ /* src/index.css */
25
+ @import "tailwindcss";
26
+
27
+ @source "../node_modules/@timbal-ai/timbal-react/dist";
28
+ ```
29
+
30
+ > Adjust the path if your CSS file lives at a different depth relative to `node_modules`.
31
+
32
+ ## CSS imports
33
+
34
+ Some components require stylesheets from their dependencies. Import these once in your app entry:
35
+
36
+ ```ts
37
+ // src/main.tsx
38
+ import "@assistant-ui/react-markdown/styles/dot.css";
39
+ import "katex/dist/katex.min.css";
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Usage
45
+
46
+ ### Drop-in chat
47
+
48
+ Wrap `TimbalRuntimeProvider` with a `workforceId` and render `<Thread />` inside it:
49
+
50
+ ```tsx
51
+ import { TimbalRuntimeProvider, Thread } from "@timbal-ai/timbal-react";
52
+
53
+ export default function App() {
54
+ return (
55
+ <TimbalRuntimeProvider workforceId="your-workforce-id">
56
+ <div style={{ height: "100vh" }}>
57
+ <Thread />
58
+ </div>
59
+ </TimbalRuntimeProvider>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### `TimbalRuntimeProvider` props
65
+
66
+ | Prop | Type | Default | Description |
67
+ |---|---|---|---|
68
+ | `workforceId` | `string` | — | ID of the workforce to stream from |
69
+ | `baseUrl` | `string` | `"/api"` | Base URL for API calls. Posts to `{baseUrl}/workforce/{workforceId}/stream` |
70
+ | `fetch` | `(url, options?) => Promise<Response>` | `authFetch` | Custom fetch function. Defaults to the built-in auth-aware fetch (Bearer token + auto-refresh) |
71
+ | `devFakeStream` | `boolean` | `false` | Enable fake streaming for local dev/testing without a backend |
72
+ | `devFakeStreamDelayMs` | `number` | `75` | Token delay in ms for fake streaming |
73
+
74
+ ---
75
+
76
+ ## Auth
77
+
78
+ The package includes a session/auth system backed by localStorage tokens. The API is expected to expose `/api/auth/login`, `/api/auth/logout`, and `/api/auth/refresh`.
79
+
80
+ ### Setup
81
+
82
+ Wrap your app with `SessionProvider` and protect routes with `AuthGuard`:
83
+
84
+ ```tsx
85
+ import { SessionProvider, AuthGuard, TooltipProvider } from "@timbal-ai/timbal-react";
86
+
87
+ const isAuthEnabled = !!import.meta.env.VITE_TIMBAL_PROJECT_ID;
88
+
89
+ function App() {
90
+ return (
91
+ <SessionProvider enabled={isAuthEnabled}>
92
+ <TooltipProvider>
93
+ <AuthGuard requireAuth enabled={isAuthEnabled}>
94
+ <YourApp />
95
+ </AuthGuard>
96
+ </TooltipProvider>
97
+ </SessionProvider>
98
+ );
99
+ }
100
+ ```
101
+
102
+ ### `SessionProvider` props
103
+
104
+ | Prop | Type | Default | Description |
105
+ |---|---|---|---|
106
+ | `enabled` | `boolean` | `true` | When `false`, session is always `null` and no API calls are made |
107
+
108
+ ### `AuthGuard` props
109
+
110
+ | Prop | Type | Default | Description |
111
+ |---|---|---|---|
112
+ | `requireAuth` | `boolean` | `false` | Redirect to login if not authenticated |
113
+ | `enabled` | `boolean` | `true` | When `false`, renders children unconditionally |
114
+
115
+ ### `useSession` hook
116
+
117
+ ```tsx
118
+ import { useSession } from "@timbal-ai/timbal-react";
119
+
120
+ function Header() {
121
+ const { user, isAuthenticated, loading, logout } = useSession();
122
+ // ...
123
+ }
124
+ ```
125
+
126
+ ### `authFetch`
127
+
128
+ A drop-in replacement for `fetch` that attaches the Bearer token and auto-refreshes on 401:
129
+
130
+ ```tsx
131
+ import { authFetch } from "@timbal-ai/timbal-react";
132
+
133
+ const res = await authFetch("/api/workforce");
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Components
139
+
140
+ All components accept `className` for Tailwind overrides.
141
+
142
+ | Export | Description |
143
+ |---|---|
144
+ | `Thread` | Full chat UI — messages, composer, attachments, action bar |
145
+ | `MarkdownText` | Markdown renderer with GFM, math (KaTeX), and syntax highlighting |
146
+ | `ToolFallback` | Animated "Using tool: …" indicator shown while a tool runs |
147
+ | `SyntaxHighlighter` | Shiki-based code highlighter (vitesse-dark / vitesse-light themes) |
148
+ | `UserMessageAttachments` | Attachment thumbnails in user messages |
149
+ | `ComposerAttachments` | Attachment previews inside the composer |
150
+ | `ComposerAddAttachment` | "+" button to add attachments |
151
+ | `TooltipIconButton` | Icon button with a tooltip |
152
+
153
+ ### UI primitives
154
+
155
+ Re-exported Radix UI wrappers pre-styled to match the Timbal design system:
156
+
157
+ `Button` · `Tooltip` · `TooltipTrigger` · `TooltipContent` · `TooltipProvider` · `Avatar` · `AvatarImage` · `AvatarFallback` · `Dialog` · `DialogContent` · `DialogTitle` · `DialogTrigger` · `Shimmer`
158
+
159
+ ---
160
+
161
+ ## Local development
162
+
163
+ The package isn't published yet. Install it via a local path reference:
164
+
165
+ ```json
166
+ // package.json
167
+ {
168
+ "dependencies": {
169
+ "@timbal-ai/timbal-react": "file:../../timbal-react"
170
+ }
171
+ }
172
+ ```
173
+
174
+ Adjust the relative path to where `timbal-react` lives on your machine.
175
+
176
+ After editing source files, rebuild the package:
177
+
178
+ ```bash
179
+ cd timbal-react
180
+ bun run build # one-off build
181
+ bun run build:watch # rebuild on every change
182
+ ```
183
+
184
+ Vite picks up the new `dist/` automatically via HMR — no reinstall needed.