@pipelex/sdk 0.69.5 → 0.71.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/artifacts.d.ts +46 -23
- package/dist/artifacts.js +89 -35
- package/dist/artifacts.js.map +1 -1
- package/dist/cli/script.d.ts +1 -1
- package/dist/client.d.ts +41 -5
- package/dist/client.js +91 -12
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +38 -16
- package/dist/errors.js +43 -16
- package/dist/errors.js.map +1 -1
- package/dist/hooks/claude-mthds-check.d.ts +2 -1
- package/dist/hooks/claude-mthds-check.js +5 -6
- package/dist/hooks/claude-mthds-check.js.map +1 -1
- package/dist/hooks/format-write.d.ts +67 -0
- package/dist/hooks/format-write.js +175 -0
- package/dist/hooks/format-write.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/product-models.d.ts +61 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/architecture.md +3 -3
- package/docs/artifact-download.md +10 -10
- package/docs/errors.md +2 -2
- package/docs/files.md +41 -1
- package/docs/hook-bundle.md +13 -1
- package/docs/run-results.md +8 -6
- package/package.json +1 -1
package/dist/artifacts.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - {@link locateArtifacts} — a pure walk of any JSON value for the strings that
|
|
6
6
|
* ARE `pipelex-storage://` references, each with every path it sits at.
|
|
7
7
|
* {@link collectArtifacts} is the same walk's bare references. No network, no key.
|
|
8
|
-
* - {@link resolveArtifacts} — the
|
|
8
|
+
* - {@link resolveArtifacts} — the server's bulk resolve route over a whole
|
|
9
9
|
* list, chunked at the route's bound, one verdict per reference.
|
|
10
10
|
* - {@link fetchArtifact} — a bounded `Response` for one reference: resolved
|
|
11
11
|
* fresh, timed out, redirects refused, the byte cap enforced mid-stream, no
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
* A produced file is never embedded in a run's results: the content carries its
|
|
17
17
|
* durable `pipelex-storage://` reference beside a signed `public_url` that expires
|
|
18
18
|
* on the provider's schedule. Nothing here reads that embedded link — every link
|
|
19
|
-
* is minted fresh by the
|
|
20
|
-
*
|
|
19
|
+
* is minted fresh by the server's bulk resolve route (the hosted platform's presigned
|
|
20
|
+
* link, or a self-hosted runner's own signed link), and re-minted when it has expired
|
|
21
|
+
* by the time a worker reaches it. See `docs/artifact-download.md`.
|
|
21
22
|
*
|
|
22
23
|
* `node:fs/promises`, `node:path` and `undici` come from the Node host
|
|
23
24
|
* (`node-host.ts`), which a bundler building for the browser resolves to a module
|
|
@@ -33,7 +34,8 @@ import type { ConceptSource, StoredTextKind } from "./stored-texts.js";
|
|
|
33
34
|
export declare const PIPELEX_STORAGE_SCHEME = "pipelex-storage://";
|
|
34
35
|
/**
|
|
35
36
|
* How many references one bulk resolve request takes — the route's bound, fixed
|
|
36
|
-
* by the
|
|
37
|
+
* by the route's contract, the same on the platform and a self-hosted runner,
|
|
38
|
+
* rather than configured per deployment. A longer list
|
|
37
39
|
* is a `422`, so {@link resolveArtifacts} chunks at this size.
|
|
38
40
|
*/
|
|
39
41
|
export declare const BULK_RESOLVE_MAX_URIS = 100;
|
|
@@ -51,14 +53,17 @@ export declare const DEFAULT_DOWNLOAD_MAX_TOTAL_BYTES: number;
|
|
|
51
53
|
export declare const DEFAULT_DOWNLOAD_CONCURRENCY = 4;
|
|
52
54
|
/**
|
|
53
55
|
* Why one reference failed — a value, never a thrown error. `code` is the
|
|
54
|
-
* resolve route's own per-reference code (`pipelex.storage.uri_invalid`, `pipelex.org.mismatch
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* resolve route's own per-reference code (`pipelex.storage.uri_invalid`, `pipelex.org.mismatch`,
|
|
57
|
+
* and a self-hosted runner's `auth.forbidden` whose `requirement` is `read_scope_under_caller` for
|
|
58
|
+
* a reference outside the caller's scope) or one of the fetch boundary's (see `ArtifactFetchError`),
|
|
59
|
+
* plus the download's own `resolve_failed`, `total_limit_exceeded`, `write_failed` and `aborted`.
|
|
60
|
+
* `detail` is the sentence a person reads, and `params` the parameters the route's code declares,
|
|
61
|
+
* when the route sent them.
|
|
58
62
|
*/
|
|
59
63
|
export interface ArtifactItemError {
|
|
60
64
|
code: string;
|
|
61
65
|
detail: string;
|
|
66
|
+
params?: Record<string, unknown> | null;
|
|
62
67
|
}
|
|
63
68
|
/**
|
|
64
69
|
* One reference's resolution — the bulk resolve route's item, verbatim. Either
|
|
@@ -69,11 +74,15 @@ export interface ArtifactItemError {
|
|
|
69
74
|
export type ResolvedArtifact = {
|
|
70
75
|
/** The reference exactly as sent. */
|
|
71
76
|
uri: string;
|
|
72
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* A short-lived signed link, fetchable now and until `expires_at`, whose lifetime the server
|
|
79
|
+
* sets: the hosted platform's presigned link lasts about fifteen minutes, and a self-hosted
|
|
80
|
+
* runner's link to its own download route lasts its `STORAGE_LINK_TTL_SECONDS`.
|
|
81
|
+
*/
|
|
73
82
|
url: string;
|
|
74
83
|
/** UTC expiry of the link, ISO 8601. */
|
|
75
84
|
expires_at: string;
|
|
76
|
-
/** The
|
|
85
|
+
/** The server's content-type guess from the reference's extension; null when it has none. */
|
|
77
86
|
content_type: string | null;
|
|
78
87
|
error: null;
|
|
79
88
|
} | {
|
|
@@ -101,9 +110,12 @@ export interface FetchArtifactOptions {
|
|
|
101
110
|
*/
|
|
102
111
|
timeoutMs?: number;
|
|
103
112
|
/**
|
|
104
|
-
* Accept a plain `http:` link. Off by default: a general-purpose
|
|
105
|
-
* not fetch over plain http silently.
|
|
106
|
-
*
|
|
113
|
+
* Accept a plain `http:` link on any origin. Off by default: a general-purpose
|
|
114
|
+
* library does not fetch over plain http silently. A plain `http:` link on the
|
|
115
|
+
* origin of the client's configured base URL, which a self-hosted runner hands
|
|
116
|
+
* out, is accepted without it, since the client already sends its API key
|
|
117
|
+
* there. The local compose stack's object store hands out plain `http:` links
|
|
118
|
+
* on another origin, which is the case this opts into.
|
|
107
119
|
*/
|
|
108
120
|
allowHttp?: boolean;
|
|
109
121
|
/** Cancels the fetch; a body being read is cancelled too. */
|
|
@@ -190,7 +202,7 @@ export type DownloadedKind = "file" | "text";
|
|
|
190
202
|
* One reference's outcome in a download verdict — one shape with nullable fields,
|
|
191
203
|
* like {@link ResolvedArtifact}: either `path` and `size` are set and `error` is
|
|
192
204
|
* null, or `error` is set and both are null. `found_at` says where the reference
|
|
193
|
-
* sits in the walked scope, and `content_type` is the
|
|
205
|
+
* sits in the walked scope, and `content_type` is the server's guess from the
|
|
194
206
|
* reference's extension, known before the fetch; both are on both arms, so an
|
|
195
207
|
* item that was not saved still says which field it would have filled.
|
|
196
208
|
*/
|
|
@@ -234,11 +246,18 @@ export interface DownloadArtifactsResult {
|
|
|
234
246
|
aborted?: true;
|
|
235
247
|
}
|
|
236
248
|
/**
|
|
237
|
-
* The client surface the artifact operations need: the raw bulk resolve call
|
|
238
|
-
*
|
|
239
|
-
* `PipelexApiClient` satisfies it structurally, and so
|
|
249
|
+
* The client surface the artifact operations need: the raw bulk resolve call, the
|
|
250
|
+
* single-shot result lookup and the origin the client is configured with. Typed as
|
|
251
|
+
* the client's own members so `PipelexApiClient` satisfies it structurally, and so
|
|
252
|
+
* tests inject a fake.
|
|
240
253
|
*/
|
|
241
254
|
export interface ArtifactCapableClient {
|
|
255
|
+
/**
|
|
256
|
+
* The origin (`scheme://host[:port]`) of the client's configured base URL. A
|
|
257
|
+
* resolved link on it is fetched over plain http without `allowHttp`, since the
|
|
258
|
+
* client already sends its API key there.
|
|
259
|
+
*/
|
|
260
|
+
readonly originUrl: string;
|
|
242
261
|
resolveStorageUrls(input: BulkResolveStorageUrlsInput, options?: {
|
|
243
262
|
signal?: AbortSignal;
|
|
244
263
|
}): Promise<BulkResolvedStorageUrls>;
|
|
@@ -293,7 +312,7 @@ export declare function locateStoredReferences(value: unknown, node?: InputFormI
|
|
|
293
312
|
export declare function isStorageReference(value: string): boolean;
|
|
294
313
|
/**
|
|
295
314
|
* A `url` a stored text may be loaded from: a `pipelex-storage://` reference, resolved through the
|
|
296
|
-
*
|
|
315
|
+
* server's bulk route to a link it signs, or a `data:` URL, decoded where it is. A stored text at
|
|
297
316
|
* any other URL is never fetched, so a method cannot have the SDK read a host the caller did not
|
|
298
317
|
* choose: the loader refuses it as `unsupported_url`.
|
|
299
318
|
*
|
|
@@ -350,7 +369,7 @@ export declare function resolveArtifacts(client: Pick<ArtifactCapableClient, "re
|
|
|
350
369
|
}): Promise<ResolvedArtifact[]>;
|
|
351
370
|
/**
|
|
352
371
|
* A bounded `Response` for one reference: the link is minted fresh through the
|
|
353
|
-
* bulk route, then fetched with `redirect: "manual"` (a
|
|
372
|
+
* bulk route, then fetched with `redirect: "manual"` (a signed link has no
|
|
354
373
|
* reason to redirect, and one that does is refused rather than followed), no
|
|
355
374
|
* headers of ours (the link carries its own authorization in the query string,
|
|
356
375
|
* and nothing must ride along to the object store), a budget covering the
|
|
@@ -369,7 +388,7 @@ export declare function resolveArtifacts(client: Pick<ArtifactCapableClient, "re
|
|
|
369
388
|
* caller's abort propagates as-is. Whole-request failures of the resolve step
|
|
370
389
|
* propagate unchanged (`ApiResponseError`, `ApiUnreachableError`).
|
|
371
390
|
*/
|
|
372
|
-
export declare function fetchArtifact(client: Pick<ArtifactCapableClient, "resolveStorageUrls">, uri: string, options?: FetchArtifactOptions): Promise<Response>;
|
|
391
|
+
export declare function fetchArtifact(client: Pick<ArtifactCapableClient, "resolveStorageUrls" | "originUrl">, uri: string, options?: FetchArtifactOptions): Promise<Response>;
|
|
373
392
|
/**
|
|
374
393
|
* The cap on one stored text's bytes: the runtime's own cap on what it reads from storage, so a
|
|
375
394
|
* text the runtime could read is never one the SDK refuses.
|
|
@@ -404,7 +423,11 @@ export interface LoadStoredTextsOptions {
|
|
|
404
423
|
maxTotalBytes?: number;
|
|
405
424
|
/** Budget for each text's exchange — connect, headers and body. Default 120 s. */
|
|
406
425
|
timeoutMs?: number;
|
|
407
|
-
/**
|
|
426
|
+
/**
|
|
427
|
+
* Accept a plain `http:` link on any origin, as the local stack's object store hands out. Off
|
|
428
|
+
* by default; a plain `http:` link on the origin of the client's configured base URL is
|
|
429
|
+
* accepted without it.
|
|
430
|
+
*/
|
|
408
431
|
allowHttp?: boolean;
|
|
409
432
|
/** How many texts are read at once. Default 8. */
|
|
410
433
|
concurrency?: number;
|
|
@@ -428,7 +451,7 @@ export interface LoadStoredTextsOptions {
|
|
|
428
451
|
* `main_stuff`, so a read can land in between: `waitForResult` keeps polling through that window
|
|
429
452
|
* for a few polls before it throws.
|
|
430
453
|
*
|
|
431
|
-
* A `pipelex-storage://` reference is resolved through the
|
|
454
|
+
* A `pipelex-storage://` reference is resolved through the server's bulk route, at most
|
|
432
455
|
* {@link BULK_RESOLVE_MAX_URIS} per request, and its signed link fetched under the same bounds as
|
|
433
456
|
* `fetchArtifact`; a link within ten seconds of its `expires_at` when its read is about to start,
|
|
434
457
|
* having waited behind the other reads, is resolved again first. A `data:` URL is decoded, its
|
|
@@ -449,7 +472,7 @@ export interface LoadStoredTextsOptions {
|
|
|
449
472
|
* route's error as its `cause`), the load's total over `maxTotalBytes` as
|
|
450
473
|
* `total_limit_exceeded`, and lets the caller's abort through.
|
|
451
474
|
*/
|
|
452
|
-
export declare function loadStoredTexts(client: Pick<ArtifactCapableClient, "resolveStorageUrls">, results: RunResults, options?: LoadStoredTextsOptions): Promise<RunResults>;
|
|
475
|
+
export declare function loadStoredTexts(client: Pick<ArtifactCapableClient, "resolveStorageUrls" | "originUrl">, results: RunResults, options?: LoadStoredTextsOptions): Promise<RunResults>;
|
|
453
476
|
/**
|
|
454
477
|
* The concept facts of a run's results: the results themselves when their read carried the
|
|
455
478
|
* working memory and the forms (`selection` undefined reads every artifact), else those three
|
package/dist/artifacts.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - {@link locateArtifacts} — a pure walk of any JSON value for the strings that
|
|
6
6
|
* ARE `pipelex-storage://` references, each with every path it sits at.
|
|
7
7
|
* {@link collectArtifacts} is the same walk's bare references. No network, no key.
|
|
8
|
-
* - {@link resolveArtifacts} — the
|
|
8
|
+
* - {@link resolveArtifacts} — the server's bulk resolve route over a whole
|
|
9
9
|
* list, chunked at the route's bound, one verdict per reference.
|
|
10
10
|
* - {@link fetchArtifact} — a bounded `Response` for one reference: resolved
|
|
11
11
|
* fresh, timed out, redirects refused, the byte cap enforced mid-stream, no
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
* A produced file is never embedded in a run's results: the content carries its
|
|
17
17
|
* durable `pipelex-storage://` reference beside a signed `public_url` that expires
|
|
18
18
|
* on the provider's schedule. Nothing here reads that embedded link — every link
|
|
19
|
-
* is minted fresh by the
|
|
20
|
-
*
|
|
19
|
+
* is minted fresh by the server's bulk resolve route (the hosted platform's presigned
|
|
20
|
+
* link, or a self-hosted runner's own signed link), and re-minted when it has expired
|
|
21
|
+
* by the time a worker reaches it. See `docs/artifact-download.md`.
|
|
21
22
|
*
|
|
22
23
|
* `node:fs/promises`, `node:path` and `undici` come from the Node host
|
|
23
24
|
* (`node-host.ts`), which a bundler building for the browser resolves to a module
|
|
@@ -39,7 +40,8 @@ import { parseExactJson } from "./exact-json.js";
|
|
|
39
40
|
export const PIPELEX_STORAGE_SCHEME = "pipelex-storage://";
|
|
40
41
|
/**
|
|
41
42
|
* How many references one bulk resolve request takes — the route's bound, fixed
|
|
42
|
-
* by the
|
|
43
|
+
* by the route's contract, the same on the platform and a self-hosted runner,
|
|
44
|
+
* rather than configured per deployment. A longer list
|
|
43
45
|
* is a `422`, so {@link resolveArtifacts} chunks at this size.
|
|
44
46
|
*/
|
|
45
47
|
export const BULK_RESOLVE_MAX_URIS = 100;
|
|
@@ -57,9 +59,9 @@ export const DEFAULT_DOWNLOAD_MAX_TOTAL_BYTES = 4 * 1024 * 1024 * 1024;
|
|
|
57
59
|
export const DEFAULT_DOWNLOAD_CONCURRENCY = 4;
|
|
58
60
|
/**
|
|
59
61
|
* A link this close to its `expires_at` is re-resolved rather than fetched: the
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
62
|
+
* store checks the signature when the request arrives, and a few seconds of
|
|
63
|
+
* clock skew between the server that signed it and this process must not turn a
|
|
64
|
+
* link the server still considers live into a `403`.
|
|
63
65
|
*/
|
|
64
66
|
const EXPIRY_MARGIN_MS = 10_000;
|
|
65
67
|
/** Longest filename `downloadArtifacts` writes, extension included. */
|
|
@@ -112,6 +114,11 @@ const TEXT_EXTENSION_BY_KIND = {
|
|
|
112
114
|
html: ".html",
|
|
113
115
|
json: ".json",
|
|
114
116
|
};
|
|
117
|
+
/** The `requirement` a resolve route's refusal names in its `params`, when it names one. */
|
|
118
|
+
function refusalRequirement(error) {
|
|
119
|
+
const requirement = error.params?.requirement;
|
|
120
|
+
return typeof requirement === "string" ? requirement : undefined;
|
|
121
|
+
}
|
|
115
122
|
/** An object key rendered as `.key` in a path; any other key is rendered as `["…"]`. */
|
|
116
123
|
const IDENTIFIER_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
117
124
|
/**
|
|
@@ -300,7 +307,7 @@ export function isStorageReference(value) {
|
|
|
300
307
|
}
|
|
301
308
|
/**
|
|
302
309
|
* A `url` a stored text may be loaded from: a `pipelex-storage://` reference, resolved through the
|
|
303
|
-
*
|
|
310
|
+
* server's bulk route to a link it signs, or a `data:` URL, decoded where it is. A stored text at
|
|
304
311
|
* any other URL is never fetched, so a method cannot have the SDK read a host the caller did not
|
|
305
312
|
* choose: the loader refuses it as `unsupported_url`.
|
|
306
313
|
*
|
|
@@ -486,7 +493,7 @@ export async function resolveArtifacts(client, uris, options = {}) {
|
|
|
486
493
|
// ── fetchArtifact ────────────────────────────────────────────────────
|
|
487
494
|
/**
|
|
488
495
|
* A bounded `Response` for one reference: the link is minted fresh through the
|
|
489
|
-
* bulk route, then fetched with `redirect: "manual"` (a
|
|
496
|
+
* bulk route, then fetched with `redirect: "manual"` (a signed link has no
|
|
490
497
|
* reason to redirect, and one that does is refused rather than followed), no
|
|
491
498
|
* headers of ours (the link carries its own authorization in the query string,
|
|
492
499
|
* and nothing must ride along to the object store), a budget covering the
|
|
@@ -506,17 +513,23 @@ export async function resolveArtifacts(client, uris, options = {}) {
|
|
|
506
513
|
* propagate unchanged (`ApiResponseError`, `ApiUnreachableError`).
|
|
507
514
|
*/
|
|
508
515
|
export async function fetchArtifact(client, uri, options = {}) {
|
|
509
|
-
const bounds = fetchBounds(options);
|
|
516
|
+
const bounds = fetchBounds(options, client.originUrl);
|
|
510
517
|
const [resolved] = await resolveArtifacts(client, [uri], { signal: options.signal });
|
|
511
518
|
if (resolved.error !== null) {
|
|
512
|
-
throw new ArtifactFetchError(resolved.error.detail, uri, resolved.error.code
|
|
519
|
+
throw new ArtifactFetchError(resolved.error.detail, uri, resolved.error.code, undefined, {
|
|
520
|
+
requirement: refusalRequirement(resolved.error),
|
|
521
|
+
});
|
|
513
522
|
}
|
|
514
523
|
const dispatcher = await dispatcherFor(bounds.timeoutMs);
|
|
515
524
|
return fetchResolvedUrl(uri, resolved.url, bounds, dispatcher, () => {
|
|
516
525
|
void dispatcher?.close().catch(() => undefined);
|
|
517
526
|
});
|
|
518
527
|
}
|
|
519
|
-
|
|
528
|
+
/**
|
|
529
|
+
* The bounds, defaults filled in and validated. `originUrl` is the client's own
|
|
530
|
+
* origin, the one on which a plain-http link is fetched without `allowHttp`.
|
|
531
|
+
*/
|
|
532
|
+
function fetchBounds(options, originUrl) {
|
|
520
533
|
const maxBytes = options.maxBytes ?? DEFAULT_ARTIFACT_MAX_BYTES;
|
|
521
534
|
const timeoutMs = options.timeoutMs ?? DEFAULT_ARTIFACT_TIMEOUT_MS;
|
|
522
535
|
requirePositive("maxBytes", maxBytes);
|
|
@@ -525,7 +538,34 @@ function fetchBounds(options) {
|
|
|
525
538
|
throw new ArtifactOperationError(`"timeoutMs" must be a positive number no larger than ${MAX_TIMER_DELAY_MS}, got ` +
|
|
526
539
|
`${String(timeoutMs)}.`, { problem: argumentInvalidProblem("timeoutMs", "not_positive") });
|
|
527
540
|
}
|
|
528
|
-
return {
|
|
541
|
+
return {
|
|
542
|
+
maxBytes,
|
|
543
|
+
timeoutMs,
|
|
544
|
+
allowHttp: options.allowHttp ?? false,
|
|
545
|
+
clientOrigin: originOf(originUrl),
|
|
546
|
+
signal: options.signal,
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* The origin of an http(s) URL as compared: the WHATWG serialization, which
|
|
551
|
+
* lowercases the scheme and the host, encodes an internationalized name as IDNA,
|
|
552
|
+
* rewrites an IPv4 or IPv6 address in its canonical form (`127.1` is
|
|
553
|
+
* `127.0.0.1`) and drops a default port, so `http://localhost` and
|
|
554
|
+
* `http://LOCALHOST:80/` are one origin. Null for anything else, which then
|
|
555
|
+
* matches nothing. A name is never resolved: `127.0.0.1` and `localhost` are two
|
|
556
|
+
* origins.
|
|
557
|
+
*/
|
|
558
|
+
function originOf(value) {
|
|
559
|
+
let url;
|
|
560
|
+
try {
|
|
561
|
+
url = new URL(value);
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
567
|
+
return null;
|
|
568
|
+
return url.origin;
|
|
529
569
|
}
|
|
530
570
|
function requirePositive(name, value) {
|
|
531
571
|
if (!Number.isFinite(value) || value <= 0) {
|
|
@@ -554,25 +594,35 @@ async function dispatcherFor(timeoutMs) {
|
|
|
554
594
|
return null;
|
|
555
595
|
}
|
|
556
596
|
}
|
|
557
|
-
/**
|
|
558
|
-
|
|
597
|
+
/**
|
|
598
|
+
* The parsed, boundary-approved URL — the object the fetch then uses verbatim. A
|
|
599
|
+
* plain-http link is fetched when the caller opted in with `allowHttp`, or when its
|
|
600
|
+
* origin is `clientOrigin`, the origin of the client's configured base URL: the
|
|
601
|
+
* client already sends its API key there, so a link to it reveals nothing the
|
|
602
|
+
* client does not already trust that server with. That is how a self-hosted runner
|
|
603
|
+
* listening on plain http hands back what it stores.
|
|
604
|
+
*/
|
|
605
|
+
function checkUrl(uri, downloadUrl, allowHttp, clientOrigin) {
|
|
559
606
|
let url;
|
|
560
607
|
try {
|
|
561
608
|
url = new URL(downloadUrl);
|
|
562
609
|
}
|
|
563
610
|
catch {
|
|
564
|
-
throw new ArtifactFetchError("The
|
|
611
|
+
throw new ArtifactFetchError("The server resolved the reference to a link that is not a valid absolute URL.", uri, "unsupported_url");
|
|
565
612
|
}
|
|
566
|
-
if (url.protocol === "http:" &&
|
|
567
|
-
|
|
568
|
-
|
|
613
|
+
if (url.protocol === "http:" &&
|
|
614
|
+
!allowHttp &&
|
|
615
|
+
(clientOrigin === null || url.origin !== clientOrigin)) {
|
|
616
|
+
throw new ArtifactFetchError("The server resolved the reference to a plain http link on an origin other than the " +
|
|
617
|
+
"client's own, which is refused by default; pass allowHttp: true to accept it (the local " +
|
|
618
|
+
"stack's object store hands out such links).", uri, "plain_http_refused");
|
|
569
619
|
}
|
|
570
620
|
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
571
|
-
throw new ArtifactFetchError(`The
|
|
621
|
+
throw new ArtifactFetchError(`The server resolved the reference to a "${url.protocol.replace(":", "")}" link, which is not fetched; ` +
|
|
572
622
|
"only http(s) links are.", uri, "unsupported_url");
|
|
573
623
|
}
|
|
574
624
|
if (url.username !== "" || url.password !== "") {
|
|
575
|
-
throw new ArtifactFetchError("The
|
|
625
|
+
throw new ArtifactFetchError("The server resolved the reference to a link carrying credentials, which is not fetched.", uri, "unsupported_url");
|
|
576
626
|
}
|
|
577
627
|
return url;
|
|
578
628
|
}
|
|
@@ -585,7 +635,7 @@ function checkUrl(uri, downloadUrl, allowHttp) {
|
|
|
585
635
|
async function fetchResolvedUrl(uri, downloadUrl, bounds, dispatcher, release) {
|
|
586
636
|
let url;
|
|
587
637
|
try {
|
|
588
|
-
url = checkUrl(uri, downloadUrl, bounds.allowHttp);
|
|
638
|
+
url = checkUrl(uri, downloadUrl, bounds.allowHttp, bounds.clientOrigin);
|
|
589
639
|
}
|
|
590
640
|
catch (err) {
|
|
591
641
|
release();
|
|
@@ -829,7 +879,7 @@ export const STORED_TEXT_CONCEPTS_MISSING = "concepts_missing";
|
|
|
829
879
|
* `main_stuff`, so a read can land in between: `waitForResult` keeps polling through that window
|
|
830
880
|
* for a few polls before it throws.
|
|
831
881
|
*
|
|
832
|
-
* A `pipelex-storage://` reference is resolved through the
|
|
882
|
+
* A `pipelex-storage://` reference is resolved through the server's bulk route, at most
|
|
833
883
|
* {@link BULK_RESOLVE_MAX_URIS} per request, and its signed link fetched under the same bounds as
|
|
834
884
|
* `fetchArtifact`; a link within ten seconds of its `expires_at` when its read is about to start,
|
|
835
885
|
* having waited behind the other reads, is resolved again first. A `data:` URL is decoded, its
|
|
@@ -1018,7 +1068,7 @@ async function loadStoredTextValues(client, value, node, options, runId) {
|
|
|
1018
1068
|
timeoutMs: options.timeoutMs,
|
|
1019
1069
|
allowHttp: options.allowHttp,
|
|
1020
1070
|
signal: stopping.signal,
|
|
1021
|
-
});
|
|
1071
|
+
}, client.originUrl);
|
|
1022
1072
|
const references = urls.filter(isStorageReference);
|
|
1023
1073
|
const resolved = new Map();
|
|
1024
1074
|
const items = await resolveForTexts(client, references, firstSite, options.signal);
|
|
@@ -1089,7 +1139,7 @@ async function resolveForTexts(client, references, firstSite, signal) {
|
|
|
1089
1139
|
const site = firstSite.get(references[0]);
|
|
1090
1140
|
const path = renderPath(site.segments);
|
|
1091
1141
|
const detail = err instanceof Error ? err.message : String(err);
|
|
1092
|
-
throw new StoredTextLoadError(`The stored text at ${path} could not be loaded: the
|
|
1142
|
+
throw new StoredTextLoadError(`The stored text at ${path} could not be loaded: the bulk resolve route failed: ${detail}`, {
|
|
1093
1143
|
uri: site.url,
|
|
1094
1144
|
path,
|
|
1095
1145
|
reason: "resolve_failed",
|
|
@@ -1165,7 +1215,7 @@ function findStoredTexts(value, node) {
|
|
|
1165
1215
|
async function readStoredBytes(site, resolved, bounds, maxTotalBytes, take, dispatcher) {
|
|
1166
1216
|
const path = renderPath(site.segments);
|
|
1167
1217
|
const fail = (reason, detail, extra) => {
|
|
1168
|
-
throw new StoredTextLoadError(`The stored text at ${path} could not be loaded: ${detail}`, { uri: site.url, path, reason, status: extra?.status }, { cause: extra?.cause, problem: extra?.problem });
|
|
1218
|
+
throw new StoredTextLoadError(`The stored text at ${path} could not be loaded: ${detail}`, { uri: site.url, path, reason, status: extra?.status, requirement: extra?.requirement }, { cause: extra?.cause, problem: extra?.problem });
|
|
1169
1219
|
};
|
|
1170
1220
|
if (site.url.startsWith("data:")) {
|
|
1171
1221
|
const bytes = decodeDataUrl(site.url, bounds.maxBytes);
|
|
@@ -1179,10 +1229,13 @@ async function readStoredBytes(site, resolved, bounds, maxTotalBytes, take, disp
|
|
|
1179
1229
|
}
|
|
1180
1230
|
// Unreachable: the walk admits only a reference or a data: URL, and every reference is resolved first.
|
|
1181
1231
|
if (resolved === undefined) {
|
|
1182
|
-
return fail("unsupported_url", "its url was not resolved by the
|
|
1232
|
+
return fail("unsupported_url", "its url was not resolved by the bulk resolve route.");
|
|
1233
|
+
}
|
|
1234
|
+
if (resolved.error !== null) {
|
|
1235
|
+
return fail(resolved.error.code, resolved.error.detail, {
|
|
1236
|
+
requirement: refusalRequirement(resolved.error),
|
|
1237
|
+
});
|
|
1183
1238
|
}
|
|
1184
|
-
if (resolved.error !== null)
|
|
1185
|
-
return fail(resolved.error.code, resolved.error.detail);
|
|
1186
1239
|
const link = resolved.url;
|
|
1187
1240
|
let reader;
|
|
1188
1241
|
try {
|
|
@@ -1221,6 +1274,7 @@ async function readStoredBytes(site, resolved, bounds, maxTotalBytes, take, disp
|
|
|
1221
1274
|
cause: err,
|
|
1222
1275
|
problem: err.problem,
|
|
1223
1276
|
status: err.status,
|
|
1277
|
+
requirement: err.requirement,
|
|
1224
1278
|
});
|
|
1225
1279
|
}
|
|
1226
1280
|
return fail("unknown", err instanceof Error ? err.message : String(err), { cause: err });
|
|
@@ -1415,7 +1469,7 @@ class ArtifactWriteError extends Error {
|
|
|
1415
1469
|
const SKIPPED_ABORTED = "The download was aborted before this artifact was fetched.";
|
|
1416
1470
|
const SKIPPED_CREDENTIAL = "The download stopped on a credential failure before this artifact was fetched.";
|
|
1417
1471
|
const SKIPPED_TOTAL = "Skipped: the download's total byte limit was reached by an earlier artifact.";
|
|
1418
|
-
function itemError(location, contentType, code, detail) {
|
|
1472
|
+
function itemError(location, contentType, code, detail, params) {
|
|
1419
1473
|
return {
|
|
1420
1474
|
uri: location.uri,
|
|
1421
1475
|
kind: location.kind,
|
|
@@ -1423,7 +1477,7 @@ function itemError(location, contentType, code, detail) {
|
|
|
1423
1477
|
path: null,
|
|
1424
1478
|
content_type: contentType,
|
|
1425
1479
|
size: null,
|
|
1426
|
-
error: { code, detail },
|
|
1480
|
+
error: params === undefined || params === null ? { code, detail } : { code, detail, params },
|
|
1427
1481
|
};
|
|
1428
1482
|
}
|
|
1429
1483
|
function isExpired(expiresAt) {
|
|
@@ -1496,7 +1550,7 @@ export async function downloadArtifacts(client, request) {
|
|
|
1496
1550
|
throw new ArtifactOperationError(`"concurrency" must be a positive integer, got ${String(concurrency)}.`, { problem: argumentInvalidProblem("concurrency", "not_positive") });
|
|
1497
1551
|
}
|
|
1498
1552
|
requirePositive("maxTotalBytes", maxTotalBytes);
|
|
1499
|
-
const bounds = fetchBounds(request);
|
|
1553
|
+
const bounds = fetchBounds(request, client.originUrl);
|
|
1500
1554
|
const hasRunId = typeof request.run_id === "string" && request.run_id !== "";
|
|
1501
1555
|
const hasResults = request.results != null;
|
|
1502
1556
|
if (hasRunId === hasResults) {
|
|
@@ -1534,7 +1588,7 @@ export async function downloadArtifacts(client, request) {
|
|
|
1534
1588
|
kind: reference.text === undefined ? "file" : "text",
|
|
1535
1589
|
}));
|
|
1536
1590
|
const uris = located.map((reference) => reference.uri);
|
|
1537
|
-
// A stored text's MIME type is its reference's, the
|
|
1591
|
+
// A stored text's MIME type is its reference's, the server's guess from the key otherwise.
|
|
1538
1592
|
const contentTypeOf = (index, resolvedType) => {
|
|
1539
1593
|
const stated = located[index].text?.reference["mime_type"];
|
|
1540
1594
|
return typeof stated === "string" ? stated : resolvedType;
|
|
@@ -1583,7 +1637,7 @@ export async function downloadArtifacts(client, request) {
|
|
|
1583
1637
|
const aborted = () => signal?.aborted === true;
|
|
1584
1638
|
const workerBounds = { ...bounds, signal };
|
|
1585
1639
|
// A credential refusal on a re-resolve stops the workers taking new items, and
|
|
1586
|
-
// nothing else: a fetch already running is on a
|
|
1640
|
+
// nothing else: a fetch already running is on a signed link that does not
|
|
1587
1641
|
// carry the credential, so it is left to finish and its file is kept.
|
|
1588
1642
|
let credentialFailure;
|
|
1589
1643
|
// What the total cap is held against: the bytes of every file saved or being
|
|
@@ -1744,7 +1798,7 @@ export async function downloadArtifacts(client, request) {
|
|
|
1744
1798
|
}
|
|
1745
1799
|
}
|
|
1746
1800
|
if (entry.error !== null) {
|
|
1747
|
-
outcomes[index] = itemError(location, contentTypeOf(index, null), entry.error.code, entry.error.detail);
|
|
1801
|
+
outcomes[index] = itemError(location, contentTypeOf(index, null), entry.error.code, entry.error.detail, entry.error.params);
|
|
1748
1802
|
continue;
|
|
1749
1803
|
}
|
|
1750
1804
|
outcomes[index] = await saveOne(index, entry.url, contentTypeOf(index, entry.content_type));
|