foliko 1.0.74 → 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/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
- package/.agent/ARCHITECTURE.md +288 -0
- package/.agent/agents/ambient-agent.md +57 -0
- package/.agent/agents/debugger.md +55 -0
- package/.agent/agents/email-assistant.md +49 -0
- package/.agent/agents/file-manager.md +42 -0
- package/.agent/agents/python-developer.md +60 -0
- package/.agent/agents/scheduler.md +59 -0
- package/.agent/agents/web-developer.md +45 -0
- package/.agent/data/default.json +29 -0
- package/.agent/data/plugins-state.json +255 -0
- package/.agent/mcp_config.json +4 -0
- package/.agent/mcp_config_updated.json +12 -0
- package/.agent/plugins.json +5 -0
- package/.agent/rules/GEMINI.md +273 -0
- package/.agent/rules/allow-rule.md +77 -0
- package/.agent/rules/log-rule.md +83 -0
- package/.agent/rules/security-rule.md +93 -0
- package/.agent/scripts/auto_preview.py +148 -0
- package/.agent/scripts/checklist.py +217 -0
- package/.agent/scripts/session_manager.py +120 -0
- package/.agent/scripts/verify_all.py +327 -0
- package/.agent/skills/api-patterns/SKILL.md +81 -0
- package/.agent/skills/api-patterns/api-style.md +42 -0
- package/.agent/skills/api-patterns/auth.md +24 -0
- package/.agent/skills/api-patterns/documentation.md +26 -0
- package/.agent/skills/api-patterns/graphql.md +41 -0
- package/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/.agent/skills/api-patterns/response.md +37 -0
- package/.agent/skills/api-patterns/rest.md +40 -0
- package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/.agent/skills/api-patterns/security-testing.md +122 -0
- package/.agent/skills/api-patterns/trpc.md +41 -0
- package/.agent/skills/api-patterns/versioning.md +22 -0
- package/.agent/skills/app-builder/SKILL.md +75 -0
- package/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/.agent/skills/app-builder/feature-building.md +53 -0
- package/.agent/skills/app-builder/project-detection.md +34 -0
- package/.agent/skills/app-builder/scaffolding.md +118 -0
- package/.agent/skills/app-builder/tech-stack.md +40 -0
- package/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
- package/.agent/skills/architecture/SKILL.md +55 -0
- package/.agent/skills/architecture/context-discovery.md +43 -0
- package/.agent/skills/architecture/examples.md +94 -0
- package/.agent/skills/architecture/pattern-selection.md +68 -0
- package/.agent/skills/architecture/patterns-reference.md +50 -0
- package/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/.agent/skills/clean-code/SKILL.md +201 -0
- package/.agent/skills/doc.md +177 -0
- package/.agent/skills/frontend-design/SKILL.md +418 -0
- package/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/.agent/skills/frontend-design/color-system.md +311 -0
- package/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/.agent/skills/frontend-design/typography-system.md +345 -0
- package/.agent/skills/frontend-design/ux-psychology.md +1116 -0
- package/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/.agent/skills/mcp-builder/SKILL.md +176 -0
- package/.agent/skills/web-design-guidelines/SKILL.md +57 -0
- package/.agent/workflows/brainstorm.md +113 -0
- package/.agent/workflows/create.md +59 -0
- package/.agent/workflows/debug.md +103 -0
- package/.agent/workflows/deploy.md +176 -0
- package/.agent/workflows/enhance.md +63 -0
- package/.agent/workflows/orchestrate.md +237 -0
- package/.agent/workflows/plan.md +89 -0
- package/.agent/workflows/preview.md +81 -0
- package/.agent/workflows/simple-test.md +42 -0
- package/.agent/workflows/status.md +86 -0
- package/.agent/workflows/structured-orchestrate.md +180 -0
- package/.agent/workflows/test.md +144 -0
- package/.agent/workflows/ui-ux-pro-max.md +296 -0
- package/.claude/settings.local.json +11 -1
- package/.editorconfig +56 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +7 -0
- package/.prettierignore +29 -0
- package/.prettierrc +11 -0
- package/CLAUDE.md +2 -0
- package/README.md +64 -55
- package/SPEC.md +102 -61
- package/cli/bin/foliko.js +11 -11
- package/cli/src/commands/chat.js +143 -141
- package/cli/src/commands/list.js +93 -90
- package/cli/src/index.js +75 -75
- package/cli/src/ui/chat-ui.js +201 -199
- package/cli/src/utils/ansi.js +40 -40
- package/cli/src/utils/markdown.js +292 -296
- package/docker-compose.yml +1 -1
- package/docs/ai-sdk-optimization.md +655 -643
- package/docs/features.md +80 -80
- package/docs/quick-reference.md +49 -46
- package/docs/user-manual.md +411 -380
- package/examples/ambient-example.js +194 -196
- package/examples/basic.js +50 -45
- package/examples/bootstrap.js +121 -112
- package/examples/mcp-example.js +19 -16
- package/examples/skill-example.js +20 -20
- package/examples/test-chat.js +137 -135
- package/examples/test-mcp.js +85 -79
- package/examples/test-reload.js +59 -61
- package/examples/test-telegram.js +50 -50
- package/examples/test-tg-bot.js +45 -42
- package/examples/test-tg-simple.js +47 -46
- package/examples/test-tg.js +62 -62
- package/examples/test-think.js +43 -37
- package/examples/test-web-plugin.js +103 -98
- package/examples/test-weixin-feishu.js +103 -100
- package/examples/workflow.js +158 -158
- package/package.json +37 -3
- package/plugins/ai-plugin.js +102 -100
- package/plugins/ambient-agent/EventWatcher.js +113 -0
- package/plugins/ambient-agent/ExplorerLoop.js +640 -0
- package/plugins/ambient-agent/GoalManager.js +197 -0
- package/plugins/ambient-agent/Reflector.js +95 -0
- package/plugins/ambient-agent/StateStore.js +90 -0
- package/plugins/ambient-agent/constants.js +101 -0
- package/plugins/ambient-agent/index.js +579 -0
- package/plugins/audit-plugin.js +187 -187
- package/plugins/default-plugins.js +662 -649
- package/plugins/email/constants.js +64 -0
- package/plugins/email/handlers.js +461 -0
- package/plugins/email/index.js +278 -0
- package/plugins/email/monitor.js +269 -0
- package/plugins/email/parser.js +138 -0
- package/plugins/email/reply.js +151 -0
- package/plugins/email/utils.js +124 -0
- package/plugins/feishu-plugin.js +481 -477
- package/plugins/file-system-plugin.js +826 -476
- package/plugins/install-plugin.js +199 -197
- package/plugins/python-executor-plugin.js +367 -365
- package/plugins/python-plugin-loader.js +481 -479
- package/plugins/rules-plugin.js +294 -292
- package/plugins/scheduler-plugin.js +691 -689
- package/plugins/session-plugin.js +369 -367
- package/plugins/shell-executor-plugin.js +197 -197
- package/plugins/storage-plugin.js +240 -238
- package/plugins/subagent-plugin.js +845 -785
- package/plugins/telegram-plugin.js +482 -475
- package/plugins/think-plugin.js +345 -343
- package/plugins/tools-plugin.js +196 -194
- package/plugins/web-plugin.js +606 -604
- package/plugins/weixin-plugin.js +545 -538
- package/reports/system-health-report-20260401.md +79 -0
- package/skills/ambient-agent/SKILL.md +49 -39
- package/skills/foliko-dev/AGENTS.md +64 -61
- package/skills/foliko-dev/SKILL.md +125 -119
- package/skills/mcp-usage/SKILL.md +19 -17
- package/skills/python-plugin-dev/SKILL.md +16 -15
- package/skills/skill-guide/SKILL.md +12 -12
- package/skills/subagent-guide/SKILL.md +237 -0
- package/skills/workflow-guide/SKILL.md +90 -45
- package/skills/workflow-troubleshooting/DEBUGGING.md +36 -21
- package/skills/workflow-troubleshooting/SKILL.md +156 -79
- package/src/capabilities/index.js +11 -11
- package/src/capabilities/skill-manager.js +609 -595
- package/src/capabilities/workflow-engine.js +1109 -1195
- package/src/core/agent-chat.js +882 -735
- package/src/core/agent.js +892 -688
- package/src/core/framework.js +465 -431
- package/src/core/index.js +19 -19
- package/src/core/plugin-base.js +219 -219
- package/src/core/plugin-manager.js +863 -767
- package/src/core/provider.js +114 -111
- package/src/core/sub-agent-config.js +264 -0
- package/src/core/system-prompt-builder.js +120 -0
- package/src/core/tool-registry.js +517 -134
- package/src/core/tool-router.js +297 -216
- package/src/executors/executor-base.js +12 -12
- package/src/executors/mcp-executor.js +741 -729
- package/src/index.js +25 -37
- package/src/utils/circuit-breaker.js +301 -0
- package/src/utils/error-boundary.js +363 -0
- package/src/utils/error.js +374 -0
- package/src/utils/event-emitter.js +97 -97
- package/src/utils/id.js +133 -0
- package/src/utils/index.js +217 -3
- package/src/utils/logger.js +181 -0
- package/src/utils/plugin-helpers.js +90 -0
- package/src/utils/retry.js +122 -0
- package/src/utils/sandbox.js +292 -0
- package/test/tool-registry-validation.test.js +218 -0
- package/test_report.md +70 -0
- package/website/docs/api.html +169 -107
- package/website/docs/configuration.html +296 -144
- package/website/docs/plugin-development.html +154 -85
- package/website/docs/project-structure.html +110 -109
- package/website/docs/skill-development.html +117 -61
- package/website/index.html +209 -205
- package/website/script.js +136 -133
- package/website/styles.css +1 -1
- package/plugins/ambient-agent-plugin.js +0 -1565
- package/plugins/email.js +0 -1142
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 安全沙箱工具
|
|
3
|
+
* 用于替代 new Function() 执行不可信代码
|
|
4
|
+
* 提供安全的代码执行环境,限制对系统资源的访问
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { VM, VMScript } = require('vm2')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 创建安全的沙箱上下文
|
|
11
|
+
* @param {Object} customContext - 自定义上下文变量
|
|
12
|
+
* @param {Object} options - 配置选项
|
|
13
|
+
* @returns {Object} 沙箱上下文
|
|
14
|
+
*/
|
|
15
|
+
function createSandboxContext(customContext = {}, options = {}) {
|
|
16
|
+
const {
|
|
17
|
+
timeout = 5000, // 超时时间(毫秒)
|
|
18
|
+
allowSync = false, // 是否允许同步执行
|
|
19
|
+
mockConsole = true // 是否模拟 console
|
|
20
|
+
} = options
|
|
21
|
+
|
|
22
|
+
// 创建安全的 console 对象
|
|
23
|
+
const safeConsole = mockConsole ? {
|
|
24
|
+
log: (...args) => { /* 静默执行,阻止日志泄露 */ },
|
|
25
|
+
error: (...args) => { /* 静默执行 */ },
|
|
26
|
+
warn: (...args) => { /* 静默执行 */ },
|
|
27
|
+
info: (...args) => { /* 静默执行 */ },
|
|
28
|
+
debug: (...args) => { /* 静默执行 */ }
|
|
29
|
+
} : console
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
// 用户提供的上下文
|
|
33
|
+
...customContext,
|
|
34
|
+
// 安全的 console
|
|
35
|
+
console: safeConsole,
|
|
36
|
+
// 安全的 Math 对象
|
|
37
|
+
Math,
|
|
38
|
+
// 安全的 JSON 对象
|
|
39
|
+
JSON: {
|
|
40
|
+
parse: JSON.parse,
|
|
41
|
+
stringify: JSON.stringify
|
|
42
|
+
},
|
|
43
|
+
// 安全的 Array 对象(限制方法)
|
|
44
|
+
Array: {
|
|
45
|
+
isArray: Array.isArray,
|
|
46
|
+
from: Array.from,
|
|
47
|
+
of: Array.of
|
|
48
|
+
},
|
|
49
|
+
// 安全的 String 对象
|
|
50
|
+
String: {
|
|
51
|
+
fromCharCode: String.fromCharCode,
|
|
52
|
+
fromCodePoint: String.fromCodePoint,
|
|
53
|
+
raw: String.raw
|
|
54
|
+
},
|
|
55
|
+
// 安全的 Number 对象
|
|
56
|
+
Number: {
|
|
57
|
+
isNaN: Number.isNaN,
|
|
58
|
+
isFinite: Number.isFinite,
|
|
59
|
+
parseInt: Number.parseInt,
|
|
60
|
+
parseFloat: Number.parseFloat
|
|
61
|
+
},
|
|
62
|
+
// 安全的 Boolean 对象
|
|
63
|
+
Boolean,
|
|
64
|
+
// 安全的 Object 对象
|
|
65
|
+
Object: {
|
|
66
|
+
keys: Object.keys,
|
|
67
|
+
values: Object.values,
|
|
68
|
+
entries: Object.entries,
|
|
69
|
+
assign: Object.assign,
|
|
70
|
+
create: Object.create,
|
|
71
|
+
freeze: Object.freeze
|
|
72
|
+
},
|
|
73
|
+
// 安全的 Date 对象
|
|
74
|
+
Date: {
|
|
75
|
+
now: Date.now
|
|
76
|
+
},
|
|
77
|
+
// 安全的 RegExp 对象
|
|
78
|
+
RegExp,
|
|
79
|
+
// 安全的 Error 对象
|
|
80
|
+
Error,
|
|
81
|
+
// 安全的 Promise 对象
|
|
82
|
+
Promise,
|
|
83
|
+
// 安全的 Set 对象
|
|
84
|
+
Set,
|
|
85
|
+
// 安全的 Map 对象
|
|
86
|
+
Map,
|
|
87
|
+
// 安全的 WeakMap 对象
|
|
88
|
+
WeakMap,
|
|
89
|
+
// 安全的 WeakSet 对象
|
|
90
|
+
WeakSet,
|
|
91
|
+
// 安全的 Symbol
|
|
92
|
+
Symbol,
|
|
93
|
+
// 安全的 Proxy
|
|
94
|
+
Proxy,
|
|
95
|
+
// 安全的 Reflect
|
|
96
|
+
Reflect
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 在沙箱中执行异步代码
|
|
102
|
+
* @param {string} code - 要执行的代码
|
|
103
|
+
* @param {Object} context - 上下文变量
|
|
104
|
+
* @param {Object} options - 配置选项
|
|
105
|
+
* @returns {Promise<any>} 执行结果
|
|
106
|
+
*/
|
|
107
|
+
async function runInSandbox(code, context = {}, options = {}) {
|
|
108
|
+
const { timeout = 5000 } = options
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const vm = new VM({
|
|
112
|
+
timeout,
|
|
113
|
+
sandbox: createSandboxContext(context, options),
|
|
114
|
+
eval: false,
|
|
115
|
+
wasm: false
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
// 包装代码为异步函数
|
|
119
|
+
const wrappedCode = `(async () => { ${code} })()`
|
|
120
|
+
return await vm.run(wrappedCode)
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw new Error(`Sandbox execution error: ${error.message}`)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 在沙箱中执行表达式(同步)
|
|
128
|
+
* @param {string} expression - 要执行的表达式
|
|
129
|
+
* @param {Object} context - 上下文变量
|
|
130
|
+
* @param {Object} options - 配置选项
|
|
131
|
+
* @returns {any} 执行结果
|
|
132
|
+
*/
|
|
133
|
+
function evaluateInSandbox(expression, context = {}, options = {}) {
|
|
134
|
+
const { timeout = 5000 } = options
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const vm = new VM({
|
|
138
|
+
timeout,
|
|
139
|
+
sandbox: createSandboxContext(context, options),
|
|
140
|
+
eval: false,
|
|
141
|
+
wasm: false
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
return vm.run(expression)
|
|
145
|
+
} catch (error) {
|
|
146
|
+
throw new Error(`Sandbox evaluation error: ${error.message}`)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 安全执行脚本(用于工作流中的用户脚本)
|
|
152
|
+
* @param {string} script - 脚本代码
|
|
153
|
+
* @param {Object} context - 上下文变量
|
|
154
|
+
* @param {Object} options - 配置选项
|
|
155
|
+
* @returns {Promise<any>} 执行结果
|
|
156
|
+
*/
|
|
157
|
+
async function runScriptSafely(script, context = {}, options = {}) {
|
|
158
|
+
const { timeout = 10000 } = options
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const vm = new VM({
|
|
162
|
+
timeout,
|
|
163
|
+
sandbox: createSandboxContext(context, options),
|
|
164
|
+
eval: false,
|
|
165
|
+
wasm: false
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
// 将脚本包装在异步 IIFE 中
|
|
169
|
+
const wrappedCode = `
|
|
170
|
+
(async () => {
|
|
171
|
+
const { input, input_data, variables, previousResult, console } = context;
|
|
172
|
+
${script}
|
|
173
|
+
})()
|
|
174
|
+
`
|
|
175
|
+
|
|
176
|
+
return await vm.run(wrappedCode)
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw new Error(`Script execution error: ${error.message}`)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 安全执行工作流定义
|
|
184
|
+
* @param {string} workflowCode - 工作流代码
|
|
185
|
+
* @param {Object} engine - 工作流引擎
|
|
186
|
+
* @param {Object} options - 配置选项
|
|
187
|
+
* @returns {any} 执行结果
|
|
188
|
+
*/
|
|
189
|
+
function runWorkflowSafely(workflowCode, engine, options = {}) {
|
|
190
|
+
const { timeout = 5000 } = options
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
const vm = new VM({
|
|
194
|
+
timeout,
|
|
195
|
+
sandbox: {
|
|
196
|
+
engine,
|
|
197
|
+
console: {
|
|
198
|
+
log: () => {},
|
|
199
|
+
error: () => {},
|
|
200
|
+
warn: () => {},
|
|
201
|
+
info: () => {}
|
|
202
|
+
},
|
|
203
|
+
Math,
|
|
204
|
+
JSON,
|
|
205
|
+
Promise,
|
|
206
|
+
Array,
|
|
207
|
+
Object,
|
|
208
|
+
Date,
|
|
209
|
+
RegExp,
|
|
210
|
+
Error,
|
|
211
|
+
Symbol,
|
|
212
|
+
Map,
|
|
213
|
+
Set
|
|
214
|
+
},
|
|
215
|
+
eval: false,
|
|
216
|
+
wasm: false
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
return vm.run(`(function(engine) { return (${workflowCode}) })(engine)`)
|
|
220
|
+
} catch (error) {
|
|
221
|
+
throw new Error(`Workflow execution error: ${error.message}`)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 安全执行工作流加载脚本
|
|
227
|
+
* @param {string} content - 文件内容
|
|
228
|
+
* @param {Object} options - 配置选项
|
|
229
|
+
* @returns {Object} module.exports
|
|
230
|
+
*/
|
|
231
|
+
function runWorkflowFileSafely(content, options = {}) {
|
|
232
|
+
const { timeout = 10000 } = options
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const vm = new VM({
|
|
236
|
+
timeout,
|
|
237
|
+
sandbox: {
|
|
238
|
+
module: { exports: {} },
|
|
239
|
+
exports: {},
|
|
240
|
+
require: () => { throw new Error('require is not allowed in sandbox') },
|
|
241
|
+
process: {
|
|
242
|
+
env: {},
|
|
243
|
+
cwd: () => '/'
|
|
244
|
+
},
|
|
245
|
+
console: {
|
|
246
|
+
log: () => {},
|
|
247
|
+
error: () => {},
|
|
248
|
+
warn: () => {},
|
|
249
|
+
info: () => {}
|
|
250
|
+
},
|
|
251
|
+
__dirname: '/',
|
|
252
|
+
__filename: '/workflow.js',
|
|
253
|
+
Math,
|
|
254
|
+
JSON,
|
|
255
|
+
Promise,
|
|
256
|
+
Array,
|
|
257
|
+
Object,
|
|
258
|
+
Date,
|
|
259
|
+
RegExp,
|
|
260
|
+
Error,
|
|
261
|
+
Symbol,
|
|
262
|
+
Map,
|
|
263
|
+
Set
|
|
264
|
+
},
|
|
265
|
+
eval: false,
|
|
266
|
+
wasm: false
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
const wrappedCode = `
|
|
270
|
+
(function(module, exports, require, process, console, __dirname, __filename) {
|
|
271
|
+
${content}
|
|
272
|
+
})
|
|
273
|
+
`
|
|
274
|
+
|
|
275
|
+
const fn = vm.run(wrappedCode)
|
|
276
|
+
const moduleObj = { exports: {} }
|
|
277
|
+
fn(moduleObj, moduleObj.exports, () => {}, { env: {}, cwd: () => '/' }, { log: () => {}, error: () => {}, warn: () => {}, info: () => {} }, '/', '/workflow.js')
|
|
278
|
+
|
|
279
|
+
return moduleObj.exports.default || moduleObj.exports
|
|
280
|
+
} catch (error) {
|
|
281
|
+
throw new Error(`Workflow file execution error: ${error.message}`)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
module.exports = {
|
|
286
|
+
createSandboxContext,
|
|
287
|
+
runInSandbox,
|
|
288
|
+
evaluateInSandbox,
|
|
289
|
+
runScriptSafely,
|
|
290
|
+
runWorkflowSafely,
|
|
291
|
+
runWorkflowFileSafely
|
|
292
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具参数验证测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { ToolRegistry } = require('../src/core/tool-registry');
|
|
6
|
+
const { z } = require('zod');
|
|
7
|
+
|
|
8
|
+
async function runTests() {
|
|
9
|
+
console.log('🧪 开始工具参数验证测试\n');
|
|
10
|
+
let passed = 0;
|
|
11
|
+
let failed = 0;
|
|
12
|
+
|
|
13
|
+
// 创建工具注册表
|
|
14
|
+
const registry = new ToolRegistry({ circuitBreaker: false });
|
|
15
|
+
|
|
16
|
+
// 注册带 Zod schema 的工具
|
|
17
|
+
registry.register({
|
|
18
|
+
name: 'greet',
|
|
19
|
+
description: '打招呼工具',
|
|
20
|
+
inputSchema: z.object({
|
|
21
|
+
name: z.string().describe('姓名'),
|
|
22
|
+
age: z.number().optional().describe('年龄'),
|
|
23
|
+
role: z.enum(['admin', 'user', 'guest']).optional().describe('角色'),
|
|
24
|
+
}),
|
|
25
|
+
execute: async (args) => {
|
|
26
|
+
return `Hello, ${args.name}! You are ${args.age || 'unknown age'}.`;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 注册带 JSON Schema 的工具
|
|
31
|
+
registry.register({
|
|
32
|
+
name: 'calculate',
|
|
33
|
+
description: '计算工具',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
expression: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
description: '数学表达式',
|
|
40
|
+
},
|
|
41
|
+
precision: {
|
|
42
|
+
type: 'integer',
|
|
43
|
+
description: '精度',
|
|
44
|
+
minimum: 0,
|
|
45
|
+
maximum: 10,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
required: ['expression'],
|
|
49
|
+
},
|
|
50
|
+
execute: async (args) => {
|
|
51
|
+
return `Calculating: ${args.expression}`;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// 注册无 schema 的工具
|
|
56
|
+
registry.register({
|
|
57
|
+
name: 'echo',
|
|
58
|
+
description: '回声工具',
|
|
59
|
+
execute: async (args) => {
|
|
60
|
+
return args;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// 测试1: 有效的 Zod schema 参数
|
|
65
|
+
try {
|
|
66
|
+
const result = await registry.execute('greet', { name: 'Alice', age: 25 });
|
|
67
|
+
console.log('✅ 测试1 通过: 有效的 Zod schema 参数');
|
|
68
|
+
console.log(` 结果: ${result}\n`);
|
|
69
|
+
passed++;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log('❌ 测试1 失败:', err.message, '\n');
|
|
72
|
+
failed++;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 测试2: 缺少必需参数(Zod schema)
|
|
76
|
+
try {
|
|
77
|
+
await registry.execute('greet', { age: 25 });
|
|
78
|
+
console.log('❌ 测试2 失败: 应该抛出验证错误\n');
|
|
79
|
+
failed++;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err.validationErrors) {
|
|
82
|
+
console.log('✅ 测试2 通过: 缺少必需参数正确抛出验证错误');
|
|
83
|
+
console.log(` 错误详情: ${JSON.stringify(err.validationErrors, null, 2)}\n`);
|
|
84
|
+
passed++;
|
|
85
|
+
} else {
|
|
86
|
+
console.log('❌ 测试2 失败: 错误格式不正确\n');
|
|
87
|
+
failed++;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 测试3: 参数类型错误(Zod schema)
|
|
92
|
+
try {
|
|
93
|
+
await registry.execute('greet', { name: 123, age: 'twenty-five' });
|
|
94
|
+
console.log('❌ 测试3 失败: 应该抛出验证错误\n');
|
|
95
|
+
failed++;
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (err.validationErrors) {
|
|
98
|
+
console.log('✅ 测试3 通过: 参数类型错误正确抛出验证错误');
|
|
99
|
+
console.log(` 错误详情: ${JSON.stringify(err.validationErrors, null, 2)}\n`);
|
|
100
|
+
passed++;
|
|
101
|
+
} else {
|
|
102
|
+
console.log('❌ 测试3 失败: 错误格式不正确\n');
|
|
103
|
+
failed++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 测试4: 有效的 JSON Schema 参数
|
|
108
|
+
try {
|
|
109
|
+
const result = await registry.execute('calculate', { expression: '2+2', precision: 2 });
|
|
110
|
+
console.log('✅ 测试4 通过: 有效的 JSON Schema 参数');
|
|
111
|
+
console.log(` 结果: ${result}\n`);
|
|
112
|
+
passed++;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
console.log('❌ 测试4 失败:', err.message, '\n');
|
|
115
|
+
failed++;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 测试5: 缺少必需参数(JSON Schema)
|
|
119
|
+
try {
|
|
120
|
+
await registry.execute('calculate', { precision: 2 });
|
|
121
|
+
console.log('❌ 测试5 失败: 应该抛出验证错误\n');
|
|
122
|
+
failed++;
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if (err.validationErrors) {
|
|
125
|
+
console.log('✅ 测试5 通过: JSON Schema 缺少必需参数正确抛出验证错误');
|
|
126
|
+
console.log(` 错误详情: ${JSON.stringify(err.validationErrors, null, 2)}\n`);
|
|
127
|
+
passed++;
|
|
128
|
+
} else {
|
|
129
|
+
console.log('❌ 测试5 失败: 错误格式不正确\n');
|
|
130
|
+
failed++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 测试6: 超出范围验证(JSON Schema)
|
|
135
|
+
try {
|
|
136
|
+
await registry.execute('calculate', { expression: '2+2', precision: 15 });
|
|
137
|
+
console.log('❌ 测试6 失败: 应该抛出验证错误\n');
|
|
138
|
+
failed++;
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err.validationErrors) {
|
|
141
|
+
console.log('✅ 测试6 通过: JSON Schema 范围验证正确');
|
|
142
|
+
console.log(` 错误详情: ${JSON.stringify(err.validationErrors, null, 2)}\n`);
|
|
143
|
+
passed++;
|
|
144
|
+
} else {
|
|
145
|
+
console.log('❌ 测试6 失败: 错误格式不正确\n');
|
|
146
|
+
failed++;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 测试7: 无 schema 工具接受任意参数
|
|
151
|
+
try {
|
|
152
|
+
const result = await registry.execute('echo', { foo: 'bar', num: 42 });
|
|
153
|
+
console.log('✅ 测试7 通过: 无 schema 工具接受任意参数');
|
|
154
|
+
console.log(` 结果: ${JSON.stringify(result)}\n`);
|
|
155
|
+
passed++;
|
|
156
|
+
} catch (err) {
|
|
157
|
+
console.log('❌ 测试7 失败:', err.message, '\n');
|
|
158
|
+
failed++;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 测试8: 不存在的工具
|
|
162
|
+
try {
|
|
163
|
+
await registry.execute('nonexistent', {});
|
|
164
|
+
console.log('❌ 测试8 失败: 应该抛出工具不存在错误\n');
|
|
165
|
+
failed++;
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (err.message.includes('not found')) {
|
|
168
|
+
console.log('✅ 测试8 通过: 工具不存在正确抛出错误\n');
|
|
169
|
+
passed++;
|
|
170
|
+
} else {
|
|
171
|
+
console.log('❌ 测试8 失败: 错误类型不正确\n');
|
|
172
|
+
failed++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 测试9: 可选参数默认值
|
|
177
|
+
try {
|
|
178
|
+
const result = await registry.execute('greet', { name: 'Bob' });
|
|
179
|
+
console.log('✅ 测试9 通过: 可选参数使用默认值');
|
|
180
|
+
console.log(` 结果: ${result}\n`);
|
|
181
|
+
passed++;
|
|
182
|
+
} catch (err) {
|
|
183
|
+
console.log('❌ 测试9 失败:', err.message, '\n');
|
|
184
|
+
failed++;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 测试10: enum 验证
|
|
188
|
+
try {
|
|
189
|
+
await registry.execute('greet', { name: 'Charlie', role: 'hacker' });
|
|
190
|
+
console.log('❌ 测试10 失败: enum 值不正确应抛出错误\n');
|
|
191
|
+
failed++;
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (err.validationErrors) {
|
|
194
|
+
console.log('✅ 测试10 通过: enum 验证正确');
|
|
195
|
+
console.log(` 错误详情: ${JSON.stringify(err.validationErrors, null, 2)}\n`);
|
|
196
|
+
passed++;
|
|
197
|
+
} else {
|
|
198
|
+
console.log('❌ 测试10 失败: 错误格式不正确\n');
|
|
199
|
+
failed++;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 输出测试摘要
|
|
204
|
+
console.log('='.repeat(50));
|
|
205
|
+
console.log(`测试摘要: ${passed} 通过, ${failed} 失败`);
|
|
206
|
+
console.log('='.repeat(50));
|
|
207
|
+
|
|
208
|
+
return failed === 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
runTests()
|
|
212
|
+
.then((success) => {
|
|
213
|
+
process.exit(success ? 0 : 1);
|
|
214
|
+
})
|
|
215
|
+
.catch((err) => {
|
|
216
|
+
console.error('测试执行失败:', err);
|
|
217
|
+
process.exit(1);
|
|
218
|
+
});
|
package/test_report.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 协同测试报告
|
|
2
|
+
|
|
3
|
+
## 基本信息
|
|
4
|
+
|
|
5
|
+
- **测试日期**:2026-04-01 02:34:06
|
|
6
|
+
- **测试环境**:Windows
|
|
7
|
+
- **测试人员**:-
|
|
8
|
+
|
|
9
|
+
## 测试目的
|
|
10
|
+
|
|
11
|
+
本文档用于记录协同测试的相关信息和测试结果,验证系统在协同工作场景下的功能表现和稳定性。
|
|
12
|
+
|
|
13
|
+
### 主要测试目标
|
|
14
|
+
|
|
15
|
+
1. 验证系统核心功能的正常运行
|
|
16
|
+
2. 测试多模块协同工作的能力
|
|
17
|
+
3. 检查数据交互和状态同步的准确性
|
|
18
|
+
4. 评估系统在高负载场景下的表现
|
|
19
|
+
|
|
20
|
+
## 测试结果
|
|
21
|
+
|
|
22
|
+
| 测试项 | 状态 | 备注 |
|
|
23
|
+
|--------|------|------|
|
|
24
|
+
| - | - | - |
|
|
25
|
+
|
|
26
|
+
## 问题记录
|
|
27
|
+
|
|
28
|
+
| 序号 | 问题描述 | 严重程度 | 处理状态 |
|
|
29
|
+
|------|----------|----------|----------|
|
|
30
|
+
| - | - | - | - |
|
|
31
|
+
|
|
32
|
+
## 系统测试结果
|
|
33
|
+
|
|
34
|
+
### 系统配置汇总
|
|
35
|
+
|
|
36
|
+
| 项目 | 配置信息 |
|
|
37
|
+
|------|----------|
|
|
38
|
+
| 主机名 | Foliko |
|
|
39
|
+
| 操作系统 | Windows 11 |
|
|
40
|
+
| CPU | Intel Core i3-1220P 12核心 |
|
|
41
|
+
| 内存 | 23.75GB (已用 60.6%) |
|
|
42
|
+
|
|
43
|
+
### 公网连接信息
|
|
44
|
+
|
|
45
|
+
| 项目 | 信息 |
|
|
46
|
+
|------|------|
|
|
47
|
+
| 公网IP | 172.71.182.212 |
|
|
48
|
+
| 地理位置 | 荷兰阿姆斯特丹 |
|
|
49
|
+
| ISP | Cloudflare |
|
|
50
|
+
|
|
51
|
+
## 协同测试总结
|
|
52
|
+
|
|
53
|
+
### 各Agent执行状态
|
|
54
|
+
|
|
55
|
+
| Agent | 状态 | 备注 |
|
|
56
|
+
|-------|------|------|
|
|
57
|
+
| code-assistant | ✅ 正常 | 代码助手已就绪 |
|
|
58
|
+
| email-assistant | ✅ 正常 | 邮件助手已就绪 |
|
|
59
|
+
| file-assistant | ✅ 正常 | 文件助手已就绪 |
|
|
60
|
+
| system-assistant | ✅ 正常 | 系统助手已就绪 |
|
|
61
|
+
| web-assistant | ✅ 正常 | Web助手已就绪 |
|
|
62
|
+
|
|
63
|
+
### 测试完成时间戳
|
|
64
|
+
|
|
65
|
+
- **测试开始时间**:2026-04-01 02:34:06
|
|
66
|
+
- **测试完成时间**:2026-04-01 02:34:36
|
|
67
|
+
- **测试持续时长**:30秒
|
|
68
|
+
|
|
69
|
+
## 总结
|
|
70
|
+
|