@pipelex/sdk 0.47.0 → 0.48.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 (46) hide show
  1. package/README.md +8 -6
  2. package/dist/cli/script.d.ts +1 -1
  3. package/dist/cli/source.d.ts +8 -7
  4. package/dist/cli/source.js +11 -5
  5. package/dist/cli/source.js.map +1 -1
  6. package/dist/client.d.ts +321 -210
  7. package/dist/client.js +819 -514
  8. package/dist/client.js.map +1 -1
  9. package/dist/errors.d.ts +5 -2
  10. package/dist/errors.js +5 -2
  11. package/dist/errors.js.map +1 -1
  12. package/dist/hooks/bundle-gather.d.ts +28 -40
  13. package/dist/hooks/bundle-gather.js +55 -230
  14. package/dist/hooks/bundle-gather.js.map +1 -1
  15. package/dist/hooks/claude-mthds-check.d.ts +7 -5
  16. package/dist/hooks/claude-mthds-check.js +8 -53
  17. package/dist/hooks/claude-mthds-check.js.map +1 -1
  18. package/dist/hooks/validate-stage.d.ts +27 -0
  19. package/dist/hooks/validate-stage.js +57 -0
  20. package/dist/hooks/validate-stage.js.map +1 -0
  21. package/dist/index.d.ts +3 -4
  22. package/dist/index.js +4 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/method-trees.d.ts +208 -73
  25. package/dist/method-trees.js +221 -34
  26. package/dist/method-trees.js.map +1 -1
  27. package/dist/models.d.ts +162 -59
  28. package/dist/prepare-inputs.d.ts +46 -27
  29. package/dist/prepare-inputs.js +123 -42
  30. package/dist/prepare-inputs.js.map +1 -1
  31. package/dist/product-models.d.ts +14 -16
  32. package/dist/version.d.ts +1 -1
  33. package/dist/version.js +1 -1
  34. package/docs/architecture.md +17 -18
  35. package/docs/cli.md +1 -1
  36. package/docs/crate-routes.md +42 -20
  37. package/docs/errors.md +5 -5
  38. package/docs/hook-bundle.md +1 -1
  39. package/docs/input-preparation.md +11 -11
  40. package/docs/method-trees.md +119 -21
  41. package/docs/run-results.md +5 -2
  42. package/package.json +2 -2
  43. package/dist/bundle-resources.d.ts +0 -62
  44. package/dist/bundle-resources.js +0 -165
  45. package/dist/bundle-resources.js.map +0 -1
  46. package/docs/bundle-resources.md +0 -107
package/dist/models.d.ts CHANGED
@@ -8,8 +8,8 @@
8
8
  * the model reference check. Built on the protocol wire types imported from the
9
9
  * `mthds/protocol` subpath.
10
10
  */
