Add workflow support and enhance runtime configuration in models and services

- Introduce RuntimeModelResource and RuntimeKnowledgeBase classes to manage workflow resources.
- Update AssistantConfig to include workflow_model_resources and workflow_knowledge_bases for better integration.
- Refactor validation and processing logic in routes and services to accommodate workflow types.
- Implement dynamic variable support for workflow assistants and enhance graph normalization.
- Add ToolExecutor for reusable tool execution across different assistant types.
- Update various services to ensure compatibility with new workflow features and improve error handling.
This commit is contained in:
Xin Wang
2026-07-13 16:13:27 +08:00
parent 6108b00007
commit 32aef14ddb
27 changed files with 2563 additions and 910 deletions

View File

@@ -11,6 +11,35 @@ export const API_BASE =
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8000";
export type ModelType = "LLM" | "ASR" | "TTS" | "Realtime" | "Embedding" | "Agent";
function formatErrorDetail(detail: unknown): string | null {
if (typeof detail === "string") return detail;
if (Array.isArray(detail)) {
const messages = detail
.map((item) => {
if (!item || typeof item !== "object") return null;
const record = item as { loc?: unknown; msg?: unknown };
const message = typeof record.msg === "string" ? record.msg : null;
if (!message) return null;
const path = Array.isArray(record.loc)
? record.loc
.filter((part) => part !== "body")
.map(String)
.join(".")
: "";
return path ? `${path}${message}` : message;
})
.filter((message): message is string => Boolean(message));
return messages.length ? messages.join("") : null;
}
if (detail && typeof detail === "object") {
const record = detail as { message?: unknown; msg?: unknown };
if (typeof record.message === "string") return record.message;
if (typeof record.msg === "string") return record.msg;
}
return null;
}
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const isFormData = init?.body instanceof FormData;
const res = await fetch(`${API_BASE}${path}`, {
@@ -30,8 +59,8 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
if (!res.ok) {
let detail = `请求失败 (${res.status})`;
try {
const body = (await res.json()) as { detail?: string };
if (body?.detail) detail = body.detail;
const body = (await res.json()) as { detail?: unknown };
detail = formatErrorDetail(body?.detail) ?? detail;
} catch {
// 响应体不是 JSON,沿用默认错误信息
}