@ai-setting/roy-agent-core 1.7.5 → 1.7.7
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
|
@@ -68,7 +68,7 @@ import"../shared/@ai-setting/roy-agent-core-c1v263jn.js";
|
|
|
68
68
|
import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
69
69
|
import {
|
|
70
70
|
PluginComponent
|
|
71
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
71
|
+
} from "../shared/@ai-setting/roy-agent-core-h9230kg6.js";
|
|
72
72
|
import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
73
73
|
import {
|
|
74
74
|
McpComponent
|
package/dist/env/plugin/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EventBusNotificationChannel,
|
|
3
3
|
PluginComponent
|
|
4
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
4
|
+
} from "../../shared/@ai-setting/roy-agent-core-h9230kg6.js";
|
|
5
5
|
import {
|
|
6
6
|
BasePlugin
|
|
7
7
|
} from "../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
package/dist/index.js
CHANGED
|
@@ -188,7 +188,7 @@ import {
|
|
|
188
188
|
} from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
189
189
|
import {
|
|
190
190
|
PluginComponent
|
|
191
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
191
|
+
} from "./shared/@ai-setting/roy-agent-core-h9230kg6.js";
|
|
192
192
|
import {
|
|
193
193
|
BasePlugin
|
|
194
194
|
} from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
createLogger,
|
|
19
19
|
init_logger
|
|
20
20
|
} from "./roy-agent-core-kaq037np.js";
|
|
21
|
+
import {
|
|
22
|
+
__require
|
|
23
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
21
24
|
|
|
22
25
|
// src/env/plugin/event-bus-notification-channel.ts
|
|
23
26
|
init_logger();
|
|
@@ -71,8 +74,35 @@ init_global_hook_manager();
|
|
|
71
74
|
init_logger();
|
|
72
75
|
init_context();
|
|
73
76
|
import { existsSync, readFileSync } from "node:fs";
|
|
74
|
-
import { join } from "node:path";
|
|
77
|
+
import { join, dirname } from "node:path";
|
|
75
78
|
import { homedir } from "node:os";
|
|
79
|
+
function readActualVersion(resolvedPath) {
|
|
80
|
+
let dir = dirname(resolvedPath);
|
|
81
|
+
const root = dirname(dir);
|
|
82
|
+
while (dir !== root) {
|
|
83
|
+
const pkgPath = join(dir, "package.json");
|
|
84
|
+
if (existsSync(pkgPath)) {
|
|
85
|
+
try {
|
|
86
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
87
|
+
return pkg.version ?? null;
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
dir = dirname(dir);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function checkVersionDrift(declaredVersion, resolvedPath, logger2) {
|
|
97
|
+
const actual = readActualVersion(resolvedPath);
|
|
98
|
+
const drifted = actual !== null && actual !== declaredVersion;
|
|
99
|
+
if (drifted && logger2) {
|
|
100
|
+
const pkgName = resolvedPath.includes("/node_modules/") ? resolvedPath.split("/node_modules/").pop() ?? resolvedPath : resolvedPath;
|
|
101
|
+
logger2.warn(`⚠️ Plugin '${pkgName}' version mismatch: declared ${declaredVersion} vs loaded ${actual} (path: ${resolvedPath})`);
|
|
102
|
+
}
|
|
103
|
+
return { declared: declaredVersion, actual, resolvedPath, drifted };
|
|
104
|
+
}
|
|
105
|
+
|
|
76
106
|
class PluginComponent extends BaseComponent {
|
|
77
107
|
name = "plugin";
|
|
78
108
|
version = "1.0.0";
|
|
@@ -127,42 +157,76 @@ class PluginComponent extends BaseComponent {
|
|
|
127
157
|
this.logger.info(`[PluginComponent] Loading ${allPlugins.length} installed plugin(s) from all configs`);
|
|
128
158
|
for (const entry of allPlugins) {
|
|
129
159
|
try {
|
|
130
|
-
await this.loadPluginFromPackage(entry.packageName);
|
|
160
|
+
await this.loadPluginFromPackage(entry.packageName, entry.version);
|
|
131
161
|
} catch (err) {
|
|
132
162
|
this.logger.error(`[PluginComponent] Failed to load plugin '${entry.packageName}': ${err}`);
|
|
133
163
|
}
|
|
134
164
|
}
|
|
135
165
|
}
|
|
136
|
-
async loadPluginFromPackage(packageName) {
|
|
166
|
+
async loadPluginFromPackage(packageName, declaredVersion) {
|
|
137
167
|
let pluginModule;
|
|
168
|
+
let resolvedPath = null;
|
|
138
169
|
try {
|
|
139
170
|
pluginModule = await import(packageName);
|
|
171
|
+
try {
|
|
172
|
+
const { createRequire } = await import("node:module");
|
|
173
|
+
const req = createRequire(import.meta.url);
|
|
174
|
+
resolvedPath = req.resolve(packageName);
|
|
175
|
+
} catch {}
|
|
140
176
|
} catch (_err) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
let loadedFromGlobalRoot = false;
|
|
178
|
+
try {
|
|
179
|
+
const { execSync } = await import("node:child_process");
|
|
180
|
+
const npmGlobalRoot = execSync("npm root -g", {
|
|
181
|
+
encoding: "utf-8",
|
|
182
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
183
|
+
}).trim();
|
|
184
|
+
if (npmGlobalRoot) {
|
|
185
|
+
const globalPkgPath = join(npmGlobalRoot, packageName);
|
|
186
|
+
if (existsSync(globalPkgPath)) {
|
|
187
|
+
this.logger.debug(`[PluginComponent] Falling back to npm global root: ${globalPkgPath}`);
|
|
188
|
+
pluginModule = await import(globalPkgPath);
|
|
189
|
+
resolvedPath = globalPkgPath;
|
|
190
|
+
loadedFromGlobalRoot = true;
|
|
191
|
+
}
|
|
149
192
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
193
|
+
} catch (npmRootErr) {
|
|
194
|
+
this.logger.debug(`[PluginComponent] npm root -g failed: ${npmRootErr}`);
|
|
195
|
+
}
|
|
196
|
+
if (!loadedFromGlobalRoot) {
|
|
197
|
+
const projectPluginPath = join(process.cwd(), ".roy", "plugins", packageName);
|
|
198
|
+
if (existsSync(projectPluginPath)) {
|
|
199
|
+
this.logger.debug(`[PluginComponent] Falling back to project plugin path: ${projectPluginPath}`);
|
|
154
200
|
try {
|
|
155
|
-
pluginModule = await import(
|
|
156
|
-
|
|
157
|
-
|
|
201
|
+
pluginModule = await import(projectPluginPath);
|
|
202
|
+
resolvedPath = projectPluginPath;
|
|
203
|
+
} catch (err2) {
|
|
204
|
+
this.logger.warn(`[PluginComponent] Could not import plugin '${packageName}' from project path: ${err2}`);
|
|
158
205
|
return;
|
|
159
206
|
}
|
|
160
207
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
208
|
+
const globalPluginPath = join(homedir(), ".roy-agent", "node_modules", packageName);
|
|
209
|
+
if (existsSync(globalPluginPath)) {
|
|
210
|
+
this.logger.debug(`[PluginComponent] Falling back to global plugin path: ${globalPluginPath}`);
|
|
211
|
+
try {
|
|
212
|
+
pluginModule = await import(globalPluginPath);
|
|
213
|
+
resolvedPath = globalPluginPath;
|
|
214
|
+
} catch (err3) {
|
|
215
|
+
this.logger.warn(`[PluginComponent] Could not import plugin '${packageName}' from global path: ${err3}`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
this.logger.warn(`[PluginComponent] Could not import plugin '${packageName}': ${_err}`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
163
222
|
}
|
|
164
223
|
}
|
|
165
224
|
}
|
|
225
|
+
if (declaredVersion && resolvedPath) {
|
|
226
|
+
checkVersionDrift(declaredVersion, resolvedPath, {
|
|
227
|
+
warn: (msg) => this.logger.warn(`[PluginComponent] ${msg}`)
|
|
228
|
+
});
|
|
229
|
+
}
|
|
166
230
|
const tryCreateInstance = (candidate, exportKind) => {
|
|
167
231
|
if (!candidate)
|
|
168
232
|
return;
|