@retab/node 1.0.96 → 1.0.99

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.
Files changed (79) hide show
  1. package/README.md +39 -42
  2. package/dist/api/client.d.ts +4 -2
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +4 -2
  5. package/dist/api/documents/client.d.ts +17 -11
  6. package/dist/api/documents/client.d.ts.map +1 -1
  7. package/dist/api/documents/client.js +85 -38
  8. package/dist/api/edit/agent/client.js +1 -1
  9. package/dist/api/edit/client.d.ts +1 -1
  10. package/dist/api/edit/client.js +1 -1
  11. package/dist/api/edit/templates/client.d.ts +1 -75
  12. package/dist/api/edit/templates/client.d.ts.map +1 -1
  13. package/dist/api/edit/templates/client.js +3 -130
  14. package/dist/api/evals/classify/client.d.ts +20 -0
  15. package/dist/api/evals/classify/client.d.ts.map +1 -0
  16. package/dist/api/evals/classify/client.js +25 -0
  17. package/dist/api/evals/client.d.ts +11 -0
  18. package/dist/api/evals/client.d.ts.map +1 -0
  19. package/dist/api/evals/client.js +12 -0
  20. package/dist/api/evals/extract/client.d.ts +287 -0
  21. package/dist/api/evals/extract/client.d.ts.map +1 -0
  22. package/dist/api/evals/extract/client.js +56 -0
  23. package/dist/api/evals/helpers.d.ts +30 -0
  24. package/dist/api/evals/helpers.d.ts.map +1 -0
  25. package/dist/api/evals/helpers.js +46 -0
  26. package/dist/api/evals/schemas.d.ts +6522 -0
  27. package/dist/api/evals/schemas.d.ts.map +1 -0
  28. package/dist/api/evals/schemas.js +219 -0
  29. package/dist/api/evals/split/client.d.ts +105 -0
  30. package/dist/api/evals/split/client.d.ts.map +1 -0
  31. package/dist/api/evals/split/client.js +28 -0
  32. package/dist/api/extractions/client.d.ts +3 -43
  33. package/dist/api/extractions/client.d.ts.map +1 -1
  34. package/dist/api/extractions/client.js +6 -67
  35. package/dist/api/files/client.d.ts +9 -1
  36. package/dist/api/files/client.d.ts.map +1 -1
  37. package/dist/api/files/client.js +11 -5
  38. package/dist/api/jobs/client.d.ts +12 -10
  39. package/dist/api/jobs/client.d.ts.map +1 -1
  40. package/dist/api/jobs/client.js +13 -17
  41. package/dist/api/models/client.d.ts +3 -10
  42. package/dist/api/models/client.d.ts.map +1 -1
  43. package/dist/api/models/client.js +9 -8
  44. package/dist/api/projects/client.d.ts +1640 -4
  45. package/dist/api/projects/client.d.ts.map +1 -1
  46. package/dist/api/projects/client.js +457 -28
  47. package/dist/api/schemas/client.d.ts +3 -0
  48. package/dist/api/schemas/client.d.ts.map +1 -1
  49. package/dist/api/schemas/client.js +1 -1
  50. package/dist/api/workflows/blocks/client.d.ts +67 -0
  51. package/dist/api/workflows/blocks/client.d.ts.map +1 -0
  52. package/dist/api/workflows/blocks/client.js +132 -0
  53. package/dist/api/workflows/client.d.ts +90 -2
  54. package/dist/api/workflows/client.d.ts.map +1 -1
  55. package/dist/api/workflows/client.js +153 -1
  56. package/dist/api/workflows/edges/client.d.ts +66 -0
  57. package/dist/api/workflows/edges/client.d.ts.map +1 -0
  58. package/dist/api/workflows/edges/client.js +120 -0
  59. package/dist/api/workflows/runs/client.d.ts +57 -113
  60. package/dist/api/workflows/runs/client.d.ts.map +1 -1
  61. package/dist/api/workflows/runs/client.js +118 -119
  62. package/dist/api/workflows/runs/steps/client.d.ts +35 -13
  63. package/dist/api/workflows/runs/steps/client.d.ts.map +1 -1
  64. package/dist/api/workflows/runs/steps/client.js +63 -15
  65. package/dist/client.d.ts +4 -2
  66. package/dist/client.d.ts.map +1 -1
  67. package/dist/client.js +79 -5
  68. package/dist/generated_types.d.ts +7778 -2745
  69. package/dist/generated_types.d.ts.map +1 -1
  70. package/dist/generated_types.js +711 -70
  71. package/dist/mime.d.ts.map +1 -1
  72. package/dist/mime.js +11 -1
  73. package/dist/schema_types.d.ts +2 -2
  74. package/dist/schema_types.d.ts.map +1 -1
  75. package/dist/schema_types.js +2 -2
  76. package/dist/types.d.ts +655 -109
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/types.js +84 -14
  79. package/package.json +1 -1
