@lastbrain/ai-ui-react 1.0.19 → 1.0.22
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/AiPromptPanel.d.ts.map +1 -1
- package/dist/components/AiPromptPanel.js +2 -2
- package/dist/hooks/useAiClient.d.ts.map +1 -1
- package/dist/hooks/useAiClient.js +8 -0
- package/dist/hooks/useModelManagement.d.ts.map +1 -1
- package/dist/hooks/useModelManagement.js +2 -1
- package/dist/hooks/usePrompts.d.ts.map +1 -1
- package/dist/hooks/usePrompts.js +70 -14
- package/dist/utils/modelManagement.d.ts.map +1 -1
- package/dist/utils/modelManagement.js +27 -11
- package/package.json +1 -1
- package/src/components/AiPromptPanel.tsx +2 -0
- package/src/hooks/useAiClient.ts +9 -0
- package/src/hooks/useModelManagement.ts +2 -1
- package/src/hooks/usePrompts.ts +78 -14
- package/src/utils/modelManagement.ts +40 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiPromptPanel.d.ts","sourceRoot":"","sources":["../../src/components/AiPromptPanel.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAOvC,OAAO,EAAsB,KAAK,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAE/E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE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,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,IAAI,CAAC;IAExB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EAAE,OAAiB,EACzB,MAAW,EACX,UAAU,EACV,QAAQ,EACR,qBAA6B,EAC7B,eAAoB,EACpB,UAAe,EACf,aAAa,EACb,MAAM,EACN,OAAO,GACR,EAAE,kBAAkB,kDAupCpB"}
|
|
@@ -289,7 +289,7 @@ export function AiPromptPanel({ isOpen, onClose, onSubmit, uiMode: _uiMode = "mo
|
|
|
289
289
|
color: "white",
|
|
290
290
|
borderRadius: "10px",
|
|
291
291
|
}, children: ["+", effectiveAvailableModels.filter((m) => m.category === "text" &&
|
|
292
|
-
!effectiveUserModels.includes(m.id)).length] }))] })),
|
|
292
|
+
!effectiveUserModels.includes(m.id)).length] }))] })), _jsxs("button", { onClick: () => setIsModelManagementOpen(true), style: {
|
|
293
293
|
padding: "4px 8px",
|
|
294
294
|
fontSize: "12px",
|
|
295
295
|
color: "#8b5cf6",
|
|
@@ -305,7 +305,7 @@ export function AiPromptPanel({ isOpen, onClose, onSubmit, uiMode: _uiMode = "mo
|
|
|
305
305
|
e.currentTarget.style.background = "#8b5cf620";
|
|
306
306
|
}, onMouseLeave: (e) => {
|
|
307
307
|
e.currentTarget.style.background = "#8b5cf610";
|
|
308
|
-
}, children: _jsx(Settings, { size: 12 }) })] })] }), _jsxs("select", { id: "model-select", value: activeModelId, onChange: (e) => setSelectedModel(e.target.value), onFocus: () => setModelFocused(true), onBlur: () => setModelFocused(false), style: {
|
|
308
|
+
}, title: "G\u00E9rer les mod\u00E8les", children: [_jsx(Settings, { size: 12 }), "G\u00E9rer"] })] })] }), _jsxs("select", { id: "model-select", value: activeModelId, onChange: (e) => setSelectedModel(e.target.value), onFocus: () => setModelFocused(true), onBlur: () => setModelFocused(false), style: {
|
|
309
309
|
...aiStyles.select,
|
|
310
310
|
...(modelFocused && aiStyles.selectFocus),
|
|
311
311
|
}, children: [getFilteredModels().length === 0 && (_jsx("option", { value: "", children: "Loading models..." })), getFilteredModels().map((model) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAiClient.d.ts","sourceRoot":"","sources":["../../src/hooks/useAiClient.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB;;;;;;
|
|
1
|
+
{"version":3,"file":"useAiClient.d.ts","sourceRoot":"","sources":["../../src/hooks/useAiClient.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB;;;;;;EAoBvD"}
|
|
@@ -7,6 +7,14 @@ export function useAiClient(options) {
|
|
|
7
7
|
const client = useMemo(() => {
|
|
8
8
|
const baseUrl = options?.baseUrl || context.baseUrl;
|
|
9
9
|
const apiKeyId = options?.apiKeyId || context.apiKeyId;
|
|
10
|
+
console.log("[useAiClient] Creating client with:", {
|
|
11
|
+
contextBaseUrl: context.baseUrl,
|
|
12
|
+
contextApiKeyId: context.apiKeyId,
|
|
13
|
+
optionsBaseUrl: options?.baseUrl,
|
|
14
|
+
optionsApiKeyId: options?.apiKeyId,
|
|
15
|
+
finalBaseUrl: baseUrl,
|
|
16
|
+
finalApiKeyId: apiKeyId,
|
|
17
|
+
});
|
|
10
18
|
return createClient({ baseUrl, apiKeyId });
|
|
11
19
|
}, [options?.baseUrl, options?.apiKeyId, context.baseUrl, context.apiKeyId]);
|
|
12
20
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModelManagement.d.ts","sourceRoot":"","sources":["../../src/hooks/useModelManagement.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAElC,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,yBAA0B,SAAQ,kBAAkB;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;CACjD;AAED,MAAM,WAAW,wBAAwB;IAEvC,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,K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OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAGrB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAGvC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,eAAe,EAAE,MAAM,OAAO,EAAE,CAAC;IACjC,iBAAiB,EAAE,MAAM,OAAO,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,wBAAwB,CAwL1B"}
|
|
@@ -113,7 +113,8 @@ export function useModelManagement(options = {}) {
|
|
|
113
113
|
}, [availableModels, userModels]);
|
|
114
114
|
// Auto-fetch au mount - si autoFetch ET (apiKey OU baseUrl avec proxy externe)
|
|
115
115
|
useEffect(() => {
|
|
116
|
-
const isExternalProxy = effectiveOptions.baseUrl &&
|
|
116
|
+
const isExternalProxy = effectiveOptions.baseUrl &&
|
|
117
|
+
effectiveOptions.baseUrl.includes("/api/lastbrain");
|
|
117
118
|
console.log("[useModelManagement] useEffect triggered:", {
|
|
118
119
|
autoFetch,
|
|
119
120
|
hasApiKey: !!effectiveOptions.apiKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrompts.d.ts","sourceRoot":"","sources":["../../src/hooks/usePrompts.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,SAAS,EAAE,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AC,CAAC;IAC5B,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5E,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,aAAa,EAAE,CACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,wBAAgB,UAAU,IAAI,gBAAgB,CAgP7C"}
|
package/dist/hooks/usePrompts.js
CHANGED
|
@@ -15,22 +15,42 @@ export function usePrompts() {
|
|
|
15
15
|
params.append("type", options.type);
|
|
16
16
|
if (options?.favorite !== undefined)
|
|
17
17
|
params.append("favorite", String(options.favorite));
|
|
18
|
-
// Déterminer
|
|
18
|
+
// Déterminer le contexte:
|
|
19
|
+
// - isExternalProxy: app externe via proxy /api/lastbrain
|
|
20
|
+
// - isPublicApi: app consommatrice avec API key via /api/public/v1
|
|
21
|
+
// - isAuthInternal: app interne avec session via /api/ai/auth
|
|
19
22
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
23
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
20
24
|
// Use public route without auth if public=true, otherwise use auth route
|
|
21
25
|
let endpoint;
|
|
22
26
|
if (options?.public) {
|
|
23
27
|
endpoint = isExternalProxy
|
|
24
28
|
? `${baseUrl}/ai/public/prompts?${params}`
|
|
25
|
-
:
|
|
29
|
+
: isPublicApi
|
|
30
|
+
? `${baseUrl}/prompts?${params}`
|
|
31
|
+
: baseUrl
|
|
32
|
+
? `${baseUrl}/public/prompts?${params}`
|
|
33
|
+
: `/api/ai/public/prompts?${params}`;
|
|
26
34
|
}
|
|
27
35
|
else {
|
|
28
36
|
endpoint = isExternalProxy
|
|
29
37
|
? `${baseUrl}/ai/auth/prompts?${params}`
|
|
30
|
-
:
|
|
38
|
+
: isPublicApi
|
|
39
|
+
? `${baseUrl}/prompts?${params}`
|
|
40
|
+
: baseUrl
|
|
41
|
+
? `${baseUrl}/auth/prompts?${params}`
|
|
42
|
+
: `/api/ai/auth/prompts?${params}`;
|
|
31
43
|
}
|
|
32
44
|
console.log("[usePrompts] Fetching prompts from:", endpoint);
|
|
33
|
-
const
|
|
45
|
+
const headers = {};
|
|
46
|
+
// Ajouter l'API key pour les appels publics directs (pas de proxy externe ni auth interne)
|
|
47
|
+
if (isPublicApi && apiKeyId) {
|
|
48
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
49
|
+
}
|
|
50
|
+
const response = await fetch(endpoint, {
|
|
51
|
+
headers,
|
|
52
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
53
|
+
});
|
|
34
54
|
const data = await response.json();
|
|
35
55
|
if (response.ok) {
|
|
36
56
|
setPrompts(data.prompts || []);
|
|
@@ -53,10 +73,15 @@ export function usePrompts() {
|
|
|
53
73
|
const endpoint = isExternalProxy
|
|
54
74
|
? `${baseUrl}/ai/auth/prompts`
|
|
55
75
|
: "/api/ai/auth/prompts";
|
|
76
|
+
const headers = { "Content-Type": "application/json" };
|
|
77
|
+
if (!isExternalProxy && apiKeyId) {
|
|
78
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
79
|
+
}
|
|
56
80
|
const response = await fetch(endpoint, {
|
|
57
81
|
method: "POST",
|
|
58
|
-
headers
|
|
82
|
+
headers,
|
|
59
83
|
body: JSON.stringify(data),
|
|
84
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
60
85
|
});
|
|
61
86
|
const result = await response.json();
|
|
62
87
|
if (response.ok) {
|
|
@@ -71,18 +96,28 @@ export function usePrompts() {
|
|
|
71
96
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
72
97
|
return null;
|
|
73
98
|
}
|
|
74
|
-
}, [baseUrl]);
|
|
99
|
+
}, [baseUrl, apiKeyId]);
|
|
75
100
|
const updatePrompt = useCallback(async (id, data) => {
|
|
76
101
|
try {
|
|
77
102
|
setError(null);
|
|
78
103
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
104
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
79
105
|
const endpoint = isExternalProxy
|
|
80
106
|
? `${baseUrl}/ai/auth/prompts`
|
|
81
|
-
:
|
|
107
|
+
: isPublicApi
|
|
108
|
+
? `${baseUrl}/prompts`
|
|
109
|
+
: baseUrl
|
|
110
|
+
? `${baseUrl}/auth/prompts`
|
|
111
|
+
: "/api/ai/auth/prompts";
|
|
112
|
+
const headers = { "Content-Type": "application/json" };
|
|
113
|
+
if (isPublicApi && apiKeyId) {
|
|
114
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
115
|
+
}
|
|
82
116
|
const response = await fetch(endpoint, {
|
|
83
117
|
method: "PUT",
|
|
84
|
-
headers
|
|
118
|
+
headers,
|
|
85
119
|
body: JSON.stringify({ id, ...data }),
|
|
120
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
86
121
|
});
|
|
87
122
|
const result = await response.json();
|
|
88
123
|
if (response.ok) {
|
|
@@ -97,16 +132,27 @@ export function usePrompts() {
|
|
|
97
132
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
98
133
|
return null;
|
|
99
134
|
}
|
|
100
|
-
}, [baseUrl]);
|
|
135
|
+
}, [baseUrl, apiKeyId]);
|
|
101
136
|
const deletePrompt = useCallback(async (id) => {
|
|
102
137
|
try {
|
|
103
138
|
setError(null);
|
|
104
139
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
140
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
105
141
|
const endpoint = isExternalProxy
|
|
106
142
|
? `${baseUrl}/ai/auth/prompts?id=${id}`
|
|
107
|
-
:
|
|
143
|
+
: isPublicApi
|
|
144
|
+
? `${baseUrl}/prompts?id=${id}`
|
|
145
|
+
: baseUrl
|
|
146
|
+
? `${baseUrl}/auth/prompts?id=${id}`
|
|
147
|
+
: `/api/ai/auth/prompts?id=${id}`;
|
|
148
|
+
const headers = {};
|
|
149
|
+
if (isPublicApi && apiKeyId) {
|
|
150
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
151
|
+
}
|
|
108
152
|
const response = await fetch(endpoint, {
|
|
109
153
|
method: "DELETE",
|
|
154
|
+
headers,
|
|
155
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
110
156
|
});
|
|
111
157
|
const result = await response.json();
|
|
112
158
|
if (response.ok) {
|
|
@@ -121,23 +167,33 @@ export function usePrompts() {
|
|
|
121
167
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
122
168
|
return false;
|
|
123
169
|
}
|
|
124
|
-
}, [baseUrl]);
|
|
170
|
+
}, [baseUrl, apiKeyId]);
|
|
125
171
|
const incrementStat = useCallback(async (promptId, statType) => {
|
|
126
172
|
try {
|
|
127
173
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
174
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
128
175
|
const endpoint = isExternalProxy
|
|
129
176
|
? `${baseUrl}/ai/auth/prompts/stats`
|
|
130
|
-
:
|
|
177
|
+
: isPublicApi
|
|
178
|
+
? `${baseUrl}/prompts/stats`
|
|
179
|
+
: baseUrl
|
|
180
|
+
? `${baseUrl}/auth/prompts/stats`
|
|
181
|
+
: "/api/ai/auth/prompts/stats";
|
|
182
|
+
const headers = { "Content-Type": "application/json" };
|
|
183
|
+
if (isPublicApi && apiKeyId) {
|
|
184
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
185
|
+
}
|
|
131
186
|
await fetch(endpoint, {
|
|
132
187
|
method: "POST",
|
|
133
|
-
headers
|
|
188
|
+
headers,
|
|
134
189
|
body: JSON.stringify({ prompt_id: promptId, stat_type: statType }),
|
|
190
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
135
191
|
});
|
|
136
192
|
}
|
|
137
193
|
catch (err) {
|
|
138
194
|
// Silent fail for stats
|
|
139
195
|
}
|
|
140
|
-
}, [baseUrl]);
|
|
196
|
+
}, [baseUrl, apiKeyId]);
|
|
141
197
|
return {
|
|
142
198
|
prompts,
|
|
143
199
|
loading,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelManagement.d.ts","sourceRoot":"","sources":["../../src/utils/modelManagement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"modelManagement.d.ts","sourceRoot":"","sources":["../../src/utils/modelManagement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAiCf;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CACR,KAAK,CAAC;IACJ,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,CAAC,CACH,CA6CA;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,MAAM,EAAE,CAAC,CA6CnB"}
|
|
@@ -13,7 +13,13 @@ export async function toggleUserModel(modelId, isActive, options = {}) {
|
|
|
13
13
|
if (apiKey) {
|
|
14
14
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
17
|
+
const endpoint = isPublicApi
|
|
18
|
+
? `${baseUrl}/ai/user/models/toggle`
|
|
19
|
+
: baseUrl
|
|
20
|
+
? `${baseUrl}/auth/ai-models-toggle`
|
|
21
|
+
: `/api/ai/auth/ai-models-toggle`;
|
|
22
|
+
const response = await fetch(endpoint, {
|
|
17
23
|
method: "PUT",
|
|
18
24
|
headers,
|
|
19
25
|
body: JSON.stringify({
|
|
@@ -31,15 +37,20 @@ export async function toggleUserModel(modelId, isActive, options = {}) {
|
|
|
31
37
|
*/
|
|
32
38
|
export async function getAvailableModels(options = {}) {
|
|
33
39
|
const { apiKey, baseUrl = "" } = options;
|
|
34
|
-
// Déterminer
|
|
40
|
+
// Déterminer le contexte
|
|
35
41
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
42
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
36
43
|
const endpoint = isExternalProxy
|
|
37
44
|
? `${baseUrl}/ai/auth/ai-models-available` // → /api/lastbrain/ai/auth/ai-models-available
|
|
38
|
-
:
|
|
39
|
-
|
|
45
|
+
: isPublicApi
|
|
46
|
+
? `${baseUrl}/ai/models/available` // → /api/public/v1/ai/models/available
|
|
47
|
+
: baseUrl
|
|
48
|
+
? `${baseUrl}/auth/ai-models-available` // → /api/ai/auth/ai-models-available
|
|
49
|
+
: `/api/ai/auth/ai-models-available`; // fallback
|
|
50
|
+
console.log("[getAvailableModels] isExternalProxy:", isExternalProxy, "isPublicApi:", isPublicApi, "endpoint:", endpoint);
|
|
40
51
|
const headers = {};
|
|
41
|
-
// Ajouter la clé API
|
|
42
|
-
if (
|
|
52
|
+
// Ajouter la clé API pour les appels publics directs
|
|
53
|
+
if (isPublicApi && apiKey) {
|
|
43
54
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
44
55
|
}
|
|
45
56
|
const response = await fetch(endpoint, {
|
|
@@ -58,15 +69,20 @@ export async function getAvailableModels(options = {}) {
|
|
|
58
69
|
*/
|
|
59
70
|
export async function getUserModels(options = {}) {
|
|
60
71
|
const { apiKey, baseUrl = "" } = options;
|
|
61
|
-
// Déterminer
|
|
72
|
+
// Déterminer le contexte
|
|
62
73
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
74
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
63
75
|
const endpoint = isExternalProxy
|
|
64
76
|
? `${baseUrl}/ai/auth/user-models` // → /api/lastbrain/ai/auth/user-models
|
|
65
|
-
:
|
|
66
|
-
|
|
77
|
+
: isPublicApi
|
|
78
|
+
? `${baseUrl}/ai/user/models` // → /api/public/v1/ai/user/models
|
|
79
|
+
: baseUrl
|
|
80
|
+
? `${baseUrl}/auth/user-models` // → /api/ai/auth/user-models
|
|
81
|
+
: `/api/ai/auth/user-models`; // fallback
|
|
82
|
+
console.log("[getUserModels] isExternalProxy:", isExternalProxy, "isPublicApi:", isPublicApi, "endpoint:", endpoint);
|
|
67
83
|
const headers = {};
|
|
68
|
-
// Ajouter la clé API
|
|
69
|
-
if (
|
|
84
|
+
// Ajouter la clé API pour les appels publics directs
|
|
85
|
+
if (isPublicApi && apiKey) {
|
|
70
86
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
71
87
|
}
|
|
72
88
|
const response = await fetch(endpoint, {
|
package/package.json
CHANGED
package/src/hooks/useAiClient.ts
CHANGED
|
@@ -16,6 +16,15 @@ export function useAiClient(options?: UseAiClientOptions) {
|
|
|
16
16
|
const baseUrl = options?.baseUrl || context.baseUrl;
|
|
17
17
|
const apiKeyId = options?.apiKeyId || context.apiKeyId;
|
|
18
18
|
|
|
19
|
+
console.log("[useAiClient] Creating client with:", {
|
|
20
|
+
contextBaseUrl: context.baseUrl,
|
|
21
|
+
contextApiKeyId: context.apiKeyId,
|
|
22
|
+
optionsBaseUrl: options?.baseUrl,
|
|
23
|
+
optionsApiKeyId: options?.apiKeyId,
|
|
24
|
+
finalBaseUrl: baseUrl,
|
|
25
|
+
finalApiKeyId: apiKeyId,
|
|
26
|
+
});
|
|
27
|
+
|
|
19
28
|
return createClient({ baseUrl, apiKeyId });
|
|
20
29
|
}, [options?.baseUrl, options?.apiKeyId, context.baseUrl, context.apiKeyId]);
|
|
21
30
|
|
|
@@ -187,7 +187,8 @@ export function useModelManagement(
|
|
|
187
187
|
// Auto-fetch au mount - si autoFetch ET (apiKey OU baseUrl avec proxy externe)
|
|
188
188
|
useEffect(() => {
|
|
189
189
|
const isExternalProxy =
|
|
190
|
-
effectiveOptions.baseUrl &&
|
|
190
|
+
effectiveOptions.baseUrl &&
|
|
191
|
+
effectiveOptions.baseUrl.includes("/api/lastbrain");
|
|
191
192
|
|
|
192
193
|
console.log("[useModelManagement] useEffect triggered:", {
|
|
193
194
|
autoFetch,
|
package/src/hooks/usePrompts.ts
CHANGED
|
@@ -63,24 +63,45 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
63
63
|
if (options?.favorite !== undefined)
|
|
64
64
|
params.append("favorite", String(options.favorite));
|
|
65
65
|
|
|
66
|
-
// Déterminer
|
|
66
|
+
// Déterminer le contexte:
|
|
67
|
+
// - isExternalProxy: app externe via proxy /api/lastbrain
|
|
68
|
+
// - isPublicApi: app consommatrice avec API key via /api/public/v1
|
|
69
|
+
// - isAuthInternal: app interne avec session via /api/ai/auth
|
|
67
70
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
71
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
68
72
|
|
|
69
73
|
// Use public route without auth if public=true, otherwise use auth route
|
|
70
74
|
let endpoint: string;
|
|
71
75
|
if (options?.public) {
|
|
72
76
|
endpoint = isExternalProxy
|
|
73
77
|
? `${baseUrl}/ai/public/prompts?${params}`
|
|
74
|
-
:
|
|
78
|
+
: isPublicApi
|
|
79
|
+
? `${baseUrl}/prompts?${params}`
|
|
80
|
+
: baseUrl
|
|
81
|
+
? `${baseUrl}/public/prompts?${params}`
|
|
82
|
+
: `/api/ai/public/prompts?${params}`;
|
|
75
83
|
} else {
|
|
76
84
|
endpoint = isExternalProxy
|
|
77
85
|
? `${baseUrl}/ai/auth/prompts?${params}`
|
|
78
|
-
:
|
|
86
|
+
: isPublicApi
|
|
87
|
+
? `${baseUrl}/prompts?${params}`
|
|
88
|
+
: baseUrl
|
|
89
|
+
? `${baseUrl}/auth/prompts?${params}`
|
|
90
|
+
: `/api/ai/auth/prompts?${params}`;
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
console.log("[usePrompts] Fetching prompts from:", endpoint);
|
|
82
94
|
|
|
83
|
-
const
|
|
95
|
+
const headers: HeadersInit = {};
|
|
96
|
+
// Ajouter l'API key pour les appels publics directs (pas de proxy externe ni auth interne)
|
|
97
|
+
if (isPublicApi && apiKeyId) {
|
|
98
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const response = await fetch(endpoint, {
|
|
102
|
+
headers,
|
|
103
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
104
|
+
});
|
|
84
105
|
|
|
85
106
|
const data = await response.json();
|
|
86
107
|
|
|
@@ -108,10 +129,16 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
108
129
|
? `${baseUrl}/ai/auth/prompts`
|
|
109
130
|
: "/api/ai/auth/prompts";
|
|
110
131
|
|
|
132
|
+
const headers: HeadersInit = { "Content-Type": "application/json" };
|
|
133
|
+
if (!isExternalProxy && apiKeyId) {
|
|
134
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
111
137
|
const response = await fetch(endpoint, {
|
|
112
138
|
method: "POST",
|
|
113
|
-
headers
|
|
139
|
+
headers,
|
|
114
140
|
body: JSON.stringify(data),
|
|
141
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
115
142
|
});
|
|
116
143
|
|
|
117
144
|
const result = await response.json();
|
|
@@ -127,7 +154,7 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
127
154
|
return null;
|
|
128
155
|
}
|
|
129
156
|
},
|
|
130
|
-
[baseUrl]
|
|
157
|
+
[baseUrl, apiKeyId]
|
|
131
158
|
);
|
|
132
159
|
|
|
133
160
|
const updatePrompt = useCallback(
|
|
@@ -136,14 +163,26 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
136
163
|
setError(null);
|
|
137
164
|
|
|
138
165
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
166
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
167
|
+
|
|
139
168
|
const endpoint = isExternalProxy
|
|
140
169
|
? `${baseUrl}/ai/auth/prompts`
|
|
141
|
-
:
|
|
170
|
+
: isPublicApi
|
|
171
|
+
? `${baseUrl}/prompts`
|
|
172
|
+
: baseUrl
|
|
173
|
+
? `${baseUrl}/auth/prompts`
|
|
174
|
+
: "/api/ai/auth/prompts";
|
|
175
|
+
|
|
176
|
+
const headers: HeadersInit = { "Content-Type": "application/json" };
|
|
177
|
+
if (isPublicApi && apiKeyId) {
|
|
178
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
179
|
+
}
|
|
142
180
|
|
|
143
181
|
const response = await fetch(endpoint, {
|
|
144
182
|
method: "PUT",
|
|
145
|
-
headers
|
|
183
|
+
headers,
|
|
146
184
|
body: JSON.stringify({ id, ...data }),
|
|
185
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
147
186
|
});
|
|
148
187
|
|
|
149
188
|
const result = await response.json();
|
|
@@ -159,7 +198,7 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
159
198
|
return null;
|
|
160
199
|
}
|
|
161
200
|
},
|
|
162
|
-
[baseUrl]
|
|
201
|
+
[baseUrl, apiKeyId]
|
|
163
202
|
);
|
|
164
203
|
|
|
165
204
|
const deletePrompt = useCallback(
|
|
@@ -168,12 +207,25 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
168
207
|
setError(null);
|
|
169
208
|
|
|
170
209
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
210
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
211
|
+
|
|
171
212
|
const endpoint = isExternalProxy
|
|
172
213
|
? `${baseUrl}/ai/auth/prompts?id=${id}`
|
|
173
|
-
:
|
|
214
|
+
: isPublicApi
|
|
215
|
+
? `${baseUrl}/prompts?id=${id}`
|
|
216
|
+
: baseUrl
|
|
217
|
+
? `${baseUrl}/auth/prompts?id=${id}`
|
|
218
|
+
: `/api/ai/auth/prompts?id=${id}`;
|
|
219
|
+
|
|
220
|
+
const headers: HeadersInit = {};
|
|
221
|
+
if (isPublicApi && apiKeyId) {
|
|
222
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
223
|
+
}
|
|
174
224
|
|
|
175
225
|
const response = await fetch(endpoint, {
|
|
176
226
|
method: "DELETE",
|
|
227
|
+
headers,
|
|
228
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
177
229
|
});
|
|
178
230
|
|
|
179
231
|
const result = await response.json();
|
|
@@ -189,27 +241,39 @@ export function usePrompts(): UsePromptsReturn {
|
|
|
189
241
|
return false;
|
|
190
242
|
}
|
|
191
243
|
},
|
|
192
|
-
[baseUrl]
|
|
244
|
+
[baseUrl, apiKeyId]
|
|
193
245
|
);
|
|
194
246
|
|
|
195
247
|
const incrementStat = useCallback(
|
|
196
248
|
async (promptId: string, statType: "views" | "used" | "picked") => {
|
|
197
249
|
try {
|
|
198
250
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
251
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
252
|
+
|
|
199
253
|
const endpoint = isExternalProxy
|
|
200
254
|
? `${baseUrl}/ai/auth/prompts/stats`
|
|
201
|
-
:
|
|
255
|
+
: isPublicApi
|
|
256
|
+
? `${baseUrl}/prompts/stats`
|
|
257
|
+
: baseUrl
|
|
258
|
+
? `${baseUrl}/auth/prompts/stats`
|
|
259
|
+
: "/api/ai/auth/prompts/stats";
|
|
260
|
+
|
|
261
|
+
const headers: HeadersInit = { "Content-Type": "application/json" };
|
|
262
|
+
if (isPublicApi && apiKeyId) {
|
|
263
|
+
headers["Authorization"] = `Bearer ${apiKeyId}`;
|
|
264
|
+
}
|
|
202
265
|
|
|
203
266
|
await fetch(endpoint, {
|
|
204
267
|
method: "POST",
|
|
205
|
-
headers
|
|
268
|
+
headers,
|
|
206
269
|
body: JSON.stringify({ prompt_id: promptId, stat_type: statType }),
|
|
270
|
+
credentials: isExternalProxy ? "include" : "same-origin",
|
|
207
271
|
});
|
|
208
272
|
} catch (err) {
|
|
209
273
|
// Silent fail for stats
|
|
210
274
|
}
|
|
211
275
|
},
|
|
212
|
-
[baseUrl]
|
|
276
|
+
[baseUrl, apiKeyId]
|
|
213
277
|
);
|
|
214
278
|
|
|
215
279
|
return {
|
|
@@ -26,17 +26,22 @@ export async function toggleUserModel(
|
|
|
26
26
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
30
|
+
|
|
31
|
+
const endpoint = isPublicApi
|
|
32
|
+
? `${baseUrl}/ai/user/models/toggle`
|
|
33
|
+
: baseUrl
|
|
34
|
+
? `${baseUrl}/auth/ai-models-toggle`
|
|
35
|
+
: `/api/ai/auth/ai-models-toggle`;
|
|
36
|
+
|
|
37
|
+
const response = await fetch(endpoint, {
|
|
38
|
+
method: "PUT",
|
|
39
|
+
headers,
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
model_id: modelId,
|
|
42
|
+
is_active: isActive,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
40
45
|
|
|
41
46
|
if (!response.ok) {
|
|
42
47
|
const error = await response.text();
|
|
@@ -63,23 +68,31 @@ export async function getAvailableModels(
|
|
|
63
68
|
> {
|
|
64
69
|
const { apiKey, baseUrl = "" } = options;
|
|
65
70
|
|
|
66
|
-
// Déterminer
|
|
71
|
+
// Déterminer le contexte
|
|
67
72
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
73
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
74
|
+
|
|
68
75
|
const endpoint = isExternalProxy
|
|
69
76
|
? `${baseUrl}/ai/auth/ai-models-available` // → /api/lastbrain/ai/auth/ai-models-available
|
|
70
|
-
:
|
|
77
|
+
: isPublicApi
|
|
78
|
+
? `${baseUrl}/ai/models/available` // → /api/public/v1/ai/models/available
|
|
79
|
+
: baseUrl
|
|
80
|
+
? `${baseUrl}/auth/ai-models-available` // → /api/ai/auth/ai-models-available
|
|
81
|
+
: `/api/ai/auth/ai-models-available`; // fallback
|
|
71
82
|
|
|
72
83
|
console.log(
|
|
73
84
|
"[getAvailableModels] isExternalProxy:",
|
|
74
85
|
isExternalProxy,
|
|
86
|
+
"isPublicApi:",
|
|
87
|
+
isPublicApi,
|
|
75
88
|
"endpoint:",
|
|
76
89
|
endpoint
|
|
77
90
|
);
|
|
78
91
|
|
|
79
92
|
const headers: Record<string, string> = {};
|
|
80
93
|
|
|
81
|
-
// Ajouter la clé API
|
|
82
|
-
if (
|
|
94
|
+
// Ajouter la clé API pour les appels publics directs
|
|
95
|
+
if (isPublicApi && apiKey) {
|
|
83
96
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
84
97
|
}
|
|
85
98
|
|
|
@@ -107,23 +120,31 @@ export async function getUserModels(
|
|
|
107
120
|
): Promise<string[]> {
|
|
108
121
|
const { apiKey, baseUrl = "" } = options;
|
|
109
122
|
|
|
110
|
-
// Déterminer
|
|
123
|
+
// Déterminer le contexte
|
|
111
124
|
const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
|
|
125
|
+
const isPublicApi = baseUrl && baseUrl.includes("/api/public/v1");
|
|
126
|
+
|
|
112
127
|
const endpoint = isExternalProxy
|
|
113
128
|
? `${baseUrl}/ai/auth/user-models` // → /api/lastbrain/ai/auth/user-models
|
|
114
|
-
:
|
|
129
|
+
: isPublicApi
|
|
130
|
+
? `${baseUrl}/ai/user/models` // → /api/public/v1/ai/user/models
|
|
131
|
+
: baseUrl
|
|
132
|
+
? `${baseUrl}/auth/user-models` // → /api/ai/auth/user-models
|
|
133
|
+
: `/api/ai/auth/user-models`; // fallback
|
|
115
134
|
|
|
116
135
|
console.log(
|
|
117
136
|
"[getUserModels] isExternalProxy:",
|
|
118
137
|
isExternalProxy,
|
|
138
|
+
"isPublicApi:",
|
|
139
|
+
isPublicApi,
|
|
119
140
|
"endpoint:",
|
|
120
141
|
endpoint
|
|
121
142
|
);
|
|
122
143
|
|
|
123
144
|
const headers: Record<string, string> = {};
|
|
124
145
|
|
|
125
|
-
// Ajouter la clé API
|
|
126
|
-
if (
|
|
146
|
+
// Ajouter la clé API pour les appels publics directs
|
|
147
|
+
if (isPublicApi && apiKey) {
|
|
127
148
|
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
128
149
|
}
|
|
129
150
|
|