@fastgpt-plugin/cli 0.1.0-beta.4 → 0.1.0-beta.5

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/package.json CHANGED
@@ -1,28 +1,29 @@
1
1
  {
2
2
  "name": "@fastgpt-plugin/cli",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.5",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "bin": {
10
- "@fastgpt-plugin/cli": "index.js"
10
+ "@fastgpt-plugin/cli": "index.js",
11
+ "fastgpt-plugin": "index.js"
11
12
  },
12
13
  "files": [
13
14
  "dist",
14
15
  "index.js",
15
- "templates"
16
+ "templates",
17
+ "skills"
16
18
  ],
17
19
  "scripts": {
18
20
  "build": "tsdown",
19
21
  "build:verbose": "tsdown",
20
22
  "test": "vitest run",
21
- "dev": "bun run src/index.ts",
22
- "prepublishOnly": "npm run build"
23
+ "dev": "tsx src/index.ts",
24
+ "prepublishOnly": "pnpm run build"
23
25
  },
24
26
  "dependencies": {
25
- "@fastgpt-plugin/helpers": "0.0.1-alpha.6",
26
27
  "@oxc-parser/binding-wasm32-wasi": "^0.112.0",
27
28
  "@inquirer/prompts": "^8.2.0",
28
29
  "commander": "^14.0.3",
@@ -30,7 +31,9 @@
30
31
  "es-toolkit": "^1.44.0",
31
32
  "oxc-parser": "^0.112.0",
32
33
  "tsdown": "^0.20.1",
33
- "yazl": "^3.3.1"
34
+ "yazl": "^3.3.1",
35
+ "yaml": "^2.6.1",
36
+ "zod": "^4"
34
37
  },
