Skip to content

Commit 76f1980

Browse files
committed
feat: add getType endpoint to tool API for retrieving tool types and translations
1 parent 65d6ad6 commit 76f1980

File tree

6 files changed

+117
-4
lines changed

6 files changed

+117
-4
lines changed

modules/tool/api/getType.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { s } from '@/router/init';
2+
import { contract } from '@/contract';
3+
import { getToolType } from '@tool/controller';
4+
5+
export const getTypeHandler = s.route(contract.tool.getType, async () => {
6+
const type = getToolType();
7+
8+
return {
9+
status: 200,
10+
body: type
11+
};
12+
});

modules/tool/contract.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import z from 'zod';
22
import { c } from '@/contract/init';
33
import { ToolListItemSchema, type ToolListItemType } from './type/api';
4-
import { SystemVarSchema } from './type/tool';
4+
import { ToolTypeEnum } from './type/tool';
55

66
export const toolContract = c.router(
77
{
@@ -23,6 +23,23 @@ export const toolContract = c.router(
2323
responses: {
2424
200: ToolListItemSchema
2525
}
26+
},
27+
getType: {
28+
path: '/getType',
29+
method: 'GET',
30+
description: 'Get tool type',
31+
responses: {
32+
200: z.array(
33+
z.object({
34+
type: z.nativeEnum(ToolTypeEnum),
35+
name: z.object({
36+
en: z.string(),
37+
'zh-CN': z.string(),
38+
'zh-Hant': z.string()
39+
})
40+
})
41+
)
42+
}
2643
}
2744
},
2845
{

modules/tool/controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import type { ToolType } from './type';
22
import { tools } from './constants';
3+
import type { ToolTypeEnum } from './type/tool';
4+
import { ToolTypeTranslations } from './type/tool';
35

46
export function getTool(toolId: string): ToolType | undefined {
57
return tools.find((tool) => tool.toolId === toolId);
68
}
9+
10+
export function getToolType(): Array<{
11+
type: ToolTypeEnum;
12+
name: { en: string; 'zh-CN': string; 'zh-Hant': string };
13+
}> {
14+
return Object.entries(ToolTypeTranslations).map(([type, name]) => ({
15+
type: type as ToolTypeEnum,
16+
name
17+
}));
18+
}

modules/tool/router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { s } from '@/router/init';
22
import { getToolHandler } from './api/getTool';
33
import { getToolsHandler } from './api/list';
4+
import { getTypeHandler } from './api/getType';
45
import { contract } from '@/contract';
56

67
export const toolRouter = s.router(contract.tool, {
78
getTool: getToolHandler,
8-
list: getToolsHandler
9+
list: getToolsHandler,
10+
getType: getTypeHandler
911
});

modules/tool/type/tool.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,78 @@ export enum ToolTypeEnum {
9191
other = 'other'
9292
}
9393

94+
export type ToolClassifyType = {
95+
[key in ToolTypeEnum]: {
96+
en: string;
97+
'zh-CN': string;
98+
'zh-Hant': string;
99+
};
100+
};
101+
102+
/* Tool config is passed to FastGPT */
103+
export const ToolTypeTranslations = {
104+
[ToolTypeEnum.tools]: {
105+
en: 'tools',
106+
'zh-CN': '工具',
107+
'zh-Hant': '工具'
108+
},
109+
[ToolTypeEnum.search]: {
110+
en: 'search',
111+
'zh-CN': '搜索',
112+
'zh-Hant': '搜尋'
113+
},
114+
[ToolTypeEnum.multimodal]: {
115+
en: 'multimodal',
116+
'zh-CN': '多模态',
117+
'zh-Hant': '多模態'
118+
},
119+
[ToolTypeEnum.communication]: {
120+
en: 'communication',
121+
'zh-CN': '通信',
122+
'zh-Hant': '通信'
123+
},
124+
[ToolTypeEnum.finance]: {
125+
en: 'finance',
126+
'zh-CN': '金融',
127+
'zh-Hant': '金融'
128+
},
129+
[ToolTypeEnum.design]: {
130+
en: 'design',
131+
'zh-CN': '设计',
132+
'zh-Hant': '設計'
133+
},
134+
[ToolTypeEnum.productivity]: {
135+
en: 'productivity',
136+
'zh-CN': '生产力',
137+
'zh-Hant': '生產力'
138+
},
139+
[ToolTypeEnum.news]: {
140+
en: 'news',
141+
'zh-CN': '新闻',
142+
'zh-Hant': '新聞'
143+
},
144+
[ToolTypeEnum.entertainment]: {
145+
en: 'entertainment',
146+
'zh-CN': '娱乐',
147+
'zh-Hant': '娛樂'
148+
},
149+
[ToolTypeEnum.social]: {
150+
en: 'social',
151+
'zh-CN': '社交',
152+
'zh-Hant': '社交'
153+
},
154+
[ToolTypeEnum.scientific]: {
155+
en: 'scientific',
156+
'zh-CN': '科学',
157+
'zh-Hant': '科學'
158+
},
159+
[ToolTypeEnum.other]: {
160+
en: 'other',
161+
'zh-CN': '其他',
162+
'zh-Hant': '其他'
163+
}
164+
} as const;
165+
94166
export const VersionListItemSchema = z.object({
95167
value: z.string(),
96168
description: z.string().optional(),

sdk/client.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import createClient from '@/contract/client';
22
import type { SystemVarType } from '@tool/type/tool';
33
import type { StreamMessageType } from '@tool/type/tool';
4-
54
export default createClient;
65

76
export type { SystemVarType, StreamMessageType as StreamMessage };
8-
97
export { RunToolWithStream } from './runToolStream';
108
export { StreamDataAnswerTypeEnum } from '@tool/type/tool';
119
export { ModelProviders, aiproxyIdMap } from '@model/constants';

0 commit comments

Comments
 (0)