Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/model/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StringI18nType } from '@/type/i18n';
import type { I18nStringType } from '@/type/i18n';
import type { ListModelsType } from './api/type';

export const modelsBuffer: {
Expand Down Expand Up @@ -180,7 +180,7 @@ export type ModelProviderIdType = keyof typeof ModelProviders;
export const aiproxyIdMap: Record<
number,
{
name: StringI18nType | string;
name: I18nStringType | string;
provider: ModelProviderIdType; // Use to sort,get avatar
avatar?: string;
}
Expand Down
12 changes: 12 additions & 0 deletions modules/tool/api/getType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { s } from '@/router/init';
import { contract } from '@/contract';
import { getToolType } from '@tool/controller';

export const getTypeHandler = s.route(contract.tool.getType, async () => {
const type = getToolType();

return {
status: 200,
body: type
};
});
11 changes: 10 additions & 1 deletion modules/tool/contract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import z from 'zod';
import { c } from '@/contract/init';
import { ToolListItemSchema, type ToolListItemType } from './type/api';
import { SystemVarSchema } from './type/tool';
import { ToolTypeEnum } from './type/tool';
import { ToolTypeListSchema } from './controller';

export const toolContract = c.router(
{
Expand All @@ -23,6 +24,14 @@ export const toolContract = c.router(
responses: {
200: ToolListItemSchema
}
},
getType: {
path: '/getType',
method: 'GET',
description: 'Get tool type',
responses: {
200: ToolTypeListSchema
}
}
},
{
Expand Down
18 changes: 18 additions & 0 deletions modules/tool/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import type { ToolType } from './type';
import { tools } from './constants';
import { ToolTypeEnum } from './type/tool';
import { ToolTypeTranslations } from './type/tool';
import z from 'zod';
import { I18nStringStrictSchema } from '@/type/i18n';

export const ToolTypeListSchema = z.array(
z.object({
type: z.nativeEnum(ToolTypeEnum),
name: I18nStringStrictSchema
})
);

export function getTool(toolId: string): ToolType | undefined {
return tools.find((tool) => tool.toolId === toolId);
}

export function getToolType(): z.infer<typeof ToolTypeListSchema> {
return Object.entries(ToolTypeTranslations).map(([type, name]) => ({
type: type as ToolTypeEnum,
name
}));
}
4 changes: 3 additions & 1 deletion modules/tool/router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { s } from '@/router/init';
import { getToolHandler } from './api/getTool';
import { getToolsHandler } from './api/list';
import { getTypeHandler } from './api/getType';
import { contract } from '@/contract';

export const toolRouter = s.router(contract.tool, {
getTool: getToolHandler,
list: getToolsHandler
list: getToolsHandler,
getType: getTypeHandler
});
6 changes: 3 additions & 3 deletions modules/tool/type/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InfoString } from '@/type/i18n';
import { I18nStringSchema } from '@/type/i18n';
import { z } from 'zod';
import { ToolTypeEnum, VersionListItemSchema } from './tool';
import { InputConfigSchema } from './fastgpt';
Expand All @@ -8,10 +8,10 @@ export const ToolListItemSchema = z.object({
parentId: z.string().optional().describe('The parent id of the tool'),
author: z.string().optional().describe('The author of the tool'),
courseUrl: z.string().optional().describe('The documentation URL of the tool'),
name: InfoString.describe('The name of the tool'),
name: I18nStringSchema.describe('The name of the tool'),
avatar: z.string().describe('The icon of the tool'),
versionList: z.array(VersionListItemSchema).min(1).describe('The version list'),
description: InfoString.describe('The introduction of the tool'),
description: I18nStringSchema.describe('The introduction of the tool'),
toolDescription: z
.string()
.optional()
Expand Down
79 changes: 76 additions & 3 deletions modules/tool/type/tool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from 'zod';
import { InfoString } from '@/type/i18n';
import { I18nStringSchema } from '@/type/i18n';
import { InputConfigSchema, InputSchema, OutputSchema } from './fastgpt';
import type { ToolTypeListSchema } from '@tool/controller';

/* Call back type */
export const SystemVarSchema = z.object({
Expand Down Expand Up @@ -91,6 +92,78 @@ export enum ToolTypeEnum {
other = 'other'
}

export type ToolClassifyType = {
[key in ToolTypeEnum]: {
en: string;
'zh-CN': string;
'zh-Hant': string;
};
};

/* Tool config is passed to FastGPT */
export const ToolTypeTranslations = {
[ToolTypeEnum.tools]: {
en: 'tools',
'zh-CN': '工具',
'zh-Hant': '工具'
},
[ToolTypeEnum.search]: {
en: 'search',
'zh-CN': '搜索',
'zh-Hant': '搜尋'
},
[ToolTypeEnum.multimodal]: {
en: 'multimodal',
'zh-CN': '多模态',
'zh-Hant': '多模態'
},
[ToolTypeEnum.communication]: {
en: 'communication',
'zh-CN': '通信',
'zh-Hant': '通訊'
},
[ToolTypeEnum.finance]: {
en: 'finance',
'zh-CN': '金融',
'zh-Hant': '金融'
},
[ToolTypeEnum.design]: {
en: 'design',
'zh-CN': '设计',
'zh-Hant': '設計'
},
[ToolTypeEnum.productivity]: {
en: 'productivity',
'zh-CN': '生产力',
'zh-Hant': '生產力'
},
[ToolTypeEnum.news]: {
en: 'news',
'zh-CN': '新闻',
'zh-Hant': '新聞'
},
[ToolTypeEnum.entertainment]: {
en: 'entertainment',
'zh-CN': '娱乐',
'zh-Hant': '娛樂'
},
[ToolTypeEnum.social]: {
en: 'social',
'zh-CN': '社交',
'zh-Hant': '社群'
},
[ToolTypeEnum.scientific]: {
en: 'scientific',
'zh-CN': '科学',
'zh-Hant': '科學'
},
[ToolTypeEnum.other]: {
en: 'other',
'zh-CN': '其他',
'zh-Hant': '其他'
}
} as const;

export const VersionListItemSchema = z.object({
value: z.string(),
description: z.string().optional(),
Expand All @@ -101,8 +174,8 @@ export const VersionListItemSchema = z.object({
export const ToolConfigSchema = z
.object({
toolId: z.string().optional().describe('The unique id of the tool'),
name: InfoString.describe('The name of the tool'),
description: InfoString.describe('The description of the tool'),
name: I18nStringSchema.describe('The name of the tool'),
description: I18nStringSchema.describe('The description of the tool'),
toolDescription: z
.string()
.optional()
Expand Down
2 changes: 0 additions & 2 deletions sdk/client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import createClient from '@/contract/client';
import type { SystemVarType } from '@tool/type/tool';
import type { StreamMessageType } from '@tool/type/tool';

export default createClient;

export type { SystemVarType, StreamMessageType as StreamMessage };

export { RunToolWithStream } from './runToolStream';
export { StreamDataAnswerTypeEnum } from '@tool/type/tool';
export { ModelProviders, aiproxyIdMap } from '@model/constants';
12 changes: 10 additions & 2 deletions src/type/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { z } from 'zod';

export const InfoString = z.object({
export const I18nStringSchema = z.object({
en: z.string(),
'zh-CN': z.string().optional(),
'zh-Hant': z.string().optional()
});
export type StringI18nType = z.infer<typeof InfoString>;

export const I18nStringStrictSchema = z.object({
en: z.string(),
'zh-CN': z.string(),
'zh-Hant': z.string()
});

export type I18nStringType = z.infer<typeof I18nStringSchema>;
export type I18nStringStrictType = z.infer<typeof I18nStringStrictSchema>;