Split custom world generation into staged lightweight batches
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-05 22:20:30 +08:00
parent 89cecda7da
commit fcd8d727b0
57 changed files with 7646 additions and 1425 deletions

View File

@@ -18,6 +18,13 @@ export class LlmConnectivityError extends Error {
}
}
export class LlmTimeoutError extends LlmConnectivityError {
constructor(message: string) {
super(message);
this.name = 'LlmTimeoutError';
}
}
export function resolveTimeoutMs(rawValue: string | undefined, fallback: number) {
const parsed = Number(rawValue);
return Number.isFinite(parsed) && parsed > 0 ? Math.round(parsed) : fallback;
@@ -26,7 +33,7 @@ export function resolveTimeoutMs(rawValue: string | undefined, fallback: number)
export const REQUEST_TIMEOUT_MS = resolveTimeoutMs(ENV.VITE_LLM_REQUEST_TIMEOUT_MS, 15000);
export const CUSTOM_WORLD_REQUEST_TIMEOUT_MS = resolveTimeoutMs(
ENV.VITE_LLM_CUSTOM_WORLD_TIMEOUT_MS,
Math.max(REQUEST_TIMEOUT_MS, 45000),
Math.max(REQUEST_TIMEOUT_MS, 120000),
);
function logLlmDebug(title: string, payload: unknown) {
@@ -39,7 +46,7 @@ function logLlmDebug(title: string, payload: unknown) {
function normalizeLlmError(error: unknown): never {
if (error instanceof DOMException && error.name === 'AbortError') {
throw new LlmConnectivityError('The LLM request timed out. Please check the network or endpoint.');
throw new LlmTimeoutError('The LLM request timed out. Please check the network or endpoint.');
}
if (error instanceof TypeError) {
@@ -53,6 +60,10 @@ export function isLlmConnectivityError(error: unknown): error is LlmConnectivity
return error instanceof LlmConnectivityError;
}
export function isLlmTimeoutError(error: unknown): error is LlmTimeoutError {
return error instanceof LlmTimeoutError;
}
async function requestMessageContent(
systemPrompt: string,
userPrompt: string,