@nones/agentflow-core 0.1.0 → 0.6.1

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/src/client.ts CHANGED
@@ -2,17 +2,29 @@ import type { Socket } from "bun";
2
2
  import { AgentFlowError } from "./errors";
3
3
  import { sleep } from "./json";
4
4
  import { JsonLines, JsonLineWriter } from "./jsonl-socket";
5
- import type { RpcResponse } from "./protocol";
6
5
  import type {
6
+ AmendRunPayload,
7
+ DrainOptions,
8
+ DrainReport,
9
+ RpcResponse,
10
+ } from "./protocol";
11
+ import type {
12
+ AmendPreview,
7
13
  AppendRequest,
8
14
  ArtifactOutput,
9
15
  Client,
10
16
  ClientEventsOptions,
11
17
  ClientOptions,
18
+ ContinueRunOptions,
12
19
  EngineEvent,
20
+ LimitRunOptions,
13
21
  LimitsSnapshot,
14
22
  MessageSnapshot,
23
+ OperationReceipt,
24
+ PauseRunOptions,
25
+ RecoveryItem,
15
26
  ResumeOptions,
27
+ RetryRunOptions,
16
28
  RunRequest,
17
29
  RunSnapshot,
18
30
  SendOptions,
@@ -157,6 +169,74 @@ class ClientImpl implements Client {
157
169
  return this.call<ArtifactOutput>("output", { id, artifactId });
158
170
  }
159
171
 
172
+ async pauseRun(
173
+ id: string,
174
+ options: PauseRunOptions = {},
175
+ ): Promise<OperationReceipt> {
176
+ return this.call<OperationReceipt>("pauseRun", { id, ...options });
177
+ }
178
+
179
+ async continueRun(
180
+ id: string,
181
+ options: ContinueRunOptions = {},
182
+ ): Promise<OperationReceipt> {
183
+ return this.call<OperationReceipt>("continueRun", { id, ...options });
184
+ }
185
+
186
+ async limitRun(
187
+ id: string,
188
+ maxConcurrent: number,
189
+ options: LimitRunOptions = {},
190
+ ): Promise<OperationReceipt> {
191
+ return this.call<OperationReceipt>("limitRun", {
192
+ id,
193
+ maxConcurrent,
194
+ ...options,
195
+ });
196
+ }
197
+
198
+ async retryRun(
199
+ id: string,
200
+ options: RetryRunOptions = {},
201
+ ): Promise<OperationReceipt> {
202
+ return this.call<OperationReceipt>("retryRun", { id, ...options });
203
+ }
204
+
205
+ async amendRun(
206
+ id: string,
207
+ amendment: AmendRunPayload,
208
+ ): Promise<AmendPreview> {
209
+ return this.call<AmendPreview>("amendRun", {
210
+ id,
211
+ amendment: {
212
+ input: amendment.input,
213
+ ...(amendment.strategy === undefined
214
+ ? {}
215
+ : { strategy: amendment.strategy }),
216
+ ...(amendment.newRunId === undefined
217
+ ? {}
218
+ : { newRunId: amendment.newRunId }),
219
+ ...(amendment.apply === undefined ? {} : { apply: amendment.apply }),
220
+ ...operatorOptionsOf(amendment),
221
+ },
222
+ });
223
+ }
224
+
225
+ async operations(id: string): Promise<OperationReceipt[]> {
226
+ return this.call<OperationReceipt[]>("operations", { id });
227
+ }
228
+
229
+ async recovery(id: string): Promise<RecoveryItem[]> {
230
+ return this.call<RecoveryItem[]>("recovery", { id });
231
+ }
232
+
233
+ async drain(options: DrainOptions = {}): Promise<DrainReport> {
234
+ return this.call<DrainReport>(
235
+ "drain",
236
+ options.graceMs === undefined ? {} : { graceMs: options.graceMs },
237
+ );
238
+ }
239
+
160
240
  async close(): Promise<void> {
161
241
  if (this.closed) return;
162
242
  this.closed = true;
@@ -314,3 +394,14 @@ class ClientImpl implements Client {
314
394
  this.pending.clear();
315
395
  }
316
396
  }
397
+
398
+ /** Copies only the shared operator fields that were actually provided. */
399
+ function operatorOptionsOf(
400
+ options: PauseRunOptions,
401
+ ): Pick<PauseRunOptions, "actionId" | "actor" | "reason"> {
402
+ return {
403
+ ...(options.actionId === undefined ? {} : { actionId: options.actionId }),
404
+ ...(options.actor === undefined ? {} : { actor: options.actor }),
405
+ ...(options.reason === undefined ? {} : { reason: options.reason }),
406
+ };
407
+ }