foliko 2.0.1 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foliko",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "简约的插件化 Agent 框架",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
@@ -44,6 +44,7 @@ class AmbientAgentPlugin extends Plugin {
44
44
  this._explorerLoop = null
45
45
  this._memories = []
46
46
  this._thinkAgent = null
47
+ this._initialized = false
47
48
  }
48
49
 
49
50
  // ============================================================================
@@ -88,6 +89,9 @@ class AmbientAgentPlugin extends Plugin {
88
89
  }
89
90
 
90
91
  start(framework) {
92
+ if (this._initialized) return this;
93
+ this._initialized = true;
94
+
91
95
  if (!this.config.enabled) {
92
96
  // log.info('插件已禁用,跳过启动')
93
97
  return this
@@ -20,7 +20,7 @@ class CoordinatorPlugin extends Plugin {
20
20
  this.version = '1.0.0';
21
21
  this.description = 'Coordinator模式插件,支持多Worker协作';
22
22
  this.priority = 50;
23
- this.enabled = false
23
+ this.enabled = config.enabled === true
24
24
  this._framework = null;
25
25
  this._coordinatorAgent = null;
26
26
  }
@@ -56,6 +56,7 @@ class TelegramPlugin extends Plugin {
56
56
  this._sessionScopes = new Map()
57
57
  this._pendingResponses = new Map()
58
58
  this._thinkingMessages = new Map()
59
+ this._initialized = false
59
60
  }
60
61
 
61
62
  install(framework) {
@@ -64,6 +65,9 @@ class TelegramPlugin extends Plugin {
64
65
  }
65
66
 
66
67
  start(framework) {
68
+ if (this._initialized) return this;
69
+ this._initialized = true;
70
+
67
71
  if (!this.config.botToken) {
68
72
  log.warn(' No bot token. Set TELEGRAM_BOT_TOKEN env var.')
69
73
  return this
@@ -335,12 +335,21 @@ class PluginManager {
335
335
  this.framework?.emit('plugin:reloaded', newInstance);
336
336
  }
337
337
  } else {
338
- // 没有 sourcePath,调用 reload
338
+ // 没有 sourcePath,用现有实例重启
339
339
  if (typeof entry.instance.reload === 'function') {
340
+ // 有自定义 reload,由它处理完整重启(内部应调 start)
340
341
  await entry.instance.reload(this.framework);
341
- }
342
- if (typeof entry.instance.start === 'function') {
343
- await entry.instance.start(this.framework);
342
+ } else {
343
+ // 没有 reload,走完整 uninstall + install + start
344
+ if (typeof entry.instance.uninstall === 'function') {
345
+ entry.instance.uninstall(this.framework);
346
+ }
347
+ if (typeof entry.instance.install === 'function') {
348
+ entry.instance.install(this.framework);
349
+ }
350
+ if (typeof entry.instance.start === 'function') {
351
+ await entry.instance.start(this.framework);
352
+ }
344
353
  }
345
354
  entry.instance._started = true;
346
355
  }