@lastbrain/ai-ui-core 1.0.16 → 1.0.18
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 +34 -16
- package/dist/route-handlers/nextjs/enhanced-gateway.d.ts.map +1 -1
- package/dist/route-handlers/nextjs/enhanced-gateway.js +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/createClient.ts +42 -23
- package/src/route-handlers/nextjs/enhanced-gateway.ts +5 -0
- package/src/types/index.ts +2 -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;AA4FlB,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY;qBAsBnB,OAAO,CAAC,QAAQ,EAAE,CAAC;wBAqCd,aAAa,KAAG,OAAO,CAAC,cAAc,CAAC;yBAoCtC,cAAc,KAAG,OAAO,CAAC,eAAe,CAAC;iBAoCjD,cAAc,KAAG,OAAO,CAAC,eAAe,CAAC;qBAkBvC,OAAO,CAAC,QAAQ,CAAC;EAyB9C"}
|
|
@@ -36,6 +36,33 @@ async function fetchWithRetry(url, options, retryConfig) {
|
|
|
36
36
|
}
|
|
37
37
|
throw lastError;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Build URL for API endpoint with proper routing
|
|
41
|
+
* For internal app (baseUrl="/api/ai"): use internal routes like /generate-text, /auth/status
|
|
42
|
+
* For external app (baseUrl="/api/lastbrain"): use proxy routes like /text-ai, /status
|
|
43
|
+
*/
|
|
44
|
+
function buildUrl(baseUrl, endpoint) {
|
|
45
|
+
const isInternalApp = baseUrl.includes("/api/ai");
|
|
46
|
+
// Map endpoints for internal vs external context
|
|
47
|
+
const endpointMap = {
|
|
48
|
+
// Text and image generation
|
|
49
|
+
"text-ai": { internal: "/generate-text", external: "/text-ai" },
|
|
50
|
+
"image-ai": { internal: "/generate-image", external: "/image-ai" },
|
|
51
|
+
// Auth endpoints need /auth/ prefix for internal
|
|
52
|
+
status: { internal: "/auth/status", external: "/status" },
|
|
53
|
+
provider: { internal: "/auth/provider", external: "/provider" },
|
|
54
|
+
// Other endpoints
|
|
55
|
+
"track-usage": { internal: "/track-usage", external: "/track-usage" },
|
|
56
|
+
"ai/embed": { internal: "/ai/embed", external: "/ai/embed" },
|
|
57
|
+
};
|
|
58
|
+
const mapping = endpointMap[endpoint];
|
|
59
|
+
if (mapping) {
|
|
60
|
+
const finalEndpoint = isInternalApp ? mapping.internal : mapping.external;
|
|
61
|
+
return `${baseUrl}${finalEndpoint}`;
|
|
62
|
+
}
|
|
63
|
+
// Fallback for unmapped endpoints
|
|
64
|
+
return `${baseUrl}/${endpoint}`;
|
|
65
|
+
}
|
|
39
66
|
export function createClient(config) {
|
|
40
67
|
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
41
68
|
const retries = config.retries ?? DEFAULT_RETRIES;
|
|
@@ -43,7 +70,6 @@ export function createClient(config) {
|
|
|
43
70
|
const headers = {
|
|
44
71
|
"Content-Type": "application/json",
|
|
45
72
|
};
|
|
46
|
-
console.log("[APIKEY] config.apiKeyId:", config.apiKeyId);
|
|
47
73
|
if (config.apiKeyId) {
|
|
48
74
|
headers.Authorization = `Bearer ${config.apiKeyId}`;
|
|
49
75
|
}
|
|
@@ -56,15 +82,12 @@ export function createClient(config) {
|
|
|
56
82
|
}
|
|
57
83
|
async function getModels() {
|
|
58
84
|
try {
|
|
59
|
-
const url =
|
|
60
|
-
console.log("[createClient] getModels() calling URL:", url);
|
|
61
|
-
console.log("[createClient] headers:", createHeaders());
|
|
85
|
+
const url = buildUrl(config.baseUrl, "provider");
|
|
62
86
|
const response = await fetchWithRetry(url, {
|
|
63
87
|
method: "GET",
|
|
64
88
|
headers: createHeaders(),
|
|
65
89
|
signal: createAbortSignal(),
|
|
66
90
|
}, { retries, delay: INITIAL_RETRY_DELAY });
|
|
67
|
-
console.log("[createClient] getModels() response:", response);
|
|
68
91
|
// Transform response: extract all models from providers array
|
|
69
92
|
if (response.providers && Array.isArray(response.providers)) {
|
|
70
93
|
const allModels = [];
|
|
@@ -73,12 +96,10 @@ export function createClient(config) {
|
|
|
73
96
|
allModels.push(...provider.models);
|
|
74
97
|
}
|
|
75
98
|
}
|
|
76
|
-
console.log("[createClient] getModels() extracted models:", allModels.length);
|
|
77
99
|
return allModels;
|
|
78
100
|
}
|
|
79
101
|
// Fallback: if response is already a flat array
|
|
80
102
|
if (Array.isArray(response)) {
|
|
81
|
-
console.log("[createClient] getModels() direct array:", response.length);
|
|
82
103
|
return response;
|
|
83
104
|
}
|
|
84
105
|
return [];
|
|
@@ -89,7 +110,7 @@ export function createClient(config) {
|
|
|
89
110
|
}
|
|
90
111
|
async function generateText(req) {
|
|
91
112
|
try {
|
|
92
|
-
const url =
|
|
113
|
+
const url = buildUrl(config.baseUrl, "text-ai");
|
|
93
114
|
const response = await fetchWithRetry(url, {
|
|
94
115
|
method: "POST",
|
|
95
116
|
headers: createHeaders(),
|
|
@@ -99,7 +120,7 @@ export function createClient(config) {
|
|
|
99
120
|
// Track prompt usage if promptId is provided
|
|
100
121
|
if (req.promptId) {
|
|
101
122
|
try {
|
|
102
|
-
await fetch(
|
|
123
|
+
await fetch(buildUrl(config.baseUrl, "track-usage"), {
|
|
103
124
|
method: "POST",
|
|
104
125
|
headers: createHeaders(),
|
|
105
126
|
body: JSON.stringify({ promptId: req.promptId }),
|
|
@@ -119,7 +140,7 @@ export function createClient(config) {
|
|
|
119
140
|
}
|
|
120
141
|
async function generateImage(req) {
|
|
121
142
|
try {
|
|
122
|
-
const url =
|
|
143
|
+
const url = buildUrl(config.baseUrl, "image-ai");
|
|
123
144
|
const response = await fetchWithRetry(url, {
|
|
124
145
|
method: "POST",
|
|
125
146
|
headers: createHeaders(),
|
|
@@ -129,7 +150,7 @@ export function createClient(config) {
|
|
|
129
150
|
// Track prompt usage if promptId is provided
|
|
130
151
|
if (req.promptId) {
|
|
131
152
|
try {
|
|
132
|
-
await fetch(
|
|
153
|
+
await fetch(buildUrl(config.baseUrl, "track-usage"), {
|
|
133
154
|
method: "POST",
|
|
134
155
|
headers: createHeaders(),
|
|
135
156
|
body: JSON.stringify({ promptId: req.promptId }),
|
|
@@ -149,7 +170,7 @@ export function createClient(config) {
|
|
|
149
170
|
}
|
|
150
171
|
async function embed(req) {
|
|
151
172
|
try {
|
|
152
|
-
const url =
|
|
173
|
+
const url = buildUrl(config.baseUrl, "ai/embed");
|
|
153
174
|
return await fetchWithRetry(url, {
|
|
154
175
|
method: "POST",
|
|
155
176
|
headers: createHeaders(),
|
|
@@ -163,9 +184,7 @@ export function createClient(config) {
|
|
|
163
184
|
}
|
|
164
185
|
async function getStatus() {
|
|
165
186
|
try {
|
|
166
|
-
const url =
|
|
167
|
-
console.log("[createClient] getStatus() calling URL:", url);
|
|
168
|
-
console.log("[createClient] headers:", createHeaders());
|
|
187
|
+
const url = buildUrl(config.baseUrl, "status");
|
|
169
188
|
return await fetchWithRetry(url, {
|
|
170
189
|
method: "GET",
|
|
171
190
|
headers: createHeaders(),
|
|
@@ -173,7 +192,6 @@ export function createClient(config) {
|
|
|
173
192
|
}, { retries, delay: INITIAL_RETRY_DELAY });
|
|
174
193
|
}
|
|
175
194
|
catch (error) {
|
|
176
|
-
console.error("[createClient] getStatus() error:", error);
|
|
177
195
|
throw normalizeError(error);
|
|
178
196
|
}
|
|
179
197
|
}
|
|
@@ -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/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE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AAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;QACjC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -69,6 +69,37 @@ async function fetchWithRetry<T>(
|
|
|
69
69
|
throw lastError;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Build URL for API endpoint with proper routing
|
|
74
|
+
* For internal app (baseUrl="/api/ai"): use internal routes like /generate-text, /auth/status
|
|
75
|
+
* For external app (baseUrl="/api/lastbrain"): use proxy routes like /text-ai, /status
|
|
76
|
+
*/
|
|
77
|
+
function buildUrl(baseUrl: string, endpoint: string): string {
|
|
78
|
+
const isInternalApp = baseUrl.includes("/api/ai");
|
|
79
|
+
|
|
80
|
+
// Map endpoints for internal vs external context
|
|
81
|
+
const endpointMap: Record<string, { internal: string; external: string }> = {
|
|
82
|
+
// Text and image generation
|
|
83
|
+
"text-ai": { internal: "/generate-text", external: "/text-ai" },
|
|
84
|
+
"image-ai": { internal: "/generate-image", external: "/image-ai" },
|
|
85
|
+
// Auth endpoints need /auth/ prefix for internal
|
|
86
|
+
status: { internal: "/auth/status", external: "/status" },
|
|
87
|
+
provider: { internal: "/auth/provider", external: "/provider" },
|
|
88
|
+
// Other endpoints
|
|
89
|
+
"track-usage": { internal: "/track-usage", external: "/track-usage" },
|
|
90
|
+
"ai/embed": { internal: "/ai/embed", external: "/ai/embed" },
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const mapping = endpointMap[endpoint];
|
|
94
|
+
if (mapping) {
|
|
95
|
+
const finalEndpoint = isInternalApp ? mapping.internal : mapping.external;
|
|
96
|
+
return `${baseUrl}${finalEndpoint}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Fallback for unmapped endpoints
|
|
100
|
+
return `${baseUrl}/${endpoint}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
72
103
|
export function createClient(config: ClientConfig) {
|
|
73
104
|
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
74
105
|
const retries = config.retries ?? DEFAULT_RETRIES;
|
|
@@ -77,7 +108,7 @@ export function createClient(config: ClientConfig) {
|
|
|
77
108
|
const headers: Record<string, string> = {
|
|
78
109
|
"Content-Type": "application/json",
|
|
79
110
|
};
|
|
80
|
-
|
|
111
|
+
|
|
81
112
|
if (config.apiKeyId) {
|
|
82
113
|
headers.Authorization = `Bearer ${config.apiKeyId}`;
|
|
83
114
|
}
|
|
@@ -93,9 +124,7 @@ export function createClient(config: ClientConfig) {
|
|
|
93
124
|
|
|
94
125
|
async function getModels(): Promise<ModelRef[]> {
|
|
95
126
|
try {
|
|
96
|
-
const url =
|
|
97
|
-
console.log("[createClient] getModels() calling URL:", url);
|
|
98
|
-
console.log("[createClient] headers:", createHeaders());
|
|
127
|
+
const url = buildUrl(config.baseUrl, "provider");
|
|
99
128
|
|
|
100
129
|
const response = await fetchWithRetry<any>(
|
|
101
130
|
url,
|
|
@@ -107,8 +136,6 @@ export function createClient(config: ClientConfig) {
|
|
|
107
136
|
{ retries, delay: INITIAL_RETRY_DELAY }
|
|
108
137
|
);
|
|
109
138
|
|
|
110
|
-
console.log("[createClient] getModels() response:", response);
|
|
111
|
-
|
|
112
139
|
// Transform response: extract all models from providers array
|
|
113
140
|
if (response.providers && Array.isArray(response.providers)) {
|
|
114
141
|
const allModels: ModelRef[] = [];
|
|
@@ -117,19 +144,12 @@ export function createClient(config: ClientConfig) {
|
|
|
117
144
|
allModels.push(...provider.models);
|
|
118
145
|
}
|
|
119
146
|
}
|
|
120
|
-
|
|
121
|
-
"[createClient] getModels() extracted models:",
|
|
122
|
-
allModels.length
|
|
123
|
-
);
|
|
147
|
+
|
|
124
148
|
return allModels;
|
|
125
149
|
}
|
|
126
150
|
|
|
127
151
|
// Fallback: if response is already a flat array
|
|
128
152
|
if (Array.isArray(response)) {
|
|
129
|
-
console.log(
|
|
130
|
-
"[createClient] getModels() direct array:",
|
|
131
|
-
response.length
|
|
132
|
-
);
|
|
133
153
|
return response;
|
|
134
154
|
}
|
|
135
155
|
|
|
@@ -141,7 +161,8 @@ export function createClient(config: ClientConfig) {
|
|
|
141
161
|
|
|
142
162
|
async function generateText(req: AiTextRequest): Promise<AiTextResponse> {
|
|
143
163
|
try {
|
|
144
|
-
const url =
|
|
164
|
+
const url = buildUrl(config.baseUrl, "text-ai");
|
|
165
|
+
|
|
145
166
|
const response = await fetchWithRetry<AiTextResponse>(
|
|
146
167
|
url,
|
|
147
168
|
{
|
|
@@ -156,7 +177,7 @@ export function createClient(config: ClientConfig) {
|
|
|
156
177
|
// Track prompt usage if promptId is provided
|
|
157
178
|
if (req.promptId) {
|
|
158
179
|
try {
|
|
159
|
-
await fetch(
|
|
180
|
+
await fetch(buildUrl(config.baseUrl, "track-usage"), {
|
|
160
181
|
method: "POST",
|
|
161
182
|
headers: createHeaders(),
|
|
162
183
|
body: JSON.stringify({ promptId: req.promptId }),
|
|
@@ -176,7 +197,8 @@ export function createClient(config: ClientConfig) {
|
|
|
176
197
|
|
|
177
198
|
async function generateImage(req: AiImageRequest): Promise<AiImageResponse> {
|
|
178
199
|
try {
|
|
179
|
-
const url =
|
|
200
|
+
const url = buildUrl(config.baseUrl, "image-ai");
|
|
201
|
+
|
|
180
202
|
const response = await fetchWithRetry<AiImageResponse>(
|
|
181
203
|
url,
|
|
182
204
|
{
|
|
@@ -191,7 +213,7 @@ export function createClient(config: ClientConfig) {
|
|
|
191
213
|
// Track prompt usage if promptId is provided
|
|
192
214
|
if (req.promptId) {
|
|
193
215
|
try {
|
|
194
|
-
await fetch(
|
|
216
|
+
await fetch(buildUrl(config.baseUrl, "track-usage"), {
|
|
195
217
|
method: "POST",
|
|
196
218
|
headers: createHeaders(),
|
|
197
219
|
body: JSON.stringify({ promptId: req.promptId }),
|
|
@@ -211,7 +233,7 @@ export function createClient(config: ClientConfig) {
|
|
|
211
233
|
|
|
212
234
|
async function embed(req: AiEmbedRequest): Promise<AiEmbedResponse> {
|
|
213
235
|
try {
|
|
214
|
-
const url =
|
|
236
|
+
const url = buildUrl(config.baseUrl, "ai/embed");
|
|
215
237
|
return await fetchWithRetry<AiEmbedResponse>(
|
|
216
238
|
url,
|
|
217
239
|
{
|
|
@@ -229,9 +251,7 @@ export function createClient(config: ClientConfig) {
|
|
|
229
251
|
|
|
230
252
|
async function getStatus(): Promise<AiStatus> {
|
|
231
253
|
try {
|
|
232
|
-
const url =
|
|
233
|
-
console.log("[createClient] getStatus() calling URL:", url);
|
|
234
|
-
console.log("[createClient] headers:", createHeaders());
|
|
254
|
+
const url = buildUrl(config.baseUrl, "status");
|
|
235
255
|
|
|
236
256
|
return await fetchWithRetry<AiStatus>(
|
|
237
257
|
url,
|
|
@@ -243,7 +263,6 @@ export function createClient(config: ClientConfig) {
|
|
|
243
263
|
{ retries, delay: INITIAL_RETRY_DELAY }
|
|
244
264
|
);
|
|
245
265
|
} catch (error) {
|
|
246
|
-
console.error("[createClient] getStatus() error:", error);
|
|
247
266
|
throw normalizeError(error);
|
|
248
267
|
}
|
|
249
268
|
}
|
|
@@ -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",
|
package/src/types/index.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface AiImageRequest {
|
|
|
37
37
|
size?: string;
|
|
38
38
|
n?: number;
|
|
39
39
|
promptId?: string; // Track which prompt was used
|
|
40
|
+
storeOutputs?: boolean; // Whether to store outputs (external API)
|
|
41
|
+
artifactTitle?: string; // Title for stored artifacts
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
export interface AiImageResponse {
|