apcore-js 0.19.0 → 0.21.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 +110 -9
- package/dist/acl.d.ts +18 -0
- package/dist/acl.d.ts.map +1 -1
- package/dist/acl.js +54 -17
- package/dist/acl.js.map +1 -1
- package/dist/async-task.d.ts +70 -16
- package/dist/async-task.d.ts.map +1 -1
- package/dist/async-task.js +212 -72
- package/dist/async-task.js.map +1 -1
- package/dist/builtin-steps.d.ts +16 -5
- package/dist/builtin-steps.d.ts.map +1 -1
- package/dist/builtin-steps.js +45 -28
- package/dist/builtin-steps.js.map +1 -1
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +163 -33
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +12 -1
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +32 -10
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +55 -16
- package/dist/errors.js.map +1 -1
- package/dist/events/circuit-breaker.d.ts +45 -0
- package/dist/events/circuit-breaker.d.ts.map +1 -0
- package/dist/events/circuit-breaker.js +115 -0
- package/dist/events/circuit-breaker.js.map +1 -0
- package/dist/events/emitter.d.ts +22 -1
- package/dist/events/emitter.d.ts.map +1 -1
- package/dist/events/emitter.js +66 -2
- package/dist/events/emitter.js.map +1 -1
- package/dist/events/index.d.ts +4 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -2
- package/dist/events/index.js.map +1 -1
- package/dist/events/subscribers.d.ts +33 -1
- package/dist/events/subscribers.d.ts.map +1 -1
- package/dist/events/subscribers.js +124 -1
- package/dist/events/subscribers.js.map +1 -1
- package/dist/executor.d.ts +10 -2
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +173 -52
- package/dist/executor.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/index.d.ts +35 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -17
- package/dist/index.js.map +1 -1
- package/dist/middleware/base.d.ts +25 -3
- package/dist/middleware/base.d.ts.map +1 -1
- package/dist/middleware/base.js +24 -0
- package/dist/middleware/base.js.map +1 -1
- package/dist/middleware/circuit-breaker.d.ts +54 -0
- package/dist/middleware/circuit-breaker.d.ts.map +1 -0
- package/dist/middleware/circuit-breaker.js +168 -0
- package/dist/middleware/circuit-breaker.js.map +1 -0
- package/dist/middleware/context-namespace.d.ts +30 -0
- package/dist/middleware/context-namespace.d.ts.map +1 -0
- package/dist/middleware/context-namespace.js +38 -0
- package/dist/middleware/context-namespace.js.map +1 -0
- package/dist/middleware/index.d.ts +7 -1
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +4 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/manager.d.ts +11 -4
- package/dist/middleware/manager.d.ts.map +1 -1
- package/dist/middleware/manager.js +25 -9
- package/dist/middleware/manager.js.map +1 -1
- package/dist/middleware/platform-notify.d.ts +8 -4
- package/dist/middleware/platform-notify.d.ts.map +1 -1
- package/dist/middleware/platform-notify.js +11 -7
- package/dist/middleware/platform-notify.js.map +1 -1
- package/dist/middleware/tracing.d.ts +50 -0
- package/dist/middleware/tracing.d.ts.map +1 -0
- package/dist/middleware/tracing.js +89 -0
- package/dist/middleware/tracing.js.map +1 -0
- package/dist/module.d.ts +94 -2
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +99 -2
- package/dist/module.js.map +1 -1
- package/dist/observability/batch-span-processor.d.ts +48 -0
- package/dist/observability/batch-span-processor.d.ts.map +1 -0
- package/dist/observability/batch-span-processor.js +89 -0
- package/dist/observability/batch-span-processor.js.map +1 -0
- package/dist/observability/context-logger.d.ts +54 -1
- package/dist/observability/context-logger.d.ts.map +1 -1
- package/dist/observability/context-logger.js +270 -6
- package/dist/observability/context-logger.js.map +1 -1
- package/dist/observability/error-history.d.ts +36 -7
- package/dist/observability/error-history.d.ts.map +1 -1
- package/dist/observability/error-history.js +169 -50
- package/dist/observability/error-history.js.map +1 -1
- package/dist/observability/index.d.ts +16 -5
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +8 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/metrics.d.ts +14 -1
- package/dist/observability/metrics.d.ts.map +1 -1
- package/dist/observability/metrics.js +23 -2
- package/dist/observability/metrics.js.map +1 -1
- package/dist/observability/prometheus-exporter.d.ts +37 -0
- package/dist/observability/prometheus-exporter.d.ts.map +1 -0
- package/dist/observability/prometheus-exporter.js +135 -0
- package/dist/observability/prometheus-exporter.js.map +1 -0
- package/dist/observability/storage.d.ts +43 -0
- package/dist/observability/storage.d.ts.map +1 -0
- package/dist/observability/storage.js +58 -0
- package/dist/observability/storage.js.map +1 -0
- package/dist/observability/store.d.ts +29 -0
- package/dist/observability/store.d.ts.map +1 -0
- package/dist/observability/store.js +36 -0
- package/dist/observability/store.js.map +1 -0
- package/dist/observability/usage-exporter.d.ts +58 -0
- package/dist/observability/usage-exporter.d.ts.map +1 -0
- package/dist/observability/usage-exporter.js +86 -0
- package/dist/observability/usage-exporter.js.map +1 -0
- package/dist/observability/usage.d.ts +18 -1
- package/dist/observability/usage.d.ts.map +1 -1
- package/dist/observability/usage.js +25 -3
- package/dist/observability/usage.js.map +1 -1
- package/dist/pipeline-config.d.ts +11 -0
- package/dist/pipeline-config.d.ts.map +1 -1
- package/dist/pipeline-config.js +36 -10
- package/dist/pipeline-config.js.map +1 -1
- package/dist/pipeline.d.ts +123 -2
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +249 -50
- package/dist/pipeline.js.map +1 -1
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -0
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/multi-class.d.ts +71 -0
- package/dist/registry/multi-class.d.ts.map +1 -0
- package/dist/registry/multi-class.js +120 -0
- package/dist/registry/multi-class.js.map +1 -0
- package/dist/registry/registry.d.ts +246 -5
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +485 -16
- package/dist/registry/registry.js.map +1 -1
- package/dist/schema/annotations.d.ts.map +1 -1
- package/dist/schema/annotations.js +1 -0
- package/dist/schema/annotations.js.map +1 -1
- package/dist/schema/constants.d.ts +9 -0
- package/dist/schema/constants.d.ts.map +1 -0
- package/dist/schema/constants.js +9 -0
- package/dist/schema/constants.js.map +1 -0
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/loader.d.ts +27 -3
- package/dist/schema/loader.d.ts.map +1 -1
- package/dist/schema/loader.js +137 -32
- package/dist/schema/loader.js.map +1 -1
- package/dist/schema/types.d.ts +4 -0
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js.map +1 -1
- package/dist/schema/validator.d.ts +9 -0
- package/dist/schema/validator.d.ts.map +1 -1
- package/dist/schema/validator.js +153 -4
- package/dist/schema/validator.js.map +1 -1
- package/dist/sys-modules/audit.d.ts +50 -0
- package/dist/sys-modules/audit.d.ts.map +1 -0
- package/dist/sys-modules/audit.js +89 -0
- package/dist/sys-modules/audit.js.map +1 -0
- package/dist/sys-modules/control.d.ts +32 -4
- package/dist/sys-modules/control.d.ts.map +1 -1
- package/dist/sys-modules/control.js +196 -25
- package/dist/sys-modules/control.js.map +1 -1
- package/dist/sys-modules/index.d.ts +7 -2
- package/dist/sys-modules/index.d.ts.map +1 -1
- package/dist/sys-modules/index.js +3 -1
- package/dist/sys-modules/index.js.map +1 -1
- package/dist/sys-modules/overrides.d.ts +58 -0
- package/dist/sys-modules/overrides.d.ts.map +1 -0
- package/dist/sys-modules/overrides.js +106 -0
- package/dist/sys-modules/overrides.js.map +1 -0
- package/dist/sys-modules/registration.d.ts +17 -12
- package/dist/sys-modules/registration.d.ts.map +1 -1
- package/dist/sys-modules/registration.js +134 -23
- package/dist/sys-modules/registration.js.map +1 -1
- package/dist/sys-modules/toggle.d.ts +7 -2
- package/dist/sys-modules/toggle.d.ts.map +1 -1
- package/dist/sys-modules/toggle.js +61 -5
- package/dist/sys-modules/toggle.js.map +1 -1
- package/dist/trace-context.d.ts +47 -9
- package/dist/trace-context.d.ts.map +1 -1
- package/dist/trace-context.js +139 -16
- package/dist/trace-context.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Event subscribers for webhook and
|
|
2
|
+
* Event subscribers for webhook, A2A, file, stdout, and filter delivery.
|
|
3
3
|
*/
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
const SEVERITY_ORDER = { info: 0, warn: 1, error: 2, fatal: 3 };
|
|
6
|
+
const _patternCache = new Map();
|
|
7
|
+
function fnmatch(text, pattern) {
|
|
8
|
+
let regex = _patternCache.get(pattern);
|
|
9
|
+
if (regex === undefined) {
|
|
10
|
+
const regexStr = Array.from(pattern)
|
|
11
|
+
.map((c) => {
|
|
12
|
+
if (c === '*')
|
|
13
|
+
return '.*';
|
|
14
|
+
if (c === '?')
|
|
15
|
+
return '.';
|
|
16
|
+
return c.replace(/[$()*+.?[\]^{|}-]/g, '\\$&');
|
|
17
|
+
})
|
|
18
|
+
.join('');
|
|
19
|
+
regex = new RegExp(`^${regexStr}$`);
|
|
20
|
+
_patternCache.set(pattern, regex);
|
|
21
|
+
}
|
|
22
|
+
return regex.test(text);
|
|
23
|
+
}
|
|
4
24
|
/**
|
|
5
25
|
* Delivers events via HTTP POST to a webhook URL.
|
|
6
26
|
*
|
|
@@ -129,4 +149,107 @@ export class A2ASubscriber {
|
|
|
129
149
|
}
|
|
130
150
|
}
|
|
131
151
|
}
|
|
152
|
+
/** Writes events to a local file (built-in type: 'file'). */
|
|
153
|
+
export class FileSubscriber {
|
|
154
|
+
_path;
|
|
155
|
+
_append;
|
|
156
|
+
_format;
|
|
157
|
+
_rotateBytes;
|
|
158
|
+
constructor(path, append = true, format = 'json', rotateBytes) {
|
|
159
|
+
this._path = path;
|
|
160
|
+
this._append = append;
|
|
161
|
+
this._format = format;
|
|
162
|
+
this._rotateBytes = rotateBytes ?? null;
|
|
163
|
+
}
|
|
164
|
+
async onEvent(event) {
|
|
165
|
+
try {
|
|
166
|
+
if (this._rotateBytes !== null) {
|
|
167
|
+
try {
|
|
168
|
+
const stat = fs.statSync(this._path);
|
|
169
|
+
if (stat.size >= this._rotateBytes) {
|
|
170
|
+
fs.renameSync(this._path, `${this._path}.1`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// file doesn't exist yet — no rotation needed
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const line = this._format === 'json'
|
|
178
|
+
? JSON.stringify({
|
|
179
|
+
event_type: event.eventType,
|
|
180
|
+
module_id: event.moduleId,
|
|
181
|
+
timestamp: event.timestamp,
|
|
182
|
+
severity: event.severity,
|
|
183
|
+
data: event.data,
|
|
184
|
+
}) + '\n'
|
|
185
|
+
: `[${event.timestamp}] [${event.severity.toUpperCase()}] ${event.eventType} module=${event.moduleId} data=${JSON.stringify(event.data)}\n`;
|
|
186
|
+
fs.writeFileSync(this._path, line, { flag: this._append ? 'a' : 'w', encoding: 'utf-8' });
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
console.warn('[apcore:events]', `FileSubscriber failed to write event ${event.eventType} to ${this._path}:`, err);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** Writes events to stdout (built-in type: 'stdout'). */
|
|
194
|
+
export class StdoutSubscriber {
|
|
195
|
+
_format;
|
|
196
|
+
_levelFilter;
|
|
197
|
+
constructor(format = 'text', levelFilter) {
|
|
198
|
+
this._format = format;
|
|
199
|
+
if (levelFilter !== undefined && !(levelFilter in SEVERITY_ORDER)) {
|
|
200
|
+
console.warn(`[apcore:events] StdoutSubscriber: unknown level_filter '${levelFilter}' — valid values: info, warn, error, fatal. All events will pass.`);
|
|
201
|
+
}
|
|
202
|
+
this._levelFilter = levelFilter ?? null;
|
|
203
|
+
}
|
|
204
|
+
async onEvent(event) {
|
|
205
|
+
if (this._levelFilter !== null) {
|
|
206
|
+
const minLevel = SEVERITY_ORDER[this._levelFilter] ?? 0;
|
|
207
|
+
const eventLevel = SEVERITY_ORDER[event.severity] ?? 0;
|
|
208
|
+
if (eventLevel < minLevel)
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const line = this._format === 'json'
|
|
212
|
+
? JSON.stringify({
|
|
213
|
+
event_type: event.eventType,
|
|
214
|
+
module_id: event.moduleId,
|
|
215
|
+
timestamp: event.timestamp,
|
|
216
|
+
severity: event.severity,
|
|
217
|
+
data: event.data,
|
|
218
|
+
})
|
|
219
|
+
: `[${event.timestamp}] [${event.severity.toUpperCase()}] ${event.eventType} module=${event.moduleId} data=${JSON.stringify(event.data)}`;
|
|
220
|
+
process.stdout.write(line + '\n');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Wraps a delegate subscriber with event-name filtering (built-in type: 'filter').
|
|
225
|
+
*
|
|
226
|
+
* Matching rules (evaluated in order):
|
|
227
|
+
* 1. If include_events is set, forward only events matching any pattern.
|
|
228
|
+
* 2. Otherwise if exclude_events is set, discard events matching any pattern.
|
|
229
|
+
* 3. If neither is set, forward all events.
|
|
230
|
+
*/
|
|
231
|
+
export class FilterSubscriber {
|
|
232
|
+
_delegate;
|
|
233
|
+
_includeEvents;
|
|
234
|
+
_excludeEvents;
|
|
235
|
+
constructor(delegate, includeEvents, excludeEvents) {
|
|
236
|
+
this._delegate = delegate;
|
|
237
|
+
this._includeEvents = includeEvents ?? null;
|
|
238
|
+
this._excludeEvents = excludeEvents ?? null;
|
|
239
|
+
}
|
|
240
|
+
async onEvent(event) {
|
|
241
|
+
if (this._matches(event.eventType)) {
|
|
242
|
+
await this._delegate.onEvent(event);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
_matches(eventType) {
|
|
246
|
+
if (this._includeEvents !== null) {
|
|
247
|
+
return this._includeEvents.some((pattern) => fnmatch(eventType, pattern));
|
|
248
|
+
}
|
|
249
|
+
if (this._excludeEvents !== null) {
|
|
250
|
+
return !this._excludeEvents.some((pattern) => fnmatch(eventType, pattern));
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
132
255
|
//# sourceMappingURL=subscribers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribers.js","sourceRoot":"","sources":["../../src/events/subscribers.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"subscribers.js","sourceRoot":"","sources":["../../src/events/subscribers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAG9B,MAAM,cAAc,GAA2B,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAExF,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEhD,SAAS,OAAO,CAAC,IAAY,EAAE,OAAe;IAC5C,IAAI,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;aACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,GAAG,CAAC;YAC1B,OAAO,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC,CAAC;aACD,IAAI,CA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 @@ import type { ACL } from './acl.js';
|
|
|
8
8
|
import type { ApprovalHandler } from './approval.js';
|
|
9
9
|
import type { Config } from './config.js';
|
|
10
10
|
import { Context } from './context.js';
|
|
11
|
-
import { Middleware } from './middleware/index.js';
|
|
11
|
+
import { type Middleware } from './middleware/index.js';
|
|
12
12
|
import type { PreflightResult } from './module.js';
|
|
13
|
-
import type { Registry } from './registry/registry.js';
|
|
14
13
|
import type { PipelineTrace, StrategyInfo } from './pipeline.js';
|
|
15
14
|
import { ExecutionStrategy } from './pipeline.js';
|
|
15
|
+
import type { Registry } from './registry/registry.js';
|
|
16
16
|
import type { ToggleState } from './sys-modules/toggle.js';
|
|
17
17
|
export declare const REDACTED_VALUE: string;
|
|
18
18
|
/** Well-known context.data keys used internally by the runtime. */
|
|
@@ -62,6 +62,14 @@ export declare class Executor {
|
|
|
62
62
|
useAfter(callback: (moduleId: string, inputs: Record<string, unknown>, output: Record<string, unknown>, context: Context) => Record<string, unknown> | null): Executor;
|
|
63
63
|
remove(middleware: Middleware): boolean;
|
|
64
64
|
call(moduleId: string, inputs?: Record<string, unknown> | null, context?: Context | null, versionHint?: string | null): Promise<Record<string, unknown>>;
|
|
65
|
+
/**
|
|
66
|
+
* Reset PipelineContext for another attempt triggered by a RetrySignal.
|
|
67
|
+
*
|
|
68
|
+
* Preserves the top-level Context (so retry counters in context.data carry
|
|
69
|
+
* across attempts) while clearing per-run fields that the next attempt
|
|
70
|
+
* will re-populate. (sync finding A-D-017)
|
|
71
|
+
*/
|
|
72
|
+
private _resetPipeCtxForRetry;
|
|
65
73
|
/**
|
|
66
74
|
* Alias for call(). Provided for compatibility with MCP bridge packages
|
|
67
75
|
* that may call callAsync() by convention.
|
package/dist/executor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,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_async() merge into one async call().
|
|
5
5
|
* Timeout uses Promise.race instead of threading.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { BuiltinACLCheck, BuiltinApprovalGate, buildInternalStrategy, buildMinimalStrategy, buildPerformanceStrategy, buildStandardStrategy, buildTestingStrategy, } from './builtin-steps.js';
|
|
8
8
|
import { ExecutionCancelledError } from './cancel.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { Context } from './context.js';
|
|
10
|
+
import { InvalidInputError, ModuleError, ModuleTimeoutError } from './errors.js';
|
|
11
|
+
import { AfterMiddleware, BeforeMiddleware, RetrySignal, } from './middleware/index.js';
|
|
11
12
|
import { MiddlewareChainError, MiddlewareManager } from './middleware/manager.js';
|
|
12
13
|
import { createPreflightResult } from './module.js';
|
|
14
|
+
import { ExecutionStrategy, PipelineAbortError, PipelineEngine, PipelineStepError, StrategyNotFoundError, } from './pipeline.js';
|
|
13
15
|
import { MODULE_ID_PATTERN } from './registry/registry.js';
|
|
14
|
-
import { ExecutionStrategy, PipelineEngine, PipelineAbortError, StrategyNotFoundError } from './pipeline.js';
|
|
15
|
-
import { BuiltinACLCheck, BuiltinApprovalGate, buildStandardStrategy, buildInternalStrategy, buildTestingStrategy, buildPerformanceStrategy, buildMinimalStrategy, } from './builtin-steps.js';
|
|
16
16
|
import { propagateError } from './utils/error-propagation.js';
|
|
17
17
|
export const REDACTED_VALUE = '***REDACTED***';
|
|
18
18
|
/** Well-known context.data keys used internally by the runtime. */
|
|
@@ -38,7 +38,11 @@ function redactFields(data, schemaDict) {
|
|
|
38
38
|
}
|
|
39
39
|
continue;
|
|
40
40
|
}
|
|
41
|
-
if (fieldSchema['type'] === 'object' &&
|
|
41
|
+
if (fieldSchema['type'] === 'object' &&
|
|
42
|
+
'properties' in fieldSchema &&
|
|
43
|
+
typeof value === 'object' &&
|
|
44
|
+
value !== null &&
|
|
45
|
+
!Array.isArray(value)) {
|
|
42
46
|
redactFields(value, fieldSchema);
|
|
43
47
|
continue;
|
|
44
48
|
}
|
|
@@ -171,7 +175,7 @@ export class Executor {
|
|
|
171
175
|
}
|
|
172
176
|
/** List info for all registered strategies. */
|
|
173
177
|
static listStrategies() {
|
|
174
|
-
return [...Executor._strategyRegistry.values()].map(s => s.info());
|
|
178
|
+
return [...Executor._strategyRegistry.values()].map((s) => s.info());
|
|
175
179
|
}
|
|
176
180
|
/** Describe the pipeline of the executor's current strategy. */
|
|
177
181
|
describePipeline() {
|
|
@@ -252,29 +256,54 @@ export class Executor {
|
|
|
252
256
|
trace: null,
|
|
253
257
|
versionHint: versionHint ?? null,
|
|
254
258
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
259
|
+
// Loop iterates only when a RetrySignal is returned from middleware
|
|
260
|
+
// onError; every other path returns or throws on the first attempt
|
|
261
|
+
// (sync finding A-D-017).
|
|
262
|
+
while (true) {
|
|
263
|
+
try {
|
|
264
|
+
const [output, _trace] = await this._pipelineEngine.run(this._strategy, pipeCtx);
|
|
265
|
+
return (output ?? {});
|
|
266
|
+
}
|
|
267
|
+
catch (exc) {
|
|
268
|
+
if (exc instanceof ExecutionCancelledError)
|
|
269
|
+
throw exc;
|
|
270
|
+
// PipelineStepError is the engine-level contract (§1.1). Unwrap the cause
|
|
271
|
+
// so the executor's public API surfaces the original typed error.
|
|
272
|
+
const unwrapped = exc instanceof PipelineStepError ? (exc.cause instanceof Error ? exc.cause : exc) : exc;
|
|
273
|
+
// MiddlewareChainError wraps the original; unwrap it so callers see the
|
|
274
|
+
// real error class/code instead of a generic MODULE_EXECUTE_ERROR.
|
|
275
|
+
const ctxObj = pipeCtx.context;
|
|
276
|
+
const underlying = unwrapped instanceof MiddlewareChainError ? unwrapped.original : unwrapped;
|
|
277
|
+
const wrapped = propagateError(underlying, moduleId, ctxObj);
|
|
278
|
+
const executedMw = pipeCtx.executedMiddlewares;
|
|
279
|
+
if (executedMw && executedMw.length > 0) {
|
|
280
|
+
const recovery = await this._middlewareManager.executeOnError(moduleId, pipeCtx.inputs, wrapped, ctxObj, executedMw);
|
|
281
|
+
if (recovery instanceof RetrySignal) {
|
|
282
|
+
this._resetPipeCtxForRetry(pipeCtx, recovery.inputs);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (recovery !== null)
|
|
286
|
+
return recovery;
|
|
287
|
+
}
|
|
288
|
+
throw wrapped;
|
|
274
289
|
}
|
|
275
|
-
throw wrapped;
|
|
276
290
|
}
|
|
277
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Reset PipelineContext for another attempt triggered by a RetrySignal.
|
|
294
|
+
*
|
|
295
|
+
* Preserves the top-level Context (so retry counters in context.data carry
|
|
296
|
+
* across attempts) while clearing per-run fields that the next attempt
|
|
297
|
+
* will re-populate. (sync finding A-D-017)
|
|
298
|
+
*/
|
|
299
|
+
_resetPipeCtxForRetry(pipeCtx, newInputs) {
|
|
300
|
+
pipeCtx.inputs = newInputs;
|
|
301
|
+
pipeCtx.validatedInputs = null;
|
|
302
|
+
pipeCtx.module = null;
|
|
303
|
+
pipeCtx.output = null;
|
|
304
|
+
pipeCtx.validatedOutput = null;
|
|
305
|
+
pipeCtx.executedMiddlewares = [];
|
|
306
|
+
}
|
|
278
307
|
/**
|
|
279
308
|
* Alias for call(). Provided for compatibility with MCP bridge packages
|
|
280
309
|
* that may call callAsync() by convention.
|
|
@@ -303,8 +332,18 @@ export class Executor {
|
|
|
303
332
|
strategy,
|
|
304
333
|
trace: null,
|
|
305
334
|
};
|
|
306
|
-
|
|
307
|
-
|
|
335
|
+
try {
|
|
336
|
+
const [output, trace] = await this._pipelineEngine.run(strategy, pipelineCtx);
|
|
337
|
+
return [(output ?? {}), trace];
|
|
338
|
+
}
|
|
339
|
+
catch (exc) {
|
|
340
|
+
// Unwrap PipelineStepError so callers see the original typed cause, consistent
|
|
341
|
+
// with call() behaviour (§1.1 engine-level contract vs public API surface).
|
|
342
|
+
if (exc instanceof PipelineStepError && exc.cause instanceof Error) {
|
|
343
|
+
throw exc.cause;
|
|
344
|
+
}
|
|
345
|
+
throw exc;
|
|
346
|
+
}
|
|
308
347
|
}
|
|
309
348
|
/**
|
|
310
349
|
* Streaming execution pipeline. If the module exposes a stream() async generator,
|
|
@@ -352,10 +391,15 @@ export class Executor {
|
|
|
352
391
|
if (exc instanceof ExecutionCancelledError)
|
|
353
392
|
throw exc;
|
|
354
393
|
const ctxObj = pipeCtx.context;
|
|
355
|
-
|
|
394
|
+
// Unwrap PipelineStepError to expose the original typed cause (§1.1).
|
|
395
|
+
const unwrapped = exc instanceof PipelineStepError ? (exc.cause instanceof Error ? exc.cause : exc) : exc;
|
|
396
|
+
const wrapped = propagateError(unwrapped, moduleId, ctxObj);
|
|
356
397
|
if (pipeCtx.executedMiddlewares && pipeCtx.executedMiddlewares.length > 0) {
|
|
357
|
-
const recovery = this._middlewareManager.executeOnError(moduleId, pipeCtx.inputs, wrapped, ctxObj, pipeCtx.executedMiddlewares);
|
|
358
|
-
|
|
398
|
+
const recovery = await this._middlewareManager.executeOnError(moduleId, pipeCtx.inputs, wrapped, ctxObj, pipeCtx.executedMiddlewares);
|
|
399
|
+
// RetrySignal is not supported in stream mode — re-running a stream
|
|
400
|
+
// mid-flight is not well-defined. Fall through to throwing the wrapped
|
|
401
|
+
// error so the caller sees a normal failure (sync finding A-D-017).
|
|
402
|
+
if (recovery !== null && !(recovery instanceof RetrySignal)) {
|
|
359
403
|
yield recovery;
|
|
360
404
|
return;
|
|
361
405
|
}
|
|
@@ -370,8 +414,22 @@ export class Executor {
|
|
|
370
414
|
// Phase 2: Iterate stream, accumulate chunks
|
|
371
415
|
const outputStream = pipeCtx.outputStream;
|
|
372
416
|
const accumulated = {};
|
|
417
|
+
// Read the canonical deadline slot written by BuiltinContextCreation
|
|
418
|
+
// (ms-since-epoch). The earlier `pipeCtx.context.globalDeadline` read was
|
|
419
|
+
// always null in the executor pipeline path because that field is a
|
|
420
|
+
// separate context attribute that the pipeline never populates — and the
|
|
421
|
+
// subsequent `Date.now() / 1000` divisor pretended the value was epoch
|
|
422
|
+
// seconds. (sync finding A-D-202.)
|
|
423
|
+
const globalDeadline = pipeCtx.context?.data?.[CTX_GLOBAL_DEADLINE] ?? null;
|
|
373
424
|
try {
|
|
374
425
|
for await (const chunk of outputStream) {
|
|
426
|
+
// Enforce global_deadline between chunks — matches apcore-python
|
|
427
|
+
// executor.py:872-879 (sync finding A-D-014). The slot is stored as
|
|
428
|
+
// ms-since-epoch (Date.now() + globalTimeout in BuiltinContextCreation),
|
|
429
|
+
// so compare against Date.now() directly.
|
|
430
|
+
if (globalDeadline !== null && Date.now() > globalDeadline) {
|
|
431
|
+
throw new ModuleTimeoutError(moduleId, 0);
|
|
432
|
+
}
|
|
375
433
|
deepMergeChunk(accumulated, chunk);
|
|
376
434
|
yield chunk;
|
|
377
435
|
}
|
|
@@ -382,8 +440,9 @@ export class Executor {
|
|
|
382
440
|
const ctxObj = pipeCtx.context;
|
|
383
441
|
const wrapped = propagateError(exc, moduleId, ctxObj);
|
|
384
442
|
if (pipeCtx.executedMiddlewares && pipeCtx.executedMiddlewares.length > 0) {
|
|
385
|
-
const recovery = this._middlewareManager.executeOnError(moduleId, pipeCtx.inputs, wrapped, ctxObj, pipeCtx.executedMiddlewares);
|
|
386
|
-
|
|
443
|
+
const recovery = await this._middlewareManager.executeOnError(moduleId, pipeCtx.inputs, wrapped, ctxObj, pipeCtx.executedMiddlewares);
|
|
444
|
+
// RetrySignal not supported mid-stream (sync finding A-D-017).
|
|
445
|
+
if (recovery !== null && !(recovery instanceof RetrySignal)) {
|
|
387
446
|
yield recovery;
|
|
388
447
|
return;
|
|
389
448
|
}
|
|
@@ -392,25 +451,39 @@ export class Executor {
|
|
|
392
451
|
}
|
|
393
452
|
// Phase 3: Output validation + middleware_after on accumulated result
|
|
394
453
|
pipeCtx.output = accumulated;
|
|
395
|
-
const postSteps = this._strategy.steps.filter((s) => s.name === 'output_validation' ||
|
|
454
|
+
const postSteps = this._strategy.steps.filter((s) => s.name === 'output_validation' ||
|
|
455
|
+
s.name === 'middleware_after' ||
|
|
456
|
+
s.name === 'return_result');
|
|
396
457
|
if (postSteps.length > 0) {
|
|
397
|
-
|
|
458
|
+
// The post-stream sub-strategy starts with module + output already
|
|
459
|
+
// populated on pipeCtx (set by Phase 1 / Phase 2 above), so seed those
|
|
460
|
+
// names into the dependency check (§2.1).
|
|
461
|
+
const postStrategy = new ExecutionStrategy('post_stream', postSteps, {
|
|
462
|
+
seedProvides: ['module', 'output'],
|
|
463
|
+
});
|
|
398
464
|
try {
|
|
399
465
|
await this._pipelineEngine.run(postStrategy, pipeCtx);
|
|
400
466
|
}
|
|
401
467
|
catch (exc) {
|
|
402
468
|
if (exc instanceof ExecutionCancelledError)
|
|
403
469
|
throw exc;
|
|
404
|
-
// Chunks already
|
|
405
|
-
//
|
|
406
|
-
//
|
|
407
|
-
//
|
|
470
|
+
// Chunks are already delivered to the caller and cannot be recalled.
|
|
471
|
+
// Swallow the phase-3 error and log a warning — matches apcore-python
|
|
472
|
+
// executor.py:920 which emits an ApCoreEvent("apcore.stream.post_validation_failed")
|
|
473
|
+
// and does NOT re-raise (sync finding A-D-012).
|
|
474
|
+
// TODO: emit ApCoreEvent via injected EventEmitter when Executor gains
|
|
475
|
+
// an optional eventEmitter constructor field (pending architectural wiring).
|
|
408
476
|
const ctxObj = pipeCtx.context;
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
477
|
+
const unwrappedPost = exc instanceof PipelineStepError ? (exc.cause instanceof Error ? exc.cause : exc) : exc;
|
|
478
|
+
const wrapped = propagateError(unwrappedPost, moduleId, ctxObj);
|
|
479
|
+
// Sync finding A-D-011: phase-3 errors must NOT invoke middleware
|
|
480
|
+
// `on_error` once chunks have already been yielded. The middleware
|
|
481
|
+
// recovery contract is "produce a recovery output before any output is
|
|
482
|
+
// visible"; running on_error after partial-output emission breaks that
|
|
483
|
+
// contract. apcore-python and apcore-rust only log/emit at this point;
|
|
484
|
+
// TS now matches.
|
|
485
|
+
console.warn(`[apcore:executor] stream phase-3 failure for '${moduleId}' (chunks already delivered): ${wrapped.message}`);
|
|
486
|
+
// Do not rethrow — phase-3 errors are swallowed per spec.
|
|
414
487
|
}
|
|
415
488
|
}
|
|
416
489
|
}
|
|
@@ -427,7 +500,8 @@ export class Executor {
|
|
|
427
500
|
// Check 0: module_id format (before pipeline)
|
|
428
501
|
if (!MODULE_ID_PATTERN.test(moduleId)) {
|
|
429
502
|
checks.push({
|
|
430
|
-
check: 'module_id',
|
|
503
|
+
check: 'module_id',
|
|
504
|
+
passed: false,
|
|
431
505
|
error: { code: 'INVALID_INPUT', message: `Invalid module ID: "${moduleId}"` },
|
|
432
506
|
});
|
|
433
507
|
return createPreflightResult(checks);
|
|
@@ -459,10 +533,17 @@ export class Executor {
|
|
|
459
533
|
trace = e.pipelineTrace;
|
|
460
534
|
}
|
|
461
535
|
else {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
536
|
+
// Unwrap PipelineStepError to expose the original typed cause (§1.1).
|
|
537
|
+
const underlying = e instanceof PipelineStepError ? (e.cause instanceof Error ? e.cause : e) : e;
|
|
538
|
+
const errorDict = underlying instanceof ModuleError
|
|
539
|
+
? { code: underlying.code, message: underlying.message }
|
|
540
|
+
: {
|
|
541
|
+
code: underlying.constructor?.name ?? 'Error',
|
|
542
|
+
message: String(underlying),
|
|
543
|
+
};
|
|
544
|
+
const code = underlying instanceof ModuleError
|
|
545
|
+
? underlying.code
|
|
546
|
+
: (underlying.constructor?.name ?? 'Error');
|
|
466
547
|
let checkName;
|
|
467
548
|
if (code === 'MODULE_NOT_FOUND')
|
|
468
549
|
checkName = 'module_lookup';
|
|
@@ -470,7 +551,9 @@ export class Executor {
|
|
|
470
551
|
checkName = 'acl';
|
|
471
552
|
else if (code === 'SCHEMA_VALIDATION_ERROR' || code === 'INVALID_INPUT')
|
|
472
553
|
checkName = 'schema';
|
|
473
|
-
else if (code === 'CALL_DEPTH_EXCEEDED' ||
|
|
554
|
+
else if (code === 'CALL_DEPTH_EXCEEDED' ||
|
|
555
|
+
code === 'CIRCULAR_CALL' ||
|
|
556
|
+
code === 'CALL_FREQUENCY_EXCEEDED')
|
|
474
557
|
checkName = 'call_chain';
|
|
475
558
|
else
|
|
476
559
|
checkName = 'unknown';
|
|
@@ -511,7 +594,45 @@ export class Executor {
|
|
|
511
594
|
}
|
|
512
595
|
}
|
|
513
596
|
}
|
|
514
|
-
|
|
597
|
+
// Module-level preview() (optional, RFC `rfc-preview-method.md` — Draft / RFC).
|
|
598
|
+
// Invoked only after the standard validation pipeline has been processed.
|
|
599
|
+
// Returning null is equivalent to omitting the method. Exceptions (sync
|
|
600
|
+
// throws or async rejections) are treated as advisory warnings and do NOT
|
|
601
|
+
// fail validation, mirroring `preflight()` semantics (RFC Open Question 1).
|
|
602
|
+
let predictedChanges;
|
|
603
|
+
if (pipeCtx.module != null) {
|
|
604
|
+
const mod = pipeCtx.module;
|
|
605
|
+
const modWithPreview = mod;
|
|
606
|
+
if (typeof modWithPreview.preview === 'function') {
|
|
607
|
+
try {
|
|
608
|
+
const raw = modWithPreview.preview(effectiveInputs, pipeCtx.context);
|
|
609
|
+
// Support both sync and async preview() implementations.
|
|
610
|
+
const result = raw != null && typeof raw.then === 'function'
|
|
611
|
+
? await raw
|
|
612
|
+
: raw;
|
|
613
|
+
if (result != null && Array.isArray(result.changes) && result.changes.length > 0) {
|
|
614
|
+
predictedChanges = result.changes;
|
|
615
|
+
checks.push({ check: 'module_preview', passed: true });
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
// Method present but returned null / empty — record the no-op
|
|
619
|
+
// check so consumers can distinguish "module has preview()" from
|
|
620
|
+
// "module does not implement preview()" if desired.
|
|
621
|
+
checks.push({ check: 'module_preview', passed: true });
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
catch (exc) {
|
|
625
|
+
const excName = exc instanceof Error ? exc.constructor.name : 'Error';
|
|
626
|
+
const excMsg = exc instanceof Error ? exc.message : String(exc);
|
|
627
|
+
checks.push({
|
|
628
|
+
check: 'module_preview',
|
|
629
|
+
passed: true,
|
|
630
|
+
warnings: [`preview() raised ${excName}: ${excMsg}`],
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return createPreflightResult(checks, requiresApproval, predictedChanges);
|
|
515
636
|
}
|
|
516
637
|
/** Map pipeline step names to PreflightResult check names. */
|
|
517
638
|
static _STEP_TO_CHECK = {
|