From 759fa78a30b75a95db58e1f7d408338bcf848a29 Mon Sep 17 00:00:00 2001 From: Roland Date: Fri, 9 May 2025 13:30:21 +0800 Subject: [PATCH] feat: add the "Export Agent" feature (#5789) --- src/renderer/src/i18n/locales/en-us.json | 5 ++- src/renderer/src/i18n/locales/ja-jp.json | 3 ++ src/renderer/src/i18n/locales/ru-ru.json | 3 ++ src/renderer/src/i18n/locales/zh-cn.json | 3 ++ src/renderer/src/i18n/locales/zh-tw.json | 3 ++ .../src/pages/agents/components/AgentCard.tsx | 35 ++++++++++++++++++- 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 298e65b2fc..dae4ed6ca5 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -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" } } -} \ No newline at end of file +} diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index a881ba0f0b..046d2ff589 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -25,6 +25,9 @@ "invalid_format": "無効なエージェント形式:必須フィールドが不足しています" } }, + "export": { + "agent": "エージェントをエクスポート" + }, "delete.popup.content": "このエージェントを削除してもよろしいですか?", "edit.message.add.title": "追加", "edit.message.assistant.placeholder": "アシスタントのメッセージを入力", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index b9244b6de3..41242b74c3 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -45,6 +45,9 @@ "fetch_failed": "Не удалось получить данные по URL", "invalid_format": "Неверный формат агента: отсутствуют обязательные поля" } + }, + "export": { + "agent": "Экспорт агента" } }, "assistants": { diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 950c1d5145..a57c106b49 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -25,6 +25,9 @@ "invalid_format": "无效的代理格式:缺少必填字段" } }, + "export": { + "agent": "导出智能体" + }, "delete.popup.content": "确定要删除此智能体吗?", "edit.message.add.title": "添加", "edit.message.assistant.placeholder": "输入助手消息", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 6d782435f6..d91d8fb257 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -25,6 +25,9 @@ "invalid_format": "無效的代理人格式:缺少必填欄位" } }, + "export": { + "agent": "匯出智慧代理人" + }, "delete.popup.content": "確定要刪除此智慧代理人嗎?", "edit.message.add.title": "新增", "edit.message.assistant.placeholder": "輸入助手訊息", diff --git a/src/renderer/src/pages/agents/components/AgentCard.tsx b/src/renderer/src/pages/agents/components/AgentCard.tsx index d322061a56..a1d92d0a25 100644 --- a/src/renderer/src/pages/agents/components/AgentCard.tsx +++ b/src/renderer/src/pages/agents/components/AgentCard.tsx @@ -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 = ({ 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 = ({ agent, onClick, activegroup, getLocalizedGroupNa ManageAgentsPopup.show() } }, + { + key: 'export', + label: t('agents.export.agent'), + icon: , + onClick: (e: any) => { + e.domEvent.stopPropagation() + exportAgent() + } + }, { key: 'delete', label: t('common.delete'),