@lastbrain/ai-ui-core 1.0.43 → 1.0.45

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":"enhanced-gateway.d.ts","sourceRoot":"","sources":["../../../src/route-handlers/nextjs/enhanced-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAsKxD,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,IAAI,CACxB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD"}
1
+ {"version":3,"file":"enhanced-gateway.d.ts","sourceRoot":"","sources":["../../../src/route-handlers/nextjs/enhanced-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAgMxD,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,IAAI,CACxB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD"}
@@ -20,6 +20,7 @@ function mapAuthRouteToPublicRoute(path) {
20
20
  const rawPath = path.startsWith("/") ? path.slice(1) : path;
21
21
  // Remove leading 'ai/' if present (for routes like ai/auth/prompts)
22
22
  const cleanPath = rawPath.startsWith("ai/") ? rawPath.slice(3) : rawPath;
23
+ console.log(`[Enhanced Gateway] Raw path: "${path}" -> Clean path: "${cleanPath}"`);
23
24
  // Route mapping: auth routes -> public routes (without api/public/v1 prefix)
24
25
  const routeMappings = {
25
26
  // Prompts
@@ -53,17 +54,24 @@ function mapAuthRouteToPublicRoute(path) {
53
54
  "auth/generate-image": "image-ai",
54
55
  "generate-image": "image-ai",
55
56
  // Status and provider
56
- status: "status",
57
- provider: "provider",
58
- "public/status": "status",
57
+ status: "auth/status",
58
+ provider: "auth/provider",
59
+ "auth/status": "auth/status", // Direct mapping
60
+ "auth/status/storage": "auth/status/storage", // Direct mapping for storage endpoint
61
+ "auth/provider": "auth/provider", // Direct mapping
62
+ "auth/api-keys": "auth/api-keys", // Direct mapping
63
+ "auth/session/verify": "auth/session/verify", // Direct mapping
64
+ "public/status": "auth/status",
59
65
  };
60
66
  // Try exact match first
61
67
  if (routeMappings[cleanPath]) {
62
68
  return routeMappings[cleanPath];
63
69
  }
64
- // Try pattern matching
65
- for (const [pattern, target] of Object.entries(routeMappings)) {
66
- if (cleanPath.startsWith(pattern)) {
70
+ // Try pattern matching with priority to longer/more specific patterns first
71
+ const sortedPatterns = Object.entries(routeMappings)
72
+ .sort(([a], [b]) => b.length - a.length); // Longer patterns first
73
+ for (const [pattern, target] of sortedPatterns) {
74
+ if (cleanPath.startsWith(pattern + "/") || cleanPath === pattern) {
67
75
  return target + cleanPath.slice(pattern.length);
68
76
  }
69
77
  }
@@ -85,10 +93,24 @@ async function handleRequest(request, context) {
85
93
  console.log(`[Enhanced Gateway] Proxying to: ${finalUrl}`);
86
94
  console.log("[Enhanced Gateway] Bearer token:", LB_API_KEY ? `${LB_API_KEY.substring(0, 10)}...` : "MISSING");
87
95
  try {
96
+ // Déterminer le type d'auth selon le path
97
+ const isAuthRoute = originalPath.startsWith('auth/') || mappedPath.startsWith('auth/');
88
98
  const headers = {
89
- Authorization: `Bearer ${LB_API_KEY}`,
90
99
  "Content-Type": "application/json",
91
100
  };
101
+ if (isAuthRoute) {
102
+ // Routes auth/* : forward les cookies de session
103
+ console.log("[Enhanced Gateway] Auth route - forwarding session cookies");
104
+ const cookies = request.headers.get('cookie');
105
+ if (cookies) {
106
+ headers['Cookie'] = cookies;
107
+ }
108
+ }
109
+ else {
110
+ // Routes v1/* : utiliser LB_API_KEY
111
+ console.log("[Enhanced Gateway] API route - using LB_API_KEY");
112
+ headers['Authorization'] = `Bearer ${LB_API_KEY}`;
113
+ }
92
114
  let body;
93
115
  if (request.method === "POST" ||
94
116
  request.method === "PUT" ||
@@ -105,6 +127,7 @@ async function handleRequest(request, context) {
105
127
  method: request.method,
106
128
  headers,
107
129
  body,
130
+ credentials: isAuthRoute ? 'include' : 'omit', // Include cookies for auth routes
108
131
  });
109
132
  if (!response.ok) {
110
133
  const errorText = await response.text();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lastbrain/ai-ui-core",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "Framework-agnostic core library for LastBrain AI UI Kit",
5
5
  "private": false,
6
6
  "type": "module",
@@ -29,6 +29,8 @@ function mapAuthRouteToPublicRoute(path: string): string {
29
29
  // Remove leading 'ai/' if present (for routes like ai/auth/prompts)
30
30
  const cleanPath = rawPath.startsWith("ai/") ? rawPath.slice(3) : rawPath;
31
31
 
32
+ console.log(`[Enhanced Gateway] Raw path: "${path}" -> Clean path: "${cleanPath}"`);
33
+
32
34
  // Route mapping: auth routes -> public routes (without api/public/v1 prefix)
33
35
  const routeMappings: Record<string, string> = {
34
36
  // Prompts
@@ -69,9 +71,14 @@ function mapAuthRouteToPublicRoute(path: string): string {
69
71
  "generate-image": "image-ai",
70
72
 
71
73
  // Status and provider
72
- status: "status",
73
- provider: "provider",
74
- "public/status": "status",
74
+ status: "auth/status",
75
+ provider: "auth/provider",
76
+ "auth/status": "auth/status", // Direct mapping
77
+ "auth/status/storage": "auth/status/storage", // Direct mapping for storage endpoint
78
+ "auth/provider": "auth/provider", // Direct mapping
79
+ "auth/api-keys": "auth/api-keys", // Direct mapping
80
+ "auth/session/verify": "auth/session/verify", // Direct mapping
81
+ "public/status": "auth/status",
75
82
  };
76
83
 
77
84
  // Try exact match first
@@ -79,9 +86,12 @@ function mapAuthRouteToPublicRoute(path: string): string {
79
86
  return routeMappings[cleanPath];
80
87
  }
81
88
 
82
- // Try pattern matching
83
- for (const [pattern, target] of Object.entries(routeMappings)) {
84
- if (cleanPath.startsWith(pattern)) {
89
+ // Try pattern matching with priority to longer/more specific patterns first
90
+ const sortedPatterns = Object.entries(routeMappings)
91
+ .sort(([a], [b]) => b.length - a.length); // Longer patterns first
92
+
93
+ for (const [pattern, target] of sortedPatterns) {
94
+ if (cleanPath.startsWith(pattern + "/") || cleanPath === pattern) {
85
95
  return target + cleanPath.slice(pattern.length);
86
96
  }
87
97
  }
@@ -119,11 +129,26 @@ async function handleRequest(
119
129
  );
120
130
 
121
131
  try {
132
+ // Déterminer le type d'auth selon le path
133
+ const isAuthRoute = originalPath.startsWith('auth/') || mappedPath.startsWith('auth/');
134
+
122
135
  const headers: HeadersInit = {
123
- Authorization: `Bearer ${LB_API_KEY}`,
124
136
  "Content-Type": "application/json",
125
137
  };
126
138
 
139
+ if (isAuthRoute) {
140
+ // Routes auth/* : forward les cookies de session
141
+ console.log("[Enhanced Gateway] Auth route - forwarding session cookies");
142
+ const cookies = request.headers.get('cookie');
143
+ if (cookies) {
144
+ headers['Cookie'] = cookies;
145
+ }
146
+ } else {
147
+ // Routes v1/* : utiliser LB_API_KEY
148
+ console.log("[Enhanced Gateway] API route - using LB_API_KEY");
149
+ headers['Authorization'] = `Bearer ${LB_API_KEY}`;
150
+ }
151
+
127
152
  let body: string | undefined;
128
153
  if (
129
154
  request.method === "POST" ||
@@ -142,6 +167,7 @@ async function handleRequest(
142
167
  method: request.method,
143
168
  headers,
144
169
  body,
170
+ credentials: isAuthRoute ? 'include' : 'omit', // Include cookies for auth routes
145
171
  });
146
172
 
147
173
  if (!response.ok) {