@outputai/cli 0.16.1-next.219890f.0 → 0.16.1-next.54cf419.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.
Files changed (38) hide show
  1. package/dist/api/generated/api.d.ts +36 -4
  2. package/dist/api/generated/api.js +5 -2
  3. package/dist/assets/docker/docker-compose-dev.yml +1 -1
  4. package/dist/commands/workflow/cost.js +2 -2
  5. package/dist/commands/workflow/dataset/generate.js +2 -2
  6. package/dist/commands/workflow/dataset/list.d.ts +1 -0
  7. package/dist/commands/workflow/dataset/list.js +4 -0
  8. package/dist/commands/workflow/debug.js +2 -2
  9. package/dist/commands/workflow/history.js +2 -2
  10. package/dist/commands/workflow/input.js +2 -2
  11. package/dist/commands/workflow/list.js +2 -2
  12. package/dist/commands/workflow/monitor.js +2 -2
  13. package/dist/commands/workflow/reset.js +2 -2
  14. package/dist/commands/workflow/result.js +2 -2
  15. package/dist/commands/workflow/run.js +2 -2
  16. package/dist/commands/workflow/runs/list.js +2 -2
  17. package/dist/commands/workflow/start.js +2 -2
  18. package/dist/commands/workflow/start.spec.js +10 -0
  19. package/dist/commands/workflow/status.js +2 -2
  20. package/dist/commands/workflow/stop.js +2 -2
  21. package/dist/commands/workflow/terminate.js +2 -2
  22. package/dist/commands/workflow/test.js +2 -2
  23. package/dist/generated/framework_version.json +1 -1
  24. package/dist/services/trace_reader.d.ts +8 -0
  25. package/dist/services/trace_reader.js +29 -1
  26. package/dist/services/trace_reader.spec.js +37 -0
  27. package/dist/utils/error_handler.d.ts +25 -8
  28. package/dist/utils/error_handler.js +45 -13
  29. package/dist/utils/error_handler.spec.js +53 -7
  30. package/dist/utils/size_formatter.d.ts +7 -0
  31. package/dist/utils/size_formatter.js +12 -0
  32. package/dist/utils/size_formatter.spec.d.ts +1 -0
  33. package/dist/utils/size_formatter.spec.js +21 -0
  34. package/dist/views/dev/hooks/use_run_detail.d.ts +2 -0
  35. package/dist/views/dev/hooks/use_run_detail.js +8 -4
  36. package/dist/views/dev/modals/steps_modal.js +2 -2
  37. package/oclif.manifest.json +1 -1
  38. package/package.json +2 -2
@@ -20,6 +20,26 @@ export interface ErrorResponse {
20
20
  */
21
21
  workflowId?: string | null;
22
22
  }
23
+ export type TraceFileTooLargeResponseError = typeof TraceFileTooLargeResponseError[keyof typeof TraceFileTooLargeResponseError];
24
+ export declare const TraceFileTooLargeResponseError: {
25
+ readonly TraceFileTooLargeError: "TraceFileTooLargeError";
26
+ };
27
+ /**
28
+ * The trace file is bigger than the API serves inline. Download it directly with `downloadUrl`.
29
+ */
30
+ export interface TraceFileTooLargeResponse {
31
+ error: TraceFileTooLargeResponseError;
32
+ /** Human-readable error message */
33
+ message: string;
34
+ /** Trace file size in bytes */
35
+ size: number;
36
+ /** Maximum trace file size served inline, in bytes */
37
+ maxSize: number;
38
+ /** Signed S3 URL to download the trace file directly. Treat it as a secret, it grants read access until it expires. */
39
+ downloadUrl: string;
40
+ /** When `downloadUrl` stops working */
41
+ expiresAt: string;
42
+ }
23
43
  export type ValidationErrorResponseError = typeof ValidationErrorResponseError[keyof typeof ValidationErrorResponseError];