35
38
  "devDependencies": {
36
39
  "@types/yazl": "^3.3.0",
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: cli-usage
3
+ description: 使用 FastGPT plugin CLI 时启用,适用于创建插件项目、构建 dist 产物、校验构建输出、打包 .pkg 文件,以及指导用户选择 create/build/check/pack 命令和参数。该技能使用通用说明风格,可被 Claude、Codex 等代理直接阅读。
4
+ ---
5
+
6
+ # FastGPT CLI 使用技能
7
+
8
+ 在需要“使用 `apps/cli` 这个命令行工具”时使用这个技能,不用于修改 CLI 源码。
9
+
10
+ ## 适用场景
11
+
12
+ - 想创建一个新的 FastGPT 插件项目
13
+ - 想把插件源码构建成 `dist` 产物
14
+ - 想检查 `dist` 下的构建结果是否符合约定
15
+ - 想把构建产物打成 `.pkg`
16
+ - 不确定该用 `create`、`build`、`check` 还是 `pack`
17
+
18
+ ## CLI 范围
19
+
20
+ CLI 入口在 `apps/cli/src/cmd.ts`,当前主要命令有:
21
+
22
+ - `create`
23
+ - `build`
24
+ - `check`
25
+ - `pack`
26
+
27
+ 包名与可执行名见 `apps/cli/package.json`:
28
+
29
+ - `@fastgpt-plugin/cli`
30
+ - `fastgpt-plugin`
31
+
32
+ ## 常用命令
33
+
34
+ 推荐两种调用方式:
35
+
36
+ ```bash
37
+ npx @fastgpt-plugin/cli <command>
38
+ ```
39
+
40
+ ```bash
41
+ pnpm fastgpt-plugin <command>
42
+ ```
43
+
44
+ ### 1. 创建插件项目
45
+
46
+ 创建单工具:
47
+
48
+ ```bash
49
+ npx @fastgpt-plugin/cli create my-tool --type tool
50
+ ```
51
+
52
+ 创建工具集:
53
+
54
+ ```bash
55
+ npx @fastgpt-plugin/cli create my-suite --type tool-suite
56
+ ```
57
+
58
+ 常用参数:
59
+
60
+ - `--cwd <path>`: 指定项目创建目录
61
+ - `--description <desc>`: 指定插件描述
62
+
63
+ 说明:
64
+
65
+ - `tool` 会生成单工具模板
66
+ - `tool-suite` 会生成工具集模板
67
+ - 模板目录在 `apps/cli/templates/tool`
68
+
69
+ ### 2. 构建插件
70
+
71
+ ```bash
72
+ npx @fastgpt-plugin/cli build --entry ./path/to/plugin --output ./dist
73
+ ```
74
+
75
+ 常用参数:
76
+
77
+ - `--entry <path>`: 插件源码根目录
78
+ - `--output <path>`: 构建输出目录,默认 `./dist`
79
+ - `--minify`: 是否压缩
80
+ - `--format esm|cjs`: 输出格式
81
+
82
+ 适用时机:
83
+
84
+ - 想先拿到 `dist/index.js`、`dist/manifest.json` 等产物
85
+ - `pack` 前先单独确认构建结果
86
+
87
+ ### 3. 检查构建输出
88
+
89
+ ```bash
90
+ npx @fastgpt-plugin/cli check --entry ./path/to/plugin --output ./dist
91
+ ```
92
+
93
+ 它会检查构建产物是否包含并满足约定:
94
+
95
+ - `manifest.json`
96
+ - `index.js`
97
+ - logo 引用
98
+
99
+ 适用时机:
100
+
101
+ - 打包前做一次快速校验
102
+ - CI 中校验插件产物格式
103
+
104
+ ### 4. 打包为 .pkg
105
+
106
+ ```bash
107
+ npx @fastgpt-plugin/cli pack --entry ./path/to/plugin --dist ./dist --output ./out
108
+ ```
109
+
110
+ 常用参数:
111
+
112
+ - `--entry <path>`: 插件源码根目录
113
+ - `--dist <path>`: 构建产物目录,默认 `./dist`
114
+ - `--output <path>`: `.pkg` 输出目录
115
+ - `--name <name>`: 包名,默认取入口目录名
116
+
117
+ 说明:
118
+
119
+ - `pack` 会先执行构建,再把构建产物打成 `.pkg`
120
+ - `.pkg` 里按约定包含 `index.js`、`manifest.json`、logo、可选 `README.md` 和 `assets/**`
121
+
122
+ ## 选择建议
123
+
124
+ - 只想生成项目骨架:用 `create`
125
+ - 已有源码,想得到构建产物:用 `build`
126
+ - 已有 `dist`,想校验格式:用 `check`
127
+ - 想直接得到最终 `.pkg`:用 `pack`
128
+
129
+ ## 排查建议
130
+
131
+ - 模板生成不符合预期:检查 `apps/cli/templates/tool`
132
+ - 命令参数不生效:检查 `apps/cli/src/commands/*.ts` 的 Commander 定义
133
+ - 测试命令找不到用例:优先在 `apps/cli` 目录下运行 `pnpm test`
134
+
135
+ ## 验证
136
+
137
+ 在 `apps/cli` 目录下:
138
+
139
+ ```bash
140
+ pnpm fastgpt-plugin --help
141
+ ```
142
+
143
+ 如果已经安装依赖并希望用 pnpm 执行:
144
+
145
+ ```bash
146
+ pnpm fastgpt-plugin create my-tool --type tool
147
+ ```
@@ -5,7 +5,7 @@
5
5
  ## 开发
6
6
 
7
7
  ```bash
8
- bun install
9
- bun run build
10
- bun run test
8
+ pnpm install
9
+ pnpm run build
10
+ pnpm run test
11
11
  ```
@@ -0,0 +1,35 @@
1
+ import { createToolHandler, defineTool } from '@fastgpt-plugin/sdk-factory';
2
+ import z from 'zod';
3
+
4
+ const handler = createToolHandler({
5
+ inputSchema: z.object({
6
+ delay: z.number()
7
+ }),
8
+ outputSchema: z.object({}),
9
+ handler: async (input, _ctx) => {
10
+ await new Promise((resolve) => setTimeout(resolve, input.delay));
11
+ return {};
12
+ }
13
+ });
14
+
15
+ const tool = defineTool({
16
+ manifest: {
17
+ description: {
18
+ en: 'Delay for a specified amount of time',
19
+ 'zh-CN': '延迟指定的时间'
20
+ },
21
+ name: {
22
+ en: 'Delay',
23
+ 'zh-CN': '延迟工具'
24
+ },
25
+ pluginId: 'delay',
26
+ version: '1.0.0',
27
+ versionDescription: {
28
+ en: 'Initial version',
29
+ 'zh-CN': '初始版本'
30
+ }
31
+ },
32
+ handler
33
+ });
34
+
35
+ export default tool;
@@ -0,0 +1,109 @@
1
+ import { defineToolSet } from 'sdk/factory/dist';
2
+ import { createToolHandler } from 'sdk/factory/src';
3
+ import z from 'zod';
4
+
5
+ const secretSchema = z.object({
6
+ host: z.string(),
7
+ port: z.number(),
8
+ username: z.string(),
9
+ password: z.string(),
10
+ database: z.string()
11
+ });
12
+
13
+ const mysqlHandler = createToolHandler({
14
+ inputSchema: z.object({
15
+ query: z.string()
16
+ }),
17
+ outputSchema: z.object({
18
+ results: z.array(z.record(z.string(), z.unknown()))
19
+ }),
20
+ secretSchema,
21
+ handler: async (input, ctx) => {
22
+ return {
23
+ results: [
24
+ {
25
+ query: input.query,
26
+ host: ctx.secrets?.host,
27
+ port: ctx.secrets?.port,
28
+ username: ctx.secrets?.username,
29
+ password: ctx.secrets?.password,
30
+ database: ctx.secrets?.database,
31
+ db: 'MySQL'
32
+ }
33
+ ]
34
+ };
35
+ }
36
+ });
37
+
38
+ const pgsqlHandler = createToolHandler({
39
+ inputSchema: z.object({
40
+ query: z.string()
41
+ }),
42
+ outputSchema: z.object({
43
+ results: z.array(z.record(z.string(), z.unknown()))
44
+ }),
45
+ secretSchema,
46
+ handler: async (input, ctx) => {
47
+ return {
48
+ results: [
49
+ {
50
+ query: input.query,
51
+ host: ctx.secrets?.host,
52
+ port: ctx.secrets?.port,
53
+ username: ctx.secrets?.username,
54
+ password: ctx.secrets?.password,
55
+ database: ctx.secrets?.database,
56
+ db: 'PostgreSQL'
57
+ }
58
+ ]
59
+ };
60
+ }
61
+ });
62
+
63
+ export default defineToolSet({
64
+ manifest: {
65
+ pluginId: 'dbops',
66
+ name: {
67
+ en: 'DB Operations',
68
+ 'zh-CN': '数据库操作'
69
+ },
70
+ description: {
71
+ en: 'A suite of tools for database operations, including MySQL, PostgreSQL, SQL Server, Oracle, and ClickHouse.',
72
+ 'zh-CN':
73
+ '一套用于数据库操作的工具,包括 MySQL、PostgreSQL、SQL Server、Oracle 和 ClickHouse。'
74
+ },
75
+ version: '1.0.0',
76
+ versionDescription: {
77
+ en: 'Initial version with basic database operation tools.',
78
+ 'zh-CN': '初始版本,包含基本的数据库操作工具。'
79
+ },
80
+ author: 'test author'
81
+ },
82
+ children: [
83
+ {
84
+ description: {
85
+ en: 'MySQL database operation tool',
86
+ 'zh-CN': 'MySQL 数据库操作工具'
87
+ },
88
+ name: {
89
+ en: 'MySQL Tool',
90
+ 'zh-CN': 'MySQL 工具'
91
+ },
92
+ id: 'mysql',
93
+ handler: mysqlHandler
94
+ },
95
+ {
96
+ description: {
97
+ en: 'PostgreSQL database operation tool',
98
+ 'zh-CN': 'PostgreSQL 数据库操作工具'
99
+ },
100
+ name: {
101
+ en: 'PostgreSQL Tool',
102
+ 'zh-CN': 'PostgreSQL 工具'
103
+ },
104
+ id: 'pgsql',
105
+ handler: pgsqlHandler
106
+ }
107
+ ],
108
+ secretSchema
109
+ });
@@ -13,7 +13,7 @@
13
13
  "dependencies": {},
14
14
  "devDependencies": {
15
15
  "@fastgpt-plugin/cli": "catalog:",
16
- "@fastgpt-plugin/helpers": "catalog:",
16
+ "@fastgpt-plugin/sdk-factory": "catalog:",
17
17
  "typescript": "catalog:",
18
18
  "vitest": "catalog:",
19
19
  "zod": "catalog:"
@@ -1,28 +0,0 @@
1
- import { defineTool, WorkflowIOValueTypeEnum, ToolTagEnum } from '@fastgpt-plugin/helpers';
2
-
3
- export default defineTool({
4
- tags: [ToolTagEnum.tools],
5
- name: {
6
- 'zh-CN': '{{name}}',
7
- en: '{{name}}'
8
- },
9
- description: {
10
- 'zh-CN': '{{description}}',
11
- en: '{{description}}'
12
- },
13
- versionList: [
14
- {
15
- value: '0.0.1',
16
- description: 'Initial version',
17
- inputs: [],
18
- outputs: [
19
- {
20
- key: 'time',
21
- valueType: WorkflowIOValueTypeEnum.string,
22
- label: '时间',
23
- description: '当前时间'
24
- }
25
- ]
26
- }
27
- ]
28
- });
@@ -1,11 +0,0 @@
1
- import { exportTool } from '@fastgpt-plugin/helpers/tools/helper';
2
- import config from './config';
3
- import { InputSchema, OutputSchema } from './src/schemas';
4
- import { handler } from './src/tool';
5
-
6
- export default exportTool({
7
- handler,
8
- InputSchema,
9
- OutputSchema,
10
- config
11
- });
@@ -1,9 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- export const InputSchema = z.object({});
4
- export type Input = z.infer<typeof InputSchema>;
5
-
6
- export const OutputSchema = z.object({
7
- time: z.string().nonempty()
8
- });
9
- export type Output = z.infer<typeof OutputSchema>;
@@ -1,17 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { InputSchema, OutputSchema } from './schemas';
3
- import { tool } from './tool';
4
- import { mockedEventEmitter, mockedSystemVar } from '@fastgpt-plugin/helpers/tools/mocks';
5
-
6
- describe('get-time', () => {
7
- it('should run with valid IO schemas', async () => {
8
- const input = InputSchema.parse({});
9
- const result = await tool(input, {
10
- systemVar: mockedSystemVar,
11
- emitter: mockedEventEmitter
12
- });
13
-
14
- const output = OutputSchema.parse(result);
15
- expect(output).toBeDefined();
16
- });
17
- });
@@ -1,8 +0,0 @@
1
- import type { ToolContextType } from '@fastgpt-plugin/helpers/tools/schemas/req';
2
- import type { Input, Output } from './schemas';
3
-
4
- export async function handler(_: Input, ctx: ToolContextType): Promise<Output> {
5
- const { systemVar } = ctx;
6
-
7
- return { time: systemVar.time };
8
- }
@@ -1,11 +0,0 @@
1
- # {{name}}
2
-
3
- {{description}}
4
-
5
- ## 开发
6
-
7
- ```bash
8
- bun install
9
- bun run build
10
- bun run test
11
- ```
@@ -1,29 +0,0 @@
1
- import { defineTool, ToolTagEnum, WorkflowIOValueTypeEnum } from '@fastgpt-plugin/helpers';
2
-
3
- export default defineTool({
4
- tags: [ToolTagEnum.tools],
5
- name: {
6
- 'zh-CN': '{{name}}',
7
- en: '{{name}}'
8
- },
9
- description: {
10
- 'zh-CN': '{{description}}',
11
- en: '{{description}}'
12
- },
13
- icon: 'core/workflow/template/{{name}}',
14
- versionList: [
15
- {
16
- value: '0.0.1',
17
- description: 'Default version',
18
- inputs: [],
19
- outputs: [
20
- {
21
- key: 'time',
22
- valueType: WorkflowIOValueTypeEnum.string,
23
- label: '时间',
24
- description: '当前时间'
25
- }
26
- ]
27
- }
28
- ]
29
- });
@@ -1,11 +0,0 @@
1
- import { exportTool } from '@fastgpt-plugin/helpers/tools/helper';
2
- import config from './config';
3
- import { InputSchema, OutputSchema } from './src/schemas';
4
- import { handler } from './src/tool';
5
-
6
- export default exportTool({
7
- handler,
8
- InputSchema,
9
- OutputSchema,
10
- config
11
- });
@@ -1,4 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
2
- <rect width="64" height="64" rx="8" fill="#e0e7ff" />
3
- <text x="32" y="40" text-anchor="middle" font-size="24" fill="#4338ca">?</text>
4
- </svg>
@@ -1,9 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- export const InputSchema = z.object({});
4
- export type Input = z.infer<typeof InputSchema>;
5
-
6
- export const OutputSchema = z.object({
7
- time: z.string().nonempty()
8
- });
9
- export type Output = z.infer<typeof OutputSchema>;
@@ -1,37 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { tool } from './tool';
3
- import { InputType, OutputType } from './schemas';
4
-
5
- describe('{{name}} child tool', () => {
6
- it('should run with valid IO schemas', async () => {
7
- const input = InputType.parse({});
8
- const result = await tool(input, {
9
- systemVar: {
10
- user: {
11
- id: 'test',
12
- username: 'test',
13
- contact: 'test',
14
- membername: 'test',
15
- teamName: 'test',
16
- teamId: 'test',
17
- name: 'test'
18
- },
19
- app: {
20
- id: 'test',
21
- name: 'test'
22
- },
23
- tool: {
24
- id: 'test',
25
- version: '0.0.1'
26
- },
27
- time: new Date().toISOString()
28
- },
29
- streamResponse: () => {
30
- // noop
31
- }
32
- });
33
-
34
- const output = OutputType.parse(result);
35
- expect(output).toBeDefined();
36
- });
37
- });
@@ -1,8 +0,0 @@
1
- import type { ToolContextType } from '@fastgpt-plugin/helpers/tools/schemas/req';
2
- import type { Input, Output } from './schemas';
3
-
4
- export async function handler(_: Input, ctx: ToolContextType): Promise<Output> {
5
- const { systemVar } = ctx;
6
-
7
- return { time: systemVar.time };
8
- }
@@ -1,19 +0,0 @@
1
- import { defineToolSet, ToolTagEnum } from '@fastgpt-plugin/helpers';
2
-
3
- export default defineToolSet({
4
- name: {
5
- 'zh-CN': '企业微信智能表',
6
- en: 'WeCom Smart Sheet'
7
- },
8
- tags: [ToolTagEnum.tools],
9
- description: {
10
- 'zh-CN':
11
- '提供企业微信智能表的完整操作功能,包括文档创建、子表管理、视图管理、字段管理及记录 CRUD 等。',
12
- en: 'Provides comprehensive WeCom Smart Sheet operations including document creation, sheet management, view management, field management, and record CRUD.'
13
- },
14
- toolDescription: `A comprehensive WeCom (Work WeChat) Smart Sheet toolset for managing documents, sheets, views, fields, and records.
15
- Supports complete CRUD operations for efficient data management within WeCom.`,
16
- author: 'FastGPT Team',
17
- tutorialUrl: 'https://developer.work.weixin.qq.com/document/path/96601',
18
- secretInputConfig: []
19
- });
@@ -1,6 +0,0 @@
1
- import { exportToolSet } from '@fastgpt-plugin/helpers/tools/helper';
2
- import config from './config';
3
-
4
- export default exportToolSet({
5
- config
6
- });
@@ -1,4 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64">
2
- <rect width="64" height="64" rx="8" fill="#e0e7ff" />
3
- <text x="32" y="40" text-anchor="middle" font-size="24" fill="#4338ca">?</text>
4
- </svg>
@@ -1,21 +0,0 @@
1
- {
2
- "name": "{{name}}",
3
- "version": "0.0.1",
4
- "description": "{{description}}",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "scripts": {
8
- "build": "npx @fastgpt-plugin/cli build --minify",
9
- "build:dev": "npx @fastgpt-plugin/cli build",
10
- "pack": "npx @fastgpt-plugin/cli pack",
11
- "test": "vitest run"
12
- },
13
- "dependencies": {},
14
- "devDependencies": {
15
- "@fastgpt-plugin/cli": "catalog:",
16
- "@fastgpt-plugin/helpers": "catalog:",
17
- "typescript": "catalog:",
18
- "vitest": "catalog:",
19
- "zod": "catalog:"
20
- }
21
- }
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "target": "es2022",
5
- "moduleResolution": "bundler",
6
- "types": [],
7
- "noUncheckedIndexedAccess": true,
8
- "exactOptionalPropertyTypes": true,
9
- "strict": true,
10
- "jsx": "react-jsx",
11
- "verbatimModuleSyntax": true,
12
- "isolatedModules": true,
13
- "noUncheckedSideEffectImports": true,
14
- "moduleDetection": "force",
15
- "skipLibCheck": true,
16
- "noEmit": true
17
- },
18
- "exclude": ["**/*.test.ts", "**/*.spec.ts", "**/*.test.tsx", "**/*.spec.tsx"]
19
- }
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node'
6
- }
7
- });