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:
@@ -83,6 +83,34 @@ async def get_assistant(
|
||||
return _to_out(a)
|
||||
|
||||
|
||||
@router.post("/{assistant_id}/duplicate", response_model=AssistantOut)
|
||||
async def duplicate_assistant(
|
||||
assistant_id: str, session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
"""服务端整行复制:含真实 config(真 key),DB→DB,密钥不经过浏览器,副本可直接用。"""
|
||||
src = await session.get(Assistant, assistant_id)
|
||||
if not src:
|
||||
raise HTTPException(404, "助手不存在")
|
||||
a = Assistant(
|
||||
id=f"asst_{uuid.uuid4().hex[:12]}",
|
||||
name=f"{src.name} 副本",
|
||||
type=src.type,
|
||||
runtime_mode=src.runtime_mode,
|
||||
greeting=src.greeting,
|
||||
enable_interrupt=src.enable_interrupt,
|
||||
llm_credential_id=src.llm_credential_id,
|
||||
asr_credential_id=src.asr_credential_id,
|
||||
tts_credential_id=src.tts_credential_id,
|
||||
realtime_credential_id=src.realtime_credential_id,
|
||||
knowledge_base_id=src.knowledge_base_id,
|
||||
config=dict(src.config or {}), # 浅拷贝,避免与源行共享同一 dict
|
||||
)
|
||||
session.add(a)
|
||||
await session.commit()
|
||||
await session.refresh(a)
|
||||
return _to_out(a)
|
||||
|
||||
|
||||
@router.put("/{assistant_id}", response_model=AssistantOut)
|
||||
async def update_assistant(
|
||||
assistant_id: str,
|
||||
|
||||
Reference in New Issue
Block a user