@anvia/client 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/durable.js CHANGED
@@ -1,259 +1,219 @@
1
- import {
2
- readSseStream
3
- } from "./chunk-PD72KNCV.js";
4
-
1
+ import { i as readSseStream } from "./streams-BXxF27Hp.js";
2
+ import { parseDurableEvent, parseDurableGraphEvent, parseDurableGraphPage, parseDurableGraphSnapshot, parseDurableRunPage, parseDurableSnapshot, parseDurableSteerReceipt, parseTaskEvent, parseTaskGraph, parseTaskPage, parseTaskSnapshot } from "@anvia/durable/protocol";
5
3
  // src/durable.ts
6
- import {
7
- parseTaskSnapshot,
8
- parseTaskGraph,
9
- parseTaskPage,
10
- parseTaskEvent
11
- } from "@anvia/durable/protocol";
12
- import {
13
- parseDurableEvent,
14
- parseDurableSteerReceipt,
15
- parseDurableGraphSnapshot,
16
- parseDurableGraphEvent,
17
- parseDurableGraphPage,
18
- parseDurableRunPage,
19
- parseDurableSnapshot
20
- } from "@anvia/durable/protocol";
21
4
  var DurableHttpError = class extends Error {
22
- constructor(status) {
23
- super(`Durable request failed with HTTP ${status}.`);
24
- this.status = status;
25
- this.name = "DurableHttpError";
26
- }
27
- status;
5
+ status;
6
+ code;
7
+ field;
8
+ constructor(status, code, field, message) {
9
+ super(message ?? `Durable request failed with HTTP ${status}.`);
10
+ this.status = status;
11
+ this.code = code;
12
+ this.field = field;
13
+ this.name = "DurableHttpError";
14
+ }
28
15
  };
