mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 16:00:51 +00:00
feat: Add discord channel for Agent (#11950)
This commit is contained in:
@@ -312,6 +312,47 @@ func (b *BaseApi) UpdateAgentTelegramConfig(c *gin.Context) {
|
||||
helper.Success(c)
|
||||
}
|
||||
|
||||
// @Tags AI
|
||||
// @Summary Get Agent Discord channel config
|
||||
// @Accept json
|
||||
// @Param request body dto.AgentDiscordConfigReq true "request"
|
||||
// @Success 200 {object} dto.AgentDiscordConfig
|
||||
// @Security ApiKeyAuth
|
||||
// @Security Timestamp
|
||||
// @Router /ai/agents/channel/discord/get [post]
|
||||
func (b *BaseApi) GetAgentDiscordConfig(c *gin.Context) {
|
||||
var req dto.AgentDiscordConfigReq
|
||||
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||
return
|
||||
}
|
||||
data, err := agentService.GetDiscordConfig(req)
|
||||
if err != nil {
|
||||
helper.BadRequest(c, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, data)
|
||||
}
|
||||
|
||||
// @Tags AI
|
||||
// @Summary Update Agent Discord channel config
|
||||
// @Accept json
|
||||
// @Param request body dto.AgentDiscordConfigUpdateReq true "request"
|
||||
// @Success 200
|
||||
// @Security ApiKeyAuth
|
||||
// @Security Timestamp
|
||||
// @Router /ai/agents/channel/discord/update [post]
|
||||
func (b *BaseApi) UpdateAgentDiscordConfig(c *gin.Context) {
|
||||
var req dto.AgentDiscordConfigUpdateReq
|
||||
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||
return
|
||||
}
|
||||
if err := agentService.UpdateDiscordConfig(req); err != nil {
|
||||
helper.BadRequest(c, err)
|
||||
return
|
||||
}
|
||||
helper.Success(c)
|
||||
}
|
||||
|
||||
// @Tags AI
|
||||
// @Summary Approve Agent Feishu pairing code
|
||||
// @Accept json
|
||||
|
||||
+24
-1
@@ -180,16 +180,39 @@ type AgentTelegramConfigUpdateReq struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
DmPolicy string `json:"dmPolicy" validate:"required"`
|
||||
BotToken string `json:"botToken" validate:"required"`
|
||||
Proxy string `json:"proxy"`
|
||||
}
|
||||
|
||||
type AgentTelegramConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
DmPolicy string `json:"dmPolicy"`
|
||||
BotToken string `json:"botToken"`
|
||||
Proxy string `json:"proxy"`
|
||||
}
|
||||
|
||||
type AgentChannelPairingApproveReq struct {
|
||||
AgentID uint `json:"agentId" validate:"required"`
|
||||
Type string `json:"type" validate:"required,oneof=feishu telegram"`
|
||||
Type string `json:"type" validate:"required,oneof=feishu telegram discord"`
|
||||
PairingCode string `json:"pairingCode" validate:"required"`
|
||||
}
|
||||
|
||||
type AgentDiscordConfigReq struct {
|
||||
AgentID uint `json:"agentId" validate:"required"`
|
||||
}
|
||||
|
||||
type AgentDiscordConfigUpdateReq struct {
|
||||
AgentID uint `json:"agentId" validate:"required"`
|
||||
Enabled bool `json:"enabled"`
|
||||
DmPolicy string `json:"dmPolicy" validate:"required"`
|
||||
GroupPolicy string `json:"groupPolicy" validate:"required,oneof=open allowlist disabled"`
|
||||
Token string `json:"token" validate:"required"`
|
||||
Proxy string `json:"proxy"`
|
||||
}
|
||||
|
||||
type AgentDiscordConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
DmPolicy string `json:"dmPolicy"`
|
||||
GroupPolicy string `json:"groupPolicy"`
|
||||
Token string `json:"token"`
|
||||
Proxy string `json:"proxy"`
|
||||
}
|
||||
|
||||
+113
-1
@@ -45,6 +45,8 @@ type IAgentService interface {
|
||||
UpdateFeishuConfig(req dto.AgentFeishuConfigUpdateReq) error
|
||||
GetTelegramConfig(req dto.AgentTelegramConfigReq) (*dto.AgentTelegramConfig, error)
|
||||
UpdateTelegramConfig(req dto.AgentTelegramConfigUpdateReq) error
|
||||
GetDiscordConfig(req dto.AgentDiscordConfigReq) (*dto.AgentDiscordConfig, error)
|
||||
UpdateDiscordConfig(req dto.AgentDiscordConfigUpdateReq) error
|
||||
ApproveChannelPairing(req dto.AgentChannelPairingApproveReq) error
|
||||
ApproveFeishuPairing(req dto.AgentFeishuPairingApproveReq) error
|
||||
}
|
||||
@@ -602,6 +604,48 @@ func (a AgentService) UpdateTelegramConfig(req dto.AgentTelegramConfigUpdateReq)
|
||||
Enabled: req.Enabled,
|
||||
DmPolicy: req.DmPolicy,
|
||||
BotToken: req.BotToken,
|
||||
Proxy: req.Proxy,
|
||||
})
|
||||
if err := writeOpenclawConfigRaw(agent.ConfigPath, conf); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a AgentService) GetDiscordConfig(req dto.AgentDiscordConfigReq) (*dto.AgentDiscordConfig, error) {
|
||||
agent, _, err := a.loadAgentAndInstall(req.AgentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conf, err := readOpenclawConfig(agent.ConfigPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := extractDiscordConfig(conf)
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (a AgentService) UpdateDiscordConfig(req dto.AgentDiscordConfigUpdateReq) error {
|
||||
agent, _, err := a.loadAgentAndInstall(req.AgentID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conf, err := readOpenclawConfig(agent.ConfigPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if req.DmPolicy == "" {
|
||||
req.DmPolicy = "pairing"
|
||||
}
|
||||
if req.GroupPolicy == "" {
|
||||
req.GroupPolicy = "open"
|
||||
}
|
||||
setDiscordConfig(conf, dto.AgentDiscordConfig{
|
||||
Enabled: req.Enabled,
|
||||
DmPolicy: req.DmPolicy,
|
||||
GroupPolicy: req.GroupPolicy,
|
||||
Token: req.Token,
|
||||
Proxy: req.Proxy,
|
||||
})
|
||||
if err := writeOpenclawConfigRaw(agent.ConfigPath, conf); err != nil {
|
||||
return err
|
||||
@@ -618,7 +662,7 @@ func (a AgentService) ApproveChannelPairing(req dto.AgentChannelPairingApproveRe
|
||||
if channelType == "" {
|
||||
channelType = "feishu"
|
||||
}
|
||||
if channelType != "feishu" && channelType != "telegram" {
|
||||
if channelType != "feishu" && channelType != "telegram" && channelType != "discord" {
|
||||
return fmt.Errorf("unsupported channel type: %s", channelType)
|
||||
}
|
||||
if err := cmd.RunDefaultBashCf(
|
||||
@@ -733,6 +777,9 @@ func setFeishuConfig(conf map[string]interface{}, config dto.AgentFeishuConfig)
|
||||
},
|
||||
},
|
||||
}
|
||||
if strings.EqualFold(config.DmPolicy, "open") {
|
||||
feishu["allowFrom"] = []string{"*"}
|
||||
}
|
||||
channels["feishu"] = feishu
|
||||
}
|
||||
|
||||
@@ -762,6 +809,9 @@ func extractTelegramConfig(conf map[string]interface{}) dto.AgentTelegramConfig
|
||||
if botToken, ok := telegram["botToken"].(string); ok {
|
||||
result.BotToken = botToken
|
||||
}
|
||||
if proxy, ok := telegram["proxy"].(string); ok {
|
||||
result.Proxy = proxy
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -772,9 +822,71 @@ func setTelegramConfig(conf map[string]interface{}, config dto.AgentTelegramConf
|
||||
"dmPolicy": config.DmPolicy,
|
||||
"botToken": config.BotToken,
|
||||
}
|
||||
if strings.EqualFold(config.DmPolicy, "open") {
|
||||
telegram["allowFrom"] = []string{"*"}
|
||||
}
|
||||
if strings.TrimSpace(config.Proxy) != "" {
|
||||
telegram["proxy"] = strings.TrimSpace(config.Proxy)
|
||||
}
|
||||
channels["telegram"] = telegram
|
||||
}
|
||||
|
||||
func extractDiscordConfig(conf map[string]interface{}) dto.AgentDiscordConfig {
|
||||
result := dto.AgentDiscordConfig{Enabled: true, DmPolicy: "pairing", GroupPolicy: "open"}
|
||||
channels, ok := conf["channels"].(map[string]interface{})
|
||||
if !ok {
|
||||
return result
|
||||
}
|
||||
discord, ok := channels["discord"].(map[string]interface{})
|
||||
if !ok {
|
||||
return result
|
||||
}
|
||||
if enabled, ok := discord["enabled"].(bool); ok {
|
||||
result.Enabled = enabled
|
||||
}
|
||||
if token, ok := discord["token"].(string); ok {
|
||||
result.Token = token
|
||||
}
|
||||
if groupPolicy, ok := discord["groupPolicy"].(string); ok && strings.TrimSpace(groupPolicy) != "" {
|
||||
result.GroupPolicy = groupPolicy
|
||||
}
|
||||
if proxy, ok := discord["proxy"].(string); ok {
|
||||
result.Proxy = proxy
|
||||
}
|
||||
if policy, ok := discord["dmPolicy"].(string); ok && strings.TrimSpace(policy) != "" {
|
||||
result.DmPolicy = policy
|
||||
return result
|
||||
}
|
||||
// backward compatibility: old nested style
|
||||
dm, ok := discord["dm"].(map[string]interface{})
|
||||
if ok {
|
||||
if policy, ok := dm["policy"].(string); ok && strings.TrimSpace(policy) != "" {
|
||||
result.DmPolicy = policy
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func setDiscordConfig(conf map[string]interface{}, config dto.AgentDiscordConfig) {
|
||||
channels := ensureChildMap(conf, "channels")
|
||||
discord := ensureChildMap(channels, "discord")
|
||||
discord["enabled"] = config.Enabled
|
||||
discord["token"] = config.Token
|
||||
discord["dmPolicy"] = config.DmPolicy
|
||||
discord["groupPolicy"] = config.GroupPolicy
|
||||
if strings.EqualFold(config.DmPolicy, "open") {
|
||||
discord["allowFrom"] = []string{"*"}
|
||||
} else {
|
||||
delete(discord, "allowFrom")
|
||||
}
|
||||
if strings.TrimSpace(config.Proxy) != "" {
|
||||
discord["proxy"] = strings.TrimSpace(config.Proxy)
|
||||
} else {
|
||||
delete(discord, "proxy")
|
||||
}
|
||||
delete(discord, "dm")
|
||||
}
|
||||
|
||||
func (a AgentService) syncAgentsByAccount(account *model.AgentAccount) error {
|
||||
agents, err := agentRepo.List(repo.WithByAccountID(account.ID))
|
||||
if err != nil {
|
||||
|
||||
@@ -56,6 +56,8 @@ func (a *AIToolsRouter) InitRouter(Router *gin.RouterGroup) {
|
||||
aiToolsRouter.POST("/agents/channel/feishu/approve", baseApi.ApproveAgentFeishuPairing)
|
||||
aiToolsRouter.POST("/agents/channel/telegram/get", baseApi.GetAgentTelegramConfig)
|
||||
aiToolsRouter.POST("/agents/channel/telegram/update", baseApi.UpdateAgentTelegramConfig)
|
||||
aiToolsRouter.POST("/agents/channel/discord/get", baseApi.GetAgentDiscordConfig)
|
||||
aiToolsRouter.POST("/agents/channel/discord/update", baseApi.UpdateAgentDiscordConfig)
|
||||
aiToolsRouter.POST("/agents/channel/pairing/approve", baseApi.ApproveAgentChannelPairing)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,6 +413,7 @@ export namespace AI {
|
||||
enabled: boolean;
|
||||
dmPolicy: string;
|
||||
botToken: string;
|
||||
proxy: string;
|
||||
}
|
||||
|
||||
export interface AgentTelegramConfigUpdateReq {
|
||||
@@ -420,11 +421,33 @@ export namespace AI {
|
||||
enabled: boolean;
|
||||
dmPolicy: string;
|
||||
botToken: string;
|
||||
proxy: string;
|
||||
}
|
||||
|
||||
export interface AgentChannelPairingApproveReq {
|
||||
agentId: number;
|
||||
type: 'feishu' | 'telegram';
|
||||
type: 'feishu' | 'telegram' | 'discord';
|
||||
pairingCode: string;
|
||||
}
|
||||
|
||||
export interface AgentDiscordConfigReq {
|
||||
agentId: number;
|
||||
}
|
||||
|
||||
export interface AgentDiscordConfig {
|
||||
enabled: boolean;
|
||||
dmPolicy: string;
|
||||
groupPolicy: string;
|
||||
token: string;
|
||||
proxy: string;
|
||||
}
|
||||
|
||||
export interface AgentDiscordConfigUpdateReq {
|
||||
agentId: number;
|
||||
enabled: boolean;
|
||||
dmPolicy: string;
|
||||
groupPolicy: string;
|
||||
token: string;
|
||||
proxy: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +156,14 @@ export const updateAgentTelegramConfig = (req: AI.AgentTelegramConfigUpdateReq)
|
||||
return http.post(`/ai/agents/channel/telegram/update`, req);
|
||||
};
|
||||
|
||||
export const getAgentDiscordConfig = (req: AI.AgentDiscordConfigReq) => {
|
||||
return http.post<AI.AgentDiscordConfig>(`/ai/agents/channel/discord/get`, req);
|
||||
};
|
||||
|
||||
export const updateAgentDiscordConfig = (req: AI.AgentDiscordConfigUpdateReq) => {
|
||||
return http.post(`/ai/agents/channel/discord/update`, req);
|
||||
};
|
||||
|
||||
export const approveAgentChannelPairing = (req: AI.AgentChannelPairingApproveReq) => {
|
||||
return http.post(`/ai/agents/channel/pairing/approve`, req);
|
||||
};
|
||||
|
||||
@@ -702,6 +702,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -698,6 +698,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -687,6 +687,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -684,6 +684,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -699,6 +699,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -696,6 +696,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -692,6 +692,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -706,6 +706,10 @@ const message = {
|
||||
channelsTab: 'Channels',
|
||||
feishu: 'Feishu',
|
||||
dmPolicy: 'DM Policy',
|
||||
groupPolicy: 'Group Policy',
|
||||
policyPairing: 'Pairing',
|
||||
policyOpen: 'Open',
|
||||
policyDisabled: 'Disabled',
|
||||
botName: 'Bot Name',
|
||||
appId: 'App ID',
|
||||
appSecret: 'App Secret',
|
||||
|
||||
@@ -674,6 +674,10 @@ const message = {
|
||||
channelsTab: '聊天渠道',
|
||||
feishu: '飛書',
|
||||
dmPolicy: '私聊策略',
|
||||
groupPolicy: '群組策略',
|
||||
policyPairing: '配對',
|
||||
policyOpen: '開放',
|
||||
policyDisabled: '禁用',
|
||||
botName: '機器人名稱',
|
||||
appId: '應用 App ID',
|
||||
appSecret: '應用 App Secret',
|
||||
|
||||
@@ -676,6 +676,10 @@ const message = {
|
||||
channelsTab: '聊天渠道',
|
||||
feishu: '飞书',
|
||||
dmPolicy: '私聊策略',
|
||||
groupPolicy: '群组策略',
|
||||
policyPairing: '配对码',
|
||||
policyOpen: '开放',
|
||||
policyDisabled: '禁用',
|
||||
botName: '机器人名称',
|
||||
appId: '应用 App ID',
|
||||
appSecret: '应用 App Secret',
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
<el-tab-pane label="Telegram" name="telegram">
|
||||
<TelegramTab ref="telegramRef" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="Discord" name="discord">
|
||||
<DiscordTab ref="discordRef" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</template>
|
||||
|
||||
@@ -14,18 +17,24 @@ import { nextTick, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import FeishuTab from './channels/feishu.vue';
|
||||
import TelegramTab from './channels/telegram.vue';
|
||||
import DiscordTab from './channels/discord.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const activeTab = ref('feishu');
|
||||
const agentId = ref(0);
|
||||
const feishuRef = ref();
|
||||
const telegramRef = ref();
|
||||
const discordRef = ref();
|
||||
|
||||
const loadCurrentTab = async () => {
|
||||
if (agentId.value <= 0) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
if (activeTab.value === 'discord') {
|
||||
await discordRef.value?.load(agentId.value);
|
||||
return;
|
||||
}
|
||||
if (activeTab.value === 'telegram') {
|
||||
await telegramRef.value?.load(agentId.value);
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-position="top">
|
||||
<el-form-item :label="t('commons.table.status')">
|
||||
<el-switch v-model="form.enabled" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('aiTools.agents.dmPolicy')" prop="dmPolicy">
|
||||
<el-select v-model="form.dmPolicy">
|
||||
<el-option :label="t('aiTools.agents.policyPairing')" value="pairing" />
|
||||
<el-option :label="t('aiTools.agents.policyOpen')" value="open" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('aiTools.agents.groupPolicy')" prop="groupPolicy">
|
||||
<el-select v-model="form.groupPolicy">
|
||||
<el-option :label="t('aiTools.agents.policyOpen')" value="open" />
|
||||
<el-option :label="t('aiTools.agents.policyDisabled')" value="disabled" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="Token" prop="token">
|
||||
<el-input v-model="form.token" type="password" show-password />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('setting.proxy')">
|
||||
<el-input v-model="form.proxy" placeholder="http://127.0.0.1:7890" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="saving" @click="saveChannel">
|
||||
{{ t('commons.button.save') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider />
|
||||
|
||||
<el-form-item :label="t('aiTools.agents.pairingCode')">
|
||||
<el-input v-model="pairingCode" :placeholder="t('aiTools.agents.pairingCodePlaceholder')" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="approving" @click="approvePairing">
|
||||
{{ t('aiTools.agents.approvePairing') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue';
|
||||
import type { FormInstance } from 'element-plus';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { AI } from '@/api/interface/ai';
|
||||
import { approveAgentChannelPairing, getAgentDiscordConfig, updateAgentDiscordConfig } from '@/api/modules/ai';
|
||||
import { MsgSuccess, MsgWarning } from '@/utils/message';
|
||||
import { Rules } from '@/global/form-rules';
|
||||
|
||||
const { t } = useI18n();
|
||||
const saving = ref(false);
|
||||
const approving = ref(false);
|
||||
const agentId = ref(0);
|
||||
const pairingCode = ref('');
|
||||
const formRef = ref<FormInstance>();
|
||||
|
||||
const form = reactive<AI.AgentDiscordConfig>({
|
||||
enabled: true,
|
||||
dmPolicy: 'pairing',
|
||||
groupPolicy: 'open',
|
||||
token: '',
|
||||
proxy: '',
|
||||
});
|
||||
|
||||
const rules = reactive({
|
||||
dmPolicy: [Rules.requiredSelect],
|
||||
groupPolicy: [Rules.requiredSelect],
|
||||
token: [Rules.requiredInput],
|
||||
});
|
||||
|
||||
const load = async (id: number) => {
|
||||
agentId.value = id;
|
||||
pairingCode.value = '';
|
||||
const res = await getAgentDiscordConfig({ agentId: id });
|
||||
Object.assign(form, res.data || {});
|
||||
if (!form.dmPolicy) {
|
||||
form.dmPolicy = 'pairing';
|
||||
}
|
||||
if (!form.groupPolicy) {
|
||||
form.groupPolicy = 'open';
|
||||
}
|
||||
};
|
||||
|
||||
const saveChannel = async () => {
|
||||
if (!agentId.value || !formRef.value) {
|
||||
return;
|
||||
}
|
||||
await formRef.value.validate();
|
||||
saving.value = true;
|
||||
try {
|
||||
await updateAgentDiscordConfig({
|
||||
agentId: agentId.value,
|
||||
enabled: form.enabled,
|
||||
dmPolicy: form.dmPolicy || 'pairing',
|
||||
groupPolicy: form.groupPolicy || 'open',
|
||||
token: form.token,
|
||||
proxy: form.proxy,
|
||||
});
|
||||
MsgSuccess(t('aiTools.agents.saveSuccess'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const approvePairing = async () => {
|
||||
if (!agentId.value) {
|
||||
return;
|
||||
}
|
||||
if (!pairingCode.value) {
|
||||
MsgWarning(t('aiTools.agents.pairingCodeRequired'));
|
||||
return;
|
||||
}
|
||||
approving.value = true;
|
||||
try {
|
||||
await approveAgentChannelPairing({
|
||||
agentId: agentId.value,
|
||||
type: 'discord',
|
||||
pairingCode: pairingCode.value,
|
||||
});
|
||||
MsgSuccess(t('aiTools.agents.pairingApproveSuccess'));
|
||||
pairingCode.value = '';
|
||||
} finally {
|
||||
approving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
load,
|
||||
});
|
||||
</script>
|
||||
@@ -10,7 +10,8 @@
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('aiTools.agents.dmPolicy')" prop="dmPolicy">
|
||||
<el-select v-model="form.dmPolicy">
|
||||
<el-option label="pairing" value="pairing" />
|
||||
<el-option :label="t('aiTools.agents.policyPairing')" value="pairing" />
|
||||
<el-option :label="t('aiTools.agents.policyOpen')" value="open" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('aiTools.agents.botName')" prop="botName">
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('aiTools.agents.dmPolicy')" prop="dmPolicy">
|
||||
<el-select v-model="form.dmPolicy">
|
||||
<el-option label="pairing" value="pairing" />
|
||||
<el-option :label="t('aiTools.agents.policyPairing')" value="pairing" />
|
||||
<el-option :label="t('aiTools.agents.policyOpen')" value="open" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="Bot Token" prop="botToken">
|
||||
<el-input v-model="form.botToken" type="password" show-password />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('setting.proxy')">
|
||||
<el-input v-model="form.proxy" placeholder="http://127.0.0.1:7890" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="saving" @click="saveChannel">
|
||||
{{ t('commons.button.save') }}
|
||||
@@ -50,6 +54,7 @@ const form = reactive<AI.AgentTelegramConfig>({
|
||||
enabled: true,
|
||||
dmPolicy: 'pairing',
|
||||
botToken: '',
|
||||
proxy: '',
|
||||
});
|
||||
|
||||
const rules = reactive({
|
||||
@@ -79,6 +84,7 @@ const saveChannel = async () => {
|
||||
enabled: form.enabled,
|
||||
dmPolicy: form.dmPolicy || 'pairing',
|
||||
botToken: form.botToken,
|
||||
proxy: form.proxy,
|
||||
});
|
||||
MsgSuccess(t('aiTools.agents.saveSuccess'));
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user