feat: 支持开关指定内置插件

This commit is contained in:
Hk-Gosuto
2023-09-04 21:59:42 +08:00
parent c5cc16ca09
commit c9c5ab2a9b
17 changed files with 909 additions and 8 deletions

32
app/plugins/cn.ts Normal file
View File

@@ -0,0 +1,32 @@
import { BuiltinPlugin } from "./typing";
export const CN_PLUGINS: BuiltinPlugin[] = [
{
name: "搜索引擎",
toolName: "web-search",
lang: "cn",
description: "搜索引擎的网络搜索功能工具。",
builtin: true,
createdAt: 1693744292000,
enable: true,
},
{
name: "计算器",
toolName: "calculator",
lang: "cn",
description: "计算器是一个用于计算数学表达式的工具。",
builtin: true,
createdAt: 1693744292000,
enable: true,
},
{
name: "网页浏览器",
toolName: "web-browser",
lang: "cn",
description:
"一个用于与网页进行交互的工具,可以从网页中提取信息或总结其内容。",
builtin: true,
createdAt: 1693744292000,
enable: true,
},
];

33
app/plugins/en.ts Normal file
View File

@@ -0,0 +1,33 @@
import { BuiltinPlugin } from "./typing";
export const EN_PLUGINS: BuiltinPlugin[] = [
{
name: "WebSearch",
toolName: "web-search",
lang: "en",
description: "Web search function tool for search engines.",
builtin: true,
createdAt: 1693744292000,
enable: true,
},
{
name: "Calculator",
toolName: "calculator",
lang: "en",
description:
"The Calculator class is a tool used to evaluate mathematical expressions. It extends the base Tool class.",
builtin: true,
createdAt: 1693744292000,
enable: true,
},
{
name: "WebBrowser",
toolName: "web-browser",
lang: "en",
description:
"A class designed to interact with web pages, either to extract information from them or to summarize their content.",
builtin: true,
createdAt: 1693744292000,
enable: true,
},
];

27
app/plugins/index.ts Normal file
View File

@@ -0,0 +1,27 @@
import { Plugin } from "../store/plugin";
import { CN_PLUGINS } from "./cn";
import { EN_PLUGINS } from "./en";
import { type BuiltinPlugin } from "./typing";
export { type BuiltinPlugin } from "./typing";
export const BUILTIN_PLUGIN_ID = 100000;
export const BUILTIN_PLUGIN_STORE = {
buildinId: BUILTIN_PLUGIN_ID,
plugins: {} as Record<string, BuiltinPlugin>,
get(id?: string) {
if (!id) return undefined;
return this.plugins[id] as Plugin | undefined;
},
add(m: BuiltinPlugin) {
const plugin = { ...m, id: this.buildinId++, builtin: true };
this.plugins[plugin.id] = plugin;
return plugin;
},
};
export const BUILTIN_PLUGINS: BuiltinPlugin[] = [
...CN_PLUGINS,
...EN_PLUGINS,
].map((m) => BUILTIN_PLUGIN_STORE.add(m));

5
app/plugins/typing.ts Normal file
View File

@@ -0,0 +1,5 @@
import { type Plugin } from "../store/plugin";
export type BuiltinPlugin = Omit<Plugin, "id"> & {
builtin: Boolean;
};