16
+ /** Error bodies are best-effort: a non-JSON or oversized body must not mask the status. */
17
+ async function durableErrorBody(response) {
18
+ let text;
19
+ try {
20
+ text = await response.text();
21
+ } catch {
22
+ return {};
23
+ }
24
+ if (text.length === 0 || text.length > 8192) return {};
25
+ let body;
26
+ try {
27
+ body = JSON.parse(text);
28
+ } catch {
29
+ return {};
30
+ }
31
+ if (typeof body !== "object" || body === null) return {};
32
+ const record = body;
33
+ const details = {};
34
+ if (typeof record.error === "string") details.message = record.error;
35
+ if (typeof record.code === "string") details.code = record.code;
36
+ if (typeof record.field === "string") details.field = record.field;
37
+ return details;
38
+ }
39
+ /** Browser-safe HTTP client. Reconnect explicitly using a snapshot or last applied event cursor. */
29
40
  var DurableClient = class {
30
- constructor(options) {
31
- this.options = options;
32
- const endpoint = new URL(options.endpoint);
33
- if (!["http:", "https:"].includes(endpoint.protocol) || endpoint.search || endpoint.hash || endpoint.username || endpoint.password)
34
- throw new TypeError(
35
- "endpoint must be an HTTP(S) base URL without credentials, query, or fragment."
36
- );
37
- this.endpoint = endpoint.href.replace(/\/$/, "");
38
- }
39
- options;
40
- endpoint;
41
- async submitTask(submission, options = {}) {
42
- return parseTaskSnapshot(
43
- await (await this.request("/tasks", "POST", submission, options)).json()
44
- );
45
- }
46
- async taskSnapshot(id, options = {}) {
47
- const snapshot = parseTaskSnapshot(
48
- await (await this.request(this.taskPath(id), "GET", void 0, options)).json()
49
- );
50
- if (snapshot.task.id !== id) throw new TypeError("Snapshot belongs to another task.");
51
- return snapshot;
52
- }
53
- async taskGraph(id, options = {}) {
54
- const graph = parseTaskGraph(
55
- await (await this.request(`${this.taskPath(id)}/graph`, "GET", void 0, options)).json()
56
- );
57
- if (!graph.nodes.some((task) => task.id === id))
58
- throw new TypeError("Graph belongs to another task.");
59
- return graph;
60
- }
61
- async listTasks(filter, options = {}) {
62
- const query = new URLSearchParams();
63
- for (const [key, value] of Object.entries(filter))
64
- if (value !== void 0) query.set(key, String(value));
65
- return parseTaskPage(
66
- await (await this.request(`/tasks?${query}`, "GET", void 0, options)).json()
67
- );
68
- }
69
- async signalTask(id, name, requestId, value, options = {}) {
70
- await this.request(`${this.taskPath(id)}/signal`, "POST", { name, requestId, value }, options);
71
- }
72
- async resolveEffect(id, key, value, options = {}) {
73
- await this.request(`${this.taskPath(id)}/resolve-effect`, "POST", { key, value }, options);
74
- }
75
- async retryTask(id, options = {}) {
76
- await this.request(`${this.taskPath(id)}/retry`, "POST", void 0, options);
77
- }
78
- async cancelTask(id, options = {}) {
79
- await this.request(`${this.taskPath(id)}/cancel`, "POST", void 0, options);
80
- }
81
- async *streamTask(id, options = {}) {
82
- let cursor = options.after ?? 0;
83
- if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError("Invalid task cursor.");
84
- const snapshot = await this.taskSnapshot(id, options);
85
- const response = await this.request(
86
- `${this.taskPath(id)}/events?after=${cursor}`,
87
- "GET",
88
- void 0,
89
- options
90
- );
91
- if (!response.headers.get("content-type")?.startsWith("text/event-stream") || response.body === null)
92
- throw new TypeError("Expected a task SSE response.");
93
- for await (const value of readSseStream(response.body, { strict: true })) {
94
- options.abortSignal?.throwIfAborted();
95
- const event = parseTaskEvent(value);
96
- if (event.rootId !== snapshot.task.rootId || event.sequence <= cursor)
97
- throw new TypeError("Invalid task event order or root ID.");
98
- cursor = event.sequence;
99
- yield event;
100
- }
101
- }
102
- taskPath(id) {
103
- if (id.trim().length === 0 || id === "." || id === "..") throw new TypeError("Invalid taskId.");
104
- return `/tasks/${encodeURIComponent(id)}`;
105
- }
106
- async submitGraph(submission, options = {}) {
107
- return parseDurableGraphSnapshot(
108
- await (await this.request("/graphs", "POST", submission, options)).json()
109
- );
110
- }
111
- async graphSnapshot(graphId, options = {}) {
112
- const snapshot = parseDurableGraphSnapshot(
113
- await (await this.request(this.graphPath(graphId), "GET", void 0, options)).json()
114
- );
115
- if (snapshot.id !== graphId) throw new TypeError("Snapshot belongs to another graph.");
116
- return snapshot;
117
- }
118
- async listGraphs(filter, options = {}) {
119
- const query = new URLSearchParams();
120
- for (const [key, value] of Object.entries(filter))
121
- if (value !== void 0) query.set(key, String(value));
122
- return parseDurableGraphPage(
123
- await (await this.request(`/graphs?${query}`, "GET", void 0, options)).json()
124
- );
125
- }
126
- async cancelGraph(graphId, options = {}) {
127
- await this.request(`${this.graphPath(graphId)}/cancel`, "POST", void 0, options);
128
- }
129
- async *streamGraph(graphId, options = {}) {
130
- let cursor = options.after ?? 0;
131
- if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError("Invalid graph cursor.");
132
- const response = await this.request(
133
- `${this.graphPath(graphId)}/events?after=${cursor}`,
134
- "GET",
135
- void 0,
136
- options
137
- );
138
- if (!response.headers.get("content-type")?.startsWith("text/event-stream") || response.body === null)
139
- throw new TypeError("Expected a graph SSE response.");
140
- for await (const value of readSseStream(response.body, { strict: true })) {
141
- options.abortSignal?.throwIfAborted();
142
- const event = parseDurableGraphEvent(value);
143
- if (event.graphId !== graphId || event.sequence <= cursor)
144
- throw new TypeError("Invalid graph event order or ID.");
145
- cursor = event.sequence;
146
- yield event;
147
- }
148
- }
149
- async submit(submission, options = {}) {
150
- const body = { ...submission };
151
- if (options.enqueue !== void 0) {
152
- body.enqueue = options.enqueue;
153
- }
154
- const response = await this.request("/runs", "POST", body, options);
155
- return parseDurableSnapshot(await response.json());
156
- }
157
- async listRuns(filter, options = {}) {
158
- const query = new URLSearchParams();
159
- for (const [key, value] of Object.entries(filter))
160
- if (value !== void 0) query.set(key, String(value));
161
- return parseDurableRunPage(
162
- await (await this.request(`/runs?${query}`, "GET", void 0, options)).json()
163
- );
164
- }
165
- async snapshot(runId, options = {}) {
166
- const snapshot = parseDurableSnapshot(
167
- await (await this.request(this.path(runId), "GET", void 0, options)).json()
168
- );
169
- if (snapshot.run.id !== runId) throw new TypeError("Durable snapshot belongs to another run.");
170
- return snapshot;
171
- }
172
- async *stream(runId, options = {}) {
173
- let cursor = options.after ?? 0;
174
- if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError("Invalid event cursor.");
175
- const response = await this.request(
176
- `${this.path(runId)}/events?after=${cursor}`,
177
- "GET",
178
- void 0,
179
- options
180
- );
181
- if (!response.headers.get("content-type")?.startsWith("text/event-stream") || response.body === null)
182
- throw new TypeError("Expected a durable SSE response.");
183
- for await (const value of readSseStream(response.body, { strict: true })) {
184
- options.abortSignal?.throwIfAborted();
185
- const event = parseDurableEvent(value);
186
- if (event.runId !== runId || event.sequence <= cursor)
187
- throw new TypeError("Invalid durable event order or run ID.");
188
- cursor = event.sequence;
189
- yield event;
190
- }
191
- }
192
- async steer(runId, input, options = {}) {
193
- const path = `${this.path(runId)}/steer`;
194
- const body = { input };
195
- if (options.requestId !== void 0) {
196
- body.requestId = options.requestId;
197
- }
198
- const response = await this.request(path, "POST", body, options);
199
- return parseDurableSteerReceipt(await response.json());
200
- }
201
- async respond(runId, interactionId, response, options = {}) {
202
- await this.request(`${this.path(runId)}/respond`, "POST", { interactionId, response }, options);
203
- }
204
- async resolveTool(runId, operationId, output, options = {}) {
205
- await this.request(
206
- `${this.path(runId)}/resolve-tool`,
207
- "POST",
208
- { operationId, output },
209
- options
210
- );
211
- }
212
- async retry(runId, options = {}) {
213
- await this.request(`${this.path(runId)}/retry`, "POST", void 0, options);
214
- }
215
- async cancel(runId, options = {}) {
216
- await this.request(`${this.path(runId)}/cancel`, "POST", void 0, options);
217
- }
218
- graphPath(id) {
219
- if (id.trim().length === 0 || id === "." || id === "..")
220
- throw new TypeError("Invalid graphId.");
221
- return `/graphs/${encodeURIComponent(id)}`;
222
- }
223
- path(id) {
224
- if (id.trim().length === 0) throw new TypeError("runId must not be empty.");
225
- return `/runs/${encodeURIComponent(id)}`;
226
- }
227
- async request(path, method, body, options) {
228
- options.abortSignal?.throwIfAborted();
229
- const supplied = typeof this.options.headers === "function" ? await this.options.headers() : this.options.headers;
230
- const headers = new Headers(supplied);
231
- if (body !== void 0) headers.set("content-type", "application/json");
232
- const fetch = this.options.fetch ?? globalThis.fetch;
233
- const url = `${this.endpoint}${path}`;
234
- const init = {
235
- method,
236
- headers
237
- };
238
- if (body !== void 0) {
239
- init.body = JSON.stringify(body);
240
- }
241
- if (options.abortSignal !== void 0) {
242
- init.signal = options.abortSignal;
243
- }
244
- if (this.options.credentials !== void 0) {
245
- init.credentials = this.options.credentials;
246
- }
247
- const response = await fetch(url, init);
248
- if (!response.ok) {
249
- await response.body?.cancel();
250
- throw new DurableHttpError(response.status);
251
- }
252
- return response;
253
- }
254
- };
255
- export {
256
- DurableClient,
257
- DurableHttpError
41
+ options;
42
+ endpoint;
43
+ constructor(options) {
44
+ this.options = options;
45
+ const endpoint = new URL(options.endpoint);
46
+ if (!["http:", "https:"].includes(endpoint.protocol) || endpoint.search || endpoint.hash || endpoint.username || endpoint.password) throw new TypeError("endpoint must be an HTTP(S) base URL without credentials, query, or fragment.");
47
+ this.endpoint = endpoint.href.replace(/\/$/, "");
48
+ }
49
+ async submitTask(submission, options = {}) {
50
+ return parseTaskSnapshot(await (await this.request("/tasks", "POST", submission, options)).json());
51
+ }
52
+ async taskSnapshot(id, options = {}) {
53
+ const snapshot = parseTaskSnapshot(await (await this.request(this.taskPath(id), "GET", void 0, options)).json());
54
+ if (snapshot.task.id !== id) throw new TypeError("Snapshot belongs to another task.");
55
+ return snapshot;
56
+ }
57
+ async taskGraph(id, options = {}) {
58
+ const graph = parseTaskGraph(await (await this.request(`${this.taskPath(id)}/graph`, "GET", void 0, options)).json());
59
+ if (!graph.nodes.some((task) => task.id === id)) throw new TypeError("Graph belongs to another task.");
60
+ return graph;
61
+ }
62
+ async listTasks(filter, options = {}) {
63
+ const query = new URLSearchParams();
64
+ for (const [key, value] of Object.entries(filter)) if (value !== void 0) query.set(key, String(value));
65
+ return parseTaskPage(await (await this.request(`/tasks?${query}`, "GET", void 0, options)).json());
66
+ }
67
+ async signalTask(id, name, requestId, value, options = {}) {
68
+ await this.request(`${this.taskPath(id)}/signal`, "POST", {
69
+ name,
70
+ requestId,
71
+ value
72
+ }, options);
73
+ }
74
+ async resolveEffect(id, key, value, options = {}) {
75
+ await this.request(`${this.taskPath(id)}/resolve-effect`, "POST", {
76
+ key,
77
+ value
78
+ }, options);
79
+ }
80
+ async retryTask(id, options = {}) {
81
+ await this.request(`${this.taskPath(id)}/retry`, "POST", void 0, options);
82
+ }
83
+ async cancelTask(id, options = {}) {
84
+ await this.request(`${this.taskPath(id)}/cancel`, "POST", void 0, options);
85
+ }
86
+ async *streamTask(id, options = {}) {
87
+ let cursor = options.after ?? 0;
88
+ if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError("Invalid task cursor.");
89
+ const snapshot = await this.taskSnapshot(id, options);
90
+ const response = await this.request(`${this.taskPath(id)}/events?after=${cursor}`, "GET", void 0, options);
91
+ if (!response.headers.get("content-type")?.startsWith("text/event-stream") || response.body === null) throw new TypeError("Expected a task SSE response.");
92
+ for await (const value of readSseStream(response.body, { strict: true })) {
93
+ options.abortSignal?.throwIfAborted();
94
+ const event = parseTaskEvent(value);
95
+ if (event.rootId !== snapshot.task.rootId || event.sequence <= cursor) throw new TypeError("Invalid task event order or root ID.");
96
+ cursor = event.sequence;
97
+ yield event;
98
+ }
99
+ }
100
+ taskPath(id) {
101
+ if (id.trim().length === 0 || id === "." || id === "..") throw new TypeError("Invalid taskId.");
102
+ return `/tasks/${encodeURIComponent(id)}`;
103
+ }
104
+ async submitGraph(submission, options = {}) {
105
+ return parseDurableGraphSnapshot(await (await this.request("/graphs", "POST", submission, options)).json());
106
+ }
107
+ async graphSnapshot(graphId, options = {}) {
108
+ const snapshot = parseDurableGraphSnapshot(await (await this.request(this.graphPath(graphId), "GET", void 0, options)).json());
109
+ if (snapshot.id !== graphId) throw new TypeError("Snapshot belongs to another graph.");
110
+ return snapshot;
111
+ }
112
+ async listGraphs(filter, options = {}) {
113
+ const query = new URLSearchParams();
114
+ for (const [key, value] of Object.entries(filter)) if (value !== void 0) query.set(key, String(value));
115
+ return parseDurableGraphPage(await (await this.request(`/graphs?${query}`, "GET", void 0, options)).json());
116
+ }
117
+ async cancelGraph(graphId, options = {}) {
118
+ await this.request(`${this.graphPath(graphId)}/cancel`, "POST", void 0, options);
119
+ }
120
+ async *streamGraph(graphId, options = {}) {
121
+ let cursor = options.after ?? 0;
122
+ if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError("Invalid graph cursor.");
123
+ const response = await this.request(`${this.graphPath(graphId)}/events?after=${cursor}`, "GET", void 0, options);
124
+ if (!response.headers.get("content-type")?.startsWith("text/event-stream") || response.body === null) throw new TypeError("Expected a graph SSE response.");
125
+ for await (const value of readSseStream(response.body, { strict: true })) {
126
+ options.abortSignal?.throwIfAborted();
127
+ const event = parseDurableGraphEvent(value);
128
+ if (event.graphId !== graphId || event.sequence <= cursor) throw new TypeError("Invalid graph event order or ID.");
129
+ cursor = event.sequence;
130
+ yield event;
131
+ }
132
+ }
133
+ async submit(submission, options = {}) {
134
+ const body = { ...submission };
135
+ if (options.enqueue !== void 0) body.enqueue = options.enqueue;
136
+ const response = await this.request("/runs", "POST", body, options);
137
+ return parseDurableSnapshot(await response.json());
138
+ }
139
+ async listRuns(filter, options = {}) {
140
+ const query = new URLSearchParams();
141
+ for (const [key, value] of Object.entries(filter)) if (value !== void 0) query.set(key, String(value));
142
+ return parseDurableRunPage(await (await this.request(`/runs?${query}`, "GET", void 0, options)).json());
143
+ }
144
+ async snapshot(runId, options = {}) {
145
+ const snapshot = parseDurableSnapshot(await (await this.request(this.path(runId), "GET", void 0, options)).json());
146
+ if (snapshot.run.id !== runId) throw new TypeError("Durable snapshot belongs to another run.");
147
+ return snapshot;
148
+ }
149
+ async *stream(runId, options = {}) {
150
+ let cursor = options.after ?? 0;
151
+ if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError("Invalid event cursor.");
152
+ const response = await this.request(`${this.path(runId)}/events?after=${cursor}`, "GET", void 0, options);
153
+ if (!response.headers.get("content-type")?.startsWith("text/event-stream") || response.body === null) throw new TypeError("Expected a durable SSE response.");
154
+ for await (const value of readSseStream(response.body, { strict: true })) {
155
+ options.abortSignal?.throwIfAborted();
156
+ const event = parseDurableEvent(value);
157
+ if (event.runId !== runId || event.sequence <= cursor) throw new TypeError("Invalid durable event order or run ID.");
158
+ cursor = event.sequence;
159
+ yield event;
160
+ }
161
+ }
162
+ async steer(runId, input, options = {}) {
163
+ const path = `${this.path(runId)}/steer`;
164
+ const body = { input };
165
+ if (options.requestId !== void 0) body.requestId = options.requestId;
166
+ const response = await this.request(path, "POST", body, options);
167
+ return parseDurableSteerReceipt(await response.json());
168
+ }
169
+ async respond(runId, interactionId, response, options = {}) {
170
+ await this.request(`${this.path(runId)}/respond`, "POST", {
171
+ interactionId,
172
+ response
173
+ }, options);
174
+ }
175
+ async resolveTool(runId, operationId, output, options = {}) {
176
+ await this.request(`${this.path(runId)}/resolve-tool`, "POST", {
177
+ operationId,
178
+ output
179
+ }, options);
180
+ }
181
+ async retry(runId, options = {}) {
182
+ await this.request(`${this.path(runId)}/retry`, "POST", void 0, options);
183
+ }
184
+ async cancel(runId, options = {}) {
185
+ await this.request(`${this.path(runId)}/cancel`, "POST", void 0, options);
186
+ }
187
+ graphPath(id) {
188
+ if (id.trim().length === 0 || id === "." || id === "..") throw new TypeError("Invalid graphId.");
189
+ return `/graphs/${encodeURIComponent(id)}`;
190
+ }
191
+ path(id) {
192
+ if (id.trim().length === 0) throw new TypeError("runId must not be empty.");
193
+ return `/runs/${encodeURIComponent(id)}`;
194
+ }
195
+ async request(path, method, body, options) {
196
+ options.abortSignal?.throwIfAborted();
197
+ const supplied = typeof this.options.headers === "function" ? await this.options.headers() : this.options.headers;
198
+ const headers = new Headers(supplied);
199
+ if (body !== void 0) headers.set("content-type", "application/json");
200
+ const fetch = this.options.fetch ?? globalThis.fetch;
201
+ const url = `${this.endpoint}${path}`;
202
+ const init = {
203
+ method,
204
+ headers
205
+ };
206
+ if (body !== void 0) init.body = JSON.stringify(body);
207
+ if (options.abortSignal !== void 0) init.signal = options.abortSignal;
208
+ if (this.options.credentials !== void 0) init.credentials = this.options.credentials;
209
+ const response = await fetch(url, init);
210
+ if (!response.ok) {
211
+ const details = await durableErrorBody(response);
212
+ throw new DurableHttpError(response.status, details.code, details.field, details.message);
213
+ }
214
+ return response;
215
+ }
258
216
  };
