foliko 2.0.7 → 2.0.9

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.
@@ -238,7 +238,8 @@
238
238
  "Bash(cmd //c \"D:\\\\\\\\tmp\\\\\\\\run-diag3.bat\")",
239
239
  "Bash(npm start *)",
240
240
  "Bash(xxd)",
241
- "Bash(python fix_ext2.py)"
241
+ "Bash(python fix_ext2.py)",
242
+ "Bash(npx vitest *)"
242
243
  ]
243
244
  }
244
245
  }
package/.editorconfig CHANGED
@@ -1,56 +1,56 @@
1
- # EditorConfig is awesome: https://EditorConfig.org
2
-
3
- # top-most EditorConfig file
4
- root = true
5
-
6
- # 代码文件
7
- [*]
8
- charset = utf-8
9
- end_of_line = lf
10
- insert_final_newline = true
11
- trim_trailing_whitespace = true
12
-
13
- # JavaScript / Node.js
14
- [*.{js,jsx,mjs,cjs}]
15
- indent_style = space
16
- indent_size = 2
17
-
18
- # TypeScript
19
- [*.{ts,tsx}]
20
- indent_style = space
21
- indent_size = 2
22
-
23
- # JSON
24
- [*.json]
25
- indent_style = space
26
- indent_size = 2
27
-
28
- # YAML
29
- [*.{yaml,yml}]
30
- indent_style = space
31
- indent_size = 2
32
-
33
- # Markdown
34
- [*.md]
35
- trim_trailing_whitespace = false
36
- indent_style = space
37
- indent_size = 2
38
-
39
- # Shell
40
- [*.sh]
41
- indent_style = space
42
- indent_size = 2
43
-
44
- # PowerShell
45
- [*.ps1]
46
- indent_style = space
47
- indent_size = 4
48
-
49
- # Dockerfile
50
- [Dockerfile]
51
- indent_style = space
52
- indent_size = 4
53
-
54
- # Makefile
55
- [Makefile]
56
- indent_style = tab
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # 代码文件
7
+ [*]
8
+ charset = utf-8
9
+ end_of_line = lf
10
+ insert_final_newline = true
11
+ trim_trailing_whitespace = true
12
+
13
+ # JavaScript / Node.js
14
+ [*.{js,jsx,mjs,cjs}]
15
+ indent_style = space
16
+ indent_size = 2
17
+
18
+ # TypeScript
19
+ [*.{ts,tsx}]
20
+ indent_style = space
21
+ indent_size = 2
22
+
23
+ # JSON
24
+ [*.json]
25
+ indent_style = space
26
+ indent_size = 2
27
+
28
+ # YAML
29
+ [*.{yaml,yml}]
30
+ indent_style = space
31
+ indent_size = 2
32
+
33
+ # Markdown
34
+ [*.md]
35
+ trim_trailing_whitespace = false
36
+ indent_style = space
37
+ indent_size = 2
38
+
39
+ # Shell
40
+ [*.sh]
41
+ indent_style = space
42
+ indent_size = 2
43
+
44
+ # PowerShell
45
+ [*.ps1]
46
+ indent_style = space
47
+ indent_size = 4
48
+
49
+ # Dockerfile
50
+ [Dockerfile]
51
+ indent_style = space
52
+ indent_size = 4
53
+
54
+ # Makefile
55
+ [Makefile]
56
+ indent_style = tab
package/.lintstagedrc CHANGED
@@ -1,7 +1,7 @@
1
- {
2
- "*.{js,jsx,ts,tsx}": ["prettier --write", "git add"],
3
- "*.{json,yaml,yml}": ["prettier --write", "git add"],
4
- "*.{md,mdx}": ["prettier --write", "git add"],
5
- "*.{css,scss,less}": ["prettier --write", "git add"],
6
- "*.{html,svg}": ["prettier --write", "git add"]
7
- }
1
+ {
2
+ "*.{js,jsx,ts,tsx}": ["prettier --write", "git add"],
3
+ "*.{json,yaml,yml}": ["prettier --write", "git add"],
4
+ "*.{md,mdx}": ["prettier --write", "git add"],
5
+ "*.{css,scss,less}": ["prettier --write", "git add"],
6
+ "*.{html,svg}": ["prettier --write", "git add"]
7
+ }
package/.prettierignore CHANGED
@@ -1,29 +1,29 @@
1
- # 依赖
2
- node_modules/
3
- pnpm-lock.yaml
4
- yarn.lock
5
- package-lock.json
6
-
7
- # 构建输出
8
- dist/
9
- build/
10
- out/
11
-
12
- # 插件目录(第三方代码)
13
- plugins/
14
-
15
- # 测试报告
16
- reports/
17
- test_report.md
18
-
19
- # 配置文件(不需要格式化)
20
- .env
21
- .env.example
22
-
23
- # 静态资源
24
- images/
25
- audio/
26
- public/
27
-
28
- # 锁文件
29
- *.lock
1
+ # 依赖
2
+ node_modules/
3
+ pnpm-lock.yaml
4
+ yarn.lock
5
+ package-lock.json
6
+
7
+ # 构建输出
8
+ dist/
9
+ build/
10
+ out/
11
+
12
+ # 插件目录(第三方代码)
13
+ plugins/
14
+
15
+ # 测试报告
16
+ reports/
17
+ test_report.md
18
+
19
+ # 配置文件(不需要格式化)
20
+ .env
21
+ .env.example
22
+
23
+ # 静态资源
24
+ images/
25
+ audio/
26
+ public/
27
+
28
+ # 锁文件
29
+ *.lock
package/.prettierrc CHANGED
@@ -1,11 +1,11 @@
1
- {
2
- "semi": true,
3
- "singleQuote": true,
4
- "tabWidth": 2,
5
- "trailingComma": "es5",
6
- "printWidth": 100,
7
- "bracketSpacing": true,
8
- "arrowParens": "always",
9
- "endOfLine": "lf",
10
- "plugins": []
11
- }
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "es5",
6
+ "printWidth": 100,
7
+ "bracketSpacing": true,
8
+ "arrowParens": "always",
9
+ "endOfLine": "lf",
10
+ "plugins": []
11
+ }
package/Dockerfile CHANGED
@@ -1,63 +1,63 @@
1
- # ========== Foliko - 插件化 Agent 框架 ==========
2
- # 基于 Node.js 20 LTS
3
-
4
- FROM node:25-slim
5
-
6
- # 安装无头浏览器(Chromium)和构建工具
7
- RUN apt-get update && apt-get install -y --no-install-recommends \
8
- build-essential \
9
- python3 \
10
- python3-pip \
11
- curl \
12
- git \
13
- wget \
14
- gnupg \
15
- # Chromium 及依赖
16
- chromium \
17
- chromium-sandbox \
18
- libnss3 \
19
- libatk1.0-0 \
20
- libatk-bridge2.0-0 \
21
- libcups2 \
22
- libdrm2 \
23
- libxkbcommon0 \
24
- libxcomposite1 \
25
- libxdamage1 \
26
- libxfixes3 \
27
- libxrandr2 \
28
- libgbm1 \
29
- libasound2 \
30
- libpango-1.0-0 \
31
- libpangocairo-1.0-0 \
32
- libgtk-3-0 \
33
- fonts-liberation \
34
- xdg-utils \
35
- && rm -rf /var/lib/apt/lists/* \
36
- && ln -sf /usr/bin/python3 /usr/bin/python \
37
- && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
38
-
39
- # 设置 Chromium 环境变量(无头模式运行)
40
- ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
41
- ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
42
- ENV CHROME_BIN=/usr/bin/chromium
43
-
44
- # 安装 uv(快速的 Python 包管理器)
45
- RUN curl -LsSf https://astral.sh/uv/install.sh | sh
46
- ENV PATH="/root/.local/bin:$PATH"
47
-
48
- # 设置工作目录
49
- WORKDIR /app
50
-
51
- # 全局安装 foliko CLI
52
- # RUN npm install -g foliko
53
-
54
- # 暴露端口
55
- # 3000: Web 服务端口
56
- EXPOSE 3000
57
-
58
- # 环境变量(可以在 docker-compose 或运行时覆盖)
59
- ENV NODE_ENV=production
60
-
61
-
62
- # 默认命令:运行聊天界面
63
- # CMD ["foliko", "chat"]
1
+ # ========== Foliko - 插件化 Agent 框架 ==========
2
+ # 基于 Node.js 20 LTS
3
+
4
+ FROM node:25-slim
5
+
6
+ # 安装无头浏览器(Chromium)和构建工具
7
+ RUN apt-get update && apt-get install -y --no-install-recommends \
8
+ build-essential \
9
+ python3 \
10
+ python3-pip \
11
+ curl \
12
+ git \
13
+ wget \
14
+ gnupg \
15
+ # Chromium 及依赖
16
+ chromium \
17
+ chromium-sandbox \
18
+ libnss3 \
19
+ libatk1.0-0 \
20
+ libatk-bridge2.0-0 \
21
+ libcups2 \
22
+ libdrm2 \
23
+ libxkbcommon0 \
24
+ libxcomposite1 \
25
+ libxdamage1 \
26
+ libxfixes3 \
27
+ libxrandr2 \
28
+ libgbm1 \
29
+ libasound2 \
30
+ libpango-1.0-0 \
31
+ libpangocairo-1.0-0 \
32
+ libgtk-3-0 \
33
+ fonts-liberation \
34
+ xdg-utils \
35
+ && rm -rf /var/lib/apt/lists/* \
36
+ && ln -sf /usr/bin/python3 /usr/bin/python \
37
+ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
38
+
39
+ # 设置 Chromium 环境变量(无头模式运行)
40
+ ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
41
+ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
42
+ ENV CHROME_BIN=/usr/bin/chromium
43
+
44
+ # 安装 uv(快速的 Python 包管理器)
45
+ RUN curl -LsSf https://astral.sh/uv/install.sh | sh
46
+ ENV PATH="/root/.local/bin:$PATH"
47
+
48
+ # 设置工作目录
49
+ WORKDIR /app
50
+
51
+ # 全局安装 foliko CLI
52
+ # RUN npm install -g foliko
53
+
54
+ # 暴露端口
55
+ # 3000: Web 服务端口
56
+ EXPOSE 3000
57
+
58
+ # 环境变量(可以在 docker-compose 或运行时覆盖)
59
+ ENV NODE_ENV=production
60
+
61
+
62
+ # 默认命令:运行聊天界面
63
+ # CMD ["foliko", "chat"]
@@ -718,13 +718,13 @@ framework.workflows.list();
718
718
 
719
719
  // 获取单个工作流定义
720
720
  framework.workflows.get('my-workflow');
721
- // { name, description, steps: [...], type }
721
+ // { flow, version, stages: [...], description }
722
722
 
723
723
  // 检查工作流是否存在
724
724
  framework.workflows.has('my-workflow'); // true/false
725
725
 
726
- // 获取工作流引擎(用于创建步骤)
727
- framework.workflows.getEngine(); // WorkflowEngine 实例
726
+ // 获取工作流引擎(v2 FlowEngine 实例,实际执行路径)
727
+ framework.workflows.getEngine();
728
728
  ```
729
729
 
730
730
  #### 执行工作流
@@ -1,106 +1,111 @@
1
1
  /**
2
- * 工作流示例
3
- * 展示如何使用工作流引擎
2
+ * 工作流示例(v2 格式)
3
+ * 展示如何使用工作流引擎的 JSON / JS / 内联 schema 三种入口
4
4
  */
