@pipelex/sdk 0.25.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -4
- package/dist/artifacts.js +1 -1
- package/dist/artifacts.js.map +1 -1
- package/dist/client.d.ts +50 -15
- package/dist/client.js +164 -51
- package/dist/client.js.map +1 -1
- package/dist/error-models.d.ts +198 -0
- package/dist/error-models.js +26 -0
- package/dist/error-models.js.map +1 -0
- package/dist/errors.d.ts +132 -26
- package/dist/errors.js +134 -23
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js.map +1 -1
- package/dist/method-source.d.ts +3 -3
- package/dist/method-source.js +3 -3
- package/dist/models.d.ts +147 -18
- package/dist/prepare-inputs.d.ts +35 -34
- package/dist/prepare-inputs.js +110 -129
- package/dist/prepare-inputs.js.map +1 -1
- package/dist/product-models.d.ts +4 -15
- package/dist/runs.d.ts +22 -8
- package/dist/runs.js +4 -3
- package/dist/runs.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/architecture.md +12 -11
- package/docs/artifact-download.md +1 -1
- package/docs/build-routes.md +1 -1
- package/docs/crate-routes.md +49 -12
- package/docs/errors.md +143 -0
- package/docs/input-preparation.md +16 -19
- package/docs/run-results.md +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error-report wire models — a failed run's stored report, and the typed members of a
|
|
3
|
+
* problem document.
|
|
4
|
+
*
|
|
5
|
+
* **The runner owns these shapes; this SDK follows them.** A run that fails reports why as
|
|
6
|
+
* the runner's `ErrorReport` (`pipelex.base_exceptions`), which the hosted platform stores
|
|
7
|
+
* whole on the run row as `error` and serves as it was stored: on the status read
|
|
8
|
+
* (`RunRead.error`), on the run records (`PipelineRun.error`), and inside the problem
|
|
9
|
+
* document of the results read's `409`, where the client lifts it onto the failed arm of
|
|
10
|
+
* `RunResultState` and onto `RunFailedError.error`. The same classification fields
|
|
11
|
+
* (`error_domain`, `user_action`, …) ride a runner-rendered problem document as extension
|
|
12
|
+
* members, which is why `ApiResponseError` types its members with the models declared here.
|
|
13
|
+
*
|
|
14
|
+
* Every field is optional and every interface keeps an index signature, for the reason
|
|
15
|
+
* `TokensUsageRecord` gives: the runner adds fields without asking this SDK, and a field this
|
|
16
|
+
* version does not name still reaches the caller. The enum-ish fields (`error_domain`,
|
|
17
|
+
* `error_category`, `user_action.kind`) are open sets on the wire and stay `string`, never
|
|
18
|
+
* frozen unions, so a value the runner adds is not an SDK break; their known values are listed
|
|
19
|
+
* where they are declared.
|
|
20
|
+
*
|
|
21
|
+
* **Nothing is stripped.** The platform serves the runner's VERBOSE report, so `message` and
|
|
22
|
+
* `provider_metadata` can hold a provider's raw text. Deciding what of it a person should see
|
|
23
|
+
* is each consumer's presentation, not this SDK's; the report arrives here whole.
|
|
24
|
+
*/
|
|
25
|
+
import type { ValidationErrorItem } from "./models.js";
|
|
26
|
+
/**
|
|
27
|
+
* The next step an error advises — the runner's `UserAction`, carried as `user_action` on a
|
|
28
|
+
* stored report and on a runner's problem document. `kind` names the category of advice, so a
|
|
29
|
+
* consumer can render consistent guidance; `detail` is the advice itself, in words (a billing
|
|
30
|
+
* URL, a retry hint, the model to change).
|
|
31
|
+
*
|
|
32
|
+
* Known `kind` values: `wait_and_retry`, `check_billing`, `check_credentials`, `change_input`,
|
|
33
|
+
* `change_model`, `contact_support`, `unknown`. The set is the runner's, so it is typed open.
|
|
34
|
+
* The shape is the one `mthds`'s `UserAction` declares, so a value moves between the two
|
|
35
|
+
* clients' errors unchanged.
|
|
36
|
+
*/
|
|
37
|
+
export interface UserAction {
|
|
38
|
+
kind: string;
|
|
39
|
+
detail: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What the inference provider's SDK said about a failed call — the runner's
|
|
43
|
+
* `ProviderErrorMetadata`. Present on a report whose failure came back from a model provider.
|
|
44
|
+
* `message` is the provider SDK's own text, relayed raw; the provider's response body never
|
|
45
|
+
* crosses the wire, because the runner excludes it from every serialization.
|
|
46
|
+
*
|
|
47
|
+
* **The hosted store turns its numbers into strings.** A report read back from the platform's
|
|
48
|
+
* run store carries `status_code` and `retry_after_seconds` as JSON strings (`"404"`,
|
|
49
|
+
* `"1.5"`), because the store hands its numbers back as decimals that the platform serializes
|
|
50
|
+
* as strings. A problem document rendered by a runner carries them as numbers. Both are typed,
|
|
51
|
+
* so read them with `Number(...)` when you need the value.
|
|
52
|
+
*/
|
|
53
|
+
export interface ProviderErrorMetadata {
|
|
54
|
+
provider?: string | null;
|
|
55
|
+
sdk_exception_type?: string | null;
|
|
56
|
+
message?: string | null;
|
|
57
|
+
/** The provider's HTTP status, when it answered one. */
|
|
58
|
+
status_code?: number | string | null;
|
|
59
|
+
/** The provider's own request id — what its support desk asks for. */
|
|
60
|
+
request_id?: string | null;
|
|
61
|
+
retry_after_seconds?: number | string | null;
|
|
62
|
+
provider_error_code?: string | null;
|
|
63
|
+
[extension: string]: unknown;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A pending configuration migration that explains the failure — the runner's
|
|
67
|
+
* `MigrationErrorBlock`. Present only on a configuration failure whose raiser scanned the
|
|
68
|
+
* host's configuration directories; a consumer branches on its presence. `plans` is carried
|
|
69
|
+
* opaquely: it is the shape `pipelex-agent migrate --dry-run --format json` emits, which no
|
|
70
|
+
* published package declares.
|
|
71
|
+
*/
|
|
72
|
+
export interface MigrationErrorBlock {
|
|
73
|
+
/** The command that applies whatever can be applied without a decision. */
|
|
74
|
+
remedy?: string | null;
|
|
75
|
+
/** Whether running `remedy` would rewrite any file. */
|
|
76
|
+
would_write?: boolean | null;
|
|
77
|
+
/** Whether something here is a person's to resolve rather than the tool's. */
|
|
78
|
+
needs_attention?: boolean | null;
|
|
79
|
+
plans?: Record<string, unknown>[] | null;
|
|
80
|
+
[extension: string]: unknown;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Why a run failed — the runner's `ErrorReport`, typed with every field it carries.
|
|
84
|
+
*
|
|
85
|
+
* The one type for a failed run's report wherever the SDK hands it back: `RunPublic.error`
|
|
86
|
+
* (and so `RunRead.error` on the status read), `PipelineRun.error` on the run records, `error`
|
|
87
|
+
* on the failed arm of `RunResultState` (the results read's `409`), and `RunFailedError.error`
|
|
88
|
+
* when `waitForResult`, `startAndWaitForResult` or an artifact download throws for a run that
|
|
89
|
+
* ended without a result.
|
|
90
|
+
*
|
|
91
|
+
* **Branch on `error_domain`, `type_uri` and `retryable`**, never on the wording of `message`.
|
|
92
|
+
* `error_type` is the runner's open-ended exception class name: finer than `error_domain`,
|
|
93
|
+
* useful in a support line, but not a closed set to match against. Which fault's identity a run
|
|
94
|
+
* failure's report carries, and how its `message` names the failing pipe, is the runner's to
|
|
95
|
+
* decide; read them as given.
|
|
96
|
+
*
|
|
97
|
+
* A report is `null` where the run has none — a cancelled, terminated or timed-out run, or one
|
|
98
|
+
* the platform finalized itself — so the absence of a report says nothing about why.
|
|
99
|
+
*/
|
|
100
|
+
export interface RunErrorReport {
|
|
101
|
+
/**
|
|
102
|
+
* The runner's exception class name (`LLMCompletionError`, `PipeRunError`, …) — an open
|
|
103
|
+
* set, for display and support, not for branching.
|
|
104
|
+
*/
|
|
105
|
+
error_type?: string | null;
|
|
106
|
+
/**
|
|
107
|
+
* What went wrong, as the runner wrote it. On the VERBOSE report the platform serves, it can
|
|
108
|
+
* carry a provider's raw text.
|
|
109
|
+
*/
|
|
110
|
+
message?: string | null;
|
|
111
|
+
/** A stable human label for the error class (`LLM completion`). */
|
|
112
|
+
title?: string | null;
|
|
113
|
+
/** The stable URI naming the error class — a branch field, and where its documentation lives. */
|
|
114
|
+
type_uri?: string | null;
|
|
115
|
+
/**
|
|
116
|
+
* Who can fix it, the coarse branch field. Known values: `input` (the caller — a malformed
|
|
117
|
+
* bundle, a bad input), `config` (a configuration change — a model not served, a missing
|
|
118
|
+
* secret), `runtime` (nobody beforehand — a provider outage during execution).
|
|
119
|
+
*/
|
|
120
|
+
error_domain?: string | null;
|
|
121
|
+
/**
|
|
122
|
+
* A finer classification of an inference failure, when the runner has one. Known values:
|
|
123
|
+
* `transient`, `configuration`, `content`, `capacity`, `ambiguous`, `unknown`.
|
|
124
|
+
*/
|
|
125
|
+
error_category?: string | null;
|
|
126
|
+
/** Whether retrying the same run can succeed. Absent or `null` means unknown, never "no". */
|
|
127
|
+
retryable?: boolean | null;
|
|
128
|
+
/** The next step the runner advises. */
|
|
129
|
+
user_action?: UserAction | null;
|
|
130
|
+
/** The model the failing call used, when the failure is an inference failure. */
|
|
131
|
+
model?: string | null;
|
|
132
|
+
/** The provider the failing call reached, when the failure is an inference failure. */
|
|
133
|
+
provider?: string | null;
|
|
134
|
+
/** What the provider's SDK said, when the failure came back from a provider. */
|
|
135
|
+
provider_metadata?: ProviderErrorMetadata | null;
|
|
136
|
+
/** True when `message` was written as caller-facing copy. The runner emits it only when true. */
|
|
137
|
+
caller_facing_message?: boolean | null;
|
|
138
|
+
/**
|
|
139
|
+
* The structured diagnostics of a bundle that failed validation — the same items the
|
|
140
|
+
* validate report and a `422`'s `ApiResponseError.validationErrors` carry.
|
|
141
|
+
*/
|
|
142
|
+
validation_errors?: ValidationErrorItem[] | null;
|
|
143
|
+
/** A pending configuration migration that explains the failure. */
|
|
144
|
+
migration?: MigrationErrorBlock | null;
|
|
145
|
+
/** Fields a newer runner adds, reachable before this SDK names them. */
|
|
146
|
+
[extension: string]: unknown;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* One field-level failure of a request — an item of the platform problem document's
|
|
150
|
+
* `errors[]`. `field` is the dotted path to the offending attribute, `code` a stable sub-code
|
|
151
|
+
* (`invalid_format`, `out_of_range`, …), `detail` optional human text.
|
|
152
|
+
*/
|
|
153
|
+
export interface FieldError {
|
|
154
|
+
field?: string | null;
|
|
155
|
+
code?: string | null;
|
|
156
|
+
detail?: string | null;
|
|
157
|
+
[extension: string]: unknown;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The members of an RFC 9457 problem document that `ApiResponseError` exposes beyond its
|
|
161
|
+
* message, as the client parsed them: the standard's own `type`, `title` and `instance`, the
|
|
162
|
+
* request id, and the extension members the runner and the platform add to classify the
|
|
163
|
+
* failure. Every member is optional — a server sends what it knows, and a body that is not a
|
|
164
|
+
* problem document carries none of them.
|
|
165
|
+
*
|
|
166
|
+
* It is a superset of `mthds`'s `ProblemDetails`, member for member under the same names, so a
|
|
167
|
+
* consumer reads one vocabulary whichever client raised the error; the members past that set
|
|
168
|
+
* (`errorCategory`, `model`, `provider`, `providerMetadata`, `migration`, `errors`) are the ones
|
|
169
|
+
* the standard's client leaves to this SDK.
|
|
170
|
+
*/
|
|
171
|
+
export interface ProblemDetails {
|
|
172
|
+
/** RFC 9457 `type` — the stable URI of the error class. */
|
|
173
|
+
type?: string;
|
|
174
|
+
/** RFC 9457 `title` — the short human label of the error class. */
|
|
175
|
+
title?: string;
|
|
176
|
+
/** RFC 9457 `instance` — the occurrence (a request path or a request URN). */
|
|
177
|
+
instance?: string;
|
|
178
|
+
/** The request's correlation id: the body's `request_id`, else the `X-Request-ID` response header. */
|
|
179
|
+
requestId?: string;
|
|
180
|
+
/** The body's `error_domain` — `input`, `config` or `runtime`. */
|
|
181
|
+
errorDomain?: string;
|
|
182
|
+
/** The body's `error_category` — the finer classification of an inference failure. */
|
|
183
|
+
errorCategory?: string;
|
|
184
|
+
/** The body's `retryable` — whether retrying the same request can plausibly succeed. */
|
|
185
|
+
retryable?: boolean;
|
|
186
|
+
/** The body's `user_action` — what the caller should do next. */
|
|
187
|
+
userAction?: UserAction;
|
|
188
|
+
/** The body's `model` — the model an inference failure used. */
|
|
189
|
+
model?: string;
|
|
190
|
+
/** The body's `provider` — the provider an inference failure reached. */
|
|
191
|
+
provider?: string;
|
|
192
|
+
/** The body's `provider_metadata` — what the provider's SDK said. */
|
|
193
|
+
providerMetadata?: ProviderErrorMetadata;
|
|
194
|
+
/** The body's `migration` — a pending configuration migration that explains the failure. */
|
|
195
|
+
migration?: MigrationErrorBlock;
|
|
196
|
+
/** The platform's field-level `errors[]`. */
|
|
197
|
+
errors?: FieldError[];
|
|
198
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error-report wire models — a failed run's stored report, and the typed members of a
|
|
3
|
+
* problem document.
|
|
4
|
+
*
|
|
5
|
+
* **The runner owns these shapes; this SDK follows them.** A run that fails reports why as
|
|
6
|
+
* the runner's `ErrorReport` (`pipelex.base_exceptions`), which the hosted platform stores
|
|
7
|
+
* whole on the run row as `error` and serves as it was stored: on the status read
|
|
8
|
+
* (`RunRead.error`), on the run records (`PipelineRun.error`), and inside the problem
|
|
9
|
+
* document of the results read's `409`, where the client lifts it onto the failed arm of
|
|
10
|
+
* `RunResultState` and onto `RunFailedError.error`. The same classification fields
|
|
11
|
+
* (`error_domain`, `user_action`, …) ride a runner-rendered problem document as extension
|
|
12
|
+
* members, which is why `ApiResponseError` types its members with the models declared here.
|
|
13
|
+
*
|
|
14
|
+
* Every field is optional and every interface keeps an index signature, for the reason
|
|
15
|
+
* `TokensUsageRecord` gives: the runner adds fields without asking this SDK, and a field this
|
|
16
|
+
* version does not name still reaches the caller. The enum-ish fields (`error_domain`,
|
|
17
|
+
* `error_category`, `user_action.kind`) are open sets on the wire and stay `string`, never
|
|
18
|
+
* frozen unions, so a value the runner adds is not an SDK break; their known values are listed
|
|
19
|
+
* where they are declared.
|
|
20
|
+
*
|
|
21
|
+
* **Nothing is stripped.** The platform serves the runner's VERBOSE report, so `message` and
|
|
22
|
+
* `provider_metadata` can hold a provider's raw text. Deciding what of it a person should see
|
|
23
|
+
* is each consumer's presentation, not this SDK's; the report arrives here whole.
|
|
24
|
+
*/
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=error-models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-models.js","sourceRoot":"","sources":["../src/error-models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { PipelineRequestError } from "mthds/protocol";
|
|
7
7
|
import type { ValidationErrorItem } from "./models.js";
|
|
8
8
|
import type { ArtifactScope, DownloadArtifactsResult } from "./artifacts.js";
|
|
9
|
+
import type { FieldError, MigrationErrorBlock, ProblemDetails, ProviderErrorMetadata, RunErrorReport, UserAction } from "./error-models.js";
|
|
10
|
+
import type { RunStatus } from "./runs.js";
|
|
9
11
|
export { PipelineRequestError };
|
|
10
12
|
export declare class ClientAuthenticationError extends Error {
|
|
11
13
|
constructor(message: string);
|
|
@@ -225,16 +227,34 @@ export declare class PipelineExecuteTimeoutError extends PipelineRequestError {
|
|
|
225
227
|
});
|
|
226
228
|
}
|
|
227
229
|
/**
|
|
228
|
-
* Thrown when a run reaches a terminal state that is not `COMPLETED`
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
230
|
+
* Thrown when a run reaches a terminal state that is not `COMPLETED` (`FAILED`, `CANCELLED`,
|
|
231
|
+
* `TERMINATED`, `TIMED_OUT`) — by `waitForResult`, `startAndWaitForResult` and the artifact
|
|
232
|
+
* download when the platform answers the results read with HTTP 409. (`getRunResult` returns
|
|
233
|
+
* the same facts as its `failed` arm instead of throwing.)
|
|
234
|
+
*
|
|
235
|
+
* - `status` is the run's terminal status, read from the problem's `run_status` member, or from
|
|
236
|
+
* its `detail` sentence on a platform that predates the member.
|
|
237
|
+
* - `error` is the run's stored error report, typed whole as `RunErrorReport`: the runner's
|
|
238
|
+
* `error_type`, `message`, `title`, `type_uri`, `error_domain`, `error_category`,
|
|
239
|
+
* `retryable`, `user_action`, `model`, `provider`, `provider_metadata`, `validation_errors`
|
|
240
|
+
* and anything newer through its index signature. Branch on `error.error_domain`,
|
|
241
|
+
* `error.type_uri` and `error.retryable`; show `error.user_action` as the next step. It is
|
|
242
|
+
* the runner's VERBOSE report, so `message` and `provider_metadata` can hold a provider's raw
|
|
243
|
+
* text — deciding what a person sees is the consumer's. `null` when the run ended with no
|
|
244
|
+
* stored report (a cancelled, terminated or timed-out run, or one the platform finalized
|
|
245
|
+
* itself).
|
|
246
|
+
* - The error's own `message` is the problem's `detail`, which names the status and then the
|
|
247
|
+
* report's message (`Run finished with status FAILED: <message>`), so printing the error
|
|
248
|
+
* already tells the reason.
|
|
249
|
+
* - `runId` locates the run, for a status read or a support request.
|
|
232
250
|
*/
|
|
233
251
|
export declare class RunFailedError extends PipelineRequestError {
|
|
234
252
|
readonly runId: string;
|
|
235
|
-
readonly status:
|
|
236
|
-
|
|
253
|
+
readonly status: RunStatus;
|
|
254
|
+
readonly error: RunErrorReport | null;
|
|
255
|
+
constructor(message: string, runId: string, status: RunStatus, options?: {
|
|
237
256
|
cause?: unknown;
|
|
257
|
+
error?: RunErrorReport | null;
|
|
238
258
|
});
|
|
239
259
|
}
|
|
240
260
|
/**
|
|
@@ -295,15 +315,46 @@ export declare class RunLifecycleUnavailableError extends PipelineRequestError {
|
|
|
295
315
|
});
|
|
296
316
|
}
|
|
297
317
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
318
|
+
* The last constructor argument of `ApiResponseError`: the error's `cause`, the problem
|
|
319
|
+
* document's typed members, and the decoded document whole. The same shape as `mthds`'s
|
|
320
|
+
* `ApiResponseErrorOptions`, plus `problemDocument`.
|
|
321
|
+
*/
|
|
322
|
+
export interface ApiResponseErrorOptions {
|
|
323
|
+
cause?: unknown;
|
|
324
|
+
problem?: ProblemDetails;
|
|
325
|
+
problemDocument?: Record<string, unknown>;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* A non-2xx response that DID come back from the API, with its problem document parsed.
|
|
329
|
+
*
|
|
330
|
+
* Every error the hosted API answers is an RFC 9457 `application/problem+json` document, and
|
|
331
|
+
* this error carries its members as typed fields, each `undefined` when the document did not
|
|
332
|
+
* carry it (a member of the wrong type reads as absent rather than as a wrong value):
|
|
333
|
+
*
|
|
334
|
+
* - **The branch fields.** `errorDomain` says who can fix the failure — `input` (the caller),
|
|
335
|
+
* `config` (a configuration change), `runtime` (nobody beforehand) — and `type` is the stable
|
|
336
|
+
* URI naming the error class. `retryable` says whether a retry can succeed, `undefined`
|
|
337
|
+
* meaning unknown. Branch on these, never on the HTTP status or on the wording of a message.
|
|
338
|
+
* - **The native codes.** `code` is the platform's own closed code (`conflict`, `not_found`,
|
|
339
|
+
* `pipelex_api_key_limit_reached`, …) and `errorType` the runner's open exception class
|
|
340
|
+
* name. Each is finer than `errorDomain` and specific to the surface that emits it; the
|
|
341
|
+
* platform's `type` is one-to-one with its `code` (`https://pipelex.com/errors/<code>`).
|
|
342
|
+
* - **For a person.** `title` is the stable label of the error class, `serverMessage` the
|
|
343
|
+
* per-occurrence `detail`, `userAction` the advised next step, and `errorCategory`, `model`,
|
|
344
|
+
* `provider` and `providerMetadata` describe an inference failure.
|
|
345
|
+
* - **For support.** `requestId` correlates the response with the server's logs; it is read
|
|
346
|
+
* from the body, or from the `X-Request-ID` response header when the body has none.
|
|
347
|
+
* `instance` is the occurrence's URN or request path.
|
|
348
|
+
* - **Per-item failures.** `errors` is the platform's field-level list (`field`, `code`,
|
|
349
|
+
* `detail`), and `validationErrors` the structured diagnostics of a bundle that failed
|
|
350
|
+
* validation.
|
|
301
351
|
*
|
|
302
|
-
* `
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
352
|
+
* `problemDocument` is the decoded document whole, so a member this SDK does not name stays
|
|
353
|
+
* reachable without re-parsing `responseBody`, which is the raw text; it is `undefined` when
|
|
354
|
+
* the body was not a JSON object. The members `mthds`'s own `ApiResponseError` carries have the
|
|
355
|
+
* same names and types here, and the rest (`code`, `errorCategory`, `model`, `provider`,
|
|
356
|
+
* `providerMetadata`, `migration`, `errors`) are the Pipelex members the standard's client
|
|
357
|
+
* leaves to this SDK.
|
|
307
358
|
*/
|
|
308
359
|
export declare class ApiResponseError extends PipelineRequestError {
|
|
309
360
|
readonly apiUrl: string;
|
|
@@ -312,22 +363,77 @@ export declare class ApiResponseError extends PipelineRequestError {
|
|
|
312
363
|
readonly responseBody: string;
|
|
313
364
|
readonly errorType: string | undefined;
|
|
314
365
|
readonly serverMessage: string | undefined;
|
|
366
|
+
/**
|
|
367
|
+
* The platform's native code — a closed set (`conflict`, `not_found`, `run_not_found`,
|
|
368
|
+
* `pipelex_api_key_limit_reached`, …), one-to-one with `type`. Finer than `errorDomain` and
|
|
369
|
+
* specific to the platform: a runner's problem carries `errorType` instead. `undefined` for a
|
|
370
|
+
* body that carries no `code`.
|
|
371
|
+
*/
|
|
315
372
|
readonly code: string | undefined;
|
|
373
|
+
/**
|
|
374
|
+
* RFC 9457 `type`: the stable URI naming the error class. With `errorDomain`, the field a
|
|
375
|
+
* machine consumer branches on — the same class carries the same URI on every occurrence.
|
|
376
|
+
*/
|
|
377
|
+
readonly type: string | undefined;
|
|
378
|
+
/** RFC 9457 `title`: the short human label of the error class. */
|
|
379
|
+
readonly title: string | undefined;
|
|
380
|
+
/** RFC 9457 `instance`: the occurrence — the request path, or a request URN. */
|
|
381
|
+
readonly instance: string | undefined;
|
|
382
|
+
/**
|
|
383
|
+
* The request's correlation id — the body's `request_id`, or the `X-Request-ID` response
|
|
384
|
+
* header when the body carries none. The id to hand to support: it finds the server's log
|
|
385
|
+
* lines for this request.
|
|
386
|
+
*/
|
|
387
|
+
readonly requestId: string | undefined;
|
|
388
|
+
/**
|
|
389
|
+
* The body's `error_domain`: who can fix the failure. `input` — the caller (a malformed
|
|
390
|
+
* bundle, a bad argument, a missing input); `config` — a configuration change (a missing
|
|
391
|
+
* secret, a model the backend does not serve); `runtime` — nobody beforehand (a provider
|
|
392
|
+
* outage during execution). Typed open, as the server owns the vocabulary; `undefined` when
|
|
393
|
+
* the server did not classify it.
|
|
394
|
+
*/
|
|
395
|
+
readonly errorDomain: string | undefined;
|
|
396
|
+
/**
|
|
397
|
+
* The body's `error_category`: the finer classification of an inference failure — known
|
|
398
|
+
* values `transient`, `configuration`, `content`, `capacity`, `ambiguous`, `unknown`.
|
|
399
|
+
*/
|
|
400
|
+
readonly errorCategory: string | undefined;
|
|
401
|
+
/**
|
|
402
|
+
* The body's `retryable`: whether retrying the same request can plausibly succeed.
|
|
403
|
+
* `undefined` means unknown, which is not the same as `false`.
|
|
404
|
+
*/
|
|
405
|
+
readonly retryable: boolean | undefined;
|
|
406
|
+
/** The body's `user_action`: what the caller should do next, when the server can say. */
|
|
407
|
+
readonly userAction: UserAction | undefined;
|
|
408
|
+
/** The body's `model`: the model an inference failure used. */
|
|
409
|
+
readonly model: string | undefined;
|
|
410
|
+
/** The body's `provider`: the provider an inference failure reached. */
|
|
411
|
+
readonly provider: string | undefined;
|
|
412
|
+
/** The body's `provider_metadata`: what the provider's SDK said, raw text included. */
|
|
413
|
+
readonly providerMetadata: ProviderErrorMetadata | undefined;
|
|
414
|
+
/** The body's `migration`: a pending configuration migration that explains the failure. */
|
|
415
|
+
readonly migration: MigrationErrorBlock | undefined;
|
|
416
|
+
/** The platform's field-level `errors[]` — one item per offending request field. */
|
|
417
|
+
readonly errors: FieldError[] | undefined;
|
|
418
|
+
/**
|
|
419
|
+
* The decoded problem document whole — every member, named or not, such as a failed run's
|
|
420
|
+
* `run_status` and `error` or a member a newer server adds. `undefined` when the body was not
|
|
421
|
+
* a JSON object.
|
|
422
|
+
*/
|
|
423
|
+
readonly problemDocument: Record<string, unknown> | undefined;
|
|
316
424
|
/**
|
|
317
425
|
* Structured per-error diagnostics on a problem body that carries a top-level
|
|
318
|
-
* `validation_errors[]` — the **
|
|
319
|
-
*
|
|
426
|
+
* `validation_errors[]` — the 422 a **run route** (`execute`, `start`) answers when the
|
|
427
|
+
* runner refuses the method for its validation errors.
|
|
320
428
|
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* per-error list (auth, transport, a request-shape 422
|
|
326
|
-
* assume a given `error_type` implies a
|
|
327
|
-
* `serverMessage` when this is empty.
|
|
429
|
+
* Everywhere else an invalid bundle is a produced verdict, not an `ApiResponseError`:
|
|
430
|
+
* `POST /v1/validate` answers it with a **200** `PipelexInvalidReport`, and the build
|
|
431
|
+
* and crate routes with a **200** `CrateInvalidReport`, whose `validation_errors[]` the
|
|
432
|
+
* caller reads off the returned value. This field is `undefined` for any error that
|
|
433
|
+
* carries no per-error list (auth, transport, a request-shape 422, a build route's 422
|
|
434
|
+
* for a pipe it cannot build). A consumer must NOT assume a given `error_type` implies a
|
|
435
|
+
* populated list — fall back to `serverMessage` when this is empty.
|
|
328
436
|
*/
|
|
329
437
|
readonly validationErrors: ValidationErrorItem[] | undefined;
|
|
330
|
-
constructor(message: string, apiUrl: string, status: number, statusText: string, responseBody: string, errorType: string | undefined, serverMessage: string | undefined, validationErrors: ValidationErrorItem[] | undefined, code: string | undefined, options?:
|
|
331
|
-
cause?: unknown;
|
|
332
|
-
});
|
|
438
|
+
constructor(message: string, apiUrl: string, status: number, statusText: string, responseBody: string, errorType: string | undefined, serverMessage: string | undefined, validationErrors: ValidationErrorItem[] | undefined, code: string | undefined, options?: ApiResponseErrorOptions);
|
|
333
439
|
}
|
package/dist/errors.js
CHANGED
|
@@ -227,19 +227,37 @@ export class PipelineExecuteTimeoutError extends PipelineRequestError {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
|
-
* Thrown when a run reaches a terminal state that is not `COMPLETED`
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
230
|
+
* Thrown when a run reaches a terminal state that is not `COMPLETED` (`FAILED`, `CANCELLED`,
|
|
231
|
+
* `TERMINATED`, `TIMED_OUT`) — by `waitForResult`, `startAndWaitForResult` and the artifact
|
|
232
|
+
* download when the platform answers the results read with HTTP 409. (`getRunResult` returns
|
|
233
|
+
* the same facts as its `failed` arm instead of throwing.)
|
|
234
|
+
*
|
|
235
|
+
* - `status` is the run's terminal status, read from the problem's `run_status` member, or from
|
|
236
|
+
* its `detail` sentence on a platform that predates the member.
|
|
237
|
+
* - `error` is the run's stored error report, typed whole as `RunErrorReport`: the runner's
|
|
238
|
+
* `error_type`, `message`, `title`, `type_uri`, `error_domain`, `error_category`,
|
|
239
|
+
* `retryable`, `user_action`, `model`, `provider`, `provider_metadata`, `validation_errors`
|
|
240
|
+
* and anything newer through its index signature. Branch on `error.error_domain`,
|
|
241
|
+
* `error.type_uri` and `error.retryable`; show `error.user_action` as the next step. It is
|
|
242
|
+
* the runner's VERBOSE report, so `message` and `provider_metadata` can hold a provider's raw
|
|
243
|
+
* text — deciding what a person sees is the consumer's. `null` when the run ended with no
|
|
244
|
+
* stored report (a cancelled, terminated or timed-out run, or one the platform finalized
|
|
245
|
+
* itself).
|
|
246
|
+
* - The error's own `message` is the problem's `detail`, which names the status and then the
|
|
247
|
+
* report's message (`Run finished with status FAILED: <message>`), so printing the error
|
|
248
|
+
* already tells the reason.
|
|
249
|
+
* - `runId` locates the run, for a status read or a support request.
|
|
234
250
|
*/
|
|
235
251
|
export class RunFailedError extends PipelineRequestError {
|
|
236
252
|
runId;
|
|
237
253
|
status;
|
|
254
|
+
error;
|
|
238
255
|
constructor(message, runId, status, options) {
|
|
239
|
-
super(message, options);
|
|
256
|
+
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
240
257
|
this.name = "RunFailedError";
|
|
241
258
|
this.runId = runId;
|
|
242
259
|
this.status = status;
|
|
260
|
+
this.error = options?.error ?? null;
|
|
243
261
|
}
|
|
244
262
|
}
|
|
245
263
|
/**
|
|
@@ -315,15 +333,36 @@ export class RunLifecycleUnavailableError extends PipelineRequestError {
|
|
|
315
333
|
}
|
|
316
334
|
}
|
|
317
335
|
/**
|
|
318
|
-
* A non-2xx response that DID come back from the API
|
|
319
|
-
*
|
|
320
|
-
*
|
|
336
|
+
* A non-2xx response that DID come back from the API, with its problem document parsed.
|
|
337
|
+
*
|
|
338
|
+
* Every error the hosted API answers is an RFC 9457 `application/problem+json` document, and
|
|
339
|
+
* this error carries its members as typed fields, each `undefined` when the document did not
|
|
340
|
+
* carry it (a member of the wrong type reads as absent rather than as a wrong value):
|
|
321
341
|
*
|
|
322
|
-
* `
|
|
323
|
-
* (`
|
|
324
|
-
*
|
|
325
|
-
* the HTTP status
|
|
326
|
-
*
|
|
342
|
+
* - **The branch fields.** `errorDomain` says who can fix the failure — `input` (the caller),
|
|
343
|
+
* `config` (a configuration change), `runtime` (nobody beforehand) — and `type` is the stable
|
|
344
|
+
* URI naming the error class. `retryable` says whether a retry can succeed, `undefined`
|
|
345
|
+
* meaning unknown. Branch on these, never on the HTTP status or on the wording of a message.
|
|
346
|
+
* - **The native codes.** `code` is the platform's own closed code (`conflict`, `not_found`,
|
|
347
|
+
* `pipelex_api_key_limit_reached`, …) and `errorType` the runner's open exception class
|
|
348
|
+
* name. Each is finer than `errorDomain` and specific to the surface that emits it; the
|
|
349
|
+
* platform's `type` is one-to-one with its `code` (`https://pipelex.com/errors/<code>`).
|
|
350
|
+
* - **For a person.** `title` is the stable label of the error class, `serverMessage` the
|
|
351
|
+
* per-occurrence `detail`, `userAction` the advised next step, and `errorCategory`, `model`,
|
|
352
|
+
* `provider` and `providerMetadata` describe an inference failure.
|
|
353
|
+
* - **For support.** `requestId` correlates the response with the server's logs; it is read
|
|
354
|
+
* from the body, or from the `X-Request-ID` response header when the body has none.
|
|
355
|
+
* `instance` is the occurrence's URN or request path.
|
|
356
|
+
* - **Per-item failures.** `errors` is the platform's field-level list (`field`, `code`,
|
|
357
|
+
* `detail`), and `validationErrors` the structured diagnostics of a bundle that failed
|
|
358
|
+
* validation.
|
|
359
|
+
*
|
|
360
|
+
* `problemDocument` is the decoded document whole, so a member this SDK does not name stays
|
|
361
|
+
* reachable without re-parsing `responseBody`, which is the raw text; it is `undefined` when
|
|
362
|
+
* the body was not a JSON object. The members `mthds`'s own `ApiResponseError` carries have the
|
|
363
|
+
* same names and types here, and the rest (`code`, `errorCategory`, `model`, `provider`,
|
|
364
|
+
* `providerMetadata`, `migration`, `errors`) are the Pipelex members the standard's client
|
|
365
|
+
* leaves to this SDK.
|
|
327
366
|
*/
|
|
328
367
|
export class ApiResponseError extends PipelineRequestError {
|
|
329
368
|
apiUrl;
|
|
@@ -332,23 +371,80 @@ export class ApiResponseError extends PipelineRequestError {
|
|
|
332
371
|
responseBody;
|
|
333
372
|
errorType;
|
|
334
373
|
serverMessage;
|
|
374
|
+
/**
|
|
375
|
+
* The platform's native code — a closed set (`conflict`, `not_found`, `run_not_found`,
|
|
376
|
+
* `pipelex_api_key_limit_reached`, …), one-to-one with `type`. Finer than `errorDomain` and
|
|
377
|
+
* specific to the platform: a runner's problem carries `errorType` instead. `undefined` for a
|
|
378
|
+
* body that carries no `code`.
|
|
379
|
+
*/
|
|
335
380
|
code;
|
|
381
|
+
/**
|
|
382
|
+
* RFC 9457 `type`: the stable URI naming the error class. With `errorDomain`, the field a
|
|
383
|
+
* machine consumer branches on — the same class carries the same URI on every occurrence.
|
|
384
|
+
*/
|
|
385
|
+
type;
|
|
386
|
+
/** RFC 9457 `title`: the short human label of the error class. */
|
|
387
|
+
title;
|
|
388
|
+
/** RFC 9457 `instance`: the occurrence — the request path, or a request URN. */
|
|
389
|
+
instance;
|
|
390
|
+
/**
|
|
391
|
+
* The request's correlation id — the body's `request_id`, or the `X-Request-ID` response
|
|
392
|
+
* header when the body carries none. The id to hand to support: it finds the server's log
|
|
393
|
+
* lines for this request.
|
|
394
|
+
*/
|
|
395
|
+
requestId;
|
|
396
|
+
/**
|
|
397
|
+
* The body's `error_domain`: who can fix the failure. `input` — the caller (a malformed
|
|
398
|
+
* bundle, a bad argument, a missing input); `config` — a configuration change (a missing
|
|
399
|
+
* secret, a model the backend does not serve); `runtime` — nobody beforehand (a provider
|
|
400
|
+
* outage during execution). Typed open, as the server owns the vocabulary; `undefined` when
|
|
401
|
+
* the server did not classify it.
|
|
402
|
+
*/
|
|
403
|
+
errorDomain;
|
|
404
|
+
/**
|
|
405
|
+
* The body's `error_category`: the finer classification of an inference failure — known
|
|
406
|
+
* values `transient`, `configuration`, `content`, `capacity`, `ambiguous`, `unknown`.
|
|
407
|
+
*/
|
|
408
|
+
errorCategory;
|
|
409
|
+
/**
|
|
410
|
+
* The body's `retryable`: whether retrying the same request can plausibly succeed.
|
|
411
|
+
* `undefined` means unknown, which is not the same as `false`.
|
|
412
|
+
*/
|
|
413
|
+
retryable;
|
|
414
|
+
/** The body's `user_action`: what the caller should do next, when the server can say. */
|
|
415
|
+
userAction;
|
|
416
|
+
/** The body's `model`: the model an inference failure used. */
|
|
417
|
+
model;
|
|
418
|
+
/** The body's `provider`: the provider an inference failure reached. */
|
|
419
|
+
provider;
|
|
420
|
+
/** The body's `provider_metadata`: what the provider's SDK said, raw text included. */
|
|
421
|
+
providerMetadata;
|
|
422
|
+
/** The body's `migration`: a pending configuration migration that explains the failure. */
|
|
423
|
+
migration;
|
|
424
|
+
/** The platform's field-level `errors[]` — one item per offending request field. */
|
|
425
|
+
errors;
|
|
426
|
+
/**
|
|
427
|
+
* The decoded problem document whole — every member, named or not, such as a failed run's
|
|
428
|
+
* `run_status` and `error` or a member a newer server adds. `undefined` when the body was not
|
|
429
|
+
* a JSON object.
|
|
430
|
+
*/
|
|
431
|
+
problemDocument;
|
|
336
432
|
/**
|
|
337
433
|
* Structured per-error diagnostics on a problem body that carries a top-level
|
|
338
|
-
* `validation_errors[]` — the **
|
|
339
|
-
*
|
|
434
|
+
* `validation_errors[]` — the 422 a **run route** (`execute`, `start`) answers when the
|
|
435
|
+
* runner refuses the method for its validation errors.
|
|
340
436
|
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
* per-error list (auth, transport, a request-shape 422
|
|
346
|
-
* assume a given `error_type` implies a
|
|
347
|
-
* `serverMessage` when this is empty.
|
|
437
|
+
* Everywhere else an invalid bundle is a produced verdict, not an `ApiResponseError`:
|
|
438
|
+
* `POST /v1/validate` answers it with a **200** `PipelexInvalidReport`, and the build
|
|
439
|
+
* and crate routes with a **200** `CrateInvalidReport`, whose `validation_errors[]` the
|
|
440
|
+
* caller reads off the returned value. This field is `undefined` for any error that
|
|
441
|
+
* carries no per-error list (auth, transport, a request-shape 422, a build route's 422
|
|
442
|
+
* for a pipe it cannot build). A consumer must NOT assume a given `error_type` implies a
|
|
443
|
+
* populated list — fall back to `serverMessage` when this is empty.
|
|
348
444
|
*/
|
|
349
445
|
validationErrors;
|
|
350
446
|
constructor(message, apiUrl, status, statusText, responseBody, errorType, serverMessage, validationErrors, code, options) {
|
|
351
|
-
super(message, options);
|
|
447
|
+
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
352
448
|
this.name = "ApiResponseError";
|
|
353
449
|
this.apiUrl = apiUrl;
|
|
354
450
|
this.status = status;
|
|
@@ -358,6 +454,21 @@ export class ApiResponseError extends PipelineRequestError {
|
|
|
358
454
|
this.serverMessage = serverMessage;
|
|
359
455
|
this.validationErrors = validationErrors;
|
|
360
456
|
this.code = code;
|
|
457
|
+
const problem = options?.problem;
|
|
458
|
+
this.type = problem?.type;
|
|
459
|
+
this.title = problem?.title;
|
|
460
|
+
this.instance = problem?.instance;
|
|
461
|
+
this.requestId = problem?.requestId;
|
|
462
|
+
this.errorDomain = problem?.errorDomain;
|
|
463
|
+
this.errorCategory = problem?.errorCategory;
|
|
464
|
+
this.retryable = problem?.retryable;
|
|
465
|
+
this.userAction = problem?.userAction;
|
|
466
|
+
this.model = problem?.model;
|
|
467
|
+
this.provider = problem?.provider;
|
|
468
|
+
this.providerMetadata = problem?.providerMetadata;
|
|
469
|
+
this.migration = problem?.migration;
|
|
470
|
+
this.errors = problem?.errors;
|
|
471
|
+
this.problemDocument = options?.problemDocument;
|
|
361
472
|
}
|
|
362
473
|
}
|
|
363
474
|
//# sourceMappingURL=errors.js.map
|