@pipelex/sdk 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,15 @@ if (report.is_valid) {
36
36
  // also rides `pipe_output` on the blocking path).
37
37
  console.log(result.main_stuff);
38
38
  }
39
+
40
+ // Or run a published method by address — resolved server-side (fetch at tag,
41
+ // commit SHA recorded as provenance on the start ack). Requires pipelex-api >= 0.21.0;
42
+ // on api.pipelex.com, availability follows the platform deploy that forwards it.
43
+ const ack = await client.start({
44
+ method_ref: "github.com/Pipelex/methods/documents@v0.1.0",
45
+ inputs: { document: { url: "https://example.com/report.pdf" } },
46
+ });
47
+ console.log(ack.method_provenance); // { address, tag, commit_sha }
39
48
  ```
40
49
 
41
50
  ### Product routes
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { MTHDSProtocol, ModelCategory, ModelDeck, RunOptions, RunResultStart, StartOptions, VersionInfo } from "mthds/protocol";
2
- import type { BuildInputsRequest, BuildInputsResponse, BuildOutputRequest, BuildOutputResponse, BuildRunnerRequest, BuildRunnerResponse, CodegenRequest, CodegenResponse, ConceptRequest, ConceptResponse, DictPipeOutput, FormatResponse, InputsTemplateFormat, LintResponse, MthdsFileItem, PipeSpecRequest, PipeSpecResponse, PipelexValidationResult, ResolveRequest, ResolveResponse } from "./models.js";
1
+ import type { MTHDSProtocol, ModelCategory, ModelDeck, RunOptions, StartOptions, VersionInfo } from "mthds/protocol";
2
+ import type { BuildInputsRequest, BuildInputsResponse, BuildOutputRequest, BuildOutputResponse, BuildRunnerRequest, BuildRunnerResponse, CodegenRequest, CodegenResponse, ConceptRequest, ConceptResponse, DictPipeOutput, FormatResponse, LintResponse, MthdsFileItem, PipeSpecRequest, PipeSpecResponse, PipelexRunResultStart, PipelexValidationResult, ResolveRequest, ResolveResponse, ValidateMethodSelector } from "./models.js";
3
3
  import { type RunRead, type RunResults, type RunResultState, type WaitForResultOptions } from "./runs.js";
4
4
  import type { BillingPortalResponse, ChangePlanResponse, CheckoutResponse, GatewayApiKey, GatewayApiKeyStatus, InvoiceView, Membership, MembershipsResponse, ListMethodsQuery, MethodData, MethodDeletionAccepted, MethodPage, MethodSummary, MethodWriteInput, OnboardingSubmission, PipelexApiKeyCreated, PipelexApiKeyList, ListRunsQuery, PipelineRun, RunDetail, RunPage, PlanView, ResolvedStorageUrl, SubscriptionResponse, UpdateRunInput, UploadInput, UploadedFile, UserProfile } from "./product-models.js";
5
5
  import type { UploadableAsset, UploadFileOptions, UploadRecord } from "./upload.js";
@@ -11,6 +11,37 @@ export interface MthdsFile {
11
11
  /** Optional provenance URI threaded into validation diagnostics. */
12
12
  uri?: string;
13
13
  }
14
+ /**
15
+ * The Pipelex API's own run-source extension — the layer-2 argument the RUNNER
16
+ * itself resolves, beside the protocol's inline sources (`mthds_contents` and
17
+ * the bundle encodings). Served by any pipelex-api >= 0.21.0 deployment, bare
18
+ * or hosted (on `api.pipelex.com`, once the platform deploy carrying it lands).
19
+ *
20
+ * Named options rather than `extra` entries, for the same reason as the hosted
21
+ * extensions below: `extra` remains the escape hatch for an extension this
22
+ * client does not know about, never the way to pass one it does.
23
+ */
24
+ export interface PipelexApiRunExtensions {
25
+ /**
26
+ * A published method's address — `github.com/<owner>/<repo>[/<selector>][@<tag>]`
27
+ * (e.g. `github.com/Pipelex/methods/documents@v0.1.0`). Resolved by the
28
+ * server: the repository is fetched at the tag (a bare address means the
29
+ * default branch at HEAD), the package is located by manifest identity, and
30
+ * the resolved commit SHA comes back as `method_provenance` on the response.
31
+ *
32
+ * A complete run source of its own — the fetched package carries its `.mthds`
33
+ * and its entry pipe — so it pairs with NOTHING: exclusive with inline
34
+ * `mthds_contents`, with a method bundle (`files` / `bundle_b64`), and with
35
+ * the hosted `method_id` (an address run has its own provenance and needs no
36
+ * linkage id). `pipe_code` beside it is fine — it overrides the manifest's
37
+ * `main_pipe` to pick which pipe in the fetched package to run. This client
38
+ * rejects the illegal pairings before anything hits the wire, mirroring the
39
+ * server's own 422s.
40
+ *
41
+ * An empty string is treated as absent and is not sent.
42
+ */
43
+ method_ref?: string | null;
44
+ }
14
45
  /**
15
46
  * The hosted API's own run arguments — the layer-3 extensions this client adds
16
47
  * on top of the MTHDS Protocol's run-argument surface (`RunOptions` /
@@ -38,40 +69,30 @@ export interface PipelexHostedRunExtensions {
38
69
  * **run-history linkage** on the Run row. That linkage is what writes the
39
70
  * index key `GET /v1/runs?method_id=` queries, so a run started without it
40
71
  * is absent from its method's history permanently.
72
+ * - **Alongside `method_ref`** — rejected client-side (and a 422 on the
73
+ * hosted API): an address run carries its own provenance, so it takes no
74
+ * linkage id.
41
75
  *
42
76
  * An empty string is treated as absent and is not sent.
43
77
  */
44
78
  method_id?: string | null;
45
79
  }
46
- /** `execute()` options — the protocol's run arguments plus the hosted extensions. */
47
- export type PipelexRunOptions = RunOptions & PipelexHostedRunExtensions;
80
+ /** `execute()` options — the protocol's run arguments plus the Pipelex API and hosted extensions. */
81
+ export type PipelexRunOptions = RunOptions & PipelexApiRunExtensions & PipelexHostedRunExtensions;
48
82
  /** `start()` / `startAndWaitForResult()` options — the same, for the durable path. */
49
- export type PipelexStartOptions = StartOptions & PipelexHostedRunExtensions;
83
+ export type PipelexStartOptions = StartOptions & PipelexApiRunExtensions & PipelexHostedRunExtensions;
50
84
  /**
51
- * The by-id alternative to the wire model `BuildInputsRequest`: resolve the
52
- * closure from a stored method's `method_id` instead of inline `files`.
53
- *
54
- * Client-side sugar — `method_id` is resolved to `files` via `getMethodClosure`
55
- * before the request hits the wire, so it never travels as a wire field (and is
56
- * distinct from `BuildRequestBase.method_ref`, the reserved registry ref). Supply
57
- * a `method_id` OR inline `files`, never both.
85
+ * The method selector `validate()` takes in place of inline contents — declared
86
+ * beside the other wire shapes in `./models.js` and re-exported here, the import
87
+ * path consumers have always used.
58
88
  */
59
- export interface BuildInputsByMethodId {
60
- /** A stored method's id — resolved client-side to its closure before the build call. Requires an API key. */
61
- method_id: string;
62
- files?: never;
63
- method_ref?: never;
64
- /** The pipe to project, as a qualified `domain.pipe_code`; omit to default to the closure's `main_pipe`. */
65
- pipe_ref?: string;
66
- format?: InputsTemplateFormat;
67
- explicit?: boolean;
68
- }
89
+ export type { ValidateMethodSelector };
69
90
  export interface ValidateFilesOptions {
70
91
  /** Whether unresolved pipe signatures are accepted as pending instead of invalid. */
71
92
  allowSignatures?: boolean;
72
93
  /** Optional validate presentation hints, e.g. ["markdown"]. */
73
94
  render?: string[];
74
- /** Optional structured-view opt-in tokens, e.g. ["input_form"]; sent only when given. */
95
+ /** Optional structured-view opt-in tokens, e.g. ["input_form", "output_form"]; sent only when given. */
75
96
  views?: string[];
76
97
  /** Per-call request ceiling; defaults to the 20-min execute ceiling. */
77
98
  timeoutMs?: number;
@@ -159,14 +180,17 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
159
180
  /**
160
181
  * Start a method asynchronously — `POST /v1/start` (202, no output yet).
161
182
  *
162
- * The hosted `method_id` is a named option (see `PipelexHostedRunExtensions`);
163
- * `options.extra` stays the generic passthrough for extension args this client
164
- * does not know about — the server you call defines and handles them
165
- * (including a client-supplied run id where a server supports one). The
166
- * returned `pipeline_run_id` is always authoritative; on a hosted deployment
167
- * it is durable — poll `getRunStatus` / `getRunResult`.
183
+ * The `method_ref` address and the hosted `method_id` are named options (see
184
+ * `PipelexApiRunExtensions` / `PipelexHostedRunExtensions`); `options.extra`
185
+ * stays the generic passthrough for extension args this client does not know
186
+ * about — the server you call defines and handles them (including a
187
+ * client-supplied run id where a server supports one). The returned
188
+ * `pipeline_run_id` is always authoritative; on a hosted deployment it is
189
+ * durable — poll `getRunStatus` / `getRunResult`. A `method_ref` run's ack
190
+ * additionally carries `method_provenance` — the address, the tag, and the
191
+ * commit SHA that was actually fetched.
168
192
  */
169
- start(options: PipelexStartOptions): Promise<RunResultStart>;
193
+ start(options: PipelexStartOptions): Promise<PipelexRunResultStart>;
170
194
  /**
171
195
  * Parse, validate, and dry-run an MTHDS bundle — `POST /v1/validate`.
172
196
  *
@@ -178,11 +202,32 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
178
202
  * *no-verdict* condition (a malformed request, an `mthds_sources` length mismatch,
179
203
  * auth, a server fault) is non-2xx and surfaces as `ApiResponseError`.
180
204
  *
181
- * `mthdsSources` (optional, parallel to `mthdsContents`) names each submitted
205
+ * `source` selects WHAT is validated, in exactly one of three forms — the
206
+ * strict tooling XOR (the routes are stateless, so there is no linkage
207
+ * exception; a second selector is a request-shape `422`):
208
+ *
209
+ * - **inline contents** (a `string[]`) — the protocol's own envelope;
210
+ * - **`{ method_ref }`** — a published method's address, resolved by the
211
+ * server (pipelex-api >= 0.21.0) through the same fetch path as a
212
+ * `method_ref` run, the package's real file names feeding the diagnostics'
213
+ * source labels;
214
+ * - **`{ method_id }`** — a stored method's catalog id, hosted-only: the
215
+ * platform resolves it and injects the stored source before the runner sees
216
+ * the request (a bare runner rejects the request as carrying no source it
217
+ * understands).
218
+ *
219
+ * A selector-resolution failure (fetch failure, no package at the address, an
220
+ * unknown or foreign-org id) is a non-2xx `ApiResponseError` — never an
221
+ * `is_valid: false` verdict, which is reserved for actual MTHDS content.
222
+ *
223
+ * `mthdsSources` (optional, parallel to inline contents) names each submitted
182
224
  * content — a Pipelex-API extension threaded onto `blueprint.source`, so
183
225
  * cross-file diagnostics name the owning file (an unnamed content yields
184
226
  * `source: null`). The server 422s a length mismatch; this client sends the
185
- * arrays verbatim and surfaces that as an `ApiResponseError`.
227
+ * arrays verbatim and surfaces that as an `ApiResponseError`. It is an
228
+ * inline-contents companion only: a `method_ref` / `method_id` validation gets
229
+ * its source labels from the package's (or the stored method's) real file
230
+ * names, so supplying it beside a selector is rejected client-side.
186
231
  *
187
232
  * `render` is the Pipelex-API presentation hint — a list of view-format tokens.
188
233
  * This client always asks for Markdown so both valid results and produced
@@ -192,7 +237,7 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
192
237
  * `views` is the sibling opt-in for *structured* views where `render` carries
193
238
  * *rendered text*. The two lists are independent, each resolving its own tokens
194
239
  * against its own supported set, and each supported token adds a same-named
195
- * top-level field to the valid arm — today only `input_form`. Unlike `render`,
240
+ * top-level field to the valid arm — `input_form` and `output_form`. Unlike `render`,
196
241
  * this client sends `views` ONLY when the caller asks: the point of an opt-in view
197
242
  * is that the default response stays byte-identical, and the highest-frequency
198
243
  * consumers (hook pipelines, CI gates, agent loops) never pay for bytes they
@@ -200,8 +245,17 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
200
245
  * runner resolved no token (the key is silently ignored, never a 422) and emitted
201
246
  * the field regardless — which is why `PipelexValidationReport.input_form` is typed
202
247
  * optional rather than required.
248
+ *
249
+ * A `{ method_ref }` source makes the server clone a repository before it
250
+ * validates anything, and it needs no special budget here: this route already
251
+ * defaults to the 20-minute execute ceiling, which clears the internal
252
+ * fetch-sized budget (`METHOD_REF_FETCH_TIMEOUT_MS`, three minutes) that
253
+ * `crateRequestTimeoutMs` gives the crate routes several times over. That budget
254
+ * exists to RAISE routes whose default is the ~30s poll ceiling; applying it here
255
+ * would lower this one — which is why `buildRunner`, on its own five-minute
256
+ * default, is excluded from it for the same reason.
203
257
  */
204
- validate(mthdsContents: string[], allowSignatures?: boolean, mthdsSources?: string[], render?: string[], views?: string[], options?: {
258
+ validate(source: string[] | ValidateMethodSelector, allowSignatures?: boolean, mthdsSources?: string[], render?: string[], views?: string[], options?: {
205
259
  timeoutMs?: number;
206
260
  signal?: AbortSignal;
207
261
  }): Promise<PipelexValidationResult>;
@@ -251,7 +305,8 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
251
305
  * The mapping is what makes their no-verdict arms usable: a crate-family route
252
306
  * answers `422` for a request it cannot act on (an unresolvable pipe selector on the
253
307
  * build routes; an unknown `kind`/`target`, or a `pipe_ref` on the concept-set-wide
254
- * `types` kind, on `codegen`) and `501` for the reserved `method_ref`. A caller
308
+ * `types` kind, on `codegen`) and `501` for the reserved registry-form `method_ref`
309
+ * (the address form is resolved server-side as of pipelex-api 0.21.0). A caller
255
310
  * branches on `ApiResponseError.status`, never on a message.
256
311
  *
257
312
  * All of these are inference-free, so they default to the management-call timeout.
@@ -298,10 +353,15 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
298
353
  * Returns a **200 verdict**: pattern-match `is_valid` before reading the arm — a
299
354
  * closure that does not parse/load/validate comes back as `is_valid: false` with
300
355
  * `validation_errors[]`, not as a thrown error. Only a no-verdict condition throws
301
- * `ApiResponseError`: a malformed selector (neither or both of `files`/`method_ref`)
302
- * is a 422, and the reserved `method_ref` is a `501` until the server-side method
303
- * registry lands. To resolve a STORED method today, expand it first:
304
- * `resolve({ files: await client.getMethodClosure(methodId) })`.
356
+ * `ApiResponseError`: a malformed selector (none, or more than one, of
357
+ * `files` / `method_ref` / `method_id`) is a 422; a selector-resolution failure
358
+ * (fetch failure, no package at the address, an unknown or foreign-org id) is
359
+ * non-2xx too — never an `is_valid: false` verdict.
360
+ *
361
+ * The closure arrives in exactly one of three forms: inline `files`, an
362
+ * address-form `method_ref` (server-resolved, pipelex-api >= 0.21.0; the
363
+ * registry form stays a `501`), or a hosted `method_id` (platform-resolved —
364
+ * see {@link PipelexHostedToolingExtensions}).
305
365
  */
306
366
  resolve(request: ResolveRequest): Promise<ResolveResponse>;
307
367
  /**
@@ -314,9 +374,10 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
314
374
  * local `pipelex codegen types` run, so the offline `pipelex codegen check` passes on
315
375
  * it; the SDK deliberately does not write files for you.
316
376
  *
317
- * Same 200-verdict discipline as {@link resolve}. Only a no-verdict condition throws
318
- * `ApiResponseError`: an unknown `kind`/`target`, a `pipe_ref` on the concept-set-wide
319
- * `types` kind, or a malformed selector is a 422; `method_ref` is a `501`.
377
+ * Same 200-verdict discipline and same three-form closure selector as
378
+ * {@link resolve}. Only a no-verdict condition throws `ApiResponseError`: an
379
+ * unknown `kind`/`target`, a `pipe_ref` on the concept-set-wide `types` kind, or
380
+ * a malformed selector is a 422; a registry-form `method_ref` is a `501`.
320
381
  */
321
382
  codegen(request: CodegenRequest): Promise<CodegenResponse>;
322
383
  /**
@@ -331,14 +392,22 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
331
392
  * unresolvable closure comes back as `is_valid: false` with `validation_errors[]`,
332
393
  * not as a thrown error.
333
394
  *
334
- * Accepts the closure as inline `files` (the wire model {@link BuildInputsRequest}),
335
- * as a reserved `method_ref` (also on {@link BuildInputsRequest} — still `501`s,
336
- * same as `buildOutput`/`buildRunner`), or as a stored {@link BuildInputsByMethodId}
337
- * — the by-id form is resolved to `files` via {@link getMethodClosure} before the
338
- * request hits the wire (an empty source throws `EmptyMethodSourceError`; an
339
- * unknown/foreign id, the `getMethod` 404). Supply exactly one of the three.
395
+ * Accepts the closure as inline `files` or as a `method_ref` (both on the wire
396
+ * model {@link BuildInputsRequest}; the address form is server-resolved, the
397
+ * registry form `501`s) — exactly one of the two, like `buildOutput` /
398
+ * `buildRunner`. There is NO by-id form: the build routes take no `method_id`
399
+ * (the hosted tooling selector covers `validate`/`resolve`/`codegen` only), so a
400
+ * stored method is expanded first — `buildInputs({ files: await
401
+ * client.getMethodClosure(methodId) })`. That expansion stays the answer here
402
+ * because a `buildInputs` caller wants this route's template; it is not what
403
+ * `prepareInputs` does any more.
404
+ *
405
+ * Nothing inside this SDK calls this route: `prepareInputs` reads its signature
406
+ * from the input-form descriptor on the validate report. It survives for the
407
+ * consumers that still render a template over HTTP, and is retired with the rest
408
+ * of `/v1/build/*` once they project it client-side.
340
409
  */
