@lastbrain/ai-ui-react 1.0.11 → 1.0.14

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.
Files changed (44) hide show
  1. package/dist/components/AiInput.d.ts.map +1 -1
  2. package/dist/components/AiInput.js +1 -1
  3. package/dist/components/AiPromptPanel.d.ts +14 -1
  4. package/dist/components/AiPromptPanel.d.ts.map +1 -1
  5. package/dist/components/AiPromptPanel.js +255 -7
  6. package/dist/components/AiSettingsButton.d.ts.map +1 -1
  7. package/dist/components/AiSettingsButton.js +1 -1
  8. package/dist/components/AiStatusButton.d.ts.map +1 -1
  9. package/dist/components/AiStatusButton.js +106 -11
  10. package/dist/examples/AiImageGenerator.d.ts +34 -0
  11. package/dist/examples/AiImageGenerator.d.ts.map +1 -0
  12. package/dist/examples/AiImageGenerator.js +85 -0
  13. package/dist/examples/AiPromptPanelAdvanced.d.ts +20 -0
  14. package/dist/examples/AiPromptPanelAdvanced.d.ts.map +1 -0
  15. package/dist/examples/AiPromptPanelAdvanced.js +222 -0
  16. package/dist/examples/ExternalIntegration.d.ts +2 -0
  17. package/dist/examples/ExternalIntegration.d.ts.map +1 -0
  18. package/dist/examples/ExternalIntegration.js +2 -0
  19. package/dist/hooks/useAiStatus.d.ts.map +1 -1
  20. package/dist/hooks/useAiStatus.js +3 -0
  21. package/dist/hooks/useModelManagement.d.ts +32 -0
  22. package/dist/hooks/useModelManagement.d.ts.map +1 -0
  23. package/dist/hooks/useModelManagement.js +135 -0
  24. package/dist/index.d.ts +4 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +6 -0
  27. package/dist/styles/inline.d.ts.map +1 -1
  28. package/dist/styles/inline.js +10 -1
  29. package/dist/utils/modelManagement.d.ts +29 -0
  30. package/dist/utils/modelManagement.d.ts.map +1 -0
  31. package/dist/utils/modelManagement.js +82 -0
  32. package/package.json +2 -2
  33. package/src/components/AiInput.tsx +3 -0
  34. package/src/components/AiPromptPanel.tsx +502 -24
  35. package/src/components/AiSettingsButton.tsx +4 -2
  36. package/src/components/AiStatusButton.tsx +185 -39
  37. package/src/examples/AiImageGenerator.tsx +214 -0
  38. package/src/examples/AiPromptPanelAdvanced.tsx +381 -0
  39. package/src/examples/ExternalIntegration.ts +55 -0
  40. package/src/hooks/useAiStatus.ts +4 -0
  41. package/src/hooks/useModelManagement.ts +210 -0
  42. package/src/index.ts +8 -0
  43. package/src/styles/inline.ts +10 -1
  44. package/src/utils/modelManagement.ts +134 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Utilitaires pour la gestion des modèles IA
3
+ */
4
+ /**
5
+ * Active ou désactive un modèle pour l'utilisateur courant
6
+ */
7
+ export async function toggleUserModel(modelId, isActive, options = {}) {
8
+ const { apiKey, baseUrl = "" } = options;
9
+ const headers = {
10
+ "Content-Type": "application/json",
11
+ };
12
+ // Ajouter la clé API si fournie
13
+ if (apiKey) {
14
+ headers["Authorization"] = `Bearer ${apiKey}`;
15
+ }
16
+ const response = await fetch(`${baseUrl}/api/public/v1/ai/user/models/toggle`, {
17
+ method: "PUT",
18
+ headers,
19
+ body: JSON.stringify({
20
+ model_id: modelId,
21
+ is_active: isActive,
22
+ }),
23
+ });
24
+ if (!response.ok) {
25
+ const error = await response.text();
26
+ throw new Error(`Erreur lors de la modification du modèle: ${error}`);
27
+ }
28
+ }
29
+ /**
30
+ * Récupère tous les modèles disponibles avec API key ou via proxy
31
+ */
32
+ export async function getAvailableModels(options = {}) {
33
+ const { apiKey, baseUrl = "" } = options;
34
+ // Déterminer si on est dans un contexte externe (proxy nécessaire)
35
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
36
+ const endpoint = isExternalProxy
37
+ ? `${baseUrl}/ai/auth/ai-models-available` // → /api/lastbrain/ai/auth/ai-models-available
38
+ : `/api/public/v1/ai/models/available`; // → /api/public/v1/ai/models/available
39
+ console.log("[getAvailableModels] isExternalProxy:", isExternalProxy, "endpoint:", endpoint);
40
+ const headers = {};
41
+ // Ajouter la clé API seulement si pas de proxy externe (appel direct)
42
+ if (!isExternalProxy && apiKey) {
43
+ headers["Authorization"] = `Bearer ${apiKey}`;
44
+ }
45
+ const response = await fetch(endpoint, {
46
+ method: "GET",
47
+ headers,
48
+ credentials: isExternalProxy ? 'include' : 'same-origin',
49
+ });
50
+ if (!response.ok) {
51
+ throw new Error(`Erreur lors de la récupération des modèles: ${response.status}`);
52
+ }
53
+ const data = await response.json();
54
+ return data.models || [];
55
+ }
56
+ /**
57
+ * Récupère les modèles activés par l'utilisateur avec API key
58
+ */
59
+ export async function getUserModels(options = {}) {
60
+ const { apiKey, baseUrl = "" } = options;
61
+ // Déterminer si on est dans un contexte externe (proxy nécessaire)
62
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
63
+ const endpoint = isExternalProxy
64
+ ? `${baseUrl}/ai/auth/user-models` // → /api/lastbrain/ai/auth/user-models
65
+ : `/api/public/v1/ai/user/models`; // → /api/public/v1/ai/user/models
66
+ console.log("[getUserModels] isExternalProxy:", isExternalProxy, "endpoint:", endpoint);
67
+ const headers = {};
68
+ // Ajouter la clé API seulement si pas de proxy externe (appel direct)
69
+ if (!isExternalProxy && apiKey) {
70
+ headers["Authorization"] = `Bearer ${apiKey}`;
71
+ }
72
+ const response = await fetch(endpoint, {
73
+ method: "GET",
74
+ headers,
75
+ credentials: isExternalProxy ? 'include' : 'same-origin',
76
+ });
77
+ if (!response.ok) {
78
+ throw new Error(`Erreur lors de la récupération des modèles utilisateur: ${response.status}`);
79
+ }
80
+ const data = await response.json();
81
+ return data.enabled_models || [];
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lastbrain/ai-ui-react",
3
- "version": "1.0.11",
3
+ "version": "1.0.14",
4
4
  "description": "Headless React components for LastBrain AI UI Kit",
5
5
  "private": false,
6
6
  "type": "module",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "lucide-react": "^0.257.0",
51
- "@lastbrain/ai-ui-core": "1.0.5"
51
+ "@lastbrain/ai-ui-core": "1.0.8"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/react": "^19.2.0",
@@ -183,6 +183,9 @@ export function AiInput({
183
183
  uiMode={uiMode}
184
184
  models={models || []}
185
185
  sourceText={inputValue || undefined}
186
+ apiKey={apiKeyId}
187
+ baseUrl={baseUrl}
188
+ enableModelManagement={true}
186
189
  />
187
190
  )}
188
191
  {Boolean(toastData) && (