feat(runtime): 即梦本机运行时 - 接入安全生成闭环与桌面本机渠道
Refs #225 Co-authored-by: zkhyww <127009345+zkhyww@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,9 @@ export function generationFailureMetadata(error: unknown, prompt: string): Gener
|
||||
}
|
||||
|
||||
export function generationErrorMessage(error: unknown) {
|
||||
const stableCode = generationErrorCode(error);
|
||||
const stableMessage = stableCode ? DREAMINA_SUBMIT_ERROR_MESSAGES[stableCode] : undefined;
|
||||
if (stableMessage) return stableMessage;
|
||||
const raw = rawGenerationError(error);
|
||||
if (isContentModerationError(raw)) return CONTENT_MODERATION_MESSAGE;
|
||||
|
||||
@@ -38,6 +41,22 @@ export function generationErrorMessage(error: unknown) {
|
||||
return displayMessage || DEFAULT_GENERATION_ERROR_MESSAGE;
|
||||
}
|
||||
|
||||
export const DREAMINA_SUBMIT_ERROR_MESSAGES: Record<string, string> = {
|
||||
dreamina_submit_spawn_failed: "无法启动官方即梦 CLI,任务尚未提交。",
|
||||
dreamina_submit_exit_nonzero: "官方即梦 CLI 未接受本次提交,任务没有自动重试。",
|
||||
dreamina_submit_timeout: "等待官方即梦 CLI 确认提交超时,为避免重复扣费,任务没有自动重试。",
|
||||
dreamina_submit_receipt_missing: "官方即梦 CLI 未返回任务凭证,为避免重复扣费,任务没有自动重试。",
|
||||
dreamina_submission_unknown: "提交结果待确认,为避免重复扣费未自动重试。",
|
||||
};
|
||||
|
||||
export function generationErrorCode(error: unknown) {
|
||||
if (error && typeof error === "object" && "code" in error && typeof (error as { code?: unknown }).code === "string") {
|
||||
const code = (error as { code: string }).code;
|
||||
if (/^(?:dreamina|local_generation|origin)_[a-z0-9_]{2,80}$/.test(code)) return code;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function isContentModerationError(value: unknown) {
|
||||
const text = value instanceof Error ? value.message : String(value || "");
|
||||
return text.toLowerCase().includes(CONTENT_MODERATION_ERROR_CODE) || text.includes("内容审核未通过");
|
||||
@@ -84,9 +103,7 @@ function extractWrappedProviderMessage(raw: string) {
|
||||
const requestFailure = raw.match(/^Request failed with status code \d{3}\s*[::-]?\s*(.+)$/is);
|
||||
const wrapped = interfaceFailure?.[1] ?? requestFailure?.[1];
|
||||
if (!wrapped) return "";
|
||||
const message = wrapped
|
||||
.replace(/^\d{3}(?:\s+(?:Bad Gateway|Service Unavailable|Gateway Timeout|Internal Server Error|Not Found|Unauthorized|Forbidden|Too Many Requests))?\s*[::-]?\s*/i, "")
|
||||
.trim();
|
||||
const message = wrapped.replace(/^\d{3}(?:\s+(?:Bad Gateway|Service Unavailable|Gateway Timeout|Internal Server Error|Not Found|Unauthorized|Forbidden|Too Many Requests))?\s*[::-]?\s*/i, "").trim();
|
||||
return message && !containsInfrastructureDetails(message) ? message : "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user