@lastbrain/ai-ui-react 1.0.12 → 1.0.15

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":"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,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAa,SAAQ,MAAM;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,YAAY,EAAE,CACZ,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,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AC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,YAAY,EAAE,CACZ,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,YAAY,GAAG,YAAY,CAAC,KACnD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,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,CA0K7C"}
@@ -2,7 +2,7 @@
2
2
  import { useState, useCallback } from "react";
3
3
  import { useAiContext } from "../context/AiProvider";
4
4
  export function usePrompts() {
5
- const { apiKeyId } = useAiContext();
5
+ const { apiKeyId, baseUrl } = useAiContext();
6
6
  const [prompts, setPrompts] = useState([]);
7
7
  const [loading, setLoading] = useState(false);
8
8
  const [error, setError] = useState(null);
@@ -15,10 +15,21 @@ 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 si on est dans un contexte externe (proxy nécessaire)
19
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
18
20
  // Use public route without auth if public=true, otherwise use auth route
19
- const endpoint = options?.public
20
- ? `/api/ai/public/prompts?${params}`
21
- : `/api/ai/auth/prompts?${params}`;
21
+ let endpoint;
22
+ if (options?.public) {
23
+ endpoint = isExternalProxy
24
+ ? `${baseUrl}/ai/public/prompts?${params}`
25
+ : `/api/ai/public/prompts?${params}`;
26
+ }
27
+ else {
28
+ endpoint = isExternalProxy
29
+ ? `${baseUrl}/ai/auth/prompts?${params}`
30
+ : `/api/ai/auth/prompts?${params}`;
31
+ }
32
+ console.log("[usePrompts] Fetching prompts from:", endpoint);
22
33
  const response = await fetch(endpoint);
23
34
  const data = await response.json();
24
35
  if (response.ok) {
@@ -34,11 +45,15 @@ export function usePrompts() {
34
45
  finally {
35
46
  setLoading(false);
36
47
  }
37
- }, []);
48
+ }, [baseUrl]);
38
49
  const createPrompt = useCallback(async (data) => {
39
50
  try {
40
51
  setError(null);
41
- const response = await fetch("/api/ai/auth/prompts", {
52
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
53
+ const endpoint = isExternalProxy
54
+ ? `${baseUrl}/ai/auth/prompts`
55
+ : "/api/ai/auth/prompts";
56
+ const response = await fetch(endpoint, {
42
57
  method: "POST",
43
58
  headers: { "Content-Type": "application/json" },
44
59
  body: JSON.stringify(data),
@@ -56,11 +71,15 @@ export function usePrompts() {
56
71
  setError(err instanceof Error ? err.message : "Unknown error");
57
72
  return null;
58
73
  }
59
- }, []);
74
+ }, [baseUrl]);
60
75
  const updatePrompt = useCallback(async (id, data) => {
61
76
  try {
62
77
  setError(null);
63
- const response = await fetch("/api/ai/auth/prompts", {
78
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
79
+ const endpoint = isExternalProxy
80
+ ? `${baseUrl}/ai/auth/prompts`
81
+ : "/api/ai/auth/prompts";
82
+ const response = await fetch(endpoint, {
64
83
  method: "PUT",
65
84
  headers: { "Content-Type": "application/json" },
66
85
  body: JSON.stringify({ id, ...data }),
@@ -78,11 +97,15 @@ export function usePrompts() {
78
97
  setError(err instanceof Error ? err.message : "Unknown error");
79
98
  return null;
80
99
  }
81
- }, []);
100
+ }, [baseUrl]);
82
101
  const deletePrompt = useCallback(async (id) => {
83
102
  try {
84
103
  setError(null);
85
- const response = await fetch(`/api/ai/auth/prompts?id=${id}`, {
104
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
105
+ const endpoint = isExternalProxy
106
+ ? `${baseUrl}/ai/auth/prompts?id=${id}`
107
+ : `/api/ai/auth/prompts?id=${id}`;
108
+ const response = await fetch(endpoint, {
86
109
  method: "DELETE",
87
110
  });
88
111
  const result = await response.json();
@@ -98,10 +121,14 @@ export function usePrompts() {
98
121
  setError(err instanceof Error ? err.message : "Unknown error");
99
122
  return false;
100
123
  }
101
- }, []);
124
+ }, [baseUrl]);
102
125
  const incrementStat = useCallback(async (promptId, statType) => {
103
126
  try {
104
- await fetch("/api/ai/auth/prompts/stats", {
127
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
128
+ const endpoint = isExternalProxy
129
+ ? `${baseUrl}/ai/auth/prompts/stats`
130
+ : "/api/ai/auth/prompts/stats";
131
+ await fetch(endpoint, {
105
132
  method: "POST",
106
133
  headers: { "Content-Type": "application/json" },
107
134
  body: JSON.stringify({ prompt_id: promptId, stat_type: statType }),
@@ -110,7 +137,7 @@ export function usePrompts() {
110
137
  catch (err) {
111
138
  // Silent fail for stats
112
139
  }
113
- }, []);
140
+ }, [baseUrl]);
114
141
  return {
115
142
  prompts,
116
143
  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,EAC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AAC;IAC/C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CACH,CAgCA;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,MAAM,EAAE,CAAC,CAgCnB"}
@@ -31,20 +31,21 @@ export async function toggleUserModel(modelId, isActive, options = {}) {
31
31
  */
32
32
  export async function getAvailableModels(options = {}) {
33
33
  const { apiKey, baseUrl = "" } = options;
34
- // Si baseUrl est fourni (contexte externe), utiliser la route auth qui sera proxifiée
35
- const isExternal = baseUrl && baseUrl !== "";
36
- const endpoint = isExternal
37
- ? `${baseUrl}/ai/auth/ai-models-available`
38
- : `/api/public/v1/ai/models/available`;
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);
39
40
  const headers = {};
40
- // Ajouter la clé API seulement si pas de baseUrl (appel direct)
41
- if (!isExternal && apiKey) {
41
+ // Ajouter la clé API seulement si pas de proxy externe (appel direct)
42
+ if (!isExternalProxy && apiKey) {
42
43
  headers["Authorization"] = `Bearer ${apiKey}`;
43
44
  }
44
45
  const response = await fetch(endpoint, {
45
46
  method: "GET",
46
47
  headers,
47
- credentials: isExternal ? "include" : "same-origin",
48
+ credentials: isExternalProxy ? 'include' : 'same-origin',
48
49
  });
49
50
  if (!response.ok) {
50
51
  throw new Error(`Erreur lors de la récupération des modèles: ${response.status}`);
@@ -57,20 +58,21 @@ export async function getAvailableModels(options = {}) {
57
58
  */
58
59
  export async function getUserModels(options = {}) {
59
60
  const { apiKey, baseUrl = "" } = options;
60
- // Si baseUrl est fourni (contexte externe), utiliser la route auth qui sera proxifiée
61
- const isExternal = baseUrl && baseUrl !== "";
62
- const endpoint = isExternal
63
- ? `${baseUrl}/ai/auth/user-models`
64
- : `/api/public/v1/ai/user/models`;
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);
65
67
  const headers = {};
66
- // Ajouter la clé API seulement si pas de baseUrl (appel direct)
67
- if (!isExternal && apiKey) {
68
+ // Ajouter la clé API seulement si pas de proxy externe (appel direct)
69
+ if (!isExternalProxy && apiKey) {
68
70
  headers["Authorization"] = `Bearer ${apiKey}`;
69
71
  }
70
72
  const response = await fetch(endpoint, {
71
73
  method: "GET",
72
74
  headers,
73
- credentials: isExternal ? "include" : "same-origin",
75
+ credentials: isExternalProxy ? 'include' : 'same-origin',
74
76
  });
75
77
  if (!response.ok) {
76
78
  throw new Error(`Erreur lors de la récupération des modèles utilisateur: ${response.status}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lastbrain/ai-ui-react",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
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.6"
51
+ "@lastbrain/ai-ui-core": "1.0.8"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/react": "^19.2.0",
@@ -47,7 +47,7 @@ export interface UsePromptsReturn {
47
47
  }
48
48
 
49
49
  export function usePrompts(): UsePromptsReturn {
50
- const { apiKeyId } = useAiContext();
50
+ const { apiKeyId, baseUrl } = useAiContext();
51
51
  const [prompts, setPrompts] = useState<Prompt[] | PublicPrompt[]>([]);
52
52
  const [loading, setLoading] = useState(false);
53
53
  const [error, setError] = useState<string | null>(null);
@@ -62,10 +62,22 @@ export function usePrompts(): UsePromptsReturn {
62
62
  if (options?.favorite !== undefined)
63
63
  params.append("favorite", String(options.favorite));
64
64
 
65
+ // Déterminer si on est dans un contexte externe (proxy nécessaire)
66
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
67
+
65
68
  // Use public route without auth if public=true, otherwise use auth route
66
- const endpoint = options?.public
67
- ? `/api/ai/public/prompts?${params}`
68
- : `/api/ai/auth/prompts?${params}`;
69
+ let endpoint: string;
70
+ if (options?.public) {
71
+ endpoint = isExternalProxy
72
+ ? `${baseUrl}/ai/public/prompts?${params}`
73
+ : `/api/ai/public/prompts?${params}`;
74
+ } else {
75
+ endpoint = isExternalProxy
76
+ ? `${baseUrl}/ai/auth/prompts?${params}`
77
+ : `/api/ai/auth/prompts?${params}`;
78
+ }
79
+
80
+ console.log("[usePrompts] Fetching prompts from:", endpoint);
69
81
 
70
82
  const response = await fetch(endpoint);
71
83
 
@@ -81,14 +93,19 @@ export function usePrompts(): UsePromptsReturn {
81
93
  } finally {
82
94
  setLoading(false);
83
95
  }
84
- }, []);
96
+ }, [baseUrl]);
85
97
 
86
98
  const createPrompt = useCallback(
87
99
  async (data: Omit<Prompt, "id" | "created_at" | "updated_at">) => {
88
100
  try {
89
101
  setError(null);
90
102
 
91
- const response = await fetch("/api/ai/auth/prompts", {
103
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
104
+ const endpoint = isExternalProxy
105
+ ? `${baseUrl}/ai/auth/prompts`
106
+ : "/api/ai/auth/prompts";
107
+
108
+ const response = await fetch(endpoint, {
92
109
  method: "POST",
93
110
  headers: { "Content-Type": "application/json" },
94
111
  body: JSON.stringify(data),
@@ -107,7 +124,7 @@ export function usePrompts(): UsePromptsReturn {
107
124
  return null;
108
125
  }
109
126
  },
110
- []
127
+ [baseUrl]
111
128
  );
112
129
 
113
130
  const updatePrompt = useCallback(
@@ -115,7 +132,12 @@ export function usePrompts(): UsePromptsReturn {
115
132
  try {
116
133
  setError(null);
117
134
 
118
- const response = await fetch("/api/ai/auth/prompts", {
135
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
136
+ const endpoint = isExternalProxy
137
+ ? `${baseUrl}/ai/auth/prompts`
138
+ : "/api/ai/auth/prompts";
139
+
140
+ const response = await fetch(endpoint, {
119
141
  method: "PUT",
120
142
  headers: { "Content-Type": "application/json" },
121
143
  body: JSON.stringify({ id, ...data }),
@@ -134,14 +156,19 @@ export function usePrompts(): UsePromptsReturn {
134
156
  return null;
135
157
  }
136
158
  },
137
- []
159
+ [baseUrl]
138
160
  );
139
161
 
140
162
  const deletePrompt = useCallback(async (id: string) => {
141
163
  try {
142
164
  setError(null);
143
165
 
144
- const response = await fetch(`/api/ai/auth/prompts?id=${id}`, {
166
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
167
+ const endpoint = isExternalProxy
168
+ ? `${baseUrl}/ai/auth/prompts?id=${id}`
169
+ : `/api/ai/auth/prompts?id=${id}`;
170
+
171
+ const response = await fetch(endpoint, {
145
172
  method: "DELETE",
146
173
  });
147
174
 
@@ -157,12 +184,17 @@ export function usePrompts(): UsePromptsReturn {
157
184
  setError(err instanceof Error ? err.message : "Unknown error");
158
185
  return false;
159
186
  }
160
- }, []);
187
+ }, [baseUrl]);
161
188
 
162
189
  const incrementStat = useCallback(
163
190
  async (promptId: string, statType: "views" | "used" | "picked") => {
164
191
  try {
165
- await fetch("/api/ai/auth/prompts/stats", {
192
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
193
+ const endpoint = isExternalProxy
194
+ ? `${baseUrl}/ai/auth/prompts/stats`
195
+ : "/api/ai/auth/prompts/stats";
196
+
197
+ await fetch(endpoint, {
166
198
  method: "POST",
167
199
  headers: { "Content-Type": "application/json" },
168
200
  body: JSON.stringify({ prompt_id: promptId, stat_type: statType }),
@@ -171,7 +203,7 @@ export function usePrompts(): UsePromptsReturn {
171
203
  // Silent fail for stats
172
204
  }
173
205
  },
174
- []
206
+ [baseUrl]
175
207
  );
176
208
 
177
209
  return {
@@ -63,23 +63,25 @@ export async function getAvailableModels(
63
63
  > {
64
64
  const { apiKey, baseUrl = "" } = options;
65
65
 
66
- // Si baseUrl est fourni (contexte externe), utiliser la route auth qui sera proxifiée
67
- const isExternal = baseUrl && baseUrl !== "";
68
- const endpoint = isExternal
69
- ? `${baseUrl}/ai/auth/ai-models-available`
70
- : `/api/public/v1/ai/models/available`;
66
+ // Déterminer si on est dans un contexte externe (proxy nécessaire)
67
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
68
+ const endpoint = isExternalProxy
69
+ ? `${baseUrl}/ai/auth/ai-models-available` // → /api/lastbrain/ai/auth/ai-models-available
70
+ : `/api/public/v1/ai/models/available`; // → /api/public/v1/ai/models/available
71
+
72
+ console.log("[getAvailableModels] isExternalProxy:", isExternalProxy, "endpoint:", endpoint);
71
73
 
72
74
  const headers: Record<string, string> = {};
73
75
 
74
- // Ajouter la clé API seulement si pas de baseUrl (appel direct)
75
- if (!isExternal && apiKey) {
76
+ // Ajouter la clé API seulement si pas de proxy externe (appel direct)
77
+ if (!isExternalProxy && apiKey) {
76
78
  headers["Authorization"] = `Bearer ${apiKey}`;
77
79
  }
78
80
 
79
81
  const response = await fetch(endpoint, {
80
82
  method: "GET",
81
83
  headers,
82
- credentials: isExternal ? "include" : "same-origin",
84
+ credentials: isExternalProxy ? 'include' : 'same-origin',
83
85
  });
84
86
 
85
87
  if (!response.ok) {
@@ -100,23 +102,25 @@ export async function getUserModels(
100
102
  ): Promise<string[]> {
101
103
  const { apiKey, baseUrl = "" } = options;
102
104
 
103
- // Si baseUrl est fourni (contexte externe), utiliser la route auth qui sera proxifiée
104
- const isExternal = baseUrl && baseUrl !== "";
105
- const endpoint = isExternal
106
- ? `${baseUrl}/ai/auth/user-models`
107
- : `/api/public/v1/ai/user/models`;
105
+ // Déterminer si on est dans un contexte externe (proxy nécessaire)
106
+ const isExternalProxy = baseUrl && baseUrl.includes("/api/lastbrain");
107
+ const endpoint = isExternalProxy
108
+ ? `${baseUrl}/ai/auth/user-models` // → /api/lastbrain/ai/auth/user-models
109
+ : `/api/public/v1/ai/user/models`; // → /api/public/v1/ai/user/models
110
+
111
+ console.log("[getUserModels] isExternalProxy:", isExternalProxy, "endpoint:", endpoint);
108
112
 
109
113
  const headers: Record<string, string> = {};
110
114
 
111
- // Ajouter la clé API seulement si pas de baseUrl (appel direct)
112
- if (!isExternal && apiKey) {
115
+ // Ajouter la clé API seulement si pas de proxy externe (appel direct)
116
+ if (!isExternalProxy && apiKey) {
113
117
  headers["Authorization"] = `Bearer ${apiKey}`;
114
118
  }
115
119
 
116
120
  const response = await fetch(endpoint, {
117
121
  method: "GET",
118
122
  headers,
119
- credentials: isExternal ? "include" : "same-origin",
123
+ credentials: isExternalProxy ? 'include' : 'same-origin',
120
124
  });
121
125
 
122
126
  if (!response.ok) {