@pipelex/sdk 0.69.5 → 0.71.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/docs/errors.md CHANGED
@@ -126,8 +126,8 @@ The classes remain, so a `catch` can still tell an argument refusal from a refus
126
126
  | `MethodFileTransferError` | By `reason`: `unreachable` and `storage_error` are `runtime.unavailable`; `refused` reads storage's status, as above, `runtime.unexpected` with none; `mismatch`, downloaded bytes that are not the file listed, is `client.response_unreadable`. It carries `operation`, `reason`, `sha256`, `path` and `status`, and neither the link, nor storage's error body, nor a cause ([method-trees.md](./method-trees.md#when-a-transfer-fails)). |
127
127
  | `ArtifactOperationError` | `runtime.unexpected` when built without a problem; the SDK gives `client.argument_invalid` where it refuses an argument (a `scope`, a bound, a location), `runtime.unsupported` for a runtime with no filesystem, `client.write_failed` for a directory that cannot be created, and `client.response_unreadable` for a resolution that answered the wrong count of items. |
128
128
  | `ScopeUnavailableError` | `client.response_unreadable`: the run's results carry no artifact in the scope asked for. |
129
- | `ArtifactFetchError` | The SDK gives `client.download_limit_exceeded` naming the cap for a file over it (`too_large`), `client.timeout` naming the budget for a download that ran out of time, and `client.unreachable` naming the store's origin for one that failed on the network. Otherwise by `reason` and `status`: `input.reference_not_found` naming the reference for the bulk resolve route's `pipelex.storage.uri_invalid` and `pipelex.org.mismatch` and for `not_found`; `client.link_refused` for `unsupported_url`, `plain_http_refused` and `redirect_refused`; for `store_error` and `store_refused`, the reading of the store's status as for any storage answer (`runtime.unavailable` for a `408`, a `429` or a `5xx` other than `501`, `runtime.unsupported` for a `501`, `client.response_unreadable` naming any other status, a `401` or a `403` included), and `runtime.unavailable` when no status is known; `runtime.unavailable` for `timeout` and `network`; and `runtime.unexpected` otherwise. |
130
- | `StoredTextLoadError` | The fetch failure's own problem, as `ArtifactFetchError` gives it, when a stored text's bytes could not be read, a refusal of the resolve route included; the resolve route's own problem for `resolve_failed`, the route failing as a whole; `client.link_refused` for `unsupported_url`, a stored text whose `url` is neither a `pipelex-storage://` reference nor a `data:` URL, which is never fetched; and `client.response_unreadable` naming the run for `not_utf8` and `not_json_object`, bytes read that are not the value. `uri`, `path` and `reason` name the text; `wireResults` carries the completed result as it was answered on the blocking fallback alone, where there is no run to read again, and is `undefined` elsewhere, where reading it again with `loadStoredTexts: false` gives it. |
129
+ | `ArtifactFetchError` | The SDK gives `client.download_limit_exceeded` naming the cap for a file over it (`too_large`), `client.timeout` naming the budget for a download that ran out of time, and `client.unreachable` naming the store's origin for one that failed on the network. Otherwise by `reason` and `status`: `input.reference_not_found` naming the reference for the bulk resolve route's `pipelex.storage.uri_invalid` and `pipelex.org.mismatch`, for a self-hosted runner's `auth.forbidden` whose `params.requirement` is `read_scope_under_caller`, and for `not_found`; `client.link_refused` for `unsupported_url`, `plain_http_refused` and `redirect_refused`; for `store_error` and `store_refused`, the reading of the store's status as for any storage answer (`runtime.unavailable` for a `408`, a `429` or a `5xx` other than `501`, `runtime.unsupported` for a `501`, `client.response_unreadable` naming any other status, a `401` or a `403` included), and `runtime.unavailable` when no status is known; `runtime.unavailable` for `timeout` and `network`; and `runtime.unexpected` otherwise. `uri` and `reason` name the reference and the failure, `status` the store's HTTP status when one was received, and `requirement` the `requirement` the resolve route's refusal names in its `params`, when it names one, which tells a self-hosted runner's scope refusal from any other `auth.forbidden`. |
130
+ | `StoredTextLoadError` | The fetch failure's own problem, as `ArtifactFetchError` gives it, when a stored text's bytes could not be read, a refusal of the resolve route included; the resolve route's own problem for `resolve_failed`, the route failing as a whole; `client.link_refused` for `unsupported_url`, a stored text whose `url` is neither a `pipelex-storage://` reference nor a `data:` URL, which is never fetched; and `client.response_unreadable` naming the run for `not_utf8` and `not_json_object`, bytes read that are not the value. `uri`, `path` and `reason` name the text, `status` the HTTP status received when one was, and `requirement` the `requirement` the resolve route's refusal of the reference names in its `params`, when it names one, which tells a self-hosted runner's scope refusal from any other `auth.forbidden`; `wireResults` carries the completed result as it was answered on the blocking fallback alone, where there is no run to read again, and is `undefined` elsewhere, where reading it again with `loadStoredTexts: false` gives it. |
131
131
  | `CodegenLockError` | `client.file_unreadable` naming `codegen.lock` for a lock that is malformed or tracks an unsafe path, `client.tool_outdated` naming this SDK for a lock newer than it reads, and `client.argument_invalid` naming `files` for a supplied tree holding an unsafe or duplicate path. It extends `ProblemError` rather than `PipelexRequestError`, since nothing was requested. |
132
132
  | `ExactJsonUnsupportedError` | `client.tool_outdated`, naming the JavaScript runtime: `parseExactJson` met a number past `Number.MAX_SAFE_INTEGER` on a runtime whose `JSON.parse` hands a reviver no source text ([exact-integers.md](./exact-integers.md)). It extends `ProblemError`; the client reports it as the `ApiResponseError` of an answer it cannot read, with this error as `cause`. |
133
133
 
package/docs/files.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # An organization's files
2
2
 
3
- A **file** is the record the hosted platform keeps of a stored object: a member's upload, a test file made for a method, or a file a run made that reached its result. The bytes stay where they were written, and a run, a form or an example still points at them by their `pipelex-storage://` address; the record adds what the bytes lack, the name a person sees, a kind, a type, a size and where the file came from. A file belongs to the organization: every role of it reads every file of it, as every role reads every run. The client reaches them on the hosted API's `/v1/files` routes, a run's files on `GET /v1/runs/{run_id}/files` and the copy into a method's draft on `POST /v1/methods/{method_id}/draft/files/from-file`, and the types are in `src/product-models.ts`. The platform's own contract is `platform/docs/files.md` in `pipelex-server`.
3
+ A **file** is the record the hosted platform keeps of a stored object: a member's upload, a test file made for a method, or a file a run made that reached its result. The bytes stay where they were written, and a run, a form or an example still points at them by their `pipelex-storage://` address; the record adds what the bytes lack, the name a person sees, a kind, a type, a size and where the file came from. A file belongs to the organization: every role of it reads every file of it, as every role reads every run. The client reaches them on the hosted API's `/v1/files` routes, the PDF preview of an Office file on `GET /v1/files/preview`, a run's files on `GET /v1/runs/{run_id}/files` and the copy into a method's draft on `POST /v1/methods/{method_id}/draft/files/from-file`, and the types are in `src/product-models.ts`. The platform's own contract is `platform/docs/files.md` in `pipelex-server`.
4
4
 
5
5
  The point of the list for a program is the `uri` on every row: a run's inputs take it as they take any address, so an agent or an app can find "the invoice uploaded this morning" and run a method on it without uploading it again.
6
6
 
@@ -45,6 +45,7 @@ A file read by its id or its address, renamed, or listed among a run's files is
45
45
  | `linkFiles(files)` | `POST /v1/files/links` | A `FileLinksResult`, `{ items }`: one `FileLink` per requested file, in order, each a link or an error. |
46
46
  | `requestFileArchive(request)` | `POST /v1/files/archives` | The `FileArchive`, `queued`. |
47
47
  | `getFileArchive(archiveId)` | `GET /v1/files/archives/{archive_id}` | The `FileArchive` as it stands, with a link to the zip once it is `ready`. |
48
+ | `getFilePreview(uri)` | `GET /v1/files/preview` | A `FilePreview`, discriminated on `state`: the PDF preview of an Office file, with a link to it once it is `ready`. |
48
49
  | `listRunFiles(runId, { limit?, cursor? })` | `GET /v1/runs/{run_id}/files` | One `RunFilesPage`: the run's inputs, outputs, intermediate files and web links, with `nextCursor`. |
49
50
  | `copyFileIntoDraft(methodId, { file_id, path, expected_updated_at? })` | `POST /v1/methods/{method_id}/draft/files/from-file` | A `DraftFileFromFileResult`, discriminated on `blob`. |
50
51
 
@@ -198,6 +199,45 @@ try {
198
199
 
199
200
  The other refusals of a request: `422` `request.invalid` for more than 1,000 ids listed or an id longer than one can be; `404` `pipelex.storage.not_found` for a file that is not the organization's, the `detail` naming up to five of them, or a run whose files hold nothing stored to zip; `404` `run.not_found` for a run that is not the organization's; `409` `run.not_finished`, `retry` `yes`, for a run whose files are not all recorded yet, which the same request clears a few seconds after the run ends, and a `409` with `retry` `no` for a selected file whose upload has not finished; and `503` `runtime.unavailable`, `retry` `yes`, when the archive could not be queued. Each is an `ApiResponseError` whose problem's `domain` and `retry` say what to do ([errors.md](./errors.md)).
200
201
 
202
+ ## The PDF preview of an Office file
203
+
204
+ A browser cannot draw a Word, Excel or PowerPoint file, so the platform keeps a PDF of it. `getFilePreview` asks where that PDF stands, naming the file by its `pipelex-storage://` address. The platform converts the files whose address ends in `docx`, `xlsx`, `pptx`, `doc`, `xls`, `ppt`, `odt`, `ods` or `odp`.
205
+
206
+ **The answer is always a `200`: branch on `state`.** The platform never waits on a conversion: the first ask queues one and answers `preparing` at once, and asking again queues nothing more, so polling is safe; the app polls for up to three minutes. The SDK has no waiting helper, since how long to wait and how to show it is the caller's.
207
+
208
+ ```ts
209
+ let preview = await client.getFilePreview(output.uri);
210
+ while (preview.state === "preparing") {
211
+ await new Promise((resolve) => setTimeout(resolve, 2000));
212
+ preview = await client.getFilePreview(output.uri);
213
+ }
214
+ if (preview.state === "ready") frame.src = preview.url;
215
+ else if (preview.state === "failed") console.warn(preview.failure.code, preview.failure.detail);
216
+ ```
217
+
218
+ A `FilePreview` carries all four members in every state, those its state does not fill `null`, and the type narrows on `state`, so a `ready` preview's `url` is a `string` and a `failed` one's `failure` is never `null`.
219
+
220
+ | `state` | What it means | The other members |
221
+ |---|---|---|
222
+ | `ready` | The PDF is there. | `url`, a presigned `GET` of the PDF signed fresh on each read, valid for fifteen minutes and answered `inline` under the file's name with its extension swapped to `.pdf`, and `url_expires_at`, the UTC instant it lapses. |
223
+ | `preparing` | A conversion is on its way: ask again shortly. | All `null`. |
224
+ | `failed` | The last conversion failed. | `failure`, a `FilePreviewFailure` `{ code, detail }`, `detail` being a sentence for a person. |
225
+ | `unavailable` | The file gets no preview: a type that is not converted, a file over 50 MB, or an address holding nothing. | All `null`. |
226
+
227
+ **A failure stands for a day** from the moment it failed: asking again within that day answers the same failure and queues nothing, and after it the next ask starts a new conversion. `FilePreviewFailureCode` names the codes the platform answers today, and `code` is typed open, so a code a later platform adds still reads.
228
+
229
+ | `failure.code` | Why | What happens next |
230
+ |---|---|---|
231
+ | `file_unreadable` | The converter could not open the file. A damaged file and one protected by a password cannot be told apart reliably, so the sentence names both. | The file will fail the same way. |
232
+ | `file_too_large` | The converter refused the file as over its input cap. | The file will fail the same way. |
233
+ | `conversion_too_slow` | The conversion ran out of the converter's two minutes, as a hostile or very large file does. | The file will almost certainly fail the same way. |
234
+ | `file_gone` | The bytes were deleted between the request and the conversion. | Nothing to retry. |
235
+ | `conversion_failed` | The worker's last attempt failed, or the job was not done within the hour it has; the cause is not the file's. | A later ask tries again once the failure's day has passed. |
236
+
237
+ **The link is a bearer capability.** Keep it out of logs and ask again for a fresh one rather than storing it. The SDK keeps it out of its own errors: an answer it cannot read, one whose `state` it does not know, a `ready` one without a non-empty `url` and a string `url_expires_at`, or a `failed` one whose `failure` is not a `code` and a `detail`, is an `ApiResponseError` of `client.response_unreadable` whose `responseBody` replaces every `url` member and every link's query with `[redacted]`, and which carries no `cause` ([errors.md](./errors.md)). The answer it hands back holds the four members and nothing else the platform may add.
238
+
239
+ A `uri` that is not a non-empty string is refused before any request with a `RequestArgumentError`. The platform answers `422` `pipelex.storage.uri_invalid` for a malformed address, `403` `pipelex.org.mismatch` for another organization's, `422` `request.invalid` for an address over 512 characters, and `503` `runtime.unavailable`, `retry` `yes`, when the conversion could not be queued, so the same request can be sent again. Each is an `ApiResponseError` whose problem's `domain` and `retry` say what to do.
240
+
201
241
  ## A run's files
202
242
 
203
243
  `listRunFiles` answers a `RunFilesPage` of what went in, what came out and what was made along the way, sorted by where each file sits in the run. Each `RunFileEntry` carries its `mark` (`input`, `final` or `intermediate`), the `input_name` of the run's input that held an input given by its address (`null` for an inline input and for every file the run made), its `uri` and the `FileRecord` a surface shows for it, `null` for an input no record holds.
@@ -238,17 +238,17 @@ The runtime keeps a large text out of a run's results. A `native.Text`, `native.
238
238
  { "url": "pipelex-storage://org/…/generated/3f9c…/value.md", "size": 182344, "mime_type": "text/markdown", "preview": "# Quarterly review…" }
239
239
  ```
240
240
 
241
- An inline value arrives as `{ "text": "…" }`, `{ "inner_html": "…" }` (its `css_class` beside it) or `{ "json_obj": { … } }`. **The result readers load every stored text of `main_stuff` before they return**, so it reaches the generated parser in the shape the method's concepts describe, the value field required: `getRunResult`, `waitForResult` and `startAndWaitForResult` resolve the references through the platform's bulk route, at most `BULK_RESOLVE_MAX_URIS` per request, fetch each signed link under the bounds `fetchArtifact` applies, and decode the bytes as UTF-8, a JSON value being the object they serialize. A text that cannot be loaded throws `StoredTextLoadError`, naming its `uri`, its `path` in `main_stuff` and a `reason` (`not_found`, `pipelex.org.mismatch`, `resolve_failed`, `unsupported_url`, `too_large`, `total_limit_exceeded`, `concepts_missing`, `not_utf8`, `not_json_object`, …). The first text that fails stops every other read in flight.
241
+ An inline value arrives as `{ "text": "…" }`, `{ "inner_html": "…" }` (its `css_class` beside it) or `{ "json_obj": { … } }`. **The result readers load every stored text of `main_stuff` before they return**, so it reaches the generated parser in the shape the method's concepts describe, the value field required: `getRunResult`, `waitForResult` and `startAndWaitForResult` resolve the references through the server's bulk route, at most `BULK_RESOLVE_MAX_URIS` per request, fetch each signed link under the bounds `fetchArtifact` applies, and decode the bytes as UTF-8, a JSON value being the object they serialize. A text that cannot be loaded throws `StoredTextLoadError`, naming its `uri`, its `path` in `main_stuff` and a `reason` (`not_found`, `pipelex.org.mismatch`, `resolve_failed`, `unsupported_url`, `too_large`, `total_limit_exceeded`, `concepts_missing`, `not_utf8`, `not_json_object`, …). The first text that fails stops every other read in flight.
242
242
 
243
243
  **A load holds a bounded amount of memory.** Each text is capped by `maxBytes` (100 MiB by default) and the load as a whole by `maxTotalBytes` (256 MiB by default, `DEFAULT_STORED_TEXT_MAX_TOTAL_BYTES`), since every loaded value is held until the load ends, as bytes and then as a string that can take twice as many. Both caps are checked first against the `size` each reference states, before anything is sent, then counted as the bytes arrive; a load whose texts together cross `maxTotalBytes` throws `StoredTextLoadError` with the reason `total_limit_exceeded`, naming the text that crossed it. A `data:` URL's decoded size is bounded from its length before it is decoded. Pass larger caps to `loadStoredTexts(client, results, { maxBytes, maxTotalBytes })` on a result read with `loadStoredTexts: false`.
244
244
 
245
- **A link about to expire is resolved again before its read.** The platform signs each link for about fifteen minutes, and a load reads only a few texts at once, so a text waiting behind long reads could reach its turn with a stale link. A link within ten seconds of its `expires_at` when its read is about to start is resolved again first, as `downloadArtifacts` does.
245
+ **A link about to expire is resolved again before its read.** The server signs each link for a short time, about fifteen minutes on the hosted platform and `STORAGE_LINK_TTL_SECONDS` on a self-hosted runner, and a load reads only a few texts at once, so a text waiting behind long reads could reach its turn with a stale link. A link within ten seconds of its `expires_at` when its read is about to start is resolved again first, as `downloadArtifacts` does.
246
246
 
247
- **Only the platform's references and `data:` URLs are loaded.** A `pipelex-storage://` reference is fetched through the link the platform signs for it, and a `data:` URL is decoded where it is. A stored text under any other URL, which a method's own code can put there, is refused as `unsupported_url` before anything is sent, so a method never has the SDK read a host the caller did not choose; `loadStoredTexts: false` hands it back as written.
247
+ **Only the platform's references and `data:` URLs are loaded.** A `pipelex-storage://` reference is fetched through the link the platform signs for it, and a `data:` URL is decoded where it is. A signed link on plain `http:` is fetched when it is on the origin of the client's configured base URL, which is what a self-hosted runner listening on plain http hands out, and refused as `plain_http_refused` on any other origin unless `allowHttp` is set ([artifact-download.md](./artifact-download.md)). A stored text under any other URL, which a method's own code can put there, is refused as `unsupported_url` before anything is sent, so a method never has the SDK read a host the caller did not choose; `loadStoredTexts: false` hands it back as written.
248
248
 
249
249
  **`waitForResult`'s `timeoutMs` bounds the load.** The wait reads the run's status without loading, then loads the completed result under the time it has left. A deadline that passes during the load throws `RunTimeoutError` saying the run completed and its stored texts did not load in time; `getRunResult` reads it again, and with `loadStoredTexts: false` it answers at once.
250
250
 
251
- **The blocking fallback never loses a completed result.** `startAndWaitForResult` on a bare runner, or falling back to one, holds the run's only copy in the `POST /v1/execute` answer, and a bare runner serves no bulk resolve route. A load that fails there throws `StoredTextLoadError` with that result, every stored text still its reference, on its `wireResults`; on every other path `wireResults` is `undefined`, since the run can be read again.
251
+ **The blocking fallback never loses a completed result.** `startAndWaitForResult` on a bare runner, or falling back to one, holds the run's only copy in the `POST /v1/execute` answer, and a runner older than pipelex-api 0.118.0 serves no bulk resolve route; the hosted platform and, from that version, a self-hosted runner serve it. A load that fails there throws `StoredTextLoadError` with that result, every stored text still its reference, on its `wireResults`; on every other path `wireResults` is `undefined`, since the run can be read again.
252
252
 
253
253
  **`loadStoredTexts: false` hands the wire shape back**, the references untouched, on all three readers. The generated `<Name>Wire` types describe that shape, the value field optional beside the reference's fields. `loadStoredTexts(client, results, options)`, exported, loads such a result later, and returns a new one, never changing the one it is given.
254
254
 
@@ -376,13 +376,15 @@ For the run's totals, call `summarizeUsage(results)` rather than adding the reco
376
376
 
377
377
  A run that produces an image, a PDF or a document does not embed the bytes. The content inside `main_stuff` carries the file's durable reference — a `pipelex-storage://` URI, in the content's `url` — beside a `public_url` the storage provider signed when the run wrote the file. **That signed link is short-lived and must not be stored**: it expires on the provider's own schedule, so a link persisted in a database or rendered into a cached page stops working without warning, while the `pipelex-storage://` reference beside it is permanent and is what belongs in your records.
378
378
 
379
- To read the bytes, mint a fresh link from the reference:
379
+ To read the bytes, mint a fresh link from the reference. On the hosted platform, `resolveStorageUrl` mints one link:
380
380
 
381
381
  ```ts
382
382
  const resolved = await client.resolveStorageUrl({ uri: "pipelex-storage://..." });
383
383
  // { url, expires_at, content_type } — fetch `url` now; re-resolve for the next reader.
384
384
  ```
385
385
 
386
- The same rule holds in a browser: resolve on the server, hand the client a link it uses immediately, and never let a presigned URL outlive the request it was minted for.
386
+ `resolveStorageUrl` calls `POST /v1/resolve-storage-url`, which only the hosted platform serves: a self-hosted runner, from pipelex-api 0.118.0, serves the bulk route alone, so a caller of one mints its link with `resolveArtifacts([uri])`, a one-item list.
387
+
388
+ The same rule holds in a browser: resolve on the server, hand the client a link it uses immediately, and never let a signed link outlive the request it was minted for.
387
389
 
388
390
  Bringing the files down is the SDK's job, not something to re-implement over `resolveStorageUrl`: `locateArtifacts` lists a result's references without touching the network, each with the paths of the fields it fills (`collectArtifacts` gives the references alone), `resolveArtifacts` mints fresh links for a whole list in one bulk call, `fetchArtifact` streams one file within safe bounds, and `downloadArtifacts` saves everything a run produced under a directory, each file named after the field it fills, by run id even days later. They all share one page, [`artifact-download.md`](./artifact-download.md). The upload direction — turning local files into `pipelex-storage://` references before a run — is the mirror of this and has its own page too, [`input-preparation.md`](./input-preparation.md).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipelex/sdk",
3
- "version": "0.69.5",
3
+ "version": "0.71.0",
4
4
  "description": "TypeScript SDK for the Pipelex hosted API — execute methods, manage runs, and call the product surface.",
5
5
  "license": "MIT",
6
6
  "repository": {