@ai-setting/roy-agent-core 1.5.72 → 1.5.73

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/dist/env/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  import"../shared/@ai-setting/roy-agent-core-v8xa6vs8.js";
17
17
  import {
18
18
  PluginComponent
19
- } from "../shared/@ai-setting/roy-agent-core-ap59dpve.js";
19
+ } from "../shared/@ai-setting/roy-agent-core-p7grnnzp.js";
20
20
  import"../shared/@ai-setting/roy-agent-core-xp8xrxgc.js";
21
21
  import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
22
22
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PluginComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-ap59dpve.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-p7grnnzp.js";
4
4
  import {
5
5
  BasePlugin
6
6
  } from "../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
package/dist/index.js CHANGED
@@ -79,7 +79,7 @@ import {
79
79
  } from "./shared/@ai-setting/roy-agent-core-v8xa6vs8.js";
80
80
  import {
81
81
  PluginComponent
82
- } from "./shared/@ai-setting/roy-agent-core-ap59dpve.js";
82
+ } from "./shared/@ai-setting/roy-agent-core-p7grnnzp.js";
83
83
  import {
84
84
  TaskTagPlugin,
85
85
  createAutoTaskPlugin
@@ -1,3 +1,6 @@
1
+ import {
2
+ BasePlugin
3
+ } from "./roy-agent-core-az13yzmc.js";
1
4
  import {
2
5
  BaseComponent
3
6
  } from "./roy-agent-core-rgckng3p.js";
@@ -13,6 +16,9 @@ import {
13
16
  // src/env/plugin/plugin-component.ts
14
17
  init_global_hook_manager();
15
18
  init_logger();
19
+ import { existsSync, readFileSync } from "node:fs";
20
+ import { join } from "node:path";
21
+ import { homedir } from "node:os";
16
22
 
17
23
  class PluginComponent extends BaseComponent {
18
24
  name = "plugin";
@@ -32,27 +38,87 @@ class PluginComponent extends BaseComponent {
32
38
  }
33
39
  this.configComponent = options.configComponent;
34
40
  this.setStatus("running");
41
+ await this.loadInstalledPlugins();
35
42
  this.logger.info("[PluginComponent] Initialized");
36
43
  }
37
- register(plugin) {
44
+ async loadInstalledPlugins() {
45
+ const configPath = join(homedir(), ".roy-agent", "plugins.json");
46
+ if (!existsSync(configPath)) {
47
+ this.logger.debug("[PluginComponent] No plugins.json found, skipping auto-load");
48
+ return;
49
+ }
50
+ let config;
51
+ try {
52
+ const raw = readFileSync(configPath, "utf-8");
53
+ config = JSON.parse(raw);
54
+ } catch (err) {
55
+ this.logger.warn(`[PluginComponent] Failed to read plugins.json: ${err}`);
56
+ return;
57
+ }
58
+ const plugins = config.plugins ?? [];
59
+ if (plugins.length === 0) {
60
+ this.logger.debug("[PluginComponent] plugins.json is empty, skipping auto-load");
61
+ return;
62
+ }
63
+ this.logger.info(`[PluginComponent] Loading ${plugins.length} installed plugin(s) from plugins.json`);
64
+ for (const entry of plugins) {
65
+ try {
66
+ await this.loadPluginFromPackage(entry.packageName);
67
+ } catch (err) {
68
+ this.logger.error(`[PluginComponent] Failed to load plugin '${entry.packageName}': ${err}`);
69
+ }
70
+ }
71
+ }
72
+ async loadPluginFromPackage(packageName) {
73
+ let pluginModule;
74
+ try {
75
+ pluginModule = await import(packageName);
76
+ } catch (err) {
77
+ this.logger.warn(`[PluginComponent] Could not import plugin '${packageName}': ${err}`);
78
+ return;
79
+ }
80
+ const tryCreateInstance = (candidate, exportKind) => {
81
+ if (!candidate)
82
+ return;
83
+ if (candidate instanceof BasePlugin) {
84
+ return candidate;
85
+ }
86
+ if (typeof candidate === "function" && candidate.prototype instanceof BasePlugin) {
87
+ return new candidate;
88
+ }
89
+ if (typeof candidate === "object" && typeof candidate.name === "string" && typeof candidate.init === "function") {
90
+ this.logger.debug(`[PluginComponent] Plugin '${packageName}' ${exportKind} matches duck-type BasePlugin interface (instance)`);
91
+ return candidate;
92
+ }
93
+ if (typeof candidate === "function" && typeof candidate.prototype?.init === "function") {
94
+ this.logger.debug(`[PluginComponent] Plugin '${packageName}' ${exportKind} matches duck-type BasePlugin interface (class)`);
95
+ return new candidate;
96
+ }
97
+ return;
98
+ };
99
+ let pluginInstance;
100
+ if (pluginModule.default) {
101
+ pluginInstance = tryCreateInstance(pluginModule.default, "default export");
102
+ }
103
+ if (!pluginInstance && pluginModule.plugin) {
104
+ pluginInstance = tryCreateInstance(pluginModule.plugin, "named export 'plugin'");
105
+ }
106
+ if (!pluginInstance) {
107
+ this.logger.warn(`[PluginComponent] Plugin '${packageName}' does not export a valid plugin instance (expected default export or named export 'plugin' with { name, init, dispose? })`);
108
+ return;
109
+ }
110
+ await this.register(pluginInstance);
111
+ this.logger.info(`[PluginComponent] Loaded plugin: ${pluginInstance.name} (from ${packageName})`);
112
+ }
113
+ async register(plugin) {
38
114
  if (this.registry.has(plugin.name)) {
39
115
  throw new Error(`Plugin "${plugin.name}" is already registered`);
40
116
  }
41
117
  const env = this.createPluginEnv(plugin);
42
118
  try {
43
- const result = plugin.init(env);
44
- if (result instanceof Promise) {
45
- result.then(() => {
46
- this.registry.set(plugin.name, plugin);
47
- this.logger.info(`Registered plugin: ${plugin.name}`);
48
- }).catch((err) => {
49
- this.logger.error(`Failed to init plugin ${plugin.name}: ${err}`);
50
- throw err;
51
- });
52
- } else {
53
- this.registry.set(plugin.name, plugin);
54
- this.logger.info(`Registered plugin: ${plugin.name}`);
55
- }
119
+ await plugin.init(env);
120
+ this.registry.set(plugin.name, plugin);
121
+ this.logger.info(`Registered plugin: ${plugin.name}`);
56
122
  } catch (err) {
57
123
  this.logger.error(`Failed to init plugin ${plugin.name}: ${err}`);
58
124
  throw err;
@@ -84,9 +150,9 @@ class PluginComponent extends BaseComponent {
84
150
  getConfig(name) {
85
151
  return this.configComponent?.get(`plugin.${name}`);
86
152
  }
87
- registerAll(plugins) {
153
+ async registerAll(plugins) {
88
154
  for (const plugin of plugins) {
89
- this.register(plugin);
155
+ await this.register(plugin);
90
156
  }
91
157
  }
92
158
  async stop() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.72",
3
+ "version": "1.5.73",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",