apcore-js 0.10.0 → 0.12.0
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/README.md +58 -2
- package/dist/cancel.d.ts +2 -1
- package/dist/cancel.d.ts.map +1 -1
- package/dist/cancel.js +3 -2
- package/dist/cancel.js.map +1 -1
- package/dist/client.d.ts +37 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +85 -4
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +12 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +25 -8
- package/dist/errors.js.map +1 -1
- package/dist/events/emitter.d.ts +30 -0
- package/dist/events/emitter.d.ts.map +1 -0
- package/dist/events/emitter.js +67 -0
- package/dist/events/emitter.js.map +1 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/subscribers.d.ts +32 -0
- package/dist/events/subscribers.d.ts.map +1 -0
- package/dist/events/subscribers.js +132 -0
- package/dist/events/subscribers.js.map +1 -0
- package/dist/executor.d.ts +5 -5
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +29 -7
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/middleware/error-history.d.ts +16 -0
- package/dist/middleware/error-history.d.ts.map +1 -0
- package/dist/middleware/error-history.js +23 -0
- package/dist/middleware/error-history.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/logging.js +2 -2
- package/dist/middleware/logging.js.map +1 -1
- package/dist/middleware/platform-notify.d.ts +30 -0
- package/dist/middleware/platform-notify.d.ts.map +1 -0
- package/dist/middleware/platform-notify.js +84 -0
- package/dist/middleware/platform-notify.js.map +1 -0
- package/dist/middleware/retry.d.ts +2 -2
- package/dist/middleware/retry.d.ts.map +1 -1
- package/dist/middleware/retry.js +3 -3
- package/dist/middleware/retry.js.map +1 -1
- package/dist/module.d.ts +12 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/observability/context-logger.js +4 -4
- package/dist/observability/context-logger.js.map +1 -1
- package/dist/observability/error-history.d.ts +33 -0
- package/dist/observability/error-history.d.ts.map +1 -0
- package/dist/observability/error-history.js +96 -0
- package/dist/observability/error-history.js.map +1 -0
- package/dist/observability/index.d.ts +5 -1
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +3 -1
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/metrics-utils.d.ts +30 -0
- package/dist/observability/metrics-utils.d.ts.map +1 -0
- package/dist/observability/metrics-utils.js +71 -0
- package/dist/observability/metrics-utils.js.map +1 -0
- package/dist/observability/metrics.js +4 -4
- package/dist/observability/metrics.js.map +1 -1
- package/dist/observability/tracing.js +10 -10
- package/dist/observability/tracing.js.map +1 -1
- package/dist/observability/usage.d.ts +66 -0
- package/dist/observability/usage.d.ts.map +1 -0
- package/dist/observability/usage.js +216 -0
- package/dist/observability/usage.js.map +1 -0
- package/dist/registry/registry.d.ts +5 -0
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +32 -0
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/schema-export.d.ts.map +1 -1
- package/dist/registry/schema-export.js.map +1 -1
- package/dist/schema/exporter.js +1 -1
- package/dist/schema/exporter.js.map +1 -1
- package/dist/schema/strict.d.ts +1 -1
- package/dist/schema/strict.d.ts.map +1 -1
- package/dist/schema/strict.js +4 -4
- package/dist/schema/strict.js.map +1 -1
- package/dist/sys-modules/control.d.ts +39 -0
- package/dist/sys-modules/control.d.ts.map +1 -0
- package/dist/sys-modules/control.js +105 -0
- package/dist/sys-modules/control.js.map +1 -0
- package/dist/sys-modules/health.d.ts +45 -0
- package/dist/sys-modules/health.d.ts.map +1 -0
- package/dist/sys-modules/health.js +115 -0
- package/dist/sys-modules/health.js.map +1 -0
- package/dist/sys-modules/index.d.ts +8 -0
- package/dist/sys-modules/index.d.ts.map +1 -0
- package/dist/sys-modules/index.js +7 -0
- package/dist/sys-modules/index.js.map +1 -0
- package/dist/sys-modules/manifest.d.ts +38 -0
- package/dist/sys-modules/manifest.d.ts.map +1 -0
- package/dist/sys-modules/manifest.js +91 -0
- package/dist/sys-modules/manifest.js.map +1 -0
- package/dist/sys-modules/registration.d.ts +35 -0
- package/dist/sys-modules/registration.d.ts.map +1 -0
- package/dist/sys-modules/registration.js +132 -0
- package/dist/sys-modules/registration.js.map +1 -0
- package/dist/sys-modules/toggle.d.ts +44 -0
- package/dist/sys-modules/toggle.d.ts.map +1 -0
- package/dist/sys-modules/toggle.js +82 -0
- package/dist/sys-modules/toggle.js.map +1 -0
- package/dist/sys-modules/usage.d.ts +35 -0
- package/dist/sys-modules/usage.d.ts.map +1 -0
- package/dist/sys-modules/usage.js +105 -0
- package/dist/sys-modules/usage.js.map +1 -0
- package/dist/trace-context.js +1 -1
- package/dist/trace-context.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ToggleState, ToggleFeatureModule, defaultToggleState, isModuleDisabled, checkModuleDisabled } from './toggle.js';
|
|
2
|
+
export { HealthSummaryModule, HealthModuleModule, classifyHealthStatus } from './health.js';
|
|
3
|
+
export { ManifestModuleModule, ManifestFullModule } from './manifest.js';
|
|
4
|
+
export { UpdateConfigModule, ReloadModuleModule } from './control.js';
|
|
5
|
+
export { UsageSummaryModule, UsageModuleModule } from './usage.js';
|
|
6
|
+
export { registerSysModules, registerSubscriberType, unregisterSubscriberType, resetSubscriberRegistry } from './registration.js';
|
|
7
|
+
export type { SysModulesContext } from './registration.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sys-modules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1H,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAClI,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ToggleState, ToggleFeatureModule, defaultToggleState, isModuleDisabled, checkModuleDisabled } from './toggle.js';
|
|
2
|
+
export { HealthSummaryModule, HealthModuleModule, classifyHealthStatus } from './health.js';
|
|
3
|
+
export { ManifestModuleModule, ManifestFullModule } from './manifest.js';
|
|
4
|
+
export { UpdateConfigModule, ReloadModuleModule } from './control.js';
|
|
5
|
+
export { UsageSummaryModule, UsageModuleModule } from './usage.js';
|
|
6
|
+
export { registerSysModules, registerSubscriberType, unregisterSubscriberType, resetSubscriberRegistry } from './registration.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sys-modules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1H,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System manifest modules -- module metadata and full system manifest.
|
|
3
|
+
*/
|
|
4
|
+
import type { Registry } from '../registry/registry.js';
|
|
5
|
+
import type { Config } from '../config.js';
|
|
6
|
+
export declare class ManifestModuleModule {
|
|
7
|
+
readonly description = "Full manifest for a registered module including source path";
|
|
8
|
+
readonly annotations: {
|
|
9
|
+
readonly: boolean;
|
|
10
|
+
destructive: boolean;
|
|
11
|
+
idempotent: boolean;
|
|
12
|
+
requiresApproval: boolean;
|
|
13
|
+
openWorld: boolean;
|
|
14
|
+
streaming: boolean;
|
|
15
|
+
};
|
|
16
|
+
private readonly _registry;
|
|
17
|
+
private readonly _config;
|
|
18
|
+
constructor(registry: Registry, config?: Config | null);
|
|
19
|
+
execute(inputs: Record<string, unknown>, _context: unknown): Record<string, unknown>;
|
|
20
|
+
private _computeSourcePath;
|
|
21
|
+
}
|
|
22
|
+
export declare class ManifestFullModule {
|
|
23
|
+
readonly description = "Complete system manifest with filtering by prefix and tags";
|
|
24
|
+
readonly annotations: {
|
|
25
|
+
readonly: boolean;
|
|
26
|
+
destructive: boolean;
|
|
27
|
+
idempotent: boolean;
|
|
28
|
+
requiresApproval: boolean;
|
|
29
|
+
openWorld: boolean;
|
|
30
|
+
streaming: boolean;
|
|
31
|
+
};
|
|
32
|
+
private readonly _registry;
|
|
33
|
+
private readonly _config;
|
|
34
|
+
constructor(registry: Registry, config?: Config | null);
|
|
35
|
+
execute(inputs: Record<string, unknown>, _context: unknown): Record<string, unknown>;
|
|
36
|
+
private _computeSourcePath;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/sys-modules/manifest.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,qBAAa,oBAAoB;IAC/B,QAAQ,CAAC,WAAW,iEAAiE;IACrF,QAAQ,CAAC,WAAW;;;;;;;MAAyH;IAE7I,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;gBAGtC,QAAQ,EAAE,QAAQ,EAClB,MAAM,GAAE,MAAM,GAAG,IAAW;IAM9B,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAyBpF,OAAO,CAAC,kBAAkB;CAO3B;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,WAAW,gEAAgE;IACpF,QAAQ,CAAC,WAAW;;;;;;;MAAyH;IAE7I,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;gBAGtC,QAAQ,EAAE,QAAQ,EAClB,MAAM,GAAE,MAAM,GAAG,IAAW;IAM9B,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IA+BpF,OAAO,CAAC,kBAAkB;CAM3B"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System manifest modules -- module metadata and full system manifest.
|
|
3
|
+
*/
|
|
4
|
+
import { InvalidInputError, ModuleNotFoundError } from '../errors.js';
|
|
5
|
+
export class ManifestModuleModule {
|
|
6
|
+
description = 'Full manifest for a registered module including source path';
|
|
7
|
+
annotations = { readonly: true, destructive: false, idempotent: true, requiresApproval: false, openWorld: false, streaming: false };
|
|
8
|
+
_registry;
|
|
9
|
+
_config;
|
|
10
|
+
constructor(registry, config = null) {
|
|
11
|
+
this._registry = registry;
|
|
12
|
+
this._config = config;
|
|
13
|
+
}
|
|
14
|
+
execute(inputs, _context) {
|
|
15
|
+
const moduleId = inputs['module_id'];
|
|
16
|
+
if (typeof moduleId !== 'string' || !moduleId) {
|
|
17
|
+
throw new InvalidInputError('module_id is required');
|
|
18
|
+
}
|
|
19
|
+
const descriptor = this._registry.getDefinition(moduleId);
|
|
20
|
+
if (!descriptor) {
|
|
21
|
+
throw new ModuleNotFoundError(moduleId);
|
|
22
|
+
}
|
|
23
|
+
const sourcePath = this._computeSourcePath(moduleId);
|
|
24
|
+
return {
|
|
25
|
+
module_id: descriptor.moduleId,
|
|
26
|
+
description: descriptor.description,
|
|
27
|
+
documentation: descriptor.documentation,
|
|
28
|
+
source_path: sourcePath,
|
|
29
|
+
input_schema: descriptor.inputSchema,
|
|
30
|
+
output_schema: descriptor.outputSchema,
|
|
31
|
+
annotations: descriptor.annotations,
|
|
32
|
+
tags: descriptor.tags,
|
|
33
|
+
metadata: descriptor.metadata ?? {},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
_computeSourcePath(moduleId) {
|
|
37
|
+
if (!this._config)
|
|
38
|
+
return null;
|
|
39
|
+
const sourceRoot = this._config.get('project.source_root', '');
|
|
40
|
+
if (!sourceRoot)
|
|
41
|
+
return null;
|
|
42
|
+
const relativePath = moduleId.replace(/\./g, '/') + '.ts';
|
|
43
|
+
return `${sourceRoot}/${relativePath}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class ManifestFullModule {
|
|
47
|
+
description = 'Complete system manifest with filtering by prefix and tags';
|
|
48
|
+
annotations = { readonly: true, destructive: false, idempotent: true, requiresApproval: false, openWorld: false, streaming: false };
|
|
49
|
+
_registry;
|
|
50
|
+
_config;
|
|
51
|
+
constructor(registry, config = null) {
|
|
52
|
+
this._registry = registry;
|
|
53
|
+
this._config = config;
|
|
54
|
+
}
|
|
55
|
+
execute(inputs, _context) {
|
|
56
|
+
const includeSchemas = inputs['include_schemas'] !== false;
|
|
57
|
+
const includeSourcePaths = inputs['include_source_paths'] !== false;
|
|
58
|
+
const prefix = inputs['prefix'];
|
|
59
|
+
const tags = inputs['tags'];
|
|
60
|
+
const moduleIds = this._registry.list({ prefix, tags });
|
|
61
|
+
const modules = [];
|
|
62
|
+
for (const mid of moduleIds) {
|
|
63
|
+
const descriptor = this._registry.getDefinition(mid);
|
|
64
|
+
if (!descriptor)
|
|
65
|
+
continue;
|
|
66
|
+
const sourcePath = includeSourcePaths ? this._computeSourcePath(mid) : null;
|
|
67
|
+
modules.push({
|
|
68
|
+
module_id: descriptor.moduleId,
|
|
69
|
+
description: descriptor.description,
|
|
70
|
+
documentation: descriptor.documentation,
|
|
71
|
+
source_path: sourcePath,
|
|
72
|
+
input_schema: includeSchemas ? descriptor.inputSchema : null,
|
|
73
|
+
output_schema: includeSchemas ? descriptor.outputSchema : null,
|
|
74
|
+
annotations: descriptor.annotations,
|
|
75
|
+
tags: descriptor.tags,
|
|
76
|
+
metadata: descriptor.metadata ?? {},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const projectName = (this._config?.get('project.name', '') ?? '');
|
|
80
|
+
return { project_name: projectName, module_count: modules.length, modules };
|
|
81
|
+
}
|
|
82
|
+
_computeSourcePath(moduleId) {
|
|
83
|
+
if (!this._config)
|
|
84
|
+
return null;
|
|
85
|
+
const sourceRoot = this._config.get('project.source_root', '');
|
|
86
|
+
if (!sourceRoot)
|
|
87
|
+
return null;
|
|
88
|
+
return `${sourceRoot}/${moduleId.replace(/\./g, '/')}.ts`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/sys-modules/manifest.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtE,MAAM,OAAO,oBAAoB;IACtB,WAAW,GAAG,6DAA6D,CAAC;IAC5E,WAAW,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAE5H,SAAS,CAAW;IACpB,OAAO,CAAgB;IAExC,YACE,QAAkB,EAClB,SAAwB,IAAI;QAE5B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,MAA+B,EAAE,QAAiB;QACxD,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9C,MAAM,IAAI,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ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c,EAAE,EAAE,CAAC,IAAI,EAAE,CAAW,CAAC;QAC5E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;IAC9E,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACzC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAW,CAAC;QACzE,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC;QAC7B,OAAO,GAAG,UAAU,IAAI,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC;IAC5D,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-registration of sys.* modules and middleware from config.
|
|
3
|
+
*/
|
|
4
|
+
import type { Registry } from '../registry/registry.js';
|
|
5
|
+
import type { Executor } from '../executor.js';
|
|
6
|
+
import type { Config } from '../config.js';
|
|
7
|
+
import type { MetricsCollector } from '../observability/metrics.js';
|
|
8
|
+
import { ErrorHistory } from '../observability/error-history.js';
|
|
9
|
+
import { ErrorHistoryMiddleware } from '../middleware/error-history.js';
|
|
10
|
+
import { UsageCollector, UsageMiddleware } from '../observability/usage.js';
|
|
11
|
+
import type { EventSubscriber } from '../events/emitter.js';
|
|
12
|
+
import { EventEmitter } from '../events/emitter.js';
|
|
13
|
+
import { PlatformNotifyMiddleware } from '../middleware/platform-notify.js';
|
|
14
|
+
type SubscriberFactory = (config: Record<string, unknown>) => EventSubscriber;
|
|
15
|
+
export declare function registerSubscriberType(typeName: string, factory: SubscriberFactory): void;
|
|
16
|
+
export declare function unregisterSubscriberType(typeName: string): void;
|
|
17
|
+
export declare function resetSubscriberRegistry(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Instantiate subscribers from config and subscribe them to the emitter.
|
|
20
|
+
*/
|
|
21
|
+
export declare function _instantiateSubscribers(config: Config, eventEmitter: EventEmitter): void;
|
|
22
|
+
export interface SysModulesContext {
|
|
23
|
+
errorHistory?: ErrorHistory;
|
|
24
|
+
errorHistoryMiddleware?: ErrorHistoryMiddleware;
|
|
25
|
+
usageCollector?: UsageCollector;
|
|
26
|
+
usageMiddleware?: UsageMiddleware;
|
|
27
|
+
eventEmitter?: EventEmitter;
|
|
28
|
+
platformNotifyMiddleware?: PlatformNotifyMiddleware;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Auto-register all sys.* modules and middleware based on config.
|
|
32
|
+
*/
|
|
33
|
+
export declare function registerSysModules(registry: Registry, executor: Executor, config: Config, metricsCollector?: MetricsCollector | null): SysModulesContext;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/sys-modules/registration.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAW5E,KAAK,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,eAAe,CAAC;AAwB9E,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,GACzB,IAAI,CAEN;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAK/D;AAED,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,GACzB,IAAI,CAwBN;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;CACrD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,IAAI,GACzC,iBAAiB,CAuEnB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-registration of sys.* modules and middleware from config.
|
|
3
|
+
*/
|
|
4
|
+
import { ErrorHistory } from '../observability/error-history.js';
|
|
5
|
+
import { ErrorHistoryMiddleware } from '../middleware/error-history.js';
|
|
6
|
+
import { UsageCollector, UsageMiddleware } from '../observability/usage.js';
|
|
7
|
+
import { EventEmitter, createEvent } from '../events/emitter.js';
|
|
8
|
+
import { WebhookSubscriber, A2ASubscriber } from '../events/subscribers.js';
|
|
9
|
+
import { PlatformNotifyMiddleware } from '../middleware/platform-notify.js';
|
|
10
|
+
import { HealthSummaryModule, HealthModuleModule } from './health.js';
|
|
11
|
+
import { ManifestFullModule, ManifestModuleModule } from './manifest.js';
|
|
12
|
+
import { ToggleFeatureModule } from './toggle.js';
|
|
13
|
+
import { UpdateConfigModule, ReloadModuleModule } from './control.js';
|
|
14
|
+
import { UsageSummaryModule, UsageModuleModule } from './usage.js';
|
|
15
|
+
const _subscriberFactories = new Map();
|
|
16
|
+
function _registerBuiltInFactories() {
|
|
17
|
+
_subscriberFactories.set('webhook', (config) => {
|
|
18
|
+
const url = config['url'];
|
|
19
|
+
const headers = config['headers'];
|
|
20
|
+
const retryCount = config['retry_count'];
|
|
21
|
+
const timeoutMs = config['timeout_ms'];
|
|
22
|
+
return new WebhookSubscriber(url, headers, retryCount, timeoutMs);
|
|
23
|
+
});
|
|
24
|
+
_subscriberFactories.set('a2a', (config) => {
|
|
25
|
+
const platformUrl = config['platform_url'];
|
|
26
|
+
const auth = config['auth'];
|
|
27
|
+
const timeoutMs = config['timeout_ms'];
|
|
28
|
+
return new A2ASubscriber(platformUrl, auth, timeoutMs);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// Register built-in factories on module load
|
|
32
|
+
_registerBuiltInFactories();
|
|
33
|
+
export function registerSubscriberType(typeName, factory) {
|
|
34
|
+
_subscriberFactories.set(typeName, factory);
|
|
35
|
+
}
|
|
36
|
+
export function unregisterSubscriberType(typeName) {
|
|
37
|
+
if (!_subscriberFactories.has(typeName)) {
|
|
38
|
+
throw new Error(`Subscriber type '${typeName}' is not registered`);
|
|
39
|
+
}
|
|
40
|
+
_subscriberFactories.delete(typeName);
|
|
41
|
+
}
|
|
42
|
+
export function resetSubscriberRegistry() {
|
|
43
|
+
_subscriberFactories.clear();
|
|
44
|
+
_registerBuiltInFactories();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Instantiate subscribers from config and subscribe them to the emitter.
|
|
48
|
+
*/
|
|
49
|
+
export function _instantiateSubscribers(config, eventEmitter) {
|
|
50
|
+
const subscriberConfigs = config.get('sys_modules.events.subscribers', []);
|
|
51
|
+
for (const subscriberConfig of subscriberConfigs) {
|
|
52
|
+
const typeName = subscriberConfig['type'];
|
|
53
|
+
if (typeof typeName !== 'string') {
|
|
54
|
+
console.warn('[apcore:events]', 'Subscriber config missing "type" field, skipping');
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const factory = _subscriberFactories.get(typeName);
|
|
58
|
+
if (factory === undefined) {
|
|
59
|
+
console.warn('[apcore:events]', `Unknown subscriber type '${typeName}', skipping`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const subscriber = factory(subscriberConfig);
|
|
64
|
+
eventEmitter.subscribe(subscriber);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
console.warn('[apcore:events]', `Failed to create subscriber of type '${typeName}':`, err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Auto-register all sys.* modules and middleware based on config.
|
|
73
|
+
*/
|
|
74
|
+
export function registerSysModules(registry, executor, config, metricsCollector) {
|
|
75
|
+
const result = {};
|
|
76
|
+
if (!config.get('sys_modules.enabled', false)) {
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
// Error history
|
|
80
|
+
const maxPerModule = Number(config.get('sys_modules.error_history.max_entries_per_module', 50));
|
|
81
|
+
const maxTotal = Number(config.get('sys_modules.error_history.max_total_entries', 1000));
|
|
82
|
+
const errorHistory = new ErrorHistory(maxPerModule, maxTotal);
|
|
83
|
+
result.errorHistory = errorHistory;
|
|
84
|
+
const ehMiddleware = new ErrorHistoryMiddleware(errorHistory);
|
|
85
|
+
executor.use(ehMiddleware);
|
|
86
|
+
result.errorHistoryMiddleware = ehMiddleware;
|
|
87
|
+
// Usage tracking
|
|
88
|
+
const usageCollector = new UsageCollector();
|
|
89
|
+
result.usageCollector = usageCollector;
|
|
90
|
+
const usageMiddleware = new UsageMiddleware(usageCollector);
|
|
91
|
+
executor.use(usageMiddleware);
|
|
92
|
+
result.usageMiddleware = usageMiddleware;
|
|
93
|
+
// Register sys modules via registerInternal to bypass reserved-word checks
|
|
94
|
+
const reg = (id, mod) => {
|
|
95
|
+
registry.registerInternal(id, mod);
|
|
96
|
+
};
|
|
97
|
+
// Health modules
|
|
98
|
+
reg('system.health.summary', new HealthSummaryModule(registry, metricsCollector ?? null, errorHistory, config));
|
|
99
|
+
reg('system.health.module', new HealthModuleModule(registry, metricsCollector ?? null, errorHistory));
|
|
100
|
+
// Manifest modules
|
|
101
|
+
reg('system.manifest.module', new ManifestModuleModule(registry, config));
|
|
102
|
+
reg('system.manifest.full', new ManifestFullModule(registry, config));
|
|
103
|
+
// Usage modules
|
|
104
|
+
reg('system.usage.summary', new UsageSummaryModule(usageCollector));
|
|
105
|
+
reg('system.usage.module', new UsageModuleModule(registry, usageCollector));
|
|
106
|
+
// Events system
|
|
107
|
+
if (config.get('sys_modules.events.enabled', false)) {
|
|
108
|
+
const eventEmitter = new EventEmitter();
|
|
109
|
+
result.eventEmitter = eventEmitter;
|
|
110
|
+
// Config-driven subscribers
|
|
111
|
+
_instantiateSubscribers(config, eventEmitter);
|
|
112
|
+
// PlatformNotifyMiddleware
|
|
113
|
+
const errorRateThreshold = Number(config.get('sys_modules.events.thresholds.error_rate', 0.1));
|
|
114
|
+
const latencyP99Threshold = Number(config.get('sys_modules.events.thresholds.latency_p99_ms', 5000));
|
|
115
|
+
const pnMiddleware = new PlatformNotifyMiddleware(eventEmitter, metricsCollector ?? null, errorRateThreshold, latencyP99Threshold);
|
|
116
|
+
executor.use(pnMiddleware);
|
|
117
|
+
result.platformNotifyMiddleware = pnMiddleware;
|
|
118
|
+
// Control modules (require EventEmitter)
|
|
119
|
+
reg('system.control.toggle_feature', new ToggleFeatureModule(registry, eventEmitter));
|
|
120
|
+
reg('system.control.update_config', new UpdateConfigModule(config, eventEmitter));
|
|
121
|
+
reg('system.control.reload_module', new ReloadModuleModule(registry, eventEmitter));
|
|
122
|
+
// Bridge registry events
|
|
123
|
+
registry.on('register', (moduleId) => {
|
|
124
|
+
eventEmitter.emit(createEvent('module_registered', moduleId, 'info', {}));
|
|
125
|
+
});
|
|
126
|
+
registry.on('unregister', (moduleId) => {
|
|
127
|
+
eventEmitter.emit(createEvent('module_unregistered', moduleId, 'info', {}));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/sys-modules/registration.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAQnE,MAAM,oBAAoB,GAAmC,IAAI,GAAG,EAAE,CAAC;AAEvE,SAAS,yBAAyB;IAChC,oBAAoB,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,MAA+B,EAAmB,EAA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CAAC,QAAgB,EAAE,EAAE;YAC3C,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,QAAgB,EAAE,EAAE;YAC7C,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;QAC9E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module toggle system -- disable/enable modules without unloading.
|
|
3
|
+
*/
|
|
4
|
+
import type { Registry } from '../registry/registry.js';
|
|
5
|
+
import type { EventEmitter } from '../events/emitter.js';
|
|
6
|
+
/**
|
|
7
|
+
* Toggle state container. Tracks which modules are disabled.
|
|
8
|
+
* State survives module reload since it lives outside the Registry.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ToggleState {
|
|
11
|
+
private readonly _disabled;
|
|
12
|
+
isDisabled(moduleId: string): boolean;
|
|
13
|
+
disable(moduleId: string): void;
|
|
14
|
+
enable(moduleId: string): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
|
17
|
+
/** Default global toggle state. */
|
|
18
|
+
export declare const defaultToggleState: ToggleState;
|
|
19
|
+
/** Check if a module is disabled using the default toggle state. */
|
|
20
|
+
export declare function isModuleDisabled(moduleId: string): boolean;
|
|
21
|
+
/** Throw ModuleDisabledError if the module is disabled. */
|
|
22
|
+
export declare function checkModuleDisabled(moduleId: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Disable or enable a module without unloading it from the Registry.
|
|
25
|
+
* A disabled module remains registered but calls return MODULE_DISABLED error.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ToggleFeatureModule {
|
|
28
|
+
readonly description = "Disable or enable a module without unloading it";
|
|
29
|
+
readonly annotations: {
|
|
30
|
+
readonly: boolean;
|
|
31
|
+
destructive: boolean;
|
|
32
|
+
idempotent: boolean;
|
|
33
|
+
requiresApproval: boolean;
|
|
34
|
+
openWorld: boolean;
|
|
35
|
+
streaming: boolean;
|
|
36
|
+
};
|
|
37
|
+
private readonly _registry;
|
|
38
|
+
private readonly _emitter;
|
|
39
|
+
private readonly _toggleState;
|
|
40
|
+
constructor(registry: Registry, eventEmitter: EventEmitter, toggleState?: ToggleState);
|
|
41
|
+
execute(inputs: Record<string, unknown>, _context: unknown): Record<string, unknown>;
|
|
42
|
+
private _validateInputs;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../src/sys-modules/toggle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IAEpD,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIrC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI/B,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI9B,KAAK,IAAI,IAAI;CAGd;AAED,mCAAmC;AACnC,eAAO,MAAM,kBAAkB,aAAoB,CAAC;AAEpD,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,2DAA2D;AAC3D,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAI1D;AAED;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,WAAW,qDAAqD;IACzE,QAAQ,CAAC,WAAW;;;;;;;MAAyH;IAE7I,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;gBAE/B,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,WAAW;IAMrF,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcpF,OAAO,CAAC,eAAe;CAexB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module toggle system -- disable/enable modules without unloading.
|
|
3
|
+
*/
|
|
4
|
+
import { InvalidInputError, ModuleNotFoundError, ModuleDisabledError } from '../errors.js';
|
|
5
|
+
import { createEvent } from '../events/emitter.js';
|
|
6
|
+
/**
|
|
7
|
+
* Toggle state container. Tracks which modules are disabled.
|
|
8
|
+
* State survives module reload since it lives outside the Registry.
|
|
9
|
+
*/
|
|
10
|
+
export class ToggleState {
|
|
11
|
+
_disabled = new Set();
|
|
12
|
+
isDisabled(moduleId) {
|
|
13
|
+
return this._disabled.has(moduleId);
|
|
14
|
+
}
|
|
15
|
+
disable(moduleId) {
|
|
16
|
+
this._disabled.add(moduleId);
|
|
17
|
+
}
|
|
18
|
+
enable(moduleId) {
|
|
19
|
+
this._disabled.delete(moduleId);
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this._disabled.clear();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Default global toggle state. */
|
|
26
|
+
export const defaultToggleState = new ToggleState();
|
|
27
|
+
/** Check if a module is disabled using the default toggle state. */
|
|
28
|
+
export function isModuleDisabled(moduleId) {
|
|
29
|
+
return defaultToggleState.isDisabled(moduleId);
|
|
30
|
+
}
|
|
31
|
+
/** Throw ModuleDisabledError if the module is disabled. */
|
|
32
|
+
export function checkModuleDisabled(moduleId) {
|
|
33
|
+
if (isModuleDisabled(moduleId)) {
|
|
34
|
+
throw new ModuleDisabledError(moduleId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Disable or enable a module without unloading it from the Registry.
|
|
39
|
+
* A disabled module remains registered but calls return MODULE_DISABLED error.
|
|
40
|
+
*/
|
|
41
|
+
export class ToggleFeatureModule {
|
|
42
|
+
description = 'Disable or enable a module without unloading it';
|
|
43
|
+
annotations = { readonly: false, destructive: false, idempotent: true, requiresApproval: true, openWorld: false, streaming: false };
|
|
44
|
+
_registry;
|
|
45
|
+
_emitter;
|
|
46
|
+
_toggleState;
|
|
47
|
+
constructor(registry, eventEmitter, toggleState) {
|
|
48
|
+
this._registry = registry;
|
|
49
|
+
this._emitter = eventEmitter;
|
|
50
|
+
this._toggleState = toggleState ?? defaultToggleState;
|
|
51
|
+
}
|
|
52
|
+
execute(inputs, _context) {
|
|
53
|
+
const { moduleId, enabled, reason } = this._validateInputs(inputs);
|
|
54
|
+
if (!this._registry.has(moduleId)) {
|
|
55
|
+
throw new ModuleNotFoundError(moduleId);
|
|
56
|
+
}
|
|
57
|
+
if (enabled) {
|
|
58
|
+
this._toggleState.enable(moduleId);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this._toggleState.disable(moduleId);
|
|
62
|
+
}
|
|
63
|
+
this._emitter.emit(createEvent('module_health_changed', moduleId, 'info', { enabled, reason }));
|
|
64
|
+
return { success: true, module_id: moduleId, enabled, reason };
|
|
65
|
+
}
|
|
66
|
+
_validateInputs(inputs) {
|
|
67
|
+
const moduleId = inputs['module_id'];
|
|
68
|
+
if (typeof moduleId !== 'string' || !moduleId) {
|
|
69
|
+
throw new InvalidInputError("'module_id' is required and must be a non-empty string");
|
|
70
|
+
}
|
|
71
|
+
const enabled = inputs['enabled'];
|
|
72
|
+
if (typeof enabled !== 'boolean') {
|
|
73
|
+
throw new InvalidInputError("'enabled' is required and must be a boolean");
|
|
74
|
+
}
|
|
75
|
+
const reason = inputs['reason'];
|
|
76
|
+
if (typeof reason !== 'string' || !reason) {
|
|
77
|
+
throw new InvalidInputError("'reason' is required and must be a non-empty string");
|
|
78
|
+
}
|
|
79
|
+
return { moduleId, enabled, reason };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=toggle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.js","sourceRoot":"","sources":["../../src/sys-modules/toggle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAG3F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,WAAW;IACL,SAAS,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEpD,UAAU,CAAC,QAAgB;QACzB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,CAAC,QAAgB;QACtB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,QAAgB;QACrB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC;AAEpD,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED,2DAA2D;AAC3D,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EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAChG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACjE,CAAC;IAEO,eAAe,CAAC,MAA+B;QACrD,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9C,MAAM,IAAI,iBAAiB,CAAC,wDAAwD,CAAC,CAAC;QACxF,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,OAAO,OAAO,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,iBAAiB,CAAC,6CAA6C,CAAC,CAAC;QAC7E,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;YAC1C,MAAM,IAAI,iBAAiB,CAAC,qDAAqD,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System usage modules -- summary and single-module usage detail.
|
|
3
|
+
*/
|
|
4
|
+
import type { Registry } from '../registry/registry.js';
|
|
5
|
+
import type { UsageCollector } from '../observability/usage.js';
|
|
6
|
+
export declare class UsageSummaryModule {
|
|
7
|
+
readonly description = "All modules usage overview with trend detection";
|
|
8
|
+
readonly annotations: {
|
|
9
|
+
readonly: boolean;
|
|
10
|
+
destructive: boolean;
|
|
11
|
+
idempotent: boolean;
|
|
12
|
+
requiresApproval: boolean;
|
|
13
|
+
openWorld: boolean;
|
|
14
|
+
streaming: boolean;
|
|
15
|
+
};
|
|
16
|
+
private readonly _collector;
|
|
17
|
+
constructor(collector: UsageCollector);
|
|
18
|
+
execute(inputs: Record<string, unknown>, _context: unknown): Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export declare class UsageModuleModule {
|
|
21
|
+
readonly description = "Detailed usage statistics for a single module";
|
|
22
|
+
readonly annotations: {
|
|
23
|
+
readonly: boolean;
|
|
24
|
+
destructive: boolean;
|
|
25
|
+
idempotent: boolean;
|
|
26
|
+
requiresApproval: boolean;
|
|
27
|
+
openWorld: boolean;
|
|
28
|
+
streaming: boolean;
|
|
29
|
+
};
|
|
30
|
+
private readonly _registry;
|
|
31
|
+
private readonly _collector;
|
|
32
|
+
constructor(registry: Registry, usageCollector: UsageCollector);
|
|
33
|
+
execute(inputs: Record<string, unknown>, _context: unknown): Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/sys-modules/usage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAmChE,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,WAAW,qDAAqD;IACzE,QAAQ,CAAC,WAAW;;;;;;;MAAyH;IAE7I,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAEhC,SAAS,EAAE,cAAc;IAIrC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAsBrF;AAED,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,WAAW,mDAAmD;IACvE,QAAQ,CAAC,WAAW;;;;;;;MAAyH;IAE7I,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAEhC,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc;IAK9D,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAmCrF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System usage modules -- summary and single-module usage detail.
|
|
3
|
+
*/
|
|
4
|
+
import { InvalidInputError, ModuleNotFoundError } from '../errors.js';
|
|
5
|
+
import { bucketKey } from '../observability/usage.js';
|
|
6
|
+
function computeP99(latencies) {
|
|
7
|
+
if (latencies.length === 0)
|
|
8
|
+
return 0;
|
|
9
|
+
const sorted = [...latencies].sort((a, b) => a - b);
|
|
10
|
+
const idx = Math.max(0, Math.ceil(0.99 * sorted.length) - 1);
|
|
11
|
+
return sorted[idx];
|
|
12
|
+
}
|
|
13
|
+
function padHourlyDistribution(buckets) {
|
|
14
|
+
const now = new Date();
|
|
15
|
+
const existing = new Map();
|
|
16
|
+
for (const b of buckets)
|
|
17
|
+
existing.set(b.hour, b);
|
|
18
|
+
const keys = [];
|
|
19
|
+
for (let i = 0; i < 24; i++) {
|
|
20
|
+
const d = new Date(now.getTime() - (23 - i) * 3600_000);
|
|
21
|
+
keys.push(bucketKey(d));
|
|
22
|
+
}
|
|
23
|
+
for (const k of existing.keys()) {
|
|
24
|
+
if (!keys.includes(k))
|
|
25
|
+
keys.push(k);
|
|
26
|
+
}
|
|
27
|
+
keys.sort();
|
|
28
|
+
const latest = keys.slice(-24);
|
|
29
|
+
return latest.map((k) => {
|
|
30
|
+
const b = existing.get(k);
|
|
31
|
+
return b
|
|
32
|
+
? { hour: k, call_count: b.callCount, error_count: b.errorCount }
|
|
33
|
+
: { hour: k, call_count: 0, error_count: 0 };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export class UsageSummaryModule {
|
|
37
|
+
description = 'All modules usage overview with trend detection';
|
|
38
|
+
annotations = { readonly: true, destructive: false, idempotent: true, requiresApproval: false, openWorld: false, streaming: false };
|
|
39
|
+
_collector;
|
|
40
|
+
constructor(collector) {
|
|
41
|
+
this._collector = collector;
|
|
42
|
+
}
|
|
43
|
+
execute(inputs, _context) {
|
|
44
|
+
const period = inputs['period'] ?? '24h';
|
|
45
|
+
const summaries = this._collector.getSummary(period);
|
|
46
|
+
const sorted = [...summaries].sort((a, b) => b.callCount - a.callCount);
|
|
47
|
+
const totalCalls = sorted.reduce((s, e) => s + e.callCount, 0);
|
|
48
|
+
const totalErrors = sorted.reduce((s, e) => s + e.errorCount, 0);
|
|
49
|
+
return {
|
|
50
|
+
period,
|
|
51
|
+
total_calls: totalCalls,
|
|
52
|
+
total_errors: totalErrors,
|
|
53
|
+
modules: sorted.map((e) => ({
|
|
54
|
+
module_id: e.moduleId,
|
|
55
|
+
call_count: e.callCount,
|
|
56
|
+
error_count: e.errorCount,
|
|
57
|
+
avg_latency_ms: e.avgLatencyMs,
|
|
58
|
+
unique_callers: e.uniqueCallers,
|
|
59
|
+
trend: e.trend,
|
|
60
|
+
})),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class UsageModuleModule {
|
|
65
|
+
description = 'Detailed usage statistics for a single module';
|
|
66
|
+
annotations = { readonly: true, destructive: false, idempotent: true, requiresApproval: false, openWorld: false, streaming: false };
|
|
67
|
+
_registry;
|
|
68
|
+
_collector;
|
|
69
|
+
constructor(registry, usageCollector) {
|
|
70
|
+
this._registry = registry;
|
|
71
|
+
this._collector = usageCollector;
|
|
72
|
+
}
|
|
73
|
+
execute(inputs, _context) {
|
|
74
|
+
const moduleId = inputs['module_id'];
|
|
75
|
+
if (typeof moduleId !== 'string' || !moduleId) {
|
|
76
|
+
throw new InvalidInputError('module_id is required');
|
|
77
|
+
}
|
|
78
|
+
if (!this._registry.has(moduleId)) {
|
|
79
|
+
throw new ModuleNotFoundError(moduleId);
|
|
80
|
+
}
|
|
81
|
+
const period = inputs['period'] ?? '24h';
|
|
82
|
+
const detail = this._collector.getModule(moduleId, period);
|
|
83
|
+
const latencies = this._collector.getLatencies(moduleId, period);
|
|
84
|
+
const p99 = computeP99(latencies);
|
|
85
|
+
const callers = detail.callers.map((c) => ({
|
|
86
|
+
caller_id: c.callerId,
|
|
87
|
+
call_count: c.callCount,
|
|
88
|
+
error_count: c.errorCount,
|
|
89
|
+
avg_latency_ms: c.avgLatencyMs,
|
|
90
|
+
}));
|
|
91
|
+
const hourly = padHourlyDistribution(detail.hourlyDistribution);
|
|
92
|
+
return {
|
|
93
|
+
module_id: detail.moduleId,
|
|
94
|
+
period,
|
|
95
|
+
call_count: detail.callCount,
|
|
96
|
+
error_count: detail.errorCount,
|
|
97
|
+
avg_latency_ms: detail.avgLatencyMs,
|
|
98
|
+
p99_latency_ms: p99,
|
|
99
|
+
trend: detail.trend,
|
|
100
|
+
callers,
|
|
101
|
+
hourly_distribution: hourly,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=usage.js.map
|