@retab/node 1.0.87 → 1.0.91

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.
@@ -1,9 +1,14 @@
1
1
  import { CompositionClient, RequestOptions } from "../../../client.js";
2
- import { MIMEDataInput, WorkflowRun } from "../../../types.js";
2
+ import { MIMEDataInput, WorkflowRun, PaginatedList, CancelWorkflowResponse, ResumeWorkflowResponse } from "../../../types.js";
3
+ import APIWorkflowRunSteps from "./steps/client.js";
3
4
  /**
4
5
  * Workflow Runs API client for managing workflow executions.
6
+ *
7
+ * Sub-clients:
8
+ * - steps: Step output operations (get, getBatch)
5
9
  */
6
10
  export default class APIWorkflowRuns extends CompositionClient {
11
+ steps: APIWorkflowRunSteps;
7
12
  constructor(client: CompositionClient);
8
13
  /**
9
14
  * Run a workflow with the provided inputs.
@@ -56,5 +61,170 @@ export default class APIWorkflowRuns extends CompositionClient {
56
61
  * ```
57
62
  */
58
63
  get(runId: string, options?: RequestOptions): Promise<WorkflowRun>;
64
+ /**
65
+ * List workflow runs with filtering and pagination.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const runs = await client.workflows.runs.list({
70
+ * workflowId: "wf_abc123",
71
+ * status: "completed",
72
+ * limit: 10,
73
+ * });
74
+ * console.log(`Found ${runs.data.length} runs`);
75
+ * ```
76
+ */
77
+ list({ workflowId, status, statuses, excludeStatus, triggerType, triggerTypes, fromDate, toDate, minCost, maxCost, minDuration, maxDuration, search, sortBy, fields, before, after, limit, order, }?: {
78
+ workflowId?: string;
79
+ status?: "pending" | "running" | "completed" | "error" | "waiting_for_human" | "cancelled";
80
+ statuses?: string;
81
+ excludeStatus?: "pending" | "running" | "completed" | "error" | "waiting_for_human" | "cancelled";
82
+ triggerType?: "manual" | "api" | "schedule" | "webhook" | "restart";
83
+ triggerTypes?: string;
84
+ fromDate?: string;
85
+ toDate?: string;
86
+ minCost?: number;
87
+ maxCost?: number;
88
+ minDuration?: number;
89
+ maxDuration?: number;
90
+ search?: string;
91
+ sortBy?: string;
92
+ fields?: string;
93
+ before?: string;
94
+ after?: string;
95
+ limit?: number;
96
+ order?: "asc" | "desc";
97
+ }, options?: RequestOptions): Promise<PaginatedList>;
98
+ /**
99
+ * Delete a workflow run and its associated step data.
100
+ *
101
+ * @param runId - The ID of the workflow run to delete
102
+ * @param options - Optional request options
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * await client.workflows.runs.delete("run_abc123");
107
+ * ```
108
+ */
109
+ delete(runId: string, options?: RequestOptions): Promise<void>;
110
+ /**
111
+ * Cancel a running or pending workflow run.
112
+ *
113
+ * @param runId - The ID of the workflow run to cancel
114
+ * @param commandId - Optional idempotency key for deduplicating cancel commands
115
+ * @param options - Optional request options
116
+ * @returns The updated run with cancellation status
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const result = await client.workflows.runs.cancel("run_abc123");
121
+ * console.log(`Cancellation: ${result.cancellation_status}`);
122
+ * ```
123
+ */
124
+ cancel(runId: string, { commandId }?: {
125
+ commandId?: string;
126
+ }, options?: RequestOptions): Promise<CancelWorkflowResponse>;
127
+ /**
128
+ * Restart a completed or failed workflow run with the same inputs.
129
+ *
130
+ * @param runId - The ID of the workflow run to restart
131
+ * @param commandId - Optional idempotency key for deduplicating restart commands
132
+ * @param options - Optional request options
133
+ * @returns The new workflow run
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const newRun = await client.workflows.runs.restart("run_abc123");
138
+ * console.log(`New run: ${newRun.id}`);
139
+ * ```
140
+ */
141
+ restart(runId: string, { commandId }?: {
142
+ commandId?: string;
143
+ }, options?: RequestOptions): Promise<WorkflowRun>;
144
+ /**
145
+ * Resume a workflow run after human-in-the-loop (HIL) review.
146
+ *
147
+ * @param runId - The ID of the workflow run to resume
148
+ * @param nodeId - The ID of the HIL node being approved/rejected
149
+ * @param approved - Whether the human approved the data
150
+ * @param modifiedData - Optional modified data if the human made changes
151
+ * @param commandId - Optional idempotency key for deduplicating resume commands
152
+ * @param options - Optional request options
153
+ * @returns The resume response with status and queue information
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const result = await client.workflows.runs.resume("run_abc123", {
158
+ * nodeId: "hil-node-1",
159
+ * approved: true,
160
+ * modifiedData: { field: "corrected value" },
161
+ * });
162
+ * console.log(`Resume status: ${result.resume_status}`);
163
+ * ```
164
+ */
165
+ resume(runId: string, { nodeId, approved, modifiedData, commandId, }: {
166
+ nodeId: string;
167
+ approved: boolean;
168
+ modifiedData?: Record<string, unknown> | null;
169
+ commandId?: string;
170
+ }, options?: RequestOptions): Promise<ResumeWorkflowResponse>;
171
+ /**
172
+ * Poll a workflow run until it reaches a terminal state.
173
+ *
174
+ * Terminal states: "completed", "error", "cancelled".
175
+ *
176
+ * @param runId - The ID of the workflow run to wait for
177
+ * @param pollIntervalMs - Milliseconds between polls (default: 2000)
178
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 600000 = 10 minutes)
179
+ * @returns The workflow run in a terminal state
180
+ * @throws Error if the run doesn't complete within the timeout
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const run = await client.workflows.runs.waitForCompletion("run_abc123", {
185
+ * pollIntervalMs: 1000,
186
+ * timeoutMs: 300000,
187
+ * });
188
+ * console.log(`Final status: ${run.status}`);
189
+ * ```
190
+ */
191
+ waitForCompletion(runId: string, { pollIntervalMs, timeoutMs, }?: {
192
+ pollIntervalMs?: number;
193
+ timeoutMs?: number;
194
+ }): Promise<WorkflowRun>;
195
+ /**
196
+ * Create a workflow run and wait for it to complete.
197
+ *
198
+ * Convenience method that combines create() and waitForCompletion().
199
+ *
200
+ * @param workflowId - The ID of the workflow to run
201
+ * @param documents - Mapping of start node IDs to their input documents
202
+ * @param jsonInputs - Mapping of start_json node IDs to their input JSON data
203
+ * @param textInputs - Mapping of start_text node IDs to their input text
204
+ * @param pollIntervalMs - Milliseconds between polls (default: 2000)
205
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 600000)
206
+ * @param options - Optional request options
207
+ * @returns The workflow run in a terminal state
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const run = await client.workflows.runs.createAndWait({
212
+ * workflowId: "wf_abc123",
213
+ * documents: { "start-node-1": "./invoice.pdf" },
214
+ * timeoutMs: 120000,
215
+ * });
216
+ * if (run.status === "completed") {
217
+ * console.log("Outputs:", run.final_outputs);
218
+ * }
219
+ * ```
220
+ */
221
+ createAndWait({ workflowId, documents, jsonInputs, textInputs, pollIntervalMs, timeoutMs, }: {
222
+ workflowId: string;
223
+ documents?: Record<string, MIMEDataInput>;
224
+ jsonInputs?: Record<string, Record<string, unknown>>;
225
+ textInputs?: Record<string, string>;
226
+ pollIntervalMs?: number;
227
+ timeoutMs?: number;
228
+ }, options?: RequestOptions): Promise<WorkflowRun>;
59
229
  }
