@pipelex/sdk 0.34.1 → 0.35.1

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/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { MTHDSProtocol, ModelCategory, ModelDeck, RunOptions, StartOptions, VersionInfo } from "mthds/protocol";
2
2
  import type { CodegenRequest, CodegenResponse, DictPipeOutput, FormatResponse, LintResponse, ModelCheckCategory, ModelReferenceVerdict, MthdsFileItem, PipeIORequest, PipeIOResponse, PipelexRunResultStart, PipelexValidationResult, ResolveRequest, ResolveResponse, ValidateMethodSelector } from "./models.js";
3
3
  import { type GetRunResultOptions, type RunRead, type RunResults, type RunResultState, type StartAndWaitForResultOptions, type WaitForResultOptions } from "./runs.js";
4
- import type { BillingPortalResponse, ChangePlanResponse, CheckoutResponse, InvoiceView, Membership, MembershipsResponse, ListMethodsQuery, MethodData, MethodDeletionAccepted, MethodPage, MethodSummary, MethodWriteInput, OnboardingSubmission, PipelexApiKeyCreated, PipelexApiKeyList, ListRunsQuery, RunHistoryItem, RunDetail, RunPage, PlanView, ResolvedStorageUrl, SubscriptionResponse, UpdateRunInput, UploadGrant, UploadGrantInput, UploadInput, UploadedFile, UserProfile } from "./product-models.js";
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
7
  import type { PrepareInputsRequest, PreparedInputs } from "./prepare-inputs.js";
