apcore-js 0.9.0 → 0.11.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 +90 -7
- package/dist/client.d.ts +130 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +187 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +30 -2
- 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 +128 -0
- package/dist/events/subscribers.js.map +1 -0
- package/dist/executor.d.ts +3 -3
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +4 -4
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +14 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -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/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/module.d.ts +8 -0
- package/dist/module.d.ts.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 +4 -0
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +2 -0
- 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/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/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/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* apcore - Schema-driven module development framework.
|
|
3
3
|
*/
|
|
4
|
+
// Client
|
|
5
|
+
export { APCore } from './client.js';
|
|
4
6
|
// Core
|
|
5
7
|
export { CancelToken, ExecutionCancelledError } from './cancel.js';
|
|
6
8
|
export { Context, createIdentity } from './context.js';
|
|
@@ -13,15 +15,19 @@ export { Config } from './config.js';
|
|
|
13
15
|
// Approval
|
|
14
16
|
export { createApprovalRequest, createApprovalResult, AlwaysDenyHandler, AutoApproveHandler, CallbackApprovalHandler, } from './approval.js';
|
|
15
17
|
// Errors
|
|
16
|
-
export { ModuleError, ConfigNotFoundError, ConfigError, ACLRuleError, ACLDeniedError, ApprovalError, ApprovalDeniedError, ApprovalTimeoutError, ApprovalPendingError, ModuleNotFoundError, ModuleTimeoutError, SchemaValidationError, SchemaNotFoundError, SchemaParseError, SchemaCircularRefError, CallDepthExceededError, CircularCallError, CallFrequencyExceededError, InvalidInputError, FuncMissingTypeHintError, FuncMissingReturnTypeError, BindingInvalidTargetError, BindingModuleNotFoundError, BindingCallableNotFoundError, BindingNotCallableError, BindingSchemaMissingError, BindingFileInvalidError, CircularDependencyError, ModuleLoadError, ModuleExecuteError, InternalError, ErrorCodes, } from './errors.js';
|
|
18
|
+
export { ModuleError, ConfigNotFoundError, ConfigError, ACLRuleError, ACLDeniedError, ApprovalError, ApprovalDeniedError, ApprovalTimeoutError, ApprovalPendingError, ModuleNotFoundError, ModuleDisabledError, ModuleTimeoutError, SchemaValidationError, SchemaNotFoundError, SchemaParseError, SchemaCircularRefError, CallDepthExceededError, CircularCallError, CallFrequencyExceededError, InvalidInputError, FuncMissingTypeHintError, FuncMissingReturnTypeError, BindingInvalidTargetError, BindingModuleNotFoundError, BindingCallableNotFoundError, BindingNotCallableError, BindingSchemaMissingError, BindingFileInvalidError, CircularDependencyError, DependencyNotFoundError, FeatureNotImplementedError, ModuleLoadError, ReloadFailedError, ModuleExecuteError, InternalError, ErrorCodes, } from './errors.js';
|
|
17
19
|
// ACL
|
|
18
20
|
export { ACL } from './acl.js';
|
|
19
21
|
// Middleware
|
|
20
|
-
export { Middleware, MiddlewareManager, MiddlewareChainError, BeforeMiddleware, AfterMiddleware, LoggingMiddleware, RetryMiddleware, CTX_RETRY_COUNT_PREFIX, CTX_RETRY_DELAY_PREFIX } from './middleware/index.js';
|
|
22
|
+
export { Middleware, MiddlewareManager, MiddlewareChainError, BeforeMiddleware, AfterMiddleware, LoggingMiddleware, RetryMiddleware, CTX_RETRY_COUNT_PREFIX, CTX_RETRY_DELAY_PREFIX, ErrorHistoryMiddleware, PlatformNotifyMiddleware } from './middleware/index.js';
|
|
21
23
|
// Decorator
|
|
22
24
|
export { module, FunctionModule, normalizeResult, makeAutoId } from './decorator.js';
|
|
23
25
|
// Extensions
|
|
24
26
|
export { ExtensionManager } from './extensions.js';
|
|
27
|
+
// Events
|
|
28
|
+
export { EventEmitter, createEvent, WebhookSubscriber, A2ASubscriber } from './events/index.js';
|
|
29
|
+
// System Modules
|
|
30
|
+
export { registerSysModules, registerSubscriberType, unregisterSubscriberType, resetSubscriberRegistry, ToggleState, ToggleFeatureModule, defaultToggleState, isModuleDisabled, checkModuleDisabled, HealthSummaryModule, HealthModuleModule, classifyHealthStatus, ManifestModuleModule, ManifestFullModule, UpdateConfigModule, ReloadModuleModule, UsageSummaryModule, UsageModuleModule, } from './sys-modules/index.js';
|
|
25
31
|
// Async tasks
|
|
26
32
|
export { AsyncTaskManager, TaskStatus } from './async-task.js';
|
|
27
33
|
// Bindings
|
|
@@ -46,7 +52,10 @@ export { toStrictSchema, applyLlmDescriptions, stripExtensions } from './schema/
|
|
|
46
52
|
export { TracingMiddleware, StdoutExporter, InMemoryExporter, OTLPExporter, createSpan } from './observability/tracing.js';
|
|
47
53
|
export { MetricsCollector, MetricsMiddleware } from './observability/metrics.js';
|
|
48
54
|
export { ContextLogger, ObsLoggingMiddleware } from './observability/context-logger.js';
|
|
55
|
+
export { ErrorHistory } from './observability/error-history.js';
|
|
56
|
+
export { UsageCollector, UsageMiddleware, bucketKey } from './observability/usage.js';
|
|
57
|
+
export { computeModuleErrorRate, estimateP99FromHistogram, matchesModuleId, METRIC_CALLS_TOTAL, METRIC_DURATION_SECONDS } from './observability/metrics-utils.js';
|
|
49
58
|
// Trace Context
|
|
50
59
|
export { TraceContext } from './trace-context.js';
|
|
51
|
-
export const VERSION = '0.
|
|
60
|
+
export const VERSION = '0.11.0';
|
|
52
61
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO;AACP,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE5H,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElH,eAAe;AACf,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzE,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,WAAW;AACX,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAGvB,SAAS;AACT,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,aAAa,EACb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AAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE3H,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,eAAe,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAGlK,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware that records ModuleError details into ErrorHistory.
|
|
3
|
+
*/
|
|
4
|
+
import type { Context } from '../context.js';
|
|
5
|
+
import { Middleware } from './base.js';
|
|
6
|
+
import type { ErrorHistory } from '../observability/error-history.js';
|
|
7
|
+
/**
|
|
8
|
+
* Records ModuleError instances into ErrorHistory on every onError() call.
|
|
9
|
+
* Generic exceptions are ignored. This middleware never recovers from errors.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ErrorHistoryMiddleware extends Middleware {
|
|
12
|
+
private readonly _errorHistory;
|
|
13
|
+
constructor(errorHistory: ErrorHistory);
|
|
14
|
+
onError(moduleId: string, _inputs: Record<string, unknown>, error: Error, _context: Context): Record<string, unknown> | null;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=error-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-history.d.ts","sourceRoot":"","sources":["../../src/middleware/error-history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEtE;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;gBAEjC,YAAY,EAAE,YAAY;IAK7B,OAAO,CACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,OAAO,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAMlC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware that records ModuleError details into ErrorHistory.
|
|
3
|
+
*/
|
|
4
|
+
import { ModuleError } from '../errors.js';
|
|
5
|
+
import { Middleware } from './base.js';
|
|
6
|
+
/**
|
|
7
|
+
* Records ModuleError instances into ErrorHistory on every onError() call.
|
|
8
|
+
* Generic exceptions are ignored. This middleware never recovers from errors.
|
|
9
|
+
*/
|
|
10
|
+
export class ErrorHistoryMiddleware extends Middleware {
|
|
11
|
+
_errorHistory;
|
|
12
|
+
constructor(errorHistory) {
|
|
13
|
+
super();
|
|
14
|
+
this._errorHistory = errorHistory;
|
|
15
|
+
}
|
|
16
|
+
onError(moduleId, _inputs, error, _context) {
|
|
17
|
+
if (error instanceof ModuleError) {
|
|
18
|
+
this._errorHistory.record(moduleId, error);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=error-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-history.js","sourceRoot":"","sources":["../../src/middleware/error-history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IACnC,aAAa,CAAe;IAE7C,YAAY,YAA0B;QACpC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAEQ,OAAO,CACd,QAAgB,EAChB,OAAgC,EAChC,KAAY,EACZ,QAAiB;QAEjB,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -6,4 +6,6 @@ export { LoggingMiddleware } from './logging.js';
|
|
|
6
6
|
export type { Logger } from './logging.js';
|
|
7
7
|
export { RetryMiddleware, CTX_RETRY_COUNT_PREFIX, CTX_RETRY_DELAY_PREFIX } from './retry.js';
|
|
8
8
|
export type { RetryConfig } from './retry.js';
|
|
9
|
+
export { ErrorHistoryMiddleware } from './error-history.js';
|
|
10
|
+
export { PlatformNotifyMiddleware } from './platform-notify.js';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC7F,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC7F,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/middleware/index.js
CHANGED
|
@@ -3,4 +3,6 @@ export { MiddlewareManager, MiddlewareChainError } from './manager.js';
|
|
|
3
3
|
export { BeforeMiddleware, AfterMiddleware } from './adapters.js';
|
|
4
4
|
export { LoggingMiddleware } from './logging.js';
|
|
5
5
|
export { RetryMiddleware, CTX_RETRY_COUNT_PREFIX, CTX_RETRY_DELAY_PREFIX } from './retry.js';
|
|
6
|
+
export { ErrorHistoryMiddleware } from './error-history.js';
|
|
7
|
+
export { PlatformNotifyMiddleware } from './platform-notify.js';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE7F,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlatformNotifyMiddleware -- threshold sensor with hysteresis.
|
|
3
|
+
*
|
|
4
|
+
* Monitors error rates and latency, emits threshold events with hysteresis.
|
|
5
|
+
* Emits error_threshold_exceeded when a module's error rate crosses the
|
|
6
|
+
* configured threshold, latency_threshold_exceeded when p99 latency
|
|
7
|
+
* exceeds the limit, and module_health_changed when a previously alerted
|
|
8
|
+
* module recovers below threshold * 0.5.
|
|
9
|
+
*/
|
|
10
|
+
import type { Context } from '../context.js';
|
|
11
|
+
import type { EventEmitter } from '../events/emitter.js';
|
|
12
|
+
import type { MetricsCollector } from '../observability/metrics.js';
|
|
13
|
+
import { Middleware } from './base.js';
|
|
14
|
+
export declare class PlatformNotifyMiddleware extends Middleware {
|
|
15
|
+
private readonly _emitter;
|
|
16
|
+
private readonly _metricsCollector;
|
|
17
|
+
private readonly _errorRateThreshold;
|
|
18
|
+
private readonly _latencyP99ThresholdMs;
|
|
19
|
+
private readonly _alerted;
|
|
20
|
+
constructor(eventEmitter: EventEmitter, metricsCollector?: MetricsCollector | null, errorRateThreshold?: number, latencyP99ThresholdMs?: number);
|
|
21
|
+
after(moduleId: string, _inputs: Record<string, unknown>, _output: Record<string, unknown>, _context: Context): Record<string, unknown> | null;
|
|
22
|
+
onError(moduleId: string, _inputs: Record<string, unknown>, _error: Error, _context: Context): Record<string, unknown> | null;
|
|
23
|
+
private _getAlerted;
|
|
24
|
+
private _computeErrorRate;
|
|
25
|
+
private _checkErrorRateThreshold;
|
|
26
|
+
private _checkLatencyThreshold;
|
|
27
|
+
private _estimateP99Ms;
|
|
28
|
+
private _checkErrorRecovery;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=platform-notify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-notify.d.ts","sourceRoot":"","sources":["../../src/middleware/platform-notify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,qBAAa,wBAAyB,SAAQ,UAAU;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0B;IAC5D,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;gBAG9D,YAAY,EAAE,YAAY,EAC1B,gBAAgB,GAAE,gBAAgB,GAAG,IAAW,EAChD,kBAAkB,GAAE,MAAY,EAChC,qBAAqB,GAAE,MAAa;IAS7B,KAAK,CACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,OAAO,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAMxB,OAAO,CACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,MAAM,EAAE,KAAK,EACb,QAAQ,EAAE,OAAO,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAKjC,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,wBAAwB;IAchC,OAAO,CAAC,sBAAsB;IAiB9B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,mBAAmB;CAe5B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlatformNotifyMiddleware -- threshold sensor with hysteresis.
|
|
3
|
+
*
|
|
4
|
+
* Monitors error rates and latency, emits threshold events with hysteresis.
|
|
5
|
+
* Emits error_threshold_exceeded when a module's error rate crosses the
|
|
6
|
+
* configured threshold, latency_threshold_exceeded when p99 latency
|
|
7
|
+
* exceeds the limit, and module_health_changed when a previously alerted
|
|
8
|
+
* module recovers below threshold * 0.5.
|
|
9
|
+
*/
|
|
10
|
+
import { createEvent } from '../events/emitter.js';
|
|
11
|
+
import { computeModuleErrorRate, estimateP99FromHistogram } from '../observability/metrics-utils.js';
|
|
12
|
+
import { Middleware } from './base.js';
|
|
13
|
+
export class PlatformNotifyMiddleware extends Middleware {
|
|
14
|
+
_emitter;
|
|
15
|
+
_metricsCollector;
|
|
16
|
+
_errorRateThreshold;
|
|
17
|
+
_latencyP99ThresholdMs;
|
|
18
|
+
_alerted = new Map();
|
|
19
|
+
constructor(eventEmitter, metricsCollector = null, errorRateThreshold = 0.1, latencyP99ThresholdMs = 5000) {
|
|
20
|
+
super();
|
|
21
|
+
this._emitter = eventEmitter;
|
|
22
|
+
this._metricsCollector = metricsCollector;
|
|
23
|
+
this._errorRateThreshold = errorRateThreshold;
|
|
24
|
+
this._latencyP99ThresholdMs = latencyP99ThresholdMs;
|
|
25
|
+
}
|
|
26
|
+
after(moduleId, _inputs, _output, _context) {
|
|
27
|
+
this._checkLatencyThreshold(moduleId);
|
|
28
|
+
this._checkErrorRecovery(moduleId);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
onError(moduleId, _inputs, _error, _context) {
|
|
32
|
+
this._checkErrorRateThreshold(moduleId);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
_getAlerted(moduleId) {
|
|
36
|
+
let set = this._alerted.get(moduleId);
|
|
37
|
+
if (!set) {
|
|
38
|
+
set = new Set();
|
|
39
|
+
this._alerted.set(moduleId, set);
|
|
40
|
+
}
|
|
41
|
+
return set;
|
|
42
|
+
}
|
|
43
|
+
_computeErrorRate(moduleId) {
|
|
44
|
+
if (!this._metricsCollector)
|
|
45
|
+
return 0;
|
|
46
|
+
return computeModuleErrorRate(this._metricsCollector, moduleId).errorRate;
|
|
47
|
+
}
|
|
48
|
+
_checkErrorRateThreshold(moduleId) {
|
|
49
|
+
const errorRate = this._computeErrorRate(moduleId);
|
|
50
|
+
const alerted = this._getAlerted(moduleId);
|
|
51
|
+
if (errorRate >= this._errorRateThreshold && !alerted.has('error_rate')) {
|
|
52
|
+
this._emitter.emit(createEvent('error_threshold_exceeded', moduleId, 'warning', { error_rate: errorRate, threshold: this._errorRateThreshold }));
|
|
53
|
+
alerted.add('error_rate');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_checkLatencyThreshold(moduleId) {
|
|
57
|
+
if (!this._metricsCollector)
|
|
58
|
+
return;
|
|
59
|
+
const alerted = this._getAlerted(moduleId);
|
|
60
|
+
if (alerted.has('latency'))
|
|
61
|
+
return;
|
|
62
|
+
const p99Ms = this._estimateP99Ms(moduleId);
|
|
63
|
+
if (p99Ms >= this._latencyP99ThresholdMs) {
|
|
64
|
+
this._emitter.emit(createEvent('latency_threshold_exceeded', moduleId, 'warning', { p99_latency_ms: p99Ms, threshold_ms: this._latencyP99ThresholdMs }));
|
|
65
|
+
alerted.add('latency');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_estimateP99Ms(moduleId) {
|
|
69
|
+
if (!this._metricsCollector)
|
|
70
|
+
return 0;
|
|
71
|
+
return estimateP99FromHistogram(this._metricsCollector, moduleId).p99LatencyMs;
|
|
72
|
+
}
|
|
73
|
+
_checkErrorRecovery(moduleId) {
|
|
74
|
+
const alerted = this._alerted.get(moduleId);
|
|
75
|
+
if (!alerted || !alerted.has('error_rate'))
|
|
76
|
+
return;
|
|
77
|
+
const errorRate = this._computeErrorRate(moduleId);
|
|
78
|
+
if (errorRate < this._errorRateThreshold * 0.5) {
|
|
79
|
+
this._emitter.emit(createEvent('module_health_changed', moduleId, 'info', { status: 'recovered', error_rate: errorRate }));
|
|
80
|
+
alerted.delete('error_rate');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=platform-notify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-notify.js","sourceRoot":"","sources":["../../src/middleware/platform-notify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,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AAC,SAAS,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,QAAgB;QACrC,IAAI,CAAC,IAAI,CAAC,iBAAiB;YAAE,OAAO,CAAC,CAAC;QACtC,OAAO,wBAAwB,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC,YAAY,CAAC;IACjF,CAAC;IAEO,mBAAmB,CAAC,QAAgB;QAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;YAAE,OAAO;QAEnD,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,SAAS,GAAG,IAAI,CAAC,mBAAmB,GAAG,GAAG,EAAE,CAAC;YAC/C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAC5B,uBAAuB,EACvB,QAAQ,EACR,MAAM,EACN,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,CAC/C,CAAC,CAAC;YACH,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
|
package/dist/module.d.ts
CHANGED
|
@@ -39,5 +39,13 @@ export interface Module {
|
|
|
39
39
|
outputSchema: TSchema;
|
|
40
40
|
description: string;
|
|
41
41
|
execute(inputs: Record<string, unknown>, context: Context): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
42
|
+
/** Optional: Stream module output chunk by chunk. */
|
|
43
|
+
stream?(inputs: Record<string, unknown>, context: Context): AsyncGenerator<Record<string, unknown>>;
|
|
44
|
+
/** Optional: Custom input validation without execution. */
|
|
45
|
+
validate?(inputs: Record<string, unknown>): ValidationResult | Promise<ValidationResult>;
|
|
46
|
+
/** Optional: Called when module is loaded into the registry. */
|
|
47
|
+
onLoad?(): void | Promise<void>;
|
|
48
|
+
/** Optional: Called when module is unloaded from the registry. */
|
|
49
|
+
onUnload?(): void | Promise<void>;
|
|
42
50
|
}
|
|
43
51
|
//# sourceMappingURL=module.d.ts.map
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,mBAAmB,EAAE,iBAOhC,CAAC;AAEH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,M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AAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvH,qDAAqD;IACrD,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpG,2DAA2D;IAC3D,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACzF,gEAAgE;IAChE,MAAM,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,kEAAkE;IAClE,QAAQ,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error history with ring-buffer eviction and deduplication.
|
|
3
|
+
*/
|
|
4
|
+
import { ModuleError } from '../errors.js';
|
|
5
|
+
export interface ErrorEntry {
|
|
6
|
+
readonly moduleId: string;
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
readonly aiGuidance: string | null;
|
|
10
|
+
readonly timestamp: string;
|
|
11
|
+
count: number;
|
|
12
|
+
firstOccurred: string;
|
|
13
|
+
lastOccurred: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ring buffer storing recent error details per module.
|
|
17
|
+
* Supports deduplication by (code, message) within each module,
|
|
18
|
+
* per-module eviction, and global total eviction.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ErrorHistory {
|
|
21
|
+
private readonly _maxEntriesPerModule;
|
|
22
|
+
private readonly _maxTotalEntries;
|
|
23
|
+
private readonly _entries;
|
|
24
|
+
constructor(maxEntriesPerModule?: number, maxTotalEntries?: number);
|
|
25
|
+
record(moduleId: string, error: ModuleError): void;
|
|
26
|
+
get(moduleId: string, limit?: number): ErrorEntry[];
|
|
27
|
+
clear(): void;
|
|
28
|
+
clearModule(moduleId: string): void;
|
|
29
|
+
getAll(limit?: number): ErrorEntry[];
|
|
30
|
+
private _evictModule;
|
|
31
|
+
private _evictTotal;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=error-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-history.d.ts","sourceRoot":"","sources":["../../src/observability/error-history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;gBAErD,mBAAmB,GAAE,MAAW,EAAE,eAAe,GAAE,MAAa;IAK5E,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI;IAgClD,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;IAMnD,KAAK,IAAI,IAAI;IAIb,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAInC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;IASpC,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;CA0BpB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error history with ring-buffer eviction and deduplication.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Ring buffer storing recent error details per module.
|
|
6
|
+
* Supports deduplication by (code, message) within each module,
|
|
7
|
+
* per-module eviction, and global total eviction.
|
|
8
|
+
*/
|
|
9
|
+
export class ErrorHistory {
|
|
10
|
+
_maxEntriesPerModule;
|
|
11
|
+
_maxTotalEntries;
|
|
12
|
+
_entries = new Map();
|
|
13
|
+
constructor(maxEntriesPerModule = 50, maxTotalEntries = 1000) {
|
|
14
|
+
this._maxEntriesPerModule = maxEntriesPerModule;
|
|
15
|
+
this._maxTotalEntries = maxTotalEntries;
|
|
16
|
+
}
|
|
17
|
+
record(moduleId, error) {
|
|
18
|
+
const now = new Date().toISOString();
|
|
19
|
+
let moduleEntries = this._entries.get(moduleId);
|
|
20
|
+
if (!moduleEntries) {
|
|
21
|
+
moduleEntries = [];
|
|
22
|
+
this._entries.set(moduleId, moduleEntries);
|
|
23
|
+
}
|
|
24
|
+
const existing = moduleEntries.find((e) => e.code === error.code && e.message === error.message);
|
|
25
|
+
if (existing) {
|
|
26
|
+
existing.count++;
|
|
27
|
+
existing.lastOccurred = now;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const entry = {
|
|
31
|
+
moduleId,
|
|
32
|
+
code: error.code,
|
|
33
|
+
message: error.message,
|
|
34
|
+
aiGuidance: error.aiGuidance,
|
|
35
|
+
timestamp: now,
|
|
36
|
+
count: 1,
|
|
37
|
+
firstOccurred: now,
|
|
38
|
+
lastOccurred: now,
|
|
39
|
+
};
|
|
40
|
+
moduleEntries.push(entry);
|
|
41
|
+
this._evictModule(moduleEntries);
|
|
42
|
+
this._evictTotal();
|
|
43
|
+
}
|
|
44
|
+
get(moduleId, limit) {
|
|
45
|
+
const moduleEntries = this._entries.get(moduleId) ?? [];
|
|
46
|
+
const result = [...moduleEntries].reverse();
|
|
47
|
+
return limit !== undefined ? result.slice(0, limit) : result;
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
this._entries.clear();
|
|
51
|
+
}
|
|
52
|
+
clearModule(moduleId) {
|
|
53
|
+
this._entries.delete(moduleId);
|
|
54
|
+
}
|
|
55
|
+
getAll(limit) {
|
|
56
|
+
const all = [];
|
|
57
|
+
for (const entries of this._entries.values()) {
|
|
58
|
+
all.push(...entries);
|
|
59
|
+
}
|
|
60
|
+
all.sort((a, b) => (a.lastOccurred > b.lastOccurred ? -1 : 1));
|
|
61
|
+
return limit !== undefined ? all.slice(0, limit) : all;
|
|
62
|
+
}
|
|
63
|
+
_evictModule(moduleEntries) {
|
|
64
|
+
while (moduleEntries.length > this._maxEntriesPerModule) {
|
|
65
|
+
moduleEntries.shift();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_evictTotal() {
|
|
69
|
+
let total = 0;
|
|
70
|
+
for (const entries of this._entries.values()) {
|
|
71
|
+
total += entries.length;
|
|
72
|
+
}
|
|
73
|
+
while (total > this._maxTotalEntries) {
|
|
74
|
+
let oldestEntry = null;
|
|
75
|
+
let oldestModuleId = null;
|
|
76
|
+
for (const [mid, entries] of this._entries) {
|
|
77
|
+
if (entries.length > 0) {
|
|
78
|
+
const candidate = entries[0];
|
|
79
|
+
if (oldestEntry === null || candidate.lastOccurred < oldestEntry.lastOccurred) {
|
|
80
|
+
oldestEntry = candidate;
|
|
81
|
+
oldestModuleId = mid;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (oldestModuleId === null)
|
|
86
|
+
break;
|
|
87
|
+
const entries = this._entries.get(oldestModuleId);
|
|
88
|
+
entries.shift();
|
|
89
|
+
if (entries.length === 0) {
|
|
90
|
+
this._entries.delete(oldestModuleId);
|
|
91
|
+
}
|
|
92
|
+
total--;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=error-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-history.js","sourceRoot":"","sources":["../../src/observability/error-history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACN,oBAAoB,CAAS;IAC7B,gBAAgB,CAAS;IACzB,QAAQ,GAA8B,IAAI,GAAG,EAAE,CAAC;IAEjE,YAAY,sBAA8B,EAAE,EAAE,kBAA0B,IAAI;QAC1E,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;QAChD,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,QAAgB,EAAE,KAAkB;QACzC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,aAAa,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CACjC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAC5D,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,QAAQ,CAAC,YAAY,GAAG,GAAG,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAe;YACxB,QAAQ;YACR,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,UA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ACvC,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;IACH,CAAC;CACF"}
|
|
@@ -2,4 +2,8 @@ export { TracingMiddleware, StdoutExporter, InMemoryExporter, createSpan } from
|
|
|
2
2
|
export type { Span, SpanExporter } from './tracing.js';
|
|
3
3
|
export { MetricsCollector, MetricsMiddleware } from './metrics.js';
|
|
4
4
|
export { ContextLogger, ObsLoggingMiddleware } from './context-logger.js';
|
|
5
|
+
export { ErrorHistory } from './error-history.js';
|
|
6
|
+
export type { ErrorEntry } from './error-history.js';
|
|
7
|
+
export { UsageCollector, UsageMiddleware, bucketKey } from './usage.js';
|
|
8
|
+
export type { UsageRecord, CallerUsageSummary, HourlyBucket, ModuleUsageSummary, ModuleUsageDetail } from './usage.js';
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACxE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { TracingMiddleware, StdoutExporter, InMemoryExporter, createSpan } from './tracing.js';
|
|
2
2
|
export { MetricsCollector, MetricsMiddleware } from './metrics.js';
|
|
3
3
|
export { ContextLogger, ObsLoggingMiddleware } from './context-logger.js';
|
|
4
|
+
export { ErrorHistory } from './error-history.js';
|
|
5
|
+
export { UsageCollector, UsageMiddleware, bucketKey } from './usage.js';
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for extracting module-level metrics from MetricsCollector snapshots.
|
|
3
|
+
*/
|
|
4
|
+
import type { MetricsCollector } from './metrics.js';
|
|
5
|
+
export declare const METRIC_CALLS_TOTAL = "apcore_module_calls_total";
|
|
6
|
+
export declare const METRIC_DURATION_SECONDS = "apcore_module_duration_seconds";
|
|
7
|
+
/**
|
|
8
|
+
* Check if a metric key's labels contain an exact module_id match.
|
|
9
|
+
* Keys have the format: "metric_name|module_id=foo,status=bar"
|
|
10
|
+
* This prevents false-matching when one module ID is a suffix of another.
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchesModuleId(key: string, moduleId: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Compute error rate for a module from a MetricsCollector snapshot.
|
|
15
|
+
*/
|
|
16
|
+
export declare function computeModuleErrorRate(metricsCollector: MetricsCollector, moduleId: string): {
|
|
17
|
+
totalCalls: number;
|
|
18
|
+
errorCount: number;
|
|
19
|
+
errorRate: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Estimate p99 latency in milliseconds from histogram buckets.
|
|
23
|
+
* Returns the upper bound of the first bucket that contains ≥99% of observations.
|
|
24
|
+
* If all observations exceed the largest bucket, returns the last bucket upper bound.
|
|
25
|
+
*/
|
|
26
|
+
export declare function estimateP99FromHistogram(metricsCollector: MetricsCollector, moduleId: string): {
|
|
27
|
+
avgLatencyMs: number;
|
|
28
|
+
p99LatencyMs: number;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=metrics-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-utils.d.ts","sourceRoot":"","sources":["../../src/observability/metrics-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAC9D,eAAO,MAAM,uBAAuB,mCAAmC,CAAC;AAMxE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGtE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,GACf;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAiB/D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,GACf;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CA8BhD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for extracting module-level metrics from MetricsCollector snapshots.
|
|
3
|
+
*/
|
|
4
|
+
export const METRIC_CALLS_TOTAL = 'apcore_module_calls_total';
|
|
5
|
+
export const METRIC_DURATION_SECONDS = 'apcore_module_duration_seconds';
|
|
6
|
+
const DEFAULT_HISTOGRAM_BUCKETS = [
|
|
7
|
+
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0,
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Check if a metric key's labels contain an exact module_id match.
|
|
11
|
+
* Keys have the format: "metric_name|module_id=foo,status=bar"
|
|
12
|
+
* This prevents false-matching when one module ID is a suffix of another.
|
|
13
|
+
*/
|
|
14
|
+
export function matchesModuleId(key, moduleId) {
|
|
15
|
+
const labelMatch = `|module_id=${moduleId}`;
|
|
16
|
+
return key.includes(`${labelMatch},`) || key.endsWith(labelMatch);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Compute error rate for a module from a MetricsCollector snapshot.
|
|
20
|
+
*/
|
|
21
|
+
export function computeModuleErrorRate(metricsCollector, moduleId) {
|
|
22
|
+
const snap = metricsCollector.snapshot();
|
|
23
|
+
const counters = snap['counters'];
|
|
24
|
+
if (!counters)
|
|
25
|
+
return { totalCalls: 0, errorCount: 0, errorRate: 0 };
|
|
26
|
+
let total = 0;
|
|
27
|
+
let errors = 0;
|
|
28
|
+
const prefix = `${METRIC_CALLS_TOTAL}|`;
|
|
29
|
+
for (const [key, value] of Object.entries(counters)) {
|
|
30
|
+
if (!key.startsWith(prefix))
|
|
31
|
+
continue;
|
|
32
|
+
if (!matchesModuleId(key, moduleId))
|
|
33
|
+
continue;
|
|
34
|
+
total += value;
|
|
35
|
+
if (key.includes('status=error')) {
|
|
36
|
+
errors += value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { totalCalls: total, errorCount: errors, errorRate: total === 0 ? 0 : errors / total };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Estimate p99 latency in milliseconds from histogram buckets.
|
|
43
|
+
* Returns the upper bound of the first bucket that contains ≥99% of observations.
|
|
44
|
+
* If all observations exceed the largest bucket, returns the last bucket upper bound.
|
|
45
|
+
*/
|
|
46
|
+
export function estimateP99FromHistogram(metricsCollector, moduleId) {
|
|
47
|
+
const snap = metricsCollector.snapshot();
|
|
48
|
+
const histograms = snap['histograms'];
|
|
49
|
+
if (!histograms)
|
|
50
|
+
return { avgLatencyMs: 0, p99LatencyMs: 0 };
|
|
51
|
+
const durationKey = `${METRIC_DURATION_SECONDS}|module_id=${moduleId}`;
|
|
52
|
+
const sumVal = histograms.sums?.[durationKey] ?? 0;
|
|
53
|
+
const countVal = histograms.counts?.[durationKey] ?? 0;
|
|
54
|
+
const avgLatencyMs = countVal > 0 ? (sumVal / countVal) * 1000 : 0;
|
|
55
|
+
let p99LatencyMs = 0;
|
|
56
|
+
if (countVal > 0 && histograms.buckets) {
|
|
57
|
+
const target = countVal * 0.99;
|
|
58
|
+
for (const b of DEFAULT_HISTOGRAM_BUCKETS) {
|
|
59
|
+
const bkey = `${durationKey}|${b}`;
|
|
60
|
+
const cumCount = histograms.buckets[bkey] ?? 0;
|
|
61
|
+
if (cumCount >= target) {
|
|
62
|
+
p99LatencyMs = b * 1000;
|
|
63
|
+
return { avgLatencyMs, p99LatencyMs };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// All observations exceed the largest bucket
|
|
67
|
+
p99LatencyMs = DEFAULT_HISTOGRAM_BUCKETS[DEFAULT_HISTOGRAM_BUCKETS.length - 1] * 1000;
|
|
68
|
+
}
|
|
69
|
+
return { avgLatencyMs, p99LatencyMs };
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=metrics-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-utils.js","sourceRoot":"","sources":["../../src/observability/metrics-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AAC9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,gCAAgC,CAAC;AAExE,MAAM,yBAAyB,GAAG;IAChC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CAC1E,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,QAAgB;IAC3D,MAAM,UAAU,GAAG,cAAc,QAAQ,EAAE,CAAC;IAC5C,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,UAAU,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACpE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU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