@alint-js/core 0.0.37 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.mjs +28 -3
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -396,8 +396,27 @@ function resolveModel(registry, options = {}) {
396
396
  const ruleId = options.ruleId ?? "<unknown>";
397
397
  if (options.request !== void 0) {
398
398
  const request = options.request;
399
- const candidate = candidates.find((candidate) => matchesRequest(candidate, request));
400
- if (candidate === void 0) throw new Error(`Unknown model "${request}".`);
399
+ const canonicalCandidates = candidates.filter((candidate) => canonicalIdentity(candidate) === request);
400
+ if (canonicalCandidates.length > 1) throw duplicateDefinitionError(request);
401
+ let candidate = canonicalCandidates[0];
402
+ if (candidate === void 0) {
403
+ const matchingCandidates = candidates.filter((candidate) => matchesRequest(candidate, request));
404
+ const matchesByCanonical = /* @__PURE__ */ new Map();
405
+ for (const matchingCandidate of matchingCandidates) {
406
+ const identity = canonicalIdentity(matchingCandidate);
407
+ const matches = matchesByCanonical.get(identity) ?? [];
408
+ matches.push(matchingCandidate);
409
+ matchesByCanonical.set(identity, matches);
410
+ }
411
+ const duplicateIdentity = [...matchesByCanonical].find(([, matches]) => matches.length > 1)?.[0];
412
+ if (duplicateIdentity !== void 0) throw duplicateDefinitionError(duplicateIdentity);
413
+ if (matchingCandidates.length === 0) throw new Error(`Unknown model "${request}".`);
414
+ if (matchingCandidates.length > 1) {
415
+ const choices = [...matchesByCanonical.keys()];
416
+ throw new Error(`Ambiguous model "${request}".\nSpecify a provider-qualified model:\n${choices.map((choice) => ` ${choice}`).join("\n")}`);
417
+ }
418
+ candidate = matchingCandidates[0];
419
+ }
401
420
  if (!satisfiesHardRequirements(candidate.model, options.requirement)) throw new Error(`Model "${request}" does not satisfy requirement for rule "${ruleId}".`);
402
421
  return toResolvedModel(candidate, options.requirement);
403
422
  }
@@ -405,6 +424,12 @@ function resolveModel(registry, options = {}) {
405
424
  if (candidate === void 0) throw new Error(`No model satisfies requirement for rule "${ruleId}".`);
406
425
  return toResolvedModel(candidate, options.requirement);
407
426
  }
427
+ function canonicalIdentity({ model, provider }) {
428
+ return `${provider.id}/${model.id}`;
429
+ }
430
+ function duplicateDefinitionError(identity) {
431
+ return /* @__PURE__ */ new Error(`Model "${identity}" is configured more than once.\nRemove duplicate provider/model definitions from the setup configuration.`);
432
+ }
408
433
  function flattenModels(registry) {
409
434
  return registry.providers.flatMap((provider) => provider.models.map((model) => ({
410
435
  model,
@@ -619,7 +644,7 @@ function statSyncIsDirectory(path) {
619
644
  }
620
645
  //#endregion
621
646
  //#region package.json
622
- var version = "0.0.37";
647
+ var version = "0.1.0";
623
648
  //#endregion
624
649
  //#region src/core/execution/job.ts
625
650
  var CacheReplayProcessingError = class {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alint-js/core",
3
3
  "type": "module",
4
- "version": "0.0.37",
4
+ "version": "0.1.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.mts",