@@ -1,7 +1,23 @@
1
+ import * as z from "zod";
1
2
  import { CompositionClient } from "../../../client.js";
2
- import { ZMIMEData, ZWorkflowRun, ZPaginatedList, ZCancelWorkflowResponse, ZResumeWorkflowResponse, } from "../../../types.js";
3
+ import { ZMIMEData, ZWorkflowRun, ZPaginatedList, ZCancelWorkflowResponse, ZResumeWorkflowResponse, ZWorkflowRunExportResponse, } from "../../../types.js";
3
4
  import APIWorkflowRunSteps from "./steps/client.js";
4
5
  const TERMINAL_STATUSES = new Set(["completed", "error", "cancelled"]);
6
+ function normalizeCsvParam(value) {
7
+ if (value === undefined) {
8
+ return undefined;
9
+ }
10
+ return Array.isArray(value) ? value.join(",") : value;
11
+ }
12
+ function normalizeDateParam(value) {
13
+ if (value === undefined) {
14
+ return undefined;
15
+ }
16
+ if (value instanceof Date) {
17
+ return value.toISOString().slice(0, 10);
18
+ }
19
+ return value;
20
+ }
5
21
  function sleep(ms) {
6
22
  return new Promise((resolve) => setTimeout(resolve, ms));
7
23
  }