60
230
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/api/workflows/runs/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAa,WAAW,EAAgB,MAAM,mBAAmB,CAAC;AAExF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,iBAAiB;gBAC9C,MAAM,EAAE,iBAAiB;IAIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACG,MAAM,CACR,EACI,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,GACb,EAAE;QACC,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAC1C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACrD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvC,EACD,OAAO,CAAC,EA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CAAC;QAC1C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACrD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACpC,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,EACD,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,WAAW,CAAC;CAO1B"}
@@ -1,11 +1,20 @@
1
1
  import { CompositionClient } from "../../../client.js";
2
- import { ZMIMEData, ZWorkflowRun } from "../../../types.js";
2
+ import { ZMIMEData, ZWorkflowRun, ZPaginatedList, ZCancelWorkflowResponse, ZResumeWorkflowResponse, } from "../../../types.js";
3
+ import APIWorkflowRunSteps from "./steps/client.js";
4
+ const TERMINAL_STATUSES = new Set(["completed", "error", "cancelled"]);
5
+ function sleep(ms) {
6
+ return new Promise((resolve) => setTimeout(resolve, ms));
7
+ }
3
8
  /**
4
9
  * Workflow Runs API client for managing workflow executions.
10
+ *
11
+ * Sub-clients:
12
+ * - steps: Step output operations (get, getBatch)
5
13
  */
