11// TODO:后续替换为 sdk
22import { LobeChatPlugins } from '@lobehub/lobe-chat-plugins' ;
33
4- import { PluginsMap } from '../../plugins' ;
54import { OpenAIPluginPayload } from '../../types/plugins' ;
65
76export const config = {
@@ -15,14 +14,14 @@ const INDEX_URL = `https://registry.npmmirror.com/${INDEX_PKG}/latest/files`;
1514export default async ( req : Request ) => {
1615 if ( req . method !== 'POST' ) return new Response ( 'Method Not Allowed' , { status : 405 } ) ;
1716
17+ const res = await fetch ( INDEX_URL ) ;
18+ const manifest : LobeChatPlugins = await res . json ( ) ;
19+ console . log ( 'manifest:' , manifest ) ;
20+
1821 const { name, arguments : args } = ( await req . json ( ) ) as OpenAIPluginPayload ;
1922
2023 console . log ( `检测到 functionCall: ${ name } ` ) ;
2124
22- const res = await fetch ( INDEX_URL ) ;
23- const manifest : LobeChatPlugins = await res . json ( ) ;
24- console . log ( manifest ) ;
25-
2625 const item = manifest . plugins . find ( ( i ) => i . name === name ) ;
2726
2827 // 先通过插件资产 endpoint 路径查询
@@ -33,16 +32,5 @@ export default async (req: Request) => {
3332 return new Response ( data ) ;
3433 }
3534
36- // TODO:兼容性代码,全量完成迁移后移除
37- const func = PluginsMap [ name ] ;
38-
39- if ( func ) {
40- const data = JSON . parse ( args ) ;
41- const result = await func . runner ( data ) ;
42-
43- console . log ( `[${ name } ]` , args , `result:` , JSON . stringify ( result , null , 2 ) . slice ( 0 , 3600 ) ) ;
44-
45- return new Response ( JSON . stringify ( result ) ) ;
46- }
4735 return ;
4836} ;
0 commit comments