@opengeni/runtime 0.4.0 → 0.6.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.
@@ -249,8 +249,9 @@ var modalProvider = {
249
249
  if (settings.modalWorkspacePersistence) {
250
250
  options.workspacePersistence = settings.modalWorkspacePersistence;
251
251
  }
252
- if (settings.modalImageRef) {
253
- options.image = ModalImageSelector.fromTag(settings.modalImageRef);
252
+ const imageSelector = resolveModalImageSelector(settings);
253
+ if (imageSelector) {
254
+ options.image = imageSelector;
254
255
  }
255
256
  if (settings.modalTokenId) {
256
257
  options.tokenId = settings.modalTokenId;
@@ -264,6 +265,55 @@ var modalProvider = {
264
265
  return new ModalSandboxClient(options);
265
266
  }
266
267
  };
268
+ var defaultModalLoader = () => import("modal");
269
+ var resolvedRegistryImages = /* @__PURE__ */ new Map();
270
+ var inFlightRegistryImages = /* @__PURE__ */ new Map();
271
+ function registryImageCacheKey(settings) {
272
+ return [
273
+ settings.modalImageRef ?? "",
274
+ settings.modalImageRegistrySecret ?? "",
275
+ settings.modalEnvironment ?? ""
276
+ ].join("|");
277
+ }
278
+ async function ensureModalRegistryImage(settings, loadModal = defaultModalLoader) {
279
+ if (!settings.modalImageRegistrySecret || !settings.modalImageRef) {
280
+ return;
281
+ }
282
+ const key = registryImageCacheKey(settings);
283
+ if (resolvedRegistryImages.has(key)) {
284
+ return;
285
+ }
286
+ let pending = inFlightRegistryImages.get(key);
287
+ if (!pending) {
288
+ pending = (async () => {
289
+ const modal = await loadModal();
290
+ const client = new modal.ModalClient(modalClientOptions(settings));
291
+ const secret = await modal.Secret.fromName(
292
+ settings.modalImageRegistrySecret,
293
+ settings.modalEnvironment ? { environment: settings.modalEnvironment } : void 0
294
+ );
295
+ const image = client.images.fromRegistry(settings.modalImageRef, secret);
296
+ resolvedRegistryImages.set(key, image);
297
+ })().finally(() => {
298
+ inFlightRegistryImages.delete(key);
299
+ });
300
+ inFlightRegistryImages.set(key, pending);
301
+ }
302
+ await pending;
303
+ }
304
+ function cachedModalRegistryImage(settings) {
305
+ if (!settings.modalImageRegistrySecret || !settings.modalImageRef) {
306
+ return void 0;
307
+ }
308
+ return resolvedRegistryImages.get(registryImageCacheKey(settings));
309
+ }
310
+ function resolveModalImageSelector(settings) {
311
+ if (!settings.modalImageRef) {
312
+ return void 0;
313
+ }
314
+ const registryImage = cachedModalRegistryImage(settings);
315
+ return registryImage ? ModalImageSelector.fromImage(registryImage) : ModalImageSelector.fromTag(settings.modalImageRef);
316
+ }
267
317
  function modalClientOptions(settings) {
268
318
  return {
269
319
  ...settings.modalTokenId ? { tokenId: settings.modalTokenId } : {},
@@ -637,6 +687,17 @@ function setSelfhostedApplyDiff(fn) {
637
687
  injectedApplyDiff = fn;
638
688
  }
639
689
  var SELFHOSTED_DEFAULT_TIMEOUT_MS = 3e4;
690
+ var SELFHOSTED_EXEC_ENV_ALLOWLIST = ["OPENGENI_TOOLSPACE_URL", "OPENGENI_TOOLSPACE_TOKEN_FILE"];
691
+ function selfhostedExecEnv(environment) {
692
+ const env = {};
693
+ for (const key of SELFHOSTED_EXEC_ENV_ALLOWLIST) {
694
+ const value = environment[key];
695
+ if (value) {
696
+ env[key] = value;
697
+ }
698
+ }
699
+ return env;
700
+ }
640
701
  var SELFHOSTED_RELAY_STREAM_PATH = "/stream";
641
702
  var SelfhostedSession = class {
642
703
  backendId = "selfhosted";
@@ -733,7 +794,11 @@ var SelfhostedSession = class {
733
794
  // SELFHOSTED_VIRTUAL_ROOT). Empty → the session workingDir (itself "" by
734
795
  // default ⇒ the agent runs in its workspace_root).
735
796
  cwd: toMachinePath(args.workdir, this.workingDir),
736
- env: {},
797
+ // The machine owns its own shell environment; the manifest env is NOT
798
+ // exported here. The ONE exception is the non-secret toolspace pointers
799
+ // (URL + token-file path), so a programmatic `ogtool` call and the token-
800
+ // seed hook can find the tool surface. See SELFHOSTED_EXEC_ENV_ALLOWLIST.
801
+ env: selfhostedExecEnv(this.state.environment),
737
802
  stdin: new Uint8Array(0),
738
803
  timeoutMs: 0
739
804
  };
@@ -3621,6 +3686,7 @@ export {
3621
3686
  SandboxProviderUnavailableError,
3622
3687
  modalSandboxAttributionEnvironment,
3623
3688
  modalSandboxAttributionTags,
3689
+ ensureModalRegistryImage,
3624
3690
  tagModalSandbox,
3625
3691
  terminateModalSandboxById,
3626
3692
  sweepModalOrphanSandboxes,
@@ -3711,4 +3777,4 @@ export {
3711
3777
  collectSandboxEnvironment2 as collectSandboxEnvironment,
3712
3778
  parseExposedPorts2 as parseExposedPorts
3713
3779
  };
3714
- //# sourceMappingURL=chunk-HGQ252FL.js.map
3780
+ //# sourceMappingURL=chunk-BHA2SU3H.js.map