@lastbrain/ai-ui-core 1.0.16 → 1.0.17
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.
- package/dist/client/createClient.d.ts.map +1 -1
- package/dist/client/createClient.js +17 -11
- package/dist/route-handlers/nextjs/enhanced-gateway.d.ts.map +1 -1
- package/dist/route-handlers/nextjs/enhanced-gateway.js +5 -0
- package/package.json +1 -1
- package/src/client/createClient.ts +24 -18
- package/src/route-handlers/nextjs/enhanced-gateway.ts +5 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../src/client/createClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,QAAQ,EACT,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../src/client/createClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,eAAe,EACf,QAAQ,EACT,MAAM,UAAU,CAAC;AAiFlB,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY;qBAsBnB,OAAO,CAAC,QAAQ,EAAE,CAAC;wBAqCd,aAAa,KAAG,OAAO,CAAC,cAAc,CAAC;yBAmCtC,cAAc,KAAG,OAAO,CAAC,eAAe,CAAC;iBAmCjD,cAAc,KAAG,OAAO,CAAC,eAAe,CAAC;qBAkBvC,OAAO,CAAC,QAAQ,CAAC;EAyB9C"}
|
|
@@ -36,6 +36,21 @@ async function fetchWithRetry(url, options, retryConfig) {
|
|
|
36
36
|
}
|
|
37
37
|
throw lastError;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Build URL for API endpoint with proper auth prefix
|
|
41
|
+
* For baseUrl="/api/ai", status and provider need /auth/ prefix
|
|
42
|
+
* For baseUrl="/api/public/v1" or "/api/lastbrain", no prefix needed
|
|
43
|
+
*/
|
|
44
|
+
function buildUrl(baseUrl, endpoint) {
|
|
45
|
+
const isAuthContext = baseUrl.includes("/api/ai");
|
|
46
|
+
// For auth context, status and provider need /auth/ prefix
|
|
47
|
+
if (isAuthContext && (endpoint === "status" || endpoint === "provider")) {
|
|
48
|
+
const url = `${baseUrl}/auth/${endpoint}`;
|
|
49
|
+
return url;
|
|
50
|
+
}
|
|
51
|
+
const url = `${baseUrl}/${endpoint}`;
|
|
52
|
+
return url;
|
|
53
|
+
}
|
|
39
54
|
export function createClient(config) {
|
|
40
55
|
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
41
56
|
const retries = config.retries ?? DEFAULT_RETRIES;
|
|
@@ -43,7 +58,6 @@ export function createClient(config) {
|
|
|
43
58
|
const headers = {
|
|
44
59
|
"Content-Type": "application/json",
|
|
45
60
|
};
|
|
46
|
-
console.log("[APIKEY] config.apiKeyId:", config.apiKeyId);
|
|
47
61
|
if (config.apiKeyId) {
|
|
48
62
|
headers.Authorization = `Bearer ${config.apiKeyId}`;
|
|
49
63
|
}
|
|
@@ -56,15 +70,12 @@ export function createClient(config) {
|
|
|
56
70
|
}
|
|
57
71
|
async function getModels() {
|
|
58
72
|
try {
|
|
59
|
-
const url =
|
|
60
|
-
console.log("[createClient] getModels() calling URL:", url);
|
|
61
|
-
console.log("[createClient] headers:", createHeaders());
|
|
73
|
+
const url = buildUrl(config.baseUrl, "provider");
|
|
62
74
|
const response = await fetchWithRetry(url, {
|
|
63
75
|
method: "GET",
|
|
64
76
|
headers: createHeaders(),
|
|
65
77
|
signal: createAbortSignal(),
|
|
66
78
|
}, { retries, delay: INITIAL_RETRY_DELAY });
|
|
67
|
-
console.log("[createClient] getModels() response:", response);
|
|
68
79
|
// Transform response: extract all models from providers array
|
|
69
80
|
if (response.providers && Array.isArray(response.providers)) {
|
|
70
81
|
const allModels = [];
|
|
@@ -73,12 +84,10 @@ export function createClient(config) {
|
|
|
73
84
|
allModels.push(...provider.models);
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
|
-
console.log("[createClient] getModels() extracted models:", allModels.length);
|
|
77
87
|
return allModels;
|
|
78
88
|
}
|
|
79
89
|
// Fallback: if response is already a flat array
|
|
80
90
|
if (Array.isArray(response)) {
|
|
81
|
-
console.log("[createClient] getModels() direct array:", response.length);
|
|
82
91
|
return response;
|
|
83
92
|
}
|
|
84
93
|
return [];
|
|
@@ -163,9 +172,7 @@ export function createClient(config) {
|
|
|
163
172
|
}
|
|
164
173
|
async function getStatus() {
|
|
165
174
|
try {
|
|
166
|
-
const url =
|
|
167
|
-
console.log("[createClient] getStatus() calling URL:", url);
|
|
168
|
-
console.log("[createClient] headers:", createHeaders());
|
|
175
|
+
const url = buildUrl(config.baseUrl, "status");
|
|
169
176
|
return await fetchWithRetry(url, {
|
|
170
177
|
method: "GET",
|
|
171
178
|
headers: createHeaders(),
|
|
@@ -173,7 +180,6 @@ export function createClient(config) {
|
|
|
173
180
|
}, { retries, delay: INITIAL_RETRY_DELAY });
|
|
174
181
|
}
|
|
175
182
|
catch (error) {
|
|
176
|
-
console.error("[createClient] getStatus() error:", error);
|
|
177
183
|
throw normalizeError(error);
|
|
178
184
|
}
|
|
179
185
|
}
|
|
@@ -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;AAiKxD,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"}
|
|
@@ -25,17 +25,22 @@ function mapAuthRouteToPublicRoute(path) {
|
|
|
25
25
|
// Prompts
|
|
26
26
|
"auth/prompts": "prompts",
|
|
27
27
|
"auth/prompts/stats": "prompts/stats",
|
|
28
|
+
prompts: "prompts", // Direct mapping for prompts
|
|
29
|
+
"prompts/stats": "prompts/stats", // Direct mapping for stats
|
|
28
30
|
// AI Models - Available
|
|
29
31
|
"auth/ai-models-available": "ai/models/available",
|
|
30
32
|
"ai-models-available": "ai/models/available",
|
|
33
|
+
"ai/models/available": "ai/models/available", // Direct mapping
|
|
31
34
|
// AI Models - User models
|
|
32
35
|
"auth/ai-models-user": "ai/user/models",
|
|
33
36
|
"auth/user-models": "ai/user/models",
|
|
34
37
|
"ai-models-user": "ai/user/models",
|
|
35
38
|
"user-models": "ai/user/models",
|
|
39
|
+
"ai/user/models": "ai/user/models", // Direct mapping
|
|
36
40
|
// AI Models - Toggle
|
|
37
41
|
"auth/ai-models-toggle": "ai/user/models/toggle",
|
|
38
42
|
"ai-models-toggle": "ai/user/models/toggle",
|
|
43
|
+
"ai/user/models/toggle": "ai/user/models/toggle", // Direct mapping
|
|
39
44
|
// Text generation
|
|
40
45
|
"auth/generate-text": "text-ai",
|
|
41
46
|
"generate-text": "text-ai",
|
package/package.json
CHANGED
|
@@ -69,6 +69,26 @@ async function fetchWithRetry<T>(
|
|
|
69
69
|
throw lastError;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Build URL for API endpoint with proper auth prefix
|
|
74
|
+
* For baseUrl="/api/ai", status and provider need /auth/ prefix
|
|
75
|
+
* For baseUrl="/api/public/v1" or "/api/lastbrain", no prefix needed
|
|
76
|
+
*/
|
|
77
|
+
function buildUrl(baseUrl: string, endpoint: string): string {
|
|
78
|
+
const isAuthContext = baseUrl.includes("/api/ai");
|
|
79
|
+
|
|
80
|
+
// For auth context, status and provider need /auth/ prefix
|
|
81
|
+
if (isAuthContext && (endpoint === "status" || endpoint === "provider")) {
|
|
82
|
+
const url = `${baseUrl}/auth/${endpoint}`;
|
|
83
|
+
|
|
84
|
+
return url;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const url = `${baseUrl}/${endpoint}`;
|
|
88
|
+
|
|
89
|
+
return url;
|
|
90
|
+
}
|
|
91
|
+
|
|
72
92
|
export function createClient(config: ClientConfig) {
|
|
73
93
|
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
74
94
|
const retries = config.retries ?? DEFAULT_RETRIES;
|
|
@@ -77,7 +97,7 @@ export function createClient(config: ClientConfig) {
|
|
|
77
97
|
const headers: Record<string, string> = {
|
|
78
98
|
"Content-Type": "application/json",
|
|
79
99
|
};
|
|
80
|
-
|
|
100
|
+
|
|
81
101
|
if (config.apiKeyId) {
|
|
82
102
|
headers.Authorization = `Bearer ${config.apiKeyId}`;
|
|
83
103
|
}
|
|
@@ -93,9 +113,7 @@ export function createClient(config: ClientConfig) {
|
|
|
93
113
|
|
|
94
114
|
async function getModels(): Promise<ModelRef[]> {
|
|
95
115
|
try {
|
|
96
|
-
const url =
|
|
97
|
-
console.log("[createClient] getModels() calling URL:", url);
|
|
98
|
-
console.log("[createClient] headers:", createHeaders());
|
|
116
|
+
const url = buildUrl(config.baseUrl, "provider");
|
|
99
117
|
|
|
100
118
|
const response = await fetchWithRetry<any>(
|
|
101
119
|
url,
|
|
@@ -107,8 +125,6 @@ export function createClient(config: ClientConfig) {
|
|
|
107
125
|
{ retries, delay: INITIAL_RETRY_DELAY }
|
|
108
126
|
);
|
|
109
127
|
|
|
110
|
-
console.log("[createClient] getModels() response:", response);
|
|
111
|
-
|
|
112
128
|
// Transform response: extract all models from providers array
|
|
113
129
|
if (response.providers && Array.isArray(response.providers)) {
|
|
114
130
|
const allModels: ModelRef[] = [];
|
|
@@ -117,19 +133,12 @@ export function createClient(config: ClientConfig) {
|
|
|
117
133
|
allModels.push(...provider.models);
|
|
118
134
|
}
|
|
119
135
|
}
|
|
120
|
-
|
|
121
|
-
"[createClient] getModels() extracted models:",
|
|
122
|
-
allModels.length
|
|
123
|
-
);
|
|
136
|
+
|
|
124
137
|
return allModels;
|
|
125
138
|
}
|
|
126
139
|
|
|
127
140
|
// Fallback: if response is already a flat array
|
|
128
141
|
if (Array.isArray(response)) {
|
|
129
|
-
console.log(
|
|
130
|
-
"[createClient] getModels() direct array:",
|
|
131
|
-
response.length
|
|
132
|
-
);
|
|
133
142
|
return response;
|
|
134
143
|
}
|
|
135
144
|
|
|
@@ -229,9 +238,7 @@ export function createClient(config: ClientConfig) {
|
|
|
229
238
|
|
|
230
239
|
async function getStatus(): Promise<AiStatus> {
|
|
231
240
|
try {
|
|
232
|
-
const url =
|
|
233
|
-
console.log("[createClient] getStatus() calling URL:", url);
|
|
234
|
-
console.log("[createClient] headers:", createHeaders());
|
|
241
|
+
const url = buildUrl(config.baseUrl, "status");
|
|
235
242
|
|
|
236
243
|
return await fetchWithRetry<AiStatus>(
|
|
237
244
|
url,
|
|
@@ -243,7 +250,6 @@ export function createClient(config: ClientConfig) {
|
|
|
243
250
|
{ retries, delay: INITIAL_RETRY_DELAY }
|
|
244
251
|
);
|
|
245
252
|
} catch (error) {
|
|
246
|
-
console.error("[createClient] getStatus() error:", error);
|
|
247
253
|
throw normalizeError(error);
|
|
248
254
|
}
|
|
249
255
|
}
|
|
@@ -34,20 +34,25 @@ function mapAuthRouteToPublicRoute(path: string): string {
|
|
|
34
34
|
// Prompts
|
|
35
35
|
"auth/prompts": "prompts",
|
|
36
36
|
"auth/prompts/stats": "prompts/stats",
|
|
37
|
+
prompts: "prompts", // Direct mapping for prompts
|
|
38
|
+
"prompts/stats": "prompts/stats", // Direct mapping for stats
|
|
37
39
|
|
|
38
40
|
// AI Models - Available
|
|
39
41
|
"auth/ai-models-available": "ai/models/available",
|
|
40
42
|
"ai-models-available": "ai/models/available",
|
|
43
|
+
"ai/models/available": "ai/models/available", // Direct mapping
|
|
41
44
|
|
|
42
45
|
// AI Models - User models
|
|
43
46
|
"auth/ai-models-user": "ai/user/models",
|
|
44
47
|
"auth/user-models": "ai/user/models",
|
|
45
48
|
"ai-models-user": "ai/user/models",
|
|
46
49
|
"user-models": "ai/user/models",
|
|
50
|
+
"ai/user/models": "ai/user/models", // Direct mapping
|
|
47
51
|
|
|
48
52
|
// AI Models - Toggle
|
|
49
53
|
"auth/ai-models-toggle": "ai/user/models/toggle",
|
|
50
54
|
"ai-models-toggle": "ai/user/models/toggle",
|
|
55
|
+
"ai/user/models/toggle": "ai/user/models/toggle", // Direct mapping
|
|
51
56
|
|
|
52
57
|
// Text generation
|
|
53
58
|
"auth/generate-text": "text-ai",
|