@fastgpt-plugin/cli 0.1.0-beta.1 → 0.1.0-beta.2

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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{consola as e}from"consola/basic";import{Command as t}from"commander";import n from"node:path";import r from"node:fs/promises";import{build as i}from"tsdown";import{Visitor as a,parseSync as o}from"oxc-parser";import{createHash as s}from"node:crypto";import{input as c,select as l}from"@inquirer/prompts";import{kebabCase as u}from"es-toolkit";import{createWriteStream as d}from"node:fs";import{ZipFile as f}from"yazl";const p=e;var m=`@fastgpt-plugin/cli`,h=`0.1.0-beta.1`;const g=m,_=h,v=`This is a FastGPT plugin`,y=n.join(import.meta.dirname,`../templates`);var b=class{};async function x(e){let t=n.join(e.rootDir,`src`);if(!await C(t))return w(``);let i=[],a=async t=>{let o=await r.readdir(t,{withFileTypes:!0});for(let r of o){let o=n.join(t,r.name);if(r.isDirectory()){if(r.name===`__tests__`)continue;await a(o);continue}if(!r.isFile())continue;let s=r.name;if(s.includes(`.test.`)||s.includes(`.spec.`))continue;let c=n.relative(e.rootDir,o).split(n.sep).join(`/`);c.startsWith(`src/`)&&i.push({rel:c,abs:o})}};await a(t),i.sort((e,t)=>e.rel.localeCompare(t.rel));let o=``;for(let e of i){let t=w(await r.readFile(e.abs));o+=`${e.rel}:${t}\n`}return w(o)}async function S(e){let{rootDir:t,toolId:r}=e,i=[...e.children].sort(),a=[];for(let e of i){let i=await x({rootDir:n.join(t,`children`,e)});a.push(`${r}/${e}:${i}`)}return w(a.length>0?`${a.join(`
2
+ import{consola as e}from"consola/basic";import{Command as t}from"commander";import n from"node:path";import r from"node:fs/promises";import{build as i}from"tsdown";import{Visitor as a,parseSync as o}from"oxc-parser";import{createHash as s}from"node:crypto";import{input as c,select as l}from"@inquirer/prompts";import{kebabCase as u}from"es-toolkit";import{createWriteStream as d}from"node:fs";import{ZipFile as f}from"yazl";const p=e;var m=`@fastgpt-plugin/cli`,h=`0.1.0-beta.2`;const g=m,_=h,v=`This is a FastGPT plugin`,y=n.join(import.meta.dirname,`../templates`);var b=class{};async function x(e){let t=n.join(e.rootDir,`src`);if(!await C(t))return w(``);let i=[],a=async t=>{let o=await r.readdir(t,{withFileTypes:!0});for(let r of o){let o=n.join(t,r.name);if(r.isDirectory()){if(r.name===`__tests__`)continue;await a(o);continue}if(!r.isFile())continue;let s=r.name;if(s.includes(`.test.`)||s.includes(`.spec.`))continue;let c=n.relative(e.rootDir,o).split(n.sep).join(`/`);c.startsWith(`src/`)&&i.push({rel:c,abs:o})}};await a(t),i.sort((e,t)=>e.rel.localeCompare(t.rel));let o=``;for(let e of i){let t=w(await r.readFile(e.abs));o+=`${e.rel}:${t}\n`}return w(o)}async function S(e){let{rootDir:t,toolId:r}=e,i=[...e.children].sort(),a=[];for(let e of i){let i=await x({rootDir:n.join(t,`children`,e)});a.push(`${r}/${e}:${i}`)}return w(a.length>0?`${a.join(`
3
3
  `)}\n`:``)}async function C(e){try{return await r.access(e),!0}catch{return!1}}function w(e){let t=s(`md5`);return t.update(e),t.digest(`hex`)}function T(e){let t=e.split(`/`);return t.at(-3)===`children`?`${t.at(-4)}/${t.at(-2)}`:t.at(-2)||`unknown`}async function E(e){let t=n.join(e,`children`);try{await r.access(t)}catch{return[]}try{return await r.readdir(t)}catch{return[]}}function D(e,t){return e.some(e=>e.type===`Property`&&e.key?.type===`Identifier`&&e.key?.name===t)}function O(e,t){let n=t.sort((e,t)=>t.start-e.start),r=e;for(let e of n)r=r.slice(0,e.start)+e.content+r.slice(e.end);return r}async function k({sourceCode:e,filePath:t}){if(e.includes(`toolId:`))return{code:e,hasToolId:!0};let r=T(t),i=n.dirname(t),s=await E(i),c=await x({rootDir:i}),l=s.length>0?await S({rootDir:i,toolId:r,children:s}):null,u=o(n.basename(t),e,{sourceType:`module`});if(u.errors.length>0)throw Error(`Parse errors: ${u.errors.map(e=>e.message).join(`, `)}`);let d=[],f=[];new a({CallExpression(e){e.callee?.type===`Identifier`&&(e.callee.name===`defineTool`||e.callee.name===`defineToolSet`)&&e.arguments?.[0]?.type===`ObjectExpression`&&f.push(e)}}).visit(u.program);for(let e of f){let t=e.arguments[0];if(t?.type!==`ObjectExpression`)continue;let n=t,i=n.properties||[],a=e.callee?.type===`Identifier`&&e.callee.name===`defineToolSet`,o=!D(i,`toolId`),u=!D(i,`etag`),f=a&&!D(i,`children`)&&s.length>0;if(!o&&!u&&!f)continue;let p=i[i.length-1],m=p?p.end:(n.start??0)+1,h=[];if(o&&h.push(`toolId: '${r}'`),u){let e=a&&l?l:c;h.push(`etag: '${e}'`)}if(f){let e=s.map(e=>e).join(`, `);h.push(`children: [${e}]`);let t=s.map(e=>`import ${e} from './children/${e}';`).join(`
4
4
  `);d.push({start:0,end:0,content:t+`
5
5
  `})}if(h.length>0){let e=(p?`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastgpt-plugin/cli",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.2",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -22,12 +22,13 @@
22
22
  "prepublishOnly": "npm run build"
23
23
  },
24
24
  "dependencies": {
25
+ "@fastgpt-plugin/helpers": "0.0.1-alpha.3",
25
26
  "@oxc-parser/binding-wasm32-wasi": "^0.112.0",
26
- "oxc-parser": "^0.112.0",
27
27
  "@inquirer/prompts": "^8.2.0",
28
28
  "commander": "^14.0.3",
29
29
  "consola": "^3.4.2",
30
30
  "es-toolkit": "^1.44.0",
31
+ "oxc-parser": "^0.112.0",
31
32
  "tsdown": "^0.20.1",
32
33
  "yazl": "^3.3.1"
33
34
  },
@@ -1,7 +1,7 @@
1
1
  import { defineTool, WorkflowIOValueTypeEnum, ToolTagEnum } from '@fastgpt-plugin/helpers';
2
2
 
3
3
  export default defineTool({
4
- tags: [ToolTagEnum.enum.tools],
4
+ tags: [ToolTagEnum.tools],
5
5
  name: {
6
6
  'zh-CN': '{{name}}',
7
7
  en: '{{name}}'
@@ -18,10 +18,10 @@ export default defineTool({
18
18
  inputs: [],
19
19
  outputs: [
20
20
  {
21
- key: 'message',
22
- valueType: WorkflowIOValueTypeEnum.enum.string,
23
- label: 'Message',
24
- description: 'Tool output message'
21
+ key: 'time',
22
+ valueType: WorkflowIOValueTypeEnum.string,
23
+ label: '时间',
24
+ description: '当前时间'
25
25
  }
26
26
  ]
27
27
  }
@@ -1,11 +1,11 @@
1
1
  import { exportTool } from '@fastgpt-plugin/helpers/tools/helper';
2
2
  import config from './config';
3
- import { tool as toolCb } from './src/tool';
4
- import { InputType, OutputType } from './src/schemas';
3
+ import { InputSchema, OutputSchema } from './src/schemas';
4
+ import { handler } from './src/tool';
5
5
 
6
6
  export default exportTool({
7
- toolCb,
8
- InputType,
9
- OutputType,
7
+ handler,
8
+ InputSchema,
9
+ OutputSchema,
10
10
  config
11
11
  });
@@ -5,16 +5,17 @@
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
8
- "build": "npx @fastgpt-plugin/cli build",
8
+ "build": "npx @fastgpt-plugin/cli build --minify",
9
+ "build:dev": "npx @fastgpt-plugin/cli build",
10
+ "pack": "npx @fastgpt-plugin/cli pack",
9
11
  "test": "vitest run"
10
12
  },
11
- "dependencies": {
12
- "@fastgpt-plugin/helpers": "catalog:",
13
- "zod": "catalog:"
14
- },
13
+ "dependencies": {},
15
14
  "devDependencies": {
16
15
  "@fastgpt-plugin/cli": "catalog:",
16
+ "@fastgpt-plugin/helpers": "catalog:",
17
17
  "typescript": "catalog:",
18
- "vitest": "catalog:"
18
+ "vitest": "catalog:",
19
+ "zod": "catalog:"
19
20
  }
20
21
  }
@@ -1,7 +1,9 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const InputType = z.object({});
3
+ export const InputSchema = z.object({});
4
+ export type Input = z.infer<typeof InputSchema>;
4
5
 
5
- export const OutputType = z.object({
6
- message: z.string()
6
+ export const OutputSchema = z.object({
7
+ time: z.string().nonempty()
7
8
  });
9
+ export type Output = z.infer<typeof OutputSchema>;
@@ -1,37 +1,17 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { InputType, OutputType } from './schemas';
2
+ import { InputSchema, OutputSchema } from './schemas';
3
3
  import { tool } from './tool';
4
+ import { mockedEventEmitter, mockedSystemVar } from '@fastgpt-plugin/helpers/tools/mocks';
4
5
 
5
6
  describe('get-time', () => {
6
7
  it('should run with valid IO schemas', async () => {
7
- const input = InputType.parse({});
8
+ const input = InputSchema.parse({});
8
9
  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
- }
10
+ systemVar: mockedSystemVar,
11
+ emitter: mockedEventEmitter
32
12
  });
33
13
 
34
- const output = OutputType.parse(result);
14
+ const output = OutputSchema.parse(result);
35
15
  expect(output).toBeDefined();
36
16
  });
37
17
  });
@@ -1,10 +1,8 @@
1
- import type { RunToolSecondParamsType } from '@fastgpt-plugin/helpers/tools/schemas/req';
2
- import type { z } from 'zod';
3
- import type { InputType, OutputType } from './schemas';
1
+ import type { ToolContextType } from '@fastgpt-plugin/helpers/tools/schemas/req';
2
+ import type { Input, Output } from './schemas';
4
3
 
5
- export async function tool(
6
- _input: z.infer<typeof InputType>,
7
- _ctx: RunToolSecondParamsType
8
- ): Promise<z.infer<typeof OutputType>> {
9
- return { message: 'Hello from {{name}}' };
4
+ export async function handler(_: Input, ctx: ToolContextType): Promise<Output> {
5
+ const { systemVar } = ctx;
6
+
7
+ return { time: systemVar.time };
10
8
  }
@@ -1,7 +1,7 @@
1
- import { defineTool, WorkflowIOValueTypeEnum, ToolTagEnum } from '@fastgpt-plugin/helpers';
1
+ import { defineTool, ToolTagEnum, WorkflowIOValueTypeEnum } from '@fastgpt-plugin/helpers';
2
2
 
3
3
  export default defineTool({
4
- tags: [ToolTagEnum.enum.tools],
4
+ tags: [ToolTagEnum.tools],
5
5
  name: {
6
6
  'zh-CN': '{{name}}',
7
7
  en: '{{name}}'
@@ -14,14 +14,14 @@ export default defineTool({
14
14
  versionList: [
15
15
  {
16
16
  value: '0.0.1',
17
- description: 'Initial version',
17
+ description: 'Default version',
18
18
  inputs: [],
19
19
  outputs: [
20
20
  {
21
- key: 'message',
22
- valueType: WorkflowIOValueTypeEnum.enum.string,
23
- label: 'Message',
24
- description: 'Tool output message'
21
+ key: 'time',
22
+ valueType: WorkflowIOValueTypeEnum.string,
23
+ label: '时间',
24
+ description: '当前时间'
25
25
  }
26
26
  ]
27
27
  }
@@ -1,11 +1,11 @@
1
1
  import { exportTool } from '@fastgpt-plugin/helpers/tools/helper';
2
2
  import config from './config';
3
- import { tool as toolCb } from './src/tool';
4
- import { InputType, OutputType } from './src/schemas';
3
+ import { InputSchema, OutputSchema } from './src/schemas';
4
+ import { handler } from './src/tool';
5
5
 
6
6
  export default exportTool({
7
- toolCb,
8
- InputType,
9
- OutputType,
7
+ handler,
8
+ InputSchema,
9
+ OutputSchema,
10
10
  config
11
11
  });
@@ -1,7 +1,9 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const InputType = z.object({});
3
+ export const InputSchema = z.object({});
4
+ export type Input = z.infer<typeof InputSchema>;
4
5
 
5
- export const OutputType = z.object({
6
- message: z.string()
6
+ export const OutputSchema = z.object({
7
+ time: z.string().nonempty()
7
8
  });
9
+ export type Output = z.infer<typeof OutputSchema>;
@@ -1,10 +1,8 @@
1
- import type { RunToolSecondParamsType } from '@fastgpt-plugin/helpers/tools/schemas/req';
2
- import type { z } from 'zod';
3
- import { InputType, OutputType } from './schemas';
1
+ import type { ToolContextType } from '@fastgpt-plugin/helpers/tools/schemas/req';
2
+ import type { Input, Output } from './schemas';
4
3
 
5
- export async function tool(
6
- _input: z.infer<typeof InputType>,
7
- _ctx: RunToolSecondParamsType
8
- ): Promise<z.infer<typeof OutputType>> {
9
- return { message: 'Hello from {{name}}' };
4
+ export async function handler(_: Input, ctx: ToolContextType): Promise<Output> {
5
+ const { systemVar } = ctx;
6
+
7
+ return { time: systemVar.time };
10
8
  }
@@ -1,7 +1,7 @@
1
- import { defineToolSet, ToolTagEnum } from '@fastgpt-plugin/helpers';
1
+ import { defineTool, ToolTagEnum, WorkflowIOValueTypeEnum } from '@fastgpt-plugin/helpers';
2
2
 
3
- export default defineToolSet({
4
- tags: [ToolTagEnum.enum.tools],
3
+ export default defineTool({
4
+ tags: [ToolTagEnum.tools],
5
5
  name: {
6
6
  'zh-CN': '{{name}}',
7
7
  en: '{{name}}'
@@ -9,5 +9,21 @@ export default defineToolSet({
9
9
  description: {
10
10
  'zh-CN': '{{description}}',
11
11
  en: '{{description}}'
12
- }
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
+ ]
13
29
  });
@@ -5,16 +5,17 @@
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
8
- "build": "npx @fastgpt-plugin/cli build",
8
+ "build": "npx @fastgpt-plugin/cli build --minify",
9
+ "build:dev": "npx @fastgpt-plugin/cli build",
10
+ "pack": "npx @fastgpt-plugin/cli pack",
9
11
  "test": "vitest run"
10
12
  },
11
- "dependencies": {
12
- "@fastgpt-plugin/helpers": "catalog:",
13
- "zod": "catalog:"
14
- },
13
+ "dependencies": {},
15
14
  "devDependencies": {
16
15
  "@fastgpt-plugin/cli": "catalog:",
16
+ "@fastgpt-plugin/helpers": "catalog:",
17
17
  "typescript": "catalog:",
18
- "vitest": "catalog:"
18
+ "vitest": "catalog:",
19
+ "zod": "catalog:"
19
20
  }
20
21
  }
@@ -5,4 +5,3 @@ export default defineConfig({
5
5
  environment: 'node'
6
6
  }
7
7
  });
8
-