feat: add the "Export Agent" feature (#5789)

This commit is contained in:
Roland 2025-05-09 13:30:21 +08:00 committed by GitHub
parent 45827890ac
commit be64faf9e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 50 additions and 2 deletions

View File

@ -25,6 +25,9 @@
"invalid_format": "Invalid agent format: missing required fields"
}
},
"export": {
"agent": "Export Agent"
},
"delete.popup.content": "Are you sure you want to delete this agent?",
"edit.message.add.title": "Add",
"edit.message.assistant.placeholder": "Enter assistant message",
@ -1634,4 +1637,4 @@
"visualization": "Visualization"
}
}
}
}

View File

@ -25,6 +25,9 @@
"invalid_format": "無効なエージェント形式:必須フィールドが不足しています"
}
},
"export": {
"agent": "エージェントをエクスポート"
},
"delete.popup.content": "このエージェントを削除してもよろしいですか?",
"edit.message.add.title": "追加",
"edit.message.assistant.placeholder": "アシスタントのメッセージを入力",

View File

@ -45,6 +45,9 @@
"fetch_failed": "Не удалось получить данные по URL",
"invalid_format": "Неверный формат агента: отсутствуют обязательные поля"
}
},
"export": {
"agent": "Экспорт агента"
}
},
"assistants": {

View File

@ -25,6 +25,9 @@
"invalid_format": "无效的代理格式:缺少必填字段"
}
},
"export": {
"agent": "导出智能体"
},
"delete.popup.content": "确定要删除此智能体吗?",
"edit.message.add.title": "添加",
"edit.message.assistant.placeholder": "输入助手消息",

View File

@ -25,6 +25,9 @@
"invalid_format": "無效的代理人格式:缺少必填欄位"
}
},
"export": {
"agent": "匯出智慧代理人"
},
"delete.popup.content": "確定要刪除此智慧代理人嗎?",
"edit.message.add.title": "新增",
"edit.message.assistant.placeholder": "輸入助手訊息",

View File

@ -1,4 +1,11 @@
import { DeleteOutlined, EditOutlined, EllipsisOutlined, PlusOutlined, SortAscendingOutlined } from '@ant-design/icons'
import {
DeleteOutlined,
EditOutlined,
EllipsisOutlined,
ExportOutlined,
PlusOutlined,
SortAscendingOutlined
} from '@ant-design/icons'
import CustomTag from '@renderer/components/CustomTag'
import { useAgents } from '@renderer/hooks/useAgents'
import AssistantSettingsPopup from '@renderer/pages/settings/AssistantSettings'
@ -35,6 +42,23 @@ const AgentCard: FC<Props> = ({ agent, onClick, activegroup, getLocalizedGroupNa
[removeAgent]
)
const exportAgent = useCallback(async () => {
const result = {
name: agent.name,
emoji: agent.emoji,
group: agent.group,
prompt: agent.prompt,
description: agent.description,
type: 'agent'
}
const resultStr = JSON.stringify(result, null, 2)
await window.api.file.save(`${agent.name}.json`, new TextEncoder().encode(resultStr), {
filters: [{ name: t('agents.import.file_filter'), extensions: ['json'] }]
})
}, [agent])
const menuItems = [
{
key: 'edit',
@ -63,6 +87,15 @@ const AgentCard: FC<Props> = ({ agent, onClick, activegroup, getLocalizedGroupNa
ManageAgentsPopup.show()
}
},
{
key: 'export',
label: t('agents.export.agent'),
icon: <ExportOutlined />,
onClick: (e: any) => {
e.domEvent.stopPropagation()
exportAgent()
}
},
{
key: 'delete',
label: t('common.delete'),