@lastbrain/ai-ui-react 1.0.66 → 1.0.67
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiProvider.d.ts","sourceRoot":"","sources":["../../src/context/AiProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"AiProvider.d.ts","sourceRoot":"","sources":["../../src/context/AiProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAKtD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAC/C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,EAAE,OAAO,CAAC;IAE3B,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC,eAAe,EAAE,CACf,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,KAC1C,QAAQ,EAAE,CAAC;IAChB,aAAa,EAAE,MAAM,QAAQ,EAAE,CAAC;IAChC,cAAc,EAAE,MAAM,QAAQ,EAAE,CAAC;CAClC;AAED,QAAA,MAAM,SAAS,qDAAuD,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,EACzB,OAAO,EACP,QAAQ,EACR,MAAgB,EAChB,QAAQ,GACT,EAAE,eAAe,2CAuSjB;AAED,wBAAgB,YAAY,IAAI,cAAc,CAM7C;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -3,8 +3,20 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { createContext, useContext, useState, useEffect, useCallback, useRef, } from "react";
|
|
4
4
|
import { createClient } from "@lastbrain/ai-ui-core";
|
|
5
5
|
import { getUserModels } from "../utils/modelManagement";
|
|
6
|
+
import { useLB } from "./LBAuthProvider";
|
|
6
7
|
const AiContext = createContext(undefined);
|
|
7
8
|
export function AiProvider({ baseUrl, apiKeyId, uiMode = "modal", children, }) {
|
|
9
|
+
let lbStatus;
|
|
10
|
+
let lbSelectedKeyId;
|
|
11
|
+
try {
|
|
12
|
+
const lb = useLB();
|
|
13
|
+
lbStatus = lb.status;
|
|
14
|
+
lbSelectedKeyId = lb.selectedKey?.id;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
lbStatus = undefined;
|
|
18
|
+
lbSelectedKeyId = undefined;
|
|
19
|
+
}
|
|
8
20
|
const [providers, setProviders] = useState([]);
|
|
9
21
|
const [allModels, setAllModels] = useState([]);
|
|
10
22
|
const [availableModels, setAvailableModels] = useState([]);
|
|
@@ -188,6 +200,18 @@ export function AiProvider({ baseUrl, apiKeyId, uiMode = "modal", children, }) {
|
|
|
188
200
|
fetchProviders(); // Fetch providers + available models en même temps
|
|
189
201
|
fetchUserModels();
|
|
190
202
|
}, [fetchProviders, fetchUserModels]);
|
|
203
|
+
// Après authentification (ex: lb_session), forcer un refetch propre des modèles.
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (lbStatus !== "ready") {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
hasFetchedProviders.current = false;
|
|
209
|
+
hasFetchedUserModels.current = false;
|
|
210
|
+
providersAvailable.current = true;
|
|
211
|
+
userModelsAvailable.current = true;
|
|
212
|
+
fetchProviders();
|
|
213
|
+
fetchUserModels();
|
|
214
|
+
}, [lbStatus, lbSelectedKeyId, fetchProviders, fetchUserModels]);
|
|
191
215
|
// Helpers pour filtrer les modèles par type
|
|
192
216
|
const getModelsByType = useCallback((type) => {
|
|
193
217
|
const filtered = allModels.filter((model) => model.type === type);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lastbrain/ai-ui-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.67",
|
|
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.
|
|
51
|
+
"@lastbrain/ai-ui-core": "1.0.51"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/react": "^19.2.0",
|
|
@@ -13,6 +13,7 @@ import type { UiMode } from "../types";
|
|
|
13
13
|
import type { ModelRef } from "@lastbrain/ai-ui-core";
|
|
14
14
|
import { createClient } from "@lastbrain/ai-ui-core";
|
|
15
15
|
import { getUserModels } from "../utils/modelManagement";
|
|
16
|
+
import { useLB } from "./LBAuthProvider";
|
|
16
17
|
|
|
17
18
|
export interface AIModel {
|
|
18
19
|
id: string;
|
|
@@ -70,6 +71,17 @@ export function AiProvider({
|
|
|
70
71
|
uiMode = "modal",
|
|
71
72
|
children,
|
|
72
73
|
}: AiProviderProps) {
|
|
74
|
+
let lbStatus: string | undefined;
|
|
75
|
+
let lbSelectedKeyId: string | undefined;
|
|
76
|
+
try {
|
|
77
|
+
const lb = useLB();
|
|
78
|
+
lbStatus = lb.status;
|
|
79
|
+
lbSelectedKeyId = lb.selectedKey?.id;
|
|
80
|
+
} catch {
|
|
81
|
+
lbStatus = undefined;
|
|
82
|
+
lbSelectedKeyId = undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
73
85
|
const [providers, setProviders] = useState<ProviderData[]>([]);
|
|
74
86
|
const [allModels, setAllModels] = useState<ModelRef[]>([]);
|
|
75
87
|
const [availableModels, setAvailableModels] = useState<AIModel[]>([]);
|
|
@@ -289,6 +301,21 @@ export function AiProvider({
|
|
|
289
301
|
fetchUserModels();
|
|
290
302
|
}, [fetchProviders, fetchUserModels]);
|
|
291
303
|
|
|
304
|
+
// Après authentification (ex: lb_session), forcer un refetch propre des modèles.
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
if (lbStatus !== "ready") {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
hasFetchedProviders.current = false;
|
|
311
|
+
hasFetchedUserModels.current = false;
|
|
312
|
+
providersAvailable.current = true;
|
|
313
|
+
userModelsAvailable.current = true;
|
|
314
|
+
|
|
315
|
+
fetchProviders();
|
|
316
|
+
fetchUserModels();
|
|
317
|
+
}, [lbStatus, lbSelectedKeyId, fetchProviders, fetchUserModels]);
|
|
318
|
+
|
|
292
319
|
// Helpers pour filtrer les modèles par type
|
|
293
320
|
const getModelsByType = useCallback(
|
|
294
321
|
(type: "text" | "language" | "image" | "embed") => {
|