Integrate Canvas V2 subgraphs, editable edges and AI runs

This commit is contained in:
2026-11-06 19:59:56 +08:00
parent 3478daeccb
commit 05d96abd0e
35 changed files with 1626 additions and 443 deletions
+20 -4
View File
@@ -5,17 +5,22 @@ export type Profile = {
email: string | null;
avatar_url?: string | null;
};
export class ApiError extends Error {
constructor(code: string, readonly status: number, readonly details?: unknown, readonly retryAfter?: string | null) { super(code); this.name = "ApiError"; }
}
export async function api<T>(
path: string,
options: RequestInit = {},
): Promise<T> {
const res = await fetch("/api/foundry/" + path, {
...options,
headers: { "Content-Type": "application/json", ...options.headers },
headers: { ...(options.body instanceof FormData ? {} : { "Content-Type": "application/json" }), ...options.headers },
});
const body = await res.json().catch(() => null);
if (!res.ok)
throw new Error(body?.error?.code || body?.error || "request_failed");
if (!res.ok) {
const code = body?.error?.code || body?.error;
throw new ApiError(typeof code === "string" ? code : "request_failed", res.status, body?.details, res.headers.get("retry-after"));
}
return body as T;
}
export const PROJECT = process.env.NEXT_PUBLIC_FOUNDRY_PROJECT || "endoleap";
@@ -46,11 +51,22 @@ export const errorText = (error: unknown) => {
workspace_required: "请先创建或选择一个工作空间。",
invalid_workspace: "工作空间名称不符合要求,请修改后重试。",
invalid_title: "名称不能为空,且不能超过 300 字节(约 100 个汉字)。",
version_conflict: "图谱已在别处修改,请再次保存以读取最新版本。",
version_conflict: "画布已更新,本地草稿已保留,请导出备份或重新读取后处理冲突。",
invalid_profile: "请检查显示名称,以及用户名是否为 3–40 位小写字母、数字、下划线或连字符。",
forbidden: "你没有在此工作空间创建或编辑图谱的权限。",
invalid_canvas: "画布数据未通过服务端校验,请导出备份后检查节点内容。",
invalid_canvas_snapshot: "服务端画布数据格式无效,请重新读取或联系维护者。",
canvas_schema_upgrade_required: "这张画布已升级,请刷新以加载新版客户端。",
undo_receipt_expired: "撤销记录已过期,当前内容已保留。",
draft_recovery_required: "请先处理未同步的本地草稿。",
canvas_busy: "画布正在同步,请稍后重试。",
node_busy: "这个元素正在生成,请等待完成或先取消。",
model_unavailable: "模型暂时不可用,请重新选择。",
model_incompatible: "这个模型不支持当前元素的输出类型。",
ownership_conflict: "子画布关系已变化,请重新读取画布。",
execution_cycle: "执行路径中有循环,请先断开循环连接。",
queue_full: "生成队列已满,请稍后重试。",
context_too_large: "输入内容超出模型容量,请减少输入。",
canvas_too_large: "画布超过 5 MiB,请减少图片或拆分画布后重试。",
body_too_large: "画布内容过大,请减少图片或拆分画布。",
invalid_material: "画布名称或内容不符合要求,请修改后重试。",