@@ -9,7 +25,7 @@ function sleep(ms) {
9
25
  * Workflow Runs API client for managing workflow executions.
10
26
  *
11
27
  * Sub-clients:
12
- * - steps: Step output operations (get, list)
28
+ * - steps: Step output operations (get, list, getMany, getAll)
13
29
  */
14
30
  export default class APIWorkflowRuns extends CompositionClient {
15
31
  constructor(client) {
@@ -23,24 +39,12 @@ export default class APIWorkflowRuns extends CompositionClient {
23
39
  * The returned WorkflowRun will have status "running" - use get()
24
40
  * to check for updates on the run status.
25
41
  *
26
- * @param workflowId - The ID of the workflow to run
27
- * @param documents - Mapping of start node IDs to their input documents
28
- * @param jsonInputs - Mapping of start_json node IDs to their input JSON data
29
- * @param options - Optional request options
30
- * @returns The created workflow run with status "running"
31
- *
32
42
  * @example
33
43
  * ```typescript
34
44
  * const run = await client.workflows.runs.create({
35
45
  * workflowId: "wf_abc123",
36
- * documents: {
37
- * "start-node-1": "./invoice.pdf",
38
- * },
39
- * jsonInputs: {
40
- * "json-node-1": { key: "value" },
41
- * },
46
+ * documents: { "start-node-1": "./invoice.pdf" },
42
47
  * });
43
- * console.log(`Run started: ${run.id}, status: ${run.status}`);
44
48
  * ```
45
49
  */
46
50
  async create({ workflowId, documents, jsonInputs, }, options) {
@@ -64,7 +68,7 @@ export default class APIWorkflowRuns extends CompositionClient {
64
68
  body.json_inputs = jsonInputs;
65
69
  }
66
70
  return this._fetchJson(ZWorkflowRun, {
67
- url: `/v1/workflows/${workflowId}/run`,
71
+ url: `/workflows/${workflowId}/run`,
68
72
  method: "POST",
69
73
  body: { ...body, ...(options?.body || {}) },
70
74
  params: options?.params,
@@ -73,20 +77,10 @@ export default class APIWorkflowRuns extends CompositionClient {
73
77
  }
74
78
  /**
75
79
  * Get a workflow run by ID.
76
- *
77
- * @param runId - The ID of the workflow run to retrieve
78
- * @param options - Optional request options
79
- * @returns The workflow run
80
- *
81
- * @example
82
- * ```typescript
83
- * const run = await client.workflows.runs.get("run_abc123");
84
- * console.log(`Run status: ${run.status}`);
85
- * ```
86
80
  */
87
81
  async get(runId, options) {
88
82
  return this._fetchJson(ZWorkflowRun, {
89
- url: `/v1/workflows/runs/${runId}`,
83
+ url: `/workflows/runs/${runId}`,
90
84
  method: "GET",
91
85
  params: options?.params,
92
86
  headers: options?.headers,
@@ -94,35 +88,25 @@ export default class APIWorkflowRuns extends CompositionClient {
94
88
  }
95
89
  /**
96
90
  * List workflow runs with filtering and pagination.
97
- *
98
- * @example
99
- * ```typescript
100
- * const runs = await client.workflows.runs.list({
101
- * workflowId: "wf_abc123",
102
- * status: "completed",
103
- * limit: 10,
104
- * });
105
- * console.log(`Found ${runs.data.length} runs`);
106
- * ```
107
91
  */
108
92
  async list({ workflowId, status, statuses, excludeStatus, triggerType, triggerTypes, fromDate, toDate, minCost, maxCost, minDuration, maxDuration, search, sortBy, fields, before, after, limit = 20, order = "desc", } = {}, options) {
109
93
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
94
  const params = {
111
95
  workflow_id: workflowId,
112
96
  status,
113
- statuses,
97
+ statuses: normalizeCsvParam(statuses),
114
98
  exclude_status: excludeStatus,
115
99
  trigger_type: triggerType,
116
- trigger_types: triggerTypes,
117
- from_date: fromDate,
118
- to_date: toDate,
100
+ trigger_types: normalizeCsvParam(triggerTypes),
101
+ from_date: normalizeDateParam(fromDate),
102
+ to_date: normalizeDateParam(toDate),
119
103
  min_cost: minCost,
120
104
  max_cost: maxCost,
121
105
  min_duration: minDuration,
122
106
  max_duration: maxDuration,
123
107
  search,
124
108
  sort_by: sortBy,
125
- fields,
109
+ fields: normalizeCsvParam(fields),
126
110
  before,
127
111
  after,
128
112
  limit,
@@ -130,7 +114,7 @@ export default class APIWorkflowRuns extends CompositionClient {
130
114
  };
131
115
  const cleanParams = Object.fromEntries(Object.entries(params).filter(([_, v]) => v !== undefined));
132
116
  return this._fetchJson(ZPaginatedList, {
133
- url: "/v1/workflows/runs",
117
+ url: "/workflows/runs",
134
118
  method: "GET",
135
119
  params: { ...cleanParams, ...(options?.params || {}) },
136
120
  headers: options?.headers,
@@ -138,18 +122,10 @@ export default class APIWorkflowRuns extends CompositionClient {
138
122
  }
139
123
  /**
140
124
  * Delete a workflow run and its associated step data.
141
- *
142
- * @param runId - The ID of the workflow run to delete
143
- * @param options - Optional request options
144
- *
145
- * @example
146
- * ```typescript
147
- * await client.workflows.runs.delete("run_abc123");
148
- * ```
149
125
  */
150
126
  async delete(runId, options) {
151
127
  return this._fetchJson({
152
- url: `/v1/workflows/runs/${runId}`,
128
+ url: `/workflows/runs/${runId}`,
153
129
  method: "DELETE",
154
130
  params: options?.params,
155
131
  headers: options?.headers,
@@ -157,17 +133,6 @@ export default class APIWorkflowRuns extends CompositionClient {
157
133
  }
158
134
  /**
159
135
  * Cancel a running or pending workflow run.
160
- *
161
- * @param runId - The ID of the workflow run to cancel
162
- * @param commandId - Optional idempotency key for deduplicating cancel commands
163
- * @param options - Optional request options
164
- * @returns The updated run with cancellation status
165
- *
166
- * @example
167
- * ```typescript
168
- * const result = await client.workflows.runs.cancel("run_abc123");
169
- * console.log(`Cancellation: ${result.cancellation_status}`);
170
- * ```
171
136
  */
172
137
  async cancel(runId, { commandId } = {}, options) {
173
138
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -175,7 +140,7 @@ export default class APIWorkflowRuns extends CompositionClient {
175
140
  if (commandId !== undefined)
176
141
  body.command_id = commandId;
177
142
  return this._fetchJson(ZCancelWorkflowResponse, {
178
- url: `/v1/workflows/runs/${runId}/cancel`,
143
+ url: `/workflows/runs/${runId}/cancel`,
179
144
  method: "POST",
180
145
  body: { ...body, ...(options?.body || {}) },
181
146
  params: options?.params,
@@ -184,17 +149,6 @@ export default class APIWorkflowRuns extends CompositionClient {
184
149
  }
185
150
  /**
186
151
  * Restart a completed or failed workflow run with the same inputs.
187
- *
188
- * @param runId - The ID of the workflow run to restart
189
- * @param commandId - Optional idempotency key for deduplicating restart commands
190
- * @param options - Optional request options
191
- * @returns The new workflow run
192
- *
193
- * @example
194
- * ```typescript
195
- * const newRun = await client.workflows.runs.restart("run_abc123");
196
- * console.log(`New run: ${newRun.id}`);
197
- * ```
198
152
  */
199
153
  async restart(runId, { commandId } = {}, options) {
200
154
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -202,7 +156,7 @@ export default class APIWorkflowRuns extends CompositionClient {
202
156
  if (commandId !== undefined)
203
157
  body.command_id = commandId;
204
158
  return this._fetchJson(ZWorkflowRun, {
205
- url: `/v1/workflows/runs/${runId}/restart`,
159
+ url: `/workflows/runs/${runId}/restart`,
206
160
  method: "POST",
207
161
  body: { ...body, ...(options?.body || {}) },
208
162
  params: options?.params,
@@ -211,24 +165,6 @@ export default class APIWorkflowRuns extends CompositionClient {
211
165
  }
212
166
  /**
213
167
  * Resume a workflow run after human-in-the-loop (HIL) review.
214
- *
215
- * @param runId - The ID of the workflow run to resume
216
- * @param nodeId - The ID of the HIL node being approved/rejected
217
- * @param approved - Whether the human approved the data
218
- * @param modifiedData - Optional modified data if the human made changes
219
- * @param commandId - Optional idempotency key for deduplicating resume commands
220
- * @param options - Optional request options
221
- * @returns The resume response with status and queue information
222
- *
223
- * @example
224
- * ```typescript
225
- * const result = await client.workflows.runs.resume("run_abc123", {
226
- * nodeId: "hil-node-1",
227
- * approved: true,
228
- * modifiedData: { field: "corrected value" },
229
- * });
230
- * console.log(`Resume status: ${result.resume_status}`);
231
- * ```
232
168
  */
233
169
  async resume(runId, { nodeId, approved, modifiedData, commandId, }, options) {
234
170
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -241,7 +177,7 @@ export default class APIWorkflowRuns extends CompositionClient {
241
177
  if (commandId !== undefined)
242
178
  body.command_id = commandId;
243
179
  return this._fetchJson(ZResumeWorkflowResponse, {
244
- url: `/v1/workflows/runs/${runId}/resume`,
180
+ url: `/workflows/runs/${runId}/resume`,
245
181
  method: "POST",
246
182
  body: { ...body, ...(options?.body || {}) },
247
183
  params: options?.params,
@@ -251,24 +187,21 @@ export default class APIWorkflowRuns extends CompositionClient {
251
187
  /**
252
188
  * Poll a workflow run until it reaches a terminal state.
253
189
  *
254
- * Terminal states: "completed", "error", "cancelled".
190
+ * Terminal states: "completed", "error", "cancelled", "waiting_for_human".
255
191
  *
256
192
  * @param runId - The ID of the workflow run to wait for
257
193
  * @param pollIntervalMs - Milliseconds between polls (default: 2000)
258
194
  * @param timeoutMs - Maximum time to wait in milliseconds (default: 600000 = 10 minutes)
259
- * @returns The workflow run in a terminal state
260
- * @throws Error if the run doesn't complete within the timeout
195
+ * @param onStatus - Optional callback invoked with the WorkflowRun on each poll
261
196
  *
262
197
  * @example
263
198
  * ```typescript
264
199
  * const run = await client.workflows.runs.waitForCompletion("run_abc123", {
265
- * pollIntervalMs: 1000,
266
- * timeoutMs: 300000,
200
+ * onStatus: (r) => console.log(`${r.status}...`),
267
201
  * });
268
- * console.log(`Final status: ${run.status}`);
269
202
  * ```
270
203
  */
271
- async waitForCompletion(runId, { pollIntervalMs = 2000, timeoutMs = 600000, } = {}) {
204
+ async waitForCompletion(runId, { pollIntervalMs = 2000, timeoutMs = 600000, onStatus, } = {}) {
272
205
  if (pollIntervalMs <= 0)
273
206
  throw new Error("pollIntervalMs must be positive");
274
207
  if (timeoutMs <= 0)
@@ -276,7 +209,9 @@ export default class APIWorkflowRuns extends CompositionClient {
276
209
  const deadline = Date.now() + timeoutMs;
277
210
  while (true) {
278
211
  const run = await this.get(runId);
279
- if (TERMINAL_STATUSES.has(run.status)) {
212
+ if (onStatus)
213
+ await onStatus(run);
214
+ if (TERMINAL_STATUSES.has(run.status) || run.status === "waiting_for_human") {
280
215
  return run;
281
216
  }
282
217
  if (Date.now() >= deadline) {
@@ -285,33 +220,97 @@ export default class APIWorkflowRuns extends CompositionClient {
285
220
  await sleep(pollIntervalMs);
286
221
  }
287
222
  }
223
+ async wait_for_completion(runId, { poll_interval_ms = 2000, timeout_ms = 600000, on_status, } = {}) {
224
+ return this.waitForCompletion(runId, {
225
+ pollIntervalMs: poll_interval_ms,
226
+ timeoutMs: timeout_ms,
227
+ onStatus: on_status,
228
+ });
229
+ }
288
230
  /**
289
231
  * Create a workflow run and wait for it to complete.
290
232
  *
291
- * Convenience method that combines create() and waitForCompletion().
292
- *
293
- * @param workflowId - The ID of the workflow to run
294
- * @param documents - Mapping of start node IDs to their input documents
295
- * @param jsonInputs - Mapping of start_json node IDs to their input JSON data
296
- * @param pollIntervalMs - Milliseconds between polls (default: 2000)
297
- * @param timeoutMs - Maximum time to wait in milliseconds (default: 600000)
298
- * @param options - Optional request options
299
- * @returns The workflow run in a terminal state
300
- *
301
233
  * @example
302
234
  * ```typescript
235
+ * import { raiseForStatus } from "retab";
236
+ *
303
237
  * const run = await client.workflows.runs.createAndWait({
304
238
  * workflowId: "wf_abc123",
305
239
  * documents: { "start-node-1": "./invoice.pdf" },
306
- * timeoutMs: 120000,
240
+ * onStatus: (r) => console.log(`${r.status}...`),
307
241
  * });
308
- * if (run.status === "completed") {
309
- * console.log("Outputs:", run.final_outputs);
310
- * }
242
+ * raiseForStatus(run);
243
+ * console.log(run.final_outputs);
311
244
  * ```
312
245
  */
313
- async createAndWait({ workflowId, documents, jsonInputs, pollIntervalMs = 2000, timeoutMs = 600000, }, options) {
246
+ async createAndWait({ workflowId, documents, jsonInputs, pollIntervalMs = 2000, timeoutMs = 600000, onStatus, }, options) {
314
247
  const run = await this.create({ workflowId, documents, jsonInputs }, options);
315
- return this.waitForCompletion(run.id, { pollIntervalMs, timeoutMs });
248
+ return this.waitForCompletion(run.id, { pollIntervalMs, timeoutMs, onStatus });
249
+ }
250
+ /**
251
+ * Get the configuration snapshot used for a run.
252
+ */
253
+ async getConfig(runId, options) {
254
+ return this._fetchJson(z.record(z.any()), {
255
+ url: `/workflows/runs/${runId}/config`,
256
+ method: "GET",
257
+ params: options?.params,
258
+ headers: options?.headers,
259
+ });
260
+ }
261
+ /**
262
+ * Get the DAG-ordered execution order for a run.
263
+ */
264
+ async executionOrder(runId, options) {
265
+ return this._fetchJson(z.record(z.any()), {
266
+ url: `/workflows/runs/${runId}/execution-order`,
267
+ method: "GET",
268
+ params: options?.params,
269
+ headers: options?.headers,
270
+ });
271
+ }
272
+ /**
273
+ * Get a signed URL for downloading a document from a run step.
274
+ */
275
+ async getDocumentUrl(runId, nodeId, options) {
276
+ return this._fetchJson(z.record(z.any()), {
277
+ url: `/workflows/runs/${runId}/documents/${nodeId}`,
278
+ method: "GET",
279
+ params: options?.params,
280
+ headers: options?.headers,
281
+ });
282
+ }
283
+ /**
284
+ * Export run results as structured CSV data.
285
+ *
286
+ * @returns Object with `csv_data` (string), `rows` (number), `columns` (number)
287
+ */
288
+ async export({ workflowId, nodeId, exportSource = "outputs", selectedRunIds, status, excludeStatus, fromDate, toDate, triggerTypes, preferredColumns, }, options) {
289
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
290
+ const body = {
291
+ workflow_id: workflowId,
292
+ node_id: nodeId,
293
+ export_source: exportSource,
294
+ preferred_columns: preferredColumns || [],
295
+ };
296
+ if (selectedRunIds !== undefined)
297
+ body.selected_run_ids = selectedRunIds;
298
+ if (status !== undefined)
299
+ body.status = status;
300
+ if (excludeStatus !== undefined)
301
+ body.exclude_status = excludeStatus;
302
+ if (fromDate !== undefined)
303
+ body.from_date = normalizeDateParam(fromDate);
304
+ if (toDate !== undefined)
305
+ body.to_date = normalizeDateParam(toDate);
306
+ if (triggerTypes !== undefined)
307
+ body.trigger_types = triggerTypes;
308
+ return this._fetchJson(ZWorkflowRunExportResponse, {
309
+ url: "/workflows/runs/export_payload",
310
+ method: "POST",
311
+ body: { ...body, ...(options?.body || {}) },
312
+ params: options?.params,
313
+ headers: options?.headers,
314
+ });
316
315
  }
317
316
  }
@@ -1,34 +1,25 @@
1
1
  import { CompositionClient, RequestOptions } from "../../../../client.js";
2
- import { StepOutputResponse, WorkflowRunStep } from "../../../../types.js";
2
+ import { StepOutputResponse, StepOutputsBatchResponse, WorkflowRunStep, WorkflowRun } from "../../../../types.js";
3
3
  /**
4
4
  * Workflow Run Steps API client for accessing step-level outputs.
5
5
  *
6
- * Usage: `client.workflows.runs.steps.get(runId, nodeId)` or `client.workflows.runs.steps.list(runId)`
6
+ * Usage: `client.workflows.runs.steps.get(runId, nodeId)` or `client.workflows.runs.steps.getMany(runId, nodeIds)`
7
7
  */
8
8
  export default class APIWorkflowRunSteps extends CompositionClient {
9
9
  constructor(client: CompositionClient);
10
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
11
+ * Get step status and handle data for a specific step in a workflow run.
17
12
  *
18
13
  * @example
19
14
  * ```typescript
20
15
  * const step = await client.workflows.runs.steps.get("run_abc123", "extract-node-1");
21
- * console.log(`Step status: ${step.status}, output:`, step.output);
16
+ * const data = step.handle_outputs?.["output-json-0"]?.data;
22
17
  * ```
23
18
  */
24
19
  get(runId: string, nodeId: string, options?: RequestOptions): Promise<StepOutputResponse>;
25
20
  /**
26
21
  * List all persisted step documents for a workflow run.
27
22
  *
28
- * @param runId - The ID of the workflow run
29
- * @param options - Optional request options
30
- * @returns All step documents for the run
31
- *
32
23
  * @example
33
24
  * ```typescript
34
25
  * const steps = await client.workflows.runs.steps.list("run_abc123");
@@ -38,5 +29,36 @@ export default class APIWorkflowRunSteps extends CompositionClient {
38
29
  * ```
39
30
  */
40
31
  list(runId: string, options?: RequestOptions): Promise<WorkflowRunStep[]>;
32
+ /**
33
+ * Batch-get step outputs for multiple nodes in a single request.
34
+ *
35
+ * @param runId - The workflow run ID
36
+ * @param nodeIds - List of node IDs to fetch outputs for
37
+ * @returns Step outputs keyed by node ID
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const batch = await client.workflows.runs.steps.getMany("run_abc123", ["extract-1", "classifier-1"]);
42
+ * console.log(batch.outputs["extract-1"]?.handle_outputs);
43
+ * ```
44
+ */
45
+ getMany(runId: string, nodeIds: string[], options?: RequestOptions): Promise<StepOutputsBatchResponse>;
46
+ get_many(runId: string, nodeIds: string[], options?: RequestOptions): Promise<StepOutputsBatchResponse>;
47
+ /**
48
+ * Fetch outputs for all steps in a workflow run in one call.
49
+ *
50
+ * Internally fetches the run to discover step node IDs, then batch-fetches all outputs.
51
+ *
52
+ * @param runId - The workflow run ID
53
+ * @returns Step outputs keyed by node ID
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const allOutputs = await client.workflows.runs.steps.getAll("run_abc123");
58
+ * console.log(allOutputs.outputs["extract-1"]?.handle_outputs);
59
+ * ```
60
+ */
61
+ getAll(run: WorkflowRun | string, options?: RequestOptions): Promise<StepOutputsBatchResponse>;
62
+ get_all(run: WorkflowRun | string, options?: RequestOptions): Promise<StepOutputsBatchResponse>;
41
63
  }
42
64
  //# sourceMappingURL=client.d.ts.map
@@ -1 +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,eAAe,EAElB,MAAM,sBAAsB,CAAC;AAG9B;;;;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;;;;;;;;;;;;;;OAcG;IACG,IAAI,CACN,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,eAAe,EAAE,CAAC;CAQhC"}
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,EAExB,eAAe,EAEf,WAAW,EAEd,MAAM,sBAAsB,CAAC;AAG9B;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,iBAAiB;gBAClD,MAAM,EAAE,iBAAiB;IAIrC;;;;;;;;OAQG;IACG,GAAG,CACL,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAS9B;;;;;;;;;;OAUG;IACG,IAAI,CACN,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,eAAe,EAAE,CAAC;IAS7B;;;;;;;;;;;;OAYG;IACG,OAAO,CACT,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,wBAAwB,CAAC;IAU9B,QAAQ,CACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,wBAAwB,CAAC;IAIpC;;;;;;;;;;;;;OAaG;IACG,MAAM,CACR,GAAG,EAAE,WAAW,GAAG,MAAM,EACzB,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,wBAAwB,CAAC;IAkB9B,OAAO,CACT,GAAG,EAAE,WAAW,GAAG,MAAM,EACzB,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,wBAAwB,CAAC;CAGvC"}
@@ -1,32 +1,27 @@
1
1
  import { CompositionClient } from "../../../../client.js";
2
- import { ZStepOutputResponse, ZWorkflowRunStep, } from "../../../../types.js";
2
+ import { ZStepOutputResponse, ZStepOutputsBatchResponse, ZWorkflowRunStep, ZWorkflowRun, } from "../../../../types.js";
3
3
  import * as z from "zod";
4
4
  /**
5
5
  * Workflow Run Steps API client for accessing step-level outputs.
6
6
  *
7
- * Usage: `client.workflows.runs.steps.get(runId, nodeId)` or `client.workflows.runs.steps.list(runId)`
7
+ * Usage: `client.workflows.runs.steps.get(runId, nodeId)` or `client.workflows.runs.steps.getMany(runId, nodeIds)`
8
8
  */
9
9
  export default class APIWorkflowRunSteps extends CompositionClient {
10
10
  constructor(client) {
11
11
  super(client);
12
12
  }
13
13
  /**
14
- * Get the full output data for a specific step in a workflow run.
15
- *
16
- * @param runId - The ID of the workflow run
17
- * @param nodeId - The ID of the node/step to get output for
18
- * @param options - Optional request options
19
- * @returns The step output with handle outputs and inputs
14
+ * Get step status and handle data for a specific step in a workflow run.
20
15
  *
21
16
  * @example
22
17
  * ```typescript
23
18
  * const step = await client.workflows.runs.steps.get("run_abc123", "extract-node-1");
24
- * console.log(`Step status: ${step.status}, output:`, step.output);
19
+ * const data = step.handle_outputs?.["output-json-0"]?.data;
25
20
  * ```
26
21
  */
27
22
  async get(runId, nodeId, options) {
28
23
  return this._fetchJson(ZStepOutputResponse, {
29
- url: `/v1/workflows/runs/${runId}/steps/${nodeId}`,
24
+ url: `/workflows/runs/${runId}/steps/${nodeId}`,
30
25
  method: "GET",
31
26
  params: options?.params,
32
27
  headers: options?.headers,
@@ -35,10 +30,6 @@ export default class APIWorkflowRunSteps extends CompositionClient {
35
30
  /**
36
31
  * List all persisted step documents for a workflow run.
37
32
  *
38
- * @param runId - The ID of the workflow run
39
- * @param options - Optional request options
40
- * @returns All step documents for the run
41
- *
42
33
  * @example
43
34
  * ```typescript
44
35
  * const steps = await client.workflows.runs.steps.list("run_abc123");
@@ -49,10 +40,67 @@ export default class APIWorkflowRunSteps extends CompositionClient {
49
40
  */
50
41
  async list(runId, options) {
51
42
  return this._fetchJson(z.array(ZWorkflowRunStep), {
52
- url: `/v1/workflows/runs/${runId}/steps`,
43
+ url: `/workflows/runs/${runId}/steps`,
53
44
  method: "GET",
54
45
  params: options?.params,
55
46
  headers: options?.headers,
56
47
  });
57
48
  }
49
+ /**
50
+ * Batch-get step outputs for multiple nodes in a single request.
51
+ *
52
+ * @param runId - The workflow run ID
53
+ * @param nodeIds - List of node IDs to fetch outputs for
54
+ * @returns Step outputs keyed by node ID
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const batch = await client.workflows.runs.steps.getMany("run_abc123", ["extract-1", "classifier-1"]);
59
+ * console.log(batch.outputs["extract-1"]?.handle_outputs);
60
+ * ```
61
+ */
62
+ async getMany(runId, nodeIds, options) {
63
+ return this._fetchJson(ZStepOutputsBatchResponse, {
64
+ url: `/workflows/runs/${runId}/steps/batch`,
65
+ method: "POST",
66
+ body: { node_ids: nodeIds, ...(options?.body || {}) },
67
+ params: options?.params,
68
+ headers: options?.headers,
69
+ });
70
+ }
71
+ async get_many(runId, nodeIds, options) {
72
+ return this.getMany(runId, nodeIds, options);
73
+ }
74
+ /**
75
+ * Fetch outputs for all steps in a workflow run in one call.
76
+ *
77
+ * Internally fetches the run to discover step node IDs, then batch-fetches all outputs.
78
+ *
79
+ * @param runId - The workflow run ID
80
+ * @returns Step outputs keyed by node ID
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const allOutputs = await client.workflows.runs.steps.getAll("run_abc123");
85
+ * console.log(allOutputs.outputs["extract-1"]?.handle_outputs);
86
+ * ```
87
+ */
88
+ async getAll(run, options) {
89
+ const workflowRun = typeof run === "string"
90
+ ? await this._fetchJson(ZWorkflowRun, {
91
+ url: `/workflows/runs/${run}`,
92
+ method: "GET",
93
+ params: options?.params,
94
+ headers: options?.headers,
95
+ })
96
+ : run;
97
+ const nodeIds = workflowRun.steps.map((s) => s.node_id);
98
+ if (nodeIds.length === 0) {
99
+ return { outputs: {} };
100
+ }
101
+ return this.getMany(workflowRun.id, nodeIds, options);
102
+ }
103
+ async get_all(run, options) {
104
+ return this.getAll(run, options);
105
+ }
58
106
  }
package/dist/client.d.ts CHANGED
@@ -5,7 +5,7 @@ type FetchParams = {
5
5
  params?: Record<string, any>;
6
6
  headers?: Record<string, any>;
7
7
  bodyMime?: "application/json" | "multipart/form-data";
8
- body?: Record<string, any>;
8
+ body?: Record<string, any> | unknown[];
9
9
  auth?: string[];
10
10
  };
11
11
  export declare class AbstractClient {
@@ -18,6 +18,8 @@ export declare class CompositionClient extends AbstractClient {
18
18
  protected _client: AbstractClient;
19
19
  constructor(client: AbstractClient);
20
20
  protected _fetch(params: FetchParams): Promise<Response>;
21
+ private _installPrepareMethods;
22
+ protected _capturePreparedRequest(methodName: string, args: unknown[]): Promise<FetchParams>;
21
23
  }
22
24
  export declare class APIError extends Error {
23
25
  status: number;
@@ -50,7 +52,7 @@ export declare class FetcherClient extends AbstractClient {
50
52
  params?: Record<string, any>;
51
53
  headers?: Record<string, any>;
52
54
  bodyMime?: "application/json" | "multipart/form-data";
53
- body?: Record<string, any>;
55
+ body?: Record<string, any> | unknown[];
54
56
  }): Promise<Response>;
55
57
  /**
56
58
  * Verify the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