@lastbrain/ai-ui-core 1.0.13 → 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;
|
|
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,42 +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
|
|
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
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return path.slice("api/public/v1".length).replace(/^\//, "") || path;
|
|
24
|
-
}
|
|
25
|
-
// Remove leading 'ai/' if present
|
|
26
|
-
const cleanPath = path.startsWith("ai/") ? path.slice(3) : path;
|
|
27
|
-
// 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)
|
|
28
24
|
const routeMappings = {
|
|
29
25
|
// Prompts
|
|
30
|
-
"auth/prompts": "
|
|
31
|
-
"auth/prompts/stats": "
|
|
26
|
+
"auth/prompts": "prompts",
|
|
27
|
+
"auth/prompts/stats": "prompts/stats",
|
|
32
28
|
// AI Models
|
|
33
|
-
"auth/ai-models-available": "
|
|
34
|
-
"auth/ai-models-user": "
|
|
35
|
-
"auth/user-models": "
|
|
36
|
-
"auth/ai-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",
|
|
37
33
|
// Text generation
|
|
38
|
-
"auth/generate-text": "
|
|
34
|
+
"auth/generate-text": "text-ai",
|
|
39
35
|
// Image generation
|
|
40
|
-
"auth/generate-image": "
|
|
41
|
-
// Status and provider
|
|
42
|
-
status: "
|
|
43
|
-
provider: "
|
|
44
|
-
"public/gateway-models": "
|
|
45
|
-
"public/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",
|
|
46
42
|
};
|
|
47
43
|
// Try exact match first
|
|
48
44
|
if (routeMappings[cleanPath]) {
|
|
@@ -54,12 +50,8 @@ function mapAuthRouteToPublicRoute(path) {
|
|
|
54
50
|
return target + cleanPath.slice(pattern.length);
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
return cleanPath;
|
|
60
|
-
}
|
|
61
|
-
// Fallback: treat as public v1 route
|
|
62
|
-
return `api/public/v1/${cleanPath}`;
|
|
53
|
+
// Fallback: return clean path as-is
|
|
54
|
+
return cleanPath;
|
|
63
55
|
}
|
|
64
56
|
async function handleRequest(request, context) {
|
|
65
57
|
if (!LB_API_KEY) {
|
package/package.json
CHANGED
|
@@ -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 =
|
|
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,44 +19,39 @@ if (!LB_API_KEY) {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
|
-
* Maps internal auth routes to public
|
|
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
|
-
//
|
|
25
|
-
|
|
26
|
-
return path.split("api/public/v1/")[1] || path;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (path.startsWith("api/public/v1")) {
|
|
30
|
-
return path.slice("api/public/v1".length).replace(/^\//, "") || path;
|
|
31
|
-
}
|
|
26
|
+
// Remove leading slash if present
|
|
27
|
+
const rawPath = path.startsWith("/") ? path.slice(1) : path;
|
|
32
28
|
|
|
33
|
-
// Remove leading 'ai/' if present
|
|
34
|
-
const cleanPath =
|
|
29
|
+
// Remove leading 'ai/' if present (for routes like ai/auth/prompts)
|
|
30
|
+
const cleanPath = rawPath.startsWith("ai/") ? rawPath.slice(3) : rawPath;
|
|
35
31
|
|
|
36
|
-
// Route mapping
|
|
32
|
+
// Route mapping: auth routes -> public routes (without api/public/v1 prefix)
|
|
37
33
|
const routeMappings: Record<string, string> = {
|
|
38
34
|
// Prompts
|
|
39
|
-
"auth/prompts": "
|
|
40
|
-
"auth/prompts/stats": "
|
|
35
|
+
"auth/prompts": "prompts",
|
|
36
|
+
"auth/prompts/stats": "prompts/stats",
|
|
41
37
|
|
|
42
38
|
// AI Models
|
|
43
|
-
"auth/ai-models-available": "
|
|
44
|
-
"auth/ai-models-user": "
|
|
45
|
-
"auth/user-models": "
|
|
46
|
-
"auth/ai-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",
|
|
47
43
|
|
|
48
44
|
// Text generation
|
|
49
|
-
"auth/generate-text": "
|
|
45
|
+
"auth/generate-text": "text-ai",
|
|
50
46
|
|
|
51
47
|
// Image generation
|
|
52
|
-
"auth/generate-image": "
|
|
48
|
+
"auth/generate-image": "image-ai",
|
|
53
49
|
|
|
54
|
-
// Status and provider
|
|
55
|
-
status: "
|
|
56
|
-
provider: "
|
|
57
|
-
"public/gateway-models": "
|
|
58
|
-
"public/status": "
|
|
50
|
+
// Status and provider
|
|
51
|
+
status: "status",
|
|
52
|
+
provider: "provider",
|
|
53
|
+
"public/gateway-models": "provider",
|
|
54
|
+
"public/status": "status",
|
|
59
55
|
};
|
|
60
56
|
|
|
61
57
|
// Try exact match first
|
|
@@ -70,13 +66,8 @@ function mapAuthRouteToPublicRoute(path: string): string {
|
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
return cleanPath;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Fallback: treat as public v1 route
|
|
79
|
-
return `api/public/v1/${cleanPath}`;
|
|
69
|
+
// Fallback: return clean path as-is
|
|
70
|
+
return cleanPath;
|
|
80
71
|
}
|
|
81
72
|
|
|
82
73
|
async function handleRequest(
|