nexus-ai-pro 2.0.0 → 2.2.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/API_STABILITY.md +65 -0
- package/CHANGELOG.md +267 -1
- package/MIGRATING.md +1 -1
- package/README.md +17 -8
- package/dist/agent/create-agent.d.ts +9 -1
- package/dist/agent/create-agent.js +40 -1
- package/dist/cache/memory-cache.d.ts +8 -0
- package/dist/cache/memory-cache.js +9 -0
- package/dist/cache/semantic-cache.d.ts +6 -3
- package/dist/cache/semantic-cache.js +5 -2
- package/dist/cli/args.js +3 -0
- package/dist/cli/db.d.ts +16 -4
- package/dist/cli/db.js +169 -22
- package/dist/cli/doctor.d.ts +17 -0
- package/dist/cli/doctor.js +53 -0
- package/dist/cli/graph.d.ts +9 -0
- package/dist/cli/graph.js +47 -0
- package/dist/cli.js +21 -2
- package/dist/core/lifecycle.js +11 -6
- package/dist/core/nexus.d.ts +12 -2
- package/dist/core/nexus.js +106 -23
- package/dist/doctor/index.d.ts +90 -0
- package/dist/doctor/index.js +237 -0
- package/dist/evals/judge.d.ts +11 -0
- package/dist/evals/judge.js +33 -0
- package/dist/evaluate/index.d.ts +1 -0
- package/dist/evaluate/index.js +1 -0
- package/dist/evaluate/provenance.d.ts +22 -0
- package/dist/evaluate/provenance.js +10 -0
- package/dist/evaluate/run.js +20 -4
- package/dist/graph/durability.d.ts +27 -0
- package/dist/graph/durability.js +66 -0
- package/dist/graph/errors.d.ts +30 -4
- package/dist/graph/errors.js +18 -2
- package/dist/graph/event-stream.d.ts +75 -0
- package/dist/graph/event-stream.js +289 -0
- package/dist/graph/functional.d.ts +80 -7
- package/dist/graph/functional.js +138 -35
- package/dist/graph/graph.d.ts +56 -8
- package/dist/graph/graph.js +331 -49
- package/dist/graph/index.d.ts +4 -2
- package/dist/graph/index.js +3 -1
- package/dist/graph/lint.d.ts +57 -0
- package/dist/graph/lint.js +141 -0
- package/dist/graph/run-control.d.ts +28 -0
- package/dist/graph/run-control.js +26 -0
- package/dist/images/evals.js +4 -2
- package/dist/operations/adapters.d.ts +52 -4
- package/dist/operations/adapters.js +194 -7
- package/dist/operations/runner.js +14 -15
- package/dist/operations/stats.js +8 -1
- package/dist/operations/store.d.ts +5 -1
- package/dist/operations/store.js +7 -0
- package/dist/ops/circuit-breaker.d.ts +52 -0
- package/dist/ops/circuit-breaker.js +4 -0
- package/dist/ops/circuit-store.d.ts +13 -2
- package/dist/ops/circuit-store.js +68 -0
- package/dist/ops/circuit-sync.d.ts +17 -0
- package/dist/ops/circuit-sync.js +86 -0
- package/dist/ops/health.d.ts +24 -0
- package/dist/ops/health.js +38 -10
- package/dist/ops/index.d.ts +1 -1
- package/dist/ops/index.js +1 -1
- package/dist/ops/rate-limit-adapters.d.ts +23 -0
- package/dist/ops/rate-limit-adapters.js +34 -0
- package/dist/ops/rate-limiter.d.ts +14 -2
- package/dist/ops/rate-limiter.js +31 -0
- package/dist/postgres/circuits.d.ts +21 -4
- package/dist/postgres/circuits.js +65 -4
- package/dist/postgres/client.d.ts +0 -2
- package/dist/postgres/client.js +0 -4
- package/dist/postgres/evaluate.d.ts +16 -4
- package/dist/postgres/evaluate.js +17 -5
- package/dist/postgres/index.d.ts +32 -11
- package/dist/postgres/index.js +65 -31
- package/dist/postgres/migrations.d.ts +60 -0
- package/dist/postgres/migrations.js +121 -0
- package/dist/postgres/operations.d.ts +14 -3
- package/dist/postgres/operations.js +45 -15
- package/dist/postgres/prompts.d.ts +11 -2
- package/dist/postgres/prompts.js +14 -3
- package/dist/postgres/rollups.d.ts +35 -0
- package/dist/postgres/rollups.js +129 -0
- package/dist/postgres/store.d.ts +11 -2
- package/dist/postgres/store.js +14 -3
- package/dist/postgres/traces.d.ts +13 -3
- package/dist/postgres/traces.js +25 -3
- package/dist/postgres/vectors.d.ts +11 -2
- package/dist/postgres/vectors.js +14 -3
- package/dist/router/auto-router.d.ts +34 -7
- package/dist/router/auto-router.js +201 -68
- package/dist/server/assistant.d.ts +44 -0
- package/dist/server/assistant.js +39 -0
- package/dist/server/errors.d.ts +12 -0
- package/dist/server/errors.js +7 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/runs.d.ts +28 -1
- package/dist/server/runs.js +110 -14
- package/dist/sqlite/index.d.ts +16 -3
- package/dist/sqlite/index.js +16 -3
- package/dist/sqlite/migrations.d.ts +26 -0
- package/dist/sqlite/migrations.js +63 -0
- package/dist/sqlite/operations.d.ts +14 -3
- package/dist/sqlite/operations.js +42 -15
- package/dist/sqlite/store.d.ts +9 -2
- package/dist/sqlite/store.js +13 -3
- package/dist/sqlite/vectors.d.ts +11 -2
- package/dist/sqlite/vectors.js +13 -2
- package/dist/store/tenant.d.ts +12 -0
- package/dist/store/tenant.js +29 -0
- package/dist/tenancy/index.d.ts +113 -0
- package/dist/tenancy/index.js +233 -0
- package/dist/testing/record.d.ts +42 -0
- package/dist/testing/record.js +57 -5
- package/dist/tracing/index.d.ts +3 -3
- package/dist/tracing/index.js +2 -2
- package/dist/tracing/instrument.js +30 -0
- package/dist/tracing/otlp.d.ts +91 -0
- package/dist/tracing/otlp.js +124 -0
- package/dist/tracing/rollups.d.ts +100 -0
- package/dist/tracing/rollups.js +139 -0
- package/dist/tracing/stores.d.ts +17 -0
- package/dist/tracing/stores.js +23 -0
- package/dist/tracing/tracer.d.ts +50 -4
- package/dist/tracing/tracer.js +85 -6
- package/dist/types/config.d.ts +33 -2
- package/dist/types/evaluate.d.ts +37 -0
- package/dist/types/graph.d.ts +354 -9
- package/dist/types/graph.js +3 -1
- package/dist/types/messages.d.ts +5 -0
- package/dist/types/operations.d.ts +22 -2
- package/dist/types/response.d.ts +20 -0
- package/dist/types/server.d.ts +18 -0
- package/dist/types/tracing.d.ts +11 -0
- package/dist/utils/schema-migrations.d.ts +97 -0
- package/dist/utils/schema-migrations.js +91 -0
- package/dist/utils/signals.d.ts +17 -0
- package/dist/utils/signals.js +26 -0
- package/dist/utils/tenant.d.ts +14 -0
- package/dist/utils/tenant.js +16 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +1 -0
- package/dist-cjs/agent/create-agent.d.ts +9 -1
- package/dist-cjs/agent/create-agent.js +40 -1
- package/dist-cjs/cache/memory-cache.d.ts +8 -0
- package/dist-cjs/cache/memory-cache.js +9 -0
- package/dist-cjs/cache/semantic-cache.d.ts +6 -3
- package/dist-cjs/cache/semantic-cache.js +5 -2
- package/dist-cjs/cli/args.js +3 -0
- package/dist-cjs/cli/db.d.ts +16 -4
- package/dist-cjs/cli/db.js +200 -20
- package/dist-cjs/cli/doctor.d.ts +17 -0
- package/dist-cjs/cli/doctor.js +56 -0
- package/dist-cjs/cli/graph.d.ts +9 -0
- package/dist-cjs/cli/graph.js +50 -0
- package/dist-cjs/core/lifecycle.js +11 -6
- package/dist-cjs/core/nexus.d.ts +12 -2
- package/dist-cjs/core/nexus.js +106 -23
- package/dist-cjs/doctor/index.d.ts +90 -0
- package/dist-cjs/doctor/index.js +276 -0
- package/dist-cjs/evals/judge.d.ts +11 -0
- package/dist-cjs/evals/judge.js +33 -0
- package/dist-cjs/evaluate/index.d.ts +1 -0
- package/dist-cjs/evaluate/index.js +3 -1
- package/dist-cjs/evaluate/provenance.d.ts +22 -0
- package/dist-cjs/evaluate/provenance.js +14 -0
- package/dist-cjs/evaluate/run.js +20 -4
- package/dist-cjs/graph/durability.d.ts +27 -0
- package/dist-cjs/graph/durability.js +70 -0
- package/dist-cjs/graph/errors.d.ts +30 -4
- package/dist-cjs/graph/errors.js +20 -3
- package/dist-cjs/graph/event-stream.d.ts +75 -0
- package/dist-cjs/graph/event-stream.js +295 -0
- package/dist-cjs/graph/functional.d.ts +80 -7
- package/dist-cjs/graph/functional.js +137 -34
- package/dist-cjs/graph/graph.d.ts +56 -8
- package/dist-cjs/graph/graph.js +330 -48
- package/dist-cjs/graph/index.d.ts +4 -2
- package/dist-cjs/graph/index.js +7 -1
- package/dist-cjs/graph/lint.d.ts +57 -0
- package/dist-cjs/graph/lint.js +144 -0
- package/dist-cjs/graph/run-control.d.ts +28 -0
- package/dist-cjs/graph/run-control.js +30 -0
- package/dist-cjs/images/evals.js +4 -2
- package/dist-cjs/operations/adapters.d.ts +52 -4
- package/dist-cjs/operations/adapters.js +193 -6
- package/dist-cjs/operations/runner.js +14 -15
- package/dist-cjs/operations/stats.js +8 -1
- package/dist-cjs/operations/store.d.ts +5 -1
- package/dist-cjs/operations/store.js +7 -0
- package/dist-cjs/ops/circuit-breaker.d.ts +52 -0
- package/dist-cjs/ops/circuit-breaker.js +4 -0
- package/dist-cjs/ops/circuit-store.d.ts +13 -2
- package/dist-cjs/ops/circuit-store.js +68 -0
- package/dist-cjs/ops/circuit-sync.d.ts +17 -0
- package/dist-cjs/ops/circuit-sync.js +87 -0
- package/dist-cjs/ops/health.d.ts +24 -0
- package/dist-cjs/ops/health.js +38 -10
- package/dist-cjs/ops/index.d.ts +1 -1
- package/dist-cjs/ops/rate-limit-adapters.d.ts +23 -0
- package/dist-cjs/ops/rate-limit-adapters.js +35 -1
- package/dist-cjs/ops/rate-limiter.d.ts +14 -2
- package/dist-cjs/ops/rate-limiter.js +32 -0
- package/dist-cjs/postgres/circuits.d.ts +21 -4
- package/dist-cjs/postgres/circuits.js +98 -3
- package/dist-cjs/postgres/client.d.ts +0 -2
- package/dist-cjs/postgres/client.js +0 -5
- package/dist-cjs/postgres/evaluate.d.ts +16 -4
- package/dist-cjs/postgres/evaluate.js +50 -4
- package/dist-cjs/postgres/index.d.ts +32 -11
- package/dist-cjs/postgres/index.js +69 -20
- package/dist-cjs/postgres/migrations.d.ts +60 -0
- package/dist-cjs/postgres/migrations.js +129 -0
- package/dist-cjs/postgres/operations.d.ts +14 -3
- package/dist-cjs/postgres/operations.js +78 -14
- package/dist-cjs/postgres/prompts.d.ts +11 -2
- package/dist-cjs/postgres/prompts.js +47 -2
- package/dist-cjs/postgres/rollups.d.ts +35 -0
- package/dist-cjs/postgres/rollups.js +168 -0
- package/dist-cjs/postgres/store.d.ts +11 -2
- package/dist-cjs/postgres/store.js +47 -2
- package/dist-cjs/postgres/traces.d.ts +13 -3
- package/dist-cjs/postgres/traces.js +58 -2
- package/dist-cjs/postgres/vectors.d.ts +11 -2
- package/dist-cjs/postgres/vectors.js +47 -2
- package/dist-cjs/router/auto-router.d.ts +34 -7
- package/dist-cjs/router/auto-router.js +201 -68
- package/dist-cjs/server/assistant.d.ts +44 -0
- package/dist-cjs/server/assistant.js +39 -0
- package/dist-cjs/server/errors.d.ts +12 -0
- package/dist-cjs/server/errors.js +9 -1
- package/dist-cjs/server/index.d.ts +1 -1
- package/dist-cjs/server/index.js +2 -1
- package/dist-cjs/server/runs.d.ts +28 -1
- package/dist-cjs/server/runs.js +109 -13
- package/dist-cjs/sqlite/index.d.ts +16 -3
- package/dist-cjs/sqlite/index.js +31 -10
- package/dist-cjs/sqlite/migrations.d.ts +26 -0
- package/dist-cjs/sqlite/migrations.js +71 -0
- package/dist-cjs/sqlite/operations.d.ts +14 -3
- package/dist-cjs/sqlite/operations.js +76 -15
- package/dist-cjs/sqlite/store.d.ts +9 -2
- package/dist-cjs/sqlite/store.js +47 -3
- package/dist-cjs/sqlite/vectors.d.ts +11 -2
- package/dist-cjs/sqlite/vectors.js +47 -2
- package/dist-cjs/store/tenant.d.ts +12 -0
- package/dist-cjs/store/tenant.js +33 -0
- package/dist-cjs/tenancy/index.d.ts +113 -0
- package/dist-cjs/tenancy/index.js +250 -0
- package/dist-cjs/testing/record.d.ts +42 -0
- package/dist-cjs/testing/record.js +57 -5
- package/dist-cjs/tracing/index.d.ts +3 -3
- package/dist-cjs/tracing/index.js +4 -1
- package/dist-cjs/tracing/instrument.js +30 -0
- package/dist-cjs/tracing/otlp.d.ts +91 -0
- package/dist-cjs/tracing/otlp.js +129 -0
- package/dist-cjs/tracing/rollups.d.ts +100 -0
- package/dist-cjs/tracing/rollups.js +147 -0
- package/dist-cjs/tracing/stores.d.ts +17 -0
- package/dist-cjs/tracing/stores.js +24 -0
- package/dist-cjs/tracing/tracer.d.ts +50 -4
- package/dist-cjs/tracing/tracer.js +87 -6
- package/dist-cjs/types/config.d.ts +33 -2
- package/dist-cjs/types/evaluate.d.ts +37 -0
- package/dist-cjs/types/graph.d.ts +354 -9
- package/dist-cjs/types/graph.js +3 -1
- package/dist-cjs/types/messages.d.ts +5 -0
- package/dist-cjs/types/operations.d.ts +22 -2
- package/dist-cjs/types/response.d.ts +20 -0
- package/dist-cjs/types/server.d.ts +18 -0
- package/dist-cjs/types/tracing.d.ts +11 -0
- package/dist-cjs/utils/schema-migrations.d.ts +97 -0
- package/dist-cjs/utils/schema-migrations.js +102 -0
- package/dist-cjs/utils/signals.d.ts +17 -0
- package/dist-cjs/utils/signals.js +29 -0
- package/dist-cjs/utils/tenant.d.ts +14 -0
- package/dist-cjs/utils/tenant.js +22 -0
- package/dist-cjs/version.d.ts +5 -0
- package/dist-cjs/version.js +4 -0
- package/llms.txt +4 -3
- package/package.json +110 -2
|
@@ -98,7 +98,8 @@ export declare class GraphNotInterruptedError extends GraphError {
|
|
|
98
98
|
status: string);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* Raised when a node outlives its
|
|
101
|
+
* Raised when a node outlives its run limit, or goes longer than its idle limit without showing
|
|
102
|
+
* progress.
|
|
102
103
|
*
|
|
103
104
|
* Separate from an ordinary failure because it is usually worth retrying, and because the node's
|
|
104
105
|
* signal was aborted underneath it rather than the node choosing to stop.
|
|
@@ -106,13 +107,38 @@ export declare class GraphNotInterruptedError extends GraphError {
|
|
|
106
107
|
export declare class GraphNodeTimeoutError extends GraphError {
|
|
107
108
|
/** The node. */
|
|
108
109
|
readonly node: string;
|
|
109
|
-
/** The
|
|
110
|
+
/** The limit it exceeded, in milliseconds. */
|
|
110
111
|
readonly timeoutMs: number;
|
|
112
|
+
/** `run` for the whole-attempt limit, `idle` for the limit between signs of progress. */
|
|
113
|
+
readonly kind: 'run' | 'idle';
|
|
111
114
|
constructor(
|
|
112
115
|
/** The node. */
|
|
113
116
|
node: string,
|
|
114
|
-
/** The
|
|
115
|
-
timeoutMs: number
|
|
117
|
+
/** The limit it exceeded, in milliseconds. */
|
|
118
|
+
timeoutMs: number,
|
|
119
|
+
/** `run` for the whole-attempt limit, `idle` for the limit between signs of progress. */
|
|
120
|
+
kind?: 'run' | 'idle');
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Raised when a run stops because its `RunControl` was drained.
|
|
124
|
+
*
|
|
125
|
+
* Not a failure: the superstep in flight finished and its checkpoint was written, so the thread is
|
|
126
|
+
* intact. Call `continue(threadId)` to resume it, on this worker or another.
|
|
127
|
+
*/
|
|
128
|
+
export declare class GraphDrainedError extends GraphError {
|
|
129
|
+
/** The thread to continue. */
|
|
130
|
+
readonly threadId: string;
|
|
131
|
+
/** Supersteps completed before the drain. */
|
|
132
|
+
readonly step: number;
|
|
133
|
+
/** Why the drain was requested. */
|
|
134
|
+
readonly reason?: string | undefined;
|
|
135
|
+
constructor(
|
|
136
|
+
/** The thread to continue. */
|
|
137
|
+
threadId: string,
|
|
138
|
+
/** Supersteps completed before the drain. */
|
|
139
|
+
step: number,
|
|
140
|
+
/** Why the drain was requested. */
|
|
141
|
+
reason?: string | undefined);
|
|
116
142
|
}
|
|
117
143
|
/**
|
|
118
144
|
* Stable key for one interrupt, so a replayed node picks up the answer it was given.
|
package/dist-cjs/graph/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GraphNodeTimeoutError = exports.GraphNotInterruptedError = exports.GraphThreadNotFoundError = exports.GraphNodeError = exports.GraphStepLimitError = exports.GraphInterrupt = exports.GraphValidationError = exports.GraphError = void 0;
|
|
3
|
+
exports.GraphDrainedError = exports.GraphNodeTimeoutError = exports.GraphNotInterruptedError = exports.GraphThreadNotFoundError = exports.GraphNodeError = exports.GraphStepLimitError = exports.GraphInterrupt = exports.GraphValidationError = exports.GraphError = void 0;
|
|
4
4
|
exports.interruptKey = interruptKey;
|
|
5
5
|
class GraphError extends Error {
|
|
6
6
|
code;
|
|
@@ -82,14 +82,31 @@ exports.GraphNotInterruptedError = GraphNotInterruptedError;
|
|
|
82
82
|
class GraphNodeTimeoutError extends GraphError {
|
|
83
83
|
node;
|
|
84
84
|
timeoutMs;
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
kind;
|
|
86
|
+
constructor(node, timeoutMs, kind = 'run') {
|
|
87
|
+
super(kind === 'idle'
|
|
88
|
+
? `Graph node "${node}" showed no progress for ${timeoutMs}ms, its idle timeout`
|
|
89
|
+
: `Graph node "${node}" exceeded its ${timeoutMs}ms timeout`, 'GRAPH_NODE_TIMEOUT');
|
|
87
90
|
this.node = node;
|
|
88
91
|
this.timeoutMs = timeoutMs;
|
|
92
|
+
this.kind = kind;
|
|
89
93
|
this.name = 'GraphNodeTimeoutError';
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
exports.GraphNodeTimeoutError = GraphNodeTimeoutError;
|
|
97
|
+
class GraphDrainedError extends GraphError {
|
|
98
|
+
threadId;
|
|
99
|
+
step;
|
|
100
|
+
reason;
|
|
101
|
+
constructor(threadId, step, reason) {
|
|
102
|
+
super(`Graph run on thread "${threadId}" drained after step ${step}${reason ? ` (${reason})` : ''}; continue() resumes it`, 'GRAPH_DRAINED');
|
|
103
|
+
this.threadId = threadId;
|
|
104
|
+
this.step = step;
|
|
105
|
+
this.reason = reason;
|
|
106
|
+
this.name = 'GraphDrainedError';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.GraphDrainedError = GraphDrainedError;
|
|
93
110
|
function interruptKey(pending) {
|
|
94
111
|
return `${pending.taskId ?? pending.node}:${pending.step}:${pending.index}`;
|
|
95
112
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ChannelSchema, GraphEvent, GraphResult, GraphStepEvent, GraphStreamEvent, GraphStreamOverflow, GraphStreamProjection, GraphStreamStats } from '../types/graph.js';
|
|
2
|
+
import { GraphError } from './errors.js';
|
|
3
|
+
/** Raised by an event stream whose reader fell behind with `overflow: 'error'`. The run is stopped. */
|
|
4
|
+
export declare class GraphStreamOverflowError extends GraphError {
|
|
5
|
+
/** The buffer that filled. */
|
|
6
|
+
readonly maxBuffered: number;
|
|
7
|
+
constructor(
|
|
8
|
+
/** The buffer that filled. */
|
|
9
|
+
maxBuffered: number);
|
|
10
|
+
}
|
|
11
|
+
/** What starts the run behind a stream: given the event listener and a signal, the step events. */
|
|
12
|
+
export type GraphRunStarter<S extends ChannelSchema> = (onEvent: (event: GraphEvent) => void, signal: AbortSignal) => AsyncIterable<GraphStepEvent<S>>;
|
|
13
|
+
interface StreamSettings {
|
|
14
|
+
include: GraphStreamProjection[];
|
|
15
|
+
subgraphs: boolean;
|
|
16
|
+
maxBuffered: number;
|
|
17
|
+
overflow: GraphStreamOverflow;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A graph run as one stream of typed events, with each projection readable on its own.
|
|
21
|
+
*
|
|
22
|
+
* Iterate the stream for every included event, or take `messages()`, `tools()`, `values()`, or
|
|
23
|
+
* `updates()` for one kind. Every reader gets its own bounded buffer. The run starts when the first
|
|
24
|
+
* reader asks for an event, so create every reader before reading any. It stops when every reader
|
|
25
|
+
* has stopped.
|
|
26
|
+
*/
|
|
27
|
+
export declare class GraphEventStream<S extends ChannelSchema, O extends keyof S = keyof S> implements AsyncIterable<GraphStreamEvent<S>> {
|
|
28
|
+
private readonly start;
|
|
29
|
+
private readonly toResult;
|
|
30
|
+
private readonly settings;
|
|
31
|
+
private readonly readers;
|
|
32
|
+
private readonly controller;
|
|
33
|
+
private started;
|
|
34
|
+
private readonly stats;
|
|
35
|
+
private resolveResult;
|
|
36
|
+
private rejectResult;
|
|
37
|
+
/** Resolves with the run's result once it ends, or rejects with its error. */
|
|
38
|
+
readonly result: Promise<GraphResult<S, O>>;
|
|
39
|
+
constructor(start: GraphRunStarter<S>, toResult: (last: GraphStepEvent<S> | undefined) => GraphResult<S, O>, settings: StreamSettings);
|
|
40
|
+
/** Every included event. */
|
|
41
|
+
[Symbol.asyncIterator](): AsyncIterator<GraphStreamEvent<S>>;
|
|
42
|
+
/** Model output, as nodes stream it. */
|
|
43
|
+
messages(): AsyncIterable<Extract<GraphStreamEvent<S>, {
|
|
44
|
+
type: 'messages';
|
|
45
|
+
}>>;
|
|
46
|
+
/** Tool calls: each starting, progressing, and returning or failing. */
|
|
47
|
+
tools(): AsyncIterable<Extract<GraphStreamEvent<S>, {
|
|
48
|
+
type: 'tools';
|
|
49
|
+
}>>;
|
|
50
|
+
/** The state after each superstep. */
|
|
51
|
+
values(): AsyncIterable<Extract<GraphStreamEvent<S>, {
|
|
52
|
+
type: 'values';
|
|
53
|
+
}>>;
|
|
54
|
+
/** Each task's write. */
|
|
55
|
+
updates(): AsyncIterable<Extract<GraphStreamEvent<S>, {
|
|
56
|
+
type: 'updates';
|
|
57
|
+
}>>;
|
|
58
|
+
/** How the stream kept up with its slowest reader so far. */
|
|
59
|
+
streamStats(): GraphStreamStats;
|
|
60
|
+
/** A reader for one projection, registered now so it sees the run from its first event. */
|
|
61
|
+
private only;
|
|
62
|
+
private reader;
|
|
63
|
+
private begin;
|
|
64
|
+
private publish;
|
|
65
|
+
private fail;
|
|
66
|
+
private pump;
|
|
67
|
+
}
|
|
68
|
+
/** Builds a stream's settings from its options. */
|
|
69
|
+
export declare function streamSettings(options: {
|
|
70
|
+
include?: GraphStreamProjection[];
|
|
71
|
+
subgraphs?: boolean;
|
|
72
|
+
maxBuffered?: number;
|
|
73
|
+
overflow?: GraphStreamOverflow;
|
|
74
|
+
}): StreamSettings;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphEventStream = exports.GraphStreamOverflowError = void 0;
|
|
4
|
+
exports.streamSettings = streamSettings;
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const DEFAULT_INCLUDE = ['values', 'updates', 'messages', 'tools', 'custom'];
|
|
7
|
+
const DEFAULT_MAX_BUFFERED = 1_000;
|
|
8
|
+
class GraphStreamOverflowError extends errors_js_1.GraphError {
|
|
9
|
+
maxBuffered;
|
|
10
|
+
constructor(maxBuffered) {
|
|
11
|
+
super(`A graph event reader fell more than ${maxBuffered} events behind`, 'GRAPH_STREAM_OVERFLOW');
|
|
12
|
+
this.maxBuffered = maxBuffered;
|
|
13
|
+
this.name = 'GraphStreamOverflowError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.GraphStreamOverflowError = GraphStreamOverflowError;
|
|
17
|
+
class Reader {
|
|
18
|
+
accepts;
|
|
19
|
+
settings;
|
|
20
|
+
stats;
|
|
21
|
+
onOverflow;
|
|
22
|
+
queue = [];
|
|
23
|
+
waiting;
|
|
24
|
+
failure;
|
|
25
|
+
drained = [];
|
|
26
|
+
ended = false;
|
|
27
|
+
error;
|
|
28
|
+
closed = false;
|
|
29
|
+
constructor(accepts, settings, stats, onOverflow) {
|
|
30
|
+
this.accepts = accepts;
|
|
31
|
+
this.settings = settings;
|
|
32
|
+
this.stats = stats;
|
|
33
|
+
this.onOverflow = onOverflow;
|
|
34
|
+
}
|
|
35
|
+
push(event) {
|
|
36
|
+
if (this.closed || !this.accepts(event))
|
|
37
|
+
return;
|
|
38
|
+
if (this.waiting) {
|
|
39
|
+
const resolve = this.waiting;
|
|
40
|
+
this.waiting = undefined;
|
|
41
|
+
this.failure = undefined;
|
|
42
|
+
resolve({ value: event, done: false });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (this.queue.length >= this.settings.maxBuffered && !this.makeRoom(event))
|
|
46
|
+
return;
|
|
47
|
+
this.queue.push(event);
|
|
48
|
+
this.stats.peak = Math.max(this.stats.peak, this.queue.length);
|
|
49
|
+
}
|
|
50
|
+
makeRoom(event) {
|
|
51
|
+
switch (this.settings.overflow) {
|
|
52
|
+
case 'drop-newest':
|
|
53
|
+
this.stats.dropped += 1;
|
|
54
|
+
return false;
|
|
55
|
+
case 'drop-oldest':
|
|
56
|
+
this.queue.shift();
|
|
57
|
+
this.stats.dropped += 1;
|
|
58
|
+
return true;
|
|
59
|
+
case 'error':
|
|
60
|
+
this.onOverflow(new GraphStreamOverflowError(this.settings.maxBuffered));
|
|
61
|
+
return false;
|
|
62
|
+
default: {
|
|
63
|
+
if (this.coalesce(event)) {
|
|
64
|
+
this.stats.coalesced += 1;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
this.queue.shift();
|
|
68
|
+
this.stats.dropped += 1;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
coalesce(event) {
|
|
74
|
+
for (let index = this.queue.length - 1; index >= 0; index -= 1) {
|
|
75
|
+
const queued = this.queue[index];
|
|
76
|
+
if (event.type === 'messages' && queued.type === 'messages') {
|
|
77
|
+
const sameMessage = queued.taskId === event.taskId &&
|
|
78
|
+
(queued.chunk.kind ?? 'text') === (event.chunk.kind ?? 'text') &&
|
|
79
|
+
queued.chunk.messageId === event.chunk.messageId &&
|
|
80
|
+
queued.namespace.join('/') === event.namespace.join('/');
|
|
81
|
+
if (!sameMessage)
|
|
82
|
+
continue;
|
|
83
|
+
this.queue[index] = {
|
|
84
|
+
...queued,
|
|
85
|
+
chunk: { ...queued.chunk, content: queued.chunk.content + event.chunk.content },
|
|
86
|
+
};
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (event.type === 'values' &&
|
|
90
|
+
queued.type === 'values' &&
|
|
91
|
+
queued.namespace.join('/') === event.namespace.join('/')) {
|
|
92
|
+
this.queue[index] = event;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
whenDrained() {
|
|
99
|
+
if (this.closed || this.queue.length <= this.settings.maxBuffered / 2)
|
|
100
|
+
return Promise.resolve();
|
|
101
|
+
return new Promise((resolve) => this.drained.push(resolve));
|
|
102
|
+
}
|
|
103
|
+
next() {
|
|
104
|
+
const event = this.queue.shift();
|
|
105
|
+
if (this.queue.length <= this.settings.maxBuffered / 2)
|
|
106
|
+
this.releaseWaiters();
|
|
107
|
+
if (event)
|
|
108
|
+
return Promise.resolve({ value: event, done: false });
|
|
109
|
+
if (this.error !== undefined)
|
|
110
|
+
return Promise.reject(this.error);
|
|
111
|
+
if (this.ended || this.closed)
|
|
112
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
this.waiting = resolve;
|
|
115
|
+
this.failure = reject;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
end(error) {
|
|
119
|
+
this.ended = true;
|
|
120
|
+
if (error !== undefined)
|
|
121
|
+
this.error = error;
|
|
122
|
+
this.releaseWaiters();
|
|
123
|
+
if (!this.waiting)
|
|
124
|
+
return;
|
|
125
|
+
const resolve = this.waiting;
|
|
126
|
+
const reject = this.failure;
|
|
127
|
+
this.waiting = undefined;
|
|
128
|
+
this.failure = undefined;
|
|
129
|
+
if (error !== undefined)
|
|
130
|
+
reject?.(error);
|
|
131
|
+
else
|
|
132
|
+
resolve({ value: undefined, done: true });
|
|
133
|
+
}
|
|
134
|
+
close() {
|
|
135
|
+
this.closed = true;
|
|
136
|
+
this.queue.length = 0;
|
|
137
|
+
this.end();
|
|
138
|
+
}
|
|
139
|
+
releaseWaiters() {
|
|
140
|
+
const waiters = this.drained;
|
|
141
|
+
this.drained = [];
|
|
142
|
+
for (const resolve of waiters)
|
|
143
|
+
resolve();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
class GraphEventStream {
|
|
147
|
+
start;
|
|
148
|
+
toResult;
|
|
149
|
+
settings;
|
|
150
|
+
readers = [];
|
|
151
|
+
controller = new AbortController();
|
|
152
|
+
started = false;
|
|
153
|
+
stats = { peak: 0, coalesced: 0, dropped: 0 };
|
|
154
|
+
resolveResult;
|
|
155
|
+
rejectResult;
|
|
156
|
+
result;
|
|
157
|
+
constructor(start, toResult, settings) {
|
|
158
|
+
this.start = start;
|
|
159
|
+
this.toResult = toResult;
|
|
160
|
+
this.settings = settings;
|
|
161
|
+
this.result = new Promise((resolve, reject) => {
|
|
162
|
+
this.resolveResult = resolve;
|
|
163
|
+
this.rejectResult = reject;
|
|
164
|
+
});
|
|
165
|
+
this.result.catch(() => undefined);
|
|
166
|
+
}
|
|
167
|
+
[Symbol.asyncIterator]() {
|
|
168
|
+
return this.reader(() => true);
|
|
169
|
+
}
|
|
170
|
+
messages() {
|
|
171
|
+
return this.only('messages');
|
|
172
|
+
}
|
|
173
|
+
tools() {
|
|
174
|
+
return this.only('tools');
|
|
175
|
+
}
|
|
176
|
+
values() {
|
|
177
|
+
return this.only('values');
|
|
178
|
+
}
|
|
179
|
+
updates() {
|
|
180
|
+
return this.only('updates');
|
|
181
|
+
}
|
|
182
|
+
streamStats() {
|
|
183
|
+
return { ...this.stats };
|
|
184
|
+
}
|
|
185
|
+
only(type) {
|
|
186
|
+
const iterator = this.reader((event) => event.type === type);
|
|
187
|
+
return { [Symbol.asyncIterator]: () => iterator };
|
|
188
|
+
}
|
|
189
|
+
reader(accepts) {
|
|
190
|
+
const reader = new Reader(accepts, this.settings, this.stats, (error) => this.fail(error));
|
|
191
|
+
if (this.started)
|
|
192
|
+
reader.end();
|
|
193
|
+
else
|
|
194
|
+
this.readers.push(reader);
|
|
195
|
+
return {
|
|
196
|
+
next: () => {
|
|
197
|
+
this.begin();
|
|
198
|
+
return reader.next();
|
|
199
|
+
},
|
|
200
|
+
return: async () => {
|
|
201
|
+
reader.close();
|
|
202
|
+
if (this.readers.every((item) => item.closed))
|
|
203
|
+
this.controller.abort(new Error('Every reader stopped'));
|
|
204
|
+
return { value: undefined, done: true };
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
begin() {
|
|
209
|
+
if (this.started)
|
|
210
|
+
return;
|
|
211
|
+
this.started = true;
|
|
212
|
+
void this.pump();
|
|
213
|
+
}
|
|
214
|
+
publish(event) {
|
|
215
|
+
if (event.namespace.length > 0 && !this.settings.subgraphs)
|
|
216
|
+
return;
|
|
217
|
+
const projection = event.type;
|
|
218
|
+
if (!this.settings.include.includes(projection))
|
|
219
|
+
return;
|
|
220
|
+
for (const reader of this.readers)
|
|
221
|
+
reader.push(event);
|
|
222
|
+
}
|
|
223
|
+
fail(error) {
|
|
224
|
+
if (this.controller.signal.aborted)
|
|
225
|
+
return;
|
|
226
|
+
this.controller.abort(error);
|
|
227
|
+
for (const reader of this.readers)
|
|
228
|
+
reader.end(error);
|
|
229
|
+
this.rejectResult(error);
|
|
230
|
+
}
|
|
231
|
+
async pump() {
|
|
232
|
+
let last;
|
|
233
|
+
try {
|
|
234
|
+
for await (const step of this.start((event) => {
|
|
235
|
+
for (const item of fromGraphEvent(event))
|
|
236
|
+
this.publish(item);
|
|
237
|
+
}, this.controller.signal)) {
|
|
238
|
+
last = step;
|
|
239
|
+
this.publish({ type: 'values', step: step.step, status: step.status, state: step.state, namespace: [] });
|
|
240
|
+
await Promise.all(this.readers.map((reader) => reader.whenDrained()));
|
|
241
|
+
}
|
|
242
|
+
for (const reader of this.readers)
|
|
243
|
+
reader.end();
|
|
244
|
+
this.resolveResult(this.toResult(last));
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
const reason = this.controller.signal.reason;
|
|
248
|
+
this.fail(reason instanceof GraphStreamOverflowError ? reason : error);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.GraphEventStream = GraphEventStream;
|
|
253
|
+
function streamSettings(options) {
|
|
254
|
+
return {
|
|
255
|
+
include: options.include ?? DEFAULT_INCLUDE,
|
|
256
|
+
subgraphs: options.subgraphs ?? false,
|
|
257
|
+
maxBuffered: Math.max(2, options.maxBuffered ?? DEFAULT_MAX_BUFFERED),
|
|
258
|
+
overflow: options.overflow ?? 'coalesce',
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function fromGraphEvent(event) {
|
|
262
|
+
const namespace = event.namespace ?? [];
|
|
263
|
+
switch (event.type) {
|
|
264
|
+
case 'message':
|
|
265
|
+
return [
|
|
266
|
+
{ type: 'messages', step: event.step, node: event.node, taskId: event.taskId, chunk: event.chunk, namespace },
|
|
267
|
+
];
|
|
268
|
+
case 'tool':
|
|
269
|
+
return [{ type: 'tools', step: event.step, node: event.node, taskId: event.taskId, tool: event.tool, namespace }];
|
|
270
|
+
case 'custom':
|
|
271
|
+
return [
|
|
272
|
+
{ type: 'custom', step: event.step, node: event.node, taskId: event.taskId, data: event.data, namespace },
|
|
273
|
+
];
|
|
274
|
+
case 'checkpoint':
|
|
275
|
+
return [{ type: 'checkpoints', step: event.step, status: event.status, next: event.next, namespace }];
|
|
276
|
+
case 'task_end':
|
|
277
|
+
return [
|
|
278
|
+
{ type: 'tasks', event, namespace },
|
|
279
|
+
...(event.update === undefined
|
|
280
|
+
? []
|
|
281
|
+
: [
|
|
282
|
+
{
|
|
283
|
+
type: 'updates',
|
|
284
|
+
step: event.step,
|
|
285
|
+
node: event.node,
|
|
286
|
+
taskId: event.taskId,
|
|
287
|
+
update: event.update,
|
|
288
|
+
namespace,
|
|
289
|
+
},
|
|
290
|
+
]),
|
|
291
|
+
];
|
|
292
|
+
default:
|
|
293
|
+
return [{ type: 'tasks', event, namespace }];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { OperationLifecycleLike } from '../types/lifecycle.js';
|
|
2
2
|
import { GraphError } from './errors.js';
|
|
3
|
-
import type { GraphCheckpoint, GraphCheckpointer, GraphDescription, GraphEvent, GraphStatus, InterruptRequest, PendingInterrupt, RetryPolicy } from '../types/graph.js';
|
|
3
|
+
import type { GraphCheckpoint, GraphCheckpointer, GraphDescription, GraphEvent, GraphStatus, InterruptRequest, PendingInterrupt, RetryPolicy, RunControlLike } from '../types/graph.js';
|
|
4
4
|
import type { Store } from '../types/store.js';
|
|
5
5
|
/** What a workflow checkpoint holds: the input, every completed step's result, and the output. */
|
|
6
6
|
export interface WorkflowState<I = unknown, O = unknown> {
|
|
7
7
|
/** The input the workflow was started with. */
|
|
8
8
|
input: I;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Each completed step's result, keyed by step name — `name#2` for the second call with a name. A
|
|
11
|
+
* step whose `onError` supplied its result after its retries ran out also records `recovered`.
|
|
12
|
+
*/
|
|
10
13
|
steps: Record<string, {
|
|
11
14
|
value?: unknown;
|
|
15
|
+
recovered?: StepRecovery;
|
|
12
16
|
}>;
|
|
13
17
|
/** The workflow's return value, once it has completed. */
|
|
14
18
|
output?: O;
|
|
@@ -23,21 +27,68 @@ export interface StepContext {
|
|
|
23
27
|
readonly attempt: number;
|
|
24
28
|
/** Aborted when the run is cancelled or the step exceeds its timeout. */
|
|
25
29
|
readonly signal: AbortSignal;
|
|
30
|
+
/**
|
|
31
|
+
* Shows the step is still making progress, which refreshes its idle timeout. For long work that
|
|
32
|
+
* sends nothing else, such as a large upload or a slow tool call.
|
|
33
|
+
*/
|
|
34
|
+
heartbeat(): void;
|
|
35
|
+
}
|
|
36
|
+
/** Limits on one attempt of a step: its whole run, and the time it may go without progress. */
|
|
37
|
+
export interface StepTimeout {
|
|
38
|
+
/** Fails the attempt when it runs longer than this, in milliseconds. */
|
|
39
|
+
runMs?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Fails the attempt when this long passes without `context.heartbeat()`, in milliseconds, which
|
|
42
|
+
* tells a hung step from a slow one that is working.
|
|
43
|
+
*/
|
|
44
|
+
idleMs?: number;
|
|
45
|
+
}
|
|
46
|
+
/** What a step's `onError` receives once its retries have run out. */
|
|
47
|
+
export interface StepFailure {
|
|
48
|
+
/** The step's name. */
|
|
49
|
+
name: string;
|
|
50
|
+
/** The key its result is recorded under. */
|
|
51
|
+
key: string;
|
|
52
|
+
/** Attempts made. */
|
|
53
|
+
attempts: number;
|
|
54
|
+
/** The last attempt's error. */
|
|
55
|
+
error: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** How a step's result was recovered, as recorded in the workflow state. */
|
|
58
|
+
export interface StepRecovery {
|
|
59
|
+
/** The error that exhausted the step's retries. */
|
|
60
|
+
error: {
|
|
61
|
+
name: string;
|
|
62
|
+
message: string;
|
|
63
|
+
};
|
|
64
|
+
/** Attempts made before `onError` decided. */
|
|
65
|
+
attempts: number;
|
|
26
66
|
}
|
|
27
67
|
/** How one step runs. */
|
|
28
|
-
export interface StepOptions {
|
|
68
|
+
export interface StepOptions<T = unknown> {
|
|
29
69
|
/** Retries a failing attempt, overriding the workflow's default policy. */
|
|
30
70
|
retry?: RetryPolicy;
|
|
31
71
|
/** Aborts the step's signal and fails the attempt when it runs longer than this, in milliseconds. */
|
|
32
72
|
timeoutMs?: number;
|
|
73
|
+
/** Run and idle limits on each attempt. `runMs` is `timeoutMs` by another name; `timeoutMs` wins when both are set. */
|
|
74
|
+
timeout?: StepTimeout;
|
|
75
|
+
/**
|
|
76
|
+
* Decides what happens once the step's retries run out. What it returns becomes the step's
|
|
77
|
+
* result, recorded with `recovered`, so a resumed run does not run the step again — a refund after
|
|
78
|
+
* a charge that kept failing, say. Throwing fails the step with that error. A cancelled run, a
|
|
79
|
+
* question, or a drain is never passed to it.
|
|
80
|
+
*/
|
|
81
|
+
onError?: (failure: StepFailure) => T | Promise<T>;
|
|
33
82
|
}
|
|
34
83
|
/** What a workflow function receives besides its input. */
|
|
35
84
|
export interface WorkflowContext {
|
|
36
85
|
/** The thread this run belongs to. */
|
|
37
86
|
readonly threadId: string;
|
|
87
|
+
/** The tenant the run is for, when it has one. */
|
|
88
|
+
readonly tenantId?: string;
|
|
38
89
|
/** Aborted when the run is cancelled. */
|
|
39
90
|
readonly signal: AbortSignal;
|
|
40
|
-
/** Long-term memory, when the workflow was created with a store. */
|
|
91
|
+
/** Long-term memory, when the workflow was created with a store. In a tenant's run, the tenant's view of it. */
|
|
41
92
|
readonly store?: Store;
|
|
42
93
|
/**
|
|
43
94
|
* Runs a piece of work once per thread and records its result.
|
|
@@ -46,7 +97,7 @@ export interface WorkflowContext {
|
|
|
46
97
|
* running. Name steps so the same call has the same name every time; a name used more than once
|
|
47
98
|
* is numbered in call order. The result must survive JSON serialization.
|
|
48
99
|
*/
|
|
49
|
-
step<T>(name: string, run: (context: StepContext) => Promise<T> | T, options?: StepOptions): Promise<T>;
|
|
100
|
+
step<T>(name: string, run: (context: StepContext) => Promise<T> | T, options?: StepOptions<T>): Promise<T>;
|
|
50
101
|
/**
|
|
51
102
|
* Suspends the workflow until a person answers.
|
|
52
103
|
*
|
|
@@ -73,6 +124,11 @@ export interface WorkflowOptions {
|
|
|
73
124
|
store?: Store;
|
|
74
125
|
/** Default retry policy for every step. A step's own policy wins. Defaults to one attempt. */
|
|
75
126
|
retry?: RetryPolicy;
|
|
127
|
+
/**
|
|
128
|
+
* Defaults for every step: its retries, its run and idle timeouts, and its `onError`. A step's own
|
|
129
|
+
* options win, field by field.
|
|
130
|
+
*/
|
|
131
|
+
stepDefaults?: Pick<StepOptions, 'retry' | 'timeout' | 'onError'>;
|
|
76
132
|
/** Steps that may run at once, for a workflow that starts many with `Promise.all`. Defaults to 16. */
|
|
77
133
|
maxConcurrency?: number;
|
|
78
134
|
/**
|
|
@@ -93,6 +149,19 @@ export interface WorkflowRunOptions {
|
|
|
93
149
|
metadata?: Record<string, unknown>;
|
|
94
150
|
/** Receives each step starting, retrying, and finishing, each checkpoint, and custom events. */
|
|
95
151
|
onEvent?: (event: GraphEvent) => void;
|
|
152
|
+
/**
|
|
153
|
+
* Lets the caller stop the run between steps: pass a `RunControl` and call `drain()`. Steps in
|
|
154
|
+
* flight finish and are recorded, no new step starts, and the run ends with `GraphDrainedError`;
|
|
155
|
+
* `continue()` carries it on, on this worker or another. The agent server drains a workflow it
|
|
156
|
+
* serves this way.
|
|
157
|
+
*/
|
|
158
|
+
control?: RunControlLike;
|
|
159
|
+
/**
|
|
160
|
+
* The tenant the run is for. Recorded on every checkpoint as `metadata.tenantId`, read as
|
|
161
|
+
* `context.tenantId`, and scoping `context.store`; another tenant's thread is not found. A run
|
|
162
|
+
* without one carries on the thread's.
|
|
163
|
+
*/
|
|
164
|
+
tenantId?: string;
|
|
96
165
|
}
|
|
97
166
|
/** One event of a streamed workflow run. */
|
|
98
167
|
export type WorkflowEvent<O = unknown> = {
|
|
@@ -152,17 +221,21 @@ export interface WorkflowResult<O = unknown> {
|
|
|
152
221
|
/** Every pending question. */
|
|
153
222
|
interrupts?: PendingInterrupt[];
|
|
154
223
|
}
|
|
155
|
-
/** Raised when a step outlives its
|
|
224
|
+
/** Raised when a step outlives its run timeout, or goes longer than its idle timeout without progress. */
|
|
156
225
|
export declare class WorkflowStepTimeoutError extends GraphError {
|
|
157
226
|
/** The step. */
|
|
158
227
|
readonly stepName: string;
|
|
159
228
|
/** The limit it exceeded, in milliseconds. */
|
|
160
229
|
readonly timeoutMs: number;
|
|
230
|
+
/** Which limit: `run` for the whole attempt, `idle` for the time without progress. */
|
|
231
|
+
readonly kind: 'run' | 'idle';
|
|
161
232
|
constructor(
|
|
162
233
|
/** The step. */
|
|
163
234
|
stepName: string,
|
|
164
235
|
/** The limit it exceeded, in milliseconds. */
|
|
165
|
-
timeoutMs: number
|
|
236
|
+
timeoutMs: number,
|
|
237
|
+
/** Which limit: `run` for the whole attempt, `idle` for the time without progress. */
|
|
238
|
+
kind?: 'run' | 'idle');
|
|
166
239
|
}
|
|
167
240
|
/**
|
|
168
241
|
* A durable workflow: a function whose steps are checkpointed, so it survives interrupts, restarts,
|