@pipelex/sdk 0.38.0 → 0.40.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 (52) hide show
  1. package/README.md +3 -2
  2. package/dist/bundle-resources.d.ts +62 -0
  3. package/dist/bundle-resources.js +165 -0
  4. package/dist/bundle-resources.js.map +1 -0
  5. package/dist/cli/run.js +8 -111
  6. package/dist/cli/run.js.map +1 -1
  7. package/dist/cli/script.d.ts +1 -1
  8. package/dist/cli/source.d.ts +2 -1
  9. package/dist/cli/source.js +61 -3
  10. package/dist/cli/source.js.map +1 -1
  11. package/dist/client.d.ts +116 -30
  12. package/dist/client.js +235 -75
  13. package/dist/client.js.map +1 -1
  14. package/dist/error-models.d.ts +64 -18
  15. package/dist/error-models.js +20 -9
  16. package/dist/error-models.js.map +1 -1
  17. package/dist/errors.d.ts +125 -23
  18. package/dist/errors.js +124 -22
  19. package/dist/errors.js.map +1 -1
  20. package/dist/execute-result.js +4 -4
  21. package/dist/execute-result.js.map +1 -1
  22. package/dist/hooks/bundle-gather.d.ts +28 -1
  23. package/dist/hooks/bundle-gather.js +163 -3
  24. package/dist/hooks/bundle-gather.js.map +1 -1
  25. package/dist/hooks/claude-mthds-check.d.ts +4 -2
  26. package/dist/hooks/claude-mthds-check.js +5 -2
  27. package/dist/hooks/claude-mthds-check.js.map +1 -1
  28. package/dist/index.d.ts +7 -5
  29. package/dist/index.js +6 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/models.d.ts +42 -4
  32. package/dist/prepare-inputs.d.ts +58 -4
  33. package/dist/prepare-inputs.js +307 -61
  34. package/dist/prepare-inputs.js.map +1 -1
  35. package/dist/product-models.d.ts +13 -5
  36. package/dist/run-may-have-started.d.ts +31 -0
  37. package/dist/run-may-have-started.js +138 -0
  38. package/dist/run-may-have-started.js.map +1 -0
  39. package/dist/runs.d.ts +95 -7
  40. package/dist/runs.js +18 -0
  41. package/dist/runs.js.map +1 -1
  42. package/dist/version.d.ts +1 -1
  43. package/dist/version.js +1 -1
  44. package/docs/architecture.md +6 -3
  45. package/docs/bundle-resources.md +107 -0
  46. package/docs/cli.md +2 -1
  47. package/docs/crate-routes.md +5 -1
  48. package/docs/errors.md +87 -17
  49. package/docs/hook-bundle.md +2 -0
  50. package/docs/input-preparation.md +26 -4
  51. package/docs/run-results.md +39 -0
  52. package/package.json +2 -2
