@aopslabs/aops-server 0.2.1 → 0.2.3
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/THIRD_PARTY_NOTICES +425 -16
- package/THIRD_PARTY_NOTICES.inventory.json +70 -10
- package/build/client/_app/immutable/chunks/B88gKiyt.js +1 -0
- package/build/client/_app/immutable/entry/{app.a0iGCm6X.js → app.DyrORum_.js} +2 -2
- package/build/client/_app/immutable/entry/start.BCM14rdL.js +1 -0
- package/build/client/_app/immutable/nodes/{1.BtbjYUHR.js → 1.DM-iOsKD.js} +1 -1
- package/build/client/_app/version.json +1 -1
- package/build/handler.js +3 -3
- package/build/index.js +3 -3
- package/build/server/chunks/{1-UJuUicIe.js → 1-CbIMYd7N.js} +2 -2
- package/build/server/chunks/{_server.ts-6bdzoHJH.js → _server.ts-5jTLRkY0.js} +17 -6
- package/build/server/chunks/{_server.ts-u2UWBqNN.js → _server.ts-6MVYw3sO.js} +1 -1
- package/build/server/chunks/{_server.ts-DQzYSH_C.js → _server.ts-B7LBExsI.js} +12 -9
- package/build/server/chunks/{_server.ts-o9pJceJP.js → _server.ts-BF5YsxES.js} +1 -1
- package/build/server/chunks/{_server.ts-Ua5Ieisy.js → _server.ts-BUI8oOpK.js} +13 -10
- package/build/server/chunks/{_server.ts-Bz-Erv-1.js → _server.ts-BWMQcP-R.js} +1 -1
- package/build/server/chunks/{_server.ts-CRKd0KAC.js → _server.ts-Bd_TqS-J.js} +13 -10
- package/build/server/chunks/{_server.ts-BX4X0tW0.js → _server.ts-BrEAWHDb.js} +1 -1
- package/build/server/chunks/{_server.ts-DsTeOL2P.js → _server.ts-C1zRNRcN.js} +1 -1
- package/build/server/chunks/{_server.ts-DQWRrk5C.js → _server.ts-CQ436Lhs.js} +1 -1
- package/build/server/chunks/{_server.ts-N61POKjl.js → _server.ts-CX96Yo6-.js} +12 -9
- package/build/server/chunks/{_server.ts-BkxSxdd0.js → _server.ts-CkYsJYFX.js} +29 -68
- package/build/server/chunks/{_server.ts-DaIr3NkR.js → _server.ts-ClhXKSU-.js} +1 -1
- package/build/server/chunks/{_server.ts-B9gjXi95.js → _server.ts-D7mxMg8q.js} +1 -1
- package/build/server/chunks/{_server.ts-CjzSQgpk.js → _server.ts-DHaqrCbN.js} +11 -8
- package/build/server/chunks/{_server.ts-XmKDT59M.js → _server.ts-DbPb54XR.js} +13 -10
- package/build/server/chunks/{_server.ts-De9ZrSV0.js → _server.ts-P-bj5Kfv.js} +12 -9
- package/build/server/chunks/{_server.ts-AwMeEYiZ.js → _server.ts-p6Wxv_wG.js} +1 -1
- package/build/server/chunks/{agent-gateway-runtime-C7Kvvy0H.js → agent-gateway-runtime-DV-xLmJx.js} +39 -4
- package/build/server/chunks/commercial-admission-loader-ZGZHRPLe.js +480 -0
- package/build/server/chunks/{discovery-BvDEgiqC.js → discovery-DL0RzVks.js} +2 -2
- package/build/server/chunks/{error.svelte-B9R6O_Hn.js → error.svelte-BTdVSWca.js} +1 -1
- package/build/server/chunks/{handler-DurXhqww.js → handler-VLy1sI9x.js} +262 -2
- package/build/server/chunks/{hooks.server-DYGrWbgh.js → hooks.server-Zx-k_ERd.js} +1 -1
- package/build/server/chunks/{index.js-BQnOaW3H.js → index.js-CWgll4BT.js} +921 -924
- package/build/server/chunks/{manifest.js-CCJDdahY.js → manifest.js-C2lkmNzz.js} +20 -20
- package/build/server/chunks/{registry-DO8ob5o1.js → registry-DIreA2IZ.js} +132 -268
- package/cockpit/.vite/manifest.json +122 -122
- package/cockpit/community.module-inventory.json +30 -30
- package/host.config.json +140 -0
- package/npm-shrinkwrap.json +64 -2
- package/package.json +8 -2
- package/runtime/commercial-integrity-worker.mjs +8 -1
- package/runtime-closure.package.json +12 -1
- package/build/client/_app/immutable/chunks/BlANKL2r.js +0 -1
- package/build/client/_app/immutable/entry/start.Df7u6fQ1.js +0 -1
- package/build/server/chunks/admission-snapshot-C2wGfTWE.js +0 -1034
- package/build/server/chunks/canonical-text-order-DbXJJnFD.js +0 -5
- package/build/server/chunks/commercial-admission-loader-V_vXHdVa.js +0 -2077
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import fs__default, { existsSync } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
1
3
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import './aops-runtime-config-CHpDUCdE.js';
|
|
7
|
-
import { existsSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
|
+
import { createLeaseAdmissionProvider } from '@aopslabs/host-admission';
|
|
6
|
+
import { createTrustedLocalAuthorityProvider } from '@aopslabs/host-auth';
|
|
7
|
+
import { bootstrapHostRuntime, resolveHostConfig } from '@aopslabs/host-shell';
|
|
8
8
|
import { Worker } from 'node:worker_threads';
|
|
9
|
-
import {
|
|
9
|
+
import { AdmissionDecisionCache, buildAdmittedDomainSnapshot, CommercialArtifactError } from '@aopslabs/artifact-trust-contracts';
|
|
10
|
+
import './aops-runtime-config-CHpDUCdE.js';
|
|
11
|
+
import { validateHostConfig } from '@aopslabs/host-core';
|
|
10
12
|
|
|
11
13
|
const COMMUNITY_FREE_DOMAIN_IDS = Object.freeze([
|
|
12
14
|
"agentspace",
|
|
@@ -81,7 +83,7 @@ function applyScheduledCommercialIntegrityFailure(error, now) {
|
|
|
81
83
|
const configuredAdmission = process.env.AOPS_COMMERCIAL_ADMISSION_CONFIG?.trim();
|
|
82
84
|
if (configuredAdmission) {
|
|
83
85
|
try {
|
|
84
|
-
const { loadCommercialAdmissionSnapshot } = await import('./commercial-admission-loader-
|
|
86
|
+
const { loadCommercialAdmissionSnapshot } = await import('./commercial-admission-loader-ZGZHRPLe.js');
|
|
85
87
|
const loaded = loadCommercialAdmissionSnapshot(
|
|
86
88
|
configuredAdmission,
|
|
87
89
|
COMMUNITY_FREE_DOMAIN_IDS
|
|
@@ -99,9 +101,6 @@ if (configuredAdmission) {
|
|
|
99
101
|
function getHostAdmissionSnapshot() {
|
|
100
102
|
return cache.read();
|
|
101
103
|
}
|
|
102
|
-
function getCommercialRuntimeProjection() {
|
|
103
|
-
return commercialRuntime;
|
|
104
|
-
}
|
|
105
104
|
function runCommercialIntegrityVerificationWorker(input, now, options = {}) {
|
|
106
105
|
return new Promise((resolve, reject) => {
|
|
107
106
|
const workerData = {
|
|
@@ -168,7 +167,7 @@ async function runScheduledIntegrityVerification() {
|
|
|
168
167
|
dueAt: now.toISOString()
|
|
169
168
|
});
|
|
170
169
|
try {
|
|
171
|
-
const { resolveCommercialIntegrityWorkerInput } = await import('./commercial-admission-loader-
|
|
170
|
+
const { resolveCommercialIntegrityWorkerInput } = await import('./commercial-admission-loader-ZGZHRPLe.js');
|
|
172
171
|
await runCommercialIntegrityVerificationWorker(
|
|
173
172
|
resolveCommercialIntegrityWorkerInput(configuredAdmission),
|
|
174
173
|
now
|
|
@@ -195,7 +194,7 @@ async function planScheduledIntegrityVerification() {
|
|
|
195
194
|
if (!configuredAdmission || integrityWorkerRunning || integritySchedulerStopped) return;
|
|
196
195
|
const now = /* @__PURE__ */ new Date();
|
|
197
196
|
try {
|
|
198
|
-
const { readCommercialAdmissionIntegritySchedule } = await import('./commercial-admission-loader-
|
|
197
|
+
const { readCommercialAdmissionIntegritySchedule } = await import('./commercial-admission-loader-ZGZHRPLe.js');
|
|
199
198
|
const schedule = readCommercialAdmissionIntegritySchedule(configuredAdmission, now);
|
|
200
199
|
if (schedule.state === "authority-unavailable" || schedule.state === "quarantined") {
|
|
201
200
|
applyScheduledCommercialIntegrityFailure(
|
|
@@ -253,9 +252,6 @@ process.once(
|
|
|
253
252
|
function checkHostDomainAdmission(domain, operationId, now) {
|
|
254
253
|
return cache.check(domain, operationId, now);
|
|
255
254
|
}
|
|
256
|
-
function getAdmittedDomainIds() {
|
|
257
|
-
return getHostAdmissionSnapshot().orderedDomains.map((decision) => decision.domain);
|
|
258
|
-
}
|
|
259
255
|
function getHostAdmissionDiagnostics() {
|
|
260
256
|
const snapshot = getHostAdmissionSnapshot();
|
|
261
257
|
return Object.freeze({
|
|
@@ -283,6 +279,8 @@ function getHostAdmissionDiagnostics() {
|
|
|
283
279
|
})))
|
|
284
280
|
});
|
|
285
281
|
}
|
|
282
|
+
const profile = "static";
|
|
283
|
+
const authority = { "mode": "trusted-local" };
|
|
286
284
|
const host = { "name": "aops-community-server", "apiBasePath": "/api" };
|
|
287
285
|
const runtime = { "env": { "AOPS_PG_URL": { "fromEnv": "AOPS_PG_URL", "required": true } } };
|
|
288
286
|
const pluginLoader = { "strictAllowlist": true, "tolerantBootstrap": false, "allowlist": ["@aopslabs/domain-host-plugin-sys", "./runtime/agentspace-host-adapter.mjs", "./runtime/docman-host-adapter.mjs", "./runtime/projectman-host-adapter.mjs", "@aopslabs/domain-host-plugin-chatv3"] };
|
|
@@ -290,6 +288,8 @@ const diagnostics = { "exposePluginBootstrap": true };
|
|
|
290
288
|
const agentGateway = { "enabled": true, "includeLocal": true, "catalog": { "enabled": true, "manifestProviders": [{ "id": "sys-dcm", "domain": "sys", "enabled": true, "module": "@aopslabs/domain-kit-sys", "exportName": "buildSysDomainCapabilityManifest", "options": { "domainVersion": "0.0.1", "includeDocs": true } }, { "id": "agentspace-dcm", "domain": "agentspace", "enabled": true, "module": "./runtime/agentspace-tooling.mjs", "exportName": "buildCommunityAgentspaceDomainCapabilityManifest", "options": { "domainVersion": "0.0.4", "includeDocs": true } }, { "id": "docman-dcm", "domain": "docman", "enabled": true, "module": "./runtime/docman-tooling.mjs", "exportName": "buildAopsDocmanDomainCapabilityManifest", "options": { "domainVersion": "0.1.3", "includeDocs": true } }, { "id": "projectman-dcm", "domain": "projectman", "enabled": true, "module": "@aopslabs/domain-kit-projectman", "exportName": "buildProjectmanDomainCapabilityManifest", "options": { "domainVersion": "0.1.2", "includeDocs": true } }, { "id": "chatv3-dcm", "domain": "chatv3", "enabled": true, "module": "@aopslabs/domain-kit-chatv3", "exportName": "buildChatv3DomainCapabilityManifest", "options": { "domainVersion": "0.1.0", "includeDocs": true } }] }, "sources": [] };
|
|
291
289
|
const plugins = [{ "domain": "sys", "enabled": true, "module": "@aopslabs/domain-host-plugin-sys", "factory": "createSysPlugin" }, { "domain": "agentspace", "enabled": true, "module": "./runtime/agentspace-host-adapter.mjs", "factory": "createCommunityAgentspacePlugin", "options": { "defaultTenantId": "123e4567-e89b-41d4-a000-000000000001" } }, { "domain": "docman", "enabled": true, "module": "./runtime/docman-host-adapter.mjs", "factory": "createDocmanPlugin", "options": { "defaultScopeId": "00000000-0000-4000-8000-000000000000" } }, { "domain": "projectman", "enabled": true, "module": "./runtime/projectman-host-adapter.mjs", "factory": "createProjectmanPlugin", "options": { "defaultProjectId": "123e4567-e89b-41d4-a000-000000000000", "enableAopsWriteback": true, "failOnWritebackError": false } }, { "domain": "chatv3", "enabled": true, "module": "@aopslabs/domain-host-plugin-chatv3", "factory": "createChatv3Plugin" }];
|
|
292
290
|
const configRaw = {
|
|
291
|
+
profile,
|
|
292
|
+
authority,
|
|
293
293
|
host,
|
|
294
294
|
runtime,
|
|
295
295
|
pluginLoader,
|
|
@@ -297,22 +297,22 @@ const configRaw = {
|
|
|
297
297
|
agentGateway,
|
|
298
298
|
plugins
|
|
299
299
|
};
|
|
300
|
-
const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
300
|
+
const MODULE_DIR$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
301
301
|
const SERVER_PACKAGE_ROOT_CANDIDATE = [
|
|
302
|
-
path.resolve(MODULE_DIR, "../../.."),
|
|
303
|
-
path.resolve(MODULE_DIR, "../../../.."),
|
|
304
|
-
path.resolve(MODULE_DIR, "../..")
|
|
302
|
+
path.resolve(MODULE_DIR$1, "../../.."),
|
|
303
|
+
path.resolve(MODULE_DIR$1, "../../../.."),
|
|
304
|
+
path.resolve(MODULE_DIR$1, "../..")
|
|
305
305
|
].find(
|
|
306
306
|
(candidate) => existsSync(path.join(candidate, "runtime", "agentspace-host-adapter.mjs"))
|
|
307
307
|
);
|
|
308
308
|
if (!SERVER_PACKAGE_ROOT_CANDIDATE) {
|
|
309
309
|
throw new Error("community_server_package_root_not_found");
|
|
310
310
|
}
|
|
311
|
-
const SERVER_PACKAGE_ROOT = SERVER_PACKAGE_ROOT_CANDIDATE;
|
|
311
|
+
const SERVER_PACKAGE_ROOT$1 = SERVER_PACKAGE_ROOT_CANDIDATE;
|
|
312
312
|
function resolveCommunityPackageModule(moduleName) {
|
|
313
313
|
if (!moduleName) throw new Error("community_host_module_missing");
|
|
314
314
|
if (!moduleName.startsWith("./runtime/")) return moduleName;
|
|
315
|
-
return path.join(SERVER_PACKAGE_ROOT, moduleName.slice(2));
|
|
315
|
+
return path.join(SERVER_PACKAGE_ROOT$1, moduleName.slice(2));
|
|
316
316
|
}
|
|
317
317
|
const COMMUNITY_PLUGIN_MODULES = Object.freeze([
|
|
318
318
|
"@aopslabs/domain-host-plugin-sys",
|
|
@@ -354,50 +354,22 @@ function validateStaticCommunityConfig(input) {
|
|
|
354
354
|
if (config.pluginLoader) {
|
|
355
355
|
config.pluginLoader.allowlist = (config.pluginLoader.allowlist ?? []).map(resolveCommunityPackageModule);
|
|
356
356
|
}
|
|
357
|
-
const commercial = getCommercialRuntimeProjection();
|
|
358
|
-
if (commercial) {
|
|
359
|
-
config.plugins = [
|
|
360
|
-
...config.plugins ?? [],
|
|
361
|
-
{
|
|
362
|
-
domain: commercial.domain,
|
|
363
|
-
enabled: true,
|
|
364
|
-
module: commercial.pluginModule,
|
|
365
|
-
factory: commercial.pluginFactory
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
const catalog = config.agentGateway?.catalog;
|
|
369
|
-
if (!catalog) throw new Error("community_host_config_catalog_missing");
|
|
370
|
-
catalog.manifestProviders = [
|
|
371
|
-
...catalog.manifestProviders ?? [],
|
|
372
|
-
{
|
|
373
|
-
id: `${commercial.domain}-commercial-dcm`,
|
|
374
|
-
domain: commercial.domain,
|
|
375
|
-
enabled: true,
|
|
376
|
-
module: commercial.manifestModule,
|
|
377
|
-
exportName: commercial.manifestExport
|
|
378
|
-
}
|
|
379
|
-
];
|
|
380
|
-
const loader = config.pluginLoader;
|
|
381
|
-
if (!loader) throw new Error("community_host_config_plugin_loader_missing");
|
|
382
|
-
loader.allowlist = [...loader.allowlist ?? [], commercial.pluginModule];
|
|
383
|
-
}
|
|
384
357
|
const issues = validateHostConfig(config);
|
|
385
358
|
if (issues.length > 0) {
|
|
386
359
|
const first = issues[0];
|
|
387
360
|
throw new Error(`host_config_invalid:${first.code}:${first.path}`);
|
|
388
361
|
}
|
|
389
362
|
const domains = inventory(config);
|
|
390
|
-
|
|
391
|
-
exactSet("
|
|
392
|
-
exactSet("manifest-providers", domains.manifestProviderDomains, admittedDomains);
|
|
363
|
+
exactSet("plugins", domains.pluginDomains, COMMUNITY_FREE_DOMAIN_IDS);
|
|
364
|
+
exactSet("manifest-providers", domains.manifestProviderDomains, COMMUNITY_FREE_DOMAIN_IDS);
|
|
393
365
|
exactSet("remote-sources", domains.sourceDomains, []);
|
|
394
366
|
exactSet(
|
|
395
367
|
"plugin-loader",
|
|
396
368
|
config.pluginLoader?.allowlist ?? [],
|
|
397
|
-
|
|
369
|
+
COMMUNITY_PLUGIN_MODULES
|
|
398
370
|
);
|
|
399
371
|
exactSet("runtime-env", Object.keys(config.runtime?.env ?? {}), COMMUNITY_RUNTIME_ENV_KEYS);
|
|
400
|
-
if (config.pluginLoader?.strictAllowlist !== true || config.pluginLoader?.tolerantBootstrap !== false || config.agentGateway?.enabled !== true || config.agentGateway?.includeLocal !== true || config.agentGateway?.catalog?.enabled !== true) {
|
|
372
|
+
if (config.profile !== "static" || config.authority?.mode !== "trusted-local" || config.pluginLoader?.strictAllowlist !== true || config.pluginLoader?.tolerantBootstrap !== false || config.agentGateway?.enabled !== true || config.agentGateway?.includeLocal !== true || config.agentGateway?.catalog?.enabled !== true) {
|
|
401
373
|
throw new Error("community_host_config_policy_mismatch");
|
|
402
374
|
}
|
|
403
375
|
return config;
|
|
@@ -423,238 +395,130 @@ function getHostRegistrationDiagnostics() {
|
|
|
423
395
|
registrations: []
|
|
424
396
|
};
|
|
425
397
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
398
|
+
const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
399
|
+
const SERVER_PACKAGE_ROOT = [
|
|
400
|
+
path.resolve(MODULE_DIR, "../.."),
|
|
401
|
+
path.resolve(MODULE_DIR, "../../.."),
|
|
402
|
+
path.resolve(process.cwd(), "apps/aops-server"),
|
|
403
|
+
path.resolve(process.cwd())
|
|
404
|
+
].find((candidate) => fs__default.existsSync(path.join(candidate, "host.config.json")));
|
|
405
|
+
if (!SERVER_PACKAGE_ROOT) {
|
|
406
|
+
throw new Error("aops_kernel_server_package_root_not_found");
|
|
407
|
+
}
|
|
408
|
+
let cachedSnapshot = null;
|
|
409
|
+
let cachedSnapshotPromise = null;
|
|
410
|
+
function normalized(value) {
|
|
411
|
+
return typeof value === "string" ? value.trim() : "";
|
|
412
|
+
}
|
|
413
|
+
function resolveKernelHostConfigPath() {
|
|
414
|
+
const explicit = normalized(process.env.AOPS_HOST_CONFIG);
|
|
415
|
+
return explicit ? path.resolve(explicit) : path.join(SERVER_PACKAGE_ROOT, "host.config.json");
|
|
416
|
+
}
|
|
417
|
+
function kernelBootstrapOptions() {
|
|
418
|
+
getHostConfig();
|
|
419
|
+
const configPath = resolveKernelHostConfigPath();
|
|
420
|
+
const stateRoot = path.resolve(
|
|
421
|
+
normalized(process.env.AOPS_STATE_ROOT) || path.join(os.homedir(), ".aops")
|
|
422
|
+
);
|
|
423
|
+
const common = {
|
|
424
|
+
brand: "aops",
|
|
425
|
+
profile: "static",
|
|
426
|
+
configPath,
|
|
427
|
+
stateRoot,
|
|
428
|
+
registrationsDir: path.join(stateRoot, "host-registrations"),
|
|
429
|
+
moduleSearchRoot: SERVER_PACKAGE_ROOT,
|
|
430
|
+
processEnv: process.env
|
|
431
|
+
};
|
|
432
|
+
const resolved = resolveHostConfig(common);
|
|
433
|
+
if (resolved.profile !== "static" || resolved.registrations.length !== 0) {
|
|
434
|
+
throw new Error("aops_kernel_static_profile_required");
|
|
435
|
+
}
|
|
436
|
+
if (resolved.authority.mode !== "trusted-local") {
|
|
437
|
+
throw new Error("aops_kernel_trusted_local_authority_required");
|
|
436
438
|
}
|
|
437
|
-
}
|
|
438
|
-
function guardCommercialPluginExecution(instance, domain, checkAdmission) {
|
|
439
|
-
const baseExecute = instance.execute;
|
|
440
|
-
if (typeof baseExecute !== "function") return instance;
|
|
441
439
|
return {
|
|
442
|
-
...
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
440
|
+
...common,
|
|
441
|
+
authority: createTrustedLocalAuthorityProvider({
|
|
442
|
+
principalId: "aops-local-operator",
|
|
443
|
+
tenantId: "123e4567-e89b-41d4-a000-000000000001",
|
|
444
|
+
roles: ["admin", "operator"],
|
|
445
|
+
requireLoopback: false
|
|
446
|
+
}),
|
|
447
|
+
admission: createLeaseAdmissionProvider({
|
|
448
|
+
generation: 1,
|
|
449
|
+
freeDomains: COMMUNITY_FREE_DOMAIN_IDS,
|
|
450
|
+
licensedDomains: []
|
|
451
|
+
})
|
|
454
452
|
};
|
|
455
453
|
}
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
state: "idle",
|
|
462
|
-
loadedDomains: [],
|
|
463
|
-
plugins: []
|
|
464
|
-
};
|
|
465
|
-
let singletonPromise = null;
|
|
466
|
-
let bootstrapAttempt = 0;
|
|
467
|
-
let registryDiagnostics = { ...DEFAULT_DIAGNOSTICS };
|
|
468
|
-
function extractErrorMessage(error) {
|
|
469
|
-
if (error instanceof Error) return error.message;
|
|
470
|
-
return String(error ?? "unknown_error");
|
|
471
|
-
}
|
|
472
|
-
function resolveModuleSpecifier(moduleName) {
|
|
473
|
-
const trimmed = moduleName.trim();
|
|
474
|
-
if (!trimmed) return trimmed;
|
|
475
|
-
if (trimmed.startsWith("file://")) return trimmed;
|
|
476
|
-
if (path.isAbsolute(trimmed)) return pathToFileURL(trimmed).href;
|
|
477
|
-
if (!trimmed.startsWith(".")) {
|
|
478
|
-
const resolvePaths = [process.cwd(), path.resolve(process.cwd(), "apps/aops-server")];
|
|
479
|
-
try {
|
|
480
|
-
const resolved = nodeRequire.resolve(trimmed, { paths: resolvePaths });
|
|
481
|
-
return pathToFileURL(resolved).href;
|
|
482
|
-
} catch {
|
|
483
|
-
return trimmed;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
const absolutePath = path.resolve(process.cwd(), trimmed);
|
|
487
|
-
return pathToFileURL(absolutePath).href;
|
|
488
|
-
}
|
|
489
|
-
function withImportVersion(specifier) {
|
|
490
|
-
if (!specifier.startsWith("file://")) return specifier;
|
|
491
|
-
const url = new URL(specifier);
|
|
492
|
-
url.searchParams.set("v", String(pluginImportVersion));
|
|
493
|
-
return url.href;
|
|
494
|
-
}
|
|
495
|
-
function isModuleAllowed(moduleName, resolvedSpecifier, policy) {
|
|
496
|
-
const allowlist = policy.allowlist ?? [];
|
|
497
|
-
if (allowlist.length === 0) return policy.strictAllowlist === false;
|
|
498
|
-
return allowlist.includes(moduleName) || allowlist.includes(resolvedSpecifier);
|
|
499
|
-
}
|
|
500
|
-
function assertModuleAllowed(moduleName, resolvedSpecifier, pluginConfig, policy) {
|
|
501
|
-
if (isModuleAllowed(moduleName, resolvedSpecifier, policy)) return;
|
|
502
|
-
if ((policy.allowlist ?? []).length === 0 && policy.strictAllowlist) {
|
|
503
|
-
throw new Error(`plugin_module_allowlist_empty:${pluginConfig.domain}`);
|
|
454
|
+
async function warmupRuntime(runtime2) {
|
|
455
|
+
for (const domain of runtime2.registry.listDomains()) {
|
|
456
|
+
await runtime2.registry.ensureSetup(domain);
|
|
457
|
+
const plugin = runtime2.registry.get(domain);
|
|
458
|
+
if (plugin?.health) await plugin.health();
|
|
504
459
|
}
|
|
505
|
-
throw new Error(`plugin_module_not_allowed:${pluginConfig.domain}:${moduleName}`);
|
|
506
460
|
}
|
|
507
|
-
async function
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
510
|
-
|
|
461
|
+
async function buildKernelRuntimeSnapshot(options = {}) {
|
|
462
|
+
const kernel = await bootstrapHostRuntime(kernelBootstrapOptions());
|
|
463
|
+
if (options.warmup) await warmupRuntime(kernel);
|
|
464
|
+
return {
|
|
465
|
+
loadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
466
|
+
warmupCompleted: options.warmup === true,
|
|
467
|
+
kernel,
|
|
468
|
+
registry: kernel.registry,
|
|
469
|
+
gateway: kernel.gateway
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
async function getKernelRuntimeSnapshot(options = {}) {
|
|
473
|
+
if (options.reset) resetKernelRuntimeSnapshot();
|
|
474
|
+
if (cachedSnapshot && (!options.warmup || cachedSnapshot.warmupCompleted)) {
|
|
475
|
+
return cachedSnapshot;
|
|
511
476
|
}
|
|
512
|
-
|
|
513
|
-
assertModuleAllowed(moduleName, resolvedSpecifier, pluginConfig, policy);
|
|
514
|
-
const exportName = pluginConfig.factory?.trim() || "createPlugin";
|
|
515
|
-
let mod;
|
|
477
|
+
cachedSnapshotPromise ??= buildKernelRuntimeSnapshot({ warmup: options.warmup });
|
|
516
478
|
try {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
const maybeFactory = mod[exportName] ?? mod.default;
|
|
524
|
-
if (typeof maybeFactory !== "function") {
|
|
525
|
-
throw new Error(`plugin_factory_not_found:${pluginConfig.domain}:${moduleName}#${exportName}`);
|
|
526
|
-
}
|
|
527
|
-
const instance = await Promise.resolve(
|
|
528
|
-
maybeFactory(pluginConfig.options)
|
|
529
|
-
);
|
|
530
|
-
if (!instance || typeof instance !== "object") {
|
|
531
|
-
throw new Error(`plugin_factory_invalid_result:${pluginConfig.domain}`);
|
|
532
|
-
}
|
|
533
|
-
const configDomain = normalizeDomainName(pluginConfig.domain);
|
|
534
|
-
const pluginDomain = normalizeDomainName(instance.domain ?? "");
|
|
535
|
-
if (configDomain && pluginDomain && configDomain !== pluginDomain) {
|
|
536
|
-
throw new Error(`plugin_config_domain_mismatch:${configDomain}:${pluginDomain}`);
|
|
479
|
+
cachedSnapshot = await cachedSnapshotPromise;
|
|
480
|
+
return cachedSnapshot;
|
|
481
|
+
} finally {
|
|
482
|
+
cachedSnapshotPromise = null;
|
|
537
483
|
}
|
|
538
|
-
return guardCommercialPluginExecution(
|
|
539
|
-
instance,
|
|
540
|
-
configDomain,
|
|
541
|
-
checkHostDomainAdmission
|
|
542
|
-
);
|
|
543
484
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const plugins2 = config.plugins ?? [];
|
|
554
|
-
const diagnostics2 = {
|
|
555
|
-
attempt: ++bootstrapAttempt,
|
|
556
|
-
state: "building",
|
|
557
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
558
|
-
loadedDomains: [],
|
|
559
|
-
plugins: []
|
|
560
|
-
};
|
|
561
|
-
registryDiagnostics = diagnostics2;
|
|
562
|
-
applyHostRuntimeEnv(config);
|
|
563
|
-
const failedDomains = [];
|
|
564
|
-
try {
|
|
565
|
-
for (const pluginConfig of plugins2) {
|
|
566
|
-
const pluginStart = Date.now();
|
|
567
|
-
const domain = normalizeDomainName(pluginConfig.domain ?? "");
|
|
568
|
-
const moduleName = pluginConfig.module?.trim() || null;
|
|
569
|
-
const factoryName = pluginConfig.factory?.trim() || "createPlugin";
|
|
570
|
-
if (pluginConfig.enabled === false) {
|
|
571
|
-
diagnostics2.plugins.push({
|
|
572
|
-
domain,
|
|
573
|
-
module: moduleName,
|
|
574
|
-
factory: factoryName,
|
|
575
|
-
status: "skipped",
|
|
576
|
-
durationMs: Date.now() - pluginStart
|
|
577
|
-
});
|
|
578
|
-
continue;
|
|
579
|
-
}
|
|
580
|
-
if (!checkHostDomainAdmission(domain).allowed) {
|
|
581
|
-
diagnostics2.plugins.push({
|
|
582
|
-
domain,
|
|
583
|
-
module: moduleName,
|
|
584
|
-
factory: factoryName,
|
|
585
|
-
status: "skipped",
|
|
586
|
-
durationMs: Date.now() - pluginStart,
|
|
587
|
-
error: "domain_not_admitted"
|
|
588
|
-
});
|
|
589
|
-
continue;
|
|
590
|
-
}
|
|
591
|
-
try {
|
|
592
|
-
const plugin = await createPluginFromConfig(pluginConfig, policy);
|
|
593
|
-
registry.register(plugin);
|
|
594
|
-
diagnostics2.plugins.push({
|
|
595
|
-
domain: normalizeDomainName(plugin.domain ?? domain),
|
|
596
|
-
module: moduleName,
|
|
597
|
-
factory: factoryName,
|
|
598
|
-
status: "loaded",
|
|
599
|
-
durationMs: Date.now() - pluginStart
|
|
600
|
-
});
|
|
601
|
-
} catch (error) {
|
|
602
|
-
const message = extractErrorMessage(error);
|
|
603
|
-
diagnostics2.plugins.push({
|
|
604
|
-
domain,
|
|
605
|
-
module: moduleName,
|
|
606
|
-
factory: factoryName,
|
|
607
|
-
status: "failed",
|
|
608
|
-
durationMs: Date.now() - pluginStart,
|
|
609
|
-
error: message
|
|
610
|
-
});
|
|
611
|
-
if (tolerantBootstrap) {
|
|
612
|
-
failedDomains.push(domain);
|
|
613
|
-
continue;
|
|
614
|
-
}
|
|
615
|
-
throw new Error(`plugin_bootstrap_failed:${domain}:${message}`);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
diagnostics2.state = "ready";
|
|
619
|
-
if (failedDomains.length > 0) {
|
|
620
|
-
diagnostics2.error = `plugin_bootstrap_partial_failure:${failedDomains.join(",")}`;
|
|
621
|
-
}
|
|
622
|
-
diagnostics2.loadedDomains = registry.listDomains();
|
|
623
|
-
diagnostics2.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
624
|
-
registryDiagnostics = diagnostics2;
|
|
625
|
-
return registry;
|
|
626
|
-
} catch (error) {
|
|
627
|
-
diagnostics2.state = "failed";
|
|
628
|
-
diagnostics2.error = extractErrorMessage(error);
|
|
629
|
-
diagnostics2.loadedDomains = registry.listDomains();
|
|
630
|
-
diagnostics2.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
631
|
-
registryDiagnostics = diagnostics2;
|
|
632
|
-
throw error;
|
|
485
|
+
function peekKernelRuntimeSnapshot() {
|
|
486
|
+
return cachedSnapshot;
|
|
487
|
+
}
|
|
488
|
+
function resetKernelRuntimeSnapshot() {
|
|
489
|
+
const runtime2 = cachedSnapshot?.kernel;
|
|
490
|
+
cachedSnapshot = null;
|
|
491
|
+
cachedSnapshotPromise = null;
|
|
492
|
+
if (runtime2) {
|
|
493
|
+
void Promise.all(runtime2.shutdownHooks.map((hook) => hook.run())).catch(() => void 0);
|
|
633
494
|
}
|
|
634
495
|
}
|
|
635
496
|
async function getHostPluginRegistry() {
|
|
636
|
-
|
|
637
|
-
singletonPromise = buildRegistry().catch((error) => {
|
|
638
|
-
singletonPromise = null;
|
|
639
|
-
throw error;
|
|
640
|
-
});
|
|
641
|
-
return singletonPromise;
|
|
497
|
+
return (await getKernelRuntimeSnapshot()).registry;
|
|
642
498
|
}
|
|
643
499
|
function getHostPluginRegistryDiagnostics() {
|
|
500
|
+
const snapshot = peekKernelRuntimeSnapshot();
|
|
501
|
+
if (!snapshot) {
|
|
502
|
+
return { attempt: 0, state: "idle", loadedDomains: [], plugins: [] };
|
|
503
|
+
}
|
|
644
504
|
return {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
505
|
+
attempt: 1,
|
|
506
|
+
state: "ready",
|
|
507
|
+
startedAt: snapshot.loadedAt,
|
|
508
|
+
finishedAt: snapshot.loadedAt,
|
|
509
|
+
loadedDomains: snapshot.registry.listDomains(),
|
|
510
|
+
plugins: snapshot.kernel.pluginDiagnostics.map((plugin) => ({
|
|
511
|
+
domain: plugin.domain,
|
|
512
|
+
module: plugin.module,
|
|
513
|
+
factory: plugin.factory ?? "createPlugin",
|
|
514
|
+
status: plugin.status === "disabled" ? "skipped" : plugin.status,
|
|
515
|
+
durationMs: 0,
|
|
516
|
+
...plugin.error ? { error: plugin.error } : {}
|
|
517
|
+
}))
|
|
648
518
|
};
|
|
649
519
|
}
|
|
650
520
|
function resetHostPluginRegistry() {
|
|
651
|
-
|
|
652
|
-
pluginImportVersion += 1;
|
|
653
|
-
registryDiagnostics = {
|
|
654
|
-
...DEFAULT_DIAGNOSTICS,
|
|
655
|
-
loadedDomains: [],
|
|
656
|
-
plugins: []
|
|
657
|
-
};
|
|
521
|
+
resetKernelRuntimeSnapshot();
|
|
658
522
|
}
|
|
659
523
|
|
|
660
|
-
export {
|
|
524
|
+
export { getKernelRuntimeSnapshot as a, getHostRegistrationDiagnostics as b, getHostPluginRegistryDiagnostics as c, getHostAdmissionDiagnostics as d, getHostPluginRegistry as e, checkHostDomainAdmission as f, getHostConfig as g, resetHostPluginRegistry as h, resolveCommunityPackageModule as r };
|