@zelari/core 2.10.0 → 2.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/dist/context/ContextPolicy.d.ts +48 -0
- package/dist/context/ContextPolicy.d.ts.map +1 -0
- package/dist/context/ContextPolicy.js +71 -0
- package/dist/context/ContextPolicy.js.map +1 -0
- package/dist/context/ContextProjector.d.ts +44 -0
- package/dist/context/ContextProjector.d.ts.map +1 -0
- package/dist/context/ContextProjector.js +156 -0
- package/dist/context/ContextProjector.js.map +1 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +11 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/parentContext.d.ts +39 -0
- package/dist/context/parentContext.d.ts.map +1 -0
- package/dist/context/parentContext.js +67 -0
- package/dist/context/parentContext.js.map +1 -0
- package/dist/core/AgentHarness.d.ts +38 -0
- package/dist/core/AgentHarness.d.ts.map +1 -1
- package/dist/core/AgentHarness.js +142 -0
- package/dist/core/AgentHarness.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/controls/RuntimeControlQueue.d.ts +35 -0
- package/dist/runtime/controls/RuntimeControlQueue.d.ts.map +1 -0
- package/dist/runtime/controls/RuntimeControlQueue.js +54 -0
- package/dist/runtime/controls/RuntimeControlQueue.js.map +1 -0
- package/dist/runtime/controls/SteeringObserver.d.ts +24 -0
- package/dist/runtime/controls/SteeringObserver.d.ts.map +1 -0
- package/dist/runtime/controls/SteeringObserver.js +46 -0
- package/dist/runtime/controls/SteeringObserver.js.map +1 -0
- package/dist/runtime/controls/index.d.ts +4 -0
- package/dist/runtime/controls/index.d.ts.map +1 -0
- package/dist/runtime/controls/index.js +4 -0
- package/dist/runtime/controls/index.js.map +1 -0
- package/dist/runtime/controls/types.d.ts +43 -0
- package/dist/runtime/controls/types.d.ts.map +1 -0
- package/dist/runtime/controls/types.js +18 -0
- package/dist/runtime/controls/types.js.map +1 -0
- package/dist/runtime/guards/DuplicateSearchGuard.d.ts +41 -0
- package/dist/runtime/guards/DuplicateSearchGuard.d.ts.map +1 -0
- package/dist/runtime/guards/DuplicateSearchGuard.js +150 -0
- package/dist/runtime/guards/DuplicateSearchGuard.js.map +1 -0
- package/dist/runtime/guards/FailureSignatureGuard.d.ts +34 -0
- package/dist/runtime/guards/FailureSignatureGuard.d.ts.map +1 -0
- package/dist/runtime/guards/FailureSignatureGuard.js +143 -0
- package/dist/runtime/guards/FailureSignatureGuard.js.map +1 -0
- package/dist/runtime/guards/NoProgressGuard.d.ts +23 -0
- package/dist/runtime/guards/NoProgressGuard.d.ts.map +1 -0
- package/dist/runtime/guards/NoProgressGuard.js +84 -0
- package/dist/runtime/guards/NoProgressGuard.js.map +1 -0
- package/dist/runtime/guards/ReasoningWatchdog.d.ts +48 -0
- package/dist/runtime/guards/ReasoningWatchdog.d.ts.map +1 -0
- package/dist/runtime/guards/ReasoningWatchdog.js +135 -0
- package/dist/runtime/guards/ReasoningWatchdog.js.map +1 -0
- package/dist/runtime/guards/RepetitionGuard.d.ts +22 -0
- package/dist/runtime/guards/RepetitionGuard.d.ts.map +1 -0
- package/dist/runtime/guards/RepetitionGuard.js +56 -0
- package/dist/runtime/guards/RepetitionGuard.js.map +1 -0
- package/dist/runtime/guards/index.d.ts +6 -0
- package/dist/runtime/guards/index.d.ts.map +1 -0
- package/dist/runtime/guards/index.js +6 -0
- package/dist/runtime/guards/index.js.map +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/observers/MetricsObserver.d.ts +42 -0
- package/dist/runtime/observers/MetricsObserver.d.ts.map +1 -0
- package/dist/runtime/observers/MetricsObserver.js +110 -0
- package/dist/runtime/observers/MetricsObserver.js.map +1 -0
- package/dist/runtime/observers/ObserverBus.d.ts +49 -0
- package/dist/runtime/observers/ObserverBus.d.ts.map +1 -0
- package/dist/runtime/observers/ObserverBus.js +160 -0
- package/dist/runtime/observers/ObserverBus.js.map +1 -0
- package/dist/runtime/observers/TraceObserver.d.ts +36 -0
- package/dist/runtime/observers/TraceObserver.d.ts.map +1 -0
- package/dist/runtime/observers/TraceObserver.js +78 -0
- package/dist/runtime/observers/TraceObserver.js.map +1 -0
- package/dist/runtime/observers/composeObservers.d.ts +10 -0
- package/dist/runtime/observers/composeObservers.d.ts.map +1 -0
- package/dist/runtime/observers/composeObservers.js +30 -0
- package/dist/runtime/observers/composeObservers.js.map +1 -0
- package/dist/runtime/observers/index.d.ts +7 -0
- package/dist/runtime/observers/index.d.ts.map +1 -0
- package/dist/runtime/observers/index.js +7 -0
- package/dist/runtime/observers/index.js.map +1 -0
- package/dist/runtime/observers/resolve.d.ts +3 -0
- package/dist/runtime/observers/resolve.d.ts.map +1 -0
- package/dist/runtime/observers/resolve.js +30 -0
- package/dist/runtime/observers/resolve.js.map +1 -0
- package/dist/runtime/observers/types.d.ts +113 -0
- package/dist/runtime/observers/types.d.ts.map +1 -0
- package/dist/runtime/observers/types.js +13 -0
- package/dist/runtime/observers/types.js.map +1 -0
- package/dist/runtime/recorder/Redactor.d.ts +19 -0
- package/dist/runtime/recorder/Redactor.d.ts.map +1 -0
- package/dist/runtime/recorder/Redactor.js +78 -0
- package/dist/runtime/recorder/Redactor.js.map +1 -0
- package/dist/runtime/recorder/RunRecorder.d.ts +73 -0
- package/dist/runtime/recorder/RunRecorder.d.ts.map +1 -0
- package/dist/runtime/recorder/RunRecorder.js +137 -0
- package/dist/runtime/recorder/RunRecorder.js.map +1 -0
- package/dist/runtime/recorder/index.d.ts +8 -0
- package/dist/runtime/recorder/index.d.ts.map +1 -0
- package/dist/runtime/recorder/index.js +8 -0
- package/dist/runtime/recorder/index.js.map +1 -0
- package/dist/runtime/recorder/recorderObserver.d.ts +4 -0
- package/dist/runtime/recorder/recorderObserver.d.ts.map +1 -0
- package/dist/runtime/recorder/recorderObserver.js +63 -0
- package/dist/runtime/recorder/recorderObserver.js.map +1 -0
- package/dist/runtime/recorder/retention.d.ts +15 -0
- package/dist/runtime/recorder/retention.d.ts.map +1 -0
- package/dist/runtime/recorder/retention.js +105 -0
- package/dist/runtime/recorder/retention.js.map +1 -0
- package/dist/session/taskContract.d.ts +2 -2
- package/dist/shared/events.d.ts +40 -2
- package/dist/shared/events.d.ts.map +1 -1
- package/dist/shared/events.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObserverBus.d.ts","sourceRoot":"","sources":["../../../src/runtime/observers/ObserverBus.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AAYpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAID,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuB;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;gBAGjD,WAAW,GAAE,kBAAkB,EAAO,EACtC,OAAO,GAAE,kBAAuB;IAMlC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEK,IAAI,CAAC,CAAC,SAAS,MAAM,aAAa,EACtC,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,cAAc,EAAE,CAAC;IA2BtB,YAAY,CAAC,CAAC,SAAS,MAAM,aAAa,EAC9C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,cAAc,CAAC;CAG3B;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAGjD;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,yBAA8B,GACtC,WAAW,GAAG,SAAS,CA6EzB"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObserverBus — ordered, failure-mode-aware fan-out to a set of observers.
|
|
3
|
+
*
|
|
4
|
+
* Observers run in ascending priority; each throw is isolated per the
|
|
5
|
+
* descriptor's `failureMode`. `emit` returns the raw result list;
|
|
6
|
+
* `emitResolved` collapses it to a single intervention via
|
|
7
|
+
* {@link resolveInterventions}.
|
|
8
|
+
*/
|
|
9
|
+
import { CONTINUE } from './types.js';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { resolveInterventions } from './resolve.js';
|
|
12
|
+
import { RepetitionGuard } from '../guards/RepetitionGuard.js';
|
|
13
|
+
import { FailureSignatureGuard } from '../guards/FailureSignatureGuard.js';
|
|
14
|
+
import { DuplicateSearchGuard } from '../guards/DuplicateSearchGuard.js';
|
|
15
|
+
import { NoProgressGuard } from '../guards/NoProgressGuard.js';
|
|
16
|
+
import { ReasoningWatchdog } from '../guards/ReasoningWatchdog.js';
|
|
17
|
+
import { TraceObserver } from './TraceObserver.js';
|
|
18
|
+
import { MetricsObserver } from './MetricsObserver.js';
|
|
19
|
+
import { RunRecorder, newRunId, runRecordEnabled } from '../recorder/RunRecorder.js';
|
|
20
|
+
import { createRecorderObserver } from '../recorder/recorderObserver.js';
|
|
21
|
+
import { SteeringObserver } from '../controls/SteeringObserver.js';
|
|
22
|
+
export class ObserverBus {
|
|
23
|
+
descriptors;
|
|
24
|
+
logger;
|
|
25
|
+
constructor(descriptors = [], options = {}) {
|
|
26
|
+
this.descriptors = [...descriptors].sort((a, b) => a.priority - b.priority);
|
|
27
|
+
this.logger = options.logger ?? (() => { });
|
|
28
|
+
}
|
|
29
|
+
get size() {
|
|
30
|
+
return this.descriptors.length;
|
|
31
|
+
}
|
|
32
|
+
async emit(hook, event) {
|
|
33
|
+
const results = [];
|
|
34
|
+
for (const descriptor of this.descriptors) {
|
|
35
|
+
const callback = descriptor.observer[hook];
|
|
36
|
+
if (typeof callback !== 'function')
|
|
37
|
+
continue;
|
|
38
|
+
try {
|
|
39
|
+
const result = await callback.call(descriptor.observer, event);
|
|
40
|
+
results.push(result ?? CONTINUE);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
44
|
+
if (descriptor.failureMode === 'fail-closed') {
|
|
45
|
+
results.push({
|
|
46
|
+
action: 'stop',
|
|
47
|
+
reason: `observer "${descriptor.id}" failed: ${message}`,
|
|
48
|
+
code: 'OBSERVER_FAIL_CLOSED',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (descriptor.failureMode === 'warn') {
|
|
53
|
+
this.logger(`[observers] ${descriptor.id} (${String(hook)}) failed: ${message}`);
|
|
54
|
+
}
|
|
55
|
+
results.push(CONTINUE);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
61
|
+
async emitResolved(hook, event) {
|
|
62
|
+
return resolveInterventions(await this.emit(hook, event));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Env flag for the default runtime-observer set (Frontier PHASE 1 rollout).
|
|
67
|
+
* Explicit `AgentHarnessConfig.observers` always run; this flag only gates
|
|
68
|
+
* the implicit default bus (RepetitionGuard, failureMode 'warn').
|
|
69
|
+
*/
|
|
70
|
+
export function runtimeObserversEnabled() {
|
|
71
|
+
const raw = process.env.ZELARI_RUNTIME_OBSERVERS?.trim().toLowerCase();
|
|
72
|
+
return raw === '1' || raw === 'true' || raw === 'on';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build the default observer bus: the four runtime guards (priority 30,
|
|
76
|
+
* warn) plus the telemetry-only observers — ReasoningWatchdog (priority 30,
|
|
77
|
+
* warn), TraceObserver (80, warn) and MetricsObserver (90, ignore). Returns
|
|
78
|
+
* `undefined` (→ observers OFF) unless ZELARI_RUNTIME_OBSERVERS is enabled,
|
|
79
|
+
* so the default hot path pays zero observer overhead.
|
|
80
|
+
*
|
|
81
|
+
* With ZELARI_RUN_RECORD=1 a Run Flight Recorder observer (priority 85) is
|
|
82
|
+
* appended: manifest/trace/agents/metrics under `<runsDir>/<runId>/`.
|
|
83
|
+
*/
|
|
84
|
+
export function buildRuntimeObserverBus(options = {}) {
|
|
85
|
+
const steering = options.steeringQueue
|
|
86
|
+
? [
|
|
87
|
+
{
|
|
88
|
+
id: 'steering-observer',
|
|
89
|
+
priority: 20,
|
|
90
|
+
failureMode: 'warn',
|
|
91
|
+
observer: new SteeringObserver(options.steeringQueue),
|
|
92
|
+
},
|
|
93
|
+
]
|
|
94
|
+
: [];
|
|
95
|
+
// Without a steering queue the env flag still gates everything (the default
|
|
96
|
+
// hot path pays zero observer overhead). With one, a bus containing only
|
|
97
|
+
// the SteeringObserver is returned even when the flag is off.
|
|
98
|
+
if (!runtimeObserversEnabled()) {
|
|
99
|
+
return steering.length > 0 ? new ObserverBus(steering) : undefined;
|
|
100
|
+
}
|
|
101
|
+
const descriptors = [
|
|
102
|
+
...steering,
|
|
103
|
+
{
|
|
104
|
+
id: 'repetition-guard',
|
|
105
|
+
priority: 30,
|
|
106
|
+
failureMode: 'warn',
|
|
107
|
+
observer: new RepetitionGuard(),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: 'failure-signature-guard',
|
|
111
|
+
priority: 30,
|
|
112
|
+
failureMode: 'warn',
|
|
113
|
+
observer: new FailureSignatureGuard(),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 'duplicate-search-guard',
|
|
117
|
+
priority: 30,
|
|
118
|
+
failureMode: 'warn',
|
|
119
|
+
observer: new DuplicateSearchGuard(),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: 'no-progress-guard',
|
|
123
|
+
priority: 30,
|
|
124
|
+
failureMode: 'warn',
|
|
125
|
+
observer: new NoProgressGuard(),
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'reasoning-watchdog',
|
|
129
|
+
priority: 30,
|
|
130
|
+
failureMode: 'warn',
|
|
131
|
+
observer: new ReasoningWatchdog(),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: 'trace-observer',
|
|
135
|
+
priority: 80,
|
|
136
|
+
failureMode: 'warn',
|
|
137
|
+
observer: new TraceObserver(),
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 'metrics-observer',
|
|
141
|
+
priority: 90,
|
|
142
|
+
failureMode: 'ignore',
|
|
143
|
+
observer: new MetricsObserver(),
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
if (runRecordEnabled()) {
|
|
147
|
+
const recorder = new RunRecorder({
|
|
148
|
+
runsDir: options.runsDir ?? join(process.cwd(), '.zelari', 'runs'),
|
|
149
|
+
runId: options.runId ?? newRunId(),
|
|
150
|
+
});
|
|
151
|
+
descriptors.push({
|
|
152
|
+
id: 'run-recorder',
|
|
153
|
+
priority: 85,
|
|
154
|
+
failureMode: 'warn',
|
|
155
|
+
observer: createRecorderObserver(recorder),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return new ObserverBus(descriptors);
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=ObserverBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|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untimeAgentRole, ToolCallEvent, ToolResultEvent, TurnEndEvent } from './types.js';
|
|
2
|
+
export interface TraceEntry {
|
|
3
|
+
hook: string;
|
|
4
|
+
eventId: string;
|
|
5
|
+
ts: number;
|
|
6
|
+
agentId: string;
|
|
7
|
+
role: RuntimeAgentRole;
|
|
8
|
+
turn: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TraceObserverOptions {
|
|
11
|
+
/** Best-effort forward of every recorded entry. */
|
|
12
|
+
sink?: (entry: TraceEntry) => void;
|
|
13
|
+
/** Ring buffer capacity (default 500). */
|
|
14
|
+
capacity?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class TraceObserver implements AgentObserver {
|
|
17
|
+
private readonly entries;
|
|
18
|
+
private readonly sink?;
|
|
19
|
+
private readonly capacity;
|
|
20
|
+
constructor(options?: TraceObserverOptions);
|
|
21
|
+
onRunStart(event: RunStartEvent): Promise<ObserverResult>;
|
|
22
|
+
onModelAttempt(event: ModelAttemptEvent): Promise<ObserverResult>;
|
|
23
|
+
onModelDelta(event: ModelDeltaEvent): Promise<ObserverResult>;
|
|
24
|
+
onModelResponse(event: ModelResponseEvent): Promise<ObserverResult>;
|
|
25
|
+
onToolCall(event: ToolCallEvent): Promise<ObserverResult>;
|
|
26
|
+
onToolResult(event: ToolResultEvent): Promise<ObserverResult>;
|
|
27
|
+
onTurnEnd(event: TurnEndEvent): Promise<ObserverResult>;
|
|
28
|
+
onRunEnd(event: RunEndEvent): Promise<ObserverResult>;
|
|
29
|
+
onCancelled(event: RunCancelledEvent): Promise<ObserverResult>;
|
|
30
|
+
/** Recorded entries, oldest first. */
|
|
31
|
+
getEntries(): TraceEntry[];
|
|
32
|
+
get size(): number;
|
|
33
|
+
clear(): void;
|
|
34
|
+
private record;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=TraceObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TraceObserver.d.ts","sourceRoot":"","sources":["../../../src/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AE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAIvD,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;IAIrD,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC;IAIpE,sCAAsC;IACtC,UAAU,IAAI,UAAU,EAAE;IAI1B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,MAAM;CAkBf"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TraceObserver — bounded in-memory trace of every runtime event it sees
|
|
3
|
+
* (Frontier upgrade, PHASE 1 observer set).
|
|
4
|
+
*
|
|
5
|
+
* Best-effort: keeps a ring buffer (default 500 entries) and forwards each
|
|
6
|
+
* entry to an optional sink (e.g. the future Run Flight Recorder writer).
|
|
7
|
+
* Sink errors are swallowed — a tracing failure must never break a run
|
|
8
|
+
* (§102: recorder failure does not block; authorization does).
|
|
9
|
+
*/
|
|
10
|
+
import { CONTINUE } from './types.js';
|
|
11
|
+
const DEFAULT_CAPACITY = 500;
|
|
12
|
+
export class TraceObserver {
|
|
13
|
+
entries = [];
|
|
14
|
+
sink;
|
|
15
|
+
capacity;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.sink = options.sink;
|
|
18
|
+
this.capacity = Math.max(1, options.capacity ?? DEFAULT_CAPACITY);
|
|
19
|
+
}
|
|
20
|
+
async onRunStart(event) {
|
|
21
|
+
return this.record('onRunStart', event);
|
|
22
|
+
}
|
|
23
|
+
async onModelAttempt(event) {
|
|
24
|
+
return this.record('onModelAttempt', event);
|
|
25
|
+
}
|
|
26
|
+
async onModelDelta(event) {
|
|
27
|
+
return this.record('onModelDelta', event);
|
|
28
|
+
}
|
|
29
|
+
async onModelResponse(event) {
|
|
30
|
+
return this.record('onModelResponse', event);
|
|
31
|
+
}
|
|
32
|
+
async onToolCall(event) {
|
|
33
|
+
return this.record('onToolCall', event);
|
|
34
|
+
}
|
|
35
|
+
async onToolResult(event) {
|
|
36
|
+
return this.record('onToolResult', event);
|
|
37
|
+
}
|
|
38
|
+
async onTurnEnd(event) {
|
|
39
|
+
return this.record('onTurnEnd', event);
|
|
40
|
+
}
|
|
41
|
+
async onRunEnd(event) {
|
|
42
|
+
return this.record('onRunEnd', event);
|
|
43
|
+
}
|
|
44
|
+
async onCancelled(event) {
|
|
45
|
+
return this.record('onCancelled', event);
|
|
46
|
+
}
|
|
47
|
+
/** Recorded entries, oldest first. */
|
|
48
|
+
getEntries() {
|
|
49
|
+
return [...this.entries];
|
|
50
|
+
}
|
|
51
|
+
get size() {
|
|
52
|
+
return this.entries.length;
|
|
53
|
+
}
|
|
54
|
+
clear() {
|
|
55
|
+
this.entries.length = 0;
|
|
56
|
+
}
|
|
57
|
+
record(hook, event) {
|
|
58
|
+
const entry = {
|
|
59
|
+
hook,
|
|
60
|
+
eventId: event.id,
|
|
61
|
+
ts: event.ts,
|
|
62
|
+
agentId: event.identity.agentId,
|
|
63
|
+
role: event.identity.role,
|
|
64
|
+
turn: event.turn,
|
|
65
|
+
};
|
|
66
|
+
this.entries.push(entry);
|
|
67
|
+
if (this.entries.length > this.capacity)
|
|
68
|
+
this.entries.shift();
|
|
69
|
+
try {
|
|
70
|
+
this.sink?.(entry);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Best-effort sink: swallow.
|
|
74
|
+
}
|
|
75
|
+
return CONTINUE;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=TraceObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TraceObserver.js","sourceRoot":"","sources":["../../../src/runtime/observers/TraceObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiCtC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B,MAA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CAAC,WAAW,CAAC,KAAwB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,sCAAsC;IACtC,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,KAAuB;QAClD,MAAM,KAAK,GAAe;YACxB,IAAI;YACJ,OAAO,EAAE,KAAK,CAAC,EAAE;YACjB,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO;YAC/B,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;YACzB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC9D,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,6BAA6B;QAC/B,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* composeObservers — collapse several observers into a single AgentObserver.
|
|
3
|
+
*
|
|
4
|
+
* Each hook fans out to every observer in order and returns the resolved
|
|
5
|
+
* intervention. This is a raw fan-out (no failure modes); use {@link ObserverBus}
|
|
6
|
+
* when throw isolation / fail-closed semantics are required.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentObserver } from './types.js';
|
|
9
|
+
export declare function composeObservers(observers: AgentObserver[]): AgentObserver;
|
|
10
|
+
//# sourceMappingURL=composeObservers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composeObservers.d.ts","sourceRoot":"","sources":["../../../src/runtime/observers/composeObservers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAC;AAkBhE,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,aAAa,CAe1E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CONTINUE } from './types.js';
|
|
2
|
+
import { resolveInterventions } from './resolve.js';
|
|
3
|
+
const HOOKS = [
|
|
4
|
+
'onRunStart',
|
|
5
|
+
'onModelAttempt',
|
|
6
|
+
'onModelDelta',
|
|
7
|
+
'onModelResponse',
|
|
8
|
+
'onToolCall',
|
|
9
|
+
'onToolResult',
|
|
10
|
+
'onTurnEnd',
|
|
11
|
+
'onRunEnd',
|
|
12
|
+
'onCancelled',
|
|
13
|
+
];
|
|
14
|
+
export function composeObservers(observers) {
|
|
15
|
+
const composed = {};
|
|
16
|
+
for (const hook of HOOKS) {
|
|
17
|
+
composed[hook] = async (event) => {
|
|
18
|
+
const results = [];
|
|
19
|
+
for (const observer of observers) {
|
|
20
|
+
const callback = observer[hook];
|
|
21
|
+
if (typeof callback === 'function') {
|
|
22
|
+
results.push((await callback(event)) ?? CONTINUE);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return resolveInterventions(results);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return composed;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=composeObservers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composeObservers.js","sourceRoot":"","sources":["../../../src/runtime/observers/composeObservers.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,KAAK,GAA4B;IACrC,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,YAAY;IACZ,cAAc;IACd,WAAW;IACX,UAAU;IACV,aAAa;CACd,CAAC;AAIF,MAAM,UAAU,gBAAgB,CAAC,SAA0B;IACzD,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACxB,QAAoC,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,KAAc,EAA2B,EAAE;YAC9F,MAAM,OAAO,GAAqB,EAAE,CAAC;YACrC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,MAAM,QAAQ,GAAI,QAAoC,CAAC,IAAI,CAAC,CAAC;gBAC7D,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;oBACnC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAO,QAAyB,CAAC,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC;gBACtE,CAAC;YACH,CAAC;YACD,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/runtime/observers/resolve.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAWjD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,cAAc,CAY9E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intervention resolution — semantic precedence when several observers answer
|
|
3
|
+
* the same event. `deny_tool` (hardest) wins over everything; `continue` is the
|
|
4
|
+
* weakest. Ties at the same action are resolved by the bus in descriptor order
|
|
5
|
+
* (lowest priority first); this function only ranks by action kind.
|
|
6
|
+
*/
|
|
7
|
+
import { CONTINUE } from './types.js';
|
|
8
|
+
const ACTION_RANK = {
|
|
9
|
+
deny_tool: 6,
|
|
10
|
+
stop: 5,
|
|
11
|
+
retry: 4,
|
|
12
|
+
replace: 3,
|
|
13
|
+
inject: 2,
|
|
14
|
+
continue: 1,
|
|
15
|
+
};
|
|
16
|
+
export function resolveInterventions(results) {
|
|
17
|
+
if (results.length === 0)
|
|
18
|
+
return CONTINUE;
|
|
19
|
+
let best = results[0];
|
|
20
|
+
let bestRank = ACTION_RANK[best.action];
|
|
21
|
+
for (let i = 1; i < results.length; i += 1) {
|
|
22
|
+
const rank = ACTION_RANK[results[i].action];
|
|
23
|
+
if (rank > bestRank) {
|
|
24
|
+
best = results[i];
|
|
25
|
+
bestRank = rank;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return best;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../src/runtime/observers/resolve.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,WAAW,GAA6C;IAC5D,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1C,IAAI,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YACpB,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAClB,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer / Intervention runtime — shared contracts (Frontier upgrade, PHASE 1).
|
|
3
|
+
*
|
|
4
|
+
* A provider-neutral, in-process complement to the external lifecycle hooks
|
|
5
|
+
* (`core/hooks`). Observers run inside the agent loop and return typed
|
|
6
|
+
* interventions without mutating global state. The runtime core stays neutral:
|
|
7
|
+
* observers are opt-in and must not throw for ordinary policy decisions.
|
|
8
|
+
*
|
|
9
|
+
* Naming note: the role type here is `RuntimeAgentRole` because `AgentRole` is
|
|
10
|
+
* already an exported council-role interface (`types/legacy.ts`).
|
|
11
|
+
*/
|
|
12
|
+
/** Which agent a runtime event belongs to. */
|
|
13
|
+
export type RuntimeAgentRole = 'lead' | 'explore' | 'general' | 'verify' | 'planner' | 'council' | 'mission';
|
|
14
|
+
export interface RuntimeIdentity {
|
|
15
|
+
runId: string;
|
|
16
|
+
agentId: string;
|
|
17
|
+
parentAgentId?: string;
|
|
18
|
+
role: RuntimeAgentRole;
|
|
19
|
+
mode: 'kraken' | 'council' | 'zelari';
|
|
20
|
+
model?: string;
|
|
21
|
+
provider?: string;
|
|
22
|
+
graphNodeId?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Fields shared by every observer event. */
|
|
25
|
+
export interface RuntimeEventBase {
|
|
26
|
+
id: string;
|
|
27
|
+
ts: number;
|
|
28
|
+
identity: RuntimeIdentity;
|
|
29
|
+
turn: number;
|
|
30
|
+
}
|
|
31
|
+
export interface RunStartEvent extends RuntimeEventBase {
|
|
32
|
+
}
|
|
33
|
+
export interface ModelAttemptEvent extends RuntimeEventBase {
|
|
34
|
+
}
|
|
35
|
+
export interface ModelDeltaEvent extends RuntimeEventBase {
|
|
36
|
+
delta: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ModelResponseEvent extends RuntimeEventBase {
|
|
39
|
+
}
|
|
40
|
+
export interface ToolCallEvent extends RuntimeEventBase {
|
|
41
|
+
toolCallId: string;
|
|
42
|
+
toolName: string;
|
|
43
|
+
args: unknown;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolResultEvent extends RuntimeEventBase {
|
|
46
|
+
toolCallId: string;
|
|
47
|
+
toolName: string;
|
|
48
|
+
result: unknown;
|
|
49
|
+
ok: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface TurnEndEvent extends RuntimeEventBase {
|
|
52
|
+
}
|
|
53
|
+
export interface RunEndEvent extends RuntimeEventBase {
|
|
54
|
+
reason: 'completed' | 'cancelled' | 'error';
|
|
55
|
+
}
|
|
56
|
+
export interface RunCancelledEvent extends RuntimeEventBase {
|
|
57
|
+
reason?: string;
|
|
58
|
+
}
|
|
59
|
+
/** A message an observer injects back into the agent conversation. */
|
|
60
|
+
export interface RuntimeInjectedMessage {
|
|
61
|
+
role: 'system' | 'user';
|
|
62
|
+
kind: string;
|
|
63
|
+
content: string;
|
|
64
|
+
}
|
|
65
|
+
/** Explicit decision an observer returns. Never mutate global state inline. */
|
|
66
|
+
export type ObserverResult = {
|
|
67
|
+
action: 'continue';
|
|
68
|
+
} | {
|
|
69
|
+
action: 'retry';
|
|
70
|
+
reason?: string;
|
|
71
|
+
consumeTurn?: boolean;
|
|
72
|
+
} | {
|
|
73
|
+
action: 'stop';
|
|
74
|
+
reason: string;
|
|
75
|
+
code?: string;
|
|
76
|
+
} | {
|
|
77
|
+
action: 'replace';
|
|
78
|
+
content: unknown;
|
|
79
|
+
} | {
|
|
80
|
+
action: 'inject';
|
|
81
|
+
message: RuntimeInjectedMessage;
|
|
82
|
+
} | {
|
|
83
|
+
action: 'deny_tool';
|
|
84
|
+
reason: string;
|
|
85
|
+
};
|
|
86
|
+
export declare const CONTINUE: ObserverResult;
|
|
87
|
+
/** Observer callbacks on the agent loop. */
|
|
88
|
+
export interface AgentObserver {
|
|
89
|
+
onRunStart?(event: RunStartEvent): ObserverResult | Promise<ObserverResult>;
|
|
90
|
+
onModelAttempt?(event: ModelAttemptEvent): ObserverResult | Promise<ObserverResult>;
|
|
91
|
+
onModelDelta?(event: ModelDeltaEvent): ObserverResult | Promise<ObserverResult>;
|
|
92
|
+
onModelResponse?(event: ModelResponseEvent): ObserverResult | Promise<ObserverResult>;
|
|
93
|
+
onToolCall?(event: ToolCallEvent): ObserverResult | Promise<ObserverResult>;
|
|
94
|
+
onToolResult?(event: ToolResultEvent): ObserverResult | Promise<ObserverResult>;
|
|
95
|
+
onTurnEnd?(event: TurnEndEvent): ObserverResult | Promise<ObserverResult>;
|
|
96
|
+
onRunEnd?(event: RunEndEvent): ObserverResult | Promise<ObserverResult>;
|
|
97
|
+
onCancelled?(event: RunCancelledEvent): ObserverResult | Promise<ObserverResult>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* How the bus treats an observer that throws.
|
|
101
|
+
* - `ignore` → swallow, continue
|
|
102
|
+
* - `warn` → log + continue
|
|
103
|
+
* - `fail-closed` → emit a stop intervention (safety-critical observers)
|
|
104
|
+
*/
|
|
105
|
+
export type ObserverFailureMode = 'ignore' | 'warn' | 'fail-closed';
|
|
106
|
+
export interface ObserverDescriptor {
|
|
107
|
+
id: string;
|
|
108
|
+
/** Lower runs first. 10 = authorization/safety, 90 = metrics. */
|
|
109
|
+
priority: number;
|
|
110
|
+
failureMode: ObserverFailureMode;
|
|
111
|
+
observer: AgentObserver;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/observers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,8CAA8C;AAC9C,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,SAAS,GACT,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,6CAA6C;AAC7C,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,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B,GAAG,QAAQ,GAAG,MAAM,GAAG,aAAa,CAAC;AAEpE,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,mBAAmB,CAAC;IACjC,QAAQ,EAAE,aAAa,CAAC;CACzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observer / Intervention runtime — shared contracts (Frontier upgrade, PHASE 1).
|
|
3
|
+
*
|
|
4
|
+
* A provider-neutral, in-process complement to the external lifecycle hooks
|
|
5
|
+
* (`core/hooks`). Observers run inside the agent loop and return typed
|
|
6
|
+
* interventions without mutating global state. The runtime core stays neutral:
|
|
7
|
+
* observers are opt-in and must not throw for ordinary policy decisions.
|
|
8
|
+
*
|
|
9
|
+
* Naming note: the role type here is `RuntimeAgentRole` because `AgentRole` is
|
|
10
|
+
* already an exported council-role interface (`types/legacy.ts`).
|
|
11
|
+
*/
|
|
12
|
+
export const CONTINUE = { action: 'continue' };
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/runtime/observers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgFH,MAAM,CAAC,MAAM,QAAQ,GAAmB,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized redaction for run-recorder payloads (Frontier PHASE 5, §99).
|
|
3
|
+
*
|
|
4
|
+
* Every writer funnels through `redactRuntimePayload()`; no individual
|
|
5
|
+
* recorder path is allowed to serialize secrets on its own. Best-effort by
|
|
6
|
+
* nature (regex-based), but the single choke point keeps patterns auditable.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REDACTED = "[REDACTED]";
|
|
9
|
+
/** Redact secret-looking substrings from free text. */
|
|
10
|
+
export declare function redactString(input: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Recursively redact a payload before it is persisted by the recorder.
|
|
13
|
+
* - secret-ish object keys → whole value replaced
|
|
14
|
+
* - strings → pattern scrub
|
|
15
|
+
* - arrays/objects → walked
|
|
16
|
+
* - primitives → passed through
|
|
17
|
+
*/
|
|
18
|
+
export declare function redactRuntimePayload(value: unknown): unknown;
|
|
19
|
+
//# sourceMappingURL=Redactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Redactor.d.ts","sourceRoot":"","sources":["../../../src/runtime/recorder/Redactor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,QAAQ,eAAe,CAAC;AAwCrC,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAc5D"}
|