@pipelex/sdk 0.67.0 → 0.69.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/dist/client.js CHANGED
@@ -5,17 +5,18 @@ import { assertOneMethodSource, buildProblem, isProblem, parseJsonBody, readProb
5
5
  import { LAYOUT_INPUT_MEMBERS, PROVENANCE_INPUT_MEMBERS, methodLayoutFault, readMethodLayout, readMethodLayouts, } from "./method-layouts.js";
6
6
  import { methodShowcaseDetailFault, methodShowcaseFreezeFault, readMethodShowcaseSummaries, } from "./method-showcases.js";
7
7
  import { assertArtifactSelection, assertWaitOptions, pollUntilResult, readRunDegradation, RUN_STATUSES, runProgressFault, runStatusFilter, selectionIncludesMainStuff, throwIfAborted, withCheckedProgressHealth, } from "./runs.js";
8
- import { ABORT_TIMEOUT, ApiResponseError, argumentInvalidProblem, ApiUnreachableError, MissingMainStuffError, PagingNotTerminatingError, PipelineExecuteTimeoutError, ProblemError, RequestArgumentError, RunLifecycleUnavailableError, RunStillRunningError, } from "./errors.js";
8
+ import { ABORT_TIMEOUT, ApiResponseError, argumentInvalidProblem, ApiUnreachableError, MissingMainStuffError, PagingNotTerminatingError, PipelineExecuteTimeoutError, ProblemError, RequestArgumentError, RunLifecycleUnavailableError, RunStillRunningError, StoredTextLoadError, } from "./errors.js";
9
9
  import { isPlainObject } from "./records.js";
10
10
  import { readProblemItems } from "./problem-items.js";
11
11
  import { outcomeUnknownProblem, readHostedAnswer, runIdNamedBy } from "./answer-reading.js";
12
- import { HANDSHAKE_TTL_MS, INLINE_TREE_MAX_BYTES, MAX_CONCURRENT_TRANSFERS, REQUEST_SENDING, SAVE_SENDING, announcedTreeLimits, contentsTreeSource, declaresBlobStore, eitherSignal, emptyTreeRefusal, fileByBlob, forEachConcurrently, hashMethodFiles, inlineFilesOf, inlineMapBytes, inlineThreshold, isMethodTreeTooLarge, listDirectoryTree, listerLimitsOf, missingBlobsOf, presentMap, readTreeBytesInto, redactSignedLinks, sha256Hex, treeShapeFault, treeListerFor, treeTotalSize, uniqueBlobs, uploadBlob, writeMethodTreeTo, } from "./method-trees.js";
12
+ import { HANDSHAKE_TTL_MS, INLINE_TREE_MAX_BYTES, MAX_CONCURRENT_TRANSFERS, REQUEST_SENDING, SAVE_SENDING, announcedTreeLimits, contentsTreeSource, declaresBlobStore, emptyTreeRefusal, fileByBlob, forEachConcurrently, hashMethodFiles, inlineFilesOf, inlineMapBytes, inlineThreshold, isMethodTreeTooLarge, listDirectoryTree, listerLimitsOf, missingBlobsOf, presentMap, readTreeBytesInto, redactSignedLinks, sha256Hex, treeShapeFault, treeListerFor, treeTotalSize, uniqueBlobs, uploadBlob, writeMethodTreeTo, } from "./method-trees.js";
13
13
  import { buildUserAgent } from "./user-agent.js";
14
14
  import { uploadFile as uploadFileImpl } from "./upload.js";
15
15
  import { prepareInputs as prepareInputsImpl } from "./prepare-inputs.js";
16
- import { downloadArtifacts as downloadArtifactsImpl, fetchArtifact as fetchArtifactImpl, resolveArtifacts as resolveArtifactsImpl, } from "./artifacts.js";
16
+ import { carriesConceptArtifacts, downloadArtifacts as downloadArtifactsImpl, fetchArtifact as fetchArtifactImpl, loadStoredTexts as loadStoredTextsImpl, mayHoldStoredTexts, resolveArtifacts as resolveArtifactsImpl, withConceptArtifacts, } from "./artifacts.js";
17
17
  import { PipelexExecuteResult, resultsFromExecute } from "./execute-result.js";
18
18
  import { ExactJsonUnsupportedError, parseExactJson, stringifyExactJson } from "./exact-json.js";
19
+ import { eitherSignal } from "./signals.js";
19
20
  import { MAX_TIMER_DELAY_MS, isTimerDelay } from "./timers.js";
20
21
  // A pure RUNAWAY guard on the paged-list iterators (`iterateMethods`,
21
22
  // `iterateRuns`, `iterateMethodExamples`, `iterateFiles`), deliberately not a coverage limit.
@@ -23,7 +24,7 @@ import { MAX_TIMER_DELAY_MS, isTimerDelay } from "./timers.js";
23
24
  // It counts TOTAL pages, not empty ones. An earlier version capped consecutive
24
25
  // empty pages, which is the wrong axis: an empty page whose cursor ADVANCED is
25
26
  // real progress through the index — the platform applies the list filters
26
- // (`q` and `published` on methods, `createdBy` and `status` on runs) after a
27
+ // (`q`, `published` and `createdBy` on methods, `createdBy` and `status` on runs) after a
27
28
  // bounded read per request, so a sparse match legitimately yields runs of
28
29
  // empty pages — and capping them turns a valid sparse search into a thrown
29
30
  // error. The stuck case is already caught by the no-progress check (the
@@ -1785,16 +1786,48 @@ export class PipelexApiClient {
1785
1786
  if (selectionIncludesMainStuff(options.artifacts) && result.main_stuff == null) {
1786
1787
  throw new MissingMainStuffError(`Completed run '${runId}' returned no main stuff — a completed run always delivers a main stuff.`, runId);
1787
1788
  }
1788
- return { state: "completed", pipeline_run_id: runId, result };
1789
+ if (options.loadStoredTexts === false || !selectionIncludesMainStuff(options.artifacts)) {
1790
+ return { state: "completed", pipeline_run_id: runId, result };
1791
+ }
1792
+ const loaded = await this.withStoredTextsLoaded(result, options.artifacts, options.signal);
1793
+ return { state: "completed", pipeline_run_id: runId, result: loaded };
1794
+ }
1795
+ /**
1796
+ * A completed result with the stored texts of its `main_stuff` loaded, as the result readers
1797
+ * hand it back by default (`loadStoredTexts`); only `main_stuff` changes in the result handed
1798
+ * back. A read that carried the concepts is walked by them at once, which costs no request when
1799
+ * nothing is stored. A read whose `selection` left them out reads the working memory and the
1800
+ * forms again by the run's id only when `main_stuff` holds a value shaped like a stored text's
1801
+ * reference ({@link mayHoldStoredTexts}), so a narrowed read of images and documents stays one
1802
+ * request.
1803
+ */
1804
+ async withStoredTextsLoaded(result, selection, signal) {
1805
+ if (result.main_stuff == null)
1806
+ return result;
1807
+ if (!carriesConceptArtifacts(selection) && !mayHoldStoredTexts(result.main_stuff)) {
1808
+ return result;
1809
+ }
1810
+ const source = await withConceptArtifacts(this, result, selection, signal);
1811
+ const loaded = await loadStoredTextsImpl(this, { ...result, ...source }, {
1812
+ signal,
1813
+ });
1814
+ return loaded.main_stuff === result.main_stuff
1815
+ ? result
1816
+ : { ...result, main_stuff: loaded.main_stuff };
1789
1817
  }
1790
1818
  /**
1791
1819
  * Poll an already-started run (by id) until it reaches a terminal state. With `onProgress`,
1792
1820
  * each poll that finds the run still running also reads `getRunProgress` and hands the callback
1793
1821
  * every snapshot fresher than the last it delivered; a failed progress read never fails the wait
1794
- * (see `WaitForResultOptions.onProgress`).
1822
+ * (see `WaitForResultOptions.onProgress`). `timeoutMs` bounds the whole wait, the load of the
1823
+ * completed result's stored texts included: a run that completed but whose texts did not load
1824
+ * in the time left throws `RunTimeoutError` saying so.
1795
1825
  */
1796
1826
  async waitForResult(runId, options) {
1797
- return pollUntilResult((id, opts) => this.getRunResult(id, opts), runId, options, (id, opts) => this.getRunProgress(id, opts));
1827
+ const selection = options?.artifacts;
1828
+ return pollUntilResult((id, opts) => this.getRunResult(id, opts), runId, options, (id, opts) => this.getRunProgress(id, opts), options?.loadStoredTexts === false || !selectionIncludesMainStuff(selection)
1829
+ ? undefined
1830
+ : (result, opts) => this.withStoredTextsLoaded(result, selection, opts.signal));
1798
1831
  }
1799
1832
  /**
1800
1833
  * Whether the configured server serves the durable run lifecycle, decided
@@ -1908,14 +1941,14 @@ export class PipelexApiClient {
1908
1941
  this.lifecycleAvailable = false;
1909
1942
  throwIfAborted(signal);
1910
1943
  onStarting?.();
1911
- return this.executeBlocking(options, signal, sending);
1944
+ return this.executeBlocking(options, signal, sending, waitOptions.loadStoredTexts);
1912
1945
  }
1913
1946
  onStarted?.(ack);
1914
1947
  return this.waitForResult(ack.pipeline_run_id, waitOptions);
1915
1948
  }
1916
1949
  throwIfAborted(signal);
1917
1950
  onStarting?.();
1918
- return this.executeBlocking(options, signal, sending);
1951
+ return this.executeBlocking(options, signal, sending, waitOptions.loadStoredTexts);
1919
1952
  }
1920
1953
  /**
1921
1954
  * A run's tree prepared once for `startAndWaitForResult`, under `call`'s refusals: the run's
@@ -1955,16 +1988,19 @@ export class PipelexApiClient {
1955
1988
  * Rows are `MethodSummary`: no `mthds`, no `python`, no `updated_at`. Reach
1956
1989
  * for `getMethod(id)` when you need a method's source.
1957
1990
  *
1958
- * `q` is applied server-side over the whole catalog, not over the page, and so is
1991
+ * `q` is applied server-side over the whole catalog, not over the page, and so are
1959
1992
  * `published` (`true` for the methods with a published version, `false` for those never
1960
- * published). Each row carries the method's publish state (`latest_version`,
1961
- * `latest_published`, `draft_digest`). Both filters run after the index read, so a page can
1962
- * come back empty and still carry a `nextCursor`: keep following it until it is `null`.
1993
+ * published) and `createdBy` (`"me"` for the caller's own methods, or a member's user id, sent
1994
+ * as `created_by`); the three combine. Each row carries the method's publish state
1995
+ * (`latest_version`, `latest_published`, `draft_digest`) and who created it
1996
+ * (`created_by_user_id`). The filters run after the index read, so a page can come back empty
1997
+ * and still carry a `nextCursor`: keep following it until it is `null`.
1963
1998
  */
1964
1999
  async listMethods(query = {}) {
1965
2000
  const search = productQuery({
1966
2001
  q: query.q,
1967
2002
  published: query.published,
2003
+ created_by: query.createdBy,
1968
2004
  limit: query.limit,
1969
2005
  cursor: query.cursor,
1970
2006
  });
@@ -1989,9 +2025,11 @@ export class PipelexApiClient {
1989
2025
  * remove. If you truly want an array, `Array.fromAsync` makes that your
1990
2026
  * explicit choice.
1991
2027
  *
1992
- * It keeps going **through an empty page that carries a cursor**: under `q` or `published`
1993
- * such a page means "nothing matched in the slice just read", not "done". It stops on a
1994
- * `null` cursor or on a cursor the server failed to advance, and throws
2028
+ * Takes the query `listMethods` takes, the cursor aside, and sends it with every page.
2029
+ *
2030
+ * It keeps going **through an empty page that carries a cursor**: under `q`, `published` or
2031
+ * `createdBy` such a page means "nothing matched in the slice just read", not "done". It stops
2032
+ * on a `null` cursor or on a cursor the server failed to advance, and throws
1995
2033
  * `PagingNotTerminatingError` past a page ceiling no real catalog reaches.
1996
2034
  */
1997
2035
  async *iterateMethods(query = {}) {
@@ -3855,9 +3893,9 @@ export class PipelexApiClient {
3855
3893
  * file got a verdict. A linked file carries its `url`, a presigned `GET` valid for fifteen
3856
3894
  * minutes, with its `expires_at`, the `name` the download saves under and its `media_type`, and
3857
3895
  * a `null` `error`. A file that got no link carries `error`, `{ code, detail }`, and `null` link
3858
- * members: `not_found` for an unknown file id, `conflict` for a file whose upload has not
3859
- * finished, `invalid_storage_uri` for a malformed address and `forbidden` for another
3860
- * organization's.
3896
+ * members: the platform's registry codes, `request.invalid` naming `file_id` or `uri` for an
3897
+ * unknown file or one whose upload has not finished, `pipelex.storage.uri_invalid` for a malformed
3898
+ * address and `pipelex.org.mismatch` for another organization's.
3861
3899
  *
3862
3900
  * Each link is signed with a `Content-Disposition` naming the file, so a download saves under
3863
3901
  * the name a person sees rather than the bytes' hash. It opens in place (`inline`) for an image,
@@ -4350,7 +4388,7 @@ export class PipelexApiClient {
4350
4388
  * so a runner that cannot resolve it says so (Rule 4) instead of the client
4351
4389
  * silently dropping it.
4352
4390
  */
4353
- async executeBlocking(options, signal, sending) {
4391
+ async executeBlocking(options, signal, sending, loadStoredTexts) {
4354
4392
  const response = await this.executeRun({
4355
4393
  pipe_code: options.pipe_code ?? undefined,
4356
4394
  inputs: options.inputs ?? undefined,
@@ -4370,7 +4408,26 @@ export class PipelexApiClient {
4370
4408
  method_id: options.method_id ?? undefined,
4371
4409
  extra: options.extra ?? undefined,
4372
4410
  }, signal, sending);
4373
- return resultsFromExecute(response);
4411
+ const results = resultsFromExecute(response);
4412
+ if (loadStoredTexts === false)
4413
+ return results;
4414
+ // The blocking answer carries the working memory and the forms, so nothing is read again.
4415
+ try {
4416
+ return await this.withStoredTextsLoaded(results, undefined, signal);
4417
+ }
4418
+ catch (err) {
4419
+ if (!(err instanceof StoredTextLoadError))
4420
+ throw err;
4421
+ // The answer is the only copy of a completed run, and a bare runner serves no bulk resolve
4422
+ // route: the error carries the result.
4423
+ throw new StoredTextLoadError(err.message, {
4424
+ uri: err.uri,
4425
+ path: err.path,
4426
+ reason: err.reason,
4427
+ status: err.status,
4428
+ wireResults: results,
4429
+ }, { cause: err.cause, problem: err.problem });
4430
+ }
4374
4431
  }
4375
4432
  }
4376
4433
  // ── Module helpers ────────────────────────────────────────────────────