5
5
 
6
6
  const foliko = require('../src');
7
7
  const { WorkflowPlugin } = require('../plugins/core/workflow');
8
8
 
9
9
  async function main() {
10
- console.log('=== Workflow Example ===\n');
10
+ console.log('=== Workflow v2 Example ===\n');
11
11
 
12
12
  const framework = foliko.createApp({ debug: true });
13
13
 
14
14
  // 加载工作流插件
15
15
  await framework.loadPlugin(new WorkflowPlugin());
16
16
 
17
- console.log('\n--- Testing Script Step ---');
17
+ // --------------------------------------------------------------
18
+ // 示例 1:内联 JSON(v2 schema: stages + action: "script")
19
+ // --------------------------------------------------------------
20
+ console.log('\n--- Example 1: action:script stages ---');
18
21
  const result1 = await framework.executeTool('execute_workflow', {
19
22
  workflow: JSON.stringify({
20
- steps: [
23
+ flow: 'calc',
24
+ version: '2.0',
25
+ description: '两个 script stage 顺序执行,结果通过 $.data 串联',
26
+ stages: [
21
27
  {
22
- type: 'script',
23
- name: 'Calculate',
24
- script: `
25
- const a = 10;
26
- const b = 20;
27
- context.variables.sum = a + b;
28
- return a + b;
29
- `,
28
+ name: 'sum',
29
+ action: 'script',
30
+ script: '$.data.sum = 10 + 20; return $.data.sum;',
30
31
  },
31
32
  {
32
- type: 'script',
33
- name: 'Multiply',
34
- script: `
35
- const sum = context.variables.sum;
36
- context.variables.product = sum * 2;
37
- return sum * 2;
38
- `,
33
+ name: 'double',
34
+ action: 'script',
35
+ script: 'const sum = $.data.sum; $.data.product = sum * 2; return $.data.product;',
39
36
  },
40
37
  ],
41
38
  }),
42
39
  input: {},
43
40
  });
44
- console.log('Result:', result1);
41
+ console.log('Result:', JSON.stringify(result1, null, 2));
45
42
 
46
- console.log('\n--- Testing Loop Step ---');
43
+ // --------------------------------------------------------------
44
+ // 示例 2:each 循环(v2 schema: each + as + stages)
45
+ // --------------------------------------------------------------
46
+ console.log('\n--- Example 2: each loop ---');
47
47
  const result2 = await framework.executeTool('execute_workflow', {
48
48
  workflow: JSON.stringify({
49
- steps: [
49
+ flow: 'loop-demo',
50
+ version: '2.0',
51
+ input: { items: ['a', 'b', 'c'] },
52
+ stages: [
50
53
  {
51
- type: 'loop',
52
- name: 'Loop 3 times',
53
- maxIterations: 3,
54
- loopVariable: 'i',
55
- steps: [
54
+ name: 'process-items',
55
+ each: '{{input.items}}',
56
+ as: 'item',
57
+ index: 'i',
58
+ stages: [
56
59
  {
57
- type: 'script',
58
- name: 'Log iteration',
59
- script: `console.log('Iteration ' + context.variables.i); return context.variables.i;`,
60
+ name: 'log',
61
+ action: 'script',
62
+ script: 'return `iter ${$.data.i} = ${$.data.item}`;',
60
63
  },
61
64
  ],
62
65
  },
63
66
  ],
64
67
  }),
65
- input: {},
68
+ input: { items: ['a', 'b', 'c'] },
66
69
  });
67
- console.log('Result:', result2);
70
+ console.log('Result:', JSON.stringify(result2, null, 2));
68
71
 
69
- console.log('\n--- Testing Condition Step ---');
72
+ // --------------------------------------------------------------
73
+ // 示例 3:choice 分支(v2 schema: choice[] + default + 同级 stages)
74
+ // --------------------------------------------------------------
75
+ console.log('\n--- Example 3: choice routing ---');
70
76
  const result3 = await framework.executeTool('execute_workflow', {
71
77
  workflow: JSON.stringify({
72
- steps: [
78
+ flow: 'route-by-value',
79
+ version: '2.0',
80
+ stages: [
73
81
  {
74
- type: 'script',
75
- name: 'Set value',
76
- outputVariable: 'value',
77
- script: `context.variables.value = 15; return 15;`,
82
+ name: 'set-value',
83
+ action: 'script',
84
+ script: '$.data.value = 15; return $.data.value;',
78
85
  },
79
86
  {
80
- type: 'condition',
81
- name: 'Check value',
82
- branches: [
83
- {
84
- name: 'Greater than 10',
85
- condition: 'context.variables.value > 10',
86
- steps: [
87
- { type: 'script', name: 'Log greater', script: `console.log('Value is greater than 10'); return 'greater';` },
88
- ],
89
- },
90
- {
91
- name: 'Less than or equal 10',
92
- condition: 'context.variables.value <= 10',
93
- steps: [
94
- { type: 'script', name: 'Log less', script: `console.log('Value is less than or equal 10'); return 'less-or-equal';` },
95
- ],
96
- },
87
+ name: 'classify',
88
+ choice: [
89
+ { when: '$.data.value > 10', do: 'big' },
90
+ { when: '$.data.value <= 10', do: 'small' },
97
91
  ],
92
+ default: 'big',
93
+ },
94
+ {
95
+ name: 'big',
96
+ action: 'script',
97
+ script: 'return "value is greater than 10";',
98
+ },
99
+ {
100
+ name: 'small',
101
+ action: 'script',
102
+ script: 'return "value is less than or equal to 10";',
98
103
  },
99
104
  ],
100
105
  }),
101
106
  input: {},
102
107
  });
103
- console.log('Result:', result3);
108
+ console.log('Result:', JSON.stringify(result3, null, 2));
104
109
 
105
110
  // 清理
106
111
  await foliko.destroy(framework);