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
package/dist/types/graph.d.ts
CHANGED
|
@@ -30,11 +30,20 @@ export declare class Send {
|
|
|
30
30
|
readonly node: string;
|
|
31
31
|
/** What the task receives as `context.input`. */
|
|
32
32
|
readonly input?: unknown | undefined;
|
|
33
|
+
/** Options for this task alone. `timeout` replaces the node's own for it. */
|
|
34
|
+
readonly options?: SendOptions | undefined;
|
|
33
35
|
constructor(
|
|
34
36
|
/** The node to run. */
|
|
35
37
|
node: string,
|
|
36
38
|
/** What the task receives as `context.input`. */
|
|
37
|
-
input?: unknown | undefined
|
|
39
|
+
input?: unknown | undefined,
|
|
40
|
+
/** Options for this task alone. `timeout` replaces the node's own for it. */
|
|
41
|
+
options?: SendOptions | undefined);
|
|
42
|
+
}
|
|
43
|
+
/** Options for one task a `Send` creates. */
|
|
44
|
+
export interface SendOptions {
|
|
45
|
+
/** Replaces the node's timeout for this task, such as a longer limit for one large document. */
|
|
46
|
+
timeout?: NodeTimeout;
|
|
38
47
|
}
|
|
39
48
|
/** Where a `Command` sends control. */
|
|
40
49
|
export type CommandTarget = string | Send | Array<string | Send>;
|
|
@@ -79,6 +88,118 @@ export interface GraphTask {
|
|
|
79
88
|
node: string;
|
|
80
89
|
/** The task's `Send` input. */
|
|
81
90
|
input?: unknown;
|
|
91
|
+
/** The timeout its `Send` set, replacing the node's own. */
|
|
92
|
+
timeout?: NodeTimeout;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* How long a node may run, in two senses.
|
|
96
|
+
*
|
|
97
|
+
* `runMs` caps the whole attempt: "this may never take longer than ten minutes". `idleMs` caps the
|
|
98
|
+
* time between signs of progress: "this may take ten minutes, but must show progress every thirty
|
|
99
|
+
* seconds". A node shows progress by calling `context.heartbeat()`, `context.emit()`, or
|
|
100
|
+
* `context.report()`. Either limit fails the attempt with `GraphNodeTimeoutError`, which the retry
|
|
101
|
+
* policy may retry.
|
|
102
|
+
*/
|
|
103
|
+
export interface NodeTimeout {
|
|
104
|
+
/** The longest an attempt may run, in milliseconds. */
|
|
105
|
+
runMs?: number;
|
|
106
|
+
/** The longest an attempt may go without showing progress, in milliseconds. */
|
|
107
|
+
idleMs?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* When a graph writes its checkpoints.
|
|
111
|
+
*
|
|
112
|
+
* - `sync` (the default) writes each checkpoint before the next superstep starts. Use it when a
|
|
113
|
+
* node's side effects must line up with the state that records them, such as payments.
|
|
114
|
+
* - `async` writes checkpoints in the background while the graph runs on. Every write still
|
|
115
|
+
* happens, in order, and the run waits for them before it returns, pauses, fails, or drains. A
|
|
116
|
+
* crash can lose the last few supersteps, which then run again.
|
|
117
|
+
* - `exit` writes only when the run stops: at an interrupt, a breakpoint, completion, a failure, an
|
|
118
|
+
* abort, or a drain. A crash loses the whole run. For short, high-throughput graphs.
|
|
119
|
+
*/
|
|
120
|
+
export type DurabilityMode = 'sync' | 'async' | 'exit';
|
|
121
|
+
/**
|
|
122
|
+
* Why a node's last attempt failed, handed to its `onError` once retries are exhausted.
|
|
123
|
+
*
|
|
124
|
+
* Everything here is what the runtime knows at the moment of failure. The decision `onError`
|
|
125
|
+
* returns is checkpointed before the graph moves on, so a crash after it resumes into the same path.
|
|
126
|
+
*/
|
|
127
|
+
export interface NodeFailure {
|
|
128
|
+
/** The node that failed. */
|
|
129
|
+
node: string;
|
|
130
|
+
/** The task that failed. Equal to `node` unless the task came from a `Send`. */
|
|
131
|
+
taskId: string;
|
|
132
|
+
/** The superstep it failed in. */
|
|
133
|
+
step: number;
|
|
134
|
+
/** Attempts made, including the last. */
|
|
135
|
+
attempts: number;
|
|
136
|
+
/** ISO-8601 time of the first attempt. */
|
|
137
|
+
firstAttemptAt: string;
|
|
138
|
+
/** ISO-8601 time the last attempt failed. */
|
|
139
|
+
failedAt: string;
|
|
140
|
+
/** What the last attempt threw. */
|
|
141
|
+
error: unknown;
|
|
142
|
+
/** True when the retry policy ran out; false when the error was not retryable. */
|
|
143
|
+
retryExhausted: boolean;
|
|
144
|
+
/** The limit that ended the last attempt, when a timeout did. */
|
|
145
|
+
timeout?: {
|
|
146
|
+
type: 'run' | 'idle';
|
|
147
|
+
limitMs: number;
|
|
148
|
+
};
|
|
149
|
+
/** The task's `Send` input. */
|
|
150
|
+
input?: unknown;
|
|
151
|
+
/** The thread the run belongs to. */
|
|
152
|
+
threadId: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Decides what happens after a node's retries are exhausted: a state update, a `Command` that
|
|
156
|
+
* routes to a compensation node, or nothing, to carry on along the node's own edges. Throwing fails
|
|
157
|
+
* the graph with that error.
|
|
158
|
+
*
|
|
159
|
+
* It decides; it should not act. Compensation with side effects belongs in the node it routes to,
|
|
160
|
+
* which runs only after the decision is checkpointed.
|
|
161
|
+
*/
|
|
162
|
+
export type NodeErrorHandler<S extends ChannelSchema = ChannelSchema> = (failure: NodeFailure, context: {
|
|
163
|
+
state: Readonly<StateOf<S>>;
|
|
164
|
+
}) => NodeResult<S> | Promise<NodeResult<S>>;
|
|
165
|
+
/** A failure a node's `onError` recovered from, as its checkpoint records it. */
|
|
166
|
+
export interface RecoveredFailure {
|
|
167
|
+
/** The node that failed. */
|
|
168
|
+
node: string;
|
|
169
|
+
/** The task that failed. */
|
|
170
|
+
taskId: string;
|
|
171
|
+
/** The superstep it failed in. */
|
|
172
|
+
step: number;
|
|
173
|
+
/** Attempts made. */
|
|
174
|
+
attempts: number;
|
|
175
|
+
/** What the last attempt threw, as a name and a message. */
|
|
176
|
+
error: {
|
|
177
|
+
name: string;
|
|
178
|
+
message: string;
|
|
179
|
+
};
|
|
180
|
+
/** ISO-8601 time the last attempt failed. */
|
|
181
|
+
failedAt: string;
|
|
182
|
+
/** True when the retry policy ran out. */
|
|
183
|
+
retryExhausted: boolean;
|
|
184
|
+
/** The limit that ended the last attempt, when a timeout did. */
|
|
185
|
+
timeout?: {
|
|
186
|
+
type: 'run' | 'idle';
|
|
187
|
+
limitMs: number;
|
|
188
|
+
};
|
|
189
|
+
/** Where `onError` sent the run, when it returned a `Command` with a target. */
|
|
190
|
+
goto?: string[];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Asks a running graph to stop at the end of its current superstep.
|
|
194
|
+
*
|
|
195
|
+
* `RunControl` from `nexus-ai-pro/graph` implements it. Any object with these members works, so a
|
|
196
|
+
* server can pass its own.
|
|
197
|
+
*/
|
|
198
|
+
export interface RunControlLike {
|
|
199
|
+
/** True once a drain was requested. */
|
|
200
|
+
readonly draining: boolean;
|
|
201
|
+
/** Why the drain was requested. */
|
|
202
|
+
readonly reason?: string;
|
|
82
203
|
}
|
|
83
204
|
/**
|
|
84
205
|
* How a node retries. Applied per node, or as the graph default through `compile({ retry })`.
|
|
@@ -100,12 +221,28 @@ export interface RetryPolicy {
|
|
|
100
221
|
/** Decides whether this error is worth retrying. Defaults to retrying anything else. */
|
|
101
222
|
retryOn?(error: unknown, attempt: number): boolean;
|
|
102
223
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
224
|
+
/**
|
|
225
|
+
* How a node runs: retries, timeouts, recovery, where it may route, deferral, caching, and whether
|
|
226
|
+
* it is safe to run twice.
|
|
227
|
+
*/
|
|
228
|
+
export interface NodeOptions<S extends ChannelSchema = ChannelSchema> {
|
|
105
229
|
/** Retries failed attempts, overriding the graph's default policy. */
|
|
106
230
|
retry?: RetryPolicy;
|
|
107
|
-
/** Aborts the node's signal and fails the attempt when it runs longer than this. */
|
|
231
|
+
/** Aborts the node's signal and fails the attempt when it runs longer than this. Same as `timeout.runMs`. */
|
|
108
232
|
timeoutMs?: number;
|
|
233
|
+
/** A run limit, an idle limit, or both. `timeout.runMs` wins over `timeoutMs`. */
|
|
234
|
+
timeout?: NodeTimeout;
|
|
235
|
+
/**
|
|
236
|
+
* Called once retries are exhausted, instead of failing the graph. See `NodeErrorHandler`. A
|
|
237
|
+
* `Command` it returns may route anywhere; declare those targets in `ends`.
|
|
238
|
+
*/
|
|
239
|
+
onError?: NodeErrorHandler<S>;
|
|
240
|
+
/**
|
|
241
|
+
* Declares that running this node twice is safe: it has no side effects, or they carry an
|
|
242
|
+
* idempotency key. Nothing at run time depends on it; `lintGraph()` uses it to flag retried nodes
|
|
243
|
+
* that are not.
|
|
244
|
+
*/
|
|
245
|
+
idempotent?: boolean;
|
|
109
246
|
/**
|
|
110
247
|
* Nodes this one may reach through `Send` or a `Command`. Declaring them keeps compile-time
|
|
111
248
|
* reachability checks and diagrams exact, so a node reached only that way is not reported as
|
|
@@ -235,6 +372,8 @@ export interface NodeContext<S extends ChannelSchema> {
|
|
|
235
372
|
readonly step: number;
|
|
236
373
|
/** The thread this run belongs to. */
|
|
237
374
|
readonly threadId: string;
|
|
375
|
+
/** The tenant the run is for, when it has one. */
|
|
376
|
+
readonly tenantId?: string;
|
|
238
377
|
/** Identifies this task. Equal to `node` unless the task came from a `Send`. */
|
|
239
378
|
readonly taskId: string;
|
|
240
379
|
/** Input carried by a `Send`. Undefined for a node reached through an ordinary edge. */
|
|
@@ -258,16 +397,33 @@ export interface NodeContext<S extends ChannelSchema> {
|
|
|
258
397
|
* Long-term memory, present when the graph was compiled with a store.
|
|
259
398
|
*
|
|
260
399
|
* State is this thread's; the store is everything else the application remembers — across threads,
|
|
261
|
-
* users, and runs.
|
|
400
|
+
* users, and runs. In a run with a `tenantId`, it is that tenant's view of the store, and nothing
|
|
401
|
+
* another tenant stored can be read through it.
|
|
262
402
|
*/
|
|
263
403
|
readonly store?: Store;
|
|
264
|
-
/** Reports progress without writing to state. */
|
|
404
|
+
/** Reports progress without writing to state. Refreshes an idle timeout. */
|
|
265
405
|
report(progress: Omit<GraphProgress, 'step' | 'node'>): void;
|
|
266
406
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
407
|
+
* Shows the node is still making progress, which refreshes its idle timeout. For long work that
|
|
408
|
+
* neither emits nor reports, such as a large upload or a slow tool call.
|
|
409
|
+
*/
|
|
410
|
+
heartbeat(): void;
|
|
411
|
+
/**
|
|
412
|
+
* Sends anything to the run's `onEvent` listener as a `custom` event: intermediate results, a
|
|
413
|
+
* status line. Nothing is written to state or checkpointed. Refreshes an idle timeout.
|
|
269
414
|
*/
|
|
270
415
|
emit(data: unknown): void;
|
|
416
|
+
/**
|
|
417
|
+
* Streams a piece of model output as a `message` event, which `events()` delivers on its
|
|
418
|
+
* `messages` projection. `createAgent()` sends its model's output this way. Refreshes an idle
|
|
419
|
+
* timeout.
|
|
420
|
+
*/
|
|
421
|
+
message(chunk: GraphMessageChunk): void;
|
|
422
|
+
/**
|
|
423
|
+
* Reports a tool call as a `tool` event, which `events()` delivers on its `tools` projection.
|
|
424
|
+
* `createAgent()` reports every tool it runs this way. Refreshes an idle timeout.
|
|
425
|
+
*/
|
|
426
|
+
tool(event: GraphToolEvent): void;
|
|
271
427
|
}
|
|
272
428
|
/** A node: reads state from its context and returns an update, a `Command`, or nothing. */
|
|
273
429
|
export type NodeFn<S extends ChannelSchema> = (context: NodeContext<S>) => Promise<NodeResult<S>> | NodeResult<S>;
|
|
@@ -335,6 +491,13 @@ export interface GraphCheckpoint<S extends ChannelSchema = ChannelSchema> {
|
|
|
335
491
|
};
|
|
336
492
|
/** Present when the run paused at a breakpoint rather than to ask a question. */
|
|
337
493
|
breakpoint?: GraphBreakpoint;
|
|
494
|
+
/** Failures in the step this checkpoint follows that a node's `onError` recovered from. */
|
|
495
|
+
recovered?: RecoveredFailure[];
|
|
496
|
+
/** Present when the run stopped because a drain was requested. `continue()` resumes it. */
|
|
497
|
+
drained?: {
|
|
498
|
+
reason?: string;
|
|
499
|
+
at: string;
|
|
500
|
+
};
|
|
338
501
|
/** ISO-8601 time the checkpoint was written. */
|
|
339
502
|
createdAt: string;
|
|
340
503
|
/** Application data, including `graph` when the graph was compiled with a name. */
|
|
@@ -407,6 +570,13 @@ export interface GraphRunOptions {
|
|
|
407
570
|
signal?: AbortSignal;
|
|
408
571
|
/** Application data recorded on every checkpoint of the run. */
|
|
409
572
|
metadata?: Record<string, unknown>;
|
|
573
|
+
/**
|
|
574
|
+
* The tenant the run is for. It is recorded on every checkpoint as `metadata.tenantId`, nodes read
|
|
575
|
+
* it as `context.tenantId`, and `context.store` becomes the tenant's own view of the store. A thread
|
|
576
|
+
* another tenant owns is not found: resuming, continuing, forking, or editing it with a different
|
|
577
|
+
* `tenantId` is refused before anything runs. A run without one carries on the thread's tenant.
|
|
578
|
+
*/
|
|
579
|
+
tenantId?: string;
|
|
410
580
|
/** Overrides the compiled `maxConcurrency` for this run. */
|
|
411
581
|
maxConcurrency?: number;
|
|
412
582
|
/** Breakpoints for this run only, replacing the compiled ones. */
|
|
@@ -421,6 +591,19 @@ export interface GraphRunOptions {
|
|
|
421
591
|
onEvent?: (event: GraphEvent) => void;
|
|
422
592
|
/** Receives what nodes pass to `context.report()`. A throwing callback never fails the node. */
|
|
423
593
|
onProgress?: (progress: GraphProgress) => void;
|
|
594
|
+
/** Overrides the compiled `durability` for this run. */
|
|
595
|
+
durability?: DurabilityMode;
|
|
596
|
+
/**
|
|
597
|
+
* Also delivers the events of subgraphs run through `asNode()` to `onEvent`, each with the
|
|
598
|
+
* `namespace` of nodes it came through. Defaults to false.
|
|
599
|
+
*/
|
|
600
|
+
subgraphEvents?: boolean;
|
|
601
|
+
/**
|
|
602
|
+
* Lets the caller stop the run at the end of its current superstep: pass a `RunControl` and call
|
|
603
|
+
* `drain()`, on SIGTERM for example. The run writes its checkpoint and ends with
|
|
604
|
+
* `GraphDrainedError`, and `continue()` resumes it, on this worker or another.
|
|
605
|
+
*/
|
|
606
|
+
control?: RunControlLike;
|
|
424
607
|
}
|
|
425
608
|
/** The outcome of a run. */
|
|
426
609
|
export interface GraphResult<S extends ChannelSchema, O extends keyof S = keyof S> {
|
|
@@ -447,7 +630,7 @@ export interface GraphResult<S extends ChannelSchema, O extends keyof S = keyof
|
|
|
447
630
|
};
|
|
448
631
|
}
|
|
449
632
|
/** Fine-grained events delivered to `GraphRunOptions.onEvent`. */
|
|
450
|
-
export type GraphEvent = {
|
|
633
|
+
export type GraphEvent = ({
|
|
451
634
|
type: 'task_start';
|
|
452
635
|
step: number;
|
|
453
636
|
taskId: string;
|
|
@@ -460,6 +643,15 @@ export type GraphEvent = {
|
|
|
460
643
|
node: string;
|
|
461
644
|
attempt: number;
|
|
462
645
|
error: string;
|
|
646
|
+
} | {
|
|
647
|
+
type: 'task_failed';
|
|
648
|
+
step: number;
|
|
649
|
+
taskId: string;
|
|
650
|
+
node: string;
|
|
651
|
+
attempts: number;
|
|
652
|
+
error: string;
|
|
653
|
+
/** True when the node's `onError` recovered, so the graph carries on. */
|
|
654
|
+
recovered: boolean;
|
|
463
655
|
} | {
|
|
464
656
|
type: 'task_end';
|
|
465
657
|
step: number;
|
|
@@ -480,7 +672,132 @@ export type GraphEvent = {
|
|
|
480
672
|
taskId: string;
|
|
481
673
|
node: string;
|
|
482
674
|
data: unknown;
|
|
675
|
+
} | {
|
|
676
|
+
type: 'message';
|
|
677
|
+
step: number;
|
|
678
|
+
taskId: string;
|
|
679
|
+
node: string;
|
|
680
|
+
chunk: GraphMessageChunk;
|
|
681
|
+
} | {
|
|
682
|
+
type: 'tool';
|
|
683
|
+
step: number;
|
|
684
|
+
taskId: string;
|
|
685
|
+
node: string;
|
|
686
|
+
tool: GraphToolEvent;
|
|
687
|
+
}) & {
|
|
688
|
+
/**
|
|
689
|
+
* The nodes a subgraph event came through, outermost first: `['review']` for an event of a graph
|
|
690
|
+
* that runs as the parent's `review` node. Absent for the graph's own events.
|
|
691
|
+
*/
|
|
692
|
+
namespace?: string[];
|
|
693
|
+
};
|
|
694
|
+
/** A piece of a model's output, as a node streams it: text, or a reasoning summary. */
|
|
695
|
+
export interface GraphMessageChunk {
|
|
696
|
+
/** `text` for visible output, `reasoning` for a reasoning summary. Defaults to `text`. */
|
|
697
|
+
kind?: 'text' | 'reasoning';
|
|
698
|
+
/** The text. */
|
|
699
|
+
content: string;
|
|
700
|
+
/** Identifies the message the chunk belongs to, when a node streams more than one. */
|
|
701
|
+
messageId?: string;
|
|
702
|
+
}
|
|
703
|
+
/** A tool call's progress, as a node reports it. */
|
|
704
|
+
export interface GraphToolEvent {
|
|
705
|
+
/** `start` when it is called, `progress` while it runs, then `result` or `error`. */
|
|
706
|
+
phase: 'start' | 'progress' | 'result' | 'error';
|
|
707
|
+
/** The call's id, matching the model's. */
|
|
708
|
+
id: string;
|
|
709
|
+
/** The tool's name. */
|
|
710
|
+
name: string;
|
|
711
|
+
/** The arguments, on `start`. */
|
|
712
|
+
args?: unknown;
|
|
713
|
+
/** Anything the tool reported, on `progress`. */
|
|
714
|
+
progress?: unknown;
|
|
715
|
+
/** What it returned, on `result`. */
|
|
716
|
+
result?: unknown;
|
|
717
|
+
/** Why it failed, on `error`. */
|
|
718
|
+
error?: string;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* What `events()` can include. `values` is the state after each superstep; `updates` each task's
|
|
722
|
+
* write; `messages` model output as nodes stream it; `tools` tool calls; `tasks` each task
|
|
723
|
+
* starting, retrying, failing, and ending; `checkpoints` each write; `custom` what nodes emit.
|
|
724
|
+
*/
|
|
725
|
+
export type GraphStreamProjection = 'values' | 'updates' | 'messages' | 'tools' | 'tasks' | 'checkpoints' | 'custom';
|
|
726
|
+
/** One event of `events()`, tagged by its projection. */
|
|
727
|
+
export type GraphStreamEvent<S extends ChannelSchema = ChannelSchema> = ({
|
|
728
|
+
type: 'values';
|
|
729
|
+
step: number;
|
|
730
|
+
status: GraphStatus;
|
|
731
|
+
state: StateOf<S>;
|
|
732
|
+
} | {
|
|
733
|
+
type: 'updates';
|
|
734
|
+
step: number;
|
|
735
|
+
node: string;
|
|
736
|
+
taskId: string;
|
|
737
|
+
update: unknown;
|
|
738
|
+
} | {
|
|
739
|
+
type: 'messages';
|
|
740
|
+
step: number;
|
|
741
|
+
node: string;
|
|
742
|
+
taskId: string;
|
|
743
|
+
chunk: GraphMessageChunk;
|
|
744
|
+
} | {
|
|
745
|
+
type: 'tools';
|
|
746
|
+
step: number;
|
|
747
|
+
node: string;
|
|
748
|
+
taskId: string;
|
|
749
|
+
tool: GraphToolEvent;
|
|
750
|
+
} | {
|
|
751
|
+
type: 'tasks';
|
|
752
|
+
event: Extract<GraphEvent, {
|
|
753
|
+
type: 'task_start' | 'task_retry' | 'task_failed' | 'task_end';
|
|
754
|
+
}>;
|
|
755
|
+
} | {
|
|
756
|
+
type: 'checkpoints';
|
|
757
|
+
step: number;
|
|
758
|
+
status: GraphStatus;
|
|
759
|
+
next: string[];
|
|
760
|
+
} | {
|
|
761
|
+
type: 'custom';
|
|
762
|
+
step: number;
|
|
763
|
+
node: string;
|
|
764
|
+
taskId: string;
|
|
765
|
+
data: unknown;
|
|
766
|
+
}) & {
|
|
767
|
+
/** The subgraph nodes it came through, outermost first. Empty for the graph's own events. */
|
|
768
|
+
namespace: string[];
|
|
483
769
|
};
|
|
770
|
+
/**
|
|
771
|
+
* What an event stream does when a reader falls behind within a superstep. At the end of each
|
|
772
|
+
* superstep the run waits for its slowest reader, whatever the policy, so a slow reader slows the
|
|
773
|
+
* graph down rather than filling memory.
|
|
774
|
+
*
|
|
775
|
+
* - `coalesce` (the default) merges a model chunk into the one before it from the same task, and a
|
|
776
|
+
* state snapshot into the one before it; when nothing can merge, the oldest event goes.
|
|
777
|
+
* - `drop-oldest` and `drop-newest` lose events, and count them.
|
|
778
|
+
* - `error` ends the stream with `GraphStreamOverflowError` and stops the run.
|
|
779
|
+
*/
|
|
780
|
+
export type GraphStreamOverflow = 'coalesce' | 'drop-oldest' | 'drop-newest' | 'error';
|
|
781
|
+
/** Options for `events()`: the run's own options, what to include, and how much to buffer. */
|
|
782
|
+
export interface GraphEventsOptions extends GraphRunOptions {
|
|
783
|
+
/** Projections to include. Defaults to `values`, `updates`, `messages`, `tools`, and `custom`. */
|
|
784
|
+
include?: GraphStreamProjection[];
|
|
785
|
+
/** Includes the events of subgraphs, with their `namespace`. Defaults to false. */
|
|
786
|
+
subgraphs?: boolean;
|
|
787
|
+
/** Events each reader holds before `overflow` applies. Defaults to 1,000. */
|
|
788
|
+
maxBuffered?: number;
|
|
789
|
+
/** What happens when a reader's buffer is full. Defaults to `coalesce`. */
|
|
790
|
+
overflow?: GraphStreamOverflow;
|
|
791
|
+
}
|
|
792
|
+
/** What an event stream did to keep up with its slowest reader. */
|
|
793
|
+
export interface GraphStreamStats {
|
|
794
|
+
/** The most events any reader held at once. */
|
|
795
|
+
peak: number;
|
|
796
|
+
/** Events merged into another. */
|
|
797
|
+
coalesced: number;
|
|
798
|
+
/** Events lost. */
|
|
799
|
+
dropped: number;
|
|
800
|
+
}
|
|
484
801
|
/** One superstep, as seen by `stream()`. */
|
|
485
802
|
export interface GraphStepEvent<S extends ChannelSchema> {
|
|
486
803
|
/**
|
|
@@ -506,6 +823,8 @@ export interface GraphStepEvent<S extends ChannelSchema> {
|
|
|
506
823
|
interrupts?: PendingInterrupt[];
|
|
507
824
|
/** The breakpoint the step stopped at. */
|
|
508
825
|
breakpoint?: GraphBreakpoint;
|
|
826
|
+
/** Failures in this step that a node's `onError` recovered from. */
|
|
827
|
+
recovered?: RecoveredFailure[];
|
|
509
828
|
/** A `Command.PARENT` that ended this run, for the graph that contains it. In memory only. */
|
|
510
829
|
parentCommand?: Command;
|
|
511
830
|
}
|
|
@@ -523,7 +842,15 @@ export interface GraphDescription {
|
|
|
523
842
|
ends?: string[];
|
|
524
843
|
defer?: boolean;
|
|
525
844
|
retry?: boolean;
|
|
845
|
+
/** Attempts its retry policy allows, when more than one. */
|
|
846
|
+
maxAttempts?: number;
|
|
526
847
|
timeoutMs?: number;
|
|
848
|
+
/** Its run and idle limits, when it has either. */
|
|
849
|
+
timeout?: NodeTimeout;
|
|
850
|
+
/** True when the node recovers from failure through `onError`. */
|
|
851
|
+
onError?: boolean;
|
|
852
|
+
/** True when the node is declared safe to run twice. */
|
|
853
|
+
idempotent?: boolean;
|
|
527
854
|
/** True when the node reuses results through `cache`. */
|
|
528
855
|
cache?: boolean;
|
|
529
856
|
/** The graph this node runs, when it is a compiled graph used through `asNode()`. */
|
|
@@ -543,6 +870,12 @@ export interface GraphDescription {
|
|
|
543
870
|
input?: string[];
|
|
544
871
|
/** Channels a caller gets back, when the graph restricts them. */
|
|
545
872
|
output?: string[];
|
|
873
|
+
/** When checkpoints are written. */
|
|
874
|
+
durability?: DurabilityMode;
|
|
875
|
+
/** Where checkpoints go: the in-process default, a store the application passed, or nowhere. */
|
|
876
|
+
checkpointer?: 'memory' | 'custom' | 'none';
|
|
877
|
+
/** Tasks a superstep runs at once. */
|
|
878
|
+
maxConcurrency?: number;
|
|
546
879
|
}
|
|
547
880
|
/**
|
|
548
881
|
* Options applied when a graph is compiled: stores, breakpoints, concurrency, retries, and failure
|
|
@@ -565,6 +898,18 @@ export interface CompileOptions {
|
|
|
565
898
|
maxConcurrency?: number;
|
|
566
899
|
/** Default retry policy for every node. A node's own policy wins. */
|
|
567
900
|
retry?: RetryPolicy;
|
|
901
|
+
/**
|
|
902
|
+
* Defaults for every node: a retry policy, timeouts, and an `onError`. A node's own options win,
|
|
903
|
+
* field by field. `retry` here is the same as `compile({ retry })`, and wins over it.
|
|
904
|
+
*/
|
|
905
|
+
nodeDefaults?: Pick<NodeOptions, 'retry' | 'timeout' | 'onError'>;
|
|
906
|
+
/** When checkpoints are written: `sync` (the default), `async`, or `exit`. See `DurabilityMode`. */
|
|
907
|
+
durability?: DurabilityMode;
|
|
908
|
+
/**
|
|
909
|
+
* Checkpoint writes `async` durability keeps in flight before the graph waits for the store to
|
|
910
|
+
* catch up. Defaults to 8. Bounds what a slow store can cost in memory.
|
|
911
|
+
*/
|
|
912
|
+
maxPendingWrites?: number;
|
|
568
913
|
/**
|
|
569
914
|
* What happens to sibling tasks when one fails. `fail-fast` (the default) aborts their signals;
|
|
570
915
|
* `settle` lets them finish, which is worth it when their work is expensive to repeat.
|
package/dist/types/graph.js
CHANGED
package/dist/types/messages.d.ts
CHANGED
|
@@ -257,6 +257,11 @@ export interface CompletionRequest {
|
|
|
257
257
|
reasoning?: ReasoningConfig;
|
|
258
258
|
/** Provider-side prompt caching controls. */
|
|
259
259
|
cache?: PromptCacheConfig;
|
|
260
|
+
/**
|
|
261
|
+
* Skips this client's response cache for this request: `bypass` neither reads nor writes it, and
|
|
262
|
+
* `refresh` skips the read and stores the fresh answer. Either is recorded as a `bypass` outcome.
|
|
263
|
+
*/
|
|
264
|
+
responseCache?: 'bypass' | 'refresh';
|
|
260
265
|
/**
|
|
261
266
|
* Overrides the configured capability policy for this request. `'strict'` fails on an option the
|
|
262
267
|
* model cannot honor, `'warn'` drops it and records a warning, and `'off'` sends the request
|
|
@@ -158,6 +158,11 @@ export interface OperationRecord<TResult = unknown> {
|
|
|
158
158
|
lease?: OperationLease;
|
|
159
159
|
/** The latest progress reported. */
|
|
160
160
|
progress?: OperationProgress;
|
|
161
|
+
/**
|
|
162
|
+
* What the executor last passed to `context.heartbeat()`, such as the last row it processed. Kept
|
|
163
|
+
* across attempts, so a retry can resume from it. Must be serializable.
|
|
164
|
+
*/
|
|
165
|
+
heartbeatDetails?: unknown;
|
|
161
166
|
/** The result, once it succeeded. Must be serializable; bytes belong in an asset store. */
|
|
162
167
|
result?: TResult;
|
|
163
168
|
/** The failure, once it failed. */
|
|
@@ -168,6 +173,8 @@ export interface OperationRecord<TResult = unknown> {
|
|
|
168
173
|
idempotencyKey?: string;
|
|
169
174
|
/** Family and operation, such as `image.generate`, for filtering and metrics. */
|
|
170
175
|
kind?: string;
|
|
176
|
+
/** The tenant it belongs to. A tenant-scoped store reads and lists only its own. */
|
|
177
|
+
tenantId?: string;
|
|
171
178
|
/** Trace propagation headers, carried to the worker that runs it. */
|
|
172
179
|
traceContext?: Record<string, string>;
|
|
173
180
|
/** Application data. Must be serializable. */
|
|
@@ -212,6 +219,8 @@ export interface OperationStore<TResult = unknown> {
|
|
|
212
219
|
export interface OperationStoreFilter {
|
|
213
220
|
/** Only records whose `kind` starts with this, such as `assistant:` for the agent server's runs. */
|
|
214
221
|
kindPrefix?: string;
|
|
222
|
+
/** Only records of this tenant. Postgres and SQLite read it through an index on queued work. */
|
|
223
|
+
tenantId?: string;
|
|
215
224
|
}
|
|
216
225
|
/** What an operation store holds, counted: the numbers a queue dashboard and an autoscaler read. */
|
|
217
226
|
export interface OperationStoreStats {
|
|
@@ -300,6 +309,8 @@ export interface OperationSubmitOptions {
|
|
|
300
309
|
id?: string;
|
|
301
310
|
/** Family and operation, such as `image.generate`. */
|
|
302
311
|
kind?: string;
|
|
312
|
+
/** The tenant it belongs to, recorded on the operation. */
|
|
313
|
+
tenantId?: string;
|
|
303
314
|
/** Replays the operation already accepted under this key instead of starting another. */
|
|
304
315
|
idempotencyKey?: string;
|
|
305
316
|
/** Overrides the runner's attempt budget for this operation. */
|
|
@@ -327,8 +338,17 @@ export interface OperationContext {
|
|
|
327
338
|
signal: AbortSignal;
|
|
328
339
|
/** Publishes a progress event and persists it. */
|
|
329
340
|
report(progress: OperationProgress): void;
|
|
330
|
-
/**
|
|
331
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Extends the lease immediately, for a step known to exceed the heartbeat interval. `details`, when
|
|
343
|
+
* given, is stored with the record and handed to the next attempt as `previousHeartbeat`, so work
|
|
344
|
+
* that fails halfway can resume where it was instead of starting over.
|
|
345
|
+
*/
|
|
346
|
+
heartbeat(details?: unknown): Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* The `details` an earlier attempt last passed to `heartbeat()`. Undefined on a first attempt,
|
|
349
|
+
* and when no attempt passed any.
|
|
350
|
+
*/
|
|
351
|
+
previousHeartbeat?: unknown;
|
|
332
352
|
/** Trace propagation headers from submission. */
|
|
333
353
|
traceContext?: Record<string, string>;
|
|
334
354
|
/** Application data from submission. */
|
package/dist/types/response.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface ResponseMeta {
|
|
|
72
72
|
capabilityWarnings?: CapabilityWarning[];
|
|
73
73
|
/** True when the response came from the response cache and no provider was called. */
|
|
74
74
|
cacheHit: boolean;
|
|
75
|
+
/** What the response cache did for this request, and why. Present when the cache is enabled. */
|
|
76
|
+
cache?: CacheOutcome;
|
|
75
77
|
/** Guardrails and techniques applied, such as redaction, trimming, or a retry. */
|
|
76
78
|
guardrailsApplied: string[];
|
|
77
79
|
/** Why the router chose the provider, and how many fallbacks were available. */
|
|
@@ -164,3 +166,21 @@ export interface NexusStream extends AsyncIterable<StreamChunk> {
|
|
|
164
166
|
/** Stops the stream and the provider request behind it. */
|
|
165
167
|
abort(): void;
|
|
166
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* What the response cache did for one request: `hit` (answered from it), `miss` (looked, found
|
|
171
|
+
* nothing), `stale` (found an entry that had expired), `bypass` (the request skipped the lookup), or
|
|
172
|
+
* `error` (the cache failed, and the request went to the provider as on a miss). Recorded on
|
|
173
|
+
* `response.meta.cache` and on the request's trace.
|
|
174
|
+
*/
|
|
175
|
+
export interface CacheOutcome {
|
|
176
|
+
/** What happened. */
|
|
177
|
+
outcome: 'hit' | 'miss' | 'stale' | 'bypass' | 'error';
|
|
178
|
+
/** Which layer answered or was asked last: the exact cache or the semantic one. */
|
|
179
|
+
layer?: 'exact' | 'semantic';
|
|
180
|
+
/** Why, in a few words, such as `no entry for this request` or the cache's error message. */
|
|
181
|
+
reason: string;
|
|
182
|
+
/** The namespace the lookup ran in, when one applies. */
|
|
183
|
+
namespace?: string;
|
|
184
|
+
/** Set when storing the response failed; the response was still returned. */
|
|
185
|
+
writeError?: string;
|
|
186
|
+
}
|
package/dist/types/server.d.ts
CHANGED
|
@@ -334,6 +334,24 @@ export interface AssistantRunContext {
|
|
|
334
334
|
attempt?: number;
|
|
335
335
|
/** The revision serving the run, when the assistant has revisions. */
|
|
336
336
|
revision?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Set to draining when this replica drains and has a queue to hand work to. A graph served through
|
|
339
|
+
* `graphAssistant()` reads it as its `RunControl`: it finishes its superstep, writes its checkpoint,
|
|
340
|
+
* and stops, and another worker continues the run from there. A function assistant checks it between
|
|
341
|
+
* its own steps and throws `RunHandOffError` to hand the run off the same way.
|
|
342
|
+
*/
|
|
343
|
+
control?: {
|
|
344
|
+
readonly draining: boolean;
|
|
345
|
+
readonly reason?: string;
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Records how far the run got, such as the last item it finished, so the worker that continues it
|
|
349
|
+
* after a hand-off or a crash reads it as `progress` and carries on from there. Must be
|
|
350
|
+
* serializable. Extends the run's lease, as a heartbeat does.
|
|
351
|
+
*/
|
|
352
|
+
saveProgress?(details: unknown): Promise<void>;
|
|
353
|
+
/** What the run saved with `saveProgress()` before this attempt, on a later attempt. */
|
|
354
|
+
progress?: unknown;
|
|
337
355
|
/**
|
|
338
356
|
* Records US dollars the run spent, such as a model call's cost. The amount is added to the run's
|
|
339
357
|
* `cost` and to its tenant's budget; a budget that stops runs in flight cancels this one.
|
package/dist/types/tracing.d.ts
CHANGED
|
@@ -126,6 +126,17 @@ export interface TraceStore {
|
|
|
126
126
|
/** Removes runs older than a cutoff, returning how many went. */
|
|
127
127
|
prune?(before: string): Promise<number> | number;
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Receives every finished run a tracer keeps, after redaction, to send somewhere else: an
|
|
131
|
+
* OpenTelemetry collector, a log pipeline, a metrics rollup. An exporter that throws or rejects is
|
|
132
|
+
* reported through the tracer's `onError` and never fails the run.
|
|
133
|
+
*/
|
|
134
|
+
export interface TraceExporter {
|
|
135
|
+
/** Takes one finished run. */
|
|
136
|
+
export(run: Run): Promise<void> | void;
|
|
137
|
+
/** Sends anything batched. `Tracer.flush()` calls it. */
|
|
138
|
+
flush?(): Promise<void> | void;
|
|
139
|
+
}
|
|
129
140
|
/**
|
|
130
141
|
* What is removed from runs before they are stored, so a hidden field is never written anywhere.
|
|
131
142
|
*/
|