@lastbrain/ai-ui-react 1.0.68 → 1.0.70
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 +8 -3
- package/dist/components/AiChipLabel.d.ts.map +1 -1
- package/dist/components/AiChipLabel.js +23 -70
- package/dist/components/AiContextButton.d.ts +10 -2
- package/dist/components/AiContextButton.d.ts.map +1 -1
- package/dist/components/AiContextButton.js +73 -291
- package/dist/components/AiImageButton.d.ts +5 -1
- package/dist/components/AiImageButton.d.ts.map +1 -1
- package/dist/components/AiImageButton.js +6 -142
- package/dist/components/AiInput.d.ts +5 -3
- package/dist/components/AiInput.d.ts.map +1 -1
- package/dist/components/AiInput.js +13 -25
- package/dist/components/AiPromptPanel.d.ts.map +1 -1
- package/dist/components/AiPromptPanel.js +64 -212
- package/dist/components/AiSelect.d.ts +5 -3
- package/dist/components/AiSelect.d.ts.map +1 -1
- package/dist/components/AiSelect.js +21 -30
- package/dist/components/AiStatusButton.d.ts +4 -1
- package/dist/components/AiStatusButton.d.ts.map +1 -1
- package/dist/components/AiStatusButton.js +211 -676
- package/dist/components/AiTextarea.d.ts +4 -2
- package/dist/components/AiTextarea.d.ts.map +1 -1
- package/dist/components/AiTextarea.js +14 -26
- package/dist/components/LBApiKeySelector.d.ts.map +1 -1
- package/dist/components/LBApiKeySelector.js +5 -166
- package/dist/components/LBConnectButton.d.ts +4 -7
- package/dist/components/LBConnectButton.d.ts.map +1 -1
- package/dist/components/LBConnectButton.js +17 -86
- package/dist/components/LBSigninModal.d.ts +1 -1
- package/dist/components/LBSigninModal.d.ts.map +1 -1
- package/dist/components/LBSigninModal.js +42 -320
- package/dist/context/LBAuthProvider.d.ts +35 -3
- package/dist/context/LBAuthProvider.d.ts.map +1 -1
- package/dist/context/LBAuthProvider.js +2 -0
- package/dist/examples/AiUiPremiumShowcase.d.ts +2 -0
- package/dist/examples/AiUiPremiumShowcase.d.ts.map +1 -0
- package/dist/examples/AiUiPremiumShowcase.js +15 -0
- package/dist/hooks/useAiModels.d.ts.map +1 -1
- package/dist/hooks/useModelManagement.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/styles/inline.d.ts +1 -0
- package/dist/styles/inline.d.ts.map +1 -1
- package/dist/styles/inline.js +25 -129
- package/dist/styles.css +1268 -369
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errorHandler.d.ts +2 -2
- package/dist/utils/errorHandler.d.ts.map +1 -1
- package/dist/utils/errorHandler.js +8 -1
- package/dist/utils/modelManagement.d.ts +13 -10
- package/dist/utils/modelManagement.d.ts.map +1 -1
- package/dist/utils/modelManagement.js +19 -2
- package/package.json +2 -2
- package/src/components/AiChipLabel.tsx +68 -101
- package/src/components/AiContextButton.tsx +142 -413
- package/src/components/AiImageButton.tsx +29 -190
- package/src/components/AiInput.tsx +49 -74
- package/src/components/AiPromptPanel.tsx +81 -260
- package/src/components/AiSelect.tsx +61 -69
- package/src/components/AiStatusButton.tsx +496 -1327
- package/src/components/AiTextarea.tsx +50 -63
- package/src/components/LBApiKeySelector.tsx +93 -271
- package/src/components/LBConnectButton.tsx +39 -336
- package/src/components/LBSigninModal.tsx +141 -472
- package/src/context/LBAuthProvider.tsx +45 -6
- package/src/examples/AiUiPremiumShowcase.tsx +94 -0
- package/src/hooks/useAiModels.ts +2 -1
- package/src/hooks/useModelManagement.ts +2 -1
- package/src/index.ts +3 -0
- package/src/styles/inline.ts +27 -148
- package/src/styles.css +1268 -369
- package/src/types.ts +3 -0
- package/src/utils/errorHandler.ts +16 -3
- package/src/utils/modelManagement.ts +53 -15
package/src/types.ts
CHANGED
|
@@ -4,6 +4,9 @@ export type ToastType = {
|
|
|
4
4
|
code?: string;
|
|
5
5
|
};
|
|
6
6
|
export type UiMode = "modal" | "drawer";
|
|
7
|
+
export type AiSize = "sm" | "md" | "lg";
|
|
8
|
+
export type AiRadius = "none" | "sm" | "md" | "lg" | "full";
|
|
9
|
+
export type AiVariant = "default" | "light";
|
|
7
10
|
|
|
8
11
|
export interface BaseAiProps {
|
|
9
12
|
baseUrl?: string;
|
|
@@ -8,12 +8,25 @@ export interface ParsedError {
|
|
|
8
8
|
isUserFriendly: boolean;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
type NormalizedErrorLike = {
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function isNormalizedErrorLike(value: unknown): value is NormalizedErrorLike {
|
|
17
|
+
if (!value || typeof value !== "object") {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const v = value as Record<string, unknown>;
|
|
21
|
+
return typeof v.code === "string" && typeof v.message === "string";
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
/**
|
|
12
25
|
* Parse et uniformise la gestion des erreurs des composants AI
|
|
13
26
|
*/
|
|
14
|
-
export function parseAIError(error:
|
|
27
|
+
export function parseAIError(error: unknown): ParsedError {
|
|
15
28
|
// Si l'erreur est déjà un objet normalisé
|
|
16
|
-
if (error
|
|
29
|
+
if (isNormalizedErrorLike(error)) {
|
|
17
30
|
return {
|
|
18
31
|
message: getUserFriendlyMessage(error.code, error.message),
|
|
19
32
|
code: error.code,
|
|
@@ -160,7 +173,7 @@ export interface ErrorToastCallback {
|
|
|
160
173
|
* @param showInternalToast Callback interne optionnelle pour afficher un toast dans le composant
|
|
161
174
|
*/
|
|
162
175
|
export function handleAIError(
|
|
163
|
-
error:
|
|
176
|
+
error: unknown,
|
|
164
177
|
onToast?: ErrorToastCallback,
|
|
165
178
|
showInternalToast?: (error: { message: string; code?: string }) => void
|
|
166
179
|
): void {
|
|
@@ -7,6 +7,51 @@ export interface ModelToggleOptions {
|
|
|
7
7
|
baseUrl?: string; // URL de base de l'API
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
interface Provider {
|
|
11
|
+
models?: ModelInfo[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ProvidersResponse {
|
|
15
|
+
providers?: Provider[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ModelsResponse {
|
|
19
|
+
models?: ModelInfo[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type ModelCategory = "text" | "image" | "audio" | "video";
|
|
23
|
+
|
|
24
|
+
interface ModelInfo {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
provider: string;
|
|
29
|
+
category: ModelCategory;
|
|
30
|
+
isActive?: boolean;
|
|
31
|
+
isPro?: boolean;
|
|
32
|
+
costPer1M?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isModelCategory(value: unknown): value is ModelCategory {
|
|
36
|
+
return (
|
|
37
|
+
value === "text" ||
|
|
38
|
+
value === "image" ||
|
|
39
|
+
value === "audio" ||
|
|
40
|
+
value === "video"
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isModelInfo(value: unknown): value is ModelInfo {
|
|
45
|
+
if (!value || typeof value !== "object") return false;
|
|
46
|
+
const v = value as Record<string, unknown>;
|
|
47
|
+
return (
|
|
48
|
+
typeof v.id === "string" &&
|
|
49
|
+
typeof v.name === "string" &&
|
|
50
|
+
typeof v.provider === "string" &&
|
|
51
|
+
isModelCategory(v.category)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
10
55
|
function isAuthTokenCandidate(value?: string): boolean {
|
|
11
56
|
if (!value) return false;
|
|
12
57
|
const token = value.trim();
|
|
@@ -66,18 +111,7 @@ export async function toggleUserModel(
|
|
|
66
111
|
*/
|
|
67
112
|
export async function getAvailableModels(
|
|
68
113
|
options: ModelToggleOptions = {}
|
|
69
|
-
): Promise<
|
|
70
|
-
Array<{
|
|
71
|
-
id: string;
|
|
72
|
-
name: string;
|
|
73
|
-
description?: string;
|
|
74
|
-
provider: string;
|
|
75
|
-
category: "text" | "image" | "audio" | "video";
|
|
76
|
-
isActive?: boolean;
|
|
77
|
-
isPro?: boolean;
|
|
78
|
-
costPer1M?: number;
|
|
79
|
-
}>
|
|
80
|
-
> {
|
|
114
|
+
): Promise<ModelInfo[]> {
|
|
81
115
|
const { apiKey, baseUrl = "" } = options;
|
|
82
116
|
|
|
83
117
|
// Déterminer le contexte
|
|
@@ -123,11 +157,15 @@ export async function getAvailableModels(
|
|
|
123
157
|
const data = await response.json();
|
|
124
158
|
|
|
125
159
|
if (Array.isArray(data?.models)) {
|
|
126
|
-
return data.models;
|
|
160
|
+
return data.models.filter(isModelInfo);
|
|
127
161
|
}
|
|
128
162
|
if (Array.isArray(data?.providers)) {
|
|
129
|
-
return
|
|
130
|
-
|
|
163
|
+
return (
|
|
164
|
+
(data as ProvidersResponse).providers?.flatMap((provider: Provider) =>
|
|
165
|
+
Array.isArray(provider.models)
|
|
166
|
+
? provider.models.filter(isModelInfo)
|
|
167
|
+
: []
|
|
168
|
+
) || []
|
|
131
169
|
);
|
|
132
170
|
}
|
|
133
171
|
return [];
|