24
44
  export declare const ValidationErrorResponseError: {
25
45
  readonly ValidationError: "ValidationError";
@@ -370,6 +390,10 @@ export type BadRequestResponse = ValidationErrorResponse | ErrorResponse;
370
390
  * Workflow execution, workflow type, or catalog not found
371
391
  */
372
392
  export type NotFoundResponse = ErrorResponse;
393
+ /**
394
+ * The trace file is bigger than the API serves inline. The body carries a signed `downloadUrl`.
395
+ */
396
+ export type PayloadTooLargeResponse = TraceFileTooLargeResponse;
373
397
  /**
374
398
  * Synchronous execution timed out before workflow completed
375
399
  */
@@ -1109,6 +1133,10 @@ export type getWorkflowIdTraceLogResponse404 = {
1109
1133
  data: NotFoundResponse;
1110
1134
  status: 404;
1111
1135
  };
1136
+ export type getWorkflowIdTraceLogResponse413 = {
1137
+ data: PayloadTooLargeResponse;
1138
+ status: 413;
1139
+ };
1112
1140
  export type getWorkflowIdTraceLogResponse424 = {
1113
1141
  data: FailedDependencyResponse;
1114
1142
  status: 424;
@@ -1120,13 +1148,13 @@ export type getWorkflowIdTraceLogResponse500 = {
1120
1148
  export type getWorkflowIdTraceLogResponseSuccess = (getWorkflowIdTraceLogResponse200) & {
1121
1149
  headers: Headers;
1122
1150
  };
1123
- export type getWorkflowIdTraceLogResponseError = (getWorkflowIdTraceLogResponse404 | getWorkflowIdTraceLogResponse424 | getWorkflowIdTraceLogResponse500) & {
1151
+ export type getWorkflowIdTraceLogResponseError = (getWorkflowIdTraceLogResponse404 | getWorkflowIdTraceLogResponse413 | getWorkflowIdTraceLogResponse424 | getWorkflowIdTraceLogResponse500) & {
1124
1152
  headers: Headers;
1125
1153
  };
1126
1154
  export type getWorkflowIdTraceLogResponse = (getWorkflowIdTraceLogResponseSuccess | getWorkflowIdTraceLogResponseError);
1127
1155
  export declare const getGetWorkflowIdTraceLogUrl: (id: string) => string;
1128
1156
  /**
1129
- * Returns trace data for the latest run of the given workflow. If trace is stored remotely (S3), fetches and returns the data inline. If trace is local only, returns the local path. To pin a specific run, use `/workflow/{id}/runs/{rid}/trace-log`.
1157
+ * Returns trace data for the latest run of the given workflow. If trace is stored remotely (S3), fetches and returns the data inline, unless it is over 256 MB, in which case it responds 413 with a signed `downloadUrl` and `X-Trace-Size` and `X-Trace-Max-Size` headers. If trace is local only, returns the local path. To pin a specific run, use `/workflow/{id}/runs/{rid}/trace-log`.
1130
1158
  * @summary Get workflow trace log data (latest run)
1131
1159
  */
1132
1160
  export declare const getWorkflowIdTraceLog: (id: string, options?: Parameters<typeof customFetchInstance>[1]) => Promise<getWorkflowIdTraceLogResponse>;
@@ -1142,6 +1170,10 @@ export type getWorkflowIdRunsRidTraceLogResponse404 = {
1142
1170
  data: NotFoundResponse;
1143
1171
  status: 404;
1144
1172
  };
1173
+ export type getWorkflowIdRunsRidTraceLogResponse413 = {
1174
+ data: PayloadTooLargeResponse;
1175
+ status: 413;
1176
+ };
1145
1177
  export type getWorkflowIdRunsRidTraceLogResponse424 = {
1146
1178
  data: FailedDependencyResponse;
1147
1179
  status: 424;
@@ -1153,13 +1185,13 @@ export type getWorkflowIdRunsRidTraceLogResponse500 = {
1153
1185
  export type getWorkflowIdRunsRidTraceLogResponseSuccess = (getWorkflowIdRunsRidTraceLogResponse200) & {
1154
1186
  headers: Headers;
1155
1187
  };
1156
- export type getWorkflowIdRunsRidTraceLogResponseError = (getWorkflowIdRunsRidTraceLogResponse400 | getWorkflowIdRunsRidTraceLogResponse404 | getWorkflowIdRunsRidTraceLogResponse424 | getWorkflowIdRunsRidTraceLogResponse500) & {
1188
+ export type getWorkflowIdRunsRidTraceLogResponseError = (getWorkflowIdRunsRidTraceLogResponse400 | getWorkflowIdRunsRidTraceLogResponse404 | getWorkflowIdRunsRidTraceLogResponse413 | getWorkflowIdRunsRidTraceLogResponse424 | getWorkflowIdRunsRidTraceLogResponse500) & {
1157
1189
  headers: Headers;
1158
1190
  };
1159
1191
  export type getWorkflowIdRunsRidTraceLogResponse = (getWorkflowIdRunsRidTraceLogResponseSuccess | getWorkflowIdRunsRidTraceLogResponseError);
1160
1192
  export declare const getGetWorkflowIdRunsRidTraceLogUrl: (id: string, rid: string) => string;
1161
1193
  /**
1162
- * Returns trace data for a pinned workflow run. If trace is stored remotely (S3), fetches and returns the data inline. If trace is local only, returns the local path.
1194
+ * Returns trace data for a pinned workflow run. If trace is stored remotely (S3), fetches and returns the data inline, unless it is over 256 MB, in which case it responds 413 with a signed `downloadUrl` and `X-Trace-Size` and `X-Trace-Max-Size` headers. If trace is local only, returns the local path.
1163
1195
  * @summary Get workflow trace log data for a specific run
1164
1196
  */
1165
1197
  export declare const getWorkflowIdRunsRidTraceLog: (id: string, rid: string, options?: Parameters<typeof customFetchInstance>[1]) => Promise<getWorkflowIdRunsRidTraceLogResponse>;
@@ -6,6 +6,9 @@
6
6
  * OpenAPI spec version: 1.0.0
7
7
  */
8
8
  import { customFetchInstance } from '../http_client.js';
9
+ export const TraceFileTooLargeResponseError = {
10
+ TraceFileTooLargeError: 'TraceFileTooLargeError',
11
+ };
9
12
  export const ValidationErrorResponseError = {
10
13
  ValidationError: 'ValidationError',
11
14
  };
@@ -356,7 +359,7 @@ export const getGetWorkflowIdTraceLogUrl = (id) => {
356
359
  return `/workflow/${id}/trace-log`;
357
360
  };
358
361
  /**
359
- * Returns trace data for the latest run of the given workflow. If trace is stored remotely (S3), fetches and returns the data inline. If trace is local only, returns the local path. To pin a specific run, use `/workflow/{id}/runs/{rid}/trace-log`.
362
+ * Returns trace data for the latest run of the given workflow. If trace is stored remotely (S3), fetches and returns the data inline, unless it is over 256 MB, in which case it responds 413 with a signed `downloadUrl` and `X-Trace-Size` and `X-Trace-Max-Size` headers. If trace is local only, returns the local path. To pin a specific run, use `/workflow/{id}/runs/{rid}/trace-log`.
360
363
  * @summary Get workflow trace log data (latest run)
361
364
  */
362
365
  export const getWorkflowIdTraceLog = async (id, options) => {
@@ -369,7 +372,7 @@ export const getGetWorkflowIdRunsRidTraceLogUrl = (id, rid) => {
369
372
  return `/workflow/${id}/runs/${rid}/trace-log`;
370
373
  };
371
374
  /**
372
- * Returns trace data for a pinned workflow run. If trace is stored remotely (S3), fetches and returns the data inline. If trace is local only, returns the local path.
375
+ * Returns trace data for a pinned workflow run. If trace is stored remotely (S3), fetches and returns the data inline, unless it is over 256 MB, in which case it responds 413 with a signed `downloadUrl` and `X-Trace-Size` and `X-Trace-Max-Size` headers. If trace is local only, returns the local path.
373
376
  * @summary Get workflow trace log data for a specific run
374
377
  */
375
378
  export const getWorkflowIdRunsRidTraceLog = async (id, rid, options) => {
@@ -80,7 +80,7 @@ services:
80
80
  condition: service_healthy
81
81
  worker:
82
82
  condition: service_healthy
83
- image: outputai/api:${OUTPUT_API_VERSION:-0.16.1-next.219890f.0}
83
+ image: outputai/api:${OUTPUT_API_VERSION:-0.16.1-next.54cf419.0}
84
84
  init: true
85
85
  networks:
86
86
  - main
@@ -4,7 +4,7 @@ import { calculateCost, loadPricingConfig } from '#services/cost_calculator.js';
4
4
  import { getTrace } from '#services/trace_reader.js';
5
5
  import { formatCostReport } from '#utils/cost_formatter.js';
6
6
  import { getErrorCode } from '#utils/error_utils.js';
7
- import { handleApiError } from '#utils/error_handler.js';
7
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
8
8
  export default class WorkflowCost extends Command {
9
9
  static description = 'Calculate the cost of a workflow execution';
10
10
  static enableJsonFlag = true;
@@ -57,7 +57,7 @@ export default class WorkflowCost extends Command {
57
57
  }
58
58
  }
59
59
  async catch(error) {
60
- return handleApiError(error, (...args) => this.error(...args), {
60
+ return handleApiError(error, createErrorFn(this), {
61
61
  404: 'Workflow not found. Check the workflow ID and try again.'
62
62
  });
63
63
  }
@@ -7,7 +7,7 @@ import { getTrace } from '#services/trace_reader.js';
7
7
  import { extractDatasetFromTrace } from '#utils/trace_extractor.js';
8
8
  import { resolveScenarioPath, getScenarioNotFoundMessage } from '#utils/scenario_resolver.js';
9
9
  import { parseInputFlag } from '#utils/input_parser.js';
10
- import { handleApiError } from '#utils/error_handler.js';
10
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
11
11
  export default class DatasetGenerate extends Command {
12
12
  static description = 'Generate a dataset for a workflow from a scenario, trace file, or recent runs';
13
13
  static examples = [
@@ -165,7 +165,7 @@ export default class DatasetGenerate extends Command {
165
165
  ' - An input flag: output workflow dataset generate <workflow> --input <json>', { exit: 1 });
166
166
  }
167
167
  async catch(error) {
168
- return handleApiError(error, (...args) => this.error(...args), {
168
+ return handleApiError(error, createErrorFn(this), {
169
169
  404: 'Workflow not found. Check the workflow name.',
170
170
  500: 'Workflow execution failed.'
171
171
  });
@@ -11,4 +11,5 @@ export default class DatasetList extends Command {
11
11
  format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
12
  };
13
13
  run(): Promise<DatasetInfo[]>;
14
+ catch(error: Error): Promise<void>;
14
15
  }
@@ -1,6 +1,7 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import Table from 'cli-table3';
3
3
  import { listDatasets } from '#services/datasets.js';
4
+ import { createErrorFn, handleCommandError } from '#utils/error_handler.js';
4
5
  const OutputFormat = {
5
6
  TABLE: 'table',
6
7
  TEXT: 'text'
@@ -80,4 +81,7 @@ export default class DatasetList extends Command {
80
81
  this.log(`\nFound ${datasets.length} dataset(s) for "${args.workflowName}"`);
81
82
  return datasets;
82
83
  }
84
+ async catch(error) {
85
+ return handleCommandError(error, createErrorFn(this));
86
+ }
83
87
  }
@@ -1,7 +1,7 @@
1
1
  import { Args, Command } from '@oclif/core';
2
2
  import { displayDebugTree } from '#utils/trace_formatter.js';
3
3
  import { getTrace } from '#services/trace_reader.js';
4
- import { handleApiError } from '#utils/error_handler.js';
4
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
5
5
  export default class WorkflowDebug extends Command {
6
6
  static description = 'Get and display workflow execution trace for debugging';
7
7
  static enableJsonFlag = true;
@@ -34,7 +34,7 @@ export default class WorkflowDebug extends Command {
34
34
  this.log('Tip: Use --json for the full untruncated trace');
35
35
  }
36
36
  async catch(error) {
37
- return handleApiError(error, (...args) => this.error(...args), {
37
+ return handleApiError(error, createErrorFn(this), {
38
38
  404: 'Workflow not found or trace not available. Check the workflow ID.'
39
39
  });
40
40
  }
@@ -2,7 +2,7 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import { fetchWorkflowHistory } from '#services/workflow_history.js';
3
3
  import buildSpanLabels from '#utils/span_labels.js';
4
4
  import renderWaterfall, { formatDurationLabel } from '#utils/waterfall.js';
5
- import { handleApiError } from '#utils/error_handler.js';
5
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
6
6
  import { shouldColorize } from '#utils/color.js';
7
7
  const DEFAULT_WIDTH = 80;
8
8
  const OUTPUT_FORMAT = { JSON: 'json', TEXT: 'text' };
@@ -92,7 +92,7 @@ export default class WorkflowHistory extends Command {
92
92
  return `${workflowId} · run ${shortRun} · ${status ?? 'unknown'} · ${formatDurationLabel(totalDurationMs)}`;
93
93
  }
94
94
  async catch(error) {
95
- return handleApiError(error, (...args) => this.error(...args), {
95
+ return handleApiError(error, createErrorFn(this), {
96
96
  404: 'Workflow not found. Check the workflow ID.'
97
97
  });
98
98
  }
@@ -2,7 +2,7 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import fs from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import { getWorkflowIdInput, getWorkflowIdRunsRidInput } from '#api/generated/api.js';
5
- import { handleApiError } from '#utils/error_handler.js';
5
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
6
6
  export default class WorkflowInput extends Command {
7
7
  static description = 'Get the original input a workflow run was started with';
8
8
  static enableJsonFlag = true;
@@ -67,7 +67,7 @@ export default class WorkflowInput extends Command {
67
67
  return input;
68
68
  }
69
69
  async catch(error) {
70
- return handleApiError(error, (...args) => this.error(...args), {
70
+ return handleApiError(error, createErrorFn(this), {
71
71
  404: 'Workflow not found. Check the workflow ID.'
72
72
  });
73
73
  }
@@ -2,7 +2,7 @@ import { Command, Flags } from '@oclif/core';
2
2
  import Table from 'cli-table3';
3
3
  import { fetchWorkflowCatalog } from '#api/workflow_catalog.js';
4
4
  import { parseWorkflowDefinition, formatParameters } from '#api/parser.js';
5
- import { handleApiError } from '#utils/error_handler.js';
5
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
6
6
  import { listScenariosForWorkflow } from '#utils/scenario_resolver.js';
7
7
  const OUTPUT_FORMAT = {
8
8
  LIST: 'list',
@@ -149,7 +149,7 @@ export default class WorkflowList extends Command {
149
149
  return formatWorkflowsAsJson(workflows);
150
150
  }
151
151
  async catch(error) {
152
- return handleApiError(error, (...args) => this.error(...args), {
152
+ return handleApiError(error, createErrorFn(this), {
153
153
  404: 'Catalog not found.'
154
154
  });
155
155
  }
@@ -1,6 +1,6 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import { commandStreamIo, monitorErrorOverrides, streamWorkflowUpdates } from '#services/monitor_stream.js';
3
- import { handleCommandError } from '#utils/error_handler.js';
3
+ import { createErrorFn, handleCommandError } from '#utils/error_handler.js';
4
4
  import { monitorStreamFlags } from '#utils/monitor_flags.js';
5
5
  const OUTPUT_FORMAT = { JSON: 'json', TEXT: 'text' };
6
6
  /**
@@ -58,7 +58,7 @@ export default class WorkflowMonitor extends Command {
58
58
  }, commandStreamIo(this));
59
59
  }
60
60
  async catch(error) {
61
- return handleCommandError(error, (...args) => this.error(...args), {
61
+ return handleCommandError(error, createErrorFn(this), {
62
62
  ...monitorErrorOverrides(error),
63
63
  // Owned by this command rather than the shared overrides: here the id is the
64
64
  // argument the user typed, so pointing at it is actionable advice.
@@ -1,6 +1,6 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import { postWorkflowIdReset } from '#api/generated/api.js';
3
- import { handleApiError } from '#utils/error_handler.js';
3
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
4
4
  export default class WorkflowReset extends Command {
5
5
  static description = 'Reset a workflow to re-run from after a specific step';
6
6
  static examples = [
@@ -43,7 +43,7 @@ export default class WorkflowReset extends Command {
43
43
  this.log(`\n${output}`);
44
44
  }
45
45
  async catch(error) {
46
- return handleApiError(error, (...args) => this.error(...args), {
46
+ return handleApiError(error, createErrorFn(this), {
47
47
  404: 'Workflow or step not found. Check the workflow ID and step name.',
48
48
  409: 'Step has not completed yet. Cannot reset to an incomplete step.'
49
49
  });
@@ -1,7 +1,7 @@
1
1
  import { Args, Command } from '@oclif/core';
2
2
  import { getWorkflowIdResult } from '#api/generated/api.js';
3
3
  import { formatWorkflowResult, isErrorStatus } from '#utils/format_workflow_result.js';
4
- import { handleApiError } from '#utils/error_handler.js';
4
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
5
5
  export default class WorkflowResult extends Command {
6
6
  static description = 'Get workflow execution result';
7
7
  static enableJsonFlag = true;
@@ -30,7 +30,7 @@ export default class WorkflowResult extends Command {
30
30
  return data;
31
31
  }
32
32
  async catch(error) {
33
- return handleApiError(error, (...args) => this.error(...args), {
33
+ return handleApiError(error, createErrorFn(this), {
34
34
  404: 'Workflow not found. Check the workflow ID.'
35
35
  });
36
36
  }
@@ -1,7 +1,7 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import { postWorkflowRun } from '#api/generated/api.js';
3
3
  import { formatWorkflowResult, isErrorStatus } from '#utils/format_workflow_result.js';
4
- import { handleApiError } from '#utils/error_handler.js';
4
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
5
5
  import { resolveInput } from '#utils/resolve_input.js';
6
6
  import { parseSearchAttributesFlag } from '#utils/search_attributes_flag.js';
7
7
  import { getRetryDelayFromResponse } from '#utils/header_utils.js';
@@ -102,7 +102,7 @@ export default class WorkflowRun extends Command {
102
102
  return data;
103
103
  }
104
104
  async catch(error) {
105
- return handleApiError(error, (...args) => this.error(...args), {
105
+ return handleApiError(error, createErrorFn(this), {
106
106
  404: 'Workflow not found. Check the workflow name.',
107
107
  500: 'Workflow execution failed.',
108
108
  503: 'Workflow service temporarily unavailable.'
@@ -2,7 +2,7 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import Table from 'cli-table3';
3
3
  import { fetchWorkflowRuns } from '#services/workflow_runs.js';
4
4
  import { formatDate, formatDurationFromTimestamps } from '#utils/date_formatter.js';
5
- import { handleApiError } from '#utils/error_handler.js';
5
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
6
6
  const OUTPUT_FORMAT = {
7
7
  TABLE: 'table',
8
8
  TEXT: 'text'
@@ -102,7 +102,7 @@ export default class WorkflowRunsList extends Command {
102
102
  return runs;
103
103
  }
104
104
  async catch(error) {
105
- return handleApiError(error, (...args) => this.error(...args), {
105
+ return handleApiError(error, createErrorFn(this), {
106
106
  400: 'Invalid parameters provided.',
107
107
  503: 'Workflow service temporarily unavailable.'
108
108
  });
@@ -1,7 +1,7 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import { postWorkflowStart } from '#api/generated/api.js';
3
3
  import { commandStreamIo, monitorErrorOverrides, streamWorkflowUpdates } from '#services/monitor_stream.js';
4
- import { handleApiError, handleCommandError } from '#utils/error_handler.js';
4
+ import { createErrorFn, handleApiError, handleCommandError } from '#utils/error_handler.js';
5
5
  import { isErrorStatus } from '#utils/format_workflow_result.js';
6
6
  import { gatedMonitorStreamFlags, MONITOR_DEFAULTS } from '#utils/monitor_flags.js';
7
7
  import { resolveInput } from '#utils/resolve_input.js';
@@ -164,7 +164,7 @@ export default class WorkflowStart extends Command {
164
164
  return result;
165
165
  }
166
166
  async catch(error) {
167
- return handleCommandError(error, (...args) => this.error(...args), {
167
+ return handleCommandError(error, createErrorFn(this), {
168
168
  404: 'Workflow not found. Check the workflow name.'
169
169
  });
170
170
  }
@@ -2,6 +2,7 @@
2
2
  import { describe, it, expect, vi, beforeEach } from 'vitest';
3
3
  import { Parser } from '@oclif/core';
4
4
  import { CLIError } from '@oclif/core/errors';
5
+ import { ux } from '@oclif/core/ux';
5
6
  vi.mock('#api/generated/api.js', () => ({
6
7
  postWorkflowStart: vi.fn()
7
8
  }));
@@ -379,6 +380,15 @@ describe('workflow start command', () => {
379
380
  await expect(cmd.catch(usageError)).rejects.toBe(usageError);
380
381
  expect(cmd.error).not.toHaveBeenCalled();
381
382
  });
383
+ it('writes oclif errors as JSON to stderr with their own exit code under --json', async () => {
384
+ const { cmd } = await createCommand();
385
+ vi.spyOn(cmd, 'jsonEnabled').mockReturnValue(true);
386
+ const stderr = vi.spyOn(ux, 'stderr').mockImplementation(() => { });
387
+ const usageError = new CLIError('Cannot combine --monitor with --json.', { exit: 2 });
388
+ await expect(cmd.catch(usageError)).rejects.toMatchObject({ oclif: { exit: 2 } });
389
+ expect(JSON.parse(String(stderr.mock.calls[0][0]))).toEqual({ error: { message: 'Cannot combine --monitor with --json.' } });
390
+ expect(cmd.error).not.toHaveBeenCalled();
391
+ });
382
392
  });
383
393
  });
384
394
  });
@@ -1,6 +1,6 @@
1
1
  import { Args, Command } from '@oclif/core';
2
2
  import { getWorkflowIdStatus } from '#api/generated/api.js';
3
- import { handleApiError } from '#utils/error_handler.js';
3
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
4
4
  import { normalizeWorkflowStatus } from '#utils/normalize_workflow_status.js';
5
5
  function formatStatusText(result) {
6
6
  const lines = [
@@ -45,7 +45,7 @@ export default class WorkflowStatus extends Command {
45
45
  return data;
46
46
  }
47
47
  async catch(error) {
48
- return handleApiError(error, (...args) => this.error(...args), {
48
+ return handleApiError(error, createErrorFn(this), {
49
49
  404: 'Workflow not found. Check the workflow ID.'
50
50
  });
51
51
  }
@@ -1,6 +1,6 @@
1
1
  import { Args, Command } from '@oclif/core';
2
2
  import { patchWorkflowIdStop } from '#api/generated/api.js';
3
- import { handleApiError } from '#utils/error_handler.js';
3
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
4
4
  export default class WorkflowStop extends Command {
5
5
  static description = 'Stop a workflow execution';
6
6
  static examples = [
@@ -24,7 +24,7 @@ export default class WorkflowStop extends Command {
24
24
  this.log(`\n${output}`);
25
25
  }
26
26
  async catch(error) {
27
- return handleApiError(error, (...args) => this.error(...args), {
27
+ return handleApiError(error, createErrorFn(this), {
28
28
  404: 'Workflow not found. Check the workflow ID.'
29
29
  });
30
30
  }
@@ -1,6 +1,6 @@
1
1
  import { Args, Command, Flags } from '@oclif/core';
2
2
  import { postWorkflowIdTerminate } from '#api/generated/api.js';
3
- import { handleApiError } from '#utils/error_handler.js';
3
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
4
4
  export default class WorkflowTerminate extends Command {
5
5
  static description = 'Terminate a workflow execution (force stop)';
6
6
  static examples = [
@@ -32,7 +32,7 @@ export default class WorkflowTerminate extends Command {
32
32
  this.log(`\n${output}`);
33
33
  }
34
34
  async catch(error) {
35
- return handleApiError(error, (...args) => this.error(...args), {
35
+ return handleApiError(error, createErrorFn(this), {
36
36
  404: 'Workflow not found. Check the workflow ID.'
37
37
  });
38
38
  }
@@ -4,7 +4,7 @@ import { postWorkflowRun } from '#api/generated/api.js';
4
4
  import { readAllDatasets, writeDataset } from '#services/datasets.js';
5
5
  import { fetchWorkflowCatalog } from '#api/workflow_catalog.js';
6
6
  import { diagnoseMissingEvalWorkflow } from '#utils/eval_diagnostics.js';
7
- import { handleApiError } from '#utils/error_handler.js';
7
+ import { createErrorFn, handleApiError } from '#utils/error_handler.js';
8
8
  import { getEvalWorkflowName } from '#utils/eval_naming.js';
9
9
  import { renderEvalOutput, computeExitCode } from '#utils/eval_render.js';
10
10
  import { EvalOutputSchema } from '@outputai/core/evals';
@@ -153,7 +153,7 @@ export default class WorkflowTest extends Command {
153
153
  }
154
154
  }
155
155
  async catch(error) {
156
- return handleApiError(error, (...args) => this.error(...args), {
156
+ return handleApiError(error, createErrorFn(this), {
157
157
  404: 'Workflow or eval workflow not found. Check the workflow name.',
158
158
  500: 'Workflow execution failed.'
159
159
  });
@@ -1,3 +1,3 @@
1
1
  {
2
- "framework": "0.16.1-next.219890f.0"
2
+ "framework": "0.16.1-next.54cf419.0"
3
3
  }
@@ -8,6 +8,14 @@ export interface TraceResult {
8
8
  data: TraceData;
9
9
  location: TraceLocation;
10
10
  }
11
+ /**
12
+ * Builds the user-facing message for the API's 413 (trace too big to be served), even though the response
13
+ * carries a download URL. The CLI does not download these files.
14
+ *
15
+ * @param error - Error thrown by a trace log request
16
+ * @returns The message, or null when the error is not a 413
17
+ */
18
+ export declare function buildTraceTooLargeMessage(error: unknown): string | null;
11
19
  /**
12
20
  * Get trace data from workflow ID using the API
13
21
  * The API handles S3 fetching - CLI only needs to read local files when necessary
@@ -1,6 +1,8 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { getWorkflowIdTraceLog } from '#api/generated/api.js';
3
+ import { HttpError } from '#api/http_client.js';
3
4
  import { getErrorCode } from '#utils/error_utils.js';
5
+ import { formatBytes } from '#utils/size_formatter.js';
4
6
  /**
5
7
  * Read and parse trace file from local path
6
8
  */
@@ -19,13 +21,39 @@ async function readLocalTraceFile(path) {
19
21
  throw error;
20
22
  }
21
23
  }
24
+ /**
25
+ * Builds the user-facing message for the API's 413 (trace too big to be served), even though the response
26
+ * carries a download URL. The CLI does not download these files.
27
+ *
28
+ * @param error - Error thrown by a trace log request
29
+ * @returns The message, or null when the error is not a 413
30
+ */
31
+ export function buildTraceTooLargeMessage(error) {
32
+ if (!(error instanceof HttpError) || error.response.status !== 413) {
33
+ return null;
34
+ }
35
+ const { size, maxSize } = (error.response.data ?? {});
36
+ const message = 'Trace file is too big for this feature.';
37
+ return typeof size === 'number' && typeof maxSize === 'number' ?
38
+ `${message} Max size ${formatBytes(maxSize)}, file size ${formatBytes(size)}` :
39
+ message;
40
+ }
41
+ async function fetchTraceLog(workflowId) {
42
+ try {
43
+ return await getWorkflowIdTraceLog(workflowId);
44
+ }
45
+ catch (error) {
46
+ const message = buildTraceTooLargeMessage(error);
47
+ throw message ? new Error(message) : error;
48
+ }
49
+ }
22
50
  /**
23
51
  * Get trace data from workflow ID using the API
24
52
  * The API handles S3 fetching - CLI only needs to read local files when necessary
25
53
  * @returns Both the trace data and the location it was fetched from
26
54
  */
27
55
  export async function getTrace(workflowId) {
28
- const response = await getWorkflowIdTraceLog(workflowId);
56
+ const response = await fetchTraceLog(workflowId);
29
57
  if (response.status === 404) {
30
58
  throw new Error(`Workflow not found or no trace available: ${workflowId}`);
31
59
  }
@@ -1,4 +1,5 @@
1
1
  import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
2
+ import { HttpError } from '#api/http_client.js';
2
3
  const mockGetWorkflowIdTraceLog = vi.fn();
3
4
  vi.mock('#api/generated/api.js', () => ({
4
5
  getWorkflowIdTraceLog: (...args) => mockGetWorkflowIdTraceLog(...args)
@@ -75,4 +76,40 @@ describe('trace_reader', () => {
75
76
  .toThrow('S3 access denied');
76
77
  });
77
78
  });
79
+ describe('buildTraceTooLargeMessage', () => {
80
+ it('should build the friendly message with both sizes for a 413', async () => {
81
+ const error = new HttpError('Payload Too Large', { status: 413, data: { size: 587158372, maxSize: 268435456 } });
82
+ const { buildTraceTooLargeMessage } = await import('./trace_reader.js');
83
+ expect(buildTraceTooLargeMessage(error))
84
+ .toBe('Trace file is too big for this feature. Max size 256 MB, file size 560 MB');
85
+ });
86
+ it('should omit the sizes when the 413 body does not carry them', async () => {
87
+ const { buildTraceTooLargeMessage } = await import('./trace_reader.js');
88
+ expect(buildTraceTooLargeMessage(new HttpError('Payload Too Large', { status: 413 })))
89
+ .toBe('Trace file is too big for this feature.');
90
+ expect(buildTraceTooLargeMessage(new HttpError('Payload Too Large', { status: 413, data: { size: 'x' } })))
91
+ .toBe('Trace file is too big for this feature.');
92
+ });
93
+ it('should return null for other statuses and other errors', async () => {
94
+ const { buildTraceTooLargeMessage } = await import('./trace_reader.js');
95
+ expect(buildTraceTooLargeMessage(new HttpError('Server error', { status: 500 }))).toBeNull();
96
+ expect(buildTraceTooLargeMessage(new Error('boom'))).toBeNull();
97
+ expect(buildTraceTooLargeMessage(undefined)).toBeNull();
98
+ });
99
+ });
100
+ describe('getTrace with a 413', () => {
101
+ it('should throw the friendly message instead of the HTTP error', async () => {
102
+ mockGetWorkflowIdTraceLog.mockRejectedValue(new HttpError('Payload Too Large', { status: 413, data: { size: 587158372, maxSize: 268435456 } }));
103
+ const { getTrace } = await import('./trace_reader.js');
104
+ await expect(getTrace('wf-123'))
105
+ .rejects
106
+ .toThrow('Trace file is too big for this feature. Max size 256 MB, file size 560 MB');
107
+ });
108
+ it('should rethrow other request errors unchanged', async () => {
109
+ const error = new HttpError('Server error', { status: 500 });
110
+ mockGetWorkflowIdTraceLog.mockRejectedValue(error);
111
+ const { getTrace } = await import('./trace_reader.js');
112
+ await expect(getTrace('wf-123')).rejects.toBe(error);
113
+ });
114
+ });
78
115
  });
@@ -1,18 +1,35 @@
1
+ import type { Command } from '@oclif/core';
2
+ import { CLIError } from '@oclif/core/errors';
3
+ type ErrorOptions = {
4
+ exit: number;
5
+ status?: number;
6
+ code?: string;
7
+ original?: CLIError;
8
+ };
9
+ type ErrorFn = (message: string, options: ErrorOptions) => never;
1
10
  type ErrorOverrides = {
2
11
  [statusCode: number]: string;
3
12
  ECONNREFUSED?: string;
4
13
  };
5
- export declare function handleApiError(error: unknown, errorFn: (...args: [message: string, options: {
6
- exit: number;
7
- }]) => never, overrides?: ErrorOverrides): never;
14
+ /**
15
+ * Builds the `errorFn` a `--json` capable command hands to `handleApiError` and `handleCommandError`.
16
+ * In text mode it fails through `command.error()`, or rethrows the original oclif error when one is given.
17
+ * Under `--json` it writes `{ error: { message, status?, code? } }` to stderr and throws an `ExitError`, which
18
+ * oclif exits on without printing anything else. Stdout stays reserved for results, so it is empty on failure and
19
+ * the exit code says which. `command.error()` alone cannot do this: it only throws a plain-text error, and oclif's
20
+ * own JSON error handling lives in its default `catch()`, which the commands override.
21
+ *
22
+ * @param command - The command whose `catch()` reports the error
23
+ * @returns The error reporter
24
+ */
25
+ export declare function createErrorFn(command: Command): ErrorFn;
26
+ export declare function handleApiError(error: unknown, errorFn: ErrorFn, overrides?: ErrorOverrides): never;
8
27
  /**
9
28
  * `catch()` handling for a command that raises oclif errors of its own. Flag
10
29
  * relationship failures and every `this.error( ..., { exit } )` already carry an
11
30
  * exit code and formatted output, and `handleApiError` would flatten all of it
12
- * to a bare exit 1 — so pass those straight through and only map what actually
13
- * came back from the API.
31
+ * to a bare exit 1 - so hand those to `errorFn` with their own exit code and the
32
+ * original error, and only map what actually came back from the API.
14
33
  */
15
- export declare function handleCommandError(error: Error, errorFn: (...args: [message: string, options: {
16
- exit: number;
17
- }]) => never, overrides?: ErrorOverrides): never;
34
+ export declare function handleCommandError(error: Error, errorFn: ErrorFn, overrides?: ErrorOverrides): never;
18
35
  export {};
@@ -1,4 +1,5 @@
1
- import { CLIError } from '@oclif/core/errors';
1
+ import { CLIError, ExitError } from '@oclif/core/errors';
2
+ import { ux } from '@oclif/core/ux';
2
3
  import { config } from '#config.js';
3
4
  function getDefaultMessages() {
4
5
  return {
@@ -50,46 +51,77 @@ function getDetailedErrorMessage(error) {
50
51
  }
51
52
  return parts.length > 0 ? parts.join(' | ') : 'Unknown error';
52
53
  }
54
+ /**
55
+ * Builds the `errorFn` a `--json` capable command hands to `handleApiError` and `handleCommandError`.
56
+ * In text mode it fails through `command.error()`, or rethrows the original oclif error when one is given.
57
+ * Under `--json` it writes `{ error: { message, status?, code? } }` to stderr and throws an `ExitError`, which
58
+ * oclif exits on without printing anything else. Stdout stays reserved for results, so it is empty on failure and
59
+ * the exit code says which. `command.error()` alone cannot do this: it only throws a plain-text error, and oclif's
60
+ * own JSON error handling lives in its default `catch()`, which the commands override.
61
+ *
62
+ * @param command - The command whose `catch()` reports the error
63
+ * @returns The error reporter
64
+ */
65
+ export function createErrorFn(command) {
66
+ return (message, { exit, status, code, original }) => {
67
+ if (!command.jsonEnabled()) {
68
+ if (original) {
69
+ throw original;
70
+ }
71
+ return command.error(message, { exit });
72
+ }
73
+ ux.stderr(JSON.stringify({
74
+ error: {
75
+ message,
76
+ ...(status === undefined ? {} : { status }),
77
+ ...(code === undefined ? {} : { code })
78
+ }
79
+ }, null, 2));
80
+ throw new ExitError(exit);
81
+ };
82
+ }
53
83
  export function handleApiError(error, errorFn, overrides = {}) {
54
84
  const apiError = error;
55
85
  const errorMessages = { ...getDefaultMessages(), ...overrides };
86
+ const status = apiError.response?.status;
87
+ const code = apiError.code ?? apiError.cause?.code;
88
+ const fail = (message) => errorFn(message, { exit: 1, status, code });
56
89
  if (apiError.code === 'ECONNREFUSED' || apiError.cause?.code === 'ECONNREFUSED') {
57
- errorFn(errorMessages.ECONNREFUSED, { exit: 1 });
90
+ fail(errorMessages.ECONNREFUSED);
58
91
  }
59
- if (apiError.response?.status) {
60
- const status = apiError.response.status;
92
+ if (status) {
61
93
  // A caller-supplied override for this exact status wins over the raw server body. The API's
62
94
  // 404 body is a bare "WorkflowNotFoundError: ..." that the friendly override is meant to
63
95
  // replace; without this, extractApiErrorDetails consumes the body first and every command's
64
96
  // per-status override is dead code. Defaults are not consulted here, so commands that pass no
65
97
  // override still get the rich server detail below.
66
98
  if (status in overrides) {
67
- errorFn(overrides[status], { exit: 1 });
99
+ fail(overrides[status]);
68
100
  }
69
101
  // Extract error details from response body
70
- const apiErrorDetails = extractApiErrorDetails(apiError.response.data);
102
+ const apiErrorDetails = extractApiErrorDetails(apiError.response?.data);
71
103
  if (apiErrorDetails) {
72
104
  const { errorType, errorMsg } = apiErrorDetails;
73
- errorFn(`${errorType}: ${errorMsg}`, { exit: 1 });
105
+ fail(`${errorType}: ${errorMsg}`);
74
106
  }
75
107
  const message = errorMessages[status];
76
108
  if (message) {
77
- errorFn(message, { exit: 1 });
109
+ fail(message);
78
110
  }
79
111
  }
80
- const detailedMessage = getDetailedErrorMessage(error);
81
- errorFn(detailedMessage, { exit: 1 });
112
+ return fail(getDetailedErrorMessage(error));
82
113
  }
83
114
  /**
84
115
  * `catch()` handling for a command that raises oclif errors of its own. Flag
85
116
  * relationship failures and every `this.error( ..., { exit } )` already carry an
86
117
  * exit code and formatted output, and `handleApiError` would flatten all of it
87
- * to a bare exit 1 — so pass those straight through and only map what actually
88
- * came back from the API.
118
+ * to a bare exit 1 - so hand those to `errorFn` with their own exit code and the
119
+ * original error, and only map what actually came back from the API.
89
120
  */
90
121
  export function handleCommandError(error, errorFn, overrides = {}) {
91
122
  if (error instanceof CLIError) {
92
- throw error;
123
+ const exit = typeof error.oclif?.exit === 'number' ? error.oclif.exit : 1;
124
+ return errorFn(error.message, { exit, original: error });
93
125
  }
94
126
  return handleApiError(error, errorFn, overrides);
95
127
  }
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { describe, it, expect, vi } from 'vitest';
3
- import { CLIError } from '@oclif/core/errors';
4
- import { handleApiError, handleCommandError } from './error_handler.js';
2
+ import { describe, it, expect, vi, afterEach } from 'vitest';
3
+ import { CLIError, ExitError } from '@oclif/core/errors';
4
+ import { ux } from '@oclif/core/ux';
5
+ import { createErrorFn, handleApiError, handleCommandError } from './error_handler.js';
5
6
  const errorFn = () => vi.fn((message) => {
6
7
  throw new Error(message);
7
8
  });
@@ -42,21 +43,66 @@ describe('handleApiError()', () => {
42
43
  it('always exits 1, leaving a command\'s own exit codes to the command', () => {
43
44
  const fn = errorFn();
44
45
  expect(() => handleApiError(apiError(500), fn)).toThrow();
45
- expect(fn).toHaveBeenCalledWith(expect.any(String), { exit: 1 });
46
+ expect(fn).toHaveBeenCalledWith(expect.any(String), { exit: 1, status: 500, code: undefined });
47
+ });
48
+ it('passes the HTTP status and the error code along for structured output', () => {
49
+ const fn = errorFn();
50
+ const error = Object.assign(new Error('fetch failed'), { cause: { code: 'ECONNREFUSED' } });
51
+ expect(() => handleApiError(error, fn)).toThrow();
52
+ expect(fn).toHaveBeenCalledWith(expect.any(String), { exit: 1, status: undefined, code: 'ECONNREFUSED' });
46
53
  });
47
54
  });
48
55
  describe('handleCommandError()', () => {
49
- it('rethrows an oclif error untouched so its exit code and formatting survive', () => {
56
+ it('hands an oclif error to errorFn with its own exit code and the original error', () => {
50
57
  const fn = errorFn();
51
58
  // `workflow start --monitor` raises exit 2 (bad flag combination) and exit 3
52
59
  // (started but unmonitorable); flattening those to exit 1 would let a CI job
53
60
  // retrying on a failed workflow re-submit one that is already running.
54
61
  const cliError = new CLIError('Cannot combine --monitor with --json', { exit: 2 });
55
- expect(() => handleCommandError(cliError, fn)).toThrow(cliError);
56
- expect(fn).not.toHaveBeenCalled();
62
+ expect(() => handleCommandError(cliError, fn)).toThrow();
63
+ expect(fn).toHaveBeenCalledWith('Cannot combine --monitor with --json', { exit: 2, original: cliError });
57
64
  });
58
65
  it('maps anything that came back from the API the same way handleApiError does', () => {
59
66
  const fn = errorFn();
60
67
  expect(() => handleCommandError(apiError(404), fn, { 404: 'Workflow not found. Check the workflow name.' })).toThrow('Workflow not found. Check the workflow name.');
61
68
  });
62
69
  });
70
+ describe('createErrorFn()', () => {
71
+ afterEach(() => {
72
+ vi.restoreAllMocks();
73
+ });
74
+ const command = (isJson) => ({
75
+ jsonEnabled: () => isJson,
76
+ error: vi.fn((message) => {
77
+ throw new Error(message);
78
+ })
79
+ });
80
+ const printedJson = (stderr) => JSON.parse(String(stderr.mock.calls[0][0]));
81
+ it('fails through command.error() with the exit code in text mode', () => {
82
+ const cmd = command(false);
83
+ expect(() => createErrorFn(cmd)('Workflow not found.', { exit: 1, status: 404 })).toThrow('Workflow not found.');
84
+ expect(cmd.error).toHaveBeenCalledWith('Workflow not found.', { exit: 1 });
85
+ });
86
+ it('rethrows the original oclif error in text mode', () => {
87
+ const cmd = command(false);
88
+ const original = new CLIError('bad flags', { exit: 2 });
89
+ expect(() => createErrorFn(cmd)(original.message, { exit: 2, original })).toThrow(original);
90
+ expect(cmd.error).not.toHaveBeenCalled();
91
+ });
92
+ it('writes the error as JSON to stderr, leaves stdout alone and exits without printing in json mode', () => {
93
+ const stderr = vi.spyOn(ux, 'stderr').mockImplementation(() => { });
94
+ const stdout = vi.spyOn(ux, 'stdout').mockImplementation(() => { });
95
+ const cmd = command(true);
96
+ const fail = createErrorFn(cmd);
97
+ expect(() => fail('Workflow not found.', { exit: 1, status: 404, code: undefined })).toThrow(ExitError);
98
+ expect(printedJson(stderr)).toEqual({ error: { message: 'Workflow not found.', status: 404 } });
99
+ expect(stdout).not.toHaveBeenCalled();
100
+ expect(cmd.error).not.toHaveBeenCalled();
101
+ });
102
+ it('keeps the exit code of an oclif error in json mode and includes the error code', () => {
103
+ const stderr = vi.spyOn(ux, 'stderr').mockImplementation(() => { });
104
+ const original = new CLIError('Cannot combine --monitor with --json', { exit: 2 });
105
+ expect(() => createErrorFn(command(true))(original.message, { exit: 2, code: 'ECONNREFUSED', original })).toThrow(expect.objectContaining({ oclif: { exit: 2 } }));
106
+ expect(printedJson(stderr)).toEqual({ error: { message: 'Cannot combine --monitor with --json', code: 'ECONNREFUSED' } });
107
+ });
108
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Formats a byte count for humans in binary units (1 MB = 1024 KB), as S3 reports sizes.
3
+ *
4
+ * @param bytes - Size in bytes
5
+ * @returns Size such as `256 MB` or `1.5 KB`
6
+ */
7
+ export declare function formatBytes(bytes: number): string;
@@ -0,0 +1,12 @@
1
+ const units = ['B', 'KB', 'MB', 'GB'];
2
+ /**
3
+ * Formats a byte count for humans in binary units (1 MB = 1024 KB), as S3 reports sizes.
4
+ *
5
+ * @param bytes - Size in bytes
6
+ * @returns Size such as `256 MB` or `1.5 KB`
7
+ */
8
+ export function formatBytes(bytes) {
9
+ const index = bytes > 0 ? Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1) : 0;
10
+ const value = bytes / (1024 ** index);
11
+ return `${Number(value.toFixed(1))} ${units[index]}`;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { formatBytes } from '#utils/size_formatter.js';
3
+ describe('formatBytes', () => {
4
+ it('formats zero and small values in bytes', () => {
5
+ expect(formatBytes(0)).toBe('0 B');
6
+ expect(formatBytes(512)).toBe('512 B');
7
+ });
8
+ it('uses 1024-based units', () => {
9
+ expect(formatBytes(1024)).toBe('1 KB');
10
+ expect(formatBytes(1024 * 1024)).toBe('1 MB');
11
+ expect(formatBytes(256 * 1024 * 1024)).toBe('256 MB');
12
+ expect(formatBytes(1024 ** 3)).toBe('1 GB');
13
+ });
14
+ it('keeps one decimal at most and drops a trailing zero', () => {
15
+ expect(formatBytes(1536)).toBe('1.5 KB');
16
+ expect(formatBytes(587158372)).toBe('560 MB');
17
+ });
18
+ it('caps the unit at GB', () => {
19
+ expect(formatBytes(2048 * (1024 ** 3))).toBe('2048 GB');
20
+ });
21
+ });
@@ -13,6 +13,8 @@ export interface RunStep {
13
13
  export interface RunDetail {
14
14
  result: WorkflowResultResponse | null;
15
15
  trace: TraceData | null;
16
+ /** Why the trace is missing, when the API refused to serve it (for example, it is too big). */
17
+ traceError: string | null;
16
18
  steps: RunStep[];
17
19
  loading: boolean;
18
20
  }
@@ -4,9 +4,11 @@ import { getWorkflowIdResult, getWorkflowIdRunsRidResult, getWorkflowIdTraceLog,
4
4
  import { normalizeWorkflowStatus } from '#utils/normalize_workflow_status.js';
5
5
  import { isTerminalStatus } from '#utils/format_workflow_result.js';
6
6
  import { createBoundedCache } from '#views/dev/utils/bounded_cache.js';
7
+ import { buildTraceTooLargeMessage } from '#services/trace_reader.js';
7
8
  const EMPTY_DETAIL = {
8
9
  result: null,
9
10
  trace: null,
11
+ traceError: null,
10
12
  steps: [],
11
13
  loading: false
12
14
  };
@@ -81,10 +83,11 @@ const fetchTrace = async (workflowId, runId) => {
81
83
  const response = runId ?
82
84
  await getWorkflowIdRunsRidTraceLog(workflowId, runId) :
83
85
  await getWorkflowIdTraceLog(workflowId);
84
- return await readTraceLog(response.data);
86
+ return { trace: await readTraceLog(response.data), traceError: null };
85
87
  }
86
- catch {
87
- return null;
88
+ catch (error) {
89
+ // A trace the API refuses to serve because of its size is the one failure worth telling the user about.
90
+ return { trace: null, traceError: buildTraceTooLargeMessage(error) };
88
91
  }
89
92
  };
90
93
  const fetchResult = async (workflowId, runId) => {
@@ -127,13 +130,14 @@ export const useRunDetail = (workflowId, runId, status) => {
127
130
  void Promise.all([
128
131
  fetchResult(workflowId, runId),
129
132
  fetchTrace(workflowId, runId)
130
- ]).then(([result, trace]) => {
133
+ ]).then(([result, { trace, traceError }]) => {
131
134
  if (fetchIdRef.current !== id) {
132
135
  return;
133
136
  }
134
137
  const next = {
135
138
  result,
136
139
  trace,
140
+ traceError,
137
141
  steps: extractSteps(trace),
138
142
  loading: false
139
143
  };
@@ -57,7 +57,7 @@ const StepDetail = ({ step, activeTab, rows }) => {
57
57
  };
58
58
  export const StepsModal = ({ run, height }) => {
59
59
  const ui = useUiState();
60
- const { steps, loading } = useRunDetail(run.workflowId, run.runId, run.status);
60
+ const { steps, loading, traceError } = useRunDetail(run.workflowId, run.runId, run.status);
61
61
  const { selectedIndex: clamped, selectPrevious, selectNext } = useListSelection(steps.length);
62
62
  const selectedStep = steps[clamped];
63
63
  const activeTab = ui.runStepPaneTab;
@@ -94,7 +94,7 @@ export const StepsModal = ({ run, height }) => {
94
94
  return (_jsx(LoadingSpinner, { label: "Loading steps..." }));
95
95
  }
96
96
  if (steps.length === 0) {
97
- return (_jsx(Text, { dimColor: true, children: "No steps recorded for this run." }));
97
+ return (_jsx(Text, { dimColor: true, children: traceError ?? 'No steps recorded for this run.' }));
98
98
  }
99
99
  return _jsx(StepDetail, { step: selectedStep, activeTab: activeTab, rows: rows });
100
100
  };
@@ -1772,5 +1772,5 @@
1772
1772
  ]
1773
1773
  }
1774
1774
  },
1775
- "version": "0.16.1-next.219890f.0"
1775
+ "version": "0.16.1-next.54cf419.0"
1776
1776
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/cli",
3
- "version": "0.16.1-next.219890f.0",
3
+ "version": "0.16.1-next.54cf419.0",
4
4
  "description": "CLI for Output.ai workflow generation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "react": "19.3.0",
38
38
  "semver": "7.8.5",
39
39
  "undici": "8.12.3",
40
- "@outputai/core": "0.16.1-next.219890f.0"
40
+ "@outputai/core": "0.16.1-next.54cf419.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/cli-progress": "3.11.6",