@lastbrain/ai-ui-core 1.0.44 → 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;AA2KxD,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
@@ -66,9 +67,11 @@ function mapAuthRouteToPublicRoute(path) {
66
67
  if (routeMappings[cleanPath]) {
67
68
  return routeMappings[cleanPath];
68
69
  }
69
- // Try pattern matching
70
- for (const [pattern, target] of Object.entries(routeMappings)) {
71
- 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) {
72
75
  return target + cleanPath.slice(pattern.length);
73
76
  }
74
77
  }
@@ -90,10 +93,24 @@ async function handleRequest(request, context) {
90
93
  console.log(`[Enhanced Gateway] Proxying to: ${finalUrl}`);
91
94
  console.log("[Enhanced Gateway] Bearer token:", LB_API_KEY ? `${LB_API_KEY.substring(0, 10)}...` : "MISSING");
92
95
  try {
96
+ // Déterminer le type d'auth selon le path
97
+ const isAuthRoute = originalPath.startsWith('auth/') || mappedPath.startsWith('auth/');
93
98
  const headers = {
94
- Authorization: `Bearer ${LB_API_KEY}`,
95
99
  "Content-Type": "application/json",
96
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
+ }
97
114
  let body;
98
115
  if (request.method === "POST" ||
99
116
  request.method === "PUT" ||
@@ -110,6 +127,7 @@ async function handleRequest(request, context) {
110
127
  method: request.method,
111
128
  headers,
112
129
  body,
130
+ credentials: isAuthRoute ? 'include' : 'omit', // Include cookies for auth routes
113
131
  });
114
132
  if (!response.ok) {
115
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.44",
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
@@ -84,9 +86,12 @@ function mapAuthRouteToPublicRoute(path: string): string {
84
86
  return routeMappings[cleanPath];
85
87
  }
86
88
 
87
- // Try pattern matching
88
- for (const [pattern, target] of Object.entries(routeMappings)) {
89
- 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) {
90
95
  return target + cleanPath.slice(pattern.length);
91
96
  }
92
97
  }
@@ -124,11 +129,26 @@ async function handleRequest(
124
129
  );
125
130
 
126
131
  try {
132
+ // Déterminer le type d'auth selon le path
133
+ const isAuthRoute = originalPath.startsWith('auth/') || mappedPath.startsWith('auth/');
134
+
127
135
  const headers: HeadersInit = {
128
- Authorization: `Bearer ${LB_API_KEY}`,
129
136
  "Content-Type": "application/json",
130
137
  };
131
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
+
132
152
  let body: string | undefined;
133
153
  if (
134
154
  request.method === "POST" ||
@@ -147,6 +167,7 @@ async function handleRequest(
147
167
  method: request.method,
148
168
  headers,
149
169
  body,
170
+ credentials: isAuthRoute ? 'include' : 'omit', // Include cookies for auth routes
150
171
  });
151
172
 
152
173
  if (!response.ok) {