mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-22 03:45:52 +00:00

* Match SSE for FastGPT (#5168) * Match SSE for FastGPT * Modify the judgment * Optimize logic for SSE transmission * Refactor imports * directly use workflowStreamResponse from props * improve error handling and streamline onStreamData logic * Refactor API client configuration * perf: system tool support sse * update doc --------- Co-authored-by: Zhuangzai fa <143257420+ctrlz526@users.noreply.github.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import createClient, { RunToolWithStream } from '@fastgpt-sdk/plugin';
|
|
import { PluginSourceEnum } from '@fastgpt/global/core/app/plugin/constants';
|
|
|
|
const BASE_URL = process.env.PLUGIN_BASE_URL || '';
|
|
const TOKEN = process.env.PLUGIN_TOKEN || '';
|
|
|
|
const client = createClient({
|
|
baseUrl: BASE_URL,
|
|
token: TOKEN
|
|
});
|
|
|
|
export async function getSystemToolList() {
|
|
const res = await client.tool.list();
|
|
|
|
if (res.status === 200) {
|
|
return res.body.map((item) => {
|
|
return {
|
|
...item,
|
|
id: `${PluginSourceEnum.systemTool}-${item.id}`,
|
|
parentId: item.parentId ? `${PluginSourceEnum.systemTool}-${item.parentId}` : undefined,
|
|
avatar:
|
|
item.avatar && item.avatar.startsWith('/imgs/tools/')
|
|
? `/api/system/pluginImgs/${item.avatar.replace('/imgs/tools/', '')}`
|
|
: item.avatar
|
|
};
|
|
});
|
|
}
|
|
|
|
return Promise.reject(res.body);
|
|
}
|
|
|
|
const runToolInstance = new RunToolWithStream({
|
|
baseUrl: BASE_URL,
|
|
token: TOKEN
|
|
});
|
|
export const runSystemTool = runToolInstance.run.bind(runToolInstance);
|