package/dist/client.d.ts CHANGED
@@ -4,6 +4,7 @@ import { type GetRunResultOptions, type RunRead, type RunResults, type RunResult
4
4
  import type { BillingPortalResponse, ChangePlanResponse, CheckoutResponse, InvoiceView, Membership, MembershipsResponse, ListMethodsQuery, ListMethodVersionsQuery, MethodData, MethodDeletionAccepted, MethodDraftInput, MethodPage, MethodPublishInput, MethodPublishResult, MethodRenameInput, MethodSummary, MethodVersion, MethodVersionPage, MethodWriteInput, OnboardingSubmission, PipelexApiKeyCreated, PipelexApiKeyList, ListRunsQuery, RunHistoryItem, RunDetail, RunPage, PlanView, ResolvedStorageUrl, SubscriptionResponse, UpdateRunInput, UploadGrant, UploadGrantInput, UploadInput, UploadedFile, UserProfile } from "./product-models.js";
5
5
  import type { AppInfo } from "./user-agent.js";
6
6
  import type { UploadableAsset, UploadFileOptions, UploadRecord } from "./upload.js";
7
+ import type { BundleResources } from "./bundle-resources.js";
7
8
  import type { PrepareInputsRequest, PreparedInputs } from "./prepare-inputs.js";
8
9
  import type { BulkResolveStorageUrlsInput, BulkResolvedStorageUrls, DownloadArtifactsRequest, DownloadArtifactsResult, FetchArtifactOptions, ResolvedArtifact } from "./artifacts.js";
9
10
  import { PipelexExecuteResult } from "./execute-result.js";
@@ -14,10 +15,11 @@ export interface MthdsFile {
14
15
  uri?: string;
15
16
  }
16
17
  /**
17
- * The Pipelex API's own run-source extension — the layer-2 argument the RUNNER
18
- * itself resolves, beside the protocol's inline sources (`mthds_contents` and
19
- * the bundle encodings). Served by any pipelex-api >= 0.21.0 deployment, bare
20
- * or hosted (on `api.pipelex.com`, once the platform deploy carrying it lands).
18
+ * The Pipelex API's own run arguments — the layer-2 arguments the RUNNER itself
19
+ * reads, beside the protocol's inline sources (`mthds_contents` and the bundle
20
+ * encodings): the `method_ref` run source, served by any pipelex-api >= 0.21.0
21
+ * deployment, bare or hosted (on `api.pipelex.com`, once the platform deploy
22
+ * carrying it lands), and the `resources` the bundle's steps read.
21
23
  *
22
24
  * Named options rather than `extra` entries, for the same reason as the hosted
23
25
  * extensions below: `extra` remains the escape hatch for an extension this
@@ -43,6 +45,20 @@ export interface PipelexApiRunExtensions {
43
45
  * An empty string is treated as absent and is not sent.
44
46
  */
45
47
  method_ref?: string | null;
48
+ /**
49
+ * The files the bundle's steps read, such as a `PipeDocGen` step's `template_file`, keyed
50
+ * by the path the step names (`templates/invoice.docx`), each as its bytes (a `Uint8Array`,
51
+ * a Node `Buffer` included, an `ArrayBuffer` or a `Blob`). The client sends them as the
52
+ * wire's `resources`, each file in standard base64; see `docs/bundle-resources.md`.
53
+ *
54
+ * They accompany the bundle whose steps read them: inline `mthds_contents` or a method
55
+ * bundle (`files` / `bundle_b64`), or a hosted `method_id` the platform resolves. Beside a
56
+ * `method_ref` (whose files are its package's own), or with no source at all, they are
57
+ * rejected client-side, mirroring the server's `422`. A key that cannot name a file inside
58
+ * the bundle (absolute, a `..` segment, a backslash, a colon) is rejected client-side too.
59
+ * An absent, `null` or empty map is not sent.
60
+ */
61
+ resources?: BundleResources | null;
46
62
  }
47
63
  /**
48
64
  * The hosted API's own run arguments — the layer-3 extensions this client adds
@@ -104,6 +120,32 @@ export interface ValidateFilesOptions {
104
120
  render?: string[];
105
121
  /** Optional structured-view opt-in tokens, e.g. ["input_form", "output_form"]; sent only when given. */
106
122
  views?: string[];
