From cf2e1a473e1cbf28c763625cef295d9bccd203fd Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Sat, 26 Apr 2025 19:54:54 +0800 Subject: [PATCH] feat: fetch adapters from api --- .../home/bots/components/bot-form/BotForm.tsx | 8 +- web_ui/src/app/home/mock-api/index.ts | 641 ------------------ 2 files changed, 4 insertions(+), 645 deletions(-) diff --git a/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx b/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx index 72b5f69f..4eb6918e 100644 --- a/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx +++ b/web_ui/src/app/home/bots/components/bot-form/BotForm.tsx @@ -1,5 +1,4 @@ import {BotFormEntity, IBotFormEntity} from "@/app/home/bots/components/bot-form/BotFormEntity"; -import {fetchAdapterList} from "@/app/home/mock-api/index" import {Button, Form, Input, Select, Space} from "antd"; import {useEffect, useState} from "react"; import {IChooseAdapterEntity} from "@/app/home/bots/components/bot-form/ChooseAdapterEntity"; @@ -11,6 +10,7 @@ import { import {UUID} from 'uuidjs' import DynamicFormComponent from "@/app/home/components/dynamic-form/DynamicFormComponent"; import {ICreateLLMField} from "@/app/home/models/ICreateLLMField"; +import {httpClient} from "@/app/infra/http/HttpClient"; export default function BotForm({ initBotId, @@ -39,10 +39,10 @@ export default function BotForm({ async function initBotFormComponent() { // 拉取adapter - const rawAdapterList = await fetchAdapterList() + const rawAdapterList = await httpClient.getAdapters() // 初始化适配器选择列表 setAdapterNameList( - rawAdapterList.map(item => { + rawAdapterList.adapters.map(item => { return { label: item.label.zh_CN, value: item.name @@ -50,7 +50,7 @@ export default function BotForm({ }) ) // 初始化适配器表单map - rawAdapterList.forEach(rawAdapter => { + rawAdapterList.adapters.forEach(rawAdapter => { adapterNameToDynamicConfigMap.set( rawAdapter.name, rawAdapter.spec.config.map(item => diff --git a/web_ui/src/app/home/mock-api/index.ts b/web_ui/src/app/home/mock-api/index.ts index 3c4e40c9..ec6db0ef 100644 --- a/web_ui/src/app/home/mock-api/index.ts +++ b/web_ui/src/app/home/mock-api/index.ts @@ -1,647 +1,6 @@ import {GetMetaDataResponse} from "@/app/infra/api/api-types/pipelines/GetMetaDataResponse"; import {ApiResponse} from "@/app/infra/api/api-types"; -export async function fetchAdapterList() { - return [ - { - "description": { - "en_US": "Discord Adapter", - "zh_CN": "Discord 适配器" - }, - "icon": "", - "label": { - "en_US": "Discord", - "zh_CN": "Discord" - }, - "name": "discord", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "Client ID", - "zh_CN": "客户端ID" - }, - "name": "client_id", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "QQ Official API (Webhook)", - "zh_CN": "QQ 官方 API (Webhook)" - }, - "icon": "", - "label": { - "en_US": "QQ Official API", - "zh_CN": "QQ 官方 API" - }, - "name": "qqofficial", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "App ID", - "zh_CN": "应用ID" - }, - "name": "appid", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Secret", - "zh_CN": "密钥" - }, - "name": "secret", - "required": true, - "type": "string" - }, - { - "default": 2284, - "label": { - "en_US": "Port", - "zh_CN": "监听端口" - }, - "name": "port", - "required": true, - "type": "integer" - }, - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "Telegram Adapter", - "zh_CN": "电报适配器" - }, - "icon": "", - "label": { - "en_US": "Telegram", - "zh_CN": "电报" - }, - "name": "telegram", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "WeCom Adapter", - "zh_CN": "企业微信适配器" - }, - "icon": "", - "label": { - "en_US": "WeCom", - "zh_CN": "企业微信" - }, - "name": "wecom", - "spec": { - "config": [ - { - "default": "0.0.0.0", - "label": { - "en_US": "Host", - "zh_CN": "监听主机" - }, - "name": "host", - "required": true, - "type": "string" - }, - { - "default": 2290, - "label": { - "en_US": "Port", - "zh_CN": "监听端口" - }, - "name": "port", - "required": true, - "type": "integer" - }, - { - "default": "", - "label": { - "en_US": "Corpid", - "zh_CN": "企业ID" - }, - "name": "corpid", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Secret", - "zh_CN": "密钥" - }, - "name": "secret", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "EncodingAESKey", - "zh_CN": "消息加解密密钥" - }, - "name": "EncodingAESKey", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Contacts Secret", - "zh_CN": "通讯录密钥" - }, - "name": "contacts_secret", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "GeWeChat Adapter", - "zh_CN": "GeWeChat 适配器" - }, - "icon": "", - "label": { - "en_US": "GeWeChat", - "zh_CN": "GeWeChat(个人微信)" - }, - "name": "gewechat", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "GeWeChat URL", - "zh_CN": "GeWeChat URL" - }, - "name": "gewechat_url", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "GeWeChat file download URL", - "zh_CN": "GeWeChat 文件下载URL" - }, - "name": "gewechat_file_url", - "required": true, - "type": "string" - }, - { - "default": 2286, - "label": { - "en_US": "Port", - "zh_CN": "端口" - }, - "name": "port", - "required": true, - "type": "integer" - }, - { - "default": "", - "label": { - "en_US": "Callback URL", - "zh_CN": "回调URL" - }, - "name": "callback_url", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "App ID", - "zh_CN": "应用ID" - }, - "name": "app_id", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "OneBot v11 Adapter", - "zh_CN": "OneBot v11 适配器" - }, - "icon": "", - "label": { - "en_US": "OneBot v11 Adapter", - "zh_CN": "OneBot v11 适配器" - }, - "name": "aiocqhttp", - "spec": { - "config": [ - { - "default": "0.0.0.0", - "label": { - "en_US": "Host", - "zh_CN": "主机" - }, - "name": "host", - "required": true, - "type": "string" - }, - { - "default": 2280, - "label": { - "en_US": "Port", - "zh_CN": "端口" - }, - "name": "port", - "required": true, - "type": "integer" - }, - { - "default": "", - "label": { - "en_US": "Access Token", - "zh_CN": "访问令牌" - }, - "name": "access-token", - "required": false, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "Official Account Adapter", - "zh_CN": "微信公众号适配器" - }, - "icon": "", - "label": { - "en_US": "Official Account", - "zh_CN": "微信公众号" - }, - "name": "officialaccount", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "EncodingAESKey", - "zh_CN": "消息加解密密钥" - }, - "name": "EncodingAESKey", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "App ID", - "zh_CN": "应用ID" - }, - "name": "AppID", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "App Secret", - "zh_CN": "应用密钥" - }, - "name": "AppSecret", - "required": true, - "type": "string" - }, - { - "default": "0.0.0.0", - "label": { - "en_US": "Host", - "zh_CN": "监听主机" - }, - "name": "host", - "required": true, - "type": "string" - }, - { - "default": 2287, - "label": { - "en_US": "Port", - "zh_CN": "监听端口" - }, - "name": "port", - "required": true, - "type": "integer" - } - ] - } - }, - { - "description": { - "en_US": "Nakuru Adapter", - "zh_CN": "Nakuru 适配器(go-cqhttp)" - }, - "icon": "", - "label": { - "en_US": "Nakuru", - "zh_CN": "Nakuru" - }, - "name": "nakuru", - "spec": { - "config": [ - { - "default": "127.0.0.1", - "label": { - "en_US": "Host", - "zh_CN": "主机" - }, - "name": "host", - "required": true, - "type": "string" - }, - { - "default": 5700, - "label": { - "en_US": "HTTP Port", - "zh_CN": "HTTP端口" - }, - "name": "http_port", - "required": true, - "type": "integer" - }, - { - "default": 8080, - "label": { - "en_US": "WebSocket Port", - "zh_CN": "WebSocket端口" - }, - "name": "ws_port", - "required": true, - "type": "integer" - }, - { - "default": "", - "label": { - "en_US": "Token", - "zh_CN": "令牌" - }, - "name": "token", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "QQ Official API (WebSocket)", - "zh_CN": "QQ 官方 API (WebSocket)" - }, - "icon": "", - "label": { - "en_US": "QQBotPy", - "zh_CN": "QQBotPy" - }, - "name": "qq-botpy", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "App ID", - "zh_CN": "应用ID" - }, - "name": "appid", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Secret", - "zh_CN": "密钥" - }, - "name": "secret", - "required": true, - "type": "string" - }, - { - "default": [], - "label": { - "en_US": "Intents", - "zh_CN": "权限" - }, - "name": "intents", - "required": true, - "type": "array[string]" - } - ] - } - }, - { - "description": { - "en_US": "DingTalk Adapter", - "zh_CN": "钉钉适配器" - }, - "icon": "", - "label": { - "en_US": "DingTalk", - "zh_CN": "钉钉" - }, - "name": "dingtalk", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "Client ID", - "zh_CN": "客户端ID" - }, - "name": "client_id", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Client Secret", - "zh_CN": "客户端密钥" - }, - "name": "client_secret", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Robot Code", - "zh_CN": "机器人代码" - }, - "name": "robot_code", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Robot Name", - "zh_CN": "机器人名称" - }, - "name": "robot_name", - "required": true, - "type": "string" - } - ] - } - }, - { - "description": { - "en_US": "Lark Adapter", - "zh_CN": "飞书适配器" - }, - "icon": "", - "label": { - "en_US": "Lark", - "zh_CN": "飞书" - }, - "name": "lark", - "spec": { - "config": [ - { - "default": "", - "label": { - "en_US": "App ID", - "zh_CN": "应用ID" - }, - "name": "app_id", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "App Secret", - "zh_CN": "应用密钥" - }, - "name": "app_secret", - "required": true, - "type": "string" - }, - { - "default": "", - "label": { - "en_US": "Bot Name", - "zh_CN": "机器人名称" - }, - "name": "bot_name", - "required": true, - "type": "string" - }, - { - "default": false, - "label": { - "en_US": "Enable Webhook Mode", - "zh_CN": "启用Webhook模式" - }, - "name": "enable-webhook", - "required": true, - "type": "boolean" - }, - { - "default": 2285, - "label": { - "en_US": "Webhook Port", - "zh_CN": "Webhook端口" - }, - "name": "port", - "required": true, - "type": "integer" - }, - { - "default": "", - "label": { - "en_US": "Encrypt Key", - "zh_CN": "加密密钥" - }, - "name": "encrypt-key", - "required": true, - "type": "string" - } - ] - } - } - ] -} - export async function fetchPipelineMetaData(): Promise> { return { "code": 0,