foliko 1.0.75 → 1.0.77

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.
Files changed (89) hide show
  1. package/.claude/settings.local.json +159 -157
  2. package/.env.example +3 -1
  3. package/cli/bin/foliko.js +12 -12
  4. package/cli/src/commands/chat.js +143 -143
  5. package/cli/src/commands/list.js +93 -93
  6. package/cli/src/index.js +75 -75
  7. package/cli/src/ui/chat-ui.js +201 -201
  8. package/cli/src/utils/ansi.js +40 -40
  9. package/cli/src/utils/markdown.js +292 -292
  10. package/examples/ambient-example.js +194 -194
  11. package/examples/basic.js +115 -115
  12. package/examples/bootstrap.js +121 -121
  13. package/examples/mcp-example.js +56 -56
  14. package/examples/skill-example.js +49 -49
  15. package/examples/test-chat.js +137 -137
  16. package/examples/test-mcp.js +85 -85
  17. package/examples/test-reload.js +59 -59
  18. package/examples/test-telegram.js +50 -50
  19. package/examples/test-tg-bot.js +45 -45
  20. package/examples/test-tg-simple.js +47 -47
  21. package/examples/test-tg.js +62 -62
  22. package/examples/test-think.js +43 -43
  23. package/examples/test-web-plugin.js +103 -103
  24. package/examples/test-weixin-feishu.js +103 -103
  25. package/examples/workflow.js +158 -158
  26. package/package.json +81 -81
  27. package/plugins/ai-plugin.js +102 -102
  28. package/plugins/ambient-agent/EventWatcher.js +113 -113
  29. package/plugins/ambient-agent/ExplorerLoop.js +640 -640
  30. package/plugins/ambient-agent/GoalManager.js +197 -197
  31. package/plugins/ambient-agent/Reflector.js +95 -95
  32. package/plugins/ambient-agent/StateStore.js +90 -90
  33. package/plugins/ambient-agent/constants.js +101 -101
  34. package/plugins/ambient-agent/index.js +579 -579
  35. package/plugins/audit-plugin.js +187 -187
  36. package/plugins/default-plugins.js +662 -662
  37. package/plugins/email/constants.js +64 -64
  38. package/plugins/email/handlers.js +461 -461
  39. package/plugins/email/index.js +278 -278
  40. package/plugins/email/monitor.js +269 -269
  41. package/plugins/email/parser.js +138 -138
  42. package/plugins/email/reply.js +151 -151
  43. package/plugins/email/utils.js +124 -124
  44. package/plugins/feishu-plugin.js +481 -481
  45. package/plugins/file-system-plugin.js +826 -826
  46. package/plugins/install-plugin.js +199 -199
  47. package/plugins/python-executor-plugin.js +367 -367
  48. package/plugins/python-plugin-loader.js +481 -481
  49. package/plugins/rules-plugin.js +294 -294
  50. package/plugins/scheduler-plugin.js +691 -691
  51. package/plugins/session-plugin.js +369 -369
  52. package/plugins/shell-executor-plugin.js +197 -197
  53. package/plugins/storage-plugin.js +240 -240
  54. package/plugins/subagent-plugin.js +845 -845
  55. package/plugins/telegram-plugin.js +482 -482
  56. package/plugins/think-plugin.js +345 -345
  57. package/plugins/tools-plugin.js +196 -196
  58. package/plugins/web-plugin.js +606 -606
  59. package/plugins/weixin-plugin.js +545 -545
  60. package/src/capabilities/index.js +11 -11
  61. package/src/capabilities/skill-manager.js +609 -609
  62. package/src/capabilities/workflow-engine.js +1109 -1109
  63. package/src/core/agent-chat.js +882 -882
  64. package/src/core/agent.js +892 -892
  65. package/src/core/framework.js +465 -465
  66. package/src/core/index.js +19 -19
  67. package/src/core/plugin-base.js +219 -219
  68. package/src/core/plugin-manager.js +863 -863
  69. package/src/core/provider.js +114 -114
  70. package/src/core/sub-agent-config.js +264 -264
  71. package/src/core/system-prompt-builder.js +120 -120
  72. package/src/core/tool-registry.js +517 -517
  73. package/src/core/tool-router.js +297 -297
  74. package/src/executors/executor-base.js +58 -58
  75. package/src/executors/mcp-executor.js +741 -741
  76. package/src/index.js +25 -25
  77. package/src/utils/circuit-breaker.js +301 -301
  78. package/src/utils/error-boundary.js +363 -363
  79. package/src/utils/error.js +374 -374
  80. package/src/utils/event-emitter.js +97 -97
  81. package/src/utils/id.js +133 -133
  82. package/src/utils/index.js +217 -217
  83. package/src/utils/logger.js +181 -181
  84. package/src/utils/plugin-helpers.js +90 -90
  85. package/src/utils/retry.js +122 -122
  86. package/src/utils/sandbox.js +292 -292
  87. package/test/tool-registry-validation.test.js +218 -218
  88. package/website/script.js +136 -136
  89. package/foliko-1.0.75.tgz +0 -0
