@simulatte/doppler 0.1.2 → 0.1.4

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.
@@ -13,6 +13,8 @@ import { createToolingErrorEnvelope } from '../src/tooling/command-envelope.js';
13
13
 
14
14
  const NODE_WEBGPU_INCOMPLETE_MESSAGE = 'node command: WebGPU runtime is incomplete in Node';
15
15
  const CLI_POLICY_PATH = fileURLToPath(new URL('./configs/cli/doppler-cli-policy.json', import.meta.url));
16
+ const DEFAULT_EXTERNAL_MODELS_ROOT = process.env.DOPPLER_EXTERNAL_MODELS_ROOT || '/media/x/models';
17
+ const DEFAULT_EXTERNAL_RDRR_ROOT = path.join(DEFAULT_EXTERNAL_MODELS_ROOT, 'rdrr');
16
18
  const DEFAULT_CLI_POLICY = {
17
19
  defaults: {
18
20
  surface: {
@@ -413,6 +415,37 @@ async function resolveBrowserModelUrl(request, browserOptions = {}) {
413
415
  };
414
416
  }
415
417
 
418
+ export async function resolveNodeModelUrl(request, options = {}) {
419
+ if (request.modelUrl || !request.modelId) {
420
+ return request;
421
+ }
422
+
423
+ const modelId = String(request.modelId);
424
+ const rdrrRoot = path.resolve(asStringOrNull(options.rdrrRoot) || DEFAULT_EXTERNAL_RDRR_ROOT);
425
+ const manifestPath = path.join(rdrrRoot, modelId, 'manifest.json');
426
+ if (!await pathExists(manifestPath)) {
427
+ return request;
428
+ }
429
+
430
+ const modelDir = path.dirname(manifestPath);
431
+ try {
432
+ const files = await fs.readdir(modelDir, { withFileTypes: true });
433
+ const hasShards = files.some((entry) =>
434
+ entry.isFile() && /^shard_\d+\.bin$/u.test(entry.name)
435
+ );
436
+ if (!hasShards) {
437
+ return request;
438
+ }
439
+ } catch {
440
+ return request;
441
+ }
442
+
443
+ return {
444
+ ...request,
445
+ modelUrl: pathToFileURL(modelDir).href.replace(/\/$/, ''),
446
+ };
447
+ }
448
+
416
449
  function parseSurface(value, command, policy = DEFAULT_CLI_POLICY) {
417
450
  const normalizedInput = asStringOrNull(value);
418
451
  const normalizedSurface = policy.defaults && policy.defaults.surface && policy.defaults.surface.default
@@ -616,10 +649,14 @@ function isTrainingCommandFlow(request) {
616
649
 
617
650
  async function runCommandOnSurface(request, surface, runConfig, jsonOutput) {
618
651
  if (surface === 'node') {
652
+ const nodeRequest = await resolveNodeModelUrl(request);
619
653
  if (!jsonOutput) {
620
654
  console.error('[surface] running on: node');
655
+ if (nodeRequest.modelUrl && nodeRequest.modelUrl !== request.modelUrl) {
656
+ console.error(`[surface] node resolved modelUrl=${nodeRequest.modelUrl}`);
657
+ }
621
658
  }
622
- return runNodeCommand(request, buildNodeRunOptions(jsonOutput));
659
+ return runNodeCommand(nodeRequest, buildNodeRunOptions(jsonOutput));
623
660
  }
624
661
 
625
662
  const browserOptions = buildBrowserRunOptions(runConfig, jsonOutput, request);
@@ -1164,7 +1201,17 @@ async function main() {
1164
1201
  }
1165
1202
  }
1166
1203
 
1167
- main().catch((error) => {
1168
- console.error(`[error] ${error?.message || String(error)}`);
1169
- process.exit(1);
1170
- });
1204
+ function isMainModule(metaUrl) {
1205
+ const entryPath = process.argv[1];
1206
+ if (!entryPath) {
1207
+ return false;
1208
+ }
1209
+ return path.resolve(fileURLToPath(metaUrl)) === path.resolve(entryPath);
1210
+ }
1211
+
1212
+ if (isMainModule(import.meta.url)) {
1213
+ main().catch((error) => {
1214
+ console.error(`[error] ${error?.message || String(error)}`);
1215
+ process.exit(1);
1216
+ });
1217
+ }