341
- buildInputs(request: BuildInputsRequest | BuildInputsByMethodId): Promise<BuildInputsResponse>;
410
+ buildInputs(request: BuildInputsRequest): Promise<BuildInputsResponse>;
342
411
  /**
343
412
  * Project a pipe's output concept — `POST /v1/build/output`. Same envelope and
344
413
  * same 200-verdict discipline as {@link buildInputs}. `format: "schema"` (the
@@ -463,6 +532,13 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
463
532
  * with `methodSourceToContents`, and labels each resulting file with the
464
533
  * `method_id` as its `source` provenance.
465
534
  *
535
+ * This is the LOCAL expansion utility — for callers that want the files in
536
+ * hand (to edit, to diff, to feed a route with no by-id form, the `/v1/build/*`
537
+ * family being the last of those). The operations that accept `method_id`
538
+ * natively (`execute`/`start`, `validate`/`resolve`/`codegen`, and
539
+ * `prepareInputs`, which composes a `validate` of its own) take the id as a
540
+ * pass-through instead; nothing in this client expands an id behind your back.
541
+ *
466
542
  * Requires an API key: the methods catalog is org-scoped to the key's org, so
467
543
  * an unknown OR foreign-org id is a `getMethod` `404` (`ApiResponseError`
468
544
  * `not_found`), which propagates unchanged. A real, in-org method whose source
@@ -573,10 +649,20 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
573
649
  * file-bearing assets, and return copy-on-write rewritten inputs (canonical
574
650
  * content carrying `pipelex-storage://` in `url`) plus one upload record per
575
651
  * prepared asset. HTTP(S) URLs and existing `pipelex-storage://` URIs pass
576
- * through unchanged; all failures are raised before any run is created. The
577
- * caller supplies the method closure EITHER as inline `files` OR as a stored
578
- * `method_id` (resolved to its closure via `getMethodClosure` first; requires
579
- * an API key). See `docs/input-preparation.md`.
652
+ * through unchanged; all failures are raised before any run is created.
653
+ *
654
+ * Name the method exactly one of three ways, all server-resolved through the
655
+ * one `validate` call this composes:
656
+ *
657
+ * - `files` — the inline MTHDS closure;
658
+ * - `method_ref` — a published method's address, fetched by the runner;
659
+ * - `method_id` — a stored method's catalog id, resolved by the platform
660
+ * (hosted only; requires an API key).
661
+ *
662
+ * The signature itself is the input-form descriptor on the validate report
663
+ * (`views: ["input_form", "output_form"]`), which states the kind of every input at every
664
+ * depth — so a file position is a fact of the method, never a guess from the
665
+ * value's shape. See `docs/input-preparation.md`.
580
666
  */
