feat(studio): deploy manual designer and configurable AI model

This commit is contained in:
Clintchiz committed 2026-10-19 21:02:33 +05:30
1 parent 58687d8679
commit eefc86a057
10 files changed
+133 -32

No files matched your search

+19 -10
View File
@@ -3,7 +3,7 @@ import type {
GenerationRequest,
} from "@wrnexus/design-studio";
export const APIMART_MODEL = "gpt-6-luna";
export const APIMART_MODEL = "gpt-5-mini";
export const AI_TIMEOUT_MS = 60_000;
export const AI_OUTPUT_TOKENS = 8192;
type FailureKind =
@@ -22,7 +22,7 @@ const failureMessages: Record<FailureKind, string> = {
quota:
"APIMart reports insufficient credit or quota. Check the provider account balance and limits.",
model:
"APIMart could not access gpt-6-luna. Check that this model is enabled for the server API key.",
"APIMart could not access the configured model. Check that this model is enabled for the server API key.",
rate: "APIMart is rate limiting requests. Wait a minute and generate again.",
unavailable:
"APIMart is temporarily unavailable. Try generating again shortly.",
@@ -70,6 +70,7 @@ function failureFor(status: number, code?: unknown) {
export function apimartProvider(
apiKey: string,
transport: typeof fetch = fetch,
model = APIMART_MODEL,
): GenerationProvider {
return {
name: "APIMart",
@@ -87,7 +88,7 @@ export function apimartProvider(
"content-type": "application/json",
},
body: JSON.stringify({
model: APIMART_MODEL,
model,
stream: false,
max_tokens: options.maxTokens ?? AI_OUTPUT_TOKENS,
messages: [
@@ -137,7 +138,7 @@ export function apimartProvider(
return {
value: choice.message.content,
provider: "APIMart",
model: APIMART_MODEL,
model,
};
},
};
@@ -166,7 +167,11 @@ async function readBounded(source: Request | Response, limit: number) {
}
}
function synchronousStudioAI(apiKey?: string, transport: typeof fetch = fetch) {
function synchronousStudioAI(
apiKey?: string,
transport: typeof fetch = fetch,
model = APIMART_MODEL,
) {
let active = 0,
windowStart = Date.now(),
count = 0;
@@ -198,7 +203,7 @@ function synchronousStudioAI(apiKey?: string, transport: typeof fetch = fetch) {
if (url.pathname.endsWith("/generation") && request.method === "GET")
return json({
provider: "APIMart",
model: APIMART_MODEL,
model,
templateVersion: 1,
delivery: "polling",
maxAttempts: 2,
@@ -236,7 +241,7 @@ function synchronousStudioAI(apiKey?: string, transport: typeof fetch = fetch) {
let calls = 0;
let exhausted = false;
let failure: APIMartFailure | undefined;
const upstream = apimartProvider(apiKey, transport);
const upstream = apimartProvider(apiKey, transport, model);
const provider: GenerationProvider = {
name: upstream.name,
async generate(prompt, options) {
@@ -266,7 +271,7 @@ function synchronousStudioAI(apiKey?: string, transport: typeof fetch = fetch) {
const generate = () =>
generateDesigns(input, {
provider,
model: APIMART_MODEL,
model,
signal: deadline,
timeoutMs: AI_TIMEOUT_MS,
maxOutputTokens: AI_OUTPUT_TOKENS,
@@ -351,8 +356,12 @@ function synchronousStudioAI(apiKey?: string, transport: typeof fetch = fetch) {
}
/** Short HTTP requests keep the deployment proxy out of the provider wait. */
export function studioAI(apiKey?: string, transport: typeof fetch = fetch) {
const run = synchronousStudioAI(apiKey, transport);
export function studioAI(
apiKey?: string,
transport: typeof fetch = fetch,
model = APIMART_MODEL,
) {
const run = synchronousStudioAI(apiKey, transport, model);
type Job = {
status: "pending" | "complete" | "failed" | "cancelled";
controller: AbortController;