@lastbrain/ai-ui-core 1.0.32 → 1.0.34
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":"lb-proxy.d.ts","sourceRoot":"","sources":["../../../src/route-handlers/nextjs/lb-proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,aAAkB;
|
|
1
|
+
{"version":3,"file":"lb-proxy.d.ts","sourceRoot":"","sources":["../../../src/route-handlers/nextjs/lb-proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,aAAkB;mBAiDlD,WAAW,YACV;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE,KACjD,OAAO,CAAC,YAAY,CAAC;oBAFb,WAAW,YACV;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE,KACjD,OAAO,CAAC,YAAY,CAAC;mBAFb,WAAW,YACV;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE,KACjD,OAAO,CAAC,YAAY,CAAC;sBAFb,WAAW,YACV;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE,KACjD,OAAO,CAAC,YAAY,CAAC;qBAFb,WAAW,YACV;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE,KACjD,OAAO,CAAC,YAAY,CAAC;EA0HzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,MAAe,GACzB,YAAY,CAYd;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,CAGzE"}
|
|
@@ -19,11 +19,38 @@ import { NextResponse } from "next/server";
|
|
|
19
19
|
*/
|
|
20
20
|
export function createLBProxyHandler(config = {}) {
|
|
21
21
|
const { baseUrl = process.env.LB_BASE_URL || "https://prompt.lastbrain.io", apiKey = process.env.LB_API_KEY, sessionCookieName = "lb_session", } = config;
|
|
22
|
-
// Déterminer le chemin de base API
|
|
23
|
-
// Si baseUrl contient déjà /api/public/v1, l'utiliser tel quel
|
|
24
|
-
// Sinon, pour les nouvelles routes d'auth, utiliser /api/ai
|
|
22
|
+
// Déterminer le chemin de base API selon le format de baseUrl et le path
|
|
25
23
|
const isLegacyBaseUrl = baseUrl.includes("/api/public/v1");
|
|
26
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Détermine le préfixe API à ajouter selon le path
|
|
26
|
+
* - Routes auth/* : /api/ai/auth/*
|
|
27
|
+
* - Routes ai/* : /api/ai/* (déjà préfixé)
|
|
28
|
+
* - Routes public/* : /api/ai/public/*
|
|
29
|
+
* - Routes status, provider, gateway-models : /api/ai/*
|
|
30
|
+
* - Legacy : pas de préfixe si baseUrl contient déjà /api/public/v1
|
|
31
|
+
*/
|
|
32
|
+
function getApiPrefix(path) {
|
|
33
|
+
if (isLegacyBaseUrl) {
|
|
34
|
+
return ""; // Legacy: baseUrl contient déjà le préfixe
|
|
35
|
+
}
|
|
36
|
+
// Si le path commence déjà par ai/, ne rien ajouter (juste /api/)
|
|
37
|
+
if (path.startsWith("ai/")) {
|
|
38
|
+
return "/api";
|
|
39
|
+
}
|
|
40
|
+
// Routes qui vont directement sous /api/ai/
|
|
41
|
+
const directRoutes = [
|
|
42
|
+
"auth/",
|
|
43
|
+
"public/",
|
|
44
|
+
"status",
|
|
45
|
+
"provider",
|
|
46
|
+
"gateway-models",
|
|
47
|
+
];
|
|
48
|
+
if (directRoutes.some(route => path.startsWith(route) || path === route)) {
|
|
49
|
+
return "/api/ai";
|
|
50
|
+
}
|
|
51
|
+
// Par défaut, utiliser /api/ai
|
|
52
|
+
return "/api/ai";
|
|
53
|
+
}
|
|
27
54
|
/**
|
|
28
55
|
* Handler unique pour toutes les méthodes HTTP et tous les paths
|
|
29
56
|
*/
|
|
@@ -45,12 +72,19 @@ export function createLBProxyHandler(config = {}) {
|
|
|
45
72
|
const publicPaths = [
|
|
46
73
|
"auth/login",
|
|
47
74
|
"auth/session/create",
|
|
75
|
+
"auth/session",
|
|
48
76
|
"public/user/api-keys",
|
|
49
77
|
];
|
|
50
78
|
const isPublicPath = publicPaths.some((p) => path.startsWith(p));
|
|
51
79
|
// Construire l'URL complète vers LastBrain
|
|
52
|
-
|
|
53
|
-
const targetUrl = `${baseUrl}${
|
|
80
|
+
const apiPrefix = getApiPrefix(path);
|
|
81
|
+
const targetUrl = `${baseUrl}${apiPrefix}/${path}`;
|
|
82
|
+
console.log("[LB Proxy] Request:", {
|
|
83
|
+
path,
|
|
84
|
+
apiPrefix,
|
|
85
|
+
targetUrl,
|
|
86
|
+
isLegacy: isLegacyBaseUrl,
|
|
87
|
+
});
|
|
54
88
|
// Préparer les headers
|
|
55
89
|
const headers = {};
|
|
56
90
|
// Copier les headers pertinents de la requête originale
|
package/dist/types/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;CACvC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,YAAY,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,kCAAkC;IAClC,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CA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AC,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,oBAAoB;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -38,11 +38,43 @@ export function createLBProxyHandler(config: LBProxyConfig = {}) {
|
|
|
38
38
|
sessionCookieName = "lb_session",
|
|
39
39
|
} = config;
|
|
40
40
|
|
|
41
|
-
// Déterminer le chemin de base API
|
|
42
|
-
// Si baseUrl contient déjà /api/public/v1, l'utiliser tel quel
|
|
43
|
-
// Sinon, pour les nouvelles routes d'auth, utiliser /api/ai
|
|
41
|
+
// Déterminer le chemin de base API selon le format de baseUrl et le path
|
|
44
42
|
const isLegacyBaseUrl = baseUrl.includes("/api/public/v1");
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Détermine le préfixe API à ajouter selon le path
|
|
46
|
+
* - Routes auth/* : /api/ai/auth/*
|
|
47
|
+
* - Routes ai/* : /api/ai/* (déjà préfixé)
|
|
48
|
+
* - Routes public/* : /api/ai/public/*
|
|
49
|
+
* - Routes status, provider, gateway-models : /api/ai/*
|
|
50
|
+
* - Legacy : pas de préfixe si baseUrl contient déjà /api/public/v1
|
|
51
|
+
*/
|
|
52
|
+
function getApiPrefix(path: string): string {
|
|
53
|
+
if (isLegacyBaseUrl) {
|
|
54
|
+
return ""; // Legacy: baseUrl contient déjà le préfixe
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Si le path commence déjà par ai/, ne rien ajouter (juste /api/)
|
|
58
|
+
if (path.startsWith("ai/")) {
|
|
59
|
+
return "/api";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Routes qui vont directement sous /api/ai/
|
|
63
|
+
const directRoutes = [
|
|
64
|
+
"auth/",
|
|
65
|
+
"public/",
|
|
66
|
+
"status",
|
|
67
|
+
"provider",
|
|
68
|
+
"gateway-models",
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
if (directRoutes.some(route => path.startsWith(route) || path === route)) {
|
|
72
|
+
return "/api/ai";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Par défaut, utiliser /api/ai
|
|
76
|
+
return "/api/ai";
|
|
77
|
+
}
|
|
46
78
|
|
|
47
79
|
/**
|
|
48
80
|
* Handler unique pour toutes les méthodes HTTP et tous les paths
|
|
@@ -68,13 +100,21 @@ export function createLBProxyHandler(config: LBProxyConfig = {}) {
|
|
|
68
100
|
const publicPaths = [
|
|
69
101
|
"auth/login",
|
|
70
102
|
"auth/session/create",
|
|
103
|
+
"auth/session",
|
|
71
104
|
"public/user/api-keys",
|
|
72
105
|
];
|
|
73
106
|
const isPublicPath = publicPaths.some((p) => path.startsWith(p));
|
|
74
107
|
|
|
75
108
|
// Construire l'URL complète vers LastBrain
|
|
76
|
-
|
|
77
|
-
const targetUrl = `${baseUrl}${
|
|
109
|
+
const apiPrefix = getApiPrefix(path);
|
|
110
|
+
const targetUrl = `${baseUrl}${apiPrefix}/${path}`;
|
|
111
|
+
|
|
112
|
+
console.log("[LB Proxy] Request:", {
|
|
113
|
+
path,
|
|
114
|
+
apiPrefix,
|
|
115
|
+
targetUrl,
|
|
116
|
+
isLegacy: isLegacyBaseUrl,
|
|
117
|
+
});
|
|
78
118
|
|
|
79
119
|
// Préparer les headers
|
|
80
120
|
const headers: Record<string, string> = {};
|
package/src/types/auth.ts
CHANGED
|
@@ -85,7 +85,12 @@ export interface LBSessionResult {
|
|
|
85
85
|
/**
|
|
86
86
|
* Statut d'authentification
|
|
87
87
|
*/
|
|
88
|
-
export type LBAuthStatus =
|
|
88
|
+
export type LBAuthStatus =
|
|
89
|
+
| "ready"
|
|
90
|
+
| "needs_auth"
|
|
91
|
+
| "needs_key_selection"
|
|
92
|
+
| "loading"
|
|
93
|
+
| "error";
|
|
89
94
|
|
|
90
95
|
/**
|
|
91
96
|
* État d'authentification complet
|