Add duplicate functionality for assistants and credentials

Implement server-side duplication for both assistants and credentials, allowing users to create copies with unique IDs and modified names. Update the respective API routes and frontend components to handle duplication requests, ensuring sensitive information is securely managed. Enhance the AssistantPage and ComponentsModelsPage to support this new feature, including loading and error handling for the duplication process.
This commit is contained in:
Xin Wang
2026-06-09 09:48:43 +08:00
parent b444ea777c
commit 30b96bb3be
5 changed files with 642 additions and 163 deletions

View File

@@ -66,6 +66,83 @@ export const credentialsApi = {
method: "PUT",
body: JSON.stringify(body),
}),
// 服务端整行复制(含真 key,密钥不经浏览器)
duplicate: (id: string) =>
request<Credential>(`/api/credentials/${id}/duplicate`, { method: "POST" }),
remove: (id: string) =>
request<{ ok: boolean }>(`/api/credentials/${id}`, { method: "DELETE" }),
};
// ---------- 助手 ----------
export type AssistantType =
| "prompt"
| "workflow"
| "dify"
| "fastgpt"
| "opencode";
export type RuntimeMode = "pipeline" | "realtime";
/** 后端 AssistantOut。config 形态随 type 变,故用宽松 record */
export type Assistant = {
id: string;
name: string;
type: AssistantType;
runtimeMode: RuntimeMode;
greeting: string;
enableInterrupt: boolean;
llmCredentialId: string | null;
asrCredentialId: string | null;
ttsCredentialId: string | null;
realtimeCredentialId: string | null;
knowledgeBaseId: string | null;
config: Record<string, unknown>;
updatedAt?: string | null;
};
export type AssistantUpsert = {
name: string;
type: AssistantType;
runtimeMode: RuntimeMode;
greeting: string;
enableInterrupt: boolean;
llmCredentialId: string | null;
asrCredentialId: string | null;
ttsCredentialId: string | null;
realtimeCredentialId: string | null;
knowledgeBaseId: string | null;
config: Record<string, unknown>;
};
export const assistantsApi = {
list: () => request<Assistant[]>("/api/assistants"),
get: (id: string) => request<Assistant>(`/api/assistants/${id}`),
create: (body: AssistantUpsert) =>
request<Assistant>("/api/assistants", {
method: "POST",
body: JSON.stringify(body),
}),
update: (id: string, body: AssistantUpsert) =>
request<Assistant>(`/api/assistants/${id}`, {
method: "PUT",
body: JSON.stringify(body),
}),
// 服务端整行复制(含真 key,密钥不经浏览器)
duplicate: (id: string) =>
request<Assistant>(`/api/assistants/${id}/duplicate`, { method: "POST" }),
remove: (id: string) =>
request<{ ok: boolean }>(`/api/assistants/${id}`, { method: "DELETE" }),
};
// ---------- 知识库 ----------
export type KnowledgeBase = {
id: string;
name: string;
description: string;
embeddingCredentialId: string | null;
status: string;
updatedAt?: string | null;
};
export const knowledgeBasesApi = {
list: () => request<KnowledgeBase[]>("/api/knowledge-bases"),
};