@lastbrain/ai-ui-core 1.0.14 → 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":"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;AAmJxD,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"}
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;AA8IxD,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"}
@@ -7,39 +7,38 @@ import { NextResponse } from "next/server";
7
7
  * export { GET, POST, PUT } from "@lastbrain/ai-ui-core/route-handlers/nextjs/enhanced-gateway";
8
8
  */
9
9
  const LB_API_KEY = process.env.LB_API_KEY;
10
- const LB_BASE_URL = process.env.LB_BASE_URL || "https://ai.lastbrain.io";
10
+ const LB_BASE_URL = process.env.LB_BASE_URL || "https://ai.lastbrain.io/api/public/v1";
11
11
  if (!LB_API_KEY) {
12
12
  console.warn("⚠️ LB_API_KEY not found in environment variables. AI features will not work.");
13
13
  }
14
14
  /**
15
- * Maps internal auth routes to public API routes
15
+ * Maps internal auth routes to clean public routes (without api/public/v1 prefix)
16
+ * The prefix is already in LB_BASE_URL
16
17
  */
17
18
  function mapAuthRouteToPublicRoute(path) {
18
- // Si le path contient déjà api/public/v1, le retourner tel quel (sans double-prefixe)
19
- if (path.includes("api/public/v1")) {
20
- return path.replace(/^\//, "");
21
- }
22
- // Remove leading 'ai/' if present
23
- const cleanPath = path.startsWith("ai/") ? path.slice(3) : path;
24
- // Route mapping for auth routes -> public routes
19
+ // Remove leading slash if present
20
+ const rawPath = path.startsWith("/") ? path.slice(1) : path;
21
+ // Remove leading 'ai/' if present (for routes like ai/auth/prompts)
22
+ const cleanPath = rawPath.startsWith("ai/") ? rawPath.slice(3) : rawPath;
23
+ // Route mapping: auth routes -> public routes (without api/public/v1 prefix)
25
24
  const routeMappings = {
26
25
  // Prompts
27
- "auth/prompts": "api/public/v1/prompts",
28
- "auth/prompts/stats": "api/public/v1/prompts/stats",
26
+ "auth/prompts": "prompts",
27
+ "auth/prompts/stats": "prompts/stats",
29
28
  // AI Models
30
- "auth/ai-models-available": "api/public/v1/ai/models/available",
31
- "auth/ai-models-user": "api/public/v1/ai/user/models",
32
- "auth/user-models": "api/public/v1/ai/user/models",
33
- "auth/ai-models-toggle": "api/public/v1/ai/user/models/toggle",
29
+ "auth/ai-models-available": "ai/models/available",
30
+ "auth/ai-models-user": "ai/user/models",
31
+ "auth/user-models": "ai/user/models",
32
+ "auth/ai-models-toggle": "ai/user/models/toggle",
34
33
  // Text generation
35
- "auth/generate-text": "api/public/v1/text-ai",
34
+ "auth/generate-text": "text-ai",
36
35
  // Image generation
37
- "auth/generate-image": "api/public/v1/image-ai",
38
- // Status and provider (with and without public prefix)
39
- status: "api/public/v1/status",
40
- provider: "api/public/v1/provider",
41
- "public/gateway-models": "api/public/v1/provider",
42
- "public/status": "api/public/v1/status",
36
+ "auth/generate-image": "image-ai",
37
+ // Status and provider
38
+ status: "status",
39
+ provider: "provider",
40
+ "public/gateway-models": "provider",
41
+ "public/status": "status",
43
42
  };
44
43
  // Try exact match first
45
44
  if (routeMappings[cleanPath]) {
@@ -51,12 +50,8 @@ function mapAuthRouteToPublicRoute(path) {
51
50
  return target + cleanPath.slice(pattern.length);
52
51
  }
53
52
  }
54
- // Default: if already a public route, return as-is
55
- if (cleanPath.startsWith("api/public/")) {
56
- return cleanPath;
57
- }
58
- // Fallback: treat as public v1 route
59
- return `api/public/v1/${cleanPath}`;
53
+ // Fallback: return clean path as-is
54
+ return cleanPath;
60
55
  }
61
56
  async function handleRequest(request, context) {
62
57
  if (!LB_API_KEY) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lastbrain/ai-ui-core",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Framework-agnostic core library for LastBrain AI UI Kit",
5
5
  "private": false,
6
6
  "type": "module",
@@ -9,7 +9,8 @@ import { NextRequest, NextResponse } from "next/server";
9
9
  */
10
10
 
11
11
  const LB_API_KEY = process.env.LB_API_KEY;
12
- const LB_BASE_URL = process.env.LB_BASE_URL || "https://ai.lastbrain.io";
12
+ const LB_BASE_URL =
13
+ process.env.LB_BASE_URL || "https://ai.lastbrain.io/api/public/v1";
13
14
 
14
15
  if (!LB_API_KEY) {
15
16
  console.warn(
@@ -18,40 +19,39 @@ if (!LB_API_KEY) {
18
19
  }
19
20
 
20
21
  /**
21
- * Maps internal auth routes to public API routes
22
+ * Maps internal auth routes to clean public routes (without api/public/v1 prefix)
23
+ * The prefix is already in LB_BASE_URL
22
24
  */
23
25
  function mapAuthRouteToPublicRoute(path: string): string {
24
- // Si le path contient déjà api/public/v1, le retourner tel quel (sans double-prefixe)
25
- if (path.includes("api/public/v1")) {
26
- return path.replace(/^\//, "");
27
- }
26
+ // Remove leading slash if present
27
+ const rawPath = path.startsWith("/") ? path.slice(1) : path;
28
28
 
29
- // Remove leading 'ai/' if present
30
- const cleanPath = path.startsWith("ai/") ? path.slice(3) : path;
29
+ // Remove leading 'ai/' if present (for routes like ai/auth/prompts)
30
+ const cleanPath = rawPath.startsWith("ai/") ? rawPath.slice(3) : rawPath;
31
31
 
32
- // Route mapping for auth routes -> public routes
32
+ // Route mapping: auth routes -> public routes (without api/public/v1 prefix)
33
33
  const routeMappings: Record<string, string> = {
34
34
  // Prompts
35
- "auth/prompts": "api/public/v1/prompts",
36
- "auth/prompts/stats": "api/public/v1/prompts/stats",
35
+ "auth/prompts": "prompts",
36
+ "auth/prompts/stats": "prompts/stats",
37
37
 
38
38
  // AI Models
39
- "auth/ai-models-available": "api/public/v1/ai/models/available",
40
- "auth/ai-models-user": "api/public/v1/ai/user/models",
41
- "auth/user-models": "api/public/v1/ai/user/models",
42
- "auth/ai-models-toggle": "api/public/v1/ai/user/models/toggle",
39
+ "auth/ai-models-available": "ai/models/available",
40
+ "auth/ai-models-user": "ai/user/models",
41
+ "auth/user-models": "ai/user/models",
42
+ "auth/ai-models-toggle": "ai/user/models/toggle",
43
43
 
44
44
  // Text generation
45
- "auth/generate-text": "api/public/v1/text-ai",
45
+ "auth/generate-text": "text-ai",
46
46
 
47
47
  // Image generation
48
- "auth/generate-image": "api/public/v1/image-ai",
48
+ "auth/generate-image": "image-ai",
49
49
 
50
- // Status and provider (with and without public prefix)
51
- status: "api/public/v1/status",
52
- provider: "api/public/v1/provider",
53
- "public/gateway-models": "api/public/v1/provider",
54
- "public/status": "api/public/v1/status",
50
+ // Status and provider
51
+ status: "status",
52
+ provider: "provider",
53
+ "public/gateway-models": "provider",
54
+ "public/status": "status",
55
55
  };
56
56
 
57
57
  // Try exact match first
@@ -66,13 +66,8 @@ function mapAuthRouteToPublicRoute(path: string): string {
66
66
  }
67
67
  }
68
68
 
69
- // Default: if already a public route, return as-is
70
- if (cleanPath.startsWith("api/public/")) {
71
- return cleanPath;
72
- }
73
-
74
- // Fallback: treat as public v1 route
75
- return `api/public/v1/${cleanPath}`;
69
+ // Fallback: return clean path as-is
70
+ return cleanPath;
76
71
  }
77
72
 
78
73
  async function handleRequest(