@x12i/ai-profiles 2.0.1 → 2.1.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/README.md +148 -45
- package/dist/buildResolvedProfile.d.ts.map +1 -1
- package/dist/buildResolvedProfile.js +7 -0
- package/dist/buildResolvedProfile.js.map +1 -1
- package/dist/costTiers.d.ts +4 -0
- package/dist/costTiers.d.ts.map +1 -0
- package/dist/costTiers.js +20 -0
- package/dist/costTiers.js.map +1 -0
- package/dist/data/models-profiles.bak.json +2336 -0
- package/dist/data/models-profiles.json +166 -14
- package/dist/data/profiles-shortcuts.json +86 -34
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/isKnownProfileChoice.d.ts +6 -0
- package/dist/isKnownProfileChoice.d.ts.map +1 -0
- package/dist/isKnownProfileChoice.js +11 -0
- package/dist/isKnownProfileChoice.js.map +1 -0
- package/dist/listAIProfileChoices.d.ts +6 -0
- package/dist/listAIProfileChoices.d.ts.map +1 -0
- package/dist/listAIProfileChoices.js +50 -0
- package/dist/listAIProfileChoices.js.map +1 -0
- package/dist/listAIProfiles.d.ts.map +1 -1
- package/dist/listAIProfiles.js +23 -0
- package/dist/listAIProfiles.js.map +1 -1
- package/dist/modalityPolicy.d.ts +4 -1
- package/dist/modalityPolicy.d.ts.map +1 -1
- package/dist/modalityPolicy.js +82 -3
- package/dist/modalityPolicy.js.map +1 -1
- package/dist/modelInputFallback.d.ts.map +1 -1
- package/dist/modelInputFallback.js +12 -2
- package/dist/modelInputFallback.js.map +1 -1
- package/dist/normalizeKey.d.ts +6 -0
- package/dist/normalizeKey.d.ts.map +1 -1
- package/dist/normalizeKey.js +16 -0
- package/dist/normalizeKey.js.map +1 -1
- package/dist/profileChoiceKey.d.ts +37 -0
- package/dist/profileChoiceKey.d.ts.map +1 -0
- package/dist/profileChoiceKey.js +96 -0
- package/dist/profileChoiceKey.js.map +1 -0
- package/dist/profileDiscoveryMatch.d.ts +15 -0
- package/dist/profileDiscoveryMatch.d.ts.map +1 -0
- package/dist/profileDiscoveryMatch.js +18 -0
- package/dist/profileDiscoveryMatch.js.map +1 -0
- package/dist/resolveAIProfile.d.ts +4 -5
- package/dist/resolveAIProfile.d.ts.map +1 -1
- package/dist/resolveAIProfile.js +51 -81
- package/dist/resolveAIProfile.js.map +1 -1
- package/dist/resolveAIProfileByTags.d.ts +2 -2
- package/dist/resolveAIProfileByTags.d.ts.map +1 -1
- package/dist/resolveAIProfileByTags.js +28 -10
- package/dist/resolveAIProfileByTags.js.map +1 -1
- package/dist/resolveAIProfileWithCostAlternatives.d.ts +17 -0
- package/dist/resolveAIProfileWithCostAlternatives.d.ts.map +1 -0
- package/dist/resolveAIProfileWithCostAlternatives.js +129 -0
- package/dist/resolveAIProfileWithCostAlternatives.js.map +1 -0
- package/dist/resolveCatalogModel.d.ts +7 -0
- package/dist/resolveCatalogModel.d.ts.map +1 -0
- package/dist/resolveCatalogModel.js +34 -0
- package/dist/resolveCatalogModel.js.map +1 -0
- package/dist/resolveSecondaryModel.d.ts.map +1 -1
- package/dist/resolveSecondaryModel.js +17 -8
- package/dist/resolveSecondaryModel.js.map +1 -1
- package/dist/secondaryModel.d.ts +0 -5
- package/dist/secondaryModel.d.ts.map +1 -1
- package/dist/secondaryModel.js +1 -13
- package/dist/secondaryModel.js.map +1 -1
- package/dist/types.d.ts +87 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/validateProfileCatalogLinkage.d.ts.map +1 -1
- package/dist/validateProfileCatalogLinkage.js +2 -1
- package/dist/validateProfileCatalogLinkage.js.map +1 -1
- package/dist/validation/validateModelsProfilesJson.d.ts.map +1 -1
- package/dist/validation/validateModelsProfilesJson.js +11 -7
- package/dist/validation/validateModelsProfilesJson.js.map +1 -1
- package/dist/vendorPolicy.d.ts.map +1 -1
- package/dist/vendorPolicy.js +1 -6
- package/dist/vendorPolicy.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { normalizeKey, normalizeSegmentKey, resolveSegmentKey, } from "./normalizeKey.js";
|
|
2
|
+
/** Separator for the canonical profile+choice lookup key (`cheap/default`). */
|
|
3
|
+
export const PROFILE_CHOICE_KEY_SEP = "/";
|
|
4
|
+
/** Normalize composite input: trim/lowercase and treat `\` like `/`. */
|
|
5
|
+
function normalizeProfileChoiceInput(input) {
|
|
6
|
+
return normalizeKey(input).replace(/\\/g, PROFILE_CHOICE_KEY_SEP);
|
|
7
|
+
}
|
|
8
|
+
export function formatProfileChoiceKey(profile, choice) {
|
|
9
|
+
return `${profile}${PROFILE_CHOICE_KEY_SEP}${choice}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse `profile/choice` (also accepts `profile\choice` on input).
|
|
13
|
+
* Rejects empty segments and keys with more than one separator.
|
|
14
|
+
* Segment names accept `-` or `_` interchangeably at lookup time.
|
|
15
|
+
*/
|
|
16
|
+
export function parseProfileChoiceKey(input) {
|
|
17
|
+
const normalized = normalizeProfileChoiceInput(input);
|
|
18
|
+
if (!normalized.includes(PROFILE_CHOICE_KEY_SEP)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const slash = normalized.indexOf(PROFILE_CHOICE_KEY_SEP);
|
|
22
|
+
const profile = normalized.slice(0, slash);
|
|
23
|
+
const choice = normalized.slice(slash + 1);
|
|
24
|
+
if (!profile || !choice || choice.includes(PROFILE_CHOICE_KEY_SEP)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return { profile, choice };
|
|
28
|
+
}
|
|
29
|
+
export function isProfileChoiceKeyFormat(input) {
|
|
30
|
+
return parseProfileChoiceKey(input) !== undefined;
|
|
31
|
+
}
|
|
32
|
+
function resolveProfileChoiceSegments(registry, profileSegment, choiceSegment) {
|
|
33
|
+
const profileKey = resolveSegmentKey(Object.keys(registry.profiles), profileSegment);
|
|
34
|
+
if (!profileKey) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const profile = registry.profiles[profileKey];
|
|
38
|
+
const choiceKey = resolveSegmentKey(Object.keys(profile.choices), choiceSegment);
|
|
39
|
+
if (!choiceKey) {
|
|
40
|
+
return {
|
|
41
|
+
kind: "invalidChoice",
|
|
42
|
+
profile: profileKey,
|
|
43
|
+
choice: normalizeSegmentKey(choiceSegment),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
kind: "profileChoice",
|
|
48
|
+
profile: profileKey,
|
|
49
|
+
choice: choiceKey,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve input to an explicit profile+choice pair.
|
|
54
|
+
* Accepts `profile/choice` or `profile\choice` composite keys, or shortcuts that pin both fields.
|
|
55
|
+
*/
|
|
56
|
+
export function matchStrictProfileInput(registry, input) {
|
|
57
|
+
const key = normalizeKey(input);
|
|
58
|
+
if (!key) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const composite = parseProfileChoiceKey(key);
|
|
62
|
+
if (composite) {
|
|
63
|
+
return resolveProfileChoiceSegments(registry, composite.profile, composite.choice);
|
|
64
|
+
}
|
|
65
|
+
const shortcutKey = resolveSegmentKey(Object.keys(registry.shortcuts), key);
|
|
66
|
+
if (shortcutKey) {
|
|
67
|
+
const shortcut = registry.shortcuts[shortcutKey];
|
|
68
|
+
if (!shortcut.choice) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const resolved = resolveProfileChoiceSegments(registry, shortcut.profile, shortcut.choice);
|
|
72
|
+
if (!resolved || resolved.kind === "invalidChoice") {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
kind: "shortcut",
|
|
77
|
+
shortcutKey,
|
|
78
|
+
profile: resolved.profile,
|
|
79
|
+
choice: resolved.choice,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
export function listRegistryProfileChoiceKeys(registry) {
|
|
85
|
+
const out = [];
|
|
86
|
+
for (const [profileKey, profile] of Object.entries(registry.profiles)) {
|
|
87
|
+
for (const choiceKey of Object.keys(profile.choices)) {
|
|
88
|
+
out.push({ profile: profileKey, choice: choiceKey });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
export function isKnownProfileChoiceInput(registry, input) {
|
|
94
|
+
return matchStrictProfileInput(registry, input) !== undefined;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=profileChoiceKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileChoiceKey.js","sourceRoot":"","sources":["../src/profileChoiceKey.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAG3B,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAY,CAAC;AAEnD,wEAAwE;AACxE,SAAS,2BAA2B,CAAC,KAAa;IAChD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;AACpE,CAAC;AAOD,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,MAAc;IACpE,OAAO,GAAG,OAAO,GAAG,sBAAsB,GAAG,MAAM,EAAE,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,MAAM,UAAU,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,KA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,EAAE,CAAC;QACtE,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACrD,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,QAA4D,EAC5D,KAAa;IAEb,OAAO,uBAAuB,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,SAAS,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AIProfilesRegistry } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loose profile-level match for discovery APIs only (tags, search, cost scouting).
|
|
4
|
+
* Never used by {@link resolveAIProfile}.
|
|
5
|
+
*/
|
|
6
|
+
export type DiscoveryProfileMatch = {
|
|
7
|
+
kind: "profile";
|
|
8
|
+
profileKey: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "alias";
|
|
11
|
+
profileKey: string;
|
|
12
|
+
alias: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function matchDiscoveryProfileInput(registry: Pick<AIProfilesRegistry, "profiles">, input: string): DiscoveryProfileMatch | undefined;
|
|
15
|
+
//# sourceMappingURL=profileDiscoveryMatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileDiscoveryMatch.d.ts","sourceRoot":"","sources":["../src/profileDiscoveryMatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAC7B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAC9C,KAAK,EAAE,MAAM,GACZ,qBAAqB,GAAG,SAAS,CAsBnC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizeKey, normalizeSegmentKey, resolveSegmentKey } from "./normalizeKey.js";
|
|
2
|
+
export function matchDiscoveryProfileInput(registry, input) {
|
|
3
|
+
const key = normalizeKey(input);
|
|
4
|
+
if (!key) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const profileKey = resolveSegmentKey(Object.keys(registry.profiles), key);
|
|
8
|
+
if (profileKey) {
|
|
9
|
+
return { kind: "profile", profileKey };
|
|
10
|
+
}
|
|
11
|
+
for (const [profileKey, profile] of Object.entries(registry.profiles)) {
|
|
12
|
+
if (profile.aliases?.some((alias) => normalizeSegmentKey(alias) === normalizeSegmentKey(key))) {
|
|
13
|
+
return { kind: "alias", profileKey, alias: key };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=profileDiscoveryMatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profileDiscoveryMatch.js","sourceRoot":"","sources":["../src/profileDiscoveryMatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWzF,MAAM,UAAU,0BAA0B,CACxC,QAA8C,EAC9C,KAAa;IAEb,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1E,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtE,IACE,OAAO,CAAC,OAAO,EAAE,IAAI,CACnB,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,CAAC,KAAK,mBAAmB,CAAC,GAAG,CAAC,CACnE,EACD,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { ResolveAIProfileOptions, ResolvedAIProfile } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Resolve
|
|
3
|
+
* Resolve an explicit `profile/choice` key (or a shortcut that pins both) to a concrete model.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @see README.md — “Why AI profiles”
|
|
5
|
+
* For discovery (tags, search, profile-level intent), use {@link listAIProfiles},
|
|
6
|
+
* {@link resolveAIProfileByTags}, or {@link resolveAIProfileWithCostAlternatives}.
|
|
7
|
+
* For raw model SKUs, use {@link resolveCatalogModel}.
|
|
9
8
|
*/
|
|
10
9
|
export declare function resolveAIProfile(input: string, options: ResolveAIProfileOptions): Promise<ResolvedAIProfile>;
|
|
11
10
|
//# sourceMappingURL=resolveAIProfile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAIProfile.d.ts","sourceRoot":"","sources":["../src/resolveAIProfile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveAIProfile.d.ts","sourceRoot":"","sources":["../src/resolveAIProfile.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE7E;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CAoM5B"}
|
package/dist/resolveAIProfile.js
CHANGED
|
@@ -2,20 +2,18 @@ import { buildResolvedProfile } from "./buildResolvedProfile.js";
|
|
|
2
2
|
import { AIProfilesError } from "./errors.js";
|
|
3
3
|
import { loadAIProfilesRegistryWithWarnings } from "./loader/loadAIProfilesRegistry.js";
|
|
4
4
|
import { loadModelsCatalogWithWarnings } from "./loader/loadModelsCatalog.js";
|
|
5
|
-
import {
|
|
6
|
-
import { buildResolvedModelInput, modelInputLogMeta, resolveModelFromInput, } from "./modelInputFallback.js";
|
|
5
|
+
import { formatProfileChoiceKey, matchStrictProfileInput, } from "./profileChoiceKey.js";
|
|
7
6
|
import { pickProfileChoiceWithConstraints } from "./modalityPolicy.js";
|
|
8
7
|
import { normalizeCostCap } from "./costPolicy.js";
|
|
9
|
-
import {
|
|
8
|
+
import { resolveCostTierCap } from "./costTiers.js";
|
|
10
9
|
import { assertOpenRouterCatalogCoverage, assertProfileCatalogLane, } from "./profileCatalogLane.js";
|
|
11
10
|
import { attachSecondaryToResolved } from "./resolveSecondaryModel.js";
|
|
12
11
|
/**
|
|
13
|
-
* Resolve
|
|
12
|
+
* Resolve an explicit `profile/choice` key (or a shortcut that pins both) to a concrete model.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @see README.md — “Why AI profiles”
|
|
14
|
+
* For discovery (tags, search, profile-level intent), use {@link listAIProfiles},
|
|
15
|
+
* {@link resolveAIProfileByTags}, or {@link resolveAIProfileWithCostAlternatives}.
|
|
16
|
+
* For raw model SKUs, use {@link resolveCatalogModel}.
|
|
19
17
|
*/
|
|
20
18
|
export async function resolveAIProfile(input, options) {
|
|
21
19
|
if (!options.catalogLane) {
|
|
@@ -32,70 +30,39 @@ export async function resolveAIProfile(input, options) {
|
|
|
32
30
|
}),
|
|
33
31
|
]);
|
|
34
32
|
const loaderWarnings = [...warnings, ...catalogResult.warnings];
|
|
35
|
-
const match =
|
|
36
|
-
const modelFallback = match
|
|
37
|
-
? undefined
|
|
38
|
-
: resolveModelFromInput(input, catalogResult.catalog);
|
|
33
|
+
const match = matchStrictProfileInput(registry, input);
|
|
39
34
|
if (!match) {
|
|
40
|
-
|
|
41
|
-
const meta = modelInputLogMeta(input, modelFallback);
|
|
42
|
-
if (modelFallback.confidence === "low") {
|
|
43
|
-
logxer.warn("Best-effort AI model fallback for model-like input", meta);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
logxer.info("Resolved model-like input to catalog model", meta);
|
|
47
|
-
}
|
|
48
|
-
return buildResolvedModelInput({
|
|
49
|
-
input,
|
|
50
|
-
match: modelFallback,
|
|
51
|
-
registry,
|
|
52
|
-
loaderWarnings,
|
|
53
|
-
useOpenRouter: options.useOpenRouter,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
throw new AIProfilesError("UNKNOWN_PROFILE", `Unknown AI profile, shortcut, or alias: ${input}`, { input });
|
|
35
|
+
throw new AIProfilesError("UNKNOWN_PROFILE_CHOICE", `Unknown profile/choice key: ${input}. Use "profile/choice" (e.g. "cheap/default") or a shortcut that pins both.`, { input });
|
|
57
36
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let matchedShortcut;
|
|
61
|
-
switch (match.kind) {
|
|
62
|
-
case "profile":
|
|
63
|
-
profileKey = match.profileKey;
|
|
64
|
-
requestedChoiceKey = options.choice;
|
|
65
|
-
matchedShortcut = undefined;
|
|
66
|
-
break;
|
|
67
|
-
case "shortcut":
|
|
68
|
-
profileKey = match.profileKey;
|
|
69
|
-
requestedChoiceKey = options.choice ?? match.shortcut.choice;
|
|
70
|
-
matchedShortcut = match.shortcut;
|
|
71
|
-
break;
|
|
72
|
-
case "alias":
|
|
73
|
-
profileKey = match.profileKey;
|
|
74
|
-
requestedChoiceKey = options.choice;
|
|
75
|
-
matchedShortcut = undefined;
|
|
76
|
-
break;
|
|
37
|
+
if (match.kind === "invalidChoice") {
|
|
38
|
+
throw new AIProfilesError("UNKNOWN_CHOICE", `Unknown choice '${match.choice}' for AI profile '${match.profile}'`, { input, profile: match.profile, choice: match.choice });
|
|
77
39
|
}
|
|
40
|
+
const profileKey = match.profile;
|
|
41
|
+
const requestedChoiceKey = match.choice;
|
|
42
|
+
const matchedShortcut = match.kind === "shortcut"
|
|
43
|
+
? registry.shortcuts[match.shortcutKey]
|
|
44
|
+
: undefined;
|
|
78
45
|
const profile = registry.profiles[profileKey];
|
|
79
46
|
if (!profile) {
|
|
80
47
|
throw new AIProfilesError("UNKNOWN_PROFILE", `Unknown AI profile: ${profileKey}`, { input, profile: profileKey });
|
|
81
48
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
}
|
|
49
|
+
try {
|
|
50
|
+
assertProfileCatalogLane({
|
|
51
|
+
profileKey,
|
|
52
|
+
profile,
|
|
53
|
+
requestedLane: options.catalogLane,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
58
|
+
throw new AIProfilesError("CATALOG_LANE_MISMATCH", message, {
|
|
59
|
+
input,
|
|
60
|
+
profile: profileKey,
|
|
61
|
+
catalogLane: options.catalogLane,
|
|
62
|
+
});
|
|
98
63
|
}
|
|
64
|
+
const costCapPer1M = options.costCapPer1M ??
|
|
65
|
+
resolveCostTierCap(options.costTier, options.costTiers);
|
|
99
66
|
let finalChoiceKey;
|
|
100
67
|
let choice;
|
|
101
68
|
try {
|
|
@@ -103,11 +70,12 @@ export async function resolveAIProfile(input, options) {
|
|
|
103
70
|
choiceKey: requestedChoiceKey,
|
|
104
71
|
allowedProviders: options.allowedProviders,
|
|
105
72
|
preferLeadingVendors: options.preferLeadingVendors ?? true,
|
|
106
|
-
explicitChoiceRequested:
|
|
107
|
-
(match.kind === "shortcut" && match.shortcut.choice !== undefined),
|
|
73
|
+
explicitChoiceRequested: true,
|
|
108
74
|
inputModalities: options.inputModalities,
|
|
109
75
|
outputModalities: options.outputModalities,
|
|
110
|
-
costCapPer1M
|
|
76
|
+
costCapPer1M,
|
|
77
|
+
capabilityFilter: options.capabilityFilter,
|
|
78
|
+
focus: options.focus,
|
|
111
79
|
catalog: catalogResult.catalog,
|
|
112
80
|
});
|
|
113
81
|
finalChoiceKey = picked.choiceKey;
|
|
@@ -119,10 +87,8 @@ export async function resolveAIProfile(input, options) {
|
|
|
119
87
|
throw new AIProfilesError("NO_ALLOWED_VENDOR", message, {
|
|
120
88
|
input,
|
|
121
89
|
profile: profileKey,
|
|
90
|
+
choice: requestedChoiceKey,
|
|
122
91
|
allowedProviders: options.allowedProviders,
|
|
123
|
-
availableProviders: [
|
|
124
|
-
...new Set(Object.values(profile.choices).map((c) => c.provider)),
|
|
125
|
-
],
|
|
126
92
|
});
|
|
127
93
|
}
|
|
128
94
|
if (message.includes("required modalities")) {
|
|
@@ -139,22 +105,26 @@ export async function resolveAIProfile(input, options) {
|
|
|
139
105
|
input,
|
|
140
106
|
profile: profileKey,
|
|
141
107
|
choice: requestedChoiceKey,
|
|
142
|
-
costCapPer1M
|
|
108
|
+
costCapPer1M,
|
|
143
109
|
});
|
|
144
110
|
}
|
|
145
111
|
if (message.startsWith("Unknown choice")) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
throw new AIProfilesError("UNKNOWN_CHOICE", message, { input, profile: profileKey, choice: requestedChoiceKey });
|
|
112
|
+
throw new AIProfilesError("UNKNOWN_CHOICE", message, {
|
|
113
|
+
input,
|
|
114
|
+
profile: profileKey,
|
|
115
|
+
choice: requestedChoiceKey,
|
|
116
|
+
});
|
|
153
117
|
}
|
|
154
118
|
throw error;
|
|
155
119
|
}
|
|
156
|
-
if (
|
|
157
|
-
throw new AIProfilesError("
|
|
120
|
+
if (finalChoiceKey !== requestedChoiceKey) {
|
|
121
|
+
throw new AIProfilesError("CHOICE_SUBSTITUTED", `Explicit choice '${requestedChoiceKey}' was replaced with '${finalChoiceKey}' for profile '${profileKey}'. Use a different profile/choice key or discovery APIs.`, {
|
|
122
|
+
input,
|
|
123
|
+
profile: profileKey,
|
|
124
|
+
choice: requestedChoiceKey,
|
|
125
|
+
resolvedChoice: finalChoiceKey,
|
|
126
|
+
expectedKey: formatProfileChoiceKey(profileKey, requestedChoiceKey),
|
|
127
|
+
});
|
|
158
128
|
}
|
|
159
129
|
const enforceOpenRouterCatalog = profileKey === "local"
|
|
160
130
|
? options.requireOpenRouterCatalog === true
|
|
@@ -190,7 +160,7 @@ export async function resolveAIProfile(input, options) {
|
|
|
190
160
|
loaderWarnings,
|
|
191
161
|
useOpenRouter: options.useOpenRouter,
|
|
192
162
|
catalog: catalogResult.catalog,
|
|
193
|
-
costCapApplied: normalizeCostCap(
|
|
163
|
+
costCapApplied: normalizeCostCap(costCapPer1M),
|
|
194
164
|
});
|
|
195
165
|
if (options.includeSecondary) {
|
|
196
166
|
return attachSecondaryToResolved(resolved, registry, catalogResult.catalog, options.useOpenRouter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAIProfile.js","sourceRoot":"","sources":["../src/resolveAIProfile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,a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,YAAY,CAAC;KAC/C,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7B,OAAO,yBAAyB,CAC9B,QAAQ,EACR,QAAQ,EACR,aAAa,CAAC,OAAO,EACrB,OAAO,CAAC,aAAa,CACtB,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -4,8 +4,8 @@ export interface ResolveAIProfileByTagsOptions extends ResolveAIProfileOptions {
|
|
|
4
4
|
minScore?: number;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Discovery: pick the best-matching profile by tags, auto-select a choice under constraints,
|
|
8
|
+
* then resolve the resulting `profile/choice` key.
|
|
9
9
|
*/
|
|
10
10
|
export declare function resolveAIProfileByTags(tags: AIProfileTag[], options: ResolveAIProfileByTagsOptions): Promise<ResolvedAIProfile>;
|
|
11
11
|
//# sourceMappingURL=resolveAIProfileByTags.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAIProfileByTags.d.ts","sourceRoot":"","sources":["../src/resolveAIProfileByTags.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveAIProfileByTags.d.ts","sourceRoot":"","sources":["../src/resolveAIProfileByTags.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE3F,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC5E,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,YAAY,EAAE,EACpB,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,iBAAiB,CAAC,CA8D5B"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { AIProfilesError } from "./errors.js";
|
|
2
2
|
import { loadAIProfilesRegistryWithWarnings } from "./loader/loadAIProfilesRegistry.js";
|
|
3
|
+
import { loadModelsCatalogWithWarnings } from "./loader/loadModelsCatalog.js";
|
|
3
4
|
import { profileMatchesCatalogLane } from "./profileCatalogLane.js";
|
|
4
5
|
import { pickBestProfileByTags } from "./profileDiscovery.js";
|
|
6
|
+
import { formatProfileChoiceKey } from "./profileChoiceKey.js";
|
|
7
|
+
import { pickProfileChoiceWithConstraints } from "./modalityPolicy.js";
|
|
5
8
|
import { resolveAIProfile } from "./resolveAIProfile.js";
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
10
|
+
* Discovery: pick the best-matching profile by tags, auto-select a choice under constraints,
|
|
11
|
+
* then resolve the resulting `profile/choice` key.
|
|
9
12
|
*/
|
|
10
13
|
export async function resolveAIProfileByTags(tags, options) {
|
|
11
14
|
if (!options.catalogLane) {
|
|
@@ -15,19 +18,34 @@ export async function resolveAIProfileByTags(tags, options) {
|
|
|
15
18
|
if (uniqueTags.length === 0) {
|
|
16
19
|
throw new AIProfilesError("UNKNOWN_PROFILE", "resolveAIProfileByTags requires at least one tag", { tags });
|
|
17
20
|
}
|
|
18
|
-
const { registry } = await
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const [{ registry }, catalogResult] = await Promise.all([
|
|
22
|
+
loadAIProfilesRegistryWithWarnings({
|
|
23
|
+
source: options.source,
|
|
24
|
+
refresh: options.refresh,
|
|
25
|
+
}),
|
|
26
|
+
loadModelsCatalogWithWarnings({
|
|
27
|
+
source: options.source,
|
|
28
|
+
refresh: options.refresh,
|
|
29
|
+
}),
|
|
30
|
+
]);
|
|
22
31
|
const minScore = options.minScore ?? 1;
|
|
23
|
-
const pool = options.catalogLane
|
|
24
|
-
? Object.fromEntries(Object.entries(registry.profiles).filter(([, profile]) => profileMatchesCatalogLane(profile, options.catalogLane)))
|
|
25
|
-
: registry.profiles;
|
|
32
|
+
const pool = Object.fromEntries(Object.entries(registry.profiles).filter(([, profile]) => profileMatchesCatalogLane(profile, options.catalogLane)));
|
|
26
33
|
const best = pickBestProfileByTags(pool, uniqueTags);
|
|
27
34
|
if (!best || best.score < minScore) {
|
|
28
35
|
throw new AIProfilesError("UNKNOWN_PROFILE", `No profile matches tags: ${uniqueTags.join(", ")}`, { tags: uniqueTags, minScore });
|
|
29
36
|
}
|
|
37
|
+
const profile = registry.profiles[best.profileKey];
|
|
38
|
+
const picked = pickProfileChoiceWithConstraints(best.profileKey, profile, {
|
|
39
|
+
allowedProviders: options.allowedProviders,
|
|
40
|
+
preferLeadingVendors: options.preferLeadingVendors ?? true,
|
|
41
|
+
explicitChoiceRequested: false,
|
|
42
|
+
inputModalities: options.inputModalities,
|
|
43
|
+
outputModalities: options.outputModalities,
|
|
44
|
+
capabilityFilter: options.capabilityFilter,
|
|
45
|
+
focus: options.focus,
|
|
46
|
+
catalog: catalogResult.catalog,
|
|
47
|
+
});
|
|
30
48
|
const { minScore: _minScore, ...resolveOptions } = options;
|
|
31
|
-
return resolveAIProfile(best.profileKey, resolveOptions);
|
|
49
|
+
return resolveAIProfile(formatProfileChoiceKey(best.profileKey, picked.choiceKey), resolveOptions);
|
|
32
50
|
}
|
|
33
51
|
//# sourceMappingURL=resolveAIProfileByTags.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAIProfileByTags.js","sourceRoot":"","sources":["../src/resolveAIProfileByTags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kCAAkC,EAAE,MAAM,oCAAoC,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQzD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAo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AgC,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE;QACxE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,IAAI;QAC1D,uBAAuB,EAAE,KAAK;QAC9B,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,OAAO,EAAE,aAAa,CAAC,OAAO;KAC/B,CAAC,CAAC;IAEH,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,CAAC;IAC3D,OAAO,gBAAgB,CACrB,sBAAsB,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,EACzD,cAAc,CACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CostTierSpec, ResolveAIProfileOptions, ResolvedAIProfile } from "./types.js";
|
|
2
|
+
export interface ResolveAIProfileWithCostAlternativesResult {
|
|
3
|
+
primary: ResolvedAIProfile;
|
|
4
|
+
alternativesByCostTier: Array<{
|
|
5
|
+
tier: string;
|
|
6
|
+
resolved: ResolvedAIProfile | null;
|
|
7
|
+
reason?: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a fixed `profile/choice` and scout alternate choices under other cost-tier caps.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveAIProfileWithCostAlternatives(input: string, options: ResolveAIProfileOptions & {
|
|
14
|
+
tiers?: CostTierSpec[];
|
|
15
|
+
includePrimaryTier?: boolean;
|
|
16
|
+
}): Promise<ResolveAIProfileWithCostAlternativesResult>;
|
|
17
|
+
//# sourceMappingURL=resolveAIProfileWithCostAlternatives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveAIProfileWithCostAlternatives.d.ts","sourceRoot":"","sources":["../src/resolveAIProfileWithCostAlternatives.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,0CAA0C;IACzD,OAAO,EAAE,iBAAiB,CAAC;IAC3B,sBAAsB,EAAE,KAAK,CAAC;QAC5B,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;QACnC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ;AAQD;;GAEG;AACH,wBAAsB,oCAAoC,CACxD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,GAAG;IACjC,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,GACA,OAAO,CAAC,0CAA0C,CAAC,CAwJrD"}
|