217
+ export { DurableClient, DurableHttpError };
218
+
259
219
  //# sourceMappingURL=durable.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/durable.ts"],"sourcesContent":["import {\n parseTaskSnapshot,\n parseTaskGraph,\n parseTaskPage,\n parseTaskEvent,\n type TaskSubmission,\n type TaskSnapshot,\n type TaskGraphSnapshot,\n type TaskPage,\n type TaskListOptions,\n type TaskEvent,\n} from \"@anvia/durable/protocol\";\nimport type { AgentSteerInput, AgentSteerReceipt } from \"@anvia/core/agent\";\nimport type { AgentInteractionResponse } from \"@anvia/core/agent/interactions\";\nimport type { JsonValue, ToolResultOutput } from \"@anvia/core/completion\";\nimport {\n parseDurableEvent,\n parseDurableSteerReceipt,\n type DurableSteerOptions,\n parseDurableGraphSnapshot,\n parseDurableGraphEvent,\n parseDurableGraphPage,\n type DurableGraphSubmission,\n type DurableGraphSnapshot,\n type DurableGraphListOptions,\n type DurableGraphPage,\n type DurableGraphEvent,\n parseDurableRunPage,\n parseDurableSnapshot,\n type DurableEvent,\n type DurableListOptions,\n type DurableRunPage,\n type DurableSnapshot,\n type DurableSubmission,\n type DurableSubmitOptions,\n} from \"@anvia/durable/protocol\";\nimport { readSseStream } from \"./transport/streams\";\n\nexport type DurableRequestOptions = { abortSignal?: AbortSignal };\nexport type DurableClientOptions = {\n /** Absolute HTTP(S) URL matching the server handler's basePath. */\n endpoint: string;\n fetch?: typeof fetch;\n headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);\n credentials?: RequestCredentials;\n};\nexport class DurableHttpError extends Error {\n constructor(readonly status: number) {\n super(`Durable request failed with HTTP ${status}.`);\n this.name = \"DurableHttpError\";\n }\n}\n\n/** Browser-safe HTTP client. Reconnect explicitly using a snapshot or last applied event cursor. */\nexport class DurableClient {\n private readonly endpoint: string;\n constructor(private readonly options: DurableClientOptions) {\n const endpoint = new URL(options.endpoint);\n if (\n ![\"http:\", \"https:\"].includes(endpoint.protocol) ||\n endpoint.search ||\n endpoint.hash ||\n endpoint.username ||\n endpoint.password\n )\n throw new TypeError(\n \"endpoint must be an HTTP(S) base URL without credentials, query, or fragment.\",\n );\n this.endpoint = endpoint.href.replace(/\\/$/, \"\");\n }\n\n async submitTask(\n /** Trace context is set by the server's `trace` hook. */\n submission: Omit<TaskSubmission, \"trace\">,\n options: DurableRequestOptions = {},\n ): Promise<TaskSnapshot> {\n return parseTaskSnapshot(\n await (await this.request(\"/tasks\", \"POST\", submission, options)).json(),\n );\n }\n async taskSnapshot(id: string, options: DurableRequestOptions = {}): Promise<TaskSnapshot> {\n const snapshot = parseTaskSnapshot(\n await (await this.request(this.taskPath(id), \"GET\", undefined, options)).json(),\n );\n if (snapshot.task.id !== id) throw new TypeError(\"Snapshot belongs to another task.\");\n return snapshot;\n }\n async taskGraph(id: string, options: DurableRequestOptions = {}): Promise<TaskGraphSnapshot> {\n const graph = parseTaskGraph(\n await (await this.request(`${this.taskPath(id)}/graph`, \"GET\", undefined, options)).json(),\n );\n if (!graph.nodes.some((task) => task.id === id))\n throw new TypeError(\"Graph belongs to another task.\");\n return graph;\n }\n async listTasks(\n filter: TaskListOptions & { sessionId: string },\n options: DurableRequestOptions = {},\n ): Promise<TaskPage> {\n const query = new URLSearchParams();\n for (const [key, value] of Object.entries(filter))\n if (value !== undefined) query.set(key, String(value));\n return parseTaskPage(\n await (await this.request(`/tasks?${query}`, \"GET\", undefined, options)).json(),\n );\n }\n async signalTask(\n id: string,\n name: string,\n requestId: string,\n value: JsonValue,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(`${this.taskPath(id)}/signal`, \"POST\", { name, requestId, value }, options);\n }\n async resolveEffect(\n id: string,\n key: string,\n value: JsonValue,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(`${this.taskPath(id)}/resolve-effect`, \"POST\", { key, value }, options);\n }\n async retryTask(id: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.taskPath(id)}/retry`, \"POST\", undefined, options);\n }\n async cancelTask(id: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.taskPath(id)}/cancel`, \"POST\", undefined, options);\n }\n async *streamTask(\n id: string,\n options: DurableRequestOptions & { after?: number } = {},\n ): AsyncIterable<TaskEvent> {\n let cursor = options.after ?? 0;\n if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError(\"Invalid task cursor.\");\n const snapshot = await this.taskSnapshot(id, options);\n const response = await this.request(\n `${this.taskPath(id)}/events?after=${cursor}`,\n \"GET\",\n undefined,\n options,\n );\n if (\n !response.headers.get(\"content-type\")?.startsWith(\"text/event-stream\") ||\n response.body === null\n )\n throw new TypeError(\"Expected a task SSE response.\");\n for await (const value of readSseStream<unknown>(response.body, { strict: true })) {\n options.abortSignal?.throwIfAborted();\n const event = parseTaskEvent(value);\n if (event.rootId !== snapshot.task.rootId || event.sequence <= cursor)\n throw new TypeError(\"Invalid task event order or root ID.\");\n cursor = event.sequence;\n yield event;\n }\n }\n private taskPath(id: string): string {\n if (id.trim().length === 0 || id === \".\" || id === \"..\") throw new TypeError(\"Invalid taskId.\");\n return `/tasks/${encodeURIComponent(id)}`;\n }\n\n async submitGraph(\n submission: DurableGraphSubmission,\n options: DurableRequestOptions = {},\n ): Promise<DurableGraphSnapshot> {\n return parseDurableGraphSnapshot(\n await (await this.request(\"/graphs\", \"POST\", submission, options)).json(),\n );\n }\n async graphSnapshot(\n graphId: string,\n options: DurableRequestOptions = {},\n ): Promise<DurableGraphSnapshot> {\n const snapshot = parseDurableGraphSnapshot(\n await (await this.request(this.graphPath(graphId), \"GET\", undefined, options)).json(),\n );\n if (snapshot.id !== graphId) throw new TypeError(\"Snapshot belongs to another graph.\");\n return snapshot;\n }\n async listGraphs(\n filter: DurableGraphListOptions & { sessionId: string },\n options: DurableRequestOptions = {},\n ): Promise<DurableGraphPage> {\n const query = new URLSearchParams();\n for (const [key, value] of Object.entries(filter))\n if (value !== undefined) query.set(key, String(value));\n return parseDurableGraphPage(\n await (await this.request(`/graphs?${query}`, \"GET\", undefined, options)).json(),\n );\n }\n async cancelGraph(graphId: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.graphPath(graphId)}/cancel`, \"POST\", undefined, options);\n }\n async *streamGraph(\n graphId: string,\n options: DurableRequestOptions & { after?: number } = {},\n ): AsyncIterable<DurableGraphEvent> {\n let cursor = options.after ?? 0;\n if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError(\"Invalid graph cursor.\");\n const response = await this.request(\n `${this.graphPath(graphId)}/events?after=${cursor}`,\n \"GET\",\n undefined,\n options,\n );\n if (\n !response.headers.get(\"content-type\")?.startsWith(\"text/event-stream\") ||\n response.body === null\n )\n throw new TypeError(\"Expected a graph SSE response.\");\n for await (const value of readSseStream<unknown>(response.body, { strict: true })) {\n options.abortSignal?.throwIfAborted();\n const event = parseDurableGraphEvent(value);\n if (event.graphId !== graphId || event.sequence <= cursor)\n throw new TypeError(\"Invalid graph event order or ID.\");\n cursor = event.sequence;\n yield event;\n }\n }\n\n async submit(\n /** Trace context is set by the server's `trace` hook. */\n submission: Omit<DurableSubmission, \"trace\">,\n options: DurableSubmitOptions & DurableRequestOptions = {},\n ): Promise<DurableSnapshot> {\n const body: Omit<DurableSubmission, \"trace\"> & DurableSubmitOptions = { ...submission };\n\n if (options.enqueue !== undefined) {\n body.enqueue = options.enqueue;\n }\n\n const response = await this.request(\"/runs\", \"POST\", body, options);\n\n return parseDurableSnapshot(await response.json());\n }\n\n async listRuns(\n filter: DurableListOptions & { sessionId: string },\n options: DurableRequestOptions = {},\n ): Promise<DurableRunPage> {\n const query = new URLSearchParams();\n for (const [key, value] of Object.entries(filter))\n if (value !== undefined) query.set(key, String(value));\n return parseDurableRunPage(\n await (await this.request(`/runs?${query}`, \"GET\", undefined, options)).json(),\n );\n }\n async snapshot(runId: string, options: DurableRequestOptions = {}): Promise<DurableSnapshot> {\n const snapshot = parseDurableSnapshot(\n await (await this.request(this.path(runId), \"GET\", undefined, options)).json(),\n );\n if (snapshot.run.id !== runId) throw new TypeError(\"Durable snapshot belongs to another run.\");\n return snapshot;\n }\n async *stream(\n runId: string,\n options: DurableRequestOptions & { after?: number } = {},\n ): AsyncIterable<DurableEvent> {\n let cursor = options.after ?? 0;\n if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError(\"Invalid event cursor.\");\n const response = await this.request(\n `${this.path(runId)}/events?after=${cursor}`,\n \"GET\",\n undefined,\n options,\n );\n if (\n !response.headers.get(\"content-type\")?.startsWith(\"text/event-stream\") ||\n response.body === null\n )\n throw new TypeError(\"Expected a durable SSE response.\");\n for await (const value of readSseStream<unknown>(response.body, { strict: true })) {\n options.abortSignal?.throwIfAborted();\n const event = parseDurableEvent(value);\n if (event.runId !== runId || event.sequence <= cursor)\n throw new TypeError(\"Invalid durable event order or run ID.\");\n cursor = event.sequence;\n yield event;\n }\n }\n async steer(\n runId: string,\n input: AgentSteerInput,\n options: DurableSteerOptions & DurableRequestOptions = {},\n ): Promise<AgentSteerReceipt> {\n const path = `${this.path(runId)}/steer`;\n const body: { input: AgentSteerInput; requestId?: string } = { input };\n\n if (options.requestId !== undefined) {\n body.requestId = options.requestId;\n }\n\n const response = await this.request(path, \"POST\", body, options);\n\n return parseDurableSteerReceipt(await response.json());\n }\n\n async respond(\n runId: string,\n interactionId: string,\n response: AgentInteractionResponse,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(`${this.path(runId)}/respond`, \"POST\", { interactionId, response }, options);\n }\n async resolveTool(\n runId: string,\n operationId: string,\n output: ToolResultOutput,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(\n `${this.path(runId)}/resolve-tool`,\n \"POST\",\n { operationId, output },\n options,\n );\n }\n async retry(runId: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.path(runId)}/retry`, \"POST\", undefined, options);\n }\n async cancel(runId: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.path(runId)}/cancel`, \"POST\", undefined, options);\n }\n\n private graphPath(id: string): string {\n if (id.trim().length === 0 || id === \".\" || id === \"..\")\n throw new TypeError(\"Invalid graphId.\");\n return `/graphs/${encodeURIComponent(id)}`;\n }\n private path(id: string): string {\n if (id.trim().length === 0) throw new TypeError(\"runId must not be empty.\");\n return `/runs/${encodeURIComponent(id)}`;\n }\n private async request(\n path: string,\n method: string,\n body: unknown,\n options: DurableRequestOptions,\n ): Promise<Response> {\n options.abortSignal?.throwIfAborted();\n const supplied =\n typeof this.options.headers === \"function\"\n ? await this.options.headers()\n : this.options.headers;\n const headers = new Headers(supplied);\n if (body !== undefined) headers.set(\"content-type\", \"application/json\");\n\n const fetch = this.options.fetch ?? globalThis.fetch;\n const url = `${this.endpoint}${path}`;\n const init: RequestInit = {\n method,\n headers,\n };\n\n if (body !== undefined) {\n init.body = JSON.stringify(body);\n }\n\n if (options.abortSignal !== undefined) {\n init.signal = options.abortSignal;\n }\n\n if (this.options.credentials !== undefined) {\n init.credentials = this.options.credentials;\n }\n\n const response = await fetch(url, init);\n if (!response.ok) {\n await response.body?.cancel();\n throw new DurableHttpError(response.status);\n }\n return response;\n }\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAMA;AAAA,EACA;AAAA,OAOK;AAWA,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAqB,QAAgB;AACnC,UAAM,oCAAoC,MAAM,GAAG;AADhC;AAEnB,SAAK,OAAO;AAAA,EACd;AAAA,EAHqB;AAIvB;AAGO,IAAM,gBAAN,MAAoB;AAAA,EAEzB,YAA6B,SAA+B;AAA/B;AAC3B,UAAM,WAAW,IAAI,IAAI,QAAQ,QAAQ;AACzC,QACE,CAAC,CAAC,SAAS,QAAQ,EAAE,SAAS,SAAS,QAAQ,KAC/C,SAAS,UACT,SAAS,QACT,SAAS,YACT,SAAS;AAET,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,SAAK,WAAW,SAAS,KAAK,QAAQ,OAAO,EAAE;AAAA,EACjD;AAAA,EAb6B;AAAA,EADZ;AAAA,EAgBjB,MAAM,WAE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K,SAAS,QAAQ;AAAA,IACxB;AAEA,QAAI,KAAK,QAAQ,gBAAgB,QAAW;AAC1C,WAAK,cAAc,KAAK,QAAQ;AAAA,IAClC;AAEA,UAAM,WAAW,MAAM,MAAM,KAAK,IAAI;AACtC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,SAAS,MAAM,OAAO;AAC5B,YAAM,IAAI,iBAAiB,SAAS,MAAM;AAAA,IAC5C;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"file":"durable.js","names":[],"sources":["../src/durable.ts"],"sourcesContent":["import {\n parseTaskSnapshot,\n parseTaskGraph,\n parseTaskPage,\n parseTaskEvent,\n type TaskSubmission,\n type TaskSnapshot,\n type TaskGraphSnapshot,\n type TaskPage,\n type TaskListOptions,\n type TaskEvent,\n} from \"@anvia/durable/protocol\";\nimport type { AgentSteerInput, AgentSteerReceipt } from \"@anvia/core/agent\";\nimport type { AgentInteractionResponse } from \"@anvia/core/agent/interactions\";\nimport type { JsonValue, ToolResultOutput } from \"@anvia/core/completion\";\nimport {\n parseDurableEvent,\n parseDurableSteerReceipt,\n type DurableSteerOptions,\n parseDurableGraphSnapshot,\n parseDurableGraphEvent,\n parseDurableGraphPage,\n type DurableGraphSubmission,\n type DurableGraphSnapshot,\n type DurableGraphListOptions,\n type DurableGraphPage,\n type DurableGraphEvent,\n parseDurableRunPage,\n parseDurableSnapshot,\n type DurableEvent,\n type DurableListOptions,\n type DurableRunPage,\n type DurableSnapshot,\n type DurableSubmission,\n type DurableSubmitOptions,\n} from \"@anvia/durable/protocol\";\nimport { readSseStream } from \"./transport/streams\";\n\nexport type DurableRequestOptions = { abortSignal?: AbortSignal };\nexport type DurableClientOptions = {\n /** Absolute HTTP(S) URL matching the server handler's basePath. */\n endpoint: string;\n fetch?: typeof fetch;\n headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);\n credentials?: RequestCredentials;\n};\nexport class DurableHttpError extends Error {\n constructor(\n readonly status: number,\n /** Server-provided machine-readable code, such as `payload_too_large`. */\n readonly code?: string,\n /** Server-provided field name that exceeded a limit. */\n readonly field?: string,\n message?: string,\n ) {\n super(message ?? `Durable request failed with HTTP ${status}.`);\n this.name = \"DurableHttpError\";\n }\n}\n\n/** Error bodies are best-effort: a non-JSON or oversized body must not mask the status. */\nasync function durableErrorBody(\n response: Response,\n): Promise<{ message?: string; code?: string; field?: string }> {\n let text: string;\n try {\n text = await response.text();\n } catch {\n return {};\n }\n if (text.length === 0 || text.length > 8_192) return {};\n let body: unknown;\n try {\n body = JSON.parse(text);\n } catch {\n return {};\n }\n if (typeof body !== \"object\" || body === null) return {};\n const record = body as Record<string, unknown>;\n const details: { message?: string; code?: string; field?: string } = {};\n if (typeof record.error === \"string\") details.message = record.error;\n if (typeof record.code === \"string\") details.code = record.code;\n if (typeof record.field === \"string\") details.field = record.field;\n return details;\n}\n\n/** Browser-safe HTTP client. Reconnect explicitly using a snapshot or last applied event cursor. */\nexport class DurableClient {\n private readonly endpoint: string;\n constructor(private readonly options: DurableClientOptions) {\n const endpoint = new URL(options.endpoint);\n if (\n ![\"http:\", \"https:\"].includes(endpoint.protocol) ||\n endpoint.search ||\n endpoint.hash ||\n endpoint.username ||\n endpoint.password\n )\n throw new TypeError(\n \"endpoint must be an HTTP(S) base URL without credentials, query, or fragment.\",\n );\n this.endpoint = endpoint.href.replace(/\\/$/, \"\");\n }\n\n async submitTask(\n /** Trace context is set by the server's `trace` hook. */\n submission: Omit<TaskSubmission, \"trace\">,\n options: DurableRequestOptions = {},\n ): Promise<TaskSnapshot> {\n return parseTaskSnapshot(\n await (await this.request(\"/tasks\", \"POST\", submission, options)).json(),\n );\n }\n async taskSnapshot(id: string, options: DurableRequestOptions = {}): Promise<TaskSnapshot> {\n const snapshot = parseTaskSnapshot(\n await (await this.request(this.taskPath(id), \"GET\", undefined, options)).json(),\n );\n if (snapshot.task.id !== id) throw new TypeError(\"Snapshot belongs to another task.\");\n return snapshot;\n }\n async taskGraph(id: string, options: DurableRequestOptions = {}): Promise<TaskGraphSnapshot> {\n const graph = parseTaskGraph(\n await (await this.request(`${this.taskPath(id)}/graph`, \"GET\", undefined, options)).json(),\n );\n if (!graph.nodes.some((task) => task.id === id))\n throw new TypeError(\"Graph belongs to another task.\");\n return graph;\n }\n async listTasks(\n filter: TaskListOptions & { sessionId: string },\n options: DurableRequestOptions = {},\n ): Promise<TaskPage> {\n const query = new URLSearchParams();\n for (const [key, value] of Object.entries(filter))\n if (value !== undefined) query.set(key, String(value));\n return parseTaskPage(\n await (await this.request(`/tasks?${query}`, \"GET\", undefined, options)).json(),\n );\n }\n async signalTask(\n id: string,\n name: string,\n requestId: string,\n value: JsonValue,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(`${this.taskPath(id)}/signal`, \"POST\", { name, requestId, value }, options);\n }\n async resolveEffect(\n id: string,\n key: string,\n value: JsonValue,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(`${this.taskPath(id)}/resolve-effect`, \"POST\", { key, value }, options);\n }\n async retryTask(id: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.taskPath(id)}/retry`, \"POST\", undefined, options);\n }\n async cancelTask(id: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.taskPath(id)}/cancel`, \"POST\", undefined, options);\n }\n async *streamTask(\n id: string,\n options: DurableRequestOptions & { after?: number } = {},\n ): AsyncIterable<TaskEvent> {\n let cursor = options.after ?? 0;\n if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError(\"Invalid task cursor.\");\n const snapshot = await this.taskSnapshot(id, options);\n const response = await this.request(\n `${this.taskPath(id)}/events?after=${cursor}`,\n \"GET\",\n undefined,\n options,\n );\n if (\n !response.headers.get(\"content-type\")?.startsWith(\"text/event-stream\") ||\n response.body === null\n )\n throw new TypeError(\"Expected a task SSE response.\");\n for await (const value of readSseStream<unknown>(response.body, { strict: true })) {\n options.abortSignal?.throwIfAborted();\n const event = parseTaskEvent(value);\n if (event.rootId !== snapshot.task.rootId || event.sequence <= cursor)\n throw new TypeError(\"Invalid task event order or root ID.\");\n cursor = event.sequence;\n yield event;\n }\n }\n private taskPath(id: string): string {\n if (id.trim().length === 0 || id === \".\" || id === \"..\") throw new TypeError(\"Invalid taskId.\");\n return `/tasks/${encodeURIComponent(id)}`;\n }\n\n async submitGraph(\n submission: DurableGraphSubmission,\n options: DurableRequestOptions = {},\n ): Promise<DurableGraphSnapshot> {\n return parseDurableGraphSnapshot(\n await (await this.request(\"/graphs\", \"POST\", submission, options)).json(),\n );\n }\n async graphSnapshot(\n graphId: string,\n options: DurableRequestOptions = {},\n ): Promise<DurableGraphSnapshot> {\n const snapshot = parseDurableGraphSnapshot(\n await (await this.request(this.graphPath(graphId), \"GET\", undefined, options)).json(),\n );\n if (snapshot.id !== graphId) throw new TypeError(\"Snapshot belongs to another graph.\");\n return snapshot;\n }\n async listGraphs(\n filter: DurableGraphListOptions & { sessionId: string },\n options: DurableRequestOptions = {},\n ): Promise<DurableGraphPage> {\n const query = new URLSearchParams();\n for (const [key, value] of Object.entries(filter))\n if (value !== undefined) query.set(key, String(value));\n return parseDurableGraphPage(\n await (await this.request(`/graphs?${query}`, \"GET\", undefined, options)).json(),\n );\n }\n async cancelGraph(graphId: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.graphPath(graphId)}/cancel`, \"POST\", undefined, options);\n }\n async *streamGraph(\n graphId: string,\n options: DurableRequestOptions & { after?: number } = {},\n ): AsyncIterable<DurableGraphEvent> {\n let cursor = options.after ?? 0;\n if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError(\"Invalid graph cursor.\");\n const response = await this.request(\n `${this.graphPath(graphId)}/events?after=${cursor}`,\n \"GET\",\n undefined,\n options,\n );\n if (\n !response.headers.get(\"content-type\")?.startsWith(\"text/event-stream\") ||\n response.body === null\n )\n throw new TypeError(\"Expected a graph SSE response.\");\n for await (const value of readSseStream<unknown>(response.body, { strict: true })) {\n options.abortSignal?.throwIfAborted();\n const event = parseDurableGraphEvent(value);\n if (event.graphId !== graphId || event.sequence <= cursor)\n throw new TypeError(\"Invalid graph event order or ID.\");\n cursor = event.sequence;\n yield event;\n }\n }\n\n async submit(\n /** Trace context is set by the server's `trace` hook. */\n submission: Omit<DurableSubmission, \"trace\">,\n options: DurableSubmitOptions & DurableRequestOptions = {},\n ): Promise<DurableSnapshot> {\n const body: Omit<DurableSubmission, \"trace\"> & DurableSubmitOptions = { ...submission };\n\n if (options.enqueue !== undefined) {\n body.enqueue = options.enqueue;\n }\n\n const response = await this.request(\"/runs\", \"POST\", body, options);\n\n return parseDurableSnapshot(await response.json());\n }\n\n async listRuns(\n filter: DurableListOptions & { sessionId: string },\n options: DurableRequestOptions = {},\n ): Promise<DurableRunPage> {\n const query = new URLSearchParams();\n for (const [key, value] of Object.entries(filter))\n if (value !== undefined) query.set(key, String(value));\n return parseDurableRunPage(\n await (await this.request(`/runs?${query}`, \"GET\", undefined, options)).json(),\n );\n }\n async snapshot(runId: string, options: DurableRequestOptions = {}): Promise<DurableSnapshot> {\n const snapshot = parseDurableSnapshot(\n await (await this.request(this.path(runId), \"GET\", undefined, options)).json(),\n );\n if (snapshot.run.id !== runId) throw new TypeError(\"Durable snapshot belongs to another run.\");\n return snapshot;\n }\n async *stream(\n runId: string,\n options: DurableRequestOptions & { after?: number } = {},\n ): AsyncIterable<DurableEvent> {\n let cursor = options.after ?? 0;\n if (!Number.isSafeInteger(cursor) || cursor < 0) throw new TypeError(\"Invalid event cursor.\");\n const response = await this.request(\n `${this.path(runId)}/events?after=${cursor}`,\n \"GET\",\n undefined,\n options,\n );\n if (\n !response.headers.get(\"content-type\")?.startsWith(\"text/event-stream\") ||\n response.body === null\n )\n throw new TypeError(\"Expected a durable SSE response.\");\n for await (const value of readSseStream<unknown>(response.body, { strict: true })) {\n options.abortSignal?.throwIfAborted();\n const event = parseDurableEvent(value);\n if (event.runId !== runId || event.sequence <= cursor)\n throw new TypeError(\"Invalid durable event order or run ID.\");\n cursor = event.sequence;\n yield event;\n }\n }\n async steer(\n runId: string,\n input: AgentSteerInput,\n options: DurableSteerOptions & DurableRequestOptions = {},\n ): Promise<AgentSteerReceipt> {\n const path = `${this.path(runId)}/steer`;\n const body: { input: AgentSteerInput; requestId?: string } = { input };\n\n if (options.requestId !== undefined) {\n body.requestId = options.requestId;\n }\n\n const response = await this.request(path, \"POST\", body, options);\n\n return parseDurableSteerReceipt(await response.json());\n }\n\n async respond(\n runId: string,\n interactionId: string,\n response: AgentInteractionResponse,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(`${this.path(runId)}/respond`, \"POST\", { interactionId, response }, options);\n }\n async resolveTool(\n runId: string,\n operationId: string,\n output: ToolResultOutput,\n options: DurableRequestOptions = {},\n ): Promise<void> {\n await this.request(\n `${this.path(runId)}/resolve-tool`,\n \"POST\",\n { operationId, output },\n options,\n );\n }\n async retry(runId: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.path(runId)}/retry`, \"POST\", undefined, options);\n }\n async cancel(runId: string, options: DurableRequestOptions = {}): Promise<void> {\n await this.request(`${this.path(runId)}/cancel`, \"POST\", undefined, options);\n }\n\n private graphPath(id: string): string {\n if (id.trim().length === 0 || id === \".\" || id === \"..\")\n throw new TypeError(\"Invalid graphId.\");\n return `/graphs/${encodeURIComponent(id)}`;\n }\n private path(id: string): string {\n if (id.trim().length === 0) throw new TypeError(\"runId must not be empty.\");\n return `/runs/${encodeURIComponent(id)}`;\n }\n private async request(\n path: string,\n method: string,\n body: unknown,\n options: DurableRequestOptions,\n ): Promise<Response> {\n options.abortSignal?.throwIfAborted();\n const supplied =\n typeof this.options.headers === \"function\"\n ? await this.options.headers()\n : this.options.headers;\n const headers = new Headers(supplied);\n if (body !== undefined) headers.set(\"content-type\", \"application/json\");\n\n const fetch = this.options.fetch ?? globalThis.fetch;\n const url = `${this.endpoint}${path}`;\n const init: RequestInit = {\n method,\n headers,\n };\n\n if (body !== undefined) {\n init.body = JSON.stringify(body);\n }\n\n if (options.abortSignal !== undefined) {\n init.signal = options.abortSignal;\n }\n\n if (this.options.credentials !== undefined) {\n init.credentials = this.options.credentials;\n }\n\n const response = await fetch(url, init);\n if (!response.ok) {\n const details = await durableErrorBody(response);\n throw new DurableHttpError(response.status, details.code, details.field, details.message);\n }\n return response;\n }\n}\n"],"mappings":";;;AA8CA,IAAa,mBAAb,cAAsC,MAAM;CAE/B;CAEA;CAEA;CALX,YACE,QAEA,MAEA,OACA,SACA;EACA,MAAM,WAAW,oCAAoC,OAAO,EAAE;EAPrD,KAAA,SAAA;EAEA,KAAA,OAAA;EAEA,KAAA,QAAA;EAIT,KAAK,OAAO;CACd;AACF;;AAGA,eAAe,iBACb,UAC8D;CAC9D,IAAI;CACJ,IAAI;EACF,OAAO,MAAM,SAAS,KAAK;CAC7B,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,KAAK,WAAW,KAAK,KAAK,SAAS,MAAO,OAAO,CAAC;CACtD,IAAI;CACJ,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;CACxB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO,CAAC;CACvD,MAAM,SAAS;CACf,MAAM,UAA+D,CAAC;CACtE,IAAI,OAAO,OAAO,UAAU,UAAU,QAAQ,UAAU,OAAO;CAC/D,IAAI,OAAO,OAAO,SAAS,UAAU,QAAQ,OAAO,OAAO;CAC3D,IAAI,OAAO,OAAO,UAAU,UAAU,QAAQ,QAAQ,OAAO;CAC7D,OAAO;AACT;;AAGA,IAAa,gBAAb,MAA2B;CAEI;CAD7B;CACA,YAAY,SAAgD;EAA/B,KAAA,UAAA;EAC3B,MAAM,WAAW,IAAI,IAAI,QAAQ,QAAQ;EACzC,IACE,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,SAAS,SAAS,QAAQ,KAC/C,SAAS,UACT,SAAS,QACT,SAAS,YACT,SAAS,UAET,MAAM,IAAI,UACR,+EACF;EACF,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