diff --git a/next.config.mjs b/next.config.mjs index e30d5cbe3e80..6aece5e24ba7 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -3,10 +3,6 @@ import nextPWA from 'next-pwa'; const isProd = process.env.NODE_ENV === 'production'; const API_END_PORT_URL = process.env.API_END_PORT_URL || ''; -// chat plugin market -const PLUGIN_RUNNER_BASE_URL = - process.env.PLUGIN_RUNNER_BASE_URL || 'https://chat-plugins.lobehub.vercel.app'; - const withPWA = nextPWA({ dest: 'public', register: true, @@ -35,9 +31,8 @@ const nextConfig = { destination: `${API_END_PORT_URL}/api/openai`, }, { - source: '/api/plugins', - // refs to: https://github.com/lobehub/chat-plugin-server - destination: `${PLUGIN_RUNNER_BASE_URL}/api/v1/runner`, + source: '/api/plugins-dev', + destination: `${API_END_PORT_URL}/api/plugins`, }, ]; }, diff --git a/package.json b/package.json index 399e4114d89b..4207227c1035 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "@emoji-mart/data": "^1", "@emoji-mart/react": "^1", "@icons-pack/react-simple-icons": "^8", + "@lobehub/chat-plugin-sdk": "latest", "@lobehub/ui": "latest", "@vercel/analytics": "^1", "ahooks": "^3", diff --git a/src/pages/api/plugins.api.ts b/src/pages/api/plugins.api.ts new file mode 100644 index 000000000000..016f5264de5c --- /dev/null +++ b/src/pages/api/plugins.api.ts @@ -0,0 +1,10 @@ +export const runtime = 'edge'; + +// chat plugin gateway +// refs to: https://github.com/lobehub/chat-plugins-gateway +const PLUGIN_GATEWAY_URL = process.env.PLUGIN_GATEWAY_URL || 'https://chat-plugins.lobehub.com'; + +export default async function handler(req: Request) { + const payload = await req.text(); + return fetch(`${PLUGIN_GATEWAY_URL}/api/v1/runner`, { body: payload, method: 'POST' }); +} diff --git a/src/services/plugin.ts b/src/services/plugin.ts index e73d7dac73f6..572a902e93c0 100644 --- a/src/services/plugin.ts +++ b/src/services/plugin.ts @@ -1,6 +1,7 @@ +import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk'; + import { LOBE_CHAT_ACCESS_CODE } from '@/const/fetch'; import { useGlobalStore } from '@/store/global'; -import { OpenAIPluginPayload } from '@/types/plugin'; import { URLS } from './url'; @@ -13,7 +14,7 @@ interface FetchChatModelOptions { * 专门用于对话的 fetch */ export const fetchPlugin = async ( - params: Partial, + params: PluginRequestPayload, options?: FetchChatModelOptions, ) => { const res = await fetch(URLS.plugins, { diff --git a/src/services/url.ts b/src/services/url.ts index b813c1359882..f18b774bd92c 100644 --- a/src/services/url.ts +++ b/src/services/url.ts @@ -4,5 +4,5 @@ const prefix = isDev ? '-dev' : ''; export const URLS = { openai: '/api/openai' + prefix, - plugins: '/api/plugins', + plugins: '/api/plugins' + prefix, };