@aidejs/tools 0.1.0-alpha.1 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,12 @@
13
13
  <a href="https://github.com/NN-Studio/Aidejs">
14
14
  <img src="https://img.shields.io/github/forks/NN-Studio/Aidejs" alt="forks">
15
15
  </a>
16
+ <a href="https://gitee.com/NN-Studio/Aidejs" target='_blank'>
17
+ <img alt="Gitee repo stars" src="https://gitee.com/NN-Studio/Aidejs/badge/star.svg">
18
+ </a>
19
+ <a href="https://gitee.com/NN-Studio/Aidejs">
20
+ <img src="https://gitee.com/NN-Studio/Aidejs/badge/fork.svg" alt="forks">
21
+ </a>
16
22
  </p>
17
23
 
18
24
  ## 功能列表
@@ -26,7 +32,8 @@
26
32
  <tr>
27
33
  <td>名称</td>
28
34
  <td>简介</td>
29
- <td>地址</td>
35
+ <td>下周统计</td>
36
+ <td>最新版本</td>
30
37
  </tr>
31
38
  </thead>
32
39
  <tbody>
@@ -34,14 +41,28 @@
34
41
  <td>@aidejs/core</td>
35
42
  <td>必选项,基础库,提供了最核心的LLM交互功能和插件系统</td>
36
43
  <td>
37
- <a href="https://www.npmjs.com/package/@aidejs/core" target="_blank">访问</a>
44
+ <a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@aidejs/core&interval=7">
45
+ <img src="https://img.shields.io/npm/dm/@aidejs/core.svg" alt="downloads">
46
+ </a>
47
+ </td>
48
+ <td>
49
+ <a href="https://www.npmjs.com/package/@aidejs/core">
50
+ <img src="https://img.shields.io/npm/v/@aidejs/core.svg" alt="npm">
51
+ </a>
38
52
  </td>
39
53
  </tr>
40
54
  <tr>
41
55
  <td>@aidejs/tools</td>
42
56
  <td>非必选,工具库,提供了各种实用的工具函数</td>
43
57
  <td>
44
- <a href="https://www.npmjs.com/package/@aidejs/tools" target="_blank">访问</a>
58
+ <a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@aidejs/tools&interval=7">
59
+ <img src="https://img.shields.io/npm/dm/@aidejs/tools.svg" alt="downloads">
60
+ </a>
61
+ </td>
62
+ <td>
63
+ <a href="https://www.npmjs.com/package/@aidejs/tools">
64
+ <img src="https://img.shields.io/npm/v/@aidejs/tools.svg" alt="npm">
65
+ </a>
45
66
  </td>
46
67
  </tr>
47
68
  </tbody>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidejs/tools",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "@aidejs/tools",
5
5
  "main": "./src/index.js",
6
6
  "typings": "./types/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  const { exec } = require('child_process');
2
- const os = require('os');
2
+ const { platform } = require('os');
3
3
 
4
4
  module.exports = {
5
5
  "description": {
@@ -20,10 +20,10 @@ module.exports = {
20
20
  },
21
21
  },
22
22
  "valueOf": function (args) {
23
- const platform = os.platform();
23
+ const platformValue = platform();
24
24
  let command;
25
25
 
26
- switch (platform) {
26
+ switch (platformValue) {
27
27
  case 'win32': // Windows
28
28
  command = `start ${args.url}`;
29
29
  break;
@@ -37,9 +37,10 @@ module.exports = {
37
37
  return new Promise(function (resolve, reject) {
38
38
  exec(command, (error) => {
39
39
  if (error) {
40
- reject(`无法打开浏览器: ${error}`);
40
+ console.log(error);
41
+ reject(`fail`);
41
42
  } else {
42
- resolve("成功打开了网页");
43
+ resolve("success");
43
44
  }
44
45
  });
45
46
  });
@@ -21,6 +21,7 @@ module.exports = {
21
21
  },
22
22
  },
23
23
  "valueOf": function (args) {
24
- return require("oipage/nodejs/disk/index.js").copyDisk(args.sourcePath, args.targetPath, true);
24
+ require("oipage/nodejs/disk/index.js").copyDisk(args.sourcePath, args.targetPath, true);
25
+ return "success";
25
26
  }
26
27
  };
@@ -17,6 +17,7 @@ module.exports = {
17
17
  },
18
18
  },
19
19
  "valueOf": function (args) {
20
- return require("oipage/nodejs/disk/index.js").deleteDisk(args.diskPath, true);
20
+ require("oipage/nodejs/disk/index.js").deleteDisk(args.diskPath, true);
21
+ return "success";
21
22
  }
22
23
  };
package/src/disk/index.js CHANGED
@@ -5,4 +5,8 @@ module.exports = [
5
5
  require('./deleteDisk'),
6
6
  require('./linkDisk'),
7
7
  require('./moveDisk'),
8
+ require('./pathValue'),
9
+ require('./newDisk'),
10
+ require('./typeDisk'),
11
+ require('./readFolder')
8
12
  ];
@@ -21,6 +21,7 @@ module.exports = {
21
21
  },
22
22
  },
23
23
  "valueOf": function (args) {
24
- return require("oipage/nodejs/disk/index.js").linkDisk(args.sourcePath, args.targetPath, true);
24
+ require("oipage/nodejs/disk/index.js").linkDisk(args.sourcePath, args.targetPath, true);
25
+ return "success";
25
26
  }
26
27
  };
@@ -21,6 +21,7 @@ module.exports = {
21
21
  },
22
22
  },
23
23
  "valueOf": function (args) {
24
- return require("oipage/nodejs/disk/index.js").moveDisk(args.sourcePath, args.targetPath, true);
24
+ require("oipage/nodejs/disk/index.js").moveDisk(args.sourcePath, args.targetPath, true);
25
+ return "success";
25
26
  }
