Skip to content

Commit

Permalink
♻️ refactor: refactor plugin request (lobehub#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Aug 21, 2023
1 parent 7c25d3a commit 23efee3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
9 changes: 2 additions & 7 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`,
},
];
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/pages/api/plugins.api.ts
Original file line number Diff line number Diff line change
@@ -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' });
}
5 changes: 3 additions & 2 deletions src/services/plugin.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +14,7 @@ interface FetchChatModelOptions {
* 专门用于对话的 fetch
*/
export const fetchPlugin = async (
params: Partial<OpenAIPluginPayload>,
params: PluginRequestPayload,
options?: FetchChatModelOptions,
) => {
const res = await fetch(URLS.plugins, {
Expand Down
2 changes: 1 addition & 1 deletion src/services/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ const prefix = isDev ? '-dev' : '';

export const URLS = {
openai: '/api/openai' + prefix,
plugins: '/api/plugins',
plugins: '/api/plugins' + prefix,
};

0 comments on commit 23efee3

Please sign in to comment.