6
14
  export default class APIWorkflowRuns extends CompositionClient {
7
15
  constructor(client) {
8
16
  super(client);
17
+ this.steps = new APIWorkflowRunSteps(this);
9
18
  }
10
19
  /**
11
20
  * Run a workflow with the provided inputs.
@@ -39,15 +48,12 @@ export default class APIWorkflowRuns extends CompositionClient {
39
48
  * ```
40
49
  */
41
50
  async create({ workflowId, documents, jsonInputs, textInputs, }, options) {
42
- // Build the request body
43
51
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
52
  const body = {};
45
- // Convert each document to MIMEData format expected by backend
46
53
  if (documents) {
47
54
  const documentsPayload = {};
48
55
  for (const [nodeId, document] of Object.entries(documents)) {
49
56
  const parsedDocument = await ZMIMEData.parseAsync(document);
50
- // Extract base64 content from data URL
51
57
  const content = parsedDocument.url.split(",")[1];
52
58
  const mimeType = parsedDocument.url.split(";")[0].split(":")[1];
53
59
  documentsPayload[nodeId] = {
@@ -58,11 +64,9 @@ export default class APIWorkflowRuns extends CompositionClient {
58
64
  }
59
65
  body.documents = documentsPayload;
60
66
  }
61
- // Add JSON inputs directly
62
67
  if (jsonInputs) {
63
68
  body.json_inputs = jsonInputs;
64
69
  }
65
- // Add text inputs directly
66
70
  if (textInputs) {
67
71
  body.text_inputs = textInputs;
68
72
  }
@@ -95,4 +99,227 @@ export default class APIWorkflowRuns extends CompositionClient {
95
99
  headers: options?.headers,
96
100
  });
97
101
  }
102
+ /**
103
+ * List workflow runs with filtering and pagination.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const runs = await client.workflows.runs.list({
108
+ * workflowId: "wf_abc123",
109
+ * status: "completed",
110
+ * limit: 10,
111
+ * });
112
+ * console.log(`Found ${runs.data.length} runs`);
113
+ * ```
114
+ */
115
+ async list({ workflowId, status, statuses, excludeStatus, triggerType, triggerTypes, fromDate, toDate, minCost, maxCost, minDuration, maxDuration, search, sortBy, fields, before, after, limit = 20, order = "desc", } = {}, options) {
116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
+ const params = {
118
+ workflow_id: workflowId,
119
+ status,
120
+ statuses,
121
+ exclude_status: excludeStatus,
122
+ trigger_type: triggerType,
123
+ trigger_types: triggerTypes,
124
+ from_date: fromDate,
125
+ to_date: toDate,
126
+ min_cost: minCost,
127
+ max_cost: maxCost,
128
+ min_duration: minDuration,
129
+ max_duration: maxDuration,
130
+ search,
131
+ sort_by: sortBy,
132
+ fields,
133
+ before,
134
+ after,
135
+ limit,
136
+ order,
137
+ };
138
+ const cleanParams = Object.fromEntries(Object.entries(params).filter(([_, v]) => v !== undefined));
139
+ return this._fetchJson(ZPaginatedList, {
140
+ url: "/v1/workflows/runs",
141
+ method: "GET",
142
+ params: { ...cleanParams, ...(options?.params || {}) },
143
+ headers: options?.headers,
144
+ });
145
+ }
146
+ /**
147
+ * Delete a workflow run and its associated step data.
148
+ *
149
+ * @param runId - The ID of the workflow run to delete
150
+ * @param options - Optional request options
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * await client.workflows.runs.delete("run_abc123");
155
+ * ```
156
+ */
157
+ async delete(runId, options) {
158
+ return this._fetchJson({
159
+ url: `/v1/workflows/runs/${runId}`,
160
+ method: "DELETE",
161
+ params: options?.params,
162
+ headers: options?.headers,
163
+ });
164
+ }
165
+ /**
166
+ * Cancel a running or pending workflow run.
167
+ *
168
+ * @param runId - The ID of the workflow run to cancel
169
+ * @param commandId - Optional idempotency key for deduplicating cancel commands
170
+ * @param options - Optional request options
171
+ * @returns The updated run with cancellation status
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * const result = await client.workflows.runs.cancel("run_abc123");
176
+ * console.log(`Cancellation: ${result.cancellation_status}`);
177
+ * ```
178
+ */
179
+ async cancel(runId, { commandId } = {}, options) {
180
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
+ const body = {};
182
+ if (commandId !== undefined)
183
+ body.command_id = commandId;
184
+ return this._fetchJson(ZCancelWorkflowResponse, {
185
+ url: `/v1/workflows/runs/${runId}/cancel`,
186
+ method: "POST",
187
+ body: { ...body, ...(options?.body || {}) },
188
+ params: options?.params,
189
+ headers: options?.headers,
190
+ });
191
+ }
192
+ /**
193
+ * Restart a completed or failed workflow run with the same inputs.
194
+ *
195
+ * @param runId - The ID of the workflow run to restart
196
+ * @param commandId - Optional idempotency key for deduplicating restart commands
197
+ * @param options - Optional request options
198
+ * @returns The new workflow run
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const newRun = await client.workflows.runs.restart("run_abc123");
203
+ * console.log(`New run: ${newRun.id}`);
204
+ * ```
205
+ */
206
+ async restart(runId, { commandId } = {}, options) {
207
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
+ const body = {};
209
+ if (commandId !== undefined)
210
+ body.command_id = commandId;
211
+ return this._fetchJson(ZWorkflowRun, {
212
+ url: `/v1/workflows/runs/${runId}/restart`,
213
+ method: "POST",
214
+ body: { ...body, ...(options?.body || {}) },
215
+ params: options?.params,
216
+ headers: options?.headers,
217
+ });
218
+ }
219
+ /**
220
+ * Resume a workflow run after human-in-the-loop (HIL) review.
221
+ *
222
+ * @param runId - The ID of the workflow run to resume
223
+ * @param nodeId - The ID of the HIL node being approved/rejected
224
+ * @param approved - Whether the human approved the data
225
+ * @param modifiedData - Optional modified data if the human made changes
226
+ * @param commandId - Optional idempotency key for deduplicating resume commands
227
+ * @param options - Optional request options
228
+ * @returns The resume response with status and queue information
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const result = await client.workflows.runs.resume("run_abc123", {
233
+ * nodeId: "hil-node-1",
234
+ * approved: true,
235
+ * modifiedData: { field: "corrected value" },
236
+ * });
237
+ * console.log(`Resume status: ${result.resume_status}`);
238
+ * ```
239
+ */
240
+ async resume(runId, { nodeId, approved, modifiedData, commandId, }, options) {
241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
+ const body = {
243
+ node_id: nodeId,
244
+ approved,
245
+ };
246
+ if (modifiedData !== undefined)
247
+ body.modified_data = modifiedData;
248
+ if (commandId !== undefined)
249
+ body.command_id = commandId;
250
+ return this._fetchJson(ZResumeWorkflowResponse, {
251
+ url: `/v1/workflows/runs/${runId}/resume`,
252
+ method: "POST",
253
+ body: { ...body, ...(options?.body || {}) },
254
+ params: options?.params,
255
+ headers: options?.headers,
256
+ });
257
+ }
258
+ /**
259
+ * Poll a workflow run until it reaches a terminal state.
260
+ *
261
+ * Terminal states: "completed", "error", "cancelled".
262
+ *
263
+ * @param runId - The ID of the workflow run to wait for
264
+ * @param pollIntervalMs - Milliseconds between polls (default: 2000)
265
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 600000 = 10 minutes)
266
+ * @returns The workflow run in a terminal state
267
+ * @throws Error if the run doesn't complete within the timeout
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const run = await client.workflows.runs.waitForCompletion("run_abc123", {
272
+ * pollIntervalMs: 1000,
273
+ * timeoutMs: 300000,
274
+ * });
275
+ * console.log(`Final status: ${run.status}`);
276
+ * ```
277
+ */
278
+ async waitForCompletion(runId, { pollIntervalMs = 2000, timeoutMs = 600000, } = {}) {
279
+ if (pollIntervalMs <= 0)
280
+ throw new Error("pollIntervalMs must be positive");
281
+ if (timeoutMs <= 0)
282
+ throw new Error("timeoutMs must be positive");
283
+ const deadline = Date.now() + timeoutMs;
284
+ while (true) {
285
+ const run = await this.get(runId);
286
+ if (TERMINAL_STATUSES.has(run.status)) {
287
+ return run;
288
+ }
289
+ if (Date.now() >= deadline) {
290
+ throw new Error(`Workflow run ${runId} did not complete within ${timeoutMs}ms (last status: ${run.status})`);
291
+ }
292
+ await sleep(pollIntervalMs);
293
+ }
294
+ }
295
+ /**
296
+ * Create a workflow run and wait for it to complete.
297
+ *
298
+ * Convenience method that combines create() and waitForCompletion().
299
+ *
300
+ * @param workflowId - The ID of the workflow to run
301
+ * @param documents - Mapping of start node IDs to their input documents
302
+ * @param jsonInputs - Mapping of start_json node IDs to their input JSON data
303
+ * @param textInputs - Mapping of start_text node IDs to their input text
304
+ * @param pollIntervalMs - Milliseconds between polls (default: 2000)
305
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 600000)
306
+ * @param options - Optional request options
307
+ * @returns The workflow run in a terminal state
308
+ *
309
+ * @example
310
+ * ```typescript
311
+ * const run = await client.workflows.runs.createAndWait({
312
+ * workflowId: "wf_abc123",
313
+ * documents: { "start-node-1": "./invoice.pdf" },
314
+ * timeoutMs: 120000,
315
+ * });
316
+ * if (run.status === "completed") {
317
+ * console.log("Outputs:", run.final_outputs);
318
+ * }
319
+ * ```
320
+ */
321
+ async createAndWait({ workflowId, documents, jsonInputs, textInputs, pollIntervalMs = 2000, timeoutMs = 600000, }, options) {
322
+ const run = await this.create({ workflowId, documents, jsonInputs, textInputs }, options);
323
+ return this.waitForCompletion(run.id, { pollIntervalMs, timeoutMs });
324
+ }
98
325
  }
@@ -0,0 +1,46 @@
1
+ import { CompositionClient, RequestOptions } from "../../../../client.js";
2
+ import { StepOutputResponse, StepOutputsBatchResponse } from "../../../../types.js";
3
+ /**
4
+ * Workflow Run Steps API client for accessing step-level outputs.
5
+ *
6
+ * Usage: `client.workflows.runs.steps.get(runId, nodeId)`
7
+ */
8
+ export default class APIWorkflowRunSteps extends CompositionClient {
9
+ constructor(client: CompositionClient);
10
+ /**
11
+ * Get the full output data for a specific step in a workflow run.
12
+ *
13
+ * @param runId - The ID of the workflow run
14
+ * @param nodeId - The ID of the node/step to get output for
15
+ * @param options - Optional request options
16
+ * @returns The step output with handle outputs and inputs
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const step = await client.workflows.runs.steps.get("run_abc123", "extract-node-1");
21
+ * console.log(`Step status: ${step.status}, output:`, step.output);
22
+ * ```
23
+ */
24
+ get(runId: string, nodeId: string, options?: RequestOptions): Promise<StepOutputResponse>;
25
+ /**
26
+ * Get outputs for multiple steps in a single request.
27
+ *
28
+ * @param runId - The ID of the workflow run
29
+ * @param nodeIds - List of node IDs to fetch outputs for (max 1000)
30
+ * @param options - Optional request options
31
+ * @returns Step outputs keyed by node ID
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const batch = await client.workflows.runs.steps.getBatch(
36
+ * "run_abc123",
37
+ * ["extract-1", "extract-2", "split-1"]
38
+ * );
39
+ * for (const [nodeId, step] of Object.entries(batch.outputs)) {
40
+ * console.log(`${nodeId}: ${step.status}`);
41
+ * }
42
+ * ```
43
+ */
44
+ getBatch(runId: string, nodeIds: string[], options?: RequestOptions): Promise<StepOutputsBatchResponse>;
45
+ }
46
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/api/workflows/runs/steps/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EACH,kBAAkB,EAElB,wBAAwB,EAE3B,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,iBAAiB;gBAClD,MAAM,EAAE,iBAAiB;IAIrC;;;;;;;;;;;;;OAaG;IACG,GAAG,CACL,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAS9B;;;;;;;;;;;;;;;;;;OAkBG;IACG,QAAQ,CACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,wBAAwB,CAAC;CASvC"}
@@ -0,0 +1,62 @@
1
+ import { CompositionClient } from "../../../../client.js";
2
+ import { ZStepOutputResponse, ZStepOutputsBatchResponse, } from "../../../../types.js";
3
+ /**
4
+ * Workflow Run Steps API client for accessing step-level outputs.
5
+ *
6
+ * Usage: `client.workflows.runs.steps.get(runId, nodeId)`
7
+ */
8
+ export default class APIWorkflowRunSteps extends CompositionClient {
9
+ constructor(client) {
10
+ super(client);
11
+ }
12
+ /**
13
+ * Get the full output data for a specific step in a workflow run.
14
+ *
15
+ * @param runId - The ID of the workflow run
16
+ * @param nodeId - The ID of the node/step to get output for
17
+ * @param options - Optional request options
18
+ * @returns The step output with handle outputs and inputs
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const step = await client.workflows.runs.steps.get("run_abc123", "extract-node-1");
23
+ * console.log(`Step status: ${step.status}, output:`, step.output);
24
+ * ```
25
+ */
26
+ async get(runId, nodeId, options) {
27
+ return this._fetchJson(ZStepOutputResponse, {
28
+ url: `/v1/workflows/runs/${runId}/steps/${nodeId}`,
29
+ method: "GET",
30
+ params: options?.params,
31
+ headers: options?.headers,
32
+ });
33
+ }
34
+ /**
35
+ * Get outputs for multiple steps in a single request.
36
+ *
37
+ * @param runId - The ID of the workflow run
38
+ * @param nodeIds - List of node IDs to fetch outputs for (max 1000)
39
+ * @param options - Optional request options
40
+ * @returns Step outputs keyed by node ID
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const batch = await client.workflows.runs.steps.getBatch(
45
+ * "run_abc123",
46
+ * ["extract-1", "extract-2", "split-1"]
47
+ * );
48
+ * for (const [nodeId, step] of Object.entries(batch.outputs)) {
49
+ * console.log(`${nodeId}: ${step.status}`);
50
+ * }
51
+ * ```
52
+ */
53
+ async getBatch(runId, nodeIds, options) {
54
+ return this._fetchJson(ZStepOutputsBatchResponse, {
55
+ url: `/v1/workflows/runs/${runId}/steps/batch`,
56
+ method: "POST",
57
+ body: { node_ids: nodeIds, ...(options?.body || {}) },
58
+ params: options?.params,
59
+ headers: options?.headers,
60
+ });
61
+ }
62
+ }