foliko 1.0.75 → 1.0.76
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/.claude/settings.local.json +159 -157
- package/cli/bin/foliko.js +12 -12
- package/cli/src/commands/chat.js +143 -143
- package/cli/src/commands/list.js +93 -93
- package/cli/src/index.js +75 -75
- package/cli/src/ui/chat-ui.js +201 -201
- package/cli/src/utils/ansi.js +40 -40
- package/cli/src/utils/markdown.js +292 -292
- package/examples/ambient-example.js +194 -194
- package/examples/basic.js +115 -115
- package/examples/bootstrap.js +121 -121
- package/examples/mcp-example.js +56 -56
- package/examples/skill-example.js +49 -49
- package/examples/test-chat.js +137 -137
- package/examples/test-mcp.js +85 -85
- package/examples/test-reload.js +59 -59
- package/examples/test-telegram.js +50 -50
- package/examples/test-tg-bot.js +45 -45
- package/examples/test-tg-simple.js +47 -47
- package/examples/test-tg.js +62 -62
- package/examples/test-think.js +43 -43
- package/examples/test-web-plugin.js +103 -103
- package/examples/test-weixin-feishu.js +103 -103
- package/examples/workflow.js +158 -158
- package/package.json +1 -1
- package/plugins/ai-plugin.js +102 -102
- package/plugins/ambient-agent/EventWatcher.js +113 -113
- package/plugins/ambient-agent/ExplorerLoop.js +640 -640
- package/plugins/ambient-agent/GoalManager.js +197 -197
- package/plugins/ambient-agent/Reflector.js +95 -95
- package/plugins/ambient-agent/StateStore.js +90 -90
- package/plugins/ambient-agent/constants.js +101 -101
- package/plugins/ambient-agent/index.js +579 -579
- package/plugins/audit-plugin.js +187 -187
- package/plugins/default-plugins.js +662 -662
- package/plugins/email/constants.js +64 -64
- package/plugins/email/handlers.js +461 -461
- package/plugins/email/index.js +278 -278
- package/plugins/email/monitor.js +269 -269
- package/plugins/email/parser.js +138 -138
- package/plugins/email/reply.js +151 -151
- package/plugins/email/utils.js +124 -124
- package/plugins/feishu-plugin.js +481 -481
- package/plugins/file-system-plugin.js +826 -826
- package/plugins/install-plugin.js +199 -199
- package/plugins/python-executor-plugin.js +367 -367
- package/plugins/python-plugin-loader.js +481 -481
- package/plugins/rules-plugin.js +294 -294
- package/plugins/scheduler-plugin.js +691 -691
- package/plugins/session-plugin.js +369 -369
- package/plugins/shell-executor-plugin.js +197 -197
- package/plugins/storage-plugin.js +240 -240
- package/plugins/subagent-plugin.js +845 -845
- package/plugins/telegram-plugin.js +482 -482
- package/plugins/think-plugin.js +345 -345
- package/plugins/tools-plugin.js +196 -196
- package/plugins/web-plugin.js +606 -606
- package/plugins/weixin-plugin.js +545 -545
- package/src/capabilities/index.js +11 -11
- package/src/capabilities/skill-manager.js +609 -609
- package/src/capabilities/workflow-engine.js +1109 -1109
- package/src/core/agent-chat.js +882 -882
- package/src/core/agent.js +892 -892
- package/src/core/framework.js +465 -465
- package/src/core/index.js +19 -19
- package/src/core/plugin-base.js +219 -219
- package/src/core/plugin-manager.js +863 -863
- package/src/core/provider.js +114 -114
- package/src/core/sub-agent-config.js +264 -264
- package/src/core/system-prompt-builder.js +120 -120
- package/src/core/tool-registry.js +517 -517
- package/src/core/tool-router.js +297 -297
- package/src/executors/executor-base.js +58 -58
- package/src/executors/mcp-executor.js +741 -741
- package/src/index.js +25 -25
- package/src/utils/circuit-breaker.js +301 -301
- package/src/utils/error-boundary.js +363 -363
- package/src/utils/error.js +374 -374
- package/src/utils/event-emitter.js +97 -97
- package/src/utils/id.js +133 -133
- package/src/utils/index.js +217 -217
- package/src/utils/logger.js +181 -181
- package/src/utils/plugin-helpers.js +90 -90
- package/src/utils/retry.js +122 -122
- package/src/utils/sandbox.js +292 -292
- package/test/tool-registry-validation.test.js +218 -218
- package/website/script.js +136 -136
- package/foliko-1.0.75.tgz +0 -0
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 微信/飞书插件测试
|
|
3
|
-
* 测试 chat() 方法(非流式)
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { Framework } = require('../src');
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
console.log('=== Weixin/Feishu Plugin Test ===\n');
|
|
10
|
-
|
|
11
|
-
const framework = new Framework({ debug: true });
|
|
12
|
-
|
|
13
|
-
// Bootstrap 加载默认插件
|
|
14
|
-
await framework.bootstrap({
|
|
15
|
-
agentDir: './.agent',
|
|
16
|
-
aiConfig: {
|
|
17
|
-
provider: 'deepseek',
|
|
18
|
-
model: 'deepseek-chat',
|
|
19
|
-
apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// 加载微信插件
|
|
24
|
-
const { WeixinPlugin } = require('../plugins/weixin-plugin');
|
|
25
|
-
const weixinPlugin = new WeixinPlugin({
|
|
26
|
-
forceLogin: false,
|
|
27
|
-
allowedUsers: [], // 空数组表示允许所有人
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// 加载飞书插件
|
|
31
|
-
const { FeishuPlugin } = require('../plugins/feishu-plugin');
|
|
32
|
-
const feishuPlugin = new FeishuPlugin({
|
|
33
|
-
// appId: 'your-app-id',
|
|
34
|
-
// appSecret: 'your-app-secret',
|
|
35
|
-
allowedUsers: [],
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// 注册插件(不自动加载)
|
|
39
|
-
// framework.registerPlugin(weixinPlugin)
|
|
40
|
-
// framework.registerPlugin(feishuPlugin)
|
|
41
|
-
|
|
42
|
-
console.log('\n--- Plugins Registered ---');
|
|
43
|
-
console.log(
|
|
44
|
-
'Plugins:',
|
|
45
|
-
framework.pluginManager.getAll().map((p) => p.name)
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// 创建测试 Agent
|
|
49
|
-
const agent = framework.createAgent({
|
|
50
|
-
name: 'TestAgent',
|
|
51
|
-
systemPrompt: '你是一个测试助手,回复要简洁。',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// 测试 chat() 方法(模拟消息处理)
|
|
55
|
-
console.log('\n--- Test chat() method ---');
|
|
56
|
-
|
|
57
|
-
// 模拟飞书的消息处理流程
|
|
58
|
-
const mockOpenId = 'test_user_001';
|
|
59
|
-
const mockText = '你好,请介绍一下你自己';
|
|
60
|
-
|
|
61
|
-
// 获取 session agent(内部逻辑)
|
|
62
|
-
const sessionInfo = {
|
|
63
|
-
agent: framework.createSessionAgent(`test_${mockOpenId}`, {
|
|
64
|
-
systemPrompt: feishuPlugin.systemPrompt,
|
|
65
|
-
}),
|
|
66
|
-
sessionId: `test_${mockOpenId}`,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
// 使用 chat() 而非 chatStream()
|
|
71
|
-
const result = await sessionInfo.agent.chat(mockText, {
|
|
72
|
-
sessionId: sessionInfo.sessionId,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
console.log('Result:', result);
|
|
76
|
-
console.log('Message:', result.message);
|
|
77
|
-
console.log('StepCount:', result.stepCount);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.error('Chat error:', err.message);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 测试 chatStream() 对比
|
|
83
|
-
console.log('\n--- Test chatStream() for comparison ---');
|
|
84
|
-
try {
|
|
85
|
-
let fullResponse = '';
|
|
86
|
-
for await (const chunk of sessionInfo.agent.chatStream('今天天气怎么样?', {
|
|
87
|
-
sessionId: sessionInfo.sessionId,
|
|
88
|
-
})) {
|
|
89
|
-
if (chunk.type === 'text' && chunk.text) {
|
|
90
|
-
fullResponse += chunk.text;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
console.log('Stream result:', fullResponse);
|
|
94
|
-
} catch (err) {
|
|
95
|
-
console.error('Stream error:', err.message);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 清理
|
|
99
|
-
await framework.destroy();
|
|
100
|
-
console.log('\n[Done]');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
main().catch(console.error);
|
|
1
|
+
/**
|
|
2
|
+
* 微信/飞书插件测试
|
|
3
|
+
* 测试 chat() 方法(非流式)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { Framework } = require('../src');
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
console.log('=== Weixin/Feishu Plugin Test ===\n');
|
|
10
|
+
|
|
11
|
+
const framework = new Framework({ debug: true });
|
|
12
|
+
|
|
13
|
+
// Bootstrap 加载默认插件
|
|
14
|
+
await framework.bootstrap({
|
|
15
|
+
agentDir: './.agent',
|
|
16
|
+
aiConfig: {
|
|
17
|
+
provider: 'deepseek',
|
|
18
|
+
model: 'deepseek-chat',
|
|
19
|
+
apiKey: process.env.DEEPSEEK_API_KEY || 'your-api-key',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// 加载微信插件
|
|
24
|
+
const { WeixinPlugin } = require('../plugins/weixin-plugin');
|
|
25
|
+
const weixinPlugin = new WeixinPlugin({
|
|
26
|
+
forceLogin: false,
|
|
27
|
+
allowedUsers: [], // 空数组表示允许所有人
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 加载飞书插件
|
|
31
|
+
const { FeishuPlugin } = require('../plugins/feishu-plugin');
|
|
32
|
+
const feishuPlugin = new FeishuPlugin({
|
|
33
|
+
// appId: 'your-app-id',
|
|
34
|
+
// appSecret: 'your-app-secret',
|
|
35
|
+
allowedUsers: [],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 注册插件(不自动加载)
|
|
39
|
+
// framework.registerPlugin(weixinPlugin)
|
|
40
|
+
// framework.registerPlugin(feishuPlugin)
|
|
41
|
+
|
|
42
|
+
console.log('\n--- Plugins Registered ---');
|
|
43
|
+
console.log(
|
|
44
|
+
'Plugins:',
|
|
45
|
+
framework.pluginManager.getAll().map((p) => p.name)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// 创建测试 Agent
|
|
49
|
+
const agent = framework.createAgent({
|
|
50
|
+
name: 'TestAgent',
|
|
51
|
+
systemPrompt: '你是一个测试助手,回复要简洁。',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 测试 chat() 方法(模拟消息处理)
|
|
55
|
+
console.log('\n--- Test chat() method ---');
|
|
56
|
+
|
|
57
|
+
// 模拟飞书的消息处理流程
|
|
58
|
+
const mockOpenId = 'test_user_001';
|
|
59
|
+
const mockText = '你好,请介绍一下你自己';
|
|
60
|
+
|
|
61
|
+
// 获取 session agent(内部逻辑)
|
|
62
|
+
const sessionInfo = {
|
|
63
|
+
agent: framework.createSessionAgent(`test_${mockOpenId}`, {
|
|
64
|
+
systemPrompt: feishuPlugin.systemPrompt,
|
|
65
|
+
}),
|
|
66
|
+
sessionId: `test_${mockOpenId}`,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
// 使用 chat() 而非 chatStream()
|
|
71
|
+
const result = await sessionInfo.agent.chat(mockText, {
|
|
72
|
+
sessionId: sessionInfo.sessionId,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log('Result:', result);
|
|
76
|
+
console.log('Message:', result.message);
|
|
77
|
+
console.log('StepCount:', result.stepCount);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error('Chat error:', err.message);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 测试 chatStream() 对比
|
|
83
|
+
console.log('\n--- Test chatStream() for comparison ---');
|
|
84
|
+
try {
|
|
85
|
+
let fullResponse = '';
|
|
86
|
+
for await (const chunk of sessionInfo.agent.chatStream('今天天气怎么样?', {
|
|
87
|
+
sessionId: sessionInfo.sessionId,
|
|
88
|
+
})) {
|
|
89
|
+
if (chunk.type === 'text' && chunk.text) {
|
|
90
|
+
fullResponse += chunk.text;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
console.log('Stream result:', fullResponse);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.error('Stream error:', err.message);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 清理
|
|
99
|
+
await framework.destroy();
|
|
100
|
+
console.log('\n[Done]');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
main().catch(console.error);
|
package/examples/workflow.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 工作流示例
|
|
3
|
-
* 展示如何使用工作流引擎
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { Framework } = require('../src');
|
|
7
|
-
const { WorkflowPlugin } = require('../src/capabilities/workflow-engine');
|
|
8
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
console.log('=== Workflow Example ===\n');
|
|
11
|
-
|
|
12
|
-
// 创建框架
|
|
13
|
-
const framework = new Framework({ debug: true });
|
|
14
|
-
|
|
15
|
-
// 加载工作流插件
|
|
16
|
-
await framework.loadPlugin(new WorkflowPlugin());
|
|
17
|
-
|
|
18
|
-
console.log('\n--- Testing Script Step ---');
|
|
19
|
-
|
|
20
|
-
// 直接执行工作流
|
|
21
|
-
const result1 = await framework.executeTool('execute_workflow', {
|
|
22
|
-
workflow: JSON.stringify({
|
|
23
|
-
steps: [
|
|
24
|
-
{
|
|
25
|
-
type: 'script',
|
|
26
|
-
name: 'Calculate',
|
|
27
|
-
script: `
|
|
28
|
-
const a = 10;
|
|
29
|
-
const b = 20;
|
|
30
|
-
context.variables.sum = a + b;
|
|
31
|
-
return a + b;
|
|
32
|
-
`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
type: 'script',
|
|
36
|
-
name: 'Multiply',
|
|
37
|
-
script: `
|
|
38
|
-
const sum = context.variables.sum;
|
|
39
|
-
context.variables.product = sum * 2;
|
|
40
|
-
return sum * 2;
|
|
41
|
-
`,
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
}),
|
|
45
|
-
input: {},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
console.log('Result:', result1);
|
|
49
|
-
|
|
50
|
-
console.log('\n--- Testing Loop Step ---');
|
|
51
|
-
|
|
52
|
-
const result2 = await framework.executeTool('execute_workflow', {
|
|
53
|
-
workflow: JSON.stringify({
|
|
54
|
-
steps: [
|
|
55
|
-
{
|
|
56
|
-
type: 'loop',
|
|
57
|
-
name: 'Loop 3 times',
|
|
58
|
-
maxIterations: 3,
|
|
59
|
-
loopVariable: 'i',
|
|
60
|
-
steps: [
|
|
61
|
-
{
|
|
62
|
-
type: 'script',
|
|
63
|
-
name: 'Log iteration',
|
|
64
|
-
script: `
|
|
65
|
-
console.log('Iteration ' + context.variables.i);
|
|
66
|
-
return context.variables.i;
|
|
67
|
-
`,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
}),
|
|
73
|
-
input: {},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
console.log('Result:', result2);
|
|
77
|
-
|
|
78
|
-
console.log('\n--- Testing Condition Step ---');
|
|
79
|
-
|
|
80
|
-
const result3 = await framework.executeTool('execute_workflow', {
|
|
81
|
-
workflow: JSON.stringify({
|
|
82
|
-
steps: [
|
|
83
|
-
{
|
|
84
|
-
type: 'script',
|
|
85
|
-
name: 'Set value',
|
|
86
|
-
outputVariable: 'value',
|
|
87
|
-
script: `
|
|
88
|
-
context.variables.value = 15;
|
|
89
|
-
return 15;
|
|
90
|
-
`,
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
type: 'condition',
|
|
94
|
-
name: 'Check value',
|
|
95
|
-
branches: [
|
|
96
|
-
{
|
|
97
|
-
name: 'Greater than 10',
|
|
98
|
-
condition: 'context.variables.value > 10',
|
|
99
|
-
steps: [
|
|
100
|
-
{
|
|
101
|
-
type: 'script',
|
|
102
|
-
name: 'Log greater',
|
|
103
|
-
script: `console.log('Value is greater than 10'); return 'greater';`,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'Less than or equal 10',
|
|
109
|
-
condition: 'context.variables.value <= 10',
|
|
110
|
-
steps: [
|
|
111
|
-
{
|
|
112
|
-
type: 'script',
|
|
113
|
-
name: 'Log less',
|
|
114
|
-
script: `console.log('Value is less than or equal 10'); return 'less-or-equal';`,
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
}),
|
|
122
|
-
input: {},
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
console.log('Result:', result3);
|
|
126
|
-
|
|
127
|
-
console.log('\n--- Testing Delay ---');
|
|
128
|
-
|
|
129
|
-
const startTime = Date.now();
|
|
130
|
-
const result4 = await framework.executeTool('execute_workflow', {
|
|
131
|
-
workflow: JSON.stringify({
|
|
132
|
-
steps: [
|
|
133
|
-
{
|
|
134
|
-
type: 'delay',
|
|
135
|
-
name: 'Wait 500ms',
|
|
136
|
-
delayMs: 500,
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
type: 'script',
|
|
140
|
-
name: 'Check elapsed',
|
|
141
|
-
script: `
|
|
142
|
-
const elapsed = Date.now() - context.variables.startTime;
|
|
143
|
-
return { elapsed: elapsed, expected: 500 };
|
|
144
|
-
`,
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
}),
|
|
148
|
-
input: {},
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
console.log('Result:', result4);
|
|
152
|
-
|
|
153
|
-
// 清理
|
|
154
|
-
await framework.destroy();
|
|
155
|
-
console.log('\n[Done]');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
main().catch(console.error);
|
|
1
|
+
/**
|
|
2
|
+
* 工作流示例
|
|
3
|
+
* 展示如何使用工作流引擎
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { Framework } = require('../src');
|
|
7
|
+
const { WorkflowPlugin } = require('../src/capabilities/workflow-engine');
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
console.log('=== Workflow Example ===\n');
|
|
11
|
+
|
|
12
|
+
// 创建框架
|
|
13
|
+
const framework = new Framework({ debug: true });
|
|
14
|
+
|
|
15
|
+
// 加载工作流插件
|
|
16
|
+
await framework.loadPlugin(new WorkflowPlugin());
|
|
17
|
+
|
|
18
|
+
console.log('\n--- Testing Script Step ---');
|
|
19
|
+
|
|
20
|
+
// 直接执行工作流
|
|
21
|
+
const result1 = await framework.executeTool('execute_workflow', {
|
|
22
|
+
workflow: JSON.stringify({
|
|
23
|
+
steps: [
|
|
24
|
+
{
|
|
25
|
+
type: 'script',
|
|
26
|
+
name: 'Calculate',
|
|
27
|
+
script: `
|
|
28
|
+
const a = 10;
|
|
29
|
+
const b = 20;
|
|
30
|
+
context.variables.sum = a + b;
|
|
31
|
+
return a + b;
|
|
32
|
+
`,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'script',
|
|
36
|
+
name: 'Multiply',
|
|
37
|
+
script: `
|
|
38
|
+
const sum = context.variables.sum;
|
|
39
|
+
context.variables.product = sum * 2;
|
|
40
|
+
return sum * 2;
|
|
41
|
+
`,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
}),
|
|
45
|
+
input: {},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
console.log('Result:', result1);
|
|
49
|
+
|
|
50
|
+
console.log('\n--- Testing Loop Step ---');
|
|
51
|
+
|
|
52
|
+
const result2 = await framework.executeTool('execute_workflow', {
|
|
53
|
+
workflow: JSON.stringify({
|
|
54
|
+
steps: [
|
|
55
|
+
{
|
|
56
|
+
type: 'loop',
|
|
57
|
+
name: 'Loop 3 times',
|
|
58
|
+
maxIterations: 3,
|
|
59
|
+
loopVariable: 'i',
|
|
60
|
+
steps: [
|
|
61
|
+
{
|
|
62
|
+
type: 'script',
|
|
63
|
+
name: 'Log iteration',
|
|
64
|
+
script: `
|
|
65
|
+
console.log('Iteration ' + context.variables.i);
|
|
66
|
+
return context.variables.i;
|
|
67
|
+
`,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
}),
|
|
73
|
+
input: {},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log('Result:', result2);
|
|
77
|
+
|
|
78
|
+
console.log('\n--- Testing Condition Step ---');
|
|
79
|
+
|
|
80
|
+
const result3 = await framework.executeTool('execute_workflow', {
|
|
81
|
+
workflow: JSON.stringify({
|
|
82
|
+
steps: [
|
|
83
|
+
{
|
|
84
|
+
type: 'script',
|
|
85
|
+
name: 'Set value',
|
|
86
|
+
outputVariable: 'value',
|
|
87
|
+
script: `
|
|
88
|
+
context.variables.value = 15;
|
|
89
|
+
return 15;
|
|
90
|
+
`,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: 'condition',
|
|
94
|
+
name: 'Check value',
|
|
95
|
+
branches: [
|
|
96
|
+
{
|
|
97
|
+
name: 'Greater than 10',
|
|
98
|
+
condition: 'context.variables.value > 10',
|
|
99
|
+
steps: [
|
|
100
|
+
{
|
|
101
|
+
type: 'script',
|
|
102
|
+
name: 'Log greater',
|
|
103
|
+
script: `console.log('Value is greater than 10'); return 'greater';`,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'Less than or equal 10',
|
|
109
|
+
condition: 'context.variables.value <= 10',
|
|
110
|
+
steps: [
|
|
111
|
+
{
|
|
112
|
+
type: 'script',
|
|
113
|
+
name: 'Log less',
|
|
114
|
+
script: `console.log('Value is less than or equal 10'); return 'less-or-equal';`,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
}),
|
|
122
|
+
input: {},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
console.log('Result:', result3);
|
|
126
|
+
|
|
127
|
+
console.log('\n--- Testing Delay ---');
|
|
128
|
+
|
|
129
|
+
const startTime = Date.now();
|
|
130
|
+
const result4 = await framework.executeTool('execute_workflow', {
|
|
131
|
+
workflow: JSON.stringify({
|
|
132
|
+
steps: [
|
|
133
|
+
{
|
|
134
|
+
type: 'delay',
|
|
135
|
+
name: 'Wait 500ms',
|
|
136
|
+
delayMs: 500,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
type: 'script',
|
|
140
|
+
name: 'Check elapsed',
|
|
141
|
+
script: `
|
|
142
|
+
const elapsed = Date.now() - context.variables.startTime;
|
|
143
|
+
return { elapsed: elapsed, expected: 500 };
|
|
144
|
+
`,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
}),
|
|
148
|
+
input: {},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
console.log('Result:', result4);
|
|
152
|
+
|
|
153
|
+
// 清理
|
|
154
|
+
await framework.destroy();
|
|
155
|
+
console.log('\n[Done]');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
main().catch(console.error);
|