@@ -1,97 +1,97 @@
1
- /**
2
- * EventEmitter 事件发射器
3
- * 简单的事件总线实现
4
- */
5
-
6
- class EventEmitter {
7
- constructor() {
8
- this._events = new Map();
9
- }
10
-
11
- /**
12
- * 监听事件
13
- * @param {string} event - 事件名
14
- * @param {Function} handler - 处理函数
15
- * @returns {this}
16
- */
17
- on(event, handler) {
18
- if (!this._events.has(event)) {
19
- this._events.set(event, new Set());
20
- }
21
- this._events.get(event).add(handler);
22
- return this;
23
- }
24
-
25
- /**
26
- * 监听一次性事件
27
- * @param {string} event - 事件名
28
- * @param {Function} handler - 处理函数
29
- * @returns {this}
30
- */
31
- once(event, handler) {
32
- const wrapper = (...args) => {
33
- handler(...args);
34
- this.off(event, wrapper);
35
- };
36
- return this.on(event, wrapper);
37
- }
38
-
39
- /**
40
- * 取消监听
41
- * @param {string} event - 事件名
42
- * @param {Function} handler - 处理函数
43
- * @returns {this}
44
- */
45
- off(event, handler) {
46
- const handlers = this._events.get(event);
47
- if (handlers) {
48
- handlers.delete(handler);
49
- }
50
- return this;
51
- }
52
-
53
- /**
54
- * 触发事件
55
- * @param {string} event - 事件名
56
- * @param {...any} args - 参数
57
- * @returns {this}
58
- */
59
- emit(event, ...args) {
60
- const handlers = this._events.get(event);
61
- if (handlers) {
62
- for (const handler of handlers) {
63
- try {
64
- handler(...args);
65
- } catch (err) {
66
- // EventEmitter error: Error in handler for '${event}':`, err)
67
- }
68
- }
69
- }
70
- return this;
71
- }
72
-
73
- /**
74
- * 移除所有监听器
75
- * @param {string} [event] - 可选,指定事件名
76
- * @returns {this}
77
- */
78
- removeAllListeners(event) {
79
- if (event) {
80
- this._events.delete(event);
81
- } else {
82
- this._events.clear();
83
- }
84
- return this;
85
- }
86
-
87
- /**
88
- * 获取监听器数量
89
- * @param {string} event - 事件名
90
- * @returns {number}
91
- */
92
- listenerCount(event) {
93
- return this._events.get(event)?.size || 0;
94
- }
95
- }
96
-
97
- module.exports = { EventEmitter };
1
+ /**
2
+ * EventEmitter 事件发射器
3
+ * 简单的事件总线实现
4
+ */
5
+
6
+ class EventEmitter {
7
+ constructor() {
8
+ this._events = new Map();
9
+ }
10
+
11
+ /**
12
+ * 监听事件
13
+ * @param {string} event - 事件名
14
+ * @param {Function} handler - 处理函数
15
+ * @returns {this}
16
+ */
17
+ on(event, handler) {
18
+ if (!this._events.has(event)) {
19
+ this._events.set(event, new Set());
20
+ }
21
+ this._events.get(event).add(handler);
22
+ return this;
23
+ }
24
+
25
+ /**
26
+ * 监听一次性事件
27
+ * @param {string} event - 事件名
28
+ * @param {Function} handler - 处理函数
29
+ * @returns {this}
30
+ */
31
+ once(event, handler) {
32
+ const wrapper = (...args) => {
33
+ handler(...args);
34
+ this.off(event, wrapper);
35
+ };
36
+ return this.on(event, wrapper);
37
+ }
38
+
39
+ /**
40
+ * 取消监听
41
+ * @param {string} event - 事件名
42
+ * @param {Function} handler - 处理函数
43
+ * @returns {this}
44
+ */
45
+ off(event, handler) {
46
+ const handlers = this._events.get(event);
47
+ if (handlers) {
48
+ handlers.delete(handler);
49
+ }
50
+ return this;
51
+ }
52
+
53
+ /**
54
+ * 触发事件
55
+ * @param {string} event - 事件名
56
+ * @param {...any} args - 参数
57
+ * @returns {this}
58
+ */
59
+ emit(event, ...args) {
60
+ const handlers = this._events.get(event);
61
+ if (handlers) {
62
+ for (const handler of handlers) {
63
+ try {
64
+ handler(...args);
65
+ } catch (err) {
66
+ // EventEmitter error: Error in handler for '${event}':`, err)
67
+ }
68
+ }
69
+ }
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * 移除所有监听器
75
+ * @param {string} [event] - 可选,指定事件名
76
+ * @returns {this}
77
+ */
78
+ removeAllListeners(event) {
79
+ if (event) {
80
+ this._events.delete(event);
81
+ } else {
82
+ this._events.clear();
83
+ }
84
+ return this;
85
+ }
86
+
87
+ /**
88
+ * 获取监听器数量
89
+ * @param {string} event - 事件名
90
+ * @returns {number}
91
+ */
92
+ listenerCount(event) {
93
+ return this._events.get(event)?.size || 0;
94
+ }
95
+ }
96
+
97
+ module.exports = { EventEmitter };
package/src/utils/id.js CHANGED
@@ -1,133 +1,133 @@
1
- /**
2
- * Foliko ID 生成器 - 统一 ID 生成
3
- * 支持 UUID、ULID、雪花ID、自定义前缀
4
- */
5
-
6
- const crypto = require('crypto');
7
-
8
- /**
9
- * 生成标准 UUID v4
10
- * @returns {string}
11
- */
12
- function uuid() {
13
- if (crypto.randomUUID) {
14
- return crypto.randomUUID();
15
- }
16
- // 回退实现 (Node.js < 14.17)
17
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
18
- (c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
19
- );
20
- }
21
-
22
- /**
23
- * 生成带前缀的 UUID
24
- * @param {string} prefix - 前缀,如 'agent', 'session', 'task'
25
- * @returns {string}
26
- */
27
- function prefixedId(prefix = 'id') {
28
- return `${prefix}_${uuid()}`;
29
- }
30
-
31
- /**
32
- * 生成短 ID (无连字符)
33
- * @param {number} length - 长度,默认 12
34
- * @returns {string}
35
- */
36
- function shortId(length = 12) {
37
- return uuid().replace(/-/g, '').slice(0, length);
38
- }
39
-
40
- /**
41
- * 生成雪花 ID (Twitter Snowflake 简化版)
42
- * @returns {string}
43
- */
44
- let snowflakeEpoch = 1609459200000; // 2021-01-01
45
- let snowflakeSequence = 0;
46
- let snowflakeLastTime = 0;
47
-
48
- function snowflake() {
49
- const now = Date.now();
50
-
51
- if (now === snowflakeLastTime) {
52
- snowflakeSequence = (snowflakeSequence + 1) & 4095;
53
- } else {
54
- snowflakeSequence = 0;
55
- snowflakeLastTime = now;
56
- }
57
-
58
- const timestamp = now - snowflakeEpoch;
59
- const workerId = 1;
60
-
61
- const id = (BigInt(timestamp) << 22n) | (BigInt(workerId) << 12n) | BigInt(snowflakeSequence);
62
-
63
- return id.toString();
64
- }
65
-
66
- /**
67
- * 生成任务 ID (向后兼容原有格式)
68
- * @param {string} [prefix] - 可选前缀
69
- * @returns {string}
70
- */
71
- function taskId(prefix) {
72
- const suffix = crypto.randomBytes(8).toString('base64url');
73
- return prefix ? `${prefix}_${suffix}` : suffix;
74
- }
75
-
76
- /**
77
- * 生成目标 ID (向后兼容原有格式)
78
- * @returns {string}
79
- */
80
- function goalId() {
81
- const random = crypto.randomBytes(8).toString('base64url');
82
- return `goal_${Date.now()}_${random}`;
83
- }
84
-
85
- /**
86
- * 生成会话 ID (向后兼容原有格式)
87
- * @returns {string}
88
- */
89
- function sessionId() {
90
- const random = crypto.randomBytes(8).toString('base64url');
91
- return `session_${Date.now()}_${random}`;
92
- }
93
-
94
- /**
95
- * 生成邮箱消息 ID
96
- * @returns {string}
97
- */
98
- function messageId() {
99
- const timestamp = Date.now();
100
- const random = crypto.randomBytes(10).toString('base64url');
101
- return `<${timestamp}.${random}@foliko>`;
102
- }
103
-
104
- /**
105
- * 生成规则 ID
106
- * @returns {string}
107
- */
108
- function ruleId() {
109
- const random = crypto.randomBytes(8).toString('base64url');
110
- return `rule_${Date.now()}_${random}`;
111
- }
112
-
113
- /**
114
- * 重置雪花 ID 计数器 (用于测试)
115
- */
116
- function resetSnowflake() {
117
- snowflakeSequence = 0;
118
- snowflakeLastTime = 0;
119
- }
120
-
121
- // 导出所有函数
122
- module.exports = {
123
- uuid,
124
- prefixedId,
125
- shortId,
126
- snowflake,
127
- taskId,
128
- goalId,
129
- sessionId,
130
- messageId,
131
- ruleId,
132
- resetSnowflake,
133
- };
1
+ /**
2
+ * Foliko ID 生成器 - 统一 ID 生成
3
+ * 支持 UUID、ULID、雪花ID、自定义前缀
4
+ */
5
+
6
+ const crypto = require('crypto');
7
+
8
+ /**
9
+ * 生成标准 UUID v4
10
+ * @returns {string}
11
+ */
12
+ function uuid() {
13
+ if (crypto.randomUUID) {
14
+ return crypto.randomUUID();
15
+ }
16
+ // 回退实现 (Node.js < 14.17)
17
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
18
+ (c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)
19
+ );
20
+ }
21
+
22
+ /**
23
+ * 生成带前缀的 UUID
24
+ * @param {string} prefix - 前缀,如 'agent', 'session', 'task'
25
+ * @returns {string}
26
+ */
27
+ function prefixedId(prefix = 'id') {
28
+ return `${prefix}_${uuid()}`;
29
+ }
30
+
31
+ /**
32
+ * 生成短 ID (无连字符)
33
+ * @param {number} length - 长度,默认 12
34
+ * @returns {string}
35
+ */
36
+ function shortId(length = 12) {
37
+ return uuid().replace(/-/g, '').slice(0, length);
38
+ }
39
+
40
+ /**
41
+ * 生成雪花 ID (Twitter Snowflake 简化版)
42
+ * @returns {string}
43
+ */
44
+ let snowflakeEpoch = 1609459200000; // 2021-01-01
45
+ let snowflakeSequence = 0;
46
+ let snowflakeLastTime = 0;
47
+
48
+ function snowflake() {
49
+ const now = Date.now();
50
+
51
+ if (now === snowflakeLastTime) {
52
+ snowflakeSequence = (snowflakeSequence + 1) & 4095;
53
+ } else {
54
+ snowflakeSequence = 0;
55
+ snowflakeLastTime = now;
56
+ }
57
+
58
+ const timestamp = now - snowflakeEpoch;
59
+ const workerId = 1;
60
+
61
+ const id = (BigInt(timestamp) << 22n) | (BigInt(workerId) << 12n) | BigInt(snowflakeSequence);
62
+
63
+ return id.toString();
64
+ }
65
+
66
+ /**
67
+ * 生成任务 ID (向后兼容原有格式)
68
+ * @param {string} [prefix] - 可选前缀
69
+ * @returns {string}
70
+ */
71
+ function taskId(prefix) {
72
+ const suffix = crypto.randomBytes(8).toString('base64url');
73
+ return prefix ? `${prefix}_${suffix}` : suffix;
74
+ }
75
+
76
+ /**
77
+ * 生成目标 ID (向后兼容原有格式)
78
+ * @returns {string}
79
+ */
80
+ function goalId() {
81
+ const random = crypto.randomBytes(8).toString('base64url');
82
+ return `goal_${Date.now()}_${random}`;
83
+ }
84
+
85
+ /**
86
+ * 生成会话 ID (向后兼容原有格式)
87
+ * @returns {string}
88
+ */
89
+ function sessionId() {
90
+ const random = crypto.randomBytes(8).toString('base64url');
91
+ return `session_${Date.now()}_${random}`;
92
+ }
93
+
94
+ /**
95
+ * 生成邮箱消息 ID
96
+ * @returns {string}
97
+ */
98
+ function messageId() {
99
+ const timestamp = Date.now();
100
+ const random = crypto.randomBytes(10).toString('base64url');
101
+ return `<${timestamp}.${random}@foliko>`;
102
+ }
103
+
104
+ /**
105
+ * 生成规则 ID
106
+ * @returns {string}
107
+ */
108
+ function ruleId() {
109
+ const random = crypto.randomBytes(8).toString('base64url');
110
+ return `rule_${Date.now()}_${random}`;
111
+ }
112
+
113
+ /**
114
+ * 重置雪花 ID 计数器 (用于测试)
115
+ */
116
+ function resetSnowflake() {
117
+ snowflakeSequence = 0;
118
+ snowflakeLastTime = 0;
119
+ }
120
+
121
+ // 导出所有函数
122
+ module.exports = {
123
+ uuid,
124
+ prefixedId,
125
+ shortId,
126
+ snowflake,
127
+ taskId,
128
+ goalId,
129
+ sessionId,
130
+ messageId,
131
+ ruleId,
132
+ resetSnowflake,
133
+ };