@lastbrain/ai-ui-react 1.0.49 → 1.0.52
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/dist/components/AiChipLabel.d.ts.map +1 -1
- package/dist/components/AiChipLabel.js +27 -5
- package/dist/components/AiContextButton.d.ts.map +1 -1
- package/dist/components/AiContextButton.js +5 -3
- package/dist/components/AiImageButton.d.ts.map +1 -1
- package/dist/components/AiImageButton.js +5 -2
- package/dist/components/AiSelect.d.ts.map +1 -1
- package/dist/components/AiSelect.js +38 -2
- package/dist/components/AiStatusButton.d.ts.map +1 -1
- package/dist/components/AiStatusButton.js +24 -12
- package/dist/components/AiTextarea.d.ts.map +1 -1
- package/dist/components/AiTextarea.js +2 -2
- package/dist/components/LBApiKeySelector.d.ts.map +1 -1
- package/dist/components/LBApiKeySelector.js +21 -23
- package/dist/components/LBSigninModal.d.ts.map +1 -1
- package/dist/components/LBSigninModal.js +206 -115
- package/dist/context/LBAuthProvider.d.ts +5 -1
- package/dist/context/LBAuthProvider.d.ts.map +1 -1
- package/dist/context/LBAuthProvider.js +67 -0
- package/package.json +2 -2
- package/src/components/AiChipLabel.tsx +34 -5
- package/src/components/AiContextButton.tsx +9 -13
- package/src/components/AiImageButton.tsx +15 -12
- package/src/components/AiSelect.tsx +71 -1
- package/src/components/AiStatusButton.tsx +28 -15
- package/src/components/AiTextarea.tsx +2 -12
- package/src/components/LBApiKeySelector.tsx +21 -23
- package/src/components/LBSigninModal.tsx +278 -159
- package/src/context/LBAuthProvider.tsx +77 -3
- package/README.md +0 -147
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
LBSession,
|
|
20
20
|
LBLoginResult,
|
|
21
21
|
LBSessionResult,
|
|
22
|
+
AiStatus,
|
|
22
23
|
} from "@lastbrain/ai-ui-core";
|
|
23
24
|
|
|
24
25
|
interface LBProviderProps {
|
|
@@ -57,6 +58,10 @@ interface LBContextValue extends LBAuthState {
|
|
|
57
58
|
apiKeys: LBApiKey[];
|
|
58
59
|
/** Access token temporaire (après login) */
|
|
59
60
|
accessToken?: string;
|
|
61
|
+
/** Status API (balance, storage, API key info) */
|
|
62
|
+
apiStatus: AiStatus | null;
|
|
63
|
+
/** Fonction pour rafraîchir le status */
|
|
64
|
+
refreshStatus: () => Promise<void>;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
const LBContext = createContext<LBContextValue | undefined>(undefined);
|
|
@@ -73,6 +78,7 @@ export function LBProvider({
|
|
|
73
78
|
});
|
|
74
79
|
const [apiKeys, setApiKeys] = useState<LBApiKey[]>([]);
|
|
75
80
|
const [accessToken, setAccessToken] = useState<string>();
|
|
81
|
+
const [apiStatus, setApiStatus] = useState<AiStatus | null>(null);
|
|
76
82
|
|
|
77
83
|
/**
|
|
78
84
|
* Vérifie si une session existe au chargement
|
|
@@ -85,13 +91,13 @@ export function LBProvider({
|
|
|
85
91
|
|
|
86
92
|
if (response.ok) {
|
|
87
93
|
const session: LBSession = await response.json();
|
|
88
|
-
|
|
94
|
+
|
|
89
95
|
// Récupérer les infos utilisateur depuis /auth/status
|
|
90
96
|
try {
|
|
91
97
|
const statusResponse = await fetch(`${proxyUrl}/auth/status`, {
|
|
92
98
|
credentials: "include",
|
|
93
99
|
});
|
|
94
|
-
|
|
100
|
+
|
|
95
101
|
if (statusResponse.ok) {
|
|
96
102
|
const statusData = await statusResponse.json();
|
|
97
103
|
setState({
|
|
@@ -125,7 +131,7 @@ export function LBProvider({
|
|
|
125
131
|
},
|
|
126
132
|
});
|
|
127
133
|
}
|
|
128
|
-
|
|
134
|
+
|
|
129
135
|
onStatusChange?.("ready");
|
|
130
136
|
} else {
|
|
131
137
|
setState({ status: "needs_auth" });
|
|
@@ -419,6 +425,72 @@ export function LBProvider({
|
|
|
419
425
|
await checkSession();
|
|
420
426
|
}, [checkSession]);
|
|
421
427
|
|
|
428
|
+
/**
|
|
429
|
+
* Récupère le status API (balance, storage, API key info)
|
|
430
|
+
*/
|
|
431
|
+
const refreshStatus = useCallback(async (): Promise<void> => {
|
|
432
|
+
if (state.status !== "ready") {
|
|
433
|
+
setApiStatus(null);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
try {
|
|
438
|
+
const response = await fetch(`${proxyUrl}/auth/status`, {
|
|
439
|
+
credentials: "include",
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
if (response.ok) {
|
|
443
|
+
const data = await response.json();
|
|
444
|
+
setApiStatus(data);
|
|
445
|
+
} else {
|
|
446
|
+
setApiStatus(null);
|
|
447
|
+
}
|
|
448
|
+
} catch (error) {
|
|
449
|
+
console.error("[LBProvider] Failed to fetch status:", error);
|
|
450
|
+
setApiStatus(null);
|
|
451
|
+
}
|
|
452
|
+
}, [proxyUrl, state.status]);
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Récupère les clés API avec la session active
|
|
456
|
+
*/
|
|
457
|
+
const fetchApiKeysWithSession = useCallback(async (): Promise<void> => {
|
|
458
|
+
if (state.status !== "ready") {
|
|
459
|
+
setApiKeys([]);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
try {
|
|
464
|
+
console.log("[LBProvider] Fetching API keys with session...");
|
|
465
|
+
const response = await fetch(`${proxyUrl}/auth/api-keys`, {
|
|
466
|
+
credentials: "include",
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
if (response.ok) {
|
|
470
|
+
const data = await response.json();
|
|
471
|
+
console.log("[LBProvider] API keys received:", data);
|
|
472
|
+
setApiKeys(data.apiKeys || []);
|
|
473
|
+
} else {
|
|
474
|
+
console.warn("[LBProvider] Failed to fetch API keys:", response.status);
|
|
475
|
+
setApiKeys([]);
|
|
476
|
+
}
|
|
477
|
+
} catch (error) {
|
|
478
|
+
console.error("[LBProvider] Failed to fetch API keys:", error);
|
|
479
|
+
setApiKeys([]);
|
|
480
|
+
}
|
|
481
|
+
}, [proxyUrl, state.status]);
|
|
482
|
+
|
|
483
|
+
// Refresh status quand la session devient ready
|
|
484
|
+
useEffect(() => {
|
|
485
|
+
if (state.status === "ready") {
|
|
486
|
+
refreshStatus();
|
|
487
|
+
fetchApiKeysWithSession(); // Also fetch API keys list
|
|
488
|
+
} else {
|
|
489
|
+
setApiStatus(null);
|
|
490
|
+
setApiKeys([]);
|
|
491
|
+
}
|
|
492
|
+
}, [state.status, refreshStatus, fetchApiKeysWithSession]);
|
|
493
|
+
|
|
422
494
|
const value: LBContextValue = {
|
|
423
495
|
...state,
|
|
424
496
|
login,
|
|
@@ -429,6 +501,8 @@ export function LBProvider({
|
|
|
429
501
|
refreshSession,
|
|
430
502
|
apiKeys,
|
|
431
503
|
accessToken,
|
|
504
|
+
apiStatus,
|
|
505
|
+
refreshStatus,
|
|
432
506
|
};
|
|
433
507
|
|
|
434
508
|
return <LBContext.Provider value={value}>{children}</LBContext.Provider>;
|
package/README.md
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# @lastbrain/ai-ui-react
|
|
2
|
-
|
|
3
|
-
Headless React components for LastBrain AI UI Kit.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Headless components (no UI library dependency)
|
|
8
|
-
- Built-in CSS styles (optional)
|
|
9
|
-
- React hooks for AI operations
|
|
10
|
-
- Context provider for configuration
|
|
11
|
-
- TypeScript support
|
|
12
|
-
- SSR safe
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install @lastbrain/ai-ui-react @lastbrain/ai-ui-core
|
|
18
|
-
# or
|
|
19
|
-
pnpm add @lastbrain/ai-ui-react @lastbrain/ai-ui-core
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Styles
|
|
23
|
-
|
|
24
|
-
**Version 1.0.8+**: Components now use inline styles by default. No CSS import required!
|
|
25
|
-
|
|
26
|
-
The package includes built-in styling that works out of the box. Components will render correctly without any additional CSS imports.
|
|
27
|
-
|
|
28
|
-
If you want to customize the styling, you can:
|
|
29
|
-
|
|
30
|
-
1. **Override inline styles**: Pass custom `className` or `style` props
|
|
31
|
-
2. **Use the optional CSS file**: Import `@lastbrain/ai-ui-react/styles.css` for additional customization
|
|
32
|
-
3. **Provide your own styles**: Style components using the provided CSS classes
|
|
33
|
-
|
|
34
|
-
```tsx
|
|
35
|
-
// ✅ Works out of the box (no CSS import needed)
|
|
36
|
-
import { AiStatusButton } from "@lastbrain/ai-ui-react";
|
|
37
|
-
|
|
38
|
-
// ✅ Optional: Import CSS for customization
|
|
39
|
-
import "@lastbrain/ai-ui-react/styles.css";
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### CSS Classes (for custom styling)
|
|
43
|
-
|
|
44
|
-
If you want to override styles using CSS, target these classes:
|
|
45
|
-
|
|
46
|
-
- `.ai-input` - Input field
|
|
47
|
-
- `.ai-textarea` - Textarea
|
|
48
|
-
- `.ai-button` - Button
|
|
49
|
-
- `.ai-select` - Select dropdown
|
|
50
|
-
- `.ai-modal` - Modal dialog
|
|
51
|
-
- `.ai-tooltip` - Tooltip
|
|
52
|
-
- `.ai-chip` - Chip/Badge
|
|
53
|
-
- `.ai-status-button` - Status button
|
|
54
|
-
- And more...
|
|
55
|
-
|
|
56
|
-
### CSS Variables
|
|
57
|
-
|
|
58
|
-
Customize the theme using CSS variables:
|
|
59
|
-
|
|
60
|
-
```css
|
|
61
|
-
:root {
|
|
62
|
-
--ai-primary: #3b82f6;
|
|
63
|
-
--ai-primary-hover: #2563eb;
|
|
64
|
-
--ai-success: #10b981;
|
|
65
|
-
--ai-warning: #f59e0b;
|
|
66
|
-
--ai-danger: #ef4444;
|
|
67
|
-
--ai-border: #e5e7eb;
|
|
68
|
-
--ai-text: #1f2937;
|
|
69
|
-
--ai-text-secondary: #6b7280;
|
|
70
|
-
--ai-bg: #ffffff;
|
|
71
|
-
--ai-bg-hover: #f9fafb;
|
|
72
|
-
--ai-radius: 8px;
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Usage
|
|
77
|
-
|
|
78
|
-
### With Provider (Recommended)
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
import {
|
|
82
|
-
AiProvider,
|
|
83
|
-
AiInput,
|
|
84
|
-
AiSettingsButton,
|
|
85
|
-
AiStatusButton,
|
|
86
|
-
} from "@lastbrain/ai-ui-react";
|
|
87
|
-
import "@lastbrain/ai-ui-react/styles.css";
|
|
88
|
-
|
|
89
|
-
function App() {
|
|
90
|
-
return (
|
|
91
|
-
<AiProvider baseUrl="https://api.lastbrain.com" apiKeyId="your-key">
|
|
92
|
-
<div>
|
|
93
|
-
<AiInput
|
|
94
|
-
model="openai/gpt-4o-mini"
|
|
95
|
-
prompt="Improve this text"
|
|
96
|
-
onValue={(text) => console.log(text)}
|
|
97
|
-
onToast={(toast) => alert(toast.message)}
|
|
98
|
-
/>
|
|
99
|
-
<AiStatusButton />
|
|
100
|
-
<AiSettingsButton />
|
|
101
|
-
</div>
|
|
102
|
-
</AiProvider>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Without Provider
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
import { AiInput } from "@lastbrain/ai-ui-react";
|
|
111
|
-
import "@lastbrain/ai-ui-react/styles.css";
|
|
112
|
-
|
|
113
|
-
function MyComponent() {
|
|
114
|
-
return (
|
|
115
|
-
<AiInput
|
|
116
|
-
baseUrl="https://api.lastbrain.com"
|
|
117
|
-
apiKeyId="your-key"
|
|
118
|
-
model="openai/gpt-4o-mini"
|
|
119
|
-
prompt="Improve this text"
|
|
120
|
-
onValue={(text) => console.log(text)}
|
|
121
|
-
/>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Components
|
|
127
|
-
|
|
128
|
-
- `AiInput` - Text input with AI assistance
|
|
129
|
-
- `AiTextarea` - Textarea with AI assistance
|
|
130
|
-
- `AiSelect` - Select dropdown with AI assistance
|
|
131
|
-
- `AiChipLabel` - Chip/label with AI assistance
|
|
132
|
-
- `AiImageButton` - Button for AI image generation
|
|
133
|
-
- `AiSettingsButton` - Settings button with status display
|
|
134
|
-
- `AiPromptPanel` - Modal/drawer for model and prompt selection
|
|
135
|
-
- `AiModelSelect` - Model selection dropdown
|
|
136
|
-
|
|
137
|
-
## Hooks
|
|
138
|
-
|
|
139
|
-
- `useAiClient` - Access AI client instance
|
|
140
|
-
- `useAiModels` - Fetch available models
|
|
141
|
-
- `useAiStatus` - Fetch user status (tokens, wallet, storage)
|
|
142
|
-
- `useAiCallText` - Generate text
|
|
143
|
-
- `useAiCallImage` - Generate images
|
|
144
|
-
|
|
145
|
-
## API Reference
|
|
146
|
-
|
|
147
|
-
See the [full documentation](https://docs.lastbrain.com/ai-ui-kit/react) for detailed API reference.
|