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

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/dist/index.js CHANGED
@@ -56,7 +56,11 @@ const PluginUniqueIdSchema = z.object({
56
56
  etag: z.string()
57
57
  });
58
58
  const PluginSourceSchema = z.literal("system").or(z.string());
59
- const PluginTagListSchema = z.array(z.record(z.string(), I18nStringStrictSchema));
59
+ const PluginTagListItemSchema = z.object({
60
+ id: z.string(),
61
+ name: I18nStringStrictSchema
62
+ });
63
+ const PluginTagListSchema = z.array(PluginTagListItemSchema);
60
64
  const PluginRuntimeModeSchema = z.enum(["localPool", "serverless"]);
61
65
  const PluginRuntimeModeEnum = PluginRuntimeModeSchema.enum;
62
66
  const UserPluginIdSchema = z.object({
@@ -192,22 +196,26 @@ async function buildToolPackage(options) {
192
196
  const tempIndexPath = path.join(tempDir, "index.ts");
193
197
  const tBuildStart = Date.now();
194
198
  await build({
199
+ deps: { alwaysBundle: [
200
+ "*",
201
+ "*/*",
202
+ "@*/*"
203
+ ] },
195
204
  entry: { index: tempIndexPath },
196
205
  outDir: outputDir,
197
206
  format: [options.format],
198
207
  clean: true,
199
208
  minify: options.minify,
200
- inlineOnly: ["*"],
201
209
  nodeProtocol: true,
202
210
  platform: "node",
203
211
  target: "node22",
204
212
  dts: false,
205
213
  treeshake: true,
206
- noExternal: ["*"],
207
214
  outExtensions: () => ({
208
215
  dts: ".d.ts",
209
216
  js: ".js"
210
- })
217
+ }),
218
+ outputOptions: { codeSplitting: false }
211
219
  });
212
220
  tBuild = Date.now() - tBuildStart;
213
221
  const tAssembleStart = Date.now();
@@ -531,7 +539,7 @@ var CheckCommand = class extends BaseCommand {
531
539
  //#endregion
532
540
  //#region package.json
533
541
  var name = "@fastgpt-plugin/cli";
534
- var version = "0.1.0-beta.5";
542
+ var version = "0.1.0-beta.6";
535
543
 
536
544
  //#endregion
537
545
  //#region src/constants.ts
@@ -640,7 +648,7 @@ var CreateCommand = class extends BaseCommand {
640
648
  const targetDir = path.resolve(options.cwd, options.name);
641
649
  const templateDir = path.join(TOOL_TEMPLATES_DIR, "tool");
642
650
  const files = await this.collectTemplateFiles(templateDir);
643
- const description = options.description ?? DEFAULT_PLUGIN_DESCRIPTION;
651
+ const description = options.description ?? "This is a FastGPT plugin";
644
652
  await this.ensureDir(targetDir);
645
653
  for (const rel of files) {
646
654
  const templatePath = path.join(templateDir, rel);
@@ -858,9 +866,13 @@ const FileMetaSchema = z.object({
858
866
  createTime: z.date()
859
867
  });
860
868
  const FileCreateSchema = z.object({
869
+ /** 如果未提供 fileKey,则生成一个随机值 */
861
870
  fileKey: z.string().optional(),
871
+ /** 路径,将会拼接在 fileName 之前 */
862
872
  path: z.string().optional(),
873
+ /** 如果未提供fileName,则默认设置为 fileKey 的值 */
863
874
  fileName: z.string().optional(),
875
+ /** 如果未提供 contentType,则尝试进行探测,探测失败则设置为 application/octet-stream */
864
876
  contentType: MIMESchema.optional(),
865
877
  overwrite: z.boolean().optional(),
866
878
  file: z.union([z.instanceof(Readable, { error: "Stream cannot be empty" }), z.union([z.instanceof(Buffer, { error: "Buffer is required" }), z.instanceof(Uint8Array, { error: "Uint8Array is required" })]).transform((data) => {
@@ -876,11 +888,18 @@ const InvokeUploadFileInputSchema = z.object({ ...FileCreateSchema.omit({
876
888
  overwrite: true,
877
889
  path: true
878
890
  }).shape });
879
- const InvokeUploadFileOutputSchema = z.object({
880
- ...FileMetaSchema.omit({ fileKey: true }).shape,
881
- accessURL: z.string()
891
+ const InvokeUploadFileOutputSchema = z.object({ accessURL: z.string() });
892
+ const InvokeUserInfoOutputSchema = z.object({
893
+ username: z.string(),
894
+ contact: z.string().nullish(),
895
+ memberName: z.string().nullish(),
896
+ orgs: z.array(z.object({
897
+ pathId: z.string(),
898
+ name: z.string()
899
+ })),
900
+ groups: z.array(z.object({ name: z.string() }))
882
901
  });
883
- const InvokeMethodEnumSchema = z.enum(["uploadFile"]);
902
+ const InvokeMethodEnumSchema = z.enum(["uploadFile", "userInfo"]);
884
903
  const InvokeMethodEnum = InvokeMethodEnumSchema.enum;
885
904
 
886
905
  //#endregion
@@ -946,24 +965,15 @@ var StreamData = class StreamData {
946
965
  //#endregion
947
966
  //#region ../../packages/domain/src/value-objects/system-var.vo.ts
948
967
  const SystemVarSchema = z.object({
949
- user: z.object({
950
- id: z.string(),
951
- username: z.string(),
952
- contact: z.string(),
953
- membername: z.string(),
954
- teamName: z.string(),
955
- teamId: z.string(),
956
- name: z.string()
957
- }),
958
968
  app: z.object({
959
969
  id: z.string(),
960
970
  name: z.string()
961
971
  }),
962
- tool: z.object({
963
- id: z.string(),
964
- version: z.string(),
965
- prefix: z.string().optional()
966
- }).passthrough(),
972
+ chat: z.object({
973
+ chatId: z.string(),
974
+ uid: z.string().optional()
975
+ }),
976
+ invokeToken: z.string(),
967
977
  time: z.string()
968
978
  });
969
979
 
@@ -996,7 +1006,6 @@ const ToolStreamMessageSchema = z.discriminatedUnion("type", [
996
1006
  data: z.string()
997
1007
  })
998
1008
  ]);
999
- const ToolRunContextSchema = z.object({ systemVar: z.record(z.string(), z.unknown()) });
1000
1009
  const ToolRunInputSchema = z.object({
1001
1010
  pluginId: z.string(),
1002
1011
  version: z.preprocess((value) => {
@@ -1223,42 +1232,27 @@ async function runDebugTool({ runtime, snapshot, toolId, input, secrets, systemV
1223
1232
  }
1224
1233
  function createDebugSystemVar(snapshot, toolId, overrides) {
1225
1234
  const base = {
1226
- user: {
1227
- id: "debug-user",
1228
- username: "debug-user",
1229
- contact: "debug@example.com",
1230
- membername: "debug-member",
1231
- teamName: "debug-team",
1232
- teamId: "debug-team-id",
1233
- name: "Local Debug User"
1234
- },
1235
1235
  app: {
1236
1236
  id: "debug-app",
1237
1237
  name: "FastGPT Local Debug"
1238
1238
  },
1239
- tool: {
1240
- id: snapshot.pluginId,
1241
- version: snapshot.version,
1242
- prefix: snapshot.isToolSet ? toolId : snapshot.pluginId,
1243
- token: "debug-token",
1244
- accessToken: "debug-access-token"
1239
+ chat: {
1240
+ chatId: "debug-chat",
1241
+ uid: "debugger"
1245
1242
  },
1243
+ invokeToken: "debug-invoke-token",
1246
1244
  time: (/* @__PURE__ */ new Date()).toISOString()
1247
1245
  };
1248
1246
  return SystemVarSchema.parse({
1249
1247
  ...base,
1250
1248
  ...overrides,
1251
- user: {
1252
- ...base.user,
1253
- ...overrides?.user ?? {}
1254
- },
1255
1249
  app: {
1256
1250
  ...base.app,
1257
1251
  ...overrides?.app ?? {}
1258
1252
  },
1259
- tool: {
1260
- ...base.tool,
1261
- ...overrides?.tool ?? {}
1253
+ chat: {
1254
+ ...base.chat,
1255
+ ...overrides?.chat ?? {}
1262
1256
  }
1263
1257
  });
1264
1258
  }
@@ -1316,7 +1310,7 @@ function pickTargetTool(snapshot, toolId) {
1316
1310
  }
1317
1311
  function createVirtualHostHandler(uploadDir) {
1318
1312
  return async ({ method, args, input }) => {
1319
- if (method !== HOST_INVOKE_METHOD) throw new Error(`本地虚拟环境暂不支持反向调用: ${method}`);
1313
+ if (method !== "__host_invoke__") throw new Error(`本地虚拟环境暂不支持反向调用: ${method}`);
1320
1314
  const payload = ensurePlainObject(args);
1321
1315
  const invokeMethod = payload.method;
1322
1316
  const invokeArgs = ensurePlainObject(payload.args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastgpt-plugin/cli",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.6",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -30,7 +30,7 @@
30
30
  "consola": "^3.4.2",
31
31
  "es-toolkit": "^1.44.0",
32
32
  "oxc-parser": "^0.112.0",
33
- "tsdown": "^0.20.1",
33
+ "tsdown": "catalog:",
34
34
  "yazl": "^3.3.1",
35
35
  "yaml": "^2.6.1",
36
36
  "zod": "^4"
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: cli-usage
3
- description: 使用 FastGPT plugin CLI 时启用,适用于创建插件项目、构建 dist 产物、校验构建输出、打包 .pkg 文件,以及指导用户选择 create/build/check/pack 命令和参数。该技能使用通用说明风格,可被 Claude、Codex 等代理直接阅读。
3
+ description: 使用 FastGPT plugin CLI 时启用,适用于创建插件项目、构建 dist 产物、校验构建输出、打包 .pkg 文件,以及指导用户选择 create/build/check/pack 命令和参数。
4
4
  ---
5
5
 
6
6
  # FastGPT CLI 使用技能
7
7
 
8
- 在需要“使用 `apps/cli` 这个命令行工具”时使用这个技能,不用于修改 CLI 源码。
8
+ 在需要使用 FastGPT plugin CLI 完成插件创建、构建、检查或打包时使用这个技能。
9
9
 
10
10
  ## 适用场景
11
11
 
@@ -15,20 +15,6 @@ description: 使用 FastGPT plugin CLI 时启用,适用于创建插件项目
15
15
  - 想把构建产物打成 `.pkg`
16
16
  - 不确定该用 `create`、`build`、`check` 还是 `pack`
17
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
18
  ## 常用命令
33
19
 
34
20
  推荐两种调用方式:
@@ -64,7 +50,6 @@ npx @fastgpt-plugin/cli create my-suite --type tool-suite
64
50
 
65
51
  - `tool` 会生成单工具模板
66
52
  - `tool-suite` 会生成工具集模板
67
- - 模板目录在 `apps/cli/templates/tool`
68
53
 
69
54
  ### 2. 构建插件
70
55
 
@@ -128,20 +113,19 @@ npx @fastgpt-plugin/cli pack --entry ./path/to/plugin --dist ./dist --output ./o
128
113
 
129
114
  ## 排查建议
130
115
 
131
- - 模板生成不符合预期:检查 `apps/cli/templates/tool`
132
- - 命令参数不生效:检查 `apps/cli/src/commands/*.ts` Commander 定义
133
- - 测试命令找不到用例:优先在 `apps/cli` 目录下运行 `pnpm test`
116
+ - 命令无法执行:确认已安装 Node.js 和 pnpm,或直接使用 `npx @fastgpt-plugin/cli`
117
+ - 参数不确定:先运行 `npx @fastgpt-plugin/cli <command> --help`
118
+ - 构建失败:检查插件入口目录是否包含完整源码和 `manifest.json`
119
+ - 打包失败:先运行 `build` 和 `check`,确认 `dist` 产物符合约定
134
120
 
135
121
  ## 验证
136
122
 
137
- 在 `apps/cli` 目录下:
138
-
139
123
  ```bash
140
- pnpm fastgpt-plugin --help
124
+ npx @fastgpt-plugin/cli --help
141
125
  ```
142
126
 
143
- 如果已经安装依赖并希望用 pnpm 执行:
127
+ 如果项目中已经配置了 `pnpm fastgpt-plugin`:
144
128
 
145
129
  ```bash
146
- pnpm fastgpt-plugin create my-tool --type tool
130
+ pnpm fastgpt-plugin --help
147
131
  ```