@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
@@ -1,29 +1,33 @@
1
1
  "use client";
2
2
 
3
3
  import React, { useState, type SelectHTMLAttributes } from "react";
4
- import { Sparkles, Lock } from "lucide-react";
5
- import type { BaseAiProps } from "../types";
4
+ import { ChevronDown, Loader2, Lock, Sparkles } from "lucide-react";
5
+ import type { AiRadius, AiSize, BaseAiProps } from "../types";
6
6
  import { useAiCallText } from "../hooks/useAiCallText";
7
7
  import { useAiModels } from "../hooks/useAiModels";
8
8
  import { AiPromptPanel } from "./AiPromptPanel";
9
9
  import { UsageToast, useUsageToast } from "./UsageToast";
10
10
  import { LBSigninModal } from "./LBSigninModal";
11
- import { aiStyles } from "../styles/inline";
12
11
  import { handleAIError } from "../utils/errorHandler";
13
12
  import { useLB } from "../context/LBAuthProvider";
13
+ import { useAiContext } from "../context/AiProvider";
14
14
 
15
15
  export interface AiSelectProps
16
16
  extends
17
17
  Omit<BaseAiProps, "type">,
18
- Omit<SelectHTMLAttributes<HTMLSelectElement>, "onValue"> {
18
+ Omit<SelectHTMLAttributes<HTMLSelectElement>, "onValue" | "size"> {
19
19
  children: React.ReactNode;
20
20
  uiMode?: "modal" | "drawer";
21
+ size?: AiSize;
22
+ radius?: AiRadius;
21
23
  }
22
24
 
23
25
  export function AiSelect({
24
- baseUrl,
25
- apiKeyId,
26
+ baseUrl: propBaseUrl,
27
+ apiKeyId: propApiKeyId,
26
28
  uiMode = "modal",
29
+ size = "md",
30
+ radius = "full",
27
31
  context,
28
32
  model,
29
33
  prompt,
@@ -38,7 +42,6 @@ export function AiSelect({
38
42
  }: AiSelectProps) {
39
43
  const [isOpen, setIsOpen] = useState(false);
40
44
  const [showAuthModal, setShowAuthModal] = useState(false);
41
- const [isFocused, setIsFocused] = useState(false);
42
45
  const { showUsageToast, toastData, toastKey, clearToast } = useUsageToast();
43
46
 
44
47
  // Rendre l'authentification optionnelle
@@ -51,6 +54,20 @@ export function AiSelect({
51
54
  lbStatus = undefined;
52
55
  }
53
56
 
57
+ let ctxBaseUrl: string | undefined;
58
+ let ctxApiKeyId: string | undefined;
59
+ try {
60
+ const aiContext = useAiContext();
61
+ ctxBaseUrl = aiContext.baseUrl;
62
+ ctxApiKeyId = aiContext.apiKeyId;
63
+ } catch {
64
+ ctxBaseUrl = undefined;
65
+ ctxApiKeyId = undefined;
66
+ }
67
+
68
+ const baseUrl = propBaseUrl ?? ctxBaseUrl;
69
+ const apiKeyId = propApiKeyId ?? ctxApiKeyId;
70
+
54
71
  const { models } = useAiModels({
55
72
  baseUrl,
56
73
  apiKeyId,
@@ -99,69 +116,44 @@ export function AiSelect({
99
116
  }
100
117
  };
101
118
 
119
+ const sizeClass = `ai-size-${size}`;
120
+ const radiusClass = `ai-radius-${radius}`;
121
+
102
122
  return (
103
- <div style={{ width: "100%", position: "relative" }} className={className}>
104
- <select
105
- {...selectProps}
106
- style={{
107
- ...aiStyles.select,
108
- ...(isFocused && aiStyles.selectFocus),
109
- paddingRight: "40px", // Space for AI button
110
- }}
111
- onFocus={(e) => {
112
- setIsFocused(true);
113
- selectProps.onFocus?.(e);
114
- }}
115
- onBlur={(e) => {
116
- setIsFocused(false);
117
- selectProps.onBlur?.(e);
118
- }}
119
- disabled={disabled || loading}
120
- >
121
- {children}
122
- </select>
123
-
124
- {/* AI Button */}
125
- <button
126
- onClick={handleOpenPanel}
127
- style={{
128
- position: "absolute",
129
- right: "8px",
130
- top: "50%",
131
- transform: "translateY(-50%)",
132
- background: "none",
133
- border: "none",
134
- cursor: "pointer",
135
- padding: "4px",
136
- borderRadius: "4px",
137
- display: "flex",
138
- alignItems: "center",
139
- color: shouldShowSparkles ? "#6366f1" : "#ef4444",
140
- }}
141
- title={
142
- shouldShowSparkles
143
- ? "Générer avec l'IA"
144
- : "Se connecter pour utiliser l'IA"
145
- }
146
- disabled={disabled || loading}
147
- >
148
- {loading ? (
149
- <svg
150
- style={aiStyles.spinner}
151
- width="16"
152
- height="16"
153
- viewBox="0 0 24 24"
154
- fill="none"
155
- stroke="currentColor"
156
- >
157
- <path d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83" />
158
- </svg>
159
- ) : shouldShowSparkles ? (
160
- <Sparkles size={16} />
161
- ) : (
162
- <Lock size={16} />
163
- )}
164
- </button>
123
+ <div className={`ai-control-group ai-glow ${className || ""}`}>
124
+ <div className={`ai-shell ${sizeClass} ${radiusClass}`}>
125
+ <select
126
+ {...selectProps}
127
+ className={`ai-control ai-control-input ai-control-select ${sizeClass} ${radiusClass}`}
128
+ disabled={disabled || loading}
129
+ >
130
+ {children}
131
+ </select>
132
+
133
+ <span className="ai-control-select-chevron" aria-hidden="true">
134
+ <ChevronDown size={14} />
135
+ </span>
136
+
137
+ <button
138
+ className={`ai-control-action ai-spark ${sizeClass} ${radiusClass}`}
139
+ onClick={handleOpenPanel}
140
+ title={
141
+ shouldShowSparkles
142
+ ? "Générer avec l'IA"
143
+ : "Se connecter pour utiliser l'IA"
144
+ }
145
+ disabled={disabled || loading}
146
+ type="button"
147
+ >
148
+ {loading ? (
149
+ <Loader2 size={16} className="ai-spinner" />
150
+ ) : shouldShowSparkles ? (
151
+ <Sparkles size={16} />
152
+ ) : (
153
+ <Lock size={16} />
154
+ )}
155
+ </button>
156
+ </div>
165
157
  {isOpen && (
166
158
  <AiPromptPanel
167
159
  isOpen={isOpen}