26
27
  };
@@ -0,0 +1,37 @@
1
+ const { mkdirSync } = require("fs");
2
+
3
+ module.exports = {
4
+ "description": {
5
+ "type": "function",
6
+ "function": {
7
+ "name": "newDisk",
8
+ "description": "新建文件或文件夹",
9
+ "parameters": {
10
+ "type": "object",
11
+ "properties": {
12
+ "type": {
13
+ "type": "string",
14
+ "description": "目录类型,file=文件、folder=文件夹",
15
+ "enum": ["file", "folder"]
16
+ },
17
+ "diskPath": {
18
+ "type": "string",
19
+ "description": "需要创建的文件或文件夹的路径",
20
+ },
21
+ },
22
+ "required": ["type", "diskPath"],
23
+ },
24
+ },
25
+ },
26
+ "valueOf": function (args) {
27
+ if (args.type === "folder") {
28
+ mkdirSync(args.diskPath, { recursive: true });
29
+ return "success";
30
+ } else if (args.type === "file") {
31
+ require("oipage/nodejs/disk/index.js").writePlain(args.diskPath, "");
32
+ return "success";
33
+ } else {
34
+ return "fail";
35
+ }
36
+ }
37
+ };
@@ -0,0 +1,34 @@
1
+ const { homedir } = require("os");
2
+ const { join } = require("path");
3
+
4
+ module.exports = {
5
+ "description": {
6
+ "type": "function",
7
+ "function": {
8
+ "name": "pathValue",
9
+ "description": "获取指定的路径",
10
+ "parameters": {
11
+ "type": "object",
12
+ "properties": {
13
+ "type": {
14
+ "type": "string",
15
+ "description": "目录类型,current=当前路径、desktop=桌面路径、home=用户根路径",
16
+ "enum": ["desktop", "home"]
17
+ }
18
+ },
19
+ "required": ["type"],
20
+ },
21
+ },
22
+ },
23
+ "valueOf": function (args) {
24
+ if (args.type === "current") {
25
+ return process.cwd();
26
+ } else if (args.type === "home") {
27
+ return homedir();
28
+ } else if (args.type === "desktop") {
29
+ return join(homedir(), "./Desktop");
30
+ } else {
31
+ return "fail";
32
+ }
33
+ }
34
+ };
@@ -0,0 +1,24 @@
1
+ const { readdirSync } = require("fs");
2
+
3
+ module.exports = {
4
+ "description": {
5
+ "type": "function",
6
+ "function": {
7
+ "name": "readFolder",
8
+ "description": "获取文件夹的子文件和文件夹列表",
9
+ "parameters": {
10
+ "type": "object",
11
+ "properties": {
12
+ "folderPath": {
13
+ "type": "string",
14
+ "description": "需要获取的文件夹路径",
15
+ },
16
+ },
17
+ "required": ["folderPath"],
18
+ },
19
+ },
20
+ },
21
+ "valueOf": function (args) {
22
+ return readdirSync(args.folderPath).join("、");
23
+ }
24
+ };
@@ -0,0 +1,24 @@
1
+ const { lstatSync } = require("fs");
2
+
3
+ module.exports = {
4
+ "description": {
5
+ "type": "function",
6
+ "function": {
7
+ "name": "typeDisk",
8
+ "description": "判断路径类型,返回值如果是file表示文件、folder表示文件夹",
9
+ "parameters": {
10
+ "type": "object",
11
+ "properties": {
12
+ "diskPath": {
13
+ "type": "string",
14
+ "description": "需要判断的路径",
15
+ },
16
+ },
17
+ "required": ["diskPath"],
18
+ },
19
+ },
20
+ },
21
+ "valueOf": function (args) {
22
+ return lstatSync(args.diskPath).isDirectory() ? "folder" : "file";
23
+ }
24
+ };
@@ -21,6 +21,7 @@ module.exports = {
21
21
  },
22
22
  },
23
23
  "valueOf": function (args) {
24
- return require("oipage/nodejs/disk/index.js").writePlain(args.filepath, args.content);
24
+ require("oipage/nodejs/disk/index.js").writePlain(args.filepath, args.content);
25
+ return "success";
25
26
  }
26
27
  };
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- install(Aidejs) {
2
+ install(Aidejs, options) {
3
3
 
4
4
  // 工具列表
5
5
  const tools = {
@@ -10,9 +10,12 @@ module.exports = {
10
10
  // 注册工具
11
11
  for (let toolType in tools) {
12
12
  for (let toolItem of tools[toolType]) {
13
- let toolName = `aidejs_${toolType}_` + toolItem.description.function.name;
14
- toolItem.description.function.name = toolName;
15
- Aidejs.registerTool(toolName, toolItem);
13
+ let functionName = toolItem.description.function.name;
14
+ if (!options.filter || options.filter(toolType, functionName)) {
15
+ let toolName = `aidejs_${toolType}_` + functionName;
16
+ toolItem.description.function.name = toolName;
17
+ Aidejs.registerTool(toolName, toolItem);
18
+ }
16
19
  }
17
20
  }
18
21
  }
package/types/index.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import type Aidejs from "@aidejs/core"
2
2
 
3
- export default {
4
- install(Aidejs: Aidejs): void
3
+ export default class Tools {
4
+ static install(Aidejs: Aidejs, options?: {
5
+
6
+ /**
7
+ * 过滤若干不希望安装的工具
8
+ * @param toolType <string> 工具类型
9
+ * @param toolName <string> 工具名称
10
+ * @returns boolean 如果返回false,就表示当前工具不希望安装
11
+ */
12
+ filter?: (toolType: string, toolName: string) => boolean
13
+ }): void
5
14
  }