apcore-js 0.10.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.
Files changed (90) hide show
  1. package/README.md +59 -3
  2. package/dist/client.d.ts +37 -2
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +85 -4
  5. package/dist/client.js.map +1 -1
  6. package/dist/errors.d.ts +11 -1
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +18 -2
  9. package/dist/errors.js.map +1 -1
  10. package/dist/events/emitter.d.ts +30 -0
  11. package/dist/events/emitter.d.ts.map +1 -0
  12. package/dist/events/emitter.js +67 -0
  13. package/dist/events/emitter.js.map +1 -0
  14. package/dist/events/index.d.ts +4 -0
  15. package/dist/events/index.d.ts.map +1 -0
  16. package/dist/events/index.js +3 -0
  17. package/dist/events/index.js.map +1 -0
  18. package/dist/events/subscribers.d.ts +32 -0
  19. package/dist/events/subscribers.d.ts.map +1 -0
  20. package/dist/events/subscribers.js +128 -0
  21. package/dist/events/subscribers.js.map +1 -0
  22. package/dist/executor.d.ts +3 -3
  23. package/dist/executor.d.ts.map +1 -1
  24. package/dist/executor.js +4 -4
  25. package/dist/executor.js.map +1 -1
  26. package/dist/index.d.ts +12 -3
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +10 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/middleware/error-history.d.ts +16 -0
  31. package/dist/middleware/error-history.d.ts.map +1 -0
  32. package/dist/middleware/error-history.js +23 -0
  33. package/dist/middleware/error-history.js.map +1 -0
  34. package/dist/middleware/index.d.ts +2 -0
  35. package/dist/middleware/index.d.ts.map +1 -1
  36. package/dist/middleware/index.js +2 -0
  37. package/dist/middleware/index.js.map +1 -1
  38. package/dist/middleware/platform-notify.d.ts +30 -0
  39. package/dist/middleware/platform-notify.d.ts.map +1 -0
  40. package/dist/middleware/platform-notify.js +84 -0
  41. package/dist/middleware/platform-notify.js.map +1 -0
  42. package/dist/observability/error-history.d.ts +33 -0
  43. package/dist/observability/error-history.d.ts.map +1 -0
  44. package/dist/observability/error-history.js +96 -0
  45. package/dist/observability/error-history.js.map +1 -0
  46. package/dist/observability/index.d.ts +4 -0
  47. package/dist/observability/index.d.ts.map +1 -1
  48. package/dist/observability/index.js +2 -0
  49. package/dist/observability/index.js.map +1 -1
  50. package/dist/observability/metrics-utils.d.ts +30 -0
  51. package/dist/observability/metrics-utils.d.ts.map +1 -0
  52. package/dist/observability/metrics-utils.js +71 -0
  53. package/dist/observability/metrics-utils.js.map +1 -0
  54. package/dist/observability/usage.d.ts +66 -0
  55. package/dist/observability/usage.d.ts.map +1 -0
  56. package/dist/observability/usage.js +216 -0
  57. package/dist/observability/usage.js.map +1 -0
  58. package/dist/registry/registry.d.ts +5 -0
  59. package/dist/registry/registry.d.ts.map +1 -1
  60. package/dist/registry/registry.js +32 -0
  61. package/dist/registry/registry.js.map +1 -1
  62. package/dist/sys-modules/control.d.ts +39 -0
  63. package/dist/sys-modules/control.d.ts.map +1 -0
  64. package/dist/sys-modules/control.js +105 -0
  65. package/dist/sys-modules/control.js.map +1 -0
  66. package/dist/sys-modules/health.d.ts +45 -0
  67. package/dist/sys-modules/health.d.ts.map +1 -0
  68. package/dist/sys-modules/health.js +115 -0
  69. package/dist/sys-modules/health.js.map +1 -0
  70. package/dist/sys-modules/index.d.ts +8 -0
  71. package/dist/sys-modules/index.d.ts.map +1 -0
  72. package/dist/sys-modules/index.js +7 -0
  73. package/dist/sys-modules/index.js.map +1 -0
  74. package/dist/sys-modules/manifest.d.ts +38 -0
  75. package/dist/sys-modules/manifest.d.ts.map +1 -0
  76. package/dist/sys-modules/manifest.js +91 -0
  77. package/dist/sys-modules/manifest.js.map +1 -0
  78. package/dist/sys-modules/registration.d.ts +35 -0
  79. package/dist/sys-modules/registration.d.ts.map +1 -0
  80. package/dist/sys-modules/registration.js +132 -0
  81. package/dist/sys-modules/registration.js.map +1 -0
  82. package/dist/sys-modules/toggle.d.ts +44 -0
  83. package/dist/sys-modules/toggle.d.ts.map +1 -0
  84. package/dist/sys-modules/toggle.js +82 -0
  85. package/dist/sys-modules/toggle.js.map +1 -0
  86. package/dist/sys-modules/usage.d.ts +35 -0
  87. package/dist/sys-modules/usage.d.ts.map +1 -0
  88. package/dist/sys-modules/usage.js +105 -0
  89. package/dist/sys-modules/usage.js.map +1 -0
  90. package/package.json +1 -1
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/sys-modules/usage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGtE,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,SAAS,UAAU,CAAC,SAAmB;IACrC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED,SAAS,qBAAqB,CAAC,OAAuB;IACpD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IACjD,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI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AAS;YACvB,WAAW,EAAE,CAAC,CAAC,UAAU;YACzB,cAAc,EAAE,CAAC,CAAC,YAAY;SAC/B,CAAC,CAAC,CAAC;QAEJ,MAAM,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEhE,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,QAAQ;YAC1B,MAAM;YACN,UAAU,EAAE,MAAM,CAAC,SAAS;YAC5B,WAAW,EAAE,MAAM,CAAC,UAAU;YAC9B,cAAc,EAAE,MAAM,CAAC,YAAY;YACnC,cAAc,EAAE,GAAG;YACnB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,OAAO;YACP,mBAAmB,EAAE,MAAM;SAC5B,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apcore-js",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "AI-Perceivable Core — schema-driven module development framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",