123
+ /**
124
+ * The files the bundle's steps read, such as a `PipeDocGen` step's `template_file`, keyed by
125
+ * the path the step names, each as its bytes; sent as `resources` (see {@link ValidateOptions}).
126
+ */
127
+ resources?: BundleResources | null;
128
+ /**
129
+ * Per-call request ceiling; defaults to the 20-min execute ceiling. A positive number
130
+ * no larger than 2147483647, the longest delay a timer honours, else a `RangeError`.
131
+ */
132
+ timeoutMs?: number;
133
+ /** Caller-driven cancellation; the abort reason propagates untouched. */
134
+ signal?: AbortSignal;
135
+ }
136
+ /** `validate()`'s last argument: what rides beside the method, and the call's own transport. */
137
+ export interface ValidateOptions {
138
+ /**
139
+ * The files the bundle's steps read, such as a `PipeDocGen` step's `template_file`, keyed by
140
+ * the path the step names (`templates/invoice.docx`), each as its bytes (a `Uint8Array`, a
141
+ * Node `Buffer` included, an `ArrayBuffer` or a `Blob`). Sent as the wire's `resources`, each
142
+ * file in standard base64; see `docs/bundle-resources.md`. They accompany inline contents, or
143
+ * a hosted `{ method_id }` the platform resolves; beside a `{ method_ref }` they are rejected
144
+ * client-side, mirroring the server's `422`. A step whose template file was not sent makes the
145
+ * verdict invalid, saying so; the dry run checks an office template file it was sent and adds
146
+ * its findings to the valid arm's `warnings` (`template_check_warning`).
147
+ */
148
+ resources?: BundleResources | null;
107
149
  /**
108
150
  * Per-call request ceiling; defaults to the 20-min execute ceiling. A positive number
109
151
  * no larger than 2147483647, the longest delay a timer honours, else a `RangeError`.
@@ -161,7 +203,8 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
161
203
  * DNS/connect/TLS/timeout failures as `ApiUnreachableError`; a caller-driven
162
204
  * abort (Ctrl-C / agent walk-away) propagates as-is so the poll loop can stop
163
205
  * cleanly. Non-2xx interpretation is left to the caller. `url` is a fully
164
- * resolved absolute URL.
206
+ * resolved absolute URL. `mayStartRun` marks a request that may create a run,
207
+ * whose `ApiUnreachableError` then says whether it may have (see `RunCreation`).
165
208
  */
166
209
  private requestRaw;
167
210
  /**
@@ -230,6 +273,7 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
230
273
  * `API <method> <path> answered <status> with <what>`: the answer's status, its raw text as
231
274
  * `responseBody`, no problem member but the `X-Request-ID` header, the failure that made it
232
275
  * unreadable as `cause`, and the verdict the fallback gives a 2xx, `runtime` and not retryable.
276
+ * On a request that may create a run, the run may have started: the server accepted it.
233
277
  */
234
278
  private unreadableAnswer;
235
279
  /**
@@ -249,6 +293,11 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
249
293
  * error. Hosted does not emit 202 today, but the protocol permits it;
250
294
  * raising a typed error (with the `pipeline_run_id` + `Location` + `Retry-After`
251
295
  * hints) beats a generic parse failure on an unexpected body shape.
296
+ *
297
+ * The 202 must name the run it accepted, as `start`'s acknowledgement must: one whose body is
298
+ * not JSON, or names no run (an empty id included), leaves the caller a run it cannot follow, so it is an answer the
299
+ * SDK cannot read, which may have started a run, never a `RunStillRunningError` without an id.
300
+ * The Python SDK reads the same answers the same way.
252
301
  */
253
302
  private throwIfExecuteDegraded;
254
303
  /**
@@ -349,6 +398,15 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
349
398
  * the field regardless — which is why `PipelexValidationReport.input_form` is typed
350
399
  * optional rather than required.
351
400
  *
401
+ * `options.resources` sends the files the bundle's steps read, such as a
402
+ * `PipeDocGen` step's `template_file`, keyed by the path the step names, each as
403
+ * its bytes (see {@link ValidateOptions}). A step whose template file was not sent
404
+ * is an `is_valid: false` verdict saying so, and a template check's findings in an
405
+ * office template file ride the valid arm's `warnings`. A key no step names, or
406
+ * files over the server's limits, are no-verdict refusals: a `422`
407
+ * `BundleResourceNotNamedError`, a `413` `PayloadTooLarge` or
408
+ * `BundleResourcesTooLargeError`.
409
+ *
352
410
  * A `{ method_ref }` source makes the server clone a repository before it
353
411
  * validates anything, and it needs no special budget here: this route already
354
412
  * defaults to the 20-minute execute ceiling, which clears the internal
@@ -357,10 +415,7 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
357
415
  * exists to RAISE routes whose default is the ~30s poll ceiling; applying it here
358
416
  * would lower this one.
359
417
  */
360
- validate(source: string[] | ValidateMethodSelector, allowSignatures?: boolean, mthdsSources?: string[], render?: string[], views?: string[], options?: {
361
- timeoutMs?: number;
362
- signal?: AbortSignal;
363
- }): Promise<PipelexValidationResult>;
418
+ validate(source: string[] | ValidateMethodSelector, allowSignatures?: boolean, mthdsSources?: string[], render?: string[], views?: string[], options?: ValidateOptions): Promise<PipelexValidationResult>;
364
419
  /**
365
420
  * Validate paired MTHDS files while preserving URI attribution for diagnostics.
366
421
  *
@@ -411,10 +466,11 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
411
466
  * never on a message.
412
467
  *
413
468
  * All of these are static and inference-free, so they default to the management-call
414
- * timeout. The one internal raise is the fetch-sized budget `crateRequestTimeoutMs`
415
- * gives a crate route whose closure is a `method_ref`, because the server may clone a
416
- * repository before it answers; it is matched to what the server does, not a
417
- * caller-facing parameter.
469
+ * timeout. The internal raises are `crateRequestTimeoutMs`'s: the fetch-sized budget a
470
+ * crate route gets when its closure is a `method_ref`, because the server may clone a
471
+ * repository before it answers, and the execute ceiling it gets when the request
472
+ * carries `resources`, whose upload alone can outlast the default. Each is matched to
473
+ * what the request costs, not a caller-facing parameter.
418
474
  *
419
475
  * **These routes deliberately expose no `timeoutMs` / `signal`, and that is not an
420
476
  * oversight to be "fixed" per route.** Automated reviewers have proposed adding them
@@ -425,8 +481,11 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
425
481
  * ceiling and takes caller transport options; every extension route rides the
426
482
  * static core. Giving one static route an override while its siblings lack one is
427
483
  * the inconsistency.
428
- * 2. The input is **bounded server-side** — the runner's `pipelex_api/limits.py` caps a request
429
- * at 16 `.mthds` files of 1 MiB each — and none of these routes runs inference.
484
+ * 2. The input is **bounded server-side** — the runner's `pipelex_api/limits.py` caps the
485
+ * `.mthds` files of a request and the files sent with them in `resources`, each by a
486
+ * count, a size per file and, for `resources`, a total, all configurable per
487
+ * deployment — and none of these routes runs inference. The upload those limits allow
488
+ * is what `crateRequestTimeoutMs` budgets for, not the server's work.
430
489
  * 3. On the hosted path an override would be **inert**: the gateway caps responses at
431
490
  * ~30s (see `POLL_REQUEST_TIMEOUT_MS` above), so raising `timeoutMs` would still be
432
491
  * cut off upstream, just with a less honest error.
@@ -519,8 +578,14 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
519
578
  * describes every pipe instead, and never refuses for want of an entry pipe.
520
579
  * `include_files: true` echoes the resolved closure's `.mthds` files as `files`.
521
580
  *
581
+ * Beside inline `files`, `resources` sends the files the closure's steps read, such as a
582
+ * `PipeDocGen` step's `template_file`, keyed by the path the step names, each as its bytes;
583
+ * a step whose template file was not sent makes the closure invalid. `resolve` and `codegen`
584
+ * take it too (see {@link CrateRequestBase}).
585
+ *
522
586
  * Same 200-verdict discipline and same three-form closure selector as {@link resolve}
523
- * (the request is posted verbatim, and the selector XOR is the server's to enforce).
587
+ * (the request is posted as given, its `resources` encoded to base64, and the selector XOR
588
+ * and the `resources` pairing are the server's to enforce).
524
589
  * Only a no-verdict condition throws `ApiResponseError`: a malformed selector and an
525
590
  * over-limit file are `ValidationError` `422`s; a selection the route refuses is a
526
591
  * `422` whose `errorType` is `EntryPipeNotFoundError` (an unknown `pipe_ref`, no entry
@@ -528,22 +593,28 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
528
593
  * candidates in its `serverMessage`; a registry-form `method_ref` is a `501`; a pipe
529
594
  * whose artifacts cannot be derived is a `500`.
530
595
  *
531
- * A `method_ref` gets the fetch-sized budget, as on the other crate routes. On the
532
- * hosted API the gateway caps a request at about 30 seconds whatever the client
533
- * allows, so a cold `method_ref` clone can answer a `502` that a retry clears once the
534
- * runner has cached the clone.
596
+ * A `method_ref` gets the fetch-sized budget, as on the other crate routes, and a
597
+ * request carrying `resources` the execute ceiling, since their upload alone can
598
+ * outlast the default. On the hosted API the gateway caps a request at about 30
599
+ * seconds whatever the client allows, so a cold `method_ref` clone can answer a `502`
600
+ * that a retry clears once the runner has cached the clone.
535
601
  */
536
602
  pipeIo(request: PipeIORequest): Promise<PipeIOResponse>;
537
603
  /**
538
604
  * Fetch a run's status by bare id — `GET /v1/runs/{pipeline_run_id}/status`.
539
605
  *
540
606
  * Self-healing: a finished-but-unrecorded run resolves to its true terminal
541
- * status on read. `degraded: true` means Temporal was unreachable and
542
- * `status` is the last-known value; `retry_after_seconds` carries the
543
- * server's backoff hint when present. A failed run's stored report, `error`,
544
- * is checked field by field (see `RunErrorReport`). Throws
545
- * `RunLifecycleUnavailableError` when the lifecycle routes are absent (a bare
546
- * runner).
607
+ * status on read. `degraded: true` means the read is not a plain fresh reading,
608
+ * and `degradation.reason` says why (see `DegradationReason`):
609
+ * `status_unavailable` when the platform could not reach the workflow engine
610
+ * and `status` is the last one recorded, `workflow_task_failing` when `status`
611
+ * is live and the run is stuck, its workflow task failing until the platform
612
+ * ends it at `degradation.ends_at`. `retry_after_seconds` carries the server's
613
+ * `Retry-After` hint when present, and `request_id` the id to quote to support.
614
+ * A failed run's stored report, `error`, and the `degradation` are each
615
+ * checked field by field (see `RunErrorReport` and `RunDegradation`), so
616
+ * neither ever fails the read. Throws `RunLifecycleUnavailableError` when the
617
+ * lifecycle routes are absent (a bare runner).
547
618
  */
548
619
  getRunStatus(runId: string, options?: {
549
620
  signal?: AbortSignal;
@@ -609,6 +680,13 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
609
680
  * `pollOptions.signal` is also read before the run is created: a caller that aborts while the
610
681
  * version handshake is in flight gets its abort, and neither the start nor the blocking execute
611
682
  * is sent. Once one of them is sent, the abort stops only the wait.
683
+ *
684
+ * An error from the start, or from the blocking execute, says whether that request may still
685
+ * have started a run whose id never reached the caller (`runMayHaveStarted`); when it may have,
686
+ * it is not retryable, since calling this method again could pay for the run twice: look the run
687
+ * up in the run history first. An error from the wait, once `onStarted` has named the run,
688
+ * started nothing, so its `runMayHaveStarted` is false, and its `retryable` is about waiting
689
+ * again on that id with `waitForResult`, never about calling this method again.
612
690
  */
613
691
  startAndWaitForResult(options: PipelexStartOptions, pollOptions?: StartAndWaitForResultOptions): Promise<RunResults>;
614
692
  /** The authenticated user's profile — `GET /v1/me`. */
@@ -946,7 +1024,8 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
946
1024
  * Name the method exactly one of three ways, all server-resolved through the
947
1025
  * one `pipeIo` call this composes:
948
1026
  *
949
- * - `files` — the inline MTHDS closure;
1027
+ * - `files` — the inline MTHDS closure, with the `resources` its steps read
1028
+ * (a `PipeDocGen` step's `template_file`), keyed by the path a step names;
950
1029
  * - `method_ref` — a published method's address, fetched by the runner;
951
1030
  * - `method_id` — a stored method's catalog id, resolved by the platform
952
1031
  * (hosted only; requires an API key).
@@ -956,6 +1035,12 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
956
1035
  * answers with, which states the kind of every input at every depth, so a file
957
1036
  * position is a fact of the method, never a guess from the value's shape. It
958
1037
  * needs an API serving `POST /v1/pipe-io`. See `docs/input-preparation.md`.
1038
+ *
1039
+ * A value at a file input that cannot be a file, such as a number or a
1040
+ * `data:` URL that does not decode, throws `InvalidInputValueError`, naming the
1041
+ * input. With `allowUploads: false` it uploads nothing and reads no file: a
1042
+ * value that would need an upload throws `UploadNotAllowedError`, naming the
1043
+ * input too.
959
1044
  */
960
1045
  prepareInputs(request: PrepareInputsRequest): Promise<PreparedInputs>;
961
1046
  /**
@@ -1050,8 +1135,9 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
1050
1135
  * `is_gateway_cut_off` reads the same failures, its `ABORT_TIMEOUT` being httpx's read or write
1051
1136
  * timeout.
1052
1137
  *
1053
- * The blocking `execute` turns such a failure into a `PipelineExecuteTimeoutError`. A caller timing
1054
- * a request that may create a run, such as `start` from `startAndWaitForResult`'s `onStarting`,
1055
- * reads it to know the server may still be handling the request the gateway gave up on.
1138
+ * The blocking `execute` turns such a failure into a `PipelineExecuteTimeoutError`. Whether a
1139
+ * failed `start` or `execute` may have started a run needs no timing: the error says it as
1140
+ * `runMayHaveStarted`, which reads every `503` but the platform's coded one as a run that may
1141
+ * have started, however quickly it came back.
1056
1142
  */
1057
1143
  export declare function isGatewayCutOff(error: unknown, elapsedMs: number): boolean;