11
- import type { InputForm, OutputForm, PipeIOContracts, RunResultExecute, RunResultStart } from "mthds/protocol";
12
- import type { BundleResources } from "./bundle-resources.js";
11
+ import type { InputForm, MethodFiles, MethodTreeSource, OutputForm, PipeIOContracts, RunResultExecute, RunResultStart } from "mthds/protocol";
12
+ import type { MethodTreeForm, NoMethodTree } from "./method-trees.js";
13
13
  export interface DictStuff {
14
14
  concept: string;
15
15
  content: unknown;
@@ -75,7 +75,7 @@ export interface PipelexRunResultStart extends RunResultStart {
75
75
  * The hosted tooling routes' own selector — the layer-3 extension the platform
76
76
  * adds on `POST /v1/validate`, `/v1/resolve`, `/v1/codegen`, and `/v1/pipe-io`: a stored
77
77
  * method's catalog id (`mt_…`), optionally naming a version, resolved server-side against
78
- * the org's catalog, the `.mthds` files of the version it names injected as inline source
78
+ * the org's catalog, the tree of the version it names injected as the method's `files`
79
79
  * before the runner sees the request. A bare `mt_…` names the latest published version,
80
80
  * `mt_…@<n>` version `n` and `mt_…@draft` the draft. A **pass-through to the hosted API**:
81
81
  * nothing is expanded client-side, and it is meaningless off-platform (a bare runner
@@ -97,11 +97,11 @@ export interface PipelexHostedToolingExtensions {
97
97
  method_id?: string;
98
98
  }
99
99
  /**
100
- * The method selector the tooling routes take in place of inline contents: a
100
+ * The method selector the tooling routes take in place of the method's tree: a
101
101
  * `method_ref` address (server-resolved by the runner through the same fetch
102
102
  * path as a `method_ref` run) OR a hosted `method_id` (platform-resolved) —
103
103
  * never both. The tooling routes are stateless, so the strict XOR applies:
104
- * exactly one of inline contents / `method_ref` / `method_id` per request.
104
+ * exactly one of the tree / `method_ref` / `method_id` per request.
105
105
  *
106
106
  * Lives here, beside the other wire shapes, rather than on the client: it is
107
107
  * the request's shape, and a module that composes a `validate` call of its own
@@ -115,6 +115,23 @@ export type ValidateMethodSelector = {
115
115
  method_id: string;
116
116
  method_ref?: never;
117
117
  };
118
+ /**
119
+ * What `validate()` judges: the method's tree, in exactly one of the four forms of
120
+ * `MethodTreeForm` (a `directory`, `contents`, a `tree` or the `files` map), or one of the two
121
+ * selectors of `ValidateMethodSelector`. Each arm pins the others to `never`, so naming two is a
122
+ * compile error; an untyped caller naming none, or more than one, is refused with a
123
+ * `RequestArgumentError` before any request, as the route itself would refuse a second selector
124
+ * with a `422`. At run time a `null` member, an empty `directory` and an empty selector string
125
+ * are absent, and a `files` map or `contents` holding no file is refused, as the MTHDS standard
126
+ * refuses a tree holding no file.
127
+ *
128
+ * It widens the protocol's own `ValidateSource` (`{ files }` or `{ tree }`) with the two forms
129
+ * this client lists or encodes itself and the two selectors the Pipelex API resolves.
130
+ */
131
+ export type PipelexValidateSource = (MethodTreeForm & {
132
+ method_ref?: never;
133
+ method_id?: never;
134
+ }) | (ValidateMethodSelector & NoMethodTree);
118
135
  /** Per-pipe dry-run verdict in `validated_pipes[]` — mirror of pipelex's `DryRunStatus`. */
119
136
  export type DryRunStatus = "SUCCESS" | "FAILURE" | "SKIPPED";
120
137
  /** One entry of `PipelexValidationReport.validated_pipes` — `{pipe_ref, status}`. */
@@ -139,6 +156,35 @@ export interface LiftablePipeEntry {
139
156
  /** Where the possible absence originates (human-readable). */
140
157
  absence_source: string;
141
158
  }
159
+ /**
160
+ * What a step reads a file of its method tree as — mirror of pipelex's `TreeFileUse`:
161
+ * `template`, the template a `PipeDocGen` step fills, named by its `template_file`;
162
+ * `template_asset`, an image, a stylesheet or a font that step's HTML template names by a
163
+ * literal relative URL, or that one of its stylesheets names; `python_module`, the module
164
+ * defining the function a `PipeFunc` step calls, named by the import path of its
165
+ * `function_name`.
166
+ *
167
+ * A report reads it open (see {@link TreeFileRead.use}): a runner of a later version may add
168
+ * a use as another kind of step comes to read files of its tree.
169
+ */
170
+ export type TreeFileUse = "template" | "template_asset" | "python_module";
171
+ /**
172
+ * One file of its method tree a step reads — mirror of pipelex's `TreeFileRead`, an entry of
173
+ * {@link PipelexValidationReport.tree_files_read}.
174
+ */
175
+ export interface TreeFileRead {
176
+ /**
177
+ * The file's path from the root of the method's tree, with forward slashes, such as
178
+ * `templates/invoice.html`, never a path on the server.
179
+ */
180
+ tree_path: string;
181
+ /**
182
+ * What the step reads the file as. Read open: `string & {}` keeps the editor's completion
183
+ * on the uses this SDK knows, and a consumer that switches on this field has to say what a
184
+ * use it does not know does.
185
+ */
186
+ use: TreeFileUse | (string & {});
187
+ }
142
188
  /**
143
189
  * Pipelex's `POST /v1/validate` 200 body for a VALID bundle — the canonical
144
190
  * `PipelexValidationReport`, carrying the `is_valid: true` discriminant of the
@@ -209,6 +255,27 @@ export interface PipelexValidationReport {
209
255
  output_form?: OutputForm;
210
256
  /** Pipes the runtime may skip when an optional slot resolves absent. */
211
257
  liftable_pipes: LiftablePipeEntry[];
258
+ /**
259
+ * Per step, the files of the method's tree it reads, keyed by namespaced `pipe_ref` over
260
+ * the same set as `pipe_io_contracts`, each file by its tree path with what the step reads
261
+ * it as. A `PipeDocGen` step reads its template and the images, stylesheets and fonts its
262
+ * HTML template names by literal relative URLs; a `PipeFunc` step reads the module of its
263
+ * function when that module is a file of the tree. A step that reads no file of the tree,
264
+ * a controller included, has an empty list. The paths come from what each step already
265
+ * names, so a client can show which step uses a file without parsing the method.
266
+ *
267
+ * OPTIONAL because a runner predating the field sends nothing: an absent field says the
268
+ * server did not report the reads, where an empty list says that step reads no file.
269
+ */
270
+ tree_files_read?: Record<string, TreeFileRead[]>;
271
+ /**
272
+ * The per-file view of `tree_files_read`: each tree path a step reads, in sorted order, to
273
+ * the namespaced refs of the steps that read it, each listed once. A file of the tree with
274
+ * no entry is read by no step: the bundles themselves, a README, a package's `__init__.py`
275
+ * beside its modules. Optional for the same reason as `tree_files_read`, and present
276
+ * whenever it is.
277
+ */
278
+ tree_file_readers?: Record<string, string[]>;
212
279
  /**
213
280
  * The qualified ref of the pipe a selector-less run of THIS request would execute —
214
281
  * the primary blueprint's declared `main_pipe` qualified by its domain and, for a
@@ -326,9 +393,8 @@ export type ValidationErrorCategory = "blueprint_validation" | "pipe_factory" |
326
393
  * not, so the same item arrives with explicit `null`s there. A truthiness check reads
327
394
  * both; an `=== undefined` check would be wrong on one of them.
328
395
  *
329
- * `source` is the declaring file path (CLI) or the per-content `mthds_sources` name
330
- * the API threads onto the in-memory load path — the owning file for cross-file
331
- * diagnostics.
396
+ * `source` is the declaring file: its path (CLI), or its tree path in the tree the
397
+ * request sent — the owning file for cross-file diagnostics.
332
398
  *
333
399
  * An `unknown_model` item (a model reference the runner's model deck does not know)
334
400
  * carries the reference as written, the kind of model the field takes and the close
@@ -514,50 +580,84 @@ export interface FormatResponse {
514
580
  diagnostics: Diagnostic[];
515
581
  }
516
582
  /**
517
- * One MTHDS file in a crate closure. `source` is an optional provenance label (a
518
- * filename, a URI) that the server threads onto every diagnostic it raises from
519
- * this file, so an invalid verdict can point at the file that caused it.
583
+ * The method every crate route takes — `/v1/resolve`, `/v1/codegen` and `/v1/pipe-io`
584
+ * (mirror of the runner's `MethodTreeRequest`).
520
585
  *
521
- * NOT the same type as `MthdsFile` (the one `validateFiles()` takes), which the
522
- * client adapts into `/v1/validate`'s parallel `mthds_contents` + `mthds_sources`
523
- * arrays: that route spells the label `uri`, this envelope spells it `source`. The
524
- * two collapse into one only if `/v1/validate` ever migrates onto `files[]` — a
525
- * protocol-level change owned by the MTHDS standard, not ours to make here.
526
- */
527
- export interface MthdsFileItem {
528
- content: string;
529
- source?: string;
530
- }
531
- /**
532
- * The closure selector every crate route shares — `/v1/resolve`, `/v1/codegen` and
533
- * `/v1/pipe-io` (mirror of the server's `MthdsFilesRequest`).
586
+ * Supply the method EITHER as its tree OR as a `method_ref` — never both, and never neither
587
+ * (both arms are a request-shape `422`); the hosted `method_id` joins them as a third form on
588
+ * each route's own request (see {@link PipelexHostedToolingExtensions}). The tree is the MTHDS
589
+ * protocol's map of file entries, keyed by tree path, given in exactly one of the four forms
590
+ * every route takes (`MethodTreeForms`):
534
591
  *
535
- * Supply the closure EITHER as inline `files` OR as a `method_ref` — never both, and
536
- * never neither (both arms are a request-shape `422`); the hosted `method_id` joins
537
- * them as a third form on each route's own request (see
538
- * {@link PipelexHostedToolingExtensions}). An **address-form** `method_ref`
539
- * (`github.com/<owner>/<repo>[/<selector>][@<tag>]`) is resolved by the server
540
- * (pipelex-api >= 0.21.0): the repository is fetched at the tag, the package is
541
- * located by manifest identity, and its `.mthds` files feed the closure with their
542
- * real relative paths as per-file sources. The **registry form** (any non-address
543
- * reference) stays reserved and answers `501` until a method registry exists.
592
+ * - `directory`, the method's directory on disk, listed by the `mthds` package's lister under
593
+ * the standard's membership rule and the deployment's limits (Node only);
594
+ * - `contents`, each file's bytes or text by tree path;
595
+ * - `tree`, a `MethodTreeSource`, such as the `MethodTree` the `mthds` package's
596
+ * `listMethodTree` returns;
597
+ * - `files`, the map itself, each value the file's text, `{ base64 }` or `{ sha256, size }` for
598
+ * bytes the runner already holds, sent as given.
544
599
  *
545
- * The XOR is a server-side invariant, not a type-level one: expressing it as a union
546
- * here would make the common `{ files }` call site pick a branch for no gain, and the
547
- * server rejects the illegal shapes with a typed `ApiResponseError` either way.
600
+ * The client sends a `directory`, `contents` or `tree` inline when its inline map weighs 256 KiB
601
+ * or less and no more than the inline limit the API announces, or whatever its weight when the
602
+ * API keeps no blob store, and otherwise every file by hash, after uploading the files the API
603
+ * lacks, exactly as `createMethod` sends one (see `docs/method-trees.md`). Every `.mthds` file of
604
+ * the tree is one of the method's bundles, named by its tree path in diagnostics and in the
605
+ * crate's `source_map`, and every other file is one a step may read, such as a `PipeDocGen`
606
+ * template.
548
607
  *
549
- * `resources` accompanies inline `files`: the files the closure's steps read, such as a
550
- * `PipeDocGen` step's `template_file`, keyed by the path the step names, each as its bytes,
551
- * which the client encodes into the wire's base64 map before posting (see
552
- * `docs/bundle-resources.md`). It is the one member the client does not post verbatim. Beside
553
- * a `method_ref` it is the server's `422`, a published method's files being its package's
554
- * own; a step whose template file was not sent makes the closure invalid.
608
+ * An **address-form** `method_ref` (`github.com/<owner>/<repo>[/<selector>][@<tag>]`) is
609
+ * resolved by the server (pipelex-api >= 0.21.0): the package's whole tree is fetched at the tag
610
+ * and read as a tree sent in `files` is. The **registry form** (any non-address reference) stays
611
+ * reserved and answers `501` until a method registry exists.
612
+ *
613
+ * The XOR is a server-side invariant, not a type-level one: expressing it as a union here would
614
+ * make the common `{ files }` call site pick a branch for no gain, and the server rejects the
615
+ * illegal shapes with a typed `ApiResponseError` either way. Two forms of the tree at once are
616
+ * the one shape the client refuses itself, with a `RequestArgumentError`, since it prepares the
617
+ * tree before posting. An empty map or string is absent, as in the Python SDK: `files: {}`,
618
+ * `files: null`, `contents: {}`, `directory: ""` and `dependencies: {}` select and send nothing,
619
+ * so an empty one beside another selector never reaches the wire as a second selector.
620
+ *
621
+ * `dependencies` accompanies the tree: the method packages it calls by address that the runner
622
+ * cannot fetch, each a map of file entries keyed by its address, sent as given. These routes load
623
+ * a package the method calls only from what was shipped with it, so a call into one nothing
624
+ * shipped is the invalid verdict.
625
+ *
626
+ * The files the closure's steps read, such as a `PipeDocGen` step's `template_file`, are files of
627
+ * the tree like any other, so a directory sends them with its bundles.
628
+ *
629
+ * `read_scope` is the Pipelex API's scope the request reads the method under: a hash entry of
630
+ * `files` resolves in that scope's blob store, else in the caller's own. A tree sent by hash asks
631
+ * `POST /v1/blobs/missing` under the same scope, so its blobs are uploaded into the store the
632
+ * request reads. **The hosted platform ignores it**: it stamps the caller's organization as the
633
+ * read scope of every crate request and drops the one the caller sent, so it only reaches a
634
+ * runner called directly.
555
635
  */
556
636
  export interface CrateRequestBase {
557
- files?: MthdsFileItem[];
637
+ /** The method's directory, listed by the standard's lister and sent as `tree` is. Node only. */
638
+ directory?: string | null;
639
+ /** The method's files, each one's bytes or text by tree path, sent as `tree` is. */
640
+ contents?: Readonly<Record<string, Uint8Array | string>> | null;
641
+ /** The method's tree as a listed source, sent inline when small and by hash otherwise. */
642
+ tree?: MethodTreeSource | null;
643
+ /** The method's tree as the protocol's map of file entries, sent as given. */
644
+ files?: MethodFiles | null;
645
+ /** The method packages the tree calls by address, each a map of file entries keyed by its address. */
646
+ dependencies?: Record<string, MethodFiles>;
558
647
  method_ref?: string;
559
- /** The files the closure's steps read, keyed by the path a step names, each as its bytes. */
560
- resources?: BundleResources | null;
648
+ /** The scope the runner reads the tree under; the hosted platform replaces it with the caller's organization. */
649
+ read_scope?: string;
650
+ }
651
+ /**
652
+ * What a crate route call — `resolve`, `codegen`, `pipeIo` — takes beside its request.
653
+ *
654
+ * `signal` is read between the steps a `tree` or `contents` costs before the request, and before
655
+ * the request itself: once it has aborted, no further file of the tree is read, neither the blob
656
+ * route nor an upload starts, and the route is not asked, and the call throws the abort. A request
657
+ * already sent runs to its end, as in `prepareInputs`, which passes its own `signal` here.
658
+ */
659
+ export interface CrateRouteOptions {
660
+ signal?: AbortSignal;
561
661
  }
562
662
  /**
563
663
  * The `is_valid: false` arm shared by every crate route — `/v1/resolve`,
@@ -578,7 +678,7 @@ export interface CrateInvalidReport {
578
678
  }
579
679
  /**
580
680
  * `POST /v1/resolve` request — the crate envelope (no projection axes) plus the
581
- * hosted `method_id` selector. Exactly one of `files` / `method_ref` /
681
+ * hosted `method_id` selector. Exactly one of the tree / `method_ref` /
582
682
  * `method_id` — the strict tooling XOR; see {@link PipelexHostedToolingExtensions}.
583
683
  */
584
684
  export type ResolveRequest = CrateRequestBase & PipelexHostedToolingExtensions;
@@ -626,7 +726,7 @@ export type CodegenKind = "types";
626
726
  export type CodegenTarget = "ts-zod" | "python-pydantic" | "python-structures";
627
727
  /**
628
728
  * `POST /v1/codegen` request — the crate envelope plus the two explicit projection
629
- * axes and the hosted `method_id` selector (exactly one of `files` / `method_ref` /
729
+ * axes and the hosted `method_id` selector (exactly one of the tree / `method_ref` /
630
730
  * `method_id`; see {@link PipelexHostedToolingExtensions}).
631
731
  */
632
732
  export interface CodegenRequest extends CrateRequestBase, PipelexHostedToolingExtensions {
@@ -677,7 +777,7 @@ export interface CodegenValidReport {
677
777
  export type CodegenResponse = CodegenValidReport | CrateInvalidReport;
678
778
  /**
679
779
  * `POST /v1/pipe-io` request — the crate envelope plus the hosted `method_id` selector
680
- * (exactly one of `files` / `method_ref` / `method_id`; see
780
+ * (exactly one of the tree / `method_ref` / `method_id`; see
681
781
  * {@link PipelexHostedToolingExtensions}), a pipe selector, and two opt-ins.
682
782
  *
683
783
  * There is no `views` field: the valid arm always carries all three artifacts.
@@ -685,8 +785,9 @@ export type CodegenResponse = CodegenValidReport | CrateInvalidReport;
685
785
  export interface PipeIORequest extends CrateRequestBase, PipelexHostedToolingExtensions {
686
786
  /**
687
787
  * The pipe to describe, as a QUALIFIED `domain.pipe_code` ref. Omit it and the
688
- * server's selection chain decides: a fetched package's manifest `main_pipe`, else
689
- * the closure's single `main_pipe` declaration. A selection the server refuses is a
788
+ * server's selection chain decides: the `main_pipe` of the `METHODS.toml` at the tree's
789
+ * root, whether the tree was sent or fetched, else the closure's single `main_pipe`
790
+ * declaration. A selection the server refuses is a
690
791
  * `422` typed by what went wrong, with `error_domain: "input"` and the candidates, where
691
792
  * there are some, in its `detail`: `EntryPipeNotFoundError` for a ref that names no pipe
692
793
  * or (without `all_pipes`) a method with no entry pipe, `EntryPipeAmbiguousError` for a
@@ -705,9 +806,9 @@ export interface PipeIORequest extends CrateRequestBase, PipelexHostedToolingExt
705
806
  */
706
807
  all_pipes?: boolean;
707
808
  /**
708
- * Echo the resolved closure's `.mthds` files on the valid arm as `files`, in the
709
- * request's own `files[]` shape. Defaults to `false` server-side, and the field is then
710
- * absent from the answer.
809
+ * Echo the text of the method's own `.mthds` bundles on the valid arm as `files`, keyed
810
+ * by tree path. Defaults to `false` server-side, and the field is then absent from the
811
+ * answer.
711
812
  */
712
813
  include_files?: boolean;
713
814
  }
@@ -739,7 +840,8 @@ export interface PipeIOValidReport {
739
840
  output_form: OutputForm;
740
841
  /**
741
842
  * The method's own entry pipe: the selection chain without the request's `pipe_ref` —
742
- * the fetched manifest's `main_pipe`, else the closure's single declaration. A request
843
+ * the `main_pipe` of the `METHODS.toml` at the tree's root, sent or fetched, else the
844
+ * closure's single declaration. A request
743
845
  * that omits `pipe_ref` always answers `pipe_ref === default_pipe_ref`. A stated `null`
744
846
  * when the chain finds none or several.
745
847
  *
@@ -752,12 +854,13 @@ export interface PipeIOValidReport {
752
854
  /** `pending_signatures` is empty, as on `validate`. No dry run backs it. */
753
855
  is_runnable: boolean;
754
856
  /**
755
- * The resolved closure's `.mthds` files, in the request's `files[]` shape. Present only
756
- * when the request passed `include_files: true`: the request's files for inline
757
- * `files`, the fetched package's `.mthds` files under their package-relative paths for
758
- * a `method_ref`, the stored files under their stored names for a hosted `method_id`.
857
+ * The text of each `.mthds` bundle of the method's own tree, keyed by its tree path.
858
+ * Present only when the request passed `include_files: true`: for a tree the request
859
+ * sent, its bundles, whatever entry form carried them; for a `method_ref`, the fetched
860
+ * package's, keyed by their path from the package root; for a hosted `method_id`, the
861
+ * stored tree's. The tree's other files and its dependencies' bundles are never included.
759
862
  */
760
- files?: MthdsFileItem[];
863
+ files?: Record<string, string>;
761
864
  }
762
865
  /** The `POST /v1/pipe-io` 200 response — pattern-match `is_valid` before reading the arm. */
763
866
  export type PipeIOResponse = PipeIOValidReport | CrateInvalidReport;
@@ -6,10 +6,10 @@
6
6
  * `pipelex-storage://` in `url`) plus one upload record per prepared asset.
7
7
  *
8
8
  * The method is named the same three ways every other method-taking operation
9
- * takes it — inline `files`, a `method_ref` address, or a stored `method_id` —
10
- * exactly one per call. All three are pass-throughs to `POST /v1/pipe-io`, which
11
- * resolves an address on the runner and an id on the platform, so nothing is
12
- * expanded client-side. The route also SELECTS the pipe: the caller's qualified
9
+ * takes it — its tree (a `directory`, `contents`, a listed `tree` or the `files`
10
+ * map), a `method_ref` address, or a stored `method_id` — exactly one per call.
11
+ * All three reach `POST /v1/pipe-io`: the tree as the `files` map `pipeIo` sends,
12
+ * an address resolved on the runner and an id on the platform. The route also SELECTS the pipe: the caller's qualified
13
13
  * `pipe_ref`, else the method's own entry pipe, and the ref it answers with is
14
14
  * the one prepared. It runs no dry run, so preparing inputs costs one static load.
15
15
  *
@@ -30,8 +30,9 @@
30
30
  * dict. See `docs/input-preparation.md`, which `pipelex-sdk-python` mirrors case
31
31
  * for case.
32
32
  */
33
- import type { BundleResources } from "./bundle-resources.js";
34
- import type { MthdsFileItem, PipeIORequest, PipeIOResponse } from "./models.js";
33
+ import type { MethodFiles } from "mthds/protocol";
34
+ import type { CrateRouteOptions, PipeIORequest, PipeIOResponse } from "./models.js";
35
+ import type { MethodTreeForm } from "./method-trees.js";
35
36
  import type { UploadCapableClient, UploadRecord } from "./upload.js";
36
37
  /** The shared half of the request: the target pipe and the caller's inputs. */
37
38
  export interface PrepareInputsBase {
@@ -50,7 +51,9 @@ export interface PrepareInputsBase {
50
51
  /**
51
52
  * Stops the preparation between its steps, a file's read and its upload included: once it has
52
53
  * aborted, neither the pipe I/O request nor any upload starts, and `prepareInputs` throws the
53
- * abort. A request already sent runs to its end. It is not sent to the server.
54
+ * abort. A `tree` or `contents` sent by hash counts its steps too — the version handshake, the
55
+ * blob route, each read and upload of a missing blob — so an abort during the handshake starts
56
+ * none of the rest. A request already sent runs to its end. It is not sent to the server.
54
57
  */
55
58
  signal?: AbortSignal;
56
59
  /**
@@ -63,35 +66,48 @@ export interface PrepareInputsBase {
63
66
  */
64
67
  allowUploads?: boolean;
65
68
  }
69
+ /**
70
+ * The method's tree, in exactly one of the forms `pipeIo` takes it (see `CrateRequestBase`):
71
+ * `directory`, the method's directory on disk, listed by the `mthds` package's lister (Node only);
72
+ * `contents`, each file's bytes or text by tree path; `tree`, a listed source such as the
73
+ * `MethodTree` the `mthds` package's `listMethodTree` returns; or `files`, the protocol's map of
74
+ * file entries, sent as given. The client sends a `directory`, `contents` or `tree` inline when
75
+ * small and by hash otherwise.
76
+ */
77
+ export type PrepareInputsTree = MethodTreeForm;
78
+ /** What a published or stored method cannot carry: its tree is its own. */
79
+ interface NoTree {
80
+ directory?: never;
81
+ contents?: never;
82
+ tree?: never;
83
+ files?: never;
84
+ dependencies?: never;
85
+ }
66
86
  /**
67
87
  * How the method is named — exactly one of the three selectors, each pinning the
68
88
  * other two to `never` so a second one is a compile error (the same XOR
69
89
  * `ValidateMethodSelector` states for `validate`). All three reach the
70
- * server as-is: `files` inline, `method_ref` resolved by the runner, `method_id`
71
- * resolved by the platform.
90
+ * server: the tree as the `files` map, `method_ref` resolved by the runner,
91
+ * `method_id` resolved by the platform.
72
92
  *
73
- * Inline `files` may bring `resources`, the files the closure's steps read, such
74
- * as a `PipeDocGen` step's `template_file`, keyed by the path the step names, each
75
- * as its bytes: the pipe I/O route loads the closure, and a step whose template file
76
- * was not sent makes it fail to load. A published or stored method's files are its
77
- * own, so the other two selectors take none.
93
+ * The tree may bring `dependencies`, the method packages it calls by address, each a
94
+ * map of file entries keyed by its address. The files the closure's steps read, such as a
95
+ * `PipeDocGen` step's `template_file`, are files of the tree like any other. The pipe I/O
96
+ * route loads the closure, and a step whose template file is not in the tree, or a call
97
+ * into a package nothing shipped, makes it fail to load. A published or stored method's
98
+ * tree and packages are its own, so the other two selectors take no `dependencies`.
78
99
  */
79
- export type PrepareInputsClosure = {
80
- files: MthdsFileItem[];
81
- resources?: BundleResources | null;
100
+ export type PrepareInputsClosure = (PrepareInputsTree & {
101
+ dependencies?: Record<string, MethodFiles>;
82
102
  method_ref?: never;
83
103
  method_id?: never;
84
- } | {
104
+ }) | (NoTree & {
85
105
  method_ref: string;
86
- files?: never;
87
106
  method_id?: never;
88
- resources?: never;
89
- } | {
107
+ }) | (NoTree & {
90
108
  method_id: string;
91
- files?: never;
92
109
  method_ref?: never;
93
- resources?: never;
94
- };
110
+ });
95
111
  /** What `prepareInputs` takes: one method selector, the target pipe, the caller's inputs. */
96
112
  export type PrepareInputsRequest = PrepareInputsBase & PrepareInputsClosure;
97
113
  /** The result of `prepareInputs`: rewritten inputs (copy-on-write) plus upload records. */
@@ -107,7 +123,7 @@ export interface PreparedInputs {
107
123
  * `PipelexApiClient` satisfies it structurally.
108
124
  */
109
125
  export interface PrepareCapableClient extends UploadCapableClient {
110
- pipeIo(request: PipeIORequest): Promise<PipeIOResponse>;
126
+ pipeIo(request: PipeIORequest, options?: CrateRouteOptions): Promise<PipeIOResponse>;
111
127
  }
112
128
  /**
113
129
  * Where an input-form entry breaks the shape `prepareInputs` reads, and what was
@@ -147,8 +163,10 @@ export declare function inputFormFault(entry: unknown): InputFormFault | undefin
147
163
  * that would need either throws {@link UploadNotAllowedError}, naming them too.
148
164
  *
149
165
  * The pipe and its signature come from one `POST /v1/pipe-io`, whatever the
150
- * selector — inline `files`, a `method_ref` the runner resolves, or a
151
- * `method_id` the platform resolves. A bare or alias-qualified `pipe_ref`, a
166
+ * selector — the method's tree, a `method_ref` the runner resolves, or a
167
+ * `method_id` the platform resolves. A `tree` or `contents` too large to send
168
+ * inline goes by hash, and a blob that fails to upload throws
169
+ * `MethodFileTransferError` before the route is asked. A bare or alias-qualified `pipe_ref`, a
152
170
  * closure that does not load, and a selection the route refuses (an unknown
153
171
  * `pipe_ref`, no entry pipe, several) throw {@link InputPreparationError}. So
154
172
  * does an answer that breaks the route's contract, with a `runtime` verdict that
@@ -160,3 +178,4 @@ export declare function inputFormFault(entry: unknown): InputFormFault | undefin
160
178
  * the route) surfaces as `ApiResponseError`, unchanged.
161
179
  */
162
180
  export declare function prepareInputs(client: PrepareCapableClient, request: PrepareInputsRequest): Promise<PreparedInputs>;
181
+ export {};