@jini-ai/daemon 0.2.1 → 0.3.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 +92 -0
- package/dist/agent-executor.d.ts +714 -42
- package/dist/agent-executor.d.ts.map +1 -1
- package/dist/agent-executor.js +1416 -351
- package/dist/agent-executor.js.map +1 -1
- package/dist/continuation/index.d.ts +1 -0
- package/dist/continuation/index.d.ts.map +1 -1
- package/dist/continuation/index.js +1 -0
- package/dist/continuation/index.js.map +1 -1
- package/dist/continuation/run-scoped-context-store.d.ts +79 -0
- package/dist/continuation/run-scoped-context-store.d.ts.map +1 -0
- package/dist/continuation/run-scoped-context-store.js +56 -0
- package/dist/continuation/run-scoped-context-store.js.map +1 -0
- package/dist/continuation/run-start-handler.d.ts +39 -9
- package/dist/continuation/run-start-handler.d.ts.map +1 -1
- package/dist/continuation/run-start-handler.js +12 -2
- package/dist/continuation/run-start-handler.js.map +1 -1
- package/dist/delegated-tool-bridge.d.ts +8 -0
- package/dist/delegated-tool-bridge.d.ts.map +1 -1
- package/dist/delegated-tool-bridge.js +117 -1
- package/dist/delegated-tool-bridge.js.map +1 -1
- package/dist/event-log.d.ts +18 -105
- package/dist/event-log.d.ts.map +1 -1
- package/dist/event-log.js +0 -17
- package/dist/event-log.js.map +1 -1
- package/dist/frontend-capability-tools.d.ts +1 -1
- package/dist/frontend-capability-tools.js +1 -1
- package/dist/frontend-session-registry.d.ts.map +1 -1
- package/dist/frontend-session-registry.js +26 -10
- package/dist/frontend-session-registry.js.map +1 -1
- package/dist/image-prompt-delivery.d.ts +56 -0
- package/dist/image-prompt-delivery.d.ts.map +1 -0
- package/dist/image-prompt-delivery.js +104 -0
- package/dist/image-prompt-delivery.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/remote-tool-bridge.d.ts +45 -0
- package/dist/remote-tool-bridge.d.ts.map +1 -0
- package/dist/remote-tool-bridge.js +23 -0
- package/dist/remote-tool-bridge.js.map +1 -0
- package/dist/routines/routine-store.js +1 -1
- package/dist/routines/schedule.d.ts +0 -8
- package/dist/routines/schedule.d.ts.map +1 -1
- package/dist/routines/schedule.js +71 -44
- package/dist/routines/schedule.js.map +1 -1
- package/dist/routines/scheduler.d.ts +43 -0
- package/dist/routines/scheduler.d.ts.map +1 -1
- package/dist/routines/scheduler.js +160 -120
- package/dist/routines/scheduler.js.map +1 -1
- package/dist/run/core/retry.d.ts.map +1 -1
- package/dist/run/core/retry.js +47 -35
- package/dist/run/core/retry.js.map +1 -1
- package/dist/run/diagnostics/diagnostics.d.ts.map +1 -1
- package/dist/run/diagnostics/diagnostics.js +149 -91
- package/dist/run/diagnostics/diagnostics.js.map +1 -1
- package/dist/run-lifecycle.d.ts +84 -4
- package/dist/run-lifecycle.d.ts.map +1 -1
- package/dist/run-lifecycle.js +378 -116
- package/dist/run-lifecycle.js.map +1 -1
- package/dist/terminal-session.d.ts +1 -1
- package/dist/terminal-session.d.ts.map +1 -1
- package/dist/terminal-session.js +1 -1
- package/dist/tool-executor.d.ts +26 -6
- package/dist/tool-executor.d.ts.map +1 -1
- package/dist/tool-executor.js +220 -55
- package/dist/tool-executor.js.map +1 -1
- package/dist/tool-result-media.d.ts +79 -0
- package/dist/tool-result-media.d.ts.map +1 -0
- package/dist/tool-result-media.js +80 -0
- package/dist/tool-result-media.js.map +1 -0
- package/dist/tool-result-surfaces.d.ts +78 -0
- package/dist/tool-result-surfaces.d.ts.map +1 -0
- package/dist/tool-result-surfaces.js +92 -0
- package/dist/tool-result-surfaces.js.map +1 -0
- package/package.json +18 -9
|
@@ -100,6 +100,137 @@ export function collectStderrTailSummary(events = [], redact = identityRedactor)
|
|
|
100
100
|
export function collectStdoutTailSummary(events = [], redact = identityRedactor) {
|
|
101
101
|
return collectStreamTailSummary(events, 'stdout', readStdoutChunk, redact);
|
|
102
102
|
}
|
|
103
|
+
/** The set of `rpc_close_reason` strings a `runtime_close` diagnostic may legitimately carry. */
|
|
104
|
+
const RECOGNIZED_CLOSE_REASONS = new Set([
|
|
105
|
+
'exit_0',
|
|
106
|
+
'exit_nonzero',
|
|
107
|
+
'signal',
|
|
108
|
+
'cancel_requested',
|
|
109
|
+
'stream_error',
|
|
110
|
+
'fatal_rpc_error',
|
|
111
|
+
'empty_output',
|
|
112
|
+
'unknown',
|
|
113
|
+
]);
|
|
114
|
+
/** Coerces an event's `data` to a property bag so `data.type` probing never throws on a scalar/array payload. */
|
|
115
|
+
function eventDataRecord(data) {
|
|
116
|
+
return data && typeof data === 'object' ? data : {};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reads the authoritative close reason a driver recorded on a `runtime_close` diagnostic event,
|
|
120
|
+
* or `null` when this event carries none (or carries an unrecognized value).
|
|
121
|
+
*/
|
|
122
|
+
function readRecordedCloseReason(event, data) {
|
|
123
|
+
if (event.event !== 'diagnostic' || data.type !== 'runtime_close')
|
|
124
|
+
return null;
|
|
125
|
+
const reason = data.rpc_close_reason;
|
|
126
|
+
if (typeof reason !== 'string')
|
|
127
|
+
return null;
|
|
128
|
+
return RECOGNIZED_CLOSE_REASONS.has(reason) ? reason : null;
|
|
129
|
+
}
|
|
130
|
+
/** True when this event is a non-empty streamed text/thinking delta — i.e. output a user actually saw. */
|
|
131
|
+
function hasVisibleTextDelta(data) {
|
|
132
|
+
if (data.type !== 'text_delta' && data.type !== 'thinking_delta')
|
|
133
|
+
return false;
|
|
134
|
+
return typeof data.delta === 'string' && data.delta.length > 0;
|
|
135
|
+
}
|
|
136
|
+
/** Accumulates the raw stderr/stdout text carried by this event, if it is a stream chunk. */
|
|
137
|
+
function accumulateStreamChunk(observed, event) {
|
|
138
|
+
if (event.event === 'stderr') {
|
|
139
|
+
const chunk = readStderrChunk(event.data);
|
|
140
|
+
if (chunk)
|
|
141
|
+
observed.stderr += chunk;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (event.event === 'stdout') {
|
|
145
|
+
const chunk = readStdoutChunk(event.data);
|
|
146
|
+
if (chunk) {
|
|
147
|
+
observed.stdout += chunk;
|
|
148
|
+
observed.userVisibleOutputSeen = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Latches the observed-behavior flags (visible output, tool calls, artifacts, resume re-seed) for one event. */
|
|
153
|
+
function accumulateObservedFlags(observed, event, data) {
|
|
154
|
+
if (hasVisibleTextDelta(data))
|
|
155
|
+
observed.userVisibleOutputSeen = true;
|
|
156
|
+
if (data.type === 'tool_use')
|
|
157
|
+
observed.toolCallSeen = true;
|
|
158
|
+
if (data.type === 'artifact')
|
|
159
|
+
observed.artifactWriteSeen = true;
|
|
160
|
+
if (data.type === 'live_artifact' || event.event === 'live_artifact') {
|
|
161
|
+
observed.liveArtifactSeen = true;
|
|
162
|
+
}
|
|
163
|
+
if (event.event === 'diagnostic' && data.type === 'agent_resume_auto_reseed') {
|
|
164
|
+
observed.resumeAutoReseeded = true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Folds one event into the accumulator. */
|
|
168
|
+
function accumulateEvent(observed, event) {
|
|
169
|
+
if (event.event === 'error')
|
|
170
|
+
observed.hasErrorEvent = true;
|
|
171
|
+
accumulateStreamChunk(observed, event);
|
|
172
|
+
const data = eventDataRecord(event.data);
|
|
173
|
+
accumulateObservedFlags(observed, event, data);
|
|
174
|
+
const closeReason = readRecordedCloseReason(event, data);
|
|
175
|
+
if (closeReason)
|
|
176
|
+
observed.recordedCloseReason = closeReason;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Single pass over a run's event list collecting every diagnostic signal the analytics payload
|
|
180
|
+
* needs. Seeded with the daemon-supplied artifact flags so an event stream that never mentions an
|
|
181
|
+
* artifact still reports what finalization already knew.
|
|
182
|
+
*/
|
|
183
|
+
function scanRunEvents(events, seed) {
|
|
184
|
+
const observed = {
|
|
185
|
+
stderr: '',
|
|
186
|
+
stdout: '',
|
|
187
|
+
hasErrorEvent: false,
|
|
188
|
+
userVisibleOutputSeen: false,
|
|
189
|
+
toolCallSeen: false,
|
|
190
|
+
artifactWriteSeen: seed.artifactWriteSeen,
|
|
191
|
+
liveArtifactSeen: seed.liveArtifactSeen,
|
|
192
|
+
recordedCloseReason: null,
|
|
193
|
+
resumeAutoReseeded: false,
|
|
194
|
+
};
|
|
195
|
+
for (const event of events) {
|
|
196
|
+
accumulateEvent(observed, event);
|
|
197
|
+
}
|
|
198
|
+
return observed;
|
|
199
|
+
}
|
|
200
|
+
/** Picks the single most informative signal available about why the run ended, in priority order. */
|
|
201
|
+
function resolveDiagnosticSource(signals) {
|
|
202
|
+
if (signals.hasErrorEvent)
|
|
203
|
+
return 'error_event';
|
|
204
|
+
if (signals.stderrPresent)
|
|
205
|
+
return 'stderr';
|
|
206
|
+
if (signals.signal)
|
|
207
|
+
return 'signal';
|
|
208
|
+
if (typeof signals.exitCode === 'number')
|
|
209
|
+
return 'exit_code';
|
|
210
|
+
return 'unknown';
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Resolves the mechanism that closed the run. A reason a driver explicitly recorded always wins;
|
|
214
|
+
* otherwise the daemon's own finalization flags are consulted in priority order, falling back to
|
|
215
|
+
* the raw process exit signal/code.
|
|
216
|
+
*/
|
|
217
|
+
function resolveRpcCloseReason(recordedCloseReason, signals) {
|
|
218
|
+
if (recordedCloseReason)
|
|
219
|
+
return recordedCloseReason;
|
|
220
|
+
if (signals.cancelRequested === true)
|
|
221
|
+
return 'cancel_requested';
|
|
222
|
+
if (signals.fatalRpcErrorSeen === true)
|
|
223
|
+
return 'fatal_rpc_error';
|
|
224
|
+
if (signals.streamErrorSeen === true)
|
|
225
|
+
return 'stream_error';
|
|
226
|
+
if (signals.emptyOutputFailure === true)
|
|
227
|
+
return 'empty_output';
|
|
228
|
+
if (signals.signal)
|
|
229
|
+
return 'signal';
|
|
230
|
+
if (typeof signals.exitCode !== 'number')
|
|
231
|
+
return 'unknown';
|
|
232
|
+
return signals.exitCode === 0 ? 'exit_0' : 'exit_nonzero';
|
|
233
|
+
}
|
|
103
234
|
/**
|
|
104
235
|
* Produces the full `RunDiagnosticsAnalytics` payload for a completed run by scanning its event stream
|
|
105
236
|
* and combining observed flags (tool calls, artifact writes, first token) with process-level signals.
|
|
@@ -107,105 +238,32 @@ export function collectStdoutTailSummary(events = [], redact = identityRedactor)
|
|
|
107
238
|
* @returns A `RunDiagnosticsAnalytics` object ready to spread into the `run_finished` analytics event.
|
|
108
239
|
*/
|
|
109
240
|
export function summarizeRunDiagnosticsForAnalytics(args) {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let liveArtifactSeen = args.liveArtifactSeen === true;
|
|
117
|
-
let recordedCloseReason = null;
|
|
118
|
-
let resumeAutoReseeded = false;
|
|
119
|
-
for (const event of events) {
|
|
120
|
-
if (event.event === 'stderr') {
|
|
121
|
-
const chunk = readStderrChunk(event.data);
|
|
122
|
-
if (chunk)
|
|
123
|
-
stderr += chunk;
|
|
124
|
-
}
|
|
125
|
-
if (event.event === 'stdout') {
|
|
126
|
-
const chunk = readStdoutChunk(event.data);
|
|
127
|
-
if (chunk) {
|
|
128
|
-
stdout += chunk;
|
|
129
|
-
userVisibleOutputSeen = true;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const data = event.data && typeof event.data === 'object'
|
|
133
|
-
? event.data
|
|
134
|
-
: {};
|
|
135
|
-
if (data.type === 'text_delta' || data.type === 'thinking_delta') {
|
|
136
|
-
const delta = typeof data.delta === 'string' ? data.delta : '';
|
|
137
|
-
if (delta.length > 0)
|
|
138
|
-
userVisibleOutputSeen = true;
|
|
139
|
-
}
|
|
140
|
-
if (data.type === 'tool_use')
|
|
141
|
-
toolCallSeen = true;
|
|
142
|
-
if (event.event === 'diagnostic' && data.type === 'agent_resume_auto_reseed') {
|
|
143
|
-
resumeAutoReseeded = true;
|
|
144
|
-
}
|
|
145
|
-
if (data.type === 'artifact')
|
|
146
|
-
artifactWriteSeen = true;
|
|
147
|
-
if (data.type === 'live_artifact' || event.event === 'live_artifact') {
|
|
148
|
-
liveArtifactSeen = true;
|
|
149
|
-
}
|
|
150
|
-
if (event.event === 'diagnostic' &&
|
|
151
|
-
data.type === 'runtime_close' &&
|
|
152
|
-
typeof data.rpc_close_reason === 'string') {
|
|
153
|
-
const reason = data.rpc_close_reason;
|
|
154
|
-
if (reason === 'exit_0' ||
|
|
155
|
-
reason === 'exit_nonzero' ||
|
|
156
|
-
reason === 'signal' ||
|
|
157
|
-
reason === 'cancel_requested' ||
|
|
158
|
-
reason === 'stream_error' ||
|
|
159
|
-
reason === 'fatal_rpc_error' ||
|
|
160
|
-
reason === 'empty_output' ||
|
|
161
|
-
reason === 'unknown') {
|
|
162
|
-
recordedCloseReason = reason;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const stderrLineCount = countLines(stderr);
|
|
167
|
-
const stdoutLineCount = countLines(stdout);
|
|
168
|
-
const hasErrorEvent = events.some((event) => event.event === 'error');
|
|
241
|
+
const observed = scanRunEvents(args.events ?? [], {
|
|
242
|
+
artifactWriteSeen: args.artifactWriteSeen === true,
|
|
243
|
+
liveArtifactSeen: args.liveArtifactSeen === true,
|
|
244
|
+
});
|
|
245
|
+
const stderrLineCount = countLines(observed.stderr);
|
|
246
|
+
const stdoutLineCount = countLines(observed.stdout);
|
|
169
247
|
const stderrPresent = stderrLineCount > 0;
|
|
170
248
|
const stdoutPresent = stdoutLineCount > 0;
|
|
171
|
-
let diagnosticSource = 'unknown';
|
|
172
|
-
if (hasErrorEvent)
|
|
173
|
-
diagnosticSource = 'error_event';
|
|
174
|
-
else if (stderrPresent)
|
|
175
|
-
diagnosticSource = 'stderr';
|
|
176
|
-
else if (args.signal)
|
|
177
|
-
diagnosticSource = 'signal';
|
|
178
|
-
else if (typeof args.exitCode === 'number')
|
|
179
|
-
diagnosticSource = 'exit_code';
|
|
180
|
-
let rpcCloseReason = 'unknown';
|
|
181
|
-
if (recordedCloseReason)
|
|
182
|
-
rpcCloseReason = recordedCloseReason;
|
|
183
|
-
else if (args.cancelRequested === true)
|
|
184
|
-
rpcCloseReason = 'cancel_requested';
|
|
185
|
-
else if (args.fatalRpcErrorSeen === true)
|
|
186
|
-
rpcCloseReason = 'fatal_rpc_error';
|
|
187
|
-
else if (args.streamErrorSeen === true)
|
|
188
|
-
rpcCloseReason = 'stream_error';
|
|
189
|
-
else if (args.emptyOutputFailure === true)
|
|
190
|
-
rpcCloseReason = 'empty_output';
|
|
191
|
-
else if (args.signal)
|
|
192
|
-
rpcCloseReason = 'signal';
|
|
193
|
-
else if (typeof args.exitCode === 'number') {
|
|
194
|
-
rpcCloseReason = args.exitCode === 0 ? 'exit_0' : 'exit_nonzero';
|
|
195
|
-
}
|
|
196
249
|
return {
|
|
197
|
-
diagnostic_source:
|
|
250
|
+
diagnostic_source: resolveDiagnosticSource({
|
|
251
|
+
hasErrorEvent: observed.hasErrorEvent,
|
|
252
|
+
stderrPresent,
|
|
253
|
+
signal: args.signal,
|
|
254
|
+
exitCode: args.exitCode,
|
|
255
|
+
}),
|
|
198
256
|
stderr_present: stderrPresent,
|
|
199
257
|
stderr_line_count_bucket: stderrLineCountBucket(stderrLineCount),
|
|
200
258
|
stdout_present: stdoutPresent,
|
|
201
259
|
stdout_line_count_bucket: stderrLineCountBucket(stdoutLineCount),
|
|
202
|
-
rpc_close_reason:
|
|
260
|
+
rpc_close_reason: resolveRpcCloseReason(observed.recordedCloseReason, args),
|
|
203
261
|
first_token_seen: args.firstTokenSeen === true,
|
|
204
|
-
user_visible_output_seen: userVisibleOutputSeen,
|
|
205
|
-
tool_call_seen: toolCallSeen,
|
|
206
|
-
artifact_write_seen: artifactWriteSeen,
|
|
207
|
-
live_artifact_seen: liveArtifactSeen,
|
|
208
|
-
resume_auto_reseeded: resumeAutoReseeded,
|
|
262
|
+
user_visible_output_seen: observed.userVisibleOutputSeen,
|
|
263
|
+
tool_call_seen: observed.toolCallSeen,
|
|
264
|
+
artifact_write_seen: observed.artifactWriteSeen,
|
|
265
|
+
live_artifact_seen: observed.liveArtifactSeen,
|
|
266
|
+
resume_auto_reseeded: observed.resumeAutoReseeded,
|
|
209
267
|
};
|
|
210
268
|
}
|
|
211
269
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../../src/run/diagnostics/diagnostics.ts"],"names":[],"mappings":"AAAA,qIAAqI;AAWrI,MAAM,gBAAgB,GAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;AAmEtD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AAEvC,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,GAAG,GAAG,IAA+B,CAAC;IAC5C,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC,KAAK,CAAC;IACpD,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,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AQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,cAAc,EAAE,aAAa;QAC7B,wBAAwB,EAAE,qBAAqB,CAAC,eAAe,CAAC;QAChE,cAAc,EAAE,aAAa;QAC7B,wBAAwB,EAAE,qBAAqB,CAAC,eAAe,CAAC;QAChE,gBAAgB,EAAE,qBAAqB,CAAC,QAAQ,CAAC,mBAAmB,EAAE,IAAI,CAAC;QAC3E,gBAAgB,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI;QAC9C,wBAAwB,EAAE,QAAQ,CAAC,qBAAqB;QACxD,cAAc,EAAE,QAAQ,CAAC,YAAY;QACrC,mBAAmB,EAAE,QAAQ,CAAC,iBAAiB;QAC/C,kBAAkB,EAAE,QAAQ,CAAC,gBAAgB;QAC7C,oBAAoB,EAAE,QAAQ,CAAC,kBAAkB;KAClD,CAAC;AACJ,CAAC"}
|
package/dist/run-lifecycle.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RunAgentPayload, RunCancelRequest, RunChunkPayload, RunErrorPayload, RunProtocolEvent, RunStatus } from '@jini-ai/protocol';
|
|
2
|
-
import type { EventLog, EventLogReplayResult } from './event-log.js';
|
|
3
|
-
import type { TerminalRunOutcome } from './close-status.js';
|
|
1
|
+
import type { RunAgentPayload, RunCancelRequest, RunChunkPayload, RunErrorPayload, RunProtocolEvent, RunStartPayload, RunStatus } from '@jini-ai/protocol';
|
|
2
|
+
import type { EventLog, EventLogEntry, EventLogReplayResult } from './event-log.js';
|
|
3
|
+
import type { InactivityWatchdog, TerminalRunOutcome } from './close-status.js';
|
|
4
4
|
export interface StartRunInput {
|
|
5
5
|
/** Opaque caller-supplied identity the run belongs to — never a project/conversation id (see module doc). */
|
|
6
6
|
readonly contextRef: string;
|
|
@@ -96,10 +96,88 @@ export interface RunLifecycle {
|
|
|
96
96
|
*/
|
|
97
97
|
stream(runId: string, onEvent: (event: RunProtocolEvent) => void, options?: StreamOptions): Promise<StreamSubscribeResult>;
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* `start()`'s idempotency-replay lookup: the run id an existing `idempotencyKey` already maps to,
|
|
101
|
+
* or `undefined` when there is no key or no existing mapping (a fresh start proceeds normally).
|
|
102
|
+
* Pure.
|
|
103
|
+
*/
|
|
104
|
+
export declare function resolveIdempotentReplayRunId(idempotencyIndex: ReadonlyMap<string, string>, idempotencyKey: string | undefined): string | undefined;
|
|
105
|
+
/** Registers `runId` under `idempotencyKey` in `idempotencyIndex` — a no-op when no key was supplied. */
|
|
106
|
+
export declare function registerIdempotencyKeyIfPresent(idempotencyIndex: Map<string, string>, idempotencyKey: string | undefined, runId: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Removes `idempotencyKey`'s mapping from `idempotencyIndex`, but only when it still points at
|
|
109
|
+
* `runId` — used to roll back a failed durable `'start'` append without clobbering a different
|
|
110
|
+
* run that may have since claimed the same key (defensive; `start()`'s own locking makes that
|
|
111
|
+
* race unreachable today, but the check costs nothing and documents the invariant).
|
|
112
|
+
*/
|
|
113
|
+
export declare function clearIdempotencyIndexEntryIfMatching(idempotencyIndex: Map<string, string>, idempotencyKey: string | undefined, runId: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Default terminal-run retention window: how long a completed/failed/cancelled run's in-memory
|
|
116
|
+
* record stays readable via `get`/`list`/`stream`/`resume` before eviction. `runs.set()` never had
|
|
117
|
+
* a matching `runs.delete()` for a run that finishes normally — every terminal run's record was kept
|
|
118
|
+
* for the daemon process's entire lifetime, unbounded by run volume or uptime. Terminal runs are
|
|
119
|
+
* still read after they end (status polling, run-history listing, stream reconnects), so the fix
|
|
120
|
+
* cannot be "delete on completion" — this bounds *how long* a terminal record survives instead of
|
|
121
|
+
* deleting it immediately. 24h comfortably covers same-day polling/listing/reconnect without
|
|
122
|
+
* retaining every run a long-lived daemon ever processed.
|
|
123
|
+
*/
|
|
124
|
+
export declare const DEFAULT_TERMINAL_RETENTION_MS: number;
|
|
125
|
+
/**
|
|
126
|
+
* Default hard cap on concurrently-retained terminal run records, independent of
|
|
127
|
+
* {@link DEFAULT_TERMINAL_RETENTION_MS} — the oldest terminal record is evicted once this is
|
|
128
|
+
* exceeded. A TTL alone does not bound memory when runs complete faster than they age out (a burst
|
|
129
|
+
* arriving within the retention window keeps growing); this cap gives a true worst-case bound
|
|
130
|
+
* regardless of arrival rate.
|
|
131
|
+
*/
|
|
132
|
+
export declare const DEFAULT_MAX_TERMINAL_RUNS = 1000;
|
|
133
|
+
/**
|
|
134
|
+
* How long a just-terminal run should remain retained before its eviction timer fires: `retentionMs`
|
|
135
|
+
* minus however much of that window has already elapsed since `terminalAt`. Floored at `0` so a run
|
|
136
|
+
* that was already past its retention window when this is computed (relevant for `rehydrate()`,
|
|
137
|
+
* where a run may have gone terminal long before this process started) schedules an immediate
|
|
138
|
+
* eviction rather than a negative-delay timer. Pure.
|
|
139
|
+
*/
|
|
140
|
+
export declare function computeRetentionDelayMs(terminalAt: number, retentionMs: number, now: number): number;
|
|
141
|
+
/** The durable `'start'` entry's payload — pure field mapping, split out of `start()` so its two optional-field spreads don't count toward that method's own complexity. */
|
|
142
|
+
export declare function buildStartPayload(runId: string, startInput: Pick<StartRunInput, 'contextRef' | 'agentId' | 'idempotencyKey'>): RunStartPayload;
|
|
143
|
+
/**
|
|
144
|
+
* Arms `record.watchdog` when `timeoutMs` is configured — a no-op otherwise. `record` is typed as a
|
|
145
|
+
* plain `{watchdog}` shape (not `Pick<RunRecord, 'watchdog'>`) purely so this function can be
|
|
146
|
+
* exported without naming the private `RunRecord` type in a public signature.
|
|
147
|
+
*/
|
|
148
|
+
export declare function armWatchdogIfConfigured(record: {
|
|
149
|
+
watchdog: InactivityWatchdog | undefined;
|
|
150
|
+
}, timeoutMs: number | undefined, onTimeout: () => void): void;
|
|
151
|
+
/**
|
|
152
|
+
* `stream()`'s replay-delivery step: sends every already-durable entry to `onEvent`, returning the
|
|
153
|
+
* delivered eventIds so a caller can avoid re-delivering the same event from a different source
|
|
154
|
+
* (buffered live events observed during the replay, a terminal catch-up event). Pure aside from
|
|
155
|
+
* calling the injected `onEvent`.
|
|
156
|
+
*/
|
|
157
|
+
export declare function deliverReplayedEvents(runId: string, entries: readonly EventLogEntry[], onEvent: (event: RunProtocolEvent) => void): Set<string>;
|
|
158
|
+
/**
|
|
159
|
+
* Delivers every event in `events` not already present in `deliveredEventIds`, marking each as
|
|
160
|
+
* delivered as it goes. Reused in `stream()` for both the buffered-live-event catch-up and the
|
|
161
|
+
* single terminal-event catch-up, so the "don't double-deliver" bookkeeping lives in one place.
|
|
162
|
+
*/
|
|
163
|
+
export declare function deliverUndeliveredEvents(events: readonly RunProtocolEvent[], deliveredEventIds: Set<string>, onEvent: (event: RunProtocolEvent) => void): void;
|
|
164
|
+
/**
|
|
165
|
+
* Closes out a `stream()` subscription once replay and catch-up delivery are done: a terminal run's
|
|
166
|
+
* subscriber is removed immediately (no further event will ever come), a still-live run's stays
|
|
167
|
+
* registered behind the returned `unsubscribe`. `record` is typed as a plain `{subscribers}` shape
|
|
168
|
+
* for the same exportability reason as {@link armWatchdogIfConfigured}.
|
|
169
|
+
*/
|
|
170
|
+
export declare function finishStreamSubscription(record: {
|
|
171
|
+
subscribers: Set<(event: RunProtocolEvent) => void>;
|
|
172
|
+
}, subscriber: (event: RunProtocolEvent) => void, terminal: boolean): StreamSubscribeResult;
|
|
99
173
|
export interface CreateRunLifecycleInput {
|
|
100
174
|
readonly eventLog: EventLog;
|
|
101
175
|
/** Host-owned sink for asynchronous lifecycle failures that cannot be returned to a caller. Defaults to `console.error`. */
|
|
102
176
|
readonly onInternalError?: (context: RunLifecycleInternalErrorContext) => void;
|
|
177
|
+
/** How long a terminal run's in-memory record is retained before eviction. See {@link DEFAULT_TERMINAL_RETENTION_MS}. Defaults to that constant. */
|
|
178
|
+
readonly terminalRetentionMs?: number;
|
|
179
|
+
/** Hard cap on concurrently-retained terminal run records. See {@link DEFAULT_MAX_TERMINAL_RUNS}. Defaults to that constant. */
|
|
180
|
+
readonly maxTerminalRuns?: number;
|
|
103
181
|
}
|
|
104
182
|
export interface RunLifecycleInternalErrorContext {
|
|
105
183
|
readonly source: 'inactivity-timeout';
|
|
@@ -110,8 +188,10 @@ export interface RunLifecycleInternalErrorContext {
|
|
|
110
188
|
* Creates the in-process `RunLifecycle` reference implementation.
|
|
111
189
|
*
|
|
112
190
|
* @param input.eventLog - The durable `EventLog` port this lifecycle appends to and replays from.
|
|
191
|
+
* @param input.terminalRetentionMs - See {@link CreateRunLifecycleInput.terminalRetentionMs}.
|
|
192
|
+
* @param input.maxTerminalRuns - See {@link CreateRunLifecycleInput.maxTerminalRuns}.
|
|
113
193
|
* @returns A `RunLifecycle` backed by an in-memory run registry plus the injected `EventLog`.
|
|
114
|
-
* @complexity Per-call complexities documented on each method; the registry itself is a `Map` keyed by `runId` (O(1) lookup).
|
|
194
|
+
* @complexity Per-call complexities documented on each method; the registry itself is a `Map` keyed by `runId` (O(1) lookup). Memory is bounded: non-terminal runs are O(n) in concurrently-live runs, and terminal runs are capped at `maxTerminalRuns` (each additionally bounded in retention time by `terminalRetentionMs`) rather than growing for the life of the process.
|
|
115
195
|
* @overallScore 100/100
|
|
116
196
|
*/
|
|
117
197
|
export declare function createRunLifecycle(input: CreateRunLifecycleInput): RunLifecycle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-lifecycle.d.ts","sourceRoot":"","sources":["../src/run-lifecycle.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EAEf,eAAe,EACf,gBAAgB,
|
|
1
|
+
{"version":3,"file":"run-lifecycle.d.ts","sourceRoot":"","sources":["../src/run-lifecycle.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EAEf,eAAe,EACf,gBAAgB,EAChB,eAAe,EAEf,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,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