ppio-sandbox 2.1.1-a3 → 2.1.1-a5

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.
@@ -60,7 +60,7 @@ import createClient from "openapi-fetch";
60
60
  import platform2 from "platform";
61
61
 
62
62
  // package.json
63
- var version = "2.1.1-a3";
63
+ var version = "2.1.1-a5";
64
64
 
65
65
  // src/core/utils.ts
66
66
  import platform from "platform";
@@ -102,12 +102,6 @@ async function sha256(data) {
102
102
  function timeoutToSeconds(timeout) {
103
103
  return Math.ceil(timeout / 1e3);
104
104
  }
105
- function dynamicRequire(module) {
106
- if (runtime === "browser") {
107
- throw new Error("Browser runtime is not supported for require");
108
- }
109
- return __require(module);
110
- }
111
105
  async function dynamicImport(module) {
112
106
  if (runtime === "browser") {
113
107
  throw new Error("Browser runtime is not supported for dynamic import");
@@ -262,6 +256,8 @@ var FileUploadError = class extends BuildError {
262
256
  this.name = "FileUploadError";
263
257
  }
264
258
  };
259
+ var ImageConfigError = class extends BuildError {
260
+ };
265
261
  var VolumeError = class extends Error {
266
262
  constructor(message) {
267
263
  super(message);
@@ -3619,7 +3615,7 @@ var SandboxApi = class {
3619
3615
  return true;
3620
3616
  }
3621
3617
  static async createSandbox(template, timeoutMs, opts) {
3622
- var _a3, _b, _c, _d, _e, _f;
3618
+ var _a3, _b, _c, _d, _e, _f, _g;
3623
3619
  const config = new ConnectionConfig(opts);
3624
3620
  const lifecycle = getLifecycle(opts);
3625
3621
  const autoPause = lifecycle.onTimeout === "pause";
@@ -3628,8 +3624,13 @@ var SandboxApi = class {
3628
3624
  if (opts == null ? void 0 : opts.mcp) {
3629
3625
  raiseIfLegacy(config, "Sandbox.create mcp", SandboxError);
3630
3626
  }
3631
- if (opts == null ? void 0 : opts.network) {
3632
- raiseIfLegacy(config, "Sandbox.create network", SandboxError);
3627
+ const unsupportedNetworkOptions = Object.keys((_b = opts == null ? void 0 : opts.network) != null ? _b : {}).filter(
3628
+ (key) => key !== "allowPublicTraffic"
3629
+ );
3630
+ if (unsupportedNetworkOptions.length > 0) {
3631
+ throw new SandboxError(
3632
+ `Sandbox.create network only supports allowPublicTraffic on legacy domains; unsupported options: ${unsupportedNetworkOptions.join(", ")}`
3633
+ );
3633
3634
  }
3634
3635
  if (opts == null ? void 0 : opts.volumeMounts) {
3635
3636
  raiseIfLegacy(config, "Sandbox.create volumeMounts", SandboxError);
@@ -3637,14 +3638,14 @@ var SandboxApi = class {
3637
3638
  if (opts == null ? void 0 : opts.secretEnvs) {
3638
3639
  raiseIfLegacy(config, "Sandbox.create secretEnvs", SandboxError);
3639
3640
  }
3640
- const body2 = __spreadValues({
3641
+ const body2 = __spreadValues(__spreadValues({
3641
3642
  templateID: template,
3642
3643
  timeout: timeoutToSeconds(timeoutMs),
3643
- metadata: (_b = opts == null ? void 0 : opts.metadata) != null ? _b : {},
3644
- envVars: (_c = opts == null ? void 0 : opts.envs) != null ? _c : {},
3645
- secure: (_d = opts == null ? void 0 : opts.secure) != null ? _d : false,
3644
+ metadata: (_c = opts == null ? void 0 : opts.metadata) != null ? _c : {},
3645
+ envVars: (_d = opts == null ? void 0 : opts.envs) != null ? _d : {},
3646
+ secure: (_e = opts == null ? void 0 : opts.secure) != null ? _e : false,
3646
3647
  autoPause: autoPause != null ? autoPause : false
3647
- }, (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {});
3648
+ }, (opts == null ? void 0 : opts.network) ? { network: opts.network } : {}), (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {});
3648
3649
  const response = await fetch(`${config.apiUrl}/sandboxes`, {
3649
3650
  method: "POST",
3650
3651
  headers: getRawApiHeaders(config, {
@@ -3668,7 +3669,7 @@ var SandboxApi = class {
3668
3669
  sandboxDomain: data.domain || void 0,
3669
3670
  envdVersion: data.envdVersion,
3670
3671
  envdAccessToken: data.envdAccessToken,
3671
- trafficAccessToken: void 0
3672
+ trafficAccessToken: data.trafficAccessToken || void 0
3672
3673
  };
3673
3674
  }
3674
3675
  const client = new ApiClient(config);
@@ -3678,8 +3679,8 @@ var SandboxApi = class {
3678
3679
  mcp: opts == null ? void 0 : opts.mcp,
3679
3680
  envVars: opts == null ? void 0 : opts.envs,
3680
3681
  timeout: timeoutToSeconds(timeoutMs),
3681
- secure: (_e = opts == null ? void 0 : opts.secure) != null ? _e : true,
3682
- allow_internet_access: (_f = opts == null ? void 0 : opts.allowInternetAccess) != null ? _f : true,
3682
+ secure: (_f = opts == null ? void 0 : opts.secure) != null ? _f : true,
3683
+ allow_internet_access: (_g = opts == null ? void 0 : opts.allowInternetAccess) != null ? _g : true,
3683
3684
  network: opts == null ? void 0 : opts.network
3684
3685
  }, (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {}), autoPause !== void 0 ? { autoPause } : {}), autoResumeEnabled !== void 0 ? { autoResume: { enabled: autoResumeEnabled } } : {});
3685
3686
  if (opts == null ? void 0 : opts.volumeMounts) {
@@ -3732,7 +3733,9 @@ var SandboxApi = class {
3732
3733
  headers: getRawApiHeaders(config, {
3733
3734
  "Content-Type": "application/json"
3734
3735
  }),
3735
- body: JSON.stringify({ timeout: timeoutToSeconds(timeoutMs) }),
3736
+ body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues({
3737
+ timeout: timeoutToSeconds(timeoutMs)
3738
+ }, (opts == null ? void 0 : opts.secure) !== void 0 ? { secure: opts.secure } : {}), (opts == null ? void 0 : opts.allowPublicTraffic) !== void 0 ? { allowPublicTraffic: opts.allowPublicTraffic } : {}), (opts == null ? void 0 : opts.network) ? { network: opts.network } : {})),
3736
3739
  signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
3737
3740
  }
3738
3741
  );
@@ -3748,7 +3751,7 @@ var SandboxApi = class {
3748
3751
  sandboxDomain: data.domain || void 0,
3749
3752
  envdVersion: data.envdVersion || "0.0.0",
3750
3753
  envdAccessToken: data.envdAccessToken,
3751
- trafficAccessToken: void 0
3754
+ trafficAccessToken: data.trafficAccessToken || void 0
3752
3755
  };
3753
3756
  }
3754
3757
  const client = new ApiClient(config);
@@ -4858,6 +4861,7 @@ function defaultBuildLogger(options) {
4858
4861
  import crypto2 from "crypto";
4859
4862
  import fs from "fs";
4860
4863
  import path from "path";
4864
+ import { fileURLToPath } from "url";
4861
4865
 
4862
4866
  // src/core/template/consts.ts
4863
4867
  var FINALIZE_STEP_NAME = "finalize";
@@ -5021,8 +5025,7 @@ function getCallerDirectory(depth) {
5021
5025
  return void 0;
5022
5026
  }
5023
5027
  if (fileName.startsWith("file:")) {
5024
- const { fileURLToPath: fileURLToPath2 } = dynamicRequire("node:url");
5025
- fileName = fileURLToPath2(fileName);
5028
+ fileName = fileURLToPath(fileName);
5026
5029
  }
5027
5030
  return path.dirname(fileName);
5028
5031
  }
@@ -5639,6 +5642,7 @@ var SKIP_ENV = /* @__PURE__ */ new Set([
5639
5642
  ]);
5640
5643
  var RETRY_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
5641
5644
  var READ_ATTEMPTS = 3;
5645
+ var TOKEN_CLIENT_ID = "ppio-sandbox";
5642
5646
  var backoffBaseMs = 1e3;
5643
5647
  function unsupportedBase(blob) {
5644
5648
  var _a3, _b, _c, _d, _e;
@@ -5715,13 +5719,87 @@ function parseImageRef(image) {
5715
5719
  return { host, repository, reference };
5716
5720
  }
5717
5721
  var RegistryHttpError = class extends Error {
5718
- constructor(status, retryAfter, message) {
5722
+ constructor(status, retryAfter, message, challenge = null) {
5719
5723
  super(message);
5720
5724
  this.status = status;
5721
5725
  this.retryAfter = retryAfter;
5726
+ this.challenge = challenge;
5722
5727
  this.name = "RegistryHttpError";
5723
5728
  }
5724
5729
  };
5730
+ function parseChallenges(header) {
5731
+ const text = header != null ? header : "";
5732
+ const challenges = [];
5733
+ let index = 0;
5734
+ const skipSeparators = () => {
5735
+ while (index < text.length && " ,".includes(text[index])) {
5736
+ index++;
5737
+ }
5738
+ };
5739
+ const readToken = () => {
5740
+ const start = index;
5741
+ while (index < text.length && /[A-Za-z0-9\-_.:]/.test(text[index])) {
5742
+ index++;
5743
+ }
5744
+ return text.slice(start, index);
5745
+ };
5746
+ for (; ; ) {
5747
+ skipSeparators();
5748
+ const scheme = readToken();
5749
+ if (!scheme) {
5750
+ break;
5751
+ }
5752
+ const params = {};
5753
+ for (; ; ) {
5754
+ skipSeparators();
5755
+ if (index >= text.length) {
5756
+ break;
5757
+ }
5758
+ const keyStart = index;
5759
+ const key = readToken();
5760
+ if (!key) {
5761
+ break;
5762
+ }
5763
+ while (index < text.length && " ".includes(text[index])) {
5764
+ index++;
5765
+ }
5766
+ if (index >= text.length || text[index] !== "=") {
5767
+ index = keyStart;
5768
+ break;
5769
+ }
5770
+ index++;
5771
+ while (index < text.length && " ".includes(text[index])) {
5772
+ index++;
5773
+ }
5774
+ if (index < text.length && text[index] === '"') {
5775
+ index++;
5776
+ const chars = [];
5777
+ while (index < text.length) {
5778
+ if (text[index] === "\\" && index + 1 < text.length) {
5779
+ chars.push(text[index + 1]);
5780
+ index += 2;
5781
+ continue;
5782
+ }
5783
+ if (text[index] === '"') {
5784
+ index++;
5785
+ break;
5786
+ }
5787
+ chars.push(text[index]);
5788
+ index++;
5789
+ }
5790
+ params[key.toLowerCase()] = chars.join("");
5791
+ } else {
5792
+ const valueStart = index;
5793
+ while (index < text.length && text[index] !== ",") {
5794
+ index++;
5795
+ }
5796
+ params[key.toLowerCase()] = text.slice(valueStart, index).trim();
5797
+ }
5798
+ }
5799
+ challenges.push({ scheme, params });
5800
+ }
5801
+ return challenges;
5802
+ }
5725
5803
  var UnusableImageError = class extends Error {
5726
5804
  constructor(message) {
5727
5805
  super(message);
@@ -5748,15 +5826,20 @@ async function registryGet(url, headers, options) {
5748
5826
  );
5749
5827
  }
5750
5828
  try {
5751
- const response = await fetch(url, {
5829
+ const init = {
5752
5830
  headers,
5753
5831
  signal: AbortSignal.timeout(timeoutMs)
5754
- });
5832
+ };
5833
+ if ((options == null ? void 0 : options.dispatcher) !== void 0) {
5834
+ init.dispatcher = options.dispatcher;
5835
+ }
5836
+ const response = await fetch(url, init);
5755
5837
  if (!response.ok) {
5756
5838
  const error = new RegistryHttpError(
5757
5839
  response.status,
5758
5840
  response.headers.get("retry-after"),
5759
- `HTTP ${response.status} ${response.statusText}`
5841
+ `HTTP ${response.status} ${response.statusText}`,
5842
+ response.headers.get("www-authenticate")
5760
5843
  );
5761
5844
  if (!RETRY_STATUS.has(response.status)) {
5762
5845
  throw error;
@@ -5774,14 +5857,10 @@ async function registryGet(url, headers, options) {
5774
5857
  }
5775
5858
  throw last;
5776
5859
  }
5777
- async function authHeaders(host, repository, credentials) {
5860
+ async function authHeaders(host, repository, credentials, dispatcher) {
5778
5861
  const headers = { Accept: MANIFEST_TYPES };
5779
- if (credentials) {
5780
- const basic = Buffer.from(
5781
- `${credentials.username}:${credentials.password}`,
5782
- "utf8"
5783
- ).toString("base64");
5784
- headers.Authorization = `Basic ${basic}`;
5862
+ if ((credentials == null ? void 0 : credentials.username) && credentials.password) {
5863
+ headers.Authorization = basicHeader(credentials);
5785
5864
  }
5786
5865
  const services = {
5787
5866
  "registry-1.docker.io": ["auth.docker.io", "registry.docker.io"],
@@ -5795,9 +5874,9 @@ async function authHeaders(host, repository, credentials) {
5795
5874
  const url = `https://${authHost}/token?service=${serviceName}&scope=repository:${repository}:pull`;
5796
5875
  try {
5797
5876
  const tokenHeaders = headers.Authorization ? { Authorization: headers.Authorization } : {};
5798
- const body = await registryGet(url, tokenHeaders, {
5877
+ const body = await registryGet(url, tokenHeaders, __spreadValues({
5799
5878
  attempts: 1
5800
- });
5879
+ }, dispatcher === void 0 ? {} : { dispatcher }));
5801
5880
  if (body.token) {
5802
5881
  headers.Authorization = `Bearer ${body.token}`;
5803
5882
  }
@@ -5805,6 +5884,79 @@ async function authHeaders(host, repository, credentials) {
5805
5884
  }
5806
5885
  return headers;
5807
5886
  }
5887
+ var RegistrySession = class {
5888
+ constructor(repository, credentials, headers, dispatcher) {
5889
+ this.repository = repository;
5890
+ this.credentials = credentials;
5891
+ this.headers = headers;
5892
+ this.dispatcher = dispatcher;
5893
+ this.token = null;
5894
+ }
5895
+ /** GET `url`, resolving one Bearer challenge if the registry asks for it. */
5896
+ async get(url) {
5897
+ const headers = __spreadValues({}, this.headers);
5898
+ if (this.token) {
5899
+ headers.Authorization = `Bearer ${this.token}`;
5900
+ }
5901
+ try {
5902
+ return await registryGet(url, headers, __spreadValues({
5903
+ attempts: READ_ATTEMPTS
5904
+ }, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
5905
+ } catch (error) {
5906
+ if (!(error instanceof RegistryHttpError) || error.status !== 401) {
5907
+ throw error;
5908
+ }
5909
+ const token = await this.tokenFrom(error.challenge);
5910
+ if (token === null) {
5911
+ throw error;
5912
+ }
5913
+ this.token = token;
5914
+ headers.Authorization = `Bearer ${token}`;
5915
+ return registryGet(url, headers, __spreadValues({
5916
+ attempts: READ_ATTEMPTS
5917
+ }, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
5918
+ }
5919
+ }
5920
+ async tokenFrom(challenge) {
5921
+ for (const { scheme, params } of parseChallenges(challenge)) {
5922
+ if (scheme.toLowerCase() === "bearer") {
5923
+ return this.bearer(params);
5924
+ }
5925
+ }
5926
+ return null;
5927
+ }
5928
+ async bearer(params) {
5929
+ var _a3;
5930
+ const realm = params.realm;
5931
+ if (!realm || !/^https?:\/\//.test(realm)) {
5932
+ return null;
5933
+ }
5934
+ const url = new URL(realm);
5935
+ url.searchParams.set("client_id", TOKEN_CLIENT_ID);
5936
+ if (params.service) {
5937
+ url.searchParams.set("service", params.service);
5938
+ }
5939
+ url.searchParams.set("scope", params.scope || `repository:${this.repository}:pull`);
5940
+ const headers = {};
5941
+ if (((_a3 = this.credentials) == null ? void 0 : _a3.username) && this.credentials.password) {
5942
+ headers.Authorization = basicHeader(this.credentials);
5943
+ }
5944
+ const body = await registryGet(url.toString(), headers, __spreadValues({
5945
+ attempts: 1
5946
+ }, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
5947
+ if (body === null || typeof body !== "object") {
5948
+ return null;
5949
+ }
5950
+ return body.token || body.access_token || null;
5951
+ }
5952
+ };
5953
+ function basicHeader(credentials) {
5954
+ const encoded = Buffer.from(
5955
+ `${credentials.username}:${credentials.password}`,
5956
+ "utf8"
5957
+ ).toString("base64");
5958
+ return `Basic ${encoded}`;
5959
+ }
5808
5960
  function platformName(entry) {
5809
5961
  var _a3, _b, _c;
5810
5962
  const p = (_a3 = entry.platform) != null ? _a3 : {};
@@ -5849,41 +6001,53 @@ function describeFailure(error, image, host, repository, authenticated) {
5849
6001
  const reason = `no such image: Docker Hub has no official image '${image}' (HTTP 401). The \`library/\` namespace has no private repositories, so this is a typo rather than a permissions problem`;
5850
6002
  return __spreadProps(__spreadValues({}, empty), { error: reason, unusable: reason });
5851
6003
  }
6004
+ if (error.status === 401) {
6005
+ const reason = authenticated ? `cannot read '${image}' (HTTP 401): the registry rejected the credentials. Check the username, the password, and the read permission on the repository` : `cannot read '${image}' (HTTP 401): the registry wants pull credentials for it. Pass the registry username and password, or check that the reference names an existing public image`;
6006
+ return __spreadProps(__spreadValues({}, empty), { error: reason });
6007
+ }
5852
6008
  return __spreadProps(__spreadValues({}, empty), { error: `${error.name}: ${error.message}` });
5853
6009
  }
5854
6010
  const message = error instanceof Error ? error.message : String(error);
5855
6011
  return __spreadProps(__spreadValues({}, empty), { error: message });
5856
6012
  }
5857
- async function fetchImageConfig(image, credentials) {
6013
+ async function fetchImageConfig(image, credentials, options) {
5858
6014
  var _a3, _b, _c, _d, _e, _f, _g;
6015
+ const dispatcher = options == null ? void 0 : options.dispatcher;
6016
+ const cacheable = dispatcher === void 0;
5859
6017
  const key = JSON.stringify([
5860
6018
  image,
5861
6019
  (_a3 = credentials == null ? void 0 : credentials.username) != null ? _a3 : null,
5862
6020
  (_b = credentials == null ? void 0 : credentials.password) != null ? _b : null
5863
6021
  ]);
5864
- const cached = CACHE.get(key);
5865
- if (cached) {
5866
- return copyConfig(cached);
6022
+ if (cacheable) {
6023
+ const cached = CACHE.get(key);
6024
+ if (cached) {
6025
+ return copyConfig(cached);
6026
+ }
5867
6027
  }
5868
6028
  const { host, repository, reference } = parseImageRef(image);
5869
6029
  let result;
5870
6030
  try {
5871
- const auth = await authHeaders(host, repository, credentials);
6031
+ const auth = await authHeaders(host, repository, credentials, dispatcher);
6032
+ const session = new RegistrySession(
6033
+ repository,
6034
+ credentials,
6035
+ auth,
6036
+ dispatcher
6037
+ );
5872
6038
  const base = `https://${host}/v2/${repository}`;
5873
- let manifest = await registryGet(
5874
- `${base}/manifests/${reference}`,
5875
- auth
6039
+ let manifest = await session.get(
6040
+ `${base}/manifests/${reference}`
5876
6041
  );
5877
6042
  if (manifest.manifests) {
5878
6043
  const digest = pickAmd64(manifest, image);
5879
- manifest = await registryGet(`${base}/manifests/${digest}`, auth);
6044
+ manifest = await session.get(`${base}/manifests/${digest}`);
5880
6045
  }
5881
6046
  if (!((_c = manifest.config) == null ? void 0 : _c.digest)) {
5882
6047
  throw new Error(`${image}: manifest names no config blob`);
5883
6048
  }
5884
- const blob = await registryGet(
5885
- `${base}/blobs/${manifest.config.digest}`,
5886
- auth
6049
+ const blob = await session.get(
6050
+ `${base}/blobs/${manifest.config.digest}`
5887
6051
  );
5888
6052
  const declared = (_d = blob.config) != null ? _d : {};
5889
6053
  const env = {};
@@ -5910,10 +6074,14 @@ async function fetchImageConfig(image, credentials) {
5910
6074
  image,
5911
6075
  host,
5912
6076
  repository,
5913
- credentials !== void 0
6077
+ // Both, because that is what the request actually carried: a lone username
6078
+ // is not a credential the registry could have rejected.
6079
+ Boolean((credentials == null ? void 0 : credentials.username) && (credentials == null ? void 0 : credentials.password))
5914
6080
  );
5915
6081
  }
5916
- CACHE.set(key, result);
6082
+ if (cacheable) {
6083
+ CACHE.set(key, result);
6084
+ }
5917
6085
  return copyConfig(result);
5918
6086
  }
5919
6087
  function effectiveStartCmd(entrypoint, cmd) {
@@ -6096,6 +6264,13 @@ var TemplateBase = class _TemplateBase {
6096
6264
  // image's PATH -- the exact failure this reading exists to prevent.
6097
6265
  this.imageConfigError = void 0;
6098
6266
  this.imageUnusable = void 0;
6267
+ // What a failed read does. "warn" by default: one unreachable registry must not
6268
+ // abort a batch conversion, but a template silently missing the image's PATH is
6269
+ // the failure this reading exists to prevent, so it cannot pass unmentioned.
6270
+ this.imageOnConfigFailure = "warn";
6271
+ // Carries the TLS trust and proxy settings for a self-hosted registry, which
6272
+ // Node's fetch cannot be told about in any other per-request way.
6273
+ this.imageDispatcher = void 0;
6099
6274
  this.fileContextPath = runtime === "browser" ? "." : (_a2 = getCallerDirectory(STACK_TRACE_DEPTH)) != null ? _a2 : ".";
6100
6275
  this.fileIgnorePatterns = [];
6101
6276
  this.logsRefreshFrequency = 200;
@@ -6322,12 +6497,40 @@ var TemplateBase = class _TemplateBase {
6322
6497
  fromBaseImage() {
6323
6498
  return this.fromImage(this.defaultBaseImage);
6324
6499
  }
6500
+ /**
6501
+ * Build from a Docker image, restoring what the image declares.
6502
+ *
6503
+ * The image's ENV, WORKDIR and start command are read from its registry config
6504
+ * because the platform's own pull does not apply them. Reading is best-effort
6505
+ * and asynchronous, so it happens at build/serialize time.
6506
+ *
6507
+ * @param credentials registry username and password, for a private image.
6508
+ * @param options.inheritConfig restore the image's config (default true).
6509
+ * @param options.onConfigFailure what a failed read does — see
6510
+ * {@link ImageConfigFailureMode}. Defaults to `warn`.
6511
+ * @param options.dispatcher Node fetch `dispatcher` (an undici `Agent`), for a
6512
+ * self-hosted registry behind a private CA, a client certificate or a proxy.
6513
+ * For example, with a private CA:
6514
+ *
6515
+ * ```ts
6516
+ * import { Agent } from 'undici'
6517
+ * const dispatcher = new Agent({ connect: { ca: readFileSync('/ca.pem') } })
6518
+ * Template().fromImage('harbor.internal/app:1', undefined, { dispatcher })
6519
+ * ```
6520
+ */
6325
6521
  fromImage(baseImage, credentials, options) {
6326
- var _a3;
6522
+ var _a3, _b;
6523
+ if ((options == null ? void 0 : options.onConfigFailure) !== void 0 && !["warn", "raise", "ignore"].includes(options.onConfigFailure)) {
6524
+ throw new InvalidArgumentError(
6525
+ 'onConfigFailure must be "warn", "raise" or "ignore", got ' + String(options.onConfigFailure)
6526
+ );
6527
+ }
6327
6528
  this.baseImage = baseImage;
6328
6529
  this.baseTemplate = void 0;
6329
6530
  this.inheritImageConfig = (_a3 = options == null ? void 0 : options.inheritConfig) != null ? _a3 : true;
6330
6531
  this.imageCredentials = credentials;
6532
+ this.imageOnConfigFailure = (_b = options == null ? void 0 : options.onConfigFailure) != null ? _b : "warn";
6533
+ this.imageDispatcher = options == null ? void 0 : options.dispatcher;
6331
6534
  if (credentials) {
6332
6535
  this.registryConfig = {
6333
6536
  type: "registry",
@@ -6742,23 +6945,35 @@ var TemplateBase = class _TemplateBase {
6742
6945
  * restored config — but it is reported, since an image whose toolchain lives
6743
6946
  * behind its ENV will otherwise look installed and behave as though it is not.
6744
6947
  */
6948
+ /** The one wording a failed read is reported with, on every channel. */
6949
+ configFailureMessage() {
6950
+ return `Could not read ${this.baseImage}: ${this.imageConfigError}. The template will build without the environment, working directory and start command the image declares.`;
6951
+ }
6745
6952
  async resolveInheritedConfig(onBuildLogs) {
6746
6953
  var _a3;
6954
+ if (this.imageOnConfigFailure === "raise" && this.imageConfigError !== void 0) {
6955
+ throw new ImageConfigError(this.configFailureMessage());
6956
+ }
6747
6957
  if (!this.inheritImageConfig || this.baseImage === void 0) {
6748
6958
  return;
6749
6959
  }
6750
6960
  this.inheritImageConfig = false;
6751
- const config = await fetchImageConfig(this.baseImage, this.imageCredentials);
6961
+ const config = await fetchImageConfig(
6962
+ this.baseImage,
6963
+ this.imageCredentials,
6964
+ this.imageDispatcher === void 0 ? void 0 : { dispatcher: this.imageDispatcher }
6965
+ );
6752
6966
  if (config.error) {
6753
6967
  this.imageConfigError = config.error;
6754
6968
  this.imageUnusable = config.unusable;
6755
- onBuildLogs == null ? void 0 : onBuildLogs(
6756
- new LogEntry(
6757
- /* @__PURE__ */ new Date(),
6758
- "warn",
6759
- `Could not read ${this.baseImage}: ${config.error}. The template will build without the environment, working directory and start command the image declares.`
6760
- )
6761
- );
6969
+ const message = this.configFailureMessage();
6970
+ if (this.imageOnConfigFailure === "raise") {
6971
+ throw new ImageConfigError(message);
6972
+ }
6973
+ if (this.imageOnConfigFailure !== "ignore") {
6974
+ console.warn(message);
6975
+ onBuildLogs == null ? void 0 : onBuildLogs(new LogEntry(/* @__PURE__ */ new Date(), "warn", message));
6976
+ }
6762
6977
  return;
6763
6978
  }
6764
6979
  this.envs = __spreadValues(__spreadValues({}, config.env), this.envs);
@@ -7145,6 +7360,7 @@ Template.list = TemplateBase.list;
7145
7360
  Template.delete = TemplateBase.delete;
7146
7361
  Template.toJSON = TemplateBase.toJSON;
7147
7362
  Template.toDockerfile = TemplateBase.toDockerfile;
7363
+ Template.imageConfigFailure = TemplateBase.imageConfigFailure;
7148
7364
 
7149
7365
  // src/core/volume/index.ts
7150
7366
  function quotaInodesForSize(quotaSizeGiB) {
@@ -7362,7 +7578,7 @@ var Volume = class _Volume {
7362
7578
 
7363
7579
  // src/core/client.ts
7364
7580
  import path2 from "path";
7365
- import { fileURLToPath } from "url";
7581
+ import { fileURLToPath as fileURLToPath2 } from "url";
7366
7582
  function mergeConnectionOpts(base, next) {
7367
7583
  var _a3, _b;
7368
7584
  const baseHeaders = (_a3 = base.headers) != null ? _a3 : {};
@@ -7572,7 +7788,7 @@ var TemplateNamespace = class {
7572
7788
  for (const site of callsites(2)) {
7573
7789
  const fileName = site.getFileName();
7574
7790
  if (fileName && (!fileName.includes("/src/core/") || fileName.includes("/src/core/tests/")) && !fileName.includes("/node_modules/ppio-sandbox/")) {
7575
- callerContext = path2.dirname(fileName.startsWith("file:") ? fileURLToPath(fileName) : fileName);
7791
+ callerContext = path2.dirname(fileName.startsWith("file:") ? fileURLToPath2(fileName) : fileName);
7576
7792
  break;
7577
7793
  }
7578
7794
  }
@@ -7707,12 +7923,12 @@ var PPIO = class {
7707
7923
  this.secret = new SecretNamespace(opts);
7708
7924
  this.codeInterpreter = new RuntimeSandboxNamespace(
7709
7925
  opts,
7710
- () => import("./sandbox-SMDAOO7A.mjs")
7926
+ () => import("./sandbox-GD3E5T3C.mjs")
7711
7927
  );
7712
7928
  this.code_interpreter = this.codeInterpreter;
7713
7929
  this.desktop = new RuntimeSandboxNamespace(
7714
7930
  opts,
7715
- () => import("./sandbox-TZ5BE2RX.mjs")
7931
+ () => import("./sandbox-U6WT7JIS.mjs")
7716
7932
  );
7717
7933
  }
7718
7934
  async create(templateOrOpts, opts) {
@@ -7755,6 +7971,7 @@ export {
7755
7971
  RateLimitError,
7756
7972
  BuildError,
7757
7973
  FileUploadError,
7974
+ ImageConfigError,
7758
7975
  VolumeError,
7759
7976
  SecretError,
7760
7977
  ApiClient,
@@ -7790,4 +8007,4 @@ export {
7790
8007
  ALL_TRAFFIC,
7791
8008
  core_default
7792
8009
  };
7793
- //# sourceMappingURL=chunk-ALX77S7W.mjs.map
8010
+ //# sourceMappingURL=chunk-473VNTF7.mjs.map