@@ -57,20 +57,28 @@ export interface PipelexApiRunExtensions {
57
57
  */
58
58
  export interface PipelexHostedRunExtensions {
59
59
  /**
60
- * A stored method's catalog id (`mt_…`) — a **pass-through to the hosted
61
- * API**, resolved server-side against the org's catalog. Nothing is expanded
62
- * client-side, and it is meaningless off-platform: an open-source runner has
63
- * no catalog, so it answers a `422` naming the key.
60
+ * A stored method's catalog id (`mt_…`), optionally naming a version — a
61
+ * **pass-through to the hosted API**, resolved server-side against the org's
62
+ * catalog. Nothing is expanded client-side, and it is meaningless off-platform:
63
+ * an open-source runner has no catalog, so it answers a `422` naming the key.
64
64
  *
65
65
  * Its meaning depends on what else the request carries:
66
66
  *
67
- * - **Alone** — the platform resolves the stored method's source (assembling
68
- * its bundle when the method carries Python) and runs that.
67
+ * - **Alone** — the platform resolves the version the id names and runs its
68
+ * files, with the method's Python files beside them. A bare `mt_…` runs the
69
+ * latest published version, a `409` `method_not_published` for a method never
70
+ * published; `mt_…@<n>` runs version `n`, a `404` `method_version_not_found`
71
+ * for a version never published; `mt_…@draft` runs the draft. The suffix
72
+ * rides the string untouched, any other suffix is a `422`, and the answer's
73
+ * `method_version` says which version runs.
69
74
  * - **Alongside an inline source** (`mthds_contents` / `files` / `bundle_b64`)
70
75
  * — the inline source is what RUNS (precedence), and the id is recorded as
71
76
  * **run-history linkage** on the Run row. That linkage is what writes the
72
77
  * index key `GET /v1/runs?method_id=` queries, so a run started without it
73
- * is absent from its method's history permanently.
78
+ * is absent from its method's history permanently. The id must be bare
79
+ * there: the inline source is what runs, so a suffix would claim a version
80
+ * that did not, and a suffixed id is rejected client-side (a `422` on the
81
+ * hosted API).
74
82
  * - **Alongside `method_ref`** — rejected client-side (and a 422 on the
75
83
  * hosted API): an address run carries its own provenance, so it takes no
76
84
  * linkage id.
@@ -175,20 +183,25 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
175
183
  private requestProductObject;
176
184
  /**
177
185
  * A methods-catalog route answering one stored method (`getMethod`, `createMethod`,
178
- * `updateMethod`), parsed into the public shape. A stored `mthds` that is neither a string nor
179
- * absent (`null` stays "no source", which `getMethodClosure` reports), and a stored `python`
180
- * the SDK cannot parse, are an answer it cannot read, so each throws an `ApiResponseError` built
181
- * from that answer, the latter with `mthds`'s refusal as `cause`: `runtime`, not retryable,
182
- * since no change to the call fixes it.
186
+ * `writeDraft`, `renameMethod`), parsed into the public shape by `readStoredSources`.
183
187
  */
184
188
  private requestMethodData;
185
189
  /**
186
- * One page of a cursor-paged product route (`listMethods`, `listRuns`), read as the platform
187
- * always serializes it: `items` an array, `next_cursor` a string or `null`. A page breaking
188
- * either is an answer the SDK cannot read, so it throws the `ApiResponseError` `unreadableAnswer`
189
- * builds, `runtime` and not retryable, rather than handing the iterators a page they cannot
190
- * walk: `items` that is not iterable, or a missing cursor that is neither the end nor a next
191
- * page, which `iterateRuns` would follow forever.
190
+ * The stored sources of a method or of a published version, read from the answer `res`
191
+ * carried, into the public shape. A stored `mthds` that is neither a string nor absent (`null`
192
+ * stays "no source", which `getMethodClosure` reports), and a stored `python` the SDK cannot
193
+ * parse, are an answer it cannot read, so each throws an `ApiResponseError` built from that
194
+ * answer, the latter with `mthds`'s refusal as `cause`: `runtime`, not retryable, since no
195
+ * change to the call fixes it. `subject` names what carried them in the message.
196
+ */
197
+ private readStoredSources;
198
+ /**
199
+ * One page of a cursor-paged product route (`listMethods`, `listMethodVersions`, `listRuns`),
200
+ * read as the platform always serializes it: `items` an array, `next_cursor` a string or
201
+ * `null`. A page breaking either is an answer the SDK cannot read, so it throws the
202
+ * `ApiResponseError` `unreadableAnswer` builds, `runtime` and not retryable, rather than
203
+ * handing the iterators a page they cannot walk: `items` that is not iterable, or a missing
204
+ * cursor that is neither the end nor a next page, which `iterateRuns` would follow forever.
192
205
  */
193
206
  private requestPage;
194
207
  /** Issue a product request and return its 2xx answer, a non-2xx thrown as `ApiResponseError`. */
@@ -298,13 +311,17 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
298
311
  * `method_ref` run, the package's real file names feeding the diagnostics'
299
312
  * source labels;
300
313
  * - **`{ method_id }`** — a stored method's catalog id, hosted-only: the
301
- * platform resolves it and injects the stored source before the runner sees
302
- * the request (a bare runner rejects the request as carrying no source it
303
- * understands).
314
+ * platform resolves the version it names and injects that version's `.mthds`
315
+ * files before the runner sees the request (a bare runner rejects the request
316
+ * as carrying no source it understands). A bare `mt_…` validates the latest
317
+ * published version, `mt_…@<n>` version `n` and `mt_…@draft` the draft.
304
318
  *
305
319
  * A selector-resolution failure (fetch failure, no package at the address, an
306
- * unknown or foreign-org id) is a non-2xx `ApiResponseError` — never an
307
- * `is_valid: false` verdict, which is reserved for actual MTHDS content.
320
+ * unknown or foreign-org id, a bare id of a method never published, `409`
321
+ * `method_not_published`, a version never published, `404`
322
+ * `method_version_not_found`, or a malformed suffix, `422`) is a non-2xx
323
+ * `ApiResponseError` — never an `is_valid: false` verdict, which is reserved
324
+ * for actual MTHDS content.
308
325
  *
309
326
  * `mthdsSources` (optional, parallel to inline contents) names each submitted
310
327
  * content — a Pipelex-API extension threaded onto `blueprint.source`, so
@@ -633,14 +650,29 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
633
650
  * explicit choice.
634
651
  */
635
652
  iterateMethods(query?: Omit<ListMethodsQuery, "cursor">): AsyncGenerator<MethodSummary, void, undefined>;
636
- /** Fetch one method by id — `GET /v1/methods/{id}`. */
653
+ /**
654
+ * Read one method — `GET /v1/methods/{id}`: its identity, its draft (`mthds`, `python`,
655
+ * `input_data`) with the draft's token (`updated_at`) and digest (`draft_digest`), and its
656
+ * latest published version's summary (`latest_version`, `latest_published`), whatever the
657
+ * publish state. A method never published reads with both `null`, never as an error.
658
+ *
659
+ * Takes a bare catalog id: the method routes address the method itself, never a version of
660
+ * it. A caller holding `mt_…@3` strips the suffix with `parseMethodSelector` and reads that
661
+ * version with `getMethodVersion`. Every method route throws `RequestArgumentError` for a
662
+ * suffixed id, before any request, rather than read back the `404` the platform would answer.
663
+ */
637
664
  getMethod(methodId: string): Promise<MethodData>;
638
665
  /**
639
- * Resolve a stored method's id into its runnable MTHDS closure — a client-side
640
- * semantic layer over `getMethod` (the platform has no route that returns a
641
- * parsed closure). Fetches the method, parses its polymorphic `mthds` source
642
- * with `methodSourceToContents`, and labels each resulting file with the
643
- * `method_id` as its `source` provenance.
666
+ * Resolve a stored method's id into the runnable MTHDS closure of its DRAFT — a
667
+ * client-side semantic layer over `getMethod` (the platform has no route that
668
+ * returns a parsed closure). Fetches the method, parses its draft's polymorphic
669
+ * `mthds` source with `methodSourceToContents`, and labels each resulting file
670
+ * with the `method_id` as its `source` provenance.
671
+ *
672
+ * **This is the draft, not what a bare id runs.** A run, a validation or a pipe I/O
673
+ * read by a bare `method_id` resolves to the latest PUBLISHED version, which the
674
+ * draft may be ahead of. For the closure of a version, read it with
675
+ * `getMethodVersion` and parse its `mthds` with `methodSourceToContents`.
644
676
  *
645
677
  * This is the LOCAL expansion utility — for callers that want the files in
646
678
  * hand (to edit, to diff, or to send to a bare runner, which has no catalog to
@@ -649,17 +681,113 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
649
681
  * `prepareInputs`, which composes a `pipeIo` of its own) take the id as a
650
682
  * pass-through instead; nothing in this client expands an id behind your back.
651
683
  *
652
- * Requires an API key: the methods catalog is org-scoped to the key's org, so
653
- * an unknown OR foreign-org id is a `getMethod` `404` (`ApiResponseError`
654
- * `not_found`), which propagates unchanged. A real, in-org method whose source
655
- * parses to nothing throws `EmptyMethodSourceError` (distinct from the 404) —
656
- * the row exists but has no runnable source yet.
684
+ * Takes a bare catalog id, as `getMethod` does. Requires an API key: the methods
685
+ * catalog is org-scoped to the key's org, so an unknown OR foreign-org id is a
686
+ * `getMethod` `404` (`ApiResponseError` `not_found`), which propagates unchanged. A
687
+ * real, in-org method whose draft parses to nothing throws `EmptyMethodSourceError`
688
+ * (distinct from the 404) — the row exists but has no runnable source yet.
657
689
  */
658
690
  getMethodClosure(methodId: string): Promise<MthdsFileItem[]>;
659
- /** Create a method — `POST /v1/methods`. */
691
+ /**
692
+ * Create a method — `POST /v1/methods`. The new method holds the input as its draft and has
693
+ * no published version, so its bare id answers `409 method_not_published` on the run and
694
+ * tooling routes until its first `publishMethod`; its draft runs as `mt_…@draft` at once.
695
+ *
696
+ * Throws `ApiResponseError`: `413` `payload_too_large` for a method that would leave no room
697
+ * for a publish, measured as a draft write is, and `422` `validation_failed` for Python files
698
+ * no run could import or for text holding a lone surrogate.
699
+ */
660
700
  createMethod(input: MethodWriteInput): Promise<MethodData>;
661
- /** Replace a method (rename = changed `name`) — `PUT /v1/methods/{id}`. */
662
- updateMethod(methodId: string, input: MethodWriteInput): Promise<MethodData>;
701
+ /**
702
+ * Replace a method's draft — `PUT /v1/methods/{id}/draft` — and return the method with the
703
+ * draft's new token (`updated_at`) and digest (`draft_digest`).
704
+ *
705
+ * The draft is never validated on write, and writing it changes nothing for the callers of
706
+ * the method's bare id, who run the latest published version until the next `publishMethod`.
707
+ * `python` and `input_data` are three-way (see `MethodDraftInput`). With
708
+ * `expected_updated_at`, the write is a compare-and-swap on the draft token: a draft that
709
+ * moved since is refused with a `409` whose `code` is `method_update_conflict`, and nothing is
710
+ * written. Without it, last writer wins.
711
+ *
712
+ * Takes a bare catalog id, as `getMethod` does. Throws `ApiResponseError`: `404` `not_found`
713
+ * for an unknown or foreign-org method, `409` `method_being_deleted` while its erasure runs,
714
+ * `413` `payload_too_large` for a draft that would grow the method past the room a publish
715
+ * needs, which keeps a draft that saves publishable, `422` `validation_failed` for Python
716
+ * files no run could import or for text holding a lone surrogate, `403` for a read-only key,
717
+ * and a `503` that wrote nothing, safe to retry, when the method kept changing under the
718
+ * write.
719
+ */
720
+ writeDraft(methodId: string, input: MethodDraftInput): Promise<MethodData>;
721
+ /**
722
+ * Rename a method — `PATCH /v1/methods/{id}` — and return it. The name belongs to the method,
723
+ * not to a version: a rename changes nothing else, moves no token, and never commits the
724
+ * draft, so the `updated_at` a caller holds stays valid for its next `writeDraft` or
725
+ * `publishMethod`.
726
+ *
727
+ * Takes a bare catalog id, as `getMethod` does. Throws `ApiResponseError`: `404` `not_found`,
728
+ * `409` `method_being_deleted`, `403` for a read-only key, `422` for an empty name or one
729
+ * holding a lone surrogate, `413` `payload_too_large` for a name so long it would leave the
730
+ * method too large to publish, and a `503` that wrote nothing, safe to retry, when draft
731
+ * writes kept landing under the rename.
732
+ */
733
+ renameMethod(methodId: string, input: MethodRenameInput): Promise<MethodData>;
734
+ /**
735
+ * Publish a method's draft as its next version — `POST /v1/methods/{id}/publish`.
736
+ *
737
+ * `expected_draft_updated_at` is the draft token the caller last saw, and it is required: a
738
+ * publish never takes a draft its caller has not seen. The platform checks the token, answers
739
+ * `unchanged` without asking the runner when the draft's digest equals the latest version's,
740
+ * and otherwise validates the draft and, when it validates and runs, writes version N+1.
741
+ *
742
+ * The answer is a `MethodPublishResult` discriminated on `outcome` — branch on it:
743
+ * `published` with the new `version`; `unchanged` with the existing latest `version`;
744
+ * `refused` with a `reason` (`invalid`, or `not_runnable` for a draft that validates with
745
+ * pending signatures), a `message` and the runner's `validation` verdict. Every arm carries the
746
+ * `method`. A publish moves no token.
747
+ *
748
+ * Takes a bare catalog id, as `getMethod` does. Throws `RequestArgumentError` when
749
+ * `expected_draft_updated_at` is not a string, before any request. Throws `ApiResponseError`
750
+ * when no verdict was produced: `409` `method_update_conflict` for a draft that moved since
751
+ * the token, `409` `method_being_deleted`, `404` `not_found`, `422` for a draft with no
752
+ * `.mthds` file or whose file names a run could not assemble (one name used by a `.mthds` and
753
+ * a Python file), `413` `payload_too_large` for a draft too large to publish, and `403` for a
754
+ * read-only key.
755
+ *
756
+ * Only a draft that differs from the latest version reaches the runner, and a runner that
757
+ * cannot be reached, answers unusably or does not finish within the platform's deadline is a
758
+ * `502` or a `503` with nothing written, so a retry is safe; a runner that refuses the request
759
+ * itself is relayed under its own status. A retry of a publish that landed while its answer was
760
+ * lost, as on a client timeout, answers `unchanged` with the version it wrote.
761
+ *
762
+ * An answer whose `outcome` is not one of the outcomes above, or that carries no `method`
763
+ * object, is an answer the SDK cannot read, thrown as an `ApiResponseError` too.
764
+ */
765
+ publishMethod(methodId: string, input: MethodPublishInput): Promise<MethodPublishResult>;
766
+ /**
767
+ * One page of a method's published versions, newest first, without their sources —
768
+ * `GET /v1/methods/{id}/versions`.
769
+ *
770
+ * Pass the page's `nextCursor` back as `cursor` to continue; `null` is the last page. A page
771
+ * may be short while `nextCursor` is set, because the platform reads versions whole. A method
772
+ * never published answers an empty page.
773
+ *
774
+ * Takes a bare catalog id, as `getMethod` does. Throws `ApiResponseError`: `404` `not_found`
775
+ * for an unknown method, `409` `method_being_deleted`, `400` `malformed_request` for a cursor
776
+ * the listing did not issue for this method, `422` for a `limit` outside 1 to 100. A page whose `items` is not an array or whose `next_cursor` is neither a string nor `null`
777
+ * is an answer the SDK cannot read, thrown as an `ApiResponseError` too.
778
+ */
779
+ listMethodVersions(methodId: string, query?: ListMethodVersionsQuery): Promise<MethodVersionPage>;
780
+ /**
781
+ * One published version of a method, with its sources —
782
+ * `GET /v1/methods/{id}/versions/{n}`. Its `python` is parsed into `MethodFile[]` as a
783
+ * method's is.
784
+ *
785
+ * Takes a bare catalog id, as `getMethod` does, and the version number. Throws
786
+ * `RequestArgumentError` for a `version` that is not a positive integer, before any request.
787
+ * Throws `ApiResponseError`: `404` `method_version_not_found` for a version the method never
788
+ * published, `404` `not_found` for an unknown method, `409` `method_being_deleted`.
789
+ */
790
+ getMethodVersion(methodId: string, version: number): Promise<MethodVersion>;
663
791
  /**
664
792
  * Erase a method and everything it produced — `DELETE /v1/methods/{id}`.
665
793
  *
@@ -673,8 +801,10 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
673
801
  * it with a `409`.
674
802
  *
675
803
  * A double-clicked delete is safe: the claim is a conditional write, so the
676
- * second call is an `ApiResponseError` (`409 conflict`) rather than a second
677
- * cascade over the same runs. An unknown or foreign-org id is a `404`.
804
+ * second call is an `ApiResponseError` (`409 method_being_deleted`) rather than a
805
+ * second cascade over the same runs. An unknown or foreign-org id is a `404`. The
806
+ * erasure deletes the method's published versions with the rest. Takes a bare catalog id,
807
+ * as `getMethod` does: the whole method is erased, never one of its versions.
678
808
  */
679
809
  deleteMethod(methodId: string): Promise<MethodDeletionAccepted>;
680
810
  /** The caller's org memberships + active-org feature flags — `GET /v1/organizations/memberships`. */
@@ -849,6 +979,12 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
849
979
  * `createdFrom` / `createdTo` are applied server-side as index key
850
980
  * conditions, so a bounded page genuinely reads less. They are INSTANTS,
851
981
  * not days — see `ListRunsQuery`.
982
+ *
983
+ * Takes a bare catalog id: the history files the runs of every version and
984
+ * of the draft together under it, so `mt_…@3` names no history of its own
985
+ * and the platform refuses it with a `400`. Strip a suffix with
986
+ * `parseMethodSelector`, and read which version a run ran from its
987
+ * `method_version`.
852
988
  */
853
989
  listRuns(methodId: string, query?: ListRunsQuery): Promise<RunPage>;
854
990
  /**
@@ -872,6 +1008,8 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
872
1008
  * cliff: it yields until the server says there is no more, the caller decides
873
1009
  * when to stop, and only one page is ever in memory. If you truly want an
874
1010
  * array, `Array.fromAsync` makes that your explicit choice.
1011
+ *
1012
+ * Takes a bare catalog id, as `listRuns` does.
875
1013
  */
876
1014
  iterateRuns(methodId: string, query?: Omit<ListRunsQuery, "cursor">): AsyncGenerator<RunHistoryItem, void, undefined>;
877
1015
  /**