581
667
  prepareInputs(request: PrepareInputsRequest): Promise<PreparedInputs>;
582
668
  /**
@@ -633,12 +719,14 @@ export declare class PipelexApiClient implements MTHDSProtocol<DictPipeOutput> {
633
719
  updateRun(runId: string, input: UpdateRunInput): Promise<void>;
634
720
  /**
635
721
  * Blocking `POST /v1/execute` adapted onto `RunResults` — the bare-runner
636
- * path. Forwards every protocol field PLUS both extension surfaces: the
637
- * hosted `method_id` and the generic `extra` passthrough. An extension-only
638
- * call (`{ extra }` with no pipe_code/bundle) or a vendor selector riding
639
- * `extra` must survive this path, not just the durable one — and a hosted
640
- * `method_id` must reach the server here too, so a runner that cannot resolve
641
- * it says so (Rule 4) instead of the client silently dropping it.
722
+ * path. Forwards every protocol field PLUS every extension surface: the
723
+ * runner-resolved `method_ref`, the hosted `method_id`, and the generic
724
+ * `extra` passthrough. An extension-only call (`{ extra }` with no
725
+ * pipe_code/bundle) or a vendor selector riding `extra` must survive this
726
+ * path, not just the durable one — a `method_ref` run must run the same
727
+ * fetched package here, and a hosted `method_id` must reach the server too,
728
+ * so a runner that cannot resolve it says so (Rule 4) instead of the client
729
+ * silently dropping it.
642
730
  */
643
731
  private executeBlocking;
644
732
  }