@lastbrain/ai-ui-react 1.0.11 → 1.0.12
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/AiInput.d.ts.map +1 -1
- package/dist/components/AiInput.js +1 -1
- package/dist/components/AiPromptPanel.d.ts +14 -1
- package/dist/components/AiPromptPanel.d.ts.map +1 -1
- package/dist/components/AiPromptPanel.js +255 -7
- package/dist/components/AiSettingsButton.d.ts.map +1 -1
- package/dist/components/AiSettingsButton.js +1 -1
- package/dist/components/AiStatusButton.d.ts.map +1 -1
- package/dist/components/AiStatusButton.js +106 -11
- package/dist/examples/AiImageGenerator.d.ts +34 -0
- package/dist/examples/AiImageGenerator.d.ts.map +1 -0
- package/dist/examples/AiImageGenerator.js +85 -0
- package/dist/examples/AiPromptPanelAdvanced.d.ts +20 -0
- package/dist/examples/AiPromptPanelAdvanced.d.ts.map +1 -0
- package/dist/examples/AiPromptPanelAdvanced.js +222 -0
- package/dist/examples/ExternalIntegration.d.ts +2 -0
- package/dist/examples/ExternalIntegration.d.ts.map +1 -0
- package/dist/examples/ExternalIntegration.js +2 -0
- package/dist/hooks/useAiStatus.d.ts.map +1 -1
- package/dist/hooks/useAiStatus.js +3 -0
- package/dist/hooks/useModelManagement.d.ts +32 -0
- package/dist/hooks/useModelManagement.d.ts.map +1 -0
- package/dist/hooks/useModelManagement.js +135 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/styles/inline.d.ts.map +1 -1
- package/dist/styles/inline.js +10 -1
- package/dist/utils/modelManagement.d.ts +29 -0
- package/dist/utils/modelManagement.d.ts.map +1 -0
- package/dist/utils/modelManagement.js +80 -0
- package/package.json +2 -2
- package/src/components/AiInput.tsx +3 -0
- package/src/components/AiPromptPanel.tsx +502 -24
- package/src/components/AiSettingsButton.tsx +4 -2
- package/src/components/AiStatusButton.tsx +185 -39
- package/src/examples/AiImageGenerator.tsx +214 -0
- package/src/examples/AiPromptPanelAdvanced.tsx +381 -0
- package/src/examples/ExternalIntegration.ts +55 -0
- package/src/hooks/useAiStatus.ts +4 -0
- package/src/hooks/useModelManagement.ts +210 -0
- package/src/index.ts +8 -0
- package/src/styles/inline.ts +10 -1
- package/src/utils/modelManagement.ts +130 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilitaires pour la gestion des modèles IA
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ModelToggleOptions {
|
|
6
|
+
apiKey?: string; // LB_API_KEY pour l'authentification
|
|
7
|
+
baseUrl?: string; // URL de base de l'API
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Active ou désactive un modèle pour l'utilisateur courant
|
|
12
|
+
*/
|
|
13
|
+
export async function toggleUserModel(
|
|
14
|
+
modelId: string,
|
|
15
|
+
isActive: boolean,
|
|
16
|
+
options: ModelToggleOptions = {}
|
|
17
|
+
): Promise<void> {
|
|
18
|
+
const { apiKey, baseUrl = "" } = options;
|
|
19
|
+
|
|
20
|
+
const headers: Record<string, string> = {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Ajouter la clé API si fournie
|
|
25
|
+
if (apiKey) {
|
|
26
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const response = await fetch(
|
|
30
|
+
`${baseUrl}/api/public/v1/ai/user/models/toggle`,
|
|
31
|
+
{
|
|
32
|
+
method: "PUT",
|
|
33
|
+
headers,
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
model_id: modelId,
|
|
36
|
+
is_active: isActive,
|
|
37
|
+
}),
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const error = await response.text();
|
|
43
|
+
throw new Error(`Erreur lors de la modification du modèle: ${error}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Récupère tous les modèles disponibles avec API key ou via proxy
|
|
49
|
+
*/
|
|
50
|
+
export async function getAvailableModels(
|
|
51
|
+
options: ModelToggleOptions = {}
|
|
52
|
+
): Promise<
|
|
53
|
+
Array<{
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
category: "text" | "image" | "audio" | "video";
|
|
59
|
+
isActive?: boolean;
|
|
60
|
+
isPro?: boolean;
|
|
61
|
+
costPer1M?: number;
|
|
62
|
+
}>
|
|
63
|
+
> {
|
|
64
|
+
const { apiKey, baseUrl = "" } = options;
|
|
65
|
+
|
|
66
|
+
// Si baseUrl est fourni (contexte externe), utiliser la route auth qui sera proxifiée
|
|
67
|
+
const isExternal = baseUrl && baseUrl !== "";
|
|
68
|
+
const endpoint = isExternal
|
|
69
|
+
? `${baseUrl}/ai/auth/ai-models-available`
|
|
70
|
+
: `/api/public/v1/ai/models/available`;
|
|
71
|
+
|
|
72
|
+
const headers: Record<string, string> = {};
|
|
73
|
+
|
|
74
|
+
// Ajouter la clé API seulement si pas de baseUrl (appel direct)
|
|
75
|
+
if (!isExternal && apiKey) {
|
|
76
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const response = await fetch(endpoint, {
|
|
80
|
+
method: "GET",
|
|
81
|
+
headers,
|
|
82
|
+
credentials: isExternal ? "include" : "same-origin",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Erreur lors de la récupération des modèles: ${response.status}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const data = await response.json();
|
|
92
|
+
return data.models || [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Récupère les modèles activés par l'utilisateur avec API key
|
|
97
|
+
*/
|
|
98
|
+
export async function getUserModels(
|
|
99
|
+
options: ModelToggleOptions = {}
|
|
100
|
+
): Promise<string[]> {
|
|
101
|
+
const { apiKey, baseUrl = "" } = options;
|
|
102
|
+
|
|
103
|
+
// Si baseUrl est fourni (contexte externe), utiliser la route auth qui sera proxifiée
|
|
104
|
+
const isExternal = baseUrl && baseUrl !== "";
|
|
105
|
+
const endpoint = isExternal
|
|
106
|
+
? `${baseUrl}/ai/auth/user-models`
|
|
107
|
+
: `/api/public/v1/ai/user/models`;
|
|
108
|
+
|
|
109
|
+
const headers: Record<string, string> = {};
|
|
110
|
+
|
|
111
|
+
// Ajouter la clé API seulement si pas de baseUrl (appel direct)
|
|
112
|
+
if (!isExternal && apiKey) {
|
|
113
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const response = await fetch(endpoint, {
|
|
117
|
+
method: "GET",
|
|
118
|
+
headers,
|
|
119
|
+
credentials: isExternal ? "include" : "same-origin",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (!response.ok) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Erreur lors de la récupération des modèles utilisateur: ${response.status}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const data = await response.json();
|
|
129
|
+
return data.enabled_models || [];
|
|
130
|
+
}
|