@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.
Files changed (76) hide show
  1. package/dist/components/AiChipLabel.d.ts +8 -3
  2. package/dist/components/AiChipLabel.d.ts.map +1 -1
  3. package/dist/components/AiChipLabel.js +23 -70
  4. package/dist/components/AiContextButton.d.ts +10 -2
  5. package/dist/components/AiContextButton.d.ts.map +1 -1
  6. package/dist/components/AiContextButton.js +73 -291
  7. package/dist/components/AiImageButton.d.ts +5 -1
  8. package/dist/components/AiImageButton.d.ts.map +1 -1
  9. package/dist/components/AiImageButton.js +6 -142
  10. package/dist/components/AiInput.d.ts +5 -3
  11. package/dist/components/AiInput.d.ts.map +1 -1
  12. package/dist/components/AiInput.js +13 -25
  13. package/dist/components/AiPromptPanel.d.ts.map +1 -1
  14. package/dist/components/AiPromptPanel.js +64 -212
  15. package/dist/components/AiSelect.d.ts +5 -3
  16. package/dist/components/AiSelect.d.ts.map +1 -1
  17. package/dist/components/AiSelect.js +21 -30
  18. package/dist/components/AiStatusButton.d.ts +4 -1
  19. package/dist/components/AiStatusButton.d.ts.map +1 -1
  20. package/dist/components/AiStatusButton.js +211 -676
  21. package/dist/components/AiTextarea.d.ts +4 -2
  22. package/dist/components/AiTextarea.d.ts.map +1 -1
  23. package/dist/components/AiTextarea.js +14 -26
  24. package/dist/components/LBApiKeySelector.d.ts.map +1 -1
  25. package/dist/components/LBApiKeySelector.js +5 -166
  26. package/dist/components/LBConnectButton.d.ts +4 -7
  27. package/dist/components/LBConnectButton.d.ts.map +1 -1
  28. package/dist/components/LBConnectButton.js +17 -86
  29. package/dist/components/LBSigninModal.d.ts +1 -1
  30. package/dist/components/LBSigninModal.d.ts.map +1 -1
  31. package/dist/components/LBSigninModal.js +42 -320
  32. package/dist/context/LBAuthProvider.d.ts +35 -3
  33. package/dist/context/LBAuthProvider.d.ts.map +1 -1
  34. package/dist/context/LBAuthProvider.js +2 -0
  35. package/dist/examples/AiUiPremiumShowcase.d.ts +2 -0
  36. package/dist/examples/AiUiPremiumShowcase.d.ts.map +1 -0
  37. package/dist/examples/AiUiPremiumShowcase.js +15 -0
  38. package/dist/hooks/useAiModels.d.ts.map +1 -1
  39. package/dist/hooks/useModelManagement.d.ts.map +1 -1
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +2 -0
  43. package/dist/styles/inline.d.ts +1 -0
  44. package/dist/styles/inline.d.ts.map +1 -1
  45. package/dist/styles/inline.js +25 -129
  46. package/dist/styles.css +1268 -369
  47. package/dist/types.d.ts +3 -0
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/utils/errorHandler.d.ts +2 -2
  50. package/dist/utils/errorHandler.d.ts.map +1 -1
  51. package/dist/utils/errorHandler.js +8 -1
  52. package/dist/utils/modelManagement.d.ts +13 -10
  53. package/dist/utils/modelManagement.d.ts.map +1 -1
  54. package/dist/utils/modelManagement.js +19 -2
  55. package/package.json +2 -2
  56. package/src/components/AiChipLabel.tsx +68 -101
  57. package/src/components/AiContextButton.tsx +142 -413
  58. package/src/components/AiImageButton.tsx +29 -190
  59. package/src/components/AiInput.tsx +49 -74
  60. package/src/components/AiPromptPanel.tsx +81 -260
  61. package/src/components/AiSelect.tsx +61 -69
  62. package/src/components/AiStatusButton.tsx +496 -1327
  63. package/src/components/AiTextarea.tsx +50 -63
  64. package/src/components/LBApiKeySelector.tsx +93 -271
  65. package/src/components/LBConnectButton.tsx +39 -336
  66. package/src/components/LBSigninModal.tsx +141 -472
  67. package/src/context/LBAuthProvider.tsx +45 -6
  68. package/src/examples/AiUiPremiumShowcase.tsx +94 -0
  69. package/src/hooks/useAiModels.ts +2 -1
  70. package/src/hooks/useModelManagement.ts +2 -1
  71. package/src/index.ts +3 -0
  72. package/src/styles/inline.ts +27 -148
  73. package/src/styles.css +1268 -369
  74. package/src/types.ts +3 -0
  75. package/src/utils/errorHandler.ts +16 -3
  76. 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: any): ParsedError {
27
+ export function parseAIError(error: unknown): ParsedError {
15
28
  // Si l'erreur est déjà un objet normalisé
16
- if (error?.code && error?.message) {
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: any,
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 data.providers.flatMap((provider: any) =>
130
- Array.isArray(provider.models) ? provider.models : []
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 [];