Skip to content

Commit 8e88a4a

Browse files
committed
test: (drop me!) test tool wrong build
1 parent 3fbdb9a commit 8e88a4a

File tree

8 files changed

+173
-0
lines changed

8 files changed

+173
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# xxx 系统工具
2+
3+
## 参考信息
4+
5+
### 参考文档
6+
7+
### 测试密钥环境变量名
8+
9+
### 工具集/子工具列表
10+
11+
描述工具集名称,以及子工具,子工具需要包含 ID,名字,哪些输入输出,例如:
12+
13+
```
14+
工具集名:Redis 操作,需要填写 redis 链接字符串做为密钥。
15+
16+
子工具列表:
17+
1. get;获取缓存了;输入 key;输出 value和是否存在
18+
2. set;设置缓存;输入 key,value,ttl;输出是否成功
19+
3. del;删除缓存;输入 key;输出是否成功
20+
```
21+
22+
---
23+
24+
下面由 AI 生成完整的设计文档
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# example tool
2+
3+
Write the introduction for your tool here.
4+
5+
You can insert a picture with following markdown
6+
7+
```markdown
8+
Insert a assets picture (you need to put you picture file in the assets dir)
9+
![](./assets/pic.png)
10+
11+
Or insert a public pic
12+
![](https://picsum.photos/200)
13+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineTool } from '@tool/type';
2+
import {
3+
FlowNodeInputTypeEnum,
4+
FlowNodeOutputTypeEnum,
5+
WorkflowIOValueTypeEnum
6+
} from '@tool/type/fastgpt';
7+
import { ToolTagEnum } from '@tool/type/tags';
8+
9+
export default defineTool({
10+
name: {
11+
'zh-CN': '模版工具',
12+
en: 'Template tool'
13+
},
14+
tags: [ToolTagEnum.enum.tools],
15+
description: {
16+
'zh-CN': '描述',
17+
en: 'description'
18+
},
19+
toolDescription:
20+
'tool description for ai to use, fallback to English description if not provided',
21+
secretInputConfig: [
22+
{
23+
key: 'apiKey',
24+
label: 'API Key',
25+
description: '可以在 xxx 获取',
26+
required: true,
27+
inputType: 'secret'
28+
}
29+
],
30+
versionList: [
31+
{
32+
value: '0.1.0',
33+
description: 'Default version',
34+
inputs: [
35+
{
36+
key: 'formatStr',
37+
label: '格式化字符串',
38+
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
39+
valueType: WorkflowIOValueTypeEnum.string
40+
}
41+
],
42+
outputs: [
43+
{
44+
valueType: WorkflowIOValueTypeEnum.string,
45+
key: 'time',
46+
label: '时间',
47+
description: '当前时间'
48+
}
49+
]
50+
}
51+
]
52+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import config from './config';
2+
import { InputType, OutputType, tool as toolCb } from './src';
3+
import { exportTool } from '@tool/utils/tool';
4+
5+
export default exportTool({
6+
toolCb,
7+
InputType,
8+
OutputType,
9+
config
10+
});
Lines changed: 20 additions & 0 deletions
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@fastgpt-plugins/tool-test1",
3+
"module": "index.ts",
4+
"type": "module",
5+
"scripts": {
6+
"build": "bun ../../../../scripts/build.ts"
7+
},
8+
"devDependencies": {
9+
"@types/bun": "latest"
10+
},
11+
"peerDependencies": {
12+
"typescript": "^5.0.0"
13+
},
14+
"dependencies": {
15+
"zod": "^3.24.3"
16+
}
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { format } from 'date-fns';
2+
import { z } from 'zod';
3+
import next from 'next';
4+
5+
export const InputType = z.object({
6+
apiKey: z.string(),
7+
formatStr: z.string().optional().default('yyyy-MM-dd HH:mm:ss')
8+
});
9+
10+
export const OutputType = z.object({
11+
time: z.string()
12+
});
13+
14+
export async function tool({
15+
apiKey,
16+
formatStr
17+
}: z.infer<typeof InputType>): Promise<z.infer<typeof OutputType>> {
18+
// 请求数据
19+
// const result = await fetch('https://api.example.com/data', {
20+
// method: 'POST',
21+
// body: JSON.stringify({
22+
// apiKey
23+
// })
24+
// });
25+
26+
return {
27+
time: format(new Date(), formatStr)
28+
};
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { expect, test } from 'vitest';
2+
import tool from '..';
3+
4+
test(async () => {
5+
expect(tool.name).toBeDefined();
6+
expect(tool.description).toBeDefined();
7+
expect(tool.cb).toBeDefined();
8+
});

0 commit comments

Comments
 (0)